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

Wed, 31 Jul 2019 14:28:51 -0400

author
kbarrett
date
Wed, 31 Jul 2019 14:28:51 -0400
changeset 9787
9f28a4cac6d9
parent 7688
a4ad5d51d29c
child 9806
758c07667682
permissions
-rw-r--r--

8048556: Unnecessary GCLocker-initiated young GCs
Summary: Fixed recognition of unnecessary GCLocker collections.
Reviewed-by: pliden, tschatzl
Contributed-by: johnc@azul.com

duke@435 1 /*
mlarsson@7686 2 * Copyright (c) 2005, 2015, 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
mlarsson@7688 28 #include "gc_implementation/shared/gcId.hpp"
stefank@2314 29 #include "memory/heapInspection.hpp"
stefank@2314 30 #include "runtime/handles.hpp"
stefank@2314 31 #include "runtime/jniHandles.hpp"
stefank@2314 32 #include "runtime/synchronizer.hpp"
stefank@2314 33 #include "runtime/vm_operations.hpp"
kamg@2445 34 #include "prims/jvmtiExport.hpp"
stefank@2314 35
duke@435 36 // The following class hierarchy represents
duke@435 37 // a set of operations (VM_Operation) related to GC.
duke@435 38 //
duke@435 39 // VM_Operation
duke@435 40 // VM_GC_Operation
duke@435 41 // VM_GC_HeapInspection
duke@435 42 // VM_GenCollectFull
duke@435 43 // VM_GenCollectFullConcurrent
duke@435 44 // VM_ParallelGCSystemGC
mlarsson@7687 45 // VM_CollectForAllocation
mlarsson@7687 46 // VM_GenCollectForAllocation
mlarsson@7687 47 // VM_ParallelGCFailedAllocation
duke@435 48 // VM_GC_Operation
duke@435 49 // - implements methods common to all classes in the hierarchy:
duke@435 50 // prevents multiple gc requests and manages lock on heap;
duke@435 51 //
duke@435 52 // VM_GC_HeapInspection
duke@435 53 // - prints class histogram on SIGBREAK if PrintClassHistogram
duke@435 54 // is specified; and also the attach "inspectheap" operation
duke@435 55 //
mlarsson@7687 56 // VM_CollectForAllocation
duke@435 57 // VM_GenCollectForAllocation
duke@435 58 // VM_ParallelGCFailedAllocation
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:
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
duke@435 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
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:
mlarsson@7686 87 VM_GC_Operation(uint gc_count_before,
brutisso@2532 88 GCCause::Cause _cause,
mlarsson@7686 89 uint 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;
acorn@4497 135 bool _csv_format; // "comma separated values" format for spreadsheet.
acorn@4497 136 bool _print_help;
acorn@4497 137 bool _print_class_stats;
acorn@4497 138 const char* _columns;
duke@435 139 public:
sla@5237 140 VM_GC_HeapInspection(outputStream* out, bool request_full_gc) :
duke@435 141 VM_GC_Operation(0 /* total collections, dummy, ignored */,
brutisso@2532 142 GCCause::_heap_inspection /* GC Cause */,
duke@435 143 0 /* total full collections, dummy, ignored */,
duke@435 144 request_full_gc) {
duke@435 145 _out = out;
duke@435 146 _full_gc = request_full_gc;
acorn@4497 147 _csv_format = false;
acorn@4497 148 _print_help = false;
acorn@4497 149 _print_class_stats = false;
acorn@4497 150 _columns = NULL;
duke@435 151 }
duke@435 152
duke@435 153 ~VM_GC_HeapInspection() {}
duke@435 154 virtual VMOp_Type type() const { return VMOp_GC_HeapInspection; }
duke@435 155 virtual bool skip_operation() const;
duke@435 156 virtual bool doit_prologue();
duke@435 157 virtual void doit();
acorn@4497 158 void set_csv_format(bool value) {_csv_format = value;}
acorn@4497 159 void set_print_help(bool value) {_print_help = value;}
acorn@4497 160 void set_print_class_stats(bool value) {_print_class_stats = value;}
acorn@4497 161 void set_columns(const char* value) {_columns = value;}
sla@5237 162 protected:
sla@5237 163 bool collect();
duke@435 164 };
duke@435 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)
duke@435 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 {
duke@435 180 private:
duke@435 181 bool _tlab; // alloc is of a tlab.
duke@435 182 public:
mlarsson@7687 183 VM_GenCollectForAllocation(size_t word_size,
duke@435 184 bool tlab,
mlarsson@7686 185 uint gc_count_before)
mlarsson@7687 186 : VM_CollectForAllocation(word_size, gc_count_before, GCCause::_allocation_failure),
duke@435 187 _tlab(tlab) {
mlarsson@7687 188 assert(word_size != 0, "An allocation should always be requested with this operation.");
duke@435 189 }
duke@435 190 ~VM_GenCollectForAllocation() {}
duke@435 191 virtual VMOp_Type type() const { return VMOp_GenCollectForAllocation; }
duke@435 192 virtual void doit();
duke@435 193 };
duke@435 194
duke@435 195 // VM operation to invoke a collection of the heap as a
duke@435 196 // GenCollectedHeap heap.
duke@435 197 class VM_GenCollectFull: public VM_GC_Operation {
duke@435 198 private:
duke@435 199 int _max_level;
duke@435 200 public:
mlarsson@7686 201 VM_GenCollectFull(uint gc_count_before,
mlarsson@7686 202 uint full_gc_count_before,
duke@435 203 GCCause::Cause gc_cause,
kbarrett@9787 204 int max_level);
duke@435 205 ~VM_GenCollectFull() {}
duke@435 206 virtual VMOp_Type type() const { return VMOp_GenCollectFull; }
duke@435 207 virtual void doit();
duke@435 208 };
apetrusenko@574 209
coleenp@4037 210 class VM_CollectForMetadataAllocation: public VM_GC_Operation {
apetrusenko@574 211 private:
coleenp@4037 212 MetaWord* _result;
jmasa@4196 213 size_t _size; // size of object to be allocated
coleenp@4037 214 Metaspace::MetadataType _mdtype;
coleenp@4037 215 ClassLoaderData* _loader_data;
apetrusenko@574 216 public:
coleenp@4037 217 VM_CollectForMetadataAllocation(ClassLoaderData* loader_data,
coleenp@4037 218 size_t size, Metaspace::MetadataType mdtype,
mlarsson@7686 219 uint gc_count_before,
mlarsson@7686 220 uint full_gc_count_before,
mlarsson@7688 221 GCCause::Cause gc_cause);
coleenp@4037 222 virtual VMOp_Type type() const { return VMOp_CollectForMetadataAllocation; }
apetrusenko@574 223 virtual void doit();
coleenp@4037 224 MetaWord* result() const { return _result; }
stefank@6992 225
stefank@6992 226 bool initiate_concurrent_GC();
apetrusenko@574 227 };
stefank@2314 228
kamg@2445 229 class SvcGCMarker : public StackObj {
kamg@2445 230 private:
kamg@2445 231 JvmtiGCMarker _jgcm;
kamg@2445 232 public:
kamg@2445 233 typedef enum { MINOR, FULL, OTHER } reason_type;
kamg@2445 234
kamg@2445 235 SvcGCMarker(reason_type reason ) {
kamg@2445 236 VM_GC_Operation::notify_gc_begin(reason == FULL);
tonyp@2381 237 }
tonyp@2381 238
kamg@2445 239 ~SvcGCMarker() {
tonyp@2381 240 VM_GC_Operation::notify_gc_end();
tonyp@2381 241 }
tonyp@2381 242 };
tonyp@2381 243
stefank@2314 244 #endif // SHARE_VM_GC_IMPLEMENTATION_SHARED_VMGCOPERATIONS_HPP

mercurial