Search in sources :

Example 1 with HotSpotSignature

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]);
                    }
            }
        }
    }
}
Also used : ConfigurationCondition(org.graalvm.nativeimage.impl.ConfigurationCondition) HashMap(java.util.HashMap) Constructor(java.lang.reflect.Constructor) JavaType(jdk.vm.ci.meta.JavaType) HotSpotSignature(jdk.vm.ci.hotspot.HotSpotSignature) NodeClass(org.graalvm.compiler.graph.NodeClass) TargetClass(com.oracle.svm.core.annotate.TargetClass)

Example 2 with HotSpotSignature

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;
}
Also used : HotSpotBackendFactory(org.graalvm.compiler.hotspot.HotSpotBackendFactory) ForeignCallsProvider(org.graalvm.compiler.core.common.spi.ForeignCallsProvider) AnalysisConstantReflectionProvider(com.oracle.svm.hosted.ameta.AnalysisConstantReflectionProvider) HotSpotJVMCIRuntime(jdk.vm.ci.hotspot.HotSpotJVMCIRuntime) RelocatedPointer(org.graalvm.nativeimage.c.function.RelocatedPointer) SubstrateField(com.oracle.svm.graal.meta.SubstrateField) HotSpotObjectConstant(jdk.vm.ci.hotspot.HotSpotObjectConstant) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) SnippetResolvedJavaType(org.graalvm.compiler.hotspot.SnippetResolvedJavaType) HotSpotResolvedJavaType(jdk.vm.ci.hotspot.HotSpotResolvedJavaType) ResolvedJavaField(jdk.vm.ci.meta.ResolvedJavaField) HotSpotResolvedJavaField(jdk.vm.ci.hotspot.HotSpotResolvedJavaField) SnippetResolvedJavaType(org.graalvm.compiler.hotspot.SnippetResolvedJavaType) NodeClass(org.graalvm.compiler.graph.NodeClass) SnippetReflectionProvider(org.graalvm.compiler.api.replacements.SnippetReflectionProvider) MetricKey(org.graalvm.compiler.debug.MetricKey) SnippetResolvedJavaMethod(org.graalvm.compiler.hotspot.SnippetResolvedJavaMethod) HotSpotSignature(jdk.vm.ci.hotspot.HotSpotSignature) GraalHotSpotVMConfig(org.graalvm.compiler.hotspot.GraalHotSpotVMConfig) SubstrateType(com.oracle.svm.graal.meta.SubstrateType) SubstrateMethod(com.oracle.svm.graal.meta.SubstrateMethod) AnalysisConstantFieldProvider(com.oracle.svm.hosted.ameta.AnalysisConstantFieldProvider) HotSpotResolvedJavaMethod(jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod) UnsupportedFeatureException(com.oracle.graal.pointsto.constraints.UnsupportedFeatureException) Architecture(jdk.vm.ci.code.Architecture) HotSpotResolvedJavaField(jdk.vm.ci.hotspot.HotSpotResolvedJavaField) GraalRuntime(org.graalvm.compiler.api.runtime.GraalRuntime) SubstrateGraalRuntime(com.oracle.svm.graal.SubstrateGraalRuntime) FieldLocationIdentity(org.graalvm.compiler.nodes.FieldLocationIdentity) SubstrateFieldLocationIdentity(com.oracle.svm.core.graal.nodes.SubstrateFieldLocationIdentity) HotSpotResolvedJavaType(jdk.vm.ci.hotspot.HotSpotResolvedJavaType) SubstrateFieldLocationIdentity(com.oracle.svm.core.graal.nodes.SubstrateFieldLocationIdentity) MetaAccessProvider(jdk.vm.ci.meta.MetaAccessProvider) SnippetResolvedJavaMethod(org.graalvm.compiler.hotspot.SnippetResolvedJavaMethod) HotSpotResolvedJavaMethod(jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Aggregations

HotSpotSignature (jdk.vm.ci.hotspot.HotSpotSignature)2 NodeClass (org.graalvm.compiler.graph.NodeClass)2 UnsupportedFeatureException (com.oracle.graal.pointsto.constraints.UnsupportedFeatureException)1 TargetClass (com.oracle.svm.core.annotate.TargetClass)1 SubstrateFieldLocationIdentity (com.oracle.svm.core.graal.nodes.SubstrateFieldLocationIdentity)1 SubstrateGraalRuntime (com.oracle.svm.graal.SubstrateGraalRuntime)1 SubstrateField (com.oracle.svm.graal.meta.SubstrateField)1 SubstrateMethod (com.oracle.svm.graal.meta.SubstrateMethod)1 SubstrateType (com.oracle.svm.graal.meta.SubstrateType)1 AnalysisConstantFieldProvider (com.oracle.svm.hosted.ameta.AnalysisConstantFieldProvider)1 AnalysisConstantReflectionProvider (com.oracle.svm.hosted.ameta.AnalysisConstantReflectionProvider)1 Constructor (java.lang.reflect.Constructor)1 HashMap (java.util.HashMap)1 Architecture (jdk.vm.ci.code.Architecture)1 HotSpotJVMCIRuntime (jdk.vm.ci.hotspot.HotSpotJVMCIRuntime)1 HotSpotObjectConstant (jdk.vm.ci.hotspot.HotSpotObjectConstant)1 HotSpotResolvedJavaField (jdk.vm.ci.hotspot.HotSpotResolvedJavaField)1 HotSpotResolvedJavaMethod (jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod)1 HotSpotResolvedJavaType (jdk.vm.ci.hotspot.HotSpotResolvedJavaType)1 JavaType (jdk.vm.ci.meta.JavaType)1