1 /*
2 * Copyright Amazon.com Inc. or its affiliates. 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 * @ignore
27 * @bug 8316694
28 * @summary Verify that nmethod relocation posts the correct JVMTI events
29 * @requires vm.jvmti &
30 * vm.gc != "Epsilon" &
31 * vm.flavor == "server" &
32 * (vm.opt.TieredStopAtLevel == null | vm.opt.TieredStopAtLevel == 4) &
33 * vm.compMode == "Xmixed"
34 * @library /test/lib /test/hotspot/jtreg
35 * @build jdk.test.whitebox.WhiteBox
36 * @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
37 * @run main/othervm/native -agentlib:NMethodRelocationTest
38 * --enable-native-access=ALL-UNNAMED
39 * -Xbootclasspath/a:.
40 * -Xbatch
41 * -XX:+UnlockDiagnosticVMOptions
42 * -XX:+WhiteBoxAPI
43 * -XX:+SegmentedCodeCache
44 * -XX:-TieredCompilation
45 * -XX:+UnlockExperimentalVMOptions
46 * -XX:+NMethodRelocation
47 * NMethodRelocationTest
48 */
49
50 import java.lang.reflect.Executable;
51
52 import jdk.test.lib.Asserts;
53 import jdk.test.lib.process.OutputAnalyzer;
54 import jdk.test.lib.process.ProcessTools;
55 import jdk.test.whitebox.WhiteBox;
56 import jdk.test.whitebox.code.BlobType;
57 import jdk.test.whitebox.code.NMethod;
58
59 import static compiler.whitebox.CompilerWhiteBoxTest.COMP_LEVEL_FULL_OPTIMIZATION;
60
61 public class NMethodRelocationTest {
62
63 /** Load native library if required. */
64 static {
65 try {
66 System.loadLibrary("NMethodRelocationTest");
67 } catch (UnsatisfiedLinkError ule) {
68 System.err.println("Could not load NMethodRelocationTest library");
69 System.err.println("java.library.path: "
70 + System.getProperty("java.library.path"));
71 throw ule;
72 }
73 }
74
75 protected static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();
76
77 native static boolean shouldExit();
78
79 public static void main(String[] argv) throws Exception {
80 Executable method = NMethodRelocationTest.class.getDeclaredMethod("compiledMethod");
81 WHITE_BOX.testSetDontInlineMethod(method, true);
82
83 WHITE_BOX.enqueueMethodForCompilation(method, COMP_LEVEL_FULL_OPTIMIZATION);
84
85 if (!WHITE_BOX.isMethodCompiled(method)) {
86 throw new AssertionError("Method not compiled");
87 }
88
89 NMethod originalNMethod = NMethod.get(method, false);
90 if (originalNMethod == null) {
91 throw new AssertionError("Could not find original nmethod");
92 }
93
94 WHITE_BOX.relocateNMethodFromMethod(method, BlobType.MethodNonProfiled.id);
95
96 NMethod relocatedNMethod = NMethod.get(method, false);
97 if (relocatedNMethod == null) {
98 throw new AssertionError("Could not find relocated nmethod");
99 }
100
101 if (originalNMethod.address == relocatedNMethod.address) {
102 throw new AssertionError("Relocated nmethod same as original");
103 }
104
105 WHITE_BOX.deoptimizeAll();
106
107 while (!shouldExit()) {
108 WHITE_BOX.fullGC();
109 }
110 }
111
112 public static long compiledMethod() {
113 return 0;
114 }
115 }