comparison graal/com.oracle.graal.tests/src/com/oracle/graal/compiler/tests/GraphTest.java @ 5360:6cc970203f30

moved creation of a RiCodeInfo to the runtime side of the CRI
author Doug Simon <doug.simon@oracle.com>
date Mon, 07 May 2012 11:34:16 +0200
parents 9b940aff6c6b
children 0364a2a874b8
comparison
equal deleted inserted replaced
5359:4bfdf8cf87af 5360:6cc970203f30
21 * questions. 21 * questions.
22 */ 22 */
23 package com.oracle.graal.compiler.tests; 23 package com.oracle.graal.compiler.tests;
24 24
25 import java.lang.reflect.*; 25 import java.lang.reflect.*;
26 import java.util.concurrent.*;
26 27
27 import junit.framework.*; 28 import junit.framework.*;
28 29
29 import com.oracle.graal.compiler.*; 30 import com.oracle.graal.compiler.*;
30 import com.oracle.graal.compiler.phases.*; 31 import com.oracle.graal.compiler.phases.*;
31 import com.oracle.graal.compiler.phases.PhasePlan.PhasePosition; 32 import com.oracle.graal.compiler.phases.PhasePlan.PhasePosition;
32 import com.oracle.graal.cri.*; 33 import com.oracle.graal.cri.*;
33 import com.oracle.graal.debug.*; 34 import com.oracle.graal.debug.*;
34 import com.oracle.graal.java.*; 35 import com.oracle.graal.java.*;
35 import com.oracle.graal.nodes.*; 36 import com.oracle.graal.nodes.*;
37 import com.oracle.max.cri.ci.*;
36 import com.oracle.max.cri.ri.*; 38 import com.oracle.max.cri.ri.*;
37 39
38 /** 40 /**
39 * Base class for Graal compiler unit tests. These are white box tests 41 * Base class for Graal compiler unit tests. These are white box tests
40 * for Graal compiler transformations. The general pattern for a test is: 42 * for Graal compiler transformations. The general pattern for a test is:
41 * <ol> 43 * <ol>
42 * <li>Create a graph by {@linkplain #parse(String) parsing} a method.</li> 44 * <li>Create a graph by {@linkplain #parse(String) parsing} a method.</li>
43 * <li>Manually modify the graph (e.g. replace a paramter node with a constant).</li> 45 * <li>Manually modify the graph (e.g. replace a parameter node with a constant).</li>
44 * <li>Apply a transformation to the graph.</li> 46 * <li>Apply a transformation to the graph.</li>
45 * <li>Assert that the transformed graph is equal to an expected graph.</li> 47 * <li>Assert that the transformed graph is equal to an expected graph.</li>
46 * </ol> 48 * </ol>
47 * <p> 49 * <p>
48 * See {@link InvokeTest} as an example. 50 * See {@link InvokeTest} as an example.
51 * launch configuration found in the top level of this project or by 53 * launch configuration found in the top level of this project or by
52 * running {@code mx unittest} on the command line. 54 * running {@code mx unittest} on the command line.
53 */ 55 */
54 public abstract class GraphTest { 56 public abstract class GraphTest {
55 57
58 protected final GraalCompiler graalCompiler;
56 protected final GraalRuntime runtime; 59 protected final GraalRuntime runtime;
57 60
58 public GraphTest() { 61 public GraphTest() {
59 Debug.enable(); 62 Debug.enable();
60 this.runtime = GraalRuntimeAccess.getGraalRuntime(); 63 this.graalCompiler = GraalAccess.getGraalCompiler();
64 this.runtime = graalCompiler.runtime;
61 } 65 }
62 66
63 protected void assertEquals(StructuredGraph expected, StructuredGraph graph) { 67 protected void assertEquals(StructuredGraph expected, StructuredGraph graph) {
64 if (expected.getNodeCount() != graph.getNodeCount()) { 68 if (expected.getNodeCount() != graph.getNodeCount()) {
65 Debug.dump(expected, "Node count not matching - expected"); 69 Debug.dump(expected, "Node count not matching - expected");
94 } else { 98 } else {
95 throw new RuntimeException("method not found: " + methodName); 99 throw new RuntimeException("method not found: " + methodName);
96 } 100 }
97 } 101 }
98 102
103 protected RiCompiledMethod addMethod(final RiResolvedMethod method, final CiTargetMethod tm) {
104 Debug.scope("CodeInstall", new Object[] {graalCompiler, method}, new Callable<RiCompiledMethod>() {
105 @Override
106 public RiCompiledMethod call() throws Exception {
107 final RiCodeInfo[] info = Debug.isDumpEnabled() ? new RiCodeInfo[1] : null;
108 RiCompiledMethod installedMethod = runtime.addMethod(method, tm, info);
109 if (info != null) {
110 Debug.dump(info[0], "After code installation");
111 }
112 return installedMethod;
113 }
114 });
115 return runtime.addMethod(method, tm, null);
116 }
117
99 /** 118 /**
100 * Parses a Java method to produce a graph. 119 * Parses a Java method to produce a graph.
101 * 120 *
102 * @param methodName the name of the method in {@code this.getClass()} to be parsed 121 * @param methodName the name of the method in {@code this.getClass()} to be parsed
103 */ 122 */