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