Search in sources :

Example 1 with ResolvedJavaField

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

the class UnsafeAccessNode method canonical.

@Override
public Node canonical(CanonicalizerTool tool) {
    if (!isAnyLocationForced() && getLocationIdentity().isAny()) {
        if (offset().isConstant()) {
            long constantOffset = offset().asJavaConstant().asLong();
            // Try to canonicalize to a field access.
            ResolvedJavaType receiverType = StampTool.typeOrNull(object());
            if (receiverType != null) {
                ResolvedJavaField field = receiverType.findInstanceFieldWithOffset(constantOffset, accessKind());
                // never a valid access of an arbitrary address.
                if (field != null && field.getJavaKind() == this.accessKind()) {
                    assert !graph().isAfterFloatingReadPhase() : "cannot add more precise memory location after floating read phase";
                    return cloneAsFieldAccess(graph().getAssumptions(), field);
                }
            }
        }
        ResolvedJavaType receiverType = StampTool.typeOrNull(object());
        // Try to build a better location identity.
        if (receiverType != null && receiverType.isArray()) {
            LocationIdentity identity = NamedLocationIdentity.getArrayLocation(receiverType.getComponentType().getJavaKind());
            assert !graph().isAfterFloatingReadPhase() : "cannot add more precise memory location after floating read phase";
            return cloneAsArrayAccess(offset(), identity);
        }
    }
    return this;
}
Also used : LocationIdentity(org.graalvm.word.LocationIdentity) NamedLocationIdentity(org.graalvm.compiler.nodes.NamedLocationIdentity) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) ResolvedJavaField(jdk.vm.ci.meta.ResolvedJavaField)

Example 2 with ResolvedJavaField

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

the class NewFrameNode method virtualize.

@Override
public void virtualize(VirtualizerTool tool) {
    ResolvedJavaType frameType = stamp(NodeView.DEFAULT).javaType(tool.getMetaAccessProvider());
    ResolvedJavaField[] frameFields = frameType.getInstanceFields(true);
    ResolvedJavaField descriptorField = findField(frameFields, "descriptor");
    ResolvedJavaField argumentsField = findField(frameFields, "arguments");
    ResolvedJavaField localsField = findField(frameFields, "locals");
    ResolvedJavaField primitiveLocalsField = findField(frameFields, "primitiveLocals");
    ResolvedJavaField tagsField = findField(frameFields, "tags");
    ValueNode[] objectArrayEntryState = new ValueNode[frameSize];
    ValueNode[] primitiveArrayEntryState = new ValueNode[frameSize];
    ValueNode[] tagArrayEntryState = new ValueNode[frameSize];
    if (frameSize > 0) {
        Arrays.fill(objectArrayEntryState, frameDefaultValue);
        if (virtualFrameTagArray != null) {
            Arrays.fill(tagArrayEntryState, smallIntConstants.get(0));
        }
        if (virtualFramePrimitiveArray != null) {
            for (int i = 0; i < frameSize; i++) {
                JavaKind kind = frameSlotKinds[i];
                if (kind == null) {
                    kind = JavaKind.Int;
                }
                primitiveArrayEntryState[i] = ConstantNode.defaultForKind(kind, graph());
            }
        }
    }
    tool.createVirtualObject(virtualFrameObjectArray, objectArrayEntryState, Collections.<MonitorIdNode>emptyList(), false);
    if (virtualFramePrimitiveArray != null) {
        tool.createVirtualObject(virtualFramePrimitiveArray, primitiveArrayEntryState, Collections.<MonitorIdNode>emptyList(), false);
    }
    if (virtualFrameTagArray != null) {
        tool.createVirtualObject(virtualFrameTagArray, tagArrayEntryState, Collections.<MonitorIdNode>emptyList(), false);
    }
    assert frameFields.length == 5 || frameFields.length == 3;
    ValueNode[] frameEntryState = new ValueNode[frameFields.length];
    List<ResolvedJavaField> frameFieldList = Arrays.asList(frameFields);
    frameEntryState[frameFieldList.indexOf(descriptorField)] = getDescriptor();
    frameEntryState[frameFieldList.indexOf(argumentsField)] = getArguments();
    frameEntryState[frameFieldList.indexOf(localsField)] = virtualFrameObjectArray;
    if (primitiveLocalsField != null) {
        frameEntryState[frameFieldList.indexOf(primitiveLocalsField)] = virtualFramePrimitiveArray;
    }
    if (tagsField != null) {
        frameEntryState[frameFieldList.indexOf(tagsField)] = virtualFrameTagArray;
    }
    /*
         * The new frame is created with "ensureVirtualized" enabled, so that it cannot be
         * materialized. This can only be lifted by a AllowMaterializeNode, which corresponds to a
         * frame.materialize() call.
         */
    tool.createVirtualObject(virtualFrame, frameEntryState, Collections.<MonitorIdNode>emptyList(), true);
    tool.replaceWithVirtual(virtualFrame);
}
Also used : ValueNode(org.graalvm.compiler.nodes.ValueNode) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) ResolvedJavaField(jdk.vm.ci.meta.ResolvedJavaField) JavaKind(jdk.vm.ci.meta.JavaKind)

Example 3 with ResolvedJavaField

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

the class ObjectCloneNode method getLoweredSnippetGraph.

@Override
@SuppressWarnings("try")
protected StructuredGraph getLoweredSnippetGraph(LoweringTool tool) {
    ResolvedJavaType type = StampTool.typeOrNull(getObject());
    if (type != null) {
        if (type.isArray()) {
            Method method = ObjectCloneSnippets.arrayCloneMethods.get(type.getComponentType().getJavaKind());
            if (method != null) {
                final ResolvedJavaMethod snippetMethod = tool.getMetaAccess().lookupJavaMethod(method);
                final Replacements replacements = tool.getReplacements();
                StructuredGraph snippetGraph = null;
                DebugContext debug = getDebug();
                try (DebugContext.Scope s = debug.scope("ArrayCloneSnippet", snippetMethod)) {
                    snippetGraph = replacements.getSnippet(snippetMethod, null, graph().trackNodeSourcePosition(), this.getNodeSourcePosition());
                } catch (Throwable e) {
                    throw debug.handle(e);
                }
                assert snippetGraph != null : "ObjectCloneSnippets should be installed";
                assert getConcreteType(stamp(NodeView.DEFAULT)) != null;
                return lowerReplacement((StructuredGraph) snippetGraph.copy(getDebug()), tool);
            }
            assert false : "unhandled array type " + type.getComponentType().getJavaKind();
        } else {
            Assumptions assumptions = graph().getAssumptions();
            type = getConcreteType(getObject().stamp(NodeView.DEFAULT));
            if (type != null) {
                StructuredGraph newGraph = new StructuredGraph.Builder(graph().getOptions(), graph().getDebug(), AllowAssumptions.ifNonNull(assumptions)).build();
                ParameterNode param = newGraph.addWithoutUnique(new ParameterNode(0, StampPair.createSingle(getObject().stamp(NodeView.DEFAULT))));
                NewInstanceNode newInstance = newGraph.add(new NewInstanceNode(type, true));
                newGraph.addAfterFixed(newGraph.start(), newInstance);
                ReturnNode returnNode = newGraph.add(new ReturnNode(newInstance));
                newGraph.addAfterFixed(newInstance, returnNode);
                for (ResolvedJavaField field : type.getInstanceFields(true)) {
                    LoadFieldNode load = newGraph.add(LoadFieldNode.create(newGraph.getAssumptions(), param, field));
                    newGraph.addBeforeFixed(returnNode, load);
                    newGraph.addBeforeFixed(returnNode, newGraph.add(new StoreFieldNode(newInstance, field, load)));
                }
                assert getConcreteType(stamp(NodeView.DEFAULT)) != null;
                return lowerReplacement(newGraph, tool);
            }
        }
    }
    assert getConcreteType(stamp(NodeView.DEFAULT)) == null;
    return null;
}
Also used : StoreFieldNode(org.graalvm.compiler.nodes.java.StoreFieldNode) Replacements(org.graalvm.compiler.nodes.spi.Replacements) NewInstanceNode(org.graalvm.compiler.nodes.java.NewInstanceNode) Method(java.lang.reflect.Method) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) DebugContext(org.graalvm.compiler.debug.DebugContext) LoadFieldNode(org.graalvm.compiler.nodes.java.LoadFieldNode) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) ResolvedJavaField(jdk.vm.ci.meta.ResolvedJavaField) ReturnNode(org.graalvm.compiler.nodes.ReturnNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) AllowAssumptions(org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions) Assumptions(jdk.vm.ci.meta.Assumptions) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 4 with ResolvedJavaField

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

the class StandardGraphBuilderPlugins method registerStringPlugins.

private static void registerStringPlugins(InvocationPlugins plugins, BytecodeProvider bytecodeProvider, SnippetReflectionProvider snippetReflection) {
    final Registration r = new Registration(plugins, String.class, bytecodeProvider);
    r.register1("hashCode", Receiver.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            if (receiver.isConstant()) {
                String s = snippetReflection.asObject(String.class, (JavaConstant) receiver.get().asConstant());
                b.addPush(JavaKind.Int, b.add(ConstantNode.forInt(s.hashCode())));
                return true;
            }
            return false;
        }
    });
    if (Java8OrEarlier) {
        r.registerMethodSubstitution(StringSubstitutions.class, "equals", Receiver.class, Object.class);
        r.register7("indexOf", char[].class, int.class, int.class, char[].class, int.class, int.class, int.class, new StringIndexOfConstantPlugin());
        Registration sr = new Registration(plugins, StringSubstitutions.class);
        sr.register1("getValue", String.class, new InvocationPlugin() {

            @Override
            public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
                ResolvedJavaField field = b.getMetaAccess().lookupJavaField(STRING_VALUE_FIELD);
                b.addPush(JavaKind.Object, LoadFieldNode.create(b.getConstantFieldProvider(), b.getConstantReflection(), b.getMetaAccess(), b.getOptions(), b.getAssumptions(), value, field, false, false));
                return true;
            }
        });
    }
}
Also used : GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) Registration(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration) ValueNode(org.graalvm.compiler.nodes.ValueNode) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) Receiver(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver) JavaConstant(jdk.vm.ci.meta.JavaConstant) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) ResolvedJavaField(jdk.vm.ci.meta.ResolvedJavaField)

Example 5 with ResolvedJavaField

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

the class BasicObjectCloneNode method virtualize.

@Override
public void virtualize(VirtualizerTool tool) {
    ValueNode originalAlias = tool.getAlias(getObject());
    if (originalAlias instanceof VirtualObjectNode) {
        VirtualObjectNode originalVirtual = (VirtualObjectNode) originalAlias;
        if (originalVirtual.type().isCloneableWithAllocation()) {
            ValueNode[] newEntryState = new ValueNode[originalVirtual.entryCount()];
            for (int i = 0; i < newEntryState.length; i++) {
                newEntryState[i] = tool.getEntry(originalVirtual, i);
            }
            VirtualObjectNode newVirtual = originalVirtual.duplicate();
            tool.createVirtualObject(newVirtual, newEntryState, Collections.<MonitorIdNode>emptyList(), false);
            tool.replaceWithVirtual(newVirtual);
        }
    } else {
        ResolvedJavaType type = getConcreteType(originalAlias.stamp(NodeView.DEFAULT));
        if (type != null && !type.isArray()) {
            VirtualInstanceNode newVirtual = createVirtualInstanceNode(type, true);
            ResolvedJavaField[] fields = newVirtual.getFields();
            ValueNode[] state = new ValueNode[fields.length];
            final LoadFieldNode[] loads = new LoadFieldNode[fields.length];
            for (int i = 0; i < fields.length; i++) {
                state[i] = loads[i] = genLoadFieldNode(graph().getAssumptions(), originalAlias, fields[i]);
                tool.addNode(loads[i]);
            }
            tool.createVirtualObject(newVirtual, state, Collections.<MonitorIdNode>emptyList(), false);
            tool.replaceWithVirtual(newVirtual);
        }
    }
}
Also used : VirtualObjectNode(org.graalvm.compiler.nodes.virtual.VirtualObjectNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) VirtualInstanceNode(org.graalvm.compiler.nodes.virtual.VirtualInstanceNode) LoadFieldNode(org.graalvm.compiler.nodes.java.LoadFieldNode) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) ResolvedJavaField(jdk.vm.ci.meta.ResolvedJavaField)

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