# HG changeset patch # Parent a22af2c3d969665c49fd813e32ff3c2bada41631 diff -r a22af2c3d969 src/hotspot/share/gc/shenandoah/shenandoahAllocRequest.hpp --- a/src/hotspot/share/gc/shenandoah/shenandoahAllocRequest.hpp Mon Jun 15 12:28:27 2020 +0200 +++ b/src/hotspot/share/gc/shenandoah/shenandoahAllocRequest.hpp Mon Jun 15 21:58:44 2020 +0200 @@ -27,6 +27,12 @@ #include "memory/allocation.hpp" +enum ShenandoahGeneration { + YOUNG_GEN, + OLD_GEN, + NO_GEN +}; + class ShenandoahAllocRequest : StackObj { public: enum Type { @@ -58,13 +64,14 @@ size_t _requested_size; size_t _actual_size; Type _alloc_type; + ShenandoahGeneration const _generation; #ifdef ASSERT bool _actual_size_set; #endif - ShenandoahAllocRequest(size_t _min_size, size_t _requested_size, Type _alloc_type) : + ShenandoahAllocRequest(size_t _min_size, size_t _requested_size, Type _alloc_type, ShenandoahGeneration generation) : _min_size(_min_size), _requested_size(_requested_size), - _actual_size(0), _alloc_type(_alloc_type) + _actual_size(0), _alloc_type(_alloc_type), _generation(generation) #ifdef ASSERT , _actual_size_set(false) #endif @@ -72,19 +79,19 @@ public: static inline ShenandoahAllocRequest for_tlab(size_t min_size, size_t requested_size) { - return ShenandoahAllocRequest(min_size, requested_size, _alloc_tlab); + return ShenandoahAllocRequest(min_size, requested_size, _alloc_tlab, YOUNG_GEN); } static inline ShenandoahAllocRequest for_gclab(size_t min_size, size_t requested_size) { - return ShenandoahAllocRequest(min_size, requested_size, _alloc_gclab); + return ShenandoahAllocRequest(min_size, requested_size, _alloc_gclab, YOUNG_GEN); } - static inline ShenandoahAllocRequest for_shared_gc(size_t requested_size) { - return ShenandoahAllocRequest(0, requested_size, _alloc_shared_gc); + static inline ShenandoahAllocRequest for_shared_gc(size_t requested_size, ShenandoahGeneration generation) { + return ShenandoahAllocRequest(0, requested_size, _alloc_shared_gc, generation); } static inline ShenandoahAllocRequest for_shared(size_t requested_size) { - return ShenandoahAllocRequest(0, requested_size, _alloc_shared); + return ShenandoahAllocRequest(0, requested_size, _alloc_shared, YOUNG_GEN); } inline size_t size() { @@ -158,6 +165,10 @@ return false; } } + + ShenandoahGeneration generation() const { + return _generation; + } }; #endif // SHARE_GC_SHENANDOAH_SHENANDOAHALLOCREQUEST_HPP diff -r a22af2c3d969 src/hotspot/share/gc/shenandoah/shenandoahFreeSet.cpp --- a/src/hotspot/share/gc/shenandoah/shenandoahFreeSet.cpp Mon Jun 15 12:28:27 2020 +0200 +++ b/src/hotspot/share/gc/shenandoah/shenandoahFreeSet.cpp Mon Jun 15 21:58:44 2020 +0200 @@ -146,6 +146,12 @@ return NULL; } + if (r->generation() == NO_GEN) { + r->set_generation(req.generation()); + } else if (r->generation() != req.generation()) { + return NULL; + } + try_recycle_trashed(r); in_new_region = r->is_empty(); diff -r a22af2c3d969 src/hotspot/share/gc/shenandoah/shenandoahHeap.inline.hpp --- a/src/hotspot/share/gc/shenandoah/shenandoahHeap.inline.hpp Mon Jun 15 12:28:27 2020 +0200 +++ b/src/hotspot/share/gc/shenandoah/shenandoahHeap.inline.hpp Mon Jun 15 21:58:44 2020 +0200 @@ -262,6 +262,19 @@ assert(ShenandoahThreadLocalData::is_evac_allowed(thread), "must be enclosed in oom-evac scope"); size_t size = p->size(); + ShenandoahGeneration target_gen = heap_region_containing(p)->generation(); + if (target_gen == YOUNG_GEN) { + markWord mark = p->mark(); + if (mark.is_marked()) { + // Already forwarded. + return ShenandoahBarrierSet::resolve_forwarded(p); + } else { + if (mark.age() > InitialTenuringThreshold) { + //tty->print_cr("promoting object: " PTR_FORMAT, p2i(p)); + target_gen = OLD_GEN; + } + } + } assert(!heap_region_containing(p)->is_humongous(), "never evacuate humongous objects"); @@ -274,11 +287,11 @@ copy = NULL; } else { #endif - if (UseTLAB) { + if (UseTLAB && target_gen == YOUNG_GEN) { copy = allocate_from_gclab(thread, size); } if (copy == NULL) { - ShenandoahAllocRequest req = ShenandoahAllocRequest::for_shared_gc(size); + ShenandoahAllocRequest req = ShenandoahAllocRequest::for_shared_gc(size, target_gen); copy = allocate_memory(req); alloc_from_gclab = false; } @@ -303,6 +316,12 @@ if (result == copy_val) { // Successfully evacuated. Our copy is now the public one! shenandoah_assert_correct(NULL, copy_val); + + // Increment age in young copies + if (target_gen == YOUNG_GEN) { + copy_val->incr_age(); + } + return copy_val; } else { // Failed to evacuate. We need to deal with the object that is left behind. Since this diff -r a22af2c3d969 src/hotspot/share/gc/shenandoah/shenandoahHeapRegion.cpp --- a/src/hotspot/share/gc/shenandoah/shenandoahHeapRegion.cpp Mon Jun 15 12:28:27 2020 +0200 +++ b/src/hotspot/share/gc/shenandoah/shenandoahHeapRegion.cpp Mon Jun 15 21:58:44 2020 +0200 @@ -64,7 +64,8 @@ _gclab_allocs(0), _live_data(0), _critical_pins(0), - _update_watermark(start) { + _update_watermark(start), + _generation(NO_GEN) { assert(Universe::on_page_boundary(_bottom) && Universe::on_page_boundary(_end), "invalid space boundaries"); @@ -359,6 +360,19 @@ default: ShouldNotReachHere(); } + switch (_generation) { + case YOUNG_GEN: + st->print("|Y"); + break; + case OLD_GEN: + st->print("|O"); + break; + case NO_GEN: + st->print("| "); + break; + default: + ShouldNotReachHere(); + } st->print("|BTE " INTPTR_FORMAT_W(12) ", " INTPTR_FORMAT_W(12) ", " INTPTR_FORMAT_W(12), p2i(bottom()), p2i(top()), p2i(end())); st->print("|TAMS " INTPTR_FORMAT_W(12), @@ -428,6 +442,7 @@ set_update_watermark(bottom()); make_empty(); + _generation = NO_GEN; if (ZapUnusedHeapArea) { SpaceMangler::mangle_region(MemRegion(bottom(), end())); diff -r a22af2c3d969 src/hotspot/share/gc/shenandoah/shenandoahHeapRegion.hpp --- a/src/hotspot/share/gc/shenandoah/shenandoahHeapRegion.hpp Mon Jun 15 12:28:27 2020 +0200 +++ b/src/hotspot/share/gc/shenandoah/shenandoahHeapRegion.hpp Mon Jun 15 21:58:44 2020 +0200 @@ -245,6 +245,8 @@ HeapWord* volatile _update_watermark; + ShenandoahGeneration _generation; + public: ShenandoahHeapRegion(HeapWord* start, size_t index, bool committed); @@ -386,6 +388,14 @@ inline void set_update_watermark(HeapWord* w); inline void set_update_watermark_at_safepoint(HeapWord* w); + ShenandoahGeneration generation() const { + return _generation; + } + + void set_generation(ShenandoahGeneration generation) { + _generation = generation; + } + private: void do_commit(); void do_uncommit();