Search in sources :

Example 11 with NodePlugin

use of org.graalvm.compiler.nodes.graphbuilderconf.NodePlugin in project graal by oracle.

the class BytecodeParser method genCheckCast.

private void genCheckCast() {
    int cpi = getStream().readCPI();
    JavaType type = lookupType(cpi, CHECKCAST);
    ValueNode object = frameState.pop(JavaKind.Object);
    if (!(type instanceof ResolvedJavaType)) {
        handleUnresolvedCheckCast(type, object);
        return;
    }
    TypeReference checkedType = TypeReference.createTrusted(graph.getAssumptions(), (ResolvedJavaType) type);
    JavaTypeProfile profile = getProfileForTypeCheck(checkedType);
    for (NodePlugin plugin : graphBuilderConfig.getPlugins().getNodePlugins()) {
        if (plugin.handleCheckCast(this, object, checkedType.getType(), profile)) {
            return;
        }
    }
    ValueNode castNode = null;
    if (profile != null) {
        if (profile.getNullSeen().isFalse()) {
            object = nullCheckedValue(object);
            ResolvedJavaType singleType = profile.asSingleType();
            if (singleType != null && checkedType.getType().isAssignableFrom(singleType)) {
                LogicNode typeCheck = append(createInstanceOf(TypeReference.createExactTrusted(singleType), object, profile));
                if (typeCheck.isTautology()) {
                    castNode = object;
                } else {
                    FixedGuardNode fixedGuard = append(new FixedGuardNode(typeCheck, DeoptimizationReason.TypeCheckedInliningViolated, DeoptimizationAction.InvalidateReprofile, false));
                    castNode = append(PiNode.create(object, StampFactory.objectNonNull(TypeReference.createExactTrusted(singleType)), fixedGuard));
                }
            }
        }
    }
    boolean nonNull = ((ObjectStamp) object.stamp(NodeView.DEFAULT)).nonNull();
    if (castNode == null) {
        LogicNode condition = genUnique(createInstanceOfAllowNull(checkedType, object, null));
        if (condition.isTautology()) {
            castNode = object;
        } else {
            FixedGuardNode fixedGuard = append(new FixedGuardNode(condition, DeoptimizationReason.ClassCastException, DeoptimizationAction.InvalidateReprofile, false));
            castNode = append(PiNode.create(object, StampFactory.object(checkedType, nonNull), fixedGuard));
        }
    }
    frameState.push(JavaKind.Object, castNode);
}
Also used : FixedGuardNode(org.graalvm.compiler.nodes.FixedGuardNode) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) JavaType(jdk.vm.ci.meta.JavaType) ObjectStamp(org.graalvm.compiler.core.common.type.ObjectStamp) NodePlugin(org.graalvm.compiler.nodes.graphbuilderconf.NodePlugin) JavaTypeProfile(jdk.vm.ci.meta.JavaTypeProfile) ValueNode(org.graalvm.compiler.nodes.ValueNode) LogicNode(org.graalvm.compiler.nodes.LogicNode) TypeReference(org.graalvm.compiler.core.common.type.TypeReference) RuntimeConstraint(jdk.vm.ci.meta.DeoptimizationReason.RuntimeConstraint) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType)

Example 12 with NodePlugin

use of org.graalvm.compiler.nodes.graphbuilderconf.NodePlugin in project graal by oracle.

the class BytecodeParser method genNewPrimitiveArray.

private void genNewPrimitiveArray(int typeCode) {
    ResolvedJavaType elementType = metaAccess.lookupJavaType(arrayTypeCodeToClass(typeCode));
    ValueNode length = frameState.pop(JavaKind.Int);
    for (NodePlugin plugin : graphBuilderConfig.getPlugins().getNodePlugins()) {
        if (plugin.handleNewArray(this, elementType, length)) {
            return;
        }
    }
    frameState.push(JavaKind.Object, append(createNewArray(elementType, length, true)));
}
Also used : NodePlugin(org.graalvm.compiler.nodes.graphbuilderconf.NodePlugin) ValueNode(org.graalvm.compiler.nodes.ValueNode) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType)

Example 13 with NodePlugin

use of org.graalvm.compiler.nodes.graphbuilderconf.NodePlugin in project graal by oracle.

the class BytecodeParser method genPutStatic.

protected void genPutStatic(JavaField field) {
    ValueNode value = frameState.pop(field.getJavaKind());
    ResolvedJavaField resolvedField = resolveStaticFieldAccess(field, value);
    if (resolvedField == null) {
        return;
    }
    if (!parsingIntrinsic() && GeneratePIC.getValue(getOptions())) {
        graph.recordField(resolvedField);
    }
    ClassInitializationPlugin classInitializationPlugin = this.graphBuilderConfig.getPlugins().getClassInitializationPlugin();
    if (classInitializationPlugin != null && classInitializationPlugin.shouldApply(this, resolvedField.getDeclaringClass())) {
        FrameState stateBefore = frameState.create(bci(), getNonIntrinsicAncestor(), false, null, null);
        classInitializationPlugin.apply(this, resolvedField.getDeclaringClass(), stateBefore);
    }
    for (NodePlugin plugin : graphBuilderConfig.getPlugins().getNodePlugins()) {
        if (plugin.handleStoreStaticField(this, resolvedField, value)) {
            return;
        }
    }
    genStoreField(null, resolvedField, value);
}
Also used : NodePlugin(org.graalvm.compiler.nodes.graphbuilderconf.NodePlugin) ValueNode(org.graalvm.compiler.nodes.ValueNode) FrameState(org.graalvm.compiler.nodes.FrameState) ClassInitializationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.ClassInitializationPlugin) ResolvedJavaField(jdk.vm.ci.meta.ResolvedJavaField)

Aggregations

NodePlugin (org.graalvm.compiler.nodes.graphbuilderconf.NodePlugin)13 ValueNode (org.graalvm.compiler.nodes.ValueNode)11 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)7 FrameState (org.graalvm.compiler.nodes.FrameState)5 ClassInitializationPlugin (org.graalvm.compiler.nodes.graphbuilderconf.ClassInitializationPlugin)5 JavaType (jdk.vm.ci.meta.JavaType)4 ResolvedJavaField (jdk.vm.ci.meta.ResolvedJavaField)4 RuntimeConstraint (jdk.vm.ci.meta.DeoptimizationReason.RuntimeConstraint)3 JavaTypeProfile (jdk.vm.ci.meta.JavaTypeProfile)2 TypeReference (org.graalvm.compiler.core.common.type.TypeReference)2 DeoptimizeNode (org.graalvm.compiler.nodes.DeoptimizeNode)2 FixedGuardNode (org.graalvm.compiler.nodes.FixedGuardNode)2 LogicNode (org.graalvm.compiler.nodes.LogicNode)2 LoadFieldNode (org.graalvm.compiler.nodes.java.LoadFieldNode)2 JavaKind (jdk.vm.ci.meta.JavaKind)1 ObjectStamp (org.graalvm.compiler.core.common.type.ObjectStamp)1 Node (org.graalvm.compiler.graph.Node)1 BciBlock (org.graalvm.compiler.java.BciBlockMapping.BciBlock)1 AbstractBeginNode (org.graalvm.compiler.nodes.AbstractBeginNode)1 AbstractMergeNode (org.graalvm.compiler.nodes.AbstractMergeNode)1