< prev index next >

src/share/vm/compiler/compileBroker.cpp

Print this page
rev 13469 : 8186437: Lock held when compiler thread creation fails.
Reviewed-by: stuefe


 703                        string,
 704                        CHECK_0);
 705 
 706   {
 707     MutexLocker mu(Threads_lock, THREAD);
 708     if (compiler_thread) {
 709       thread = new CompilerThread(queue, counters);
 710     } else {
 711       thread = new CodeCacheSweeperThread();
 712     }
 713     // At this point the new CompilerThread data-races with this startup
 714     // thread (which I believe is the primoridal thread and NOT the VM
 715     // thread).  This means Java bytecodes being executed at startup can
 716     // queue compile jobs which will run at whatever default priority the
 717     // newly created CompilerThread runs at.
 718 
 719 
 720     // At this point it may be possible that no osthread was created for the
 721     // JavaThread due to lack of memory. We would have to throw an exception
 722     // in that case. However, since this must work and we do not allow
 723     // exceptions anyway, check and abort if this fails.

 724 
 725     if (thread == NULL || thread->osthread() == NULL) {
 726       vm_exit_during_initialization("java.lang.OutOfMemoryError",
 727                                     os::native_thread_creation_failed_msg());
 728     }
 729 
 730     java_lang_Thread::set_thread(thread_oop(), thread);
 731 
 732     // Note that this only sets the JavaThread _priority field, which by
 733     // definition is limited to Java priorities and not OS priorities.
 734     // The os-priority is set in the CompilerThread startup code itself
 735 
 736     java_lang_Thread::set_priority(thread_oop(), NearMaxPriority);
 737 
 738     // Note that we cannot call os::set_priority because it expects Java
 739     // priorities and we are *explicitly* using OS priorities so that it's
 740     // possible to set the compiler thread priority higher than any Java
 741     // thread.
 742 
 743     int native_prio = CompilerThreadPriority;
 744     if (native_prio == -1) {
 745       if (UseCriticalCompilerThreadPriority) {
 746         native_prio = os::java_to_os_priority[CriticalPriority];
 747       } else {
 748         native_prio = os::java_to_os_priority[NearMaxPriority];
 749       }
 750     }
 751     os::set_native_priority(thread, native_prio);
 752 
 753     java_lang_Thread::set_daemon(thread_oop());
 754 
 755     thread->set_threadObj(thread_oop());
 756     if (compiler_thread) {
 757       thread->as_CompilerThread()->set_compiler(comp);
 758     }
 759     Threads::add(thread);
 760     Thread::start(thread);







 761   }
 762 
 763   // Let go of Threads_lock before yielding
 764   os::naked_yield(); // make sure that the compiler thread is started early (especially helpful on SOLARIS)
 765 
 766   return thread;
 767 }
 768 
 769 
 770 void CompileBroker::init_compiler_sweeper_threads(int c1_compiler_count, int c2_compiler_count) {
 771   EXCEPTION_MARK;
 772 #if !defined(ZERO) && !defined(SHARK)
 773   assert(c2_compiler_count > 0 || c1_compiler_count > 0, "No compilers?");
 774 #endif // !ZERO && !SHARK
 775   // Initialize the compilation queue
 776   if (c2_compiler_count > 0) {
 777     const char* name = JVMCI_ONLY(UseJVMCICompiler ? "JVMCI compile queue" :) "C2 compile queue";
 778     _c2_compile_queue  = new CompileQueue(name);
 779     _compilers[1]->set_num_compiler_threads(c2_compiler_count);
 780   }




 703                        string,
 704                        CHECK_0);
 705 
 706   {
 707     MutexLocker mu(Threads_lock, THREAD);
 708     if (compiler_thread) {
 709       thread = new CompilerThread(queue, counters);
 710     } else {
 711       thread = new CodeCacheSweeperThread();
 712     }
 713     // At this point the new CompilerThread data-races with this startup
 714     // thread (which I believe is the primoridal thread and NOT the VM
 715     // thread).  This means Java bytecodes being executed at startup can
 716     // queue compile jobs which will run at whatever default priority the
 717     // newly created CompilerThread runs at.
 718 
 719 
 720     // At this point it may be possible that no osthread was created for the
 721     // JavaThread due to lack of memory. We would have to throw an exception
 722     // in that case. However, since this must work and we do not allow
 723     // exceptions anyway, check and abort if this fails. But first release the
 724     // lock.
 725 
 726     if (thread != NULL && thread->osthread() != NULL) {



 727 
 728       java_lang_Thread::set_thread(thread_oop(), thread);
 729 
 730       // Note that this only sets the JavaThread _priority field, which by
 731       // definition is limited to Java priorities and not OS priorities.
 732       // The os-priority is set in the CompilerThread startup code itself
 733 
 734       java_lang_Thread::set_priority(thread_oop(), NearMaxPriority);
 735 
 736       // Note that we cannot call os::set_priority because it expects Java
 737       // priorities and we are *explicitly* using OS priorities so that it's
 738       // possible to set the compiler thread priority higher than any Java
 739       // thread.
 740 
 741       int native_prio = CompilerThreadPriority;
 742       if (native_prio == -1) {
 743         if (UseCriticalCompilerThreadPriority) {
 744           native_prio = os::java_to_os_priority[CriticalPriority];
 745         } else {
 746           native_prio = os::java_to_os_priority[NearMaxPriority];
 747         }
 748       }
 749       os::set_native_priority(thread, native_prio);
 750 
 751       java_lang_Thread::set_daemon(thread_oop());
 752 
 753       thread->set_threadObj(thread_oop());
 754       if (compiler_thread) {
 755         thread->as_CompilerThread()->set_compiler(comp);
 756       }
 757       Threads::add(thread);
 758       Thread::start(thread);
 759     }
 760   }
 761 
 762   // First release lock before aborting VM.
 763   if (thread == NULL || thread->osthread() == NULL) {
 764     vm_exit_during_initialization("java.lang.OutOfMemoryError",
 765                                   os::native_thread_creation_failed_msg());
 766   }
 767 
 768   // Let go of Threads_lock before yielding
 769   os::naked_yield(); // make sure that the compiler thread is started early (especially helpful on SOLARIS)
 770 
 771   return thread;
 772 }
 773 
 774 
 775 void CompileBroker::init_compiler_sweeper_threads(int c1_compiler_count, int c2_compiler_count) {
 776   EXCEPTION_MARK;
 777 #if !defined(ZERO) && !defined(SHARK)
 778   assert(c2_compiler_count > 0 || c1_compiler_count > 0, "No compilers?");
 779 #endif // !ZERO && !SHARK
 780   // Initialize the compilation queue
 781   if (c2_compiler_count > 0) {
 782     const char* name = JVMCI_ONLY(UseJVMCICompiler ? "JVMCI compile queue" :) "C2 compile queue";
 783     _c2_compile_queue  = new CompileQueue(name);
 784     _compilers[1]->set_num_compiler_threads(c2_compiler_count);
 785   }


< prev index next >