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_SHENANDOAHCONCURRENTTHREAD_HPP 25 #define SHARE_VM_GC_SHENANDOAH_SHENANDOAHCONCURRENTTHREAD_HPP 26 27 #include "gc/shenandoah/shenandoahHeap.hpp" 28 #include "gc/shenandoah/shenandoahSharedVariables.hpp" 29 #include "gc/shared/concurrentGCThread.hpp" 30 #include "gc/shared/gcCause.hpp" 31 #include "memory/resourceArea.hpp" 32 #include "runtime/task.hpp" 33 34 // Periodic task is useful for doing asynchronous things that do not require (heap) locks, 35 // or synchronization with other parts of collector. These could run even when ShenandoahConcurrentThread 36 // is busy driving the GC cycle. 37 class ShenandoahPeriodicTask : public PeriodicTask { 38 private: 39 ShenandoahConcurrentThread* _thread; 40 public: 41 ShenandoahPeriodicTask(ShenandoahConcurrentThread* thread) : 42 PeriodicTask(100), _thread(thread) {} 43 virtual void task(); 44 }; 45 46 class ShenandoahConcurrentThread: public ConcurrentGCThread { 47 friend class VMStructs; 48 49 private: 50 typedef enum { 51 none, 52 concurrent_partial, 53 concurrent_traversal, 54 concurrent_normal, 55 stw_degenerated, 56 stw_full, 57 } GCMode; 58 59 // While we could have a single lock for these, it may risk unblocking 60 // explicit GC waiters when alloc failure GC cycle finishes. We want instead 61 // to make complete explicit cycle for for demanding customers. 62 Monitor _alloc_failure_waiters_lock; 63 Monitor _explicit_gc_waiters_lock; 64 ShenandoahPeriodicTask _periodic_task; 65 66 public: 67 void run_service(); 68 void stop_service(); 69 70 private: 71 ShenandoahSharedFlag _explicit_gc; 72 ShenandoahSharedFlag _alloc_failure_gc; 73 ShenandoahSharedFlag _graceful_shutdown; 74 ShenandoahSharedFlag _heap_changed; 75 ShenandoahSharedFlag _do_counters_update; 76 ShenandoahSharedFlag _force_counters_update; 77 volatile size_t _allocs_seen; 78 GCCause::Cause _explicit_gc_cause; 79 ShenandoahHeap::ShenandoahDegenPoint _degen_point; 80 81 bool check_cancellation_or_degen(ShenandoahHeap::ShenandoahDegenPoint point); 82 void service_concurrent_normal_cycle(GCCause::Cause cause); 83 void service_stw_full_cycle(GCCause::Cause cause); 84 void service_stw_degenerated_cycle(GCCause::Cause cause, ShenandoahHeap::ShenandoahDegenPoint point); 85 void service_concurrent_partial_cycle(GCCause::Cause cause); 86 void service_concurrent_traversal_cycle(GCCause::Cause cause); 87 88 bool try_set_alloc_failure_gc(); 89 void notify_alloc_failure_waiters(); 90 bool is_alloc_failure_gc(); 91 92 void notify_explicit_gc_waiters(); 93 94 public: 95 // Constructor 96 ShenandoahConcurrentThread(); 97 ~ShenandoahConcurrentThread(); 98 99 // Handle allocation failure from normal allocation. 100 // Blocks until memory is available. 101 void handle_alloc_failure(size_t words); 102 103 // Handle allocation failure from evacuation path. 104 // Optionally blocks while collector is handling the failure. 105 void handle_alloc_failure_evac(size_t words); 106 107 // Handle explicit GC request. 108 // Blocks until GC is over. 109 void handle_explicit_gc(GCCause::Cause cause); 110 111 void handle_counters_update(); 112 void handle_force_counters_update(); 113 void set_forced_counters_update(bool value); 114 115 void notify_heap_changed(); 116 117 void pacing_notify_alloc(size_t words); 118 119 void start(); 120 void prepare_for_graceful_shutdown(); 121 bool in_graceful_shutdown(); 122 123 char* name() const { return (char*)"ShenandoahConcurrentThread";} 124 125 // Printing 126 void print_on(outputStream* st) const; 127 void print() const; 128 }; 129 130 #endif // SHARE_VM_GC_SHENANDOAH_SHENANDOAHCONCURRENTTHREAD_HPP