Performance
performance4GraalVmNativeImage
- Path
- pkg19performance/performance4GraalVmNativeImage.java
- Package
- pkg19performance
- Study order
- 4
- Run
- Single-file source launch
- Command
- java pkg19performance/performance4GraalVmNativeImage.java
There is no in-browser runner. This is the file from the curriculum, unchanged.
1package pkg19performance;2 3/*4 * performance4GraalVmNativeImage.java5 * -----------------------------------6 * GraalVM native-image: ahead-of-time compilation to a standalone binary.7 *8 * DEFINITION:9 * native-image compiles Java to a native executable with fast startup and10 * lower memory footprint — ideal for CLI tools, serverless, containers.11 *12 * KEY POINTS:13 * - Trade-off: longer build, reflection/config needed for dynamic features.14 * - Reachability metadata: reflect-config.json, resource-config.json.15 * - Not all Java features at runtime (some agents, deep reflection need config).16 *17 * Build (requires GraalVM + native-image):18 * native-image -jar myapp.jar19 * ./myapp # starts in milliseconds20 */21public class performance4GraalVmNativeImage {22 23 public static void main(String[] args) {24 System.out.println("GraalVM native-image benefits:");25 System.out.println(" - Startup: ms instead of seconds (no JVM warmup phase)");26 System.out.println(" - Memory: smaller RSS (no full HotSpot runtime)");27 System.out.println(" - Single deployable binary");28 29 System.out.println("\nWhen NOT to use:");30 System.out.println(" - Heavy reflection/dynamic proxies without config");31 System.out.println(" - Apps that rely on JIT peak performance after long warmup");32 System.out.println(" - Frequent dynamic class loading");33 34 System.out.println("\nJMH benchmarks for micro-benchmarks: see pkg19performance/jmh-demo/");35 System.out.println("Hello from JVM — same code can be compiled with native-image.");36 }37}