src/share/vm/gc_implementation/g1/concurrentMark.cpp

Print this page
rev 6923 : imported patch 8054819-rename-heapregionseq


  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "classfile/symbolTable.hpp"
  27 #include "code/codeCache.hpp"
  28 #include "gc_implementation/g1/concurrentMark.inline.hpp"
  29 #include "gc_implementation/g1/concurrentMarkThread.inline.hpp"
  30 #include "gc_implementation/g1/g1CollectedHeap.inline.hpp"
  31 #include "gc_implementation/g1/g1CollectorPolicy.hpp"
  32 #include "gc_implementation/g1/g1ErgoVerbose.hpp"
  33 #include "gc_implementation/g1/g1Log.hpp"
  34 #include "gc_implementation/g1/g1OopClosures.inline.hpp"
  35 #include "gc_implementation/g1/g1RemSet.hpp"
  36 #include "gc_implementation/g1/heapRegion.inline.hpp"

  37 #include "gc_implementation/g1/heapRegionRemSet.hpp"
  38 #include "gc_implementation/g1/heapRegionSeq.inline.hpp"
  39 #include "gc_implementation/g1/heapRegionSet.inline.hpp"
  40 #include "gc_implementation/shared/vmGCOperations.hpp"
  41 #include "gc_implementation/shared/gcTimer.hpp"
  42 #include "gc_implementation/shared/gcTrace.hpp"
  43 #include "gc_implementation/shared/gcTraceTime.hpp"
  44 #include "memory/allocation.hpp"
  45 #include "memory/genOopClosures.inline.hpp"
  46 #include "memory/referencePolicy.hpp"
  47 #include "memory/resourceArea.hpp"
  48 #include "oops/oop.inline.hpp"
  49 #include "runtime/handles.inline.hpp"
  50 #include "runtime/java.hpp"
  51 #include "runtime/atomic.inline.hpp"
  52 #include "runtime/prefetch.inline.hpp"
  53 #include "services/memTracker.hpp"
  54 
  55 // Concurrent marking bit map wrapper
  56 
  57 CMBitMapRO::CMBitMapRO(int shifter) :
  58   _bm(),


1392 
1393 // Base class of the closures that finalize and verify the
1394 // liveness counting data.
1395 class CMCountDataClosureBase: public HeapRegionClosure {
1396 protected:
1397   G1CollectedHeap* _g1h;
1398   ConcurrentMark* _cm;
1399   CardTableModRefBS* _ct_bs;
1400 
1401   BitMap* _region_bm;
1402   BitMap* _card_bm;
1403 
1404   // Takes a region that's not empty (i.e., it has at least one
1405   // live object in it and sets its corresponding bit on the region
1406   // bitmap to 1. If the region is "starts humongous" it will also set
1407   // to 1 the bits on the region bitmap that correspond to its
1408   // associated "continues humongous" regions.
1409   void set_bit_for_region(HeapRegion* hr) {
1410     assert(!hr->continuesHumongous(), "should have filtered those out");
1411 
1412     BitMap::idx_t index = (BitMap::idx_t) hr->hrs_index();
1413     if (!hr->startsHumongous()) {
1414       // Normal (non-humongous) case: just set the bit.
1415       _region_bm->par_at_put(index, true);
1416     } else {
1417       // Starts humongous case: calculate how many regions are part of
1418       // this humongous region and then set the bit range.
1419       BitMap::idx_t end_index = (BitMap::idx_t) hr->last_hc_index();
1420       _region_bm->par_at_put_range(index, end_index, true);
1421     }
1422   }
1423 
1424 public:
1425   CMCountDataClosureBase(G1CollectedHeap* g1h,
1426                          BitMap* region_bm, BitMap* card_bm):
1427     _g1h(g1h), _cm(g1h->concurrent_mark()),
1428     _ct_bs((CardTableModRefBS*) (g1h->barrier_set())),
1429     _region_bm(region_bm), _card_bm(card_bm) { }
1430 };
1431 
1432 // Closure that calculates the # live objects per region. Used


1580 
1581     // Call the CalcLiveObjectsClosure to walk the marking bitmap for
1582     // this region and set the corresponding bits in the expected region
1583     // and card bitmaps.
1584     bool res = _calc_cl.doHeapRegion(hr);
1585     assert(res == false, "should be continuing");
1586 
1587     MutexLockerEx x((_verbose ? ParGCRareEvent_lock : NULL),
1588                     Mutex::_no_safepoint_check_flag);
1589 
1590     // Verify the marked bytes for this region.
1591     size_t exp_marked_bytes = _calc_cl.region_marked_bytes();
1592     size_t act_marked_bytes = hr->next_marked_bytes();
1593 
1594     // We're not OK if expected marked bytes > actual marked bytes. It means
1595     // we have missed accounting some objects during the actual marking.
1596     if (exp_marked_bytes > act_marked_bytes) {
1597       if (_verbose) {
1598         gclog_or_tty->print_cr("Region %u: marked bytes mismatch: "
1599                                "expected: " SIZE_FORMAT ", actual: " SIZE_FORMAT,
1600                                hr->hrs_index(), exp_marked_bytes, act_marked_bytes);
1601       }
1602       failures += 1;
1603     }
1604 
1605     // Verify the bit, for this region, in the actual and expected
1606     // (which was just calculated) region bit maps.
1607     // We're not OK if the bit in the calculated expected region
1608     // bitmap is set and the bit in the actual region bitmap is not.
1609     BitMap::idx_t index = (BitMap::idx_t) hr->hrs_index();
1610 
1611     bool expected = _exp_region_bm->at(index);
1612     bool actual = _region_bm->at(index);
1613     if (expected && !actual) {
1614       if (_verbose) {
1615         gclog_or_tty->print_cr("Region %u: region bitmap mismatch: "
1616                                "expected: %s, actual: %s",
1617                                hr->hrs_index(),
1618                                BOOL_TO_STR(expected), BOOL_TO_STR(actual));
1619       }
1620       failures += 1;
1621     }
1622 
1623     // Verify that the card bit maps for the cards spanned by the current
1624     // region match. We have an error if we have a set bit in the expected
1625     // bit map and the corresponding bit in the actual bitmap is not set.
1626 
1627     BitMap::idx_t start_idx = _cm->card_bitmap_index_for(hr->bottom());
1628     BitMap::idx_t end_idx = _cm->card_bitmap_index_for(hr->top());
1629 
1630     for (BitMap::idx_t i = start_idx; i < end_idx; i+=1) {
1631       expected = _exp_card_bm->at(i);
1632       actual = _card_bm->at(i);
1633 
1634       if (expected && !actual) {
1635         if (_verbose) {
1636           gclog_or_tty->print_cr("Region %u: card bitmap mismatch at " SIZE_FORMAT ": "
1637                                  "expected: %s, actual: %s",
1638                                  hr->hrs_index(), i,
1639                                  BOOL_TO_STR(expected), BOOL_TO_STR(actual));
1640         }
1641         failures += 1;
1642       }
1643     }
1644 
1645     if (failures > 0 && _verbose)  {
1646       gclog_or_tty->print_cr("Region " HR_FORMAT ", ntams: " PTR_FORMAT ", "
1647                              "marked_bytes: calc/actual " SIZE_FORMAT "/" SIZE_FORMAT,
1648                              HR_FORMAT_PARAMS(hr), p2i(hr->next_top_at_mark_start()),
1649                              _calc_cl.region_marked_bytes(), hr->next_marked_bytes());
1650     }
1651 
1652     _failures += failures;
1653 
1654     // We could stop iteration over the heap when we
1655     // find the first violating region by returning true.
1656     return false;
1657   }
1658 };


3239     assert(!_g1h->is_in_g1_reserved(end) || _ct_bs->is_card_aligned(end), "sanity");
3240 
3241     BitMap::idx_t start_idx = _cm->card_bitmap_index_for(start);
3242     BitMap::idx_t limit_idx = _cm->card_bitmap_index_for(limit);
3243     BitMap::idx_t end_idx = _cm->card_bitmap_index_for(end);
3244 
3245     // If ntams is not card aligned then we bump card bitmap index
3246     // for limit so that we get the all the cards spanned by
3247     // the object ending at ntams.
3248     // Note: if this is the last region in the heap then ntams
3249     // could be actually just beyond the end of the the heap;
3250     // limit_idx will then  correspond to a (non-existent) card
3251     // that is also outside the heap.
3252     if (_g1h->is_in_g1_reserved(limit) && !_ct_bs->is_card_aligned(limit)) {
3253       limit_idx += 1;
3254     }
3255 
3256     assert(limit_idx <= end_idx, "or else use atomics");
3257 
3258     // Aggregate the "stripe" in the count data associated with hr.
3259     uint hrs_index = hr->hrs_index();
3260     size_t marked_bytes = 0;
3261 
3262     for (uint i = 0; i < _max_worker_id; i += 1) {
3263       size_t* marked_bytes_array = _cm->count_marked_bytes_array_for(i);
3264       BitMap* task_card_bm = _cm->count_card_bitmap_for(i);
3265 
3266       // Fetch the marked_bytes in this region for task i and
3267       // add it to the running total for this region.
3268       marked_bytes += marked_bytes_array[hrs_index];
3269 
3270       // Now union the bitmaps[0,max_worker_id)[start_idx..limit_idx)
3271       // into the global card bitmap.
3272       BitMap::idx_t scan_idx = task_card_bm->get_next_one_offset(start_idx, limit_idx);
3273 
3274       while (scan_idx < limit_idx) {
3275         assert(task_card_bm->at(scan_idx) == true, "should be");
3276         _cm_card_bm->set_bit(scan_idx);
3277         assert(_cm_card_bm->at(scan_idx) == true, "should be");
3278 
3279         // BitMap::get_next_one_offset() can handle the case when
3280         // its left_offset parameter is greater than its right_offset
3281         // parameter. It does, however, have an early exit if
3282         // left_offset == right_offset. So let's limit the value
3283         // passed in for left offset here.
3284         BitMap::idx_t next_idx = MIN2(scan_idx + 1, limit_idx);
3285         scan_idx = task_card_bm->get_next_one_offset(next_idx, limit_idx);
3286       }
3287     }
3288 




  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "classfile/symbolTable.hpp"
  27 #include "code/codeCache.hpp"
  28 #include "gc_implementation/g1/concurrentMark.inline.hpp"
  29 #include "gc_implementation/g1/concurrentMarkThread.inline.hpp"
  30 #include "gc_implementation/g1/g1CollectedHeap.inline.hpp"
  31 #include "gc_implementation/g1/g1CollectorPolicy.hpp"
  32 #include "gc_implementation/g1/g1ErgoVerbose.hpp"
  33 #include "gc_implementation/g1/g1Log.hpp"
  34 #include "gc_implementation/g1/g1OopClosures.inline.hpp"
  35 #include "gc_implementation/g1/g1RemSet.hpp"
  36 #include "gc_implementation/g1/heapRegion.inline.hpp"
  37 #include "gc_implementation/g1/heapRegionManager.inline.hpp"
  38 #include "gc_implementation/g1/heapRegionRemSet.hpp"

  39 #include "gc_implementation/g1/heapRegionSet.inline.hpp"
  40 #include "gc_implementation/shared/vmGCOperations.hpp"
  41 #include "gc_implementation/shared/gcTimer.hpp"
  42 #include "gc_implementation/shared/gcTrace.hpp"
  43 #include "gc_implementation/shared/gcTraceTime.hpp"
  44 #include "memory/allocation.hpp"
  45 #include "memory/genOopClosures.inline.hpp"
  46 #include "memory/referencePolicy.hpp"
  47 #include "memory/resourceArea.hpp"
  48 #include "oops/oop.inline.hpp"
  49 #include "runtime/handles.inline.hpp"
  50 #include "runtime/java.hpp"
  51 #include "runtime/atomic.inline.hpp"
  52 #include "runtime/prefetch.inline.hpp"
  53 #include "services/memTracker.hpp"
  54 
  55 // Concurrent marking bit map wrapper
  56 
  57 CMBitMapRO::CMBitMapRO(int shifter) :
  58   _bm(),


1392 
1393 // Base class of the closures that finalize and verify the
1394 // liveness counting data.
1395 class CMCountDataClosureBase: public HeapRegionClosure {
1396 protected:
1397   G1CollectedHeap* _g1h;
1398   ConcurrentMark* _cm;
1399   CardTableModRefBS* _ct_bs;
1400 
1401   BitMap* _region_bm;
1402   BitMap* _card_bm;
1403 
1404   // Takes a region that's not empty (i.e., it has at least one
1405   // live object in it and sets its corresponding bit on the region
1406   // bitmap to 1. If the region is "starts humongous" it will also set
1407   // to 1 the bits on the region bitmap that correspond to its
1408   // associated "continues humongous" regions.
1409   void set_bit_for_region(HeapRegion* hr) {
1410     assert(!hr->continuesHumongous(), "should have filtered those out");
1411 
1412     BitMap::idx_t index = (BitMap::idx_t) hr->hrm_index();
1413     if (!hr->startsHumongous()) {
1414       // Normal (non-humongous) case: just set the bit.
1415       _region_bm->par_at_put(index, true);
1416     } else {
1417       // Starts humongous case: calculate how many regions are part of
1418       // this humongous region and then set the bit range.
1419       BitMap::idx_t end_index = (BitMap::idx_t) hr->last_hc_index();
1420       _region_bm->par_at_put_range(index, end_index, true);
1421     }
1422   }
1423 
1424 public:
1425   CMCountDataClosureBase(G1CollectedHeap* g1h,
1426                          BitMap* region_bm, BitMap* card_bm):
1427     _g1h(g1h), _cm(g1h->concurrent_mark()),
1428     _ct_bs((CardTableModRefBS*) (g1h->barrier_set())),
1429     _region_bm(region_bm), _card_bm(card_bm) { }
1430 };
1431 
1432 // Closure that calculates the # live objects per region. Used


1580 
1581     // Call the CalcLiveObjectsClosure to walk the marking bitmap for
1582     // this region and set the corresponding bits in the expected region
1583     // and card bitmaps.
1584     bool res = _calc_cl.doHeapRegion(hr);
1585     assert(res == false, "should be continuing");
1586 
1587     MutexLockerEx x((_verbose ? ParGCRareEvent_lock : NULL),
1588                     Mutex::_no_safepoint_check_flag);
1589 
1590     // Verify the marked bytes for this region.
1591     size_t exp_marked_bytes = _calc_cl.region_marked_bytes();
1592     size_t act_marked_bytes = hr->next_marked_bytes();
1593 
1594     // We're not OK if expected marked bytes > actual marked bytes. It means
1595     // we have missed accounting some objects during the actual marking.
1596     if (exp_marked_bytes > act_marked_bytes) {
1597       if (_verbose) {
1598         gclog_or_tty->print_cr("Region %u: marked bytes mismatch: "
1599                                "expected: " SIZE_FORMAT ", actual: " SIZE_FORMAT,
1600                                hr->hrm_index(), exp_marked_bytes, act_marked_bytes);
1601       }
1602       failures += 1;
1603     }
1604 
1605     // Verify the bit, for this region, in the actual and expected
1606     // (which was just calculated) region bit maps.
1607     // We're not OK if the bit in the calculated expected region
1608     // bitmap is set and the bit in the actual region bitmap is not.
1609     BitMap::idx_t index = (BitMap::idx_t) hr->hrm_index();
1610 
1611     bool expected = _exp_region_bm->at(index);
1612     bool actual = _region_bm->at(index);
1613     if (expected && !actual) {
1614       if (_verbose) {
1615         gclog_or_tty->print_cr("Region %u: region bitmap mismatch: "
1616                                "expected: %s, actual: %s",
1617                                hr->hrm_index(),
1618                                BOOL_TO_STR(expected), BOOL_TO_STR(actual));
1619       }
1620       failures += 1;
1621     }
1622 
1623     // Verify that the card bit maps for the cards spanned by the current
1624     // region match. We have an error if we have a set bit in the expected
1625     // bit map and the corresponding bit in the actual bitmap is not set.
1626 
1627     BitMap::idx_t start_idx = _cm->card_bitmap_index_for(hr->bottom());
1628     BitMap::idx_t end_idx = _cm->card_bitmap_index_for(hr->top());
1629 
1630     for (BitMap::idx_t i = start_idx; i < end_idx; i+=1) {
1631       expected = _exp_card_bm->at(i);
1632       actual = _card_bm->at(i);
1633 
1634       if (expected && !actual) {
1635         if (_verbose) {
1636           gclog_or_tty->print_cr("Region %u: card bitmap mismatch at " SIZE_FORMAT ": "
1637                                  "expected: %s, actual: %s",
1638                                  hr->hrm_index(), i,
1639                                  BOOL_TO_STR(expected), BOOL_TO_STR(actual));
1640         }
1641         failures += 1;
1642       }
1643     }
1644 
1645     if (failures > 0 && _verbose)  {
1646       gclog_or_tty->print_cr("Region " HR_FORMAT ", ntams: " PTR_FORMAT ", "
1647                              "marked_bytes: calc/actual " SIZE_FORMAT "/" SIZE_FORMAT,
1648                              HR_FORMAT_PARAMS(hr), p2i(hr->next_top_at_mark_start()),
1649                              _calc_cl.region_marked_bytes(), hr->next_marked_bytes());
1650     }
1651 
1652     _failures += failures;
1653 
1654     // We could stop iteration over the heap when we
1655     // find the first violating region by returning true.
1656     return false;
1657   }
1658 };


3239     assert(!_g1h->is_in_g1_reserved(end) || _ct_bs->is_card_aligned(end), "sanity");
3240 
3241     BitMap::idx_t start_idx = _cm->card_bitmap_index_for(start);
3242     BitMap::idx_t limit_idx = _cm->card_bitmap_index_for(limit);
3243     BitMap::idx_t end_idx = _cm->card_bitmap_index_for(end);
3244 
3245     // If ntams is not card aligned then we bump card bitmap index
3246     // for limit so that we get the all the cards spanned by
3247     // the object ending at ntams.
3248     // Note: if this is the last region in the heap then ntams
3249     // could be actually just beyond the end of the the heap;
3250     // limit_idx will then  correspond to a (non-existent) card
3251     // that is also outside the heap.
3252     if (_g1h->is_in_g1_reserved(limit) && !_ct_bs->is_card_aligned(limit)) {
3253       limit_idx += 1;
3254     }
3255 
3256     assert(limit_idx <= end_idx, "or else use atomics");
3257 
3258     // Aggregate the "stripe" in the count data associated with hr.
3259     uint hrm_index = hr->hrm_index();
3260     size_t marked_bytes = 0;
3261 
3262     for (uint i = 0; i < _max_worker_id; i += 1) {
3263       size_t* marked_bytes_array = _cm->count_marked_bytes_array_for(i);
3264       BitMap* task_card_bm = _cm->count_card_bitmap_for(i);
3265 
3266       // Fetch the marked_bytes in this region for task i and
3267       // add it to the running total for this region.
3268       marked_bytes += marked_bytes_array[hrm_index];
3269 
3270       // Now union the bitmaps[0,max_worker_id)[start_idx..limit_idx)
3271       // into the global card bitmap.
3272       BitMap::idx_t scan_idx = task_card_bm->get_next_one_offset(start_idx, limit_idx);
3273 
3274       while (scan_idx < limit_idx) {
3275         assert(task_card_bm->at(scan_idx) == true, "should be");
3276         _cm_card_bm->set_bit(scan_idx);
3277         assert(_cm_card_bm->at(scan_idx) == true, "should be");
3278 
3279         // BitMap::get_next_one_offset() can handle the case when
3280         // its left_offset parameter is greater than its right_offset
3281         // parameter. It does, however, have an early exit if
3282         // left_offset == right_offset. So let's limit the value
3283         // passed in for left offset here.
3284         BitMap::idx_t next_idx = MIN2(scan_idx + 1, limit_idx);
3285         scan_idx = task_card_bm->get_next_one_offset(next_idx, limit_idx);
3286       }
3287     }
3288