Wed, 27 Apr 2016 01:25:04 +0800
Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 1997, 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_MEMORY_ITERATOR_HPP |
aoqi@0 | 26 | #define SHARE_VM_MEMORY_ITERATOR_HPP |
aoqi@0 | 27 | |
aoqi@0 | 28 | #include "memory/allocation.hpp" |
aoqi@0 | 29 | #include "memory/memRegion.hpp" |
aoqi@0 | 30 | #include "runtime/prefetch.hpp" |
aoqi@0 | 31 | #include "utilities/top.hpp" |
aoqi@0 | 32 | |
aoqi@0 | 33 | // The following classes are C++ `closures` for iterating over objects, roots and spaces |
aoqi@0 | 34 | |
aoqi@0 | 35 | class CodeBlob; |
aoqi@0 | 36 | class nmethod; |
aoqi@0 | 37 | class ReferenceProcessor; |
aoqi@0 | 38 | class DataLayout; |
aoqi@0 | 39 | class KlassClosure; |
aoqi@0 | 40 | class ClassLoaderData; |
aoqi@0 | 41 | |
aoqi@0 | 42 | // Closure provides abortability. |
aoqi@0 | 43 | |
aoqi@0 | 44 | class Closure : public StackObj { |
aoqi@0 | 45 | protected: |
aoqi@0 | 46 | bool _abort; |
aoqi@0 | 47 | void set_abort() { _abort = true; } |
aoqi@0 | 48 | public: |
aoqi@0 | 49 | Closure() : _abort(false) {} |
aoqi@0 | 50 | // A subtype can use this mechanism to indicate to some iterator mapping |
aoqi@0 | 51 | // functions that the iteration should cease. |
aoqi@0 | 52 | bool abort() { return _abort; } |
aoqi@0 | 53 | void clear_abort() { _abort = false; } |
aoqi@0 | 54 | }; |
aoqi@0 | 55 | |
aoqi@0 | 56 | // OopClosure is used for iterating through references to Java objects. |
aoqi@0 | 57 | |
aoqi@0 | 58 | class OopClosure : public Closure { |
aoqi@0 | 59 | public: |
aoqi@0 | 60 | virtual void do_oop(oop* o) = 0; |
aoqi@0 | 61 | virtual void do_oop_v(oop* o) { do_oop(o); } |
aoqi@0 | 62 | virtual void do_oop(narrowOop* o) = 0; |
aoqi@0 | 63 | virtual void do_oop_v(narrowOop* o) { do_oop(o); } |
aoqi@0 | 64 | }; |
aoqi@0 | 65 | |
aoqi@0 | 66 | // ExtendedOopClosure adds extra code to be run during oop iterations. |
aoqi@0 | 67 | // This is needed by the GC and is extracted to a separate type to not |
aoqi@0 | 68 | // pollute the OopClosure interface. |
aoqi@0 | 69 | class ExtendedOopClosure : public OopClosure { |
aoqi@0 | 70 | public: |
aoqi@0 | 71 | ReferenceProcessor* _ref_processor; |
aoqi@0 | 72 | ExtendedOopClosure(ReferenceProcessor* rp) : _ref_processor(rp) { } |
aoqi@0 | 73 | ExtendedOopClosure() : OopClosure(), _ref_processor(NULL) { } |
aoqi@0 | 74 | |
aoqi@0 | 75 | // If the do_metadata functions return "true", |
aoqi@0 | 76 | // we invoke the following when running oop_iterate(): |
aoqi@0 | 77 | // |
aoqi@0 | 78 | // 1) do_klass on the header klass pointer. |
aoqi@0 | 79 | // 2) do_klass on the klass pointer in the mirrors. |
aoqi@0 | 80 | // 3) do_class_loader_data on the class loader data in class loaders. |
aoqi@0 | 81 | // |
aoqi@0 | 82 | // The virtual (without suffix) and the non-virtual (with _nv suffix) need |
aoqi@0 | 83 | // to be updated together, or else the devirtualization will break. |
aoqi@0 | 84 | // |
aoqi@0 | 85 | // Providing default implementations of the _nv functions unfortunately |
aoqi@0 | 86 | // removes the compile-time safeness, but reduces the clutter for the |
aoqi@0 | 87 | // ExtendedOopClosures that don't need to walk the metadata. Currently, |
aoqi@0 | 88 | // only CMS needs these. |
aoqi@0 | 89 | |
aoqi@0 | 90 | virtual bool do_metadata() { return do_metadata_nv(); } |
aoqi@0 | 91 | bool do_metadata_v() { return do_metadata(); } |
aoqi@0 | 92 | bool do_metadata_nv() { return false; } |
aoqi@0 | 93 | |
aoqi@0 | 94 | virtual void do_klass(Klass* k) { do_klass_nv(k); } |
aoqi@0 | 95 | void do_klass_v(Klass* k) { do_klass(k); } |
aoqi@0 | 96 | void do_klass_nv(Klass* k) { ShouldNotReachHere(); } |
aoqi@0 | 97 | |
aoqi@0 | 98 | virtual void do_class_loader_data(ClassLoaderData* cld) { ShouldNotReachHere(); } |
aoqi@0 | 99 | |
aoqi@0 | 100 | // Controls how prefetching is done for invocations of this closure. |
aoqi@0 | 101 | Prefetch::style prefetch_style() { // Note that this is non-virtual. |
aoqi@0 | 102 | return Prefetch::do_none; |
aoqi@0 | 103 | } |
aoqi@0 | 104 | |
aoqi@0 | 105 | // True iff this closure may be safely applied more than once to an oop |
aoqi@0 | 106 | // location without an intervening "major reset" (like the end of a GC). |
aoqi@0 | 107 | virtual bool idempotent() { return false; } |
aoqi@0 | 108 | virtual bool apply_to_weak_ref_discovered_field() { return false; } |
aoqi@0 | 109 | }; |
aoqi@0 | 110 | |
aoqi@0 | 111 | // Wrapper closure only used to implement oop_iterate_no_header(). |
aoqi@0 | 112 | class NoHeaderExtendedOopClosure : public ExtendedOopClosure { |
aoqi@0 | 113 | OopClosure* _wrapped_closure; |
aoqi@0 | 114 | public: |
aoqi@0 | 115 | NoHeaderExtendedOopClosure(OopClosure* cl) : _wrapped_closure(cl) {} |
aoqi@0 | 116 | // Warning: this calls the virtual version do_oop in the the wrapped closure. |
aoqi@0 | 117 | void do_oop_nv(oop* p) { _wrapped_closure->do_oop(p); } |
aoqi@0 | 118 | void do_oop_nv(narrowOop* p) { _wrapped_closure->do_oop(p); } |
aoqi@0 | 119 | |
aoqi@0 | 120 | void do_oop(oop* p) { assert(false, "Only the _nv versions should be used"); |
aoqi@0 | 121 | _wrapped_closure->do_oop(p); } |
aoqi@0 | 122 | void do_oop(narrowOop* p) { assert(false, "Only the _nv versions should be used"); |
aoqi@0 | 123 | _wrapped_closure->do_oop(p);} |
aoqi@0 | 124 | }; |
aoqi@0 | 125 | |
aoqi@0 | 126 | class KlassClosure : public Closure { |
aoqi@0 | 127 | public: |
aoqi@0 | 128 | virtual void do_klass(Klass* k) = 0; |
aoqi@0 | 129 | }; |
aoqi@0 | 130 | |
aoqi@0 | 131 | class KlassToOopClosure : public KlassClosure { |
aoqi@0 | 132 | OopClosure* _oop_closure; |
aoqi@0 | 133 | public: |
aoqi@0 | 134 | KlassToOopClosure(OopClosure* oop_closure) : _oop_closure(oop_closure) {} |
aoqi@0 | 135 | virtual void do_klass(Klass* k); |
aoqi@0 | 136 | }; |
aoqi@0 | 137 | |
aoqi@0 | 138 | class CLDToOopClosure { |
aoqi@0 | 139 | OopClosure* _oop_closure; |
aoqi@0 | 140 | KlassToOopClosure _klass_closure; |
aoqi@0 | 141 | bool _must_claim_cld; |
aoqi@0 | 142 | |
aoqi@0 | 143 | public: |
aoqi@0 | 144 | CLDToOopClosure(OopClosure* oop_closure, bool must_claim_cld = true) : |
aoqi@0 | 145 | _oop_closure(oop_closure), |
aoqi@0 | 146 | _klass_closure(oop_closure), |
aoqi@0 | 147 | _must_claim_cld(must_claim_cld) {} |
aoqi@0 | 148 | |
aoqi@0 | 149 | void do_cld(ClassLoaderData* cld); |
aoqi@0 | 150 | }; |
aoqi@0 | 151 | |
aoqi@0 | 152 | // ObjectClosure is used for iterating through an object space |
aoqi@0 | 153 | |
aoqi@0 | 154 | class ObjectClosure : public Closure { |
aoqi@0 | 155 | public: |
aoqi@0 | 156 | // Called for each object. |
aoqi@0 | 157 | virtual void do_object(oop obj) = 0; |
aoqi@0 | 158 | }; |
aoqi@0 | 159 | |
aoqi@0 | 160 | |
aoqi@0 | 161 | class BoolObjectClosure : public Closure { |
aoqi@0 | 162 | public: |
aoqi@0 | 163 | virtual bool do_object_b(oop obj) = 0; |
aoqi@0 | 164 | }; |
aoqi@0 | 165 | |
aoqi@0 | 166 | // Applies an oop closure to all ref fields in objects iterated over in an |
aoqi@0 | 167 | // object iteration. |
aoqi@0 | 168 | class ObjectToOopClosure: public ObjectClosure { |
aoqi@0 | 169 | ExtendedOopClosure* _cl; |
aoqi@0 | 170 | public: |
aoqi@0 | 171 | void do_object(oop obj); |
aoqi@0 | 172 | ObjectToOopClosure(ExtendedOopClosure* cl) : _cl(cl) {} |
aoqi@0 | 173 | }; |
aoqi@0 | 174 | |
aoqi@0 | 175 | // A version of ObjectClosure with "memory" (see _previous_address below) |
aoqi@0 | 176 | class UpwardsObjectClosure: public BoolObjectClosure { |
aoqi@0 | 177 | HeapWord* _previous_address; |
aoqi@0 | 178 | public: |
aoqi@0 | 179 | UpwardsObjectClosure() : _previous_address(NULL) { } |
aoqi@0 | 180 | void set_previous(HeapWord* addr) { _previous_address = addr; } |
aoqi@0 | 181 | HeapWord* previous() { return _previous_address; } |
aoqi@0 | 182 | // A return value of "true" can be used by the caller to decide |
aoqi@0 | 183 | // if this object's end should *NOT* be recorded in |
aoqi@0 | 184 | // _previous_address above. |
aoqi@0 | 185 | virtual bool do_object_bm(oop obj, MemRegion mr) = 0; |
aoqi@0 | 186 | }; |
aoqi@0 | 187 | |
aoqi@0 | 188 | // A version of ObjectClosure that is expected to be robust |
aoqi@0 | 189 | // in the face of possibly uninitialized objects. |
aoqi@0 | 190 | class ObjectClosureCareful : public ObjectClosure { |
aoqi@0 | 191 | public: |
aoqi@0 | 192 | virtual size_t do_object_careful_m(oop p, MemRegion mr) = 0; |
aoqi@0 | 193 | virtual size_t do_object_careful(oop p) = 0; |
aoqi@0 | 194 | }; |
aoqi@0 | 195 | |
aoqi@0 | 196 | // The following are used in CompactibleFreeListSpace and |
aoqi@0 | 197 | // ConcurrentMarkSweepGeneration. |
aoqi@0 | 198 | |
aoqi@0 | 199 | // Blk closure (abstract class) |
aoqi@0 | 200 | class BlkClosure : public StackObj { |
aoqi@0 | 201 | public: |
aoqi@0 | 202 | virtual size_t do_blk(HeapWord* addr) = 0; |
aoqi@0 | 203 | }; |
aoqi@0 | 204 | |
aoqi@0 | 205 | // A version of BlkClosure that is expected to be robust |
aoqi@0 | 206 | // in the face of possibly uninitialized objects. |
aoqi@0 | 207 | class BlkClosureCareful : public BlkClosure { |
aoqi@0 | 208 | public: |
aoqi@0 | 209 | size_t do_blk(HeapWord* addr) { |
aoqi@0 | 210 | guarantee(false, "call do_blk_careful instead"); |
aoqi@0 | 211 | return 0; |
aoqi@0 | 212 | } |
aoqi@0 | 213 | virtual size_t do_blk_careful(HeapWord* addr) = 0; |
aoqi@0 | 214 | }; |
aoqi@0 | 215 | |
aoqi@0 | 216 | // SpaceClosure is used for iterating over spaces |
aoqi@0 | 217 | |
aoqi@0 | 218 | class Space; |
aoqi@0 | 219 | class CompactibleSpace; |
aoqi@0 | 220 | |
aoqi@0 | 221 | class SpaceClosure : public StackObj { |
aoqi@0 | 222 | public: |
aoqi@0 | 223 | // Called for each space |
aoqi@0 | 224 | virtual void do_space(Space* s) = 0; |
aoqi@0 | 225 | }; |
aoqi@0 | 226 | |
aoqi@0 | 227 | class CompactibleSpaceClosure : public StackObj { |
aoqi@0 | 228 | public: |
aoqi@0 | 229 | // Called for each compactible space |
aoqi@0 | 230 | virtual void do_space(CompactibleSpace* s) = 0; |
aoqi@0 | 231 | }; |
aoqi@0 | 232 | |
aoqi@0 | 233 | |
aoqi@0 | 234 | // CodeBlobClosure is used for iterating through code blobs |
aoqi@0 | 235 | // in the code cache or on thread stacks |
aoqi@0 | 236 | |
aoqi@0 | 237 | class CodeBlobClosure : public Closure { |
aoqi@0 | 238 | public: |
aoqi@0 | 239 | // Called for each code blob. |
aoqi@0 | 240 | virtual void do_code_blob(CodeBlob* cb) = 0; |
aoqi@0 | 241 | }; |
aoqi@0 | 242 | |
aoqi@0 | 243 | |
aoqi@0 | 244 | class MarkingCodeBlobClosure : public CodeBlobClosure { |
aoqi@0 | 245 | public: |
aoqi@0 | 246 | // Called for each code blob, but at most once per unique blob. |
aoqi@0 | 247 | virtual void do_newly_marked_nmethod(nmethod* nm) = 0; |
aoqi@0 | 248 | |
aoqi@0 | 249 | virtual void do_code_blob(CodeBlob* cb); |
aoqi@0 | 250 | // = { if (!nmethod(cb)->test_set_oops_do_mark()) do_newly_marked_nmethod(cb); } |
aoqi@0 | 251 | |
aoqi@0 | 252 | class MarkScope : public StackObj { |
aoqi@0 | 253 | protected: |
aoqi@0 | 254 | bool _active; |
aoqi@0 | 255 | public: |
aoqi@0 | 256 | MarkScope(bool activate = true); |
aoqi@0 | 257 | // = { if (active) nmethod::oops_do_marking_prologue(); } |
aoqi@0 | 258 | ~MarkScope(); |
aoqi@0 | 259 | // = { if (active) nmethod::oops_do_marking_epilogue(); } |
aoqi@0 | 260 | }; |
aoqi@0 | 261 | }; |
aoqi@0 | 262 | |
aoqi@0 | 263 | |
aoqi@0 | 264 | // Applies an oop closure to all ref fields in code blobs |
aoqi@0 | 265 | // iterated over in an object iteration. |
aoqi@0 | 266 | class CodeBlobToOopClosure: public MarkingCodeBlobClosure { |
aoqi@0 | 267 | OopClosure* _cl; |
aoqi@0 | 268 | bool _do_marking; |
aoqi@0 | 269 | public: |
aoqi@0 | 270 | virtual void do_newly_marked_nmethod(nmethod* cb); |
aoqi@0 | 271 | // = { cb->oops_do(_cl); } |
aoqi@0 | 272 | virtual void do_code_blob(CodeBlob* cb); |
aoqi@0 | 273 | // = { if (_do_marking) super::do_code_blob(cb); else cb->oops_do(_cl); } |
aoqi@0 | 274 | CodeBlobToOopClosure(OopClosure* cl, bool do_marking) |
aoqi@0 | 275 | : _cl(cl), _do_marking(do_marking) {} |
aoqi@0 | 276 | }; |
aoqi@0 | 277 | |
aoqi@0 | 278 | |
aoqi@0 | 279 | |
aoqi@0 | 280 | // MonitorClosure is used for iterating over monitors in the monitors cache |
aoqi@0 | 281 | |
aoqi@0 | 282 | class ObjectMonitor; |
aoqi@0 | 283 | |
aoqi@0 | 284 | class MonitorClosure : public StackObj { |
aoqi@0 | 285 | public: |
aoqi@0 | 286 | // called for each monitor in cache |
aoqi@0 | 287 | virtual void do_monitor(ObjectMonitor* m) = 0; |
aoqi@0 | 288 | }; |
aoqi@0 | 289 | |
aoqi@0 | 290 | // A closure that is applied without any arguments. |
aoqi@0 | 291 | class VoidClosure : public StackObj { |
aoqi@0 | 292 | public: |
aoqi@0 | 293 | // I would have liked to declare this a pure virtual, but that breaks |
aoqi@0 | 294 | // in mysterious ways, for unknown reasons. |
aoqi@0 | 295 | virtual void do_void(); |
aoqi@0 | 296 | }; |
aoqi@0 | 297 | |
aoqi@0 | 298 | |
aoqi@0 | 299 | // YieldClosure is intended for use by iteration loops |
aoqi@0 | 300 | // to incrementalize their work, allowing interleaving |
aoqi@0 | 301 | // of an interruptable task so as to allow other |
aoqi@0 | 302 | // threads to run (which may not otherwise be able to access |
aoqi@0 | 303 | // exclusive resources, for instance). Additionally, the |
aoqi@0 | 304 | // closure also allows for aborting an ongoing iteration |
aoqi@0 | 305 | // by means of checking the return value from the polling |
aoqi@0 | 306 | // call. |
aoqi@0 | 307 | class YieldClosure : public StackObj { |
aoqi@0 | 308 | public: |
aoqi@0 | 309 | virtual bool should_return() = 0; |
aoqi@0 | 310 | }; |
aoqi@0 | 311 | |
aoqi@0 | 312 | // Abstract closure for serializing data (read or write). |
aoqi@0 | 313 | |
aoqi@0 | 314 | class SerializeClosure : public Closure { |
aoqi@0 | 315 | public: |
aoqi@0 | 316 | // Return bool indicating whether closure implements read or write. |
aoqi@0 | 317 | virtual bool reading() const = 0; |
aoqi@0 | 318 | |
aoqi@0 | 319 | // Read/write the void pointer pointed to by p. |
aoqi@0 | 320 | virtual void do_ptr(void** p) = 0; |
aoqi@0 | 321 | |
aoqi@0 | 322 | // Read/write the region specified. |
aoqi@0 | 323 | virtual void do_region(u_char* start, size_t size) = 0; |
aoqi@0 | 324 | |
aoqi@0 | 325 | // Check/write the tag. If reading, then compare the tag against |
aoqi@0 | 326 | // the passed in value and fail is they don't match. This allows |
aoqi@0 | 327 | // for verification that sections of the serialized data are of the |
aoqi@0 | 328 | // correct length. |
aoqi@0 | 329 | virtual void do_tag(int tag) = 0; |
aoqi@0 | 330 | }; |
aoqi@0 | 331 | |
aoqi@0 | 332 | class SymbolClosure : public StackObj { |
aoqi@0 | 333 | public: |
aoqi@0 | 334 | virtual void do_symbol(Symbol**) = 0; |
aoqi@0 | 335 | |
aoqi@0 | 336 | // Clear LSB in symbol address; it can be set by CPSlot. |
aoqi@0 | 337 | static Symbol* load_symbol(Symbol** p) { |
aoqi@0 | 338 | return (Symbol*)(intptr_t(*p) & ~1); |
aoqi@0 | 339 | } |
aoqi@0 | 340 | |
aoqi@0 | 341 | // Store symbol, adjusting new pointer if the original pointer was adjusted |
aoqi@0 | 342 | // (symbol references in constant pool slots have their LSB set to 1). |
aoqi@0 | 343 | static void store_symbol(Symbol** p, Symbol* sym) { |
aoqi@0 | 344 | *p = (Symbol*)(intptr_t(sym) | (intptr_t(*p) & 1)); |
aoqi@0 | 345 | } |
aoqi@0 | 346 | }; |
aoqi@0 | 347 | |
aoqi@0 | 348 | #endif // SHARE_VM_MEMORY_ITERATOR_HPP |