1 #ifdef USE_PRAGMA_IDENT_HDR 2 #pragma ident "@(#)vmGCOperations.hpp 1.14 07/05/29 09:44:12 JVM" 3 #endif 4 /* 5 * Copyright 2005-2006 Sun Microsystems, Inc. All Rights Reserved. 6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 7 * 8 * This code is free software; you can redistribute it and/or modify it 9 * under the terms of the GNU General Public License version 2 only, as 10 * published by the Free Software Foundation. 11 * 12 * This code is distributed in the hope that it will be useful, but WITHOUT 13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 15 * version 2 for more details (a copy is included in the LICENSE file that 16 * accompanied this code). 17 * 18 * You should have received a copy of the GNU General Public License version 19 * 2 along with this work; if not, write to the Free Software Foundation, 20 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 21 * 22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 23 * CA 95054 USA or visit www.sun.com if you need additional information or 24 * have any questions. 25 * 26 */ 27 28 // The following class hierarchy represents 29 // a set of operations (VM_Operation) related to GC. 30 // 31 // VM_Operation 32 // VM_GC_Operation 33 // VM_GC_HeapInspection 34 // VM_GenCollectForAllocation 35 // VM_GenCollectFull 36 // VM_GenCollectFullConcurrent 37 // VM_ParallelGCFailedAllocation 38 // VM_ParallelGCFailedPermanentAllocation 39 // VM_ParallelGCSystemGC 40 // VM_GC_Operation 41 // - implements methods common to all classes in the hierarchy: 42 // prevents multiple gc requests and manages lock on heap; 43 // 44 // VM_GC_HeapInspection 45 // - prints class histogram on SIGBREAK if PrintClassHistogram 46 // is specified; and also the attach "inspectheap" operation 47 // 48 // VM_GenCollectForAllocation 49 // VM_ParallelGCFailedAllocation 50 // VM_ParallelGCFailedPermanentAllocation 51 // - this operation is invoked when allocation is failed; 52 // operation performs garbage collection and tries to 53 // allocate afterwards; 54 // 55 // VM_GenCollectFull 56 // VM_GenCollectFullConcurrent 57 // VM_ParallelGCSystemGC 58 // - these operations preform full collection of heaps of 59 // different kind 60 // 61 62 class VM_GC_Operation: public VM_Operation { 63 protected: 64 BasicLock _pending_list_basic_lock; // for refs pending list notification (PLL) 65 unsigned int _gc_count_before; // gc count before acquiring PLL 66 unsigned int _full_gc_count_before; // full gc count before acquiring PLL 67 bool _full; // whether a "full" collection 68 bool _prologue_succeeded; // whether doit_prologue succeeded 69 GCCause::Cause _gc_cause; // the putative cause for this gc op 70 bool _gc_locked; // will be set if gc was locked 71 72 virtual bool skip_operation() const; 73 74 // java.lang.ref.Reference support 75 void acquire_pending_list_lock(); 76 void release_and_notify_pending_list_lock(); 77 78 public: 79 VM_GC_Operation(unsigned int gc_count_before, 80 unsigned int full_gc_count_before = 0, 81 bool full = false) { 82 _full = full; 83 _prologue_succeeded = false; 84 _gc_count_before = gc_count_before; 85 86 // A subclass constructor will likely overwrite the following 87 _gc_cause = GCCause::_no_cause_specified; 88 89 _gc_locked = false; 90 91 if (full) { 92 _full_gc_count_before = full_gc_count_before; 93 } 94 } 95 ~VM_GC_Operation() {} 96 97 // Acquire the reference synchronization lock 98 virtual bool doit_prologue(); 99 // Do notifyAll (if needed) and release held lock 100 virtual void doit_epilogue(); 101 102 virtual bool allow_nested_vm_operations() const { return true; } 103 bool prologue_succeeded() const { return _prologue_succeeded; } 104 105 void set_gc_locked() { _gc_locked = true; } 106 bool gc_locked() const { return _gc_locked; } 107 108 static void notify_gc_begin(bool full = false); 109 static void notify_gc_end(); 110 }; 111 112 113 class VM_GC_HeapInspection: public VM_GC_Operation { 114 private: 115 outputStream* _out; 116 bool _full_gc; 117 public: 118 VM_GC_HeapInspection(outputStream* out, bool request_full_gc) : 119 VM_GC_Operation(0 /* total collections, dummy, ignored */, 120 0 /* total full collections, dummy, ignored */, 121 request_full_gc) { 122 _out = out; 123 _full_gc = request_full_gc; 124 } 125 126 ~VM_GC_HeapInspection() {} 127 virtual VMOp_Type type() const { return VMOp_GC_HeapInspection; } 128 virtual bool skip_operation() const; 129 virtual bool doit_prologue(); 130 virtual void doit(); 131 }; 132 133 134 class VM_GenCollectForAllocation: public VM_GC_Operation { 135 private: 136 HeapWord* _res; 137 size_t _size; // size of object to be allocated. 138 bool _tlab; // alloc is of a tlab. 139 public: 140 VM_GenCollectForAllocation(size_t size, 141 bool tlab, 142 unsigned int gc_count_before) 143 : VM_GC_Operation(gc_count_before), 144 _size(size), 145 _tlab(tlab) { 146 _res = NULL; 147 } 148 ~VM_GenCollectForAllocation() {} 149 virtual VMOp_Type type() const { return VMOp_GenCollectForAllocation; } 150 virtual void doit(); 151 HeapWord* result() const { return _res; } 152 }; 153 154 155 // VM operation to invoke a collection of the heap as a 156 // GenCollectedHeap heap. 157 class VM_GenCollectFull: public VM_GC_Operation { 158 private: 159 int _max_level; 160 public: 161 VM_GenCollectFull(unsigned int gc_count_before, 162 unsigned int full_gc_count_before, 163 GCCause::Cause gc_cause, 164 int max_level) 165 : VM_GC_Operation(gc_count_before, full_gc_count_before, true /* full */), 166 _max_level(max_level) 167 { _gc_cause = gc_cause; } 168 ~VM_GenCollectFull() {} 169 virtual VMOp_Type type() const { return VMOp_GenCollectFull; } 170 virtual void doit(); 171 };