comparison test/compiler/whitebox/IsMethodCompilableTest.java @ 14661:bbfe3ac1471d

8007270: Make IsMethodCompilable test work with tiered Summary: Only c2 compiles counts toward cutoff Reviewed-by: kvn, roland
author neliasso
date Tue, 28 Jan 2014 15:05:46 +0100
parents f9a4b59ae350
children 2dfa56e10640
comparison
equal deleted inserted replaced
14660:3c6ae9109a86 14661:bbfe3ac1471d
22 */ 22 */
23 23
24 /* 24 /*
25 * @test IsMethodCompilableTest 25 * @test IsMethodCompilableTest
26 * @bug 8007270 8006683 8007288 8022832 26 * @bug 8007270 8006683 8007288 8022832
27 * @library /testlibrary /testlibrary/whitebox 27 * @library /testlibrary /testlibrary/whitebox /testlibrary/com/oracle/java/testlibrary
28 * @build IsMethodCompilableTest 28 * @build IsMethodCompilableTest
29 * @run main ClassFileInstaller sun.hotspot.WhiteBox 29 * @run main ClassFileInstaller sun.hotspot.WhiteBox
30 * @run main/othervm/timeout=2400 -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:CompileCommand=compileonly,SimpleTestCase$Helper::* IsMethodCompilableTest 30 * @run main ClassFileInstaller com.oracle.java.testlibrary.Platform
31 * @run main/othervm/timeout=2400 -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:PerMethodRecompilationCutoff=3 -XX:CompileCommand=compileonly,SimpleTestCase$Helper::* IsMethodCompilableTest
31 * @summary testing of WB::isMethodCompilable() 32 * @summary testing of WB::isMethodCompilable()
32 * @author igor.ignatyev@oracle.com 33 * @author igor.ignatyev@oracle.com
33 */ 34 */
35
36 import com.oracle.java.testlibrary.Platform;
37
34 public class IsMethodCompilableTest extends CompilerWhiteBoxTest { 38 public class IsMethodCompilableTest extends CompilerWhiteBoxTest {
35 /** 39 /**
36 * Value of {@code -XX:PerMethodRecompilationCutoff} 40 * Value of {@code -XX:PerMethodRecompilationCutoff}
37 */ 41 */
38 protected static final long PER_METHOD_RECOMPILATION_CUTOFF; 42 protected static final long PER_METHOD_RECOMPILATION_CUTOFF;
41 long tmp = Long.parseLong( 45 long tmp = Long.parseLong(
42 getVMOption("PerMethodRecompilationCutoff", "400")); 46 getVMOption("PerMethodRecompilationCutoff", "400"));
43 if (tmp == -1) { 47 if (tmp == -1) {
44 PER_METHOD_RECOMPILATION_CUTOFF = -1 /* Inf */; 48 PER_METHOD_RECOMPILATION_CUTOFF = -1 /* Inf */;
45 } else { 49 } else {
46 PER_METHOD_RECOMPILATION_CUTOFF = 1 + (0xFFFFFFFFL & tmp); 50 PER_METHOD_RECOMPILATION_CUTOFF = (0xFFFFFFFFL & tmp);
47 } 51 }
48 } 52 }
49 53
50 public static void main(String[] args) throws Exception { 54 public static void main(String[] args) throws Exception {
51 CompilerWhiteBoxTest.main(IsMethodCompilableTest::new, args); 55 CompilerWhiteBoxTest.main(IsMethodCompilableTest::new, args);
58 } 62 }
59 63
60 /** 64 /**
61 * Tests {@code WB::isMethodCompilable()} by recompilation of tested method 65 * Tests {@code WB::isMethodCompilable()} by recompilation of tested method
62 * 'PerMethodRecompilationCutoff' times and checks compilation status. Also 66 * 'PerMethodRecompilationCutoff' times and checks compilation status. Also
63 * checks that WB::clearMethodState() clears no-compilable flags. 67 * checks that WB::clearMethodState() clears no-compilable flags. Only
68 * applicable to c2 compiled methods.
64 * 69 *
65 * @throws Exception if one of the checks fails. 70 * @throws Exception if one of the checks fails.
66 */ 71 */
67 @Override 72 @Override
68 protected void test() throws Exception { 73 protected void test() throws Exception {
74
75 // Only c2 compilations can be disabled through PerMethodRecompilationCutoff
76 if (!Platform.isServer()) {
77 return;
78 }
79
69 if (testCase.isOsr() && CompilerWhiteBoxTest.MODE.startsWith( 80 if (testCase.isOsr() && CompilerWhiteBoxTest.MODE.startsWith(
70 "compiled ")) { 81 "compiled ")) {
71 System.err.printf("Warning: %s is not applicable in %s%n", 82 System.err.printf("Warning: %s is not applicable in %s%n",
72 testCase.name(), CompilerWhiteBoxTest.MODE); 83 testCase.name(), CompilerWhiteBoxTest.MODE);
73 return; 84 return;
74 } 85 }
75 if (!isCompilable()) { 86 if (!isCompilable(COMP_LEVEL_FULL_OPTIMIZATION)) {
76 throw new RuntimeException(method + " must be compilable"); 87 throw new RuntimeException(method + " must be compilable");
77 } 88 }
78 System.out.println("PerMethodRecompilationCutoff = " 89 System.out.println("PerMethodRecompilationCutoff = "
79 + PER_METHOD_RECOMPILATION_CUTOFF); 90 + PER_METHOD_RECOMPILATION_CUTOFF);
80 if (PER_METHOD_RECOMPILATION_CUTOFF == -1) { 91 if (PER_METHOD_RECOMPILATION_CUTOFF == -1) {
81 System.err.println( 92 System.err.println(
82 "Warning: test is not applicable if PerMethodRecompilationCutoff == Inf"); 93 "Warning: test is not applicable if PerMethodRecompilationCutoff == Inf");
83 return; 94 return;
84 } 95 }
85 96
86 // deoptimize 'PerMethodRecompilationCutoff' times and clear state 97 // deoptimize 'PerMethodRecompilationCutoff' times
87 for (long i = 0L, n = PER_METHOD_RECOMPILATION_CUTOFF - 1; i < n; ++i) { 98 for (long attempts = 0, successes = 0;
88 compileAndDeoptimize(); 99 (successes < PER_METHOD_RECOMPILATION_CUTOFF) &&
100 (attempts < PER_METHOD_RECOMPILATION_CUTOFF*2) &&
101 isCompilable(COMP_LEVEL_FULL_OPTIMIZATION); attempts++) {
102 if (compileAndDeoptimize() == COMP_LEVEL_FULL_OPTIMIZATION) {
103 successes++;
104 }
89 } 105 }
90 if (!testCase.isOsr() && !isCompilable()) { 106
107 if (!testCase.isOsr() && !isCompilable(COMP_LEVEL_FULL_OPTIMIZATION)) {
91 // in osr test case count of deopt maybe more than iterations 108 // in osr test case count of deopt maybe more than iterations
92 throw new RuntimeException(method + " is not compilable after " 109 throw new RuntimeException(method + " is not compilable after "
93 + (PER_METHOD_RECOMPILATION_CUTOFF - 1) + " iterations"); 110 + PER_METHOD_RECOMPILATION_CUTOFF + " iterations");
94 } 111 }
95 WHITE_BOX.clearMethodState(method);
96 112
97 // deoptimize 'PerMethodRecompilationCutoff' + 1 times 113 // Now compile once more
98 long i; 114 compileAndDeoptimize();
99 for (i = 0L; i < PER_METHOD_RECOMPILATION_CUTOFF 115
100 && isCompilable(); ++i) { 116 if (isCompilable(COMP_LEVEL_FULL_OPTIMIZATION)) {
101 compileAndDeoptimize();
102 }
103 if (!testCase.isOsr() && i != PER_METHOD_RECOMPILATION_CUTOFF) {
104 // in osr test case count of deopt maybe more than iterations
105 throw new RuntimeException(method + " is not compilable after "
106 + i + " iterations, but must only after "
107 + PER_METHOD_RECOMPILATION_CUTOFF);
108 }
109 if (isCompilable()) {
110 throw new RuntimeException(method + " is still compilable after " 117 throw new RuntimeException(method + " is still compilable after "
111 + PER_METHOD_RECOMPILATION_CUTOFF + " iterations"); 118 + PER_METHOD_RECOMPILATION_CUTOFF + " iterations");
112 } 119 }
120 checkNotCompiled();
113 compile(); 121 compile();
114 checkNotCompiled(); 122 waitBackgroundCompilation();
123 checkNotCompiled(COMP_LEVEL_FULL_OPTIMIZATION);
115 124
116 // WB.clearMethodState() must reset no-compilable flags 125 // WB.clearMethodState() must reset no-compilable flags
117 WHITE_BOX.clearMethodState(method); 126 WHITE_BOX.clearMethodState(method);
118 if (!isCompilable()) { 127 if (!isCompilable(COMP_LEVEL_FULL_OPTIMIZATION)) {
119 throw new RuntimeException(method 128 throw new RuntimeException(method
120 + " is not compilable after clearMethodState()"); 129 + " is not compilable after clearMethodState()");
121 } 130 }
122 compile(); 131 compile();
123 checkCompiled(); 132 checkCompiled();
124 } 133 }
125 134
126 private void compileAndDeoptimize() throws Exception { 135 private int compileAndDeoptimize() throws Exception {
127 compile(); 136 compile();
128 waitBackgroundCompilation(); 137 waitBackgroundCompilation();
138 int compLevel = getCompLevel();
129 deoptimize(); 139 deoptimize();
140 return compLevel;
130 } 141 }
131 } 142 }