annotate test/compiler/whitebox/CompilerWhiteBoxTest.java @ 9080:b84fd7d73702

8007288: Additional WB API for compiler's testing Reviewed-by: kvn, vlivanov
author iignatyev
date Tue, 09 Apr 2013 09:54:17 -0700
parents 4efac99a998b
children 4b2eebe03f93
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"));
8766
4efac99a998b 8008211: Some of WB tests on compiler fail
iignatyev
parents: 8051
diff changeset
38 protected static final boolean BACKGROUND_COMPILATION
4efac99a998b 8008211: Some of WB tests on compiler fail
iignatyev
parents: 8051
diff changeset
39 = Boolean.valueOf(getVMOption("BackgroundCompilation", "true"));
9080
b84fd7d73702 8007288: Additional WB API for compiler's testing
iignatyev
parents: 8766
diff changeset
40 protected static final boolean TIERED_COMPILATION
b84fd7d73702 8007288: Additional WB API for compiler's testing
iignatyev
parents: 8766
diff changeset
41 = Boolean.valueOf(getVMOption("TieredCompilation", "false"));
8051
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
42
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
43 protected static Method getMethod(String name) {
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
44 try {
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
45 return CompilerWhiteBoxTest.class.getDeclaredMethod(name);
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
46 } catch (NoSuchMethodException | SecurityException e) {
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
47 throw new RuntimeException(
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
48 "exception on getting method " + name, e);
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
49 }
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
50 }
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
51
8766
4efac99a998b 8008211: Some of WB tests on compiler fail
iignatyev
parents: 8051
diff changeset
52 protected static String getVMOption(String name) {
8051
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
53 String result;
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
54 HotSpotDiagnosticMXBean diagnostic
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
55 = ManagementFactoryHelper.getDiagnosticMXBean();
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
56 result = diagnostic.getVMOption(name).getValue();
8766
4efac99a998b 8008211: Some of WB tests on compiler fail
iignatyev
parents: 8051
diff changeset
57 return result;
4efac99a998b 8008211: Some of WB tests on compiler fail
iignatyev
parents: 8051
diff changeset
58 }
4efac99a998b 8008211: Some of WB tests on compiler fail
iignatyev
parents: 8051
diff changeset
59
4efac99a998b 8008211: Some of WB tests on compiler fail
iignatyev
parents: 8051
diff changeset
60 protected static String getVMOption(String name, String defaultValue) {
4efac99a998b 8008211: Some of WB tests on compiler fail
iignatyev
parents: 8051
diff changeset
61 String result = getVMOption(name);
8051
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
62 return result == null ? defaultValue : result;
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
63 }
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
64
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
65 protected final void runTest() throws RuntimeException {
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
66 if (ManagementFactoryHelper.getCompilationMXBean() == null) {
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
67 System.err.println(
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
68 "Warning: test is not applicable in interpreted mode");
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
69 return;
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 start:");
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 try {
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
74 test();
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
75 } catch (Exception e) {
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
76 System.out.printf("on exception '%s':", e.getMessage());
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
77 printInfo(METHOD);
8766
4efac99a998b 8008211: Some of WB tests on compiler fail
iignatyev
parents: 8051
diff changeset
78 e.printStackTrace();
8051
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
79 throw new RuntimeException(e);
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
80 }
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
81 System.out.println("at test's end:");
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
82 printInfo(METHOD);
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
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
85 protected static void checkNotCompiled(Method method) {
9080
b84fd7d73702 8007288: Additional WB API for compiler's testing
iignatyev
parents: 8766
diff changeset
86 if (WHITE_BOX.isMethodQueuedForCompilation(method)) {
b84fd7d73702 8007288: Additional WB API for compiler's testing
iignatyev
parents: 8766
diff changeset
87 throw new RuntimeException(method + " must not be in queue");
b84fd7d73702 8007288: Additional WB API for compiler's testing
iignatyev
parents: 8766
diff changeset
88 }
8051
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
89 if (WHITE_BOX.isMethodCompiled(method)) {
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
90 throw new RuntimeException(method + " must be not compiled");
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
91 }
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
92 if (WHITE_BOX.getMethodCompilationLevel(method) != 0) {
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
93 throw new RuntimeException(method + " comp_level must be == 0");
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
94 }
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
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
97 protected static void checkCompiled(Method method)
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
98 throws InterruptedException {
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
99 final long start = System.currentTimeMillis();
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
100 waitBackgroundCompilation(method);
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
101 if (WHITE_BOX.isMethodQueuedForCompilation(method)) {
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
102 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
103 method, System.currentTimeMillis() - start);
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
104 return;
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
105 }
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
106 if (!WHITE_BOX.isMethodCompiled(method)) {
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
107 throw new RuntimeException(method + " must be compiled");
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 if (WHITE_BOX.getMethodCompilationLevel(method) == 0) {
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
110 throw new RuntimeException(method + " comp_level must be != 0");
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 waitBackgroundCompilation(Method method)
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
115 throws InterruptedException {
8766
4efac99a998b 8008211: Some of WB tests on compiler fail
iignatyev
parents: 8051
diff changeset
116 if (!BACKGROUND_COMPILATION) {
4efac99a998b 8008211: Some of WB tests on compiler fail
iignatyev
parents: 8051
diff changeset
117 return;
4efac99a998b 8008211: Some of WB tests on compiler fail
iignatyev
parents: 8051
diff changeset
118 }
8051
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
119 final Object obj = new Object();
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
120 synchronized (obj) {
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
121 for (int i = 0; i < 10; ++i) {
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
122 if (!WHITE_BOX.isMethodQueuedForCompilation(method)) {
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
123 break;
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
124 }
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
125 obj.wait(1000);
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 }
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 static void printInfo(Method method) {
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
131 System.out.printf("%n%s:%n", method);
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
132 System.out.printf("\tcompilable:\t%b%n",
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
133 WHITE_BOX.isMethodCompilable(method));
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
134 System.out.printf("\tcompiled:\t%b%n",
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
135 WHITE_BOX.isMethodCompiled(method));
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
136 System.out.printf("\tcomp_level:\t%d%n",
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
137 WHITE_BOX.getMethodCompilationLevel(method));
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
138 System.out.printf("\tin_queue:\t%b%n",
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
139 WHITE_BOX.isMethodQueuedForCompilation(method));
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
140 System.out.printf("compile_queues_size:\t%d%n%n",
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
141 WHITE_BOX.getCompileQueuesSize());
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
142 }
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
143
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
144 protected abstract void test() throws Exception;
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
145
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
146 protected final int compile() {
9080
b84fd7d73702 8007288: Additional WB API for compiler's testing
iignatyev
parents: 8766
diff changeset
147 return compile(Math.max(COMPILE_THRESHOLD, 150000));
b84fd7d73702 8007288: Additional WB API for compiler's testing
iignatyev
parents: 8766
diff changeset
148 }
b84fd7d73702 8007288: Additional WB API for compiler's testing
iignatyev
parents: 8766
diff changeset
149
b84fd7d73702 8007288: Additional WB API for compiler's testing
iignatyev
parents: 8766
diff changeset
150 protected final int compile(int count) {
8051
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
151 int result = 0;
8766
4efac99a998b 8008211: Some of WB tests on compiler fail
iignatyev
parents: 8051
diff changeset
152 for (int i = 0; i < count; ++i) {
8051
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
153 result += method();
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
154 }
8766
4efac99a998b 8008211: Some of WB tests on compiler fail
iignatyev
parents: 8051
diff changeset
155 System.out.println("method was invoked " + count + " times");
8051
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
156 return result;
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
157 }
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
158
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
159 protected int method() {
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
160 return 42;
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
161 }
12e01444ca2d 8006683: Add WhiteBox API to testing of compiler
iignatyev
parents:
diff changeset
162 }