1 /*
2 * Copyright (c) 2020, Red Hat, Inc. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /*
25 * @test
26 * @summary Test for Magic.addressOf with 32-bit compressed oops
27 * @library /test/lib
28 *
29 * @run main/othervm -Xmx128m
30 * -XX:+UnlockDiagnosticVMOptions -XX:+AbortVMOnCompilationFailure -Xcheck:jni
31 * -XX:CompileCommand=exclude,AddressOfStability::testInterpreted
32 * -Xint
33 * AddressOfStability
34 *
35 * @run main/othervm -Xmx128m
36 * -XX:+UnlockDiagnosticVMOptions -XX:+AbortVMOnCompilationFailure -Xcheck:jni
37 * -XX:CompileCommand=exclude,AddressOfStability::testInterpreted
38 * -XX:TieredStopAtLevel=1
39 * AddressOfStability
40 *
41 * @run main/othervm -Xmx128m
42 * -XX:+UnlockDiagnosticVMOptions -XX:+AbortVMOnCompilationFailure -Xcheck:jni
43 * -XX:CompileCommand=exclude,AddressOfStability::testInterpreted
44 * -XX:-TieredCompilation
45 * AddressOfStability
46 */
47
48 /*
49 * @test
50 * @summary Test for Magic.addressOf with zero-based compressed oops
51 * @library /test/lib
52 * @requires vm.bits == 64
53 *
54 * @run main/othervm -Xmx4g
55 * -XX:+UnlockDiagnosticVMOptions -XX:+AbortVMOnCompilationFailure -Xcheck:jni
56 * -XX:CompileCommand=exclude,AddressOfStability::testInterpreted
57 * -Xint
58 * AddressOfStability
59 *
60 * @run main/othervm -Xmx4g
61 * -XX:+UnlockDiagnosticVMOptions -XX:+AbortVMOnCompilationFailure -Xcheck:jni
62 * -XX:CompileCommand=exclude,AddressOfStability::testInterpreted
63 * -XX:TieredStopAtLevel=1
64 * AddressOfStability
65 *
66 * @run main/othervm -Xmx4g
67 * -XX:+UnlockDiagnosticVMOptions -XX:+AbortVMOnCompilationFailure -Xcheck:jni
68 * -XX:CompileCommand=exclude,AddressOfStability::testInterpreted
69 * -XX:-TieredCompilation
70 * AddressOfStability
71 */
72
73 /*
74 * @test
75 * @summary Test for Magic.addressOf without compressed oops
76 * @library /test/lib
77 * @requires vm.bits == 64
78 *
79 * @run main/othervm -Xmx128m -XX:-UseCompressedOops
80 * -XX:+UnlockDiagnosticVMOptions -XX:+AbortVMOnCompilationFailure -Xcheck:jni
81 * -XX:CompileCommand=exclude,AddressOfStability::testInterpreted
82 * -Xint
83 * AddressOfStability
84 *
85 * @run main/othervm -Xmx128m -XX:-UseCompressedOops
86 * -XX:+UnlockDiagnosticVMOptions -XX:+AbortVMOnCompilationFailure -Xcheck:jni
87 * -XX:CompileCommand=exclude,AddressOfStability::testInterpreted
88 * -XX:TieredStopAtLevel=1
89 * AddressOfStability
90 *
91 * @run main/othervm -Xmx128m -XX:-UseCompressedOops
92 * -XX:+UnlockDiagnosticVMOptions -XX:+AbortVMOnCompilationFailure -Xcheck:jni
93 * -XX:CompileCommand=exclude,AddressOfStability::testInterpreted
94 * -XX:-TieredCompilation
95 * AddressOfStability
96 */
97
98 import java.lang.reflect.Field;
99
100 import net.shipilev.Magic;
101
102 public class AddressOfStability {
103
104 public static void main(String ... args) throws Exception {
105 Object o = new Object();
106 for (int c = 0; c < MagicUtil.ITERS; c++) {
107 long addrInt1 = testInterpreted(o);
108 long addrComp = testCompiled(o);
109 long addrInt2 = testInterpreted(o);
110
111 if (addrInt1 == addrInt2) {
112 // No moves were detected, compare with compiled.
113 MagicUtil.assertEquals(addrInt1, addrComp);
114 }
115 }
116 }
117
118 private static long testCompiled(Object o) {
119 return Magic.addressOf(o);
120 }
121
122 private static long testInterpreted(Object o) {
123 return Magic.addressOf(o);
124 }
125
126 }