738 string, |
738 string, |
739 CHECK_NH); |
739 CHECK_NH); |
740 } |
740 } |
741 |
741 |
742 |
742 |
743 JavaThread* CompileBroker::make_thread(jobject thread_handle, CompileQueue* queue, |
743 JavaThread* CompileBroker::make_thread(jobject thread_handle, CompileQueue* queue, AbstractCompiler* comp, TRAPS) { |
744 AbstractCompiler* comp, bool compiler_thread, TRAPS) { |
|
745 JavaThread* thread = NULL; |
744 JavaThread* thread = NULL; |
746 { |
745 { |
747 MutexLocker mu(Threads_lock, THREAD); |
746 MutexLocker mu(Threads_lock, THREAD); |
748 if (compiler_thread) { |
747 if (comp != NULL) { |
749 if (!InjectCompilerCreationFailure || comp->num_compiler_threads() == 0) { |
748 if (!InjectCompilerCreationFailure || comp->num_compiler_threads() == 0) { |
750 CompilerCounters* counters = new CompilerCounters(); |
749 CompilerCounters* counters = new CompilerCounters(); |
751 thread = new CompilerThread(queue, counters); |
750 thread = new CompilerThread(queue, counters); |
752 } |
751 } |
753 } else { |
752 } else { |
792 os::set_native_priority(thread, native_prio); |
791 os::set_native_priority(thread, native_prio); |
793 |
792 |
794 java_lang_Thread::set_daemon(JNIHandles::resolve_non_null(thread_handle)); |
793 java_lang_Thread::set_daemon(JNIHandles::resolve_non_null(thread_handle)); |
795 |
794 |
796 thread->set_threadObj(JNIHandles::resolve_non_null(thread_handle)); |
795 thread->set_threadObj(JNIHandles::resolve_non_null(thread_handle)); |
797 if (compiler_thread) { |
796 if (comp != NULL) { |
798 thread->as_CompilerThread()->set_compiler(comp); |
797 thread->as_CompilerThread()->set_compiler(comp); |
799 } |
798 } |
800 Threads::add(thread); |
799 Threads::add(thread); |
801 Thread::start(thread); |
800 Thread::start(thread); |
802 } |
801 } |
803 } |
802 } |
804 |
803 |
805 // First release lock before aborting VM. |
804 // First release lock before aborting VM. |
806 if (thread == NULL || thread->osthread() == NULL) { |
805 if (thread == NULL || thread->osthread() == NULL) { |
807 if (UseDynamicNumberOfCompilerThreads && comp->num_compiler_threads() > 0) { |
806 if (UseDynamicNumberOfCompilerThreads && comp != NULL && comp->num_compiler_threads() > 0) { |
808 if (thread != NULL) { |
807 if (thread != NULL) { |
809 thread->smr_delete(); |
808 thread->smr_delete(); |
810 } |
809 } |
811 return NULL; |
810 return NULL; |
812 } |
811 } |
842 char name_buffer[256]; |
841 char name_buffer[256]; |
843 |
842 |
844 for (int i = 0; i < _c2_count; i++) { |
843 for (int i = 0; i < _c2_count; i++) { |
845 // Create a name for our thread. |
844 // Create a name for our thread. |
846 sprintf(name_buffer, "%s CompilerThread%d", _compilers[1]->name(), i); |
845 sprintf(name_buffer, "%s CompilerThread%d", _compilers[1]->name(), i); |
847 jobject thread_handle = JNIHandles::make_global(create_thread_oop(name_buffer, THREAD)); |
846 Handle thread_oop = create_thread_oop(name_buffer, CHECK); |
|
847 jobject thread_handle = JNIHandles::make_global(thread_oop); |
848 _compiler2_objects[i] = thread_handle; |
848 _compiler2_objects[i] = thread_handle; |
849 _compiler2_logs[i] = NULL; |
849 _compiler2_logs[i] = NULL; |
850 |
850 |
851 if (!UseDynamicNumberOfCompilerThreads || i == 0) { |
851 if (!UseDynamicNumberOfCompilerThreads || i == 0) { |
852 JavaThread *ct = make_thread(thread_handle, _c2_compile_queue, _compilers[1], /* compiler_thread */ true, CHECK); |
852 JavaThread *ct = make_thread(thread_handle, _c2_compile_queue, _compilers[1], CHECK); |
853 assert(ct != NULL, "should have been handled for initial thread"); |
853 assert(ct != NULL, "should have been handled for initial thread"); |
854 _compilers[1]->set_num_compiler_threads(i + 1); |
854 _compilers[1]->set_num_compiler_threads(i + 1); |
855 if (TraceCompilerThreads) { |
855 if (TraceCompilerThreads) { |
856 ResourceMark rm; |
856 ResourceMark rm; |
857 MutexLocker mu(Threads_lock); |
857 MutexLocker mu(Threads_lock); |
861 } |
861 } |
862 |
862 |
863 for (int i = 0; i < _c1_count; i++) { |
863 for (int i = 0; i < _c1_count; i++) { |
864 // Create a name for our thread. |
864 // Create a name for our thread. |
865 sprintf(name_buffer, "C1 CompilerThread%d", i); |
865 sprintf(name_buffer, "C1 CompilerThread%d", i); |
866 jobject thread_handle = JNIHandles::make_global(create_thread_oop(name_buffer, THREAD)); |
866 Handle thread_oop = create_thread_oop(name_buffer, CHECK); |
|
867 jobject thread_handle = JNIHandles::make_global(thread_oop); |
867 _compiler1_objects[i] = thread_handle; |
868 _compiler1_objects[i] = thread_handle; |
868 _compiler1_logs[i] = NULL; |
869 _compiler1_logs[i] = NULL; |
869 |
870 |
870 if (!UseDynamicNumberOfCompilerThreads || i == 0) { |
871 if (!UseDynamicNumberOfCompilerThreads || i == 0) { |
871 JavaThread *ct = make_thread(thread_handle, _c1_compile_queue, _compilers[0], /* compiler_thread */ true, CHECK); |
872 JavaThread *ct = make_thread(thread_handle, _c1_compile_queue, _compilers[0], CHECK); |
872 assert(ct != NULL, "should have been handled for initial thread"); |
873 assert(ct != NULL, "should have been handled for initial thread"); |
873 _compilers[0]->set_num_compiler_threads(i + 1); |
874 _compilers[0]->set_num_compiler_threads(i + 1); |
874 if (TraceCompilerThreads) { |
875 if (TraceCompilerThreads) { |
875 ResourceMark rm; |
876 ResourceMark rm; |
876 MutexLocker mu(Threads_lock); |
877 MutexLocker mu(Threads_lock); |
883 PerfDataManager::create_constant(SUN_CI, "threads", PerfData::U_Bytes, _c1_count + _c2_count, CHECK); |
884 PerfDataManager::create_constant(SUN_CI, "threads", PerfData::U_Bytes, _c1_count + _c2_count, CHECK); |
884 } |
885 } |
885 |
886 |
886 if (MethodFlushing) { |
887 if (MethodFlushing) { |
887 // Initialize the sweeper thread |
888 // Initialize the sweeper thread |
888 jobject thread_handle = JNIHandles::make_local(THREAD, create_thread_oop("Sweeper thread", THREAD)()); |
889 Handle thread_oop = create_thread_oop("Sweeper thread", CHECK); |
889 make_thread(thread_handle, NULL, NULL, /* compiler_thread */ false, CHECK); |
890 jobject thread_handle = JNIHandles::make_local(THREAD, thread_oop()); |
|
891 make_thread(thread_handle, NULL, NULL, CHECK); |
890 } |
892 } |
891 } |
893 } |
892 |
894 |
893 void CompileBroker::possibly_add_compiler_threads() { |
895 void CompileBroker::possibly_add_compiler_threads() { |
894 EXCEPTION_MARK; |
896 EXCEPTION_MARK; |
907 _c2_compile_queue->size() / 2, |
909 _c2_compile_queue->size() / 2, |
908 (int)(available_memory / (200*M)), |
910 (int)(available_memory / (200*M)), |
909 (int)(available_cc_np / (128*K))); |
911 (int)(available_cc_np / (128*K))); |
910 |
912 |
911 for (int i = old_c2_count; i < new_c2_count; i++) { |
913 for (int i = old_c2_count; i < new_c2_count; i++) { |
912 JavaThread *ct = make_thread(compiler2_object(i), _c2_compile_queue, _compilers[1], true, CHECK); |
914 JavaThread *ct = make_thread(compiler2_object(i), _c2_compile_queue, _compilers[1], CHECK); |
913 if (ct == NULL) break; |
915 if (ct == NULL) break; |
914 _compilers[1]->set_num_compiler_threads(i + 1); |
916 _compilers[1]->set_num_compiler_threads(i + 1); |
915 if (TraceCompilerThreads) { |
917 if (TraceCompilerThreads) { |
916 ResourceMark rm; |
918 ResourceMark rm; |
917 MutexLocker mu(Threads_lock); |
919 MutexLocker mu(Threads_lock); |
927 _c1_compile_queue->size() / 4, |
929 _c1_compile_queue->size() / 4, |
928 (int)(available_memory / (100*M)), |
930 (int)(available_memory / (100*M)), |
929 (int)(available_cc_p / (128*K))); |
931 (int)(available_cc_p / (128*K))); |
930 |
932 |
931 for (int i = old_c1_count; i < new_c1_count; i++) { |
933 for (int i = old_c1_count; i < new_c1_count; i++) { |
932 JavaThread *ct = make_thread(compiler1_object(i), _c1_compile_queue, _compilers[0], true, CHECK); |
934 JavaThread *ct = make_thread(compiler1_object(i), _c1_compile_queue, _compilers[0], CHECK); |
933 if (ct == NULL) break; |
935 if (ct == NULL) break; |
934 _compilers[0]->set_num_compiler_threads(i + 1); |
936 _compilers[0]->set_num_compiler_threads(i + 1); |
935 if (TraceCompilerThreads) { |
937 if (TraceCompilerThreads) { |
936 ResourceMark rm; |
938 ResourceMark rm; |
937 MutexLocker mu(Threads_lock); |
939 MutexLocker mu(Threads_lock); |