hotspot/src/share/vm/gc/cms/concurrentMarkSweepGeneration.cpp
changeset 46620 750c6edff33b
parent 46619 a3919f5e8d2b
child 46625 edefffab74e2
--- a/hotspot/src/share/vm/gc/cms/concurrentMarkSweepGeneration.cpp	Tue Jul 04 15:58:10 2017 +0200
+++ b/hotspot/src/share/vm/gc/cms/concurrentMarkSweepGeneration.cpp	Thu Apr 13 09:57:51 2017 +0200
@@ -896,7 +896,7 @@
         // in the heap. In the case of the MUT below, that's a
         // card size.
         MemRegion mr(start,
-                     (HeapWord*)round_to((intptr_t)(start + obj_size),
+                     align_up(start + obj_size,
                         CardTableModRefBS::card_size /* bytes */));
         if (par) {
           _modUnionTable.par_mark_range(mr);
@@ -4576,13 +4576,10 @@
   const int alignment = CardTableModRefBS::card_size * BitsPerWord;
   MemRegion span = sp->used_region();
   HeapWord* start_addr = span.start();
-  HeapWord* end_addr = (HeapWord*)round_to((intptr_t)span.end(),
-                                           alignment);
+  HeapWord* end_addr = align_up(span.end(), alignment);
   const size_t chunk_size = sp->rescan_task_size(); // in HeapWord units
-  assert((HeapWord*)round_to((intptr_t)start_addr, alignment) ==
-         start_addr, "Check alignment");
-  assert((size_t)round_to((intptr_t)chunk_size, alignment) ==
-         chunk_size, "Check alignment");
+  assert(is_aligned(start_addr, alignment), "Check alignment");
+  assert(is_aligned(chunk_size, alignment), "Check alignment");
 
   while (!pst->is_task_claimed(/* reference */ nth_task)) {
     // Having claimed the nth_task, compute corresponding mem-region,
@@ -4928,7 +4925,7 @@
       markFromDirtyCardsClosure.set_space(_cmsGen->cmsSpace());
       MemRegion ur = _cmsGen->used_region();
       HeapWord* lb = ur.start();
-      HeapWord* ub = (HeapWord*)round_to((intptr_t)ur.end(), alignment);
+      HeapWord* ub = align_up(ur.end(), alignment);
       MemRegion cms_span(lb, ub);
       _modUnionTable.dirty_range_iterate_clear(cms_span,
                                                &markFromDirtyCardsClosure);
@@ -5625,10 +5622,9 @@
   }
   assert(sz > 0, "size must be nonzero");
   HeapWord* next_block = addr + sz;
-  HeapWord* next_card  = (HeapWord*)round_to((uintptr_t)next_block,
-                                             CardTableModRefBS::card_size);
-  assert(round_down((uintptr_t)addr,      CardTableModRefBS::card_size) <
-         round_down((uintptr_t)next_card, CardTableModRefBS::card_size),
+  HeapWord* next_card  = align_up(next_block, CardTableModRefBS::card_size);
+  assert(align_down((uintptr_t)addr,      CardTableModRefBS::card_size) <
+         align_down((uintptr_t)next_card, CardTableModRefBS::card_size),
          "must be different cards");
   return next_card;
 }
@@ -5732,8 +5728,7 @@
   // convert address range into offset range
   size_t start_ofs = heapWordToOffset(mr.start());
   // Make sure that end() is appropriately aligned
-  assert(mr.end() == (HeapWord*)round_to((intptr_t)mr.end(),
-                        (1 << (_shifter+LogHeapWordSize))),
+  assert(mr.end() == align_up(mr.end(), (1 << (_shifter+LogHeapWordSize))),
          "Misaligned mr.end()");
   size_t end_ofs   = heapWordToOffset(mr.end());
   assert(end_ofs > start_ofs, "Should mark at least one bit");
@@ -6287,8 +6282,7 @@
   assert(_markStack->isEmpty(), "would cause duplicates on stack");
   assert(_span.contains(addr), "Out of bounds _finger?");
   _finger = addr;
-  _threshold = (HeapWord*)round_to(
-                 (intptr_t)_finger, CardTableModRefBS::card_size);
+  _threshold = align_up(_finger, CardTableModRefBS::card_size);
 }
 
 // Should revisit to see if this should be restructured for
@@ -6315,8 +6309,7 @@
         // during the preclean or remark phase. (CMSCleanOnEnter)
         if (CMSCleanOnEnter) {
           size_t sz = _collector->block_size_using_printezis_bits(addr);
-          HeapWord* end_card_addr   = (HeapWord*)round_to(
-                                         (intptr_t)(addr+sz), CardTableModRefBS::card_size);
+          HeapWord* end_card_addr = align_up(addr + sz, CardTableModRefBS::card_size);
           MemRegion redirty_range = MemRegion(addr, end_card_addr);
           assert(!redirty_range.is_empty(), "Arithmetical tautology");
           // Bump _threshold to end_card_addr; note that
@@ -6403,11 +6396,9 @@
       // _threshold is always kept card-aligned but _finger isn't
       // always card-aligned.
       HeapWord* old_threshold = _threshold;
-      assert(old_threshold == (HeapWord*)round_to(
-              (intptr_t)old_threshold, CardTableModRefBS::card_size),
+      assert(is_aligned(old_threshold, CardTableModRefBS::card_size),
              "_threshold should always be card-aligned");
-      _threshold = (HeapWord*)round_to(
-                     (intptr_t)_finger, CardTableModRefBS::card_size);
+      _threshold = align_up(_finger, CardTableModRefBS::card_size);
       MemRegion mr(old_threshold, _threshold);
       assert(!mr.is_empty(), "Control point invariant");
       assert(_span.contains(mr), "Should clear within span");
@@ -6517,11 +6508,9 @@
     // _threshold is always kept card-aligned but _finger isn't
     // always card-aligned.
     HeapWord* old_threshold = _threshold;
-    assert(old_threshold == (HeapWord*)round_to(
-            (intptr_t)old_threshold, CardTableModRefBS::card_size),
+    assert(is_aligned(old_threshold, CardTableModRefBS::card_size),
            "_threshold should always be card-aligned");
-    _threshold = (HeapWord*)round_to(
-                   (intptr_t)_finger, CardTableModRefBS::card_size);
+    _threshold = align_up(_finger, CardTableModRefBS::card_size);
     MemRegion mr(old_threshold, _threshold);
     assert(!mr.is_empty(), "Control point invariant");
     assert(_span.contains(mr), "Should clear within span"); // _whole_span ??
@@ -6888,8 +6877,7 @@
          // are required.
          if (obj->is_objArray()) {
            size_t sz = obj->size();
-           HeapWord* end_card_addr = (HeapWord*)round_to(
-                                        (intptr_t)(addr+sz), CardTableModRefBS::card_size);
+           HeapWord* end_card_addr = align_up(addr + sz, CardTableModRefBS::card_size);
            MemRegion redirty_range = MemRegion(addr, end_card_addr);
            assert(!redirty_range.is_empty(), "Arithmetical tautology");
            _mod_union_table->mark_range(redirty_range);
@@ -7618,8 +7606,7 @@
         // table.
         if (obj->is_objArray()) {
           size_t sz = obj->size();
-          HeapWord* end_card_addr =
-            (HeapWord*)round_to((intptr_t)(addr+sz), CardTableModRefBS::card_size);
+          HeapWord* end_card_addr = align_up(addr + sz, CardTableModRefBS::card_size);
           MemRegion redirty_range = MemRegion(addr, end_card_addr);
           assert(!redirty_range.is_empty(), "Arithmetical tautology");
           _collector->_modUnionTable.mark_range(redirty_range);