src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/GraphEncoder.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File hotspot Cdiff src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/GraphEncoder.java

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/GraphEncoder.java

Print this page

        

*** 20,35 **** * or visit www.oracle.com if you need additional information or have any * questions. */ package org.graalvm.compiler.nodes; - import static org.graalvm.compiler.core.common.CompilationIdentifier.INVALID_COMPILATION_ID; - import java.util.ArrayDeque; import java.util.Deque; import java.util.Iterator; - import java.util.Map; import java.util.Objects; import org.graalvm.compiler.core.common.Fields; import org.graalvm.compiler.core.common.util.FrequencyEncoder; import org.graalvm.compiler.core.common.util.TypeConversion; --- 20,32 ----
*** 43,52 **** --- 40,51 ---- import org.graalvm.compiler.graph.NodeList; import org.graalvm.compiler.graph.NodeMap; import org.graalvm.compiler.graph.iterators.NodeIterable; import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions; import org.graalvm.compiler.nodes.java.ExceptionObjectNode; + import org.graalvm.util.UnmodifiableMapCursor; + import org.graalvm.util.Pair; import jdk.vm.ci.code.Architecture; /** * Encodes a {@link StructuredGraph} to a compact byte[] array. All nodes of the graph and edges
*** 85,96 **** * * <pre> * struct Node { * unsigned typeId * signed[] properties - * unsigned[] successorOrderIds * unsigned[] inputOrderIds * } * </pre> * * All numbers (unsigned and signed) are stored using a variable-length encoding as defined in * {@link TypeReader} and {@link TypeWriter}. Especially orderIds are small, so the variable-length --- 84,95 ---- * * <pre> * struct Node { * unsigned typeId * signed[] properties * unsigned[] inputOrderIds + * unsigned[] successorOrderIds * } * </pre> * * All numbers (unsigned and signed) are stored using a variable-length encoding as defined in * {@link TypeReader} and {@link TypeWriter}. Especially orderIds are small, so the variable-length
*** 151,161 **** */ public static EncodedGraph encodeSingleGraph(StructuredGraph graph, Architecture architecture) { GraphEncoder encoder = new GraphEncoder(architecture); encoder.prepare(graph); encoder.finishPrepare(); ! long startOffset = encoder.encode(graph); return new EncodedGraph(encoder.getEncoding(), startOffset, encoder.getObjects(), encoder.getNodeClasses(), graph.getAssumptions(), graph.getMethods()); } public GraphEncoder(Architecture architecture) { this.architecture = architecture; --- 150,160 ---- */ public static EncodedGraph encodeSingleGraph(StructuredGraph graph, Architecture architecture) { GraphEncoder encoder = new GraphEncoder(architecture); encoder.prepare(graph); encoder.finishPrepare(); ! int startOffset = encoder.encode(graph); return new EncodedGraph(encoder.getEncoding(), startOffset, encoder.getObjects(), encoder.getNodeClasses(), graph.getAssumptions(), graph.getMethods()); } public GraphEncoder(Architecture architecture) { this.architecture = architecture;
*** 201,233 **** * Compresses a graph to a byte array. Multiple graphs can be compressed with the same * {@link GraphEncoder}. * * @param graph The graph to encode */ ! public long encode(StructuredGraph graph) { assert objectsArray != null && nodeClassesArray != null : "finishPrepare() must be called before encode()"; NodeOrder nodeOrder = new NodeOrder(graph); int nodeCount = nodeOrder.nextOrderId; assert nodeOrder.orderIds.get(graph.start()) == START_NODE_ORDER_ID; assert nodeOrder.orderIds.get(graph.start().next()) == FIRST_NODE_ORDER_ID; assert nodeCount == graph.getNodeCount() + 1; long[] nodeStartOffsets = new long[nodeCount]; ! for (Map.Entry<Node, Integer> entry : nodeOrder.orderIds.entries()) { ! Node node = entry.getKey(); ! Integer orderId = entry.getValue(); assert !(node instanceof AbstractBeginNode) || nodeOrder.orderIds.get(((AbstractBeginNode) node).next()) == orderId + BEGIN_NEXT_ORDER_ID_OFFSET; nodeStartOffsets[orderId] = writer.getBytesWritten(); /* Write out the type, properties, and edges. */ NodeClass<?> nodeClass = node.getNodeClass(); writer.putUV(nodeClasses.getIndex(nodeClass)); writeProperties(node, nodeClass.getData()); - writeEdges(node, nodeClass.getEdges(Edges.Type.Successors), nodeOrder); writeEdges(node, nodeClass.getEdges(Edges.Type.Inputs), nodeOrder); /* Special handling for some nodes that require additional information for decoding. */ if (node instanceof AbstractEndNode) { AbstractEndNode end = (AbstractEndNode) node; AbstractMergeNode merge = end.merge(); --- 200,233 ---- * Compresses a graph to a byte array. Multiple graphs can be compressed with the same * {@link GraphEncoder}. * * @param graph The graph to encode */ ! public int encode(StructuredGraph graph) { assert objectsArray != null && nodeClassesArray != null : "finishPrepare() must be called before encode()"; NodeOrder nodeOrder = new NodeOrder(graph); int nodeCount = nodeOrder.nextOrderId; assert nodeOrder.orderIds.get(graph.start()) == START_NODE_ORDER_ID; assert nodeOrder.orderIds.get(graph.start().next()) == FIRST_NODE_ORDER_ID; assert nodeCount == graph.getNodeCount() + 1; long[] nodeStartOffsets = new long[nodeCount]; ! UnmodifiableMapCursor<Node, Integer> cursor = nodeOrder.orderIds.getEntries(); ! while (cursor.advance()) { ! Node node = cursor.getKey(); ! Integer orderId = cursor.getValue(); assert !(node instanceof AbstractBeginNode) || nodeOrder.orderIds.get(((AbstractBeginNode) node).next()) == orderId + BEGIN_NEXT_ORDER_ID_OFFSET; nodeStartOffsets[orderId] = writer.getBytesWritten(); /* Write out the type, properties, and edges. */ NodeClass<?> nodeClass = node.getNodeClass(); writer.putUV(nodeClasses.getIndex(nodeClass)); writeProperties(node, nodeClass.getData()); writeEdges(node, nodeClass.getEdges(Edges.Type.Inputs), nodeOrder); + writeEdges(node, nodeClass.getEdges(Edges.Type.Successors), nodeOrder); /* Special handling for some nodes that require additional information for decoding. */ if (node instanceof AbstractEndNode) { AbstractEndNode end = (AbstractEndNode) node; AbstractMergeNode merge = end.merge();
*** 275,285 **** } } } /* Write out the table of contents with the start offset for all nodes. */ ! long nodeTableStart = writer.getBytesWritten(); writer.putUV(nodeCount); for (int i = 0; i < nodeCount; i++) { assert i == NULL_ORDER_ID || i == START_NODE_ORDER_ID || nodeStartOffsets[i] > 0; writer.putUV(nodeTableStart - nodeStartOffsets[i]); } --- 275,285 ---- } } } /* Write out the table of contents with the start offset for all nodes. */ ! int nodeTableStart = TypeConversion.asS4(writer.getBytesWritten()); writer.putUV(nodeCount); for (int i = 0; i < nodeCount; i++) { assert i == NULL_ORDER_ID || i == START_NODE_ORDER_ID || nodeStartOffsets[i] > 0; writer.putUV(nodeTableStart - nodeStartOffsets[i]); }
*** 336,346 **** current = nodeQueue.pollFirst(); } } while (current != null); for (Node node : graph.getNodes()) { ! assert (node instanceof FixedNode) == (orderIds.get(node) != null) : "all fixed nodes must be ordered"; add(node); } } private void add(Node node) { --- 336,346 ---- current = nodeQueue.pollFirst(); } } while (current != null); for (Node node : graph.getNodes()) { ! assert (node instanceof FixedNode) == (orderIds.get(node) != null) : "all fixed nodes must be ordered: " + node; add(node); } } private void add(Node node) {
*** 364,382 **** } } protected void writeEdges(Node node, Edges edges, NodeOrder nodeOrder) { for (int idx = 0; idx < edges.getDirectCount(); idx++) { ! if (GraphDecoder.skipEdge(node, edges, idx, true, false)) { /* Edge is not needed for decoding, so we must not write it. */ continue; } Node edge = Edges.getNode(node, edges.getOffsets(), idx); writeOrderId(edge, nodeOrder); } for (int idx = edges.getDirectCount(); idx < edges.getCount(); idx++) { ! if (GraphDecoder.skipEdge(node, edges, idx, false, false)) { /* Edge is not needed for decoding, so we must not write it. */ continue; } NodeList<Node> edgeList = Edges.getNodeList(node, edges.getOffsets(), idx); if (edgeList == null) { --- 364,382 ---- } } protected void writeEdges(Node node, Edges edges, NodeOrder nodeOrder) { for (int idx = 0; idx < edges.getDirectCount(); idx++) { ! if (GraphDecoder.skipDirectEdge(node, edges, idx)) { /* Edge is not needed for decoding, so we must not write it. */ continue; } Node edge = Edges.getNode(node, edges.getOffsets(), idx); writeOrderId(edge, nodeOrder); } for (int idx = edges.getDirectCount(); idx < edges.getCount(); idx++) { ! if (GraphDecoder.skipIndirectEdge(node, edges, idx, false)) { /* Edge is not needed for decoding, so we must not write it. */ continue; } NodeList<Node> edgeList = Edges.getNodeList(node, edges.getOffsets(), idx); if (edgeList == null) {
*** 402,412 **** * Verification code that checks that the decoding of an encode graph is the same as the * original graph. */ @SuppressWarnings("try") public static boolean verifyEncoding(StructuredGraph originalGraph, EncodedGraph encodedGraph, Architecture architecture) { ! StructuredGraph decodedGraph = new StructuredGraph(originalGraph.method(), AllowAssumptions.YES, INVALID_COMPILATION_ID); GraphDecoder decoder = new GraphDecoder(architecture); decoder.decode(decodedGraph, encodedGraph); decodedGraph.verify(); try { --- 402,412 ---- * Verification code that checks that the decoding of an encode graph is the same as the * original graph. */ @SuppressWarnings("try") public static boolean verifyEncoding(StructuredGraph originalGraph, EncodedGraph encodedGraph, Architecture architecture) { ! StructuredGraph decodedGraph = new StructuredGraph.Builder(originalGraph.getOptions(), AllowAssumptions.YES).method(originalGraph.method()).build(); GraphDecoder decoder = new GraphDecoder(architecture); decoder.decode(decodedGraph, encodedGraph); decodedGraph.verify(); try {
*** 428,439 **** Deque<Pair<Node, Node>> workList = new ArrayDeque<>(); pushToWorklist(expectedGraph.start(), actualGraph.start(), nodeMapping, workList); while (!workList.isEmpty()) { Pair<Node, Node> pair = workList.removeFirst(); ! Node expectedNode = pair.first; ! Node actualNode = pair.second; assert expectedNode.getClass() == actualNode.getClass(); NodeClass<?> nodeClass = expectedNode.getNodeClass(); assert nodeClass == actualNode.getNodeClass(); --- 428,439 ---- Deque<Pair<Node, Node>> workList = new ArrayDeque<>(); pushToWorklist(expectedGraph.start(), actualGraph.start(), nodeMapping, workList); while (!workList.isEmpty()) { Pair<Node, Node> pair = workList.removeFirst(); ! Node expectedNode = pair.getLeft(); ! Node actualNode = pair.getRight(); assert expectedNode.getClass() == actualNode.getClass(); NodeClass<?> nodeClass = expectedNode.getNodeClass(); assert nodeClass == actualNode.getNodeClass();
*** 528,548 **** protected static void pushToWorklist(Node expectedNode, Node actualNode, NodeMap<Node> nodeMapping, Deque<Pair<Node, Node>> workList) { nodeMapping.set(expectedNode, actualNode); if (expectedNode instanceof AbstractEndNode) { /* To ensure phi nodes have been added, we handle everything before block ends. */ ! workList.addLast(new Pair<>(expectedNode, actualNode)); } else { ! workList.addFirst(new Pair<>(expectedNode, actualNode)); ! } } - } - - class Pair<F, S> { - public final F first; - public final S second; - - Pair(F first, S second) { - this.first = first; - this.second = second; } } --- 528,538 ---- protected static void pushToWorklist(Node expectedNode, Node actualNode, NodeMap<Node> nodeMapping, Deque<Pair<Node, Node>> workList) { nodeMapping.set(expectedNode, actualNode); if (expectedNode instanceof AbstractEndNode) { /* To ensure phi nodes have been added, we handle everything before block ends. */ ! workList.addLast(Pair.create(expectedNode, actualNode)); } else { ! workList.addFirst(Pair.create(expectedNode, actualNode)); } } }
src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/GraphEncoder.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File