Search in sources :

Example 1 with HotSpotObjectConstant

use of jdk.vm.ci.hotspot.HotSpotObjectConstant in project graal by oracle.

the class AArch64HotSpotLIRGenerator method emitCompare.

@Override
protected boolean emitCompare(PlatformKind cmpKind, Value a, Value b, Condition condition, boolean unorderedIsTrue) {
    Value localA = a;
    Value localB = b;
    if (isConstantValue(a)) {
        Constant c = asConstant(a);
        if (HotSpotCompressedNullConstant.COMPRESSED_NULL.equals(c)) {
            localA = AArch64.zr.asValue(LIRKind.value(AArch64Kind.DWORD));
        } else if (c instanceof HotSpotObjectConstant) {
            localA = load(localA);
        }
    }
    if (isConstantValue(b)) {
        Constant c = asConstant(b);
        if (HotSpotCompressedNullConstant.COMPRESSED_NULL.equals(c)) {
            localB = AArch64.zr.asValue(LIRKind.value(AArch64Kind.DWORD));
        } else if (c instanceof HotSpotObjectConstant) {
            localB = load(localB);
        }
    }
    return super.emitCompare(cmpKind, localA, localB, condition, unorderedIsTrue);
}
Also used : Constant(jdk.vm.ci.meta.Constant) JavaConstant(jdk.vm.ci.meta.JavaConstant) HotSpotCompressedNullConstant(jdk.vm.ci.hotspot.HotSpotCompressedNullConstant) HotSpotObjectConstant(jdk.vm.ci.hotspot.HotSpotObjectConstant) LIRValueUtil.asConstant(org.graalvm.compiler.lir.LIRValueUtil.asConstant) LIRValueUtil.isConstantValue(org.graalvm.compiler.lir.LIRValueUtil.isConstantValue) Value(jdk.vm.ci.meta.Value) AllocatableValue(jdk.vm.ci.meta.AllocatableValue) AArch64AddressValue(org.graalvm.compiler.lir.aarch64.AArch64AddressValue) RegisterValue(jdk.vm.ci.code.RegisterValue) HotSpotObjectConstant(jdk.vm.ci.hotspot.HotSpotObjectConstant)

Example 2 with HotSpotObjectConstant

use of jdk.vm.ci.hotspot.HotSpotObjectConstant in project graal by oracle.

the class LoadJavaMirrorWithKlassPhase method getClassConstantReplacement.

private ValueNode getClassConstantReplacement(StructuredGraph graph, PhaseContext context, JavaConstant constant) {
    if (constant instanceof HotSpotObjectConstant) {
        ConstantReflectionProvider constantReflection = context.getConstantReflection();
        ResolvedJavaType type = constantReflection.asJavaType(constant);
        if (type != null) {
            MetaAccessProvider metaAccess = context.getMetaAccess();
            Stamp stamp = StampFactory.objectNonNull(TypeReference.createExactTrusted(metaAccess.lookupJavaType(Class.class)));
            if (type instanceof HotSpotResolvedObjectType) {
                ConstantNode klass = ConstantNode.forConstant(KlassPointerStamp.klassNonNull(), ((HotSpotResolvedObjectType) type).klass(), metaAccess, graph);
                ValueNode getClass = graph.unique(new HubGetClassNode(metaAccess, klass));
                if (((HotSpotObjectConstant) constant).isCompressed()) {
                    return HotSpotCompressionNode.compress(getClass, oopEncoding);
                } else {
                    return getClass;
                }
            } else {
                /*
                     * Primitive classes are more difficult since they don't have a corresponding
                     * Klass* so get them from Class.TYPE for the java box type.
                     */
                HotSpotResolvedPrimitiveType primitive = (HotSpotResolvedPrimitiveType) type;
                ResolvedJavaType boxingClass = metaAccess.lookupJavaType(primitive.getJavaKind().toBoxedJavaClass());
                ConstantNode clazz = ConstantNode.forConstant(context.getConstantReflection().asJavaClass(boxingClass), metaAccess, graph);
                HotSpotResolvedJavaField[] a = (HotSpotResolvedJavaField[]) boxingClass.getStaticFields();
                HotSpotResolvedJavaField typeField = null;
                for (HotSpotResolvedJavaField f : a) {
                    if (f.getName().equals("TYPE")) {
                        typeField = f;
                        break;
                    }
                }
                if (typeField == null) {
                    throw new GraalError("Can't find TYPE field in class");
                }
                if (oopEncoding != null) {
                    stamp = HotSpotNarrowOopStamp.compressed((AbstractObjectStamp) stamp, oopEncoding);
                }
                AddressNode address = graph.unique(new OffsetAddressNode(clazz, ConstantNode.forLong(typeField.offset(), graph)));
                ValueNode read = graph.unique(new FloatingReadNode(address, FINAL_LOCATION, null, stamp));
                if (oopEncoding == null || ((HotSpotObjectConstant) constant).isCompressed()) {
                    return read;
                } else {
                    return HotSpotCompressionNode.uncompress(read, oopEncoding);
                }
            }
        }
    }
    return null;
}
Also used : KlassPointerStamp(org.graalvm.compiler.hotspot.nodes.type.KlassPointerStamp) AbstractObjectStamp(org.graalvm.compiler.core.common.type.AbstractObjectStamp) HotSpotNarrowOopStamp(org.graalvm.compiler.hotspot.nodes.type.HotSpotNarrowOopStamp) Stamp(org.graalvm.compiler.core.common.type.Stamp) HubGetClassNode(org.graalvm.compiler.hotspot.replacements.HubGetClassNode) HotSpotResolvedPrimitiveType(jdk.vm.ci.hotspot.HotSpotResolvedPrimitiveType) AbstractObjectStamp(org.graalvm.compiler.core.common.type.AbstractObjectStamp) HotSpotResolvedJavaField(jdk.vm.ci.hotspot.HotSpotResolvedJavaField) HotSpotObjectConstant(jdk.vm.ci.hotspot.HotSpotObjectConstant) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) GraalError(org.graalvm.compiler.debug.GraalError) OffsetAddressNode(org.graalvm.compiler.nodes.memory.address.OffsetAddressNode) ConstantReflectionProvider(jdk.vm.ci.meta.ConstantReflectionProvider) HotSpotResolvedObjectType(jdk.vm.ci.hotspot.HotSpotResolvedObjectType) FloatingReadNode(org.graalvm.compiler.nodes.memory.FloatingReadNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) OffsetAddressNode(org.graalvm.compiler.nodes.memory.address.OffsetAddressNode) AddressNode(org.graalvm.compiler.nodes.memory.address.AddressNode) MetaAccessProvider(jdk.vm.ci.meta.MetaAccessProvider)

Example 3 with HotSpotObjectConstant

use of jdk.vm.ci.hotspot.HotSpotObjectConstant in project graal by oracle.

the class ReplaceConstantNodesPhase method handleHotSpotObjectConstant.

/**
 * Replace an object constant with an indirect load {@link ResolveConstantNode}. Currently we
 * support only strings.
 *
 * @param graph
 * @param stateMapper
 * @param node {@link ConstantNode} containing a {@link HotSpotObjectConstant} that needs
 *            resolution.
 */
private static void handleHotSpotObjectConstant(StructuredGraph graph, FrameStateMapperClosure stateMapper, ConstantNode node) {
    HotSpotObjectConstant constant = (HotSpotObjectConstant) node.asJavaConstant();
    HotSpotResolvedJavaType type = (HotSpotResolvedJavaType) constant.getType();
    if (type.mirror().equals(String.class)) {
        assert !constant.isCompressed() : "No support for replacing compressed oop constants";
        FixedWithNextNode replacement = graph.add(new ResolveConstantNode(node));
        insertReplacement(graph, stateMapper, node, replacement);
        node.replaceAtUsages(replacement, n -> !(n instanceof ResolveConstantNode));
    } else {
        throw new GraalError("Unsupported object constant type: " + type);
    }
}
Also used : ResolveConstantNode(org.graalvm.compiler.hotspot.nodes.aot.ResolveConstantNode) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) GraalError(org.graalvm.compiler.debug.GraalError) HotSpotResolvedJavaType(jdk.vm.ci.hotspot.HotSpotResolvedJavaType) HotSpotObjectConstant(jdk.vm.ci.hotspot.HotSpotObjectConstant)

Example 4 with HotSpotObjectConstant

use of jdk.vm.ci.hotspot.HotSpotObjectConstant in project graal by oracle.

the class ResolveConstantStubCall method generate.

@Override
public void generate(NodeLIRBuilderTool gen) {
    assert constant != null : "Expected the value to fold: " + value;
    Value stringValue = gen.operand(string);
    Value result;
    LIRFrameState fs = gen.state(this);
    assert fs != null : "The stateAfter is null";
    if (constant instanceof HotSpotObjectConstant) {
        result = ((HotSpotLIRGenerator) gen.getLIRGeneratorTool()).emitObjectConstantRetrieval(constant, stringValue, fs);
    } else if (constant instanceof HotSpotMetaspaceConstant) {
        if (action == HotSpotConstantLoadAction.RESOLVE) {
            result = ((HotSpotLIRGenerator) gen.getLIRGeneratorTool()).emitMetaspaceConstantRetrieval(constant, stringValue, fs);
        } else {
            assert action == HotSpotConstantLoadAction.INITIALIZE;
            result = ((HotSpotLIRGenerator) gen.getLIRGeneratorTool()).emitKlassInitializationAndRetrieval(constant, stringValue, fs);
        }
    } else {
        throw new PermanentBailoutException("Unsupported constant type: " + constant);
    }
    gen.setResult(this, result);
}
Also used : LIRFrameState(org.graalvm.compiler.lir.LIRFrameState) HotSpotLIRGenerator(org.graalvm.compiler.hotspot.HotSpotLIRGenerator) Value(jdk.vm.ci.meta.Value) HotSpotObjectConstant(jdk.vm.ci.hotspot.HotSpotObjectConstant) HotSpotMetaspaceConstant(jdk.vm.ci.hotspot.HotSpotMetaspaceConstant) PermanentBailoutException(org.graalvm.compiler.core.common.PermanentBailoutException)

Example 5 with HotSpotObjectConstant

use of jdk.vm.ci.hotspot.HotSpotObjectConstant in project graal by oracle.

the class SPARCHotSpotLIRGenerator method emitCompareBranch.

@Override
public void emitCompareBranch(PlatformKind cmpKind, Value x, Value y, Condition cond, boolean unorderedIsTrue, LabelRef trueDestination, LabelRef falseDestination, double trueDestinationProbability) {
    Value localX = x;
    Value localY = y;
    if (localX instanceof HotSpotObjectConstant) {
        localX = load(localX);
    }
    if (localY instanceof HotSpotObjectConstant) {
        localY = load(localY);
    }
    super.emitCompareBranch(cmpKind, localX, localY, cond, unorderedIsTrue, trueDestination, falseDestination, trueDestinationProbability);
}
Also used : LIRValueUtil.isConstantValue(org.graalvm.compiler.lir.LIRValueUtil.isConstantValue) Value(jdk.vm.ci.meta.Value) AllocatableValue(jdk.vm.ci.meta.AllocatableValue) SPARCImmediateAddressValue(org.graalvm.compiler.lir.sparc.SPARCImmediateAddressValue) RegisterValue(jdk.vm.ci.code.RegisterValue) SPARCAddressValue(org.graalvm.compiler.lir.sparc.SPARCAddressValue) HotSpotObjectConstant(jdk.vm.ci.hotspot.HotSpotObjectConstant)

Aggregations

HotSpotObjectConstant (jdk.vm.ci.hotspot.HotSpotObjectConstant)12 Value (jdk.vm.ci.meta.Value)7 RegisterValue (jdk.vm.ci.code.RegisterValue)4 AllocatableValue (jdk.vm.ci.meta.AllocatableValue)4 JavaConstant (jdk.vm.ci.meta.JavaConstant)4 LIRValueUtil.isConstantValue (org.graalvm.compiler.lir.LIRValueUtil.isConstantValue)4 HotSpotMetaspaceConstant (jdk.vm.ci.hotspot.HotSpotMetaspaceConstant)3 PermanentBailoutException (org.graalvm.compiler.core.common.PermanentBailoutException)3 HotSpotLIRGenerator (org.graalvm.compiler.hotspot.HotSpotLIRGenerator)3 HotSpotCompressedNullConstant (jdk.vm.ci.hotspot.HotSpotCompressedNullConstant)2 Constant (jdk.vm.ci.meta.Constant)2 AbstractObjectStamp (org.graalvm.compiler.core.common.type.AbstractObjectStamp)2 GraalError (org.graalvm.compiler.debug.GraalError)2 LIRValueUtil.asConstant (org.graalvm.compiler.lir.LIRValueUtil.asConstant)2 AArch64AddressValue (org.graalvm.compiler.lir.aarch64.AArch64AddressValue)2 SPARCAddressValue (org.graalvm.compiler.lir.sparc.SPARCAddressValue)2 SPARCImmediateAddressValue (org.graalvm.compiler.lir.sparc.SPARCImmediateAddressValue)2 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)2 HotSpotResolvedJavaField (jdk.vm.ci.hotspot.HotSpotResolvedJavaField)1 HotSpotResolvedJavaType (jdk.vm.ci.hotspot.HotSpotResolvedJavaType)1