author | phh |
Sat, 30 Nov 2019 14:33:05 -0800 | |
changeset 59330 | 5b96c12f909d |
parent 52220 | 9c260a6b6471 |
permissions | -rw-r--r-- |
42080
1e906304457b
8167298: assert(tp->base() != Type::AnyPtr) crash with Unsafe.compareAndExchangeObject*
roland
parents:
diff
changeset
|
1 |
/* |
45514
0fc9cc73ce45
8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents:
42080
diff
changeset
|
2 |
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. |
42080
1e906304457b
8167298: assert(tp->base() != Type::AnyPtr) crash with Unsafe.compareAndExchangeObject*
roland
parents:
diff
changeset
|
3 |
* Copyright (c) 2016, Red Hat, Inc. All rights reserved. |
1e906304457b
8167298: assert(tp->base() != Type::AnyPtr) crash with Unsafe.compareAndExchangeObject*
roland
parents:
diff
changeset
|
4 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
1e906304457b
8167298: assert(tp->base() != Type::AnyPtr) crash with Unsafe.compareAndExchangeObject*
roland
parents:
diff
changeset
|
5 |
* |
1e906304457b
8167298: assert(tp->base() != Type::AnyPtr) crash with Unsafe.compareAndExchangeObject*
roland
parents:
diff
changeset
|
6 |
* This code is free software; you can redistribute it and/or modify it |
1e906304457b
8167298: assert(tp->base() != Type::AnyPtr) crash with Unsafe.compareAndExchangeObject*
roland
parents:
diff
changeset
|
7 |
* under the terms of the GNU General Public License version 2 only, as |
1e906304457b
8167298: assert(tp->base() != Type::AnyPtr) crash with Unsafe.compareAndExchangeObject*
roland
parents:
diff
changeset
|
8 |
* published by the Free Software Foundation. |
1e906304457b
8167298: assert(tp->base() != Type::AnyPtr) crash with Unsafe.compareAndExchangeObject*
roland
parents:
diff
changeset
|
9 |
* |
1e906304457b
8167298: assert(tp->base() != Type::AnyPtr) crash with Unsafe.compareAndExchangeObject*
roland
parents:
diff
changeset
|
10 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
1e906304457b
8167298: assert(tp->base() != Type::AnyPtr) crash with Unsafe.compareAndExchangeObject*
roland
parents:
diff
changeset
|
11 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
1e906304457b
8167298: assert(tp->base() != Type::AnyPtr) crash with Unsafe.compareAndExchangeObject*
roland
parents:
diff
changeset
|
12 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
1e906304457b
8167298: assert(tp->base() != Type::AnyPtr) crash with Unsafe.compareAndExchangeObject*
roland
parents:
diff
changeset
|
13 |
* version 2 for more details (a copy is included in the LICENSE file that |
1e906304457b
8167298: assert(tp->base() != Type::AnyPtr) crash with Unsafe.compareAndExchangeObject*
roland
parents:
diff
changeset
|
14 |
* accompanied this code). |
1e906304457b
8167298: assert(tp->base() != Type::AnyPtr) crash with Unsafe.compareAndExchangeObject*
roland
parents:
diff
changeset
|
15 |
* |
1e906304457b
8167298: assert(tp->base() != Type::AnyPtr) crash with Unsafe.compareAndExchangeObject*
roland
parents:
diff
changeset
|
16 |
* You should have received a copy of the GNU General Public License version |
1e906304457b
8167298: assert(tp->base() != Type::AnyPtr) crash with Unsafe.compareAndExchangeObject*
roland
parents:
diff
changeset
|
17 |
* 2 along with this work; if not, write to the Free Software Foundation, |
1e906304457b
8167298: assert(tp->base() != Type::AnyPtr) crash with Unsafe.compareAndExchangeObject*
roland
parents:
diff
changeset
|
18 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
1e906304457b
8167298: assert(tp->base() != Type::AnyPtr) crash with Unsafe.compareAndExchangeObject*
roland
parents:
diff
changeset
|
19 |
* |
1e906304457b
8167298: assert(tp->base() != Type::AnyPtr) crash with Unsafe.compareAndExchangeObject*
roland
parents:
diff
changeset
|
20 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
1e906304457b
8167298: assert(tp->base() != Type::AnyPtr) crash with Unsafe.compareAndExchangeObject*
roland
parents:
diff
changeset
|
21 |
* or visit www.oracle.com if you need additional information or have any |
1e906304457b
8167298: assert(tp->base() != Type::AnyPtr) crash with Unsafe.compareAndExchangeObject*
roland
parents:
diff
changeset
|
22 |
* questions. |
1e906304457b
8167298: assert(tp->base() != Type::AnyPtr) crash with Unsafe.compareAndExchangeObject*
roland
parents:
diff
changeset
|
23 |
*/ |
1e906304457b
8167298: assert(tp->base() != Type::AnyPtr) crash with Unsafe.compareAndExchangeObject*
roland
parents:
diff
changeset
|
24 |
|
1e906304457b
8167298: assert(tp->base() != Type::AnyPtr) crash with Unsafe.compareAndExchangeObject*
roland
parents:
diff
changeset
|
25 |
/** |
1e906304457b
8167298: assert(tp->base() != Type::AnyPtr) crash with Unsafe.compareAndExchangeObject*
roland
parents:
diff
changeset
|
26 |
* @test |
1e906304457b
8167298: assert(tp->base() != Type::AnyPtr) crash with Unsafe.compareAndExchangeObject*
roland
parents:
diff
changeset
|
27 |
* @bug 8167298 |
52220
9c260a6b6471
8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents:
47216
diff
changeset
|
28 |
* @summary Unsafe.compareAndExchangeReference should keep track of returned type after matching |
42080
1e906304457b
8167298: assert(tp->base() != Type::AnyPtr) crash with Unsafe.compareAndExchangeObject*
roland
parents:
diff
changeset
|
29 |
* @modules java.base/jdk.internal.misc |
1e906304457b
8167298: assert(tp->base() != Type::AnyPtr) crash with Unsafe.compareAndExchangeObject*
roland
parents:
diff
changeset
|
30 |
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-BackgroundCompilation -XX:-UseOnStackReplacement -XX:-UseCompressedOops TestCAEAntiDep |
1e906304457b
8167298: assert(tp->base() != Type::AnyPtr) crash with Unsafe.compareAndExchangeObject*
roland
parents:
diff
changeset
|
31 |
* |
1e906304457b
8167298: assert(tp->base() != Type::AnyPtr) crash with Unsafe.compareAndExchangeObject*
roland
parents:
diff
changeset
|
32 |
*/ |
1e906304457b
8167298: assert(tp->base() != Type::AnyPtr) crash with Unsafe.compareAndExchangeObject*
roland
parents:
diff
changeset
|
33 |
|
1e906304457b
8167298: assert(tp->base() != Type::AnyPtr) crash with Unsafe.compareAndExchangeObject*
roland
parents:
diff
changeset
|
34 |
import java.lang.reflect.Field; |
1e906304457b
8167298: assert(tp->base() != Type::AnyPtr) crash with Unsafe.compareAndExchangeObject*
roland
parents:
diff
changeset
|
35 |
import jdk.internal.misc.Unsafe; |
1e906304457b
8167298: assert(tp->base() != Type::AnyPtr) crash with Unsafe.compareAndExchangeObject*
roland
parents:
diff
changeset
|
36 |
|
1e906304457b
8167298: assert(tp->base() != Type::AnyPtr) crash with Unsafe.compareAndExchangeObject*
roland
parents:
diff
changeset
|
37 |
public class TestCAEAntiDep { |
1e906304457b
8167298: assert(tp->base() != Type::AnyPtr) crash with Unsafe.compareAndExchangeObject*
roland
parents:
diff
changeset
|
38 |
static final jdk.internal.misc.Unsafe UNSAFE = Unsafe.getUnsafe(); |
1e906304457b
8167298: assert(tp->base() != Type::AnyPtr) crash with Unsafe.compareAndExchangeObject*
roland
parents:
diff
changeset
|
39 |
static final long O_OFFSET; |
1e906304457b
8167298: assert(tp->base() != Type::AnyPtr) crash with Unsafe.compareAndExchangeObject*
roland
parents:
diff
changeset
|
40 |
|
1e906304457b
8167298: assert(tp->base() != Type::AnyPtr) crash with Unsafe.compareAndExchangeObject*
roland
parents:
diff
changeset
|
41 |
static class C { |
1e906304457b
8167298: assert(tp->base() != Type::AnyPtr) crash with Unsafe.compareAndExchangeObject*
roland
parents:
diff
changeset
|
42 |
int f1; |
1e906304457b
8167298: assert(tp->base() != Type::AnyPtr) crash with Unsafe.compareAndExchangeObject*
roland
parents:
diff
changeset
|
43 |
} |
1e906304457b
8167298: assert(tp->base() != Type::AnyPtr) crash with Unsafe.compareAndExchangeObject*
roland
parents:
diff
changeset
|
44 |
|
1e906304457b
8167298: assert(tp->base() != Type::AnyPtr) crash with Unsafe.compareAndExchangeObject*
roland
parents:
diff
changeset
|
45 |
C o = new C(); |
1e906304457b
8167298: assert(tp->base() != Type::AnyPtr) crash with Unsafe.compareAndExchangeObject*
roland
parents:
diff
changeset
|
46 |
|
1e906304457b
8167298: assert(tp->base() != Type::AnyPtr) crash with Unsafe.compareAndExchangeObject*
roland
parents:
diff
changeset
|
47 |
static { |
1e906304457b
8167298: assert(tp->base() != Type::AnyPtr) crash with Unsafe.compareAndExchangeObject*
roland
parents:
diff
changeset
|
48 |
try { |
1e906304457b
8167298: assert(tp->base() != Type::AnyPtr) crash with Unsafe.compareAndExchangeObject*
roland
parents:
diff
changeset
|
49 |
Field oField = TestCAEAntiDep.class.getDeclaredField("o"); |
1e906304457b
8167298: assert(tp->base() != Type::AnyPtr) crash with Unsafe.compareAndExchangeObject*
roland
parents:
diff
changeset
|
50 |
O_OFFSET = UNSAFE.objectFieldOffset(oField); |
1e906304457b
8167298: assert(tp->base() != Type::AnyPtr) crash with Unsafe.compareAndExchangeObject*
roland
parents:
diff
changeset
|
51 |
} catch (Exception e) { |
1e906304457b
8167298: assert(tp->base() != Type::AnyPtr) crash with Unsafe.compareAndExchangeObject*
roland
parents:
diff
changeset
|
52 |
throw new RuntimeException(e); |
1e906304457b
8167298: assert(tp->base() != Type::AnyPtr) crash with Unsafe.compareAndExchangeObject*
roland
parents:
diff
changeset
|
53 |
} |
1e906304457b
8167298: assert(tp->base() != Type::AnyPtr) crash with Unsafe.compareAndExchangeObject*
roland
parents:
diff
changeset
|
54 |
} |
1e906304457b
8167298: assert(tp->base() != Type::AnyPtr) crash with Unsafe.compareAndExchangeObject*
roland
parents:
diff
changeset
|
55 |
|
1e906304457b
8167298: assert(tp->base() != Type::AnyPtr) crash with Unsafe.compareAndExchangeObject*
roland
parents:
diff
changeset
|
56 |
static int m(TestCAEAntiDep test, Object expected, Object x) { |
52220
9c260a6b6471
8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents:
47216
diff
changeset
|
57 |
C old = (C)UNSAFE.compareAndExchangeReference(test, O_OFFSET, expected, x); |
42080
1e906304457b
8167298: assert(tp->base() != Type::AnyPtr) crash with Unsafe.compareAndExchangeObject*
roland
parents:
diff
changeset
|
58 |
int res = old.f1; |
1e906304457b
8167298: assert(tp->base() != Type::AnyPtr) crash with Unsafe.compareAndExchangeObject*
roland
parents:
diff
changeset
|
59 |
old.f1 = 0x42; |
1e906304457b
8167298: assert(tp->base() != Type::AnyPtr) crash with Unsafe.compareAndExchangeObject*
roland
parents:
diff
changeset
|
60 |
return res; |
1e906304457b
8167298: assert(tp->base() != Type::AnyPtr) crash with Unsafe.compareAndExchangeObject*
roland
parents:
diff
changeset
|
61 |
} |
1e906304457b
8167298: assert(tp->base() != Type::AnyPtr) crash with Unsafe.compareAndExchangeObject*
roland
parents:
diff
changeset
|
62 |
|
1e906304457b
8167298: assert(tp->base() != Type::AnyPtr) crash with Unsafe.compareAndExchangeObject*
roland
parents:
diff
changeset
|
63 |
static public void main(String[] args) { |
1e906304457b
8167298: assert(tp->base() != Type::AnyPtr) crash with Unsafe.compareAndExchangeObject*
roland
parents:
diff
changeset
|
64 |
TestCAEAntiDep test = new TestCAEAntiDep(); |
1e906304457b
8167298: assert(tp->base() != Type::AnyPtr) crash with Unsafe.compareAndExchangeObject*
roland
parents:
diff
changeset
|
65 |
for (int i = 0; i < 20000; i++) { |
1e906304457b
8167298: assert(tp->base() != Type::AnyPtr) crash with Unsafe.compareAndExchangeObject*
roland
parents:
diff
changeset
|
66 |
m(test, test.o, test.o); |
1e906304457b
8167298: assert(tp->base() != Type::AnyPtr) crash with Unsafe.compareAndExchangeObject*
roland
parents:
diff
changeset
|
67 |
} |
1e906304457b
8167298: assert(tp->base() != Type::AnyPtr) crash with Unsafe.compareAndExchangeObject*
roland
parents:
diff
changeset
|
68 |
} |
1e906304457b
8167298: assert(tp->base() != Type::AnyPtr) crash with Unsafe.compareAndExchangeObject*
roland
parents:
diff
changeset
|
69 |
} |