1 /*
2 * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
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 *
205 static elapsedTimer _t_invalidated_compilation;
206 static elapsedTimer _t_bailedout_compilation;
207
208 static int _total_compile_count;
209 static int _total_bailout_count;
210 static int _total_invalidated_count;
211 static int _total_native_compile_count;
212 static int _total_osr_compile_count;
213 static int _total_standard_compile_count;
214 static int _sum_osr_bytes_compiled;
215 static int _sum_standard_bytes_compiled;
216 static int _sum_nmethod_size;
217 static int _sum_nmethod_code_size;
218 static long _peak_compilation_time;
219
220 static volatile jint _print_compilation_warning;
221
222 static JavaThread* make_thread(const char* name, CompileQueue* queue, CompilerCounters* counters, AbstractCompiler* comp, bool compiler_thread, TRAPS);
223 static void init_compiler_sweeper_threads(int c1_compiler_count, int c2_compiler_count);
224 static bool compilation_is_complete (const methodHandle& method, int osr_bci, int comp_level);
225 static bool compilation_is_prohibited(const methodHandle& method, int osr_bci, int comp_level);
226 static bool is_compile_blocking();
227 static void preload_classes (const methodHandle& method, TRAPS);
228
229 static CompileTask* create_compile_task(CompileQueue* queue,
230 int compile_id,
231 const methodHandle& method,
232 int osr_bci,
233 int comp_level,
234 const methodHandle& hot_method,
235 int hot_count,
236 const char* comment,
237 bool blocking);
238 static void wait_for_completion(CompileTask* task);
239 #if INCLUDE_JVMCI
240 static bool wait_for_jvmci_completion(JVMCICompiler* comp, CompileTask* task, JavaThread* thread);
241 #endif
242
243 static void invoke_compiler_on_method(CompileTask* task);
244 static void post_compile(CompilerThread* thread, CompileTask* task, EventCompilation& event, bool success, ciEnv* ci_env);
245 static void set_last_compile(CompilerThread *thread, const methodHandle& method, bool is_osr, int comp_level);
246 static void push_jni_handle_block();
247 static void pop_jni_handle_block();
248 static void collect_statistics(CompilerThread* thread, elapsedTimer time, CompileTask* task);
249
250 static void compile_method_base(const methodHandle& method,
251 int osr_bci,
252 int comp_level,
253 const methodHandle& hot_method,
254 int hot_count,
255 const char* comment,
256 Thread* thread);
257
258 static CompileQueue* compile_queue(int comp_level);
259 static bool init_compiler_runtime();
260 static void shutdown_compiler_runtime(AbstractCompiler* comp, CompilerThread* thread);
261
262 public:
263
264 static DirectivesStack* dirstack();
265 static void set_dirstack(DirectivesStack* stack);
266
267 enum {
268 // The entry bci used for non-OSR compilations.
269 standard_entry_bci = InvocationEntryBci
270 };
271
272 static AbstractCompiler* compiler(int comp_level) {
273 if (is_c2_compile(comp_level)) return _compilers[1]; // C2
274 if (is_c1_compile(comp_level)) return _compilers[0]; // C1
275 return NULL;
276 }
277
278 static bool compilation_is_in_queue(const methodHandle& method);
279 static void print_compile_queues(outputStream* st);
280 static void print_directives(outputStream* st);
281 static int queue_size(int comp_level) {
282 CompileQueue *q = compile_queue(comp_level);
283 return q != NULL ? q->size() : 0;
284 }
285 static void compilation_init(TRAPS);
286 static void init_compiler_thread_log();
287 static nmethod* compile_method(const methodHandle& method,
288 int osr_bci,
289 int comp_level,
290 const methodHandle& hot_method,
291 int hot_count,
292 const char* comment, Thread* thread);
293
294 // Acquire any needed locks and assign a compile id
295 static uint assign_compile_id_unlocked(Thread* thread, const methodHandle& method, int osr_bci);
296
297 static void compiler_thread_loop();
298 static uint get_compilation_id() { return _compilation_id; }
299
300 // Set _should_block.
301 // Call this from the VM, with Threads_lock held and a safepoint requested.
302 static void set_should_block();
303
304 // Call this from the compiler at convenient points, to poll for _should_block.
305 static void maybe_block();
306
307 enum {
308 // Flags for toggling compiler activity
309 stop_compilation = 0,
310 run_compilation = 1,
311 shutdown_compilaton = 2
312 };
|
1 /*
2 * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
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 *
205 static elapsedTimer _t_invalidated_compilation;
206 static elapsedTimer _t_bailedout_compilation;
207
208 static int _total_compile_count;
209 static int _total_bailout_count;
210 static int _total_invalidated_count;
211 static int _total_native_compile_count;
212 static int _total_osr_compile_count;
213 static int _total_standard_compile_count;
214 static int _sum_osr_bytes_compiled;
215 static int _sum_standard_bytes_compiled;
216 static int _sum_nmethod_size;
217 static int _sum_nmethod_code_size;
218 static long _peak_compilation_time;
219
220 static volatile jint _print_compilation_warning;
221
222 static JavaThread* make_thread(const char* name, CompileQueue* queue, CompilerCounters* counters, AbstractCompiler* comp, bool compiler_thread, TRAPS);
223 static void init_compiler_sweeper_threads(int c1_compiler_count, int c2_compiler_count);
224 static bool compilation_is_complete (const methodHandle& method, int osr_bci, int comp_level);
225 static bool compilation_is_prohibited(const methodHandle& method, int osr_bci, int comp_level, bool excluded);
226 static void preload_classes (const methodHandle& method, TRAPS);
227
228 static CompileTask* create_compile_task(CompileQueue* queue,
229 int compile_id,
230 const methodHandle& method,
231 int osr_bci,
232 int comp_level,
233 const methodHandle& hot_method,
234 int hot_count,
235 const char* comment,
236 bool blocking);
237 static void wait_for_completion(CompileTask* task);
238 #if INCLUDE_JVMCI
239 static bool wait_for_jvmci_completion(JVMCICompiler* comp, CompileTask* task, JavaThread* thread);
240 #endif
241
242 static void invoke_compiler_on_method(CompileTask* task);
243 static void post_compile(CompilerThread* thread, CompileTask* task, EventCompilation& event, bool success, ciEnv* ci_env);
244 static void set_last_compile(CompilerThread *thread, const methodHandle& method, bool is_osr, int comp_level);
245 static void push_jni_handle_block();
246 static void pop_jni_handle_block();
247 static void collect_statistics(CompilerThread* thread, elapsedTimer time, CompileTask* task);
248
249 static void compile_method_base(const methodHandle& method,
250 int osr_bci,
251 int comp_level,
252 const methodHandle& hot_method,
253 int hot_count,
254 const char* comment,
255 bool blocking,
256 Thread* thread);
257
258 static CompileQueue* compile_queue(int comp_level);
259 static bool init_compiler_runtime();
260 static void shutdown_compiler_runtime(AbstractCompiler* comp, CompilerThread* thread);
261
262 public:
263
264 static DirectivesStack* dirstack();
265 static void set_dirstack(DirectivesStack* stack);
266
267 enum {
268 // The entry bci used for non-OSR compilations.
269 standard_entry_bci = InvocationEntryBci
270 };
271
272 static AbstractCompiler* compiler(int comp_level) {
273 if (is_c2_compile(comp_level)) return _compilers[1]; // C2
274 if (is_c1_compile(comp_level)) return _compilers[0]; // C1
275 return NULL;
276 }
277
278 static bool compilation_is_in_queue(const methodHandle& method);
279 static void print_compile_queues(outputStream* st);
280 static void print_directives(outputStream* st);
281 static int queue_size(int comp_level) {
282 CompileQueue *q = compile_queue(comp_level);
283 return q != NULL ? q->size() : 0;
284 }
285 static void compilation_init(TRAPS);
286 static void init_compiler_thread_log();
287 static nmethod* compile_method(const methodHandle& method,
288 int osr_bci,
289 int comp_level,
290 const methodHandle& hot_method,
291 int hot_count,
292 const char* comment, Thread* thread);
293
294 static nmethod* compile_method(const methodHandle& method,
295 int osr_bci,
296 int comp_level,
297 const methodHandle& hot_method,
298 int hot_count,
299 const char* comment,
300 DirectiveSet* directive,
301 Thread* thread);
302
303 // Acquire any needed locks and assign a compile id
304 static uint assign_compile_id_unlocked(Thread* thread, const methodHandle& method, int osr_bci);
305
306 static void compiler_thread_loop();
307 static uint get_compilation_id() { return _compilation_id; }
308
309 // Set _should_block.
310 // Call this from the VM, with Threads_lock held and a safepoint requested.
311 static void set_should_block();
312
313 // Call this from the compiler at convenient points, to poll for _should_block.
314 static void maybe_block();
315
316 enum {
317 // Flags for toggling compiler activity
318 stop_compilation = 0,
319 run_compilation = 1,
320 shutdown_compilaton = 2
321 };
|