Search in sources :

Example 1 with EnsureClassInitializedNode

use of com.oracle.svm.core.classinitialization.EnsureClassInitializedNode in project graal by oracle.

the class SubstrateGraphBuilderPlugins method registerUnsafePlugins.

private static void registerUnsafePlugins(MetaAccessProvider metaAccess, Registration r, SnippetReflectionProvider snippetReflection, ParsingReason reason, boolean isSunMiscUnsafe) {
    r.register(new RequiredInvocationPlugin("staticFieldOffset", Receiver.class, Field.class) {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode fieldNode) {
            if (fieldNode.isConstant()) {
                Field targetField = snippetReflection.asObject(Field.class, fieldNode.asJavaConstant());
                return processFieldOffset(b, targetField, reason, metaAccess, isSunMiscUnsafe);
            }
            return false;
        }
    });
    r.register(new RequiredInvocationPlugin("staticFieldBase", Receiver.class, Field.class) {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode fieldNode) {
            if (fieldNode.isConstant()) {
                Field targetField = snippetReflection.asObject(Field.class, fieldNode.asJavaConstant());
                return processStaticFieldBase(b, targetField, isSunMiscUnsafe);
            }
            return false;
        }
    });
    r.register(new RequiredInvocationPlugin("objectFieldOffset", Receiver.class, Field.class) {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode fieldNode) {
            if (fieldNode.isConstant()) {
                Field targetField = snippetReflection.asObject(Field.class, fieldNode.asJavaConstant());
                return processFieldOffset(b, targetField, reason, metaAccess, isSunMiscUnsafe);
            }
            return false;
        }
    });
    r.register(new RequiredInvocationPlugin("allocateInstance", Receiver.class, Class.class) {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver unsafe, ValueNode clazz) {
            /* Emits a null-check for the otherwise unused receiver. */
            unsafe.get();
            /*
                 * The allocated class must be null-checked already before the class initialization
                 * check.
                 */
            ValueNode clazzNonNull = b.nullCheckedValue(clazz, DeoptimizationAction.None);
            b.add(new EnsureClassInitializedNode(clazzNonNull));
            DynamicNewInstanceNode.createAndPush(b, clazzNonNull);
            return true;
        }
    });
}
Also used : ResolvedJavaField(jdk.vm.ci.meta.ResolvedJavaField) AnalysisField(com.oracle.graal.pointsto.meta.AnalysisField) Field(java.lang.reflect.Field) SharedField(com.oracle.svm.core.meta.SharedField) HostedField(com.oracle.svm.hosted.meta.HostedField) EnsureClassInitializedNode(com.oracle.svm.core.classinitialization.EnsureClassInitializedNode) GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) RequiredInvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.RequiredInvocationPlugin) StackValueNode(com.oracle.svm.core.graal.stackvalue.StackValueNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) Receiver(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 2 with EnsureClassInitializedNode

use of com.oracle.svm.core.classinitialization.EnsureClassInitializedNode in project graal by oracle.

the class HostedGraphKit method emitEnsureInitializedCall.

public void emitEnsureInitializedCall(ResolvedJavaType type) {
    if (EnsureClassInitializedNode.needsRuntimeInitialization(graph.method().getDeclaringClass(), type)) {
        ValueNode hub = createConstant(getConstantReflection().asJavaClass(type), JavaKind.Object);
        appendWithUnwind(new EnsureClassInitializedNode(hub));
    }
}
Also used : EnsureClassInitializedNode(com.oracle.svm.core.classinitialization.EnsureClassInitializedNode) ValueNode(org.graalvm.compiler.nodes.ValueNode)

Example 3 with EnsureClassInitializedNode

use of com.oracle.svm.core.classinitialization.EnsureClassInitializedNode in project graal by oracle.

the class SubstrateClassInitializationPlugin method emitEnsureClassInitialized.

private static void emitEnsureClassInitialized(GraphBuilderContext builder, JavaConstant hubConstant, FrameState frameState) {
    ValueNode hub = ConstantNode.forConstant(hubConstant, builder.getMetaAccess(), builder.getGraph());
    EnsureClassInitializedNode node = new EnsureClassInitializedNode(hub, frameState);
    builder.add(node);
}
Also used : EnsureClassInitializedNode(com.oracle.svm.core.classinitialization.EnsureClassInitializedNode) ValueNode(org.graalvm.compiler.nodes.ValueNode)

Aggregations

EnsureClassInitializedNode (com.oracle.svm.core.classinitialization.EnsureClassInitializedNode)3 ValueNode (org.graalvm.compiler.nodes.ValueNode)3 AnalysisField (com.oracle.graal.pointsto.meta.AnalysisField)1 StackValueNode (com.oracle.svm.core.graal.stackvalue.StackValueNode)1 SharedField (com.oracle.svm.core.meta.SharedField)1 HostedField (com.oracle.svm.hosted.meta.HostedField)1 Field (java.lang.reflect.Field)1 ResolvedJavaField (jdk.vm.ci.meta.ResolvedJavaField)1 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)1 GraphBuilderContext (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext)1 Receiver (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver)1 RequiredInvocationPlugin (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.RequiredInvocationPlugin)1