1.1 --- a/src/share/vm/utilities/workgroup.cpp Tue Nov 22 04:47:10 2011 -0500 1.2 +++ b/src/share/vm/utilities/workgroup.cpp Tue Aug 09 10:16:01 2011 -0700 1.3 @@ -57,7 +57,6 @@ 1.4 bool are_GC_task_threads, 1.5 bool are_ConcurrentGC_threads) : 1.6 AbstractWorkGang(name, are_GC_task_threads, are_ConcurrentGC_threads) { 1.7 - // Save arguments. 1.8 _total_workers = workers; 1.9 } 1.10 1.11 @@ -127,6 +126,12 @@ 1.12 } 1.13 1.14 void WorkGang::run_task(AbstractGangTask* task) { 1.15 + run_task(task, total_workers()); 1.16 +} 1.17 + 1.18 +void WorkGang::run_task(AbstractGangTask* task, uint no_of_parallel_workers) { 1.19 + task->set_for_termination(no_of_parallel_workers); 1.20 + 1.21 // This thread is executed by the VM thread which does not block 1.22 // on ordinary MutexLocker's. 1.23 MutexLockerEx ml(monitor(), Mutex::_no_safepoint_check_flag); 1.24 @@ -143,22 +148,32 @@ 1.25 // Tell the workers to get to work. 1.26 monitor()->notify_all(); 1.27 // Wait for them to be finished 1.28 - while (finished_workers() < total_workers()) { 1.29 + while (finished_workers() < (int) no_of_parallel_workers) { 1.30 if (TraceWorkGang) { 1.31 tty->print_cr("Waiting in work gang %s: %d/%d finished sequence %d", 1.32 - name(), finished_workers(), total_workers(), 1.33 + name(), finished_workers(), no_of_parallel_workers, 1.34 _sequence_number); 1.35 } 1.36 monitor()->wait(/* no_safepoint_check */ true); 1.37 } 1.38 _task = NULL; 1.39 if (TraceWorkGang) { 1.40 - tty->print_cr("/nFinished work gang %s: %d/%d sequence %d", 1.41 - name(), finished_workers(), total_workers(), 1.42 + tty->print_cr("\nFinished work gang %s: %d/%d sequence %d", 1.43 + name(), finished_workers(), no_of_parallel_workers, 1.44 _sequence_number); 1.45 + Thread* me = Thread::current(); 1.46 + tty->print_cr(" T: 0x%x VM_thread: %d", me, me->is_VM_thread()); 1.47 } 1.48 } 1.49 1.50 +void FlexibleWorkGang::run_task(AbstractGangTask* task) { 1.51 + // If active_workers() is passed, _finished_workers 1.52 + // must only be incremented for workers that find non_null 1.53 + // work (as opposed to all those that just check that the 1.54 + // task is not null). 1.55 + WorkGang::run_task(task, (uint) active_workers()); 1.56 +} 1.57 + 1.58 void AbstractWorkGang::stop() { 1.59 // Tell all workers to terminate, then wait for them to become inactive. 1.60 MutexLockerEx ml(monitor(), Mutex::_no_safepoint_check_flag); 1.61 @@ -168,10 +183,10 @@ 1.62 _task = NULL; 1.63 _terminate = true; 1.64 monitor()->notify_all(); 1.65 - while (finished_workers() < total_workers()) { 1.66 + while (finished_workers() < active_workers()) { 1.67 if (TraceWorkGang) { 1.68 tty->print_cr("Waiting in work gang %s: %d/%d finished", 1.69 - name(), finished_workers(), total_workers()); 1.70 + name(), finished_workers(), active_workers()); 1.71 } 1.72 monitor()->wait(/* no_safepoint_check */ true); 1.73 } 1.74 @@ -275,10 +290,12 @@ 1.75 // Check for new work. 1.76 if ((data.task() != NULL) && 1.77 (data.sequence_number() != previous_sequence_number)) { 1.78 - gang()->internal_note_start(); 1.79 - gang_monitor->notify_all(); 1.80 - part = gang()->started_workers() - 1; 1.81 - break; 1.82 + if (gang()->needs_more_workers()) { 1.83 + gang()->internal_note_start(); 1.84 + gang_monitor->notify_all(); 1.85 + part = gang()->started_workers() - 1; 1.86 + break; 1.87 + } 1.88 } 1.89 // Nothing to do. 1.90 gang_monitor->wait(/* no_safepoint_check */ true); 1.91 @@ -350,6 +367,9 @@ 1.92 1.93 #endif /* PRODUCT */ 1.94 1.95 +// FlexibleWorkGang 1.96 + 1.97 + 1.98 // *** WorkGangBarrierSync 1.99 1.100 WorkGangBarrierSync::WorkGangBarrierSync() 1.101 @@ -411,10 +431,8 @@ 1.102 } 1.103 1.104 void SubTasksDone::set_n_threads(int t) { 1.105 -#ifdef ASSERT 1.106 assert(_claimed == 0 || _threads_completed == _n_threads, 1.107 "should not be called while tasks are being processed!"); 1.108 -#endif 1.109 _n_threads = (t == 0 ? 1 : t); 1.110 } 1.111