GraalVM High-Performance Polyglot Runtime and Compiler

repository·master·Indexed 12 days ago

https://github.com/oracle/graal

A high-performance polyglot runtime and compiler that optimizes applications into standalone binaries with instant startup and low resource usage. Includes the Graal compiler, Native Image for ahead-of-time (AOT) compilation, the Truffle language implementation framework, and Espresso (Java on Truffle) for running Java bytecode in isolated contexts or alongside other GraalVM languages.

Tokens
379.8K
Snippets
1.1K
Records
1.6K
Agent score
94%

What's inside GraalVM

  1. Introduction to the Bytecode DSL

    master

    The Bytecode DSL is an experimental feature in Truffle designed to automate the generation of bytecode interpreters. It abstracts away low-level details such as bytecode encoding, control flow, and quickening, allowing developers to focus solely on implementing language-specific semantics using 'operations'.

    Bytecode interpreters are preferred over standard Truffle AST interpreters when:

    • Memory footprint is a concern: AST nodes and their state (like @Cached parameters) can be memory-intensive. Bytecode is a more compact program representation.
    • Interpreted performance needs improvement: Bytecode allows for techniques like quickening, superinstructions, host compilation, and template compilation to optimize execution before the code is hot enough for runtime compilation.
  2. Overview of GraalVM SDK modules

    master

    The GraalVM SDK consists of several specialized API collections:

    • org.graalvm.nativeimage: Public API for advanced Native Image use cases.
    • org.graalvm.polyglot: Library for embedding polyglot language implementations in Java.
    • org.graalvm.word: Low-level library for machine-word-sized values in Java.
    • org.graalvm.collections: Collections library designed for GraalVM components.
  3. Overview of the Native Bridge Annotation Processor

    master

    The Native Bridge annotation processor automates the generation of code to facilitate communication between disjoint JVM runtimes, such as between a Native Image and a HotSpot VM, or across different OS processes. It generates stubs that use JNI or UNIX domain sockets to call foreign methods.

    It supports bridging:

    • Interfaces
    • Classes
    • Classes with custom dispatch

    Supported data types include Java primitives, String, foreign reference types, arrays, and custom types (via user-defined marshallers).

  4. Overview of GraalVM Insight

    master

    GraalVM Insight (Insight) is a multipurpose, flexible tracing and instrumentation platform designed to reduce the effort of building reliable microservices. It allows developers to dynamically apply complex insights and hooks to already deployed applications running at full speed without altering the original source code.

    Key capabilities include:

    • Dynamic Instrumentation: Apply tracing to scripts (e.g., Node.js, Ruby on Rails, Python) without code modification.
    • Language Agnostic: Works with any language implemented using the Truffle framework, including static native languages like C, C++, and Rust.
    • Aspect-Oriented Programming: Enables inspecting values, types at invocation/allocation sites, modifying computed values, and interrupting execution.
    • High Performance: Insights are automatically blended into the application code, ensuring no performance loss compared to manually instrumented code.
  5. Introduction to profdiff

    master

    mx profdiff is a tool used to display and compare optimization and inlining decisions in Java application compilations. It utilizes tree-diffing algorithms to find differences between the hottest compilation units (consisting of an inlining tree and an optimization tree).

    Key Capabilities:

    • Compare JIT vs JIT: Compare two profiled JIT experiments.
    • Compare JIT vs AOT: Compare a profiled JIT experiment with an AOT experiment.
    • Compare AOT vs AOT: Compare two profiled AOT experiments.
    • Compare Replayed Recordings: Compare optimization logs from replay compilations by matching compilation IDs (useful for isolating compiler patch impacts).

    Prerequisites: To use profdiff, you must enable the optimization log in your application.

    • For JIT: Use the flag -Djdk.graal.OptimizationLog=Directory.
    • For Native Image (AOT): Use the flag -H:OptimizationLog=Directory.
  6. What is Sulong?

    master
    Sulong is a high-performance LLVM bitcode runtime built on GraalVM. It is implemented using the Truffle language implementation framework and uses Graal as a dynamic compiler. Sulong allows you to execute programming languages that can be transformed into LLVM bitcode (such as C, C++, and Fortran) directly on GraalVM.
  7. Overview of GraalVM tools for polyglot applications

    master
    GraalVM provides a specialized set of tools designed to debug, monitor, and analyze polyglot applications (applications running multiple languages). Traditional debugging tools often fail to diagnose cross-language interactions, whereas GraalVM tools are built to inspect single or multi-language applications through various interfaces including debugging clients, profiling, statement counting, and dynamic analysis.
  8. Overview of Oracle GraalVM benefits

    master

    Oracle GraalVM is designed to accelerate application performance and reduce resource consumption by compiling Java applications ahead of time (AOT) into native binaries.

    Key advantages include:

    • Low Resource Usage: Reduces memory and CPU requirements by eliminating the need for just-in-time (JIT) compilation at runtime.
    • Fast Startup: Achieves up to 100x faster startup by initializing parts of the application at build time and providing immediate peak performance without a warmup period.
    • Compact Packaging: Produces small binaries suitable for lightweight container images.
    • Improved Security: Reduces attack surface by excluding unreachable code and JIT infrastructure. It operates under a 'closed world assumption', requiring explicit configuration for dynamic features like reflection and serialization. It also supports embedding a Software Bill of Materials (SBOM) for CVE scanning.
    • Cloud Native Support: Compatible with microservices frameworks (Micronaut, Spring Boot, Helidon, Quarkus) and major cloud providers (OCI, AWS, GCP, Azure).
    • Polyglot Capabilities: Allows embedding other languages like Python and JavaScript within Java applications.
    • Tooling Compatibility: Supports standard Java tools including Maven and Gradle plugins, GitHub Actions, Java Flight Recorder (JFR), JMX, VisualVM, and JUnit.
  9. Overview of GraalVM benefits

    master

    GraalVM is a high-performance runtime that compiles Java applications ahead-of-time (AOT) into standalone binaries. Key benefits include:

    • Low Resource Usage: Reduces memory and CPU consumption by eliminating the need for just-in-time (JIT) compilation at runtime.
    • Improved Security: Reduces attack surface by excluding unreachable code and JIT infrastructure. It operates under a closed world assumption, meaning dynamic features like reflection and serialization must be explicitly included at build time. It also supports embedding a Software Bill of Materials (SBOM) for CVE scanning.
    • Fast Startup: Enables instant startup and predictable peak performance by performing application initialization at build time.
    • Compact Packaging: Produces small binaries suitable for lightweight container images.
    • Cloud Native Support: Compatible with microservices frameworks (Spring Boot, Micronaut, Helidon, Quarkus) and major cloud platforms (OCI, AWS, GCP, Azure).
    • Polyglot Capabilities: Allows embedding other languages like Python and JavaScript within Java applications.
    • Tooling Compatibility: Works with standard Java tools including Maven, Gradle, GitHub Actions, JFR, JMX, VisualVM, and JUnit.
  10. Overview of Espresso (Java on Truffle)

    master

    Espresso is a complete JVM implementation written in Java using the Truffle framework. It is designed to run on GraalVM and provides a high-performance environment for executing Java bytecode.

    Key capabilities include:

    • Sandboxing: Run Java code within isolated contexts using GraalVM's polyglot sandboxing features.
    • Advanced Hotswap: Provides more comprehensive hotswap support than HotSpot, allowing for easier code patching during runtime via IDE recompilation. Applications can react to HotSwap events to adjust internal state.
    • Native Image Integration: Enables the dynamic loading and execution of Java code from within an ahead-of-time (AOT) compiled native image.
    • Version Isolation: Allows running code that requires older Java versions on a newer host JVM by isolating the execution environment.
  11. Introduction to GraalVM

    master

    GraalVM is a high-performance runtime that accelerates Java applications by compiling them ahead-of-time (AOT) into native binaries. This process results in applications that start up to 100x faster, use significantly less memory and CPU, and provide peak performance immediately without the typical JVM warmup period.

    Key capabilities include:

    • Native Image Compilation: Compiles Java code into small, compact native binaries suitable for lightweight container images.
    • Polyglot Programming: Allows embedding and running multiple languages (such as Python and JavaScript) within a Java application.
    • Cloud Native Optimization: Designed for microservices frameworks (Micronaut, Spring Boot, Helidon, Quarkus) and major cloud platforms (OCI, AWS, GCP, Azure).
    • Security Enhancements: Reduces attack surface by excluding unreachable code and disabling dynamic features (reflection, serialization) unless explicitly included at build time via a 'closed world assumption'.
  12. Available GraalVM Native Image Guides

    master

    GraalVM provides a comprehensive set of guides for working with Native Image. These guides cover building, optimizing, debugging, and deploying native executables.

    Core Build Tasks

    • Build a Native Executable from a JAR File
    • Build a Native Shared Library
    • Build a Polyglot Native Executable (Java and JavaScript)
    • Build a Static or Mostly-Static Native Executable
    • Build Java Modules into a Native Executable
    • Include Resources in a Native Executable
    • Specify Class Initialization Explicitly

    Optimization and Configuration

    • Configure Native Image with the Tracing Agent (for reflection/dynamic features)
    • Optimize a Native Executable with Profile-Guided Optimization (PGO)
    • Optimize a Native Executable for File Size
    • Optimize Size of a Native Executable using Build Reports
    • Optimize Memory Footprint of a Native Executable
    • Include Reachability Metadata using Maven or Gradle plugins
    • Embed an SBOM to identify dependencies

    Debugging and Observability

    • Add Logging to a Native Executable
    • Build and Run Native Executables with JFR (Java Flight Recorder)
    • Build and Run Native Executables with Remote JMX
    • Create a Heap Dump from a Native Executable
    • Debug Native Executables with GDB
    • Debug Native Executables with a Python Helper Script
    • Debug Native Tests in Maven and Gradle Projects

    Deployment and Tooling

    • Containerize a Native Executable and Run in a Docker Container
    • Use Gradle or Maven to build native executables from Java applications
    • Access Environment Variables in native code