Semester: summer 2021/22
Page in SIS: NSWI176
Grading: Credit

News

This course is no longer taught and has been replaced by a course focusing on Virtual Machines and Managed Runtimes with a somewhat broader scope.

About

What’s the fastest programming language? Can JavaScript be faster than C? Is there an easy way to write a programming language that’s going to be really fast? Do we always have to write all libraries from scratch whenever there is a new language? Is it hard to implement a debugger? And what about a profiler? How much work is that? Those are some of the questions we are going to answer in this course!

To answer those questions, we are going to use GraalVM — the fastest virtual machine developed by OracleLabs in Zurich, Linz, Prague & elsewhere. Thanks to the expertise of the GraalVM team from Prague, the workshop is going to be practical, discussing latest trends in the design and development of virtual machines. There are no taboo questions — we know everything there is to know about GraalVM!

The goal of the course is to demonstrate the benefits and drawbacks of dynamic compilation, understand what the compiler is actually doing, and learn how to communicate with it (e.g., how to structure your code to get the best out of GraalVM). Should you have your own programming language — bring it with you and we’ll make it faster!

The most curious of you can also join us in our OracleLabs offices in Jinonice and spend some time coding with GraalVM during a summer internship.

Join the nswi176@d3s.mff.cuni.cz mailing-list to receive updates, resource references, and to ask questions that did not make it into the labs!

All course videos are also available in this playlist.

Schedule

TopicDetails
I. Towards the Fastest JVM on the Planet! (slides)
  • Overview of GraalVM with the help of the Sieve of Eratosthenes
  • GraalVM gives you speed, polyglot and tooling
  • Truffle: just build your AST and the interpreter is going to be fast!
  • Architecture of GraalVM
  • Java goes native with AOT compilation
  • Speculation and deoptimization

Demo: https://www.youtube.com/watch?v=zFxrZTVknmk

II. How do Modern Compilers Work (slides)

Based on Chris’s talk and slides:

  • What is a JIT compiler?
  • Why write a JIT compiler in Java?
  • Setting up Graal
  • The JVM compiler interface
  • The Graal graph
  • From bytecode to machine code
    • The bytecode parser and graph builder
    • Emitting assembly
    • Assembly out
  • Optimisations
    • Canonicalisation
    • Global value numbering
    • Lock coarsening
  • Practicalities
    • Register allocation
    • Scheduling
  • What can you use Graal for?
    • A final-tier compiler
    • Your own specific optimisations
    • Ahead-of-time compilation
    • Truffle
  • Summary
III. Talk 2 Compiler: Directives

Walk-thru Talk 2 Compiler demo project:

  • Use CallTarget & RootNode to enter partial evaluation mode
  • Use mvn test -Pigv to send graphs to IGV
  • Install maven modules to IGV to show connection between graph and source
  • Follow the README:
    • warmWelcome
    • transferToInterpreter
    • Rewrite to use profiles
  • Show how to write own language
IV. Talk 2 Compiler: Assumptions & Caches
V. Talk 2 Compiler: Nodes & Specializations
VI. Memory Management
  • Garbage Collector
  • VirtualFrame
    • Descriptor
  • DynamicObject
    • Shape
VII. Graal Self
VIII. JIT vs. AOT compilation
IX. Interop between languages
X. Tools & Instruments
  • Making your language “toolable”
    • Source section
    • Tags
    • Show how to debug in NetBeans
  • Writing an instrument
    • Debugger, profiler, code coverage, language server protocol, NetBeans
  • node.js
    • Mixing Java and JavaScript & co.
XI. Static Languages with LLVM
  • Sulong — interpreting C, Rust, etc.
  • Truffle NFI
XII. Writing bytecode interpreter
  • Espresso - Java interpreter
  • Sulong - bitcode interpreter
XIII. Real Language Problems
  • implementing FFI for languages such as Ruby/Python/R
  • yield in JavaScript
  • lazy evaluation in R
Appendix A: Contributing To Open Source
  • Overview of the repositories
  • Python, JavaScriptem, Ruby, FastR, Espresso
  • mx tooling
  • Signing OCA