< prev index next >

src/share/vm/gc/g1/satbMarkQueue.cpp

Print this page
rev 12859 : imported patch pqsize

@@ -116,15 +116,14 @@
   if (buf == NULL) {
     // nothing to do
     return;
   }
 
-  assert(_index <= _sz, "invariant");
-
   // Two-fingered compaction toward the end.
-  void** src = &buf[byte_index_to_index(_index)];
-  void** dst = &buf[byte_index_to_index(_sz)];
+  void** src = &buf[index()];
+  void** dst = &buf[capacity()];
+  assert(src <= dst, "invariant");
   for ( ; src < dst; ++src) {
     // Search low to high for an entry to keep.
     void* entry = *src;
     if (retain_entry(entry, g1h)) {
       // Found keeper.  Search high to low for an entry to discard.

@@ -137,11 +136,11 @@
       // If discard search failed (src == dst), the outer loop will also end.
     }
   }
   // dst points to the lowest retained entry, or the end of the buffer
   // if all the entries were filtered out.
-  _index = pointer_delta(dst, buf, 1);
+  set_index(dst - buf);
 }
 
 // This method will first apply the above filtering to the buffer. If
 // post-filtering a large enough chunk of the buffer has been cleared
 // we can re-use the buffer (instead of enqueueing it) and we can just

@@ -154,45 +153,46 @@
 
   // If G1SATBBufferEnqueueingThresholdPercent == 0 we could skip filtering.
 
   // This method should only be called if there is a non-NULL buffer
   // that is full.
-  assert(_index == 0, "pre-condition");
+  assert(index() == 0, "pre-condition");
   assert(_buf != NULL, "pre-condition");
 
   filter();
 
-  size_t percent_used = ((_sz - _index) * 100) / _sz;
+  size_t cap = capacity();
+  size_t percent_used = ((cap - index()) * 100) / cap;
   bool should_enqueue = percent_used > G1SATBBufferEnqueueingThresholdPercent;
   return should_enqueue;
 }
 
 void SATBMarkQueue::apply_closure_and_empty(SATBBufferClosure* cl) {
   assert(SafepointSynchronize::is_at_safepoint(),
          "SATB queues must only be processed at safepoints");
   if (_buf != NULL) {
-    assert(_index % sizeof(void*) == 0, "invariant");
-    assert(_sz % sizeof(void*) == 0, "invariant");
-    assert(_index <= _sz, "invariant");
-    cl->do_buffer(_buf + byte_index_to_index(_index),
-                  byte_index_to_index(_sz - _index));
-    _index = _sz;
+    cl->do_buffer(&_buf[index()], size());
+    reset();
   }
 }
 
 #ifndef PRODUCT
 // Helpful for debugging
 
-void SATBMarkQueue::print(const char* name) {
-  print(name, _buf, _index, _sz);
+static void print_satb_buffer(const char* name,
+                              void** buf,
+                              size_t index,
+                              size_t capacity) {
+  tty->print_cr("  SATB BUFFER [%s] buf: " PTR_FORMAT " index: " SIZE_FORMAT
+                " capacity: " SIZE_FORMAT,
+                name, p2i(buf), index, capacity);
 }
 
-void SATBMarkQueue::print(const char* name,
-                          void** buf, size_t index, size_t sz) {
-  tty->print_cr("  SATB BUFFER [%s] buf: " PTR_FORMAT " index: " SIZE_FORMAT " sz: " SIZE_FORMAT,
-                name, p2i(buf), index, sz);
+void SATBMarkQueue::print(const char* name) {
+  print_satb_buffer(name, _buf, index(), capacity());
 }
+
 #endif // PRODUCT
 
 SATBMarkQueueSet::SATBMarkQueueSet() :
   PtrQueueSet(),
   _shared_satb_queue(this, true /* permanent */) { }

@@ -273,12 +273,12 @@
       if (_n_completed_buffers == 0) _process_completed = false;
     }
   }
   if (nd != NULL) {
     void **buf = BufferNode::make_buffer_from_node(nd);
-    size_t index = SATBMarkQueue::byte_index_to_index(nd->index());
-    size_t size = SATBMarkQueue::byte_index_to_index(_sz);
+    size_t index = nd->index();
+    size_t size = buffer_size();
     assert(index <= size, "invariant");
     cl->do_buffer(buf + index, size - index);
     deallocate_buffer(nd);
     return true;
   } else {

@@ -301,11 +301,11 @@
   BufferNode* nd = _completed_buffers_head;
   int i = 0;
   while (nd != NULL) {
     void** buf = BufferNode::make_buffer_from_node(nd);
     jio_snprintf(buffer, SATB_PRINTER_BUFFER_SIZE, "Enqueued: %d", i);
-    SATBMarkQueue::print(buffer, buf, 0, _sz);
+    print_satb_buffer(buffer, buf, nd->index(), buffer_size());
     nd = nd->next();
     i += 1;
   }
 
   for (JavaThread* t = Threads::first(); t; t = t->next()) {
< prev index next >