Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are there some methods in java.base cannot be compiled by AOT compiler

Tags:

java

jvm

java-9

According to JEP-295 (http://openjdk.java.net/jeps/295)

There are some methods in java.base causing compilation failure, but why?

It will be appreciated that someone can help me so that I can realize limitation of Openjdk AOT compiler.

like image 983
cwei Avatar asked Jul 28 '17 08:07

cwei


People also ask

What is AOT compilation in Java?

Ahead-Of-Time (AOT) compilation allows the compilation of Java™ classes into native code for subsequent executions of the same program. The AOT compiler works with the class data sharing framework.

Is Java a JIT or AOT?

AOT compilation is one way of improving the performance of Java programs and in particular the startup time of the JVM. The JVM executes Java bytecode and compiles frequently executed code to native code. This is called Just-in-Time (JIT) Compilation.


1 Answers

See the documentation you are linking to:

Current AOT limitations ...

May not compile java code which uses dynamically generated classes and bytecode (lambda expressions, invoke dynamic).

These limitations may be addressed in future releases.

Thus two potential explanations:

  1. the methods that do not compile fall into the known limitations
  2. otherwise, a bug in a "brand new, experimental" product

Most likely "option 2" is the better explanation - see again your link.

It contains a list of methods that fail compilation, together with the error that occurs:

cat java.base-list.txt

# jaotc: java.lang.StackOverflowError
exclude sun.util.resources.LocaleNames.getContents()[[Ljava/lang/Object;
exclude sun.util.resources.TimeZoneNames.getContents()[[Ljava/lang/Object;
exclude sun.util.resources.cldr.LocaleNames.getContents()[[Ljava/lang/Object;
exclude sun.util.resources..*.LocaleNames_.*.getContents\(\)\[\[Ljava/lang/Object;
exclude sun.util.resources..*.LocaleNames_.*_.*.getContents\(\)\[\[Ljava/lang/Object;
exclude sun.util.resources..*.TimeZoneNames_.*.getContents\(\)\[\[Ljava/lang/Object;
exclude sun.util.resources..*.TimeZoneNames_.*_.*.getContents\(\)\[\[Ljava/lang/Object;
# java.lang.Error: Trampoline must not be defined by the bootstrap classloader
exclude sun.reflect.misc.Trampoline.<clinit>()V
exclude sun.reflect.misc.Trampoline.invoke(Ljava/lang/reflect/Method;Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;
# JVM asserts
exclude com.sun.crypto.provider.AESWrapCipher.engineUnwrap([BLjava/lang/String;I)Ljava/security/Key;
exclude sun.security.ssl.*
exclude sun.net.RegisteredDomain.<clinit>()V
# Huge methods
exclude jdk.internal.module.SystemModules.descriptors()[Ljava/lang/module/ModuleDescriptor;

And when you check the sources, for example getContents() - no lambdas there.

So the methods that fail compilation are most likely caused by the fact that the new compiler is "not yet ready" to successfully compile arbitrary Java source code!

like image 172
GhostCat Avatar answered Oct 25 '22 14:10

GhostCat