Search in sources :

Example 1 with OptionDescriptors

use of org.graalvm.compiler.options.OptionDescriptors in project graal by oracle.

the class LazyInitializationTest method checkAllowedGraalClasses.

private void checkAllowedGraalClasses(List<String> loadedGraalClassNames) {
    HashSet<Class<?>> whitelist = new HashSet<>();
    List<Class<?>> loadedGraalClasses = new ArrayList<>();
    for (String name : loadedGraalClassNames) {
        try {
            loadedGraalClasses.add(Class.forName(name));
        } catch (ClassNotFoundException e) {
            Assert.fail("loaded class " + name + " not found");
        }
    }
    /*
         * Look for all loaded OptionDescriptors classes, and whitelist the classes that declare the
         * options. They may be loaded by the option parsing code.
         */
    for (Class<?> cls : loadedGraalClasses) {
        if (OptionDescriptors.class.isAssignableFrom(cls)) {
            try {
                OptionDescriptors optionDescriptors = cls.asSubclass(OptionDescriptors.class).newInstance();
                for (OptionDescriptor option : optionDescriptors) {
                    whitelist.add(option.getDeclaringClass());
                    whitelist.add(option.getOptionValueType());
                    whitelist.add(option.getOptionType().getDeclaringClass());
                }
            } catch (ReflectiveOperationException e) {
            }
        }
    }
    whitelist.add(Cancellable.class);
    List<String> forbiddenClasses = new ArrayList<>();
    for (Class<?> cls : loadedGraalClasses) {
        if (whitelist.contains(cls)) {
            continue;
        }
        if (!isGraalClassAllowed(cls)) {
            forbiddenClasses.add(cls.getName());
        }
    }
    if (!forbiddenClasses.isEmpty()) {
        Assert.fail("loaded forbidden classes:\n    " + forbiddenClasses.stream().collect(Collectors.joining("\n    ")) + "\n");
    }
}
Also used : OptionDescriptor(org.graalvm.compiler.options.OptionDescriptor) ArrayList(java.util.ArrayList) OptionDescriptors(org.graalvm.compiler.options.OptionDescriptors) HashSet(java.util.HashSet)

Example 2 with OptionDescriptors

use of org.graalvm.compiler.options.OptionDescriptors in project graal by oracle.

the class CompileTheWorld method loadOptions.

public static OptionValues loadOptions(OptionValues initialValues) {
    EconomicMap<OptionKey<?>, Object> values = OptionValues.newOptionMap();
    List<OptionDescriptors> loader = singletonList(DESCRIPTORS);
    OptionsParser.parseOptions(extractEntries(System.getProperties(), "CompileTheWorld.", true), values, loader);
    OptionValues options = new OptionValues(initialValues, values);
    if (Options.Help.getValue(options)) {
        options.printHelp(loader, System.out, "CompileTheWorld.");
        System.exit(0);
    }
    return options;
}
Also used : OptionValues(org.graalvm.compiler.options.OptionValues) OptionKey(org.graalvm.compiler.options.OptionKey) ReflectionOptionDescriptors(org.graalvm.compiler.core.test.ReflectionOptionDescriptors) OptionDescriptors(org.graalvm.compiler.options.OptionDescriptors)

Example 3 with OptionDescriptors

use of org.graalvm.compiler.options.OptionDescriptors in project graal by oracle.

the class HotSpotGraalOptionValues method initializeOptions.

/**
 * Global options. The values for these options are initialized by parsing the file denoted by
 * the {@code VM.getSavedProperty(String) saved} system property named
 * {@value #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 OptionValues initializeOptions() {
    EconomicMap<OptionKey<?>, Object> values = OptionValues.newOptionMap();
    try (InitTimer t = timer("InitializeOptions")) {
        Iterable<OptionDescriptors> loader = OptionsParser.getOptionsLoader();
        Map<String, String> savedProps = jdk.vm.ci.services.Services.getSavedProperties();
        String optionsFile = savedProps.get(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);
                    EconomicMap<String, String> optionSettings = EconomicMap.create();
                    for (Map.Entry<Object, Object> e : props.entrySet()) {
                        optionSettings.put((String) e.getKey(), (String) e.getValue());
                    }
                    try {
                        OptionsParser.parseOptions(optionSettings, values, loader);
                    } catch (Throwable e) {
                        throw new InternalError("Error parsing an option from " + graalOptions, e);
                    }
                } catch (IOException e) {
                    throw new InternalError("Error reading " + graalOptions, e);
                }
            }
        }
        EconomicMap<String, String> optionSettings = EconomicMap.create();
        for (Map.Entry<String, String> e : savedProps.entrySet()) {
            String name = 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)) {
                // Ignore well known properties that do not denote an option
                } else {
                    String value = e.getValue();
                    optionSettings.put(name.substring(GRAAL_OPTION_PROPERTY_PREFIX.length()), value);
                }
            }
        }
        OptionsParser.parseOptions(optionSettings, values, loader);
        return new OptionValues(values);
    }
}
Also used : InitTimer(jdk.vm.ci.common.InitTimer) OptionValues(org.graalvm.compiler.options.OptionValues) OptionDescriptors(org.graalvm.compiler.options.OptionDescriptors) IOException(java.io.IOException) Properties(java.util.Properties) OptionKey(org.graalvm.compiler.options.OptionKey) FileReader(java.io.FileReader) File(java.io.File) EconomicMap(org.graalvm.collections.EconomicMap) Map(java.util.Map)

Aggregations

OptionDescriptors (org.graalvm.compiler.options.OptionDescriptors)3 OptionKey (org.graalvm.compiler.options.OptionKey)2 OptionValues (org.graalvm.compiler.options.OptionValues)2 File (java.io.File)1 FileReader (java.io.FileReader)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Properties (java.util.Properties)1 InitTimer (jdk.vm.ci.common.InitTimer)1 EconomicMap (org.graalvm.collections.EconomicMap)1 ReflectionOptionDescriptors (org.graalvm.compiler.core.test.ReflectionOptionDescriptors)1 OptionDescriptor (org.graalvm.compiler.options.OptionDescriptor)1