Search in sources :

Example 11 with VirtualObjectNode

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();
}
Also used : MonitorIdNode(org.graalvm.compiler.nodes.java.MonitorIdNode) VirtualObjectNode(org.graalvm.compiler.nodes.virtual.VirtualObjectNode) EscapeObjectState(org.graalvm.compiler.nodes.virtual.EscapeObjectState) MethodSubstitution(org.graalvm.compiler.api.replacements.MethodSubstitution)

Example 12 with VirtualObjectNode

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());
                    }
                }
            }
        }
    });
}
Also used : FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) AllocatedObjectNode(org.graalvm.compiler.nodes.virtual.AllocatedObjectNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) FloatingNode(org.graalvm.compiler.nodes.calc.FloatingNode) VirtualObjectNode(org.graalvm.compiler.nodes.virtual.VirtualObjectNode) AllocatedObjectNode(org.graalvm.compiler.nodes.virtual.AllocatedObjectNode) CommitAllocationNode(org.graalvm.compiler.nodes.virtual.CommitAllocationNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) MonitorIdNode(org.graalvm.compiler.nodes.java.MonitorIdNode) Node(org.graalvm.compiler.graph.Node) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) ArrayList(java.util.ArrayList) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) ValueNode(org.graalvm.compiler.nodes.ValueNode) FloatingNode(org.graalvm.compiler.nodes.calc.FloatingNode) ArrayList(java.util.ArrayList) List(java.util.List) Effect(org.graalvm.compiler.virtual.phases.ea.EffectList.Effect) CommitAllocationNode(org.graalvm.compiler.nodes.virtual.CommitAllocationNode)

Example 13 with VirtualObjectNode

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;
    }
}
Also used : VirtualObjectNode(org.graalvm.compiler.nodes.virtual.VirtualObjectNode) AllocatedObjectNode(org.graalvm.compiler.nodes.virtual.AllocatedObjectNode) ValueNode(org.graalvm.compiler.nodes.ValueNode)

Example 14 with VirtualObjectNode

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);
    }
}
Also used : VirtualObjectNode(org.graalvm.compiler.nodes.virtual.VirtualObjectNode) FrameState(org.graalvm.compiler.nodes.FrameState)

Example 15 with VirtualObjectNode

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;
    }
}
Also used : VirtualObjectNode(org.graalvm.compiler.nodes.virtual.VirtualObjectNode)

Aggregations

VirtualObjectNode (org.graalvm.compiler.nodes.virtual.VirtualObjectNode)42 ValueNode (org.graalvm.compiler.nodes.ValueNode)38 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)8 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)7 Node (org.graalvm.compiler.graph.Node)7 ProxyNode (org.graalvm.compiler.nodes.ProxyNode)7 VirtualObjectState (org.graalvm.compiler.virtual.nodes.VirtualObjectState)6 FixedNode (org.graalvm.compiler.nodes.FixedNode)5 PhiNode (org.graalvm.compiler.nodes.PhiNode)5 Block (org.graalvm.compiler.nodes.cfg.Block)5 ArrayList (java.util.ArrayList)4 FixedWithNextNode (org.graalvm.compiler.nodes.FixedWithNextNode)4 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)4 ValueProxyNode (org.graalvm.compiler.nodes.ValueProxyNode)4 VirtualArrayNode (org.graalvm.compiler.nodes.virtual.VirtualArrayNode)4 VirtualInstanceNode (org.graalvm.compiler.nodes.virtual.VirtualInstanceNode)4 JavaKind (jdk.vm.ci.meta.JavaKind)3 FrameState (org.graalvm.compiler.nodes.FrameState)3 LoopBeginNode (org.graalvm.compiler.nodes.LoopBeginNode)3 BitSet (java.util.BitSet)2