Home > database >  Why do I need JVM to run an AOT compiled code?
Why do I need JVM to run an AOT compiled code?

Time:02-02

Im learning about GraalVM and AOT and I was reading the spec for AOT and then I got confused, if AOT compiles my code to machine code (native) why do I need a JVM?
why I need this:

java -XX:AOTLibrary=./libHelloWorld.so HelloWorld

CodePudding user response:

You still need the JVM, because you just compiled a small portion i.e. "your HelloWorld" to native code. You still require a lot of the JVM to run your program. e.g. the Java standard library (which you haven't compiled to native code), class loading, detection of the program entry point (finding your main method), and garbage collection. All of this is provided by the JVM.

In short, you just compiled a library, a small part of your program, to native code. You don't compile the complete program to native code.

This is also stated by the summary of JEP295:

Summary
Compile Java classes to native code prior to launching the virtual machine.

I think what you actually want to do, is to compile a native image of your program. This would include all the implications like garbage collection from the JVM into the executable.

  • Related