< prev index next >

src/hotspot/share/opto/c2compiler.cpp

Print this page

  7  * published by the Free Software Foundation.
  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  *
 23  */
 24 
 25 #include "precompiled.hpp"
 26 #include "classfile/vmClasses.hpp"

 27 #include "compiler/compilationMemoryStatistic.hpp"
 28 #include "compiler/compilerDefinitions.inline.hpp"
 29 #include "runtime/handles.inline.hpp"
 30 #include "jfr/support/jfrIntrinsics.hpp"
 31 #include "opto/c2compiler.hpp"
 32 #include "opto/compile.hpp"
 33 #include "opto/optoreg.hpp"
 34 #include "opto/output.hpp"
 35 #include "opto/runtime.hpp"
 36 #include "runtime/stubRoutines.hpp"
 37 #include "runtime/globals_extension.hpp"
 38 #include "utilities/macros.hpp"
 39 
 40 
 41 // register information defined by ADLC
 42 extern const char register_save_policy[];
 43 extern const int  register_save_type[];
 44 
 45 const char* C2Compiler::retry_no_subsuming_loads() {
 46   return "retry without subsuming loads";
 47 }
 48 const char* C2Compiler::retry_no_escape_analysis() {
 49   return "retry without escape analysis";
 50 }
 51 const char* C2Compiler::retry_no_locks_coarsening() {
 52   return "retry without locks coarsening";
 53 }
 54 const char* C2Compiler::retry_no_iterative_escape_analysis() {
 55   return "retry without iterative escape analysis";
 56 }
 57 const char* C2Compiler::retry_no_reduce_allocation_merges() {
 58   return "retry without reducing allocation merges";
 59 }
 60 const char* C2Compiler::retry_no_superword() {
 61   return "retry without SuperWord";
 62 }
 63 




 64 void compiler_stubs_init(bool in_compiler_thread);
 65 
 66 bool C2Compiler::init_c2_runtime() {
 67 
 68 #ifdef ASSERT
 69   if (!AlignVector && VerifyAlignVector) {
 70     warning("VerifyAlignVector disabled because AlignVector is not enabled.");
 71     FLAG_SET_CMDLINE(VerifyAlignVector, false);
 72   }
 73 #endif
 74 
 75   // Check assumptions used while running ADLC
 76   Compile::adlc_verification();
 77   assert(REG_COUNT <= ConcreteRegisterImpl::number_of_registers, "incompatible register counts");
 78 
 79   for (int i = 0; i < ConcreteRegisterImpl::number_of_registers ; i++ ) {
 80       OptoReg::vm2opto[i] = OptoReg::Bad;
 81   }
 82 
 83   for( OptoReg::Name i=OptoReg::Name(0); i<OptoReg::Name(REG_COUNT); i = OptoReg::add(i,1) ) {
 84     VMReg r = OptoReg::as_VMReg(i);
 85     if (r->is_valid()) {
 86       OptoReg::vm2opto[r->value()] = i;
 87     }
 88   }
 89 
 90   DEBUG_ONLY( Node::init_NodeProperty(); )
 91 
 92   compiler_stubs_init(true /* in_compiler_thread */); // generate compiler's intrinsics stubs
 93 
 94   Compile::pd_compiler2_init();
 95 
 96   CompilerThread* thread = CompilerThread::current();
 97 
 98   HandleMark handle_mark(thread);
 99   return OptoRuntime::generate(thread->env());




100 }
101 
102 void C2Compiler::initialize() {
103   assert(!CompilerConfig::is_c1_or_interpreter_only_no_jvmci(), "C2 compiler is launched, it's not c1/interpreter only mode");
104   // The first compiler thread that gets here will initialize the
105   // small amount of global state (and runtime stubs) that C2 needs.
106 
107   // There is a race possible once at startup and then we're fine
108 
109   // Note that this is being called from a compiler thread not the
110   // main startup thread.
111   if (should_perform_init()) {
112     bool successful = C2Compiler::init_c2_runtime();
113     int new_state = (successful) ? initialized : failed;
114     set_state(new_state);
115   }
116 }
117 
118 void C2Compiler::compile_method(ciEnv* env, ciMethod* target, int entry_bci, bool install_code, DirectiveSet* directive) {
119   assert(is_initialized(), "Compiler thread must be initialized");
120 
121   CompilationMemoryStatisticMark cmsm(directive);

















122 
123   bool subsume_loads = SubsumeLoads;
124   bool do_escape_analysis = DoEscapeAnalysis;
125   bool do_iterative_escape_analysis = DoEscapeAnalysis;
126   bool do_reduce_allocation_merges = ReduceAllocationMerges && EliminateAllocations;
127   bool eliminate_boxing = EliminateAutoBox;
128   bool do_locks_coarsening = EliminateLocks;
129   bool do_superword = UseSuperWord;
130 




131   while (!env->failing()) {
132     ResourceMark rm;
133     // Attempt to compile while subsuming loads into machine instructions.
134     Options options(subsume_loads,
135                     do_escape_analysis,
136                     do_iterative_escape_analysis,
137                     do_reduce_allocation_merges,
138                     eliminate_boxing,
139                     do_locks_coarsening,
140                     do_superword,

141                     install_code);
142     Compile C(env, target, entry_bci, options, directive);
143 
144     // Check result and retry if appropriate.
145     if (C.failure_reason() != nullptr) {
146       if (C.failure_reason_is(retry_no_subsuming_loads())) {
147         assert(subsume_loads, "must make progress");
148         subsume_loads = false;
149         env->report_failure(C.failure_reason());
150         continue;  // retry
151       }
152       if (C.failure_reason_is(retry_no_escape_analysis())) {
153         assert(do_escape_analysis, "must make progress");
154         do_escape_analysis = false;
155         env->report_failure(C.failure_reason());
156         continue;  // retry
157       }
158       if (C.failure_reason_is(retry_no_iterative_escape_analysis())) {
159         assert(do_iterative_escape_analysis, "must make progress");
160         do_iterative_escape_analysis = false;
161         env->report_failure(C.failure_reason());
162         continue;  // retry
163       }
164       if (C.failure_reason_is(retry_no_reduce_allocation_merges())) {
165         assert(do_reduce_allocation_merges, "must make progress");
166         do_reduce_allocation_merges = false;
167         env->report_failure(C.failure_reason());
168         continue;  // retry
169       }
170       if (C.failure_reason_is(retry_no_locks_coarsening())) {
171         assert(do_locks_coarsening, "must make progress");
172         do_locks_coarsening = false;
173         env->report_failure(C.failure_reason());
174         continue;  // retry
175       }





176       if (C.failure_reason_is(retry_no_superword())) {
177         assert(do_superword, "must make progress");
178         do_superword = false;
179         env->report_failure(C.failure_reason());
180         continue;  // retry
181       }
182       if (C.has_boxed_value()) {
183         // Recompile without boxing elimination regardless failure reason.
184         assert(eliminate_boxing, "must make progress");
185         eliminate_boxing = false;
186         env->report_failure(C.failure_reason());
187         continue;  // retry
188       }
189       // Pass any other failure reason up to the ciEnv.
190       // Note that serious, irreversible failures are already logged
191       // on the ciEnv via env->record_method_not_compilable().
192       env->record_failure(C.failure_reason());
193     }
194     if (StressRecompilation) {
195       if (subsume_loads) {

  7  * published by the Free Software Foundation.
  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  *
 23  */
 24 
 25 #include "precompiled.hpp"
 26 #include "classfile/vmClasses.hpp"
 27 #include "code/SCCache.hpp"
 28 #include "compiler/compilationMemoryStatistic.hpp"
 29 #include "compiler/compilerDefinitions.inline.hpp"
 30 #include "runtime/handles.inline.hpp"
 31 #include "jfr/support/jfrIntrinsics.hpp"
 32 #include "opto/c2compiler.hpp"
 33 #include "opto/compile.hpp"
 34 #include "opto/optoreg.hpp"
 35 #include "opto/output.hpp"
 36 #include "opto/runtime.hpp"
 37 #include "runtime/stubRoutines.hpp"
 38 #include "runtime/globals_extension.hpp"
 39 #include "utilities/macros.hpp"
 40 
 41 
 42 // register information defined by ADLC
 43 extern const char register_save_policy[];
 44 extern const int  register_save_type[];
 45 
 46 const char* C2Compiler::retry_no_subsuming_loads() {
 47   return "retry without subsuming loads";
 48 }
 49 const char* C2Compiler::retry_no_escape_analysis() {
 50   return "retry without escape analysis";
 51 }
 52 const char* C2Compiler::retry_no_locks_coarsening() {
 53   return "retry without locks coarsening";
 54 }
 55 const char* C2Compiler::retry_no_iterative_escape_analysis() {
 56   return "retry without iterative escape analysis";
 57 }
 58 const char* C2Compiler::retry_no_reduce_allocation_merges() {
 59   return "retry without reducing allocation merges";
 60 }
 61 const char* C2Compiler::retry_no_superword() {
 62   return "retry without SuperWord";
 63 }
 64 
 65 const char* C2Compiler::retry_no_clinit_barriers() {
 66   return "retry without class initialization barriers";
 67 }
 68 
 69 void compiler_stubs_init(bool in_compiler_thread);
 70 
 71 bool C2Compiler::init_c2_runtime() {
 72 
 73 #ifdef ASSERT
 74   if (!AlignVector && VerifyAlignVector) {
 75     warning("VerifyAlignVector disabled because AlignVector is not enabled.");
 76     FLAG_SET_CMDLINE(VerifyAlignVector, false);
 77   }
 78 #endif
 79 
 80   // Check assumptions used while running ADLC
 81   Compile::adlc_verification();
 82   assert(REG_COUNT <= ConcreteRegisterImpl::number_of_registers, "incompatible register counts");
 83 
 84   for (int i = 0; i < ConcreteRegisterImpl::number_of_registers ; i++ ) {
 85       OptoReg::vm2opto[i] = OptoReg::Bad;
 86   }
 87 
 88   for( OptoReg::Name i=OptoReg::Name(0); i<OptoReg::Name(REG_COUNT); i = OptoReg::add(i,1) ) {
 89     VMReg r = OptoReg::as_VMReg(i);
 90     if (r->is_valid()) {
 91       OptoReg::vm2opto[r->value()] = i;
 92     }
 93   }
 94 
 95   DEBUG_ONLY( Node::init_NodeProperty(); )
 96 
 97   compiler_stubs_init(true /* in_compiler_thread */); // generate compiler's intrinsics stubs
 98 
 99   Compile::pd_compiler2_init();
100 
101   CompilerThread* thread = CompilerThread::current();
102 
103   HandleMark handle_mark(thread);
104   bool success = OptoRuntime::generate(thread->env());
105   if (success) {
106     SCCache::init_opto_table();
107   }
108   return success;
109 }
110 
111 void C2Compiler::initialize() {
112   assert(!CompilerConfig::is_c1_or_interpreter_only_no_jvmci(), "C2 compiler is launched, it's not c1/interpreter only mode");
113   // The first compiler thread that gets here will initialize the
114   // small amount of global state (and runtime stubs) that C2 needs.
115 
116   // There is a race possible once at startup and then we're fine
117 
118   // Note that this is being called from a compiler thread not the
119   // main startup thread.
120   if (should_perform_init()) {
121     bool successful = C2Compiler::init_c2_runtime();
122     int new_state = (successful) ? initialized : failed;
123     set_state(new_state);
124   }
125 }
126 
127 void C2Compiler::compile_method(ciEnv* env, ciMethod* target, int entry_bci, bool install_code, DirectiveSet* directive) {
128   assert(is_initialized(), "Compiler thread must be initialized");

129   CompilationMemoryStatisticMark cmsm(directive);
130   CompileTask* task = env->task();
131   if (install_code && task->is_scc()) {
132     bool success = SCCache::load_nmethod(env, target, entry_bci, this, CompLevel_full_optimization);
133     if (success) {
134       assert(task->is_success(), "sanity");
135       return;
136     }
137     if (!task->preload()) { // Do not mark entry if pre-loading failed - it can pass normal load
138       SCCache::invalidate(task->scc_entry()); // mark sca_entry as not entrant
139     }
140     if (SCCache::is_code_load_thread_on()) {
141       env->record_failure("Failed to load cached code");
142       // Bail out if failed to load cached code in SC thread
143       return;
144     }
145     task->clear_scc();
146   }
147 
148   bool subsume_loads = SubsumeLoads;
149   bool do_escape_analysis = DoEscapeAnalysis;
150   bool do_iterative_escape_analysis = DoEscapeAnalysis;
151   bool do_reduce_allocation_merges = ReduceAllocationMerges && EliminateAllocations;
152   bool eliminate_boxing = EliminateAutoBox;
153   bool do_locks_coarsening = EliminateLocks;
154   bool do_superword = UseSuperWord;
155   bool for_preload = (task->compile_reason() != CompileTask::Reason_Precompile) && // non-preload version is requested
156                      SCCache::gen_preload_code(target, entry_bci);
157   if (task->compile_reason() == CompileTask::Reason_PrecompileForPreload) {
158     assert(for_preload, "required");
159   }
160   while (!env->failing()) {
161     ResourceMark rm;
162     // Attempt to compile while subsuming loads into machine instructions.
163     Options options(subsume_loads,
164                     do_escape_analysis,
165                     do_iterative_escape_analysis,
166                     do_reduce_allocation_merges,
167                     eliminate_boxing,
168                     do_locks_coarsening,
169                     do_superword,
170                     for_preload,
171                     install_code);
172     Compile C(env, target, entry_bci, options, directive);
173 
174     // Check result and retry if appropriate.
175     if (C.failure_reason() != nullptr) {
176       if (C.failure_reason_is(retry_no_subsuming_loads())) {
177         assert(subsume_loads, "must make progress");
178         subsume_loads = false;
179         env->report_failure(C.failure_reason());
180         continue;  // retry
181       }
182       if (C.failure_reason_is(retry_no_escape_analysis())) {
183         assert(do_escape_analysis, "must make progress");
184         do_escape_analysis = false;
185         env->report_failure(C.failure_reason());
186         continue;  // retry
187       }
188       if (C.failure_reason_is(retry_no_iterative_escape_analysis())) {
189         assert(do_iterative_escape_analysis, "must make progress");
190         do_iterative_escape_analysis = false;
191         env->report_failure(C.failure_reason());
192         continue;  // retry
193       }
194       if (C.failure_reason_is(retry_no_reduce_allocation_merges())) {
195         assert(do_reduce_allocation_merges, "must make progress");
196         do_reduce_allocation_merges = false;
197         env->report_failure(C.failure_reason());
198         continue;  // retry
199       }
200       if (C.failure_reason_is(retry_no_locks_coarsening())) {
201         assert(do_locks_coarsening, "must make progress");
202         do_locks_coarsening = false;
203         env->report_failure(C.failure_reason());
204         continue;  // retry
205       }
206       if (C.failure_reason_is(retry_no_clinit_barriers())) {
207         assert(for_preload, "must make progress");
208         for_preload = false;
209         continue;
210       }
211       if (C.failure_reason_is(retry_no_superword())) {
212         assert(do_superword, "must make progress");
213         do_superword = false;
214         env->report_failure(C.failure_reason());
215         continue;  // retry
216       }
217       if (C.has_boxed_value()) {
218         // Recompile without boxing elimination regardless failure reason.
219         assert(eliminate_boxing, "must make progress");
220         eliminate_boxing = false;
221         env->report_failure(C.failure_reason());
222         continue;  // retry
223       }
224       // Pass any other failure reason up to the ciEnv.
225       // Note that serious, irreversible failures are already logged
226       // on the ciEnv via env->record_method_not_compilable().
227       env->record_failure(C.failure_reason());
228     }
229     if (StressRecompilation) {
230       if (subsume_loads) {
< prev index next >