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 /*
26 * @test
27 * @ignore
28 * @library /test/lib /
29 * @build jdk.test.whitebox.WhiteBox
30 * @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
31 * @run main/othervm -Xbootclasspath/a:. -Xbatch -XX:-TieredCompilation -XX:+SegmentedCodeCache -XX:+UnlockExperimentalVMOptions -XX:+HotCodeHeap
32 * -XX:+NMethodRelocation -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:HotCodeIntervalSeconds=0 -XX:HotCodeCallLevel=0
33 * -XX:HotCodeSampleSeconds=5 -XX:HotCodeStablePercent=-1 -XX:HotCodeSamplePercent=100 -XX:HotCodeStartupDelaySeconds=0
34 * -XX:CompileCommand=compileonly,compiler.hotcode.HotCodeCollectorMoveFunction::func
35 * compiler.hotcode.HotCodeCollectorMoveFunction
36 */
37
38 package compiler.hotcode;
39
40 import java.lang.reflect.Method;
41
42 import jdk.test.lib.Asserts;
43 import jdk.test.whitebox.WhiteBox;
44 import jdk.test.whitebox.code.BlobType;
45 import jdk.test.whitebox.code.NMethod;
46
47 public class HotCodeCollectorMoveFunction {
48
49 private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();
50 private static final Method method;
51 private static final int C2_LEVEL = 4;
52 private static final int FUNC_RUN_MILLIS = 60_000;
53
54 static {
55 try {
56 method = HotCodeCollectorMoveFunction.class.getMethod("func");
57 } catch (NoSuchMethodException e) {
58 throw new RuntimeException(e);
59 }
60 }
61
62 public static void main(String[] args) throws Exception {
63 WHITE_BOX.testSetDontInlineMethod(method, true);
64
65 compileFunc();
66
67 // Call function so collector samples and relocates
68 func();
69
70 // Function should now be in the Hot code heap after collector has had time to relocate
71 NMethod reloc_nm = NMethod.get(method, false);
72 Asserts.assertNotEquals(reloc_nm, null);
73 Asserts.assertEQ(reloc_nm.code_blob_type, BlobType.MethodHot);
74 }
75
76 public static void compileFunc() {
77 WHITE_BOX.enqueueMethodForCompilation(method, C2_LEVEL);
78
79 if (WHITE_BOX.getMethodCompilationLevel(method) != C2_LEVEL) {
80 throw new IllegalStateException("Method " + method + " is not compiled by C2.");
81 }
82 }
83
84 public static void func() {
85 long start = System.currentTimeMillis();
86 while (System.currentTimeMillis() - start < FUNC_RUN_MILLIS) {}
87 }
88
89 }