### Install Rust Source: https://github.com/oracle/graal/blob/master/docs/reference-manual/llvm/Compiling.md Installs Rust using the official installer script. Follow the on-screen instructions for completion. ```shell curl https://sh.rustup.rs -sSf | sh ``` -------------------------------- ### Full Kotlin DSL Example Source: https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/assets/skills/build-native-image-gradle/references/native-image-build-gradle-options.md A comprehensive example demonstrating various GraalVM native image build configurations using the Kotlin DSL. ```kotlin graalvmNative { binaries { named("main") { imageName.set("myapp") mainClass.set("com.example.Main") verbose.set(true) buildArgs.addAll( "--initialize-at-run-time=com.example.Lazy", "-H:IncludeResources=.*\\.properties$", "-O3" ) jvmArgs.add("-Xmx8g") } named("test") { imageName.set("myapp-tests") } } } ``` -------------------------------- ### Configure Installation Prefix and Compile Options Source: https://github.com/oracle/graal/blob/master/sulong/projects/com.oracle.truffle.llvm.libraries.native/CMakeLists.txt Sets the installation directory and applies compile-time path mapping options to standardize source paths in the build. ```cmake set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR}) add_compile_options(-ffile-prefix-map=${CMAKE_SOURCE_DIR}=${CMAKE_PROJECT_NAME}) add_compile_options(-ffile-prefix-map=${CMAKE_BINARY_DIR}=${CMAKE_PROJECT_NAME}) add_compile_options(-ffile-prefix-map=${TRUFFLE_NFI_NATIVE_INCLUDE}=TRUFFLE_NFI_NATIVE/include) ``` -------------------------------- ### Native Image Build Configuration Example Source: https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/guides/specify-class-initialization.md Example of using the --initialize-at-build-time option for GraalVM Native Image. It is recommended to use this option with single classes only. ```bash --initialize-at-build-time ``` -------------------------------- ### Full Groovy DSL Example Source: https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/assets/skills/build-native-image-gradle/references/native-image-build-gradle-options.md A comprehensive example demonstrating various GraalVM native image build configurations using the Groovy DSL. ```groovy graalvmNative { binaries { main { imageName = 'myapp' mainClass = 'com.example.Main' verbose = true buildArgs.addAll( '--initialize-at-run-time=com.example.Lazy', '-H:IncludeResources=.*\.properties$', '-O3' ) jvmArgs.add('-Xmx8g') } test { imageName = 'myapp-tests' } all { javaLauncher = javaToolchains.launcherFor { languageVersion.set(JavaLanguageVersion.of(21)) } } } } ``` -------------------------------- ### Install Linux Prerequisites with Apt-Get Source: https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/README.md Installs necessary build tools and libraries for Native Image on Ubuntu Linux using the `apt-get` package manager. ```shell sudo apt-get install build-essential zlib1g-dev ``` -------------------------------- ### Install perf on Debian/Ubuntu Source: https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/PerfProfiling.md Use these commands to install the perf profiler on systems using apt package manager. ```bash sudo apt update sudo apt install linux-tools-common linux-tools-generic ``` -------------------------------- ### Install MX Build Tool Source: https://github.com/oracle/graal/blob/master/truffle/README.md Commands to clone the MX build tool repository and install it. Ensure MX is on your PATH for subsequent commands. ```bash $ git clone https://github.com/graalvm/mx.git/ $ mx/mx ``` -------------------------------- ### Get JDWP Options Help Source: https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/JDWP.md Run your native image with -XX:JDWPOptions=help to get a list of supported JDWP options for Native Image. ```shell ./your-application -XX:JDWPOptions=help ``` -------------------------------- ### Install and Activate Emscripten SDK Source: https://github.com/oracle/graal/blob/master/wasm/docs/contributor/TestsAndBenchmarks.md Steps to install and activate a specific version of the Emscripten SDK. This is required for building additional tests and benchmarks written in C. ```bash $ cd [preferred emsdk install location] # Clone repository $ git clone https://github.com/emscripten-core/emsdk.git # Move to folder $ cd emsdk # Install sdk $ ./emsdk install [version number] # Activate sdk $ ./emsdk activate [version number] # Set up environment $ source ./emsdk_env.sh ``` -------------------------------- ### Install GraalVM JDK with SDKMAN! Source: https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/guides/build-spring-boot-application-aot.md Install a GraalVM JDK using SDKMAN! for building native executables on a host machine. Replace the version number as needed. ```bash sdk install java 21.0.4-graal ``` -------------------------------- ### Method Expansion Trace Example Source: https://github.com/oracle/graal/blob/master/truffle/docs/Optimizing.md An example output of the method expansion trace, detailing frequency, counts, sizes, cycles, and source locations for compiled methods. ```text [engine] Expansion tree for test after truffleTier: Name Frequency | Count Size Cycles Ifs Loops Invokes Allocs | Self Count Size Cycles Ifs Loops Invokes Allocs | IRNode ASTNode Lang:File:Line:Chars 1.00 | 64 72 42 1 1 0 1 | 34 20 0 0 0 0 0 | - OptimizedCallTarget.profiledPERoot(Object) 1.00 | 30 52 42 1 1 0 1 | 1 2 2 0 0 0 0 | 121 OptimizedCallTarget.injectArgumentsProfile(Object) 1.00 | 9 19 16 0 0 0 0 | 4 3 0 0 0 0 0 | 5 OptimizedCallTarget.unsafeCast(Object, Class, Z, Z, Z) 1.00 | 1 0 0 0 0 0 0 | 1 0 0 0 0 0 0 | 10 OptimizedCallTarget.castArgumentsImpl(Object, Class) 1.00 | 4 16 16 0 0 0 0 | 4 16 16 0 0 0 0 | 12 OptimizedCallTarget.executeRootNode(VirtualFrame) 1.00 | 20 31 24 1 1 0 1 | 0 0 0 0 0 0 0 | JavaScriptRealmBoundaryRootNode.execute(VirtualFrame) 1.00 | 20 31 24 1 1 0 1 | 1 1 0 0 0 0 0 | 34 0 js:test.js:1:0-100 JavaScriptRealmBoundaryRootNode.getRealm() 1.00 | 1 1 0 0 0 0 0 | 0 0 0 0 0 0 0 | 34 0 js:test.js:1:0-100 JSContext.getRealm() 1.00 | 1 1 0 0 0 0 0 | 0 0 0 0 0 0 0 | PolyglotReferences$AssumeSingleContext.get() 1.00 | 1 1 0 0 0 0 0 | 0 0 0 0 0 0 0 | PolyglotReferences$WeakSingleContext.get() 1.00 | 1 1 0 0 0 0 0 | 1 1 0 0 0 0 0 | 37 FunctionRootNode.executeInRealm(VirtualFrame) 1.00 | 18 29 24 1 1 0 1 | 1 1 0 0 0 0 0 | 41 0 js:test.js:1:0-100 ``` -------------------------------- ### Set up mx and Graal Repositories Source: https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/contribute/DevelopingNativeImage.md Clone the mx build system and the graal repository. Ensure they are sibling directories for proper project structure. ```shell workspace |- mx |- graal |- graal-js (optional) |- graalpython (optional) |- ... ``` -------------------------------- ### Implement SequenceArray Interface Source: https://github.com/oracle/graal/blob/master/truffle/docs/TruffleLibraries.md Implements the Array interface for a sequence of numbers defined by a start, stride, and length. Requires setup for start, stride, and length fields. ```java final class SequenceArray implements Array { private final int start; private final int stride; private final int length; /*...*/ @Override public int read(int index) { return start + (stride * index); } } ``` -------------------------------- ### Get GraalVM Home Directory Source: https://github.com/oracle/graal/blob/master/vm/README.md Retrieve the path to the GraalVM installation directory after a successful build. ```bash mx --env ce graalvm-home ``` -------------------------------- ### Run Native Application (Build-Time Initialization) Source: https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/guides/specify-class-initialization.md Run the second native executable and time its execution. Compare this with the run-time initialization version to observe performance differences. ```bash time ./buildtime-parser ``` -------------------------------- ### Run GraalVM Native Image Container Source: https://github.com/oracle/graal/blob/master/docs/getting-started/container-images/graalvm-ce-container-images.md Start a container from the GraalVM native-image image and enter a Bash session to verify the installation and versions. ```bash docker run -it --rm --entrypoint /bin/bash ghcr.io/graalvm/native-image-community:25 ``` -------------------------------- ### Clone GraalVM Demos Repository Source: https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/guides/containerise-native-executable-with-docker.md Clone the repository containing the Spring Boot 3 Native Image Microservice example. This is a prerequisite for the guide. ```shell git clone https://github.com/graalvm/graalvm-demos.git ``` -------------------------------- ### Get LLVM Toolchain Path Source: https://github.com/oracle/graal/blob/master/docs/reference-manual/llvm/Compiling.md Retrieve the installation path of the LLVM toolchain provided by GraalVM. This path is needed to access compilers and other build tools. ```shell ./path/to/bin/lli --print-toolchain-path ``` -------------------------------- ### GDB Output After Hitting Breakpoint Source: https://github.com/oracle/graal/blob/master/substratevm/src/com.oracle.svm.agent/README.md Example output from GDB after the process starts and hits the specified breakpoint. This shows the thread information and the function where execution is paused. ```text Starting program: java -agentlib:native-image-agent=config-output-dir=./native-image-config -jar app.jar [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib64/libthread_db.so.1". [Switching to Thread 0x7ffff67ff6c0 (LWP 50250)] Thread 2 "java" hit Breakpoint 2, com.oracle.svm.agent.NativeImageAgent::onLoadCallback(com.oracle.svm.core.jni.headers.JNIJavaVM, com.oracle.svm.jvmtiagentbase.jvmti.JvmtiEnv, com.oracle.svm.jvmtiagentbase.jvmti.JvmtiEventCallbacks, java.lang.String*) (this=0x7fffe4e5b6f0, vm=0x7ffff7be8fa0 , jvmti=, callbacks=, options=) at com/oracle/svm/agent/NativeImageAgent.java:134 ``` -------------------------------- ### Advanced Bundle Apply and Create Example Source: https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/Bundles.md This example demonstrates how to create a new bundle (`app_dbg.nib`) based on an existing bundle (`app.nib`), incorporating additional arguments like `-g` for debugging. ```shell native-image --bundle-apply=app.nib --bundle-create=app_dbg.nib -g ``` -------------------------------- ### Filter Gate Tasks by Name Prefix Source: https://github.com/oracle/graal/blob/master/sulong/docs/contributor/TESTS.md Use the `--task-filter` option to narrow down the tasks to be displayed or executed. This example shows how to list only Sulong-specific tasks that start with 'Test'. ```bash mx gate --summary --dry-run -t Test ``` -------------------------------- ### Navigate to Demo Directory Source: https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/guides/containerise-native-executable-with-docker.md Change the current directory to the Spring Boot microservice example within the cloned repository. This sets up the environment for building. ```shell cd graalvm-demos/native-image/spring-boot-microservice-jibber ``` -------------------------------- ### EvenOrOddLength Java Program Example Source: https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/PGO-IprofFileFormat.md A simple Java program used to illustrate call graphs and partial calling contexts. No specific setup is required beyond a standard Java environment. ```java public class EvenOrOddLength { public static void main(String[] args) { printEvenOrOdd(args[0]); } private static void printEvenOrOdd(String s) { if (s.length() % 2 == 0) { printEven(); } else { printOdd(); } } private static void printEven() { print("even"); } private static void printOdd() { print("odd"); } private static void print(String s) { System.out.println(s); } } ``` -------------------------------- ### Navigate to Sample Application Directory Source: https://github.com/oracle/graal/blob/master/docs/getting-started/oci/code-editor.md Changes the current directory to the specific sample application folder within the cloned repository. ```bash cd java-samples/graalvmee-java-hello-world/ ``` -------------------------------- ### Add Truffle as Maven Dependency Source: https://github.com/oracle/graal/blob/master/truffle/README.md Example Maven POM configuration to include Truffle API and DSL processor as project dependencies. Ensure the version matches the one installed by `mx maven-install`. ```xml org.graalvm.truffle truffle-api 25.0.0 org.graalvm.truffle truffle-dsl-processor 25.0.0 provided ``` -------------------------------- ### Basic NFI Usage Example Source: https://github.com/oracle/graal/blob/master/truffle/docs/NFI.md Demonstrates loading a library, accessing a symbol, defining a signature, binding the symbol, and calling the function. Ensure the 'libSDL2.dylib' library is accessible. ```ruby library = Polyglot.eval('nfi', 'load "libSDL2.dylib"') symbol = library['SDL_GetRevisionNumber'] signature = Polyglot.eval('nfi', '():UINT32') function = signature.bind(symbol) puts function.call ``` -------------------------------- ### Runtime Logging Initialization Example Source: https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/guides/add-logging-to-native-executable.md This Java code demonstrates how to initialize logging at runtime by reading a configuration file. Ensure the logging.properties file is included for runtime processing. ```java import java.io.IOException; import java.util.logging.Level; import java.util.logging.LogManager; import java.util.logging.Logger; public class LoggerRunTimeInit { public static void main(String[] args) throws IOException { LogManager.getLogManager().readConfiguration(LoggerRunTimeInit.class.getResourceAsStream("/logging.properties")); Logger logger = Logger.getLogger(LoggerRunTimeInit.class.getName()); logger.log(Level.WARNING, "Danger, Will Robinson!"); } } ``` ```bash javac LoggerRunTimeInit.java ``` ```shell native-image LoggerRunTimeInit -H:IncludeResources="logging.properties" ``` ```shell ./loggerruntimeinit ``` -------------------------------- ### Verify GraalVM Native Image Container Source: https://github.com/oracle/graal/blob/master/docs/getting-started/container-images/oracle-graalvm-container-images.md Start a container and enter a Bash session to verify the installation. Use the `env` command to check JAVA_HOME, `java -version` for the JDK version, and `native-image --version` for the native-image utility version. ```bash docker run -it --rm --entrypoint /bin/bash container-registry.oracle.com/graalvm/native-image:25 ``` ```bash env ``` ```bash java -version ``` ```bash native-image --version ``` -------------------------------- ### Run HelloWorld on Espresso² Source: https://github.com/oracle/graal/blob/master/espresso/docs/hacking.md Execute the HelloWorld program on Espresso² using `mx espresso-meta`. Prepend `LD_DEBUG=unused` to address a glibc bug. ```bash $ LD_DEBUG=unused mx --dy /compiler espresso-meta -cp my.jar HelloWorld ``` -------------------------------- ### Install Sulong Target Source: https://github.com/oracle/graal/blob/master/sulong/projects/com.oracle.truffle.llvm.libraries.bitcode/CMakeLists.txt Installs the 'sulong' shared library to the 'bin' directory within the installation prefix. ```cmake install(TARGETS sulong DESTINATION bin) ``` -------------------------------- ### Full Native Maven Plugin Configuration Example Source: https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/assets/skills/build-native-image-maven/references/maven-plugin-options.md An example of a complete `native-maven-plugin` configuration, including image name, main class, verbose output, build arguments, and JVM arguments. ```xml org.graalvm.buildtools native-maven-plugin 0.11.1 true build-native compile-no-fork package myapp com.example.Main true --initialize-at-run-time=com.example.Lazy -H:IncludeResources=.*\.properties$ -O2 -Xmx8g ``` -------------------------------- ### Install sulong++ Target Source: https://github.com/oracle/graal/blob/master/sulong/projects/com.oracle.truffle.llvm.libraries.bitcode/CMakeLists.txt Installs the sulong++ target to the bin directory. This makes the compiled library accessible after installation. ```cmake install(TARGETS sulong++ DESTINATION bin) ``` -------------------------------- ### ClassNotFoundException Example Source: https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/guides/build-with-reflection.md An example of the exception encountered when a class is not included in the native-image configuration. ```text Exception in thread "main" java.lang.ClassNotFoundException: StringCapitalizer at org.graalvm.nativeimage.builder/com.oracle.svm.core.hub.ClassForNameSupport.forName(ClassForNameSupport.java:190) ... at ReflectionExample.main(ReflectionExample.java:68) ``` -------------------------------- ### Compile and Run HelloWorld on JVM Source: https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/NativeImageBasics.md Standard Java compilation and execution commands for the HelloWorld example. ```bash javac HelloWorld.java java HelloWorld ``` -------------------------------- ### Initialize Git Repository for Demo Project Source: https://github.com/oracle/graal/blob/master/docs/getting-started/oci/code-editor.md Initializes a new Git repository for the GraalVM demo project. ```bash git init graalvmee-java-hello-world ``` -------------------------------- ### Install Sulong Native Library Source: https://github.com/oracle/graal/blob/master/sulong/projects/com.oracle.truffle.llvm.libraries.native/CMakeLists.txt Configures the installation of the 'sulong-native' target into the 'bin' directory. ```cmake install(TARGETS sulong-native DESTINATION bin) ``` -------------------------------- ### Check mx Installation Source: https://github.com/oracle/graal/blob/master/docs/graalvm-as-a-platform/implement-language.md Verify that the mx tool has been installed successfully by checking its version. ```shell mx --version ``` -------------------------------- ### Navigate to Demo Directory Source: https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/guides/build-java-module-app-aot.md Change the current directory to the build-java-modules example within the GraalVM demos. ```bash cd graalvm-demos/native-image/build-java-modules ``` -------------------------------- ### Fetch and Set Up Compatible JDK Source: https://github.com/oracle/graal/blob/master/compiler/README.md Fetch a compatible JDK for GraalVM development and follow the emitted instructions to set the JAVA_HOME environment variable. ```bash mx fetch-jdk labsjdk-ce-latest ``` -------------------------------- ### Install Jaeger Client Source: https://github.com/oracle/graal/blob/master/docs/tools/insight/Insight-Tracing.md Install the Jaeger client-side instrumentation library for Node.js using npm. ```bash ./bin/npm install jaeger-client@3.17.1 ``` -------------------------------- ### Compile Java Example Source: https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/guides/build-with-reflection.md Compiles the `ReflectionExample.java` file using the Java compiler. ```shell javac ReflectionExample.java ``` -------------------------------- ### Getting Engine Scope Attribute Source: https://github.com/oracle/graal/blob/master/docs/reference-manual/embedding/embed-languages.md A convenience method to get an attribute from the engine scope by default. ```java @Override public Object getAttribute(String name) { return getAttribute(name, ScriptContext.ENGINE_SCOPE); } ``` -------------------------------- ### Install GraalVM on Oracle Linux 7 Source: https://github.com/oracle/graal/blob/master/docs/getting-started/oci/installation-compute-instance-with-OL.md Steps to install a newer devtoolset, enable it, and then install Oracle GraalVM 25 using yum on Oracle Linux 7. A new bash session is required after enabling the devtoolset. ```bash sudo yum -y install oracle-softwarecollection-release-el7 ``` ```bash sudo yum install devtoolset-10 ``` ```bash echo 'source scl_source enable devtoolset-10' >> ~/.bashrc ``` ```bash bash ``` ```bash sudo yum install graalvm-25-native-image ``` -------------------------------- ### GraalVM Image Builder Command Line Example Source: https://github.com/oracle/graal/blob/master/substratevm/docs/module-system/ModuleSystemSupportHosted.md A verbose output from the native-image driver showing the constructed Java command line, including multiple --add-exports arguments. ```text Executing [ HOME=/home/graaluser \ LANG=en_US.UTF-8 \ PATH=/home/graaluser/OLabs/jdk-21/bin:/home/graaluser/OLabs/main/mx:/home/graaluser/.sdkman/candidates/java/current/bin:/home/graaluser/.sdkman/candidates/gradle/current/bin:/home/graaluser/.local/bin:/home/graaluser/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin \ PWD=/home/graaluser/OLabs/main/graal-enterprise/substratevm-enterprise/spring-boot-3_2-graalvm-21-native-image-bug/mvn \ /home/graaluser/OLabs/main/graal/sdk/mxbuild/linux-amd64/GRAALVM_427B7851E4_JAVA21/graalvm-427b7851e4-java21-24.0.0-dev/bin/java \ -XX:+UseParallelGC \ -XX:+UnlockExperimentalVMOptions \ -XX:+EnableJVMCI \ -Dtruffle.TrustAllTruffleRuntimeProviders=true \ -Dtruffle.TruffleRuntime=com.oracle.truffle.api.impl.DefaultTruffleRuntime \ -Dgraalvm.ForcePolyglotInvalid=true \ -Dgraalvm.locatorDisabled=true \ -Dsubstratevm.HostLibC=glibc \ -Dsubstratevm.IgnoreGraalVersionCheck=true \ --add-exports=java.base/com.sun.crypto.provider=org.graalvm.nativeimage.builder \ --add-exports=java.base/jdk.internal.access=org.graalvm.nativeimage.builder \ --add-exports=java.base/jdk.internal.event=org.graalvm.nativeimage.builder \ --add-exports=java.base/jdk.internal.loader=org.graalvm.nativeimage.builder \ --add-exports=java.base/jdk.internal.logger=org.graalvm.nativeimage.builder \ --add-exports=java.base/jdk.internal.misc=com.oracle.svm.svm_enterprise,org.graalvm.nativeimage.builder,org.graalvm.nativeimage.objectfile,org.graalvm.nativeimage.pointsto \ --add-exports=java.base/jdk.internal.module=org.graalvm.nativeimage.base,org.graalvm.nativeimage.builder \ ... ``` -------------------------------- ### AddAbsNode Example without Inlining Source: https://github.com/oracle/graal/blob/master/truffle/docs/DSLNodeObjectInlining.md This example demonstrates the AddAbsNode without any inlining, serving as a baseline for comparison. ```Java @GenerateInline @GenerateCached(false) public abstract static class AddAbsNode extends Node { abstract long execute(Node node, long left, long right); @Specialization static long add(Node node, long left, long right, @Cached AbsNode leftAbs, @Cached AbsNode rightAbs) { return leftAbs.execute(node, left) + rightAbs.execute(node, right); } // ... ``` -------------------------------- ### Directly Implementing Addition with InteropLibrary Source: https://github.com/oracle/graal/blob/master/truffle/docs/InteropMigration.md This example shows the recommended way to implement an operation like addition by directly using InteropLibrary messages to check types and perform conversions. This avoids the need to emulate older messages and leads to more efficient code. ```java @Specialization(guards = { "leftValues.fitsInLong(l)", "rightValues.fitsInLong(r)"}, limit="5") long doAdd(Object l, Object r, @CachedLibrary("l") InteropLibrary leftValues, @CachedLibrary("r") InteropLibrary rightValues) { return leftValues.asLong(l) + rightValues.asLong(r); } ``` -------------------------------- ### Separate Process Usage Example Source: https://github.com/oracle/graal/blob/master/compiler/docs/NativeBridgeProcessor.md Example of obtaining and using a bridged calculator in a separate process environment. ```java Builder builder = ProcessIsolateConfig.newInitiatorBuilder(isolateLauncher, hostSocket); builder.launcherArgument(isolateLibrary); builder.launcherArgument(hostSocket); ProcessIsolateConfig config = builder.build(); ForeignCalculator calculator = ForeignCalculatorFactoryGen.create(config); calculator.add(calculator.sub(41, 2), 1); ``` -------------------------------- ### Native Image Usage Example Source: https://github.com/oracle/graal/blob/master/compiler/docs/NativeBridgeProcessor.md Example of obtaining and using a bridged calculator in a Native Image environment. ```java NativeIsolateConfig config = NativeIsolateConfig.newBuilder(isolateLibrary).build(); ForeignCalculator calculator = ForeignCalculatorFactoryGen.create(config); calculator.add(calculator.sub(41, 2), 1); ``` -------------------------------- ### Run Native Image HelloWorld Source: https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/NativeImageBasics.md Command to execute the native executable built from HelloWorld. ```bash ./helloworld ``` -------------------------------- ### Print Help Message Source: https://github.com/oracle/graal/blob/master/substratevm/src/com.oracle.svm.driver.launcher/resources/com/oracle/svm/driver/launcher/BundleLauncherHelp.txt Prints the help message for the Native Image Bundle launcher. ```bash --help ``` -------------------------------- ### Set Installation Prefix Source: https://github.com/oracle/graal/blob/master/sulong/projects/com.oracle.truffle.llvm.libraries.bitcode/CMakeLists.txt Configures the installation directory for the build artifacts. By default, it's set to the binary directory. ```cmake set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR}) ``` -------------------------------- ### Command with VM Options and Arguments Source: https://github.com/oracle/graal/blob/master/sdk/mx.sdk/vm/windows.md Shows how additional VM options and application arguments are appended to the base command. Classpath is extended with provided values. ```bash "BASEDIR\\java" -Dorg.graalvm.launcher.shell=true "-Dorg.graalvm.launcher.executablename=BASEDIR\test.cmd" -fooy -cp "BASEDIR\a;BASEDIR\b;BASEDIR\c;bar;baz" foox ``` -------------------------------- ### Install SimpleLanguage Component Source: https://github.com/oracle/graal/blob/master/docs/graalvm-as-a-platform/implement-language.md Install the SimpleLanguage component into GraalVM using the GraalVM Updater tool after building the sl-component.jar. ```shell gu -L install /path/to/sl-component.jar ``` -------------------------------- ### Node.js Application Example Source: https://github.com/oracle/graal/blob/master/docs/tools/dap.md A simple Node.js application using the Express framework. This is used as an example for debugging with DAP. ```javascript const express = require('express') const app = express() const port = 3000 app.get('/', (req, res) => { res.send('Hello World!') }) app.get('/neverCalled', (req, res) => { res.send('You should not be here') }) app.get('/shutdown', (req, res) => { process.exit(); }) app.listen(port, () => console.log(`Example app listening on port ${port}!`)) ``` -------------------------------- ### Display Native Image Build Help Source: https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/README.md Command to display the full list of available options for configuring the native-image build process. This is useful for understanding all customization possibilities. ```shell native-image --help ``` -------------------------------- ### Graal Diagnostic Output Example Source: https://github.com/oracle/graal/blob/master/docs/reference-manual/java/Options.md Example of the console output when Graal diagnostics are enabled due to a compilation failure. ```text Graal diagnostic output saved in /Users/graal/graal_dumps/1549459528316/graal_diagnostics_22774.zip ``` -------------------------------- ### Running a JavaScript Example with Simple Tool Enabled Source: https://github.com/oracle/graal/blob/master/docs/graalvm-as-a-platform/implement-instrument.md Launches the GraalVM 'js' interpreter, adds a custom tool to the Truffle framework classpath, and executes a JavaScript file with the tool enabled. Ensure the tool's JAR is correctly specified in the classpath. ```bash ./simpletool js example.js ``` -------------------------------- ### Optimization Tree Matching Example (Insertion and Differences) Source: https://github.com/oracle/graal/blob/master/compiler/docs/Profdiff.md Demonstrates differences in optimization phases, specifically showing a CanonicalizerPhase with different CanonicalReplacement operations between two compilations. ```text . CanonicalizerPhase - Canonicalizer CanonicalReplacement at bci 6 {replacedNodeClass: ValuePhi, canonicalNodeClass: Constant} - Canonicalizer CanonicalReplacement at bci 9 {replacedNodeClass: ValuePhi, canonicalNodeClass: Constant} + Canonicalizer CanonicalReplacement at bci 6 {replacedNodeClass: Pi, canonicalNodeClass: Pi} ``` -------------------------------- ### JShell Interaction Example Source: https://github.com/oracle/graal/blob/master/docs/reference-manual/java-on-truffle/Demos.md An example of interacting with the JShell environment after launching it with Espresso. Demonstrates a simple arithmetic operation. ```shell jshell> 1 + 1 1 ==> 2 ``` -------------------------------- ### Initialize IntelliJ project files with mx Source: https://github.com/oracle/graal/blob/master/sulong/docs/contributor/FAQ.md Generate IntelliJ project files for Sulong development by running the `mx intellijinit` command. ```bash mx intellijinit ``` -------------------------------- ### Example Bytecode Transition Tracing Output Source: https://github.com/oracle/graal/blob/master/truffle/docs/Optimizing.md This is an example of the output generated when `--engine.TraceBytecodeTransition=transferToInterpreter` is enabled, detailing on-stack transitions. ```text # --engine.TraceBytecodeTransition=transferToInterpreter [bc-transition] kinds=transferToInterpreter lang=BytecodeDSLTestLanguage root=TransitionTracingRootNodeGen@661649b thread=main old: tier=cached bci=4 op=c.Inc src=none tag=none instr=false new: tier=cached bci=4 op=c.Inc src=none tag=none instr=false changes: addedTags=none addedInstrumentations=none ``` -------------------------------- ### Example Bytecode Tracing Output Source: https://github.com/oracle/graal/blob/master/truffle/docs/Optimizing.md This is an example of the output generated when `--engine.TraceBytecode=true` is enabled, showing executed bytecode instructions. ```text # --engine.TraceBytecode=true [bc] 1:while-loop.demo:[002] 001 load.argument index(0) | while-loop.demo 1:1 - 1:11 source-code [bc] 2:while-loop.demo:[008] 012 store.local local_offset(0) local_index(0) child0(0002) | while-loop.demo 1:1 - 1:11 source-code [bc] 3:while-loop.demo:[014] 009 load.local local_offset(0) local_index(0) | while-loop.demo 1:1 - 1:11 source-code [bc] ... ``` -------------------------------- ### Create Maven Project Source: https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/README.md Command to generate a new Maven Java project using the Maven Quickstart archetype. ```bash mvn archetype:generate \ -DarchetypeGroupId=org.apache.maven.archetypes \ -DarchetypeArtifactId=maven-archetype-quickstart \ -DarchetypeVersion=1.5 \ -DgroupId=com.example \ -DartifactId=helloworld \ -DinteractiveMode=false ``` -------------------------------- ### Example TraceInlining Output Source: https://github.com/oracle/graal/blob/master/truffle/docs/Inlining.md This is an example output from the TraceInlining engine option for a JavaScript function, showing details about inlining decisions. ```text [engine] inline start M.CollidePolygons |call diff 0.00 |Recursion Depth 0 |Explore/inline ratio 1.07 |IR Nodes 27149 |Frequency 1.00 |Truffle Callees 14 |Forced false |Depth 0 [engine] Inlined M.FindMaxSeparation |call diff -8.99 |Recursion Depth 0 |Explore/inline ratio NaN |IR Nodes 4617 |Frequency 1.00 |Truffle Callees 7 |Forced false |Depth 1 [engine] Inlined parseInt |call diff -1.00 |Recursion Depth 0 |Explore/inline ratio NaN |IR Nodes 111 |Frequency 1.00 |Truffle Callees 0 |Forced true |Depth 2 [engine] Inlined M.EdgeSeparation |call diff -3.00 |Recursion Depth 0 |Explore/inline ratio NaN |IR Nodes 4097 |Frequency 1.00 |Truffle Callees 2 |Forced false |Depth 2 [engine] Inlined parseInt |call diff -1.00 |Recursion Depth 0 |Explore/inline ratio NaN |IR Nodes 111 |Frequency 1.00 |Truffle Callees 0 |Forced true |Depth 3 [engine] Inlined parseInt |call diff -1.00 |Recursion Depth 0 |Explore/inline ratio NaN |IR Nodes 111 |Frequency 1.00 |Truffle Callees 0 |Forced true |Depth 3 [engine] Inlined parseInt |call diff -1.00 |Recursion Depth 0 |Explore/inline ratio NaN |IR Nodes 111 |Frequency 1.00 |Truffle Callees 0 |Forced true |Depth 2 [engine] Expanded M.EdgeSeparation |call diff 1.00 |Recursion Depth 0 |Explore/inline ratio NaN |IR Nodes 4097 |Frequency 1.00 |Truffle Callees 2 |Forced false |Depth 2 [engine] Inlined parseInt |call diff -1.00 |Recursion Depth 0 |Explore/inline ratio NaN |IR Nodes 111 |Frequency 1.00 |Truffle Callees 0 |Forced true |Depth 2 [engine] Inlined M.EdgeSeparation |call diff -3.00 |Recursion Depth 0 |Explore/inline ratio NaN |IR Nodes 4097 |Frequency 1.00 |Truffle Callees 2 |Forced false |Depth 2 [engine] Inlined parseInt |call diff -1.00 |Recursion Depth 0 |Explore/inline ratio NaN |IR Nodes 111 |Frequency 1.00 |Truffle Callees 0 |Forced true |Depth 3 [engine] Inlined parseInt |call diff -1.00 |Recursion Depth 0 |Explore/inline ratio NaN |IR Nodes 111 |Frequency 1.00 |Truffle Callees 0 |Forced true |Depth 3 [engine] Cutoff M.EdgeSeparation |call diff 0.01 |Recursion Depth 0 |Explore/inline ratio NaN |IR Nodes 0 |Frequency 0.01 |Truffle Callees 2 |Forced false |Depth 2 [engine] Cutoff M.FindMaxSeparation |call diff 1.00 |Recursion Depth 0 |Explore/inline ratio NaN |IR Nodes 0 |Frequency 1.00 |Truffle Callees 7 |Forced false |Depth 1 [engine] Cutoff M.FindIncidentEdge |call diff 1.00 |Recursion Depth 0 |Explore/inline ratio NaN |IR Nodes 0 |Frequency 1.00 |Truffle Callees 19 |Forced false |Depth 1 ``` -------------------------------- ### Setting up Standalone Toolchain for Bootstrapping Source: https://github.com/oracle/graal/blob/master/sulong/docs/contributor/TOOLCHAIN.md Uses `SULONG_BOOTSTRAP_STANDALONE` environment variable to specify a prebuilt standalone toolchain for faster development builds. Requires `mx` commands to set up. ```bash $ mx --env ce-llvm-standalones build --dependencies SULONG_JVM_STANDALONE $ export SULONG_BOOTSTRAP_STANDALONE=`mx --env ce-llvm-standalones path --output SULONG_JVM_STANDALONE` ``` -------------------------------- ### Install Binaryen using Homebrew Source: https://github.com/oracle/graal/blob/master/web-image/README.md On MacOS, it is recommended to install Binaryen through Homebrew. This command ensures the 'wasm-as' assembler is available on your PATH. ```bash brew install binaryen ``` -------------------------------- ### Java HelloWorld Example Source: https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/NativeImageBasics.md A simple Java class demonstrating static initialization. This code is executed at build time or run time depending on the native-image configuration. ```java public class HelloWorld { static class Greeter { static { System.out.println("Greeter is getting ready!"); } public static void greet() { System.out.println("Hello, World!"); } } public static void main(String[] args) { Greeter.greet(); } } ``` -------------------------------- ### Install perf on Oracle Linux/Red Hat/CentOS Source: https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/PerfProfiling.md Use this command to install the perf profiler on systems using yum package manager. ```bash sudo yum install perf ``` -------------------------------- ### PMH Benchmark Example Source: https://github.com/oracle/graal/blob/master/truffle/docs/polybench/PMH.md An example of a .pmh file demonstrating how to parse a JavaScript function, prepare arguments, and define a microbenchmark run. ```pmh # Lines starting with '#' are comments. # Parse a JS function to benchmark. func = EVAL "js" (function(x) { return x + 1; }) # Prepare a JS number as argument. arg = EVAL "js" 42 # Prepare both func and arg during benchmark setup. SETUP func arg # Call the function in the benchmark loop. run = EXECUTE func arg # Call the function a million times per iteration, and report the average time in nanoseconds. MICROBENCH run repeat: 1000000 unit: ns ``` -------------------------------- ### Fibonacci Java Program Example Source: https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/PGO-IprofFileFormat.md A Java program to calculate Fibonacci numbers, used as a motivating example for generating an iprof file. ```java import java.io.*; public class Fib { private int n; Fib(int n) { this.n = n; } synchronized void fibonacci() { int num1 = 0, num2 = 1; for (int i = 0; i < n; i++) { try { Thread.sleep(10); } catch (Exception e) { // ignored } // Print the number System.out.print(num1 + " "); // Swap int num3 = num2 + num1; num1 = num2; num2 = num3; } } public static void main(String args[]) { new Fib(10).fibonacci(); } } ``` -------------------------------- ### Run Native Application (Run-Time Initialization) Source: https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/guides/specify-class-initialization.md Run the compiled native executable and time its execution. This demonstrates the performance characteristics when initialization occurs at run time. ```bash time ./runtime-parser ```