Search in sources :

Example 1 with OptionDescriptor

use of org.graalvm.compiler.options.OptionDescriptor 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 OptionDescriptor

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

the class HotSpotGraalMBean method getMBeanInfo.

@Override
public javax.management.MBeanInfo getMBeanInfo() {
    List<javax.management.MBeanAttributeInfo> attrs = new ArrayList<>();
    for (OptionDescriptor descr : allOptionDescriptors()) {
        attrs.add(new javax.management.MBeanAttributeInfo(descr.getName(), descr.getOptionValueType().getName(), descr.getHelp(), true, true, false));
    }
    javax.management.MBeanOperationInfo[] ops = { new javax.management.MBeanOperationInfo("dumpMethod", "Enable IGV dumps for provided method", new javax.management.MBeanParameterInfo[] { new javax.management.MBeanParameterInfo("className", "java.lang.String", "Class to observe"), new javax.management.MBeanParameterInfo("methodName", "java.lang.String", "Method to observe") }, "void", javax.management.MBeanOperationInfo.ACTION), new javax.management.MBeanOperationInfo("dumpMethod", "Enable IGV dumps for provided method", new javax.management.MBeanParameterInfo[] { new javax.management.MBeanParameterInfo("className", "java.lang.String", "Class to observe"), new javax.management.MBeanParameterInfo("methodName", "java.lang.String", "Method to observe"), new javax.management.MBeanParameterInfo("filter", "java.lang.String", "The parameter for Dump option") }, "void", javax.management.MBeanOperationInfo.ACTION), new javax.management.MBeanOperationInfo("dumpMethod", "Enable IGV dumps for provided method", new javax.management.MBeanParameterInfo[] { new javax.management.MBeanParameterInfo("className", "java.lang.String", "Class to observe"), new javax.management.MBeanParameterInfo("methodName", "java.lang.String", "Method to observe"), new javax.management.MBeanParameterInfo("filter", "java.lang.String", "The parameter for Dump option"), new javax.management.MBeanParameterInfo("host", "java.lang.String", "The host where the IGV tool is running at"), new javax.management.MBeanParameterInfo("port", "int", "The port where the IGV tool is listening at") }, "void", javax.management.MBeanOperationInfo.ACTION) };
    return new javax.management.MBeanInfo(HotSpotGraalMBean.class.getName(), "Graal", attrs.toArray(new javax.management.MBeanAttributeInfo[attrs.size()]), null, ops, null);
}
Also used : OptionDescriptor(org.graalvm.compiler.options.OptionDescriptor) ArrayList(java.util.ArrayList)

Example 3 with OptionDescriptor

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

the class RuntimeOptionParser method lookupOption.

public OptionKey<?> lookupOption(String name, Collection<OptionDescriptor> fuzzyMatches) {
    OptionDescriptor desc = sortedOptions.get(name);
    OptionKey<?> option;
    if (desc == null) {
        if (fuzzyMatches != null) {
            OptionsParser.collectFuzzyMatches(sortedOptions.values(), name, fuzzyMatches);
        }
        option = null;
    } else {
        option = desc.getOptionKey();
    }
    return option;
}
Also used : OptionDescriptor(org.graalvm.compiler.options.OptionDescriptor)

Example 4 with OptionDescriptor

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

the class Target_org_graalvm_compiler_options_OptionKey method set.

@Override
public void set(String optionName, Object value) {
    if (setXOption(optionName)) {
        return;
    }
    if (!RuntimeOptionValues.singleton().getAllOptionNames().contains(optionName)) {
        throw new RuntimeException("Unknown option: " + optionName);
    }
    Optional<OptionDescriptor> descriptor = RuntimeOptionParser.singleton().getDescriptor(optionName);
    if (descriptor.isPresent()) {
        OptionDescriptor desc = descriptor.get();
        Class<?> valueType = value.getClass();
        if (desc.getOptionValueType().isAssignableFrom(valueType)) {
            RuntimeOptionValues.singleton().update(desc.getOptionKey(), value);
        } else {
            throw new RuntimeException("Invalid type of option '" + optionName + "': required " + desc.getOptionValueType().getSimpleName() + ", provided " + valueType);
        }
    }
}
Also used : OptionDescriptor(org.graalvm.compiler.options.OptionDescriptor)

Example 5 with OptionDescriptor

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

the class Target_org_graalvm_compiler_options_OptionKey method getOptions.

@Override
public OptionDescriptors getOptions() {
    Collection<OptionDescriptor> descriptors = RuntimeOptionParser.singleton().getDescriptors();
    List<org.graalvm.options.OptionDescriptor> graalvmDescriptors = new ArrayList<>(descriptors.size());
    for (OptionDescriptor descriptor : descriptors) {
        org.graalvm.options.OptionDescriptor.Builder builder = org.graalvm.options.OptionDescriptor.newBuilder(asGraalVMOptionKey(descriptor), descriptor.getName());
        builder.help(descriptor.getHelp());
        graalvmDescriptors.add(builder.build());
    }
    return OptionDescriptors.create(graalvmDescriptors);
}
Also used : OptionDescriptor(org.graalvm.compiler.options.OptionDescriptor) ArrayList(java.util.ArrayList)

Aggregations

OptionDescriptor (org.graalvm.compiler.options.OptionDescriptor)10 ArrayList (java.util.ArrayList)5 HashSet (java.util.HashSet)2 HostedOptionKey (com.oracle.svm.core.option.HostedOptionKey)1 InterruptImageBuilding (com.oracle.svm.core.util.InterruptImageBuilding)1 OptionDescriptors (org.graalvm.compiler.options.OptionDescriptors)1 OptionKey (org.graalvm.compiler.options.OptionKey)1 OptionType (org.graalvm.compiler.options.OptionType)1 Platforms (org.graalvm.nativeimage.Platforms)1