Search in sources :

Example 1 with HotSpotResolvedJavaField

use of jdk.vm.ci.hotspot.HotSpotResolvedJavaField 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 HotSpotResolvedJavaField

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

the class DefaultHotSpotLoweringProvider method staticFieldBase.

@Override
public ValueNode staticFieldBase(StructuredGraph graph, ResolvedJavaField f) {
    HotSpotResolvedJavaField field = (HotSpotResolvedJavaField) f;
    JavaConstant base = constantReflection.asJavaClass(field.getDeclaringClass());
    return ConstantNode.forConstant(base, metaAccess, graph);
}
Also used : JavaConstant(jdk.vm.ci.meta.JavaConstant) HotSpotResolvedJavaField(jdk.vm.ci.hotspot.HotSpotResolvedJavaField)

Example 3 with HotSpotResolvedJavaField

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

the class HotSpotResolvedJavaFieldTest method testEquivalenceForInternalFields.

/**
 * Tests that {@code HotSpotResolvedObjectType#createField(String, JavaType, long, int)} always
 * returns an {@linkplain ResolvedJavaField#equals(Object) equivalent} object for an internal
 * field.
 *
 * @throws InvocationTargetException
 * @throws IllegalArgumentException
 * @throws IllegalAccessException
 */
@Test
public void testEquivalenceForInternalFields() throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
    for (Class<?> c : classesWithInternalFields) {
        HotSpotResolvedObjectType type = HotSpotResolvedObjectType.fromObjectClass(c);
        for (ResolvedJavaField field : type.getInstanceFields(false)) {
            if (field.isInternal()) {
                HotSpotResolvedJavaField expected = (HotSpotResolvedJavaField) field;
                int index = indexField.getInt(expected);
                ResolvedJavaField actual = (ResolvedJavaField) createFieldMethod.invoke(type, expected.getType(), expected.offset(), expected.getModifiers(), index);
                Assert.assertEquals(expected, actual);
            }
        }
    }
}
Also used : HotSpotResolvedObjectType(jdk.vm.ci.hotspot.HotSpotResolvedObjectType) HotSpotResolvedJavaField(jdk.vm.ci.hotspot.HotSpotResolvedJavaField) ResolvedJavaField(jdk.vm.ci.meta.ResolvedJavaField) HotSpotResolvedJavaField(jdk.vm.ci.hotspot.HotSpotResolvedJavaField) Test(org.junit.Test)

Example 4 with HotSpotResolvedJavaField

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

the class DefaultHotSpotLoweringProvider method fieldLoadBarrierType.

@Override
protected BarrierType fieldLoadBarrierType(ResolvedJavaField f) {
    HotSpotResolvedJavaField loadField = (HotSpotResolvedJavaField) f;
    BarrierType barrierType = BarrierType.NONE;
    if (runtime.getVMConfig().useG1GC && loadField.getJavaKind() == JavaKind.Object && metaAccess.lookupJavaType(Reference.class).equals(loadField.getDeclaringClass()) && loadField.getName().equals("referent")) {
        barrierType = BarrierType.PRECISE;
    }
    return barrierType;
}
Also used : Reference(java.lang.ref.Reference) HotSpotResolvedJavaField(jdk.vm.ci.hotspot.HotSpotResolvedJavaField) BarrierType(org.graalvm.compiler.nodes.memory.HeapAccess.BarrierType)

Example 5 with HotSpotResolvedJavaField

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

the class HotSpotResolvedJavaFieldTest method testIsInObject.

@Test
public void testIsInObject() {
    for (Field f : String.class.getDeclaredFields()) {
        HotSpotResolvedJavaField rf = (HotSpotResolvedJavaField) getMetaAccess().lookupJavaField(f);
        Assert.assertEquals(rf.toString(), rf.isInObject("a string"), !rf.isStatic());
    }
}
Also used : Field(java.lang.reflect.Field) ResolvedJavaField(jdk.vm.ci.meta.ResolvedJavaField) HotSpotResolvedJavaField(jdk.vm.ci.hotspot.HotSpotResolvedJavaField) HotSpotResolvedJavaField(jdk.vm.ci.hotspot.HotSpotResolvedJavaField) Test(org.junit.Test)

Aggregations

HotSpotResolvedJavaField (jdk.vm.ci.hotspot.HotSpotResolvedJavaField)5 HotSpotResolvedObjectType (jdk.vm.ci.hotspot.HotSpotResolvedObjectType)2 ResolvedJavaField (jdk.vm.ci.meta.ResolvedJavaField)2 Test (org.junit.Test)2 Reference (java.lang.ref.Reference)1 Field (java.lang.reflect.Field)1 HotSpotObjectConstant (jdk.vm.ci.hotspot.HotSpotObjectConstant)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 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)1 AbstractObjectStamp (org.graalvm.compiler.core.common.type.AbstractObjectStamp)1 Stamp (org.graalvm.compiler.core.common.type.Stamp)1 GraalError (org.graalvm.compiler.debug.GraalError)1 HotSpotNarrowOopStamp (org.graalvm.compiler.hotspot.nodes.type.HotSpotNarrowOopStamp)1 KlassPointerStamp (org.graalvm.compiler.hotspot.nodes.type.KlassPointerStamp)1 HubGetClassNode (org.graalvm.compiler.hotspot.replacements.HubGetClassNode)1 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)1 ValueNode (org.graalvm.compiler.nodes.ValueNode)1