Search in sources :

Example 1 with AbstractObjectStamp

use of org.graalvm.compiler.core.common.type.AbstractObjectStamp 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 2 with AbstractObjectStamp

use of org.graalvm.compiler.core.common.type.AbstractObjectStamp in project graal by oracle.

the class StampTool method typeOrNull.

public static ResolvedJavaType typeOrNull(Stamp stamp, MetaAccessProvider metaAccess) {
    if (stamp instanceof AbstractObjectStamp && stamp.hasValues()) {
        AbstractObjectStamp abstractObjectStamp = (AbstractObjectStamp) stamp;
        ResolvedJavaType type = abstractObjectStamp.type();
        if (type == null) {
            return metaAccess.lookupJavaType(Object.class);
        } else {
            return type;
        }
    }
    return null;
}
Also used : AbstractObjectStamp(org.graalvm.compiler.core.common.type.AbstractObjectStamp) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType)

Example 3 with AbstractObjectStamp

use of org.graalvm.compiler.core.common.type.AbstractObjectStamp in project graal by oracle.

the class CompressionNode method generate.

@Override
public void generate(NodeLIRBuilderTool gen) {
    boolean nonNull;
    if (value.stamp(NodeView.DEFAULT) instanceof AbstractObjectStamp) {
        nonNull = StampTool.isPointerNonNull(value.stamp(NodeView.DEFAULT));
    } else {
        // metaspace pointers are never null
        nonNull = true;
    }
    LIRGeneratorTool tool = gen.getLIRGeneratorTool();
    Value result;
    switch(op) {
        case Compress:
            result = tool.emitCompress(gen.operand(value), encoding, nonNull);
            break;
        case Uncompress:
            result = tool.emitUncompress(gen.operand(value), encoding, nonNull);
            break;
        default:
            throw GraalError.shouldNotReachHere();
    }
    gen.setResult(this, result);
}
Also used : Value(jdk.vm.ci.meta.Value) AbstractObjectStamp(org.graalvm.compiler.core.common.type.AbstractObjectStamp) LIRGeneratorTool(org.graalvm.compiler.lir.gen.LIRGeneratorTool)

Example 4 with AbstractObjectStamp

use of org.graalvm.compiler.core.common.type.AbstractObjectStamp in project graal by oracle.

the class ConstantNode method forPrimitive.

/**
 * Returns a node for a primitive of a given type.
 */
public static ConstantNode forPrimitive(Stamp stamp, Constant constant) {
    if (stamp instanceof IntegerStamp) {
        PrimitiveConstant primitive = (PrimitiveConstant) constant;
        assert primitive.getJavaKind().isNumericInteger() && stamp.getStackKind() == primitive.getJavaKind().getStackKind();
        IntegerStamp istamp = (IntegerStamp) stamp;
        return forIntegerBits(istamp.getBits(), primitive);
    } else if (stamp instanceof FloatStamp) {
        PrimitiveConstant primitive = (PrimitiveConstant) constant;
        assert primitive.getJavaKind().isNumericFloat() && stamp.getStackKind() == primitive.getJavaKind();
        return forConstant(primitive, null);
    } else {
        assert !(stamp instanceof AbstractObjectStamp);
        return new ConstantNode(constant, stamp.constant(constant, null));
    }
}
Also used : PrimitiveConstant(jdk.vm.ci.meta.PrimitiveConstant) IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp) AbstractObjectStamp(org.graalvm.compiler.core.common.type.AbstractObjectStamp) FloatStamp(org.graalvm.compiler.core.common.type.FloatStamp)

Example 5 with AbstractObjectStamp

use of org.graalvm.compiler.core.common.type.AbstractObjectStamp in project graal by oracle.

the class StrengthenStampsPhase method strengthen.

private Stamp strengthen(Stamp s) {
    if (!(s instanceof AbstractObjectStamp)) {
        return null;
    }
    AbstractObjectStamp stamp = (AbstractObjectStamp) s;
    HostedType originalType = toHosted(stamp.type());
    if (originalType == null) {
        return null;
    }
    HostedType strengthenType = originalType.getStrengthenStampType();
    if (originalType.equals(strengthenType)) {
        /* Nothing to strengthen. */
        return null;
    }
    Stamp newStamp;
    if (strengthenType == null) {
        if (stamp.nonNull()) {
            /* We must be in dead code. */
            newStamp = StampFactory.empty(JavaKind.Object);
        } else {
            /* The type its subtypes are not instantiated, the only possible value is null. */
            newStamp = StampFactory.alwaysNull();
        }
    } else {
        if (stamp.isExactType()) {
            /* We must be in dead code. */
            newStamp = StampFactory.empty(JavaKind.Object);
        } else {
            TypeReference typeRef = TypeReference.createTrustedWithoutAssumptions(toTarget(strengthenType));
            newStamp = StampFactory.object(typeRef, stamp.nonNull());
        }
    }
    return newStamp;
}
Also used : HostedType(com.oracle.svm.hosted.meta.HostedType) ObjectStamp(org.graalvm.compiler.core.common.type.ObjectStamp) AbstractObjectStamp(org.graalvm.compiler.core.common.type.AbstractObjectStamp) Stamp(org.graalvm.compiler.core.common.type.Stamp) AbstractObjectStamp(org.graalvm.compiler.core.common.type.AbstractObjectStamp) TypeReference(org.graalvm.compiler.core.common.type.TypeReference)

Aggregations

AbstractObjectStamp (org.graalvm.compiler.core.common.type.AbstractObjectStamp)7 Stamp (org.graalvm.compiler.core.common.type.Stamp)3 HotSpotObjectConstant (jdk.vm.ci.hotspot.HotSpotObjectConstant)2 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)2 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)2 HostedType (com.oracle.svm.hosted.meta.HostedType)1 HotSpotResolvedJavaField (jdk.vm.ci.hotspot.HotSpotResolvedJavaField)1 HotSpotResolvedObjectType (jdk.vm.ci.hotspot.HotSpotResolvedObjectType)1 HotSpotResolvedPrimitiveType (jdk.vm.ci.hotspot.HotSpotResolvedPrimitiveType)1 ConstantReflectionProvider (jdk.vm.ci.meta.ConstantReflectionProvider)1 JavaConstant (jdk.vm.ci.meta.JavaConstant)1 MetaAccessProvider (jdk.vm.ci.meta.MetaAccessProvider)1 PrimitiveConstant (jdk.vm.ci.meta.PrimitiveConstant)1 Value (jdk.vm.ci.meta.Value)1 FloatStamp (org.graalvm.compiler.core.common.type.FloatStamp)1 IntegerStamp (org.graalvm.compiler.core.common.type.IntegerStamp)1 ObjectStamp (org.graalvm.compiler.core.common.type.ObjectStamp)1 TypeReference (org.graalvm.compiler.core.common.type.TypeReference)1 GraalError (org.graalvm.compiler.debug.GraalError)1 HotSpotNarrowOopStamp (org.graalvm.compiler.hotspot.nodes.type.HotSpotNarrowOopStamp)1