src/share/vm/memory/iterator.hpp

Sat, 01 Sep 2012 13:25:18 -0400

author
coleenp
date
Sat, 01 Sep 2012 13:25:18 -0400
changeset 4037
da91efe96a93
parent 2708
1d1603768966
child 4050
ec98e58952b2
permissions
-rw-r--r--

6964458: Reimplement class meta-data storage to use native memory
Summary: Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
Contributed-by: jmasa <jon.masamitsu@oracle.com>, stefank <stefan.karlsson@oracle.com>, mgerdin <mikael.gerdin@oracle.com>, never <tom.rodriguez@oracle.com>

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

mercurial