10

I compiled a simple class using the Java 9 Ahead-Of-Time Compiler jaotc using the following command:

javac Test.java
jaotc Test.class

This produces a file named unnammed.so. How do I run the compiled program? Do I need to write a bootstrap program to link with the .so file?

1
  • 3
    The page you linked (of the compiler) has a section titled "Steps to generate and use an AOT library for the java.base module" - have you tried adapting the last part from that? e.g.: java -XX:AOTLibrary=./unnamed.so Test Jul 25, 2017 at 8:43

2 Answers 2

15

After executing an AOT compilation, you need to specify generated AOT library during application execution:

java -XX:AOTLibrary=./Test.so Test

You should also compile java.base to gain real improvement, performance wise:

jaotc --output libjava.base.so --module java.base

Note that the same java runtime configuration should be used during AOT compilation and execution.

For Example:

jaotc -J-XX:+UseParallelGC -J-XX:-UseCompressedOops --output libTest.so Test.class 
java -XX:+UseParallelGC -XX:-UseCompressedOops -XX:AOTLibrary=./libTest.so Test

Take a look at this, for more information.

2
  • 4
    I should add that you should also compile java.base because compiling Test class only will not give any performance gain Jul 25, 2017 at 9:25
  • It might be worth mentioning that ArgOne should be the Java class name for the class to run.
    – user11171
    Jul 25, 2017 at 12:49
5

You should have a look at JEP 295, which describes AOT compilation in JDK 9, http://openjdk.java.net/jeps/295. You need to use the --XX::AOTLibrary command line flag.

To execute your app:

java -XX::AOTLibrary=./unnamed.so,./libjava.base.so Test

You will obviously have to copy the libjava.base.so file from the JDK 9 distribution or change the path to where it is.

When compiling you should also use the --output flag to jaotc so you don't get 'unnamed.so'.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.