Created
November 9, 2019 21:26
-
-
Save AugustNagro/1c1f9bc215f117488230e02c547ed08e to your computer and use it in GitHub Desktop.
Convert output of -XX:PrintTouchedMethodsAtExit into form usable by JEP 295 AOT
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.IOException; | |
import java.nio.file.Files; | |
import java.nio.file.Path; | |
import java.nio.file.Paths; | |
import java.nio.file.StandardOpenOption; | |
import java.util.stream.Stream; | |
/** | |
* Converts from TouchedMethods format to AOT format | |
* | |
* 1. Run your code: | |
* java -XX:+UnlockDiagnosticVMOptions -XX:+LogTouchedMethods -XX:+PrintTouchedMethodsAtExit \ | |
* -jar <jar> > touched-methods.txt | |
* | |
* 2. Convert to AOT compile-command form: | |
* java Converter.java touched-methods.txt | |
* | |
* 3. Make the AOT shared library, with the modules we desire | |
* jaotc --compile-for-tiered -J-Xmx4g --compile-commands aot-commands.txt \ | |
* --output libidea.so --module java.base:java.desktop --info | |
* | |
* 4. Run with shared archive | |
* java -XX:+UseAOT -XX:AOTLibrary=<lib.so> -jar <jar> | |
*/ | |
public class Converter { | |
// Recommended in https://openjdk.java.net/jeps/295 | |
private static final String JAVA_BASE_COMPILE_COMMANDS = "# jaotc: java.lang.StackOverflowError\n" + | |
"exclude sun.util.resources.LocaleNames.getContents()[[Ljava/lang/Object;\n" + | |
"exclude sun.util.resources.TimeZoneNames.getContents()[[Ljava/lang/Object;\n" + | |
"exclude sun.util.resources.cldr.LocaleNames.getContents()[[Ljava/lang/Object;\n" + | |
"exclude sun.util.resources..*.LocaleNames_.*.getContents\\(\\)\\[\\[Ljava/lang/Object;\n" + | |
"exclude sun.util.resources..*.LocaleNames_.*_.*.getContents\\(\\)\\[\\[Ljava/lang/Object;\n" + | |
"exclude sun.util.resources..*.TimeZoneNames_.*.getContents\\(\\)\\[\\[Ljava/lang/Object;\n" + | |
"exclude sun.util.resources..*.TimeZoneNames_.*_.*.getContents\\(\\)\\[\\[Ljava/lang/Object;\n" + | |
"# java.lang.Error: Trampoline must not be defined by the bootstrap classloader\n" + | |
"exclude sun.reflect.misc.Trampoline.<clinit>()V\n" + | |
"exclude sun.reflect.misc.Trampoline.invoke(Ljava/lang/reflect/Method;Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;\n" + | |
"# JVM asserts\n" + | |
"exclude com.sun.crypto.provider.AESWrapCipher.engineUnwrap([BLjava/lang/String;I)Ljava/security/Key;\n" + | |
"exclude sun.security.ssl.*\n" + | |
"exclude sun.net.RegisteredDomain.<clinit>()V\n" + | |
"# Huge methods\n" + | |
"exclude jdk.internal.module.SystemModules.descriptors()[Ljava/lang/module/ModuleDescriptor;\n"; | |
public static void main(String[] args) throws IOException { | |
Path touchedMethods = Paths.get(args[0]); | |
Path compileCommands = touchedMethods.resolveSibling("aot-commands.txt"); | |
Stream<String> converted = Files.lines(touchedMethods) | |
.filter(l -> l.startsWith("java") || l.startsWith("javax/swing") || l.startsWith("jdk")) | |
.map(Converter::toAOTForm); | |
Files.write(compileCommands, (Iterable<String>) converted::iterator); | |
Files.writeString(compileCommands, JAVA_BASE_COMPILE_COMMANDS, StandardOpenOption.APPEND); | |
System.out.println("Done writing to " + compileCommands.getFileName()); | |
} | |
private static String toAOTForm(String s) { | |
int paramIdx = s.indexOf(':'); | |
return "compileOnly " + | |
s.substring(0, paramIdx).replace('/', '.') + | |
s.substring(paramIdx + 1); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment