# HG changeset patch # User Doug Simon # Date 1427193412 -3600 # Node ID 3cbb0846337c80ac5d4a5e9f41214d2c2f68d88c # Parent 926850b25c653d58b22cfb8cc06948d81d843907 added -G:CompileTheWorldMethodFilter option diff -r 926850b25c65 -r 3cbb0846337c graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/MethodFilter.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/MethodFilter.java Mon Mar 23 15:45:19 2015 -0700 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/MethodFilter.java Tue Mar 24 11:36:52 2015 +0100 @@ -121,6 +121,18 @@ return false; } + /** + * Determines if a given class name is matched by a given array of filters. + */ + public static boolean matchesClassName(MethodFilter[] filters, String className) { + for (MethodFilter filter : filters) { + if (filter.matchesClassName(className)) { + return true; + } + } + return false; + } + public MethodFilter(String sourcePattern) { String pattern = sourcePattern.trim(); diff -r 926850b25c65 -r 3cbb0846337c graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/CompileTheWorldTest.java --- a/graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/CompileTheWorldTest.java Mon Mar 23 15:45:19 2015 -0700 +++ b/graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/CompileTheWorldTest.java Tue Mar 24 11:36:52 2015 +0100 @@ -40,7 +40,7 @@ boolean originalSetting = ExitVMOnException.getValue(); // Compile a couple classes in rt.jar String file = System.getProperty("java.home") + "/lib/rt.jar"; - new CompileTheWorld(file, new Config(null), 1, 5, false).compile(); + new CompileTheWorld(file, new Config(null), 1, 5, null, false).compile(); ExitVMOnException.setValue(originalSetting); } diff -r 926850b25c65 -r 3cbb0846337c graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/MemoryUsageBenchmark.java --- a/graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/MemoryUsageBenchmark.java Mon Mar 23 15:45:19 2015 -0700 +++ b/graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/MemoryUsageBenchmark.java Tue Mar 24 11:36:52 2015 +0100 @@ -180,7 +180,7 @@ compileAndTime("complex"); if (CompileTheWorldClasspath.getValue() != SUN_BOOT_CLASS_PATH) { CompileTheWorld ctw = new CompileTheWorld(CompileTheWorldClasspath.getValue(), new Config(CompileTheWorldConfig.getValue()), CompileTheWorldStartAt.getValue(), - CompileTheWorldStopAt.getValue(), CompileTheWorldVerbose.getValue()); + CompileTheWorldStopAt.getValue(), CompileTheWorldMethodFilter.getValue(), CompileTheWorldVerbose.getValue()); try { ctw.compile(); } catch (Throwable e) { diff -r 926850b25c65 -r 3cbb0846337c graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompileTheWorld.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompileTheWorld.java Mon Mar 23 15:45:19 2015 -0700 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompileTheWorld.java Tue Mar 24 11:36:52 2015 +0100 @@ -34,6 +34,7 @@ import java.util.concurrent.*; import java.util.concurrent.atomic.*; import java.util.jar.*; +import java.util.stream.*; import com.oracle.graal.api.meta.*; import com.oracle.graal.bytecode.*; @@ -66,6 +67,8 @@ public static final OptionValue CompileTheWorldVerbose = new OptionValue<>(true); @Option(help = "The number of CompileTheWorld iterations to perform", type = OptionType.Debug) public static final OptionValue CompileTheWorldIterations = new OptionValue<>(1); + @Option(help = "Only compile methods matching this filter", type = OptionType.Debug) + public static final OptionValue CompileTheWorldMethodFilter = new OptionValue<>(null); @Option(help = "First class to consider when using -XX:+CompileTheWorld", type = OptionType.Debug) public static final OptionValue CompileTheWorldStartAt = new OptionValue<>(1); @Option(help = "Last class to consider when using -XX:+CompileTheWorld", type = OptionType.Debug) @@ -151,6 +154,9 @@ /** Class index to stop compilation at (see {@link Options#CompileTheWorldStopAt}). */ private final int stopAt; + /** Only compile methods matching one of the filters in this array if the array is non-null. */ + private final MethodFilter[] methodFilters; + // Counters private int classFileCounter = 0; private AtomicLong compiledMethodsCounter = new AtomicLong(); @@ -174,10 +180,11 @@ * @param startAt index of the class file to start compilation at * @param stopAt index of the class file to stop compilation at */ - public CompileTheWorld(String files, Config config, int startAt, int stopAt, boolean verbose) { + public CompileTheWorld(String files, Config config, int startAt, int stopAt, String methodFilters, boolean verbose) { this.files = files; this.startAt = startAt; this.stopAt = stopAt; + this.methodFilters = methodFilters == null || methodFilters.isEmpty() ? null : MethodFilter.parse(methodFilters); this.verbose = verbose; this.config = config; @@ -265,7 +272,12 @@ continue; } - println("CompileTheWorld : Compiling all classes in " + entry); + if (methodFilters == null || methodFilters.length == 0) { + println("CompileTheWorld : Compiling all classes in " + entry); + } else { + println("CompileTheWorld : Compiling all methods in " + entry + " matching one of the following filters: " + + Arrays.asList(methodFilters).stream().map(MethodFilter::toString).collect(Collectors.joining(", "))); + } println(); URL url = new URL("jar", "", "file:" + entry + "!/"); @@ -286,11 +298,16 @@ } String className = je.getName().substring(0, je.getName().length() - ".class".length()); + String dottedClassName = className.replace('/', '.'); classFileCounter++; + if (methodFilters != null && !MethodFilter.matchesClassName(methodFilters, dottedClassName)) { + continue; + } + try { // Load and initialize class - Class javaClass = Class.forName(className.replace('/', '.'), true, loader); + Class javaClass = Class.forName(dottedClassName, true, loader); // Pre-load all classes in the constant pool. try { @@ -386,6 +403,9 @@ } private void compileMethod(HotSpotResolvedJavaMethod method) { + if (methodFilters != null && !MethodFilter.matches(methodFilters, method)) { + return; + } if (threadPool != null) { threadPool.submit(new Runnable() { public void run() { diff -r 926850b25c65 -r 3cbb0846337c graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalRuntime.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalRuntime.java Mon Mar 23 15:45:19 2015 -0700 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalRuntime.java Tue Mar 24 11:36:52 2015 +0100 @@ -552,7 +552,7 @@ getCompilerToVM().resetCompilationStatistics(); TTY.println("CompileTheWorld : iteration " + i); CompileTheWorld ctw = new CompileTheWorld(CompileTheWorldClasspath.getValue(), new Config(CompileTheWorldConfig.getValue()), CompileTheWorldStartAt.getValue(), - CompileTheWorldStopAt.getValue(), CompileTheWorldVerbose.getValue()); + CompileTheWorldStopAt.getValue(), CompileTheWorldMethodFilter.getValue(), CompileTheWorldVerbose.getValue()); ctw.compile(); } System.exit(0);