annotate test/compiler/whitebox/CompilerWhiteBoxTest.java @ 8051:12e01444ca2d

8006683: Add WhiteBox API to testing of compiler Reviewed-by: kvn, vlivanov
author iignatyev
date Wed, 13 Feb 2013 08:29:04 -0800
parents
children 4efac99a998b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8051
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
1 /*
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
4 *
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
7 * published by the Free Software Foundation.
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
8 *
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
13 * accompanied this code).
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
14 *
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
18 *
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
21 * questions.
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
22 */
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
23
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
24 import sun.hotspot.WhiteBox;
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
25 import sun.management.ManagementFactoryHelper;
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
26 import com.sun.management.HotSpotDiagnosticMXBean;
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
27
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
28 import java.lang.reflect.Method;
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
29
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
30 /*
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
31 * @author igor.ignatyev@oracle.com
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
32 */
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
33 public abstract class CompilerWhiteBoxTest {
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
34 protected static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
35 protected static final Method METHOD = getMethod("method");
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
36 protected static final int COMPILE_THRESHOLD
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
37 = Integer.parseInt(getVMOption("CompileThreshold", "10000"));
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
38
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
39 protected static Method getMethod(String name) {
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
40 try {
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
41 return CompilerWhiteBoxTest.class.getDeclaredMethod(name);
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
42 } catch (NoSuchMethodException | SecurityException e) {
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
43 throw new RuntimeException(
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
44 "exception on getting method " + name, e);
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
45 }
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
46 }
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
47
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
48 protected static String getVMOption(String name, String defaultValue) {
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
49 String result;
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
50 HotSpotDiagnosticMXBean diagnostic
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
51 = ManagementFactoryHelper.getDiagnosticMXBean();
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
52 result = diagnostic.getVMOption(name).getValue();
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
53 return result == null ? defaultValue : result;
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
54 }
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
55
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
56 protected final void runTest() throws RuntimeException {
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
57 if (ManagementFactoryHelper.getCompilationMXBean() == null) {
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
58 System.err.println(
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
59 "Warning: test is not applicable in interpreted mode");
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
60 return;
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
61 }
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
62 System.out.println("at test's start:");
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
63 printInfo(METHOD);
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
64 try {
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
65 test();
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
66 } catch (Exception e) {
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
67 System.out.printf("on exception '%s':", e.getMessage());
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
68 printInfo(METHOD);
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
69 throw new RuntimeException(e);
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
70 }
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
71 System.out.println("at test's end:");
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
72 printInfo(METHOD);
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
73 }
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
74
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
75 protected static void checkNotCompiled(Method method) {
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
76 if (WHITE_BOX.isMethodCompiled(method)) {
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
77 throw new RuntimeException(method + " must be not compiled");
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
78 }
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
79 if (WHITE_BOX.getMethodCompilationLevel(method) != 0) {
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
80 throw new RuntimeException(method + " comp_level must be == 0");
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
81 }
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
82 }
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
83
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
84 protected static void checkCompiled(Method method)
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
85 throws InterruptedException {
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
86 final long start = System.currentTimeMillis();
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
87 waitBackgroundCompilation(method);
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
88 if (WHITE_BOX.isMethodQueuedForCompilation(method)) {
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
89 System.err.printf("Warning: %s is still in queue after %dms%n",
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
90 method, System.currentTimeMillis() - start);
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
91 return;
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
92 }
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
93 if (!WHITE_BOX.isMethodCompiled(method)) {
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
94 throw new RuntimeException(method + " must be compiled");
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
95 }
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
96 if (WHITE_BOX.getMethodCompilationLevel(method) == 0) {
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
97 throw new RuntimeException(method + " comp_level must be != 0");
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
98 }
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
99 }
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
100
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
101 protected static void waitBackgroundCompilation(Method method)
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
102 throws InterruptedException {
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
103 final Object obj = new Object();
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
104 synchronized (obj) {
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
105 for (int i = 0; i < 10; ++i) {
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
106 if (!WHITE_BOX.isMethodQueuedForCompilation(method)) {
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
107 break;
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
108 }
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
109 obj.wait(1000);
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
110 }
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
111 }
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
112 }
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
113
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
114 protected static void printInfo(Method method) {
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
115 System.out.printf("%n%s:%n", method);
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
116 System.out.printf("\tcompilable:\t%b%n",
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
117 WHITE_BOX.isMethodCompilable(method));
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
118 System.out.printf("\tcompiled:\t%b%n",
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
119 WHITE_BOX.isMethodCompiled(method));
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
120 System.out.printf("\tcomp_level:\t%d%n",
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
121 WHITE_BOX.getMethodCompilationLevel(method));
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
122 System.out.printf("\tin_queue:\t%b%n",
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
123 WHITE_BOX.isMethodQueuedForCompilation(method));
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
124 System.out.printf("compile_queues_size:\t%d%n%n",
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
125 WHITE_BOX.getCompileQueuesSize());
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
126 }
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
127
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
128 protected abstract void test() throws Exception;
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
129
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
130 protected final int compile() {
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
131 int result = 0;
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
132 for (int i = 0; i < COMPILE_THRESHOLD; ++i) {
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
133 result += method();
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
134 }
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
135 return result;
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
136 }
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
137
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
138
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
139 protected int method() {
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
140 return 42;
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
141 }
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
142 }