79 #else 80 Unimplemented(); 81 #endif 82 break; 83 default: 84 fatal("CompilationPolicyChoice must be in the range: [0-3]"); 85 } 86 CompilationPolicy::policy()->initialize(); 87 } 88 89 void CompilationPolicy::completed_vm_startup() { 90 if (TraceCompilationPolicy) { 91 tty->print("CompilationPolicy: completed vm startup.\n"); 92 } 93 _in_vm_startup = false; 94 } 95 96 // Returns true if m must be compiled before executing it 97 // This is intended to force compiles for methods (usually for 98 // debugging) that would otherwise be interpreted for some reason. 99 bool CompilationPolicy::must_be_compiled(methodHandle m, int comp_level) { 100 // Don't allow Xcomp to cause compiles in replay mode 101 if (ReplayCompiles) return false; 102 103 if (m->has_compiled_code()) return false; // already compiled 104 if (!can_be_compiled(m, comp_level)) return false; 105 106 return !UseInterpreter || // must compile all methods 107 (UseCompiler && AlwaysCompileLoopMethods && m->has_loops() && CompileBroker::should_compile_new_jobs()); // eagerly compile loop methods 108 } 109 110 void CompilationPolicy::compile_if_required(methodHandle selected_method, TRAPS) { 111 if (must_be_compiled(selected_method)) { 112 // This path is unusual, mostly used by the '-Xcomp' stress test mode. 113 114 // Note: with several active threads, the must_be_compiled may be true 115 // while can_be_compiled is false; remove assert 116 // assert(CompilationPolicy::can_be_compiled(selected_method), "cannot compile"); 117 if (!THREAD->can_call_java() || THREAD->is_Compiler_thread()) { 118 // don't force compilation, resolve was on behalf of compiler 119 return; 120 } 121 if (selected_method->method_holder()->is_not_initialized()) { 122 // 'is_not_initialized' means not only '!is_initialized', but also that 123 // initialization has not been started yet ('!being_initialized') 124 // Do not force compilation of methods in uninitialized classes. 125 // Note that doing this would throw an assert later, 126 // in CompileBroker::compile_method. 127 // We sometimes use the link resolver to do reflective lookups 128 // even before classes are initialized. 129 return; 130 } 131 CompileBroker::compile_method(selected_method, InvocationEntryBci, 132 CompilationPolicy::policy()->initial_compile_level(), 133 methodHandle(), 0, CompileTask::Reason_MustBeCompiled, CHECK); 134 } 135 } 136 137 // Returns true if m is allowed to be compiled 138 bool CompilationPolicy::can_be_compiled(methodHandle m, int comp_level) { 139 // allow any levels for WhiteBox 140 assert(WhiteBoxAPI || comp_level == CompLevel_all || is_compile(comp_level), "illegal compilation level"); 141 142 if (m->is_abstract()) return false; 143 if (DontCompileHugeMethods && m->code_size() > HugeMethodLimit) return false; 144 145 // Math intrinsics should never be compiled as this can lead to 146 // monotonicity problems because the interpreter will prefer the 147 // compiled code to the intrinsic version. This can't happen in 148 // production because the invocation counter can't be incremented 149 // but we shouldn't expose the system to this problem in testing 150 // modes. 151 if (!AbstractInterpreter::can_be_compiled(m)) { 152 return false; 153 } 154 if (comp_level == CompLevel_all) { 155 if (TieredCompilation) { 156 // enough to be compilable at any level for tiered 157 return !m->is_not_compilable(CompLevel_simple) || !m->is_not_compilable(CompLevel_full_optimization); 158 } else { 159 // must be compilable at available level for non-tiered 160 return !m->is_not_compilable(CompLevel_highest_tier); 161 } 162 } else if (is_compile(comp_level)) { 163 return !m->is_not_compilable(comp_level); 164 } 165 return false; 166 } 167 168 // Returns true if m is allowed to be osr compiled 169 bool CompilationPolicy::can_be_osr_compiled(methodHandle m, int comp_level) { 170 bool result = false; 171 if (comp_level == CompLevel_all) { 172 if (TieredCompilation) { 173 // enough to be osr compilable at any level for tiered 174 result = !m->is_not_osr_compilable(CompLevel_simple) || !m->is_not_osr_compilable(CompLevel_full_optimization); 175 } else { 176 // must be osr compilable at available level for non-tiered 177 result = !m->is_not_osr_compilable(CompLevel_highest_tier); 178 } 179 } else if (is_compile(comp_level)) { 180 result = !m->is_not_osr_compilable(comp_level); 181 } 182 return (result && can_be_compiled(m, comp_level)); 183 } 184 185 bool CompilationPolicy::is_compilation_enabled() { 186 // NOTE: CompileBroker::should_compile_new_jobs() checks for UseCompiler 187 return !delay_compilation_during_startup() && CompileBroker::should_compile_new_jobs(); 188 } 189 | 79 #else 80 Unimplemented(); 81 #endif 82 break; 83 default: 84 fatal("CompilationPolicyChoice must be in the range: [0-3]"); 85 } 86 CompilationPolicy::policy()->initialize(); 87 } 88 89 void CompilationPolicy::completed_vm_startup() { 90 if (TraceCompilationPolicy) { 91 tty->print("CompilationPolicy: completed vm startup.\n"); 92 } 93 _in_vm_startup = false; 94 } 95 96 // Returns true if m must be compiled before executing it 97 // This is intended to force compiles for methods (usually for 98 // debugging) that would otherwise be interpreted for some reason. 99 bool CompilationPolicy::must_be_compiled(const methodHandle& m, int comp_level) { 100 // Don't allow Xcomp to cause compiles in replay mode 101 if (ReplayCompiles) return false; 102 103 if (m->has_compiled_code()) return false; // already compiled 104 if (!can_be_compiled(m, comp_level)) return false; 105 106 return !UseInterpreter || // must compile all methods 107 (UseCompiler && AlwaysCompileLoopMethods && m->has_loops() && CompileBroker::should_compile_new_jobs()); // eagerly compile loop methods 108 } 109 110 void CompilationPolicy::compile_if_required(const methodHandle& selected_method, TRAPS) { 111 if (must_be_compiled(selected_method)) { 112 // This path is unusual, mostly used by the '-Xcomp' stress test mode. 113 114 // Note: with several active threads, the must_be_compiled may be true 115 // while can_be_compiled is false; remove assert 116 // assert(CompilationPolicy::can_be_compiled(selected_method), "cannot compile"); 117 if (!THREAD->can_call_java() || THREAD->is_Compiler_thread()) { 118 // don't force compilation, resolve was on behalf of compiler 119 return; 120 } 121 if (selected_method->method_holder()->is_not_initialized()) { 122 // 'is_not_initialized' means not only '!is_initialized', but also that 123 // initialization has not been started yet ('!being_initialized') 124 // Do not force compilation of methods in uninitialized classes. 125 // Note that doing this would throw an assert later, 126 // in CompileBroker::compile_method. 127 // We sometimes use the link resolver to do reflective lookups 128 // even before classes are initialized. 129 return; 130 } 131 CompileBroker::compile_method(selected_method, InvocationEntryBci, 132 CompilationPolicy::policy()->initial_compile_level(), 133 methodHandle(), 0, CompileTask::Reason_MustBeCompiled, CHECK); 134 } 135 } 136 137 // Returns true if m is allowed to be compiled 138 bool CompilationPolicy::can_be_compiled(const methodHandle& m, int comp_level) { 139 // allow any levels for WhiteBox 140 assert(WhiteBoxAPI || comp_level == CompLevel_all || is_compile(comp_level), "illegal compilation level"); 141 142 if (m->is_abstract()) return false; 143 if (DontCompileHugeMethods && m->code_size() > HugeMethodLimit) return false; 144 145 // Math intrinsics should never be compiled as this can lead to 146 // monotonicity problems because the interpreter will prefer the 147 // compiled code to the intrinsic version. This can't happen in 148 // production because the invocation counter can't be incremented 149 // but we shouldn't expose the system to this problem in testing 150 // modes. 151 if (!AbstractInterpreter::can_be_compiled(m)) { 152 return false; 153 } 154 if (comp_level == CompLevel_all) { 155 if (TieredCompilation) { 156 // enough to be compilable at any level for tiered 157 return !m->is_not_compilable(CompLevel_simple) || !m->is_not_compilable(CompLevel_full_optimization); 158 } else { 159 // must be compilable at available level for non-tiered 160 return !m->is_not_compilable(CompLevel_highest_tier); 161 } 162 } else if (is_compile(comp_level)) { 163 return !m->is_not_compilable(comp_level); 164 } 165 return false; 166 } 167 168 // Returns true if m is allowed to be osr compiled 169 bool CompilationPolicy::can_be_osr_compiled(const methodHandle& m, int comp_level) { 170 bool result = false; 171 if (comp_level == CompLevel_all) { 172 if (TieredCompilation) { 173 // enough to be osr compilable at any level for tiered 174 result = !m->is_not_osr_compilable(CompLevel_simple) || !m->is_not_osr_compilable(CompLevel_full_optimization); 175 } else { 176 // must be osr compilable at available level for non-tiered 177 result = !m->is_not_osr_compilable(CompLevel_highest_tier); 178 } 179 } else if (is_compile(comp_level)) { 180 result = !m->is_not_osr_compilable(comp_level); 181 } 182 return (result && can_be_compiled(m, comp_level)); 183 } 184 185 bool CompilationPolicy::is_compilation_enabled() { 186 // NOTE: CompileBroker::should_compile_new_jobs() checks for UseCompiler 187 return !delay_compilation_during_startup() && CompileBroker::should_compile_new_jobs(); 188 } 189 |