Skip to content

Commit

Permalink
[GR-35824] Backport 21.3 : Partial Escape Do not update existing stat…
Browse files Browse the repository at this point in the history
…e mappings.

PullRequest: graal/10602
  • Loading branch information
marwan-hallaoui committed Dec 16, 2021
2 parents 406551b + 8b629ec commit cf58bea
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.graalvm.compiler.nodes.memory.MemoryKill;
import org.graalvm.compiler.nodes.util.GraphUtil;
import org.graalvm.compiler.nodes.virtual.EscapeObjectState;
import org.graalvm.compiler.virtual.nodes.VirtualObjectState;
import org.graalvm.compiler.phases.common.DeadCodeEliminationPhase;

public final class GraphEffectList extends EffectList {
Expand Down Expand Up @@ -168,8 +169,8 @@ public void initializePhiInput(PhiNode node, int index, ValueNode value) {
}

/**
* Adds a virtual object's state to the given frame state. If the given reusedVirtualObjects set
* contains the virtual object then old states for this object will be removed.
* Adds a virtual object's state to the given frame state. If the given frame state contains the
* virtual object then old states for this object will be removed.
*
* @param node The frame state to which the state should be added.
* @param state The virtual object state to add.
Expand Down Expand Up @@ -197,6 +198,29 @@ public boolean isVisible() {
});
}

/**
* Update a virtual object mapping for the given {@link VirtualObjectState} with a new value.
*
* @param state The virtual state previously constructed.
* @param field The field to update its value.
* @param newValue The new value of the field.
*/
public void updateVirtualMapping(VirtualObjectState state, int field, ValueNode newValue) {
add("add virtual mapping", new Effect() {
@Override
public void apply(StructuredGraph graph, ArrayList<Node> obsoleteNodes) {
if (state.isAlive()) {
state.values().set(field, graph.addOrUniqueWithInputs(newValue));
}
}

@Override
public boolean isVisible() {
return false;
}
});
}

/**
* Removes the given fixed node from the control flow and deletes it.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.graalvm.compiler.debug.GraalError;
import org.graalvm.compiler.graph.Node;
import org.graalvm.compiler.graph.NodeBitMap;
import org.graalvm.compiler.graph.NodeInputList;
import org.graalvm.compiler.graph.Position;
import org.graalvm.compiler.nodes.spi.Canonicalizable;
import org.graalvm.compiler.nodes.AbstractEndNode;
Expand Down Expand Up @@ -74,6 +75,7 @@
import org.graalvm.compiler.nodes.spi.VirtualizerTool;
import org.graalvm.compiler.nodes.virtual.AllocatedObjectNode;
import org.graalvm.compiler.nodes.virtual.EnsureVirtualizedNode;
import org.graalvm.compiler.nodes.virtual.EscapeObjectState;
import org.graalvm.compiler.nodes.virtual.VirtualObjectNode;
import org.graalvm.compiler.virtual.nodes.VirtualObjectState;

Expand Down Expand Up @@ -440,7 +442,30 @@ private static FrameState getUniqueFramestate(NodeWithState nodeWithState, Frame
}

private void addVirtualMappings(FrameState frameState, EconomicSet<VirtualObjectNode> virtual, BlockT state, GraphEffectList effects) {
for (VirtualObjectNode obj : virtual) {
object: for (VirtualObjectNode obj : virtual) {
/*
* Look for existing mappings: Update a virtual object mapping for the given {@link
* VirtualObjectState} with a new value. This can be necessary in iterative escape
* analysis where a previous iteration already virtualized an object. We must not update
* such mappings if no new virtualization occurred. Updating them would create invalid
* framestate - virtualization mappings of constructor written fields.
*/
for (int i = 0; i < frameState.virtualObjectMappingCount(); i++) {
EscapeObjectState mapping = frameState.virtualObjectMappingAt(i);
if (mapping.object() == obj && mapping instanceof VirtualObjectState) {
VirtualObjectState virtualState = (VirtualObjectState) mapping;
NodeInputList<ValueNode> values = virtualState.values();
for (int v = 0; v < values.size(); v++) {
ValueNode value = values.get(v);
ValueNode alias = getAlias(value);
if (alias != value) {
effects.updateVirtualMapping(virtualState, v, alias);
}
}
continue object;
}
}

effects.addVirtualMapping(frameState, state.getObjectState(obj).createEscapeObjectState(debug, tool.getMetaAccessExtensionProvider(), obj));
}
}
Expand Down

0 comments on commit cf58bea

Please sign in to comment.