1 /*
   2  * Copyright (c) 2013, 2015, Red Hat, Inc. and/or its affiliates.
   3  *
   4  * This code is free software; you can redistribute it and/or modify it
   5  * under the terms of the GNU General Public License version 2 only, as
   6  * published by the Free Software Foundation.
   7  *
   8  * This code is distributed in the hope that it will be useful, but WITHOUT
   9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  11  * version 2 for more details (a copy is included in the LICENSE file that
  12  * accompanied this code).
  13  *
  14  * You should have received a copy of the GNU General Public License version
  15  * 2 along with this work; if not, write to the Free Software Foundation,
  16  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  17  *
  18  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  19  * or visit www.oracle.com if you need additional information or have any
  20  * questions.
  21  *
  22  */
  23 
  24 #ifndef SHARE_VM_GC_SHENANDOAH_SHENANDOAH_COLLECTOR_POLICY_HPP
  25 #define SHARE_VM_GC_SHENANDOAH_SHENANDOAH_COLLECTOR_POLICY_HPP
  26 
  27 #include "gc/shenandoah/shenandoahHeapRegion.hpp"
  28 #include "gc/shenandoah/shenandoahHeapRegionSet.hpp"
  29 #include "gc/shared/gcTrace.hpp"
  30 #include "gc/shared/gcTimer.hpp"
  31 #include "gc/shared/collectorPolicy.hpp"
  32 #include "runtime/arguments.hpp"
  33 #include "utilities/numberSeq.hpp"
  34 
  35 
  36 class ShenandoahHeap;
  37 class ShenandoahHeuristics;
  38 
  39 class ShenandoahCollectorPolicy: public CollectorPolicy {
  40 
  41 public:
  42   enum TimingPhase {
  43     init_mark,
  44     final_mark,
  45     rescan_roots,
  46     drain_satb,
  47     drain_queues,
  48     weakrefs,
  49     prepare_evac,
  50     init_evac,
  51 
  52     final_evac,
  53     final_uprefs,
  54     update_roots,
  55     recycle_regions,
  56     reset_bitmaps,
  57     resize_tlabs,
  58     full_gc,
  59     conc_mark,
  60     conc_evac,
  61     conc_uprefs,
  62 
  63     _num_phases
  64   };
  65 
  66 private:
  67   struct TimingData {
  68     NumberSeq _ms;
  69     double _start;
  70     size_t _count;
  71   };
  72 
  73 private:
  74   TimingData _timing_data[_num_phases];
  75   const char* _phase_names[_num_phases];
  76 
  77   size_t _user_requested_gcs;
  78   size_t _allocation_failure_gcs;
  79 
  80   ShenandoahHeap* _pgc;
  81   ShenandoahHeuristics* _heuristics;
  82   ShenandoahTracer* _tracer;
  83   STWGCTimer* _stw_timer;
  84   ConcurrentGCTimer* _conc_timer;
  85 
  86   bool _conc_gc_aborted;
  87 
  88 public:
  89   ShenandoahCollectorPolicy();
  90 
  91   virtual ShenandoahCollectorPolicy* as_pgc_policy();
  92 
  93   BarrierSet::Name barrier_set_name();
  94 
  95   HeapWord* mem_allocate_work(size_t size,
  96                               bool is_tlab,
  97                               bool* gc_overhead_limit_was_exceeded);
  98 
  99   HeapWord* satisfy_failed_allocation(size_t size, bool is_tlab);
 100 
 101   void initialize_alignments();
 102 
 103   void post_heap_initialize();
 104 
 105   void record_phase_start(TimingPhase phase);
 106   void record_phase_end(TimingPhase phase);
 107   void report_concgc_cancelled();
 108 
 109   void record_user_requested_gc();
 110   void record_allocation_failure_gc();
 111 
 112   void record_bytes_allocated(size_t bytes);
 113   void record_bytes_reclaimed(size_t bytes);
 114   void record_bytes_start_CM(size_t bytes);
 115   void record_bytes_end_CM(size_t bytes);
 116   bool should_start_concurrent_mark(size_t used, size_t capacity);
 117   void choose_collection_and_free_sets(ShenandoahHeapRegionSet* region_set,
 118                                        ShenandoahHeapRegionSet* collection_set,
 119                                        ShenandoahHeapRegionSet* free_set);
 120 
 121   bool update_refs_early();
 122 
 123   void print_tracing_info();
 124 
 125   GCTimer* conc_timer(){return _conc_timer;}
 126   GCTimer* stw_timer() {return _stw_timer;}
 127   ShenandoahTracer* tracer() {return _tracer;}
 128 
 129   void set_conc_gc_aborted() { _conc_gc_aborted = true;}
 130   void clear_conc_gc_aborted() {_conc_gc_aborted = false;}
 131 
 132 private:
 133   void print_summary_sd(const char* str, uint indent, const NumberSeq* seq);
 134 };
 135 
 136 
 137 #endif // SHARE_VM_GC_SHENANDOAH_SHENANDOAH_COLLECTOR_POLICY_HPP