Search in sources :

Example 11 with JavaKind

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

the class FrameStateBuilder method initializeFromArgumentsArray.

public void initializeFromArgumentsArray(ValueNode[] arguments) {
    int javaIndex = 0;
    int index = 0;
    if (!getMethod().isStatic()) {
        // set the receiver
        locals[javaIndex] = arguments[index];
        javaIndex = 1;
        index = 1;
    }
    Signature sig = getMethod().getSignature();
    int max = sig.getParameterCount(false);
    for (int i = 0; i < max; i++) {
        JavaKind kind = sig.getParameterKind(i);
        locals[javaIndex] = arguments[index];
        javaIndex++;
        if (kind.needsTwoSlots()) {
            locals[javaIndex] = TWO_SLOT_MARKER;
            javaIndex++;
        }
        index++;
    }
}
Also used : Signature(jdk.vm.ci.meta.Signature) JavaKind(jdk.vm.ci.meta.JavaKind)

Example 12 with JavaKind

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

the class SubstrateAMD64RegisterConfig method getCallingConvention.

@Override
public CallingConvention getCallingConvention(Type t, JavaType returnType, JavaType[] parameterTypes, ValueKindFactory<?> valueKindFactory) {
    SubstrateCallingConventionType type = (SubstrateCallingConventionType) t;
    boolean isEntryPoint = type.nativeABI && !type.outgoing;
    AllocatableValue[] locations = new AllocatableValue[parameterTypes.length];
    int currentGeneral = 0;
    int currentXMM = 0;
    /*
         * We have to reserve a slot between return address and outgoing parameters for the deopt
         * frame handle. Exception: calls to native methods.
         */
    int currentStackOffset = (type.nativeABI ? 0 : target.wordSize);
    JavaKind[] kinds = new JavaKind[locations.length];
    for (int i = 0; i < parameterTypes.length; i++) {
        JavaKind kind = ObjectLayout.getCallSignatureKind(isEntryPoint, (ResolvedJavaType) parameterTypes[i], metaAccess, target);
        kinds[i] = kind;
        switch(kind) {
            case Byte:
            case Boolean:
            case Short:
            case Char:
            case Int:
            case Long:
            case Object:
                if (currentGeneral < generalParameterRegs.size()) {
                    Register register = generalParameterRegs.get(currentGeneral++);
                    locations[i] = register.asValue(valueKindFactory.getValueKind(kind.getStackKind()));
                }
                break;
            case Float:
            case Double:
                if (currentXMM < xmmParameterRegs.size()) {
                    Register register = xmmParameterRegs.get(currentXMM++);
                    locations[i] = register.asValue(valueKindFactory.getValueKind(kind));
                }
                break;
            default:
                throw shouldNotReachHere();
        }
        if (locations[i] == null) {
            ValueKind<?> valueKind = valueKindFactory.getValueKind(kind.getStackKind());
            locations[i] = StackSlot.get(valueKind, currentStackOffset, !type.outgoing);
            currentStackOffset += Math.max(valueKind.getPlatformKind().getSizeInBytes(), target.wordSize);
        }
    }
    JavaKind returnKind = returnType == null ? JavaKind.Void : ObjectLayout.getCallSignatureKind(isEntryPoint, (ResolvedJavaType) returnType, metaAccess, target);
    AllocatableValue returnLocation = returnKind == JavaKind.Void ? Value.ILLEGAL : getReturnRegister(returnKind).asValue(valueKindFactory.getValueKind(returnKind.getStackKind()));
    return new SubstrateCallingConvention(type, kinds, currentStackOffset, returnLocation, locations);
}
Also used : Register(jdk.vm.ci.code.Register) AllocatableValue(jdk.vm.ci.meta.AllocatableValue) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) JavaKind(jdk.vm.ci.meta.JavaKind)

Example 13 with JavaKind

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

the class DebugInfoBuilder method computeFrameForState.

protected BytecodeFrame computeFrameForState(FrameState state) {
    try {
        assert state.bci != BytecodeFrame.INVALID_FRAMESTATE_BCI;
        assert state.bci != BytecodeFrame.UNKNOWN_BCI;
        assert state.bci != BytecodeFrame.BEFORE_BCI || state.locksSize() == 0;
        assert state.bci != BytecodeFrame.AFTER_BCI || state.locksSize() == 0;
        assert state.bci != BytecodeFrame.AFTER_EXCEPTION_BCI || state.locksSize() == 0;
        assert !(state.getMethod().isSynchronized() && state.bci != BytecodeFrame.BEFORE_BCI && state.bci != BytecodeFrame.AFTER_BCI && state.bci != BytecodeFrame.AFTER_EXCEPTION_BCI) || state.locksSize() > 0;
        assert state.verify();
        int numLocals = state.localsSize();
        int numStack = state.stackSize();
        int numLocks = state.locksSize();
        int numValues = numLocals + numStack + numLocks;
        int numKinds = numLocals + numStack;
        JavaValue[] values = numValues == 0 ? NO_JAVA_VALUES : new JavaValue[numValues];
        JavaKind[] slotKinds = numKinds == 0 ? NO_JAVA_KINDS : new JavaKind[numKinds];
        computeLocals(state, numLocals, values, slotKinds);
        computeStack(state, numLocals, numStack, values, slotKinds);
        computeLocks(state, values);
        BytecodeFrame caller = null;
        if (state.outerFrameState() != null) {
            caller = computeFrameForState(state.outerFrameState());
        }
        if (!state.canProduceBytecodeFrame()) {
            // This typically means a snippet or intrinsic frame state made it to the backend
            StackTraceElement ste = state.getCode().asStackTraceElement(state.bci);
            throw new GraalError("Frame state for %s cannot be converted to a BytecodeFrame since the frame state's code is " + "not the same as the frame state method's code", ste);
        }
        return new BytecodeFrame(caller, state.getMethod(), state.bci, state.rethrowException(), state.duringCall(), values, slotKinds, numLocals, numStack, numLocks);
    } catch (GraalError e) {
        throw e.addContext("FrameState: ", state);
    }
}
Also used : BytecodeFrame(jdk.vm.ci.code.BytecodeFrame) GraalError(org.graalvm.compiler.debug.GraalError) JavaValue(jdk.vm.ci.meta.JavaValue) JavaKind(jdk.vm.ci.meta.JavaKind)

Example 14 with JavaKind

use of jdk.vm.ci.meta.JavaKind 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 15 with JavaKind

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

the class DebugInfoBuilder method checkValues.

private boolean checkValues(ResolvedJavaType type, JavaValue[] values, JavaKind[] slotKinds) {
    assert (values == null) == (slotKinds == null);
    if (values != null) {
        assert values.length == slotKinds.length;
        if (!type.isArray()) {
            ResolvedJavaField[] fields = type.getInstanceFields(true);
            int fieldIndex = 0;
            for (int valueIndex = 0; valueIndex < values.length; valueIndex++, fieldIndex++) {
                ResolvedJavaField field = fields[fieldIndex];
                JavaKind valKind = slotKinds[valueIndex].getStackKind();
                JavaKind fieldKind = storageKind(field.getType());
                if ((valKind == JavaKind.Double || valKind == JavaKind.Long) && fieldKind == JavaKind.Int) {
                    assert fieldIndex + 1 < fields.length : String.format("Not enough fields for fieldIndex = %d valueIndex = %d %s %s", fieldIndex, valueIndex, Arrays.toString(fields), Arrays.toString(values));
                    assert storageKind(fields[fieldIndex + 1].getType()) == JavaKind.Int : String.format("fieldIndex = %d valueIndex = %d %s %s %s", fieldIndex, valueIndex, storageKind(fields[fieldIndex + 1].getType()), Arrays.toString(fields), Arrays.toString(values));
                    fieldIndex++;
                } else {
                    assert valKind == fieldKind.getStackKind() : field + ": " + valKind + " != " + fieldKind;
                }
            }
            assert fields.length == fieldIndex : type + ": fields=" + Arrays.toString(fields) + ", field values=" + Arrays.toString(values);
        } else {
            JavaKind componentKind = storageKind(type.getComponentType()).getStackKind();
            if (componentKind == JavaKind.Object) {
                for (int i = 0; i < values.length; i++) {
                    assert slotKinds[i].isObject() : slotKinds[i] + " != " + componentKind;
                }
            } else {
                for (int i = 0; i < values.length; i++) {
                    assert slotKinds[i] == componentKind || componentKind.getBitCount() >= slotKinds[i].getBitCount() || (componentKind == JavaKind.Int && slotKinds[i].getBitCount() >= JavaKind.Int.getBitCount()) : slotKinds[i] + " != " + componentKind;
                }
            }
        }
    }
    return true;
}
Also used : ResolvedJavaField(jdk.vm.ci.meta.ResolvedJavaField) JavaKind(jdk.vm.ci.meta.JavaKind)

Aggregations

JavaKind (jdk.vm.ci.meta.JavaKind)90 ValueNode (org.graalvm.compiler.nodes.ValueNode)44 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)24 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)17 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)16 AddressNode (org.graalvm.compiler.nodes.memory.address.AddressNode)13 OffsetAddressNode (org.graalvm.compiler.nodes.memory.address.OffsetAddressNode)12 JavaType (jdk.vm.ci.meta.JavaType)11 Stamp (org.graalvm.compiler.core.common.type.Stamp)10 LocationIdentity (org.graalvm.word.LocationIdentity)10 ArrayList (java.util.ArrayList)9 JavaConstant (jdk.vm.ci.meta.JavaConstant)9 AbstractMergeNode (org.graalvm.compiler.nodes.AbstractMergeNode)8 FrameState (org.graalvm.compiler.nodes.FrameState)8 GraphBuilderContext (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext)8 Signature (jdk.vm.ci.meta.Signature)7 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)7 ObjectLayout (com.oracle.svm.core.config.ObjectLayout)6 ObjectStamp (org.graalvm.compiler.core.common.type.ObjectStamp)6 InvokeWithExceptionNode (org.graalvm.compiler.nodes.InvokeWithExceptionNode)6