annotate graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/LockEliminationTest.java @ 18120:86ec7f6f71b3

refactored GraalCompilerTest API to be in terms of ResolvedJavaMethod instead of Method
author Doug Simon <doug.simon@oracle.com>
date Sat, 18 Oct 2014 00:08:19 +0200
parents 1668de777c42
children 8ab925a6f724
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10807
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
1 /*
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
2 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
4 *
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
7 * published by the Free Software Foundation.
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
8 *
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
13 * accompanied this code).
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
14 *
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
18 *
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
21 * questions.
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
22 */
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
23 package com.oracle.graal.compiler.test;
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
24
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
25 import org.junit.*;
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
26
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
27 import com.oracle.graal.api.code.*;
18120
86ec7f6f71b3 refactored GraalCompilerTest API to be in terms of ResolvedJavaMethod instead of Method
Doug Simon <doug.simon@oracle.com>
parents: 16714
diff changeset
28 import com.oracle.graal.api.meta.*;
10807
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
29 import com.oracle.graal.nodes.*;
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
30 import com.oracle.graal.nodes.java.*;
13505
75a67ebd50e8 Introduce a LoweringStage so that lowerings can be conditional on one of the three times that lowering is performed by default
Christian Wimmer <christian.wimmer@oracle.com>
parents: 12054
diff changeset
31 import com.oracle.graal.nodes.spi.*;
10807
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
32 import com.oracle.graal.phases.*;
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
33 import com.oracle.graal.phases.common.*;
15470
c55f44b3c5e5 remove NodesToDoubles, refactoring of node probability and inlining relevance computation
Lukas Stadler <lukas.stadler@oracle.com>
parents: 13585
diff changeset
34 import com.oracle.graal.phases.common.inlining.*;
10807
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
35 import com.oracle.graal.phases.tiers.*;
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
36
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
37 public class LockEliminationTest extends GraalCompilerTest {
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
38
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
39 static class A {
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
40
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
41 int value;
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
42
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
43 public synchronized int getValue() {
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
44 return value;
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
45 }
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
46 }
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
47
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
48 static int field1;
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
49 static int field2;
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
50
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
51 public static void testSynchronizedSnippet(A x, A y) {
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
52 synchronized (x) {
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
53 field1 = x.value;
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
54 }
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
55 synchronized (x) {
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
56 field2 = y.value;
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
57 }
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
58 }
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
59
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
60 @Test
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
61 public void testLock() {
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
62 test("testSynchronizedSnippet", new A(), new A());
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
63
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
64 StructuredGraph graph = getGraph("testSynchronizedSnippet");
12054
bba234a1670e grouped provider values/parameters into a Providers object (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 12052
diff changeset
65 new CanonicalizerPhase(true).apply(graph, new PhaseContext(getProviders(), null));
10807
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
66 new LockEliminationPhase().apply(graph);
15622
7b09605b29c5 renamed GraalTest.assertEquals* to assertDeepEquals to avoid confusion with JUnit API methods
Doug Simon <doug.simon@oracle.com>
parents: 15470
diff changeset
67 assertDeepEquals(1, graph.getNodes().filter(MonitorEnterNode.class).count());
7b09605b29c5 renamed GraalTest.assertEquals* to assertDeepEquals to avoid confusion with JUnit API methods
Doug Simon <doug.simon@oracle.com>
parents: 15470
diff changeset
68 assertDeepEquals(1, graph.getNodes().filter(MonitorExitNode.class).count());
10807
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
69 }
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
70
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
71 public static void testSynchronizedMethodSnippet(A x) {
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
72 int value1 = x.getValue();
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
73 int value2 = x.getValue();
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
74 field1 = value1;
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
75 field2 = value2;
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
76 }
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
77
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
78 @Test
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
79 public void testSynchronizedMethod() {
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
80 test("testSynchronizedMethodSnippet", new A());
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
81
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
82 StructuredGraph graph = getGraph("testSynchronizedMethodSnippet");
12054
bba234a1670e grouped provider values/parameters into a Providers object (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 12052
diff changeset
83 new CanonicalizerPhase(true).apply(graph, new PhaseContext(getProviders(), null));
10807
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
84 new LockEliminationPhase().apply(graph);
15622
7b09605b29c5 renamed GraalTest.assertEquals* to assertDeepEquals to avoid confusion with JUnit API methods
Doug Simon <doug.simon@oracle.com>
parents: 15470
diff changeset
85 assertDeepEquals(1, graph.getNodes().filter(MonitorEnterNode.class).count());
7b09605b29c5 renamed GraalTest.assertEquals* to assertDeepEquals to avoid confusion with JUnit API methods
Doug Simon <doug.simon@oracle.com>
parents: 15470
diff changeset
86 assertDeepEquals(1, graph.getNodes().filter(MonitorExitNode.class).count());
10807
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
87 }
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
88
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
89 private StructuredGraph getGraph(String snippet) {
18120
86ec7f6f71b3 refactored GraalCompilerTest API to be in terms of ResolvedJavaMethod instead of Method
Doug Simon <doug.simon@oracle.com>
parents: 16714
diff changeset
90 ResolvedJavaMethod method = getResolvedJavaMethod(snippet);
16714
1668de777c42 renamed GraalCompilerTest.parse to GraalCompilerTest.parseEager and improved javadoc for all parse* methods
Doug Simon <doug.simon@oracle.com>
parents: 15622
diff changeset
91 StructuredGraph graph = parseEager(method);
10807
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
92 Assumptions assumptions = new Assumptions(true);
13585
f4f0a8a01ce0 remove PhasePlan
Lukas Stadler <lukas.stadler@jku.at>
parents: 13505
diff changeset
93 HighTierContext context = new HighTierContext(getProviders(), assumptions, null, getDefaultGraphBuilderSuite(), OptimisticOptimizations.ALL);
10933
9878214a0093 Remove fields from InliningPhase that are already available in HighTierContext.
Roland Schatz <roland.schatz@oracle.com>
parents: 10807
diff changeset
94 new CanonicalizerPhase(true).apply(graph, context);
11567
c69df2e602f4 Use CanonicalizerPhase.applyIncremental in InliningPhase.
Roland Schatz <roland.schatz@oracle.com>
parents: 11566
diff changeset
95 new InliningPhase(new CanonicalizerPhase(true)).apply(graph, context);
10933
9878214a0093 Remove fields from InliningPhase that are already available in HighTierContext.
Roland Schatz <roland.schatz@oracle.com>
parents: 10807
diff changeset
96 new CanonicalizerPhase(true).apply(graph, context);
10807
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
97 new DeadCodeEliminationPhase().apply(graph);
13505
75a67ebd50e8 Introduce a LoweringStage so that lowerings can be conditional on one of the three times that lowering is performed by default
Christian Wimmer <christian.wimmer@oracle.com>
parents: 12054
diff changeset
98 new LoweringPhase(new CanonicalizerPhase(true), LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
10807
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
99 new ValueAnchorCleanupPhase().apply(graph);
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
100 new LockEliminationPhase().apply(graph);
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
101 return graph;
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
102 }
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
103
d3a677910eea new ValueAnchorCleanupPhase to make lock elimination work again, tests for lock elimination
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
104 }