GraalVM Efficient Language-Level Virtualization Eric Sedlar Copyright 2017,

GraalVM Efficient Language-Level Virtualization Eric Sedlar Copyright  2017,

GraalVM Efficient Language-Level Virtualization Eric Sedlar Copyright 2017, Oracle and/or its affiliates. All rights reserved. | Confidential Oracle Internal/Restricted/Highly Restricted We live in a multilingual computing world Long tail of programming languages Programming Language Popularity(TOP 20 Languages From May 2017 Tiob If you run more than a few apps you probably run more than a few languages We use different languages for different jobs: Java Others C R or Python for data science Ruby or JavaScript for front ends Java or C/C++ for server back ends C++ Unfortunately, most runtimes cant run most languages very well JVM doesnt run JS, Python or native code well CLR doesnt run languages not from MSFT very well Python C#

Scratch PL/SQL VB.NET Delphi/Object Pascal MATLAB JavaScript Go Objective-C Assembly language R Swift VB Ruby Perl PHP Copyright 2017, Oracle and/or its affiliates. All rights reserved. | Confidential Oracle Internal/Restricted/Highly Restricted 2 GraalVM is a meta-runtime for language virtualization Doesnt just run appsdesigned to run things that run apps (i.e. interpreters) GraalVM languages are built on the Truffle API (in Java) for constructing interpreters Interpreters define the semantics of the language, and are also used to profile program behavior to guide compilation of frequently-used code (e.g. loops) GraalVM includes multiple language interpreters, and learns the type system and language from what they do in order to generate an efficient compiler based on that interpreter Since the interpreters are all implemented in Java, merging them together into a single engine looks the same to GraalVM like a single (very complicated) language (with zero language crossing costs) Graal

compiler JavaScript Interpreter Ruby R Python Interpreter Interpreter Interpreter Truffle API Graal watches Truffle API activity to learn the language Java Runtime Compiled Compiled code snippet Compiled code snippet Compiled code snippet Compiled code snippet Compiled code snippet code snippet Copyright 2017, Oracle and/or its affiliates. All rights reserved. | Confidential Oracle Internal/Restricted/Highly Restricted

3 Lets fill in the complete GraalVM architecture (I) Step one: run each languages application, libraries & frameworks on the interpreters Looks easy, right? Graal compiler JavaScript application JavaScript libraries Ruby application Ruby gems & libraries Node.js Rails JavaScript Interpreter Ruby R Python Interpreter Interpreter Interpreter Truffle API Java Runtime

Compiled Compiled code snippet Compiled code snippet Compiled code snippet Compiled code snippet Compiled code snippet code snippet Copyright 2017, Oracle and/or its affiliates. All rights reserved. | Confidential Oracle Internal/Restricted/Highly Restricted 4 But many language runtimes have a lot of native libraries They use native code for better performance in core areas or for systems functionality If you run native code in GraalVM, doesnt that break all of the abstraction you want from a virtual machine? Is that a secure way to run applications? Native code isnt in a safe sandbox Graal compiler JavaScript application JavaScript libraries

Ruby application Ruby gems & libraries Node.js Rails JavaScript Interpreter Ruby R Python Interpreter Interpreter Interpreter Truffle API Java Runtime Native Libraries & OS ??? Compiled Compiled code snippet Compiled code snippet Compiled code snippet Compiled code snippet Compiled

code snippet code snippet Copyright 2017, Oracle and/or its affiliates. All rights reserved. | Confidential Oracle Internal/Restricted/Highly Restricted 5 We have a solution for thatanother Truffle interpreter LLVM (low level virtual machine) bitcode interpreter LLVM supports dozens of (static) languages (C, C++, FORTRAN, COBOL, Rust, Julia, Swift, Objective-C, ) The LLVM compiler generates bitcode (i.e. a .bc file) for all of the languages as an intermediate step We can write a Truffle interpreter for LLVM bitcode and run in the (bounds-checked) VM sandbox! Graal compiler JavaScript application JavaScript libraries Ruby application Ruby gems & libraries Node.js Rails JavaScript Interpreter

R native libraries Node.js native libs Ruby/Rails native libs LLVM .bc Ruby R Python Interpreter Interpreter Interpreter Interpreter Truffle API Java Runtime Compiled Compiled code snippet Compiled code snippet Compiled code snippet Compiled code snippet Compiled code snippet code snippet Copyright 2017, Oracle and/or its affiliates. All rights reserved. | Confidential Oracle Internal/Restricted/Highly Restricted 6

Why is GraalVM Different? Multilingual Embeddable Secure Efficient Copyright 2017, Oracle and/or its affiliates. All rights reserved. | Oracle Confidential Highly Restricted 8 Programming Language Popularity(TOP 20 Languages From May 2017 Tiobe INDE GraalVM Language Status Available 2017 Java Groovy FORTRAN Kotlin Clojure Scala F# Others C Available 2018 C++ Proposed / Prototyping Python The rest of the languages are not really

applicable on a server, or are legacy (except Go) C# Scratch PL/SQL VB.NET Delphi/Object Pascal MATLAB JavaScript Go Objective-C Assembly language R Swift VB Ruby Perl PHP Copyright 2017, Oracle and/or its affiliates. All rights reserved. | Confidential Oracle Internal/Restricted/Highly Restricted 9 Most language-level runtimes are bad at multilingualism What are the issues? Language-level runtimes generally designed with a one or two languages in mind The semantics of the original language pollute the VM, so other languages dont fit well Foreign languages running on a language-level VM generally have a hard time achieving

high degrees (99%+) levels of compatibility Performance of multilingual runtimes is often poor outside of the base language JDK Nashorn is 3x 5x slower than Google V8, Apple Safari Generally a performance penalty for crossing language barriers (e.g. JNI) Running multiple separate VMs means two separate heaps to size, to separate engines to tune & manage, and 10x-1000x higher overhead to cross language boundaries Copyright 2017, Oracle and/or its affiliates. All rights reserved. | Confidential Oracle Internal/Restricted/Highly Restricted 10 Multilingual Demo Combining languages in one runtime Debugging multilingual apps Copyright 2017, Oracle and/or its affiliates. All rights reserved. | Confidential Oracle Internal/Restricted/Highly Restricted 11 Embeddability GraalVM allows any portions of the runtime (memory management, thread scheduling, code cache, etc.) to be supplied by the embedding engine Well demonstrate this in tomorrows session, Accelerating Your Database Applications Simply with Graal (using the Oracle RDBMS & MySQL) Copyright 2017, Oracle and/or its affiliates. All rights reserved. | Confidential Oracle Internal/Restricted/Highly Restricted 12 GraalVM is a hybrid of static & dynamic runtimes SubstrateVM provides standalone & embeddable infrastructure to run GraalVM Application code can be precompiled or dynamically loaded via SVM Copyright 2017, Oracle and/or its affiliates. All rights reserved. | Confidential Oracle Internal/Restricted/Highly Restricted

13 Flexibility and security with GraalVM two-layer design Host Language (Java + native) Guest Language (Ruby, JavaScript, Python, R, Java, native) Ahead-of-time compiled (closed world) Dynamically compiled (open world) 100x faster startup 2x lower footprint * Still managed (garbage collected, boundschecked, & secured against stack overflows) Trusted code should run here Only whitelisted code is guest accessible Reflection is limited to white lists as well Runtime-profiled against the shape of actual data to maximize peak performance Add in new code to running system Flexible, productive (dynamic) Memory-boxed & time-boxed so that totally untrusted code can run here Even native extensions to guest language libraries can be run safely No language-crossing overhead for extensions Copyright 2017, Oracle and/or its affiliates. All rights reserved. | Confidential Oracle Internal/Restricted/Highly Restricted Embeddability Demo:

Fast Startup & Low Footprint Aggressive & Complete Ahead-of-Time Compilation using SubstrateVM Copyright 2017, Oracle and/or its affiliates. All rights reserved. | Confidential Oracle Internal/Restricted/Highly Restricted 15 High-Performance for Each Language Speedup, higher is better 5 4.5 4.1 Graal Best Specialized Competition 4 3 2 1 0 1.02 Java 1.2 Scala 0.85 Ruby R

Native 0.9 JavaScript Performance on 64-bit x86 on well-known benchmark suites relative to:HotSpot/Server, JRuby, GNU R, LLVM AOT compiled, V8 Copyright 2017, Oracle and/or its affiliates. All rights reserved. | 16 Application Level Performance What about real applications, not just benchmarks According to Twitter, Graal runs Twitter 25% faster than Java8 WebLogic Server has 10% better throughput running basic web pages Copyright 2017, Oracle and/or its affiliates. All rights reserved. | Confidential Oracle Internal/Restricted/Highly Restricted 17 Multiplicative Value-Add of Graal Ecosystem Your Code Languages Java JavaScript Ruby R Python C/C++. FORTRAN, *

Graal Optimizations Tooling Interoperability * Embeddings HotSpot JVM MySQL Oracle RDBMS Spark nginx Copyright 2017, Oracle and/or its affiliates. All rights reserved. | Confidential Oracle Internal GraalVM Community Currently we use [email protected] for all external discussions We want to move most traffic off the OpenJDK site other than information related to integration of the Graal compiler with OpenJDK New mailing list: [email protected] Web: otn.oracle.com/oracle-labs/program-languages/overview/index.html These demos were done with graalvm-0.28 Graal projects on github: github.com/graalvm Copyright 2017, Oracle and/or its affiliates. All rights reserved. | Confidential Oracle Internal/Restricted/Highly Restricted 19 Confidential Oracle Internal/Restricted/Highly Restricted 20 JavaOne / OOW topics Topic

Devops Talk JavaOne Talk Walnut Talk Multilingual computingdifferent langs for various tasks Architecture overview (meta-runtime, LLVM, host + guest) Graal as a fast Java compiler (e.g. Streams, Twitter, WebLogic) Polyglot Node demo + multilingual debug + show tools (Chrome debug + VisualVM) Multilingual performance slide (Java - Native, Java-JS, JS-Native) Embeddability (Network effects of multi-language + multi-runtime)

Security Startup / AOT compilation demo (grep tool using JavaScript) Container overhead (memory overhead) slide Startup / AOT compilation (incl fast javac demo) Java integration (JVMCI, Metropolis) Using NPM public ecosystem in database processing Call to actiontry out your workload with our OTN download and find bugs (go to javaone, walnut) (Go to walnut

talk) Copyright 2017, Oracle and/or its affiliates. All rights reserved. | Confidential Oracle Internal/Restricted/Highly Restricted GraalVM Architectural Deep-Dive Copyright 2017, Oracle and/or its affiliates. All rights reserved. | Confidential Oracle Internal/Restricted/Highly Restricted 22 This picture of the GraalVM architecture is simplified The parts look a bit different depending on where GraalVM is embedded Notice we arent showing how to run Java apps yet? GraalVM compiler JavaScript application JavaScript libraries Ruby application Ruby gems & libraries Node.js Rails JavaScript Interpreter

R native libraries Node.js native libs Ruby/Rails native libs LLVM .bc Ruby R Python Interpreter Interpreter Interpreter Interpreter Truffle API Java Runtime Threads / Scheduler Filesystem Network GC / heap Compiled Compiled code snippet Compiled code snippet Compiled code snippet Compiled code snippet Compiled code snippet

code snippet Code cache 23 Copyright 2017, Oracle and/or its affiliates. All rights reserved. | GraalVM embedded in the Java VM The parts look a bit different depending on where GraalVM is embedded When GraalVM is embedded in the HotSpot JVM, you can run Java apps directly on the JVM without Truffle In this case, JVM uses Graal as a Java bytecode compiler via the JVM Compiler Interface (JVMCI, or JEP 243) Note: Truffle gives an Abstract Syntax Tree (language-agnostic representation of work to do) to Graal, not Java bytecodes eval("application/x-ruby", "def add(a, b) a + b; end;"); Polyglot API Ruby application Ruby gems & libraries Node.js Rails JavaScript Interpreter Truffle CI Graal compiler

JavaScript application JavaScript libraries R native libraries Node.js native libs Ruby/Rails native libs LLVM .bc Ruby R Interpreter Interpreter Interpreter Truffle API Java application JavaVM Runtime JVMCI Threads / Scheduler Filesystem Network GC / heap Code cache Compiled Compiled code snippet Compiled code

snippet Compiled code snippet Compiled code snippet Compiled code snippet code snippet 24 Copyright 2017, Oracle and/or its affiliates. All rights reserved. | GraalVM embedded in the Oracle Database Embedding GraalVM allows substitution of the underlying engines service layer Oracle database takes on many functions of an OS: scheduling, resource management, I/O GraalVM allows mixing & matching system components from the underlying runtime eval("application/x-ruby", "def add(a, b) a + b; end;"); Truffle Polyglot API JavaScript application JavaScript libraries Ruby application Ruby gems

& libraries Node.js Rails JavaScript Interpreter LLVM .bc Ruby R Interpreter Interpreter Interpreter Truffle CI Graal compiler R native libraries Node.js native libs Ruby/Rails native libs Truffle API GraalVM Runtime GC / heap Oracle RDBMS Runtime Net

Code cache Filesystem Threads / Scheduler Compiled Compiled code snippet Compiled code snippet Compiled code snippet Compiled code snippet Compiled code snippet code snippet 25 Copyright 2017, Oracle and/or its affiliates. All rights reserved. |

Recently Viewed Presentations

  • Sullivan Algebra and Trigonometry: Section 7.1

    Sullivan Algebra and Trigonometry: Section 7.1

    Sullivan Algebra and Trigonometry: Section 6.1 Angles and Their Measures Objectives of this Section Convert Between Degrees, Minutes, Seconds, and Decimal Forms for Angles Find the Arc Length of a Circle Convert From Degrees to Radians, Radians to Degrees Find...
  • Chapter 1: The Study of Urban Geography

    Chapter 1: The Study of Urban Geography

    Chapter 1: The Study of Urban Geography The Study of Urban Geography Concerned with Local Variability in a General Context Want to know the distinctiveness of individual places and regularities within and between cities How did these Distinctive identities evolve?
  • Chapter 2: Objects and Primitive Data (Examples)

    Chapter 2: Objects and Primitive Data (Examples)

    Chapter 2: Objects and Primitive Data (Examples) INF 523Q Countdown.java //***** // Countdown.java Author: Lewis and Loftus // Demonstrates the difference between print and println. //***** public class Countdown { // Prints two lines of output representing a rocket countdown.
  • Typhoid fever

    Typhoid fever

    Refrigeration and freezing substantially slow or halt their growth. Pasteurizing and food irradiation kill Salmonella for commercially-produced foodstuffs containing raw eggs such as ice cream. Foods prepared in the home from raw eggs can spread salmonella if not properly cooked...
  • Models and Approaches to Health Promotion

    Models and Approaches to Health Promotion

    Models Of Health Promotion (cont.) A more analytical means of identifying heath promotion is to develop models of practice. All models seek to represent reality in some way and try to show in a simplified form how different things connect.
  • Time Management - InformationAnthology

    Time Management - InformationAnthology

    Time management is a skill that EVERYONE must work on in all areas of their life. personal, academic, work, community efforts. Successful time management requires . self-evaluation. and the . desire to improve. Effective time management will require you to...
  • Gallbladder Removal Among Obese Pediatric Patients PAS 646 ...

    Gallbladder Removal Among Obese Pediatric Patients PAS 646 ...

    Gallbladder Removal Among Obese Pediatric Patients PAS 646 March 24, 2006 Advisor: Gilbert Boissonneault PhD, PA-C Review: Functions of the Gallbladder: *store bile *secretes bile when fat is ingested in the diet Types of Gallbladder disease: *cholelithiasis* *chronic and acute...
  • Vibrational Properties of the Lattice - Physics & Astronomy

    Vibrational Properties of the Lattice - Physics & Astronomy

    Using Bloch's Theorem: The Krönig-Penney Model Boundary Conditions and Bloch's Theorem Results of the Krönig-Penney Model Numerical Solution of the Krönig-Penney Model Numerical Results of the Krönig-Penney Model F. Empty Lattice Bands and Simple Metals Empty Lattice Bands for bcc...