< prev index next >

src/hotspot/share/gc/g1/g1RemSet.cpp

Print this page




1244   G1GCPhaseTimes* phase_times = _g1h->phase_times();
1245 
1246   // Set all cards back to clean.
1247   double start = os::elapsedTime();
1248   _scan_state->cleanup(_g1h->workers());
1249   phase_times->record_clear_ct_time((os::elapsedTime() - start) * 1000.0);
1250 }
1251 
1252 inline void check_card_ptr(CardTable::CardValue* card_ptr, G1CardTable* ct) {
1253 #ifdef ASSERT
1254   G1CollectedHeap* g1h = G1CollectedHeap::heap();
1255   assert(g1h->is_in_exact(ct->addr_for(card_ptr)),
1256          "Card at " PTR_FORMAT " index " SIZE_FORMAT " representing heap at " PTR_FORMAT " (%u) must be in committed heap",
1257          p2i(card_ptr),
1258          ct->index_for(ct->addr_for(card_ptr)),
1259          p2i(ct->addr_for(card_ptr)),
1260          g1h->addr_to_region(ct->addr_for(card_ptr)));
1261 #endif
1262 }
1263 
1264 bool G1RemSet::clean_card_before_refine(CardValue*& card_ptr) {

1265   assert(!_g1h->is_gc_active(), "Only call concurrently");
1266 
1267   // Find the start address represented by the card.
1268   HeapWord* start = _ct->addr_for(card_ptr);
1269   // And find the region containing it.
1270   HeapRegion* r = _g1h->heap_region_containing_or_null(start);
1271 
1272   // If this is a (stale) card into an uncommitted region, exit.
1273   if (r == NULL) {
1274     return false;
1275   }
1276 
1277   check_card_ptr(card_ptr, _ct);
1278 
1279   // If the card is no longer dirty, nothing to do.


1280   if (*card_ptr != G1CardTable::dirty_card_val()) {
1281     return false;
1282   }
1283 
1284   // This check is needed for some uncommon cases where we should
1285   // ignore the card.
1286   //
1287   // The region could be young.  Cards for young regions are
1288   // distinctly marked (set to g1_young_gen), so the post-barrier will
1289   // filter them out.  However, that marking is performed
1290   // concurrently.  A write to a young object could occur before the
1291   // card has been marked young, slipping past the filter.
1292   //
1293   // The card could be stale, because the region has been freed since
1294   // the card was recorded. In this case the region type could be
1295   // anything.  If (still) free or (reallocated) young, just ignore
1296   // it.  If (reallocated) old or humongous, the later card trimming
1297   // and additional checks in iteration may detect staleness.  At
1298   // worst, we end up processing a stale card unnecessarily.
1299   //


1342 
1343   // Non-humongous objects are only allocated in the old-gen during
1344   // GC, so if region is old then top is stable.  Humongous object
1345   // allocation sets top last; if top has not yet been set, this is
1346   // a stale card and we'll end up with an empty intersection.  If
1347   // this is not a stale card, the synchronization between the
1348   // enqueuing of the card and processing it here will have ensured
1349   // we see the up-to-date top here.
1350   HeapWord* scan_limit = r->top();
1351 
1352   if (scan_limit <= start) {
1353     // If the trimmed region is empty, the card must be stale.
1354     return false;
1355   }
1356 
1357   // Okay to clean and process the card now.  There are still some
1358   // stale card cases that may be detected by iteration and dealt with
1359   // as iteration failure.
1360   *const_cast<volatile CardValue*>(card_ptr) = G1CardTable::clean_card_val();
1361 









1362   return true;
1363 }
1364 
1365 void G1RemSet::refine_card_concurrently(CardValue* const card_ptr,
1366                                         const uint worker_id) {

1367   assert(!_g1h->is_gc_active(), "Only call concurrently");
1368   check_card_ptr(card_ptr, _ct);
1369 
1370   // Construct the MemRegion representing the card.
1371   HeapWord* start = _ct->addr_for(card_ptr);
1372   // And find the region containing it.
1373   HeapRegion* r = _g1h->heap_region_containing(start);



1374   HeapWord* scan_limit = r->top();
1375   // top() can only increase since last read of top() before cleaning the card.
1376   assert(scan_limit > start, "sanity");
1377 
1378   // Don't use addr_for(card_ptr + 1) which can ask for
1379   // a card beyond the heap.
1380   HeapWord* end = start + G1CardTable::card_size_in_words;
1381   MemRegion dirty_region(start, MIN2(scan_limit, end));
1382   assert(!dirty_region.is_empty(), "sanity");
1383 
1384   G1ConcurrentRefineOopClosure conc_refine_cl(_g1h, worker_id);
1385   if (r->oops_on_memregion_seq_iterate_careful<false>(dirty_region, &conc_refine_cl) != NULL) {
1386     return;
1387   }
1388 
1389   // If unable to process the card then we encountered an unparsable
1390   // part of the heap (e.g. a partially allocated object, so only
1391   // temporarily a problem) while processing a stale card.  Despite
1392   // the card being stale, we can't simply ignore it, because we've
1393   // already marked the card cleaned, so taken responsibility for
1394   // ensuring the card gets scanned.
1395   //
1396   // However, the card might have gotten re-dirtied and re-enqueued




1244   G1GCPhaseTimes* phase_times = _g1h->phase_times();
1245 
1246   // Set all cards back to clean.
1247   double start = os::elapsedTime();
1248   _scan_state->cleanup(_g1h->workers());
1249   phase_times->record_clear_ct_time((os::elapsedTime() - start) * 1000.0);
1250 }
1251 
1252 inline void check_card_ptr(CardTable::CardValue* card_ptr, G1CardTable* ct) {
1253 #ifdef ASSERT
1254   G1CollectedHeap* g1h = G1CollectedHeap::heap();
1255   assert(g1h->is_in_exact(ct->addr_for(card_ptr)),
1256          "Card at " PTR_FORMAT " index " SIZE_FORMAT " representing heap at " PTR_FORMAT " (%u) must be in committed heap",
1257          p2i(card_ptr),
1258          ct->index_for(ct->addr_for(card_ptr)),
1259          p2i(ct->addr_for(card_ptr)),
1260          g1h->addr_to_region(ct->addr_for(card_ptr)));
1261 #endif
1262 }
1263 
1264 bool G1RemSet::clean_card_before_refine(CardValue*& card_ptr
1265                                         DEBUG_ONLY(COMMA KVHashtable<CardTable::CardValue* COMMA HeapWord* COMMA mtGC>& top_map)) {
1266   assert(!_g1h->is_gc_active(), "Only call concurrently");
1267 
1268   // Find the start address represented by the card.
1269   HeapWord* start = _ct->addr_for(card_ptr);
1270   // And find the region containing it.
1271   HeapRegion* r = _g1h->heap_region_containing_or_null(start);
1272 
1273   // If this is a (stale) card into an uncommitted region, exit.
1274   if (r == NULL) {
1275     return false;
1276   }
1277 
1278   check_card_ptr(card_ptr, _ct);
1279 
1280   // If the card is no longer dirty, nothing to do.
1281   // We cannot load the card value before the "r == NULL" check, because G1
1282   // could uncommit parts of the card table covering uncommitted regions.
1283   if (*card_ptr != G1CardTable::dirty_card_val()) {
1284     return false;
1285   }
1286 
1287   // This check is needed for some uncommon cases where we should
1288   // ignore the card.
1289   //
1290   // The region could be young.  Cards for young regions are
1291   // distinctly marked (set to g1_young_gen), so the post-barrier will
1292   // filter them out.  However, that marking is performed
1293   // concurrently.  A write to a young object could occur before the
1294   // card has been marked young, slipping past the filter.
1295   //
1296   // The card could be stale, because the region has been freed since
1297   // the card was recorded. In this case the region type could be
1298   // anything.  If (still) free or (reallocated) young, just ignore
1299   // it.  If (reallocated) old or humongous, the later card trimming
1300   // and additional checks in iteration may detect staleness.  At
1301   // worst, we end up processing a stale card unnecessarily.
1302   //


1345 
1346   // Non-humongous objects are only allocated in the old-gen during
1347   // GC, so if region is old then top is stable.  Humongous object
1348   // allocation sets top last; if top has not yet been set, this is
1349   // a stale card and we'll end up with an empty intersection.  If
1350   // this is not a stale card, the synchronization between the
1351   // enqueuing of the card and processing it here will have ensured
1352   // we see the up-to-date top here.
1353   HeapWord* scan_limit = r->top();
1354 
1355   if (scan_limit <= start) {
1356     // If the trimmed region is empty, the card must be stale.
1357     return false;
1358   }
1359 
1360   // Okay to clean and process the card now.  There are still some
1361   // stale card cases that may be detected by iteration and dealt with
1362   // as iteration failure.
1363   *const_cast<volatile CardValue*>(card_ptr) = G1CardTable::clean_card_val();
1364 
1365 #ifdef ASSERT
1366   HeapWord** existing_top = top_map.lookup(card_ptr);
1367   if (existing_top != NULL) {
1368     assert(scan_limit == *existing_top, "top must be stable");
1369   } else {
1370     top_map.add(card_ptr, scan_limit);
1371   }
1372 #endif
1373 
1374   return true;
1375 }
1376 
1377 void G1RemSet::refine_card_concurrently(CardValue* const card_ptr,
1378                                         const uint worker_id
1379                                         DEBUG_ONLY(COMMA KVHashtable<CardTable::CardValue* COMMA HeapWord* COMMA mtGC>& top_map)) {
1380   assert(!_g1h->is_gc_active(), "Only call concurrently");
1381   check_card_ptr(card_ptr, _ct);
1382 
1383   // Construct the MemRegion representing the card.
1384   HeapWord* start = _ct->addr_for(card_ptr);
1385   // And find the region containing it.
1386   HeapRegion* r = _g1h->heap_region_containing(start);
1387   // This reload of the top is safe even though it happens after the full
1388   // fence, because top is stable for unfiltered humongous regions, so it must
1389   // return the same value as the previous load when cleaning the card.
1390   HeapWord* scan_limit = r->top();
1391   assert(scan_limit == *top_map.lookup(card_ptr), "top must be stable");

1392 
1393   // Don't use addr_for(card_ptr + 1) which can ask for
1394   // a card beyond the heap.
1395   HeapWord* end = start + G1CardTable::card_size_in_words;
1396   MemRegion dirty_region(start, MIN2(scan_limit, end));
1397   assert(!dirty_region.is_empty(), "sanity");
1398 
1399   G1ConcurrentRefineOopClosure conc_refine_cl(_g1h, worker_id);
1400   if (r->oops_on_memregion_seq_iterate_careful<false>(dirty_region, &conc_refine_cl) != NULL) {
1401     return;
1402   }
1403 
1404   // If unable to process the card then we encountered an unparsable
1405   // part of the heap (e.g. a partially allocated object, so only
1406   // temporarily a problem) while processing a stale card.  Despite
1407   // the card being stale, we can't simply ignore it, because we've
1408   // already marked the card cleaned, so taken responsibility for
1409   // ensuring the card gets scanned.
1410   //
1411   // However, the card might have gotten re-dirtied and re-enqueued


< prev index next >