提交 cdb1632f 编写于 作者: A anoll

8022494: Make compilation IDs sequential

Summary: Use atomic operations to provide sequential compilation IDs
Reviewed-by: kvn, twisti
上级 3e4c0434
...@@ -132,9 +132,9 @@ volatile jint CompileBroker::_should_compile_new_jobs = run_compilation; ...@@ -132,9 +132,9 @@ volatile jint CompileBroker::_should_compile_new_jobs = run_compilation;
// The installed compiler(s) // The installed compiler(s)
AbstractCompiler* CompileBroker::_compilers[2]; AbstractCompiler* CompileBroker::_compilers[2];
// These counters are used for assigning id's to each compilation // These counters are used to assign an unique ID to each compilation.
uint CompileBroker::_compilation_id = 0; volatile jint CompileBroker::_compilation_id = 0;
uint CompileBroker::_osr_compilation_id = 0; volatile jint CompileBroker::_osr_compilation_id = 0;
// Debugging information // Debugging information
int CompileBroker::_last_compile_type = no_compile; int CompileBroker::_last_compile_type = no_compile;
...@@ -1158,7 +1158,7 @@ void CompileBroker::compile_method_base(methodHandle method, ...@@ -1158,7 +1158,7 @@ void CompileBroker::compile_method_base(methodHandle method,
// We now know that this compilation is not pending, complete, // We now know that this compilation is not pending, complete,
// or prohibited. Assign a compile_id to this compilation // or prohibited. Assign a compile_id to this compilation
// and check to see if it is in our [Start..Stop) range. // and check to see if it is in our [Start..Stop) range.
uint compile_id = assign_compile_id(method, osr_bci); int compile_id = assign_compile_id(method, osr_bci);
if (compile_id == 0) { if (compile_id == 0) {
// The compilation falls outside the allowed range. // The compilation falls outside the allowed range.
return; return;
...@@ -1305,18 +1305,12 @@ nmethod* CompileBroker::compile_method(methodHandle method, int osr_bci, ...@@ -1305,18 +1305,12 @@ nmethod* CompileBroker::compile_method(methodHandle method, int osr_bci,
// do the compilation // do the compilation
if (method->is_native()) { if (method->is_native()) {
if (!PreferInterpreterNativeStubs || method->is_method_handle_intrinsic()) { if (!PreferInterpreterNativeStubs || method->is_method_handle_intrinsic()) {
// Acquire our lock.
int compile_id;
{
MutexLocker locker(MethodCompileQueue_lock, THREAD);
compile_id = assign_compile_id(method, standard_entry_bci);
}
// To properly handle the appendix argument for out-of-line calls we are using a small trampoline that // To properly handle the appendix argument for out-of-line calls we are using a small trampoline that
// pops off the appendix argument and jumps to the target (see gen_special_dispatch in SharedRuntime). // pops off the appendix argument and jumps to the target (see gen_special_dispatch in SharedRuntime).
// //
// Since normal compiled-to-compiled calls are not able to handle such a thing we MUST generate an adapter // Since normal compiled-to-compiled calls are not able to handle such a thing we MUST generate an adapter
// in this case. If we can't generate one and use it we can not execute the out-of-line method handle calls. // in this case. If we can't generate one and use it we can not execute the out-of-line method handle calls.
(void) AdapterHandlerLibrary::create_native_wrapper(method, compile_id); AdapterHandlerLibrary::create_native_wrapper(method);
} else { } else {
return NULL; return NULL;
} }
...@@ -1419,27 +1413,28 @@ bool CompileBroker::compilation_is_prohibited(methodHandle method, int osr_bci, ...@@ -1419,27 +1413,28 @@ bool CompileBroker::compilation_is_prohibited(methodHandle method, int osr_bci,
return false; return false;
} }
/**
// ------------------------------------------------------------------ * Generate serialized IDs for compilation requests. If certain debugging flags are used
// CompileBroker::assign_compile_id * and the ID is not within the specified range, the method is not compiled and 0 is returned.
// * The function also allows to generate separate compilation IDs for OSR compilations.
// Assign a serialized id number to this compilation request. If the */
// number falls out of the allowed range, return a 0. OSR int CompileBroker::assign_compile_id(methodHandle method, int osr_bci) {
// compilations may be numbered separately from regular compilations #ifdef ASSERT
// if certain debugging flags are used.
uint CompileBroker::assign_compile_id(methodHandle method, int osr_bci) {
assert(MethodCompileQueue_lock->owner() == Thread::current(),
"must hold the compilation queue lock");
bool is_osr = (osr_bci != standard_entry_bci); bool is_osr = (osr_bci != standard_entry_bci);
uint id; int id;
if (CICountOSR && is_osr) { if (method->is_native()) {
id = ++_osr_compilation_id; assert(!is_osr, "can't be osr");
if ((uint)CIStartOSR <= id && id < (uint)CIStopOSR) { // Adapters, native wrappers and method handle intrinsics
// should be generated always.
return Atomic::add(1, &_compilation_id);
} else if (CICountOSR && is_osr) {
id = Atomic::add(1, &_osr_compilation_id);
if (CIStartOSR <= id && id < CIStopOSR) {
return id; return id;
} }
} else { } else {
id = ++_compilation_id; id = Atomic::add(1, &_compilation_id);
if ((uint)CIStart <= id && id < (uint)CIStop) { if (CIStart <= id && id < CIStop) {
return id; return id;
} }
} }
...@@ -1447,6 +1442,11 @@ uint CompileBroker::assign_compile_id(methodHandle method, int osr_bci) { ...@@ -1447,6 +1442,11 @@ uint CompileBroker::assign_compile_id(methodHandle method, int osr_bci) {
// Method was not in the appropriate compilation range. // Method was not in the appropriate compilation range.
method->set_not_compilable_quietly(); method->set_not_compilable_quietly();
return 0; return 0;
#else
// CICountOSR is a develop flag and set to 'false' by default. In a product built,
// only _compilation_id is incremented.
return Atomic::add(1, &_compilation_id);
#endif
} }
......
...@@ -246,6 +246,8 @@ class CompileBroker: AllStatic { ...@@ -246,6 +246,8 @@ class CompileBroker: AllStatic {
// Compile type Information for print_last_compile() and CompilerCounters // Compile type Information for print_last_compile() and CompilerCounters
enum { no_compile, normal_compile, osr_compile, native_compile }; enum { no_compile, normal_compile, osr_compile, native_compile };
static int assign_compile_id (methodHandle method, int osr_bci);
private: private:
static bool _initialized; static bool _initialized;
...@@ -258,9 +260,8 @@ class CompileBroker: AllStatic { ...@@ -258,9 +260,8 @@ class CompileBroker: AllStatic {
static AbstractCompiler* _compilers[2]; static AbstractCompiler* _compilers[2];
// These counters are used for assigning id's to each compilation // These counters are used for assigning id's to each compilation
static uint _compilation_id; static volatile jint _compilation_id;
static uint _osr_compilation_id; static volatile jint _osr_compilation_id;
static uint _native_compilation_id;
static int _last_compile_type; static int _last_compile_type;
static int _last_compile_level; static int _last_compile_level;
...@@ -321,7 +322,6 @@ class CompileBroker: AllStatic { ...@@ -321,7 +322,6 @@ class CompileBroker: AllStatic {
static void init_compiler_threads(int c1_compiler_count, int c2_compiler_count); static void init_compiler_threads(int c1_compiler_count, int c2_compiler_count);
static bool compilation_is_complete (methodHandle method, int osr_bci, int comp_level); static bool compilation_is_complete (methodHandle method, int osr_bci, int comp_level);
static bool compilation_is_prohibited(methodHandle method, int osr_bci, int comp_level); static bool compilation_is_prohibited(methodHandle method, int osr_bci, int comp_level);
static uint assign_compile_id (methodHandle method, int osr_bci);
static bool is_compile_blocking (methodHandle method, int osr_bci); static bool is_compile_blocking (methodHandle method, int osr_bci);
static void preload_classes (methodHandle method, TRAPS); static void preload_classes (methodHandle method, TRAPS);
......
...@@ -3309,14 +3309,14 @@ class CommandLineFlags { ...@@ -3309,14 +3309,14 @@ class CommandLineFlags {
develop(intx, CIStart, 0, \ develop(intx, CIStart, 0, \
"The id of the first compilation to permit") \ "The id of the first compilation to permit") \
\ \
develop(intx, CIStop, -1, \ develop(intx, CIStop, max_jint, \
"The id of the last compilation to permit") \ "The id of the last compilation to permit") \
\ \
develop(intx, CIStartOSR, 0, \ develop(intx, CIStartOSR, 0, \
"The id of the first osr compilation to permit " \ "The id of the first osr compilation to permit " \
"(CICountOSR must be on)") \ "(CICountOSR must be on)") \
\ \
develop(intx, CIStopOSR, -1, \ develop(intx, CIStopOSR, max_jint, \
"The id of the last osr compilation to permit " \ "The id of the last osr compilation to permit " \
"(CICountOSR must be on)") \ "(CICountOSR must be on)") \
\ \
......
...@@ -2595,11 +2595,13 @@ bool AdapterHandlerEntry::compare_code(unsigned char* buffer, int length) { ...@@ -2595,11 +2595,13 @@ bool AdapterHandlerEntry::compare_code(unsigned char* buffer, int length) {
#endif #endif
// Create a native wrapper for this native method. The wrapper converts the /**
// java compiled calling convention to the native convention, handlizes * Create a native wrapper for this native method. The wrapper converts the
// arguments, and transitions to native. On return from the native we transition * Java-compiled calling convention to the native convention, handles
// back to java blocking if a safepoint is in progress. * arguments, and transitions to native. On return from the native we transition
nmethod *AdapterHandlerLibrary::create_native_wrapper(methodHandle method, int compile_id) { * back to java blocking if a safepoint is in progress.
*/
void AdapterHandlerLibrary::create_native_wrapper(methodHandle method) {
ResourceMark rm; ResourceMark rm;
nmethod* nm = NULL; nmethod* nm = NULL;
...@@ -2608,16 +2610,19 @@ nmethod *AdapterHandlerLibrary::create_native_wrapper(methodHandle method, int c ...@@ -2608,16 +2610,19 @@ nmethod *AdapterHandlerLibrary::create_native_wrapper(methodHandle method, int c
method->has_native_function(), "must have something valid to call!"); method->has_native_function(), "must have something valid to call!");
{ {
// perform the work while holding the lock, but perform any printing outside the lock // Perform the work while holding the lock, but perform any printing outside the lock
MutexLocker mu(AdapterHandlerLibrary_lock); MutexLocker mu(AdapterHandlerLibrary_lock);
// See if somebody beat us to it // See if somebody beat us to it
nm = method->code(); nm = method->code();
if (nm) { if (nm != NULL) {
return nm; return;
} }
ResourceMark rm; const int compile_id = CompileBroker::assign_compile_id(method, CompileBroker::standard_entry_bci);
assert(compile_id > 0, "Must generate native wrapper");
ResourceMark rm;
BufferBlob* buf = buffer_blob(); // the temporary code buffer in CodeCache BufferBlob* buf = buffer_blob(); // the temporary code buffer in CodeCache
if (buf != NULL) { if (buf != NULL) {
CodeBuffer buffer(buf); CodeBuffer buffer(buf);
...@@ -2649,16 +2654,14 @@ nmethod *AdapterHandlerLibrary::create_native_wrapper(methodHandle method, int c ...@@ -2649,16 +2654,14 @@ nmethod *AdapterHandlerLibrary::create_native_wrapper(methodHandle method, int c
int comp_args_on_stack = SharedRuntime::java_calling_convention(sig_bt, regs, total_args_passed, is_outgoing); int comp_args_on_stack = SharedRuntime::java_calling_convention(sig_bt, regs, total_args_passed, is_outgoing);
// Generate the compiled-to-native wrapper code // Generate the compiled-to-native wrapper code
nm = SharedRuntime::generate_native_wrapper(&_masm, nm = SharedRuntime::generate_native_wrapper(&_masm, method, compile_id, sig_bt, regs, ret_type);
method,
compile_id, if (nm != NULL) {
sig_bt, method->set_code(method, nm);
regs,
ret_type);
} }
} }
} // Unlock AdapterHandlerLibrary_lock
// Must unlock before calling set_code
// Install the generated code. // Install the generated code.
if (nm != NULL) { if (nm != NULL) {
...@@ -2666,13 +2669,11 @@ nmethod *AdapterHandlerLibrary::create_native_wrapper(methodHandle method, int c ...@@ -2666,13 +2669,11 @@ nmethod *AdapterHandlerLibrary::create_native_wrapper(methodHandle method, int c
ttyLocker ttyl; ttyLocker ttyl;
CompileTask::print_compilation(tty, nm, method->is_static() ? "(static)" : ""); CompileTask::print_compilation(tty, nm, method->is_static() ? "(static)" : "");
} }
method->set_code(method, nm);
nm->post_compiled_method_load_event(); nm->post_compiled_method_load_event();
} else { } else {
// CodeCache is full, disable compilation // CodeCache is full, disable compilation
CompileBroker::handle_full_code_cache(); CompileBroker::handle_full_code_cache();
} }
return nm;
} }
JRT_ENTRY_NO_ASYNC(void, SharedRuntime::block_for_jni_critical(JavaThread* thread)) JRT_ENTRY_NO_ASYNC(void, SharedRuntime::block_for_jni_critical(JavaThread* thread))
......
...@@ -666,7 +666,7 @@ class AdapterHandlerLibrary: public AllStatic { ...@@ -666,7 +666,7 @@ class AdapterHandlerLibrary: public AllStatic {
static AdapterHandlerEntry* new_entry(AdapterFingerPrint* fingerprint, static AdapterHandlerEntry* new_entry(AdapterFingerPrint* fingerprint,
address i2c_entry, address c2i_entry, address c2i_unverified_entry); address i2c_entry, address c2i_entry, address c2i_unverified_entry);
static nmethod* create_native_wrapper(methodHandle method, int compile_id); static void create_native_wrapper(methodHandle method);
static AdapterHandlerEntry* get_adapter(methodHandle method); static AdapterHandlerEntry* get_adapter(methodHandle method);
#ifdef HAVE_DTRACE_H #ifdef HAVE_DTRACE_H
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册