Search in sources :

Example 6 with LIRFrameState

use of org.graalvm.compiler.lir.LIRFrameState 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 7 with LIRFrameState

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

the class LIRGenerator method emitForeignCall.

@Override
public Variable emitForeignCall(ForeignCallLinkage linkage, LIRFrameState frameState, Value... args) {
    LIRFrameState state = null;
    if (linkage.needsDebugInfo()) {
        if (frameState != null) {
            state = frameState;
        } else {
            assert needOnlyOopMaps();
            state = new LIRFrameState(null, null, null);
        }
    }
    // move the arguments into the correct location
    CallingConvention linkageCc = linkage.getOutgoingCallingConvention();
    res.getFrameMapBuilder().callsMethod(linkageCc);
    assert linkageCc.getArgumentCount() == args.length : "argument count mismatch";
    Value[] argLocations = new Value[args.length];
    for (int i = 0; i < args.length; i++) {
        Value arg = args[i];
        AllocatableValue loc = linkageCc.getArgument(i);
        emitMove(loc, arg);
        argLocations[i] = loc;
    }
    res.setForeignCall(true);
    emitForeignCallOp(linkage, linkageCc.getReturn(), argLocations, linkage.getTemporaries(), state);
    if (isLegal(linkageCc.getReturn())) {
        return emitMove(linkageCc.getReturn());
    } else {
        return null;
    }
}
Also used : CallingConvention(jdk.vm.ci.code.CallingConvention) LIRFrameState(org.graalvm.compiler.lir.LIRFrameState) ConstantValue(org.graalvm.compiler.lir.ConstantValue) LIRValueUtil.isConstantValue(org.graalvm.compiler.lir.LIRValueUtil.isConstantValue) ValueUtil.asAllocatableValue(jdk.vm.ci.code.ValueUtil.asAllocatableValue) Value(jdk.vm.ci.meta.Value) ValueUtil.isAllocatableValue(jdk.vm.ci.code.ValueUtil.isAllocatableValue) AllocatableValue(jdk.vm.ci.meta.AllocatableValue) ValueUtil.asAllocatableValue(jdk.vm.ci.code.ValueUtil.asAllocatableValue) ValueUtil.isAllocatableValue(jdk.vm.ci.code.ValueUtil.isAllocatableValue) AllocatableValue(jdk.vm.ci.meta.AllocatableValue)

Example 8 with LIRFrameState

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

the class SPARCHotSpotBackend method newCompilationResultBuilder.

@Override
public CompilationResultBuilder newCompilationResultBuilder(LIRGenerationResult lirGenRes, FrameMap frameMap, CompilationResult compilationResult, CompilationResultBuilderFactory factory) {
    HotSpotLIRGenerationResult gen = (HotSpotLIRGenerationResult) lirGenRes;
    LIR lir = gen.getLIR();
    assert gen.getDeoptimizationRescueSlot() == null || frameMap.frameNeedsAllocating() : "method that can deoptimize must have a frame";
    Stub stub = gen.getStub();
    Assembler masm = createAssembler(frameMap);
    // On SPARC we always use stack frames.
    HotSpotFrameContext frameContext = new HotSpotFrameContext(stub != null);
    DataBuilder dataBuilder = new HotSpotDataBuilder(getCodeCache().getTarget());
    OptionValues options = lir.getOptions();
    DebugContext debug = lir.getDebug();
    CompilationResultBuilder crb = factory.createBuilder(getProviders().getCodeCache(), getProviders().getForeignCalls(), frameMap, masm, dataBuilder, frameContext, options, debug, compilationResult);
    crb.setTotalFrameSize(frameMap.totalFrameSize());
    crb.setMaxInterpreterFrameSize(gen.getMaxInterpreterFrameSize());
    StackSlot deoptimizationRescueSlot = gen.getDeoptimizationRescueSlot();
    if (deoptimizationRescueSlot != null && stub == null) {
        crb.compilationResult.setCustomStackAreaOffset(deoptimizationRescueSlot);
    }
    if (stub != null) {
        // Even on sparc we need to save floating point registers
        EconomicSet<Register> destroyedCallerRegisters = gatherDestroyedCallerRegisters(lir);
        EconomicMap<LIRFrameState, SaveRegistersOp> calleeSaveInfo = gen.getCalleeSaveInfo();
        updateStub(stub, destroyedCallerRegisters, calleeSaveInfo, frameMap);
    }
    assert registerSizePredictionValidator(crb, debug);
    return crb;
}
Also used : LIRFrameState(org.graalvm.compiler.lir.LIRFrameState) OptionValues(org.graalvm.compiler.options.OptionValues) HotSpotLIRGenerationResult(org.graalvm.compiler.hotspot.HotSpotLIRGenerationResult) HotSpotDataBuilder(org.graalvm.compiler.hotspot.HotSpotDataBuilder) Stub(org.graalvm.compiler.hotspot.stubs.Stub) StackSlot(jdk.vm.ci.code.StackSlot) DebugContext(org.graalvm.compiler.debug.DebugContext) CompilationResultBuilder(org.graalvm.compiler.lir.asm.CompilationResultBuilder) LIR(org.graalvm.compiler.lir.LIR) HotSpotDataBuilder(org.graalvm.compiler.hotspot.HotSpotDataBuilder) DataBuilder(org.graalvm.compiler.lir.asm.DataBuilder) Register(jdk.vm.ci.code.Register) ValueUtil.isRegister(jdk.vm.ci.code.ValueUtil.isRegister) ValueUtil.asRegister(jdk.vm.ci.code.ValueUtil.asRegister) ScratchRegister(org.graalvm.compiler.asm.sparc.SPARCMacroAssembler.ScratchRegister) SPARCAssembler.isGlobalRegister(org.graalvm.compiler.asm.sparc.SPARCAssembler.isGlobalRegister) SPARCAssembler(org.graalvm.compiler.asm.sparc.SPARCAssembler) SPARCMacroAssembler(org.graalvm.compiler.asm.sparc.SPARCMacroAssembler) Assembler(org.graalvm.compiler.asm.Assembler) SaveRegistersOp(org.graalvm.compiler.lir.StandardOp.SaveRegistersOp)

Example 9 with LIRFrameState

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

the class JVMCIInfopointErrorTest method testDuplicateVirtualObject.

@Test(expected = JVMCIError.class)
public void testDuplicateVirtualObject() {
    ResolvedJavaType obj = getMetaAccess().lookupJavaType(Object.class);
    test((tool, state, safepoint) -> {
        VirtualObject o1 = VirtualObject.get(obj, 0);
        o1.setValues(new JavaValue[0], new JavaKind[0]);
        VirtualObject o2 = VirtualObject.get(obj, 0);
        o2.setValues(new JavaValue[0], new JavaKind[0]);
        safepoint.accept(new LIRFrameState(state.topFrame, new VirtualObject[] { o1, o2 }, state.exceptionEdge));
    });
}
Also used : LIRFrameState(org.graalvm.compiler.lir.LIRFrameState) VirtualObject(jdk.vm.ci.code.VirtualObject) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) GraalCompilerTest(org.graalvm.compiler.core.test.GraalCompilerTest) Test(org.junit.Test)

Example 10 with LIRFrameState

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

the class JVMCIInfopointErrorTest method testUnexpectedScopeSlotKindsLength.

@Test(expected = JVMCIError.class)
public void testUnexpectedScopeSlotKindsLength() {
    test((tool, state, safepoint) -> {
        LIRFrameState newState = modifyTopFrame(state, new JavaValue[0], new JavaKind[] { JavaKind.Boolean }, 0, 0, 0);
        safepoint.accept(newState);
    });
}
Also used : LIRFrameState(org.graalvm.compiler.lir.LIRFrameState) GraalCompilerTest(org.graalvm.compiler.core.test.GraalCompilerTest) Test(org.junit.Test)

Aggregations

LIRFrameState (org.graalvm.compiler.lir.LIRFrameState)33 GraalCompilerTest (org.graalvm.compiler.core.test.GraalCompilerTest)15 Test (org.junit.Test)15 Register (jdk.vm.ci.code.Register)7 Value (jdk.vm.ci.meta.Value)7 VirtualObject (jdk.vm.ci.code.VirtualObject)5 Variable (org.graalvm.compiler.lir.Variable)5 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)4 AllocatableValue (jdk.vm.ci.meta.AllocatableValue)3 DebugContext (org.graalvm.compiler.debug.DebugContext)3 HotSpotForeignCallLinkage (org.graalvm.compiler.hotspot.HotSpotForeignCallLinkage)3 HotSpotLIRGenerator (org.graalvm.compiler.hotspot.HotSpotLIRGenerator)3 SaveRegistersOp (org.graalvm.compiler.lir.StandardOp.SaveRegistersOp)3 BytecodeFrame (jdk.vm.ci.code.BytecodeFrame)2 CallingConvention (jdk.vm.ci.code.CallingConvention)2 HotSpotMetaspaceConstant (jdk.vm.ci.hotspot.HotSpotMetaspaceConstant)2 JavaValue (jdk.vm.ci.meta.JavaValue)2 HotSpotLIRGenerationResult (org.graalvm.compiler.hotspot.HotSpotLIRGenerationResult)2 HotSpotRegistersProvider (org.graalvm.compiler.hotspot.meta.HotSpotRegistersProvider)2 Stub (org.graalvm.compiler.hotspot.stubs.Stub)2