hotspot/src/share/vm/compiler/compileBroker.cpp

Print this page




 830 
 831     java_lang_Thread::set_daemon(thread_oop());
 832 
 833     compiler_thread->set_threadObj(thread_oop());
 834     Threads::add(compiler_thread);
 835     Thread::start(compiler_thread);
 836   }
 837   // Let go of Threads_lock before yielding
 838   os::yield(); // make sure that the compiler thread is started early (especially helpful on SOLARIS)
 839 
 840   return compiler_thread;
 841 }
 842 
 843 
 844 // ------------------------------------------------------------------
 845 // CompileBroker::init_compiler_threads
 846 //
 847 // Initialize the compilation queue
 848 void CompileBroker::init_compiler_threads(int c1_compiler_count, int c2_compiler_count) {
 849   EXCEPTION_MARK;
 850 #ifndef ZERO
 851   assert(c2_compiler_count > 0 || c1_compiler_count > 0, "No compilers?");
 852 #endif // !ZERO
 853   if (c2_compiler_count > 0) {
 854     _c2_method_queue  = new CompileQueue("C2MethodQueue",  MethodCompileQueue_lock);
 855   }
 856   if (c1_compiler_count > 0) {
 857     _c1_method_queue  = new CompileQueue("C1MethodQueue",  MethodCompileQueue_lock);
 858   }
 859 
 860   int compiler_count = c1_compiler_count + c2_compiler_count;
 861 
 862   _method_threads =
 863     new (ResourceObj::C_HEAP) GrowableArray<CompilerThread*>(compiler_count, true);
 864 
 865   char name_buffer[256];
 866   for (int i = 0; i < c2_compiler_count; i++) {
 867     // Create a name for our thread.
 868     sprintf(name_buffer, "C2 CompilerThread%d", i);
 869     CompilerCounters* counters = new CompilerCounters("compilerThread", i, CHECK);
 870     CompilerThread* new_thread = make_compiler_thread(name_buffer, _c2_method_queue, counters, CHECK);
 871     _method_threads->append(new_thread);
 872   }


1101         method->set_code(method, saved);
1102         return saved;
1103       }
1104     }
1105 
1106   } else {
1107     // osr compilation
1108 #ifndef TIERED
1109     // seems like an assert of dubious value
1110     assert(comp_level == CompLevel_highest_tier,
1111            "all OSR compiles are assumed to be at a single compilation lavel");
1112 #endif // TIERED
1113     // We accept a higher level osr method
1114     nmethod* nm = method->lookup_osr_nmethod_for(osr_bci, comp_level, false);
1115     if (nm != NULL) return nm;
1116     if (method->is_not_osr_compilable()) return NULL;
1117   }
1118 
1119   assert(!HAS_PENDING_EXCEPTION, "No exception should be present");
1120   // some prerequisites that are compiler specific
1121   if (compiler(comp_level)->is_c2()) {
1122     method->constants()->resolve_string_constants(CHECK_0);
1123     // Resolve all classes seen in the signature of the method
1124     // we are compiling.
1125     methodOopDesc::load_signature_classes(method, CHECK_0);
1126   }
1127 
1128   // If the method is native, do the lookup in the thread requesting
1129   // the compilation. Native lookups can load code, which is not
1130   // permitted during compilation.
1131   //
1132   // Note: A native method implies non-osr compilation which is
1133   //       checked with an assertion at the entry of this method.
1134   if (method->is_native()) {
1135     bool in_base_library;
1136     address adr = NativeLookup::lookup(method, in_base_library, THREAD);
1137     if (HAS_PENDING_EXCEPTION) {
1138       // In case of an exception looking up the method, we just forget
1139       // about it. The interpreter will kick-in and throw the exception.
1140       method->set_not_compilable(); // implies is_not_osr_compilable()
1141       CLEAR_PENDING_EXCEPTION;




 830 
 831     java_lang_Thread::set_daemon(thread_oop());
 832 
 833     compiler_thread->set_threadObj(thread_oop());
 834     Threads::add(compiler_thread);
 835     Thread::start(compiler_thread);
 836   }
 837   // Let go of Threads_lock before yielding
 838   os::yield(); // make sure that the compiler thread is started early (especially helpful on SOLARIS)
 839 
 840   return compiler_thread;
 841 }
 842 
 843 
 844 // ------------------------------------------------------------------
 845 // CompileBroker::init_compiler_threads
 846 //
 847 // Initialize the compilation queue
 848 void CompileBroker::init_compiler_threads(int c1_compiler_count, int c2_compiler_count) {
 849   EXCEPTION_MARK;
 850 #if !defined(ZERO) && !defined(SHARK)
 851   assert(c2_compiler_count > 0 || c1_compiler_count > 0, "No compilers?");
 852 #endif // !ZERO && !SHARK
 853   if (c2_compiler_count > 0) {
 854     _c2_method_queue  = new CompileQueue("C2MethodQueue",  MethodCompileQueue_lock);
 855   }
 856   if (c1_compiler_count > 0) {
 857     _c1_method_queue  = new CompileQueue("C1MethodQueue",  MethodCompileQueue_lock);
 858   }
 859 
 860   int compiler_count = c1_compiler_count + c2_compiler_count;
 861 
 862   _method_threads =
 863     new (ResourceObj::C_HEAP) GrowableArray<CompilerThread*>(compiler_count, true);
 864 
 865   char name_buffer[256];
 866   for (int i = 0; i < c2_compiler_count; i++) {
 867     // Create a name for our thread.
 868     sprintf(name_buffer, "C2 CompilerThread%d", i);
 869     CompilerCounters* counters = new CompilerCounters("compilerThread", i, CHECK);
 870     CompilerThread* new_thread = make_compiler_thread(name_buffer, _c2_method_queue, counters, CHECK);
 871     _method_threads->append(new_thread);
 872   }


1101         method->set_code(method, saved);
1102         return saved;
1103       }
1104     }
1105 
1106   } else {
1107     // osr compilation
1108 #ifndef TIERED
1109     // seems like an assert of dubious value
1110     assert(comp_level == CompLevel_highest_tier,
1111            "all OSR compiles are assumed to be at a single compilation lavel");
1112 #endif // TIERED
1113     // We accept a higher level osr method
1114     nmethod* nm = method->lookup_osr_nmethod_for(osr_bci, comp_level, false);
1115     if (nm != NULL) return nm;
1116     if (method->is_not_osr_compilable()) return NULL;
1117   }
1118 
1119   assert(!HAS_PENDING_EXCEPTION, "No exception should be present");
1120   // some prerequisites that are compiler specific
1121   if (compiler(comp_level)->is_c2() || compiler(comp_level)->is_c2()) {
1122     method->constants()->resolve_string_constants(CHECK_0);
1123     // Resolve all classes seen in the signature of the method
1124     // we are compiling.
1125     methodOopDesc::load_signature_classes(method, CHECK_0);
1126   }
1127 
1128   // If the method is native, do the lookup in the thread requesting
1129   // the compilation. Native lookups can load code, which is not
1130   // permitted during compilation.
1131   //
1132   // Note: A native method implies non-osr compilation which is
1133   //       checked with an assertion at the entry of this method.
1134   if (method->is_native()) {
1135     bool in_base_library;
1136     address adr = NativeLookup::lookup(method, in_base_library, THREAD);
1137     if (HAS_PENDING_EXCEPTION) {
1138       // In case of an exception looking up the method, we just forget
1139       // about it. The interpreter will kick-in and throw the exception.
1140       method->set_not_compilable(); // implies is_not_osr_compilable()
1141       CLEAR_PENDING_EXCEPTION;