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

Tue, 08 Aug 2017 15:57:29 +0800

author
aoqi
date
Tue, 08 Aug 2017 15:57:29 +0800
changeset 6876
710a3c8b516e
parent 5863
85c1ca43713f
parent 0
f90c822e73f8
child 7535
7ae4e26cb1e0
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2005, 2013, 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
aoqi@0 28 #include "memory/heapInspection.hpp"
aoqi@0 29 #include "runtime/handles.hpp"
aoqi@0 30 #include "runtime/jniHandles.hpp"
aoqi@0 31 #include "runtime/synchronizer.hpp"
aoqi@0 32 #include "runtime/vm_operations.hpp"
aoqi@0 33 #include "prims/jvmtiExport.hpp"
aoqi@0 34
aoqi@0 35 // The following class hierarchy represents
aoqi@0 36 // a set of operations (VM_Operation) related to GC.
aoqi@0 37 //
aoqi@0 38 // VM_Operation
aoqi@0 39 // VM_GC_Operation
aoqi@0 40 // VM_GC_HeapInspection
aoqi@0 41 // VM_GenCollectForAllocation
aoqi@0 42 // VM_GenCollectFull
aoqi@0 43 // VM_GenCollectFullConcurrent
aoqi@0 44 // VM_ParallelGCFailedAllocation
aoqi@0 45 // VM_ParallelGCSystemGC
aoqi@0 46 // VM_GC_Operation
aoqi@0 47 // - implements methods common to all classes in the hierarchy:
aoqi@0 48 // prevents multiple gc requests and manages lock on heap;
aoqi@0 49 //
aoqi@0 50 // VM_GC_HeapInspection
aoqi@0 51 // - prints class histogram on SIGBREAK if PrintClassHistogram
aoqi@0 52 // is specified; and also the attach "inspectheap" operation
aoqi@0 53 //
aoqi@0 54 // VM_GenCollectForAllocation
aoqi@0 55 // VM_ParallelGCFailedAllocation
aoqi@0 56 // - this operation is invoked when allocation is failed;
aoqi@0 57 // operation performs garbage collection and tries to
aoqi@0 58 // allocate afterwards;
aoqi@0 59 //
aoqi@0 60 // VM_GenCollectFull
aoqi@0 61 // VM_GenCollectFullConcurrent
aoqi@0 62 // VM_ParallelGCSystemGC
aoqi@0 63 // - these operations preform full collection of heaps of
aoqi@0 64 // different kind
aoqi@0 65 //
aoqi@0 66
aoqi@0 67 class VM_GC_Operation: public VM_Operation {
aoqi@0 68 protected:
aoqi@0 69 BasicLock _pending_list_basic_lock; // for refs pending list notification (PLL)
aoqi@0 70 unsigned int _gc_count_before; // gc count before acquiring PLL
aoqi@0 71 unsigned int _full_gc_count_before; // full gc count before acquiring PLL
aoqi@0 72 bool _full; // whether a "full" collection
aoqi@0 73 bool _prologue_succeeded; // whether doit_prologue succeeded
aoqi@0 74 GCCause::Cause _gc_cause; // the putative cause for this gc op
aoqi@0 75 bool _gc_locked; // will be set if gc was locked
aoqi@0 76
aoqi@0 77 virtual bool skip_operation() const;
aoqi@0 78
aoqi@0 79 // java.lang.ref.Reference support
aoqi@0 80 void acquire_pending_list_lock();
aoqi@0 81 void release_and_notify_pending_list_lock();
aoqi@0 82
aoqi@0 83 public:
aoqi@0 84 VM_GC_Operation(unsigned int gc_count_before,
aoqi@0 85 GCCause::Cause _cause,
aoqi@0 86 unsigned int full_gc_count_before = 0,
aoqi@0 87 bool full = false) {
aoqi@0 88 _full = full;
aoqi@0 89 _prologue_succeeded = false;
aoqi@0 90 _gc_count_before = gc_count_before;
aoqi@0 91
aoqi@0 92 // A subclass constructor will likely overwrite the following
aoqi@0 93 _gc_cause = _cause;
aoqi@0 94
aoqi@0 95 _gc_locked = false;
aoqi@0 96
aoqi@0 97 _full_gc_count_before = full_gc_count_before;
aoqi@0 98 // In ParallelScavengeHeap::mem_allocate() collections can be
aoqi@0 99 // executed within a loop and _all_soft_refs_clear can be set
aoqi@0 100 // true after they have been cleared by a collection and another
aoqi@0 101 // collection started so that _all_soft_refs_clear can be true
aoqi@0 102 // when this collection is started. Don't assert that
aoqi@0 103 // _all_soft_refs_clear have to be false here even though
aoqi@0 104 // mutators have run. Soft refs will be cleared again in this
aoqi@0 105 // collection.
aoqi@0 106 }
aoqi@0 107 ~VM_GC_Operation() {
aoqi@0 108 CollectedHeap* ch = Universe::heap();
aoqi@0 109 ch->collector_policy()->set_all_soft_refs_clear(false);
aoqi@0 110 }
aoqi@0 111
aoqi@0 112 // Acquire the reference synchronization lock
aoqi@0 113 virtual bool doit_prologue();
aoqi@0 114 // Do notifyAll (if needed) and release held lock
aoqi@0 115 virtual void doit_epilogue();
aoqi@0 116
aoqi@0 117 virtual bool allow_nested_vm_operations() const { return true; }
aoqi@0 118 bool prologue_succeeded() const { return _prologue_succeeded; }
aoqi@0 119
aoqi@0 120 void set_gc_locked() { _gc_locked = true; }
aoqi@0 121 bool gc_locked() const { return _gc_locked; }
aoqi@0 122
aoqi@0 123 static void notify_gc_begin(bool full = false);
aoqi@0 124 static void notify_gc_end();
aoqi@0 125 };
aoqi@0 126
aoqi@0 127
aoqi@0 128 class VM_GC_HeapInspection: public VM_GC_Operation {
aoqi@0 129 private:
aoqi@0 130 outputStream* _out;
aoqi@0 131 bool _full_gc;
aoqi@0 132 bool _csv_format; // "comma separated values" format for spreadsheet.
aoqi@0 133 bool _print_help;
aoqi@0 134 bool _print_class_stats;
aoqi@0 135 const char* _columns;
aoqi@0 136 public:
aoqi@0 137 VM_GC_HeapInspection(outputStream* out, bool request_full_gc) :
aoqi@0 138 VM_GC_Operation(0 /* total collections, dummy, ignored */,
aoqi@0 139 GCCause::_heap_inspection /* GC Cause */,
aoqi@0 140 0 /* total full collections, dummy, ignored */,
aoqi@0 141 request_full_gc) {
aoqi@0 142 _out = out;
aoqi@0 143 _full_gc = request_full_gc;
aoqi@0 144 _csv_format = false;
aoqi@0 145 _print_help = false;
aoqi@0 146 _print_class_stats = false;
aoqi@0 147 _columns = NULL;
aoqi@0 148 }
aoqi@0 149
aoqi@0 150 ~VM_GC_HeapInspection() {}
aoqi@0 151 virtual VMOp_Type type() const { return VMOp_GC_HeapInspection; }
aoqi@0 152 virtual bool skip_operation() const;
aoqi@0 153 virtual bool doit_prologue();
aoqi@0 154 virtual void doit();
aoqi@0 155 void set_csv_format(bool value) {_csv_format = value;}
aoqi@0 156 void set_print_help(bool value) {_print_help = value;}
aoqi@0 157 void set_print_class_stats(bool value) {_print_class_stats = value;}
aoqi@0 158 void set_columns(const char* value) {_columns = value;}
aoqi@0 159 protected:
aoqi@0 160 bool collect();
aoqi@0 161 };
aoqi@0 162
aoqi@0 163
aoqi@0 164 class VM_GenCollectForAllocation: public VM_GC_Operation {
aoqi@0 165 private:
aoqi@0 166 HeapWord* _res;
aoqi@0 167 size_t _size; // size of object to be allocated.
aoqi@0 168 bool _tlab; // alloc is of a tlab.
aoqi@0 169 public:
aoqi@0 170 VM_GenCollectForAllocation(size_t size,
aoqi@0 171 bool tlab,
aoqi@0 172 unsigned int gc_count_before)
aoqi@0 173 : VM_GC_Operation(gc_count_before, GCCause::_allocation_failure),
aoqi@0 174 _size(size),
aoqi@0 175 _tlab(tlab) {
aoqi@0 176 _res = NULL;
aoqi@0 177 }
aoqi@0 178 ~VM_GenCollectForAllocation() {}
aoqi@0 179 virtual VMOp_Type type() const { return VMOp_GenCollectForAllocation; }
aoqi@0 180 virtual void doit();
aoqi@0 181 HeapWord* result() const { return _res; }
aoqi@0 182 };
aoqi@0 183
aoqi@0 184
aoqi@0 185 // VM operation to invoke a collection of the heap as a
aoqi@0 186 // GenCollectedHeap heap.
aoqi@0 187 class VM_GenCollectFull: public VM_GC_Operation {
aoqi@0 188 private:
aoqi@0 189 int _max_level;
aoqi@0 190 public:
aoqi@0 191 VM_GenCollectFull(unsigned int gc_count_before,
aoqi@0 192 unsigned int full_gc_count_before,
aoqi@0 193 GCCause::Cause gc_cause,
aoqi@0 194 int max_level)
aoqi@0 195 : VM_GC_Operation(gc_count_before, gc_cause, full_gc_count_before, true /* full */),
aoqi@0 196 _max_level(max_level) { }
aoqi@0 197 ~VM_GenCollectFull() {}
aoqi@0 198 virtual VMOp_Type type() const { return VMOp_GenCollectFull; }
aoqi@0 199 virtual void doit();
aoqi@0 200 };
aoqi@0 201
aoqi@0 202 class VM_CollectForMetadataAllocation: public VM_GC_Operation {
aoqi@0 203 private:
aoqi@0 204 MetaWord* _result;
aoqi@0 205 size_t _size; // size of object to be allocated
aoqi@0 206 Metaspace::MetadataType _mdtype;
aoqi@0 207 ClassLoaderData* _loader_data;
aoqi@0 208 public:
aoqi@0 209 VM_CollectForMetadataAllocation(ClassLoaderData* loader_data,
aoqi@0 210 size_t size, Metaspace::MetadataType mdtype,
aoqi@0 211 unsigned int gc_count_before,
aoqi@0 212 unsigned int full_gc_count_before,
aoqi@0 213 GCCause::Cause gc_cause)
aoqi@0 214 : VM_GC_Operation(gc_count_before, gc_cause, full_gc_count_before, true),
aoqi@0 215 _loader_data(loader_data), _size(size), _mdtype(mdtype), _result(NULL) {
aoqi@0 216 }
aoqi@0 217 virtual VMOp_Type type() const { return VMOp_CollectForMetadataAllocation; }
aoqi@0 218 virtual void doit();
aoqi@0 219 MetaWord* result() const { return _result; }
aoqi@0 220 };
aoqi@0 221
aoqi@0 222 class SvcGCMarker : public StackObj {
aoqi@0 223 private:
aoqi@0 224 JvmtiGCMarker _jgcm;
aoqi@0 225 public:
aoqi@0 226 typedef enum { MINOR, FULL, OTHER } reason_type;
aoqi@0 227
aoqi@0 228 SvcGCMarker(reason_type reason ) {
aoqi@0 229 VM_GC_Operation::notify_gc_begin(reason == FULL);
aoqi@0 230 }
aoqi@0 231
aoqi@0 232 ~SvcGCMarker() {
aoqi@0 233 VM_GC_Operation::notify_gc_end();
aoqi@0 234 }
aoqi@0 235 };
aoqi@0 236
aoqi@0 237 #endif // SHARE_VM_GC_IMPLEMENTATION_SHARED_VMGCOPERATIONS_HPP

mercurial