1 /*
  2  * Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.
  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  *
 23  */
 24 
 25 #ifndef SHARE_GC_SHENANDOAH_SHENANDOAHGENERATIONALHEAP
 26 #define SHARE_GC_SHENANDOAH_SHENANDOAHGENERATIONALHEAP
 27 
 28 #include "gc/shenandoah/shenandoahHeap.hpp"
 29 
 30 class ShenandoahRegulatorThread;
 31 class ShenandoahGenerationalControlThread;
 32 
 33 class ShenandoahGenerationalHeap : public ShenandoahHeap {
 34 public:
 35   explicit ShenandoahGenerationalHeap(ShenandoahCollectorPolicy* policy);
 36 
 37   static ShenandoahGenerationalHeap* heap();
 38 
 39   void print_init_logger() const override;
 40   size_t unsafe_max_tlab_alloc(Thread *thread) const override;
 41 
 42   // ---------- Evacuations and Promotions
 43   //
 44   oop evacuate_object(oop p, Thread* thread) override;
 45   oop try_evacuate_object(oop p, Thread* thread, ShenandoahHeapRegion* from_region, ShenandoahAffiliation target_gen);
 46 
 47   size_t plab_min_size() const { return _min_plab_size; }
 48   size_t plab_max_size() const { return _max_plab_size; }
 49 
 50   void retire_plab(PLAB* plab);
 51   void retire_plab(PLAB* plab, Thread* thread);
 52 
 53 private:
 54   HeapWord* allocate_from_plab(Thread* thread, size_t size, bool is_promotion);
 55   HeapWord* allocate_from_plab_slow(Thread* thread, size_t size, bool is_promotion);
 56   HeapWord* allocate_new_plab(size_t min_size, size_t word_size, size_t* actual_size);
 57 
 58   const size_t _min_plab_size;
 59   const size_t _max_plab_size;
 60 
 61   static size_t calculate_min_plab();
 62   static size_t calculate_max_plab();
 63 
 64 public:
 65   // ---------- Serviceability
 66   //
 67   void initialize_serviceability() override;
 68   GrowableArray<MemoryPool*> memory_pools() override;
 69 
 70   ShenandoahRegulatorThread* regulator_thread() const { return _regulator_thread;  }
 71 
 72   void gc_threads_do(ThreadClosure* tcl) const override;
 73 
 74   void stop() override;
 75 
 76   // Used for logging the result of a region transfer outside the heap lock
 77   struct TransferResult {
 78     bool success;
 79     size_t region_count;
 80     const char* region_destination;
 81 
 82     void print_on(const char* when, outputStream* ss) const;
 83   };
 84 
 85   // Zeros out the evacuation and promotion reserves
 86   void reset_generation_reserves();
 87 
 88   // Computes the optimal size for the old generation, represented as a surplus or deficit of old regions
 89   void compute_old_generation_balance(size_t old_xfer_limit, size_t old_cset_regions);
 90 
 91   // Transfers surplus old regions to young, or takes regions from young to satisfy old region deficit
 92   TransferResult balance_generations();
 93 
 94   void coalesce_and_fill_old_regions(bool concurrent);
 95 
 96 private:
 97   void initialize_controller() override;
 98 
 99   ShenandoahRegulatorThread* _regulator_thread;
100 
101   MemoryPool* _young_gen_memory_pool;
102   MemoryPool* _old_gen_memory_pool;
103 };
104 
105 #endif //SHARE_GC_SHENANDOAH_SHENANDOAHGENERATIONALHEAP