Search in sources :

Example 41 with ResolvedJavaField

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

the class HotSpotGraalConstantFieldProvider method isEmbeddableField.

protected boolean isEmbeddableField(ResolvedJavaField field) {
    if (nonEmbeddableFields == null) {
        synchronized (this) {
            if (nonEmbeddableFields == null) {
                List<ResolvedJavaField> fields = new ArrayList<>();
                try {
                    fields.add(metaAccess.lookupJavaField(Boolean.class.getDeclaredField("TRUE")));
                    fields.add(metaAccess.lookupJavaField(Boolean.class.getDeclaredField("FALSE")));
                    Class<?> characterCacheClass = Character.class.getDeclaredClasses()[0];
                    assert "java.lang.Character$CharacterCache".equals(characterCacheClass.getName());
                    fields.add(metaAccess.lookupJavaField(characterCacheClass.getDeclaredField("cache")));
                    Class<?> byteCacheClass = Byte.class.getDeclaredClasses()[0];
                    assert "java.lang.Byte$ByteCache".equals(byteCacheClass.getName());
                    fields.add(metaAccess.lookupJavaField(byteCacheClass.getDeclaredField("cache")));
                    Class<?> shortCacheClass = Short.class.getDeclaredClasses()[0];
                    assert "java.lang.Short$ShortCache".equals(shortCacheClass.getName());
                    fields.add(metaAccess.lookupJavaField(shortCacheClass.getDeclaredField("cache")));
                    Class<?> integerCacheClass = Integer.class.getDeclaredClasses()[0];
                    assert "java.lang.Integer$IntegerCache".equals(integerCacheClass.getName());
                    fields.add(metaAccess.lookupJavaField(integerCacheClass.getDeclaredField("cache")));
                    Class<?> longCacheClass = Long.class.getDeclaredClasses()[0];
                    assert "java.lang.Long$LongCache".equals(longCacheClass.getName());
                    fields.add(metaAccess.lookupJavaField(longCacheClass.getDeclaredField("cache")));
                    fields.add(metaAccess.lookupJavaField(Throwable.class.getDeclaredField("UNASSIGNED_STACK")));
                    fields.add(metaAccess.lookupJavaField(Throwable.class.getDeclaredField("SUPPRESSED_SENTINEL")));
                } catch (SecurityException | NoSuchFieldException e) {
                    throw new GraalError(e);
                }
                nonEmbeddableFields = fields;
            }
        }
    }
    return !nonEmbeddableFields.contains(field);
}
Also used : ArrayList(java.util.ArrayList) ResolvedJavaField(jdk.vm.ci.meta.ResolvedJavaField) GraalError(org.graalvm.compiler.debug.GraalError)

Example 42 with ResolvedJavaField

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

the class ObjectScanner method unsupportedFeature.

private void unsupportedFeature(String key, String message, Object entry) {
    StringBuilder objectBacktrace = new StringBuilder();
    Object cur = entry;
    AnalysisMethod method = null;
    while (cur instanceof WorklistEntry) {
        WorklistEntry curEntry = (WorklistEntry) cur;
        objectBacktrace.append("\tobject ").append(bb.getMetaAccess().lookupJavaType(curEntry.constant).toJavaName(true)).append(System.lineSeparator());
        cur = curEntry.reason;
    }
    if (cur instanceof ResolvedJavaField) {
        objectBacktrace.append("\tfield ").append(((ResolvedJavaField) cur).format("%H.%n"));
    } else if (cur instanceof ResolvedJavaMethod) {
        objectBacktrace.append("\tmethod ").append(((ResolvedJavaMethod) cur).format("%H.%n(%p)"));
        method = (AnalysisMethod) cur;
    } else {
        objectBacktrace.append("\t[unknown] ").append(cur.toString());
    }
    bb.getUnsupportedFeatures().addMessage(key, method, message, objectBacktrace.toString());
}
Also used : AnalysisMethod(com.oracle.graal.pointsto.meta.AnalysisMethod) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) ResolvedJavaField(jdk.vm.ci.meta.ResolvedJavaField)

Example 43 with ResolvedJavaField

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

the class NewInstanceNode method virtualize.

@Override
public void virtualize(VirtualizerTool tool) {
    /*
         * Reference objects can escape into their ReferenceQueue at any safepoint, therefore
         * they're excluded from escape analysis.
         */
    if (!tool.getMetaAccessProvider().lookupJavaType(Reference.class).isAssignableFrom(instanceClass)) {
        VirtualInstanceNode virtualObject = createVirtualInstanceNode(true);
        ResolvedJavaField[] fields = virtualObject.getFields();
        ValueNode[] state = new ValueNode[fields.length];
        for (int i = 0; i < state.length; i++) {
            state[i] = defaultFieldValue(fields[i]);
        }
        tool.createVirtualObject(virtualObject, state, Collections.<MonitorIdNode>emptyList(), false);
        tool.replaceWithVirtual(virtualObject);
    }
}
Also used : ValueNode(org.graalvm.compiler.nodes.ValueNode) VirtualInstanceNode(org.graalvm.compiler.nodes.virtual.VirtualInstanceNode) ResolvedJavaField(jdk.vm.ci.meta.ResolvedJavaField)

Example 44 with ResolvedJavaField

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

the class PushNodesThroughPiTest method test1.

@Ignore
@Test
@SuppressWarnings("try")
public void test1() {
    final String snippet = "test1Snippet";
    DebugContext debug = getDebugContext();
    try (DebugContext.Scope s = debug.scope("PushThroughPi", new DebugDumpScope(snippet))) {
        StructuredGraph graph = compileTestSnippet(snippet);
        for (ReadNode rn : graph.getNodes().filter(ReadNode.class)) {
            OffsetAddressNode address = (OffsetAddressNode) rn.getAddress();
            long disp = address.getOffset().asJavaConstant().asLong();
            ResolvedJavaType receiverType = StampTool.typeOrNull(address.getBase());
            ResolvedJavaField field = receiverType.findInstanceFieldWithOffset(disp, rn.getStackKind());
            assert field != null : "Node " + rn + " tries to access a field which doesn't exists for this type";
            if (field.getName().equals("x")) {
                Assert.assertTrue(address.getBase() instanceof ParameterNode);
            } else {
                Assert.assertTrue(address.getBase().toString(), address.getBase() instanceof PiNode);
            }
        }
        Assert.assertTrue(graph.getNodes().filter(IsNullNode.class).count() == 1);
    } catch (Throwable e) {
        throw debug.handle(e);
    }
}
Also used : DebugDumpScope(org.graalvm.compiler.debug.DebugDumpScope) DebugContext(org.graalvm.compiler.debug.DebugContext) PiNode(org.graalvm.compiler.nodes.PiNode) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) ResolvedJavaField(jdk.vm.ci.meta.ResolvedJavaField) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) OffsetAddressNode(org.graalvm.compiler.nodes.memory.address.OffsetAddressNode) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) IsNullNode(org.graalvm.compiler.nodes.calc.IsNullNode) ReadNode(org.graalvm.compiler.nodes.memory.ReadNode) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 45 with ResolvedJavaField

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

the class RecomputedFields method compute.

@Override
public Object compute(ResolvedJavaField original, ResolvedJavaField annotated, Object receiver) {
    try {
        ObjectLayout layout = ImageSingletons.lookup(ObjectLayout.class);
        /*
             * ASHIFT is a hard-coded constant in the original implementation, so there is no need
             * to recompute it. It is a private field, so we need reflection to access it.
             */
        Field ashiftField = java.util.concurrent.Exchanger.class.getDeclaredField("ASHIFT");
        ashiftField.setAccessible(true);
        int ashift = ashiftField.getInt(null);
        /*
             * The original implementation uses Node[].class, but we know that all Object arrays
             * have the same kind and layout. The kind denotes the element type of the array.
             */
        JavaKind ak = JavaKind.Object;
        // ABASE absorbs padding in front of element 0
        int abase = layout.getArrayBaseOffset(ak) + (1 << ashift);
        /* Sanity check. */
        final int s = layout.getArrayIndexScale(ak);
        if ((s & (s - 1)) != 0 || s > (1 << ashift)) {
            throw VMError.shouldNotReachHere("Unsupported array scale");
        }
        return abase;
    } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException ex) {
        throw VMError.shouldNotReachHere(ex);
    }
}
Also used : ResolvedJavaField(jdk.vm.ci.meta.ResolvedJavaField) Field(java.lang.reflect.Field) ObjectLayout(com.oracle.svm.core.config.ObjectLayout) JavaKind(jdk.vm.ci.meta.JavaKind)

Aggregations

ResolvedJavaField (jdk.vm.ci.meta.ResolvedJavaField)45 ValueNode (org.graalvm.compiler.nodes.ValueNode)16 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)10 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)10 ArrayList (java.util.ArrayList)7 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)6 AnalysisField (com.oracle.graal.pointsto.meta.AnalysisField)4 Field (java.lang.reflect.Field)4 JavaKind (jdk.vm.ci.meta.JavaKind)4 Invoke (org.graalvm.compiler.nodes.Invoke)4 OffsetAddressNode (org.graalvm.compiler.nodes.memory.address.OffsetAddressNode)4 SnippetReflectionProvider (org.graalvm.compiler.api.replacements.SnippetReflectionProvider)3 DebugCloseable (org.graalvm.compiler.debug.DebugCloseable)3 NodePlugin (org.graalvm.compiler.nodes.graphbuilderconf.NodePlugin)3 LoadFieldNode (org.graalvm.compiler.nodes.java.LoadFieldNode)3 LocationIdentity (org.graalvm.word.LocationIdentity)3 Delete (com.oracle.svm.core.annotate.Delete)2 Method (java.lang.reflect.Method)2 JavaField (jdk.vm.ci.meta.JavaField)2 MetaAccessProvider (jdk.vm.ci.meta.MetaAccessProvider)2