comparison src/share/vm/gc_implementation/g1/g1CollectedHeap.hpp @ 20305:755930f931e3

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 a22acf6d7598
children a08bb8e45ba1
comparison
equal deleted inserted replaced
20304:a22acf6d7598 20305:755930f931e3
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.
1266 1289
1267 // Returns "TRUE" iff "p" points into the committed areas of the heap. 1290 // Returns "TRUE" iff "p" points into the committed areas of the heap.
1268 virtual bool is_in(const void* p) const; 1291 virtual bool is_in(const void* p) const;
1269 1292
1270 // Return "TRUE" iff the given object address is within the collection 1293 // Return "TRUE" iff the given object address is within the collection
1271 // set. 1294 // set. Slow implementation.
1272 inline bool obj_in_cs(oop obj); 1295 inline bool obj_in_cs(oop obj);
1296
1297 inline bool is_in_cset(oop obj);
1298
1299 inline bool is_in_cset_or_humongous(const oop obj);
1300
1301 enum in_cset_state_t {
1302 InNeither, // neither in collection set nor humongous
1303 InCSet, // region is in collection set only
1304 IsHumongous // region is a humongous start region
1305 };
1306 private:
1307 // Instances of this class are used for quick tests on whether a reference points
1308 // into the collection set or is a humongous object (points into a humongous
1309 // object).
1310 // Each of the array's elements denotes whether the corresponding region is in
1311 // the collection set or a humongous region.
1312 // We use this to quickly reclaim humongous objects: by making a humongous region
1313 // succeed this test, we sort-of add it to the collection set. During the reference
1314 // iteration closures, when we see a humongous region, we simply mark it as
1315 // referenced, i.e. live.
1316 class G1FastCSetBiasedMappedArray : public G1BiasedMappedArray<char> {
1317 protected:
1318 char default_value() const { return G1CollectedHeap::InNeither; }
1319 public:
1320 void set_humongous(uintptr_t index) {
1321 assert(get_by_index(index) != InCSet, "Should not overwrite InCSet values");
1322 set_by_index(index, G1CollectedHeap::IsHumongous);
1323 }
1324
1325 void clear_humongous(uintptr_t index) {
1326 set_by_index(index, G1CollectedHeap::InNeither);
1327 }
1328
1329 void set_in_cset(uintptr_t index) {
1330 assert(get_by_index(index) != G1CollectedHeap::IsHumongous, "Should not overwrite IsHumongous value");
1331 set_by_index(index, G1CollectedHeap::InCSet);
1332 }
1333
1334 bool is_in_cset_or_humongous(HeapWord* addr) const { return get_by_address(addr) != G1CollectedHeap::InNeither; }
1335 bool is_in_cset(HeapWord* addr) const { return get_by_address(addr) == G1CollectedHeap::InCSet; }
1336 G1CollectedHeap::in_cset_state_t at(HeapWord* addr) const { return (G1CollectedHeap::in_cset_state_t)get_by_address(addr); }
1337 void clear() { G1BiasedMappedArray<char>::clear(); }
1338 };
1339
1340 // This array is used for a quick test on whether a reference points into
1341 // the collection set or not. Each of the array's elements denotes whether the
1342 // corresponding region is in the collection set or not.
1343 G1FastCSetBiasedMappedArray _in_cset_fast_test;
1344
1345 public:
1346
1347 inline in_cset_state_t in_cset_state(const oop obj);
1273 1348
1274 // Return "TRUE" iff the given object address is in the reserved 1349 // Return "TRUE" iff the given object address is in the reserved
1275 // region of g1. 1350 // region of g1.
1276 bool is_in_g1_reserved(const void* p) const { 1351 bool is_in_g1_reserved(const void* p) const {
1277 return _g1_reserved.contains(p); 1352 return _g1_reserved.contains(p);
1322 // iteration early if the "doHeapRegion" method returns "true". 1397 // iteration early if the "doHeapRegion" method returns "true".
1323 void heap_region_iterate(HeapRegionClosure* blk) const; 1398 void heap_region_iterate(HeapRegionClosure* blk) const;
1324 1399
1325 // Return the region with the given index. It assumes the index is valid. 1400 // Return the region with the given index. It assumes the index is valid.
1326 inline HeapRegion* region_at(uint index) const; 1401 inline HeapRegion* region_at(uint index) const;
1402
1403 // Calculate the region index of the given address. Given address must be
1404 // within the heap.
1405 inline uint addr_to_region(HeapWord* addr) const;
1327 1406
1328 // Divide the heap region sequence into "chunks" of some size (the number 1407 // Divide the heap region sequence into "chunks" of some size (the number
1329 // of regions divided by the number of parallel threads times some 1408 // of regions divided by the number of parallel threads times some
1330 // overpartition factor, currently 4). Assumes that this will be called 1409 // overpartition factor, currently 4). Assumes that this will be called
1331 // in parallel by ParallelGCThreads worker threads with discinct worker 1410 // in parallel by ParallelGCThreads worker threads with discinct worker