author | tschatzl |
Wed, 19 Aug 2015 13:47:40 +0200 | |
changeset 32377 | 5ee15c417d02 |
parent 30604 | b8d532cb6420 |
child 36851 | 03e2f4d0a421 |
permissions | -rw-r--r-- |
28732
d4b650e48a8f
8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff
changeset
|
1 |
/* |
d4b650e48a8f
8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff
changeset
|
2 |
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. |
d4b650e48a8f
8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
d4b650e48a8f
8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff
changeset
|
4 |
* |
d4b650e48a8f
8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
d4b650e48a8f
8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
d4b650e48a8f
8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
d4b650e48a8f
8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff
changeset
|
8 |
* |
d4b650e48a8f
8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
d4b650e48a8f
8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
d4b650e48a8f
8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
d4b650e48a8f
8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
d4b650e48a8f
8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff
changeset
|
13 |
* accompanied this code). |
d4b650e48a8f
8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff
changeset
|
14 |
* |
d4b650e48a8f
8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
d4b650e48a8f
8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
d4b650e48a8f
8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
d4b650e48a8f
8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff
changeset
|
18 |
* |
d4b650e48a8f
8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
d4b650e48a8f
8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
d4b650e48a8f
8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff
changeset
|
21 |
* questions. |
d4b650e48a8f
8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff
changeset
|
22 |
*/ |
d4b650e48a8f
8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff
changeset
|
23 |
|
d4b650e48a8f
8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff
changeset
|
24 |
/* |
d4b650e48a8f
8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff
changeset
|
25 |
* @test |
d4b650e48a8f
8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff
changeset
|
26 |
* @summary Verifies the behaviour of Unsafe.fieldOffset |
d4b650e48a8f
8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff
changeset
|
27 |
* @library /testlibrary |
29678
dd2f3932c21e
8075586: Add @modules as needed to the open hotspot tests
ykantser
parents:
28951
diff
changeset
|
28 |
* @modules java.base/sun.misc |
dd2f3932c21e
8075586: Add @modules as needed to the open hotspot tests
ykantser
parents:
28951
diff
changeset
|
29 |
* java.management |
28732
d4b650e48a8f
8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff
changeset
|
30 |
* @run main FieldOffset |
d4b650e48a8f
8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff
changeset
|
31 |
*/ |
d4b650e48a8f
8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff
changeset
|
32 |
|
d4b650e48a8f
8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff
changeset
|
33 |
import java.lang.reflect.Field; |
30604
b8d532cb6420
8067013: Rename the com.oracle.java.testlibary package
ykantser
parents:
29678
diff
changeset
|
34 |
import jdk.test.lib.*; |
28732
d4b650e48a8f
8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff
changeset
|
35 |
import sun.misc.Unsafe; |
d4b650e48a8f
8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff
changeset
|
36 |
import java.lang.reflect.*; |
30604
b8d532cb6420
8067013: Rename the com.oracle.java.testlibary package
ykantser
parents:
29678
diff
changeset
|
37 |
import static jdk.test.lib.Asserts.*; |
28732
d4b650e48a8f
8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff
changeset
|
38 |
|
d4b650e48a8f
8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff
changeset
|
39 |
public class FieldOffset { |
d4b650e48a8f
8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff
changeset
|
40 |
public static void main(String args[]) throws Exception { |
d4b650e48a8f
8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff
changeset
|
41 |
Unsafe unsafe = Utils.getUnsafe(); |
28951
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28732
diff
changeset
|
42 |
Field[] fields = Test.class.getDeclaredFields(); |
28732
d4b650e48a8f
8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff
changeset
|
43 |
|
d4b650e48a8f
8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff
changeset
|
44 |
for (int i = 0; i < fields.length; i++) { |
28951
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28732
diff
changeset
|
45 |
long offset = unsafe.objectFieldOffset(fields[i]); |
28732
d4b650e48a8f
8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff
changeset
|
46 |
// Ensure we got a valid offset value back |
d4b650e48a8f
8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff
changeset
|
47 |
assertNotEquals(offset, unsafe.INVALID_FIELD_OFFSET); |
d4b650e48a8f
8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff
changeset
|
48 |
|
d4b650e48a8f
8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff
changeset
|
49 |
// Make sure the field offset is unique |
d4b650e48a8f
8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff
changeset
|
50 |
for (int j = 0; j < i; j++) { |
28951
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28732
diff
changeset
|
51 |
assertNotEquals(offset, unsafe.objectFieldOffset(fields[j])); |
28732
d4b650e48a8f
8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff
changeset
|
52 |
} |
d4b650e48a8f
8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff
changeset
|
53 |
} |
28951
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28732
diff
changeset
|
54 |
|
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28732
diff
changeset
|
55 |
fields = StaticTest.class.getDeclaredFields(); |
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28732
diff
changeset
|
56 |
for (int i = 0; i < fields.length; i++) { |
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28732
diff
changeset
|
57 |
long offset = unsafe.staticFieldOffset(fields[i]); |
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28732
diff
changeset
|
58 |
// Ensure we got a valid offset value back |
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28732
diff
changeset
|
59 |
assertNotEquals(offset, unsafe.INVALID_FIELD_OFFSET); |
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28732
diff
changeset
|
60 |
|
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28732
diff
changeset
|
61 |
// Make sure the field offset is unique |
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28732
diff
changeset
|
62 |
for (int j = 0; j < i; j++) { |
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28732
diff
changeset
|
63 |
assertNotEquals(offset, unsafe.staticFieldOffset(fields[j])); |
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28732
diff
changeset
|
64 |
} |
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28732
diff
changeset
|
65 |
} |
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28732
diff
changeset
|
66 |
|
28732
d4b650e48a8f
8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff
changeset
|
67 |
} |
d4b650e48a8f
8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff
changeset
|
68 |
|
d4b650e48a8f
8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff
changeset
|
69 |
class Test { |
d4b650e48a8f
8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff
changeset
|
70 |
boolean booleanField; |
d4b650e48a8f
8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff
changeset
|
71 |
byte byteField; |
d4b650e48a8f
8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff
changeset
|
72 |
char charField; |
d4b650e48a8f
8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff
changeset
|
73 |
double doubleField; |
d4b650e48a8f
8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff
changeset
|
74 |
float floatField; |
d4b650e48a8f
8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff
changeset
|
75 |
int intField; |
d4b650e48a8f
8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff
changeset
|
76 |
long longField; |
d4b650e48a8f
8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff
changeset
|
77 |
Object objectField; |
d4b650e48a8f
8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff
changeset
|
78 |
short shortField; |
d4b650e48a8f
8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff
changeset
|
79 |
} |
28951
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28732
diff
changeset
|
80 |
|
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28732
diff
changeset
|
81 |
static class StaticTest { |
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28732
diff
changeset
|
82 |
static boolean booleanField; |
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28732
diff
changeset
|
83 |
static byte byteField; |
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28732
diff
changeset
|
84 |
static char charField; |
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28732
diff
changeset
|
85 |
static double doubleField; |
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28732
diff
changeset
|
86 |
static float floatField; |
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28732
diff
changeset
|
87 |
static int intField; |
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28732
diff
changeset
|
88 |
static long longField; |
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28732
diff
changeset
|
89 |
static Object objectField; |
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28732
diff
changeset
|
90 |
static short shortField; |
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28732
diff
changeset
|
91 |
} |
a29d2048e16a
8068975: Remove deprecated methods on sun.misc.Unsafe and clean up native implementation
psandoz
parents:
28732
diff
changeset
|
92 |
|
28732
d4b650e48a8f
8069207: [TESTBUG] Exception thrown for java.lang.NoSuchMethodError: sun.misc.Unsafe.monitorExit
ctornqvi
parents:
diff
changeset
|
93 |
} |