src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/HotSpotGraalCompilerFactory.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File
*** old/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/HotSpotGraalCompilerFactory.java	Mon Mar 20 17:38:32 2017
--- new/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/HotSpotGraalCompilerFactory.java	Mon Mar 20 17:38:32 2017

*** 20,86 **** --- 20,53 ---- * or visit www.oracle.com if you need additional information or have any * questions. */ package org.graalvm.compiler.hotspot; import static org.graalvm.compiler.core.common.util.Util.Java8OrEarlier; import static org.graalvm.compiler.options.OptionValue.PROFILE_OPTIONVALUE_PROPERTY_NAME; import static jdk.vm.ci.common.InitTimer.timer; + import static org.graalvm.compiler.hotspot.HotSpotGraalOptionValues.GRAAL_OPTION_PROPERTY_PREFIX; import java.io.File; import java.io.FileReader; import java.io.IOException; import java.io.PrintStream; import java.lang.reflect.Field; import java.util.HashMap; import java.util.Map; import java.util.Properties; import java.util.ServiceLoader; import org.graalvm.compiler.debug.GraalError; import org.graalvm.compiler.debug.MethodFilter; import org.graalvm.compiler.options.Option; ! import org.graalvm.compiler.options.OptionDescriptors; ! import org.graalvm.compiler.options.OptionKey; import org.graalvm.compiler.options.OptionType; ! import org.graalvm.compiler.options.OptionValues; import org.graalvm.compiler.options.OptionsParser; import org.graalvm.compiler.phases.tiers.CompilerConfiguration; import jdk.vm.ci.common.InitTimer; + import jdk.vm.ci.hotspot.HotSpotJVMCICompilerFactory; import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime; import jdk.vm.ci.hotspot.HotSpotSignature; import jdk.vm.ci.hotspot.HotSpotJVMCICompilerFactory; import jdk.vm.ci.runtime.JVMCIRuntime; + import jdk.vm.ci.services.Services; public final class HotSpotGraalCompilerFactory extends HotSpotJVMCICompilerFactory { /** * The name of the system property specifying a file containing extra Graal option settings. */ private static final String GRAAL_OPTIONS_FILE_PROPERTY_NAME = "graal.options.file"; /** * The name of the system property specifying the Graal version. */ private static final String GRAAL_VERSION_PROPERTY_NAME = "graal.version"; /** * The prefix for system properties that correspond to {@link Option} annotated fields. A field * named {@code MyOption} will have its value set from a system property with the name * {@code GRAAL_OPTION_PROPERTY_PREFIX + "MyOption"}. */ public static final String GRAAL_OPTION_PROPERTY_PREFIX = "graal."; private static MethodFilter[] graalCompileOnlyFilter; /** * Gets the system property assignment that would set the current value for a given option. */ public static String asSystemPropertySetting(OptionValue<?> value) { return GRAAL_OPTION_PROPERTY_PREFIX + value.getName() + "=" + value.getValue(); } private final HotSpotGraalJVMCIServiceLocator locator; HotSpotGraalCompilerFactory(HotSpotGraalJVMCIServiceLocator locator) { this.locator = locator; }
*** 88,228 **** --- 55,120 ---- @Override public String getCompilerName() { return "graal"; } + /** + * Initialized when this factory is {@linkplain #onSelection() selected}. + */ + private OptionValues options; + @Override public void onSelection() { initializeOptions(); JVMCIVersionCheck.check(false); + assert options == null : "cannot select " + getClass() + " service more than once"; + options = HotSpotGraalOptionValues.HOTSPOT_OPTIONS; + initializeGraalCompileOnlyFilter(options); + if (graalCompileOnlyFilter != null || !Options.UseTrivialPrefixes.getValue(options)) { + /* + * Exercise this code path early to encourage loading now. This doesn't solve problem of + * deadlock during class loading but seems to eliminate it in practice. + */ + adjustCompilationLevelInternal(Object.class, "hashCode", "()I", CompilationLevel.FullOptimization); + adjustCompilationLevelInternal(Object.class, "hashCode", "()I", CompilationLevel.Simple); + } + } + + private static void initializeGraalCompileOnlyFilter(OptionValues options) { + String optionValue = Options.GraalCompileOnly.getValue(options); + if (optionValue != null) { + MethodFilter[] filter = MethodFilter.parse(optionValue); + if (filter.length == 0) { + filter = null; + } + graalCompileOnlyFilter = filter; + } } @Override public void printProperties(PrintStream out) { ServiceLoader<OptionDescriptors> loader = ServiceLoader.load(OptionDescriptors.class, OptionDescriptors.class.getClassLoader()); out.println("[Graal properties]"); ! OptionsParser.printFlags(loader, out, allOptionsSettings.keySet(), GRAAL_OPTION_PROPERTY_PREFIX); ! options.printHelp(OptionsParser.getOptionsLoader(), out, GRAAL_OPTION_PROPERTY_PREFIX); } static class Options { // @formatter:off @Option(help = "In tiered mode compile Graal and JVMCI using optimized first tier code.", type = OptionType.Expert) ! public static final OptionValue<Boolean> CompileGraalWithC1Only = new OptionValue<>(true); ! public static final OptionKey<Boolean> CompileGraalWithC1Only = new OptionKey<>(true); @Option(help = "Hook into VM-level mechanism for denoting compilations to be performed in first tier.", type = OptionType.Expert) ! public static final OptionValue<Boolean> UseTrivialPrefixes = new OptionValue<>(false); ! public static final OptionKey<Boolean> UseTrivialPrefixes = new OptionKey<>(false); @Option(help = "A method filter selecting what should be compiled by Graal. All other requests will be reduced to CompilationLevel.Simple.", type = OptionType.Expert) ! public static final OptionValue<String> GraalCompileOnly = new OptionValue<>(null); ! public static final OptionKey<String> GraalCompileOnly = new OptionKey<>(null); // @formatter:on } private static Map<String, String> allOptionsSettings; /** * Initializes options if they haven't already been initialized. * * Initialization means first parsing the options in the file denoted by the * {@code VM.getSavedProperty(String) saved} system property named * {@value HotSpotGraalCompilerFactory#GRAAL_OPTIONS_FILE_PROPERTY_NAME} if the file exists * followed by parsing the options encoded in saved system properties whose names start with * {@value #GRAAL_OPTION_PROPERTY_PREFIX}. Key/value pairs are parsed from the aforementioned * file with {@link Properties#load(java.io.Reader)}. */ @SuppressWarnings("try") private static synchronized void initializeOptions() { if (allOptionsSettings == null) { try (InitTimer t = timer("InitializeOptions")) { ServiceLoader<OptionDescriptors> loader = ServiceLoader.load(OptionDescriptors.class, OptionDescriptors.class.getClassLoader()); Properties savedProps = getSavedProperties(Java8OrEarlier); String optionsFile = savedProps.getProperty(GRAAL_OPTIONS_FILE_PROPERTY_NAME); if (optionsFile != null) { File graalOptions = new File(optionsFile); if (graalOptions.exists()) { try (FileReader fr = new FileReader(graalOptions)) { Properties props = new Properties(); props.load(fr); Map<String, String> optionSettings = new HashMap<>(); for (Map.Entry<Object, Object> e : props.entrySet()) { optionSettings.put((String) e.getKey(), (String) e.getValue()); } try { OptionsParser.parseOptions(optionSettings, null, loader); if (allOptionsSettings == null) { allOptionsSettings = new HashMap<>(optionSettings); } else { allOptionsSettings.putAll(optionSettings); } } catch (Throwable e) { throw new InternalError("Error parsing an option from " + graalOptions, e); } } catch (IOException e) { throw new InternalError("Error reading " + graalOptions, e); } } } Map<String, String> optionSettings = new HashMap<>(); for (Map.Entry<Object, Object> e : savedProps.entrySet()) { String name = (String) e.getKey(); if (name.startsWith(GRAAL_OPTION_PROPERTY_PREFIX)) { if (name.equals("graal.PrintFlags") || name.equals("graal.ShowFlags")) { System.err.println("The " + name + " option has been removed and will be ignored. Use -XX:+JVMCIPrintProperties instead."); } else if (name.equals(GRAAL_OPTIONS_FILE_PROPERTY_NAME) || name.equals(GRAAL_VERSION_PROPERTY_NAME) || name.equals(PROFILE_OPTIONVALUE_PROPERTY_NAME)) { // Ignore well known properties that do not denote an option } else { String value = (String) e.getValue(); optionSettings.put(name.substring(GRAAL_OPTION_PROPERTY_PREFIX.length()), value); } } } OptionsParser.parseOptions(optionSettings, null, loader); if (allOptionsSettings == null) { allOptionsSettings = optionSettings; } else { allOptionsSettings.putAll(optionSettings); } if (Options.GraalCompileOnly.getValue() != null) { graalCompileOnlyFilter = MethodFilter.parse(Options.GraalCompileOnly.getValue()); if (graalCompileOnlyFilter.length == 0) { graalCompileOnlyFilter = null; } } if (graalCompileOnlyFilter != null || !Options.UseTrivialPrefixes.getValue()) { /* * Exercise this code path early to encourage loading now. This doesn't solve * problem of deadlock during class loading but seems to eliminate it in * practice. */ adjustCompilationLevelInternal(Object.class, "hashCode", "()I", CompilationLevel.FullOptimization); adjustCompilationLevelInternal(Object.class, "hashCode", "()I", CompilationLevel.Simple); } } } } private static Properties getSavedProperties(boolean jdk8OrEarlier) { try { String vmClassName = jdk8OrEarlier ? "sun.misc.VM" : "jdk.internal.misc.VM"; Class<?> vmClass = Class.forName(vmClassName); Field savedPropsField = vmClass.getDeclaredField("savedProps"); savedPropsField.setAccessible(true); return (Properties) savedPropsField.get(null); } catch (Exception e) { throw new GraalError(e); } } @Override public HotSpotGraalCompiler createCompiler(JVMCIRuntime runtime) { ! HotSpotGraalCompiler compiler = createCompiler(runtime, options, CompilerConfigurationFactory.selectFactory(null, options)); // Only the HotSpotGraalRuntime associated with the compiler created via // jdk.vm.ci.runtime.JVMCIRuntime.getCompiler() is registered for receiving // VM events. locator.onCompilerCreation(compiler); return compiler;
*** 234,255 **** --- 126,147 ---- * * @param runtime the JVMCI runtime on which the {@link HotSpotGraalRuntime} is built * @param compilerConfigurationFactory factory for the {@link CompilerConfiguration} */ @SuppressWarnings("try") ! public static HotSpotGraalCompiler createCompiler(JVMCIRuntime runtime, OptionValues options, CompilerConfigurationFactory compilerConfigurationFactory) { HotSpotJVMCIRuntime jvmciRuntime = (HotSpotJVMCIRuntime) runtime; try (InitTimer t = timer("HotSpotGraalRuntime.<init>")) { ! HotSpotGraalRuntime graalRuntime = new HotSpotGraalRuntime(jvmciRuntime, compilerConfigurationFactory, options); return new HotSpotGraalCompiler(jvmciRuntime, graalRuntime); } } @Override public String[] getTrivialPrefixes() { ! if (Options.UseTrivialPrefixes.getValue(options)) { ! if (Options.CompileGraalWithC1Only.getValue(options)) { return new String[]{"jdk/vm/ci", "org/graalvm/compiler", "com/oracle/graal"}; } } return null; }
*** 257,268 **** --- 149,160 ---- @Override public CompilationLevelAdjustment getCompilationLevelAdjustment() { if (graalCompileOnlyFilter != null) { return CompilationLevelAdjustment.ByFullSignature; } ! if (!Options.UseTrivialPrefixes.getValue(options)) { ! if (Options.CompileGraalWithC1Only.getValue(options)) { // We only decide using the class declaring the method // so no need to have the method name and signature // symbols converted to a String. return CompilationLevelAdjustment.ByHolder; }
*** 273,282 **** --- 165,181 ---- @Override public CompilationLevel adjustCompilationLevel(Class<?> declaringClass, String name, String signature, boolean isOsr, CompilationLevel level) { return adjustCompilationLevelInternal(declaringClass, name, signature, level); } + static { + // Fail-fast detection for package renaming to guard use of package + // prefixes in adjustCompilationLevelInternal. + assert Services.class.getName().equals("jdk.vm.ci.services.Services"); + assert HotSpotGraalCompilerFactory.class.getName().equals("org.graalvm.compiler.hotspot.HotSpotGraalCompilerFactory"); + } + /* * This method is static so it can be exercised during initialization. */ private static CompilationLevel adjustCompilationLevelInternal(Class<?> declaringClass, String name, String signature, CompilationLevel level) { if (graalCompileOnlyFilter != null) {

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/HotSpotGraalCompilerFactory.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File