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