src/share/vm/gc_implementation/shared/vmGCOperations.hpp

Tue, 17 Oct 2017 12:58:25 +0800

author
aoqi
date
Tue, 17 Oct 2017 12:58:25 +0800
changeset 7994
04ff2f6cd0eb
parent 7688
a4ad5d51d29c
parent 7535
7ae4e26cb1e0
child 9806
758c07667682
permissions
-rw-r--r--

merge

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

mercurial