use of jdk.vm.ci.hotspot.HotSpotSignature in project graal by oracle.
the class Target_org_graalvm_compiler_truffle_compiler_hotspot_libgraal_TruffleToLibGraalEntryPoints method registerJNIConfiguration.
private static void registerJNIConfiguration(JNIRuntimeAccess.JNIRuntimeAccessibilitySupport registry, ImageClassLoader loader) {
try (JNIConfigSource source = new JNIConfigSource(loader)) {
Map<String, Class<?>> classes = new HashMap<>();
ConfigurationCondition condition = ConfigurationCondition.alwaysTrue();
for (String line : source.lines) {
source.lineNo++;
String[] tokens = line.split(" ");
source.check(tokens.length >= 2, "Expected at least 2 tokens");
String className = tokens[1].replace('/', '.');
Class<?> clazz = classes.get(className);
if (clazz == null) {
clazz = source.findClass(className);
registry.register(condition, clazz);
registry.register(condition, Array.newInstance(clazz, 0).getClass());
classes.put(className, clazz);
}
switch(tokens[0]) {
case "field":
{
source.check(tokens.length == 4, "Expected 4 tokens for a field");
String fieldName = tokens[2];
try {
registry.register(condition, false, clazz.getDeclaredField(fieldName));
} catch (NoSuchFieldException e) {
throw source.error("Field %s.%s not found", clazz.getTypeName(), fieldName);
} catch (NoClassDefFoundError e) {
throw source.error("Could not register field %s.%s: %s", clazz.getTypeName(), fieldName, e);
}
break;
}
case "method":
{
source.check(tokens.length == 4, "Expected 4 tokens for a method");
String methodName = tokens[2];
HotSpotSignature descriptor = new HotSpotSignature(runtime(), tokens[3]);
Class<?>[] parameters = //
Arrays.asList(descriptor.toParameterTypes(null)).stream().map(JavaType::toClassName).map(//
source::findClass).collect(//
Collectors.toList()).toArray(new Class<?>[descriptor.getParameterCount(false)]);
try {
if ("<init>".equals(methodName)) {
Constructor<?> cons = clazz.getDeclaredConstructor(parameters);
registry.register(condition, false, cons);
if (Throwable.class.isAssignableFrom(clazz) && !Modifier.isAbstract(clazz.getModifiers())) {
if (usedInTranslatedException(parameters)) {
RuntimeReflection.register(clazz);
RuntimeReflection.register(cons);
}
}
} else {
registry.register(condition, false, clazz.getDeclaredMethod(methodName, parameters));
}
} catch (NoSuchMethodException e) {
throw source.error("Method %s.%s%s not found: %s", clazz.getTypeName(), methodName, descriptor, e);
} catch (NoClassDefFoundError e) {
throw source.error("Could not register method %s.%s%s: %s", clazz.getTypeName(), methodName, descriptor, e);
}
break;
}
case "class":
{
source.check(tokens.length == 2, "Expected 2 tokens for a class");
break;
}
default:
{
throw source.error("Unexpected token: " + tokens[0]);
}
}
}
}
}
use of jdk.vm.ci.hotspot.HotSpotSignature in project graal by oracle.
the class GraalObjectReplacer method apply.
@Override
public Object apply(Object source) {
if (source == null) {
return null;
}
Object dest = source;
if (source instanceof RelocatedPointer) {
return dest;
}
if (source instanceof SnippetResolvedJavaMethod || source instanceof SnippetResolvedJavaType) {
return source;
}
if (source instanceof MetaAccessProvider) {
dest = providerReplacements.getMetaAccessProvider();
} else if (source instanceof HotSpotJVMCIRuntime) {
throw new UnsupportedFeatureException("HotSpotJVMCIRuntime should not appear in the image: " + source);
} else if (source instanceof GraalHotSpotVMConfig) {
throw new UnsupportedFeatureException("GraalHotSpotVMConfig should not appear in the image: " + source);
} else if (source instanceof HotSpotBackendFactory) {
HotSpotBackendFactory factory = (HotSpotBackendFactory) source;
Architecture hostArch = HotSpotJVMCIRuntime.runtime().getHostJVMCIBackend().getTarget().arch;
if (!factory.getArchitecture().equals(hostArch.getClass())) {
throw new UnsupportedFeatureException("Non-host archtecture HotSpotBackendFactory should not appear in the image: " + source);
}
} else if (source instanceof GraalRuntime) {
dest = sGraalRuntime;
} else if (source instanceof AnalysisConstantReflectionProvider) {
dest = providerReplacements.getConstantReflectionProvider();
} else if (source instanceof AnalysisConstantFieldProvider) {
dest = providerReplacements.getConstantFieldProvider();
} else if (source instanceof ForeignCallsProvider) {
dest = providerReplacements.getForeignCallsProvider();
} else if (source instanceof SnippetReflectionProvider) {
dest = providerReplacements.getSnippetReflectionProvider();
} else if (source instanceof MetricKey) {
/* Ensure lazily initialized name fields are computed. */
((MetricKey) source).getName();
} else if (source instanceof NodeClass) {
/* Ensure lazily initialized shortName field is computed. */
((NodeClass<?>) source).shortName();
} else if (source instanceof HotSpotResolvedJavaMethod) {
throw new UnsupportedFeatureException(source.toString());
} else if (source instanceof HotSpotResolvedJavaField) {
throw new UnsupportedFeatureException(source.toString());
} else if (source instanceof HotSpotResolvedJavaType) {
throw new UnsupportedFeatureException(source.toString());
} else if (source instanceof HotSpotSignature) {
throw new UnsupportedFeatureException(source.toString());
} else if (source instanceof HotSpotObjectConstant) {
throw new UnsupportedFeatureException(source.toString());
} else if (source instanceof ResolvedJavaMethod && !(source instanceof SubstrateMethod)) {
dest = createMethod((ResolvedJavaMethod) source);
} else if (source instanceof ResolvedJavaField && !(source instanceof SubstrateField)) {
dest = createField((ResolvedJavaField) source);
} else if (source instanceof ResolvedJavaType && !(source instanceof SubstrateType)) {
dest = createType((ResolvedJavaType) source);
} else if (source instanceof FieldLocationIdentity && !(source instanceof SubstrateFieldLocationIdentity)) {
dest = createFieldLocationIdentity((FieldLocationIdentity) source);
}
assert dest != null;
String className = dest.getClass().getName();
assert SubstrateUtil.isBuildingLibgraal() || !className.contains(".hotspot.") || className.contains(".svm.jtt.hotspot.") : "HotSpot object in image " + className;
assert !className.contains(".analysis.meta.") : "Analysis meta object in image " + className;
assert !className.contains(".hosted.meta.") : "Hosted meta object in image " + className;
assert !SubstrateUtil.isBuildingLibgraal() || !className.contains(".svm.hosted.snippets.") : "Hosted snippet object in image " + className;
return dest;
}
Aggregations