src/share/vm/memory/iterator.hpp

Mon, 23 Jun 2008 16:49:37 -0700

author
ysr
date
Mon, 23 Jun 2008 16:49:37 -0700
changeset 782
60fb9c4db4e6
parent 777
37f87013dfd8
child 791
1ee8caae33af
permissions
-rw-r--r--

6718086: CMS assert: _concurrent_iteration_safe_limit update missed
Summary: Initialize the field correctly in ContiguousSpace's constructor and initialize() methods, using the latter for the survivor spaces upon initial construction or a subsequent resizing of the young generation. Add some missing Space sub-class constructors.
Reviewed-by: apetrusenko

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

mercurial