Wed, 26 Jun 2013 16:58:37 +0200
8013590: NPG: Add a memory pool MXBean for Metaspace
Reviewed-by: jmasa, mgerdin
duke@435 | 1 | /* |
coleenp@4037 | 2 | * Copyright (c) 2001, 2012, 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_MEMORY_GENOOPCLOSURES_HPP |
stefank@2314 | 26 | #define SHARE_VM_MEMORY_GENOOPCLOSURES_HPP |
stefank@2314 | 27 | |
stefank@2314 | 28 | #include "memory/iterator.hpp" |
stefank@2314 | 29 | #include "oops/oop.hpp" |
stefank@2314 | 30 | |
duke@435 | 31 | class Generation; |
duke@435 | 32 | class HeapWord; |
duke@435 | 33 | class CardTableRS; |
duke@435 | 34 | class CardTableModRefBS; |
duke@435 | 35 | class DefNewGeneration; |
coleenp@4037 | 36 | class KlassRemSet; |
duke@435 | 37 | |
zgu@3900 | 38 | template<class E, MEMFLAGS F, unsigned int N> class GenericTaskQueue; |
zgu@3900 | 39 | typedef GenericTaskQueue<oop, mtGC, TASKQUEUE_SIZE> OopTaskQueue; |
zgu@3900 | 40 | template<class T, MEMFLAGS F> class GenericTaskQueueSet; |
zgu@3900 | 41 | typedef GenericTaskQueueSet<OopTaskQueue, mtGC> OopTaskQueueSet; |
coleenp@548 | 42 | |
duke@435 | 43 | // Closure for iterating roots from a particular generation |
duke@435 | 44 | // Note: all classes deriving from this MUST call this do_barrier |
duke@435 | 45 | // method at the end of their own do_oop method! |
duke@435 | 46 | // Note: no do_oop defined, this is an abstract class. |
duke@435 | 47 | |
coleenp@4037 | 48 | class OopsInGenClosure : public ExtendedOopClosure { |
duke@435 | 49 | private: |
coleenp@548 | 50 | Generation* _orig_gen; // generation originally set in ctor |
coleenp@548 | 51 | Generation* _gen; // generation being scanned |
duke@435 | 52 | |
duke@435 | 53 | protected: |
duke@435 | 54 | // Some subtypes need access. |
coleenp@548 | 55 | HeapWord* _gen_boundary; // start of generation |
coleenp@548 | 56 | CardTableRS* _rs; // remembered set |
duke@435 | 57 | |
duke@435 | 58 | // For assertions |
duke@435 | 59 | Generation* generation() { return _gen; } |
duke@435 | 60 | CardTableRS* rs() { return _rs; } |
duke@435 | 61 | |
duke@435 | 62 | // Derived classes that modify oops so that they might be old-to-young |
duke@435 | 63 | // pointers must call the method below. |
coleenp@548 | 64 | template <class T> void do_barrier(T* p); |
duke@435 | 65 | |
ysr@777 | 66 | // Version for use by closures that may be called in parallel code. |
ysr@1280 | 67 | template <class T> void par_do_barrier(T* p); |
ysr@777 | 68 | |
duke@435 | 69 | public: |
coleenp@4037 | 70 | OopsInGenClosure() : ExtendedOopClosure(NULL), |
duke@435 | 71 | _orig_gen(NULL), _gen(NULL), _gen_boundary(NULL), _rs(NULL) {}; |
duke@435 | 72 | |
duke@435 | 73 | OopsInGenClosure(Generation* gen); |
duke@435 | 74 | void set_generation(Generation* gen); |
duke@435 | 75 | |
duke@435 | 76 | void reset_generation() { _gen = _orig_gen; } |
duke@435 | 77 | |
duke@435 | 78 | // Problem with static closures: must have _gen_boundary set at some point, |
duke@435 | 79 | // but cannot do this until after the heap is initialized. |
duke@435 | 80 | void set_orig_generation(Generation* gen) { |
duke@435 | 81 | _orig_gen = gen; |
duke@435 | 82 | set_generation(gen); |
duke@435 | 83 | } |
duke@435 | 84 | |
duke@435 | 85 | HeapWord* gen_boundary() { return _gen_boundary; } |
coleenp@4037 | 86 | |
coleenp@4037 | 87 | }; |
coleenp@4037 | 88 | |
coleenp@4037 | 89 | // Super class for scan closures. It contains code to dirty scanned Klasses. |
coleenp@4037 | 90 | class OopsInKlassOrGenClosure: public OopsInGenClosure { |
coleenp@4037 | 91 | Klass* _scanned_klass; |
coleenp@4037 | 92 | public: |
coleenp@4037 | 93 | OopsInKlassOrGenClosure(Generation* g) : OopsInGenClosure(g), _scanned_klass(NULL) {} |
coleenp@4037 | 94 | void set_scanned_klass(Klass* k) { |
coleenp@4037 | 95 | assert(k == NULL || _scanned_klass == NULL, "Must be"); |
coleenp@4037 | 96 | _scanned_klass = k; |
coleenp@4037 | 97 | } |
coleenp@4037 | 98 | bool is_scanning_a_klass() { return _scanned_klass != NULL; } |
coleenp@4037 | 99 | void do_klass_barrier(); |
duke@435 | 100 | }; |
duke@435 | 101 | |
duke@435 | 102 | // Closure for scanning DefNewGeneration. |
duke@435 | 103 | // |
duke@435 | 104 | // This closure will perform barrier store calls for ALL |
duke@435 | 105 | // pointers in scanned oops. |
coleenp@4037 | 106 | class ScanClosure: public OopsInKlassOrGenClosure { |
coleenp@548 | 107 | protected: |
duke@435 | 108 | DefNewGeneration* _g; |
coleenp@548 | 109 | HeapWord* _boundary; |
coleenp@548 | 110 | bool _gc_barrier; |
coleenp@548 | 111 | template <class T> inline void do_oop_work(T* p); |
coleenp@548 | 112 | public: |
duke@435 | 113 | ScanClosure(DefNewGeneration* g, bool gc_barrier); |
coleenp@548 | 114 | virtual void do_oop(oop* p); |
coleenp@548 | 115 | virtual void do_oop(narrowOop* p); |
coleenp@548 | 116 | inline void do_oop_nv(oop* p); |
coleenp@548 | 117 | inline void do_oop_nv(narrowOop* p); |
duke@435 | 118 | Prefetch::style prefetch_style() { |
duke@435 | 119 | return Prefetch::do_write; |
duke@435 | 120 | } |
duke@435 | 121 | }; |
duke@435 | 122 | |
duke@435 | 123 | // Closure for scanning DefNewGeneration. |
duke@435 | 124 | // |
duke@435 | 125 | // This closure only performs barrier store calls on |
duke@435 | 126 | // pointers into the DefNewGeneration. This is less |
duke@435 | 127 | // precise, but faster, than a ScanClosure |
coleenp@4037 | 128 | class FastScanClosure: public OopsInKlassOrGenClosure { |
coleenp@548 | 129 | protected: |
duke@435 | 130 | DefNewGeneration* _g; |
coleenp@548 | 131 | HeapWord* _boundary; |
coleenp@548 | 132 | bool _gc_barrier; |
coleenp@548 | 133 | template <class T> inline void do_oop_work(T* p); |
coleenp@548 | 134 | public: |
duke@435 | 135 | FastScanClosure(DefNewGeneration* g, bool gc_barrier); |
coleenp@548 | 136 | virtual void do_oop(oop* p); |
coleenp@548 | 137 | virtual void do_oop(narrowOop* p); |
coleenp@548 | 138 | inline void do_oop_nv(oop* p); |
coleenp@548 | 139 | inline void do_oop_nv(narrowOop* p); |
duke@435 | 140 | Prefetch::style prefetch_style() { |
duke@435 | 141 | return Prefetch::do_write; |
duke@435 | 142 | } |
duke@435 | 143 | }; |
duke@435 | 144 | |
coleenp@4037 | 145 | class KlassScanClosure: public KlassClosure { |
coleenp@4037 | 146 | OopsInKlassOrGenClosure* _scavenge_closure; |
coleenp@4037 | 147 | // true if the the modified oops state should be saved. |
coleenp@4037 | 148 | bool _accumulate_modified_oops; |
coleenp@4037 | 149 | public: |
coleenp@4037 | 150 | KlassScanClosure(OopsInKlassOrGenClosure* scavenge_closure, |
coleenp@4037 | 151 | KlassRemSet* klass_rem_set_policy); |
coleenp@4037 | 152 | void do_klass(Klass* k); |
coleenp@4037 | 153 | }; |
coleenp@4037 | 154 | |
coleenp@4037 | 155 | class FilteringClosure: public ExtendedOopClosure { |
coleenp@548 | 156 | private: |
coleenp@548 | 157 | HeapWord* _boundary; |
coleenp@4037 | 158 | ExtendedOopClosure* _cl; |
coleenp@548 | 159 | protected: |
coleenp@548 | 160 | template <class T> inline void do_oop_work(T* p) { |
coleenp@548 | 161 | T heap_oop = oopDesc::load_heap_oop(p); |
coleenp@548 | 162 | if (!oopDesc::is_null(heap_oop)) { |
coleenp@548 | 163 | oop obj = oopDesc::decode_heap_oop_not_null(heap_oop); |
coleenp@548 | 164 | if ((HeapWord*)obj < _boundary) { |
coleenp@548 | 165 | _cl->do_oop(p); |
coleenp@548 | 166 | } |
coleenp@548 | 167 | } |
coleenp@548 | 168 | } |
coleenp@548 | 169 | public: |
coleenp@4037 | 170 | FilteringClosure(HeapWord* boundary, ExtendedOopClosure* cl) : |
coleenp@4037 | 171 | ExtendedOopClosure(cl->_ref_processor), _boundary(boundary), |
duke@435 | 172 | _cl(cl) {} |
coleenp@548 | 173 | virtual void do_oop(oop* p); |
coleenp@548 | 174 | virtual void do_oop(narrowOop* p); |
coleenp@548 | 175 | inline void do_oop_nv(oop* p) { FilteringClosure::do_oop_work(p); } |
coleenp@548 | 176 | inline void do_oop_nv(narrowOop* p) { FilteringClosure::do_oop_work(p); } |
coleenp@4037 | 177 | virtual bool do_metadata() { return do_metadata_nv(); } |
coleenp@4037 | 178 | inline bool do_metadata_nv() { assert(!_cl->do_metadata(), "assumption broken, must change to 'return _cl->do_metadata()'"); return false; } |
duke@435 | 179 | }; |
duke@435 | 180 | |
duke@435 | 181 | // Closure for scanning DefNewGeneration's weak references. |
duke@435 | 182 | // NOTE: very much like ScanClosure but not derived from |
duke@435 | 183 | // OopsInGenClosure -- weak references are processed all |
duke@435 | 184 | // at once, with no notion of which generation they were in. |
duke@435 | 185 | class ScanWeakRefClosure: public OopClosure { |
coleenp@548 | 186 | protected: |
coleenp@548 | 187 | DefNewGeneration* _g; |
coleenp@548 | 188 | HeapWord* _boundary; |
coleenp@548 | 189 | template <class T> inline void do_oop_work(T* p); |
coleenp@548 | 190 | public: |
duke@435 | 191 | ScanWeakRefClosure(DefNewGeneration* g); |
coleenp@548 | 192 | virtual void do_oop(oop* p); |
coleenp@548 | 193 | virtual void do_oop(narrowOop* p); |
coleenp@548 | 194 | inline void do_oop_nv(oop* p); |
coleenp@548 | 195 | inline void do_oop_nv(narrowOop* p); |
duke@435 | 196 | }; |
duke@435 | 197 | |
duke@435 | 198 | class VerifyOopClosure: public OopClosure { |
coleenp@548 | 199 | protected: |
coleenp@548 | 200 | template <class T> inline void do_oop_work(T* p) { |
coleenp@548 | 201 | oop obj = oopDesc::load_decode_heap_oop(p); |
twisti@2874 | 202 | guarantee(obj->is_oop_or_null(), err_msg("invalid oop: " INTPTR_FORMAT, (oopDesc*) obj)); |
duke@435 | 203 | } |
coleenp@548 | 204 | public: |
coleenp@548 | 205 | virtual void do_oop(oop* p); |
coleenp@548 | 206 | virtual void do_oop(narrowOop* p); |
duke@435 | 207 | static VerifyOopClosure verify_oop; |
duke@435 | 208 | }; |
stefank@2314 | 209 | |
stefank@2314 | 210 | #endif // SHARE_VM_MEMORY_GENOOPCLOSURES_HPP |