Mercurial > hg > truffle
annotate test/compiler/EscapeAnalysis/TestAllocatedEscapesPtrComparison.java @ 20359:4d3a43351904
Merge
author | tschatzl |
---|---|
date | Wed, 27 Aug 2014 09:36:55 +0200 |
parents | 42d9a5f06728 |
children |
rev | line source |
---|---|
17959
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
1 /* |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
2 * Copyright 2014 Google, Inc. All Rights Reserved. |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
4 * |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
8 * |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
13 * accompanied this code). |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
14 * |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
18 * |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
21 * questions. |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
22 */ |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
23 |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
24 /* |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
25 * @test |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
26 * @bug 8043354 |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
27 * @summary bcEscapeAnalyzer allocated_escapes not conservative enough |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
28 * @run main/othervm -XX:CompileOnly=.visitAndPop TestAllocatedEscapesPtrComparison |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
29 * @author Chuck Rasbold rasbold@google.com |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
30 */ |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
31 |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
32 /* |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
33 * Test always passes with -XX:-OptmimizePtrCompare |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
34 */ |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
35 |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
36 import java.util.ArrayList; |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
37 import java.util.List; |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
38 |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
39 public class TestAllocatedEscapesPtrComparison { |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
40 |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
41 static TestAllocatedEscapesPtrComparison dummy; |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
42 |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
43 class Marker { |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
44 } |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
45 |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
46 List<Marker> markerList = new ArrayList<>(); |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
47 |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
48 // Suppress compilation of this method, it must be processed |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
49 // by the bytecode escape analyzer. |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
50 |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
51 // Make a new marker and put it on the List |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
52 Marker getMarker() { |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
53 // result escapes through markerList |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
54 final Marker result = new Marker(); |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
55 markerList.add(result); |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
56 return result; |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
57 } |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
58 |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
59 void visit(int depth) { |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
60 // Make a new marker |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
61 getMarker(); |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
62 |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
63 // Call visitAndPop every once in a while |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
64 // Cap the depth of our recursive visits |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
65 if (depth % 10 == 2) { |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
66 visitAndPop(depth + 1); |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
67 } else if (depth < 15) { |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
68 visit(depth + 1); |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
69 } |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
70 } |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
71 |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
72 void visitAndPop(int depth) { |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
73 // Random dummy allocation to force EscapeAnalysis to process this method |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
74 dummy = new TestAllocatedEscapesPtrComparison(); |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
75 |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
76 // Make a new marker |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
77 Marker marker = getMarker(); |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
78 |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
79 visit(depth + 1); |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
80 |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
81 // Walk and pop the marker list up to the current marker |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
82 boolean found = false; |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
83 for (int i = markerList.size() - 1; i >= 0; i--) { |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
84 Marker removed = markerList.remove(i); |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
85 |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
86 // In the failure, EA mistakenly converts this comparison to false |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
87 if (removed == marker) { |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
88 found = true; |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
89 break; |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
90 } |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
91 } |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
92 |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
93 if (!found) { |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
94 throw new RuntimeException("test fails"); |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
95 } |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
96 } |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
97 |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
98 |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
99 public static void main(String args[]) { |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
100 TestAllocatedEscapesPtrComparison tc = new TestAllocatedEscapesPtrComparison(); |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
101 |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
102 // Warmup and run enough times |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
103 for (int i = 0; i < 20000; i++) { |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
104 tc.visit(0); |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
105 } |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
106 } |
42d9a5f06728
8043354: OptimizePtrCompare too aggressive when allocations are present
rasbold
parents:
diff
changeset
|
107 } |