{"id":18900615,"url":"https://github.com/aseemsavio/graal-vm-native-image-poc","last_synced_at":"2026-03-02T13:30:19.814Z","repository":{"id":162382428,"uuid":"516977167","full_name":"aseemsavio/graal-vm-native-image-poc","owner":"aseemsavio","description":"How to Create a GraalVM Native Image","archived":false,"fork":false,"pushed_at":"2022-07-23T07:30:17.000Z","size":3700,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-12-31T09:34:24.194Z","etag":null,"topics":["graalvm","graalvm-native-image","java","java17"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aseemsavio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-07-23T06:26:45.000Z","updated_at":"2022-07-23T07:32:30.000Z","dependencies_parsed_at":null,"dependency_job_id":"e604f6f0-2f31-4228-a213-0029a026b4e9","html_url":"https://github.com/aseemsavio/graal-vm-native-image-poc","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aseemsavio%2Fgraal-vm-native-image-poc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aseemsavio%2Fgraal-vm-native-image-poc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aseemsavio%2Fgraal-vm-native-image-poc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aseemsavio%2Fgraal-vm-native-image-poc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aseemsavio","download_url":"https://codeload.github.com/aseemsavio/graal-vm-native-image-poc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239880418,"owners_count":19712395,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["graalvm","graalvm-native-image","java","java17"],"created_at":"2024-11-08T08:51:59.726Z","updated_at":"2026-03-02T13:30:19.682Z","avatar_url":"https://github.com/aseemsavio.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# graal-vm-native-image-poc\n\nThis project explains how `native-image` can be built for a single class Java Application.\nFor reference, I am on a **M1 Macbook Pro with an 8 core CPU**(aarch64), and 16 Gigs of Unified Memory. I'm running the \n`GraalVM Community Edition 22.1.0` for `Java 17`.\n\n\nTo start, we `cd` into the src directory.\n```\ncd src\n```\n\nTo compile the class\n```\njavac Main.java\n```\nThis would result in a `Main.class` file in the same directory.\n\nTo run the class with the GraalVM JVM or with any JVM\n```\njava Main\n```\nHere's the response:\n```\nHello World\n```\n\nNow, timing the execution on my M1 Macbook Pro.\n```\ntime java Main\n```\nHere's the response:\n```\nHello World\njava Main  0.06s user 0.02s system 113% cpu 0.074 total\n```\n\nIn the user mode (typically applications are run in user mode), the java application takes `~600ms` to start and run \nthe simple hello world program.\nThis time is mostly to bring up the JVM. JVM applications are best suited for long-running applications like web servers.\n\nEven though the JVM applications are fast in long-running use cases, they tend to have a higher startup time due to the\nissue mentioned above. This can be rectified by creating a `native-image` of the application.\n\nGraal VM's `native-image` utility compiles all the JDK classes and your classes into a self-contained binary that can be \nrun without the JVM.\n\nTo create a native image,\n```\nnative-image Main\n```\nThis generates the following logs and two files - `main` executable and a `.txt` file.\n```\naseemsavio@MacBook-Pro src % native-image Main\n========================================================================================================================\nGraalVM Native Image: Generating 'main' (executable)...\n========================================================================================================================\n[1/7] Initializing...                                                                                    (7.5s @ 0.17GB)\n Version info: 'GraalVM 22.1.0 Java 17 CE'\n C compiler: cc (apple, arm64, 13.1.6)\n Garbage collector: Serial GC\n[2/7] Performing analysis...  [******]                                                                   (5.0s @ 0.96GB)\n   2,849 (74.93%) of  3,802 classes reachable\n   3,374 (51.27%) of  6,581 fields reachable\n  12,862 (44.64%) of 28,811 methods reachable\n      35 classes,     0 fields, and   353 methods registered for reflection\n      57 classes,    59 fields, and    51 methods registered for JNI access\n[3/7] Building universe...                                                                               (0.5s @ 1.16GB)\n[4/7] Parsing methods...      [*]                                                                        (0.5s @ 0.56GB)\n[5/7] Inlining methods...     [****]                                                                     (0.8s @ 1.42GB)\n[6/7] Compiling methods...    [**]                                                                       (4.1s @ 1.41GB)\n[7/7] Creating image...                                                                                  (1.3s @ 0.35GB)\n   4.32MB (35.52%) for code area:    7,549 compilation units\n   6.97MB (57.30%) for image heap:   1,704 classes and 93,017 objects\n 893.30KB ( 7.17%) for other data\n  12.16MB in total\n------------------------------------------------------------------------------------------------------------------------\nTop 10 packages in code area:                               Top 10 object types in image heap:\n 663.16KB java.util                                          977.68KB byte[] for general heap data\n 339.13KB java.lang                                          934.59KB byte[] for code metadata\n 258.06KB java.text                                          876.72KB java.lang.String\n 236.67KB java.util.regex                                    645.13KB java.lang.Class\n 197.47KB com.oracle.svm.jni                                 531.76KB byte[] for java.lang.String\n 190.89KB java.util.concurrent                               389.06KB java.util.HashMap$Node\n 156.13KB com.oracle.svm.core.reflect                        222.58KB com.oracle.svm.core.hub.DynamicHubCompanion\n 146.05KB java.math                                          168.16KB java.util.HashMap$Node[]\n  98.20KB java.util.logging                                  163.67KB java.lang.String[]\n  95.28KB com.oracle.svm.core.genscavenge                    156.47KB java.util.concurrent.ConcurrentHashMap$Node\n      ... 115 additional packages                                 ... 774 additional object types\n                                           (use GraalVM Dashboard to see all)\n------------------------------------------------------------------------------------------------------------------------\n                        0.8s (4.0% of total time) in 18 GCs | Peak RSS: 3.26GB | CPU load: 4.14\n------------------------------------------------------------------------------------------------------------------------\nProduced artifacts:\n /Users/aseemsavio/Projects/Java/graal-vm-native-image-poc/graal-vm-native-image-poc/src/main (executable)\n /Users/aseemsavio/Projects/Java/graal-vm-native-image-poc/graal-vm-native-image-poc/src/main.build_artifacts.txt\n========================================================================================================================\nFinished generating 'main' in 20.5s.\n\n```\n\nThe generated executable can be run by just calling it.\n\n```\n./main\n```\n\nThe response is\n```\nHello World\n```\nTiming it, we can see that it took less than `1 ms`!!\n```\naseemsavio@MacBook-Pro src % time ./main\nHello World\n./main  0.00s user 0.00s system 80% cpu 0.010 total\naseemsavio@MacBook-Pro src % \n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faseemsavio%2Fgraal-vm-native-image-poc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faseemsavio%2Fgraal-vm-native-image-poc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faseemsavio%2Fgraal-vm-native-image-poc/lists"}