comparison src/share/vm/gc_implementation/g1/g1CollectedHeap.hpp @ 20296:a3953c777565

8027959: Early reclamation of large objects in G1 Summary: Try to reclaim humongous objects at every young collection after doing a conservative estimate of its liveness. Reviewed-by: brutisso, mgerdin
author tschatzl
date Wed, 23 Jul 2014 09:03:32 +0200
parents 3f2894c5052e
children c3c9eee55fce
comparison
equal deleted inserted replaced
20295:3f2894c5052e 20296:a3953c777565
195 public: 195 public:
196 G1STWIsAliveClosure(G1CollectedHeap* g1) : _g1(g1) {} 196 G1STWIsAliveClosure(G1CollectedHeap* g1) : _g1(g1) {}
197 bool do_object_b(oop p); 197 bool do_object_b(oop p);
198 }; 198 };
199 199
200 // Instances of this class are used for quick tests on whether a reference points
201 // into the collection set. Each of the array's elements denotes whether the
202 // corresponding region is in the collection set.
203 class G1FastCSetBiasedMappedArray : public G1BiasedMappedArray<bool> {
204 protected:
205 bool default_value() const { return false; }
206 public:
207 void clear() { G1BiasedMappedArray<bool>::clear(); }
208 };
209
210 class RefineCardTableEntryClosure; 200 class RefineCardTableEntryClosure;
211 201
212 class G1CollectedHeap : public SharedHeap { 202 class G1CollectedHeap : public SharedHeap {
213 friend class VM_CollectForMetadataAllocation; 203 friend class VM_CollectForMetadataAllocation;
214 friend class VM_G1CollectForAllocation; 204 friend class VM_G1CollectForAllocation;
235 friend class RegionResetter; 225 friend class RegionResetter;
236 friend class CountRCClosure; 226 friend class CountRCClosure;
237 friend class EvacPopObjClosure; 227 friend class EvacPopObjClosure;
238 friend class G1ParCleanupCTTask; 228 friend class G1ParCleanupCTTask;
239 229
230 friend class G1FreeHumongousRegionClosure;
240 // Other related classes. 231 // Other related classes.
241 friend class G1MarkSweep; 232 friend class G1MarkSweep;
242 233
243 private: 234 private:
244 // The one and only G1CollectedHeap, so static functions can find it. 235 // The one and only G1CollectedHeap, so static functions can find it.
264 // It keeps track of the old regions. 255 // It keeps track of the old regions.
265 HeapRegionSet _old_set; 256 HeapRegionSet _old_set;
266 257
267 // It keeps track of the humongous regions. 258 // It keeps track of the humongous regions.
268 HeapRegionSet _humongous_set; 259 HeapRegionSet _humongous_set;
260
261 void clear_humongous_is_live_table();
262 void eagerly_reclaim_humongous_regions();
269 263
270 // The number of regions we could create by expansion. 264 // The number of regions we could create by expansion.
271 uint _expansion_regions; 265 uint _expansion_regions;
272 266
273 // The block offset table for the G1 heap. 267 // The block offset table for the G1 heap.
365 359
366 // Outside of GC pauses, the number of bytes used in all regions other 360 // Outside of GC pauses, the number of bytes used in all regions other
367 // than the current allocation region. 361 // than the current allocation region.
368 size_t _summary_bytes_used; 362 size_t _summary_bytes_used;
369 363
370 // This array is used for a quick test on whether a reference points into 364 // Records whether the region at the given index is kept live by roots or
371 // the collection set or not. Each of the array's elements denotes whether the 365 // references from the young generation.
372 // corresponding region is in the collection set or not. 366 class HumongousIsLiveBiasedMappedArray : public G1BiasedMappedArray<bool> {
373 G1FastCSetBiasedMappedArray _in_cset_fast_test; 367 protected:
368 bool default_value() const { return false; }
369 public:
370 void clear() { G1BiasedMappedArray<bool>::clear(); }
371 void set_live(uint region) {
372 set_by_index(region, true);
373 }
374 bool is_live(uint region) {
375 return get_by_index(region);
376 }
377 };
378
379 HumongousIsLiveBiasedMappedArray _humongous_is_live;
380 // Stores whether during humongous object registration we found candidate regions.
381 // If not, we can skip a few steps.
382 bool _has_humongous_reclaim_candidates;
374 383
375 volatile unsigned _gc_time_stamp; 384 volatile unsigned _gc_time_stamp;
376 385
377 size_t* _surviving_young_words; 386 size_t* _surviving_young_words;
378 387
688 697
689 // Do anything common to GC's. 698 // Do anything common to GC's.
690 virtual void gc_prologue(bool full); 699 virtual void gc_prologue(bool full);
691 virtual void gc_epilogue(bool full); 700 virtual void gc_epilogue(bool full);
692 701
702 inline void set_humongous_is_live(oop obj);
703
704 bool humongous_is_live(uint region) {
705 return _humongous_is_live.is_live(region);
706 }
707
708 // Returns whether the given region (which must be a humongous (start) region)
709 // is to be considered conservatively live regardless of any other conditions.
710 bool humongous_region_is_always_live(uint index);
711 // Register the given region to be part of the collection set.
712 inline void register_humongous_region_with_in_cset_fast_test(uint index);
713 // Register regions with humongous objects (actually on the start region) in
714 // the in_cset_fast_test table.
715 void register_humongous_regions_with_in_cset_fast_test();
693 // We register a region with the fast "in collection set" test. We 716 // We register a region with the fast "in collection set" test. We
694 // simply set to true the array slot corresponding to this region. 717 // simply set to true the array slot corresponding to this region.
695 void register_region_with_in_cset_fast_test(HeapRegion* r) { 718 void register_region_with_in_cset_fast_test(HeapRegion* r) {
696 _in_cset_fast_test.set_by_index(r->hrs_index(), true); 719 _in_cset_fast_test.set_in_cset(r->hrs_index());
697 } 720 }
698 721
699 // This is a fast test on whether a reference points into the 722 // This is a fast test on whether a reference points into the
700 // collection set or not. Assume that the reference 723 // collection set or not. Assume that the reference
701 // points into the heap. 724 // points into the heap.
1290 1313
1291 // Returns "TRUE" iff "p" points into the committed areas of the heap. 1314 // Returns "TRUE" iff "p" points into the committed areas of the heap.
1292 virtual bool is_in(const void* p) const; 1315 virtual bool is_in(const void* p) const;
1293 1316
1294 // Return "TRUE" iff the given object address is within the collection 1317 // Return "TRUE" iff the given object address is within the collection
1295 // set. 1318 // set. Slow implementation.
1296 inline bool obj_in_cs(oop obj); 1319 inline bool obj_in_cs(oop obj);
1320
1321 inline bool is_in_cset(oop obj);
1322
1323 inline bool is_in_cset_or_humongous(const oop obj);
1324
1325 enum in_cset_state_t {
1326 InNeither, // neither in collection set nor humongous
1327 InCSet, // region is in collection set only
1328 IsHumongous // region is a humongous start region
1329 };
1330 private:
1331 // Instances of this class are used for quick tests on whether a reference points
1332 // into the collection set or is a humongous object (points into a humongous
1333 // object).
1334 // Each of the array's elements denotes whether the corresponding region is in
1335 // the collection set or a humongous region.
1336 // We use this to quickly reclaim humongous objects: by making a humongous region
1337 // succeed this test, we sort-of add it to the collection set. During the reference
1338 // iteration closures, when we see a humongous region, we simply mark it as
1339 // referenced, i.e. live.
1340 class G1FastCSetBiasedMappedArray : public G1BiasedMappedArray<char> {
1341 protected:
1342 char default_value() const { return G1CollectedHeap::InNeither; }
1343 public:
1344 void set_humongous(uintptr_t index) {
1345 assert(get_by_index(index) != InCSet, "Should not overwrite InCSet values");
1346 set_by_index(index, G1CollectedHeap::IsHumongous);
1347 }
1348
1349 void clear_humongous(uintptr_t index) {
1350 set_by_index(index, G1CollectedHeap::InNeither);
1351 }
1352
1353 void set_in_cset(uintptr_t index) {
1354 assert(get_by_index(index) != G1CollectedHeap::IsHumongous, "Should not overwrite IsHumongous value");
1355 set_by_index(index, G1CollectedHeap::InCSet);
1356 }
1357
1358 bool is_in_cset_or_humongous(HeapWord* addr) const { return get_by_address(addr) != G1CollectedHeap::InNeither; }
1359 bool is_in_cset(HeapWord* addr) const { return get_by_address(addr) == G1CollectedHeap::InCSet; }
1360 G1CollectedHeap::in_cset_state_t at(HeapWord* addr) const { return (G1CollectedHeap::in_cset_state_t)get_by_address(addr); }
1361 void clear() { G1BiasedMappedArray<char>::clear(); }
1362 };
1363
1364 // This array is used for a quick test on whether a reference points into
1365 // the collection set or not. Each of the array's elements denotes whether the
1366 // corresponding region is in the collection set or not.
1367 G1FastCSetBiasedMappedArray _in_cset_fast_test;
1368
1369 public:
1370
1371 inline in_cset_state_t in_cset_state(const oop obj);
1297 1372
1298 // Return "TRUE" iff the given object address is in the reserved 1373 // Return "TRUE" iff the given object address is in the reserved
1299 // region of g1. 1374 // region of g1.
1300 bool is_in_g1_reserved(const void* p) const { 1375 bool is_in_g1_reserved(const void* p) const {
1301 return _g1_reserved.contains(p); 1376 return _g1_reserved.contains(p);
1346 // iteration early if the "doHeapRegion" method returns "true". 1421 // iteration early if the "doHeapRegion" method returns "true".
1347 void heap_region_iterate(HeapRegionClosure* blk) const; 1422 void heap_region_iterate(HeapRegionClosure* blk) const;
1348 1423
1349 // Return the region with the given index. It assumes the index is valid. 1424 // Return the region with the given index. It assumes the index is valid.
1350 inline HeapRegion* region_at(uint index) const; 1425 inline HeapRegion* region_at(uint index) const;
1426
1427 // Calculate the region index of the given address. Given address must be
1428 // within the heap.
1429 inline uint addr_to_region(HeapWord* addr) const;
1351 1430
1352 // Divide the heap region sequence into "chunks" of some size (the number 1431 // Divide the heap region sequence into "chunks" of some size (the number
1353 // of regions divided by the number of parallel threads times some 1432 // of regions divided by the number of parallel threads times some
1354 // overpartition factor, currently 4). Assumes that this will be called 1433 // overpartition factor, currently 4). Assumes that this will be called
1355 // in parallel by ParallelGCThreads worker threads with discinct worker 1434 // in parallel by ParallelGCThreads worker threads with discinct worker