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