comparison src/share/vm/gc_implementation/g1/concurrentMark.cpp @ 6027:8a2e5a6a19a4

7143490: G1: Remove HeapRegion::_top_at_conc_mark_count Summary: Removed the HeapRegion::_top_at_conc_mark_count field. It is no longer needed as a result of the changes for 6888336 and 7127706. Refactored the closures that finalize and verify the liveness counting data so that common functionality was placed into a base class. Reviewed-by: brutisso, tonyp
author johnc
date Wed, 25 Apr 2012 10:23:12 -0700
parents f7a8920427a6
children d2a62e0f25eb 922993931b3d
comparison
equal deleted inserted replaced
6026:9f059abe8cf2 6027:8a2e5a6a19a4
1181 _remark_times.add((now - start) * 1000.0); 1181 _remark_times.add((now - start) * 1000.0);
1182 1182
1183 g1p->record_concurrent_mark_remark_end(); 1183 g1p->record_concurrent_mark_remark_end();
1184 } 1184 }
1185 1185
1186 // Used to calculate the # live objects per region 1186 // Base class of the closures that finalize and verify the
1187 // for verification purposes 1187 // liveness counting data.
1188 class CalcLiveObjectsClosure: public HeapRegionClosure { 1188 class CMCountDataClosureBase: public HeapRegionClosure {
1189 1189 protected:
1190 CMBitMapRO* _bm;
1191 ConcurrentMark* _cm; 1190 ConcurrentMark* _cm;
1192 BitMap* _region_bm; 1191 BitMap* _region_bm;
1193 BitMap* _card_bm; 1192 BitMap* _card_bm;
1194 1193
1195 size_t _region_marked_bytes; 1194 void set_card_bitmap_range(BitMap::idx_t start_idx, BitMap::idx_t last_idx) {
1196 1195 assert(start_idx <= last_idx, "sanity");
1197 intptr_t _bottom_card_num; 1196
1198 1197 // Set the inclusive bit range [start_idx, last_idx].
1199 void mark_card_num_range(intptr_t start_card_num, intptr_t last_card_num) { 1198 // For small ranges (up to 8 cards) use a simple loop; otherwise
1200 assert(start_card_num <= last_card_num, "sanity"); 1199 // use par_at_put_range.
1201 BitMap::idx_t start_idx = start_card_num - _bottom_card_num; 1200 if ((last_idx - start_idx) < 8) {
1202 BitMap::idx_t last_idx = last_card_num - _bottom_card_num; 1201 for (BitMap::idx_t i = start_idx; i <= last_idx; i += 1) {
1203 1202 _card_bm->par_set_bit(i);
1204 for (BitMap::idx_t i = start_idx; i <= last_idx; i += 1) { 1203 }
1205 _card_bm->par_at_put(i, 1); 1204 } else {
1206 } 1205 assert(last_idx < _card_bm->size(), "sanity");
1207 } 1206 // Note BitMap::par_at_put_range() is exclusive.
1208 1207 _card_bm->par_at_put_range(start_idx, last_idx+1, true);
1209 public: 1208 }
1210 CalcLiveObjectsClosure(CMBitMapRO *bm, ConcurrentMark *cm, 1209 }
1211 BitMap* region_bm, BitMap* card_bm) :
1212 _bm(bm), _cm(cm), _region_bm(region_bm), _card_bm(card_bm),
1213 _region_marked_bytes(0), _bottom_card_num(cm->heap_bottom_card_num()) { }
1214 1210
1215 // It takes a region that's not empty (i.e., it has at least one 1211 // It takes a region that's not empty (i.e., it has at least one
1216 // live object in it and sets its corresponding bit on the region 1212 // live object in it and sets its corresponding bit on the region
1217 // bitmap to 1. If the region is "starts humongous" it will also set 1213 // bitmap to 1. If the region is "starts humongous" it will also set
1218 // to 1 the bits on the region bitmap that correspond to its 1214 // to 1 the bits on the region bitmap that correspond to its
1232 BitMap::idx_t end_index = (BitMap::idx_t) last_hr->hrs_index() + 1; 1228 BitMap::idx_t end_index = (BitMap::idx_t) last_hr->hrs_index() + 1;
1233 _region_bm->par_at_put_range(index, end_index, true); 1229 _region_bm->par_at_put_range(index, end_index, true);
1234 } 1230 }
1235 } 1231 }
1236 1232
1233 public:
1234 CMCountDataClosureBase(ConcurrentMark *cm,
1235 BitMap* region_bm, BitMap* card_bm):
1236 _cm(cm), _region_bm(region_bm), _card_bm(card_bm) { }
1237 };
1238
1239 // Closure that calculates the # live objects per region. Used
1240 // for verification purposes during the cleanup pause.
1241 class CalcLiveObjectsClosure: public CMCountDataClosureBase {
1242 CMBitMapRO* _bm;
1243 size_t _region_marked_bytes;
1244
1245 public:
1246 CalcLiveObjectsClosure(CMBitMapRO *bm, ConcurrentMark *cm,
1247 BitMap* region_bm, BitMap* card_bm) :
1248 CMCountDataClosureBase(cm, region_bm, card_bm),
1249 _bm(bm), _region_marked_bytes(0) { }
1250
1237 bool doHeapRegion(HeapRegion* hr) { 1251 bool doHeapRegion(HeapRegion* hr) {
1238 1252
1239 if (hr->continuesHumongous()) { 1253 if (hr->continuesHumongous()) {
1240 // We will ignore these here and process them when their 1254 // We will ignore these here and process them when their
1241 // associated "starts humongous" region is processed (see 1255 // associated "starts humongous" region is processed (see
1258 // Find the first marked object at or after "start". 1272 // Find the first marked object at or after "start".
1259 start = _bm->getNextMarkedWordAddress(start, nextTop); 1273 start = _bm->getNextMarkedWordAddress(start, nextTop);
1260 1274
1261 size_t marked_bytes = 0; 1275 size_t marked_bytes = 0;
1262 1276
1263 // Below, the term "card num" means the result of shifting an address
1264 // by the card shift -- address 0 corresponds to card number 0. One
1265 // must subtract the card num of the bottom of the heap to obtain a
1266 // card table index.
1267
1268 // The first card num of the sequence of live cards currently being
1269 // constructed. -1 ==> no sequence.
1270 intptr_t start_card_num = -1;
1271
1272 // The last card num of the sequence of live cards currently being
1273 // constructed. -1 ==> no sequence.
1274 intptr_t last_card_num = -1;
1275
1276 while (start < nextTop) { 1277 while (start < nextTop) {
1277 oop obj = oop(start); 1278 oop obj = oop(start);
1278 int obj_sz = obj->size(); 1279 int obj_sz = obj->size();
1279
1280 // The card num of the start of the current object.
1281 intptr_t obj_card_num =
1282 intptr_t(uintptr_t(start) >> CardTableModRefBS::card_shift);
1283 HeapWord* obj_last = start + obj_sz - 1; 1280 HeapWord* obj_last = start + obj_sz - 1;
1284 intptr_t obj_last_card_num = 1281
1285 intptr_t(uintptr_t(obj_last) >> CardTableModRefBS::card_shift); 1282 BitMap::idx_t start_idx = _cm->card_bitmap_index_for(start);
1286 1283 BitMap::idx_t last_idx = _cm->card_bitmap_index_for(obj_last);
1287 if (obj_card_num != last_card_num) { 1284
1288 if (start_card_num == -1) { 1285 // Set the bits in the card BM for this object (inclusive).
1289 assert(last_card_num == -1, "Both or neither."); 1286 set_card_bitmap_range(start_idx, last_idx);
1290 start_card_num = obj_card_num; 1287
1291 } else { 1288 // Add the size of this object to the number of marked bytes.
1292 assert(last_card_num != -1, "Both or neither.");
1293 assert(obj_card_num >= last_card_num, "Inv");
1294 if ((obj_card_num - last_card_num) > 1) {
1295 // Mark the last run, and start a new one.
1296 mark_card_num_range(start_card_num, last_card_num);
1297 start_card_num = obj_card_num;
1298 }
1299 }
1300 }
1301 // In any case, we set the last card num.
1302 last_card_num = obj_last_card_num;
1303
1304 marked_bytes += (size_t)obj_sz * HeapWordSize; 1289 marked_bytes += (size_t)obj_sz * HeapWordSize;
1305 1290
1306 // Find the next marked object after this one. 1291 // Find the next marked object after this one.
1307 start = _bm->getNextMarkedWordAddress(start + 1, nextTop); 1292 start = _bm->getNextMarkedWordAddress(obj_last + 1, nextTop);
1308 }
1309
1310 // Handle the last range, if any.
1311 if (start_card_num != -1) {
1312 mark_card_num_range(start_card_num, last_card_num);
1313 } 1293 }
1314 1294
1315 // Mark the allocated-since-marking portion... 1295 // Mark the allocated-since-marking portion...
1316 HeapWord* top = hr->top(); 1296 HeapWord* top = hr->top();
1317 if (nextTop < top) { 1297 if (nextTop < top) {
1318 start_card_num = intptr_t(uintptr_t(nextTop) >> CardTableModRefBS::card_shift); 1298 BitMap::idx_t start_idx = _cm->card_bitmap_index_for(nextTop);
1319 last_card_num = intptr_t(uintptr_t(top) >> CardTableModRefBS::card_shift); 1299 BitMap::idx_t last_idx = _cm->card_bitmap_index_for(top - 1);
1320 1300
1321 mark_card_num_range(start_card_num, last_card_num); 1301 set_card_bitmap_range(start_idx, last_idx);
1322 1302
1323 // This definitely means the region has live objects. 1303 // This definitely means the region has live objects.
1324 set_bit_for_region(hr); 1304 set_bit_for_region(hr);
1325 } 1305 }
1326 1306
1392 assert(res == false, "should be continuing"); 1372 assert(res == false, "should be continuing");
1393 1373
1394 MutexLockerEx x((_verbose ? ParGCRareEvent_lock : NULL), 1374 MutexLockerEx x((_verbose ? ParGCRareEvent_lock : NULL),
1395 Mutex::_no_safepoint_check_flag); 1375 Mutex::_no_safepoint_check_flag);
1396 1376
1397 // Verify that _top_at_conc_count == ntams
1398 if (hr->top_at_conc_mark_count() != hr->next_top_at_mark_start()) {
1399 if (_verbose) {
1400 gclog_or_tty->print_cr("Region %u: top at conc count incorrect: "
1401 "expected " PTR_FORMAT ", actual: " PTR_FORMAT,
1402 hr->hrs_index(), hr->next_top_at_mark_start(),
1403 hr->top_at_conc_mark_count());
1404 }
1405 failures += 1;
1406 }
1407
1408 // Verify the marked bytes for this region. 1377 // Verify the marked bytes for this region.
1409 size_t exp_marked_bytes = _calc_cl.region_marked_bytes(); 1378 size_t exp_marked_bytes = _calc_cl.region_marked_bytes();
1410 size_t act_marked_bytes = hr->next_marked_bytes(); 1379 size_t act_marked_bytes = hr->next_marked_bytes();
1411 1380
1412 // We're not OK if expected marked bytes > actual marked bytes. It means 1381 // We're not OK if expected marked bytes > actual marked bytes. It means
1468 } 1437 }
1469 1438
1470 _failures += failures; 1439 _failures += failures;
1471 1440
1472 // We could stop iteration over the heap when we 1441 // We could stop iteration over the heap when we
1473 // find the first voilating region by returning true. 1442 // find the first violating region by returning true.
1474 return false; 1443 return false;
1475 } 1444 }
1476 }; 1445 };
1477 1446
1478 1447
1541 } 1510 }
1542 1511
1543 int failures() const { return _failures; } 1512 int failures() const { return _failures; }
1544 }; 1513 };
1545 1514
1546 // Final update of count data (during cleanup). 1515 // Closure that finalizes the liveness counting data.
1547 // Adds [top_at_count, NTAMS) to the marked bytes for each 1516 // Used during the cleanup pause.
1548 // region. Sets the bits in the card bitmap corresponding 1517 // Sets the bits corresponding to the interval [NTAMS, top]
1549 // to the interval [top_at_count, top], and sets the 1518 // (which contains the implicitly live objects) in the
1550 // liveness bit for each region containing live data 1519 // card liveness bitmap. Also sets the bit for each region,
1551 // in the region bitmap. 1520 // containing live data, in the region liveness bitmap.
1552 1521
1553 class FinalCountDataUpdateClosure: public HeapRegionClosure { 1522 class FinalCountDataUpdateClosure: public CMCountDataClosureBase {
1554 ConcurrentMark* _cm;
1555 BitMap* _region_bm;
1556 BitMap* _card_bm;
1557
1558 void set_card_bitmap_range(BitMap::idx_t start_idx, BitMap::idx_t last_idx) {
1559 assert(start_idx <= last_idx, "sanity");
1560
1561 // Set the inclusive bit range [start_idx, last_idx].
1562 // For small ranges (up to 8 cards) use a simple loop; otherwise
1563 // use par_at_put_range.
1564 if ((last_idx - start_idx) <= 8) {
1565 for (BitMap::idx_t i = start_idx; i <= last_idx; i += 1) {
1566 _card_bm->par_set_bit(i);
1567 }
1568 } else {
1569 assert(last_idx < _card_bm->size(), "sanity");
1570 // Note BitMap::par_at_put_range() is exclusive.
1571 _card_bm->par_at_put_range(start_idx, last_idx+1, true);
1572 }
1573 }
1574
1575 // It takes a region that's not empty (i.e., it has at least one
1576 // live object in it and sets its corresponding bit on the region
1577 // bitmap to 1. If the region is "starts humongous" it will also set
1578 // to 1 the bits on the region bitmap that correspond to its
1579 // associated "continues humongous" regions.
1580 void set_bit_for_region(HeapRegion* hr) {
1581 assert(!hr->continuesHumongous(), "should have filtered those out");
1582
1583 BitMap::idx_t index = (BitMap::idx_t) hr->hrs_index();
1584 if (!hr->startsHumongous()) {
1585 // Normal (non-humongous) case: just set the bit.
1586 _region_bm->par_set_bit(index);
1587 } else {
1588 // Starts humongous case: calculate how many regions are part of
1589 // this humongous region and then set the bit range.
1590 G1CollectedHeap* g1h = G1CollectedHeap::heap();
1591 HeapRegion *last_hr = g1h->heap_region_containing_raw(hr->end() - 1);
1592 BitMap::idx_t end_index = (BitMap::idx_t) last_hr->hrs_index() + 1;
1593 _region_bm->par_at_put_range(index, end_index, true);
1594 }
1595 }
1596
1597 public: 1523 public:
1598 FinalCountDataUpdateClosure(ConcurrentMark* cm, 1524 FinalCountDataUpdateClosure(ConcurrentMark* cm,
1599 BitMap* region_bm, 1525 BitMap* region_bm,
1600 BitMap* card_bm) : 1526 BitMap* card_bm) :
1601 _cm(cm), _region_bm(region_bm), _card_bm(card_bm) { } 1527 CMCountDataClosureBase(cm, region_bm, card_bm) { }
1602 1528
1603 bool doHeapRegion(HeapRegion* hr) { 1529 bool doHeapRegion(HeapRegion* hr) {
1604 1530
1605 if (hr->continuesHumongous()) { 1531 if (hr->continuesHumongous()) {
1606 // We will ignore these here and process them when their 1532 // We will ignore these here and process them when their
1611 // iteration, a "continues humongous" region might be visited 1537 // iteration, a "continues humongous" region might be visited
1612 // before its associated "starts humongous". 1538 // before its associated "starts humongous".
1613 return false; 1539 return false;
1614 } 1540 }
1615 1541
1616 HeapWord* start = hr->top_at_conc_mark_count();
1617 HeapWord* ntams = hr->next_top_at_mark_start(); 1542 HeapWord* ntams = hr->next_top_at_mark_start();
1618 HeapWord* top = hr->top(); 1543 HeapWord* top = hr->top();
1619 1544
1620 assert(hr->bottom() <= start && start <= hr->end() && 1545 assert(hr->bottom() <= ntams && ntams <= hr->end(), "Preconditions.");
1621 hr->bottom() <= ntams && ntams <= hr->end(), "Preconditions.");
1622
1623 if (start < ntams) {
1624 // Region was changed between remark and cleanup pauses
1625 // We need to add (ntams - start) to the marked bytes
1626 // for this region, and set bits for the range
1627 // [ card_idx(start), card_idx(ntams) ) in the card bitmap.
1628 size_t live_bytes = (ntams - start) * HeapWordSize;
1629 hr->add_to_marked_bytes(live_bytes);
1630
1631 // Record the new top at conc count
1632 hr->set_top_at_conc_mark_count(ntams);
1633
1634 // The setting of the bits in the card bitmap takes place below
1635 }
1636 1546
1637 // Mark the allocated-since-marking portion... 1547 // Mark the allocated-since-marking portion...
1638 if (ntams < top) { 1548 if (ntams < top) {
1639 // This definitely means the region has live objects. 1549 // This definitely means the region has live objects.
1640 set_bit_for_region(hr); 1550 set_bit_for_region(hr);
1641 } 1551 }
1642 1552
1643 // Now set the bits for [start, top] 1553 // Now set the bits for [ntams, top]
1644 BitMap::idx_t start_idx = _cm->card_bitmap_index_for(start); 1554 BitMap::idx_t start_idx = _cm->card_bitmap_index_for(ntams);
1645 BitMap::idx_t last_idx = _cm->card_bitmap_index_for(top); 1555 BitMap::idx_t last_idx = _cm->card_bitmap_index_for(top);
1646 set_card_bitmap_range(start_idx, last_idx); 1556 set_card_bitmap_range(start_idx, last_idx);
1647 1557
1648 // Set the bit for the region if it contains live data 1558 // Set the bit for the region if it contains live data
1649 if (hr->next_marked_bytes() > 0) { 1559 if (hr->next_marked_bytes() > 0) {
3069 } 2979 }
3070 } 2980 }
3071 2981
3072 // Update the marked bytes for this region. 2982 // Update the marked bytes for this region.
3073 hr->add_to_marked_bytes(marked_bytes); 2983 hr->add_to_marked_bytes(marked_bytes);
3074
3075 // Now set the top at count to NTAMS.
3076 hr->set_top_at_conc_mark_count(limit);
3077 2984
3078 // Next heap region 2985 // Next heap region
3079 return false; 2986 return false;
3080 } 2987 }
3081 }; 2988 };