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

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.

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!