< 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,122 ****
* 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}. */
public static final int NULL_ORDER_ID = 0;
! /** 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;
--- 110,126 ----
* 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}.
! */
public static final int NULL_ORDER_ID = 0;
! /**
! * 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,155 ****
--- 150,161 ----
/** 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,177 ****
--- 164,189 ----
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,298 ****
writer.putUV(nodeOrder.maxFixedNodeOrderId);
writer.putUV(nodeCount);
for (int i = 0; i < nodeCount; i++) {
writer.putUV(metadataStart - nodeStartOffsets[i]);
}
/* 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);
return metadataStart;
}
public byte[] getEncoding() {
--- 298,311 ----
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));
return metadataStart;
}
public byte[] getEncoding() {
*** 432,445 ****
/**
* 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();
// @formatter:off
! StructuredGraph decodedGraph = new StructuredGraph.Builder(originalGraph.getOptions(), debug, AllowAssumptions.YES).
method(originalGraph.method()).
setIsSubstitution(originalGraph.isSubstitution()).
trackNodeSourcePosition(originalGraph.trackNodeSourcePosition()).
build();
// @formatter:off
--- 445,458 ----
/**
* Verification code that checks that the decoding of an encode graph is the same as the
* original graph.
*/
@SuppressWarnings("try")
! public boolean verifyEncoding(StructuredGraph originalGraph, EncodedGraph encodedGraph) {
! DebugContext debugContext = debug != null ? debug : originalGraph.getDebug();
// @formatter:off
! StructuredGraph decodedGraph = new StructuredGraph.Builder(originalGraph.getOptions(), debugContext, AllowAssumptions.YES).
method(originalGraph.method()).
setIsSubstitution(originalGraph.isSubstitution()).
trackNodeSourcePosition(originalGraph.trackNodeSourcePosition()).
build();
// @formatter:off
*** 449,461 ****
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");
}
throw ex;
}
return true;
}
--- 462,474 ----
decodedGraph.verify();
try {
GraphComparison.verifyGraphsEqual(originalGraph, decodedGraph);
} catch (Throwable ex) {
originalGraph.getDebug();
! 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 >