6 * under the terms of the GNU General Public License version 2 only, as
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 "classfile/vmClasses.hpp"
26 #include "compiler/compilationMemoryStatistic.hpp"
27 #include "compiler/compilerDefinitions.inline.hpp"
28 #include "runtime/handles.inline.hpp"
29 #include "jfr/support/jfrIntrinsics.hpp"
30 #include "opto/c2compiler.hpp"
31 #include "opto/compile.hpp"
32 #include "opto/optoreg.hpp"
33 #include "opto/output.hpp"
34 #include "opto/runtime.hpp"
35 #include "runtime/stubRoutines.hpp"
36 #include "runtime/globals_extension.hpp"
37 #include "utilities/macros.hpp"
38
39
40 // register information defined by ADLC
41 extern const char register_save_policy[];
42 extern const int register_save_type[];
43
44 const char* C2Compiler::retry_no_subsuming_loads() {
45 return "retry without subsuming loads";
46 }
47 const char* C2Compiler::retry_no_escape_analysis() {
48 return "retry without escape analysis";
49 }
50 const char* C2Compiler::retry_no_locks_coarsening() {
51 return "retry without locks coarsening";
52 }
53 const char* C2Compiler::retry_no_iterative_escape_analysis() {
54 return "retry without iterative escape analysis";
55 }
56 const char* C2Compiler::retry_no_reduce_allocation_merges() {
57 return "retry without reducing allocation merges";
58 }
59 const char* C2Compiler::retry_no_superword() {
60 return "retry without SuperWord";
61 }
62
63 void compiler_stubs_init(bool in_compiler_thread);
64
65 bool C2Compiler::init_c2_runtime() {
66
67 #ifdef ASSERT
68 if (!AlignVector && VerifyAlignVector) {
69 warning("VerifyAlignVector disabled because AlignVector is not enabled.");
70 FLAG_SET_CMDLINE(VerifyAlignVector, false);
71 }
72 #endif
73
74 // Check assumptions used while running ADLC
75 Compile::adlc_verification();
76 assert(REG_COUNT <= ConcreteRegisterImpl::number_of_registers, "incompatible register counts");
77
78 for (int i = 0; i < ConcreteRegisterImpl::number_of_registers ; i++ ) {
79 OptoReg::vm2opto[i] = OptoReg::Bad;
80 }
81
82 for( OptoReg::Name i=OptoReg::Name(0); i<OptoReg::Name(REG_COUNT); i = OptoReg::add(i,1) ) {
83 VMReg r = OptoReg::as_VMReg(i);
84 if (r->is_valid()) {
85 OptoReg::vm2opto[r->value()] = i;
86 }
87 }
88
89 DEBUG_ONLY( Node::init_NodeProperty(); )
90
91 compiler_stubs_init(true /* in_compiler_thread */); // generate compiler's intrinsics stubs
92
93 Compile::pd_compiler2_init();
94
95 CompilerThread* thread = CompilerThread::current();
96
97 HandleMark handle_mark(thread);
98 return OptoRuntime::generate(thread->env());
99 }
100
101 void C2Compiler::initialize() {
102 assert(!CompilerConfig::is_c1_or_interpreter_only_no_jvmci(), "C2 compiler is launched, it's not c1/interpreter only mode");
103 // The first compiler thread that gets here will initialize the
104 // small amount of global state (and runtime stubs) that C2 needs.
105
106 // There is a race possible once at startup and then we're fine
107
108 // Note that this is being called from a compiler thread not the
109 // main startup thread.
110 if (should_perform_init()) {
111 bool successful = C2Compiler::init_c2_runtime();
112 int new_state = (successful) ? initialized : failed;
113 set_state(new_state);
114 }
115 }
116
117 void C2Compiler::compile_method(ciEnv* env, ciMethod* target, int entry_bci, bool install_code, DirectiveSet* directive) {
118 assert(is_initialized(), "Compiler thread must be initialized");
119
120 CompilationMemoryStatisticMark cmsm(directive);
121
122 bool subsume_loads = SubsumeLoads;
123 bool do_escape_analysis = DoEscapeAnalysis;
124 bool do_iterative_escape_analysis = DoEscapeAnalysis;
125 bool do_reduce_allocation_merges = ReduceAllocationMerges && EliminateAllocations;
126 bool eliminate_boxing = EliminateAutoBox;
127 bool do_locks_coarsening = EliminateLocks;
128 bool do_superword = UseSuperWord;
129
130 while (!env->failing()) {
131 ResourceMark rm;
132 // Attempt to compile while subsuming loads into machine instructions.
133 Options options(subsume_loads,
134 do_escape_analysis,
135 do_iterative_escape_analysis,
136 do_reduce_allocation_merges,
137 eliminate_boxing,
138 do_locks_coarsening,
139 do_superword,
140 install_code);
141 Compile C(env, target, entry_bci, options, directive);
142
143 // Check result and retry if appropriate.
144 if (C.failure_reason() != nullptr) {
145 if (C.failure_reason_is(retry_no_subsuming_loads())) {
146 assert(subsume_loads, "must make progress");
147 subsume_loads = false;
148 env->report_failure(C.failure_reason());
149 continue; // retry
150 }
151 if (C.failure_reason_is(retry_no_escape_analysis())) {
152 assert(do_escape_analysis, "must make progress");
153 do_escape_analysis = false;
154 env->report_failure(C.failure_reason());
155 continue; // retry
156 }
157 if (C.failure_reason_is(retry_no_iterative_escape_analysis())) {
158 assert(do_iterative_escape_analysis, "must make progress");
159 do_iterative_escape_analysis = false;
160 env->report_failure(C.failure_reason());
161 continue; // retry
162 }
163 if (C.failure_reason_is(retry_no_reduce_allocation_merges())) {
164 assert(do_reduce_allocation_merges, "must make progress");
165 do_reduce_allocation_merges = false;
166 env->report_failure(C.failure_reason());
167 continue; // retry
168 }
169 if (C.failure_reason_is(retry_no_locks_coarsening())) {
170 assert(do_locks_coarsening, "must make progress");
171 do_locks_coarsening = false;
172 env->report_failure(C.failure_reason());
173 continue; // retry
174 }
175 if (C.failure_reason_is(retry_no_superword())) {
176 assert(do_superword, "must make progress");
177 do_superword = false;
178 env->report_failure(C.failure_reason());
179 continue; // retry
180 }
181 if (C.has_boxed_value()) {
182 // Recompile without boxing elimination regardless failure reason.
183 assert(eliminate_boxing, "must make progress");
184 eliminate_boxing = false;
185 env->report_failure(C.failure_reason());
186 continue; // retry
187 }
188 // Pass any other failure reason up to the ciEnv.
189 // Note that serious, irreversible failures are already logged
190 // on the ciEnv via env->record_method_not_compilable().
191 env->record_failure(C.failure_reason());
192 }
193 if (StressRecompilation) {
194 if (subsume_loads) {
836 case vmIntrinsics::_blackhole:
837 #if INCLUDE_JVMTI
838 case vmIntrinsics::_notifyJvmtiVThreadStart:
839 case vmIntrinsics::_notifyJvmtiVThreadEnd:
840 case vmIntrinsics::_notifyJvmtiVThreadMount:
841 case vmIntrinsics::_notifyJvmtiVThreadUnmount:
842 case vmIntrinsics::_notifyJvmtiVThreadDisableSuspend:
843 #endif
844 break;
845
846 default:
847 return false;
848 }
849 return true;
850 }
851
852 int C2Compiler::initial_code_buffer_size(int const_size) {
853 // See Compile::init_scratch_buffer_blob
854 int locs_size = sizeof(relocInfo) * PhaseOutput::MAX_locs_size;
855 int slop = 2 * CodeSection::end_slop(); // space between sections
856 return PhaseOutput::MAX_inst_size + PhaseOutput::MAX_stubs_size + const_size + slop + locs_size;
857 }
|
6 * under the terms of the GNU General Public License version 2 only, as
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 "classfile/vmClasses.hpp"
26 #include "code/SCCache.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 const char* C2Compiler::retry_no_clinit_barriers() {
65 return "retry without class initialization barriers";
66 }
67
68 void compiler_stubs_init(bool in_compiler_thread);
69
70 bool C2Compiler::init_c2_runtime() {
71
72 #ifdef ASSERT
73 if (!AlignVector && VerifyAlignVector) {
74 warning("VerifyAlignVector disabled because AlignVector is not enabled.");
75 FLAG_SET_CMDLINE(VerifyAlignVector, false);
76 }
77 #endif
78
79 // Check assumptions used while running ADLC
80 Compile::adlc_verification();
81 assert(REG_COUNT <= ConcreteRegisterImpl::number_of_registers, "incompatible register counts");
82
83 for (int i = 0; i < ConcreteRegisterImpl::number_of_registers ; i++ ) {
84 OptoReg::vm2opto[i] = OptoReg::Bad;
85 }
86
87 for( OptoReg::Name i=OptoReg::Name(0); i<OptoReg::Name(REG_COUNT); i = OptoReg::add(i,1) ) {
88 VMReg r = OptoReg::as_VMReg(i);
89 if (r->is_valid()) {
90 OptoReg::vm2opto[r->value()] = i;
91 }
92 }
93
94 DEBUG_ONLY( Node::init_NodeProperty(); )
95
96 compiler_stubs_init(true /* in_compiler_thread */); // generate compiler's intrinsics stubs
97
98 Compile::pd_compiler2_init();
99
100 CompilerThread* thread = CompilerThread::current();
101
102 HandleMark handle_mark(thread);
103 bool success = OptoRuntime::generate(thread->env());
104 if (success) {
105 SCCache::init_opto_table();
106 }
107 return success;
108 }
109
110 void C2Compiler::initialize() {
111 assert(!CompilerConfig::is_c1_or_interpreter_only_no_jvmci(), "C2 compiler is launched, it's not c1/interpreter only mode");
112 // The first compiler thread that gets here will initialize the
113 // small amount of global state (and runtime stubs) that C2 needs.
114
115 // There is a race possible once at startup and then we're fine
116
117 // Note that this is being called from a compiler thread not the
118 // main startup thread.
119 if (should_perform_init()) {
120 bool successful = C2Compiler::init_c2_runtime();
121 int new_state = (successful) ? initialized : failed;
122 set_state(new_state);
123 }
124 }
125
126 void C2Compiler::compile_method(ciEnv* env, ciMethod* target, int entry_bci, bool install_code, DirectiveSet* directive) {
127 assert(is_initialized(), "Compiler thread must be initialized");
128 CompilationMemoryStatisticMark cmsm(directive);
129 CompileTask* task = env->task();
130 if (install_code && task->is_scc()) {
131 bool success = SCCache::load_nmethod(env, target, entry_bci, this, CompLevel_full_optimization);
132 if (success) {
133 assert(task->is_success(), "sanity");
134 return;
135 }
136 if (!task->preload()) { // Do not mark entry if pre-loading failed - it can pass normal load
137 SCCache::invalidate(task->scc_entry()); // mark sca_entry as not entrant
138 }
139 if (SCCache::is_code_load_thread_on()) {
140 env->record_failure("Failed to load cached code");
141 // Bail out if failed to load cached code in SC thread
142 return;
143 }
144 task->clear_scc();
145 }
146
147 bool subsume_loads = SubsumeLoads;
148 bool do_escape_analysis = DoEscapeAnalysis;
149 bool do_iterative_escape_analysis = DoEscapeAnalysis;
150 bool do_reduce_allocation_merges = ReduceAllocationMerges && EliminateAllocations;
151 bool eliminate_boxing = EliminateAutoBox;
152 bool do_locks_coarsening = EliminateLocks;
153 bool do_superword = UseSuperWord;
154 bool for_preload = (task->compile_reason() != CompileTask::Reason_Precompile) && // non-preload version is requested
155 SCCache::gen_preload_code(target, entry_bci);
156 if (task->compile_reason() == CompileTask::Reason_PrecompileForPreload) {
157 assert(for_preload, "required");
158 }
159 while (!env->failing()) {
160 ResourceMark rm;
161 // Attempt to compile while subsuming loads into machine instructions.
162 Options options(subsume_loads,
163 do_escape_analysis,
164 do_iterative_escape_analysis,
165 do_reduce_allocation_merges,
166 eliminate_boxing,
167 do_locks_coarsening,
168 do_superword,
169 for_preload,
170 install_code);
171 Compile C(env, target, entry_bci, options, directive);
172
173 // Check result and retry if appropriate.
174 if (C.failure_reason() != nullptr) {
175 if (C.failure_reason_is(retry_no_subsuming_loads())) {
176 assert(subsume_loads, "must make progress");
177 subsume_loads = false;
178 env->report_failure(C.failure_reason());
179 continue; // retry
180 }
181 if (C.failure_reason_is(retry_no_escape_analysis())) {
182 assert(do_escape_analysis, "must make progress");
183 do_escape_analysis = false;
184 env->report_failure(C.failure_reason());
185 continue; // retry
186 }
187 if (C.failure_reason_is(retry_no_iterative_escape_analysis())) {
188 assert(do_iterative_escape_analysis, "must make progress");
189 do_iterative_escape_analysis = false;
190 env->report_failure(C.failure_reason());
191 continue; // retry
192 }
193 if (C.failure_reason_is(retry_no_reduce_allocation_merges())) {
194 assert(do_reduce_allocation_merges, "must make progress");
195 do_reduce_allocation_merges = false;
196 env->report_failure(C.failure_reason());
197 continue; // retry
198 }
199 if (C.failure_reason_is(retry_no_locks_coarsening())) {
200 assert(do_locks_coarsening, "must make progress");
201 do_locks_coarsening = false;
202 env->report_failure(C.failure_reason());
203 continue; // retry
204 }
205 if (C.failure_reason_is(retry_no_clinit_barriers())) {
206 assert(for_preload, "must make progress");
207 for_preload = false;
208 continue;
209 }
210 if (C.failure_reason_is(retry_no_superword())) {
211 assert(do_superword, "must make progress");
212 do_superword = false;
213 env->report_failure(C.failure_reason());
214 continue; // retry
215 }
216 if (C.has_boxed_value()) {
217 // Recompile without boxing elimination regardless failure reason.
218 assert(eliminate_boxing, "must make progress");
219 eliminate_boxing = false;
220 env->report_failure(C.failure_reason());
221 continue; // retry
222 }
223 // Pass any other failure reason up to the ciEnv.
224 // Note that serious, irreversible failures are already logged
225 // on the ciEnv via env->record_method_not_compilable().
226 env->record_failure(C.failure_reason());
227 }
228 if (StressRecompilation) {
229 if (subsume_loads) {
871 case vmIntrinsics::_blackhole:
872 #if INCLUDE_JVMTI
873 case vmIntrinsics::_notifyJvmtiVThreadStart:
874 case vmIntrinsics::_notifyJvmtiVThreadEnd:
875 case vmIntrinsics::_notifyJvmtiVThreadMount:
876 case vmIntrinsics::_notifyJvmtiVThreadUnmount:
877 case vmIntrinsics::_notifyJvmtiVThreadDisableSuspend:
878 #endif
879 break;
880
881 default:
882 return false;
883 }
884 return true;
885 }
886
887 int C2Compiler::initial_code_buffer_size(int const_size) {
888 // See Compile::init_scratch_buffer_blob
889 int locs_size = sizeof(relocInfo) * PhaseOutput::MAX_locs_size;
890 int slop = 2 * CodeSection::end_slop(); // space between sections
891 return PhaseOutput::max_inst_size() + PhaseOutput::MAX_stubs_size + const_size + slop + locs_size;
892 }
|