author | jiangli |
Fri, 02 Nov 2018 19:30:31 -0400 | |
changeset 52397 | 1322829d1501 |
parent 52220 | 9c260a6b6471 |
permissions | -rw-r--r-- |
13486
4f0635e148c1
7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff
changeset
|
1 |
/* |
29678
dd2f3932c21e
8075586: Add @modules as needed to the open hotspot tests
ykantser
parents:
27699
diff
changeset
|
2 |
* Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. |
13486
4f0635e148c1
7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4f0635e148c1
7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff
changeset
|
4 |
* |
4f0635e148c1
7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
4f0635e148c1
7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
4f0635e148c1
7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
4f0635e148c1
7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff
changeset
|
8 |
* |
4f0635e148c1
7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
4f0635e148c1
7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
4f0635e148c1
7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
4f0635e148c1
7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
4f0635e148c1
7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff
changeset
|
13 |
* accompanied this code). |
4f0635e148c1
7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff
changeset
|
14 |
* |
4f0635e148c1
7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
4f0635e148c1
7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
4f0635e148c1
7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
4f0635e148c1
7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff
changeset
|
18 |
* |
4f0635e148c1
7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
4f0635e148c1
7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
4f0635e148c1
7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff
changeset
|
21 |
* questions. |
4f0635e148c1
7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff
changeset
|
22 |
*/ |
4f0635e148c1
7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff
changeset
|
23 |
|
4f0635e148c1
7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff
changeset
|
24 |
/* |
4f0635e148c1
7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff
changeset
|
25 |
* @test |
4f0635e148c1
7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff
changeset
|
26 |
* @bug 7190310 |
4f0635e148c1
7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff
changeset
|
27 |
* @summary Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops |
42307
cefc81dc1d52
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41705
diff
changeset
|
28 |
* @modules java.base/jdk.internal.misc:+open |
cefc81dc1d52
8169069: Module system implementation refresh (11/2016)
alanb
parents:
41705
diff
changeset
|
29 |
* @modules java.base/java.lang.ref:open |
40059 | 30 |
* |
31 |
* @run main/othervm -Xbatch compiler.c2.Test7190310_unsafe |
|
13486
4f0635e148c1
7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff
changeset
|
32 |
*/ |
4f0635e148c1
7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff
changeset
|
33 |
|
40059 | 34 |
package compiler.c2; |
35 |
||
38152
80e5da81fb2c
8154258: [TESTBUG] Various serviceability tests fail compilation
dsamersoff
parents:
36851
diff
changeset
|
36 |
import jdk.internal.misc.Unsafe; |
13486
4f0635e148c1
7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff
changeset
|
37 |
|
40059 | 38 |
import java.lang.ref.Reference; |
39 |
import java.lang.ref.WeakReference; |
|
40 |
import java.lang.reflect.Field; |
|
41 |
||
13486
4f0635e148c1
7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff
changeset
|
42 |
public class Test7190310_unsafe { |
4f0635e148c1
7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff
changeset
|
43 |
|
40059 | 44 |
static class TestObject { |
45 |
public String toString() { |
|
46 |
return "TestObject"; |
|
47 |
} |
|
13486
4f0635e148c1
7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff
changeset
|
48 |
} |
4f0635e148c1
7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff
changeset
|
49 |
|
40059 | 50 |
; |
51 |
||
52 |
private static TestObject str = new TestObject(); |
|
53 |
private static final WeakReference ref = new WeakReference(str); |
|
54 |
||
55 |
private TestObject obj; |
|
56 |
||
57 |
public static void main(String[] args) throws Exception { |
|
58 |
Class c = Test7190310_unsafe.class.getClassLoader().loadClass("jdk.internal.misc.Unsafe"); |
|
59 |
Field f = c.getDeclaredField("theUnsafe"); |
|
60 |
f.setAccessible(true); |
|
61 |
Unsafe unsafe = (Unsafe) f.get(c); |
|
62 |
||
63 |
f = Reference.class.getDeclaredField("referent"); |
|
64 |
f.setAccessible(true); |
|
65 |
long referent_offset = unsafe.objectFieldOffset(f); |
|
66 |
||
67 |
Test7190310_unsafe t = new Test7190310_unsafe(); |
|
68 |
TestObject o = new TestObject(); |
|
69 |
t.obj = o; |
|
13486
4f0635e148c1
7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff
changeset
|
70 |
|
40059 | 71 |
// Warmup (compile methods) |
72 |
System.err.println("Warmup"); |
|
73 |
Object obj = null; |
|
74 |
for (int i = 0; i < 11000; i++) { |
|
75 |
obj = getRef0(ref); |
|
76 |
} |
|
77 |
for (int i = 0; i < 11000; i++) { |
|
78 |
obj = getRef1(unsafe, ref, referent_offset); |
|
79 |
} |
|
80 |
for (int i = 0; i < 11000; i++) { |
|
81 |
obj = getRef2(unsafe, ref, referent_offset); |
|
82 |
} |
|
83 |
for (int i = 0; i < 11000; i++) { |
|
84 |
obj = getRef3(unsafe, ref, referent_offset); |
|
85 |
} |
|
86 |
for (int i = 0; i < 11000; i++) { |
|
87 |
obj = getRef4(unsafe, t, referent_offset); |
|
88 |
} |
|
89 |
||
90 |
// Access verification |
|
91 |
System.err.println("Verification"); |
|
92 |
if (!verifyGet(referent_offset, unsafe)) { |
|
93 |
System.exit(97); |
|
94 |
} |
|
95 |
||
96 |
obj = getRef3(unsafe, t, referent_offset); |
|
97 |
if (obj != o) { |
|
52220
9c260a6b6471
8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents:
47216
diff
changeset
|
98 |
System.out.println("FAILED: unsafe.getReference(Object, " + referent_offset + ") " + obj + " != " + o); |
40059 | 99 |
System.exit(97); |
100 |
} |
|
101 |
obj = getRef4(unsafe, t, referent_offset); |
|
102 |
if (obj != o) { |
|
52220
9c260a6b6471
8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents:
47216
diff
changeset
|
103 |
System.out.println("FAILED: unsafe.getReference(Test7190310, " + referent_offset + ") " + obj + " != " + o); |
40059 | 104 |
System.exit(97); |
105 |
} |
|
13486
4f0635e148c1
7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff
changeset
|
106 |
} |
4f0635e148c1
7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff
changeset
|
107 |
|
40059 | 108 |
static boolean verifyGet(long referent_offset, Unsafe unsafe) throws Exception { |
109 |
// Access verification |
|
110 |
System.out.println("referent: " + str); |
|
111 |
Object obj = getRef0(ref); |
|
112 |
if (obj != str) { |
|
113 |
System.out.println("FAILED: weakRef.get() " + obj + " != " + str); |
|
114 |
return false; |
|
115 |
} |
|
116 |
obj = getRef1(unsafe, ref, referent_offset); |
|
117 |
if (obj != str) { |
|
52220
9c260a6b6471
8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents:
47216
diff
changeset
|
118 |
System.out.println("FAILED: unsafe.getReference(weakRef, " + referent_offset + ") " + obj + " != " + str); |
40059 | 119 |
return false; |
120 |
} |
|
121 |
obj = getRef2(unsafe, ref, referent_offset); |
|
122 |
if (obj != str) { |
|
52220
9c260a6b6471
8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents:
47216
diff
changeset
|
123 |
System.out.println("FAILED: unsafe.getReference(abstRef, " + referent_offset + ") " + obj + " != " + str); |
40059 | 124 |
return false; |
125 |
} |
|
126 |
obj = getRef3(unsafe, ref, referent_offset); |
|
127 |
if (obj != str) { |
|
52220
9c260a6b6471
8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents:
47216
diff
changeset
|
128 |
System.out.println("FAILED: unsafe.getReference(Object, " + referent_offset + ") " + obj + " != " + str); |
40059 | 129 |
return false; |
130 |
} |
|
131 |
return true; |
|
132 |
} |
|
133 |
||
134 |
static Object getRef0(WeakReference ref) throws Exception { |
|
135 |
return ref.get(); |
|
136 |
} |
|
137 |
||
138 |
static Object getRef1(Unsafe unsafe, WeakReference ref, long referent_offset) throws Exception { |
|
52220
9c260a6b6471
8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents:
47216
diff
changeset
|
139 |
return unsafe.getReference(ref, referent_offset); |
40059 | 140 |
} |
141 |
||
142 |
static Object getRef2(Unsafe unsafe, Reference ref, long referent_offset) throws Exception { |
|
52220
9c260a6b6471
8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents:
47216
diff
changeset
|
143 |
return unsafe.getReference(ref, referent_offset); |
40059 | 144 |
} |
145 |
||
146 |
static Object getRef3(Unsafe unsafe, Object ref, long referent_offset) throws Exception { |
|
52220
9c260a6b6471
8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents:
47216
diff
changeset
|
147 |
return unsafe.getReference(ref, referent_offset); |
40059 | 148 |
} |
149 |
||
150 |
static Object getRef4(Unsafe unsafe, Test7190310_unsafe ref, long referent_offset) throws Exception { |
|
52220
9c260a6b6471
8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents:
47216
diff
changeset
|
151 |
return unsafe.getReference(ref, referent_offset); |
40059 | 152 |
} |
13486
4f0635e148c1
7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff
changeset
|
153 |
} |
4f0635e148c1
7190310: Inlining WeakReference.get(), and hoisting $referent may lead to non-terminating loops
kvn
parents:
diff
changeset
|
154 |