hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/cmsOopClosures.hpp
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 1 489c9b5090e2
child 360 21d113ecbf6a
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
     2
 * Copyright (c) 2007 Sun Microsystems, Inc.  All Rights Reserved.
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
/////////////////////////////////////////////////////////////////
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
// Closures used by ConcurrentMarkSweepGeneration's collector
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
/////////////////////////////////////////////////////////////////
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
class ConcurrentMarkSweepGeneration;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
class CMSBitMap;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
class CMSMarkStack;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
class CMSCollector;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
template<class E> class GenericTaskQueue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
typedef GenericTaskQueue<oop> OopTaskQueue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
template<class E> class GenericTaskQueueSet;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
typedef GenericTaskQueueSet<oop> OopTaskQueueSet;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
class MarkFromRootsClosure;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
class Par_MarkFromRootsClosure;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
class MarkRefsIntoClosure: public OopsInGenClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  const MemRegion    _span;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  CMSBitMap*         _bitMap;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  const bool         _should_do_nmethods;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  MarkRefsIntoClosure(MemRegion span, CMSBitMap* bitMap,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
                      bool should_do_nmethods);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  void do_oop(oop* p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  void do_oop_nv(oop* p) { MarkRefsIntoClosure::do_oop(p); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  bool do_header() { return true; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  virtual const bool do_nmethods() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
    return _should_do_nmethods;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  Prefetch::style prefetch_style() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
    return Prefetch::do_read;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
// A variant of the above used in certain kinds of CMS
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
// marking verification.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
class MarkRefsIntoVerifyClosure: public OopsInGenClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  const MemRegion    _span;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  CMSBitMap*         _verification_bm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  CMSBitMap*         _cms_bm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  const bool         _should_do_nmethods;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  MarkRefsIntoVerifyClosure(MemRegion span, CMSBitMap* verification_bm,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
                            CMSBitMap* cms_bm, bool should_do_nmethods);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  void do_oop(oop* p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  void do_oop_nv(oop* p) { MarkRefsIntoVerifyClosure::do_oop(p); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  bool do_header() { return true; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  virtual const bool do_nmethods() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
    return _should_do_nmethods;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  Prefetch::style prefetch_style() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
    return Prefetch::do_read;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
// The non-parallel version (the parallel version appears further below).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
class PushAndMarkClosure: public OopClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  CMSCollector*    _collector;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  MemRegion        _span;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  CMSBitMap*       _bit_map;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  CMSBitMap*       _mod_union_table;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  CMSMarkStack*    _mark_stack;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  CMSMarkStack*    _revisit_stack;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  bool             _concurrent_precleaning;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  bool     const   _should_remember_klasses;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  PushAndMarkClosure(CMSCollector* collector,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
                     MemRegion span,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
                     ReferenceProcessor* rp,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
                     CMSBitMap* bit_map,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
                     CMSBitMap* mod_union_table,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
                     CMSMarkStack*  mark_stack,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
                     CMSMarkStack*  revisit_stack,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
                     bool           concurrent_precleaning);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  void do_oop(oop* p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  void do_oop_nv(oop* p)  { PushAndMarkClosure::do_oop(p); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  bool do_header() { return true; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  Prefetch::style prefetch_style() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
    return Prefetch::do_read;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  const bool should_remember_klasses() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
    return _should_remember_klasses;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  void remember_klass(Klass* k);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
// In the parallel case, the revisit stack, the bit map and the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
// reference processor are currently all shared. Access to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
// these shared mutable structures must use appropriate
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
// synchronization (for instance, via CAS). The marking stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
// used in the non-parallel case above is here replaced with
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
// an OopTaskQueue structure to allow efficient work stealing.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
class Par_PushAndMarkClosure: public OopClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  CMSCollector*    _collector;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  MemRegion        _span;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  CMSBitMap*       _bit_map;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  OopTaskQueue*    _work_queue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  CMSMarkStack*    _revisit_stack;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  bool     const   _should_remember_klasses;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  Par_PushAndMarkClosure(CMSCollector* collector,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
                         MemRegion span,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
                         ReferenceProcessor* rp,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
                         CMSBitMap* bit_map,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
                         OopTaskQueue* work_queue,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
                         CMSMarkStack* revisit_stack);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  void do_oop(oop* p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  void do_oop_nv(oop* p)  { Par_PushAndMarkClosure::do_oop(p); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  bool do_header() { return true; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  Prefetch::style prefetch_style() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
    return Prefetch::do_read;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  const bool should_remember_klasses() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
    return _should_remember_klasses;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  void remember_klass(Klass* k);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
// The non-parallel version (the parallel version appears further below).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
class MarkRefsIntoAndScanClosure: public OopsInGenClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  MemRegion                  _span;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  CMSBitMap*                 _bit_map;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  CMSMarkStack*              _mark_stack;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  PushAndMarkClosure         _pushAndMarkClosure;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  CMSCollector*              _collector;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  bool                       _yield;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  // Whether closure is being used for concurrent precleaning
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  bool                       _concurrent_precleaning;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  Mutex*                     _freelistLock;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  MarkRefsIntoAndScanClosure(MemRegion span,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
                             ReferenceProcessor* rp,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
                             CMSBitMap* bit_map,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
                             CMSBitMap* mod_union_table,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
                             CMSMarkStack*  mark_stack,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
                             CMSMarkStack*  revisit_stack,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
                             CMSCollector* collector,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
                             bool should_yield,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
                             bool concurrent_precleaning);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
  void do_oop(oop* p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
  void do_oop_nv(oop* p) { MarkRefsIntoAndScanClosure::do_oop(p); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  bool do_header() { return true; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  virtual const bool do_nmethods() const { return true; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
  Prefetch::style prefetch_style() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
    return Prefetch::do_read;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  void set_freelistLock(Mutex* m) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
    _freelistLock = m;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
  inline void do_yield_check();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
  void do_yield_work();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
  bool take_from_overflow_list();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
// Tn this, the parallel avatar of MarkRefsIntoAndScanClosure, the revisit
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
// stack and the bitMap are shared, so access needs to be suitably
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
// sycnhronized. An OopTaskQueue structure, supporting efficient
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
// workstealing, replaces a CMSMarkStack for storing grey objects.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
class Par_MarkRefsIntoAndScanClosure: public OopsInGenClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
  MemRegion                      _span;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
  CMSBitMap*                     _bit_map;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  OopTaskQueue*                  _work_queue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
  const uint                     _low_water_mark;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
  Par_PushAndMarkClosure         _par_pushAndMarkClosure;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
  Par_MarkRefsIntoAndScanClosure(CMSCollector* collector,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
                                 MemRegion span,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
                                 ReferenceProcessor* rp,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
                                 CMSBitMap* bit_map,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
                                 OopTaskQueue* work_queue,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
                                 CMSMarkStack*  revisit_stack);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
  void do_oop(oop* p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
  void do_oop_nv(oop* p) { Par_MarkRefsIntoAndScanClosure::do_oop(p); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
  bool do_header() { return true; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
  virtual const bool do_nmethods() const { return true; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
  Prefetch::style prefetch_style() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
    return Prefetch::do_read;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
  void trim_queue(uint size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
// This closure is used during the concurrent marking phase
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
// following the first checkpoint. Its use is buried in
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
// the closure MarkFromRootsClosure.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
class PushOrMarkClosure: public OopClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
  CMSCollector*    _collector;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
  MemRegion        _span;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
  CMSBitMap*       _bitMap;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
  CMSMarkStack*    _markStack;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
  CMSMarkStack*    _revisitStack;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
  HeapWord* const  _finger;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
  MarkFromRootsClosure* const _parent;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
  bool                  const _should_remember_klasses;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
  PushOrMarkClosure(CMSCollector* cms_collector,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
                    MemRegion span,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
                    CMSBitMap* bitMap,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
                    CMSMarkStack*  markStack,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
                    CMSMarkStack*  revisitStack,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
                    HeapWord*      finger,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
                    MarkFromRootsClosure* parent);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
  void do_oop(oop* p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
  void do_oop_nv(oop* p)  { PushOrMarkClosure::do_oop(p); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
  const bool should_remember_klasses() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
    return _should_remember_klasses;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
  void remember_klass(Klass* k);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
  // Deal with a stack overflow condition
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
  void handle_stack_overflow(HeapWord* lost);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
  inline void do_yield_check();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
// A parallel (MT) version of the above.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
// This closure is used during the concurrent marking phase
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
// following the first checkpoint. Its use is buried in
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
// the closure Par_MarkFromRootsClosure.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
class Par_PushOrMarkClosure: public OopClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
  CMSCollector*    _collector;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
  MemRegion        _whole_span;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
  MemRegion        _span;        // local chunk
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
  CMSBitMap*       _bit_map;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
  OopTaskQueue*    _work_queue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
  CMSMarkStack*    _overflow_stack;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
  CMSMarkStack*    _revisit_stack;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
  HeapWord*  const _finger;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
  HeapWord** const _global_finger_addr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
  Par_MarkFromRootsClosure* const _parent;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
  bool       const _should_remember_klasses;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
  Par_PushOrMarkClosure(CMSCollector* cms_collector,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
                    MemRegion span,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
                    CMSBitMap* bit_map,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
                    OopTaskQueue* work_queue,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
                    CMSMarkStack*  mark_stack,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
                    CMSMarkStack*  revisit_stack,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
                    HeapWord*      finger,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
                    HeapWord**     global_finger_addr,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
                    Par_MarkFromRootsClosure* parent);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
  void do_oop(oop* p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
  void do_oop_nv(oop* p)  { Par_PushOrMarkClosure::do_oop(p); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
  const bool should_remember_klasses() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
    return _should_remember_klasses;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
  void remember_klass(Klass* k);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
  // Deal with a stack overflow condition
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
  void handle_stack_overflow(HeapWord* lost);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
  inline void do_yield_check();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
// For objects in CMS generation, this closure marks
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
// given objects (transitively) as being reachable/live.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
// This is currently used during the (weak) reference object
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
// processing phase of the CMS final checkpoint step.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
class CMSKeepAliveClosure: public OopClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
  CMSCollector* _collector;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
  MemRegion     _span;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
  CMSMarkStack* _mark_stack;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
  CMSBitMap*    _bit_map;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
  CMSKeepAliveClosure(CMSCollector* collector, MemRegion span,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
                      CMSBitMap* bit_map, CMSMarkStack* mark_stack):
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
    _collector(collector),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
    _span(span),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
    _bit_map(bit_map),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
    _mark_stack(mark_stack) { }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
  void do_oop(oop* p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
  void do_oop_nv(oop* p) { CMSKeepAliveClosure::do_oop(p); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
class CMSInnerParMarkAndPushClosure: public OopClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
  CMSCollector* _collector;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
  MemRegion     _span;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
  OopTaskQueue* _work_queue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
  CMSBitMap*    _bit_map;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
  CMSInnerParMarkAndPushClosure(CMSCollector* collector,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
                                MemRegion span, CMSBitMap* bit_map,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
                                OopTaskQueue* work_queue):
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
    _collector(collector),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
    _span(span),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
    _bit_map(bit_map),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
    _work_queue(work_queue) { }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
  void do_oop(oop* p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
  void do_oop_nv(oop* p) { CMSInnerParMarkAndPushClosure::do_oop(p); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
// A parallel (MT) version of the above, used when
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
// reference processing is parallel; the only difference
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
// is in the do_oop method.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
class CMSParKeepAliveClosure: public OopClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
  CMSCollector* _collector;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
  MemRegion     _span;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
  OopTaskQueue* _work_queue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
  CMSBitMap*    _bit_map;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
  CMSInnerParMarkAndPushClosure _mark_and_push;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
  const uint    _low_water_mark;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
  void trim_queue(uint max);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
  CMSParKeepAliveClosure(CMSCollector* collector, MemRegion span,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
                         CMSBitMap* bit_map, OopTaskQueue* work_queue);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
  void do_oop(oop* p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
  void do_oop_nv(oop* p) { CMSParKeepAliveClosure::do_oop(p); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
};