author | hshi |
Mon, 16 Nov 2015 16:14:15 +0100 | |
changeset 34183 | 8b683720a3e4 |
child 35099 | 982950884444 |
permissions | -rw-r--r-- |
34183
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
1 |
/* |
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
2 |
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. |
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
4 |
* |
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
10 |
* |
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
15 |
* accompanied this code). |
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
16 |
* |
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
20 |
* |
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
23 |
* questions. |
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
24 |
*/ |
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
25 |
|
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
26 |
/* |
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
27 |
* @test TestStableMemoryBarrier |
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
28 |
* @bug 8139758 |
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
29 |
* @summary tests memory barrier correctly inserted for stable fields |
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
30 |
* @library /testlibrary /../../test/lib |
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
31 |
* |
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
32 |
* @run main/bootclasspath -Xcomp -XX:CompileOnly=::testCompile |
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
33 |
* java.lang.invoke.TestStableMemoryBarrier |
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
34 |
* |
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
35 |
* @author hui.shi@linaro.org |
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
36 |
*/ |
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
37 |
package java.lang.invoke; |
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
38 |
|
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
39 |
import java.lang.reflect.InvocationTargetException; |
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
40 |
|
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
41 |
public class TestStableMemoryBarrier { |
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
42 |
|
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
43 |
public static void main(String[] args) throws Exception { |
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
44 |
run(NotDominate.class); |
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
45 |
|
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
46 |
} |
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
47 |
|
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
48 |
/* ==================================================== |
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
49 |
* Stable field initialized in method, but its allocation |
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
50 |
* doesn't dominate MemBar Release at the end of method. |
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
51 |
*/ |
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
52 |
|
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
53 |
static class NotDominate{ |
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
54 |
public @Stable int v; |
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
55 |
public static int[] array = new int[100]; |
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
56 |
public static NotDominate testCompile(int n) { |
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
57 |
if ((n % 2) == 0) return null; |
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
58 |
// add a loop here, trigger PhaseIdealLoop::verify_dominance |
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
59 |
for (int i = 0; i < 100; i++) { |
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
60 |
array[i] = n; |
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
61 |
} |
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
62 |
NotDominate nm = new NotDominate(); |
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
63 |
nm.v = n; |
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
64 |
return nm; |
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
65 |
} |
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
66 |
|
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
67 |
public static void test() throws Exception { |
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
68 |
for (int i = 0; i < 1000000; i++) |
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
69 |
testCompile(i); |
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
70 |
} |
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
71 |
} |
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
72 |
|
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
73 |
public static void run(Class<?> test) { |
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
74 |
Throwable ex = null; |
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
75 |
System.out.print(test.getName()+": "); |
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
76 |
try { |
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
77 |
test.getMethod("test").invoke(null); |
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
78 |
} catch (InvocationTargetException e) { |
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
79 |
ex = e.getCause(); |
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
80 |
} catch (Throwable e) { |
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
81 |
ex = e; |
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
82 |
} finally { |
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
83 |
if (ex == null) { |
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
84 |
System.out.println("PASSED"); |
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
85 |
} else { |
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
86 |
System.out.println("FAILED"); |
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
87 |
ex.printStackTrace(System.out); |
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
88 |
} |
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
89 |
} |
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
90 |
} |
8b683720a3e4
8139758: [REDO] Elide more final field's write memory barrier with escape analysis result
hshi
parents:
diff
changeset
|
91 |
} |