use of org.graalvm.compiler.nodes.virtual.VirtualObjectNode in project graal by oracle.
the class FrameState method verify.
@Override
public boolean verify() {
if (virtualObjectMappingCount() > 0) {
for (EscapeObjectState state : virtualObjectMappings()) {
assertTrue(state != null, "must be non-null");
}
}
/*
* The outermost FrameState should have a method that matches StructuredGraph.method except
* when it's a substitution or it's null.
*/
assertTrue(outerFrameState != null || graph() == null || graph().method() == null || code == null || Objects.equals(graph().method(), code.getMethod()) || graph().method().getAnnotation(MethodSubstitution.class) != null, "wrong outerFrameState %s != %s", code == null ? "null" : code.getMethod(), graph().method());
if (monitorIds() != null && monitorIds().size() > 0) {
int depth = outerLockDepth();
for (MonitorIdNode monitor : monitorIds()) {
assertTrue(monitor.getLockDepth() == depth++, "wrong depth");
}
}
assertTrue(locksSize() == monitorIdCount(), "mismatch in number of locks");
for (ValueNode value : values) {
assertTrue(value == null || !value.isDeleted(), "frame state must not contain deleted nodes: %s", value);
assertTrue(value == null || value instanceof VirtualObjectNode || (value.getStackKind() != JavaKind.Void), "unexpected value: %s", value);
}
verifyAfterExceptionState();
return super.verify();
}
use of org.graalvm.compiler.nodes.virtual.VirtualObjectNode in project graal by oracle.
the class PartialEscapeBlockState method materializeBefore.
/**
* Materializes the given virtual object and produces the necessary effects in the effects list.
* This transitively also materializes all other virtual objects that are reachable from the
* entries.
*/
public void materializeBefore(FixedNode fixed, VirtualObjectNode virtual, GraphEffectList materializeEffects) {
PartialEscapeClosure.COUNTER_MATERIALIZATIONS.increment(fixed.getDebug());
List<AllocatedObjectNode> objects = new ArrayList<>(2);
List<ValueNode> values = new ArrayList<>(8);
List<List<MonitorIdNode>> locks = new ArrayList<>();
List<ValueNode> otherAllocations = new ArrayList<>(2);
List<Boolean> ensureVirtual = new ArrayList<>(2);
materializeWithCommit(fixed, virtual, objects, locks, values, ensureVirtual, otherAllocations);
materializeEffects.addVirtualizationDelta(-(objects.size() + otherAllocations.size()));
materializeEffects.add("materializeBefore", new Effect() {
@Override
public void apply(StructuredGraph graph, ArrayList<Node> obsoleteNodes) {
for (ValueNode alloc : otherAllocations) {
ValueNode otherAllocation = graph.addOrUniqueWithInputs(alloc);
if (otherAllocation instanceof FixedWithNextNode) {
graph.addBeforeFixed(fixed, (FixedWithNextNode) otherAllocation);
} else {
assert otherAllocation instanceof FloatingNode;
}
}
if (!objects.isEmpty()) {
CommitAllocationNode commit;
if (fixed.predecessor() instanceof CommitAllocationNode) {
commit = (CommitAllocationNode) fixed.predecessor();
} else {
commit = graph.add(new CommitAllocationNode());
graph.addBeforeFixed(fixed, commit);
}
for (AllocatedObjectNode obj : objects) {
graph.addWithoutUnique(obj);
commit.getVirtualObjects().add(obj.getVirtualObject());
obj.setCommit(commit);
}
for (ValueNode value : values) {
commit.getValues().add(graph.addOrUniqueWithInputs(value));
}
for (List<MonitorIdNode> monitorIds : locks) {
commit.addLocks(monitorIds);
}
commit.getEnsureVirtual().addAll(ensureVirtual);
assert commit.usages().filter(AllocatedObjectNode.class).count() == commit.getUsageCount();
List<AllocatedObjectNode> materializedValues = commit.usages().filter(AllocatedObjectNode.class).snapshot();
for (int i = 0; i < commit.getValues().size(); i++) {
if (materializedValues.contains(commit.getValues().get(i))) {
commit.getValues().set(i, ((AllocatedObjectNode) commit.getValues().get(i)).getVirtualObject());
}
}
}
}
});
}
use of org.graalvm.compiler.nodes.virtual.VirtualObjectNode in project graal by oracle.
the class PartialEscapeBlockState method materializeWithCommit.
private void materializeWithCommit(FixedNode fixed, VirtualObjectNode virtual, List<AllocatedObjectNode> objects, List<List<MonitorIdNode>> locks, List<ValueNode> values, List<Boolean> ensureVirtual, List<ValueNode> otherAllocations) {
ObjectState obj = getObjectState(virtual);
ValueNode[] entries = obj.getEntries();
ValueNode representation = virtual.getMaterializedRepresentation(fixed, entries, obj.getLocks());
escape(virtual.getObjectId(), representation);
obj = getObjectState(virtual);
PartialEscapeClosure.updateStatesForMaterialized(this, virtual, obj.getMaterializedValue());
if (representation instanceof AllocatedObjectNode) {
objects.add((AllocatedObjectNode) representation);
locks.add(LockState.asList(obj.getLocks()));
ensureVirtual.add(obj.getEnsureVirtualized());
int pos = values.size();
while (values.size() < pos + entries.length) {
values.add(null);
}
for (int i = 0; i < entries.length; i++) {
if (entries[i] instanceof VirtualObjectNode) {
VirtualObjectNode entryVirtual = (VirtualObjectNode) entries[i];
ObjectState entryObj = getObjectState(entryVirtual);
if (entryObj.isVirtual()) {
materializeWithCommit(fixed, entryVirtual, objects, locks, values, ensureVirtual, otherAllocations);
entryObj = getObjectState(entryVirtual);
}
values.set(pos + i, entryObj.getMaterializedValue());
} else {
values.set(pos + i, entries[i]);
}
}
objectMaterialized(virtual, (AllocatedObjectNode) representation, values.subList(pos, pos + entries.length));
} else {
VirtualUtil.trace(options, debug, "materialized %s as %s", virtual, representation);
otherAllocations.add(representation);
assert obj.getLocks() == null;
}
}
use of org.graalvm.compiler.nodes.virtual.VirtualObjectNode in project graal by oracle.
the class PartialEscapeClosure method processNodeWithState.
private void processNodeWithState(NodeWithState nodeWithState, BlockT state, GraphEffectList effects) {
for (FrameState fs : nodeWithState.states()) {
FrameState frameState = getUniqueFramestate(nodeWithState, fs);
EconomicSet<VirtualObjectNode> virtual = EconomicSet.create(Equivalence.IDENTITY_WITH_SYSTEM_HASHCODE);
frameState.applyToNonVirtual(new CollectVirtualObjectsClosure(virtual, effects, state));
collectLockedVirtualObjects(state, virtual);
collectReferencedVirtualObjects(state, virtual);
addVirtualMappings(frameState, virtual, state, effects);
}
}
use of org.graalvm.compiler.nodes.virtual.VirtualObjectNode in project graal by oracle.
the class PartialEscapeClosure method ensureMaterialized.
/**
* @return true if materialization happened, false if not.
*/
protected boolean ensureMaterialized(PartialEscapeBlockState<?> state, int object, FixedNode materializeBefore, GraphEffectList effects, CounterKey counter) {
if (state.getObjectState(object).isVirtual()) {
counter.increment(debug);
VirtualObjectNode virtual = virtualObjects.get(object);
state.materializeBefore(materializeBefore, virtual, effects);
assert !updateStatesForMaterialized(state, virtual, state.getObjectState(object).getMaterializedValue()) : "method must already have been called before";
return true;
} else {
return false;
}
}
Aggregations