Search in sources :

Example 61 with ResolvedJavaType

use of jdk.vm.ci.meta.ResolvedJavaType in project graal by oracle.

the class SubstrateGraphBuilderPlugins method registerKnownIntrinsicsPlugins.

private static void registerKnownIntrinsicsPlugins(InvocationPlugins plugins, boolean analysis) {
    Registration r = new Registration(plugins, KnownIntrinsics.class);
    r.register0("heapBase", new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            b.addPush(JavaKind.Object, ReadRegisterFixedNode.forHeapBase());
            return true;
        }
    });
    r.register1("readArrayLength", Object.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode array) {
            b.addPush(JavaKind.Int, new ArrayLengthNode(array));
            return true;
        }
    });
    r.register1("readHub", Object.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode object) {
            ValueNode nonNullObject = b.nullCheckedValue(object);
            b.addPush(JavaKind.Object, new LoadHubNode(b.getStampProvider(), nonNullObject));
            return true;
        }
    });
    r.register3("formatObject", Pointer.class, Class.class, boolean.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode memory, ValueNode hub, ValueNode rememberedSet) {
            b.addPush(JavaKind.Object, new FormatObjectNode(memory, hub, rememberedSet));
            return true;
        }
    });
    r.register5("formatArray", Pointer.class, Class.class, int.class, boolean.class, boolean.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode memory, ValueNode hub, ValueNode length, ValueNode rememberedSet, ValueNode unaligned) {
            b.addPush(JavaKind.Object, new FormatArrayNode(memory, hub, length, rememberedSet, unaligned));
            return true;
        }
    });
    r.register2("unsafeCast", Object.class, Class.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode object, ValueNode toTypeNode) {
            /*
                 * We need to make sure that the updated type information does not flow up, because
                 * it can depend on any condition before (and we do not know which condition, so we
                 * cannot anchor at a particular block).
                 */
            ResolvedJavaType toType = typeValue(b.getConstantReflection(), b, targetMethod, toTypeNode, "toType");
            TypeReference toTypeRef = TypeReference.createTrustedWithoutAssumptions(toType);
            b.addPush(JavaKind.Object, new FixedValueAnchorNode(object, StampFactory.object(toTypeRef)));
            return true;
        }
    });
    r.register1("nonNullPointer", Pointer.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode object) {
            b.addPush(JavaKind.Object, new PiNode(object, nonZeroWord()));
            return true;
        }
    });
    r.register0("readStackPointer", new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            b.addPush(JavaKind.Object, new ReadStackPointerNode());
            return true;
        }
    });
    r.register1("writeStackPointer", Pointer.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
            b.add(new WriteStackPointerNode(value));
            return true;
        }
    });
    r.register0("readInstructionPointer", new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            b.addPush(JavaKind.Object, new ReadInstructionPointerNode());
            return true;
        }
    });
    r.register0("readCallerStackPointer", new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            b.addPush(JavaKind.Object, new ReadCallerStackPointerNode());
            return true;
        }
    });
    r.register0("readReturnAddress", new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            b.addPush(JavaKind.Object, new ReadReturnAddressNode());
            return true;
        }
    });
    r.register3("farReturn", Object.class, Pointer.class, CodePointer.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode result, ValueNode sp, ValueNode ip) {
            b.add(new FarReturnNode(result, sp, ip));
            return true;
        }
    });
    r.register0("testDeoptimize", new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            b.add(new TestDeoptimizeNode());
            return true;
        }
    });
    r.register0("isDeoptimizationTarget", new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            if (b.getGraph().method() instanceof SharedMethod) {
                SharedMethod method = (SharedMethod) b.getGraph().method();
                if (method.isDeoptTarget()) {
                    b.addPush(JavaKind.Boolean, ConstantNode.forBoolean(true));
                } else {
                    b.addPush(JavaKind.Boolean, ConstantNode.forBoolean(false));
                }
            } else {
                // In analysis the value is always true.
                b.addPush(JavaKind.Boolean, ConstantNode.forBoolean(true));
            }
            return true;
        }
    });
    r.register2("convertUnknownValue", Object.class, Class.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode object, ValueNode typeNode) {
            ResolvedJavaType type = typeValue(b.getConstantReflection(), b, targetMethod, typeNode, "type");
            TypeReference typeRef = TypeReference.createTrustedWithoutAssumptions(type);
            Stamp stamp = StampFactory.object(typeRef);
            if (analysis) {
                b.addPush(JavaKind.Object, new ConvertUnknownValueNode(object, stamp));
            } else {
                b.addPush(JavaKind.Object, PiNode.create(object, stamp));
            }
            return true;
        }
    });
}
Also used : FixedValueAnchorNode(org.graalvm.compiler.nodes.extended.FixedValueAnchorNode) TestDeoptimizeNode(com.oracle.svm.core.graal.nodes.TestDeoptimizeNode) DynamicPiNode(org.graalvm.compiler.nodes.DynamicPiNode) PiNode(org.graalvm.compiler.nodes.PiNode) ConvertUnknownValueNode(com.oracle.graal.pointsto.nodes.ConvertUnknownValueNode) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) Registration(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration) FarReturnNode(com.oracle.svm.core.graal.nodes.FarReturnNode) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) ReadStackPointerNode(com.oracle.svm.core.graal.nodes.ReadStackPointerNode) TypeReference(org.graalvm.compiler.core.common.type.TypeReference) ArrayLengthNode(org.graalvm.compiler.nodes.java.ArrayLengthNode) ReadCallerStackPointerNode(com.oracle.svm.core.graal.nodes.ReadCallerStackPointerNode) WriteStackPointerNode(com.oracle.svm.core.graal.nodes.WriteStackPointerNode) LoadHubNode(org.graalvm.compiler.nodes.extended.LoadHubNode) Stamp(org.graalvm.compiler.core.common.type.Stamp) IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp) Receiver(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver) ReadInstructionPointerNode(com.oracle.svm.core.graal.nodes.ReadInstructionPointerNode) ReadReturnAddressNode(com.oracle.svm.core.graal.nodes.ReadReturnAddressNode) FormatObjectNode(com.oracle.svm.core.graal.nodes.FormatObjectNode) FormatArrayNode(com.oracle.svm.core.graal.nodes.FormatArrayNode) GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) StackValueNode(com.oracle.svm.core.graal.stackvalue.StackValueNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) ConvertUnknownValueNode(com.oracle.graal.pointsto.nodes.ConvertUnknownValueNode) SharedMethod(com.oracle.svm.core.meta.SharedMethod) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 62 with ResolvedJavaType

use of jdk.vm.ci.meta.ResolvedJavaType in project graal by oracle.

the class AnnotationSubstitutionProcessor method handleSubstitutionClass.

private void handleSubstitutionClass(Class<?> annotatedClass, Class<?> originalClass) {
    // Not sure what happens if the target class is in a hierarchy - so prohibit that for now.
    guarantee(annotatedClass.isInterface() == originalClass.isInterface(), "if original is interface, target must also be interface: %s", annotatedClass);
    guarantee(originalClass.getSuperclass() == Object.class || originalClass.isInterface(), "target class must inherit directly from Object: %s", originalClass);
    ResolvedJavaType original = metaAccess.lookupJavaType(originalClass);
    ResolvedJavaType annotated = metaAccess.lookupJavaType(annotatedClass);
    for (int i = 0; i < ARRAY_DIMENSIONS; i++) {
        ResolvedJavaType substitution = new SubstitutionType(original, annotated);
        register(typeSubstitutions, annotated, original, substitution);
        original = original.getArrayClass();
        annotated = annotated.getArrayClass();
    }
    for (Method m : annotatedClass.getDeclaredMethods()) {
        handleAnnotatedMethodInSubstitutionClass(m, originalClass);
    }
    for (Constructor<?> c : annotatedClass.getDeclaredConstructors()) {
        handleAnnotatedMethodInSubstitutionClass(c, originalClass);
    }
    for (Method m : originalClass.getDeclaredMethods()) {
        handleOriginalMethodInSubstitutionClass(m);
    }
    for (Constructor<?> c : originalClass.getDeclaredConstructors()) {
        handleOriginalMethodInSubstitutionClass(c);
    }
    for (Field f : originalClass.getDeclaredFields()) {
        registerAsDeleted(null, metaAccess.lookupJavaField(f), SUBSTITUTION_DELETE);
    }
    for (Field f : annotatedClass.getDeclaredFields()) {
        ResolvedJavaField field = metaAccess.lookupJavaField(f);
        ResolvedJavaField alias = fieldValueRecomputation(annotatedClass, field, field, f);
        if (!alias.equals(field)) {
            register(fieldSubstitutions, field, null, alias);
        }
    }
}
Also used : AnnotationSubstitutionType(com.oracle.svm.hosted.annotation.AnnotationSubstitutionType) ResolvedJavaField(jdk.vm.ci.meta.ResolvedJavaField) Field(java.lang.reflect.Field) AnalysisField(com.oracle.graal.pointsto.meta.AnalysisField) Method(java.lang.reflect.Method) CustomSubstitutionMethod(com.oracle.svm.hosted.annotation.CustomSubstitutionMethod) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) ResolvedJavaField(jdk.vm.ci.meta.ResolvedJavaField)

Example 63 with ResolvedJavaType

use of jdk.vm.ci.meta.ResolvedJavaType in project graal by oracle.

the class AnnotationSubstitutionProcessor method handleFieldInAliasClass.

private void handleFieldInAliasClass(Field annotatedField, Class<?> originalClass) {
    if (!NativeImageGenerator.includedIn(ImageSingletons.lookup(Platform.class), lookupAnnotation(annotatedField, Platforms.class))) {
        return;
    }
    ResolvedJavaField annotated = metaAccess.lookupJavaField(annotatedField);
    Delete deleteAnnotation = lookupAnnotation(annotatedField, Delete.class);
    Alias aliasAnnotation = lookupAnnotation(annotatedField, Alias.class);
    Inject injectAnnotation = lookupAnnotation(annotatedField, Inject.class);
    int numAnnotations = (deleteAnnotation != null ? 1 : 0) + (aliasAnnotation != null ? 1 : 0) + (injectAnnotation != null ? 1 : 0);
    if (numAnnotations == 0) {
        guarantee(annotatedField.getName().equals("$assertionsDisabled"), "One of @Delete, @Alias, or @Inject must be used: %s", annotatedField);
        /*
             * The field $assertionsDisabled can be present in the original class, but does not have
             * to. We treat it like an optional @Alias fields without field value recomputation.
             */
        ResolvedJavaField original = findOriginalField(annotatedField, originalClass, true);
        if (original != null) {
            register(fieldSubstitutions, annotated, null, original);
        }
        return;
    }
    guarantee(numAnnotations == 1, "Only one of @Delete, @Alias, or @Inject can be used: %s", annotatedField);
    if (injectAnnotation != null) {
        guarantee(!annotated.isStatic(), "@Inject field must not be static: %s", annotated);
        ResolvedJavaField injected = fieldValueRecomputation(originalClass, annotated, annotated, annotatedField);
        register(fieldSubstitutions, annotated, null, injected);
        ResolvedJavaType original = metaAccess.lookupJavaType(originalClass);
        InjectedFieldsType substitution;
        if (typeSubstitutions.get(original) instanceof InjectedFieldsType) {
            substitution = (InjectedFieldsType) typeSubstitutions.get(original);
            register(typeSubstitutions, annotated.getDeclaringClass(), original, substitution);
        } else {
            substitution = new InjectedFieldsType(original);
            register(typeSubstitutions, annotated.getDeclaringClass(), original, substitution);
        }
        substitution.addInjectedField(injected);
    } else {
        ResolvedJavaField original = findOriginalField(annotatedField, originalClass, false);
        if (original == null) {
            return;
        }
        guarantee(annotated.isStatic() == original.isStatic(), "Static modifier mismatch: %s, %s", annotated, original);
        guarantee(annotated.getJavaKind() == original.getJavaKind(), "Type mismatch: %s, %s", annotated, original);
        if (deleteAnnotation != null) {
            registerAsDeleted(annotated, original, deleteAnnotation);
        } else {
            ResolvedJavaField alias = fieldValueRecomputation(originalClass, original, annotated, annotatedField);
            register(fieldSubstitutions, annotated, original, alias);
        }
    }
}
Also used : Delete(com.oracle.svm.core.annotate.Delete) Inject(com.oracle.svm.core.annotate.Inject) Alias(com.oracle.svm.core.annotate.Alias) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) ResolvedJavaField(jdk.vm.ci.meta.ResolvedJavaField)

Example 64 with ResolvedJavaType

use of jdk.vm.ci.meta.ResolvedJavaType in project graal by oracle.

the class NativeBootImage method writeMethodHeader.

private void writeMethodHeader(HostedMethod m, CSourceCodeWriter writer, boolean dynamic) {
    assert Modifier.isStatic(m.getModifiers()) : "Published methods that go into the header must be static.";
    CEntryPointData cEntryPointData = (CEntryPointData) m.getWrapped().getEntryPointData();
    String docComment = cEntryPointData.getDocumentation();
    if (docComment != null && !docComment.isEmpty()) {
        writer.appendln("/*");
        Arrays.stream(docComment.split("\n")).forEach(l -> writer.appendln(" * " + l));
        writer.appendln(" */");
    }
    if (dynamic) {
        writer.append("typedef ");
    }
    writer.append(CSourceCodeWriter.findCTypeName(metaAccess, nativeLibs, (ResolvedJavaType) m.getSignature().getReturnType(m.getDeclaringClass())));
    writer.append(" ");
    assert !cEntryPointData.getSymbolName().isEmpty();
    if (dynamic) {
        writer.append("(*").append(cEntryPointData.getSymbolName()).append("_fn_t)");
    } else {
        writer.append(cEntryPointData.getSymbolName());
    }
    writer.append("(");
    String sep = "";
    for (int i = 0; i < m.getSignature().getParameterCount(false); i++) {
        writer.append(sep);
        sep = ", ";
        writer.append(CSourceCodeWriter.findCTypeName(metaAccess, nativeLibs, (ResolvedJavaType) m.getSignature().getParameterType(i, m.getDeclaringClass())));
        Parameter param = m.getParameters()[i];
        if (param.isNamePresent()) {
            writer.append(" ");
            writer.append(param.getName());
        }
    }
    writer.appendln(");");
    writer.appendln();
}
Also used : CEntryPointData(com.oracle.svm.hosted.code.CEntryPointData) Parameter(jdk.vm.ci.meta.ResolvedJavaMethod.Parameter) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType)

Example 65 with ResolvedJavaType

use of jdk.vm.ci.meta.ResolvedJavaType in project graal by oracle.

the class CInterfaceEnumTool method invokeEnumValue.

private InvokeNode invokeEnumValue(GraphBuilderTool b, CallTargetFactory callTargetFactory, FrameStateBuilder frameState, int bci, EnumInfo enumInfo, ResolvedJavaMethod valueMethod, ValueNode arg) {
    ResolvedJavaType returnType = (ResolvedJavaType) valueMethod.getSignature().getReturnType(null);
    ValueNode[] args = new ValueNode[2];
    args[0] = ConstantNode.forConstant(snippetReflection.forObject(enumInfo.getRuntimeData()), b.getMetaAccess(), b.getGraph());
    args[1] = arg;
    StampPair returnStamp = StampFactory.forDeclaredType(null, returnType, false);
    MethodCallTargetNode callTargetNode = b.append(callTargetFactory.createMethodCallTarget(InvokeKind.Virtual, valueMethod, args, returnStamp, bci));
    Stamp invokeStamp = StampFactory.forKind(returnType.getJavaKind());
    InvokeNode invoke = b.append(new InvokeNode(callTargetNode, bci, invokeStamp));
    frameState.push(returnType.getJavaKind(), invoke);
    FrameState stateWithInvoke = frameState.create(bci, invoke);
    frameState.pop(returnType.getJavaKind());
    invoke.setStateAfter(stateWithInvoke);
    return invoke;
}
Also used : MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) ObjectStamp(org.graalvm.compiler.core.common.type.ObjectStamp) Stamp(org.graalvm.compiler.core.common.type.Stamp) ValueNode(org.graalvm.compiler.nodes.ValueNode) StampPair(org.graalvm.compiler.core.common.type.StampPair) InvokeNode(org.graalvm.compiler.nodes.InvokeNode) FrameState(org.graalvm.compiler.nodes.FrameState) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType)

Aggregations

ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)161 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)63 ValueNode (org.graalvm.compiler.nodes.ValueNode)60 JavaKind (jdk.vm.ci.meta.JavaKind)25 JavaType (jdk.vm.ci.meta.JavaType)25 MethodCallTargetNode (org.graalvm.compiler.nodes.java.MethodCallTargetNode)19 Stamp (org.graalvm.compiler.core.common.type.Stamp)17 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)17 MetaAccessProvider (jdk.vm.ci.meta.MetaAccessProvider)16 ObjectStamp (org.graalvm.compiler.core.common.type.ObjectStamp)13 TypeReference (org.graalvm.compiler.core.common.type.TypeReference)13 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)13 Signature (jdk.vm.ci.meta.Signature)11 FixedGuardNode (org.graalvm.compiler.nodes.FixedGuardNode)11 LogicNode (org.graalvm.compiler.nodes.LogicNode)11 GraphBuilderContext (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext)11 Registration (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration)11 ArrayList (java.util.ArrayList)10 InvocationPlugin (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin)10 ResolvedJavaField (jdk.vm.ci.meta.ResolvedJavaField)9