< prev index next >

src/hotspot/share/gc/shared/satbMarkQueue.cpp

Print this page
rev 53862 : [mq]: java_attach_protocol
rev 53865 : imported patch njt_iterate
rev 53867 : imported patch remove_shared_satb
rev 53868 : imported patch remove_shared_satb_lock

@@ -39,11 +39,11 @@
   // SATB queues are only active during marking cycles. We create
   // them with their active field set to false. If a thread is
   // created during a cycle and its SATB queue needs to be activated
   // before the thread starts running, we'll need to set its active
   // field to true. This must be done in the collector-specific
-  // BarrierSet::on_thread_attach() implementation.
+  // BarrierSet thread attachment protocol.
   PtrQueue(qset, permanent, false /* active */)
 { }
 
 void SATBMarkQueue::flush() {
   // Filter now to possibly save work later.  If filtering empties the

@@ -55,13 +55,10 @@
 // This method will first apply filtering to the buffer. If filtering
 // retains a small enough collection in the buffer, we can continue to
 // use the buffer as-is, instead of enqueueing and replacing it.
 
 bool SATBMarkQueue::should_enqueue_buffer() {
-  assert(_lock == NULL || _lock->owned_by_self(),
-         "we should have taken the lock before calling this");
-
   // This method should only be called if there is a non-NULL buffer
   // that is full.
   assert(index() == 0, "pre-condition");
   assert(_buf != NULL, "pre-condition");
 

@@ -105,22 +102,19 @@
 
 #endif // PRODUCT
 
 SATBMarkQueueSet::SATBMarkQueueSet() :
   PtrQueueSet(),
-  _shared_satb_queue(this, true /* permanent */),
   _buffer_enqueue_threshold(0)
 {}
 
 void SATBMarkQueueSet::initialize(Monitor* cbl_mon,
                                   BufferNode::Allocator* allocator,
                                   size_t process_completed_buffers_threshold,
-                                  uint buffer_enqueue_threshold_percentage,
-                                  Mutex* lock) {
+                                  uint buffer_enqueue_threshold_percentage) {
   PtrQueueSet::initialize(cbl_mon, allocator);
   set_process_completed_buffers_threshold(process_completed_buffers_threshold);
-  _shared_satb_queue.set_lock(lock);
   assert(buffer_size() != 0, "buffer size not initialized");
   // Minimum threshold of 1 ensures enqueuing of completely full buffers.
   size_t size = buffer_size();
   size_t enqueue_qty = (size * buffer_enqueue_threshold_percentage) / 100;
   _buffer_enqueue_threshold = MAX2(size - enqueue_qty, (size_t)1);

@@ -129,56 +123,80 @@
 #ifdef ASSERT
 void SATBMarkQueueSet::dump_active_states(bool expected_active) {
   log_error(gc, verify)("Expected SATB active state: %s", expected_active ? "ACTIVE" : "INACTIVE");
   log_error(gc, verify)("Actual SATB active states:");
   log_error(gc, verify)("  Queue set: %s", is_active() ? "ACTIVE" : "INACTIVE");
-  for (JavaThreadIteratorWithHandle jtiwh; JavaThread *t = jtiwh.next(); ) {
-    log_error(gc, verify)("  Thread \"%s\" queue: %s", t->name(), satb_queue_for_thread(t).is_active() ? "ACTIVE" : "INACTIVE");
+
+  class DumpThreadStateClosure : public ThreadClosure {
+    SATBMarkQueueSet* _qset;
+  public:
+    DumpThreadStateClosure(SATBMarkQueueSet* qset) : _qset(qset) {}
+    virtual void do_thread(Thread* t) {
+      SATBMarkQueue& queue = _qset->satb_queue_for_thread(t);
+      log_error(gc, verify)("  Thread \"%s\" queue: %s",
+                            t->name(),
+                            queue.is_active() ? "ACTIVE" : "INACTIVE");
   }
-  log_error(gc, verify)("  Shared queue: %s", shared_satb_queue()->is_active() ? "ACTIVE" : "INACTIVE");
+  } closure(this);
+  Threads::threads_do(&closure);
 }
 
 void SATBMarkQueueSet::verify_active_states(bool expected_active) {
   // Verify queue set state
   if (is_active() != expected_active) {
     dump_active_states(expected_active);
-    guarantee(false, "SATB queue set has an unexpected active state");
+    fatal("SATB queue set has an unexpected active state");
   }
 
   // Verify thread queue states
-  for (JavaThreadIteratorWithHandle jtiwh; JavaThread *t = jtiwh.next(); ) {
-    if (satb_queue_for_thread(t).is_active() != expected_active) {
-      dump_active_states(expected_active);
-      guarantee(false, "Thread SATB queue has an unexpected active state");
+  class VerifyThreadStatesClosure : public ThreadClosure {
+    SATBMarkQueueSet* _qset;
+    bool _expected_active;
+  public:
+    VerifyThreadStatesClosure(SATBMarkQueueSet* qset, bool expected_active) :
+      _qset(qset), _expected_active(expected_active) {}
+    virtual void do_thread(Thread* t) {
+      if (_qset->satb_queue_for_thread(t).is_active() != _expected_active) {
+        _qset->dump_active_states(_expected_active);
+        fatal("Thread SATB queue has an unexpected active state");
     }
   }
-
-  // Verify shared queue state
-  if (shared_satb_queue()->is_active() != expected_active) {
-    dump_active_states(expected_active);
-    guarantee(false, "Shared SATB queue has an unexpected active state");
-  }
+  } closure(this, expected_active);
+  Threads::threads_do(&closure);
 }
 #endif // ASSERT
 
 void SATBMarkQueueSet::set_active_all_threads(bool active, bool expected_active) {
   assert(SafepointSynchronize::is_at_safepoint(), "Must be at safepoint.");
 #ifdef ASSERT
   verify_active_states(expected_active);
 #endif // ASSERT
   _all_active = active;
-  for (JavaThreadIteratorWithHandle jtiwh; JavaThread *t = jtiwh.next(); ) {
-    satb_queue_for_thread(t).set_active(active);
+
+  class SetThreadActiveClosure : public ThreadClosure {
+    SATBMarkQueueSet* _qset;
+    bool _active;
+  public:
+    SetThreadActiveClosure(SATBMarkQueueSet* qset, bool active) :
+      _qset(qset), _active(active) {}
+    virtual void do_thread(Thread* t) {
+      _qset->satb_queue_for_thread(t).set_active(_active);
   }
-  shared_satb_queue()->set_active(active);
+  } closure(this, active);
+  Threads::threads_do(&closure);
 }
 
 void SATBMarkQueueSet::filter_thread_buffers() {
-  for (JavaThreadIteratorWithHandle jtiwh; JavaThread *t = jtiwh.next(); ) {
-    satb_queue_for_thread(t).filter();
+  class FilterThreadBufferClosure : public ThreadClosure {
+    SATBMarkQueueSet* _qset;
+  public:
+    FilterThreadBufferClosure(SATBMarkQueueSet* qset) : _qset(qset) {}
+    virtual void do_thread(Thread* t) {
+      _qset->satb_queue_for_thread(t).filter();
   }
-  shared_satb_queue()->filter();
+  } closure(this);
+  Threads::threads_do(&closure);
 }
 
 bool SATBMarkQueueSet::apply_closure_to_completed_buffer(SATBBufferClosure* cl) {
   BufferNode* nd = get_completed_buffer();
   if (nd != NULL) {

@@ -214,25 +232,38 @@
     print_satb_buffer(buffer, buf, nd->index(), buffer_size());
     nd = nd->next();
     i += 1;
   }
 
-  for (JavaThreadIteratorWithHandle jtiwh; JavaThread *t = jtiwh.next(); ) {
-    os::snprintf(buffer, SATB_PRINTER_BUFFER_SIZE, "Thread: %s", t->name());
-    satb_queue_for_thread(t).print(buffer);
+  class PrintThreadClosure : public ThreadClosure {
+    SATBMarkQueueSet* _qset;
+    char* _buffer;
+
+  public:
+    PrintThreadClosure(SATBMarkQueueSet* qset, char* buffer) :
+      _qset(qset), _buffer(buffer) {}
+
+    virtual void do_thread(Thread* t) {
+      os::snprintf(_buffer, SATB_PRINTER_BUFFER_SIZE, "Thread: %s", t->name());
+      _qset->satb_queue_for_thread(t).print(_buffer);
   }
-
-  shared_satb_queue()->print("Shared");
+  } closure(this, buffer);
+  Threads::threads_do(&closure);
 
   tty->cr();
 }
 #endif // PRODUCT
 
 void SATBMarkQueueSet::abandon_partial_marking() {
-  abandon_completed_buffers();
   assert(SafepointSynchronize::is_at_safepoint(), "Must be at safepoint.");
-  // So we can safely manipulate these queues.
-  for (JavaThreadIteratorWithHandle jtiwh; JavaThread *t = jtiwh.next(); ) {
-    satb_queue_for_thread(t).reset();
+  abandon_completed_buffers();
+
+  class AbandonThreadQueueClosure : public ThreadClosure {
+    SATBMarkQueueSet* _qset;
+  public:
+    AbandonThreadQueueClosure(SATBMarkQueueSet* qset) : _qset(qset) {}
+    virtual void do_thread(Thread* t) {
+      _qset->satb_queue_for_thread(t).reset();
   }
-  shared_satb_queue()->reset();
+  } closure(this);
+  Threads::threads_do(&closure);
 }
< prev index next >