1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/memory/iterator.hpp Sat Dec 01 00:00:00 2007 +0000 1.3 @@ -0,0 +1,200 @@ 1.4 +/* 1.5 + * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 1.24 + * have any questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +// The following classes are C++ `closures` for iterating over objects, roots and spaces 1.29 + 1.30 +class ReferenceProcessor; 1.31 + 1.32 +// OopClosure is used for iterating through roots (oop*) 1.33 + 1.34 +class OopClosure : public StackObj { 1.35 + public: 1.36 + ReferenceProcessor* _ref_processor; 1.37 + OopClosure(ReferenceProcessor* rp) : _ref_processor(rp) { } 1.38 + OopClosure() : _ref_processor(NULL) { } 1.39 + virtual void do_oop(oop* o) = 0; 1.40 + virtual void do_oop_v(oop* o) { do_oop(o); } 1.41 + 1.42 + // In support of post-processing of weak links of KlassKlass objects; 1.43 + // see KlassKlass::oop_oop_iterate(). 1.44 + virtual const bool should_remember_klasses() const { return false; } 1.45 + virtual void remember_klass(Klass* k) { /* do nothing */ } 1.46 + 1.47 + // If "true", invoke on nmethods (when scanning compiled frames). 1.48 + virtual const bool do_nmethods() const { return false; } 1.49 + 1.50 + // The methods below control how object iterations invoking this closure 1.51 + // should be performed: 1.52 + 1.53 + // If "true", invoke on header klass field. 1.54 + bool do_header() { return true; } // Note that this is non-virtual. 1.55 + // Controls how prefetching is done for invocations of this closure. 1.56 + Prefetch::style prefetch_style() { // Note that this is non-virtual. 1.57 + return Prefetch::do_none; 1.58 + } 1.59 +}; 1.60 + 1.61 +// ObjectClosure is used for iterating through an object space 1.62 + 1.63 +class ObjectClosure : public StackObj { 1.64 + public: 1.65 + // Called for each object. 1.66 + virtual void do_object(oop obj) = 0; 1.67 +}; 1.68 + 1.69 + 1.70 +class BoolObjectClosure : public ObjectClosure { 1.71 + public: 1.72 + virtual bool do_object_b(oop obj) = 0; 1.73 +}; 1.74 + 1.75 +// Applies an oop closure to all ref fields in objects iterated over in an 1.76 +// object iteration. 1.77 +class ObjectToOopClosure: public ObjectClosure { 1.78 + OopClosure* _cl; 1.79 +public: 1.80 + void do_object(oop obj); 1.81 + ObjectToOopClosure(OopClosure* cl) : _cl(cl) {} 1.82 +}; 1.83 + 1.84 +// A version of ObjectClosure with "memory" (see _previous_address below) 1.85 +class UpwardsObjectClosure: public BoolObjectClosure { 1.86 + HeapWord* _previous_address; 1.87 + public: 1.88 + UpwardsObjectClosure() : _previous_address(NULL) { } 1.89 + void set_previous(HeapWord* addr) { _previous_address = addr; } 1.90 + HeapWord* previous() { return _previous_address; } 1.91 + // A return value of "true" can be used by the caller to decide 1.92 + // if this object's end should *NOT* be recorded in 1.93 + // _previous_address above. 1.94 + virtual bool do_object_bm(oop obj, MemRegion mr) = 0; 1.95 +}; 1.96 + 1.97 +// A version of ObjectClosure that is expected to be robust 1.98 +// in the face of possibly uninitialized objects. 1.99 +class ObjectClosureCareful : public ObjectClosure { 1.100 + public: 1.101 + virtual size_t do_object_careful_m(oop p, MemRegion mr) = 0; 1.102 + virtual size_t do_object_careful(oop p) = 0; 1.103 +}; 1.104 + 1.105 +// The following are used in CompactibleFreeListSpace and 1.106 +// ConcurrentMarkSweepGeneration. 1.107 + 1.108 +// Blk closure (abstract class) 1.109 +class BlkClosure : public StackObj { 1.110 + public: 1.111 + virtual size_t do_blk(HeapWord* addr) = 0; 1.112 +}; 1.113 + 1.114 +// A version of BlkClosure that is expected to be robust 1.115 +// in the face of possibly uninitialized objects. 1.116 +class BlkClosureCareful : public BlkClosure { 1.117 + public: 1.118 + size_t do_blk(HeapWord* addr) { 1.119 + guarantee(false, "call do_blk_careful instead"); 1.120 + return 0; 1.121 + } 1.122 + virtual size_t do_blk_careful(HeapWord* addr) = 0; 1.123 +}; 1.124 + 1.125 +// SpaceClosure is used for iterating over spaces 1.126 + 1.127 +class Space; 1.128 +class CompactibleSpace; 1.129 + 1.130 +class SpaceClosure : public StackObj { 1.131 + public: 1.132 + // Called for each space 1.133 + virtual void do_space(Space* s) = 0; 1.134 +}; 1.135 + 1.136 +class CompactibleSpaceClosure : public StackObj { 1.137 + public: 1.138 + // Called for each compactible space 1.139 + virtual void do_space(CompactibleSpace* s) = 0; 1.140 +}; 1.141 + 1.142 + 1.143 + 1.144 +// MonitorClosure is used for iterating over monitors in the monitors cache 1.145 + 1.146 +class ObjectMonitor; 1.147 + 1.148 +class MonitorClosure : public StackObj { 1.149 + public: 1.150 + // called for each monitor in cache 1.151 + virtual void do_monitor(ObjectMonitor* m) = 0; 1.152 +}; 1.153 + 1.154 +// A closure that is applied without any arguments. 1.155 +class VoidClosure : public StackObj { 1.156 + public: 1.157 + // I would have liked to declare this a pure virtual, but that breaks 1.158 + // in mysterious ways, for unknown reasons. 1.159 + virtual void do_void(); 1.160 +}; 1.161 + 1.162 + 1.163 +// YieldClosure is intended for use by iteration loops 1.164 +// to incrementalize their work, allowing interleaving 1.165 +// of an interruptable task so as to allow other 1.166 +// threads to run (which may not otherwise be able to access 1.167 +// exclusive resources, for instance). Additionally, the 1.168 +// closure also allows for aborting an ongoing iteration 1.169 +// by means of checking the return value from the polling 1.170 +// call. 1.171 +class YieldClosure : public StackObj { 1.172 + public: 1.173 + virtual bool should_return() = 0; 1.174 +}; 1.175 + 1.176 +// Abstract closure for serializing data (read or write). 1.177 + 1.178 +class SerializeOopClosure : public OopClosure { 1.179 +public: 1.180 + // Return bool indicating whether closure implements read or write. 1.181 + virtual bool reading() const = 0; 1.182 + 1.183 + // Read/write the int pointed to by i. 1.184 + virtual void do_int(int* i) = 0; 1.185 + 1.186 + // Read/write the size_t pointed to by i. 1.187 + virtual void do_size_t(size_t* i) = 0; 1.188 + 1.189 + // Read/write the void pointer pointed to by p. 1.190 + virtual void do_ptr(void** p) = 0; 1.191 + 1.192 + // Read/write the HeapWord pointer pointed to be p. 1.193 + virtual void do_ptr(HeapWord** p) = 0; 1.194 + 1.195 + // Read/write the region specified. 1.196 + virtual void do_region(u_char* start, size_t size) = 0; 1.197 + 1.198 + // Check/write the tag. If reading, then compare the tag against 1.199 + // the passed in value and fail is they don't match. This allows 1.200 + // for verification that sections of the serialized data are of the 1.201 + // correct length. 1.202 + virtual void do_tag(int tag) = 0; 1.203 +};