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 * 24 */ 25 26 #ifndef SHARE_GC_SHENANDOAH_SHENANDOAHGENERATIONALCONTROLTHREAD_HPP 27 #define SHARE_GC_SHENANDOAH_SHENANDOAHGENERATIONALCONTROLTHREAD_HPP 28 29 #include "gc/shared/gcCause.hpp" 30 #include "gc/shenandoah/shenandoahController.hpp" 31 #include "gc/shenandoah/shenandoahGC.hpp" 32 #include "gc/shenandoah/shenandoahHeap.hpp" 33 #include "gc/shenandoah/shenandoahPadding.hpp" 34 #include "gc/shenandoah/shenandoahSharedVariables.hpp" 35 36 class ShenandoahOldGeneration; 37 38 class ShenandoahGenerationalControlThread: public ShenandoahController { 39 friend class VMStructs; 40 41 public: 42 typedef enum { 43 none, 44 concurrent_normal, 45 stw_degenerated, 46 stw_full, 47 bootstrapping_old, 48 servicing_old 49 } GCMode; 50 51 private: 52 Monitor _control_lock; 53 Monitor _regulator_lock; 54 55 ShenandoahSharedFlag _allow_old_preemption; 56 ShenandoahSharedFlag _preemption_requested; 57 58 GCCause::Cause _requested_gc_cause; 59 volatile ShenandoahGenerationType _requested_generation; 60 ShenandoahGC::ShenandoahDegenPoint _degen_point; 61 ShenandoahGeneration* _degen_generation; 62 63 shenandoah_padding(0); 64 volatile GCMode _mode; 65 shenandoah_padding(1); 66 67 public: 68 ShenandoahGenerationalControlThread(); 69 70 void run_service() override; 71 void stop_service() override; 72 73 void request_gc(GCCause::Cause cause) override; 74 75 // Return true if the request to start a concurrent GC for the given generation succeeded. 76 bool request_concurrent_gc(ShenandoahGenerationType generation); 77 78 GCMode gc_mode() { 79 return _mode; 80 } 81 private: 82 83 // Returns true if the cycle has been cancelled or degenerated. 84 bool check_cancellation_or_degen(ShenandoahGC::ShenandoahDegenPoint point); 85 86 // Returns true if the old generation marking completed (i.e., final mark executed for old generation). 87 bool resume_concurrent_old_cycle(ShenandoahOldGeneration* generation, GCCause::Cause cause); 88 void service_concurrent_cycle(ShenandoahGeneration* generation, GCCause::Cause cause, bool reset_old_bitmap_specially); 89 void service_stw_full_cycle(GCCause::Cause cause); 90 void service_stw_degenerated_cycle(GCCause::Cause cause, ShenandoahGC::ShenandoahDegenPoint point); 91 92 void notify_gc_waiters(); 93 94 // Handle GC request. 95 // Blocks until GC is over. 96 void handle_requested_gc(GCCause::Cause cause); 97 98 bool is_explicit_gc(GCCause::Cause cause) const; 99 bool is_implicit_gc(GCCause::Cause cause) const; 100 101 // Returns true if the old generation marking was interrupted to allow a young cycle. 102 bool preempt_old_marking(ShenandoahGenerationType generation); 103 104 void process_phase_timings(const ShenandoahHeap* heap); 105 106 void service_concurrent_normal_cycle(ShenandoahHeap* heap, 107 ShenandoahGenerationType generation, 108 GCCause::Cause cause); 109 110 void service_concurrent_old_cycle(ShenandoahHeap* heap, 111 GCCause::Cause &cause); 112 113 void set_gc_mode(GCMode new_mode); 114 115 static const char* gc_mode_name(GCMode mode); 116 117 void notify_control_thread(); 118 119 void service_concurrent_cycle(ShenandoahHeap* heap, 120 ShenandoahGeneration* generation, 121 GCCause::Cause &cause, 122 bool do_old_gc_bootstrap); 123 124 }; 125 126 #endif // SHARE_GC_SHENANDOAH_SHENANDOAHGENERATIONALCONTROLTHREAD_HPP