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");
}
}
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;
}
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);
}
}
Aggregations