1259 p2i(ct->addr_for(card_ptr)), |
1259 p2i(ct->addr_for(card_ptr)), |
1260 g1h->addr_to_region(ct->addr_for(card_ptr))); |
1260 g1h->addr_to_region(ct->addr_for(card_ptr))); |
1261 #endif |
1261 #endif |
1262 } |
1262 } |
1263 |
1263 |
1264 void G1RemSet::refine_card_concurrently(CardValue* card_ptr, |
1264 bool G1RemSet::clean_card_before_refine(CardValue** const card_ptr_addr) { |
1265 uint worker_id) { |
|
1266 assert(!_g1h->is_gc_active(), "Only call concurrently"); |
1265 assert(!_g1h->is_gc_active(), "Only call concurrently"); |
1267 |
1266 |
1268 // Construct the region representing the card. |
1267 CardValue* card_ptr = *card_ptr_addr; |
|
1268 // Find the start address represented by the card. |
1269 HeapWord* start = _ct->addr_for(card_ptr); |
1269 HeapWord* start = _ct->addr_for(card_ptr); |
1270 // And find the region containing it. |
1270 // And find the region containing it. |
1271 HeapRegion* r = _g1h->heap_region_containing_or_null(start); |
1271 HeapRegion* r = _g1h->heap_region_containing_or_null(start); |
1272 |
1272 |
1273 // If this is a (stale) card into an uncommitted region, exit. |
1273 // If this is a (stale) card into an uncommitted region, exit. |
1274 if (r == NULL) { |
1274 if (r == NULL) { |
1275 return; |
1275 return false; |
1276 } |
1276 } |
1277 |
1277 |
1278 check_card_ptr(card_ptr, _ct); |
1278 check_card_ptr(card_ptr, _ct); |
1279 |
1279 |
1280 // If the card is no longer dirty, nothing to do. |
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. |
1281 if (*card_ptr != G1CardTable::dirty_card_val()) { |
1283 if (*card_ptr != G1CardTable::dirty_card_val()) { |
1282 return; |
1284 return false; |
1283 } |
1285 } |
1284 |
1286 |
1285 // This check is needed for some uncommon cases where we should |
1287 // This check is needed for some uncommon cases where we should |
1286 // ignore the card. |
1288 // ignore the card. |
1287 // |
1289 // |
1319 |
1321 |
1320 const CardValue* orig_card_ptr = card_ptr; |
1322 const CardValue* orig_card_ptr = card_ptr; |
1321 card_ptr = _hot_card_cache->insert(card_ptr); |
1323 card_ptr = _hot_card_cache->insert(card_ptr); |
1322 if (card_ptr == NULL) { |
1324 if (card_ptr == NULL) { |
1323 // There was no eviction. Nothing to do. |
1325 // There was no eviction. Nothing to do. |
1324 return; |
1326 return false; |
1325 } else if (card_ptr != orig_card_ptr) { |
1327 } else if (card_ptr != orig_card_ptr) { |
1326 // Original card was inserted and an old card was evicted. |
1328 // Original card was inserted and an old card was evicted. |
1327 start = _ct->addr_for(card_ptr); |
1329 start = _ct->addr_for(card_ptr); |
1328 r = _g1h->heap_region_containing(start); |
1330 r = _g1h->heap_region_containing(start); |
1329 |
1331 |
1330 // Check whether the region formerly in the cache should be |
1332 // Check whether the region formerly in the cache should be |
1331 // ignored, as discussed earlier for the original card. The |
1333 // ignored, as discussed earlier for the original card. The |
1332 // region could have been freed while in the cache. |
1334 // region could have been freed while in the cache. |
1333 if (!r->is_old_or_humongous_or_archive()) { |
1335 if (!r->is_old_or_humongous_or_archive()) { |
1334 return; |
1336 return false; |
1335 } |
1337 } |
|
1338 *card_ptr_addr = card_ptr; |
1336 } // Else we still have the original card. |
1339 } // Else we still have the original card. |
1337 } |
1340 } |
1338 |
1341 |
1339 // Trim the region designated by the card to what's been allocated |
1342 // Trim the region designated by the card to what's been allocated |
1340 // in the region. The card could be stale, or the card could cover |
1343 // in the region. The card could be stale, or the card could cover |
1341 // (part of) an object at the end of the allocated space and extend |
1344 // (part of) an object at the end of the allocated space and extend |
1342 // beyond the end of allocation. |
1345 // beyond the end of allocation. |
1343 |
1346 |
1344 // Non-humongous objects are only allocated in the old-gen during |
1347 // Non-humongous objects are either allocated in the old regions during GC, |
1345 // GC, so if region is old then top is stable. Humongous object |
1348 // or mapped in archive regions during startup. So if region is old or |
1346 // allocation sets top last; if top has not yet been set, this is |
1349 // archive then top is stable. |
1347 // a stale card and we'll end up with an empty intersection. If |
1350 // Humongous object allocation sets top last; if top has not yet been set, |
1348 // this is not a stale card, the synchronization between the |
1351 // this is a stale card and we'll end up with an empty intersection. |
|
1352 // If this is not a stale card, the synchronization between the |
1349 // enqueuing of the card and processing it here will have ensured |
1353 // enqueuing of the card and processing it here will have ensured |
1350 // we see the up-to-date top here. |
1354 // we see the up-to-date top here. |
1351 HeapWord* scan_limit = r->top(); |
1355 HeapWord* scan_limit = r->top(); |
1352 |
1356 |
1353 if (scan_limit <= start) { |
1357 if (scan_limit <= start) { |
1354 // If the trimmed region is empty, the card must be stale. |
1358 // If the trimmed region is empty, the card must be stale. |
1355 return; |
1359 return false; |
1356 } |
1360 } |
1357 |
1361 |
1358 // Okay to clean and process the card now. There are still some |
1362 // Okay to clean and process the card now. There are still some |
1359 // stale card cases that may be detected by iteration and dealt with |
1363 // stale card cases that may be detected by iteration and dealt with |
1360 // as iteration failure. |
1364 // as iteration failure. |
1361 *const_cast<volatile CardValue*>(card_ptr) = G1CardTable::clean_card_val(); |
1365 *const_cast<volatile CardValue*>(card_ptr) = G1CardTable::clean_card_val(); |
1362 |
1366 |
1363 // This fence serves two purposes. First, the card must be cleaned |
1367 return true; |
1364 // before processing the contents. Second, we can't proceed with |
1368 } |
1365 // processing until after the read of top, for synchronization with |
1369 |
1366 // possibly concurrent humongous object allocation. It's okay that |
1370 void G1RemSet::refine_card_concurrently(CardValue* const card_ptr, |
1367 // reading top and reading type were racy wrto each other. We need |
1371 const uint worker_id) { |
1368 // both set, in any order, to proceed. |
1372 assert(!_g1h->is_gc_active(), "Only call concurrently"); |
1369 OrderAccess::fence(); |
1373 check_card_ptr(card_ptr, _ct); |
|
1374 |
|
1375 // Construct the MemRegion representing the card. |
|
1376 HeapWord* start = _ct->addr_for(card_ptr); |
|
1377 // And find the region containing it. |
|
1378 HeapRegion* r = _g1h->heap_region_containing(start); |
|
1379 // This reload of the top is safe even though it happens after the full |
|
1380 // fence, because top is stable for old, archive and unfiltered humongous |
|
1381 // regions, so it must return the same value as the previous load when |
|
1382 // cleaning the card. Also cleaning the card and refinement of the card |
|
1383 // cannot span across safepoint, so we don't need to worry about top being |
|
1384 // changed during safepoint. |
|
1385 HeapWord* scan_limit = r->top(); |
|
1386 assert(scan_limit > start, "sanity"); |
1370 |
1387 |
1371 // Don't use addr_for(card_ptr + 1) which can ask for |
1388 // Don't use addr_for(card_ptr + 1) which can ask for |
1372 // a card beyond the heap. |
1389 // a card beyond the heap. |
1373 HeapWord* end = start + G1CardTable::card_size_in_words; |
1390 HeapWord* end = start + G1CardTable::card_size_in_words; |
1374 MemRegion dirty_region(start, MIN2(scan_limit, end)); |
1391 MemRegion dirty_region(start, MIN2(scan_limit, end)); |