Search in sources :

Example 1 with ImageClassLoader

use of com.oracle.svm.hosted.ImageClassLoader in project graal by oracle.

the class NativeImageClassLoaderSupportJDK11OrLater method createModuleLayer.

private ModuleLayer createModuleLayer(Path[] modulePaths, ClassLoader parent) {
    ModuleFinder modulePathsFinder = ModuleFinder.of(modulePaths);
    Set<String> moduleNames = modulePathsFinder.findAll().stream().map(moduleReference -> moduleReference.descriptor().name()).collect(Collectors.toSet());
    /**
     * When building a moduleLayer for the module-path passed to native-image we need to be able
     * to resolve against system modules that are not used by the moduleLayer in which the
     * image-builder got loaded into. To do so we use {@link upgradeAndSystemModuleFinder} as
     * {@code ModuleFinder after} in
     * {@link Configuration#resolve(ModuleFinder, ModuleFinder, Collection)}.
     */
    Configuration configuration = ModuleLayer.boot().configuration().resolve(modulePathsFinder, upgradeAndSystemModuleFinder, moduleNames);
    /**
     * For the modules we want to build an image for, a ModuleLayer is needed that can be
     * accessed with a single classloader so we can use it for {@link ImageClassLoader}.
     */
    return ModuleLayer.defineModulesWithOneLoader(configuration, List.of(ModuleLayer.boot()), parent).layer();
}
Also used : SubstrateOptionsParser(com.oracle.svm.core.option.SubstrateOptionsParser) Arrays(java.util.Arrays) ModuleDescriptor(java.lang.module.ModuleDescriptor) ModuleReference(java.lang.module.ModuleReference) ModuleReader(java.lang.module.ModuleReader) Deque(java.util.Deque) AbstractNativeImageClassLoaderSupport(com.oracle.svm.hosted.AbstractNativeImageClassLoaderSupport) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Pair(org.graalvm.collections.Pair) ModuleFinder(java.lang.module.ModuleFinder) UserError(com.oracle.svm.core.util.UserError) NoSuchElementException(java.util.NoSuchElementException) Method(java.lang.reflect.Method) Path(java.nio.file.Path) OptionValues(org.graalvm.compiler.options.OptionValues) OptionKey(org.graalvm.compiler.options.OptionKey) Set(java.util.Set) IOException(java.io.IOException) Configuration(java.lang.module.Configuration) ModuleSupport(com.oracle.svm.util.ModuleSupport) Collectors(java.util.stream.Collectors) File(java.io.File) LocatableMultiOptionValue(com.oracle.svm.core.option.LocatableMultiOptionValue) VMError(com.oracle.svm.core.util.VMError) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) Paths(java.nio.file.Paths) ForkJoinPool(java.util.concurrent.ForkJoinPool) NativeImageClassLoaderOptions(com.oracle.svm.hosted.NativeImageClassLoaderOptions) Optional(java.util.Optional) Modules(jdk.internal.module.Modules) ArrayDeque(java.util.ArrayDeque) ImageClassLoader(com.oracle.svm.hosted.ImageClassLoader) Collections(java.util.Collections) ModuleFinder(java.lang.module.ModuleFinder) Configuration(java.lang.module.Configuration)

Example 2 with ImageClassLoader

use of com.oracle.svm.hosted.ImageClassLoader in project graal by oracle.

the class DynamicProxyFeature method duringSetup.

@Override
public void duringSetup(DuringSetupAccess a) {
    DuringSetupAccessImpl access = (DuringSetupAccessImpl) a;
    ImageClassLoader imageClassLoader = access.getImageClassLoader();
    DynamicProxySupport dynamicProxySupport = new DynamicProxySupport(imageClassLoader.getClassLoader());
    ImageSingletons.add(DynamicProxyRegistry.class, dynamicProxySupport);
    ConfigurationTypeResolver typeResolver = new ConfigurationTypeResolver("resource configuration", imageClassLoader, NativeImageOptions.AllowIncompleteClasspath.getValue());
    ProxyRegistry proxyRegistry = new ProxyRegistry(typeResolver, dynamicProxySupport, imageClassLoader);
    ImageSingletons.add(ProxyRegistry.class, proxyRegistry);
    ProxyConfigurationParser parser = new ProxyConfigurationParser(proxyRegistry, ConfigurationFiles.Options.StrictConfiguration.getValue());
    loadedConfigurations = ConfigurationParserUtils.parseAndRegisterConfigurations(parser, imageClassLoader, "dynamic proxy", ConfigurationFiles.Options.DynamicProxyConfigurationFiles, ConfigurationFiles.Options.DynamicProxyConfigurationResources, ConfigurationFile.DYNAMIC_PROXY.getFileName());
    proxyCacheField = access.findField(DynamicProxySupport.class, "proxyCache");
}
Also used : DuringSetupAccessImpl(com.oracle.svm.hosted.FeatureImpl.DuringSetupAccessImpl) DynamicProxySupport(com.oracle.svm.reflect.proxy.DynamicProxySupport) DynamicProxyRegistry(com.oracle.svm.core.jdk.proxy.DynamicProxyRegistry) ProxyConfigurationParser(com.oracle.svm.core.configure.ProxyConfigurationParser) ConfigurationTypeResolver(com.oracle.svm.hosted.ConfigurationTypeResolver) ImageClassLoader(com.oracle.svm.hosted.ImageClassLoader)

Example 3 with ImageClassLoader

use of com.oracle.svm.hosted.ImageClassLoader in project graal by oracle.

the class SerializationBuilder method duringSetup.

@Override
public void duringSetup(DuringSetupAccess a) {
    FeatureImpl.DuringSetupAccessImpl access = (FeatureImpl.DuringSetupAccessImpl) a;
    ImageClassLoader imageClassLoader = access.getImageClassLoader();
    ConfigurationTypeResolver typeResolver = new ConfigurationTypeResolver("serialization configuration", imageClassLoader, NativeImageOptions.AllowIncompleteClasspath.getValue());
    SerializationDenyRegistry serializationDenyRegistry = new SerializationDenyRegistry(typeResolver);
    serializationBuilder = new SerializationBuilder(serializationDenyRegistry, access, typeResolver);
    ImageSingletons.add(RuntimeSerializationSupport.class, serializationBuilder);
    SerializationConfigurationParser denyCollectorParser = new SerializationConfigurationParser(serializationDenyRegistry, ConfigurationFiles.Options.StrictConfiguration.getValue());
    ConfigurationParserUtils.parseAndRegisterConfigurations(denyCollectorParser, imageClassLoader, "serialization", ConfigurationFiles.Options.SerializationDenyConfigurationFiles, ConfigurationFiles.Options.SerializationDenyConfigurationResources, ConfigurationFile.SERIALIZATION_DENY.getFileName());
    SerializationConfigurationParser parser = new SerializationConfigurationParser(serializationBuilder, ConfigurationFiles.Options.StrictConfiguration.getValue());
    loadedConfigurations = ConfigurationParserUtils.parseAndRegisterConfigurations(parser, imageClassLoader, "serialization", ConfigurationFiles.Options.SerializationConfigurationFiles, ConfigurationFiles.Options.SerializationConfigurationResources, ConfigurationFile.SERIALIZATION.getFileName());
}
Also used : SerializationConfigurationParser(com.oracle.svm.core.configure.SerializationConfigurationParser) FeatureImpl(com.oracle.svm.hosted.FeatureImpl) ConfigurationTypeResolver(com.oracle.svm.hosted.ConfigurationTypeResolver) ImageClassLoader(com.oracle.svm.hosted.ImageClassLoader)

Example 4 with ImageClassLoader

use of com.oracle.svm.hosted.ImageClassLoader in project graal by oracle.

the class Target_org_graalvm_compiler_truffle_compiler_hotspot_libgraal_TruffleToLibGraalEntryPoints method duringSetup.

@Override
public void duringSetup(DuringSetupAccess access) {
    JNIRuntimeAccess.JNIRuntimeAccessibilitySupport registry = ImageSingletons.lookup(JNIRuntimeAccess.JNIRuntimeAccessibilitySupport.class);
    ImageClassLoader imageClassLoader = ((DuringSetupAccessImpl) access).getImageClassLoader();
    registerJNIConfiguration(registry, imageClassLoader);
    EconomicMap<String, OptionDescriptor> descriptors = EconomicMap.create();
    for (Class<? extends OptionDescriptors> optionsClass : imageClassLoader.findSubclasses(OptionDescriptors.class, false)) {
        if (!Modifier.isAbstract(optionsClass.getModifiers()) && !OptionDescriptorsMap.class.isAssignableFrom(optionsClass)) {
            try {
                for (OptionDescriptor d : optionsClass.getDeclaredConstructor().newInstance()) {
                    if (!(d.getOptionKey() instanceof HostedOptionKey)) {
                        descriptors.put(d.getName(), d);
                    }
                }
            } catch (ReflectiveOperationException ex) {
                throw VMError.shouldNotReachHere(ex);
            }
        }
    }
    OptionsParser.setCachedOptionDescriptors(Collections.singletonList(new OptionDescriptorsMap(descriptors)));
}
Also used : OptionDescriptor(org.graalvm.compiler.options.OptionDescriptor) HostedOptionKey(com.oracle.svm.core.option.HostedOptionKey) DuringSetupAccessImpl(com.oracle.svm.hosted.FeatureImpl.DuringSetupAccessImpl) OptionDescriptorsMap(org.graalvm.compiler.options.OptionDescriptorsMap) JNIRuntimeAccess(com.oracle.svm.core.jni.JNIRuntimeAccess) ImageClassLoader(com.oracle.svm.hosted.ImageClassLoader)

Example 5 with ImageClassLoader

use of com.oracle.svm.hosted.ImageClassLoader in project graal by oracle.

the class ReflectionPlugins method registerClassPlugins.

private void registerClassPlugins(InvocationPlugins plugins) {
    registerFoldInvocationPlugins(plugins, Class.class, "getField", "getMethod", "getConstructor", "getDeclaredField", "getDeclaredMethod", "getDeclaredConstructor");
    Registration r = new Registration(plugins, Class.class);
    r.register(new RequiredInvocationPlugin("forName", String.class) {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode nameNode) {
            return processClassForName(b, targetMethod, nameNode, ConstantNode.forBoolean(true));
        }
    });
    r.register(new RequiredInvocationPlugin("forName", String.class, boolean.class, ClassLoader.class) {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode nameNode, ValueNode initializeNode, ValueNode classLoaderNode) {
            /*
                 * For now, we ignore the ClassLoader parameter. We only intrinsify class names that
                 * are found by the ImageClassLoader, i.e., the application class loader at run
                 * time. We assume that every class loader used at run time delegates to the
                 * application class loader.
                 */
            return processClassForName(b, targetMethod, nameNode, initializeNode);
        }
    });
    r.register(new RequiredInvocationPlugin("getClassLoader", Receiver.class) {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            return processClassGetClassLoader(b, targetMethod, receiver);
        }
    });
}
Also used : GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) Registration(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration) RequiredInvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.RequiredInvocationPlugin) ValueNode(org.graalvm.compiler.nodes.ValueNode) Receiver(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver) ImageClassLoader(com.oracle.svm.hosted.ImageClassLoader) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Aggregations

ImageClassLoader (com.oracle.svm.hosted.ImageClassLoader)5 ConfigurationTypeResolver (com.oracle.svm.hosted.ConfigurationTypeResolver)2 DuringSetupAccessImpl (com.oracle.svm.hosted.FeatureImpl.DuringSetupAccessImpl)2 ProxyConfigurationParser (com.oracle.svm.core.configure.ProxyConfigurationParser)1 SerializationConfigurationParser (com.oracle.svm.core.configure.SerializationConfigurationParser)1 DynamicProxyRegistry (com.oracle.svm.core.jdk.proxy.DynamicProxyRegistry)1 JNIRuntimeAccess (com.oracle.svm.core.jni.JNIRuntimeAccess)1 HostedOptionKey (com.oracle.svm.core.option.HostedOptionKey)1 LocatableMultiOptionValue (com.oracle.svm.core.option.LocatableMultiOptionValue)1 SubstrateOptionsParser (com.oracle.svm.core.option.SubstrateOptionsParser)1 UserError (com.oracle.svm.core.util.UserError)1 VMError (com.oracle.svm.core.util.VMError)1 AbstractNativeImageClassLoaderSupport (com.oracle.svm.hosted.AbstractNativeImageClassLoaderSupport)1 FeatureImpl (com.oracle.svm.hosted.FeatureImpl)1 NativeImageClassLoaderOptions (com.oracle.svm.hosted.NativeImageClassLoaderOptions)1 DynamicProxySupport (com.oracle.svm.reflect.proxy.DynamicProxySupport)1 ModuleSupport (com.oracle.svm.util.ModuleSupport)1 File (java.io.File)1 IOException (java.io.IOException)1 Configuration (java.lang.module.Configuration)1