Search in sources :

Example 61 with JavaConstant

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

the class HostedField method readValue.

@Override
public JavaConstant readValue(JavaConstant receiver) {
    JavaConstant result;
    if (location == LOC_CONSTANT_STATIC_FIELD) {
        return getConstantValue();
    } else {
        JavaConstant wrappedReceiver;
        if (receiver != null && SubstrateObjectConstant.asObject(receiver) instanceof Class) {
            /* Manual object replacement from java.lang.Class to DynamicHub. */
            wrappedReceiver = SubstrateObjectConstant.forObject(metaAccess.lookupJavaType((Class<?>) SubstrateObjectConstant.asObject(receiver)).getHub());
        } else {
            wrappedReceiver = receiver;
        }
        result = universe.lookup(universe.getConstantReflectionProvider().readFieldValue(wrapped, wrappedReceiver));
    }
    return result;
}
Also used : JavaConstant(jdk.vm.ci.meta.JavaConstant)

Example 62 with JavaConstant

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

the class HostedMemoryAccessProvider method doRead.

/**
 * Try to look up the original field from the given displacement, and read the field value.
 */
private JavaConstant doRead(JavaKind stackKind, JavaConstant base, long displacement) {
    if (base.getJavaKind() != JavaKind.Object) {
        return null;
    }
    HostedType type = (HostedType) metaAccess.lookupJavaType(base);
    HostedField field = (HostedField) type.findInstanceFieldWithOffset(displacement, null);
    if (field == null) {
        return null;
    }
    assert field.getStorageKind().getStackKind() == stackKind;
    JavaConstant result = field.readValue(base);
    assert result.getJavaKind().getStackKind() == stackKind;
    return result;
}
Also used : JavaConstant(jdk.vm.ci.meta.JavaConstant)

Example 63 with JavaConstant

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

the class AheadOfTimeCompilationTest method testStringObjectCommon.

private void testStringObjectCommon(boolean compileAOT) {
    StructuredGraph result = compile("getStringObject", compileAOT);
    NodeIterable<ConstantNode> filter = getConstantNodes(result);
    assertDeepEquals(1, filter.count());
    JavaConstant c = filter.first().asJavaConstant();
    Assert.assertEquals(getSnippetReflection().asObject(String.class, c), "test string");
    assertDeepEquals(0, result.getNodes().filter(FloatingReadNode.class).count());
    assertDeepEquals(0, result.getNodes().filter(ReadNode.class).count());
}
Also used : ConstantNode(org.graalvm.compiler.nodes.ConstantNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) JavaConstant(jdk.vm.ci.meta.JavaConstant)

Example 64 with JavaConstant

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

the class AheadOfTimeCompilationTest method testBoxedBoolean.

@Test
public void testBoxedBoolean() {
    StructuredGraph result = compile("getBoxedBoolean", false);
    assertDeepEquals(0, result.getNodes().filter(FloatingReadNode.class).count());
    assertDeepEquals(0, result.getNodes(PiNode.TYPE).count());
    assertDeepEquals(1, getConstantNodes(result).count());
    ConstantNode constant = getConstantNodes(result).first();
    assertDeepEquals(JavaKind.Object, constant.getStackKind());
    JavaConstant c = constant.asJavaConstant();
    Assert.assertEquals(getSnippetReflection().asObject(Boolean.class, c), Boolean.TRUE);
}
Also used : ConstantNode(org.graalvm.compiler.nodes.ConstantNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) JavaConstant(jdk.vm.ci.meta.JavaConstant) Test(org.junit.Test)

Example 65 with JavaConstant

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

the class AMD64HotSpotSafepointOp method emitGlobalPoll.

private static void emitGlobalPoll(CompilationResultBuilder crb, AMD64MacroAssembler asm, GraalHotSpotVMConfig config, boolean atReturn, LIRFrameState state, Register scratch) {
    assert !atReturn || state == null : "state is unneeded at return";
    if (ImmutableCode.getValue(crb.getOptions())) {
        JavaKind hostWordKind = JavaKind.Long;
        int alignment = hostWordKind.getBitCount() / Byte.SIZE;
        JavaConstant pollingPageAddress = JavaConstant.forIntegerKind(hostWordKind, config.safepointPollingAddress);
        // co-located with the immutable code.
        if (GeneratePIC.getValue(crb.getOptions())) {
            asm.movq(scratch, asm.getPlaceholder(-1));
        } else {
            asm.movq(scratch, (AMD64Address) crb.recordDataReferenceInCode(pollingPageAddress, alignment));
        }
        final int pos = asm.position();
        crb.recordMark(atReturn ? config.MARKID_POLL_RETURN_FAR : config.MARKID_POLL_FAR);
        if (state != null) {
            crb.recordInfopoint(pos, state, InfopointReason.SAFEPOINT);
        }
        asm.testl(rax, new AMD64Address(scratch));
    } else if (isPollingPageFar(config)) {
        asm.movq(scratch, config.safepointPollingAddress);
        crb.recordMark(atReturn ? config.MARKID_POLL_RETURN_FAR : config.MARKID_POLL_FAR);
        final int pos = asm.position();
        if (state != null) {
            crb.recordInfopoint(pos, state, InfopointReason.SAFEPOINT);
        }
        asm.testl(rax, new AMD64Address(scratch));
    } else {
        crb.recordMark(atReturn ? config.MARKID_POLL_RETURN_NEAR : config.MARKID_POLL_NEAR);
        final int pos = asm.position();
        if (state != null) {
            crb.recordInfopoint(pos, state, InfopointReason.SAFEPOINT);
        }
        // The C++ code transforms the polling page offset into an RIP displacement
        // to the real address at that offset in the polling page.
        asm.testl(rax, new AMD64Address(rip, 0));
    }
}
Also used : JavaConstant(jdk.vm.ci.meta.JavaConstant) AMD64Address(org.graalvm.compiler.asm.amd64.AMD64Address) JavaKind(jdk.vm.ci.meta.JavaKind)

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