annotate graal/com.oracle.graal.tests/src/com/oracle/graal/compiler/tests/GraalCompilerTest.java @ 5571:102f87543d5e

Merge.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Mon, 11 Jun 2012 17:06:06 +0200
parents graal/com.oracle.graal.tests/src/com/oracle/graal/compiler/tests/GraphTest.java@2e2a77f091f2 graal/com.oracle.graal.tests/src/com/oracle/graal/compiler/tests/GraphTest.java@0083a59ced84
children 592dfff9d410
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
1 /*
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
2 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
4 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
8 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
13 * accompanied this code).
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
14 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
18 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
21 * questions.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
22 */
5060
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
23 package com.oracle.graal.compiler.tests;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
24
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
25 import java.lang.reflect.*;
5360
6cc970203f30 moved creation of a RiCodeInfo to the runtime side of the CRI
Doug Simon <doug.simon@oracle.com>
parents: 5122
diff changeset
26 import java.util.concurrent.*;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
27
5114
dad1ac9dba7d finished first implementation of disabling runtime feedback selectively based on deoptimization history
Christian Haeubl <christian.haeubl@oracle.com>
parents: 5109
diff changeset
28 import junit.framework.*;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
29
5533
c5c13f3ed5c4 Remove GraalAccess class, replace usages new GraalVM API.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5510
diff changeset
30 import com.oracle.graal.api.*;
5510
426c605c9d3c Move cri.ci to api.code.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5507
diff changeset
31 import com.oracle.graal.api.code.*;
5507
dc71b06d09f8 Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5499
diff changeset
32 import com.oracle.graal.api.meta.*;
5114
dad1ac9dba7d finished first implementation of disabling runtime feedback selectively based on deoptimization history
Christian Haeubl <christian.haeubl@oracle.com>
parents: 5109
diff changeset
33 import com.oracle.graal.compiler.*;
5060
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
34 import com.oracle.graal.compiler.phases.*;
5114
dad1ac9dba7d finished first implementation of disabling runtime feedback selectively based on deoptimization history
Christian Haeubl <christian.haeubl@oracle.com>
parents: 5109
diff changeset
35 import com.oracle.graal.compiler.phases.PhasePlan.PhasePosition;
5425
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents: 5360
diff changeset
36 import com.oracle.graal.compiler.schedule.*;
5060
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
37 import com.oracle.graal.cri.*;
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
38 import com.oracle.graal.debug.*;
5425
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents: 5360
diff changeset
39 import com.oracle.graal.graph.*;
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents: 5360
diff changeset
40 import com.oracle.graal.graph.Node.Verbosity;
5060
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
41 import com.oracle.graal.java.*;
5425
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents: 5360
diff changeset
42 import com.oracle.graal.lir.cfg.*;
5060
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
43 import com.oracle.graal.nodes.*;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
44
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
45 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
46 * Base class for Graal compiler unit tests. These are white box tests
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
47 * for Graal compiler transformations. The general pattern for a test is:
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
48 * <ol>
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
49 * <li>Create a graph by {@linkplain #parse(String) parsing} a method.</li>
5360
6cc970203f30 moved creation of a RiCodeInfo to the runtime side of the CRI
Doug Simon <doug.simon@oracle.com>
parents: 5122
diff changeset
50 * <li>Manually modify the graph (e.g. replace a parameter node with a constant).</li>
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
51 * <li>Apply a transformation to the graph.</li>
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
52 * <li>Assert that the transformed graph is equal to an expected graph.</li>
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
53 * </ol>
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
54 * <p>
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
55 * See {@link InvokeTest} as an example.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
56 * <p>
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
57 * The tests can be run in Eclipse with the "Compiler Unit Test" Eclipse
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
58 * launch configuration found in the top level of this project or by
4410
646a6bfecf73 Small doc fixes.
Doug Simon <doug.simon@oracle.com>
parents: 4387
diff changeset
59 * running {@code mx unittest} on the command line.
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
60 */
5565
0083a59ced84 Renaming GraphTest => GraalCompilerTest.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5546
diff changeset
61 public abstract class GraalCompilerTest {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
62
5499
8d7d009a54d8 Introduction of com.oracle.graal.api project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5461
diff changeset
63 protected final ExtendedRiRuntime runtime;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
64
5565
0083a59ced84 Renaming GraphTest => GraalCompilerTest.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5546
diff changeset
65 public GraalCompilerTest() {
5085
5bdaa08ba96b add and enable new PropagateTypeCachePhase, add type system tests
Lukas Stadler <lukas.stadler@jku.at>
parents: 5061
diff changeset
66 Debug.enable();
5533
c5c13f3ed5c4 Remove GraalAccess class, replace usages new GraalVM API.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5510
diff changeset
67 this.runtime = Graal.getRuntime().getCapability(ExtendedRiRuntime.class);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
68 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
69
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
70 protected void assertEquals(StructuredGraph expected, StructuredGraph graph) {
5425
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents: 5360
diff changeset
71 String expectedString = getCanonicalGraphString(expected);
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents: 5360
diff changeset
72 String actualString = getCanonicalGraphString(graph);
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents: 5360
diff changeset
73 String mismatchString = "mismatch in graphs:\n========= expected =========\n" + expectedString + "\n\n========= actual =========\n" + actualString;
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents: 5360
diff changeset
74
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
75 if (expected.getNodeCount() != graph.getNodeCount()) {
4363
7462c3600c3a Draft changes to the graph plotting.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4265
diff changeset
76 Debug.dump(expected, "Node count not matching - expected");
7462c3600c3a Draft changes to the graph plotting.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4265
diff changeset
77 Debug.dump(graph, "Node count not matching - actual");
5425
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents: 5360
diff changeset
78 Assert.fail("Graphs do not have the same number of nodes: " + expected.getNodeCount() + " vs. " + graph.getNodeCount() + "\n" + mismatchString);
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents: 5360
diff changeset
79 }
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents: 5360
diff changeset
80 if (!expectedString.equals(actualString)) {
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents: 5360
diff changeset
81 Debug.dump(expected, "mismatching graphs - expected");
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents: 5360
diff changeset
82 Debug.dump(graph, "mismatching graphs - actual");
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents: 5360
diff changeset
83 Assert.fail(mismatchString);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
84 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
85 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
86
5425
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents: 5360
diff changeset
87 private static String getCanonicalGraphString(StructuredGraph graph) {
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents: 5360
diff changeset
88 SchedulePhase schedule = new SchedulePhase();
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents: 5360
diff changeset
89 schedule.apply(graph);
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents: 5360
diff changeset
90
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents: 5360
diff changeset
91 NodeMap<Integer> canonicalId = graph.createNodeMap();
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents: 5360
diff changeset
92 int nextId = 0;
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents: 5360
diff changeset
93
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents: 5360
diff changeset
94 StringBuilder result = new StringBuilder();
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents: 5360
diff changeset
95 for (Block block : schedule.getCFG().getBlocks()) {
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents: 5360
diff changeset
96 result.append("Block " + block + " ");
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents: 5360
diff changeset
97 if (block == schedule.getCFG().getStartBlock()) {
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents: 5360
diff changeset
98 result.append("* ");
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents: 5360
diff changeset
99 }
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents: 5360
diff changeset
100 result.append("-> ");
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents: 5360
diff changeset
101 for (Block succ : block.getSuccessors()) {
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents: 5360
diff changeset
102 result.append(succ + " ");
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents: 5360
diff changeset
103 }
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents: 5360
diff changeset
104 result.append("\n");
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents: 5360
diff changeset
105 for (Node node : schedule.getBlockToNodesMap().get(block)) {
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents: 5360
diff changeset
106 int id;
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents: 5360
diff changeset
107 if (canonicalId.get(node) != null) {
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents: 5360
diff changeset
108 id = canonicalId.get(node);
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents: 5360
diff changeset
109 } else {
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents: 5360
diff changeset
110 id = nextId++;
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents: 5360
diff changeset
111 canonicalId.set(node, id);
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents: 5360
diff changeset
112 }
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents: 5360
diff changeset
113 String name = node instanceof ConstantNode ? node.toString(Verbosity.Name) : node.getClass().getSimpleName();
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents: 5360
diff changeset
114 result.append(" " + id + "|" + name + " (" + node.usages().size() + ")\n");
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents: 5360
diff changeset
115 }
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents: 5360
diff changeset
116 }
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents: 5360
diff changeset
117 return result.toString();
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents: 5360
diff changeset
118 }
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents: 5360
diff changeset
119
5499
8d7d009a54d8 Introduction of com.oracle.graal.api project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5461
diff changeset
120 protected ExtendedRiRuntime runtime() {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
121 return runtime;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
122 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
123
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
124 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
125 * Parses a Java method to produce a graph.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
126 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
127 * @param methodName the name of the method in {@code this.getClass()} to be parsed
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
128 */
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
129 protected StructuredGraph parse(String methodName) {
4993
897b7d18bebc added RiCompiledMethod.execute and the required VM infrastructure
Lukas Stadler <lukas.stadler@jku.at>
parents: 4410
diff changeset
130 return parse(getMethod(methodName));
897b7d18bebc added RiCompiledMethod.execute and the required VM infrastructure
Lukas Stadler <lukas.stadler@jku.at>
parents: 4410
diff changeset
131 }
897b7d18bebc added RiCompiledMethod.execute and the required VM infrastructure
Lukas Stadler <lukas.stadler@jku.at>
parents: 4410
diff changeset
132
897b7d18bebc added RiCompiledMethod.execute and the required VM infrastructure
Lukas Stadler <lukas.stadler@jku.at>
parents: 4410
diff changeset
133 protected Method getMethod(String methodName) {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
134 Method found = null;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
135 for (Method m : this.getClass().getMethods()) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
136 if (m.getName().equals(methodName)) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
137 Assert.assertNull(found);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
138 found = m;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
139 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
140 }
4340
5caca26cb1b9 small fix (missing changes)
Lukas Stadler <lukas.stadler@jku.at>
parents: 4315
diff changeset
141 if (found != null) {
4993
897b7d18bebc added RiCompiledMethod.execute and the required VM infrastructure
Lukas Stadler <lukas.stadler@jku.at>
parents: 4410
diff changeset
142 return found;
4340
5caca26cb1b9 small fix (missing changes)
Lukas Stadler <lukas.stadler@jku.at>
parents: 4315
diff changeset
143 } else {
5caca26cb1b9 small fix (missing changes)
Lukas Stadler <lukas.stadler@jku.at>
parents: 4315
diff changeset
144 throw new RuntimeException("method not found: " + methodName);
5caca26cb1b9 small fix (missing changes)
Lukas Stadler <lukas.stadler@jku.at>
parents: 4315
diff changeset
145 }
5caca26cb1b9 small fix (missing changes)
Lukas Stadler <lukas.stadler@jku.at>
parents: 4315
diff changeset
146 }
5caca26cb1b9 small fix (missing changes)
Lukas Stadler <lukas.stadler@jku.at>
parents: 4315
diff changeset
147
5433
d7b5cc23945e refactored tests to share support for dump-aware compilation
Doug Simon <doug.simon@oracle.com>
parents: 5425
diff changeset
148 private static int compilationId = 0;
d7b5cc23945e refactored tests to share support for dump-aware compilation
Doug Simon <doug.simon@oracle.com>
parents: 5425
diff changeset
149
5557
2e2a77f091f2 re-enabled disassembler output to C1Visualizer after code installation
Doug Simon <doug.simon@oracle.com>
parents: 5546
diff changeset
150 protected void test(String name, Object... args) {
2e2a77f091f2 re-enabled disassembler output to C1Visualizer after code installation
Doug Simon <doug.simon@oracle.com>
parents: 5546
diff changeset
151 Method method = getMethod(name);
2e2a77f091f2 re-enabled disassembler output to C1Visualizer after code installation
Doug Simon <doug.simon@oracle.com>
parents: 5546
diff changeset
152 Object expect = null;
2e2a77f091f2 re-enabled disassembler output to C1Visualizer after code installation
Doug Simon <doug.simon@oracle.com>
parents: 5546
diff changeset
153 Throwable exception = null;
2e2a77f091f2 re-enabled disassembler output to C1Visualizer after code installation
Doug Simon <doug.simon@oracle.com>
parents: 5546
diff changeset
154 try {
2e2a77f091f2 re-enabled disassembler output to C1Visualizer after code installation
Doug Simon <doug.simon@oracle.com>
parents: 5546
diff changeset
155 // This gives us both the expected return value as well as ensuring that the method to be compiled is fully resolved
2e2a77f091f2 re-enabled disassembler output to C1Visualizer after code installation
Doug Simon <doug.simon@oracle.com>
parents: 5546
diff changeset
156 expect = method.invoke(null, args);
2e2a77f091f2 re-enabled disassembler output to C1Visualizer after code installation
Doug Simon <doug.simon@oracle.com>
parents: 5546
diff changeset
157 } catch (InvocationTargetException e) {
2e2a77f091f2 re-enabled disassembler output to C1Visualizer after code installation
Doug Simon <doug.simon@oracle.com>
parents: 5546
diff changeset
158 exception = e.getTargetException();
2e2a77f091f2 re-enabled disassembler output to C1Visualizer after code installation
Doug Simon <doug.simon@oracle.com>
parents: 5546
diff changeset
159 } catch (Exception e) {
2e2a77f091f2 re-enabled disassembler output to C1Visualizer after code installation
Doug Simon <doug.simon@oracle.com>
parents: 5546
diff changeset
160 throw new RuntimeException(e);
2e2a77f091f2 re-enabled disassembler output to C1Visualizer after code installation
Doug Simon <doug.simon@oracle.com>
parents: 5546
diff changeset
161 }
2e2a77f091f2 re-enabled disassembler output to C1Visualizer after code installation
Doug Simon <doug.simon@oracle.com>
parents: 5546
diff changeset
162 InstalledCode compiledMethod = compile(runtime.getResolvedJavaMethod(method), parse(method));
2e2a77f091f2 re-enabled disassembler output to C1Visualizer after code installation
Doug Simon <doug.simon@oracle.com>
parents: 5546
diff changeset
163 compiledMethod.method();
2e2a77f091f2 re-enabled disassembler output to C1Visualizer after code installation
Doug Simon <doug.simon@oracle.com>
parents: 5546
diff changeset
164
2e2a77f091f2 re-enabled disassembler output to C1Visualizer after code installation
Doug Simon <doug.simon@oracle.com>
parents: 5546
diff changeset
165 if (exception != null) {
2e2a77f091f2 re-enabled disassembler output to C1Visualizer after code installation
Doug Simon <doug.simon@oracle.com>
parents: 5546
diff changeset
166 try {
2e2a77f091f2 re-enabled disassembler output to C1Visualizer after code installation
Doug Simon <doug.simon@oracle.com>
parents: 5546
diff changeset
167 compiledMethod.executeVarargs(args);
2e2a77f091f2 re-enabled disassembler output to C1Visualizer after code installation
Doug Simon <doug.simon@oracle.com>
parents: 5546
diff changeset
168 Assert.fail("expected " + exception);
2e2a77f091f2 re-enabled disassembler output to C1Visualizer after code installation
Doug Simon <doug.simon@oracle.com>
parents: 5546
diff changeset
169 } catch (Throwable e) {
2e2a77f091f2 re-enabled disassembler output to C1Visualizer after code installation
Doug Simon <doug.simon@oracle.com>
parents: 5546
diff changeset
170 Assert.assertEquals(exception.getClass(), e.getClass());
2e2a77f091f2 re-enabled disassembler output to C1Visualizer after code installation
Doug Simon <doug.simon@oracle.com>
parents: 5546
diff changeset
171 }
2e2a77f091f2 re-enabled disassembler output to C1Visualizer after code installation
Doug Simon <doug.simon@oracle.com>
parents: 5546
diff changeset
172 } else {
2e2a77f091f2 re-enabled disassembler output to C1Visualizer after code installation
Doug Simon <doug.simon@oracle.com>
parents: 5546
diff changeset
173 Object actual = compiledMethod.executeVarargs(args);
2e2a77f091f2 re-enabled disassembler output to C1Visualizer after code installation
Doug Simon <doug.simon@oracle.com>
parents: 5546
diff changeset
174 Assert.assertEquals(expect, actual);
2e2a77f091f2 re-enabled disassembler output to C1Visualizer after code installation
Doug Simon <doug.simon@oracle.com>
parents: 5546
diff changeset
175 }
2e2a77f091f2 re-enabled disassembler output to C1Visualizer after code installation
Doug Simon <doug.simon@oracle.com>
parents: 5546
diff changeset
176 }
2e2a77f091f2 re-enabled disassembler output to C1Visualizer after code installation
Doug Simon <doug.simon@oracle.com>
parents: 5546
diff changeset
177
5541
b4c406861c33 More renamings to drop Ri* prefix completely. Deleted graph.BitMap class and replaced with java.util.BitSet.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5538
diff changeset
178 protected InstalledCode compile(final ResolvedJavaMethod method, final StructuredGraph graph) {
5538
e18ba36bfebc Renamed RiConstant => Constant.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5537
diff changeset
179 return Debug.scope("Compiling", new DebugDumpScope(String.valueOf(compilationId++), true), new Callable<InstalledCode>() {
e18ba36bfebc Renamed RiConstant => Constant.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5537
diff changeset
180 public InstalledCode call() throws Exception {
5546
e42c0df7212a Rename CiTargetMethod => CompilationResult.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5541
diff changeset
181 CompilationResult targetMethod = runtime.compile(method, graph);
5433
d7b5cc23945e refactored tests to share support for dump-aware compilation
Doug Simon <doug.simon@oracle.com>
parents: 5425
diff changeset
182 return addMethod(method, targetMethod);
d7b5cc23945e refactored tests to share support for dump-aware compilation
Doug Simon <doug.simon@oracle.com>
parents: 5425
diff changeset
183 }
d7b5cc23945e refactored tests to share support for dump-aware compilation
Doug Simon <doug.simon@oracle.com>
parents: 5425
diff changeset
184 });
d7b5cc23945e refactored tests to share support for dump-aware compilation
Doug Simon <doug.simon@oracle.com>
parents: 5425
diff changeset
185 }
d7b5cc23945e refactored tests to share support for dump-aware compilation
Doug Simon <doug.simon@oracle.com>
parents: 5425
diff changeset
186
5546
e42c0df7212a Rename CiTargetMethod => CompilationResult.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5541
diff changeset
187 protected InstalledCode addMethod(final ResolvedJavaMethod method, final CompilationResult tm) {
5557
2e2a77f091f2 re-enabled disassembler output to C1Visualizer after code installation
Doug Simon <doug.simon@oracle.com>
parents: 5546
diff changeset
188 GraalCompiler graalCompiler = Graal.getRuntime().getCapability(GraalCompiler.class);
2e2a77f091f2 re-enabled disassembler output to C1Visualizer after code installation
Doug Simon <doug.simon@oracle.com>
parents: 5546
diff changeset
189 assert graalCompiler != null;
2e2a77f091f2 re-enabled disassembler output to C1Visualizer after code installation
Doug Simon <doug.simon@oracle.com>
parents: 5546
diff changeset
190 return Debug.scope("CodeInstall", new Object[] {graalCompiler, method}, new Callable<InstalledCode>() {
5360
6cc970203f30 moved creation of a RiCodeInfo to the runtime side of the CRI
Doug Simon <doug.simon@oracle.com>
parents: 5122
diff changeset
191 @Override
5538
e18ba36bfebc Renamed RiConstant => Constant.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5537
diff changeset
192 public InstalledCode call() throws Exception {
5537
80371cc2256d Renaming RiCompiledMethod => InstalledCode.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5533
diff changeset
193 final CodeInfo[] info = Debug.isDumpEnabled() ? new CodeInfo[1] : null;
5538
e18ba36bfebc Renamed RiConstant => Constant.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5537
diff changeset
194 InstalledCode installedMethod = runtime.addMethod(method, tm, info);
5360
6cc970203f30 moved creation of a RiCodeInfo to the runtime side of the CRI
Doug Simon <doug.simon@oracle.com>
parents: 5122
diff changeset
195 if (info != null) {
5557
2e2a77f091f2 re-enabled disassembler output to C1Visualizer after code installation
Doug Simon <doug.simon@oracle.com>
parents: 5546
diff changeset
196 Debug.dump(new Object[] {tm, info[0]}, "After code installation");
5360
6cc970203f30 moved creation of a RiCodeInfo to the runtime side of the CRI
Doug Simon <doug.simon@oracle.com>
parents: 5122
diff changeset
197 }
6cc970203f30 moved creation of a RiCodeInfo to the runtime side of the CRI
Doug Simon <doug.simon@oracle.com>
parents: 5122
diff changeset
198 return installedMethod;
6cc970203f30 moved creation of a RiCodeInfo to the runtime side of the CRI
Doug Simon <doug.simon@oracle.com>
parents: 5122
diff changeset
199 }
6cc970203f30 moved creation of a RiCodeInfo to the runtime side of the CRI
Doug Simon <doug.simon@oracle.com>
parents: 5122
diff changeset
200 });
6cc970203f30 moved creation of a RiCodeInfo to the runtime side of the CRI
Doug Simon <doug.simon@oracle.com>
parents: 5122
diff changeset
201 }
6cc970203f30 moved creation of a RiCodeInfo to the runtime side of the CRI
Doug Simon <doug.simon@oracle.com>
parents: 5122
diff changeset
202
4340
5caca26cb1b9 small fix (missing changes)
Lukas Stadler <lukas.stadler@jku.at>
parents: 4315
diff changeset
203 /**
5caca26cb1b9 small fix (missing changes)
Lukas Stadler <lukas.stadler@jku.at>
parents: 4315
diff changeset
204 * Parses a Java method to produce a graph.
5caca26cb1b9 small fix (missing changes)
Lukas Stadler <lukas.stadler@jku.at>
parents: 4315
diff changeset
205 *
5caca26cb1b9 small fix (missing changes)
Lukas Stadler <lukas.stadler@jku.at>
parents: 4315
diff changeset
206 * @param methodName the name of the method in {@code this.getClass()} to be parsed
5caca26cb1b9 small fix (missing changes)
Lukas Stadler <lukas.stadler@jku.at>
parents: 4315
diff changeset
207 */
5caca26cb1b9 small fix (missing changes)
Lukas Stadler <lukas.stadler@jku.at>
parents: 4315
diff changeset
208 protected StructuredGraph parseProfiled(String methodName) {
4993
897b7d18bebc added RiCompiledMethod.execute and the required VM infrastructure
Lukas Stadler <lukas.stadler@jku.at>
parents: 4410
diff changeset
209 return parseProfiled(getMethod(methodName));
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
210 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
211
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
212 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
213 * Parses a Java method to produce a graph.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
214 */
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
215 protected StructuredGraph parse(Method m) {
5541
b4c406861c33 More renamings to drop Ri* prefix completely. Deleted graph.BitMap class and replaced with java.util.BitSet.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5538
diff changeset
216 ResolvedJavaMethod riMethod = runtime.getResolvedJavaMethod(m);
4203
847e9dcb4980 Add graph builder to the phase plan.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4200
diff changeset
217 StructuredGraph graph = new StructuredGraph(riMethod);
5122
9b940aff6c6b fixed failing testcases
Christian Haeubl <christian.haeubl@oracle.com>
parents: 5118
diff changeset
218 new GraphBuilderPhase(runtime, GraphBuilderConfiguration.getSnippetDefault(), OptimisticOptimizations.ALL).apply(graph);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
219 return graph;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
220 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
221
4340
5caca26cb1b9 small fix (missing changes)
Lukas Stadler <lukas.stadler@jku.at>
parents: 4315
diff changeset
222 /**
5caca26cb1b9 small fix (missing changes)
Lukas Stadler <lukas.stadler@jku.at>
parents: 4315
diff changeset
223 * Parses a Java method to produce a graph.
5caca26cb1b9 small fix (missing changes)
Lukas Stadler <lukas.stadler@jku.at>
parents: 4315
diff changeset
224 */
5caca26cb1b9 small fix (missing changes)
Lukas Stadler <lukas.stadler@jku.at>
parents: 4315
diff changeset
225 protected StructuredGraph parseProfiled(Method m) {
5541
b4c406861c33 More renamings to drop Ri* prefix completely. Deleted graph.BitMap class and replaced with java.util.BitSet.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5538
diff changeset
226 ResolvedJavaMethod riMethod = runtime.getResolvedJavaMethod(m);
4340
5caca26cb1b9 small fix (missing changes)
Lukas Stadler <lukas.stadler@jku.at>
parents: 4315
diff changeset
227 StructuredGraph graph = new StructuredGraph(riMethod);
5114
dad1ac9dba7d finished first implementation of disabling runtime feedback selectively based on deoptimization history
Christian Haeubl <christian.haeubl@oracle.com>
parents: 5109
diff changeset
228 new GraphBuilderPhase(runtime, GraphBuilderConfiguration.getDefault(), OptimisticOptimizations.ALL).apply(graph);
4340
5caca26cb1b9 small fix (missing changes)
Lukas Stadler <lukas.stadler@jku.at>
parents: 4315
diff changeset
229 return graph;
5caca26cb1b9 small fix (missing changes)
Lukas Stadler <lukas.stadler@jku.at>
parents: 4315
diff changeset
230 }
5caca26cb1b9 small fix (missing changes)
Lukas Stadler <lukas.stadler@jku.at>
parents: 4315
diff changeset
231
4204
4df4499e0289 Fixed unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4203
diff changeset
232 protected PhasePlan getDefaultPhasePlan() {
4df4499e0289 Fixed unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4203
diff changeset
233 PhasePlan plan = new PhasePlan();
5122
9b940aff6c6b fixed failing testcases
Christian Haeubl <christian.haeubl@oracle.com>
parents: 5118
diff changeset
234 plan.addPhase(PhasePosition.AFTER_PARSING, new GraphBuilderPhase(runtime, GraphBuilderConfiguration.getSnippetDefault(), OptimisticOptimizations.ALL));
4204
4df4499e0289 Fixed unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4203
diff changeset
235 return plan;
4df4499e0289 Fixed unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4203
diff changeset
236 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
237 }