Original class file still needed after jaotc compilation?

312 views Asked by At

For those who know jaotc, I have a simple question for you.

After you do

javac HelloWorld.java
jaotc --output HelloWorld.so HelloWorld.class

You can run

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

without any problem. This is what has been shown on the internet everywhere. Fine with me.

However, if you move your HelloWorld.class somewhere else that is not in your classpath, and run

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

again, then you will get a class not found error.

So the original .class file is still needed? Then what's the point of doing the AOT?

2

There are 2 answers

0
Yanhui Xie On

Yes, at least so far. You may refer to http://openjdk.java.net/jeps/295 :

Since class bytecodes can change over time, either through changes to the source code or via class transformation and redefinition, the JVM needs to detect such changes and reject AOT-compiled code if the bytecode doesn't match. This is achieved with class fingerprinting. During AOT compilation a fingerprint for each class is generated and stored in the data section of the shared library. Later, when a class is loaded and AOT-compiled code is found for this class, the fingerprint for the current bytecode is compared to the one stored in the shared library. If there is a mismatch then the AOT code for that particular class is not used.

0
Jessie Lesbian On

I suspect this when I found out that the only Java Native Image that ever gets loaded in my native version of Minecraft is that the one of java.base. I don't know why until I read this.

AOT images are just alternative images to use if possible. They are NOT a replacement of the original Java bytecode.

This is done just in case the JVM args are different and/or running on a different platform. I believe that IKVM.NET fit your purpose better if you are trying to make a Java Native Application.