src/share/vm/memory/iterator.hpp

Wed, 02 Jul 2008 12:55:16 -0700

author
xdono
date
Wed, 02 Jul 2008 12:55:16 -0700
changeset 631
d1605aabd0a1
parent 548
ba764ed4b6f2
child 791
1ee8caae33af
permissions
-rw-r--r--

6719955: Update copyright year
Summary: Update copyright year for files that have been modified in 2008
Reviewed-by: ohair, tbell

     1 /*
     2  * Copyright 1997-2008 Sun Microsystems, Inc.  All Rights Reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     8  *
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    12  * version 2 for more details (a copy is included in the LICENSE file that
    13  * accompanied this code).
    14  *
    15  * You should have received a copy of the GNU General Public License version
    16  * 2 along with this work; if not, write to the Free Software Foundation,
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    18  *
    19  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    20  * CA 95054 USA or visit www.sun.com if you need additional information or
    21  * have any questions.
    22  *
    23  */
    25 // The following classes are C++ `closures` for iterating over objects, roots and spaces
    27 class ReferenceProcessor;
    29 // OopClosure is used for iterating through roots (oop*)
    31 class OopClosure : public StackObj {
    32  public:
    33   ReferenceProcessor* _ref_processor;
    34   OopClosure(ReferenceProcessor* rp) : _ref_processor(rp) { }
    35   OopClosure() : _ref_processor(NULL) { }
    36   virtual void do_oop(oop* o) = 0;
    37   virtual void do_oop_v(oop* o) { do_oop(o); }
    38   virtual void do_oop(narrowOop* o) = 0;
    39   virtual void do_oop_v(narrowOop* o) { do_oop(o); }
    41   // In support of post-processing of weak links of KlassKlass objects;
    42   // see KlassKlass::oop_oop_iterate().
    43   virtual const bool should_remember_klasses() const { return false;    }
    44   virtual void remember_klass(Klass* k) { /* do nothing */ }
    46   // If "true", invoke on nmethods (when scanning compiled frames).
    47   virtual const bool do_nmethods() const { return false; }
    49   // The methods below control how object iterations invoking this closure
    50   // should be performed:
    52   // If "true", invoke on header klass field.
    53   bool do_header() { return true; } // Note that this is non-virtual.
    54   // Controls how prefetching is done for invocations of this closure.
    55   Prefetch::style prefetch_style() { // Note that this is non-virtual.
    56     return Prefetch::do_none;
    57   }
    58 };
    60 // ObjectClosure is used for iterating through an object space
    62 class ObjectClosure : public StackObj {
    63  public:
    64   // Called for each object.
    65   virtual void do_object(oop obj) = 0;
    66 };
    69 class BoolObjectClosure : public ObjectClosure {
    70  public:
    71   virtual bool do_object_b(oop obj) = 0;
    72 };
    74 // Applies an oop closure to all ref fields in objects iterated over in an
    75 // object iteration.
    76 class ObjectToOopClosure: public ObjectClosure {
    77   OopClosure* _cl;
    78 public:
    79   void do_object(oop obj);
    80   ObjectToOopClosure(OopClosure* cl) : _cl(cl) {}
    81 };
    83 // A version of ObjectClosure with "memory" (see _previous_address below)
    84 class UpwardsObjectClosure: public BoolObjectClosure {
    85   HeapWord* _previous_address;
    86  public:
    87   UpwardsObjectClosure() : _previous_address(NULL) { }
    88   void set_previous(HeapWord* addr) { _previous_address = addr; }
    89   HeapWord* previous()              { return _previous_address; }
    90   // A return value of "true" can be used by the caller to decide
    91   // if this object's end should *NOT* be recorded in
    92   // _previous_address above.
    93   virtual bool do_object_bm(oop obj, MemRegion mr) = 0;
    94 };
    96 // A version of ObjectClosure that is expected to be robust
    97 // in the face of possibly uninitialized objects.
    98 class ObjectClosureCareful : public ObjectClosure {
    99  public:
   100   virtual size_t do_object_careful_m(oop p, MemRegion mr) = 0;
   101   virtual size_t do_object_careful(oop p) = 0;
   102 };
   104 // The following are used in CompactibleFreeListSpace and
   105 // ConcurrentMarkSweepGeneration.
   107 // Blk closure (abstract class)
   108 class BlkClosure : public StackObj {
   109  public:
   110   virtual size_t do_blk(HeapWord* addr) = 0;
   111 };
   113 // A version of BlkClosure that is expected to be robust
   114 // in the face of possibly uninitialized objects.
   115 class BlkClosureCareful : public BlkClosure {
   116  public:
   117   size_t do_blk(HeapWord* addr) {
   118     guarantee(false, "call do_blk_careful instead");
   119     return 0;
   120   }
   121   virtual size_t do_blk_careful(HeapWord* addr) = 0;
   122 };
   124 // SpaceClosure is used for iterating over spaces
   126 class Space;
   127 class CompactibleSpace;
   129 class SpaceClosure : public StackObj {
   130  public:
   131   // Called for each space
   132   virtual void do_space(Space* s) = 0;
   133 };
   135 class CompactibleSpaceClosure : public StackObj {
   136  public:
   137   // Called for each compactible space
   138   virtual void do_space(CompactibleSpace* s) = 0;
   139 };
   143 // MonitorClosure is used for iterating over monitors in the monitors cache
   145 class ObjectMonitor;
   147 class MonitorClosure : public StackObj {
   148  public:
   149   // called for each monitor in cache
   150   virtual void do_monitor(ObjectMonitor* m) = 0;
   151 };
   153 // A closure that is applied without any arguments.
   154 class VoidClosure : public StackObj {
   155  public:
   156   // I would have liked to declare this a pure virtual, but that breaks
   157   // in mysterious ways, for unknown reasons.
   158   virtual void do_void();
   159 };
   162 // YieldClosure is intended for use by iteration loops
   163 // to incrementalize their work, allowing interleaving
   164 // of an interruptable task so as to allow other
   165 // threads to run (which may not otherwise be able to access
   166 // exclusive resources, for instance). Additionally, the
   167 // closure also allows for aborting an ongoing iteration
   168 // by means of checking the return value from the polling
   169 // call.
   170 class YieldClosure : public StackObj {
   171   public:
   172    virtual bool should_return() = 0;
   173 };
   175 // Abstract closure for serializing data (read or write).
   177 class SerializeOopClosure : public OopClosure {
   178 public:
   179   // Return bool indicating whether closure implements read or write.
   180   virtual bool reading() const = 0;
   182   // Read/write the int pointed to by i.
   183   virtual void do_int(int* i) = 0;
   185   // Read/write the size_t pointed to by i.
   186   virtual void do_size_t(size_t* i) = 0;
   188   // Read/write the void pointer pointed to by p.
   189   virtual void do_ptr(void** p) = 0;
   191   // Read/write the HeapWord pointer pointed to be p.
   192   virtual void do_ptr(HeapWord** p) = 0;
   194   // Read/write the region specified.
   195   virtual void do_region(u_char* start, size_t size) = 0;
   197   // Check/write the tag.  If reading, then compare the tag against
   198   // the passed in value and fail is they don't match.  This allows
   199   // for verification that sections of the serialized data are of the
   200   // correct length.
   201   virtual void do_tag(int tag) = 0;
   202 };

mercurial