Search in sources :

Example 26 with JavaConstant

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

the class Deoptimizer method verifyConstant.

private boolean verifyConstant(FrameInfoQueryResult targetFrame, ValueInfo targetValue, JavaConstant source) {
    boolean equal;
    JavaConstant target = readValue(targetValue, targetFrame);
    if (source.getJavaKind() == JavaKind.Object && target.getJavaKind() == JavaKind.Object) {
        // Differences in compression are irrelevant, compare only object identities
        equal = (SubstrateObjectConstant.asObject(target) == SubstrateObjectConstant.asObject(source));
    } else {
        equal = source.equals(target);
    }
    if (!equal) {
        Log.log().string("source: ").string(source.toString()).string("  target: ").string(target.toString()).newline();
    }
    return equal;
}
Also used : JavaConstant(jdk.vm.ci.meta.JavaConstant)

Example 27 with JavaConstant

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

the class Deoptimizer method constructTargetFrame.

/**
 * Constructs the frame entries for the deopimization target method.
 *
 * @param targetInfo The bytecode frame (+ some other info) of the target.
 * @param sourceFrame The bytecode frame of the source.
 */
private VirtualFrame constructTargetFrame(CodeInfoQueryResult targetInfo, FrameInfoQueryResult sourceFrame) {
    FrameInfoQueryResult targetFrame = targetInfo.getFrameInfo();
    long targetFrameSize = targetInfo.getTotalFrameSize() - FrameAccess.returnAddressSize();
    VirtualFrame result = new VirtualFrame(targetFrame);
    /* The first word of the new content is the return address into the target method. */
    result.returnAddress = new DeoptimizedFrame.ReturnAddress(targetContentSize, targetInfo.getIP().rawValue());
    targetContentSize += FrameAccess.returnAddressSize();
    /* The source and target bytecode frame must match (as they stem from the same BCI). */
    assert sourceFrame.getNumLocals() == targetFrame.getNumLocals();
    assert sourceFrame.getNumStack() == targetFrame.getNumStack();
    assert sourceFrame.getNumLocks() == targetFrame.getNumLocks();
    assert targetFrame.getVirtualObjects().length == 0;
    assert sourceFrame.getValueInfos().length >= targetFrame.getValueInfos().length;
    int numValues = targetFrame.getValueInfos().length;
    /*
         * Create stack entries for all values of the source frame.
         */
    int newEndOfParams = endOfParams;
    for (int idx = 0; idx < numValues; idx++) {
        ValueInfo targetValue = targetFrame.getValueInfos()[idx];
        if (targetValue.getKind() == JavaKind.Illegal) {
        /*
                 * The target value is optimized out, e.g. at a position after the lifetime of a
                 * local variable. Actually we don't care what's the source value in this case, but
                 * most likely it's also "illegal".
                 */
        } else {
            JavaConstant con = readValue(sourceFrame.getValueInfos()[idx], sourceFrame);
            assert con.getJavaKind() != JavaKind.Illegal;
            if (con.getJavaKind().isObject() && SubstrateObjectConstant.isCompressed(con) != targetValue.isCompressedReference()) {
                // rewrap in constant with the appropriate compression for the target value
                Object obj = SubstrateObjectConstant.asObject(con);
                con = SubstrateObjectConstant.forObject(obj, targetValue.isCompressedReference());
            }
            relockVirtualObject(sourceFrame, idx, con);
            switch(targetValue.getType()) {
                case StackSlot:
                    /*
                         * The target value is on the stack
                         */
                    DeoptimizationCounters.counters().stackValueCount.inc();
                    int targetOffset = TypeConversion.asS4(targetValue.getData());
                    assert targetOffset != targetFrameSize : "stack slot would overwrite return address";
                    int totalOffset = targetContentSize + targetOffset;
                    assert totalOffset >= endOfParams : "stack location overwrites param area";
                    if (targetOffset < targetFrameSize) {
                        /*
                             * This is the most common case: a regular slot in the stack frame,
                             * which e.g. holds a variable.
                             */
                        assert totalOffset >= targetContentSize;
                        result.values[idx] = DeoptimizedFrame.ConstantEntry.factory(totalOffset, con);
                    } else if (sourceFrame.getCaller() != null) {
                        /*
                             * Handle stack parameters for inlined calls: write the value to the
                             * outgoing parameter area of the caller frame.
                             */
                        assert totalOffset >= targetContentSize;
                        result.values[idx] = DeoptimizedFrame.ConstantEntry.factory(totalOffset, con);
                        int endOffset = totalOffset + ConfigurationValues.getObjectLayout().sizeInBytes(con.getJavaKind(), targetValue.isCompressedReference());
                        if (endOffset > newEndOfParams) {
                            newEndOfParams = endOffset;
                        }
                    }
                    break;
                case DefaultConstant:
                case Constant:
                    /*
                         * The target value was constant propagated. Check that source and target
                         * performed the same constant propagation
                         */
                    assert verifyConstant(targetFrame, targetValue, con);
                    DeoptimizationCounters.counters().constantValueCount.inc();
                    break;
                default:
                    /*
                         * There must not be any other target value types because deoptimization
                         * target methods are only optimized in a limited way. Especially there must
                         * not be Register values because registers cannot be alive across method
                         * calls; and there must not be virtual objects because no escape analysis
                         * is performed.
                         */
                    throw VMError.shouldNotReachHere("unknown deopt target value " + targetValue);
            }
        }
    }
    targetContentSize += targetFrameSize;
    endOfParams = newEndOfParams;
    return result;
}
Also used : VirtualFrame(com.oracle.svm.core.deopt.DeoptimizedFrame.VirtualFrame) ValueInfo(com.oracle.svm.core.code.FrameInfoQueryResult.ValueInfo) JavaConstant(jdk.vm.ci.meta.JavaConstant) FrameInfoQueryResult(com.oracle.svm.core.code.FrameInfoQueryResult)

Example 28 with JavaConstant

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

the class StampMemoryAccessTest method testReadObject.

@Ignore("not all JVMCI versions are safe yet")
@Test
public void testReadObject() {
    MemoryAccessProvider memory = getConstantReflection().getMemoryAccessProvider();
    JavaConstant base = getSnippetReflection().forObject("");
    Stamp stamp = StampFactory.forKind(JavaKind.Object);
    assertTrue(stamp.readConstant(memory, base, 128) == null);
}
Also used : MemoryAccessProvider(jdk.vm.ci.meta.MemoryAccessProvider) Stamp(org.graalvm.compiler.core.common.type.Stamp) JavaConstant(jdk.vm.ci.meta.JavaConstant) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 29 with JavaConstant

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

the class StampMemoryAccessTest method testReadPrimitive.

@Ignore("not all JVMCI versions are safe yet")
@Test
public void testReadPrimitive() {
    MemoryAccessProvider memory = getConstantReflection().getMemoryAccessProvider();
    JavaConstant base = getSnippetReflection().forObject("");
    Stamp stamp = StampFactory.forKind(JavaKind.Long);
    assertTrue(stamp.readConstant(memory, base, 128) == null);
}
Also used : MemoryAccessProvider(jdk.vm.ci.meta.MemoryAccessProvider) Stamp(org.graalvm.compiler.core.common.type.Stamp) JavaConstant(jdk.vm.ci.meta.JavaConstant) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 30 with JavaConstant

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

the class LongNodeChainTest method longAddChain.

private void longAddChain(boolean reverse) {
    HighTierContext context = getDefaultHighTierContext();
    OptionValues options = getInitialOptions();
    StructuredGraph graph = new StructuredGraph.Builder(options, DebugContext.create(options, DebugHandlersFactory.LOADER)).build();
    ValueNode constant = graph.unique(ConstantNode.forPrimitive(JavaConstant.INT_1));
    ValueNode value = null;
    if (reverse) {
        // Make sure the constant's stamp is not used to infer the add node's stamp.
        OpaqueNode opaque = graph.unique(new OpaqueNode(constant));
        constant = opaque;
        AddNode addNode = graph.unique(new AddNode(constant, constant));
        value = addNode;
        for (int i = 1; i < N; ++i) {
            AddNode newAddNode = graph.addWithoutUnique(new AddNode(constant, constant));
            addNode.setY(newAddNode);
            addNode = newAddNode;
        }
        opaque.replaceAndDelete(opaque.getValue());
    } else {
        value = constant;
        for (int i = 0; i < N; ++i) {
            value = graph.unique(new AddNode(constant, value));
        }
    }
    ReturnNode returnNode = graph.add(new ReturnNode(value));
    graph.start().setNext(returnNode);
    for (SchedulingStrategy s : Strategies) {
        new SchedulePhase(s).apply(graph);
    }
    new CanonicalizerPhase().apply(graph, context);
    JavaConstant asConstant = (JavaConstant) returnNode.result().asConstant();
    Assert.assertEquals(N + 1, asConstant.asInt());
}
Also used : SchedulePhase(org.graalvm.compiler.phases.schedule.SchedulePhase) OptionValues(org.graalvm.compiler.options.OptionValues) JavaConstant(jdk.vm.ci.meta.JavaConstant) OpaqueNode(org.graalvm.compiler.nodes.debug.OpaqueNode) ReturnNode(org.graalvm.compiler.nodes.ReturnNode) SchedulingStrategy(org.graalvm.compiler.phases.schedule.SchedulePhase.SchedulingStrategy) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) ValueNode(org.graalvm.compiler.nodes.ValueNode) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) HighTierContext(org.graalvm.compiler.phases.tiers.HighTierContext) AddNode(org.graalvm.compiler.nodes.calc.AddNode)

Aggregations

JavaConstant (jdk.vm.ci.meta.JavaConstant)122 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)33 ValueNode (org.graalvm.compiler.nodes.ValueNode)24 Test (org.junit.Test)19 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)17 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)15 Stamp (org.graalvm.compiler.core.common.type.Stamp)11 LIRValueUtil.asJavaConstant (org.graalvm.compiler.lir.LIRValueUtil.asJavaConstant)11 LIRValueUtil.isJavaConstant (org.graalvm.compiler.lir.LIRValueUtil.isJavaConstant)11 JavaKind (jdk.vm.ci.meta.JavaKind)10 Constant (jdk.vm.ci.meta.Constant)9 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)8 AllocatableValue (jdk.vm.ci.meta.AllocatableValue)7 Condition (org.graalvm.compiler.core.common.calc.Condition)7 IntegerStamp (org.graalvm.compiler.core.common.type.IntegerStamp)6 FixedGuardNode (org.graalvm.compiler.nodes.FixedGuardNode)6 LogicNode (org.graalvm.compiler.nodes.LogicNode)6 FixedNode (org.graalvm.compiler.nodes.FixedNode)5 ParameterNode (org.graalvm.compiler.nodes.ParameterNode)5 ReturnNode (org.graalvm.compiler.nodes.ReturnNode)5