src/share/vm/memory/iterator.hpp

Sun, 13 Apr 2008 17:43:42 -0400

author
coleenp
date
Sun, 13 Apr 2008 17:43:42 -0400
changeset 548
ba764ed4b6f2
parent 435
a61af66fc99e
child 631
d1605aabd0a1
child 777
37f87013dfd8
permissions
-rw-r--r--

6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
Summary: Compressed oops in instances, arrays, and headers. Code contributors are coleenp, phh, never, swamyv
Reviewed-by: jmasa, kamg, acorn, tbell, kvn, rasbold

duke@435 1 /*
duke@435 2 * Copyright 1997-2006 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;
duke@435 28
duke@435 29 // OopClosure is used for iterating through roots (oop*)
duke@435 30
duke@435 31 class OopClosure : public StackObj {
duke@435 32 public:
duke@435 33 ReferenceProcessor* _ref_processor;
duke@435 34 OopClosure(ReferenceProcessor* rp) : _ref_processor(rp) { }
duke@435 35 OopClosure() : _ref_processor(NULL) { }
duke@435 36 virtual void do_oop(oop* o) = 0;
duke@435 37 virtual void do_oop_v(oop* o) { do_oop(o); }
coleenp@548 38 virtual void do_oop(narrowOop* o) = 0;
coleenp@548 39 virtual void do_oop_v(narrowOop* o) { do_oop(o); }
duke@435 40
duke@435 41 // In support of post-processing of weak links of KlassKlass objects;
duke@435 42 // see KlassKlass::oop_oop_iterate().
duke@435 43 virtual const bool should_remember_klasses() const { return false; }
duke@435 44 virtual void remember_klass(Klass* k) { /* do nothing */ }
duke@435 45
duke@435 46 // If "true", invoke on nmethods (when scanning compiled frames).
duke@435 47 virtual const bool do_nmethods() const { return false; }
duke@435 48
duke@435 49 // The methods below control how object iterations invoking this closure
duke@435 50 // should be performed:
duke@435 51
duke@435 52 // If "true", invoke on header klass field.
duke@435 53 bool do_header() { return true; } // Note that this is non-virtual.
duke@435 54 // Controls how prefetching is done for invocations of this closure.
duke@435 55 Prefetch::style prefetch_style() { // Note that this is non-virtual.
duke@435 56 return Prefetch::do_none;
duke@435 57 }
duke@435 58 };
duke@435 59
duke@435 60 // ObjectClosure is used for iterating through an object space
duke@435 61
duke@435 62 class ObjectClosure : public StackObj {
duke@435 63 public:
duke@435 64 // Called for each object.
duke@435 65 virtual void do_object(oop obj) = 0;
duke@435 66 };
duke@435 67
duke@435 68
duke@435 69 class BoolObjectClosure : public ObjectClosure {
duke@435 70 public:
duke@435 71 virtual bool do_object_b(oop obj) = 0;
duke@435 72 };
duke@435 73
duke@435 74 // Applies an oop closure to all ref fields in objects iterated over in an
duke@435 75 // object iteration.
duke@435 76 class ObjectToOopClosure: public ObjectClosure {
duke@435 77 OopClosure* _cl;
duke@435 78 public:
duke@435 79 void do_object(oop obj);
duke@435 80 ObjectToOopClosure(OopClosure* cl) : _cl(cl) {}
duke@435 81 };
duke@435 82
duke@435 83 // A version of ObjectClosure with "memory" (see _previous_address below)
duke@435 84 class UpwardsObjectClosure: public BoolObjectClosure {
duke@435 85 HeapWord* _previous_address;
duke@435 86 public:
duke@435 87 UpwardsObjectClosure() : _previous_address(NULL) { }
duke@435 88 void set_previous(HeapWord* addr) { _previous_address = addr; }
duke@435 89 HeapWord* previous() { return _previous_address; }
duke@435 90 // A return value of "true" can be used by the caller to decide
duke@435 91 // if this object's end should *NOT* be recorded in
duke@435 92 // _previous_address above.
duke@435 93 virtual bool do_object_bm(oop obj, MemRegion mr) = 0;
duke@435 94 };
duke@435 95
duke@435 96 // A version of ObjectClosure that is expected to be robust
duke@435 97 // in the face of possibly uninitialized objects.
duke@435 98 class ObjectClosureCareful : public ObjectClosure {
duke@435 99 public:
duke@435 100 virtual size_t do_object_careful_m(oop p, MemRegion mr) = 0;
duke@435 101 virtual size_t do_object_careful(oop p) = 0;
duke@435 102 };
duke@435 103
duke@435 104 // The following are used in CompactibleFreeListSpace and
duke@435 105 // ConcurrentMarkSweepGeneration.
duke@435 106
duke@435 107 // Blk closure (abstract class)
duke@435 108 class BlkClosure : public StackObj {
duke@435 109 public:
duke@435 110 virtual size_t do_blk(HeapWord* addr) = 0;
duke@435 111 };
duke@435 112
duke@435 113 // A version of BlkClosure that is expected to be robust
duke@435 114 // in the face of possibly uninitialized objects.
duke@435 115 class BlkClosureCareful : public BlkClosure {
duke@435 116 public:
duke@435 117 size_t do_blk(HeapWord* addr) {
duke@435 118 guarantee(false, "call do_blk_careful instead");
duke@435 119 return 0;
duke@435 120 }
duke@435 121 virtual size_t do_blk_careful(HeapWord* addr) = 0;
duke@435 122 };
duke@435 123
duke@435 124 // SpaceClosure is used for iterating over spaces
duke@435 125
duke@435 126 class Space;
duke@435 127 class CompactibleSpace;
duke@435 128
duke@435 129 class SpaceClosure : public StackObj {
duke@435 130 public:
duke@435 131 // Called for each space
duke@435 132 virtual void do_space(Space* s) = 0;
duke@435 133 };
duke@435 134
duke@435 135 class CompactibleSpaceClosure : public StackObj {
duke@435 136 public:
duke@435 137 // Called for each compactible space
duke@435 138 virtual void do_space(CompactibleSpace* s) = 0;
duke@435 139 };
duke@435 140
duke@435 141
duke@435 142
duke@435 143 // MonitorClosure is used for iterating over monitors in the monitors cache
duke@435 144
duke@435 145 class ObjectMonitor;
duke@435 146
duke@435 147 class MonitorClosure : public StackObj {
duke@435 148 public:
duke@435 149 // called for each monitor in cache
duke@435 150 virtual void do_monitor(ObjectMonitor* m) = 0;
duke@435 151 };
duke@435 152
duke@435 153 // A closure that is applied without any arguments.
duke@435 154 class VoidClosure : public StackObj {
duke@435 155 public:
duke@435 156 // I would have liked to declare this a pure virtual, but that breaks
duke@435 157 // in mysterious ways, for unknown reasons.
duke@435 158 virtual void do_void();
duke@435 159 };
duke@435 160
duke@435 161
duke@435 162 // YieldClosure is intended for use by iteration loops
duke@435 163 // to incrementalize their work, allowing interleaving
duke@435 164 // of an interruptable task so as to allow other
duke@435 165 // threads to run (which may not otherwise be able to access
duke@435 166 // exclusive resources, for instance). Additionally, the
duke@435 167 // closure also allows for aborting an ongoing iteration
duke@435 168 // by means of checking the return value from the polling
duke@435 169 // call.
duke@435 170 class YieldClosure : public StackObj {
duke@435 171 public:
duke@435 172 virtual bool should_return() = 0;
duke@435 173 };
duke@435 174
duke@435 175 // Abstract closure for serializing data (read or write).
duke@435 176
duke@435 177 class SerializeOopClosure : public OopClosure {
duke@435 178 public:
duke@435 179 // Return bool indicating whether closure implements read or write.
duke@435 180 virtual bool reading() const = 0;
duke@435 181
duke@435 182 // Read/write the int pointed to by i.
duke@435 183 virtual void do_int(int* i) = 0;
duke@435 184
duke@435 185 // Read/write the size_t pointed to by i.
duke@435 186 virtual void do_size_t(size_t* i) = 0;
duke@435 187
duke@435 188 // Read/write the void pointer pointed to by p.
duke@435 189 virtual void do_ptr(void** p) = 0;
duke@435 190
duke@435 191 // Read/write the HeapWord pointer pointed to be p.
duke@435 192 virtual void do_ptr(HeapWord** p) = 0;
duke@435 193
duke@435 194 // Read/write the region specified.
duke@435 195 virtual void do_region(u_char* start, size_t size) = 0;
duke@435 196
duke@435 197 // Check/write the tag. If reading, then compare the tag against
duke@435 198 // the passed in value and fail is they don't match. This allows
duke@435 199 // for verification that sections of the serialized data are of the
duke@435 200 // correct length.
duke@435 201 virtual void do_tag(int tag) = 0;
duke@435 202 };

mercurial