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

  • CS 4740/6740 Network Security

    CS 4740/6740 Network Security

    Sign overflows occur when an unsigned variable is treated as signed, or vice-versa Can occur when mixing signed and unsigned variables in an expression Or, wraparound when performing arithmetic
  • Pork Retail Cut Quiz Session Home  Shank Section

    Pork Retail Cut Quiz Session Home Shank Section

    Pork Retail Cut Quiz Session Home T-bone Structure Tenderloin Loin Eye Loin Eye Backbone Rib Bone Lean Fat Skin Lean Fat Round Bone Round Bone Round Bone Shank End Shank Bones Dark Flakes The End Home Shank Section Flat Bone...
  • Dia 1 - norden.lmi.is

    Dia 1 - norden.lmi.is

    "def" for concepts. concepts can be from any controlled vocabularies like thesauri, code lists, schemas etc. "doc" documentation related to "so", "id" or "def" Includes different formats of the data (for example GML, JSONā€¦) and references to other related data...
  • Presentation Format Guidelines for The Aerospace Corporation

    Presentation Format Guidelines for The Aerospace Corporation

    The Aerospace Corporation Space Science Applications Laboratory ... during a relatively weak outer zone enhancement 9/1/2011 to 9/1/2014 RPS-B * RPS Extended Mission Items RPS measurement of total ionizing dose is an important contribution to questions about vehicle health ~6.7...
  • Nationalism at Center Stage Sect. 2 - Schoolwires

    Nationalism at Center Stage Sect. 2 - Schoolwires

    Fletcher v. Peck: voids Georgia law violating right to make contract. ... it would become increasingly difficult in the future to argue that the union was a creation of the states, that states could exert an independent check on federal...
  • INL Background - University of Idaho

    INL Background - University of Idaho

    Virginia L. Wright. University of Idaho. Computer Science Colloquia. October 9, 2017. INL Background. One in a network of 17 DOE national labs. DOE's lead lab for nuclear energy. A major center for National Security. Research in the National Interest...
  • Close - LANG-LIT A LEVEL

    Close - LANG-LIT A LEVEL

    This alludes to the first line of the poem 'Lock the door,' portraying concealment, importance and privacy. Close as an adjective: only a short distance away or apart in space or time. ... with the pity of bells, a cigarette...
  • Boolean Algebra - Oakland University

    Boolean Algebra - Oakland University

    Generalized De Morgan's Theorem Lecture L5.4 Section 5.1 What kind of gate is this? What kind of gate is this if 0 = TRUE and 1 = FALSE? What kind of gate is this?