Search in sources :

Example 1 with ImplicitLIRFrameState

use of org.graalvm.compiler.lir.ImplicitLIRFrameState in project graal by oracle.

the class DebugInfoBuilder method build.

public LIRFrameState build(NodeWithState node, FrameState topState, LabelRef exceptionEdge, JavaConstant deoptReasonAndAction, JavaConstant deoptSpeculation) {
    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);
    assert verifyFrameState(node, topState);
    BytecodeFrame frame = computeFrameForState(node, 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(metaAccessExtensionProvider, 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.isVirtualByteArray(metaAccessExtensionProvider)) : vobjNode + " " + i + " " + previousValue + " " + currentField.values().snapshot();
                        if (vobjNode.isVirtualByteArray(metaAccessExtensionProvider)) {
                            /*
                                 * Let Illegals pass through to help knowing the number of bytes to
                                 * write. For example, writing a short to index 2 of a byte array of
                                 * size 6 would look like, in debug info:
                                 *
                                 * {b0, b1, INT(...), ILLEGAL, b4, b5}
                                 *
                                 * Thus, from the VM, we can simply count the number of illegals to
                                 * restore the byte count.
                                 */
                            values[pos] = Value.ILLEGAL;
                            slotKinds[pos] = JavaKind.Illegal;
                            pos++;
                        } else if (previousValue == null || !previousValue.getStackKind().needsTwoSlots()) {
                            // Don't allow the IllegalConstant to leak into the debug info
                            JavaKind entryKind = vobjNode.entryKind(metaAccessExtensionProvider, 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();
    if (deoptReasonAndAction == null && deoptSpeculation == null) {
        return new LIRFrameState(frame, virtualObjectsArray, exceptionEdge);
    } else {
        return new ImplicitLIRFrameState(frame, virtualObjectsArray, exceptionEdge, deoptReasonAndAction, deoptSpeculation);
    }
}
Also used : VirtualObjectNode(org.graalvm.compiler.nodes.virtual.VirtualObjectNode) LIRFrameState(org.graalvm.compiler.lir.LIRFrameState) ImplicitLIRFrameState(org.graalvm.compiler.lir.ImplicitLIRFrameState) VirtualObjectState(org.graalvm.compiler.nodes.virtual.VirtualObjectState) JavaValue(jdk.vm.ci.meta.JavaValue) LIRFrameState(org.graalvm.compiler.lir.LIRFrameState) ImplicitLIRFrameState(org.graalvm.compiler.lir.ImplicitLIRFrameState) FrameState(org.graalvm.compiler.nodes.FrameState) EscapeObjectState(org.graalvm.compiler.nodes.virtual.EscapeObjectState) BytecodeFrame(jdk.vm.ci.code.BytecodeFrame) ImplicitLIRFrameState(org.graalvm.compiler.lir.ImplicitLIRFrameState) VirtualObject(jdk.vm.ci.code.VirtualObject) ValueNode(org.graalvm.compiler.nodes.ValueNode) MaterializedObjectState(org.graalvm.compiler.nodes.virtual.MaterializedObjectState) JavaKind(jdk.vm.ci.meta.JavaKind)

Aggregations

BytecodeFrame (jdk.vm.ci.code.BytecodeFrame)1 VirtualObject (jdk.vm.ci.code.VirtualObject)1 JavaKind (jdk.vm.ci.meta.JavaKind)1 JavaValue (jdk.vm.ci.meta.JavaValue)1 ImplicitLIRFrameState (org.graalvm.compiler.lir.ImplicitLIRFrameState)1 LIRFrameState (org.graalvm.compiler.lir.LIRFrameState)1 FrameState (org.graalvm.compiler.nodes.FrameState)1 ValueNode (org.graalvm.compiler.nodes.ValueNode)1 EscapeObjectState (org.graalvm.compiler.nodes.virtual.EscapeObjectState)1 MaterializedObjectState (org.graalvm.compiler.nodes.virtual.MaterializedObjectState)1 VirtualObjectNode (org.graalvm.compiler.nodes.virtual.VirtualObjectNode)1 VirtualObjectState (org.graalvm.compiler.nodes.virtual.VirtualObjectState)1