594 |
594 |
595 // ------------------------------------------------------------------ |
595 // ------------------------------------------------------------------ |
596 // CompileBroker::compilation_init |
596 // CompileBroker::compilation_init |
597 // |
597 // |
598 // Initialize the Compilation object |
598 // Initialize the Compilation object |
599 void CompileBroker::compilation_init_phase1(TRAPS) { |
599 void CompileBroker::compilation_init_phase1(Thread* THREAD) { |
600 // No need to initialize compilation system if we do not use it. |
600 // No need to initialize compilation system if we do not use it. |
601 if (!UseCompiler) { |
601 if (!UseCompiler) { |
602 return; |
602 return; |
603 } |
603 } |
604 // Set the interface to the current compiler(s). |
604 // Set the interface to the current compiler(s). |
645 // Start the compiler thread(s) and the sweeper thread |
645 // Start the compiler thread(s) and the sweeper thread |
646 init_compiler_sweeper_threads(); |
646 init_compiler_sweeper_threads(); |
647 // totalTime performance counter is always created as it is required |
647 // totalTime performance counter is always created as it is required |
648 // by the implementation of java.lang.management.CompilationMBean. |
648 // by the implementation of java.lang.management.CompilationMBean. |
649 { |
649 { |
|
650 // Ensure OOM leads to vm_exit_during_initialization. |
650 EXCEPTION_MARK; |
651 EXCEPTION_MARK; |
651 _perf_total_compilation = |
652 _perf_total_compilation = |
652 PerfDataManager::create_counter(JAVA_CI, "totalTime", |
653 PerfDataManager::create_counter(JAVA_CI, "totalTime", |
653 PerfData::U_Ticks, CHECK); |
654 PerfData::U_Ticks, CHECK); |
654 } |
655 } |
759 string, |
760 string, |
760 CHECK_NH); |
761 CHECK_NH); |
761 } |
762 } |
762 |
763 |
763 |
764 |
764 JavaThread* CompileBroker::make_thread(jobject thread_handle, CompileQueue* queue, AbstractCompiler* comp, TRAPS) { |
765 JavaThread* CompileBroker::make_thread(jobject thread_handle, CompileQueue* queue, AbstractCompiler* comp, Thread* THREAD) { |
765 JavaThread* thread = NULL; |
766 JavaThread* new_thread = NULL; |
766 { |
767 { |
767 MutexLocker mu(Threads_lock, THREAD); |
768 MutexLocker mu(Threads_lock, THREAD); |
768 if (comp != NULL) { |
769 if (comp != NULL) { |
769 if (!InjectCompilerCreationFailure || comp->num_compiler_threads() == 0) { |
770 if (!InjectCompilerCreationFailure || comp->num_compiler_threads() == 0) { |
770 CompilerCounters* counters = new CompilerCounters(); |
771 CompilerCounters* counters = new CompilerCounters(); |
771 thread = new CompilerThread(queue, counters); |
772 new_thread = new CompilerThread(queue, counters); |
772 } |
773 } |
773 } else { |
774 } else { |
774 thread = new CodeCacheSweeperThread(); |
775 new_thread = new CodeCacheSweeperThread(); |
775 } |
776 } |
776 // At this point the new CompilerThread data-races with this startup |
777 // At this point the new CompilerThread data-races with this startup |
777 // thread (which I believe is the primoridal thread and NOT the VM |
778 // thread (which I believe is the primoridal thread and NOT the VM |
778 // thread). This means Java bytecodes being executed at startup can |
779 // thread). This means Java bytecodes being executed at startup can |
779 // queue compile jobs which will run at whatever default priority the |
780 // queue compile jobs which will run at whatever default priority the |
784 // JavaThread due to lack of memory. We would have to throw an exception |
785 // JavaThread due to lack of memory. We would have to throw an exception |
785 // in that case. However, since this must work and we do not allow |
786 // in that case. However, since this must work and we do not allow |
786 // exceptions anyway, check and abort if this fails. But first release the |
787 // exceptions anyway, check and abort if this fails. But first release the |
787 // lock. |
788 // lock. |
788 |
789 |
789 if (thread != NULL && thread->osthread() != NULL) { |
790 if (new_thread != NULL && new_thread->osthread() != NULL) { |
790 |
791 |
791 java_lang_Thread::set_thread(JNIHandles::resolve_non_null(thread_handle), thread); |
792 java_lang_Thread::set_thread(JNIHandles::resolve_non_null(thread_handle), new_thread); |
792 |
793 |
793 // Note that this only sets the JavaThread _priority field, which by |
794 // Note that this only sets the JavaThread _priority field, which by |
794 // definition is limited to Java priorities and not OS priorities. |
795 // definition is limited to Java priorities and not OS priorities. |
795 // The os-priority is set in the CompilerThread startup code itself |
796 // The os-priority is set in the CompilerThread startup code itself |
796 |
797 |
807 native_prio = os::java_to_os_priority[CriticalPriority]; |
808 native_prio = os::java_to_os_priority[CriticalPriority]; |
808 } else { |
809 } else { |
809 native_prio = os::java_to_os_priority[NearMaxPriority]; |
810 native_prio = os::java_to_os_priority[NearMaxPriority]; |
810 } |
811 } |
811 } |
812 } |
812 os::set_native_priority(thread, native_prio); |
813 os::set_native_priority(new_thread, native_prio); |
813 |
814 |
814 java_lang_Thread::set_daemon(JNIHandles::resolve_non_null(thread_handle)); |
815 java_lang_Thread::set_daemon(JNIHandles::resolve_non_null(thread_handle)); |
815 |
816 |
816 thread->set_threadObj(JNIHandles::resolve_non_null(thread_handle)); |
817 new_thread->set_threadObj(JNIHandles::resolve_non_null(thread_handle)); |
817 if (comp != NULL) { |
818 if (comp != NULL) { |
818 thread->as_CompilerThread()->set_compiler(comp); |
819 new_thread->as_CompilerThread()->set_compiler(comp); |
819 } |
820 } |
820 Threads::add(thread); |
821 Threads::add(new_thread); |
821 Thread::start(thread); |
822 Thread::start(new_thread); |
822 } |
823 } |
823 } |
824 } |
824 |
825 |
825 // First release lock before aborting VM. |
826 // First release lock before aborting VM. |
826 if (thread == NULL || thread->osthread() == NULL) { |
827 if (new_thread == NULL || new_thread->osthread() == NULL) { |
827 if (UseDynamicNumberOfCompilerThreads && comp != NULL && comp->num_compiler_threads() > 0) { |
828 if (UseDynamicNumberOfCompilerThreads && comp != NULL && comp->num_compiler_threads() > 0) { |
828 if (thread != NULL) { |
829 if (new_thread != NULL) { |
829 thread->smr_delete(); |
830 new_thread->smr_delete(); |
830 } |
831 } |
831 return NULL; |
832 return NULL; |
832 } |
833 } |
833 vm_exit_during_initialization("java.lang.OutOfMemoryError", |
834 vm_exit_during_initialization("java.lang.OutOfMemoryError", |
834 os::native_thread_creation_failed_msg()); |
835 os::native_thread_creation_failed_msg()); |
835 } |
836 } |
836 |
837 |
837 // Let go of Threads_lock before yielding |
838 // Let go of Threads_lock before yielding |
838 os::naked_yield(); // make sure that the compiler thread is started early (especially helpful on SOLARIS) |
839 os::naked_yield(); // make sure that the compiler thread is started early (especially helpful on SOLARIS) |
839 |
840 |
840 return thread; |
841 return new_thread; |
841 } |
842 } |
842 |
843 |
843 |
844 |
844 void CompileBroker::init_compiler_sweeper_threads() { |
845 void CompileBroker::init_compiler_sweeper_threads() { |
|
846 // Ensure any exceptions lead to vm_exit_during_initialization. |
845 EXCEPTION_MARK; |
847 EXCEPTION_MARK; |
846 #if !defined(ZERO) |
848 #if !defined(ZERO) |
847 assert(_c2_count > 0 || _c1_count > 0, "No compilers?"); |
849 assert(_c2_count > 0 || _c1_count > 0, "No compilers?"); |
848 #endif // !ZERO |
850 #endif // !ZERO |
849 // Initialize the compilation queue |
851 // Initialize the compilation queue |
873 JVMCI_ONLY(}) |
875 JVMCI_ONLY(}) |
874 _compiler2_objects[i] = thread_handle; |
876 _compiler2_objects[i] = thread_handle; |
875 _compiler2_logs[i] = NULL; |
877 _compiler2_logs[i] = NULL; |
876 |
878 |
877 if (!UseDynamicNumberOfCompilerThreads || i == 0) { |
879 if (!UseDynamicNumberOfCompilerThreads || i == 0) { |
878 JavaThread *ct = make_thread(thread_handle, _c2_compile_queue, _compilers[1], CHECK); |
880 JavaThread *ct = make_thread(thread_handle, _c2_compile_queue, _compilers[1], THREAD); |
879 assert(ct != NULL, "should have been handled for initial thread"); |
881 assert(ct != NULL, "should have been handled for initial thread"); |
880 _compilers[1]->set_num_compiler_threads(i + 1); |
882 _compilers[1]->set_num_compiler_threads(i + 1); |
881 if (TraceCompilerThreads) { |
883 if (TraceCompilerThreads) { |
882 ResourceMark rm; |
884 ResourceMark rm; |
883 MutexLocker mu(Threads_lock); |
885 MutexLocker mu(Threads_lock); |
893 jobject thread_handle = JNIHandles::make_global(thread_oop); |
895 jobject thread_handle = JNIHandles::make_global(thread_oop); |
894 _compiler1_objects[i] = thread_handle; |
896 _compiler1_objects[i] = thread_handle; |
895 _compiler1_logs[i] = NULL; |
897 _compiler1_logs[i] = NULL; |
896 |
898 |
897 if (!UseDynamicNumberOfCompilerThreads || i == 0) { |
899 if (!UseDynamicNumberOfCompilerThreads || i == 0) { |
898 JavaThread *ct = make_thread(thread_handle, _c1_compile_queue, _compilers[0], CHECK); |
900 JavaThread *ct = make_thread(thread_handle, _c1_compile_queue, _compilers[0], THREAD); |
899 assert(ct != NULL, "should have been handled for initial thread"); |
901 assert(ct != NULL, "should have been handled for initial thread"); |
900 _compilers[0]->set_num_compiler_threads(i + 1); |
902 _compilers[0]->set_num_compiler_threads(i + 1); |
901 if (TraceCompilerThreads) { |
903 if (TraceCompilerThreads) { |
902 ResourceMark rm; |
904 ResourceMark rm; |
903 MutexLocker mu(Threads_lock); |
905 MutexLocker mu(Threads_lock); |
912 |
914 |
913 if (MethodFlushing) { |
915 if (MethodFlushing) { |
914 // Initialize the sweeper thread |
916 // Initialize the sweeper thread |
915 Handle thread_oop = create_thread_oop("Sweeper thread", CHECK); |
917 Handle thread_oop = create_thread_oop("Sweeper thread", CHECK); |
916 jobject thread_handle = JNIHandles::make_local(THREAD, thread_oop()); |
918 jobject thread_handle = JNIHandles::make_local(THREAD, thread_oop()); |
917 make_thread(thread_handle, NULL, NULL, CHECK); |
919 make_thread(thread_handle, NULL, NULL, THREAD); |
918 } |
920 } |
919 } |
921 } |
920 |
922 |
921 void CompileBroker::possibly_add_compiler_threads() { |
923 void CompileBroker::possibly_add_compiler_threads(Thread* THREAD) { |
922 EXCEPTION_MARK; |
|
923 |
924 |
924 julong available_memory = os::available_memory(); |
925 julong available_memory = os::available_memory(); |
925 // If SegmentedCodeCache is off, both values refer to the single heap (with type CodeBlobType::All). |
926 // If SegmentedCodeCache is off, both values refer to the single heap (with type CodeBlobType::All). |
926 size_t available_cc_np = CodeCache::unallocated_capacity(CodeBlobType::MethodNonProfiled), |
927 size_t available_cc_np = CodeCache::unallocated_capacity(CodeBlobType::MethodNonProfiled), |
927 available_cc_p = CodeCache::unallocated_capacity(CodeBlobType::MethodProfiled); |
928 available_cc_p = CodeCache::unallocated_capacity(CodeBlobType::MethodProfiled); |
968 jobject thread_handle = JNIHandles::make_global(thread_oop); |
969 jobject thread_handle = JNIHandles::make_global(thread_oop); |
969 assert(compiler2_object(i) == NULL, "Old one must be released!"); |
970 assert(compiler2_object(i) == NULL, "Old one must be released!"); |
970 _compiler2_objects[i] = thread_handle; |
971 _compiler2_objects[i] = thread_handle; |
971 } |
972 } |
972 #endif |
973 #endif |
973 JavaThread *ct = make_thread(compiler2_object(i), _c2_compile_queue, _compilers[1], CHECK); |
974 JavaThread *ct = make_thread(compiler2_object(i), _c2_compile_queue, _compilers[1], THREAD); |
974 if (ct == NULL) break; |
975 if (ct == NULL) break; |
975 _compilers[1]->set_num_compiler_threads(i + 1); |
976 _compilers[1]->set_num_compiler_threads(i + 1); |
976 if (TraceCompilerThreads) { |
977 if (TraceCompilerThreads) { |
977 ResourceMark rm; |
978 ResourceMark rm; |
978 MutexLocker mu(Threads_lock); |
979 MutexLocker mu(Threads_lock); |
988 _c1_compile_queue->size() / 4, |
989 _c1_compile_queue->size() / 4, |
989 (int)(available_memory / (100*M)), |
990 (int)(available_memory / (100*M)), |
990 (int)(available_cc_p / (128*K))); |
991 (int)(available_cc_p / (128*K))); |
991 |
992 |
992 for (int i = old_c1_count; i < new_c1_count; i++) { |
993 for (int i = old_c1_count; i < new_c1_count; i++) { |
993 JavaThread *ct = make_thread(compiler1_object(i), _c1_compile_queue, _compilers[0], CHECK); |
994 JavaThread *ct = make_thread(compiler1_object(i), _c1_compile_queue, _compilers[0], THREAD); |
994 if (ct == NULL) break; |
995 if (ct == NULL) break; |
995 _compilers[0]->set_num_compiler_threads(i + 1); |
996 _compilers[0]->set_num_compiler_threads(i + 1); |
996 if (TraceCompilerThreads) { |
997 if (TraceCompilerThreads) { |
997 ResourceMark rm; |
998 ResourceMark rm; |
998 MutexLocker mu(Threads_lock); |
999 MutexLocker mu(Threads_lock); |
1509 MutexLocker locker(MethodCompileQueue_lock, thread); |
1510 MutexLocker locker(MethodCompileQueue_lock, thread); |
1510 return assign_compile_id(method, osr_bci); |
1511 return assign_compile_id(method, osr_bci); |
1511 } |
1512 } |
1512 |
1513 |
1513 // ------------------------------------------------------------------ |
1514 // ------------------------------------------------------------------ |
1514 // CompileBroker::preload_classes |
|
1515 void CompileBroker::preload_classes(const methodHandle& method, TRAPS) { |
|
1516 // Move this code over from c1_Compiler.cpp |
|
1517 ShouldNotReachHere(); |
|
1518 } |
|
1519 |
|
1520 |
|
1521 // ------------------------------------------------------------------ |
|
1522 // CompileBroker::create_compile_task |
1515 // CompileBroker::create_compile_task |
1523 // |
1516 // |
1524 // Create a CompileTask object representing the current request for |
1517 // Create a CompileTask object representing the current request for |
1525 // compilation. Add this task to the queue. |
1518 // compilation. Add this task to the queue. |
1526 CompileTask* CompileBroker::create_compile_task(CompileQueue* queue, |
1519 CompileTask* CompileBroker::create_compile_task(CompileQueue* queue, |