src/share/vm/memory/iterator.hpp

Wed, 02 Sep 2009 00:04:29 -0700

author
ysr
date
Wed, 02 Sep 2009 00:04:29 -0700
changeset 1376
8b46c4d82093
parent 1370
05f89f00a864
child 1383
89e0543e1737
child 1428
54b3b351d6f9
permissions
-rw-r--r--

4957990: Perm heap bloat in JVM
Summary: Treat ProfileData in MDO's as a source of weak, not strong, roots. Fixes the bug for stop-world collection -- the case of concurrent collection will be fixed separately.
Reviewed-by: jcoomes, jmasa, kvn, never

duke@435 1 /*
xdono@631 2 * Copyright 1997-2008 Sun Microsystems, Inc. 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 *
duke@435 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@435 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@435 21 * have any questions.
duke@435 22 *
duke@435 23 */
duke@435 24
duke@435 25 // The following classes are C++ `closures` for iterating over objects, roots and spaces
duke@435 26
duke@435 27 class ReferenceProcessor;
ysr@1376 28 class DataLayout;
duke@435 29
ysr@777 30 // Closure provides abortability.
ysr@777 31
ysr@777 32 class Closure : public StackObj {
ysr@777 33 protected:
ysr@777 34 bool _abort;
ysr@777 35 void set_abort() { _abort = true; }
ysr@777 36 public:
ysr@777 37 Closure() : _abort(false) {}
ysr@777 38 // A subtype can use this mechanism to indicate to some iterator mapping
ysr@777 39 // functions that the iteration should cease.
ysr@777 40 bool abort() { return _abort; }
ysr@777 41 void clear_abort() { _abort = false; }
ysr@777 42 };
ysr@777 43
duke@435 44 // OopClosure is used for iterating through roots (oop*)
duke@435 45
ysr@777 46 class OopClosure : public Closure {
duke@435 47 public:
duke@435 48 ReferenceProcessor* _ref_processor;
duke@435 49 OopClosure(ReferenceProcessor* rp) : _ref_processor(rp) { }
duke@435 50 OopClosure() : _ref_processor(NULL) { }
duke@435 51 virtual void do_oop(oop* o) = 0;
duke@435 52 virtual void do_oop_v(oop* o) { do_oop(o); }
coleenp@548 53 virtual void do_oop(narrowOop* o) = 0;
coleenp@548 54 virtual void do_oop_v(narrowOop* o) { do_oop(o); }
duke@435 55
duke@435 56 // In support of post-processing of weak links of KlassKlass objects;
duke@435 57 // see KlassKlass::oop_oop_iterate().
jmasa@1370 58
jmasa@1370 59 virtual const bool should_remember_klasses() const {
jmasa@1370 60 assert(!must_remember_klasses(), "Should have overriden this method.");
jmasa@1370 61 return false;
jmasa@1370 62 }
jmasa@1370 63
duke@435 64 virtual void remember_klass(Klass* k) { /* do nothing */ }
duke@435 65
ysr@1376 66 // In support of post-processing of weak references in
ysr@1376 67 // ProfileData (MethodDataOop) objects; see, for example,
ysr@1376 68 // VirtualCallData::oop_iterate().
ysr@1376 69 virtual const bool should_remember_mdo() const { return false; }
ysr@1376 70 virtual void remember_mdo(DataLayout* v) { /* do nothing */ }
ysr@1376 71
duke@435 72 // If "true", invoke on nmethods (when scanning compiled frames).
duke@435 73 virtual const bool do_nmethods() const { return false; }
duke@435 74
duke@435 75 // The methods below control how object iterations invoking this closure
duke@435 76 // should be performed:
duke@435 77
duke@435 78 // If "true", invoke on header klass field.
duke@435 79 bool do_header() { return true; } // Note that this is non-virtual.
duke@435 80 // Controls how prefetching is done for invocations of this closure.
duke@435 81 Prefetch::style prefetch_style() { // Note that this is non-virtual.
duke@435 82 return Prefetch::do_none;
duke@435 83 }
ysr@777 84
ysr@777 85 // True iff this closure may be safely applied more than once to an oop
ysr@777 86 // location without an intervening "major reset" (like the end of a GC).
ysr@777 87 virtual bool idempotent() { return false; }
ysr@777 88 virtual bool apply_to_weak_ref_discovered_field() { return false; }
jmasa@1370 89
jmasa@1370 90 #ifdef ASSERT
jmasa@1370 91 static bool _must_remember_klasses;
jmasa@1370 92 static bool must_remember_klasses();
jmasa@1370 93 static void set_must_remember_klasses(bool v);
jmasa@1370 94 #endif
duke@435 95 };
duke@435 96
duke@435 97 // ObjectClosure is used for iterating through an object space
duke@435 98
ysr@777 99 class ObjectClosure : public Closure {
duke@435 100 public:
duke@435 101 // Called for each object.
duke@435 102 virtual void do_object(oop obj) = 0;
duke@435 103 };
duke@435 104
duke@435 105
duke@435 106 class BoolObjectClosure : public ObjectClosure {
duke@435 107 public:
duke@435 108 virtual bool do_object_b(oop obj) = 0;
duke@435 109 };
duke@435 110
duke@435 111 // Applies an oop closure to all ref fields in objects iterated over in an
duke@435 112 // object iteration.
duke@435 113 class ObjectToOopClosure: public ObjectClosure {
duke@435 114 OopClosure* _cl;
duke@435 115 public:
duke@435 116 void do_object(oop obj);
duke@435 117 ObjectToOopClosure(OopClosure* cl) : _cl(cl) {}
duke@435 118 };
duke@435 119
duke@435 120 // A version of ObjectClosure with "memory" (see _previous_address below)
duke@435 121 class UpwardsObjectClosure: public BoolObjectClosure {
duke@435 122 HeapWord* _previous_address;
duke@435 123 public:
duke@435 124 UpwardsObjectClosure() : _previous_address(NULL) { }
duke@435 125 void set_previous(HeapWord* addr) { _previous_address = addr; }
duke@435 126 HeapWord* previous() { return _previous_address; }
duke@435 127 // A return value of "true" can be used by the caller to decide
duke@435 128 // if this object's end should *NOT* be recorded in
duke@435 129 // _previous_address above.
duke@435 130 virtual bool do_object_bm(oop obj, MemRegion mr) = 0;
duke@435 131 };
duke@435 132
duke@435 133 // A version of ObjectClosure that is expected to be robust
duke@435 134 // in the face of possibly uninitialized objects.
duke@435 135 class ObjectClosureCareful : public ObjectClosure {
duke@435 136 public:
duke@435 137 virtual size_t do_object_careful_m(oop p, MemRegion mr) = 0;
duke@435 138 virtual size_t do_object_careful(oop p) = 0;
duke@435 139 };
duke@435 140
duke@435 141 // The following are used in CompactibleFreeListSpace and
duke@435 142 // ConcurrentMarkSweepGeneration.
duke@435 143
duke@435 144 // Blk closure (abstract class)
duke@435 145 class BlkClosure : public StackObj {
duke@435 146 public:
duke@435 147 virtual size_t do_blk(HeapWord* addr) = 0;
duke@435 148 };
duke@435 149
duke@435 150 // A version of BlkClosure that is expected to be robust
duke@435 151 // in the face of possibly uninitialized objects.
duke@435 152 class BlkClosureCareful : public BlkClosure {
duke@435 153 public:
duke@435 154 size_t do_blk(HeapWord* addr) {
duke@435 155 guarantee(false, "call do_blk_careful instead");
duke@435 156 return 0;
duke@435 157 }
duke@435 158 virtual size_t do_blk_careful(HeapWord* addr) = 0;
duke@435 159 };
duke@435 160
duke@435 161 // SpaceClosure is used for iterating over spaces
duke@435 162
duke@435 163 class Space;
duke@435 164 class CompactibleSpace;
duke@435 165
duke@435 166 class SpaceClosure : public StackObj {
duke@435 167 public:
duke@435 168 // Called for each space
duke@435 169 virtual void do_space(Space* s) = 0;
duke@435 170 };
duke@435 171
duke@435 172 class CompactibleSpaceClosure : public StackObj {
duke@435 173 public:
duke@435 174 // Called for each compactible space
duke@435 175 virtual void do_space(CompactibleSpace* s) = 0;
duke@435 176 };
duke@435 177
duke@435 178
duke@435 179
duke@435 180 // MonitorClosure is used for iterating over monitors in the monitors cache
duke@435 181
duke@435 182 class ObjectMonitor;
duke@435 183
duke@435 184 class MonitorClosure : public StackObj {
duke@435 185 public:
duke@435 186 // called for each monitor in cache
duke@435 187 virtual void do_monitor(ObjectMonitor* m) = 0;
duke@435 188 };
duke@435 189
duke@435 190 // A closure that is applied without any arguments.
duke@435 191 class VoidClosure : public StackObj {
duke@435 192 public:
duke@435 193 // I would have liked to declare this a pure virtual, but that breaks
duke@435 194 // in mysterious ways, for unknown reasons.
duke@435 195 virtual void do_void();
duke@435 196 };
duke@435 197
duke@435 198
duke@435 199 // YieldClosure is intended for use by iteration loops
duke@435 200 // to incrementalize their work, allowing interleaving
duke@435 201 // of an interruptable task so as to allow other
duke@435 202 // threads to run (which may not otherwise be able to access
duke@435 203 // exclusive resources, for instance). Additionally, the
duke@435 204 // closure also allows for aborting an ongoing iteration
duke@435 205 // by means of checking the return value from the polling
duke@435 206 // call.
duke@435 207 class YieldClosure : public StackObj {
duke@435 208 public:
duke@435 209 virtual bool should_return() = 0;
duke@435 210 };
duke@435 211
duke@435 212 // Abstract closure for serializing data (read or write).
duke@435 213
duke@435 214 class SerializeOopClosure : public OopClosure {
duke@435 215 public:
duke@435 216 // Return bool indicating whether closure implements read or write.
duke@435 217 virtual bool reading() const = 0;
duke@435 218
duke@435 219 // Read/write the int pointed to by i.
duke@435 220 virtual void do_int(int* i) = 0;
duke@435 221
duke@435 222 // Read/write the size_t pointed to by i.
duke@435 223 virtual void do_size_t(size_t* i) = 0;
duke@435 224
duke@435 225 // Read/write the void pointer pointed to by p.
duke@435 226 virtual void do_ptr(void** p) = 0;
duke@435 227
duke@435 228 // Read/write the HeapWord pointer pointed to be p.
duke@435 229 virtual void do_ptr(HeapWord** p) = 0;
duke@435 230
duke@435 231 // Read/write the region specified.
duke@435 232 virtual void do_region(u_char* start, size_t size) = 0;
duke@435 233
duke@435 234 // Check/write the tag. If reading, then compare the tag against
duke@435 235 // the passed in value and fail is they don't match. This allows
duke@435 236 // for verification that sections of the serialized data are of the
duke@435 237 // correct length.
duke@435 238 virtual void do_tag(int tag) = 0;
duke@435 239 };
jmasa@1370 240
jmasa@1370 241 #ifdef ASSERT
jmasa@1370 242 // This class is used to flag phases of a collection that
jmasa@1370 243 // can unload classes and which should override the
jmasa@1370 244 // should_remember_klasses() and remember_klass() of OopClosure.
jmasa@1370 245 // The _must_remember_klasses is set in the contructor and restored
jmasa@1370 246 // in the destructor. _must_remember_klasses is checked in assertions
jmasa@1370 247 // in the OopClosure implementations of should_remember_klasses() and
jmasa@1370 248 // remember_klass() and the expectation is that the OopClosure
jmasa@1370 249 // implementation should not be in use if _must_remember_klasses is set.
jmasa@1370 250 // Instances of RememberKlassesChecker can be place in
jmasa@1370 251 // marking phases of collections which can do class unloading.
jmasa@1370 252 // RememberKlassesChecker can be passed "false" to turn off checking.
jmasa@1370 253 // It is used by CMS when CMS yields to a different collector.
jmasa@1370 254 class RememberKlassesChecker: StackObj {
jmasa@1370 255 bool _state;
jmasa@1370 256 bool _skip;
jmasa@1370 257 public:
jmasa@1370 258 RememberKlassesChecker(bool checking_on) : _state(false), _skip(false) {
jmasa@1370 259 _skip = !(ClassUnloading && !UseConcMarkSweepGC ||
jmasa@1370 260 CMSClassUnloadingEnabled && UseConcMarkSweepGC);
jmasa@1370 261 if (_skip) {
jmasa@1370 262 return;
jmasa@1370 263 }
jmasa@1370 264 _state = OopClosure::must_remember_klasses();
jmasa@1370 265 OopClosure::set_must_remember_klasses(checking_on);
jmasa@1370 266 }
jmasa@1370 267 ~RememberKlassesChecker() {
jmasa@1370 268 if (_skip) {
jmasa@1370 269 return;
jmasa@1370 270 }
jmasa@1370 271 OopClosure::set_must_remember_klasses(_state);
jmasa@1370 272 }
jmasa@1370 273 };
jmasa@1370 274 #endif // ASSERT

mercurial