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; |
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 // Only c2 compilations can be disabled through PerMethodRecompilationCutoff |
|
75 if (!Platform.isServer()) { |
|
76 return; |
|
77 } |
|
78 |
69 if (skipXcompOSR()) { |
79 if (skipXcompOSR()) { |
70 return; |
80 return; |
71 } |
81 } |
72 if (!isCompilable()) { |
82 if (!isCompilable(COMP_LEVEL_FULL_OPTIMIZATION)) { |
73 throw new RuntimeException(method + " must be compilable"); |
83 throw new RuntimeException(method + " must be compilable"); |
74 } |
84 } |
75 System.out.println("PerMethodRecompilationCutoff = " |
85 System.out.println("PerMethodRecompilationCutoff = " |
76 + PER_METHOD_RECOMPILATION_CUTOFF); |
86 + PER_METHOD_RECOMPILATION_CUTOFF); |
77 if (PER_METHOD_RECOMPILATION_CUTOFF == -1) { |
87 if (PER_METHOD_RECOMPILATION_CUTOFF == -1) { |
78 System.err.println( |
88 System.err.println( |
79 "Warning: test is not applicable if PerMethodRecompilationCutoff == Inf"); |
89 "Warning: test is not applicable if PerMethodRecompilationCutoff == Inf"); |
80 return; |
90 return; |
81 } |
91 } |
82 |
92 |
83 // deoptimize 'PerMethodRecompilationCutoff' times and clear state |
93 // deoptimize 'PerMethodRecompilationCutoff' times |
84 for (long i = 0L, n = PER_METHOD_RECOMPILATION_CUTOFF - 1; i < n; ++i) { |
94 for (long attempts = 0, successes = 0; |
85 compileAndDeoptimize(); |
95 (successes < PER_METHOD_RECOMPILATION_CUTOFF) && |
|
96 (attempts < PER_METHOD_RECOMPILATION_CUTOFF*2) && |
|
97 isCompilable(COMP_LEVEL_FULL_OPTIMIZATION); attempts++) { |
|
98 if (compileAndDeoptimize() == COMP_LEVEL_FULL_OPTIMIZATION) { |
|
99 successes++; |
|
100 } |
86 } |
101 } |
87 if (!testCase.isOsr() && !isCompilable()) { |
102 |
|
103 if (!testCase.isOsr() && !isCompilable(COMP_LEVEL_FULL_OPTIMIZATION)) { |
88 // in osr test case count of deopt maybe more than iterations |
104 // in osr test case count of deopt maybe more than iterations |
89 throw new RuntimeException(method + " is not compilable after " |
105 throw new RuntimeException(method + " is not compilable after " |
90 + (PER_METHOD_RECOMPILATION_CUTOFF - 1) + " iterations"); |
106 + PER_METHOD_RECOMPILATION_CUTOFF + " iterations"); |
91 } |
107 } |
92 WHITE_BOX.clearMethodState(method); |
|
93 |
108 |
94 // deoptimize 'PerMethodRecompilationCutoff' + 1 times |
109 // Now compile once more |
95 long i; |
110 compileAndDeoptimize(); |
96 for (i = 0L; i < PER_METHOD_RECOMPILATION_CUTOFF |
111 |
97 && isCompilable(); ++i) { |
112 if (isCompilable(COMP_LEVEL_FULL_OPTIMIZATION)) { |
98 compileAndDeoptimize(); |
|
99 } |
|
100 if (!testCase.isOsr() && i != PER_METHOD_RECOMPILATION_CUTOFF) { |
|
101 // in osr test case count of deopt maybe more than iterations |
|
102 throw new RuntimeException(method + " is not compilable after " |
|
103 + i + " iterations, but must only after " |
|
104 + PER_METHOD_RECOMPILATION_CUTOFF); |
|
105 } |
|
106 if (isCompilable()) { |
|
107 throw new RuntimeException(method + " is still compilable after " |
113 throw new RuntimeException(method + " is still compilable after " |
108 + PER_METHOD_RECOMPILATION_CUTOFF + " iterations"); |
114 + PER_METHOD_RECOMPILATION_CUTOFF + " iterations"); |
109 } |
115 } |
|
116 checkNotCompiled(); |
110 compile(); |
117 compile(); |
111 checkNotCompiled(); |
118 waitBackgroundCompilation(); |
|
119 checkNotCompiled(COMP_LEVEL_FULL_OPTIMIZATION); |
112 |
120 |
113 // WB.clearMethodState() must reset no-compilable flags |
121 // WB.clearMethodState() must reset no-compilable flags |
114 WHITE_BOX.clearMethodState(method); |
122 WHITE_BOX.clearMethodState(method); |
115 if (!isCompilable()) { |
123 if (!isCompilable(COMP_LEVEL_FULL_OPTIMIZATION)) { |
116 throw new RuntimeException(method |
124 throw new RuntimeException(method |
117 + " is not compilable after clearMethodState()"); |
125 + " is not compilable after clearMethodState()"); |
118 } |
126 } |
119 compile(); |
127 compile(); |
120 checkCompiled(); |
128 checkCompiled(); |
121 } |
129 } |
122 |
130 |
123 private void compileAndDeoptimize() throws Exception { |
131 private int compileAndDeoptimize() throws Exception { |
124 compile(); |
132 compile(); |
125 waitBackgroundCompilation(); |
133 waitBackgroundCompilation(); |
|
134 int compLevel = getCompLevel(); |
126 deoptimize(); |
135 deoptimize(); |
|
136 return compLevel; |
127 } |
137 } |
128 } |
138 } |