comparison src/share/vm/gc_implementation/g1/concurrentMark.cpp @ 6812:988bf00cc564

7200261: G1: Liveness counting inconsistencies during marking verification Summary: The clipping code in the routine that sets the bits for a range of cards, in the liveness accounting verification code was incorrect. It set all the bits in the card bitmap from the given starting index which would lead to spurious marking verification failures. Reviewed-by: brutisso, jwilhelm, jmasa
author johnc
date Thu, 27 Sep 2012 15:44:01 -0700
parents 859cd1a76f8a
children 8a5ea0a9ccc4
comparison
equal deleted inserted replaced
6788:7c2fd5948145 6812:988bf00cc564
1186 1186
1187 // Base class of the closures that finalize and verify the 1187 // Base class of the closures that finalize and verify the
1188 // liveness counting data. 1188 // liveness counting data.
1189 class CMCountDataClosureBase: public HeapRegionClosure { 1189 class CMCountDataClosureBase: public HeapRegionClosure {
1190 protected: 1190 protected:
1191 G1CollectedHeap* _g1h;
1191 ConcurrentMark* _cm; 1192 ConcurrentMark* _cm;
1193 CardTableModRefBS* _ct_bs;
1194
1192 BitMap* _region_bm; 1195 BitMap* _region_bm;
1193 BitMap* _card_bm; 1196 BitMap* _card_bm;
1194 1197
1195 void set_card_bitmap_range(BitMap::idx_t start_idx, BitMap::idx_t last_idx) { 1198 // Takes a region that's not empty (i.e., it has at least one
1196 assert(start_idx <= last_idx, "sanity");
1197
1198 // Set the inclusive bit range [start_idx, last_idx].
1199 // For small ranges (up to 8 cards) use a simple loop; otherwise
1200 // use par_at_put_range.
1201 if ((last_idx - start_idx) < 8) {
1202 for (BitMap::idx_t i = start_idx; i <= last_idx; i += 1) {
1203 _card_bm->par_set_bit(i);
1204 }
1205 } else {
1206 assert(last_idx < _card_bm->size(), "sanity");
1207 // Note BitMap::par_at_put_range() is exclusive.
1208 BitMap::idx_t max_idx = MAX2(last_idx+1, _card_bm->size());
1209 _card_bm->par_at_put_range(start_idx, max_idx, true);
1210 }
1211 }
1212
1213 // It takes a region that's not empty (i.e., it has at least one
1214 // live object in it and sets its corresponding bit on the region 1199 // live object in it and sets its corresponding bit on the region
1215 // bitmap to 1. If the region is "starts humongous" it will also set 1200 // bitmap to 1. If the region is "starts humongous" it will also set
1216 // to 1 the bits on the region bitmap that correspond to its 1201 // to 1 the bits on the region bitmap that correspond to its
1217 // associated "continues humongous" regions. 1202 // associated "continues humongous" regions.
1218 void set_bit_for_region(HeapRegion* hr) { 1203 void set_bit_for_region(HeapRegion* hr) {
1229 _region_bm->par_at_put_range(index, end_index, true); 1214 _region_bm->par_at_put_range(index, end_index, true);
1230 } 1215 }
1231 } 1216 }
1232 1217
1233 public: 1218 public:
1234 CMCountDataClosureBase(ConcurrentMark *cm, 1219 CMCountDataClosureBase(G1CollectedHeap* g1h,
1235 BitMap* region_bm, BitMap* card_bm): 1220 BitMap* region_bm, BitMap* card_bm):
1236 _cm(cm), _region_bm(region_bm), _card_bm(card_bm) { } 1221 _g1h(g1h), _cm(g1h->concurrent_mark()),
1222 _ct_bs((CardTableModRefBS*) (g1h->barrier_set())),
1223 _region_bm(region_bm), _card_bm(card_bm) { }
1237 }; 1224 };
1238 1225
1239 // Closure that calculates the # live objects per region. Used 1226 // Closure that calculates the # live objects per region. Used
1240 // for verification purposes during the cleanup pause. 1227 // for verification purposes during the cleanup pause.
1241 class CalcLiveObjectsClosure: public CMCountDataClosureBase { 1228 class CalcLiveObjectsClosure: public CMCountDataClosureBase {
1242 CMBitMapRO* _bm; 1229 CMBitMapRO* _bm;
1243 size_t _region_marked_bytes; 1230 size_t _region_marked_bytes;
1244 1231
1245 public: 1232 public:
1246 CalcLiveObjectsClosure(CMBitMapRO *bm, ConcurrentMark *cm, 1233 CalcLiveObjectsClosure(CMBitMapRO *bm, G1CollectedHeap* g1h,
1247 BitMap* region_bm, BitMap* card_bm) : 1234 BitMap* region_bm, BitMap* card_bm) :
1248 CMCountDataClosureBase(cm, region_bm, card_bm), 1235 CMCountDataClosureBase(g1h, region_bm, card_bm),
1249 _bm(bm), _region_marked_bytes(0) { } 1236 _bm(bm), _region_marked_bytes(0) { }
1250 1237
1251 bool doHeapRegion(HeapRegion* hr) { 1238 bool doHeapRegion(HeapRegion* hr) {
1252 1239
1253 if (hr->continuesHumongous()) { 1240 if (hr->continuesHumongous()) {
1259 // iteration, a "continues humongous" region might be visited 1246 // iteration, a "continues humongous" region might be visited
1260 // before its associated "starts humongous". 1247 // before its associated "starts humongous".
1261 return false; 1248 return false;
1262 } 1249 }
1263 1250
1264 HeapWord* nextTop = hr->next_top_at_mark_start(); 1251 HeapWord* ntams = hr->next_top_at_mark_start();
1265 HeapWord* start = hr->bottom(); 1252 HeapWord* start = hr->bottom();
1266 1253
1267 assert(start <= hr->end() && start <= nextTop && nextTop <= hr->end(), 1254 assert(start <= hr->end() && start <= ntams && ntams <= hr->end(),
1268 err_msg("Preconditions not met - " 1255 err_msg("Preconditions not met - "
1269 "start: "PTR_FORMAT", nextTop: "PTR_FORMAT", end: "PTR_FORMAT, 1256 "start: "PTR_FORMAT", ntams: "PTR_FORMAT", end: "PTR_FORMAT,
1270 start, nextTop, hr->end())); 1257 start, ntams, hr->end()));
1271 1258
1272 // Find the first marked object at or after "start". 1259 // Find the first marked object at or after "start".
1273 start = _bm->getNextMarkedWordAddress(start, nextTop); 1260 start = _bm->getNextMarkedWordAddress(start, ntams);
1274 1261
1275 size_t marked_bytes = 0; 1262 size_t marked_bytes = 0;
1276 1263
1277 while (start < nextTop) { 1264 while (start < ntams) {
1278 oop obj = oop(start); 1265 oop obj = oop(start);
1279 int obj_sz = obj->size(); 1266 int obj_sz = obj->size();
1280 HeapWord* obj_last = start + obj_sz - 1; 1267 HeapWord* obj_end = start + obj_sz;
1281 1268
1282 BitMap::idx_t start_idx = _cm->card_bitmap_index_for(start); 1269 BitMap::idx_t start_idx = _cm->card_bitmap_index_for(start);
1283 BitMap::idx_t last_idx = _cm->card_bitmap_index_for(obj_last); 1270 BitMap::idx_t end_idx = _cm->card_bitmap_index_for(obj_end);
1284 1271
1285 // Set the bits in the card BM for this object (inclusive). 1272 // Note: if we're looking at the last region in heap - obj_end
1286 set_card_bitmap_range(start_idx, last_idx); 1273 // could be actually just beyond the end of the heap; end_idx
1274 // will then correspond to a (non-existent) card that is also
1275 // just beyond the heap.
1276 if (_g1h->is_in_g1_reserved(obj_end) && !_ct_bs->is_card_aligned(obj_end)) {
1277 // end of object is not card aligned - increment to cover
1278 // all the cards spanned by the object
1279 end_idx += 1;
1280 }
1281
1282 // Set the bits in the card BM for the cards spanned by this object.
1283 _cm->set_card_bitmap_range(_card_bm, start_idx, end_idx, true /* is_par */);
1287 1284
1288 // Add the size of this object to the number of marked bytes. 1285 // Add the size of this object to the number of marked bytes.
1289 marked_bytes += (size_t)obj_sz * HeapWordSize; 1286 marked_bytes += (size_t)obj_sz * HeapWordSize;
1290 1287
1291 // Find the next marked object after this one. 1288 // Find the next marked object after this one.
1292 start = _bm->getNextMarkedWordAddress(obj_last + 1, nextTop); 1289 start = _bm->getNextMarkedWordAddress(obj_end, ntams);
1293 } 1290 }
1294 1291
1295 // Mark the allocated-since-marking portion... 1292 // Mark the allocated-since-marking portion...
1296 HeapWord* top = hr->top(); 1293 HeapWord* top = hr->top();
1297 if (nextTop < top) { 1294 if (ntams < top) {
1298 BitMap::idx_t start_idx = _cm->card_bitmap_index_for(nextTop); 1295 BitMap::idx_t start_idx = _cm->card_bitmap_index_for(ntams);
1299 BitMap::idx_t last_idx = _cm->card_bitmap_index_for(top - 1); 1296 BitMap::idx_t end_idx = _cm->card_bitmap_index_for(top);
1300 1297
1301 set_card_bitmap_range(start_idx, last_idx); 1298 // Note: if we're looking at the last region in heap - top
1299 // could be actually just beyond the end of the heap; end_idx
1300 // will then correspond to a (non-existent) card that is also
1301 // just beyond the heap.
1302 if (_g1h->is_in_g1_reserved(top) && !_ct_bs->is_card_aligned(top)) {
1303 // end of object is not card aligned - increment to cover
1304 // all the cards spanned by the object
1305 end_idx += 1;
1306 }
1307 _cm->set_card_bitmap_range(_card_bm, start_idx, end_idx, true /* is_par */);
1302 1308
1303 // This definitely means the region has live objects. 1309 // This definitely means the region has live objects.
1304 set_bit_for_region(hr); 1310 set_bit_for_region(hr);
1305 } 1311 }
1306 1312
1323 // that was accumulated concurrently and aggregated during 1329 // that was accumulated concurrently and aggregated during
1324 // the remark pause. This closure is applied to the heap 1330 // the remark pause. This closure is applied to the heap
1325 // regions during the STW cleanup pause. 1331 // regions during the STW cleanup pause.
1326 1332
1327 class VerifyLiveObjectDataHRClosure: public HeapRegionClosure { 1333 class VerifyLiveObjectDataHRClosure: public HeapRegionClosure {
1334 G1CollectedHeap* _g1h;
1328 ConcurrentMark* _cm; 1335 ConcurrentMark* _cm;
1329 CalcLiveObjectsClosure _calc_cl; 1336 CalcLiveObjectsClosure _calc_cl;
1330 BitMap* _region_bm; // Region BM to be verified 1337 BitMap* _region_bm; // Region BM to be verified
1331 BitMap* _card_bm; // Card BM to be verified 1338 BitMap* _card_bm; // Card BM to be verified
1332 bool _verbose; // verbose output? 1339 bool _verbose; // verbose output?
1335 BitMap* _exp_card_bm; // Expected card BM values 1342 BitMap* _exp_card_bm; // Expected card BM values
1336 1343
1337 int _failures; 1344 int _failures;
1338 1345
1339 public: 1346 public:
1340 VerifyLiveObjectDataHRClosure(ConcurrentMark* cm, 1347 VerifyLiveObjectDataHRClosure(G1CollectedHeap* g1h,
1341 BitMap* region_bm, 1348 BitMap* region_bm,
1342 BitMap* card_bm, 1349 BitMap* card_bm,
1343 BitMap* exp_region_bm, 1350 BitMap* exp_region_bm,
1344 BitMap* exp_card_bm, 1351 BitMap* exp_card_bm,
1345 bool verbose) : 1352 bool verbose) :
1346 _cm(cm), 1353 _g1h(g1h), _cm(g1h->concurrent_mark()),
1347 _calc_cl(_cm->nextMarkBitMap(), _cm, exp_region_bm, exp_card_bm), 1354 _calc_cl(_cm->nextMarkBitMap(), g1h, exp_region_bm, exp_card_bm),
1348 _region_bm(region_bm), _card_bm(card_bm), _verbose(verbose), 1355 _region_bm(region_bm), _card_bm(card_bm), _verbose(verbose),
1349 _exp_region_bm(exp_region_bm), _exp_card_bm(exp_card_bm), 1356 _exp_region_bm(exp_region_bm), _exp_card_bm(exp_card_bm),
1350 _failures(0) { } 1357 _failures(0) { }
1351 1358
1352 int failures() const { return _failures; } 1359 int failures() const { return _failures; }
1489 } 1496 }
1490 1497
1491 void work(uint worker_id) { 1498 void work(uint worker_id) {
1492 assert(worker_id < _n_workers, "invariant"); 1499 assert(worker_id < _n_workers, "invariant");
1493 1500
1494 VerifyLiveObjectDataHRClosure verify_cl(_cm, 1501 VerifyLiveObjectDataHRClosure verify_cl(_g1h,
1495 _actual_region_bm, _actual_card_bm, 1502 _actual_region_bm, _actual_card_bm,
1496 _expected_region_bm, 1503 _expected_region_bm,
1497 _expected_card_bm, 1504 _expected_card_bm,
1498 _verbose); 1505 _verbose);
1499 1506
1519 // card liveness bitmap. Also sets the bit for each region, 1526 // card liveness bitmap. Also sets the bit for each region,
1520 // containing live data, in the region liveness bitmap. 1527 // containing live data, in the region liveness bitmap.
1521 1528
1522 class FinalCountDataUpdateClosure: public CMCountDataClosureBase { 1529 class FinalCountDataUpdateClosure: public CMCountDataClosureBase {
1523 public: 1530 public:
1524 FinalCountDataUpdateClosure(ConcurrentMark* cm, 1531 FinalCountDataUpdateClosure(G1CollectedHeap* g1h,
1525 BitMap* region_bm, 1532 BitMap* region_bm,
1526 BitMap* card_bm) : 1533 BitMap* card_bm) :
1527 CMCountDataClosureBase(cm, region_bm, card_bm) { } 1534 CMCountDataClosureBase(g1h, region_bm, card_bm) { }
1528 1535
1529 bool doHeapRegion(HeapRegion* hr) { 1536 bool doHeapRegion(HeapRegion* hr) {
1530 1537
1531 if (hr->continuesHumongous()) { 1538 if (hr->continuesHumongous()) {
1532 // We will ignore these here and process them when their 1539 // We will ignore these here and process them when their
1546 1553
1547 // Mark the allocated-since-marking portion... 1554 // Mark the allocated-since-marking portion...
1548 if (ntams < top) { 1555 if (ntams < top) {
1549 // This definitely means the region has live objects. 1556 // This definitely means the region has live objects.
1550 set_bit_for_region(hr); 1557 set_bit_for_region(hr);
1551 } 1558
1552 1559 // Now set the bits in the card bitmap for [ntams, top)
1553 // Now set the bits for [ntams, top] 1560 BitMap::idx_t start_idx = _cm->card_bitmap_index_for(ntams);
1554 BitMap::idx_t start_idx = _cm->card_bitmap_index_for(ntams); 1561 BitMap::idx_t end_idx = _cm->card_bitmap_index_for(top);
1555 // set_card_bitmap_range() expects the last_idx to be with 1562
1556 // the range of the bit map (see assertion in set_card_bitmap_range()), 1563 // Note: if we're looking at the last region in heap - top
1557 // so limit it to that range with this application of MIN2. 1564 // could be actually just beyond the end of the heap; end_idx
1558 BitMap::idx_t last_idx = MIN2(_cm->card_bitmap_index_for(top), 1565 // will then correspond to a (non-existent) card that is also
1559 _card_bm->size()-1); 1566 // just beyond the heap.
1560 if (start_idx < _card_bm->size()) { 1567 if (_g1h->is_in_g1_reserved(top) && !_ct_bs->is_card_aligned(top)) {
1561 set_card_bitmap_range(start_idx, last_idx); 1568 // end of object is not card aligned - increment to cover
1562 } else { 1569 // all the cards spanned by the object
1563 // To reach here start_idx must be beyond the end of 1570 end_idx += 1;
1564 // the bit map and last_idx must have been limited by 1571 }
1565 // the MIN2(). 1572
1566 assert(start_idx == last_idx + 1, 1573 assert(end_idx <= _card_bm->size(),
1567 err_msg("Not beyond end start_idx " SIZE_FORMAT " last_idx " 1574 err_msg("oob: end_idx= "SIZE_FORMAT", bitmap size= "SIZE_FORMAT,
1568 SIZE_FORMAT, start_idx, last_idx)); 1575 end_idx, _card_bm->size()));
1576 assert(start_idx < _card_bm->size(),
1577 err_msg("oob: start_idx= "SIZE_FORMAT", bitmap size= "SIZE_FORMAT,
1578 start_idx, _card_bm->size()));
1579
1580 _cm->set_card_bitmap_range(_card_bm, start_idx, end_idx, true /* is_par */);
1569 } 1581 }
1570 1582
1571 // Set the bit for the region if it contains live data 1583 // Set the bit for the region if it contains live data
1572 if (hr->next_marked_bytes() > 0) { 1584 if (hr->next_marked_bytes() > 0) {
1573 set_bit_for_region(hr); 1585 set_bit_for_region(hr);
1604 } 1616 }
1605 1617
1606 void work(uint worker_id) { 1618 void work(uint worker_id) {
1607 assert(worker_id < _n_workers, "invariant"); 1619 assert(worker_id < _n_workers, "invariant");
1608 1620
1609 FinalCountDataUpdateClosure final_update_cl(_cm, 1621 FinalCountDataUpdateClosure final_update_cl(_g1h,
1610 _actual_region_bm, 1622 _actual_region_bm,
1611 _actual_card_bm); 1623 _actual_card_bm);
1612 1624
1613 if (G1CollectedHeap::use_parallel_gc_threads()) { 1625 if (G1CollectedHeap::use_parallel_gc_threads()) {
1614 _g1h->heap_region_par_iterate_chunked(&final_update_cl, 1626 _g1h->heap_region_par_iterate_chunked(&final_update_cl,
2844 } 2856 }
2845 2857
2846 // Aggregate the counting data that was constructed concurrently 2858 // Aggregate the counting data that was constructed concurrently
2847 // with marking. 2859 // with marking.
2848 class AggregateCountDataHRClosure: public HeapRegionClosure { 2860 class AggregateCountDataHRClosure: public HeapRegionClosure {
2861 G1CollectedHeap* _g1h;
2849 ConcurrentMark* _cm; 2862 ConcurrentMark* _cm;
2863 CardTableModRefBS* _ct_bs;
2850 BitMap* _cm_card_bm; 2864 BitMap* _cm_card_bm;
2851 size_t _max_task_num; 2865 size_t _max_task_num;
2852 2866
2853 public: 2867 public:
2854 AggregateCountDataHRClosure(ConcurrentMark *cm, 2868 AggregateCountDataHRClosure(G1CollectedHeap* g1h,
2855 BitMap* cm_card_bm, 2869 BitMap* cm_card_bm,
2856 size_t max_task_num) : 2870 size_t max_task_num) :
2857 _cm(cm), _cm_card_bm(cm_card_bm), 2871 _g1h(g1h), _cm(g1h->concurrent_mark()),
2858 _max_task_num(max_task_num) { } 2872 _ct_bs((CardTableModRefBS*) (g1h->barrier_set())),
2859 2873 _cm_card_bm(cm_card_bm), _max_task_num(max_task_num) { }
2860 bool is_card_aligned(HeapWord* p) {
2861 return ((uintptr_t(p) & (CardTableModRefBS::card_size - 1)) == 0);
2862 }
2863 2874
2864 bool doHeapRegion(HeapRegion* hr) { 2875 bool doHeapRegion(HeapRegion* hr) {
2865 if (hr->continuesHumongous()) { 2876 if (hr->continuesHumongous()) {
2866 // We will ignore these here and process them when their 2877 // We will ignore these here and process them when their
2867 // associated "starts humongous" region is processed. 2878 // associated "starts humongous" region is processed.
2888 if (start == limit) { 2899 if (start == limit) {
2889 // NTAMS of this region has not been set so nothing to do. 2900 // NTAMS of this region has not been set so nothing to do.
2890 return false; 2901 return false;
2891 } 2902 }
2892 2903
2893 assert(is_card_aligned(start), "sanity"); 2904 // 'start' should be in the heap.
2894 assert(is_card_aligned(end), "sanity"); 2905 assert(_g1h->is_in_g1_reserved(start) && _ct_bs->is_card_aligned(start), "sanity");
2906 // 'end' *may* be just beyone the end of the heap (if hr is the last region)
2907 assert(!_g1h->is_in_g1_reserved(end) || _ct_bs->is_card_aligned(end), "sanity");
2895 2908
2896 BitMap::idx_t start_idx = _cm->card_bitmap_index_for(start); 2909 BitMap::idx_t start_idx = _cm->card_bitmap_index_for(start);
2897 BitMap::idx_t limit_idx = _cm->card_bitmap_index_for(limit); 2910 BitMap::idx_t limit_idx = _cm->card_bitmap_index_for(limit);
2898 BitMap::idx_t end_idx = _cm->card_bitmap_index_for(end); 2911 BitMap::idx_t end_idx = _cm->card_bitmap_index_for(end);
2899 2912
2900 // If ntams is not card aligned then we bump the index for 2913 // If ntams is not card aligned then we bump card bitmap index
2901 // limit so that we get the card spanning ntams. 2914 // for limit so that we get the all the cards spanned by
2902 if (!is_card_aligned(limit)) { 2915 // the object ending at ntams.
2916 // Note: if this is the last region in the heap then ntams
2917 // could be actually just beyond the end of the the heap;
2918 // limit_idx will then correspond to a (non-existent) card
2919 // that is also outside the heap.
2920 if (_g1h->is_in_g1_reserved(limit) && !_ct_bs->is_card_aligned(limit)) {
2903 limit_idx += 1; 2921 limit_idx += 1;
2904 } 2922 }
2905 2923
2906 assert(limit_idx <= end_idx, "or else use atomics"); 2924 assert(limit_idx <= end_idx, "or else use atomics");
2907 2925
2926 _cm_card_bm->set_bit(scan_idx); 2944 _cm_card_bm->set_bit(scan_idx);
2927 assert(_cm_card_bm->at(scan_idx) == true, "should be"); 2945 assert(_cm_card_bm->at(scan_idx) == true, "should be");
2928 2946
2929 // BitMap::get_next_one_offset() can handle the case when 2947 // BitMap::get_next_one_offset() can handle the case when
2930 // its left_offset parameter is greater than its right_offset 2948 // its left_offset parameter is greater than its right_offset
2931 // parameter. If does, however, have an early exit if 2949 // parameter. It does, however, have an early exit if
2932 // left_offset == right_offset. So let's limit the value 2950 // left_offset == right_offset. So let's limit the value
2933 // passed in for left offset here. 2951 // passed in for left offset here.
2934 BitMap::idx_t next_idx = MIN2(scan_idx + 1, limit_idx); 2952 BitMap::idx_t next_idx = MIN2(scan_idx + 1, limit_idx);
2935 scan_idx = task_card_bm->get_next_one_offset(next_idx, limit_idx); 2953 scan_idx = task_card_bm->get_next_one_offset(next_idx, limit_idx);
2936 } 2954 }
2962 _g1h(g1h), _cm(cm), _cm_card_bm(cm_card_bm), 2980 _g1h(g1h), _cm(cm), _cm_card_bm(cm_card_bm),
2963 _max_task_num(max_task_num), 2981 _max_task_num(max_task_num),
2964 _active_workers(n_workers) { } 2982 _active_workers(n_workers) { }
2965 2983
2966 void work(uint worker_id) { 2984 void work(uint worker_id) {
2967 AggregateCountDataHRClosure cl(_cm, _cm_card_bm, _max_task_num); 2985 AggregateCountDataHRClosure cl(_g1h, _cm_card_bm, _max_task_num);
2968 2986
2969 if (G1CollectedHeap::use_parallel_gc_threads()) { 2987 if (G1CollectedHeap::use_parallel_gc_threads()) {
2970 _g1h->heap_region_par_iterate_chunked(&cl, worker_id, 2988 _g1h->heap_region_par_iterate_chunked(&cl, worker_id,
2971 _active_workers, 2989 _active_workers,
2972 HeapRegion::AggregateCountClaimValue); 2990 HeapRegion::AggregateCountClaimValue);