1 /* 2 * Copyright (c) 2017, 2018, Red Hat, Inc. All rights reserved. 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_SHENANDOAHUTILS_HPP 25 #define SHARE_VM_GC_SHENANDOAHUTILS_HPP 26 27 #include "runtime/vmThread.hpp" 28 #include "gc_interface/gcCause.hpp" 29 #include "gc_implementation/shared/isGCActiveMark.hpp" 30 #include "gc_implementation/shared/vmGCOperations.hpp" 31 #include "memory/allocation.hpp" 32 #include "gc_implementation/shenandoah/shenandoahPhaseTimings.hpp" 33 34 class GCTimer; 35 class GCTracer; 36 37 class ShenandoahGCSession : public StackObj { 38 private: 39 ShenandoahHeap* const _heap; 40 GCTimer* const _timer; 41 GCTracer* const _tracer; 42 43 TraceMemoryManagerStats _trace_cycle; 44 public: 45 ShenandoahGCSession(GCCause::Cause cause); 46 ~ShenandoahGCSession(); 47 }; 48 49 class ShenandoahGCPhase : public StackObj { 50 private: 51 static const ShenandoahPhaseTimings::Phase _invalid_phase = ShenandoahPhaseTimings::_num_phases; 52 static ShenandoahPhaseTimings::Phase _current_phase; 53 54 ShenandoahHeap* const _heap; 55 const ShenandoahPhaseTimings::Phase _phase; 56 ShenandoahPhaseTimings::Phase _parent_phase; 57 public: 58 ShenandoahGCPhase(ShenandoahPhaseTimings::Phase phase); 59 ~ShenandoahGCPhase(); 60 61 static ShenandoahPhaseTimings::Phase current_phase() { return _current_phase; } 62 63 static bool is_valid_phase(ShenandoahPhaseTimings::Phase phase); 64 static bool is_current_phase_valid() { return is_valid_phase(current_phase()); } 65 static bool is_root_work_phase(); 66 }; 67 68 // Aggregates all the things that should happen before/after the pause. 69 class ShenandoahGCPauseMark : public StackObj { 70 private: 71 ShenandoahHeap* const _heap; 72 const SvcGCMarker _svc_gc_mark; 73 const IsGCActiveMark _is_gc_active_mark; 74 TraceMemoryManagerStats _trace_pause; 75 public: 76 ShenandoahGCPauseMark(SvcGCMarker::reason_type type); 77 ~ShenandoahGCPauseMark(); 78 }; 79 80 class ShenandoahAllocTrace : public StackObj { 81 private: 82 double _start; 83 size_t _size; 84 ShenandoahAllocRequest::Type _alloc_type; 85 public: 86 ShenandoahAllocTrace(size_t words_size, ShenandoahAllocRequest::Type alloc_type); 87 ~ShenandoahAllocTrace(); 88 }; 89 90 class ShenandoahSafepoint : public AllStatic { 91 public: 92 // check if Shenandoah GC safepoint is in progress 93 static inline bool is_at_shenandoah_safepoint() { 94 if (!SafepointSynchronize::is_at_safepoint()) return false; 95 96 VM_Operation* vm_op = VMThread::vm_operation(); 97 if (vm_op == NULL) return false; 98 99 VM_Operation::VMOp_Type type = vm_op->type(); 100 return type == VM_Operation::VMOp_ShenandoahInitMark || 101 type == VM_Operation::VMOp_ShenandoahFinalMarkStartEvac || 102 type == VM_Operation::VMOp_ShenandoahFinalEvac || 103 type == VM_Operation::VMOp_ShenandoahInitUpdateRefs || 104 type == VM_Operation::VMOp_ShenandoahFinalUpdateRefs || 105 type == VM_Operation::VMOp_ShenandoahFullGC || 106 type == VM_Operation::VMOp_ShenandoahDegeneratedGC; 107 } 108 }; 109 110 class ShenandoahWorkerSession : public StackObj { 111 static const uint INVALID_WORKER_ID = uint(-1); 112 protected: 113 uint _worker_id; 114 115 ShenandoahWorkerSession(uint worker_id); 116 ~ShenandoahWorkerSession(); 117 118 public: 119 static inline uint worker_id() { 120 Thread* thr = Thread::current(); 121 uint id = thr->worker_id(); 122 assert(id != INVALID_WORKER_ID, "Worker session has not been created"); 123 return id; 124 } 125 }; 126 127 class ShenandoahConcurrentWorkerSession : public ShenandoahWorkerSession { 128 public: 129 ShenandoahConcurrentWorkerSession(uint worker_id) : ShenandoahWorkerSession(worker_id) { } 130 ~ShenandoahConcurrentWorkerSession(); 131 }; 132 133 class ShenandoahParallelWorkerSession : public ShenandoahWorkerSession { 134 public: 135 ShenandoahParallelWorkerSession(uint worker_id) : ShenandoahWorkerSession(worker_id) { } 136 ~ShenandoahParallelWorkerSession(); 137 }; 138 139 #endif // SHARE_VM_GC_SHENANDOAHUTILS_HPP