src/share/vm/memory/iterator.hpp

Thu, 27 Jan 2011 16:11:27 -0800

author
coleenp
date
Thu, 27 Jan 2011 16:11:27 -0800
changeset 2497
3582bf76420e
parent 2314
f95d63e2154a
child 2708
1d1603768966
permissions
-rw-r--r--

6990754: Use native memory and reference counting to implement SymbolTable
Summary: move symbols from permgen into C heap and reference count them
Reviewed-by: never, acorn, jmasa, stefank

duke@435 1 /*
stefank@2314 2 * Copyright (c) 1997, 2010, 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;
duke@435 39
ysr@777 40 // Closure provides abortability.
ysr@777 41
ysr@777 42 class Closure : public StackObj {
ysr@777 43 protected:
ysr@777 44 bool _abort;
ysr@777 45 void set_abort() { _abort = true; }
ysr@777 46 public:
ysr@777 47 Closure() : _abort(false) {}
ysr@777 48 // A subtype can use this mechanism to indicate to some iterator mapping
ysr@777 49 // functions that the iteration should cease.
ysr@777 50 bool abort() { return _abort; }
ysr@777 51 void clear_abort() { _abort = false; }
ysr@777 52 };
ysr@777 53
duke@435 54 // OopClosure is used for iterating through roots (oop*)
duke@435 55
ysr@777 56 class OopClosure : public Closure {
duke@435 57 public:
duke@435 58 ReferenceProcessor* _ref_processor;
duke@435 59 OopClosure(ReferenceProcessor* rp) : _ref_processor(rp) { }
duke@435 60 OopClosure() : _ref_processor(NULL) { }
duke@435 61 virtual void do_oop(oop* o) = 0;
duke@435 62 virtual void do_oop_v(oop* o) { do_oop(o); }
coleenp@548 63 virtual void do_oop(narrowOop* o) = 0;
coleenp@548 64 virtual void do_oop_v(narrowOop* o) { do_oop(o); }
duke@435 65
duke@435 66 // In support of post-processing of weak links of KlassKlass objects;
duke@435 67 // see KlassKlass::oop_oop_iterate().
jmasa@1370 68
jmasa@1370 69 virtual const bool should_remember_klasses() const {
jmasa@1370 70 assert(!must_remember_klasses(), "Should have overriden this method.");
jmasa@1370 71 return false;
jmasa@1370 72 }
jmasa@1370 73
duke@435 74 virtual void remember_klass(Klass* k) { /* do nothing */ }
duke@435 75
ysr@1376 76 // In support of post-processing of weak references in
ysr@1376 77 // ProfileData (MethodDataOop) objects; see, for example,
ysr@1376 78 // VirtualCallData::oop_iterate().
ysr@1376 79 virtual const bool should_remember_mdo() const { return false; }
ysr@1376 80 virtual void remember_mdo(DataLayout* v) { /* do nothing */ }
ysr@1376 81
duke@435 82 // The methods below control how object iterations invoking this closure
duke@435 83 // should be performed:
duke@435 84
duke@435 85 // If "true", invoke on header klass field.
duke@435 86 bool do_header() { return true; } // Note that this is non-virtual.
duke@435 87 // Controls how prefetching is done for invocations of this closure.
duke@435 88 Prefetch::style prefetch_style() { // Note that this is non-virtual.
duke@435 89 return Prefetch::do_none;
duke@435 90 }
ysr@777 91
ysr@777 92 // True iff this closure may be safely applied more than once to an oop
ysr@777 93 // location without an intervening "major reset" (like the end of a GC).
ysr@777 94 virtual bool idempotent() { return false; }
ysr@777 95 virtual bool apply_to_weak_ref_discovered_field() { return false; }
jmasa@1370 96
jmasa@1370 97 #ifdef ASSERT
jmasa@1370 98 static bool _must_remember_klasses;
jmasa@1370 99 static bool must_remember_klasses();
jmasa@1370 100 static void set_must_remember_klasses(bool v);
jmasa@1370 101 #endif
duke@435 102 };
duke@435 103
duke@435 104 // ObjectClosure is used for iterating through an object space
duke@435 105
ysr@777 106 class ObjectClosure : public Closure {
duke@435 107 public:
duke@435 108 // Called for each object.
duke@435 109 virtual void do_object(oop obj) = 0;
duke@435 110 };
duke@435 111
duke@435 112
duke@435 113 class BoolObjectClosure : public ObjectClosure {
duke@435 114 public:
duke@435 115 virtual bool do_object_b(oop obj) = 0;
duke@435 116 };
duke@435 117
duke@435 118 // Applies an oop closure to all ref fields in objects iterated over in an
duke@435 119 // object iteration.
duke@435 120 class ObjectToOopClosure: public ObjectClosure {
duke@435 121 OopClosure* _cl;
duke@435 122 public:
duke@435 123 void do_object(oop obj);
duke@435 124 ObjectToOopClosure(OopClosure* cl) : _cl(cl) {}
duke@435 125 };
duke@435 126
duke@435 127 // A version of ObjectClosure with "memory" (see _previous_address below)
duke@435 128 class UpwardsObjectClosure: public BoolObjectClosure {
duke@435 129 HeapWord* _previous_address;
duke@435 130 public:
duke@435 131 UpwardsObjectClosure() : _previous_address(NULL) { }
duke@435 132 void set_previous(HeapWord* addr) { _previous_address = addr; }
duke@435 133 HeapWord* previous() { return _previous_address; }
duke@435 134 // A return value of "true" can be used by the caller to decide
duke@435 135 // if this object's end should *NOT* be recorded in
duke@435 136 // _previous_address above.
duke@435 137 virtual bool do_object_bm(oop obj, MemRegion mr) = 0;
duke@435 138 };
duke@435 139
duke@435 140 // A version of ObjectClosure that is expected to be robust
duke@435 141 // in the face of possibly uninitialized objects.
duke@435 142 class ObjectClosureCareful : public ObjectClosure {
duke@435 143 public:
duke@435 144 virtual size_t do_object_careful_m(oop p, MemRegion mr) = 0;
duke@435 145 virtual size_t do_object_careful(oop p) = 0;
duke@435 146 };
duke@435 147
duke@435 148 // The following are used in CompactibleFreeListSpace and
duke@435 149 // ConcurrentMarkSweepGeneration.
duke@435 150
duke@435 151 // Blk closure (abstract class)
duke@435 152 class BlkClosure : public StackObj {
duke@435 153 public:
duke@435 154 virtual size_t do_blk(HeapWord* addr) = 0;
duke@435 155 };
duke@435 156
duke@435 157 // A version of BlkClosure that is expected to be robust
duke@435 158 // in the face of possibly uninitialized objects.
duke@435 159 class BlkClosureCareful : public BlkClosure {
duke@435 160 public:
duke@435 161 size_t do_blk(HeapWord* addr) {
duke@435 162 guarantee(false, "call do_blk_careful instead");
duke@435 163 return 0;
duke@435 164 }
duke@435 165 virtual size_t do_blk_careful(HeapWord* addr) = 0;
duke@435 166 };
duke@435 167
duke@435 168 // SpaceClosure is used for iterating over spaces
duke@435 169
duke@435 170 class Space;
duke@435 171 class CompactibleSpace;
duke@435 172
duke@435 173 class SpaceClosure : public StackObj {
duke@435 174 public:
duke@435 175 // Called for each space
duke@435 176 virtual void do_space(Space* s) = 0;
duke@435 177 };
duke@435 178
duke@435 179 class CompactibleSpaceClosure : public StackObj {
duke@435 180 public:
duke@435 181 // Called for each compactible space
duke@435 182 virtual void do_space(CompactibleSpace* s) = 0;
duke@435 183 };
duke@435 184
duke@435 185
jrose@1424 186 // CodeBlobClosure is used for iterating through code blobs
jrose@1424 187 // in the code cache or on thread stacks
jrose@1424 188
jrose@1424 189 class CodeBlobClosure : public Closure {
jrose@1424 190 public:
jrose@1424 191 // Called for each code blob.
jrose@1424 192 virtual void do_code_blob(CodeBlob* cb) = 0;
jrose@1424 193 };
jrose@1424 194
jrose@1424 195
jrose@1424 196 class MarkingCodeBlobClosure : public CodeBlobClosure {
jrose@1424 197 public:
jrose@1424 198 // Called for each code blob, but at most once per unique blob.
jrose@1429 199 virtual void do_newly_marked_nmethod(nmethod* nm) = 0;
jrose@1424 200
jrose@1424 201 virtual void do_code_blob(CodeBlob* cb);
jrose@1424 202 // = { if (!nmethod(cb)->test_set_oops_do_mark()) do_newly_marked_nmethod(cb); }
jrose@1424 203
jrose@1424 204 class MarkScope : public StackObj {
jrose@1424 205 protected:
jrose@1424 206 bool _active;
jrose@1424 207 public:
jrose@1424 208 MarkScope(bool activate = true);
jrose@1424 209 // = { if (active) nmethod::oops_do_marking_prologue(); }
jrose@1424 210 ~MarkScope();
jrose@1424 211 // = { if (active) nmethod::oops_do_marking_epilogue(); }
jrose@1424 212 };
jrose@1424 213 };
jrose@1424 214
jrose@1424 215
jrose@1424 216 // Applies an oop closure to all ref fields in code blobs
jrose@1424 217 // iterated over in an object iteration.
jrose@1424 218 class CodeBlobToOopClosure: public MarkingCodeBlobClosure {
jrose@1424 219 OopClosure* _cl;
jrose@1424 220 bool _do_marking;
jrose@1424 221 public:
jrose@1429 222 virtual void do_newly_marked_nmethod(nmethod* cb);
jrose@1424 223 // = { cb->oops_do(_cl); }
jrose@1424 224 virtual void do_code_blob(CodeBlob* cb);
jrose@1424 225 // = { if (_do_marking) super::do_code_blob(cb); else cb->oops_do(_cl); }
jrose@1424 226 CodeBlobToOopClosure(OopClosure* cl, bool do_marking)
jrose@1424 227 : _cl(cl), _do_marking(do_marking) {}
jrose@1424 228 };
jrose@1424 229
jrose@1424 230
duke@435 231
duke@435 232 // MonitorClosure is used for iterating over monitors in the monitors cache
duke@435 233
duke@435 234 class ObjectMonitor;
duke@435 235
duke@435 236 class MonitorClosure : public StackObj {
duke@435 237 public:
duke@435 238 // called for each monitor in cache
duke@435 239 virtual void do_monitor(ObjectMonitor* m) = 0;
duke@435 240 };
duke@435 241
duke@435 242 // A closure that is applied without any arguments.
duke@435 243 class VoidClosure : public StackObj {
duke@435 244 public:
duke@435 245 // I would have liked to declare this a pure virtual, but that breaks
duke@435 246 // in mysterious ways, for unknown reasons.
duke@435 247 virtual void do_void();
duke@435 248 };
duke@435 249
duke@435 250
duke@435 251 // YieldClosure is intended for use by iteration loops
duke@435 252 // to incrementalize their work, allowing interleaving
duke@435 253 // of an interruptable task so as to allow other
duke@435 254 // threads to run (which may not otherwise be able to access
duke@435 255 // exclusive resources, for instance). Additionally, the
duke@435 256 // closure also allows for aborting an ongoing iteration
duke@435 257 // by means of checking the return value from the polling
duke@435 258 // call.
duke@435 259 class YieldClosure : public StackObj {
duke@435 260 public:
duke@435 261 virtual bool should_return() = 0;
duke@435 262 };
duke@435 263
duke@435 264 // Abstract closure for serializing data (read or write).
duke@435 265
duke@435 266 class SerializeOopClosure : public OopClosure {
duke@435 267 public:
duke@435 268 // Return bool indicating whether closure implements read or write.
duke@435 269 virtual bool reading() const = 0;
duke@435 270
duke@435 271 // Read/write the int pointed to by i.
duke@435 272 virtual void do_int(int* i) = 0;
duke@435 273
duke@435 274 // Read/write the size_t pointed to by i.
duke@435 275 virtual void do_size_t(size_t* i) = 0;
duke@435 276
duke@435 277 // Read/write the void pointer pointed to by p.
duke@435 278 virtual void do_ptr(void** p) = 0;
duke@435 279
duke@435 280 // Read/write the HeapWord pointer pointed to be p.
duke@435 281 virtual void do_ptr(HeapWord** p) = 0;
duke@435 282
duke@435 283 // Read/write the region specified.
duke@435 284 virtual void do_region(u_char* start, size_t size) = 0;
duke@435 285
duke@435 286 // Check/write the tag. If reading, then compare the tag against
duke@435 287 // the passed in value and fail is they don't match. This allows
duke@435 288 // for verification that sections of the serialized data are of the
duke@435 289 // correct length.
duke@435 290 virtual void do_tag(int tag) = 0;
duke@435 291 };
jmasa@1370 292
coleenp@2497 293 class SymbolClosure : public StackObj {
coleenp@2497 294 public:
coleenp@2497 295 virtual void do_symbol(Symbol**) = 0;
coleenp@2497 296
coleenp@2497 297 // Clear LSB in symbol address; it can be set by CPSlot.
coleenp@2497 298 static Symbol* load_symbol(Symbol** p) {
coleenp@2497 299 return (Symbol*)(intptr_t(*p) & ~1);
coleenp@2497 300 }
coleenp@2497 301
coleenp@2497 302 // Store symbol, adjusting new pointer if the original pointer was adjusted
coleenp@2497 303 // (symbol references in constant pool slots have their LSB set to 1).
coleenp@2497 304 static void store_symbol(Symbol** p, Symbol* sym) {
coleenp@2497 305 *p = (Symbol*)(intptr_t(sym) | (intptr_t(*p) & 1));
coleenp@2497 306 }
coleenp@2497 307 };
coleenp@2497 308
jmasa@1370 309 #ifdef ASSERT
jmasa@1370 310 // This class is used to flag phases of a collection that
jmasa@1370 311 // can unload classes and which should override the
jmasa@1370 312 // should_remember_klasses() and remember_klass() of OopClosure.
jmasa@1370 313 // The _must_remember_klasses is set in the contructor and restored
jmasa@1370 314 // in the destructor. _must_remember_klasses is checked in assertions
jmasa@1370 315 // in the OopClosure implementations of should_remember_klasses() and
jmasa@1370 316 // remember_klass() and the expectation is that the OopClosure
jmasa@1370 317 // implementation should not be in use if _must_remember_klasses is set.
jmasa@1370 318 // Instances of RememberKlassesChecker can be place in
jmasa@1370 319 // marking phases of collections which can do class unloading.
jmasa@1370 320 // RememberKlassesChecker can be passed "false" to turn off checking.
jmasa@1370 321 // It is used by CMS when CMS yields to a different collector.
jmasa@1370 322 class RememberKlassesChecker: StackObj {
jmasa@1625 323 bool _saved_state;
jmasa@1625 324 bool _do_check;
jmasa@1370 325 public:
jmasa@1625 326 RememberKlassesChecker(bool checking_on) : _saved_state(false),
jmasa@1625 327 _do_check(true) {
jmasa@1625 328 // The ClassUnloading unloading flag affects the collectors except
jmasa@1625 329 // for CMS.
jmasa@1625 330 // CMS unloads classes if CMSClassUnloadingEnabled is true or
jmasa@1625 331 // if ExplicitGCInvokesConcurrentAndUnloadsClasses is true and
jmasa@1625 332 // the current collection is an explicit collection. Turning
jmasa@1625 333 // on the checking in general for
jmasa@1625 334 // ExplicitGCInvokesConcurrentAndUnloadsClasses and
jmasa@1625 335 // UseConcMarkSweepGC should not lead to false positives.
jmasa@1625 336 _do_check =
jmasa@1625 337 ClassUnloading && !UseConcMarkSweepGC ||
jmasa@1625 338 CMSClassUnloadingEnabled && UseConcMarkSweepGC ||
jmasa@1625 339 ExplicitGCInvokesConcurrentAndUnloadsClasses && UseConcMarkSweepGC;
jmasa@1625 340 if (_do_check) {
jmasa@1625 341 _saved_state = OopClosure::must_remember_klasses();
jmasa@1625 342 OopClosure::set_must_remember_klasses(checking_on);
jmasa@1370 343 }
jmasa@1370 344 }
jmasa@1370 345 ~RememberKlassesChecker() {
jmasa@1625 346 if (_do_check) {
jmasa@1625 347 OopClosure::set_must_remember_klasses(_saved_state);
jmasa@1370 348 }
jmasa@1370 349 }
jmasa@1370 350 };
jmasa@1370 351 #endif // ASSERT
stefank@2314 352
stefank@2314 353 #endif // SHARE_VM_MEMORY_ITERATOR_HPP

mercurial