< prev index next >

src/hotspot/share/gc/shenandoah/shenandoahControlThread.hpp

Print this page

  1 /*
  2  * Copyright (c) 2013, 2021, Red Hat, Inc. 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  *

 40 class ShenandoahPeriodicTask : public PeriodicTask {
 41 private:
 42   ShenandoahControlThread* _thread;
 43 public:
 44   ShenandoahPeriodicTask(ShenandoahControlThread* thread) :
 45           PeriodicTask(100), _thread(thread) {}
 46   virtual void task();
 47 };
 48 
 49 // Periodic task to notify blocked paced waiters.
 50 class ShenandoahPeriodicPacerNotify : public PeriodicTask {
 51 public:
 52   ShenandoahPeriodicPacerNotify() : PeriodicTask(PeriodicTask::min_interval) {}
 53   virtual void task();
 54 };
 55 
 56 class ShenandoahControlThread: public ConcurrentGCThread {
 57   friend class VMStructs;
 58 
 59 private:
 60   typedef enum {
 61     none,
 62     concurrent_normal,
 63     stw_degenerated,
 64     stw_full
 65   } GCMode;
 66 
 67   // While we could have a single lock for these, it may risk unblocking
 68   // GC waiters when alloc failure GC cycle finishes. We want instead
 69   // to make complete explicit cycle for for demanding customers.
 70   Monitor _alloc_failure_waiters_lock;
 71   Monitor _gc_waiters_lock;


 72   ShenandoahPeriodicTask _periodic_task;
 73   ShenandoahPeriodicPacerNotify _periodic_pacer_notify_task;
 74 
 75 public:









 76   void run_service();
 77   void stop_service();
 78 


 79 private:
 80   ShenandoahSharedFlag _gc_requested;

 81   ShenandoahSharedFlag _alloc_failure_gc;

 82   ShenandoahSharedFlag _graceful_shutdown;
 83   ShenandoahSharedFlag _heap_changed;
 84   ShenandoahSharedFlag _do_counters_update;
 85   ShenandoahSharedFlag _force_counters_update;
 86   GCCause::Cause       _requested_gc_cause;


 87   ShenandoahGC::ShenandoahDegenPoint _degen_point;

 88 
 89   shenandoah_padding(0);
 90   volatile size_t _allocs_seen;
 91   shenandoah_padding(1);
 92   volatile size_t _gc_id;
 93   shenandoah_padding(2);


 94 

 95   bool check_cancellation_or_degen(ShenandoahGC::ShenandoahDegenPoint point);
 96   void service_concurrent_normal_cycle(GCCause::Cause cause);



 97   void service_stw_full_cycle(GCCause::Cause cause);
 98   void service_stw_degenerated_cycle(GCCause::Cause cause, ShenandoahGC::ShenandoahDegenPoint point);
 99   void service_uncommit(double shrink_before, size_t shrink_until);
100 
101   bool try_set_alloc_failure_gc();



102   void notify_alloc_failure_waiters();


103   bool is_alloc_failure_gc();
104 
105   void reset_gc_id();
106   void update_gc_id();
107   size_t get_gc_id();
108 
109   void notify_gc_waiters();
110 
111   // Handle GC request.
112   // Blocks until GC is over.
113   void handle_requested_gc(GCCause::Cause cause);
114 
115   bool is_explicit_gc(GCCause::Cause cause) const;




116 

117   bool check_soft_max_changed() const;
118 


119 public:
120   // Constructor
121   ShenandoahControlThread();
122   ~ShenandoahControlThread();
123 
124   // Handle allocation failure from normal allocation.
125   // Blocks until memory is available.
126   void handle_alloc_failure(ShenandoahAllocRequest& req);
127 
128   // Handle allocation failure from evacuation path.
129   // Optionally blocks while collector is handling the failure.
130   void handle_alloc_failure_evac(size_t words);
131 
132   void request_gc(GCCause::Cause cause);


133 
134   void handle_counters_update();
135   void handle_force_counters_update();
136   void set_forced_counters_update(bool value);
137 
138   void notify_heap_changed();
139 
140   void pacing_notify_alloc(size_t words);
141 
142   void start();
143   void prepare_for_graceful_shutdown();
144   bool in_graceful_shutdown();
























145 };
146 
147 #endif // SHARE_GC_SHENANDOAH_SHENANDOAHCONTROLTHREAD_HPP

  1 /*
  2  * Copyright (c) 2013, 2021, Red Hat, Inc. All rights reserved.
  3  * Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
  4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  5  *
  6  * This code is free software; you can redistribute it and/or modify it
  7  * under the terms of the GNU General Public License version 2 only, as
  8  * published by the Free Software Foundation.
  9  *
 10  * This code is distributed in the hope that it will be useful, but WITHOUT
 11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 13  * version 2 for more details (a copy is included in the LICENSE file that
 14  * accompanied this code).
 15  *
 16  * You should have received a copy of the GNU General Public License version
 17  * 2 along with this work; if not, write to the Free Software Foundation,
 18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 19  *
 20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 21  * or visit www.oracle.com if you need additional information or have any
 22  * questions.
 23  *

 41 class ShenandoahPeriodicTask : public PeriodicTask {
 42 private:
 43   ShenandoahControlThread* _thread;
 44 public:
 45   ShenandoahPeriodicTask(ShenandoahControlThread* thread) :
 46           PeriodicTask(100), _thread(thread) {}
 47   virtual void task();
 48 };
 49 
 50 // Periodic task to notify blocked paced waiters.
 51 class ShenandoahPeriodicPacerNotify : public PeriodicTask {
 52 public:
 53   ShenandoahPeriodicPacerNotify() : PeriodicTask(PeriodicTask::min_interval) {}
 54   virtual void task();
 55 };
 56 
 57 class ShenandoahControlThread: public ConcurrentGCThread {
 58   friend class VMStructs;
 59 
 60 private:







 61   // While we could have a single lock for these, it may risk unblocking
 62   // GC waiters when alloc failure GC cycle finishes. We want instead
 63   // to make complete explicit cycle for demanding customers.
 64   Monitor _alloc_failure_waiters_lock;
 65   Monitor _gc_waiters_lock;
 66   Monitor _control_lock;
 67   Monitor _regulator_lock;
 68   ShenandoahPeriodicTask _periodic_task;
 69   ShenandoahPeriodicPacerNotify _periodic_pacer_notify_task;
 70 
 71 public:
 72   typedef enum {
 73     none,
 74     concurrent_normal,
 75     stw_degenerated,
 76     stw_full,
 77     bootstrapping_old,
 78     servicing_old
 79   } GCMode;
 80 
 81   void run_service();
 82   void stop_service();
 83 
 84   size_t get_gc_id();
 85 
 86 private:
 87   ShenandoahSharedFlag _allow_old_preemption;
 88   ShenandoahSharedFlag _preemption_requested;
 89   ShenandoahSharedFlag _alloc_failure_gc;
 90   ShenandoahSharedFlag _humongous_alloc_failure_gc;
 91   ShenandoahSharedFlag _graceful_shutdown;

 92   ShenandoahSharedFlag _do_counters_update;
 93   ShenandoahSharedFlag _force_counters_update;
 94 
 95   GCCause::Cause  _requested_gc_cause;
 96   volatile ShenandoahGenerationType _requested_generation;
 97   ShenandoahGC::ShenandoahDegenPoint _degen_point;
 98   ShenandoahGeneration* _degen_generation;
 99 
100   shenandoah_padding(0);
101   volatile size_t _allocs_seen;
102   shenandoah_padding(1);
103   volatile size_t _gc_id;
104   shenandoah_padding(2);
105   volatile GCMode _mode;
106   shenandoah_padding(3);
107 
108   // Returns true if the cycle has been cancelled or degenerated.
109   bool check_cancellation_or_degen(ShenandoahGC::ShenandoahDegenPoint point);
110 
111   // Returns true if the old generation marking completed (i.e., final mark executed for old generation).
112   bool resume_concurrent_old_cycle(ShenandoahGeneration* generation, GCCause::Cause cause);
113   void service_concurrent_cycle(ShenandoahGeneration* generation, GCCause::Cause cause, bool reset_old_bitmap_specially);
114   void service_stw_full_cycle(GCCause::Cause cause);
115   void service_stw_degenerated_cycle(GCCause::Cause cause, ShenandoahGC::ShenandoahDegenPoint point);
116   void service_uncommit(double shrink_before, size_t shrink_until);
117 
118   // Return true if setting the flag which indicates allocation failure succeeds.
119   bool try_set_alloc_failure_gc(bool is_humongous);
120 
121   // Notify threads waiting for GC to complete.
122   void notify_alloc_failure_waiters();
123 
124   // True if allocation failure flag has been set.
125   bool is_alloc_failure_gc();
126 
127   void reset_gc_id();
128   void update_gc_id();

129 
130   void notify_gc_waiters();
131 
132   // Handle GC request.
133   // Blocks until GC is over.
134   void handle_requested_gc(GCCause::Cause cause);
135 
136   bool is_explicit_gc(GCCause::Cause cause) const;
137   bool is_implicit_gc(GCCause::Cause cause) const;
138 
139   // Returns true if the old generation marking was interrupted to allow a young cycle.
140   bool preempt_old_marking(ShenandoahGenerationType generation);
141 
142   // Returns true if the soft maximum heap has been changed using management APIs.
143   bool check_soft_max_changed() const;
144 
145   void process_phase_timings(const ShenandoahHeap* heap);
146 
147 public:
148   // Constructor
149   ShenandoahControlThread();
150   ~ShenandoahControlThread();
151 
152   // Handle allocation failure from normal allocation.
153   // Blocks until memory is available.
154   void handle_alloc_failure(ShenandoahAllocRequest& req);
155 
156   // Handle allocation failure from evacuation path.
157   // Optionally blocks while collector is handling the failure.
158   void handle_alloc_failure_evac(size_t words);
159 
160   void request_gc(GCCause::Cause cause);
161   // Return true if the request to start a concurrent GC for the given generation succeeded.
162   bool request_concurrent_gc(ShenandoahGenerationType generation);
163 
164   void handle_counters_update();
165   void handle_force_counters_update();
166   void set_forced_counters_update(bool value);
167 
168   void notify_heap_changed();
169 
170   void pacing_notify_alloc(size_t words);
171 
172   void start();
173   void prepare_for_graceful_shutdown();
174   bool in_graceful_shutdown();
175 
176   void service_concurrent_normal_cycle(ShenandoahHeap* heap,
177                                        const ShenandoahGenerationType generation,
178                                        GCCause::Cause cause);
179 
180   void service_concurrent_old_cycle(ShenandoahHeap* heap,
181                                     GCCause::Cause &cause);
182 
183   void set_gc_mode(GCMode new_mode);
184   GCMode gc_mode() {
185     return _mode;
186   }
187 
188   static ShenandoahGenerationType select_global_generation();
189 
190  private:
191   static const char* gc_mode_name(GCMode mode);
192   void notify_control_thread();
193 
194   void service_concurrent_cycle(ShenandoahHeap* heap,
195                                 ShenandoahGeneration* generation,
196                                 GCCause::Cause &cause,
197                                 bool do_old_gc_bootstrap);
198 
199 };
200 
201 #endif // SHARE_GC_SHENANDOAH_SHENANDOAHCONTROLTHREAD_HPP
< prev index next >