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

  • Cong nystagmus - Private Eye Clinic

    Cong nystagmus - Private Eye Clinic

    Clinical Examination. A complete . ocular exam, (VA at different gaze angles, AHP assessment, identification of asymmetric (a)periodic alternating nystagmus (APAN)- (*if undetected, may result in improper muscle-shifting surgery),- ask parents if AHP is stable (if EVER seen FT to...
  • Exploring the persistence of paper with the electronic health ...

    Exploring the persistence of paper with the electronic health ...

    International Journal of Medical Informatics . 7 8 ( 2 0 0 9 ) 618-628. Presented by: Brooke Ethington. BUS 550; 11/16/2010. Exploring the Persistence of Paper with the Electronic Health Record (EHR)
  • Figure 1.1 Centers of early civilizations - Water was a ...

    Figure 1.1 Centers of early civilizations - Water was a ...

    If a man has released waters and so has let the water carry away the works on his neighbour's field, he shall pay 10 gur of corn for every bur flooded. ... Spanish law recognized sound water practices used by...
  • Analysis and write-up of qualitative data

    Analysis and write-up of qualitative data

    Info on observer. The problem with qualitative data. Often a mass of data with no rules for the researcher to apply. There are no pre-defined categories, dimensions, etc. to tally up. The language used by interviewees, etc. has multiple meanings...
  • Evidence-Based Medicine - Using the Cochrane Library - ATSU

    Evidence-Based Medicine - Using the Cochrane Library - ATSU

    The End * Table of Contents Review of Prior Lessons: Evidence Pyramid Using the Cochrane Library Purpose of the Cochrane Library Access the Cochrane Library through the ATSU Portal Search the Cochrane Library Advanced Search MeSH Search Search History Saved...
  • Fungus  Like Protists Chapter 19 p. 540 Fungus-like

    Fungus Like Protists Chapter 19 p. 540 Fungus-like

    Phylum Myxomycota Acellular Slime Molds Begin life cycles as amebalike cells that grow into large masses The Mass is actually a single cell with thousands of nuclei Slime Mold on the move Slime Mold movement Acellular Slime Mold cont.
  • Program Leadership Vice Dean, MD Program Dr. Patricia

    Program Leadership Vice Dean, MD Program Dr. Patricia

    Operations, Mississauga Academy of Medicine. Wendy Leslie, Interim Manager. Curriculum . Nadia Taylor, Manager. Assessment and Evaluation. David Tihanyi, Manager
  • From Objectives to Outcomes - Laerdal Medical

    From Objectives to Outcomes - Laerdal Medical

    Belmont UniversityNashville, Tennessee. 2- Eight bed Adult Health laboratories. 8 bed "Acute care" lab. 4 bed Peds lab. 8 bed Health Assessment/OB lab. 4 Inter-professional private patient areas