compileBroker.hpp revision 0
0N/A/*
0N/A * Copyright 1999-2006 Sun Microsystems, Inc. All Rights Reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
0N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
0N/A * CA 95054 USA or visit www.sun.com if you need additional information or
0N/A * have any questions.
0N/A *
0N/A */
0N/A
0N/Aclass nmethod;
0N/Aclass nmethodLocker;
0N/A
0N/A// CompileTask
0N/A//
0N/A// An entry in the compile queue. It represents a pending or current
0N/A// compilation.
0N/Aclass CompileTask : public CHeapObj {
0N/A private:
0N/A Monitor* _lock;
0N/A uint _compile_id;
0N/A jobject _method;
0N/A int _osr_bci;
0N/A bool _is_complete;
0N/A bool _is_success;
0N/A bool _is_blocking;
0N/A int _comp_level;
0N/A int _num_inlined_bytecodes;
0N/A nmethodLocker* _code_handle; // holder of eventual result
0N/A CompileTask* _next;
0N/A
0N/A // Fields used for logging why the compilation was initiated:
0N/A jlong _time_queued; // in units of os::elapsed_counter()
0N/A jobject _hot_method; // which method actually triggered this task
0N/A int _hot_count; // information about its invocation counter
0N/A const char* _comment; // more info about the task
0N/A
0N/A public:
0N/A CompileTask() {
0N/A _lock = new Monitor(Mutex::nonleaf+2, "CompileTaskLock");
0N/A }
0N/A
0N/A void initialize(int compile_id, methodHandle method, int osr_bci, int comp_level,
0N/A methodHandle hot_method, int hot_count, const char* comment,
0N/A bool is_blocking);
0N/A
0N/A void free();
0N/A
0N/A int compile_id() const { return _compile_id; }
0N/A jobject method_handle() const { return _method; }
0N/A int osr_bci() const { return _osr_bci; }
0N/A bool is_complete() const { return _is_complete; }
0N/A bool is_blocking() const { return _is_blocking; }
0N/A bool is_success() const { return _is_success; }
0N/A
0N/A nmethodLocker* code_handle() const { return _code_handle; }
0N/A void set_code_handle(nmethodLocker* l) { _code_handle = l; }
0N/A nmethod* code() const; // _code_handle->code()
0N/A void set_code(nmethod* nm); // _code_handle->set_code(nm)
0N/A
0N/A Monitor* lock() const { return _lock; }
0N/A
0N/A void mark_complete() { _is_complete = true; }
0N/A void mark_success() { _is_success = true; }
0N/A
0N/A int comp_level() { return _comp_level;}
0N/A void set_comp_level(int comp_level) { _comp_level = comp_level;}
0N/A
0N/A int num_inlined_bytecodes() const { return _num_inlined_bytecodes; }
0N/A void set_num_inlined_bytecodes(int n) { _num_inlined_bytecodes = n; }
0N/A
0N/A CompileTask* next() const { return _next; }
0N/A void set_next(CompileTask* next) { _next = next; }
0N/A
0N/A void print();
0N/A void print_line();
0N/A void print_line_on_error(outputStream* st, char* buf, int buflen);
0N/A void log_task(xmlStream* log);
0N/A void log_task_queued();
0N/A void log_task_start(CompileLog* log);
0N/A void log_task_done(CompileLog* log);
0N/A
0N/A};
0N/A
0N/A// CompilerCounters
0N/A//
0N/A// Per Compiler Performance Counters.
0N/A//
0N/Aclass CompilerCounters : public CHeapObj {
0N/A
0N/A public:
0N/A enum {
0N/A cmname_buffer_length = 160
0N/A };
0N/A
0N/A private:
0N/A
0N/A char _current_method[cmname_buffer_length];
0N/A PerfStringVariable* _perf_current_method;
0N/A
0N/A int _compile_type;
0N/A PerfVariable* _perf_compile_type;
0N/A
0N/A PerfCounter* _perf_time;
0N/A PerfCounter* _perf_compiles;
0N/A
0N/A public:
0N/A CompilerCounters(const char* name, int instance, TRAPS);
0N/A
0N/A // these methods should be called in a thread safe context
0N/A
0N/A void set_current_method(const char* method) {
0N/A strncpy(_current_method, method, (size_t)cmname_buffer_length);
0N/A if (UsePerfData) _perf_current_method->set_value(method);
0N/A }
0N/A
0N/A char* current_method() { return _current_method; }
0N/A
0N/A void set_compile_type(int compile_type) {
0N/A _compile_type = compile_type;
0N/A if (UsePerfData) _perf_compile_type->set_value((jlong)compile_type);
0N/A }
0N/A
0N/A int compile_type() { return _compile_type; }
0N/A
0N/A PerfCounter* time_counter() { return _perf_time; }
0N/A PerfCounter* compile_counter() { return _perf_compiles; }
0N/A};
0N/A
0N/A
0N/A// CompileQueue
0N/A//
0N/A// A list of CompileTasks.
0N/Aclass CompileQueue : public CHeapObj {
0N/A private:
0N/A const char* _name;
0N/A Monitor* _lock;
0N/A
0N/A CompileTask* _first;
0N/A CompileTask* _last;
0N/A
0N/A public:
0N/A CompileQueue(const char* name, Monitor* lock) {
0N/A _name = name;
0N/A _lock = lock;
0N/A _first = NULL;
0N/A _last = NULL;
0N/A }
0N/A
0N/A const char* name() const { return _name; }
0N/A Monitor* lock() const { return _lock; }
0N/A
0N/A void add(CompileTask* task);
0N/A
0N/A CompileTask* get();
0N/A
0N/A bool is_empty() const { return _first == NULL; }
0N/A
0N/A void print();
0N/A};
0N/A
0N/A
0N/A// Compilation
0N/A//
0N/A// The broker for all compilation requests.
0N/Aclass CompileBroker: AllStatic {
0N/A friend class Threads;
0N/A friend class CompileTaskWrapper;
0N/A
0N/A public:
0N/A enum {
0N/A name_buffer_length = 100
0N/A };
0N/A
0N/A // Compile type Information for print_last_compile() and CompilerCounters
0N/A enum { no_compile, normal_compile, osr_compile, native_compile };
0N/A
0N/A private:
0N/A static bool _initialized;
0N/A static volatile bool _should_block;
0N/A
0N/A // The installed compiler(s)
0N/A static AbstractCompiler* _compilers[2];
0N/A
0N/A // These counters are used for assigning id's to each compilation
0N/A static uint _compilation_id;
0N/A static uint _osr_compilation_id;
0N/A static uint _native_compilation_id;
0N/A
0N/A static int _last_compile_type;
0N/A static int _last_compile_level;
0N/A static char _last_method_compiled[name_buffer_length];
0N/A
0N/A static CompileQueue* _method_queue;
0N/A static CompileTask* _task_free_list;
0N/A
0N/A static GrowableArray<CompilerThread*>* _method_threads;
0N/A
0N/A // performance counters
0N/A static PerfCounter* _perf_total_compilation;
0N/A static PerfCounter* _perf_native_compilation;
0N/A static PerfCounter* _perf_osr_compilation;
0N/A static PerfCounter* _perf_standard_compilation;
0N/A
0N/A static PerfCounter* _perf_total_bailout_count;
0N/A static PerfCounter* _perf_total_invalidated_count;
0N/A static PerfCounter* _perf_total_compile_count;
0N/A static PerfCounter* _perf_total_native_compile_count;
0N/A static PerfCounter* _perf_total_osr_compile_count;
0N/A static PerfCounter* _perf_total_standard_compile_count;
0N/A
0N/A static PerfCounter* _perf_sum_osr_bytes_compiled;
0N/A static PerfCounter* _perf_sum_standard_bytes_compiled;
0N/A static PerfCounter* _perf_sum_nmethod_size;
0N/A static PerfCounter* _perf_sum_nmethod_code_size;
0N/A
0N/A static PerfStringVariable* _perf_last_method;
0N/A static PerfStringVariable* _perf_last_failed_method;
0N/A static PerfStringVariable* _perf_last_invalidated_method;
0N/A static PerfVariable* _perf_last_compile_type;
0N/A static PerfVariable* _perf_last_compile_size;
0N/A static PerfVariable* _perf_last_failed_type;
0N/A static PerfVariable* _perf_last_invalidated_type;
0N/A
0N/A // Timers and counters for generating statistics
0N/A static elapsedTimer _t_total_compilation;
0N/A static elapsedTimer _t_osr_compilation;
0N/A static elapsedTimer _t_standard_compilation;
0N/A
0N/A static int _total_bailout_count;
0N/A static int _total_invalidated_count;
0N/A static int _total_compile_count;
0N/A static int _total_native_compile_count;
0N/A static int _total_osr_compile_count;
0N/A static int _total_standard_compile_count;
0N/A
0N/A static int _sum_osr_bytes_compiled;
0N/A static int _sum_standard_bytes_compiled;
0N/A static int _sum_nmethod_size;
0N/A static int _sum_nmethod_code_size;
0N/A
0N/A static int compiler_count() {
0N/A return CICompilerCountPerCPU
0N/A // Example: if CICompilerCountPerCPU is true, then we get
0N/A // max(log2(8)-1,1) = 2 compiler threads on an 8-way machine.
0N/A // May help big-app startup time.
0N/A ? (MAX2(log2_intptr(os::active_processor_count())-1,1))
0N/A : CICompilerCount;
0N/A }
0N/A
0N/A static CompilerThread* make_compiler_thread(const char* name, CompileQueue* queue, CompilerCounters* counters, TRAPS);
0N/A static void init_compiler_threads(int compiler_count);
0N/A static bool compilation_is_complete (methodHandle method, int osr_bci, int comp_level);
0N/A static bool compilation_is_in_queue (methodHandle method, int osr_bci);
0N/A static bool compilation_is_prohibited(methodHandle method, int osr_bci, int comp_level);
0N/A static uint assign_compile_id (methodHandle method, int osr_bci);
0N/A static bool is_compile_blocking (methodHandle method, int osr_bci);
0N/A static void preload_classes (methodHandle method, TRAPS);
0N/A
0N/A static CompileTask* create_compile_task(CompileQueue* queue,
0N/A int compile_id,
0N/A methodHandle method,
0N/A int osr_bci,
0N/A int comp_level,
0N/A methodHandle hot_method,
0N/A int hot_count,
0N/A const char* comment,
0N/A bool blocking);
0N/A static CompileTask* allocate_task();
0N/A static void free_task(CompileTask* task);
0N/A static void wait_for_completion(CompileTask* task);
0N/A
0N/A static void invoke_compiler_on_method(CompileTask* task);
0N/A static void set_last_compile(CompilerThread *thread, methodHandle method, bool is_osr, int comp_level);
0N/A static void push_jni_handle_block();
0N/A static void pop_jni_handle_block();
0N/A static bool check_break_at(methodHandle method, int compile_id, bool is_osr);
0N/A static void collect_statistics(CompilerThread* thread, elapsedTimer time, CompileTask* task);
0N/A
0N/A static void compile_method_base(methodHandle method,
0N/A int osr_bci,
0N/A int comp_level,
0N/A methodHandle hot_method,
0N/A int hot_count,
0N/A const char* comment,
0N/A TRAPS);
0N/A
0N/A public:
0N/A enum {
0N/A // The entry bci used for non-OSR compilations.
0N/A standard_entry_bci = InvocationEntryBci
0N/A };
0N/A
0N/A static AbstractCompiler* compiler(int level ) {
0N/A if (level == CompLevel_fast_compile) return _compilers[0];
0N/A assert(level == CompLevel_highest_tier, "what level?")
0N/A return _compilers[1];
0N/A }
0N/A
0N/A static void compilation_init();
0N/A static void init_compiler_thread_log();
0N/A static nmethod* compile_method(methodHandle method, int osr_bci,
0N/A methodHandle hot_method, int hot_count,
0N/A const char* comment, TRAPS);
0N/A
0N/A static void compiler_thread_loop();
0N/A
0N/A static bool is_idle();
0N/A
0N/A // Set _should_block.
0N/A // Call this from the VM, with Threads_lock held and a safepoint requested.
0N/A static void set_should_block();
0N/A
0N/A // Call this from the compiler at convenient points, to poll for _should_block.
0N/A static void maybe_block();
0N/A
0N/A // Return total compilation ticks
0N/A static jlong total_compilation_ticks() {
0N/A return _perf_total_compilation != NULL ? _perf_total_compilation->get_value() : 0;
0N/A }
0N/A
0N/A // Print a detailed accounting of compilation time
0N/A static void print_times();
0N/A
0N/A // Debugging output for failure
0N/A static void print_last_compile();
0N/A
0N/A static void print_compiler_threads_on(outputStream* st);
0N/A};