diff --git a/compiler/src/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/extended/BoxNode.java b/compiler/src/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/extended/BoxNode.java index 735760cc09dc..3e3798cd662c 100644 --- a/compiler/src/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/extended/BoxNode.java +++ b/compiler/src/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/extended/BoxNode.java @@ -136,7 +136,6 @@ public ValueNode canonical(CanonicalizerTool tool, ValueNode forValue) { protected VirtualBoxingNode createVirtualBoxingNode() { VirtualBoxingNode node = new VirtualBoxingNode(StampTool.typeOrNull(stamp(NodeView.DEFAULT)), boxingKind); - node.setNodeSourcePosition(getNodeSourcePosition()); return node; } @@ -151,7 +150,7 @@ public void virtualize(VirtualizerTool tool) { VirtualBoxingNode newVirtual = createVirtualBoxingNode(); assert newVirtual.getFields().length == 1; - tool.createVirtualObject(newVirtual, new ValueNode[]{alias}, Collections. emptyList(), false); + tool.createVirtualObject(newVirtual, new ValueNode[]{alias}, Collections. emptyList(), getNodeSourcePosition(), false); tool.replaceWithVirtual(newVirtual); } diff --git a/compiler/src/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/java/NewArrayNode.java b/compiler/src/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/java/NewArrayNode.java index 4c8753cb24f8..db6ab6955185 100644 --- a/compiler/src/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/java/NewArrayNode.java +++ b/compiler/src/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/java/NewArrayNode.java @@ -108,7 +108,7 @@ public void virtualize(VirtualizerTool tool) { } VirtualObjectNode virtualObject = new VirtualArrayNode(elementType(), constantLength); - tool.createVirtualObject(virtualObject, state, Collections. emptyList(), false); + tool.createVirtualObject(virtualObject, state, Collections. emptyList(), getNodeSourcePosition(), false); tool.replaceWithVirtual(virtualObject); } } diff --git a/compiler/src/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/java/NewInstanceNode.java b/compiler/src/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/java/NewInstanceNode.java index 705da03a04e5..571779870209 100644 --- a/compiler/src/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/java/NewInstanceNode.java +++ b/compiler/src/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/java/NewInstanceNode.java @@ -86,7 +86,7 @@ public void virtualize(VirtualizerTool tool) { for (int i = 0; i < state.length; i++) { state[i] = ConstantNode.defaultForKind(tool.getMetaAccessExtensionProvider().getStorageKind(fields[i].getType()), graph()); } - tool.createVirtualObject(virtualObject, state, Collections. emptyList(), false); + tool.createVirtualObject(virtualObject, state, Collections. emptyList(), getNodeSourcePosition(), false); tool.replaceWithVirtual(virtualObject); } } diff --git a/compiler/src/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/spi/VirtualizerTool.java b/compiler/src/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/spi/VirtualizerTool.java index dd1f931cd60a..c9e8ab4e0fed 100644 --- a/compiler/src/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/spi/VirtualizerTool.java +++ b/compiler/src/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/spi/VirtualizerTool.java @@ -29,6 +29,7 @@ import org.graalvm.compiler.debug.DebugContext; import org.graalvm.compiler.debug.GraalError; import org.graalvm.compiler.graph.Node; +import org.graalvm.compiler.graph.NodeSourcePosition; import org.graalvm.compiler.nodes.ValueNode; import org.graalvm.compiler.nodes.WithExceptionNode; import org.graalvm.compiler.nodes.java.MonitorIdNode; @@ -61,9 +62,10 @@ public interface VirtualizerTool extends CoreProviders { * @param virtualObject the new virtual object. * @param entryState the initial state of the virtual object's fields. * @param locks the initial locking depths. + * @param sourcePosition a source position for the new node or null if none is available * @param ensureVirtualized true if this object needs to stay virtual */ - void createVirtualObject(VirtualObjectNode virtualObject, ValueNode[] entryState, List locks, boolean ensureVirtualized); + void createVirtualObject(VirtualObjectNode virtualObject, ValueNode[] entryState, List locks, NodeSourcePosition sourcePosition, boolean ensureVirtualized); /** * Returns a VirtualObjectNode if the given value is aliased with a virtual object that is still diff --git a/compiler/src/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/util/GraphUtil.java b/compiler/src/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/util/GraphUtil.java index 5d31507dc3ff..0b5e8c8b7923 100644 --- a/compiler/src/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/util/GraphUtil.java +++ b/compiler/src/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/util/GraphUtil.java @@ -1159,7 +1159,7 @@ public static void virtualizeArrayCopy(VirtualizerTool tool, ValueNode source, V } /* Perform the replacement. */ VirtualArrayNode newVirtualArray = virtualArrayProvider.apply(newComponentType, newLengthInt); - tool.createVirtualObject(newVirtualArray, newEntryState, Collections. emptyList(), false); + tool.createVirtualObject(newVirtualArray, newEntryState, Collections. emptyList(), source.getNodeSourcePosition(), false); tool.replaceWithVirtual(newVirtualArray); } diff --git a/compiler/src/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/virtual/CommitAllocationNode.java b/compiler/src/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/virtual/CommitAllocationNode.java index 0dd2fba8d92f..23571cc405a0 100644 --- a/compiler/src/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/virtual/CommitAllocationNode.java +++ b/compiler/src/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/virtual/CommitAllocationNode.java @@ -141,7 +141,11 @@ public void virtualize(VirtualizerTool tool) { for (int i = 0; i < virtualObjects.size(); i++) { VirtualObjectNode virtualObject = virtualObjects.get(i); int entryCount = virtualObject.entryCount(); - tool.createVirtualObject(virtualObject, values.subList(pos, pos + entryCount).toArray(new ValueNode[entryCount]), getLocks(i), ensureVirtual.get(i)); + /* + * n.b. the node source position of virtualObject will have been set when it was + * created. + */ + tool.createVirtualObject(virtualObject, values.subList(pos, pos + entryCount).toArray(new ValueNode[entryCount]), getLocks(i), virtualObject.getNodeSourcePosition(), ensureVirtual.get(i)); pos += entryCount; } tool.delete(); diff --git a/compiler/src/org.graalvm.compiler.replacements/src/org/graalvm/compiler/replacements/nodes/ObjectClone.java b/compiler/src/org.graalvm.compiler.replacements/src/org/graalvm/compiler/replacements/nodes/ObjectClone.java index 418229047ea6..1f1bc10530da 100644 --- a/compiler/src/org.graalvm.compiler.replacements/src/org/graalvm/compiler/replacements/nodes/ObjectClone.java +++ b/compiler/src/org.graalvm.compiler.replacements/src/org/graalvm/compiler/replacements/nodes/ObjectClone.java @@ -29,6 +29,7 @@ import org.graalvm.compiler.core.common.type.ObjectStamp; import org.graalvm.compiler.core.common.type.Stamp; import org.graalvm.compiler.core.common.type.StampFactory; +import org.graalvm.compiler.graph.NodeSourcePosition; import org.graalvm.compiler.nodes.ConstantNode; import org.graalvm.compiler.nodes.NodeView; import org.graalvm.compiler.nodes.StateSplit; @@ -95,7 +96,9 @@ default LoadIndexedNode genLoadIndexedNode(Assumptions assumptions, ValueNode or @Override default void virtualize(VirtualizerTool tool) { - ValueNode originalAlias = tool.getAlias(getObject()); + ValueNode original = getObject(); + ValueNode originalAlias = tool.getAlias(original); + NodeSourcePosition sourcePosition = original.getNodeSourcePosition(); if (originalAlias instanceof VirtualObjectNode) { VirtualObjectNode originalVirtual = (VirtualObjectNode) originalAlias; if (originalVirtual.type().isCloneableWithAllocation()) { @@ -104,7 +107,8 @@ default void virtualize(VirtualizerTool tool) { newEntryState[i] = tool.getEntry(originalVirtual, i); } VirtualObjectNode newVirtual = originalVirtual.duplicate(); - tool.createVirtualObject(newVirtual, newEntryState, Collections. emptyList(), false); + /* n.b. duplicate will replicate the source position so pass null */ + tool.createVirtualObject(newVirtual, newEntryState, Collections. emptyList(), null, false); tool.replaceWithVirtual(newVirtual); } } else { @@ -122,7 +126,7 @@ default void virtualize(VirtualizerTool tool) { state[i] = load; tool.addNode(load); } - tool.createVirtualObject(newVirtual, state, Collections. emptyList(), false); + tool.createVirtualObject(newVirtual, state, Collections. emptyList(), sourcePosition, false); tool.replaceWithVirtual(newVirtual); } else { ValueNode length = findLength(FindLengthMode.SEARCH_ONLY, tool.getConstantReflection()); @@ -145,7 +149,7 @@ default void virtualize(VirtualizerTool tool) { tool.addNode(load); } VirtualObjectNode virtualObject = new VirtualArrayNode(componentType, constantLength); - tool.createVirtualObject(virtualObject, state, Collections. emptyList(), false); + tool.createVirtualObject(virtualObject, state, Collections. emptyList(), sourcePosition, false); tool.replaceWithVirtual(virtualObject); } } diff --git a/compiler/src/org.graalvm.compiler.truffle.compiler/src/org/graalvm/compiler/truffle/compiler/nodes/frame/NewFrameNode.java b/compiler/src/org.graalvm.compiler.truffle.compiler/src/org/graalvm/compiler/truffle/compiler/nodes/frame/NewFrameNode.java index bc0ad42f88ba..26aff6ea0848 100644 --- a/compiler/src/org.graalvm.compiler.truffle.compiler/src/org/graalvm/compiler/truffle/compiler/nodes/frame/NewFrameNode.java +++ b/compiler/src/org.graalvm.compiler.truffle.compiler/src/org/graalvm/compiler/truffle/compiler/nodes/frame/NewFrameNode.java @@ -37,6 +37,7 @@ import org.graalvm.compiler.graph.Node; import org.graalvm.compiler.graph.NodeClass; import org.graalvm.compiler.graph.NodeInputList; +import org.graalvm.compiler.graph.NodeSourcePosition; import org.graalvm.compiler.nodes.spi.Canonicalizable; import org.graalvm.compiler.nodes.spi.CanonicalizerTool; import org.graalvm.compiler.nodeinfo.NodeInfo; @@ -268,12 +269,13 @@ public void virtualize(VirtualizerTool tool) { } } - tool.createVirtualObject(virtualFrameObjectArray, objectArrayEntryState, Collections. emptyList(), false); + NodeSourcePosition sourcePosition = getNodeSourcePosition(); + tool.createVirtualObject(virtualFrameObjectArray, objectArrayEntryState, Collections. emptyList(), sourcePosition, false); if (virtualFramePrimitiveArray != null) { - tool.createVirtualObject(virtualFramePrimitiveArray, primitiveArrayEntryState, Collections. emptyList(), false); + tool.createVirtualObject(virtualFramePrimitiveArray, primitiveArrayEntryState, Collections. emptyList(), sourcePosition, false); } if (virtualFrameTagArray != null) { - tool.createVirtualObject(virtualFrameTagArray, tagArrayEntryState, Collections. emptyList(), false); + tool.createVirtualObject(virtualFrameTagArray, tagArrayEntryState, Collections. emptyList(), sourcePosition, false); } assert frameFields.length == 5 || frameFields.length == 3; @@ -293,7 +295,7 @@ public void virtualize(VirtualizerTool tool) { * materialized. This can only be lifted by a AllowMaterializeNode, which corresponds to a * frame.materialize() call. */ - tool.createVirtualObject(virtualFrame, frameEntryState, Collections. emptyList(), true); + tool.createVirtualObject(virtualFrame, frameEntryState, Collections. emptyList(), sourcePosition, true); tool.replaceWithVirtual(virtualFrame); } diff --git a/compiler/src/org.graalvm.compiler.virtual/src/org/graalvm/compiler/virtual/phases/ea/VirtualizerToolImpl.java b/compiler/src/org.graalvm.compiler.virtual/src/org/graalvm/compiler/virtual/phases/ea/VirtualizerToolImpl.java index 5c78a89623ad..c21ae1cf72b6 100644 --- a/compiler/src/org.graalvm.compiler.virtual/src/org/graalvm/compiler/virtual/phases/ea/VirtualizerToolImpl.java +++ b/compiler/src/org.graalvm.compiler.virtual/src/org/graalvm/compiler/virtual/phases/ea/VirtualizerToolImpl.java @@ -30,6 +30,7 @@ import org.graalvm.compiler.debug.DebugContext; import org.graalvm.compiler.graph.Node; +import org.graalvm.compiler.graph.NodeSourcePosition; import org.graalvm.compiler.nodes.spi.CanonicalizerTool; import org.graalvm.compiler.nodes.ConstantNode; import org.graalvm.compiler.nodes.FixedNode; @@ -290,7 +291,7 @@ public void addNode(ValueNode node) { } @Override - public void createVirtualObject(VirtualObjectNode virtualObject, ValueNode[] entryState, List locks, boolean ensureVirtualized) { + public void createVirtualObject(VirtualObjectNode virtualObject, ValueNode[] entryState, List locks, NodeSourcePosition sourcePosition, boolean ensureVirtualized) { VirtualUtil.trace(options, debug, "{{%s}} ", current); if (!virtualObject.isAlive()) { effects.addFloatingNode(virtualObject, "newVirtualObject"); @@ -309,6 +310,10 @@ public void createVirtualObject(VirtualObjectNode virtualObject, ValueNode[] ent closure.addVirtualAlias(virtualObject, virtualObject); PartialEscapeClosure.COUNTER_ALLOCATION_REMOVED.increment(debug); effects.addVirtualizationDelta(1); + if (sourcePosition != null) { + assert virtualObject.getNodeSourcePosition() == null || virtualObject.getNodeSourcePosition() == sourcePosition : "unexpected source pos!"; + virtualObject.setNodeSourcePosition(sourcePosition); + } } @Override