Unlock Faster Java Apps with GraalVM: Run, Native‑Compile, and Polyglot Programming
This article provides a concise, English‑language guide to GraalVM, covering its high‑performance JIT compiler, native‑image generation for instant‑start binaries, and polyglot capabilities for running Java, JVM languages, JavaScript, Python, Ruby, R, and more, with key commands and options.
Preface
GraalVM helps developers use Java better in three ways: faster JIT compilation, compiling to instant‑start low‑memory native binaries, and supporting multiple languages.
This quick reference is a one‑page summary of what GraalVM can do and its key options and commands.
1. Running Java Applications
GraalVM distribution includes a JDK, so you can compile with javac and run Java or any JVM language. It uses the HotSpot VM, so most JVM options apply. javac MyApp.java Run the application: java -jar MyApp.jar Specify classpath: java -cp target/myapp.jar com.example.Main GraalVM’s compiler usually runs in pre‑compiled native library mode, but you can configure modes with options such as -XX:+-UseJVMCINativeLibrary, -Dgraal.CompilerConfiguration=enterprise|community|economy, and enable compilation logging with -Dgraal.PrintCompilation=true or dump graphs with -Dgraal.Dump=:2. Java agents can also be attached.
-javaagent:path/to/jar.jar
-agentlib:path/to/native/agent2. Compiling to Native Executables
The Native Image feature compiles applications ahead‑of‑time into binaries. Install the native‑image component first: gu install -L native-image.jar Generate a binary:
native-image [options] MyClass
native-image -jar MyApp.jar
./myAppTo build a shared library use --shared with @CEntryPoint. For a statically linked binary add --static --libc=muslc.
--shared
--static --libc=muslc3. Polyglot Programming
GraalVM can run Truffle‑based languages such as JavaScript, Ruby, Python, R, and LLVM. Enable languages with options like --language:js, --language:python, etc.
--language:js
--language:python
--language:llvm
--language:rubyNative Image supports profile‑guided optimization (PGO) to improve performance:
native-image — pgo-instrument MyApp
./myApp
native-image — pgo profile.iprof MyAppTrace class initialization with -H:+TraceClassInitialization=package.class.Name and attach a debugger with --debug-attach=[port]. Additional options are listed with --expert-options-all.
Run language‑specific launchers (node, graalpython, ruby, etc.) and choose execution mode with --jvm or --polyglot. Resource limits can be set, e.g., --sandbox.MaxCPUTime=Nms.
4. General Development Tools
GraalVM ships with built‑in tools such as Chrome DevTools‑based debugger, CPU sampler, CPU tracer, and memory sampler, enabled with:
--inspect
--cpusampler
--cputracer
--memsamplerConclusion
GraalVM is a versatile platform offering a high‑performance JIT compiler, native‑image generation, and polyglot runtime for Java, JVM languages, JavaScript, Ruby, Python, R, and more. Download the quick‑reference PDF, print it, and explore the many capabilities.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Java Architecture Diary
Committed to sharing original, high‑quality technical articles; no fluff or promotional content.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
