< prev index next >

src/share/vm/gc/shared/workgroup.cpp

Print this page
rev 11036 : 6858051: Create GC worker threads dynamically
Reviewed-by:

@@ -23,10 +23,11 @@
  */
 
 #include "precompiled.hpp"
 #include "gc/shared/gcId.hpp"
 #include "gc/shared/workgroup.hpp"
+#include "gc/shared/adaptiveSizePolicy.inline.hpp"
 #include "memory/allocation.hpp"
 #include "memory/allocation.inline.hpp"
 #include "runtime/atomic.inline.hpp"
 #include "runtime/os.hpp"
 #include "runtime/semaphore.hpp"

@@ -44,30 +45,37 @@
   _workers = NEW_C_HEAP_ARRAY(AbstractGangWorker*, total_workers(), mtInternal);
   if (_workers == NULL) {
     vm_exit_out_of_memory(0, OOM_MALLOC_ERROR, "Cannot create GangWorker array.");
     return false;
   }
+
+  _active_workers = AdaptiveSizePolicy::initial_number_of_workers();
+  return add_workers(true);
+}
+
+
+AbstractGangWorker* AbstractWorkGang::install_worker(uint worker_id) {
+  AbstractGangWorker* new_worker = allocate_worker(worker_id);
+  set_thread(worker_id, new_worker);
+  return new_worker;
+}
+
+bool AbstractWorkGang::add_workers(bool initializing) {
+
   os::ThreadType worker_type;
   if (are_ConcurrentGC_threads()) {
     worker_type = os::cgc_thread;
   } else {
     worker_type = os::pgc_thread;
   }
-  for (uint worker = 0; worker < total_workers(); worker += 1) {
-    AbstractGangWorker* new_worker = allocate_worker(worker);
-    assert(new_worker != NULL, "Failed to allocate GangWorker");
-    _workers[worker] = new_worker;
-    if (new_worker == NULL || !os::create_thread(new_worker, worker_type)) {
-      vm_exit_out_of_memory(0, OOM_MALLOC_ERROR,
-              "Cannot create worker GC thread. Out of system resources.");
-      return false;
-    }
-    if (!DisableStartThread) {
-      os::start_thread(new_worker);
-    }
-  }
-  return true;
+
+  return AdaptiveSizePolicy::add_workers(this,
+                                         _active_workers,
+                                         _total_workers,
+                                         _created_workers,
+                                         worker_type,
+                                         initializing);
 }
 
 AbstractGangWorker* AbstractWorkGang::worker(uint i) const {
   // Array index bounds checking.
   AbstractGangWorker* result = NULL;

@@ -77,20 +85,20 @@
   assert(result != NULL, "Indexing to null worker");
   return result;
 }
 
 void AbstractWorkGang::print_worker_threads_on(outputStream* st) const {
-  uint workers = total_workers();
+  uint workers = created_workers();
   for (uint i = 0; i < workers; i++) {
     worker(i)->print_on(st);
     st->cr();
   }
 }
 
 void AbstractWorkGang::threads_do(ThreadClosure* tc) const {
   assert(tc != NULL, "Null ThreadClosure");
-  uint workers = total_workers();
+  uint workers = created_workers();
   for (uint i = 0; i < workers; i++) {
     tc->do_thread(worker(i));
   }
 }
 
< prev index next >