Mercurial > hg > truffle
annotate graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/GraalCompilerTest.java @ 6578:1112609bb5dc
updated javadoc
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Thu, 25 Oct 2012 12:29:56 +0200 |
parents | ec196bfc458b |
children | 090868cbcda6 |
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 */ |
6334
f8ba3bb81f6f
Renamed com.oracle.graal.tests project to com.oracle.graal.compiler.test
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
6329
diff
changeset
|
23 package com.oracle.graal.compiler.test; |
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.*; |
5650
8d420cfd2a6f
added unit tests for the Word type
Doug Simon <doug.simon@oracle.com>
parents:
5599
diff
changeset
|
26 import java.util.*; |
5360
6cc970203f30
moved creation of a RiCodeInfo to the runtime side of the CRI
Doug Simon <doug.simon@oracle.com>
parents:
5122
diff
changeset
|
27 import java.util.concurrent.*; |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
28 |
5114
dad1ac9dba7d
finished first implementation of disabling runtime feedback selectively based on deoptimization history
Christian Haeubl <christian.haeubl@oracle.com>
parents:
5109
diff
changeset
|
29 import junit.framework.*; |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
30 |
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.*; |
6540
31aa76ffd3bb
Rename project graal.api to graal.api.runtime
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6539
diff
changeset
|
33 import com.oracle.graal.api.runtime.*; |
5114
dad1ac9dba7d
finished first implementation of disabling runtime feedback selectively based on deoptimization history
Christian Haeubl <christian.haeubl@oracle.com>
parents:
5109
diff
changeset
|
34 import com.oracle.graal.compiler.*; |
5060
4ed4295ce15f
Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5059
diff
changeset
|
35 import com.oracle.graal.debug.*; |
5425
0364a2a874b8
changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
5360
diff
changeset
|
36 import com.oracle.graal.graph.*; |
0364a2a874b8
changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
5360
diff
changeset
|
37 import com.oracle.graal.graph.Node.Verbosity; |
5060
4ed4295ce15f
Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5059
diff
changeset
|
38 import com.oracle.graal.java.*; |
4ed4295ce15f
Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5059
diff
changeset
|
39 import com.oracle.graal.nodes.*; |
6529
2e96dc4eb8e2
renamed package: com.oracle.graal.lir.cfg -> com.oracle.graal.nodes.cfg
Doug Simon <doug.simon@oracle.com>
parents:
6526
diff
changeset
|
40 import com.oracle.graal.nodes.cfg.*; |
5720
46ad94a0574a
moved everything from com.oracle.graal.nodes.cri into com.oracle.graal.nodes.spi
Doug Simon <doug.simon@oracle.com>
parents:
5719
diff
changeset
|
41 import com.oracle.graal.nodes.spi.*; |
6525
2c913b643422
rename packages in graal.phases to match project name
Doug Simon <doug.simon@oracle.com>
parents:
6447
diff
changeset
|
42 import com.oracle.graal.phases.*; |
6543
ec196bfc458b
Minor fixes after cleanup
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6540
diff
changeset
|
43 import com.oracle.graal.phases.PhasePlan.PhasePosition; |
6525
2c913b643422
rename packages in graal.phases to match project name
Doug Simon <doug.simon@oracle.com>
parents:
6447
diff
changeset
|
44 import com.oracle.graal.phases.schedule.*; |
3733
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 /** |
6578 | 47 * Base class for Graal compiler unit tests. |
48 * <p> | |
49 * White box tests for Graal compiler transformations use this pattern: | |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
50 * <ol> |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
51 * <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
|
52 * <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
|
53 * <li>Apply a transformation to the graph.</li> |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
54 * <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
|
55 * </ol> |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
56 * <p> |
6578 | 57 * See {@link InvokeHintsTest} as an example of a white box test. |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
58 * <p> |
6578 | 59 * Black box tests use the {@link #test(String, Object...)} or {@link #testN(int, String, Object...)} |
60 * to execute some method in the interpreter and compare its result against that produced | |
61 * by a Graal compiled version of the method. | |
62 * <p> | |
63 * These tests will be run by the {@code mx unittest} command. | |
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 abstract class GraalCompilerTest { |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
66 |
5718
10341299528c
renamings: ExtendedRiRuntime -> GraalCodeCacheProvider, CiLoweringTool -> LoweringTool, RiGraphCache -> GraphCache
Doug Simon <doug.simon@oracle.com>
parents:
5657
diff
changeset
|
67 protected final GraalCodeCacheProvider runtime; |
5780
64257cbef60c
removed compile method from GraalCodeCacheProvider interface
Doug Simon <doug.simon@oracle.com>
parents:
5720
diff
changeset
|
68 protected final GraalCompiler graalCompiler; |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
69 |
5565
0083a59ced84
Renaming GraphTest => GraalCompilerTest.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5546
diff
changeset
|
70 public GraalCompilerTest() { |
5085
5bdaa08ba96b
add and enable new PropagateTypeCachePhase, add type system tests
Lukas Stadler <lukas.stadler@jku.at>
parents:
5061
diff
changeset
|
71 Debug.enable(); |
6334
f8ba3bb81f6f
Renamed com.oracle.graal.tests project to com.oracle.graal.compiler.test
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
6329
diff
changeset
|
72 this.runtime = Graal.getRequiredCapability(GraalCodeCacheProvider.class); |
f8ba3bb81f6f
Renamed com.oracle.graal.tests project to com.oracle.graal.compiler.test
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
6329
diff
changeset
|
73 this.graalCompiler = Graal.getRequiredCapability(GraalCompiler.class); |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
74 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
75 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
76 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
|
77 String expectedString = getCanonicalGraphString(expected); |
0364a2a874b8
changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
5360
diff
changeset
|
78 String actualString = getCanonicalGraphString(graph); |
0364a2a874b8
changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
5360
diff
changeset
|
79 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
|
80 |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
81 if (expected.getNodeCount() != graph.getNodeCount()) { |
4363
7462c3600c3a
Draft changes to the graph plotting.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
4265
diff
changeset
|
82 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
|
83 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
|
84 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
|
85 } |
0364a2a874b8
changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
5360
diff
changeset
|
86 if (!expectedString.equals(actualString)) { |
0364a2a874b8
changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
5360
diff
changeset
|
87 Debug.dump(expected, "mismatching graphs - expected"); |
0364a2a874b8
changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
5360
diff
changeset
|
88 Debug.dump(graph, "mismatching graphs - actual"); |
0364a2a874b8
changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
5360
diff
changeset
|
89 Assert.fail(mismatchString); |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
90 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
91 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
92 |
5657
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
5650
diff
changeset
|
93 protected void assertConstantReturn(StructuredGraph graph, int value) { |
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
5650
diff
changeset
|
94 String graphString = getCanonicalGraphString(graph); |
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
5650
diff
changeset
|
95 Assert.assertEquals("unexpected number of ReturnNodes: " + graphString, graph.getNodes(ReturnNode.class).count(), 1); |
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
5650
diff
changeset
|
96 ValueNode result = graph.getNodes(ReturnNode.class).first().result(); |
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
5650
diff
changeset
|
97 Assert.assertTrue("unexpected ReturnNode result node: " + graphString, result.isConstant()); |
6329
92bc58dc5b5e
More clean up and documentation in api.code and api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5780
diff
changeset
|
98 Assert.assertEquals("unexpected ReturnNode result kind: " + graphString, result.asConstant().getKind(), Kind.Int); |
5657
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
5650
diff
changeset
|
99 Assert.assertEquals("unexpected ReturnNode result: " + graphString, result.asConstant().asInt(), value); |
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
5650
diff
changeset
|
100 } |
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
5650
diff
changeset
|
101 |
d71eb56d6bb0
new stamp inference in CanonicalizerPhase, IntegerStamp.mask
Lukas Stadler <lukas.stadler@jku.at>
parents:
5650
diff
changeset
|
102 protected static String getCanonicalGraphString(StructuredGraph graph) { |
5425
0364a2a874b8
changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
5360
diff
changeset
|
103 SchedulePhase schedule = new SchedulePhase(); |
0364a2a874b8
changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
5360
diff
changeset
|
104 schedule.apply(graph); |
0364a2a874b8
changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
5360
diff
changeset
|
105 |
0364a2a874b8
changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
5360
diff
changeset
|
106 NodeMap<Integer> canonicalId = graph.createNodeMap(); |
0364a2a874b8
changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
5360
diff
changeset
|
107 int nextId = 0; |
0364a2a874b8
changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
5360
diff
changeset
|
108 |
0364a2a874b8
changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
5360
diff
changeset
|
109 StringBuilder result = new StringBuilder(); |
0364a2a874b8
changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
5360
diff
changeset
|
110 for (Block block : schedule.getCFG().getBlocks()) { |
0364a2a874b8
changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
5360
diff
changeset
|
111 result.append("Block " + block + " "); |
0364a2a874b8
changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
5360
diff
changeset
|
112 if (block == schedule.getCFG().getStartBlock()) { |
0364a2a874b8
changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
5360
diff
changeset
|
113 result.append("* "); |
0364a2a874b8
changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
5360
diff
changeset
|
114 } |
0364a2a874b8
changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
5360
diff
changeset
|
115 result.append("-> "); |
0364a2a874b8
changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
5360
diff
changeset
|
116 for (Block succ : block.getSuccessors()) { |
0364a2a874b8
changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
5360
diff
changeset
|
117 result.append(succ + " "); |
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 result.append("\n"); |
0364a2a874b8
changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
5360
diff
changeset
|
120 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
|
121 int id; |
0364a2a874b8
changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
5360
diff
changeset
|
122 if (canonicalId.get(node) != null) { |
0364a2a874b8
changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
5360
diff
changeset
|
123 id = canonicalId.get(node); |
0364a2a874b8
changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
5360
diff
changeset
|
124 } else { |
0364a2a874b8
changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
5360
diff
changeset
|
125 id = nextId++; |
0364a2a874b8
changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
5360
diff
changeset
|
126 canonicalId.set(node, id); |
0364a2a874b8
changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
5360
diff
changeset
|
127 } |
0364a2a874b8
changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
5360
diff
changeset
|
128 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
|
129 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
|
130 } |
0364a2a874b8
changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
5360
diff
changeset
|
131 } |
0364a2a874b8
changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
5360
diff
changeset
|
132 return result.toString(); |
0364a2a874b8
changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
5360
diff
changeset
|
133 } |
0364a2a874b8
changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents:
5360
diff
changeset
|
134 |
5718
10341299528c
renamings: ExtendedRiRuntime -> GraalCodeCacheProvider, CiLoweringTool -> LoweringTool, RiGraphCache -> GraphCache
Doug Simon <doug.simon@oracle.com>
parents:
5657
diff
changeset
|
135 protected GraalCodeCacheProvider runtime() { |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
136 return runtime; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
137 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
138 |
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 * Parses a Java method to produce a graph. |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
141 * |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
142 * @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
|
143 */ |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
144 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
|
145 return parse(getMethod(methodName)); |
897b7d18bebc
added RiCompiledMethod.execute and the required VM infrastructure
Lukas Stadler <lukas.stadler@jku.at>
parents:
4410
diff
changeset
|
146 } |
897b7d18bebc
added RiCompiledMethod.execute and the required VM infrastructure
Lukas Stadler <lukas.stadler@jku.at>
parents:
4410
diff
changeset
|
147 |
897b7d18bebc
added RiCompiledMethod.execute and the required VM infrastructure
Lukas Stadler <lukas.stadler@jku.at>
parents:
4410
diff
changeset
|
148 protected Method getMethod(String methodName) { |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
149 Method found = null; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
150 for (Method m : this.getClass().getMethods()) { |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
151 if (m.getName().equals(methodName)) { |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
152 Assert.assertNull(found); |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
153 found = m; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
154 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
155 } |
4340
5caca26cb1b9
small fix (missing changes)
Lukas Stadler <lukas.stadler@jku.at>
parents:
4315
diff
changeset
|
156 if (found != null) { |
4993
897b7d18bebc
added RiCompiledMethod.execute and the required VM infrastructure
Lukas Stadler <lukas.stadler@jku.at>
parents:
4410
diff
changeset
|
157 return found; |
4340
5caca26cb1b9
small fix (missing changes)
Lukas Stadler <lukas.stadler@jku.at>
parents:
4315
diff
changeset
|
158 } else { |
5caca26cb1b9
small fix (missing changes)
Lukas Stadler <lukas.stadler@jku.at>
parents:
4315
diff
changeset
|
159 throw new RuntimeException("method not found: " + methodName); |
5caca26cb1b9
small fix (missing changes)
Lukas Stadler <lukas.stadler@jku.at>
parents:
4315
diff
changeset
|
160 } |
5caca26cb1b9
small fix (missing changes)
Lukas Stadler <lukas.stadler@jku.at>
parents:
4315
diff
changeset
|
161 } |
5caca26cb1b9
small fix (missing changes)
Lukas Stadler <lukas.stadler@jku.at>
parents:
4315
diff
changeset
|
162 |
5433
d7b5cc23945e
refactored tests to share support for dump-aware compilation
Doug Simon <doug.simon@oracle.com>
parents:
5425
diff
changeset
|
163 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
|
164 |
5599
592dfff9d410
modified GraalCompilerTest so that subclasses can override the assertEquals test
Doug Simon <doug.simon@oracle.com>
parents:
5571
diff
changeset
|
165 protected void assertEquals(Object expected, Object actual) { |
592dfff9d410
modified GraalCompilerTest so that subclasses can override the assertEquals test
Doug Simon <doug.simon@oracle.com>
parents:
5571
diff
changeset
|
166 Assert.assertEquals(expected, actual); |
592dfff9d410
modified GraalCompilerTest so that subclasses can override the assertEquals test
Doug Simon <doug.simon@oracle.com>
parents:
5571
diff
changeset
|
167 } |
592dfff9d410
modified GraalCompilerTest so that subclasses can override the assertEquals test
Doug Simon <doug.simon@oracle.com>
parents:
5571
diff
changeset
|
168 |
6370
703a6ab8ca82
added support for multi-threaded compiler tests
Doug Simon <doug.simon@oracle.com>
parents:
6334
diff
changeset
|
169 protected void testN(int n, final String name, final Object... args) { |
703a6ab8ca82
added support for multi-threaded compiler tests
Doug Simon <doug.simon@oracle.com>
parents:
6334
diff
changeset
|
170 final Throwable[] errors = new Throwable[n]; |
703a6ab8ca82
added support for multi-threaded compiler tests
Doug Simon <doug.simon@oracle.com>
parents:
6334
diff
changeset
|
171 Thread[] threads = new Thread[n]; |
703a6ab8ca82
added support for multi-threaded compiler tests
Doug Simon <doug.simon@oracle.com>
parents:
6334
diff
changeset
|
172 for (int i = 0; i < n; i++) { |
703a6ab8ca82
added support for multi-threaded compiler tests
Doug Simon <doug.simon@oracle.com>
parents:
6334
diff
changeset
|
173 final int idx = i; |
703a6ab8ca82
added support for multi-threaded compiler tests
Doug Simon <doug.simon@oracle.com>
parents:
6334
diff
changeset
|
174 Thread t = new Thread(i + ":" + name) { |
703a6ab8ca82
added support for multi-threaded compiler tests
Doug Simon <doug.simon@oracle.com>
parents:
6334
diff
changeset
|
175 @Override |
703a6ab8ca82
added support for multi-threaded compiler tests
Doug Simon <doug.simon@oracle.com>
parents:
6334
diff
changeset
|
176 public void run() { |
703a6ab8ca82
added support for multi-threaded compiler tests
Doug Simon <doug.simon@oracle.com>
parents:
6334
diff
changeset
|
177 try { |
703a6ab8ca82
added support for multi-threaded compiler tests
Doug Simon <doug.simon@oracle.com>
parents:
6334
diff
changeset
|
178 test(name, args); |
703a6ab8ca82
added support for multi-threaded compiler tests
Doug Simon <doug.simon@oracle.com>
parents:
6334
diff
changeset
|
179 } catch (Throwable e) { |
703a6ab8ca82
added support for multi-threaded compiler tests
Doug Simon <doug.simon@oracle.com>
parents:
6334
diff
changeset
|
180 errors[idx] = e; |
703a6ab8ca82
added support for multi-threaded compiler tests
Doug Simon <doug.simon@oracle.com>
parents:
6334
diff
changeset
|
181 } |
703a6ab8ca82
added support for multi-threaded compiler tests
Doug Simon <doug.simon@oracle.com>
parents:
6334
diff
changeset
|
182 } |
703a6ab8ca82
added support for multi-threaded compiler tests
Doug Simon <doug.simon@oracle.com>
parents:
6334
diff
changeset
|
183 }; |
703a6ab8ca82
added support for multi-threaded compiler tests
Doug Simon <doug.simon@oracle.com>
parents:
6334
diff
changeset
|
184 threads[i] = t; |
703a6ab8ca82
added support for multi-threaded compiler tests
Doug Simon <doug.simon@oracle.com>
parents:
6334
diff
changeset
|
185 t.start(); |
703a6ab8ca82
added support for multi-threaded compiler tests
Doug Simon <doug.simon@oracle.com>
parents:
6334
diff
changeset
|
186 } |
703a6ab8ca82
added support for multi-threaded compiler tests
Doug Simon <doug.simon@oracle.com>
parents:
6334
diff
changeset
|
187 int failed = 0; |
703a6ab8ca82
added support for multi-threaded compiler tests
Doug Simon <doug.simon@oracle.com>
parents:
6334
diff
changeset
|
188 for (int i = 0; i < n; i++) { |
703a6ab8ca82
added support for multi-threaded compiler tests
Doug Simon <doug.simon@oracle.com>
parents:
6334
diff
changeset
|
189 try { |
703a6ab8ca82
added support for multi-threaded compiler tests
Doug Simon <doug.simon@oracle.com>
parents:
6334
diff
changeset
|
190 threads[i].join(); |
703a6ab8ca82
added support for multi-threaded compiler tests
Doug Simon <doug.simon@oracle.com>
parents:
6334
diff
changeset
|
191 } catch (InterruptedException e) { |
703a6ab8ca82
added support for multi-threaded compiler tests
Doug Simon <doug.simon@oracle.com>
parents:
6334
diff
changeset
|
192 errors[i] = e; |
703a6ab8ca82
added support for multi-threaded compiler tests
Doug Simon <doug.simon@oracle.com>
parents:
6334
diff
changeset
|
193 } |
703a6ab8ca82
added support for multi-threaded compiler tests
Doug Simon <doug.simon@oracle.com>
parents:
6334
diff
changeset
|
194 if (errors[i] != null) { |
703a6ab8ca82
added support for multi-threaded compiler tests
Doug Simon <doug.simon@oracle.com>
parents:
6334
diff
changeset
|
195 errors[i].printStackTrace(); |
703a6ab8ca82
added support for multi-threaded compiler tests
Doug Simon <doug.simon@oracle.com>
parents:
6334
diff
changeset
|
196 failed++; |
703a6ab8ca82
added support for multi-threaded compiler tests
Doug Simon <doug.simon@oracle.com>
parents:
6334
diff
changeset
|
197 } |
703a6ab8ca82
added support for multi-threaded compiler tests
Doug Simon <doug.simon@oracle.com>
parents:
6334
diff
changeset
|
198 } |
703a6ab8ca82
added support for multi-threaded compiler tests
Doug Simon <doug.simon@oracle.com>
parents:
6334
diff
changeset
|
199 Assert.assertTrue(failed + " of " + n + " failed", failed == 0); |
703a6ab8ca82
added support for multi-threaded compiler tests
Doug Simon <doug.simon@oracle.com>
parents:
6334
diff
changeset
|
200 } |
703a6ab8ca82
added support for multi-threaded compiler tests
Doug Simon <doug.simon@oracle.com>
parents:
6334
diff
changeset
|
201 |
6431
2e376f8ea4e2
added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents:
6370
diff
changeset
|
202 protected Object referenceInvoke(Method method, Object receiver, Object... args) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException { |
2e376f8ea4e2
added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents:
6370
diff
changeset
|
203 return method.invoke(receiver, args); |
2e376f8ea4e2
added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents:
6370
diff
changeset
|
204 } |
2e376f8ea4e2
added snippet for lowering NewMultiArrayNodes
Doug Simon <doug.simon@oracle.com>
parents:
6370
diff
changeset
|
205 |
6447
d7bcbdf4749c
minor restructuring of GraalCompilerTest
Doug Simon <doug.simon@oracle.com>
parents:
6431
diff
changeset
|
206 static class Result { |
d7bcbdf4749c
minor restructuring of GraalCompilerTest
Doug Simon <doug.simon@oracle.com>
parents:
6431
diff
changeset
|
207 final Object returnValue; |
d7bcbdf4749c
minor restructuring of GraalCompilerTest
Doug Simon <doug.simon@oracle.com>
parents:
6431
diff
changeset
|
208 final Throwable exception; |
d7bcbdf4749c
minor restructuring of GraalCompilerTest
Doug Simon <doug.simon@oracle.com>
parents:
6431
diff
changeset
|
209 public Result(Object returnValue, Throwable exception) { |
d7bcbdf4749c
minor restructuring of GraalCompilerTest
Doug Simon <doug.simon@oracle.com>
parents:
6431
diff
changeset
|
210 this.returnValue = returnValue; |
d7bcbdf4749c
minor restructuring of GraalCompilerTest
Doug Simon <doug.simon@oracle.com>
parents:
6431
diff
changeset
|
211 this.exception = exception; |
d7bcbdf4749c
minor restructuring of GraalCompilerTest
Doug Simon <doug.simon@oracle.com>
parents:
6431
diff
changeset
|
212 } |
d7bcbdf4749c
minor restructuring of GraalCompilerTest
Doug Simon <doug.simon@oracle.com>
parents:
6431
diff
changeset
|
213 } |
d7bcbdf4749c
minor restructuring of GraalCompilerTest
Doug Simon <doug.simon@oracle.com>
parents:
6431
diff
changeset
|
214 |
d7bcbdf4749c
minor restructuring of GraalCompilerTest
Doug Simon <doug.simon@oracle.com>
parents:
6431
diff
changeset
|
215 protected Result executeExpected(Method method, Object receiver, Object... args) { |
5557
2e2a77f091f2
re-enabled disassembler output to C1Visualizer after code installation
Doug Simon <doug.simon@oracle.com>
parents:
5546
diff
changeset
|
216 try { |
2e2a77f091f2
re-enabled disassembler output to C1Visualizer after code installation
Doug Simon <doug.simon@oracle.com>
parents:
5546
diff
changeset
|
217 // This gives us both the expected return value as well as ensuring that the method to be compiled is fully resolved |
6447
d7bcbdf4749c
minor restructuring of GraalCompilerTest
Doug Simon <doug.simon@oracle.com>
parents:
6431
diff
changeset
|
218 return new Result(referenceInvoke(method, receiver, args), null); |
5557
2e2a77f091f2
re-enabled disassembler output to C1Visualizer after code installation
Doug Simon <doug.simon@oracle.com>
parents:
5546
diff
changeset
|
219 } catch (InvocationTargetException e) { |
6447
d7bcbdf4749c
minor restructuring of GraalCompilerTest
Doug Simon <doug.simon@oracle.com>
parents:
6431
diff
changeset
|
220 return new Result(null, e.getTargetException()); |
5557
2e2a77f091f2
re-enabled disassembler output to C1Visualizer after code installation
Doug Simon <doug.simon@oracle.com>
parents:
5546
diff
changeset
|
221 } catch (Exception e) { |
2e2a77f091f2
re-enabled disassembler output to C1Visualizer after code installation
Doug Simon <doug.simon@oracle.com>
parents:
5546
diff
changeset
|
222 throw new RuntimeException(e); |
2e2a77f091f2
re-enabled disassembler output to C1Visualizer after code installation
Doug Simon <doug.simon@oracle.com>
parents:
5546
diff
changeset
|
223 } |
6447
d7bcbdf4749c
minor restructuring of GraalCompilerTest
Doug Simon <doug.simon@oracle.com>
parents:
6431
diff
changeset
|
224 } |
6370
703a6ab8ca82
added support for multi-threaded compiler tests
Doug Simon <doug.simon@oracle.com>
parents:
6334
diff
changeset
|
225 |
6447
d7bcbdf4749c
minor restructuring of GraalCompilerTest
Doug Simon <doug.simon@oracle.com>
parents:
6431
diff
changeset
|
226 protected Result executeActual(Method method, Object receiver, Object... args) { |
6370
703a6ab8ca82
added support for multi-threaded compiler tests
Doug Simon <doug.simon@oracle.com>
parents:
6334
diff
changeset
|
227 Object[] executeArgs; |
703a6ab8ca82
added support for multi-threaded compiler tests
Doug Simon <doug.simon@oracle.com>
parents:
6334
diff
changeset
|
228 if (receiver == null) { |
703a6ab8ca82
added support for multi-threaded compiler tests
Doug Simon <doug.simon@oracle.com>
parents:
6334
diff
changeset
|
229 executeArgs = args; |
703a6ab8ca82
added support for multi-threaded compiler tests
Doug Simon <doug.simon@oracle.com>
parents:
6334
diff
changeset
|
230 } else { |
703a6ab8ca82
added support for multi-threaded compiler tests
Doug Simon <doug.simon@oracle.com>
parents:
6334
diff
changeset
|
231 executeArgs = new Object[args.length + 1]; |
703a6ab8ca82
added support for multi-threaded compiler tests
Doug Simon <doug.simon@oracle.com>
parents:
6334
diff
changeset
|
232 executeArgs[0] = receiver; |
703a6ab8ca82
added support for multi-threaded compiler tests
Doug Simon <doug.simon@oracle.com>
parents:
6334
diff
changeset
|
233 for (int i = 0; i < args.length; i++) { |
703a6ab8ca82
added support for multi-threaded compiler tests
Doug Simon <doug.simon@oracle.com>
parents:
6334
diff
changeset
|
234 executeArgs[i + 1] = args[i]; |
703a6ab8ca82
added support for multi-threaded compiler tests
Doug Simon <doug.simon@oracle.com>
parents:
6334
diff
changeset
|
235 } |
703a6ab8ca82
added support for multi-threaded compiler tests
Doug Simon <doug.simon@oracle.com>
parents:
6334
diff
changeset
|
236 } |
5557
2e2a77f091f2
re-enabled disassembler output to C1Visualizer after code installation
Doug Simon <doug.simon@oracle.com>
parents:
5546
diff
changeset
|
237 |
6539
2463eb24b644
Cleanup of Graal API: Rename methods so that it follows the getXxx naming convention and so that they are similar to the names of the java.lang.reflect classes. Remove unused methods.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6529
diff
changeset
|
238 InstalledCode compiledMethod = getCode(runtime.lookupJavaMethod(method), parse(method)); |
6447
d7bcbdf4749c
minor restructuring of GraalCompilerTest
Doug Simon <doug.simon@oracle.com>
parents:
6431
diff
changeset
|
239 try { |
d7bcbdf4749c
minor restructuring of GraalCompilerTest
Doug Simon <doug.simon@oracle.com>
parents:
6431
diff
changeset
|
240 return new Result(compiledMethod.executeVarargs(executeArgs), null); |
d7bcbdf4749c
minor restructuring of GraalCompilerTest
Doug Simon <doug.simon@oracle.com>
parents:
6431
diff
changeset
|
241 } catch (Throwable e) { |
d7bcbdf4749c
minor restructuring of GraalCompilerTest
Doug Simon <doug.simon@oracle.com>
parents:
6431
diff
changeset
|
242 return new Result(null, e); |
d7bcbdf4749c
minor restructuring of GraalCompilerTest
Doug Simon <doug.simon@oracle.com>
parents:
6431
diff
changeset
|
243 } |
d7bcbdf4749c
minor restructuring of GraalCompilerTest
Doug Simon <doug.simon@oracle.com>
parents:
6431
diff
changeset
|
244 } |
d7bcbdf4749c
minor restructuring of GraalCompilerTest
Doug Simon <doug.simon@oracle.com>
parents:
6431
diff
changeset
|
245 |
d7bcbdf4749c
minor restructuring of GraalCompilerTest
Doug Simon <doug.simon@oracle.com>
parents:
6431
diff
changeset
|
246 protected void test(String name, Object... args) { |
d7bcbdf4749c
minor restructuring of GraalCompilerTest
Doug Simon <doug.simon@oracle.com>
parents:
6431
diff
changeset
|
247 Method method = getMethod(name); |
d7bcbdf4749c
minor restructuring of GraalCompilerTest
Doug Simon <doug.simon@oracle.com>
parents:
6431
diff
changeset
|
248 Object receiver = Modifier.isStatic(method.getModifiers()) ? null : this; |
d7bcbdf4749c
minor restructuring of GraalCompilerTest
Doug Simon <doug.simon@oracle.com>
parents:
6431
diff
changeset
|
249 |
d7bcbdf4749c
minor restructuring of GraalCompilerTest
Doug Simon <doug.simon@oracle.com>
parents:
6431
diff
changeset
|
250 Result expect = executeExpected(method, receiver, args); |
d7bcbdf4749c
minor restructuring of GraalCompilerTest
Doug Simon <doug.simon@oracle.com>
parents:
6431
diff
changeset
|
251 if (runtime == null) { |
d7bcbdf4749c
minor restructuring of GraalCompilerTest
Doug Simon <doug.simon@oracle.com>
parents:
6431
diff
changeset
|
252 return; |
d7bcbdf4749c
minor restructuring of GraalCompilerTest
Doug Simon <doug.simon@oracle.com>
parents:
6431
diff
changeset
|
253 } |
d7bcbdf4749c
minor restructuring of GraalCompilerTest
Doug Simon <doug.simon@oracle.com>
parents:
6431
diff
changeset
|
254 Result actual = executeActual(method, receiver, args); |
d7bcbdf4749c
minor restructuring of GraalCompilerTest
Doug Simon <doug.simon@oracle.com>
parents:
6431
diff
changeset
|
255 |
d7bcbdf4749c
minor restructuring of GraalCompilerTest
Doug Simon <doug.simon@oracle.com>
parents:
6431
diff
changeset
|
256 if (expect.exception != null) { |
d7bcbdf4749c
minor restructuring of GraalCompilerTest
Doug Simon <doug.simon@oracle.com>
parents:
6431
diff
changeset
|
257 Assert.assertTrue("expected " + expect.exception, actual.exception != null); |
d7bcbdf4749c
minor restructuring of GraalCompilerTest
Doug Simon <doug.simon@oracle.com>
parents:
6431
diff
changeset
|
258 Assert.assertEquals(expect.exception.getClass(), actual.exception.getClass()); |
5557
2e2a77f091f2
re-enabled disassembler output to C1Visualizer after code installation
Doug Simon <doug.simon@oracle.com>
parents:
5546
diff
changeset
|
259 } else { |
6447
d7bcbdf4749c
minor restructuring of GraalCompilerTest
Doug Simon <doug.simon@oracle.com>
parents:
6431
diff
changeset
|
260 assertEquals(expect.returnValue, actual.returnValue); |
5557
2e2a77f091f2
re-enabled disassembler output to C1Visualizer after code installation
Doug Simon <doug.simon@oracle.com>
parents:
5546
diff
changeset
|
261 } |
2e2a77f091f2
re-enabled disassembler output to C1Visualizer after code installation
Doug Simon <doug.simon@oracle.com>
parents:
5546
diff
changeset
|
262 } |
2e2a77f091f2
re-enabled disassembler output to C1Visualizer after code installation
Doug Simon <doug.simon@oracle.com>
parents:
5546
diff
changeset
|
263 |
5650
8d420cfd2a6f
added unit tests for the Word type
Doug Simon <doug.simon@oracle.com>
parents:
5599
diff
changeset
|
264 private Map<ResolvedJavaMethod, InstalledCode> cache = new HashMap<>(); |
8d420cfd2a6f
added unit tests for the Word type
Doug Simon <doug.simon@oracle.com>
parents:
5599
diff
changeset
|
265 |
8d420cfd2a6f
added unit tests for the Word type
Doug Simon <doug.simon@oracle.com>
parents:
5599
diff
changeset
|
266 /** |
8d420cfd2a6f
added unit tests for the Word type
Doug Simon <doug.simon@oracle.com>
parents:
5599
diff
changeset
|
267 * Gets installed code for a given method and graph, compiling it first if necessary. |
8d420cfd2a6f
added unit tests for the Word type
Doug Simon <doug.simon@oracle.com>
parents:
5599
diff
changeset
|
268 */ |
8d420cfd2a6f
added unit tests for the Word type
Doug Simon <doug.simon@oracle.com>
parents:
5599
diff
changeset
|
269 protected InstalledCode getCode(final ResolvedJavaMethod method, final StructuredGraph graph) { |
8d420cfd2a6f
added unit tests for the Word type
Doug Simon <doug.simon@oracle.com>
parents:
5599
diff
changeset
|
270 return getCode(method, graph, false); |
8d420cfd2a6f
added unit tests for the Word type
Doug Simon <doug.simon@oracle.com>
parents:
5599
diff
changeset
|
271 } |
8d420cfd2a6f
added unit tests for the Word type
Doug Simon <doug.simon@oracle.com>
parents:
5599
diff
changeset
|
272 |
8d420cfd2a6f
added unit tests for the Word type
Doug Simon <doug.simon@oracle.com>
parents:
5599
diff
changeset
|
273 /** |
5780
64257cbef60c
removed compile method from GraalCodeCacheProvider interface
Doug Simon <doug.simon@oracle.com>
parents:
5720
diff
changeset
|
274 * Can be overridden to modify the compilation phases applied for a test. |
64257cbef60c
removed compile method from GraalCodeCacheProvider interface
Doug Simon <doug.simon@oracle.com>
parents:
5720
diff
changeset
|
275 * |
64257cbef60c
removed compile method from GraalCodeCacheProvider interface
Doug Simon <doug.simon@oracle.com>
parents:
5720
diff
changeset
|
276 * @param method the method being compiled |
64257cbef60c
removed compile method from GraalCodeCacheProvider interface
Doug Simon <doug.simon@oracle.com>
parents:
5720
diff
changeset
|
277 * @param graph the graph being compiled |
64257cbef60c
removed compile method from GraalCodeCacheProvider interface
Doug Simon <doug.simon@oracle.com>
parents:
5720
diff
changeset
|
278 * @param phasePlan the phase plan to be edited |
64257cbef60c
removed compile method from GraalCodeCacheProvider interface
Doug Simon <doug.simon@oracle.com>
parents:
5720
diff
changeset
|
279 */ |
64257cbef60c
removed compile method from GraalCodeCacheProvider interface
Doug Simon <doug.simon@oracle.com>
parents:
5720
diff
changeset
|
280 protected void editPhasePlan(ResolvedJavaMethod method, StructuredGraph graph, PhasePlan phasePlan) { |
64257cbef60c
removed compile method from GraalCodeCacheProvider interface
Doug Simon <doug.simon@oracle.com>
parents:
5720
diff
changeset
|
281 } |
64257cbef60c
removed compile method from GraalCodeCacheProvider interface
Doug Simon <doug.simon@oracle.com>
parents:
5720
diff
changeset
|
282 |
64257cbef60c
removed compile method from GraalCodeCacheProvider interface
Doug Simon <doug.simon@oracle.com>
parents:
5720
diff
changeset
|
283 /** |
5650
8d420cfd2a6f
added unit tests for the Word type
Doug Simon <doug.simon@oracle.com>
parents:
5599
diff
changeset
|
284 * Gets installed code for a given method and graph, compiling it first if necessary. |
8d420cfd2a6f
added unit tests for the Word type
Doug Simon <doug.simon@oracle.com>
parents:
5599
diff
changeset
|
285 * |
8d420cfd2a6f
added unit tests for the Word type
Doug Simon <doug.simon@oracle.com>
parents:
5599
diff
changeset
|
286 * @param forceCompile specifies whether to ignore any previous code cached for the (method, key) pair |
8d420cfd2a6f
added unit tests for the Word type
Doug Simon <doug.simon@oracle.com>
parents:
5599
diff
changeset
|
287 */ |
8d420cfd2a6f
added unit tests for the Word type
Doug Simon <doug.simon@oracle.com>
parents:
5599
diff
changeset
|
288 protected InstalledCode getCode(final ResolvedJavaMethod method, final StructuredGraph graph, boolean forceCompile) { |
8d420cfd2a6f
added unit tests for the Word type
Doug Simon <doug.simon@oracle.com>
parents:
5599
diff
changeset
|
289 if (!forceCompile) { |
8d420cfd2a6f
added unit tests for the Word type
Doug Simon <doug.simon@oracle.com>
parents:
5599
diff
changeset
|
290 InstalledCode cached = cache.get(method); |
8d420cfd2a6f
added unit tests for the Word type
Doug Simon <doug.simon@oracle.com>
parents:
5599
diff
changeset
|
291 if (cached != null && cached.isValid()) { |
8d420cfd2a6f
added unit tests for the Word type
Doug Simon <doug.simon@oracle.com>
parents:
5599
diff
changeset
|
292 return cached; |
8d420cfd2a6f
added unit tests for the Word type
Doug Simon <doug.simon@oracle.com>
parents:
5599
diff
changeset
|
293 } |
8d420cfd2a6f
added unit tests for the Word type
Doug Simon <doug.simon@oracle.com>
parents:
5599
diff
changeset
|
294 } |
8d420cfd2a6f
added unit tests for the Word type
Doug Simon <doug.simon@oracle.com>
parents:
5599
diff
changeset
|
295 InstalledCode installedCode = Debug.scope("Compiling", new DebugDumpScope(String.valueOf(compilationId++), true), new Callable<InstalledCode>() { |
5538
e18ba36bfebc
Renamed RiConstant => Constant.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5537
diff
changeset
|
296 public InstalledCode call() throws Exception { |
5780
64257cbef60c
removed compile method from GraalCodeCacheProvider interface
Doug Simon <doug.simon@oracle.com>
parents:
5720
diff
changeset
|
297 PhasePlan phasePlan = new PhasePlan(); |
64257cbef60c
removed compile method from GraalCodeCacheProvider interface
Doug Simon <doug.simon@oracle.com>
parents:
5720
diff
changeset
|
298 GraphBuilderPhase graphBuilderPhase = new GraphBuilderPhase(runtime, GraphBuilderConfiguration.getDefault(), OptimisticOptimizations.ALL); |
64257cbef60c
removed compile method from GraalCodeCacheProvider interface
Doug Simon <doug.simon@oracle.com>
parents:
5720
diff
changeset
|
299 phasePlan.addPhase(PhasePosition.AFTER_PARSING, graphBuilderPhase); |
64257cbef60c
removed compile method from GraalCodeCacheProvider interface
Doug Simon <doug.simon@oracle.com>
parents:
5720
diff
changeset
|
300 editPhasePlan(method, graph, phasePlan); |
64257cbef60c
removed compile method from GraalCodeCacheProvider interface
Doug Simon <doug.simon@oracle.com>
parents:
5720
diff
changeset
|
301 CompilationResult compResult = graalCompiler.compileMethod(method, graph, -1, null, phasePlan, OptimisticOptimizations.ALL); |
64257cbef60c
removed compile method from GraalCodeCacheProvider interface
Doug Simon <doug.simon@oracle.com>
parents:
5720
diff
changeset
|
302 return addMethod(method, compResult); |
5433
d7b5cc23945e
refactored tests to share support for dump-aware compilation
Doug Simon <doug.simon@oracle.com>
parents:
5425
diff
changeset
|
303 } |
d7b5cc23945e
refactored tests to share support for dump-aware compilation
Doug Simon <doug.simon@oracle.com>
parents:
5425
diff
changeset
|
304 }); |
5650
8d420cfd2a6f
added unit tests for the Word type
Doug Simon <doug.simon@oracle.com>
parents:
5599
diff
changeset
|
305 cache.put(method, installedCode); |
8d420cfd2a6f
added unit tests for the Word type
Doug Simon <doug.simon@oracle.com>
parents:
5599
diff
changeset
|
306 return installedCode; |
5433
d7b5cc23945e
refactored tests to share support for dump-aware compilation
Doug Simon <doug.simon@oracle.com>
parents:
5425
diff
changeset
|
307 } |
d7b5cc23945e
refactored tests to share support for dump-aware compilation
Doug Simon <doug.simon@oracle.com>
parents:
5425
diff
changeset
|
308 |
5780
64257cbef60c
removed compile method from GraalCodeCacheProvider interface
Doug Simon <doug.simon@oracle.com>
parents:
5720
diff
changeset
|
309 protected InstalledCode addMethod(final ResolvedJavaMethod method, final CompilationResult compResult) { |
5557
2e2a77f091f2
re-enabled disassembler output to C1Visualizer after code installation
Doug Simon <doug.simon@oracle.com>
parents:
5546
diff
changeset
|
310 assert graalCompiler != null; |
2e2a77f091f2
re-enabled disassembler output to C1Visualizer after code installation
Doug Simon <doug.simon@oracle.com>
parents:
5546
diff
changeset
|
311 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
|
312 @Override |
5538
e18ba36bfebc
Renamed RiConstant => Constant.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5537
diff
changeset
|
313 public InstalledCode call() throws Exception { |
5537
80371cc2256d
Renaming RiCompiledMethod => InstalledCode.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
5533
diff
changeset
|
314 final CodeInfo[] info = Debug.isDumpEnabled() ? new CodeInfo[1] : null; |
5780
64257cbef60c
removed compile method from GraalCodeCacheProvider interface
Doug Simon <doug.simon@oracle.com>
parents:
5720
diff
changeset
|
315 InstalledCode installedMethod = runtime.addMethod(method, compResult, 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
|
316 if (info != null) { |
5780
64257cbef60c
removed compile method from GraalCodeCacheProvider interface
Doug Simon <doug.simon@oracle.com>
parents:
5720
diff
changeset
|
317 Debug.dump(new Object[] {compResult, 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
|
318 } |
6cc970203f30
moved creation of a RiCodeInfo to the runtime side of the CRI
Doug Simon <doug.simon@oracle.com>
parents:
5122
diff
changeset
|
319 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
|
320 } |
6cc970203f30
moved creation of a RiCodeInfo to the runtime side of the CRI
Doug Simon <doug.simon@oracle.com>
parents:
5122
diff
changeset
|
321 }); |
6cc970203f30
moved creation of a RiCodeInfo to the runtime side of the CRI
Doug Simon <doug.simon@oracle.com>
parents:
5122
diff
changeset
|
322 } |
6cc970203f30
moved creation of a RiCodeInfo to the runtime side of the CRI
Doug Simon <doug.simon@oracle.com>
parents:
5122
diff
changeset
|
323 |
4340
5caca26cb1b9
small fix (missing changes)
Lukas Stadler <lukas.stadler@jku.at>
parents:
4315
diff
changeset
|
324 /** |
5caca26cb1b9
small fix (missing changes)
Lukas Stadler <lukas.stadler@jku.at>
parents:
4315
diff
changeset
|
325 * Parses a Java method to produce a graph. |
5caca26cb1b9
small fix (missing changes)
Lukas Stadler <lukas.stadler@jku.at>
parents:
4315
diff
changeset
|
326 * |
5caca26cb1b9
small fix (missing changes)
Lukas Stadler <lukas.stadler@jku.at>
parents:
4315
diff
changeset
|
327 * @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
|
328 */ |
5caca26cb1b9
small fix (missing changes)
Lukas Stadler <lukas.stadler@jku.at>
parents:
4315
diff
changeset
|
329 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
|
330 return parseProfiled(getMethod(methodName)); |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
331 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
332 |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
333 /** |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
334 * Parses a Java method to produce a graph. |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
335 */ |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
336 protected StructuredGraph parse(Method m) { |
6539
2463eb24b644
Cleanup of Graal API: Rename methods so that it follows the getXxx naming convention and so that they are similar to the names of the java.lang.reflect classes. Remove unused methods.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6529
diff
changeset
|
337 ResolvedJavaMethod javaMethod = runtime.lookupJavaMethod(m); |
5719
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5718
diff
changeset
|
338 StructuredGraph graph = new StructuredGraph(javaMethod); |
5122
9b940aff6c6b
fixed failing testcases
Christian Haeubl <christian.haeubl@oracle.com>
parents:
5118
diff
changeset
|
339 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
|
340 return graph; |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
341 } |
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
342 |
4340
5caca26cb1b9
small fix (missing changes)
Lukas Stadler <lukas.stadler@jku.at>
parents:
4315
diff
changeset
|
343 /** |
5caca26cb1b9
small fix (missing changes)
Lukas Stadler <lukas.stadler@jku.at>
parents:
4315
diff
changeset
|
344 * Parses a Java method to produce a graph. |
5caca26cb1b9
small fix (missing changes)
Lukas Stadler <lukas.stadler@jku.at>
parents:
4315
diff
changeset
|
345 */ |
5caca26cb1b9
small fix (missing changes)
Lukas Stadler <lukas.stadler@jku.at>
parents:
4315
diff
changeset
|
346 protected StructuredGraph parseProfiled(Method m) { |
6539
2463eb24b644
Cleanup of Graal API: Rename methods so that it follows the getXxx naming convention and so that they are similar to the names of the java.lang.reflect classes. Remove unused methods.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
6529
diff
changeset
|
347 ResolvedJavaMethod javaMethod = runtime.lookupJavaMethod(m); |
5719
429accae15aa
moved some methods from CodeUtil to MetaUtil
Doug Simon <doug.simon@oracle.com>
parents:
5718
diff
changeset
|
348 StructuredGraph graph = new StructuredGraph(javaMethod); |
5114
dad1ac9dba7d
finished first implementation of disabling runtime feedback selectively based on deoptimization history
Christian Haeubl <christian.haeubl@oracle.com>
parents:
5109
diff
changeset
|
349 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
|
350 return graph; |
5caca26cb1b9
small fix (missing changes)
Lukas Stadler <lukas.stadler@jku.at>
parents:
4315
diff
changeset
|
351 } |
5caca26cb1b9
small fix (missing changes)
Lukas Stadler <lukas.stadler@jku.at>
parents:
4315
diff
changeset
|
352 |
4204
4df4499e0289
Fixed unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
4203
diff
changeset
|
353 protected PhasePlan getDefaultPhasePlan() { |
4df4499e0289
Fixed unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
4203
diff
changeset
|
354 PhasePlan plan = new PhasePlan(); |
5122
9b940aff6c6b
fixed failing testcases
Christian Haeubl <christian.haeubl@oracle.com>
parents:
5118
diff
changeset
|
355 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
|
356 return plan; |
4df4499e0289
Fixed unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
4203
diff
changeset
|
357 } |
3733
e233f5660da4
Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
358 } |