comparison src/share/vm/gc_implementation/g1/g1CollectedHeap.hpp @ 7601:5cdbde3a9a57

8060025: Object copy time regressions after JDK-8031323 and JDK-8057536 Summary: Evaluate and improve object copy time by micro-optimizations and splitting out slow and fast paths aggressively. Reviewed-by: kbarrett, mgerdin, jmasa Contributed-by: Tony Printezis <tprintezis@twitter.com>, Thomas Schatzl <thomas.schatzl@oracle.com>
author tschatzl
date Fri, 19 Dec 2014 09:21:06 +0100
parents 6aa9ea790814
children 3f138457d7e6
comparison
equal deleted inserted replaced
169:8938f9c2bb3f 170:3b2f137e5448
30 #include "gc_implementation/g1/concurrentMark.hpp" 30 #include "gc_implementation/g1/concurrentMark.hpp"
31 #include "gc_implementation/g1/evacuationInfo.hpp" 31 #include "gc_implementation/g1/evacuationInfo.hpp"
32 #include "gc_implementation/g1/g1AllocRegion.hpp" 32 #include "gc_implementation/g1/g1AllocRegion.hpp"
33 #include "gc_implementation/g1/g1BiasedArray.hpp" 33 #include "gc_implementation/g1/g1BiasedArray.hpp"
34 #include "gc_implementation/g1/g1HRPrinter.hpp" 34 #include "gc_implementation/g1/g1HRPrinter.hpp"
35 #include "gc_implementation/g1/g1InCSetState.hpp"
35 #include "gc_implementation/g1/g1MonitoringSupport.hpp" 36 #include "gc_implementation/g1/g1MonitoringSupport.hpp"
36 #include "gc_implementation/g1/g1SATBCardTableModRefBS.hpp" 37 #include "gc_implementation/g1/g1SATBCardTableModRefBS.hpp"
37 #include "gc_implementation/g1/g1YCTypes.hpp" 38 #include "gc_implementation/g1/g1YCTypes.hpp"
38 #include "gc_implementation/g1/heapRegionManager.hpp" 39 #include "gc_implementation/g1/heapRegionManager.hpp"
39 #include "gc_implementation/g1/heapRegionSet.hpp" 40 #include "gc_implementation/g1/heapRegionSet.hpp"
545 546
546 // Allocate blocks during garbage collection. Will ensure an 547 // Allocate blocks during garbage collection. Will ensure an
547 // allocation region, either by picking one or expanding the 548 // allocation region, either by picking one or expanding the
548 // heap, and then allocate a block of the given size. The block 549 // heap, and then allocate a block of the given size. The block
549 // may not be a humongous - it must fit into a single heap region. 550 // may not be a humongous - it must fit into a single heap region.
550 HeapWord* par_allocate_during_gc(GCAllocPurpose purpose, 551 inline HeapWord* par_allocate_during_gc(InCSetState dest,
551 size_t word_size, 552 size_t word_size,
552 AllocationContext_t context); 553 AllocationContext_t context);
553
554 HeapWord* allocate_during_gc_slow(GCAllocPurpose purpose,
555 HeapRegion* alloc_region,
556 bool par,
557 size_t word_size);
558
559 // Ensure that no further allocations can happen in "r", bearing in mind 554 // Ensure that no further allocations can happen in "r", bearing in mind
560 // that parallel threads might be attempting allocations. 555 // that parallel threads might be attempting allocations.
561 void par_allocate_remaining_space(HeapRegion* r); 556 void par_allocate_remaining_space(HeapRegion* r);
562 557
563 // Allocation attempt during GC for a survivor object / PLAB. 558 // Allocation attempt during GC for a survivor object / PLAB.
575 void retire_mutator_alloc_region(HeapRegion* alloc_region, 570 void retire_mutator_alloc_region(HeapRegion* alloc_region,
576 size_t allocated_bytes); 571 size_t allocated_bytes);
577 572
578 // For GC alloc regions. 573 // For GC alloc regions.
579 HeapRegion* new_gc_alloc_region(size_t word_size, uint count, 574 HeapRegion* new_gc_alloc_region(size_t word_size, uint count,
580 GCAllocPurpose ap); 575 InCSetState dest);
581 void retire_gc_alloc_region(HeapRegion* alloc_region, 576 void retire_gc_alloc_region(HeapRegion* alloc_region,
582 size_t allocated_bytes, GCAllocPurpose ap); 577 size_t allocated_bytes, InCSetState dest);
583 578
584 // - if explicit_gc is true, the GC is for a System.gc() or a heap 579 // - if explicit_gc is true, the GC is for a System.gc() or a heap
585 // inspection request and should collect the entire heap 580 // inspection request and should collect the entire heap
586 // - if clear_all_soft_refs is true, all soft references should be 581 // - if clear_all_soft_refs is true, all soft references should be
587 // cleared during the GC 582 // cleared during the GC
638 // Returns true if the heap was expanded by the requested amount; 633 // Returns true if the heap was expanded by the requested amount;
639 // false otherwise. 634 // false otherwise.
640 // (Rounds up to a HeapRegion boundary.) 635 // (Rounds up to a HeapRegion boundary.)
641 bool expand(size_t expand_bytes); 636 bool expand(size_t expand_bytes);
642 637
643 // Returns the PLAB statistics given a purpose. 638 // Returns the PLAB statistics for a given destination.
644 PLABStats* stats_for_purpose(GCAllocPurpose purpose) { 639 inline PLABStats* alloc_buffer_stats(InCSetState dest);
645 PLABStats* stats = NULL; 640
646 641 // Determines PLAB size for a given destination.
647 switch (purpose) { 642 inline size_t desired_plab_sz(InCSetState dest);
648 case GCAllocForSurvived:
649 stats = &_survivor_plab_stats;
650 break;
651 case GCAllocForTenured:
652 stats = &_old_plab_stats;
653 break;
654 default:
655 assert(false, "unrecognized GCAllocPurpose");
656 }
657
658 return stats;
659 }
660
661 // Determines PLAB size for a particular allocation purpose.
662 size_t desired_plab_sz(GCAllocPurpose purpose);
663 643
664 inline AllocationContextStats& allocation_context_stats(); 644 inline AllocationContextStats& allocation_context_stats();
665 645
666 // Do anything common to GC's. 646 // Do anything common to GC's.
667 virtual void gc_prologue(bool full); 647 virtual void gc_prologue(bool full);
681 // Register regions with humongous objects (actually on the start region) in 661 // Register regions with humongous objects (actually on the start region) in
682 // the in_cset_fast_test table. 662 // the in_cset_fast_test table.
683 void register_humongous_regions_with_in_cset_fast_test(); 663 void register_humongous_regions_with_in_cset_fast_test();
684 // We register a region with the fast "in collection set" test. We 664 // We register a region with the fast "in collection set" test. We
685 // simply set to true the array slot corresponding to this region. 665 // simply set to true the array slot corresponding to this region.
686 void register_region_with_in_cset_fast_test(HeapRegion* r) { 666 void register_young_region_with_in_cset_fast_test(HeapRegion* r) {
687 _in_cset_fast_test.set_in_cset(r->hrm_index()); 667 _in_cset_fast_test.set_in_young(r->hrm_index());
668 }
669 void register_old_region_with_in_cset_fast_test(HeapRegion* r) {
670 _in_cset_fast_test.set_in_old(r->hrm_index());
688 } 671 }
689 672
690 // This is a fast test on whether a reference points into the 673 // This is a fast test on whether a reference points into the
691 // collection set or not. Assume that the reference 674 // collection set or not. Assume that the reference
692 // points into the heap. 675 // points into the heap.
1179 // If G1VerifyBitmaps is set, verify that the marking bitmaps do not 1162 // If G1VerifyBitmaps is set, verify that the marking bitmaps do not
1180 // have any spurious marks. If errors are detected, print 1163 // have any spurious marks. If errors are detected, print
1181 // appropriate error messages and crash. 1164 // appropriate error messages and crash.
1182 void check_bitmaps(const char* caller) PRODUCT_RETURN; 1165 void check_bitmaps(const char* caller) PRODUCT_RETURN;
1183 1166
1167 // Do sanity check on the contents of the in-cset fast test table.
1168 bool check_cset_fast_test() PRODUCT_RETURN_( return true; );
1169
1184 // verify_region_sets() performs verification over the region 1170 // verify_region_sets() performs verification over the region
1185 // lists. It will be compiled in the product code to be used when 1171 // lists. It will be compiled in the product code to be used when
1186 // necessary (i.e., during heap verification). 1172 // necessary (i.e., during heap verification).
1187 void verify_region_sets(); 1173 void verify_region_sets();
1188 1174
1274 1260
1275 inline bool is_in_cset(oop obj); 1261 inline bool is_in_cset(oop obj);
1276 1262
1277 inline bool is_in_cset_or_humongous(const oop obj); 1263 inline bool is_in_cset_or_humongous(const oop obj);
1278 1264
1279 enum in_cset_state_t {
1280 InNeither, // neither in collection set nor humongous
1281 InCSet, // region is in collection set only
1282 IsHumongous // region is a humongous start region
1283 };
1284 private: 1265 private:
1285 // Instances of this class are used for quick tests on whether a reference points
1286 // into the collection set or is a humongous object (points into a humongous
1287 // object).
1288 // Each of the array's elements denotes whether the corresponding region is in
1289 // the collection set or a humongous region.
1290 // We use this to quickly reclaim humongous objects: by making a humongous region
1291 // succeed this test, we sort-of add it to the collection set. During the reference
1292 // iteration closures, when we see a humongous region, we simply mark it as
1293 // referenced, i.e. live.
1294 class G1FastCSetBiasedMappedArray : public G1BiasedMappedArray<char> {
1295 protected:
1296 char default_value() const { return G1CollectedHeap::InNeither; }
1297 public:
1298 void set_humongous(uintptr_t index) {
1299 assert(get_by_index(index) != InCSet, "Should not overwrite InCSet values");
1300 set_by_index(index, G1CollectedHeap::IsHumongous);
1301 }
1302
1303 void clear_humongous(uintptr_t index) {
1304 set_by_index(index, G1CollectedHeap::InNeither);
1305 }
1306
1307 void set_in_cset(uintptr_t index) {
1308 assert(get_by_index(index) != G1CollectedHeap::IsHumongous, "Should not overwrite IsHumongous value");
1309 set_by_index(index, G1CollectedHeap::InCSet);
1310 }
1311
1312 bool is_in_cset_or_humongous(HeapWord* addr) const { return get_by_address(addr) != G1CollectedHeap::InNeither; }
1313 bool is_in_cset(HeapWord* addr) const { return get_by_address(addr) == G1CollectedHeap::InCSet; }
1314 G1CollectedHeap::in_cset_state_t at(HeapWord* addr) const { return (G1CollectedHeap::in_cset_state_t)get_by_address(addr); }
1315 void clear() { G1BiasedMappedArray<char>::clear(); }
1316 };
1317
1318 // This array is used for a quick test on whether a reference points into 1266 // This array is used for a quick test on whether a reference points into
1319 // the collection set or not. Each of the array's elements denotes whether the 1267 // the collection set or not. Each of the array's elements denotes whether the
1320 // corresponding region is in the collection set or not. 1268 // corresponding region is in the collection set or not.
1321 G1FastCSetBiasedMappedArray _in_cset_fast_test; 1269 G1InCSetStateFastTestBiasedMappedArray _in_cset_fast_test;
1322 1270
1323 public: 1271 public:
1324 1272
1325 inline in_cset_state_t in_cset_state(const oop obj); 1273 inline InCSetState in_cset_state(const oop obj);
1326 1274
1327 // Return "TRUE" iff the given object address is in the reserved 1275 // Return "TRUE" iff the given object address is in the reserved
1328 // region of g1. 1276 // region of g1.
1329 bool is_in_g1_reserved(const void* p) const { 1277 bool is_in_g1_reserved(const void* p) const {
1330 return _hrm.reserved().contains(p); 1278 return _hrm.reserved().contains(p);