< prev index next >

src/hotspot/share/compiler/compileBroker.cpp

Print this page
rev 60703 : 8227745, 8233915: Enable Escape Analysis for Better Performance in the Presence of JVMTI Agents
Reviewed-by: mdoerr, goetz


 788   }
 789 }
 790 
 791 // Completes compiler initialization. Compilation requests submitted
 792 // prior to this will be silently ignored.
 793 void CompileBroker::compilation_init_phase2() {
 794   _initialized = true;
 795 }
 796 
 797 Handle CompileBroker::create_thread_oop(const char* name, TRAPS) {
 798   Handle string = java_lang_String::create_from_str(name, CHECK_NH);
 799   Handle thread_group(THREAD, Universe::system_thread_group());
 800   return JavaCalls::construct_new_instance(
 801                        SystemDictionary::Thread_klass(),
 802                        vmSymbols::threadgroup_string_void_signature(),
 803                        thread_group,
 804                        string,
 805                        CHECK_NH);
 806 }
 807 



































































 808 
 809 JavaThread* CompileBroker::make_thread(jobject thread_handle, CompileQueue* queue, AbstractCompiler* comp, Thread* THREAD) {
 810   JavaThread* new_thread = NULL;
 811   {
 812     MutexLocker mu(THREAD, Threads_lock);
 813     if (comp != NULL) {


 814       if (!InjectCompilerCreationFailure || comp->num_compiler_threads() == 0) {
 815         CompilerCounters* counters = new CompilerCounters();
 816         new_thread = new CompilerThread(queue, counters);
 817       }
 818     } else {

 819       new_thread = new CodeCacheSweeperThread();








 820     }

 821     // At this point the new CompilerThread data-races with this startup
 822     // thread (which I believe is the primoridal thread and NOT the VM
 823     // thread).  This means Java bytecodes being executed at startup can
 824     // queue compile jobs which will run at whatever default priority the
 825     // newly created CompilerThread runs at.
 826 
 827 
 828     // At this point it may be possible that no osthread was created for the
 829     // JavaThread due to lack of memory. We would have to throw an exception
 830     // in that case. However, since this must work and we do not allow
 831     // exceptions anyway, check and abort if this fails. But first release the
 832     // lock.
 833 
 834     if (new_thread != NULL && new_thread->osthread() != NULL) {
 835 
 836       java_lang_Thread::set_thread(JNIHandles::resolve_non_null(thread_handle), new_thread);
 837 
 838       // Note that this only sets the JavaThread _priority field, which by
 839       // definition is limited to Java priorities and not OS priorities.
 840       // The os-priority is set in the CompilerThread startup code itself


 842       java_lang_Thread::set_priority(JNIHandles::resolve_non_null(thread_handle), NearMaxPriority);
 843 
 844       // Note that we cannot call os::set_priority because it expects Java
 845       // priorities and we are *explicitly* using OS priorities so that it's
 846       // possible to set the compiler thread priority higher than any Java
 847       // thread.
 848 
 849       int native_prio = CompilerThreadPriority;
 850       if (native_prio == -1) {
 851         if (UseCriticalCompilerThreadPriority) {
 852           native_prio = os::java_to_os_priority[CriticalPriority];
 853         } else {
 854           native_prio = os::java_to_os_priority[NearMaxPriority];
 855         }
 856       }
 857       os::set_native_priority(new_thread, native_prio);
 858 
 859       java_lang_Thread::set_daemon(JNIHandles::resolve_non_null(thread_handle));
 860 
 861       new_thread->set_threadObj(JNIHandles::resolve_non_null(thread_handle));
 862       if (comp != NULL) {
 863         new_thread->as_CompilerThread()->set_compiler(comp);
 864       }
 865       Threads::add(new_thread);
 866       Thread::start(new_thread);
 867     }
 868   }
 869 
 870   // First release lock before aborting VM.
 871   if (new_thread == NULL || new_thread->osthread() == NULL) {
 872     if (UseDynamicNumberOfCompilerThreads && comp != NULL && comp->num_compiler_threads() > 0) {
 873       if (new_thread != NULL) {
 874         new_thread->smr_delete();
 875       }
 876       return NULL;
 877     }
 878     vm_exit_during_initialization("java.lang.OutOfMemoryError",
 879                                   os::native_thread_creation_failed_msg());
 880   }
 881 
 882   // Let go of Threads_lock before yielding
 883   os::naked_yield(); // make sure that the compiler thread is started early (especially helpful on SOLARIS)
 884 
 885   return new_thread;
 886 }
 887 
 888 
 889 void CompileBroker::init_compiler_sweeper_threads() {
 890   NMethodSweeper::set_sweep_threshold_bytes(static_cast<size_t>(SweeperThreshold * ReservedCodeCacheSize / 100.0));
 891   log_info(codecache, sweep)("Sweeper threshold: " SIZE_FORMAT " bytes", NMethodSweeper::sweep_threshold_bytes());
 892 


 907     _compiler1_objects = NEW_C_HEAP_ARRAY(jobject, _c1_count, mtCompiler);
 908     _compiler1_logs = NEW_C_HEAP_ARRAY(CompileLog*, _c1_count, mtCompiler);
 909   }
 910 
 911   char name_buffer[256];
 912 
 913   for (int i = 0; i < _c2_count; i++) {
 914     jobject thread_handle = NULL;
 915     // Create all j.l.Thread objects for C1 and C2 threads here, but only one
 916     // for JVMCI compiler which can create further ones on demand.
 917     JVMCI_ONLY(if (!UseJVMCICompiler || !UseDynamicNumberOfCompilerThreads || i == 0) {)
 918     // Create a name for our thread.
 919     sprintf(name_buffer, "%s CompilerThread%d", _compilers[1]->name(), i);
 920     Handle thread_oop = create_thread_oop(name_buffer, CHECK);
 921     thread_handle = JNIHandles::make_global(thread_oop);
 922     JVMCI_ONLY(})
 923     _compiler2_objects[i] = thread_handle;
 924     _compiler2_logs[i] = NULL;
 925 
 926     if (!UseDynamicNumberOfCompilerThreads || i == 0) {
 927       JavaThread *ct = make_thread(thread_handle, _c2_compile_queue, _compilers[1], THREAD);
 928       assert(ct != NULL, "should have been handled for initial thread");
 929       _compilers[1]->set_num_compiler_threads(i + 1);
 930       if (TraceCompilerThreads) {
 931         ResourceMark rm;
 932         MutexLocker mu(Threads_lock);
 933         tty->print_cr("Added initial compiler thread %s", ct->get_thread_name());
 934       }
 935     }
 936   }
 937 
 938   for (int i = 0; i < _c1_count; i++) {
 939     // Create a name for our thread.
 940     sprintf(name_buffer, "C1 CompilerThread%d", i);
 941     Handle thread_oop = create_thread_oop(name_buffer, CHECK);
 942     jobject thread_handle = JNIHandles::make_global(thread_oop);
 943     _compiler1_objects[i] = thread_handle;
 944     _compiler1_logs[i] = NULL;
 945 
 946     if (!UseDynamicNumberOfCompilerThreads || i == 0) {
 947       JavaThread *ct = make_thread(thread_handle, _c1_compile_queue, _compilers[0], THREAD);
 948       assert(ct != NULL, "should have been handled for initial thread");
 949       _compilers[0]->set_num_compiler_threads(i + 1);
 950       if (TraceCompilerThreads) {
 951         ResourceMark rm;
 952         MutexLocker mu(Threads_lock);
 953         tty->print_cr("Added initial compiler thread %s", ct->get_thread_name());
 954       }
 955     }
 956   }
 957 
 958   if (UsePerfData) {
 959     PerfDataManager::create_constant(SUN_CI, "threads", PerfData::U_Bytes, _c1_count + _c2_count, CHECK);
 960   }
 961 
 962   if (MethodFlushing) {
 963     // Initialize the sweeper thread
 964     Handle thread_oop = create_thread_oop("Sweeper thread", CHECK);
 965     jobject thread_handle = JNIHandles::make_local(THREAD, thread_oop());
 966     make_thread(thread_handle, NULL, NULL, THREAD);











 967   }

 968 }
 969 
 970 void CompileBroker::possibly_add_compiler_threads(Thread* THREAD) {
 971 
 972   julong available_memory = os::available_memory();
 973   // If SegmentedCodeCache is off, both values refer to the single heap (with type CodeBlobType::All).
 974   size_t available_cc_np  = CodeCache::unallocated_capacity(CodeBlobType::MethodNonProfiled),
 975          available_cc_p   = CodeCache::unallocated_capacity(CodeBlobType::MethodProfiled);
 976 
 977   // Only do attempt to start additional threads if the lock is free.
 978   if (!CompileThread_lock->try_lock()) return;
 979 
 980   if (_c2_compile_queue != NULL) {
 981     int old_c2_count = _compilers[1]->num_compiler_threads();
 982     int new_c2_count = MIN4(_c2_count,
 983         _c2_compile_queue->size() / 2,
 984         (int)(available_memory / (200*M)),
 985         (int)(available_cc_np / (128*K)));
 986 
 987     for (int i = old_c2_count; i < new_c2_count; i++) {


1001           // We have to give up the lock temporarily for the Java calls.
1002           MutexUnlocker mu(CompileThread_lock);
1003           thread_oop = create_thread_oop(name_buffer, THREAD);
1004         }
1005         if (HAS_PENDING_EXCEPTION) {
1006           if (TraceCompilerThreads) {
1007             ResourceMark rm;
1008             tty->print_cr("JVMCI compiler thread creation failed:");
1009             PENDING_EXCEPTION->print();
1010           }
1011           CLEAR_PENDING_EXCEPTION;
1012           break;
1013         }
1014         // Check if another thread has beaten us during the Java calls.
1015         if (_compilers[1]->num_compiler_threads() != i) break;
1016         jobject thread_handle = JNIHandles::make_global(thread_oop);
1017         assert(compiler2_object(i) == NULL, "Old one must be released!");
1018         _compiler2_objects[i] = thread_handle;
1019       }
1020 #endif
1021       JavaThread *ct = make_thread(compiler2_object(i), _c2_compile_queue, _compilers[1], THREAD);
1022       if (ct == NULL) break;
1023       _compilers[1]->set_num_compiler_threads(i + 1);
1024       if (TraceCompilerThreads) {
1025         ResourceMark rm;
1026         MutexLocker mu(Threads_lock);
1027         tty->print_cr("Added compiler thread %s (available memory: %dMB, available non-profiled code cache: %dMB)",
1028                       ct->get_thread_name(), (int)(available_memory/M), (int)(available_cc_np/M));
1029       }
1030     }
1031   }
1032 
1033   if (_c1_compile_queue != NULL) {
1034     int old_c1_count = _compilers[0]->num_compiler_threads();
1035     int new_c1_count = MIN4(_c1_count,
1036         _c1_compile_queue->size() / 4,
1037         (int)(available_memory / (100*M)),
1038         (int)(available_cc_p / (128*K)));
1039 
1040     for (int i = old_c1_count; i < new_c1_count; i++) {
1041       JavaThread *ct = make_thread(compiler1_object(i), _c1_compile_queue, _compilers[0], THREAD);
1042       if (ct == NULL) break;
1043       _compilers[0]->set_num_compiler_threads(i + 1);
1044       if (TraceCompilerThreads) {
1045         ResourceMark rm;
1046         MutexLocker mu(Threads_lock);
1047         tty->print_cr("Added compiler thread %s (available memory: %dMB, available profiled code cache: %dMB)",
1048                       ct->get_thread_name(), (int)(available_memory/M), (int)(available_cc_p/M));
1049       }
1050     }
1051   }
1052 
1053   CompileThread_lock->unlock();
1054 }
1055 
1056 
1057 /**
1058  * Set the methods on the stack as on_stack so that redefine classes doesn't
1059  * reclaim them. This method is executed at a safepoint.
1060  */
1061 void CompileBroker::mark_on_stack() {




 788   }
 789 }
 790 
 791 // Completes compiler initialization. Compilation requests submitted
 792 // prior to this will be silently ignored.
 793 void CompileBroker::compilation_init_phase2() {
 794   _initialized = true;
 795 }
 796 
 797 Handle CompileBroker::create_thread_oop(const char* name, TRAPS) {
 798   Handle string = java_lang_String::create_from_str(name, CHECK_NH);
 799   Handle thread_group(THREAD, Universe::system_thread_group());
 800   return JavaCalls::construct_new_instance(
 801                        SystemDictionary::Thread_klass(),
 802                        vmSymbols::threadgroup_string_void_signature(),
 803                        thread_group,
 804                        string,
 805                        CHECK_NH);
 806 }
 807 
 808 #if defined(ASSERT) && COMPILER2_OR_JVMCI
 809 // Stress testing. Dedicated threads revert optimizations based on escape analysis concurrently to
 810 // the running java application.  Configured with vm options DeoptimizeObjectsALot*.
 811 class DeoptimizeObjectsALotThread : public JavaThread {
 812 
 813   static void deopt_objs_alot_thread_entry(JavaThread* thread, TRAPS);
 814   void deoptimize_objects_alot_loop_single();
 815   void deoptimize_objects_alot_loop_all();
 816 
 817 public:
 818   DeoptimizeObjectsALotThread() : JavaThread(&deopt_objs_alot_thread_entry) { }
 819 
 820   bool is_hidden_from_external_view() const      { return true; }
 821 };
 822 
 823 // Entry for DeoptimizeObjectsALotThread. The threads are started in
 824 // CompileBroker::init_compiler_sweeper_threads() iff DeoptimizeObjectsALot is enabled
 825 void DeoptimizeObjectsALotThread::deopt_objs_alot_thread_entry(JavaThread* thread, TRAPS) {
 826     DeoptimizeObjectsALotThread* dt = ((DeoptimizeObjectsALotThread*) thread);
 827     bool enter_single_loop;
 828     {
 829       MonitorLocker ml(dt, EscapeBarrier_lock, Mutex::_no_safepoint_check_flag);
 830       static int single_thread_count = 0;
 831       enter_single_loop = single_thread_count++ < DeoptimizeObjectsALotThreadCountSingle;
 832     }
 833     if (enter_single_loop) {
 834       dt->deoptimize_objects_alot_loop_single();
 835     } else {
 836       dt->deoptimize_objects_alot_loop_all();
 837     }
 838   }
 839 
 840 // Execute EscapeBarriers in an endless loop to revert optimizations based on escape analysis. Each
 841 // barrier targets a single thread which is selected round robin.
 842 void DeoptimizeObjectsALotThread::deoptimize_objects_alot_loop_single() {
 843   HandleMark hm(this);
 844   while (!this->is_terminated()) {
 845     for (JavaThreadIteratorWithHandle jtiwh; JavaThread *deoptee_thread = jtiwh.next(); ) {
 846       { // Begin new scope for escape barrier
 847         HandleMarkCleaner hmc(this);
 848         ResourceMark rm(this);
 849         EscapeBarrier eb(this, deoptee_thread, true);
 850         eb.deoptimize_objects(100);
 851       }
 852       // Now sleep after the escape barriers destructor resumed deoptee_thread.
 853       sleep(DeoptimizeObjectsALotInterval);
 854     }
 855   }
 856 }
 857 
 858 // Execute EscapeBarriers in an endless loop to revert optimizations based on escape analysis. Each
 859 // barrier targets all java threads in the vm at once.
 860 void DeoptimizeObjectsALotThread::deoptimize_objects_alot_loop_all() {
 861   HandleMark hm(this);
 862   while (!is_terminated()) {
 863     { // Begin new scope for escape barrier
 864       HandleMarkCleaner hmc(this);
 865       ResourceMark rm(this);
 866       EscapeBarrier eb(this, true);
 867       eb.deoptimize_objects_all_threads();
 868     }
 869     // Now sleep after the escape barriers destructor resumed the java threads.
 870     sleep(DeoptimizeObjectsALotInterval);
 871   }
 872 }
 873 #endif // defined(ASSERT) && COMPILER2_OR_JVMCI
 874 
 875 
 876 JavaThread* CompileBroker::make_thread(ThreadType type, jobject thread_handle, CompileQueue* queue, AbstractCompiler* comp, Thread* THREAD) {
 877   JavaThread* new_thread = NULL;
 878   {
 879     MutexLocker mu(THREAD, Threads_lock);
 880     switch (type) {
 881       case compiler_t:
 882         assert(comp != NULL, "Compiler instance missing.");
 883         if (!InjectCompilerCreationFailure || comp->num_compiler_threads() == 0) {
 884           CompilerCounters* counters = new CompilerCounters();
 885           new_thread = new CompilerThread(queue, counters);
 886         }
 887         break;
 888       case sweeper_t:
 889         new_thread = new CodeCacheSweeperThread();
 890         break;
 891 #if defined(ASSERT) && COMPILER2_OR_JVMCI
 892       case deoptimizer_t:
 893         new_thread = new DeoptimizeObjectsALotThread();
 894         break;
 895 #endif // ASSERT
 896       default:
 897         ShouldNotReachHere();
 898     }
 899 
 900     // At this point the new CompilerThread data-races with this startup
 901     // thread (which I believe is the primoridal thread and NOT the VM
 902     // thread).  This means Java bytecodes being executed at startup can
 903     // queue compile jobs which will run at whatever default priority the
 904     // newly created CompilerThread runs at.
 905 
 906 
 907     // At this point it may be possible that no osthread was created for the
 908     // JavaThread due to lack of memory. We would have to throw an exception
 909     // in that case. However, since this must work and we do not allow
 910     // exceptions anyway, check and abort if this fails. But first release the
 911     // lock.
 912 
 913     if (new_thread != NULL && new_thread->osthread() != NULL) {
 914 
 915       java_lang_Thread::set_thread(JNIHandles::resolve_non_null(thread_handle), new_thread);
 916 
 917       // Note that this only sets the JavaThread _priority field, which by
 918       // definition is limited to Java priorities and not OS priorities.
 919       // The os-priority is set in the CompilerThread startup code itself


 921       java_lang_Thread::set_priority(JNIHandles::resolve_non_null(thread_handle), NearMaxPriority);
 922 
 923       // Note that we cannot call os::set_priority because it expects Java
 924       // priorities and we are *explicitly* using OS priorities so that it's
 925       // possible to set the compiler thread priority higher than any Java
 926       // thread.
 927 
 928       int native_prio = CompilerThreadPriority;
 929       if (native_prio == -1) {
 930         if (UseCriticalCompilerThreadPriority) {
 931           native_prio = os::java_to_os_priority[CriticalPriority];
 932         } else {
 933           native_prio = os::java_to_os_priority[NearMaxPriority];
 934         }
 935       }
 936       os::set_native_priority(new_thread, native_prio);
 937 
 938       java_lang_Thread::set_daemon(JNIHandles::resolve_non_null(thread_handle));
 939 
 940       new_thread->set_threadObj(JNIHandles::resolve_non_null(thread_handle));
 941       if (type == compiler_t) {
 942         new_thread->as_CompilerThread()->set_compiler(comp);
 943       }
 944       Threads::add(new_thread);
 945       Thread::start(new_thread);
 946     }
 947   }
 948 
 949   // First release lock before aborting VM.
 950   if (new_thread == NULL || new_thread->osthread() == NULL) {
 951     if (UseDynamicNumberOfCompilerThreads && type == compiler_t && comp->num_compiler_threads() > 0) {
 952       if (new_thread != NULL) {
 953         new_thread->smr_delete();
 954       }
 955       return NULL;
 956     }
 957     vm_exit_during_initialization("java.lang.OutOfMemoryError",
 958                                   os::native_thread_creation_failed_msg());
 959   }
 960 
 961   // Let go of Threads_lock before yielding
 962   os::naked_yield(); // make sure that the compiler thread is started early (especially helpful on SOLARIS)
 963 
 964   return new_thread;
 965 }
 966 
 967 
 968 void CompileBroker::init_compiler_sweeper_threads() {
 969   NMethodSweeper::set_sweep_threshold_bytes(static_cast<size_t>(SweeperThreshold * ReservedCodeCacheSize / 100.0));
 970   log_info(codecache, sweep)("Sweeper threshold: " SIZE_FORMAT " bytes", NMethodSweeper::sweep_threshold_bytes());
 971 


 986     _compiler1_objects = NEW_C_HEAP_ARRAY(jobject, _c1_count, mtCompiler);
 987     _compiler1_logs = NEW_C_HEAP_ARRAY(CompileLog*, _c1_count, mtCompiler);
 988   }
 989 
 990   char name_buffer[256];
 991 
 992   for (int i = 0; i < _c2_count; i++) {
 993     jobject thread_handle = NULL;
 994     // Create all j.l.Thread objects for C1 and C2 threads here, but only one
 995     // for JVMCI compiler which can create further ones on demand.
 996     JVMCI_ONLY(if (!UseJVMCICompiler || !UseDynamicNumberOfCompilerThreads || i == 0) {)
 997     // Create a name for our thread.
 998     sprintf(name_buffer, "%s CompilerThread%d", _compilers[1]->name(), i);
 999     Handle thread_oop = create_thread_oop(name_buffer, CHECK);
1000     thread_handle = JNIHandles::make_global(thread_oop);
1001     JVMCI_ONLY(})
1002     _compiler2_objects[i] = thread_handle;
1003     _compiler2_logs[i] = NULL;
1004 
1005     if (!UseDynamicNumberOfCompilerThreads || i == 0) {
1006       JavaThread *ct = make_thread(compiler_t, thread_handle, _c2_compile_queue, _compilers[1], THREAD);
1007       assert(ct != NULL, "should have been handled for initial thread");
1008       _compilers[1]->set_num_compiler_threads(i + 1);
1009       if (TraceCompilerThreads) {
1010         ResourceMark rm;
1011         MutexLocker mu(Threads_lock);
1012         tty->print_cr("Added initial compiler thread %s", ct->get_thread_name());
1013       }
1014     }
1015   }
1016 
1017   for (int i = 0; i < _c1_count; i++) {
1018     // Create a name for our thread.
1019     sprintf(name_buffer, "C1 CompilerThread%d", i);
1020     Handle thread_oop = create_thread_oop(name_buffer, CHECK);
1021     jobject thread_handle = JNIHandles::make_global(thread_oop);
1022     _compiler1_objects[i] = thread_handle;
1023     _compiler1_logs[i] = NULL;
1024 
1025     if (!UseDynamicNumberOfCompilerThreads || i == 0) {
1026       JavaThread *ct = make_thread(compiler_t, thread_handle, _c1_compile_queue, _compilers[0], THREAD);
1027       assert(ct != NULL, "should have been handled for initial thread");
1028       _compilers[0]->set_num_compiler_threads(i + 1);
1029       if (TraceCompilerThreads) {
1030         ResourceMark rm;
1031         MutexLocker mu(Threads_lock);
1032         tty->print_cr("Added initial compiler thread %s", ct->get_thread_name());
1033       }
1034     }
1035   }
1036 
1037   if (UsePerfData) {
1038     PerfDataManager::create_constant(SUN_CI, "threads", PerfData::U_Bytes, _c1_count + _c2_count, CHECK);
1039   }
1040 
1041   if (MethodFlushing) {
1042     // Initialize the sweeper thread
1043     Handle thread_oop = create_thread_oop("Sweeper thread", CHECK);
1044     jobject thread_handle = JNIHandles::make_local(THREAD, thread_oop());
1045     make_thread(sweeper_t, thread_handle, NULL, NULL, THREAD);
1046   }
1047 
1048 #if defined(ASSERT) && COMPILER2_OR_JVMCI
1049   if (DeoptimizeObjectsALot) {
1050     // Initialize and start the object deoptimizer threads
1051     const int total_count = DeoptimizeObjectsALotThreadCountSingle + DeoptimizeObjectsALotThreadCountAll;
1052     for (int count = 0; count < total_count; count++) {
1053       Handle thread_oop = create_thread_oop("Deoptimize objects a lot single mode", CHECK);
1054       jobject thread_handle = JNIHandles::make_local(THREAD, thread_oop());
1055       make_thread(deoptimizer_t, thread_handle, NULL, NULL, THREAD);
1056     }
1057   }
1058 #endif // defined(ASSERT) && COMPILER2_OR_JVMCI
1059 }
1060 
1061 void CompileBroker::possibly_add_compiler_threads(Thread* THREAD) {
1062 
1063   julong available_memory = os::available_memory();
1064   // If SegmentedCodeCache is off, both values refer to the single heap (with type CodeBlobType::All).
1065   size_t available_cc_np  = CodeCache::unallocated_capacity(CodeBlobType::MethodNonProfiled),
1066          available_cc_p   = CodeCache::unallocated_capacity(CodeBlobType::MethodProfiled);
1067 
1068   // Only do attempt to start additional threads if the lock is free.
1069   if (!CompileThread_lock->try_lock()) return;
1070 
1071   if (_c2_compile_queue != NULL) {
1072     int old_c2_count = _compilers[1]->num_compiler_threads();
1073     int new_c2_count = MIN4(_c2_count,
1074         _c2_compile_queue->size() / 2,
1075         (int)(available_memory / (200*M)),
1076         (int)(available_cc_np / (128*K)));
1077 
1078     for (int i = old_c2_count; i < new_c2_count; i++) {


1092           // We have to give up the lock temporarily for the Java calls.
1093           MutexUnlocker mu(CompileThread_lock);
1094           thread_oop = create_thread_oop(name_buffer, THREAD);
1095         }
1096         if (HAS_PENDING_EXCEPTION) {
1097           if (TraceCompilerThreads) {
1098             ResourceMark rm;
1099             tty->print_cr("JVMCI compiler thread creation failed:");
1100             PENDING_EXCEPTION->print();
1101           }
1102           CLEAR_PENDING_EXCEPTION;
1103           break;
1104         }
1105         // Check if another thread has beaten us during the Java calls.
1106         if (_compilers[1]->num_compiler_threads() != i) break;
1107         jobject thread_handle = JNIHandles::make_global(thread_oop);
1108         assert(compiler2_object(i) == NULL, "Old one must be released!");
1109         _compiler2_objects[i] = thread_handle;
1110       }
1111 #endif
1112       JavaThread *ct = make_thread(compiler_t, compiler2_object(i), _c2_compile_queue, _compilers[1], THREAD);
1113       if (ct == NULL) break;
1114       _compilers[1]->set_num_compiler_threads(i + 1);
1115       if (TraceCompilerThreads) {
1116         ResourceMark rm;
1117         MutexLocker mu(Threads_lock);
1118         tty->print_cr("Added compiler thread %s (available memory: %dMB, available non-profiled code cache: %dMB)",
1119                       ct->get_thread_name(), (int)(available_memory/M), (int)(available_cc_np/M));
1120       }
1121     }
1122   }
1123 
1124   if (_c1_compile_queue != NULL) {
1125     int old_c1_count = _compilers[0]->num_compiler_threads();
1126     int new_c1_count = MIN4(_c1_count,
1127         _c1_compile_queue->size() / 4,
1128         (int)(available_memory / (100*M)),
1129         (int)(available_cc_p / (128*K)));
1130 
1131     for (int i = old_c1_count; i < new_c1_count; i++) {
1132       JavaThread *ct = make_thread(compiler_t, compiler1_object(i), _c1_compile_queue, _compilers[0], THREAD);
1133       if (ct == NULL) break;
1134       _compilers[0]->set_num_compiler_threads(i + 1);
1135       if (TraceCompilerThreads) {
1136         ResourceMark rm;
1137         MutexLocker mu(Threads_lock);
1138         tty->print_cr("Added compiler thread %s (available memory: %dMB, available profiled code cache: %dMB)",
1139                       ct->get_thread_name(), (int)(available_memory/M), (int)(available_cc_p/M));
1140       }
1141     }
1142   }
1143 
1144   CompileThread_lock->unlock();
1145 }
1146 
1147 
1148 /**
1149  * Set the methods on the stack as on_stack so that redefine classes doesn't
1150  * reclaim them. This method is executed at a safepoint.
1151  */
1152 void CompileBroker::mark_on_stack() {


< prev index next >