Thu, 03 Feb 2011 20:49:09 -0800
7015169: GC Cause not always set
Summary: Sometimes the gc cause was not always set. This caused JStat to print the wrong information.
Reviewed-by: tonyp, ysr
Contributed-by: suenaga.yasumasa@oss.ntt.co.jp
duke@435 | 1 | /* |
brutisso@2532 | 2 | * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved. |
duke@435 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@435 | 4 | * |
duke@435 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@435 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@435 | 7 | * published by the Free Software Foundation. |
duke@435 | 8 | * |
duke@435 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@435 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@435 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@435 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@435 | 13 | * accompanied this code). |
duke@435 | 14 | * |
duke@435 | 15 | * You should have received a copy of the GNU General Public License version |
duke@435 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@435 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@435 | 18 | * |
trims@1907 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
trims@1907 | 20 | * or visit www.oracle.com if you need additional information or have any |
trims@1907 | 21 | * questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
stefank@2314 | 25 | #ifndef SHARE_VM_GC_IMPLEMENTATION_SHARED_VMGCOPERATIONS_HPP |
stefank@2314 | 26 | #define SHARE_VM_GC_IMPLEMENTATION_SHARED_VMGCOPERATIONS_HPP |
stefank@2314 | 27 | |
stefank@2314 | 28 | #include "memory/heapInspection.hpp" |
stefank@2314 | 29 | #include "runtime/handles.hpp" |
stefank@2314 | 30 | #include "runtime/jniHandles.hpp" |
stefank@2314 | 31 | #include "runtime/synchronizer.hpp" |
stefank@2314 | 32 | #include "runtime/vm_operations.hpp" |
kamg@2445 | 33 | #include "prims/jvmtiExport.hpp" |
stefank@2314 | 34 | |
duke@435 | 35 | // The following class hierarchy represents |
duke@435 | 36 | // a set of operations (VM_Operation) related to GC. |
duke@435 | 37 | // |
duke@435 | 38 | // VM_Operation |
duke@435 | 39 | // VM_GC_Operation |
duke@435 | 40 | // VM_GC_HeapInspection |
duke@435 | 41 | // VM_GenCollectForAllocation |
duke@435 | 42 | // VM_GenCollectFull |
duke@435 | 43 | // VM_GenCollectFullConcurrent |
duke@435 | 44 | // VM_ParallelGCFailedAllocation |
duke@435 | 45 | // VM_ParallelGCFailedPermanentAllocation |
duke@435 | 46 | // VM_ParallelGCSystemGC |
duke@435 | 47 | // VM_GC_Operation |
duke@435 | 48 | // - implements methods common to all classes in the hierarchy: |
duke@435 | 49 | // prevents multiple gc requests and manages lock on heap; |
duke@435 | 50 | // |
duke@435 | 51 | // VM_GC_HeapInspection |
duke@435 | 52 | // - prints class histogram on SIGBREAK if PrintClassHistogram |
duke@435 | 53 | // is specified; and also the attach "inspectheap" operation |
duke@435 | 54 | // |
duke@435 | 55 | // VM_GenCollectForAllocation |
apetrusenko@574 | 56 | // VM_GenCollectForPermanentAllocation |
duke@435 | 57 | // VM_ParallelGCFailedAllocation |
duke@435 | 58 | // VM_ParallelGCFailedPermanentAllocation |
duke@435 | 59 | // - this operation is invoked when allocation is failed; |
duke@435 | 60 | // operation performs garbage collection and tries to |
duke@435 | 61 | // allocate afterwards; |
duke@435 | 62 | // |
duke@435 | 63 | // VM_GenCollectFull |
duke@435 | 64 | // VM_GenCollectFullConcurrent |
duke@435 | 65 | // VM_ParallelGCSystemGC |
duke@435 | 66 | // - these operations preform full collection of heaps of |
duke@435 | 67 | // different kind |
duke@435 | 68 | // |
duke@435 | 69 | |
duke@435 | 70 | class VM_GC_Operation: public VM_Operation { |
duke@435 | 71 | protected: |
duke@435 | 72 | BasicLock _pending_list_basic_lock; // for refs pending list notification (PLL) |
duke@435 | 73 | unsigned int _gc_count_before; // gc count before acquiring PLL |
duke@435 | 74 | unsigned int _full_gc_count_before; // full gc count before acquiring PLL |
duke@435 | 75 | bool _full; // whether a "full" collection |
duke@435 | 76 | bool _prologue_succeeded; // whether doit_prologue succeeded |
duke@435 | 77 | GCCause::Cause _gc_cause; // the putative cause for this gc op |
duke@435 | 78 | bool _gc_locked; // will be set if gc was locked |
duke@435 | 79 | |
duke@435 | 80 | virtual bool skip_operation() const; |
duke@435 | 81 | |
duke@435 | 82 | // java.lang.ref.Reference support |
duke@435 | 83 | void acquire_pending_list_lock(); |
duke@435 | 84 | void release_and_notify_pending_list_lock(); |
duke@435 | 85 | |
duke@435 | 86 | public: |
duke@435 | 87 | VM_GC_Operation(unsigned int gc_count_before, |
brutisso@2532 | 88 | GCCause::Cause _cause, |
duke@435 | 89 | unsigned int full_gc_count_before = 0, |
duke@435 | 90 | bool full = false) { |
duke@435 | 91 | _full = full; |
duke@435 | 92 | _prologue_succeeded = false; |
duke@435 | 93 | _gc_count_before = gc_count_before; |
duke@435 | 94 | |
duke@435 | 95 | // A subclass constructor will likely overwrite the following |
brutisso@2532 | 96 | _gc_cause = _cause; |
duke@435 | 97 | |
duke@435 | 98 | _gc_locked = false; |
duke@435 | 99 | |
tonyp@2011 | 100 | _full_gc_count_before = full_gc_count_before; |
jmasa@1822 | 101 | // In ParallelScavengeHeap::mem_allocate() collections can be |
jmasa@1822 | 102 | // executed within a loop and _all_soft_refs_clear can be set |
jmasa@1822 | 103 | // true after they have been cleared by a collection and another |
jmasa@1822 | 104 | // collection started so that _all_soft_refs_clear can be true |
jmasa@1822 | 105 | // when this collection is started. Don't assert that |
jmasa@1822 | 106 | // _all_soft_refs_clear have to be false here even though |
jmasa@1822 | 107 | // mutators have run. Soft refs will be cleared again in this |
jmasa@1822 | 108 | // collection. |
duke@435 | 109 | } |
jmasa@1822 | 110 | ~VM_GC_Operation() { |
jmasa@1822 | 111 | CollectedHeap* ch = Universe::heap(); |
jmasa@1822 | 112 | ch->collector_policy()->set_all_soft_refs_clear(false); |
jmasa@1822 | 113 | } |
duke@435 | 114 | |
duke@435 | 115 | // Acquire the reference synchronization lock |
duke@435 | 116 | virtual bool doit_prologue(); |
duke@435 | 117 | // Do notifyAll (if needed) and release held lock |
duke@435 | 118 | virtual void doit_epilogue(); |
duke@435 | 119 | |
duke@435 | 120 | virtual bool allow_nested_vm_operations() const { return true; } |
duke@435 | 121 | bool prologue_succeeded() const { return _prologue_succeeded; } |
duke@435 | 122 | |
duke@435 | 123 | void set_gc_locked() { _gc_locked = true; } |
duke@435 | 124 | bool gc_locked() const { return _gc_locked; } |
duke@435 | 125 | |
duke@435 | 126 | static void notify_gc_begin(bool full = false); |
duke@435 | 127 | static void notify_gc_end(); |
duke@435 | 128 | }; |
duke@435 | 129 | |
duke@435 | 130 | |
duke@435 | 131 | class VM_GC_HeapInspection: public VM_GC_Operation { |
duke@435 | 132 | private: |
duke@435 | 133 | outputStream* _out; |
duke@435 | 134 | bool _full_gc; |
ysr@1050 | 135 | bool _need_prologue; |
duke@435 | 136 | public: |
ysr@1050 | 137 | VM_GC_HeapInspection(outputStream* out, bool request_full_gc, |
ysr@1050 | 138 | bool need_prologue) : |
duke@435 | 139 | VM_GC_Operation(0 /* total collections, dummy, ignored */, |
brutisso@2532 | 140 | GCCause::_heap_inspection /* GC Cause */, |
duke@435 | 141 | 0 /* total full collections, dummy, ignored */, |
duke@435 | 142 | request_full_gc) { |
duke@435 | 143 | _out = out; |
duke@435 | 144 | _full_gc = request_full_gc; |
ysr@1050 | 145 | _need_prologue = need_prologue; |
duke@435 | 146 | } |
duke@435 | 147 | |
duke@435 | 148 | ~VM_GC_HeapInspection() {} |
duke@435 | 149 | virtual VMOp_Type type() const { return VMOp_GC_HeapInspection; } |
duke@435 | 150 | virtual bool skip_operation() const; |
duke@435 | 151 | virtual bool doit_prologue(); |
duke@435 | 152 | virtual void doit(); |
duke@435 | 153 | }; |
duke@435 | 154 | |
duke@435 | 155 | |
duke@435 | 156 | class VM_GenCollectForAllocation: public VM_GC_Operation { |
duke@435 | 157 | private: |
duke@435 | 158 | HeapWord* _res; |
duke@435 | 159 | size_t _size; // size of object to be allocated. |
duke@435 | 160 | bool _tlab; // alloc is of a tlab. |
duke@435 | 161 | public: |
duke@435 | 162 | VM_GenCollectForAllocation(size_t size, |
duke@435 | 163 | bool tlab, |
duke@435 | 164 | unsigned int gc_count_before) |
brutisso@2532 | 165 | : VM_GC_Operation(gc_count_before, GCCause::_allocation_failure), |
duke@435 | 166 | _size(size), |
duke@435 | 167 | _tlab(tlab) { |
duke@435 | 168 | _res = NULL; |
duke@435 | 169 | } |
duke@435 | 170 | ~VM_GenCollectForAllocation() {} |
duke@435 | 171 | virtual VMOp_Type type() const { return VMOp_GenCollectForAllocation; } |
duke@435 | 172 | virtual void doit(); |
duke@435 | 173 | HeapWord* result() const { return _res; } |
duke@435 | 174 | }; |
duke@435 | 175 | |
duke@435 | 176 | |
duke@435 | 177 | // VM operation to invoke a collection of the heap as a |
duke@435 | 178 | // GenCollectedHeap heap. |
duke@435 | 179 | class VM_GenCollectFull: public VM_GC_Operation { |
duke@435 | 180 | private: |
duke@435 | 181 | int _max_level; |
duke@435 | 182 | public: |
duke@435 | 183 | VM_GenCollectFull(unsigned int gc_count_before, |
duke@435 | 184 | unsigned int full_gc_count_before, |
duke@435 | 185 | GCCause::Cause gc_cause, |
duke@435 | 186 | int max_level) |
brutisso@2532 | 187 | : VM_GC_Operation(gc_count_before, gc_cause, full_gc_count_before, true /* full */), |
brutisso@2532 | 188 | _max_level(max_level) { } |
duke@435 | 189 | ~VM_GenCollectFull() {} |
duke@435 | 190 | virtual VMOp_Type type() const { return VMOp_GenCollectFull; } |
duke@435 | 191 | virtual void doit(); |
duke@435 | 192 | }; |
apetrusenko@574 | 193 | |
apetrusenko@574 | 194 | class VM_GenCollectForPermanentAllocation: public VM_GC_Operation { |
apetrusenko@574 | 195 | private: |
apetrusenko@574 | 196 | HeapWord* _res; |
apetrusenko@574 | 197 | size_t _size; // size of object to be allocated |
apetrusenko@574 | 198 | public: |
apetrusenko@574 | 199 | VM_GenCollectForPermanentAllocation(size_t size, |
apetrusenko@574 | 200 | unsigned int gc_count_before, |
apetrusenko@574 | 201 | unsigned int full_gc_count_before, |
apetrusenko@574 | 202 | GCCause::Cause gc_cause) |
brutisso@2532 | 203 | : VM_GC_Operation(gc_count_before, gc_cause, full_gc_count_before, true), |
apetrusenko@574 | 204 | _size(size) { |
apetrusenko@574 | 205 | _res = NULL; |
apetrusenko@574 | 206 | _gc_cause = gc_cause; |
apetrusenko@574 | 207 | } |
apetrusenko@574 | 208 | ~VM_GenCollectForPermanentAllocation() {} |
apetrusenko@574 | 209 | virtual VMOp_Type type() const { return VMOp_GenCollectForPermanentAllocation; } |
apetrusenko@574 | 210 | virtual void doit(); |
apetrusenko@574 | 211 | HeapWord* result() const { return _res; } |
apetrusenko@574 | 212 | }; |
stefank@2314 | 213 | |
kamg@2445 | 214 | class SvcGCMarker : public StackObj { |
kamg@2445 | 215 | private: |
kamg@2445 | 216 | JvmtiGCMarker _jgcm; |
kamg@2445 | 217 | public: |
kamg@2445 | 218 | typedef enum { MINOR, FULL, OTHER } reason_type; |
kamg@2445 | 219 | |
kamg@2445 | 220 | SvcGCMarker(reason_type reason ) { |
kamg@2445 | 221 | VM_GC_Operation::notify_gc_begin(reason == FULL); |
tonyp@2381 | 222 | } |
tonyp@2381 | 223 | |
kamg@2445 | 224 | ~SvcGCMarker() { |
tonyp@2381 | 225 | VM_GC_Operation::notify_gc_end(); |
tonyp@2381 | 226 | } |
tonyp@2381 | 227 | }; |
tonyp@2381 | 228 | |
stefank@2314 | 229 | #endif // SHARE_VM_GC_IMPLEMENTATION_SHARED_VMGCOPERATIONS_HPP |