Search in sources :

Example 1 with EscapeObjectState

use of org.graalvm.compiler.nodes.virtual.EscapeObjectState in project graal by oracle.

the class DebugInfoBuilder method build.

public LIRFrameState build(FrameState topState, LabelRef exceptionEdge) {
    assert virtualObjects.size() == 0;
    assert objectStates.size() == 0;
    assert pendingVirtualObjects.size() == 0;
    // collect all VirtualObjectField instances:
    FrameState current = topState;
    do {
        if (current.virtualObjectMappingCount() > 0) {
            for (EscapeObjectState state : current.virtualObjectMappings()) {
                if (!objectStates.containsKey(state.object())) {
                    if (!(state instanceof MaterializedObjectState) || ((MaterializedObjectState) state).materializedValue() != state.object()) {
                        objectStates.put(state.object(), state);
                    }
                }
            }
        }
        current = current.outerFrameState();
    } while (current != null);
    BytecodeFrame frame = computeFrameForState(topState);
    VirtualObject[] virtualObjectsArray = null;
    if (virtualObjects.size() != 0) {
        // fill in the VirtualObject values
        VirtualObjectNode vobjNode;
        while ((vobjNode = pendingVirtualObjects.poll()) != null) {
            VirtualObject vobjValue = virtualObjects.get(vobjNode);
            assert vobjValue.getValues() == null;
            JavaValue[] values;
            JavaKind[] slotKinds;
            int entryCount = vobjNode.entryCount();
            if (entryCount == 0) {
                values = NO_JAVA_VALUES;
                slotKinds = NO_JAVA_KINDS;
            } else {
                values = new JavaValue[entryCount];
                slotKinds = new JavaKind[entryCount];
            }
            if (values.length > 0) {
                VirtualObjectState currentField = (VirtualObjectState) objectStates.get(vobjNode);
                assert currentField != null;
                int pos = 0;
                for (int i = 0; i < entryCount; i++) {
                    ValueNode value = currentField.values().get(i);
                    if (value == null) {
                        JavaKind entryKind = vobjNode.entryKind(i);
                        values[pos] = JavaConstant.defaultForKind(entryKind.getStackKind());
                        slotKinds[pos] = entryKind.getStackKind();
                        pos++;
                    } else if (!value.isConstant() || value.asJavaConstant().getJavaKind() != JavaKind.Illegal) {
                        values[pos] = toJavaValue(value);
                        slotKinds[pos] = toSlotKind(value);
                        pos++;
                    } else {
                        assert value.getStackKind() == JavaKind.Illegal;
                        ValueNode previousValue = currentField.values().get(i - 1);
                        assert (previousValue != null && previousValue.getStackKind().needsTwoSlots()) : vobjNode + " " + i + " " + previousValue + " " + currentField.values().snapshot();
                        if (previousValue == null || !previousValue.getStackKind().needsTwoSlots()) {
                            // Don't allow the IllegalConstant to leak into the debug info
                            JavaKind entryKind = vobjNode.entryKind(i);
                            values[pos] = JavaConstant.defaultForKind(entryKind.getStackKind());
                            slotKinds[pos] = entryKind.getStackKind();
                            pos++;
                        }
                    }
                }
                if (pos != entryCount) {
                    values = Arrays.copyOf(values, pos);
                    slotKinds = Arrays.copyOf(slotKinds, pos);
                }
            }
            assert checkValues(vobjValue.getType(), values, slotKinds);
            vobjValue.setValues(values, slotKinds);
        }
        virtualObjectsArray = new VirtualObject[virtualObjects.size()];
        int index = 0;
        for (VirtualObject value : virtualObjects.getValues()) {
            virtualObjectsArray[index++] = value;
        }
        virtualObjects.clear();
    }
    objectStates.clear();
    return newLIRFrameState(exceptionEdge, frame, virtualObjectsArray);
}
Also used : VirtualObjectNode(org.graalvm.compiler.nodes.virtual.VirtualObjectNode) VirtualObjectState(org.graalvm.compiler.virtual.nodes.VirtualObjectState) JavaValue(jdk.vm.ci.meta.JavaValue) LIRFrameState(org.graalvm.compiler.lir.LIRFrameState) FrameState(org.graalvm.compiler.nodes.FrameState) EscapeObjectState(org.graalvm.compiler.nodes.virtual.EscapeObjectState) BytecodeFrame(jdk.vm.ci.code.BytecodeFrame) VirtualObject(jdk.vm.ci.code.VirtualObject) ValueNode(org.graalvm.compiler.nodes.ValueNode) MaterializedObjectState(org.graalvm.compiler.virtual.nodes.MaterializedObjectState) JavaKind(jdk.vm.ci.meta.JavaKind)

Example 2 with EscapeObjectState

use of org.graalvm.compiler.nodes.virtual.EscapeObjectState in project graal by oracle.

the class FrameState method verify.

@Override
public boolean verify() {
    if (virtualObjectMappingCount() > 0) {
        for (EscapeObjectState state : virtualObjectMappings()) {
            assertTrue(state != null, "must be non-null");
        }
    }
    /*
         * The outermost FrameState should have a method that matches StructuredGraph.method except
         * when it's a substitution or it's null.
         */
    assertTrue(outerFrameState != null || graph() == null || graph().method() == null || code == null || Objects.equals(graph().method(), code.getMethod()) || graph().method().getAnnotation(MethodSubstitution.class) != null, "wrong outerFrameState %s != %s", code == null ? "null" : code.getMethod(), graph().method());
    if (monitorIds() != null && monitorIds().size() > 0) {
        int depth = outerLockDepth();
        for (MonitorIdNode monitor : monitorIds()) {
            assertTrue(monitor.getLockDepth() == depth++, "wrong depth");
        }
    }
    assertTrue(locksSize() == monitorIdCount(), "mismatch in number of locks");
    for (ValueNode value : values) {
        assertTrue(value == null || !value.isDeleted(), "frame state must not contain deleted nodes: %s", value);
        assertTrue(value == null || value instanceof VirtualObjectNode || (value.getStackKind() != JavaKind.Void), "unexpected value: %s", value);
    }
    verifyAfterExceptionState();
    return super.verify();
}
Also used : MonitorIdNode(org.graalvm.compiler.nodes.java.MonitorIdNode) VirtualObjectNode(org.graalvm.compiler.nodes.virtual.VirtualObjectNode) EscapeObjectState(org.graalvm.compiler.nodes.virtual.EscapeObjectState) MethodSubstitution(org.graalvm.compiler.api.replacements.MethodSubstitution)

Example 3 with EscapeObjectState

use of org.graalvm.compiler.nodes.virtual.EscapeObjectState in project graal by oracle.

the class DebugInfoBuilder method toJavaValue.

protected JavaValue toJavaValue(ValueNode value) {
    try {
        if (value instanceof VirtualObjectNode) {
            VirtualObjectNode obj = (VirtualObjectNode) value;
            EscapeObjectState state = objectStates.get(obj);
            if (state == null && obj.entryCount() > 0) {
                // null states occur for objects with 0 fields
                throw new GraalError("no mapping found for virtual object %s", obj);
            }
            if (state instanceof MaterializedObjectState) {
                return toJavaValue(((MaterializedObjectState) state).materializedValue());
            } else {
                assert obj.entryCount() == 0 || state instanceof VirtualObjectState;
                VirtualObject vobject = virtualObjects.get(obj);
                if (vobject == null) {
                    vobject = VirtualObject.get(obj.type(), virtualObjects.size());
                    virtualObjects.put(obj, vobject);
                    pendingVirtualObjects.add(obj);
                }
                STATE_VIRTUAL_OBJECTS.increment(debug);
                return vobject;
            }
        } else {
            // Remove proxies from constants so the constant can be directly embedded.
            ValueNode unproxied = GraphUtil.unproxify(value);
            if (unproxied instanceof ConstantNode) {
                STATE_CONSTANTS.increment(debug);
                return unproxied.asJavaConstant();
            } else if (value != null) {
                STATE_VARIABLES.increment(debug);
                Value operand = nodeValueMap.operand(value);
                if (operand instanceof ConstantValue && ((ConstantValue) operand).isJavaConstant()) {
                    return ((ConstantValue) operand).getJavaConstant();
                } else {
                    assert operand instanceof Variable : operand + " for " + value;
                    return (JavaValue) operand;
                }
            } else {
                // return a dummy value because real value not needed
                STATE_ILLEGALS.increment(debug);
                return Value.ILLEGAL;
            }
        }
    } catch (GraalError e) {
        throw e.addContext("toValue: ", value);
    }
}
Also used : VirtualObjectNode(org.graalvm.compiler.nodes.virtual.VirtualObjectNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) Variable(org.graalvm.compiler.lir.Variable) GraalError(org.graalvm.compiler.debug.GraalError) VirtualObjectState(org.graalvm.compiler.virtual.nodes.VirtualObjectState) VirtualObject(jdk.vm.ci.code.VirtualObject) ValueNode(org.graalvm.compiler.nodes.ValueNode) JavaValue(jdk.vm.ci.meta.JavaValue) ConstantValue(org.graalvm.compiler.lir.ConstantValue) Value(jdk.vm.ci.meta.Value) MaterializedObjectState(org.graalvm.compiler.virtual.nodes.MaterializedObjectState) ConstantValue(org.graalvm.compiler.lir.ConstantValue) EscapeObjectState(org.graalvm.compiler.nodes.virtual.EscapeObjectState)

Example 4 with EscapeObjectState

use of org.graalvm.compiler.nodes.virtual.EscapeObjectState in project graal by oracle.

the class FrameState method duplicateWithVirtualState.

/**
 * Duplicates a FrameState, along with a deep copy of all connected VirtualState (outer
 * FrameStates, VirtualObjectStates, ...).
 */
@Override
public FrameState duplicateWithVirtualState() {
    FrameState newOuterFrameState = outerFrameState();
    if (newOuterFrameState != null) {
        newOuterFrameState = newOuterFrameState.duplicateWithVirtualState();
    }
    ArrayList<EscapeObjectState> newVirtualMappings = null;
    if (virtualObjectMappings != null) {
        newVirtualMappings = new ArrayList<>(virtualObjectMappings.size());
        for (EscapeObjectState state : virtualObjectMappings) {
            newVirtualMappings.add(state.duplicateWithVirtualState());
        }
    }
    return graph().add(new FrameState(newOuterFrameState, code, bci, values, localsSize, stackSize, rethrowException, duringCall, monitorIds, newVirtualMappings));
}
Also used : EscapeObjectState(org.graalvm.compiler.nodes.virtual.EscapeObjectState)

Aggregations

EscapeObjectState (org.graalvm.compiler.nodes.virtual.EscapeObjectState)4 VirtualObjectNode (org.graalvm.compiler.nodes.virtual.VirtualObjectNode)3 VirtualObject (jdk.vm.ci.code.VirtualObject)2 JavaValue (jdk.vm.ci.meta.JavaValue)2 ValueNode (org.graalvm.compiler.nodes.ValueNode)2 MaterializedObjectState (org.graalvm.compiler.virtual.nodes.MaterializedObjectState)2 VirtualObjectState (org.graalvm.compiler.virtual.nodes.VirtualObjectState)2 BytecodeFrame (jdk.vm.ci.code.BytecodeFrame)1 JavaKind (jdk.vm.ci.meta.JavaKind)1 Value (jdk.vm.ci.meta.Value)1 MethodSubstitution (org.graalvm.compiler.api.replacements.MethodSubstitution)1 GraalError (org.graalvm.compiler.debug.GraalError)1 ConstantValue (org.graalvm.compiler.lir.ConstantValue)1 LIRFrameState (org.graalvm.compiler.lir.LIRFrameState)1 Variable (org.graalvm.compiler.lir.Variable)1 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)1 FrameState (org.graalvm.compiler.nodes.FrameState)1 MonitorIdNode (org.graalvm.compiler.nodes.java.MonitorIdNode)1