Search in sources :

Example 1 with RawStoreNode

use of org.graalvm.compiler.nodes.extended.RawStoreNode in project graal by oracle.

the class JNIFieldAccessorMethod method buildGraph.

@Override
public StructuredGraph buildGraph(DebugContext debug, ResolvedJavaMethod method, HostedProviders providers, Purpose purpose) {
    JNIGraphKit kit = new JNIGraphKit(debug, providers, method);
    StructuredGraph graph = kit.getGraph();
    FrameStateBuilder state = new FrameStateBuilder(null, method, graph);
    state.initializeForMethodStart(null, true, providers.getGraphBuilderPlugins());
    ValueNode vmThread = kit.loadLocal(0, signature.getParameterKind(0));
    kit.append(new CEntryPointEnterNode(EnterAction.Enter, vmThread));
    List<ValueNode> arguments = kit.loadArguments(signature.toParameterTypes(null));
    ValueNode object;
    if (isStatic) {
        if (fieldKind.isPrimitive()) {
            object = kit.getStaticPrimitiveFieldsArray();
        } else {
            object = kit.getStaticObjectFieldsArray();
        }
    } else {
        ValueNode handle = arguments.get(1);
        object = kit.unboxHandle(handle);
    }
    ValueNode fieldId = arguments.get(2);
    ValueNode offset = kit.getFieldOffsetFromId(fieldId);
    ValueNode returnValue;
    if (isSetter) {
        // void
        returnValue = null;
        ValueNode newValue = arguments.get(3);
        if (fieldKind.isObject()) {
            newValue = kit.unboxHandle(newValue);
        }
        kit.append(new RawStoreNode(object, offset, newValue, fieldKind, LocationIdentity.ANY_LOCATION));
    } else {
        returnValue = kit.append(new RawLoadNode(object, offset, fieldKind, LocationIdentity.ANY_LOCATION));
        if (fieldKind.isObject()) {
            returnValue = kit.boxObjectInLocalHandle(returnValue);
        }
    }
    kit.append(new CEntryPointLeaveNode(LeaveAction.Leave));
    JavaKind returnKind = isSetter ? JavaKind.Void : fieldKind;
    kit.createReturn(returnValue, returnKind);
    assert graph.verify();
    return graph;
}
Also used : RawStoreNode(org.graalvm.compiler.nodes.extended.RawStoreNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) CEntryPointEnterNode(com.oracle.svm.core.graal.nodes.CEntryPointEnterNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) FrameStateBuilder(org.graalvm.compiler.java.FrameStateBuilder) CEntryPointLeaveNode(com.oracle.svm.core.graal.nodes.CEntryPointLeaveNode) RawLoadNode(org.graalvm.compiler.nodes.extended.RawLoadNode) JavaKind(jdk.vm.ci.meta.JavaKind)

Example 2 with RawStoreNode

use of org.graalvm.compiler.nodes.extended.RawStoreNode in project graal by oracle.

the class ReadEliminationClosure method processNode.

@Override
protected boolean processNode(Node node, ReadEliminationBlockState state, GraphEffectList effects, FixedWithNextNode lastFixedNode) {
    boolean deleted = false;
    if (node instanceof AccessFieldNode) {
        AccessFieldNode access = (AccessFieldNode) node;
        if (access.isVolatile()) {
            processIdentity(state, any());
        } else {
            ValueNode object = GraphUtil.unproxify(access.object());
            LoadCacheEntry identifier = new LoadCacheEntry(object, new FieldLocationIdentity(access.field()));
            ValueNode cachedValue = state.getCacheEntry(identifier);
            if (node instanceof LoadFieldNode) {
                if (cachedValue != null && access.stamp(NodeView.DEFAULT).isCompatible(cachedValue.stamp(NodeView.DEFAULT))) {
                    effects.replaceAtUsages(access, cachedValue, access);
                    addScalarAlias(access, cachedValue);
                    deleted = true;
                } else {
                    state.addCacheEntry(identifier, access);
                }
            } else {
                assert node instanceof StoreFieldNode;
                StoreFieldNode store = (StoreFieldNode) node;
                ValueNode value = getScalarAlias(store.value());
                if (GraphUtil.unproxify(value) == GraphUtil.unproxify(cachedValue)) {
                    effects.deleteNode(store);
                    deleted = true;
                }
                state.killReadCache(identifier.identity);
                state.addCacheEntry(identifier, value);
            }
        }
    } else if (node instanceof ReadNode) {
        ReadNode read = (ReadNode) node;
        if (read.getLocationIdentity().isSingle()) {
            ValueNode object = GraphUtil.unproxify(read.getAddress());
            LoadCacheEntry identifier = new LoadCacheEntry(object, read.getLocationIdentity());
            ValueNode cachedValue = state.getCacheEntry(identifier);
            if (cachedValue != null && areValuesReplaceable(read, cachedValue, considerGuards)) {
                effects.replaceAtUsages(read, cachedValue, read);
                addScalarAlias(read, cachedValue);
                deleted = true;
            } else {
                state.addCacheEntry(identifier, read);
            }
        }
    } else if (node instanceof WriteNode) {
        WriteNode write = (WriteNode) node;
        if (write.getLocationIdentity().isSingle()) {
            ValueNode object = GraphUtil.unproxify(write.getAddress());
            LoadCacheEntry identifier = new LoadCacheEntry(object, write.getLocationIdentity());
            ValueNode cachedValue = state.getCacheEntry(identifier);
            ValueNode value = getScalarAlias(write.value());
            if (GraphUtil.unproxify(value) == GraphUtil.unproxify(cachedValue)) {
                effects.deleteNode(write);
                deleted = true;
            }
            processIdentity(state, write.getLocationIdentity());
            state.addCacheEntry(identifier, value);
        } else {
            processIdentity(state, write.getLocationIdentity());
        }
    } else if (node instanceof UnsafeAccessNode) {
        ResolvedJavaType type = StampTool.typeOrNull(((UnsafeAccessNode) node).object());
        if (type != null && !type.isArray()) {
            if (node instanceof RawLoadNode) {
                RawLoadNode load = (RawLoadNode) node;
                if (load.getLocationIdentity().isSingle()) {
                    ValueNode object = GraphUtil.unproxify(load.object());
                    UnsafeLoadCacheEntry identifier = new UnsafeLoadCacheEntry(object, load.offset(), load.getLocationIdentity());
                    ValueNode cachedValue = state.getCacheEntry(identifier);
                    if (cachedValue != null && areValuesReplaceable(load, cachedValue, considerGuards)) {
                        effects.replaceAtUsages(load, cachedValue, load);
                        addScalarAlias(load, cachedValue);
                        deleted = true;
                    } else {
                        state.addCacheEntry(identifier, load);
                    }
                }
            } else {
                assert node instanceof RawStoreNode;
                RawStoreNode write = (RawStoreNode) node;
                if (write.getLocationIdentity().isSingle()) {
                    ValueNode object = GraphUtil.unproxify(write.object());
                    UnsafeLoadCacheEntry identifier = new UnsafeLoadCacheEntry(object, write.offset(), write.getLocationIdentity());
                    ValueNode cachedValue = state.getCacheEntry(identifier);
                    ValueNode value = getScalarAlias(write.value());
                    if (GraphUtil.unproxify(value) == GraphUtil.unproxify(cachedValue)) {
                        effects.deleteNode(write);
                        deleted = true;
                    }
                    processIdentity(state, write.getLocationIdentity());
                    state.addCacheEntry(identifier, value);
                } else {
                    processIdentity(state, write.getLocationIdentity());
                }
            }
        }
    } else if (node instanceof MemoryCheckpoint.Single) {
        LocationIdentity identity = ((MemoryCheckpoint.Single) node).getLocationIdentity();
        processIdentity(state, identity);
    } else if (node instanceof MemoryCheckpoint.Multi) {
        for (LocationIdentity identity : ((MemoryCheckpoint.Multi) node).getLocationIdentities()) {
            processIdentity(state, identity);
        }
    }
    return deleted;
}
Also used : RawStoreNode(org.graalvm.compiler.nodes.extended.RawStoreNode) StoreFieldNode(org.graalvm.compiler.nodes.java.StoreFieldNode) LoadFieldNode(org.graalvm.compiler.nodes.java.LoadFieldNode) UnsafeLoadCacheEntry(org.graalvm.compiler.virtual.phases.ea.ReadEliminationBlockState.UnsafeLoadCacheEntry) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) RawLoadNode(org.graalvm.compiler.nodes.extended.RawLoadNode) FieldLocationIdentity(org.graalvm.compiler.nodes.FieldLocationIdentity) UnsafeAccessNode(org.graalvm.compiler.nodes.extended.UnsafeAccessNode) MemoryCheckpoint(org.graalvm.compiler.nodes.memory.MemoryCheckpoint) AccessFieldNode(org.graalvm.compiler.nodes.java.AccessFieldNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) LocationIdentity(org.graalvm.word.LocationIdentity) FieldLocationIdentity(org.graalvm.compiler.nodes.FieldLocationIdentity) ReadNode(org.graalvm.compiler.nodes.memory.ReadNode) WriteNode(org.graalvm.compiler.nodes.memory.WriteNode) LoadCacheEntry(org.graalvm.compiler.virtual.phases.ea.ReadEliminationBlockState.LoadCacheEntry) UnsafeLoadCacheEntry(org.graalvm.compiler.virtual.phases.ea.ReadEliminationBlockState.UnsafeLoadCacheEntry)

Example 3 with RawStoreNode

use of org.graalvm.compiler.nodes.extended.RawStoreNode in project graal by oracle.

the class PEReadEliminationClosure method processNode.

@Override
protected boolean processNode(Node node, PEReadEliminationBlockState state, GraphEffectList effects, FixedWithNextNode lastFixedNode) {
    if (super.processNode(node, state, effects, lastFixedNode)) {
        return true;
    }
    if (node instanceof LoadFieldNode) {
        return processLoadField((LoadFieldNode) node, state, effects);
    } else if (node instanceof StoreFieldNode) {
        return processStoreField((StoreFieldNode) node, state, effects);
    } else if (node instanceof LoadIndexedNode) {
        return processLoadIndexed((LoadIndexedNode) node, state, effects);
    } else if (node instanceof StoreIndexedNode) {
        return processStoreIndexed((StoreIndexedNode) node, state, effects);
    } else if (node instanceof ArrayLengthNode) {
        return processArrayLength((ArrayLengthNode) node, state, effects);
    } else if (node instanceof UnboxNode) {
        return processUnbox((UnboxNode) node, state, effects);
    } else if (node instanceof RawLoadNode) {
        return processUnsafeLoad((RawLoadNode) node, state, effects);
    } else if (node instanceof RawStoreNode) {
        return processUnsafeStore((RawStoreNode) node, state, effects);
    } else if (node instanceof MemoryCheckpoint.Single) {
        COUNTER_MEMORYCHECKPOINT.increment(node.getDebug());
        LocationIdentity identity = ((MemoryCheckpoint.Single) node).getLocationIdentity();
        processIdentity(state, identity);
    } else if (node instanceof MemoryCheckpoint.Multi) {
        COUNTER_MEMORYCHECKPOINT.increment(node.getDebug());
        for (LocationIdentity identity : ((MemoryCheckpoint.Multi) node).getLocationIdentities()) {
            processIdentity(state, identity);
        }
    }
    return false;
}
Also used : RawStoreNode(org.graalvm.compiler.nodes.extended.RawStoreNode) StoreIndexedNode(org.graalvm.compiler.nodes.java.StoreIndexedNode) UnboxNode(org.graalvm.compiler.nodes.extended.UnboxNode) StoreFieldNode(org.graalvm.compiler.nodes.java.StoreFieldNode) MemoryCheckpoint(org.graalvm.compiler.nodes.memory.MemoryCheckpoint) LoadIndexedNode(org.graalvm.compiler.nodes.java.LoadIndexedNode) LocationIdentity(org.graalvm.word.LocationIdentity) FieldLocationIdentity(org.graalvm.compiler.nodes.FieldLocationIdentity) NamedLocationIdentity(org.graalvm.compiler.nodes.NamedLocationIdentity) LoadFieldNode(org.graalvm.compiler.nodes.java.LoadFieldNode) ArrayLengthNode(org.graalvm.compiler.nodes.java.ArrayLengthNode) RawLoadNode(org.graalvm.compiler.nodes.extended.RawLoadNode)

Example 4 with RawStoreNode

use of org.graalvm.compiler.nodes.extended.RawStoreNode in project graal by oracle.

the class StandardGraphBuilderPlugins method registerEdgesPlugins.

/**
 * Substitutions for improving the performance of some critical methods in {@link Edges}. These
 * substitutions improve the performance by forcing the relevant methods to be inlined
 * (intrinsification being a special form of inlining) and removing a checked cast.
 */
private static void registerEdgesPlugins(MetaAccessProvider metaAccess, InvocationPlugins plugins) {
    Registration r = new Registration(plugins, Edges.class);
    for (Class<?> c : new Class<?>[] { Node.class, NodeList.class }) {
        r.register2("get" + c.getSimpleName() + "Unsafe", Node.class, long.class, new InvocationPlugin() {

            @Override
            public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode node, ValueNode offset) {
                ObjectStamp stamp = StampFactory.object(TypeReference.createTrusted(b.getAssumptions(), metaAccess.lookupJavaType(c)));
                RawLoadNode value = b.add(new RawLoadNode(stamp, node, offset, LocationIdentity.any(), JavaKind.Object));
                b.addPush(JavaKind.Object, value);
                return true;
            }
        });
        r.register3("put" + c.getSimpleName() + "Unsafe", Node.class, long.class, c, new InvocationPlugin() {

            @Override
            public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode node, ValueNode offset, ValueNode value) {
                b.add(new RawStoreNode(node, offset, value, JavaKind.Object, LocationIdentity.any()));
                return true;
            }
        });
    }
}
Also used : RawStoreNode(org.graalvm.compiler.nodes.extended.RawStoreNode) ObjectStamp(org.graalvm.compiler.core.common.type.ObjectStamp) RawLoadNode(org.graalvm.compiler.nodes.extended.RawLoadNode) DynamicNewInstanceNode(org.graalvm.compiler.nodes.java.DynamicNewInstanceNode) OpaqueNode(org.graalvm.compiler.nodes.debug.OpaqueNode) NarrowNode(org.graalvm.compiler.nodes.calc.NarrowNode) BindToRegisterNode(org.graalvm.compiler.nodes.debug.BindToRegisterNode) IntegerMulExactNode(org.graalvm.compiler.replacements.nodes.arithmetic.IntegerMulExactNode) SignExtendNode(org.graalvm.compiler.nodes.calc.SignExtendNode) ZeroExtendNode(org.graalvm.compiler.nodes.calc.ZeroExtendNode) RegisterFinalizerNode(org.graalvm.compiler.nodes.java.RegisterFinalizerNode) BoxNode(org.graalvm.compiler.nodes.extended.BoxNode) IntegerAddExactNode(org.graalvm.compiler.replacements.nodes.arithmetic.IntegerAddExactNode) EnsureVirtualizedNode(org.graalvm.compiler.nodes.virtual.EnsureVirtualizedNode) RawStoreNode(org.graalvm.compiler.nodes.extended.RawStoreNode) FixedGuardNode(org.graalvm.compiler.nodes.FixedGuardNode) LogicNode(org.graalvm.compiler.nodes.LogicNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) VirtualizableInvokeMacroNode(org.graalvm.compiler.replacements.nodes.VirtualizableInvokeMacroNode) DynamicNewArrayNode(org.graalvm.compiler.nodes.java.DynamicNewArrayNode) UnsignedDivNode(org.graalvm.compiler.nodes.calc.UnsignedDivNode) UnsafeCompareAndSwapNode(org.graalvm.compiler.nodes.java.UnsafeCompareAndSwapNode) CompareNode(org.graalvm.compiler.nodes.calc.CompareNode) LoadFieldNode(org.graalvm.compiler.nodes.java.LoadFieldNode) IntegerSubExactNode(org.graalvm.compiler.replacements.nodes.arithmetic.IntegerSubExactNode) BranchProbabilityNode(org.graalvm.compiler.nodes.extended.BranchProbabilityNode) UnsafeMemoryStoreNode(org.graalvm.compiler.nodes.extended.UnsafeMemoryStoreNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) ReinterpretNode(org.graalvm.compiler.nodes.calc.ReinterpretNode) ClassIsAssignableFromNode(org.graalvm.compiler.nodes.java.ClassIsAssignableFromNode) ControlFlowAnchorNode(org.graalvm.compiler.nodes.debug.ControlFlowAnchorNode) InstanceOfDynamicNode(org.graalvm.compiler.nodes.java.InstanceOfDynamicNode) IntegerEqualsNode(org.graalvm.compiler.nodes.calc.IntegerEqualsNode) AbsNode(org.graalvm.compiler.nodes.calc.AbsNode) RightShiftNode(org.graalvm.compiler.nodes.calc.RightShiftNode) ConditionalNode(org.graalvm.compiler.nodes.calc.ConditionalNode) DeoptimizeNode(org.graalvm.compiler.nodes.DeoptimizeNode) SpillRegistersNode(org.graalvm.compiler.nodes.debug.SpillRegistersNode) UnsafeMemoryLoadNode(org.graalvm.compiler.nodes.extended.UnsafeMemoryLoadNode) BlackholeNode(org.graalvm.compiler.nodes.debug.BlackholeNode) UnsignedRemNode(org.graalvm.compiler.nodes.calc.UnsignedRemNode) SqrtNode(org.graalvm.compiler.nodes.calc.SqrtNode) ReverseBytesNode(org.graalvm.compiler.replacements.nodes.ReverseBytesNode) MembarNode(org.graalvm.compiler.nodes.extended.MembarNode) GetClassNode(org.graalvm.compiler.nodes.extended.GetClassNode) Node(org.graalvm.compiler.graph.Node) UnboxNode(org.graalvm.compiler.nodes.extended.UnboxNode) NodeList(org.graalvm.compiler.graph.NodeList) Receiver(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver) RawLoadNode(org.graalvm.compiler.nodes.extended.RawLoadNode) 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) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 5 with RawStoreNode

use of org.graalvm.compiler.nodes.extended.RawStoreNode in project graal by oracle.

the class UnsafeEATest method canonicalizeGraph.

@Override
protected void canonicalizeGraph() {
    if (testingUnsafe) {
        // transformation into field access nodes.
        for (Node node : graph.getNodes().filter(x -> x instanceof UnsafeAccessNode).snapshot()) {
            if (node instanceof RawStoreNode) {
                RawStoreNode store = (RawStoreNode) node;
                RawStoreNode newStore = graph.add(new RawStoreNode(store.object(), store.offset(), store.value(), store.accessKind(), NamedLocationIdentity.any(), store.needsBarrier(), store.stateAfter(), true));
                graph.replaceFixedWithFixed(store, newStore);
            } else if (node instanceof RawLoadNode) {
                RawLoadNode load = (RawLoadNode) node;
                RawLoadNode newLoad = graph.add(new RawLoadNode(load.object(), load.offset(), load.accessKind(), NamedLocationIdentity.any(), true));
                graph.replaceFixedWithFixed(load, newLoad);
            }
        }
    }
    super.canonicalizeGraph();
}
Also used : RawLoadNode(org.graalvm.compiler.nodes.extended.RawLoadNode) UnsafeAccessNode(org.graalvm.compiler.nodes.extended.UnsafeAccessNode) UnpackEndianHalfNode(org.graalvm.compiler.nodes.calc.UnpackEndianHalfNode) LoadFieldNode(org.graalvm.compiler.nodes.java.LoadFieldNode) ValuePhiNode(org.graalvm.compiler.nodes.ValuePhiNode) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) RawStoreNode(org.graalvm.compiler.nodes.extended.RawStoreNode) Test(org.junit.Test) ByteBuffer(java.nio.ByteBuffer) Graph(org.graalvm.compiler.graph.Graph) NamedLocationIdentity(org.graalvm.compiler.nodes.NamedLocationIdentity) JavaConstant(jdk.vm.ci.meta.JavaConstant) GraalDirectives(org.graalvm.compiler.api.directives.GraalDirectives) JavaKind(jdk.vm.ci.meta.JavaKind) Node(org.graalvm.compiler.graph.Node) Assert(org.junit.Assert) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) PhiNode(org.graalvm.compiler.nodes.PhiNode) RawStoreNode(org.graalvm.compiler.nodes.extended.RawStoreNode) UnsafeAccessNode(org.graalvm.compiler.nodes.extended.UnsafeAccessNode) RawLoadNode(org.graalvm.compiler.nodes.extended.RawLoadNode) UnsafeAccessNode(org.graalvm.compiler.nodes.extended.UnsafeAccessNode) UnpackEndianHalfNode(org.graalvm.compiler.nodes.calc.UnpackEndianHalfNode) LoadFieldNode(org.graalvm.compiler.nodes.java.LoadFieldNode) ValuePhiNode(org.graalvm.compiler.nodes.ValuePhiNode) RawStoreNode(org.graalvm.compiler.nodes.extended.RawStoreNode) Node(org.graalvm.compiler.graph.Node) PhiNode(org.graalvm.compiler.nodes.PhiNode) RawLoadNode(org.graalvm.compiler.nodes.extended.RawLoadNode)

Aggregations

RawLoadNode (org.graalvm.compiler.nodes.extended.RawLoadNode)5 RawStoreNode (org.graalvm.compiler.nodes.extended.RawStoreNode)5 LoadFieldNode (org.graalvm.compiler.nodes.java.LoadFieldNode)4 ValueNode (org.graalvm.compiler.nodes.ValueNode)3 JavaKind (jdk.vm.ci.meta.JavaKind)2 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)2 Node (org.graalvm.compiler.graph.Node)2 FieldLocationIdentity (org.graalvm.compiler.nodes.FieldLocationIdentity)2 NamedLocationIdentity (org.graalvm.compiler.nodes.NamedLocationIdentity)2 UnboxNode (org.graalvm.compiler.nodes.extended.UnboxNode)2 CEntryPointEnterNode (com.oracle.svm.core.graal.nodes.CEntryPointEnterNode)1 CEntryPointLeaveNode (com.oracle.svm.core.graal.nodes.CEntryPointLeaveNode)1 ByteBuffer (java.nio.ByteBuffer)1 JavaConstant (jdk.vm.ci.meta.JavaConstant)1 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)1 GraalDirectives (org.graalvm.compiler.api.directives.GraalDirectives)1 ObjectStamp (org.graalvm.compiler.core.common.type.ObjectStamp)1 Graph (org.graalvm.compiler.graph.Graph)1 NodeList (org.graalvm.compiler.graph.NodeList)1 FrameStateBuilder (org.graalvm.compiler.java.FrameStateBuilder)1