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 "jfr/support/jfrIntrinsics.hpp"
29 #include "opto/c2compiler.hpp"
30 #include "opto/compile.hpp"
31 #include "opto/optoreg.hpp"
32 #include "opto/output.hpp"
33 #include "opto/runtime.hpp"
34 #include "runtime/globals_extension.hpp"
35 #include "runtime/handles.inline.hpp"
36 #include "runtime/stubRoutines.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";
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 // If there was an error generating the blob then UseCompiler will
94 // have been unset and we need to skip the remaining initialization
95 if (!UseCompiler) {
96 return false;
97 }
98
99 Compile::pd_compiler2_init();
100
101 CompilerThread* thread = CompilerThread::current();
102
103 HandleMark handle_mark(thread);
104 return OptoRuntime::generate(thread->env());
105 }
106
107 void C2Compiler::initialize() {
108 assert(!CompilerConfig::is_c1_or_interpreter_only_no_jvmci(), "C2 compiler is launched, it's not c1/interpreter only mode");
109 // The first compiler thread that gets here will initialize the
110 // small amount of global state (and runtime stubs) that C2 needs.
111
112 // There is a race possible once at startup and then we're fine
113
114 // Note that this is being called from a compiler thread not the
115 // main startup thread.
116 if (should_perform_init()) {
117 bool successful = C2Compiler::init_c2_runtime();
118 int new_state = (successful) ? initialized : failed;
119 set_state(new_state);
120 }
121 }
122
123 void C2Compiler::compile_method(ciEnv* env, ciMethod* target, int entry_bci, bool install_code, DirectiveSet* directive) {
124 assert(is_initialized(), "Compiler thread must be initialized");
125
126 CompilationMemoryStatisticMark cmsm(directive);
127
128 bool subsume_loads = SubsumeLoads;
129 bool do_escape_analysis = DoEscapeAnalysis;
130 bool do_iterative_escape_analysis = DoEscapeAnalysis;
131 bool do_reduce_allocation_merges = ReduceAllocationMerges && EliminateAllocations;
132 bool eliminate_boxing = EliminateAutoBox;
133 bool do_locks_coarsening = EliminateLocks;
134 bool do_superword = UseSuperWord;
135
136 while (!env->failing()) {
137 ResourceMark rm;
138 // Attempt to compile while subsuming loads into machine instructions.
139 Options options(subsume_loads,
140 do_escape_analysis,
141 do_iterative_escape_analysis,
142 do_reduce_allocation_merges,
143 eliminate_boxing,
144 do_locks_coarsening,
145 do_superword,
146 install_code);
147 Compile C(env, target, entry_bci, options, directive);
148
149 // Check result and retry if appropriate.
150 if (C.failure_reason() != nullptr) {
151 if (C.failure_reason_is(retry_no_subsuming_loads())) {
152 assert(subsume_loads, "must make progress");
153 subsume_loads = false;
154 env->report_failure(C.failure_reason());
155 continue; // retry
156 }
157 if (C.failure_reason_is(retry_no_escape_analysis())) {
158 assert(do_escape_analysis, "must make progress");
159 do_escape_analysis = false;
160 env->report_failure(C.failure_reason());
161 continue; // retry
162 }
163 if (C.failure_reason_is(retry_no_iterative_escape_analysis())) {
164 assert(do_iterative_escape_analysis, "must make progress");
165 do_iterative_escape_analysis = false;
861 case vmIntrinsics::_blackhole:
862 #if INCLUDE_JVMTI
863 case vmIntrinsics::_notifyJvmtiVThreadStart:
864 case vmIntrinsics::_notifyJvmtiVThreadEnd:
865 case vmIntrinsics::_notifyJvmtiVThreadMount:
866 case vmIntrinsics::_notifyJvmtiVThreadUnmount:
867 case vmIntrinsics::_notifyJvmtiVThreadDisableSuspend:
868 #endif
869 break;
870
871 default:
872 return false;
873 }
874 return true;
875 }
876
877 int C2Compiler::initial_code_buffer_size(int const_size) {
878 // See Compile::init_scratch_buffer_blob
879 int locs_size = sizeof(relocInfo) * PhaseOutput::MAX_locs_size;
880 int slop = 2 * CodeSection::end_slop(); // space between sections
881 return PhaseOutput::MAX_inst_size + PhaseOutput::MAX_stubs_size + const_size + slop + locs_size;
882 }
|
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/aotCodeCache.hpp"
27 #include "compiler/compilationMemoryStatistic.hpp"
28 #include "compiler/compilerDefinitions.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/globals_extension.hpp"
36 #include "runtime/handles.inline.hpp"
37 #include "runtime/stubRoutines.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";
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 // If there was an error generating the blob then UseCompiler will
95 // have been unset and we need to skip the remaining initialization
96 if (!UseCompiler) {
97 return false;
98 }
99
100 Compile::pd_compiler2_init();
101
102 CompilerThread* thread = CompilerThread::current();
103
104 HandleMark handle_mark(thread);
105 bool success = OptoRuntime::generate(thread->env());
106 if (success) {
107 AOTCodeCache::init_c2_table();
108 }
109 return success;
110 }
111
112 void C2Compiler::initialize() {
113 assert(!CompilerConfig::is_c1_or_interpreter_only_no_jvmci(), "C2 compiler is launched, it's not c1/interpreter only mode");
114 // The first compiler thread that gets here will initialize the
115 // small amount of global state (and runtime stubs) that C2 needs.
116
117 // There is a race possible once at startup and then we're fine
118
119 // Note that this is being called from a compiler thread not the
120 // main startup thread.
121 if (should_perform_init()) {
122 bool successful = C2Compiler::init_c2_runtime();
123 int new_state = (successful) ? initialized : failed;
124 set_state(new_state);
125 }
126 }
127
128 void C2Compiler::compile_method(ciEnv* env, ciMethod* target, int entry_bci, bool install_code, DirectiveSet* directive) {
129 assert(is_initialized(), "Compiler thread must be initialized");
130 CompilationMemoryStatisticMark cmsm(directive);
131 CompileTask* task = env->task();
132 if (install_code && task->is_aot_load()) {
133 bool success = AOTCodeCache::load_nmethod(env, target, entry_bci, this, CompLevel_full_optimization);
134 if (success) {
135 assert(task->is_success(), "sanity");
136 return;
137 }
138 AOTCodeCache::invalidate(task->aot_code_entry()); // mark aot_code_entry as not entrant
139 if (AOTCodeCache::is_code_load_thread_on()) {
140 // Bail out if AOT code load failed in AOT Code loading thread
141 // when UseAOTCodeLoadThread flag is on.
142 // We want this thread go quickly through AOT code load requests
143 // instead of spending time on normal compilation.
144 // TODO: pass this task to normal compilation thread.
145 env->record_failure("Failed to load AOT code");
146 return;
147 } else {
148 task->clear_aot();
149 }
150 }
151
152 bool subsume_loads = SubsumeLoads;
153 bool do_escape_analysis = DoEscapeAnalysis;
154 bool do_iterative_escape_analysis = DoEscapeAnalysis;
155 bool do_reduce_allocation_merges = ReduceAllocationMerges && EliminateAllocations;
156 bool eliminate_boxing = EliminateAutoBox;
157 bool do_locks_coarsening = EliminateLocks;
158 bool do_superword = UseSuperWord;
159 bool gen_preload = (task->compile_reason() == CompileTask::Reason_PrecompileForPreload);
160 assert(!gen_preload || (AOTCodeCache::is_dumping_code() && (ClassInitBarrierMode > 0)), "sanity");
161 while (!env->failing()) {
162 ResourceMark rm;
163 // Attempt to compile while subsuming loads into machine instructions.
164 Options options(subsume_loads,
165 do_escape_analysis,
166 do_iterative_escape_analysis,
167 do_reduce_allocation_merges,
168 eliminate_boxing,
169 do_locks_coarsening,
170 do_superword,
171 gen_preload,
172 install_code);
173 Compile C(env, target, entry_bci, options, directive);
174
175 // Check result and retry if appropriate.
176 if (C.failure_reason() != nullptr) {
177 if (C.failure_reason_is(retry_no_subsuming_loads())) {
178 assert(subsume_loads, "must make progress");
179 subsume_loads = false;
180 env->report_failure(C.failure_reason());
181 continue; // retry
182 }
183 if (C.failure_reason_is(retry_no_escape_analysis())) {
184 assert(do_escape_analysis, "must make progress");
185 do_escape_analysis = false;
186 env->report_failure(C.failure_reason());
187 continue; // retry
188 }
189 if (C.failure_reason_is(retry_no_iterative_escape_analysis())) {
190 assert(do_iterative_escape_analysis, "must make progress");
191 do_iterative_escape_analysis = false;
887 case vmIntrinsics::_blackhole:
888 #if INCLUDE_JVMTI
889 case vmIntrinsics::_notifyJvmtiVThreadStart:
890 case vmIntrinsics::_notifyJvmtiVThreadEnd:
891 case vmIntrinsics::_notifyJvmtiVThreadMount:
892 case vmIntrinsics::_notifyJvmtiVThreadUnmount:
893 case vmIntrinsics::_notifyJvmtiVThreadDisableSuspend:
894 #endif
895 break;
896
897 default:
898 return false;
899 }
900 return true;
901 }
902
903 int C2Compiler::initial_code_buffer_size(int const_size) {
904 // See Compile::init_scratch_buffer_blob
905 int locs_size = sizeof(relocInfo) * PhaseOutput::MAX_locs_size;
906 int slop = 2 * CodeSection::end_slop(); // space between sections
907 return PhaseOutput::max_inst_size() + PhaseOutput::MAX_stubs_size + const_size + slop + locs_size;
908 }
|