< prev index next >
src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/GraphEncoder.java
Print this page
@@ -110,13 +110,17 @@
* mappings} from this end to the merge node are written. <item>{@link LoopExitNode}: the orderId of
* all {@link ProxyNode proxy nodes} of the loop exit is written.</li>
*/
public class GraphEncoder {
- /** The orderId that always represents {@code null}. */
+ /**
+ * The orderId that always represents {@code null}.
+ */
public static final int NULL_ORDER_ID = 0;
- /** The orderId of the {@link StructuredGraph#start() start node} of the encoded graph. */
+ /**
+ * The orderId of the {@link StructuredGraph#start() start node} of the encoded graph.
+ */
public static final int START_NODE_ORDER_ID = 1;
/**
* The orderId of the first actual node after the {@link StructuredGraph#start() start node}.
*/
public static final int FIRST_NODE_ORDER_ID = 2;
@@ -146,10 +150,12 @@
/** The last snapshot of {@link #objects} that was retrieved. */
protected Object[] objectsArray;
/** The last snapshot of {@link #nodeClasses} that was retrieved. */
protected NodeClass<?>[] nodeClassesArray;
+ protected DebugContext debug;
+
/**
* Utility method that does everything necessary to encode a single graph.
*/
public static EncodedGraph encodeSingleGraph(StructuredGraph graph, Architecture architecture) {
GraphEncoder encoder = new GraphEncoder(architecture);
@@ -158,20 +164,26 @@
int startOffset = encoder.encode(graph);
return new EncodedGraph(encoder.getEncoding(), startOffset, encoder.getObjects(), encoder.getNodeClasses(), graph);
}
public GraphEncoder(Architecture architecture) {
+ this(architecture, null);
+ }
+
+ public GraphEncoder(Architecture architecture, DebugContext debug) {
this.architecture = architecture;
+ this.debug = debug;
objects = FrequencyEncoder.createEqualityEncoder();
nodeClasses = FrequencyEncoder.createIdentityEncoder();
writer = UnsafeArrayTypeWriter.create(architecture.supportsUnalignedMemoryAccess());
}
/**
* Must be invoked before {@link #finishPrepare()} and {@link #encode}.
*/
public void prepare(StructuredGraph graph) {
+ objects.addObject(graph.getGuardsStage());
for (Node node : graph.getNodes()) {
NodeClass<? extends Node> nodeClass = node.getNodeClass();
nodeClasses.addObject(nodeClass);
objects.addObject(node.getNodeSourcePosition());
for (int i = 0; i < nodeClass.getData().getCount(); i++) {
@@ -286,13 +298,14 @@
writer.putUV(nodeOrder.maxFixedNodeOrderId);
writer.putUV(nodeCount);
for (int i = 0; i < nodeCount; i++) {
writer.putUV(metadataStart - nodeStartOffsets[i]);
}
+ writeObjectId(graph.getGuardsStage());
/* Check that the decoding of the encode graph is the same as the input. */
- assert verifyEncoding(graph, new EncodedGraph(getEncoding(), metadataStart, getObjects(), getNodeClasses(), graph), architecture);
+ assert verifyEncoding(graph, new EncodedGraph(getEncoding(), metadataStart, getObjects(), getNodeClasses(), graph));
return metadataStart;
}
public byte[] getEncoding() {
@@ -432,14 +445,14 @@
/**
* 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) {
- DebugContext debug = originalGraph.getDebug();
+ public boolean verifyEncoding(StructuredGraph originalGraph, EncodedGraph encodedGraph) {
+ DebugContext debugContext = debug != null ? debug : originalGraph.getDebug();
// @formatter:off
- StructuredGraph decodedGraph = new StructuredGraph.Builder(originalGraph.getOptions(), debug, AllowAssumptions.YES).
+ StructuredGraph decodedGraph = new StructuredGraph.Builder(originalGraph.getOptions(), debugContext, AllowAssumptions.YES).
method(originalGraph.method()).
setIsSubstitution(originalGraph.isSubstitution()).
trackNodeSourcePosition(originalGraph.trackNodeSourcePosition()).
build();
// @formatter:off
@@ -449,13 +462,13 @@
decodedGraph.verify();
try {
GraphComparison.verifyGraphsEqual(originalGraph, decodedGraph);
} catch (Throwable ex) {
originalGraph.getDebug();
- try (DebugContext.Scope scope = debug.scope("GraphEncoder")) {
- debug.dump(DebugContext.VERBOSE_LEVEL, originalGraph, "Original Graph");
- debug.dump(DebugContext.VERBOSE_LEVEL, decodedGraph, "Decoded Graph");
+ try (DebugContext.Scope scope = debugContext.scope("GraphEncoder")) {
+ debugContext.dump(DebugContext.VERBOSE_LEVEL, originalGraph, "Original Graph");
+ debugContext.dump(DebugContext.VERBOSE_LEVEL, decodedGraph, "Decoded Graph");
}
throw ex;
}
return true;
}
< prev index next >