hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.hpp
author trims
Thu, 27 May 2010 19:08:38 -0700
changeset 5547 f4b087cbb361
parent 5343 95a5c4b89273
child 6245 c37d2cf6de1a
permissions -rw-r--r--
6941466: Oracle rebranding changes for Hotspot repositories Summary: Change all the Sun copyrights to Oracle copyright Reviewed-by: ohair
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5343
diff changeset
     2
 * Copyright (c) 2001, 2010, Oracle and/or its affiliates. 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
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5343
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5343
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5343
diff changeset
    21
 * questions.
1
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
// ConcurrentMarkSweepGeneration is in support of a concurrent
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
// mark-sweep old generation in the Detlefs-Printezis--Boehm-Demers-Schenker
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
// style. We assume, for now, that this generation is always the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
// seniormost generation (modulo the PermGeneration), and for simplicity
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
// in the first implementation, that this generation is a single compactible
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
// space. Neither of these restrictions appears essential, and will be
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
// relaxed in the future when more time is available to implement the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
// greater generality (and there's a need for it).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
// Concurrent mode failures are currently handled by
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
// means of a sliding mark-compact.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
class CMSAdaptiveSizePolicy;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
class CMSConcMarkingTask;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
class CMSGCAdaptivePolicyCounters;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
class ConcurrentMarkSweepGeneration;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
class ConcurrentMarkSweepPolicy;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
class ConcurrentMarkSweepThread;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
class CompactibleFreeListSpace;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
class FreeChunk;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
class PromotionInfo;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
class ScanMarkedObjectsAgainCarefullyClosure;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
// A generic CMS bit map. It's the basis for both the CMS marking bit map
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
// as well as for the mod union table (in each case only a subset of the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
// methods are used). This is essentially a wrapper around the BitMap class,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
// with one bit per (1<<_shifter) HeapWords. (i.e. for the marking bit map,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
// we have _shifter == 0. and for the mod union table we have
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
// shifter == CardTableModRefBS::card_shift - LogHeapWordSize.)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
// XXX 64-bit issues in BitMap?
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
class CMSBitMap VALUE_OBJ_CLASS_SPEC {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  friend class VMStructs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  HeapWord* _bmStartWord;   // base address of range covered by map
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  size_t    _bmWordSize;    // map size (in #HeapWords covered)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  const int _shifter;       // shifts to convert HeapWord to bit position
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  VirtualSpace _virtual_space; // underlying the bit map
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  BitMap    _bm;            // the bit map itself
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  Mutex* const _lock;       // mutex protecting _bm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  // constructor
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  CMSBitMap(int shifter, int mutex_rank, const char* mutex_name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  // allocates the actual storage for the map
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  bool allocate(MemRegion mr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  // field getter
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  Mutex* lock() const { return _lock; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  // locking verifier convenience function
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  void assert_locked() const PRODUCT_RETURN;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  // inquiries
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  HeapWord* startWord()   const { return _bmStartWord; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  size_t    sizeInWords() const { return _bmWordSize;  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  size_t    sizeInBits()  const { return _bm.size();   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  // the following is one past the last word in space
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  HeapWord* endWord()     const { return _bmStartWord + _bmWordSize; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  // reading marks
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  bool isMarked(HeapWord* addr) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  bool par_isMarked(HeapWord* addr) const; // do not lock checks
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  bool isUnmarked(HeapWord* addr) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  bool isAllClear() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  // writing marks
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  void mark(HeapWord* addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  // For marking by parallel GC threads;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  // returns true if we did, false if another thread did
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  bool par_mark(HeapWord* addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  void mark_range(MemRegion mr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  void par_mark_range(MemRegion mr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  void mark_large_range(MemRegion mr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  void par_mark_large_range(MemRegion mr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  void par_clear(HeapWord* addr); // For unmarking by parallel GC threads.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  void clear_range(MemRegion mr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  void par_clear_range(MemRegion mr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  void clear_large_range(MemRegion mr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  void par_clear_large_range(MemRegion mr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  void clear_all();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  void clear_all_incrementally();  // Not yet implemented!!
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  NOT_PRODUCT(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
    // checks the memory region for validity
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
    void region_invariant(MemRegion mr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  // iteration
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  void iterate(BitMapClosure* cl) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
    _bm.iterate(cl);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  void iterate(BitMapClosure* cl, HeapWord* left, HeapWord* right);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  void dirty_range_iterate_clear(MemRegionClosure* cl);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  void dirty_range_iterate_clear(MemRegion mr, MemRegionClosure* cl);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  // auxiliary support for iteration
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  HeapWord* getNextMarkedWordAddress(HeapWord* addr) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  HeapWord* getNextMarkedWordAddress(HeapWord* start_addr,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
                                            HeapWord* end_addr) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  HeapWord* getNextUnmarkedWordAddress(HeapWord* addr) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  HeapWord* getNextUnmarkedWordAddress(HeapWord* start_addr,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
                                              HeapWord* end_addr) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  MemRegion getAndClearMarkedRegion(HeapWord* addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  MemRegion getAndClearMarkedRegion(HeapWord* start_addr,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
                                           HeapWord* end_addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  // conversion utilities
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  HeapWord* offsetToHeapWord(size_t offset) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  size_t    heapWordToOffset(HeapWord* addr) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  size_t    heapWordDiffToOffsetDiff(size_t diff) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  // debugging
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  // is this address range covered by the bit-map?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  NOT_PRODUCT(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
    bool covers(MemRegion mr) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
    bool covers(HeapWord* start, size_t size = 0) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  void verifyNoOneBitsInRange(HeapWord* left, HeapWord* right) PRODUCT_RETURN;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
// Represents a marking stack used by the CMS collector.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
// Ideally this should be GrowableArray<> just like MSC's marking stack(s).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
class CMSMarkStack: public CHeapObj  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  friend class CMSCollector;   // to get at expasion stats further below
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  VirtualSpace _virtual_space;  // space for the stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  oop*   _base;      // bottom of stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  size_t _index;     // one more than last occupied index
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
  size_t _capacity;  // max #elements
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  Mutex  _par_lock;  // an advisory lock used in case of parallel access
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  NOT_PRODUCT(size_t _max_depth;)  // max depth plumbed during run
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
 protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
  size_t _hit_limit;      // we hit max stack size limit
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
  size_t _failed_double;  // we failed expansion before hitting limit
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  CMSMarkStack():
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
    _par_lock(Mutex::event, "CMSMarkStack._par_lock", true),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
    _hit_limit(0),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
    _failed_double(0) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
  bool allocate(size_t size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
  size_t capacity() const { return _capacity; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
  oop pop() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
    if (!isEmpty()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
      return _base[--_index] ;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
  bool push(oop ptr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
    if (isFull()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
      return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
      _base[_index++] = ptr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
      NOT_PRODUCT(_max_depth = MAX2(_max_depth, _index));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
      return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
  bool isEmpty() const { return _index == 0; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
  bool isFull()  const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
    assert(_index <= _capacity, "buffer overflow");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
    return _index == _capacity;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
  size_t length() { return _index; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
  // "Parallel versions" of some of the above
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
  oop par_pop() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
    // lock and pop
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
    MutexLockerEx x(&_par_lock, Mutex::_no_safepoint_check_flag);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
    return pop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
  bool par_push(oop ptr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
    // lock and push
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
    MutexLockerEx x(&_par_lock, Mutex::_no_safepoint_check_flag);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
    return push(ptr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
  // Forcibly reset the stack, losing all of its contents.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
  void reset() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
    _index = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
  // Expand the stack, typically in response to an overflow condition
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
  void expand();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
  // Compute the least valued stack element.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
  oop least_value(HeapWord* low) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
     oop least = (oop)low;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
     for (size_t i = 0; i < _index; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
       least = MIN2(least, _base[i]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
     }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
     return least;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
  // Exposed here to allow stack expansion in || case
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
  Mutex* par_lock() { return &_par_lock; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
class CardTableRS;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
class CMSParGCThreadState;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
class ModUnionClosure: public MemRegionClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
 protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
  CMSBitMap* _t;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
  ModUnionClosure(CMSBitMap* t): _t(t) { }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
  void do_MemRegion(MemRegion mr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
class ModUnionClosurePar: public ModUnionClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
  ModUnionClosurePar(CMSBitMap* t): ModUnionClosure(t) { }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
  void do_MemRegion(MemRegion mr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
// Survivor Chunk Array in support of parallelization of
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
// Survivor Space rescan.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
class ChunkArray: public CHeapObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
  size_t _index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
  size_t _capacity;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
  HeapWord** _array;   // storage for array
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
  ChunkArray() : _index(0), _capacity(0), _array(NULL) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
  ChunkArray(HeapWord** a, size_t c):
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
    _index(0), _capacity(c), _array(a) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
  HeapWord** array() { return _array; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
  void set_array(HeapWord** a) { _array = a; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
  size_t capacity() { return _capacity; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
  void set_capacity(size_t c) { _capacity = c; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
  size_t end() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
    assert(_index < capacity(), "_index out of bounds");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
    return _index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
  }  // exclusive
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
  HeapWord* nth(size_t n) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
    assert(n < end(), "Out of bounds access");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
    return _array[n];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
  void reset() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
    _index = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
  void record_sample(HeapWord* p, size_t sz) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
    // For now we do not do anything with the size
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
    if (_index < _capacity) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
      _array[_index++] = p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
// Timing, allocation and promotion statistics for gc scheduling and incremental
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
// mode pacing.  Most statistics are exponential averages.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
class CMSStats VALUE_OBJ_CLASS_SPEC {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
  ConcurrentMarkSweepGeneration* const _cms_gen;   // The cms (old) gen.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
  // The following are exponential averages with factor alpha:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
  //   avg = (100 - alpha) * avg + alpha * cur_sample
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
  //   The durations measure:  end_time[n] - start_time[n]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
  //   The periods measure:    start_time[n] - start_time[n-1]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
  // The cms period and duration include only concurrent collections; time spent
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
  // in foreground cms collections due to System.gc() or because of a failure to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
  // keep up are not included.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
  // There are 3 alphas to "bootstrap" the statistics.  The _saved_alpha is the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
  // real value, but is used only after the first period.  A value of 100 is
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
  // used for the first sample so it gets the entire weight.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
  unsigned int _saved_alpha; // 0-100
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
  unsigned int _gc0_alpha;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
  unsigned int _cms_alpha;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
  double _gc0_duration;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
  double _gc0_period;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
  size_t _gc0_promoted;         // bytes promoted per gc0
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
  double _cms_duration;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
  double _cms_duration_pre_sweep; // time from initiation to start of sweep
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
  double _cms_duration_per_mb;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
  double _cms_period;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
  size_t _cms_allocated;        // bytes of direct allocation per gc0 period
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
  // Timers.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
  elapsedTimer _cms_timer;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
  TimeStamp    _gc0_begin_time;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
  TimeStamp    _cms_begin_time;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
  TimeStamp    _cms_end_time;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
  // Snapshots of the amount used in the CMS generation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
  size_t _cms_used_at_gc0_begin;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
  size_t _cms_used_at_gc0_end;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
  size_t _cms_used_at_cms_begin;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
  // Used to prevent the duty cycle from being reduced in the middle of a cms
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
  // cycle.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
  bool _allow_duty_cycle_reduction;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
  enum {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
    _GC0_VALID = 0x1,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
    _CMS_VALID = 0x2,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
    _ALL_VALID = _GC0_VALID | _CMS_VALID
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
  unsigned int _valid_bits;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
  unsigned int _icms_duty_cycle;        // icms duty cycle (0-100).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
 protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
  // Return a duty cycle that avoids wild oscillations, by limiting the amount
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
  // of change between old_duty_cycle and new_duty_cycle (the latter is treated
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
  // as a recommended value).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
  static unsigned int icms_damped_duty_cycle(unsigned int old_duty_cycle,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
                                             unsigned int new_duty_cycle);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
  unsigned int icms_update_duty_cycle_impl();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
4574
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 3690
diff changeset
   358
  // In support of adjusting of cms trigger ratios based on history
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 3690
diff changeset
   359
  // of concurrent mode failure.
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 3690
diff changeset
   360
  double cms_free_adjustment_factor(size_t free) const;
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 3690
diff changeset
   361
  void   adjust_cms_free_adjustment_factor(bool fail, size_t free);
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 3690
diff changeset
   362
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
  CMSStats(ConcurrentMarkSweepGeneration* cms_gen,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
           unsigned int alpha = CMSExpAvgFactor);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
  // Whether or not the statistics contain valid data; higher level statistics
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
  // cannot be called until this returns true (they require at least one young
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
  // gen and one cms cycle to have completed).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
  bool valid() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
  // Record statistics.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
  void record_gc0_begin();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
  void record_gc0_end(size_t cms_gen_bytes_used);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
  void record_cms_begin();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
  void record_cms_end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
  // Allow management of the cms timer, which must be stopped/started around
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
  // yield points.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
  elapsedTimer& cms_timer()     { return _cms_timer; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
  void start_cms_timer()        { _cms_timer.start(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
  void stop_cms_timer()         { _cms_timer.stop(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
  // Basic statistics; units are seconds or bytes.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
  double gc0_period() const     { return _gc0_period; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
  double gc0_duration() const   { return _gc0_duration; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
  size_t gc0_promoted() const   { return _gc0_promoted; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
  double cms_period() const          { return _cms_period; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
  double cms_duration() const        { return _cms_duration; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
  double cms_duration_per_mb() const { return _cms_duration_per_mb; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
  size_t cms_allocated() const       { return _cms_allocated; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
  size_t cms_used_at_gc0_end() const { return _cms_used_at_gc0_end;}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
  // Seconds since the last background cms cycle began or ended.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
  double cms_time_since_begin() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
  double cms_time_since_end() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
  // Higher level statistics--caller must check that valid() returns true before
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
  // calling.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
  // Returns bytes promoted per second of wall clock time.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
  double promotion_rate() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
  // Returns bytes directly allocated per second of wall clock time.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
  double cms_allocation_rate() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
  // Rate at which space in the cms generation is being consumed (sum of the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
  // above two).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
  double cms_consumption_rate() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
  // Returns an estimate of the number of seconds until the cms generation will
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
  // fill up, assuming no collection work is done.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
  double time_until_cms_gen_full() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
  // Returns an estimate of the number of seconds remaining until
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
  // the cms generation collection should start.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
  double time_until_cms_start() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
  // End of higher level statistics.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
  // Returns the cms incremental mode duty cycle, as a percentage (0-100).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
  unsigned int icms_duty_cycle() const { return _icms_duty_cycle; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
  // Update the duty cycle and return the new value.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
  unsigned int icms_update_duty_cycle();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
  // Debugging.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
  void print_on(outputStream* st) const PRODUCT_RETURN;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
  void print() const { print_on(gclog_or_tty); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
// A closure related to weak references processing which
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
// we embed in the CMSCollector, since we need to pass
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
// it to the reference processor for secondary filtering
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
// of references based on reachability of referent;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
// see role of _is_alive_non_header closure in the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
// ReferenceProcessor class.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
// For objects in the CMS generation, this closure checks
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
// if the object is "live" (reachable). Used in weak
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
// reference processing.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
class CMSIsAliveClosure: public BoolObjectClosure {
390
2e094c1be4af 6662086: 6u4+, 7b11+: CMS never clears referents when -XX:+ParallelRefProcEnabled
ysr
parents: 360
diff changeset
   443
  const MemRegion  _span;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
  const CMSBitMap* _bit_map;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
  friend class CMSCollector;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
  CMSIsAliveClosure(MemRegion span,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
                    CMSBitMap* bit_map):
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
    _span(span),
390
2e094c1be4af 6662086: 6u4+, 7b11+: CMS never clears referents when -XX:+ParallelRefProcEnabled
ysr
parents: 360
diff changeset
   451
    _bit_map(bit_map) {
2e094c1be4af 6662086: 6u4+, 7b11+: CMS never clears referents when -XX:+ParallelRefProcEnabled
ysr
parents: 360
diff changeset
   452
    assert(!span.is_empty(), "Empty span could spell trouble");
2e094c1be4af 6662086: 6u4+, 7b11+: CMS never clears referents when -XX:+ParallelRefProcEnabled
ysr
parents: 360
diff changeset
   453
  }
2e094c1be4af 6662086: 6u4+, 7b11+: CMS never clears referents when -XX:+ParallelRefProcEnabled
ysr
parents: 360
diff changeset
   454
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
  void do_object(oop obj) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
    assert(false, "not to be invoked");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
  }
390
2e094c1be4af 6662086: 6u4+, 7b11+: CMS never clears referents when -XX:+ParallelRefProcEnabled
ysr
parents: 360
diff changeset
   458
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
  bool do_object_b(oop obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
// Implements AbstractRefProcTaskExecutor for CMS.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
class CMSRefProcTaskExecutor: public AbstractRefProcTaskExecutor {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
  CMSRefProcTaskExecutor(CMSCollector& collector)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
    : _collector(collector)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
  { }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
  // Executes a task using worker threads.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
  virtual void execute(ProcessTask& task);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
  virtual void execute(EnqueueTask& task);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
  CMSCollector& _collector;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
class CMSCollector: public CHeapObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
  friend class VMStructs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
  friend class ConcurrentMarkSweepThread;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
  friend class ConcurrentMarkSweepGeneration;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
  friend class CompactibleFreeListSpace;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
  friend class CMSParRemarkTask;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
  friend class CMSConcMarkingTask;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
  friend class CMSRefProcTaskProxy;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
  friend class CMSRefProcTaskExecutor;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
  friend class ScanMarkedObjectsAgainCarefullyClosure;  // for sampling eden
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
  friend class SurvivorSpacePrecleanClosure;            // --- ditto -------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
  friend class PushOrMarkClosure;             // to access _restart_addr
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
  friend class Par_PushOrMarkClosure;             // to access _restart_addr
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
  friend class MarkFromRootsClosure;          //  -- ditto --
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
                                              // ... and for clearing cards
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
  friend class Par_MarkFromRootsClosure;      //  to access _restart_addr
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
                                              // ... and for clearing cards
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
  friend class Par_ConcMarkingClosure;        //  to access _restart_addr etc.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
  friend class MarkFromRootsVerifyClosure;    // to access _restart_addr
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
  friend class PushAndMarkVerifyClosure;      //  -- ditto --
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
  friend class MarkRefsIntoAndScanClosure;    // to access _overflow_list
489c9b5090e2 Initial load
duke
parents:
diff changeset
   500
  friend class PushAndMarkClosure;            //  -- ditto --
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
  friend class Par_PushAndMarkClosure;        //  -- ditto --
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
  friend class CMSKeepAliveClosure;           //  -- ditto --
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
  friend class CMSDrainMarkingStackClosure;   //  -- ditto --
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
  friend class CMSInnerParMarkAndPushClosure; //  -- ditto --
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
  NOT_PRODUCT(friend class ScanMarkedObjectsAgainClosure;) //  assertion on _overflow_list
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
  friend class ReleaseForegroundGC;  // to access _foregroundGCShouldWait
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
  friend class VM_CMS_Operation;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
  friend class VM_CMS_Initial_Mark;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   509
  friend class VM_CMS_Final_Remark;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   510
489c9b5090e2 Initial load
duke
parents:
diff changeset
   511
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   512
  jlong _time_of_last_gc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   513
  void update_time_of_last_gc(jlong now) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   514
    _time_of_last_gc = now;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   516
489c9b5090e2 Initial load
duke
parents:
diff changeset
   517
  OopTaskQueueSet* _task_queues;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   518
489c9b5090e2 Initial load
duke
parents:
diff changeset
   519
  // Overflow list of grey objects, threaded through mark-word
489c9b5090e2 Initial load
duke
parents:
diff changeset
   520
  // Manipulated with CAS in the parallel/multi-threaded case.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   521
  oop _overflow_list;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   522
  // The following array-pair keeps track of mark words
489c9b5090e2 Initial load
duke
parents:
diff changeset
   523
  // displaced for accomodating overflow list above.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   524
  // This code will likely be revisited under RFE#4922830.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   525
  GrowableArray<oop>*     _preserved_oop_stack;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
  GrowableArray<markOop>* _preserved_mark_stack;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   527
489c9b5090e2 Initial load
duke
parents:
diff changeset
   528
  int*             _hash_seed;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   529
489c9b5090e2 Initial load
duke
parents:
diff changeset
   530
  // In support of multi-threaded concurrent phases
489c9b5090e2 Initial load
duke
parents:
diff changeset
   531
  YieldingFlexibleWorkGang* _conc_workers;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   532
489c9b5090e2 Initial load
duke
parents:
diff changeset
   533
  // Performance Counters
489c9b5090e2 Initial load
duke
parents:
diff changeset
   534
  CollectorCounters* _gc_counters;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   535
489c9b5090e2 Initial load
duke
parents:
diff changeset
   536
  // Initialization Errors
489c9b5090e2 Initial load
duke
parents:
diff changeset
   537
  bool _completed_initialization;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   538
489c9b5090e2 Initial load
duke
parents:
diff changeset
   539
  // In support of ExplicitGCInvokesConcurrent
489c9b5090e2 Initial load
duke
parents:
diff changeset
   540
  static   bool _full_gc_requested;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   541
  unsigned int  _collection_count_start;
341
6578aad59716 6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents: 1
diff changeset
   542
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   543
  // Should we unload classes this concurrent cycle?
341
6578aad59716 6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents: 1
diff changeset
   544
  bool _should_unload_classes;
6578aad59716 6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents: 1
diff changeset
   545
  unsigned int  _concurrent_cycles_since_last_unload;
6578aad59716 6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents: 1
diff changeset
   546
  unsigned int concurrent_cycles_since_last_unload() const {
6578aad59716 6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents: 1
diff changeset
   547
    return _concurrent_cycles_since_last_unload;
6578aad59716 6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents: 1
diff changeset
   548
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   549
  // Did we (allow) unload classes in the previous concurrent cycle?
341
6578aad59716 6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents: 1
diff changeset
   550
  bool unloaded_classes_last_cycle() const {
6578aad59716 6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents: 1
diff changeset
   551
    return concurrent_cycles_since_last_unload() == 0;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   552
  }
2885
7dd49b9daa4a 6848641: CMSCollector::_roots_scanning_options should be initialized
ysr
parents: 2105
diff changeset
   553
  // Root scanning options for perm gen
7dd49b9daa4a 6848641: CMSCollector::_roots_scanning_options should be initialized
ysr
parents: 2105
diff changeset
   554
  int _roots_scanning_options;
7dd49b9daa4a 6848641: CMSCollector::_roots_scanning_options should be initialized
ysr
parents: 2105
diff changeset
   555
  int roots_scanning_options() const      { return _roots_scanning_options; }
7dd49b9daa4a 6848641: CMSCollector::_roots_scanning_options should be initialized
ysr
parents: 2105
diff changeset
   556
  void add_root_scanning_option(int o)    { _roots_scanning_options |= o;   }
7dd49b9daa4a 6848641: CMSCollector::_roots_scanning_options should be initialized
ysr
parents: 2105
diff changeset
   557
  void remove_root_scanning_option(int o) { _roots_scanning_options &= ~o;  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   558
489c9b5090e2 Initial load
duke
parents:
diff changeset
   559
  // Verification support
489c9b5090e2 Initial load
duke
parents:
diff changeset
   560
  CMSBitMap     _verification_mark_bm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   561
  void verify_after_remark_work_1();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   562
  void verify_after_remark_work_2();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   563
489c9b5090e2 Initial load
duke
parents:
diff changeset
   564
  // true if any verification flag is on.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   565
  bool _verifying;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   566
  bool verifying() const { return _verifying; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   567
  void set_verifying(bool v) { _verifying = v; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   568
489c9b5090e2 Initial load
duke
parents:
diff changeset
   569
  // Collector policy
489c9b5090e2 Initial load
duke
parents:
diff changeset
   570
  ConcurrentMarkSweepPolicy* _collector_policy;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   571
  ConcurrentMarkSweepPolicy* collector_policy() { return _collector_policy; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   572
489c9b5090e2 Initial load
duke
parents:
diff changeset
   573
  // XXX Move these to CMSStats ??? FIX ME !!!
4574
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 3690
diff changeset
   574
  elapsedTimer _inter_sweep_timer;   // time between sweeps
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 3690
diff changeset
   575
  elapsedTimer _intra_sweep_timer;   // time _in_ sweeps
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 3690
diff changeset
   576
  // padded decaying average estimates of the above
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 3690
diff changeset
   577
  AdaptivePaddedAverage _inter_sweep_estimate;
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 3690
diff changeset
   578
  AdaptivePaddedAverage _intra_sweep_estimate;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   579
489c9b5090e2 Initial load
duke
parents:
diff changeset
   580
 protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   581
  ConcurrentMarkSweepGeneration* _cmsGen;  // old gen (CMS)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   582
  ConcurrentMarkSweepGeneration* _permGen; // perm gen
489c9b5090e2 Initial load
duke
parents:
diff changeset
   583
  MemRegion                      _span;    // span covering above two
489c9b5090e2 Initial load
duke
parents:
diff changeset
   584
  CardTableRS*                   _ct;      // card table
489c9b5090e2 Initial load
duke
parents:
diff changeset
   585
489c9b5090e2 Initial load
duke
parents:
diff changeset
   586
  // CMS marking support structures
489c9b5090e2 Initial load
duke
parents:
diff changeset
   587
  CMSBitMap     _markBitMap;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   588
  CMSBitMap     _modUnionTable;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   589
  CMSMarkStack  _markStack;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   590
  CMSMarkStack  _revisitStack;            // used to keep track of klassKlass objects
489c9b5090e2 Initial load
duke
parents:
diff changeset
   591
                                          // to revisit
489c9b5090e2 Initial load
duke
parents:
diff changeset
   592
  CMSBitMap     _perm_gen_verify_bit_map; // Mark bit map for perm gen verification support.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   593
489c9b5090e2 Initial load
duke
parents:
diff changeset
   594
  HeapWord*     _restart_addr; // in support of marking stack overflow
489c9b5090e2 Initial load
duke
parents:
diff changeset
   595
  void          lower_restart_addr(HeapWord* low);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   596
489c9b5090e2 Initial load
duke
parents:
diff changeset
   597
  // Counters in support of marking stack / work queue overflow handling:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   598
  // a non-zero value indicates certain types of overflow events during
489c9b5090e2 Initial load
duke
parents:
diff changeset
   599
  // the current CMS cycle and could lead to stack resizing efforts at
489c9b5090e2 Initial load
duke
parents:
diff changeset
   600
  // an opportune future time.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   601
  size_t        _ser_pmc_preclean_ovflw;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   602
  size_t        _ser_pmc_remark_ovflw;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   603
  size_t        _par_pmc_remark_ovflw;
1605
6b43d186eb8d 6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents: 1388
diff changeset
   604
  size_t        _ser_kac_preclean_ovflw;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   605
  size_t        _ser_kac_ovflw;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   606
  size_t        _par_kac_ovflw;
1910
386106352d02 6786503: Overflow list performance can be improved
ysr
parents: 1893
diff changeset
   607
  NOT_PRODUCT(ssize_t _num_par_pushes;)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   608
489c9b5090e2 Initial load
duke
parents:
diff changeset
   609
  // ("Weak") Reference processing support
489c9b5090e2 Initial load
duke
parents:
diff changeset
   610
  ReferenceProcessor*            _ref_processor;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   611
  CMSIsAliveClosure              _is_alive_closure;
390
2e094c1be4af 6662086: 6u4+, 7b11+: CMS never clears referents when -XX:+ParallelRefProcEnabled
ysr
parents: 360
diff changeset
   612
      // keep this textually after _markBitMap and _span; c'tor dependency
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   613
489c9b5090e2 Initial load
duke
parents:
diff changeset
   614
  ConcurrentMarkSweepThread*     _cmsThread;   // the thread doing the work
489c9b5090e2 Initial load
duke
parents:
diff changeset
   615
  ModUnionClosure    _modUnionClosure;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   616
  ModUnionClosurePar _modUnionClosurePar;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   617
489c9b5090e2 Initial load
duke
parents:
diff changeset
   618
  // CMS abstract state machine
489c9b5090e2 Initial load
duke
parents:
diff changeset
   619
  // initial_state: Idling
489c9b5090e2 Initial load
duke
parents:
diff changeset
   620
  // next_state(Idling)            = {Marking}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   621
  // next_state(Marking)           = {Precleaning, Sweeping}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   622
  // next_state(Precleaning)       = {AbortablePreclean, FinalMarking}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   623
  // next_state(AbortablePreclean) = {FinalMarking}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   624
  // next_state(FinalMarking)      = {Sweeping}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   625
  // next_state(Sweeping)          = {Resizing}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   626
  // next_state(Resizing)          = {Resetting}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   627
  // next_state(Resetting)         = {Idling}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   628
  // The numeric values below are chosen so that:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   629
  // . _collectorState <= Idling ==  post-sweep && pre-mark
489c9b5090e2 Initial load
duke
parents:
diff changeset
   630
  // . _collectorState in (Idling, Sweeping) == {initial,final}marking ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   631
  //                                            precleaning || abortablePrecleanb
4574
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 3690
diff changeset
   632
 public:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   633
  enum CollectorState {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   634
    Resizing            = 0,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   635
    Resetting           = 1,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   636
    Idling              = 2,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   637
    InitialMarking      = 3,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   638
    Marking             = 4,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   639
    Precleaning         = 5,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   640
    AbortablePreclean   = 6,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   641
    FinalMarking        = 7,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   642
    Sweeping            = 8
489c9b5090e2 Initial load
duke
parents:
diff changeset
   643
  };
4574
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 3690
diff changeset
   644
 protected:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   645
  static CollectorState _collectorState;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   646
489c9b5090e2 Initial load
duke
parents:
diff changeset
   647
  // State related to prologue/epilogue invocation for my generations
489c9b5090e2 Initial load
duke
parents:
diff changeset
   648
  bool _between_prologue_and_epilogue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   649
489c9b5090e2 Initial load
duke
parents:
diff changeset
   650
  // Signalling/State related to coordination between fore- and backgroud GC
489c9b5090e2 Initial load
duke
parents:
diff changeset
   651
  // Note: When the baton has been passed from background GC to foreground GC,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   652
  // _foregroundGCIsActive is true and _foregroundGCShouldWait is false.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   653
  static bool _foregroundGCIsActive;    // true iff foreground collector is active or
489c9b5090e2 Initial load
duke
parents:
diff changeset
   654
                                 // wants to go active
489c9b5090e2 Initial load
duke
parents:
diff changeset
   655
  static bool _foregroundGCShouldWait;  // true iff background GC is active and has not
489c9b5090e2 Initial load
duke
parents:
diff changeset
   656
                                 // yet passed the baton to the foreground GC
489c9b5090e2 Initial load
duke
parents:
diff changeset
   657
489c9b5090e2 Initial load
duke
parents:
diff changeset
   658
  // Support for CMSScheduleRemark (abortable preclean)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   659
  bool _abort_preclean;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   660
  bool _start_sampling;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   661
489c9b5090e2 Initial load
duke
parents:
diff changeset
   662
  int    _numYields;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   663
  size_t _numDirtyCards;
4574
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 3690
diff changeset
   664
  size_t _sweep_count;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   665
  // number of full gc's since the last concurrent gc.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   666
  uint   _full_gcs_since_conc_gc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   667
489c9b5090e2 Initial load
duke
parents:
diff changeset
   668
  // occupancy used for bootstrapping stats
489c9b5090e2 Initial load
duke
parents:
diff changeset
   669
  double _bootstrap_occupancy;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   670
489c9b5090e2 Initial load
duke
parents:
diff changeset
   671
  // timer
489c9b5090e2 Initial load
duke
parents:
diff changeset
   672
  elapsedTimer _timer;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   673
489c9b5090e2 Initial load
duke
parents:
diff changeset
   674
  // Timing, allocation and promotion statistics, used for scheduling.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   675
  CMSStats      _stats;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   676
489c9b5090e2 Initial load
duke
parents:
diff changeset
   677
  // Allocation limits installed in the young gen, used only in
489c9b5090e2 Initial load
duke
parents:
diff changeset
   678
  // CMSIncrementalMode.  When an allocation in the young gen would cross one of
489c9b5090e2 Initial load
duke
parents:
diff changeset
   679
  // these limits, the cms generation is notified and the cms thread is started
489c9b5090e2 Initial load
duke
parents:
diff changeset
   680
  // or stopped, respectively.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   681
  HeapWord*     _icms_start_limit;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   682
  HeapWord*     _icms_stop_limit;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   683
489c9b5090e2 Initial load
duke
parents:
diff changeset
   684
  enum CMS_op_type {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   685
    CMS_op_checkpointRootsInitial,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   686
    CMS_op_checkpointRootsFinal
489c9b5090e2 Initial load
duke
parents:
diff changeset
   687
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   688
489c9b5090e2 Initial load
duke
parents:
diff changeset
   689
  void do_CMS_operation(CMS_op_type op);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   690
  bool stop_world_and_do(CMS_op_type op);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   691
489c9b5090e2 Initial load
duke
parents:
diff changeset
   692
  OopTaskQueueSet* task_queues() { return _task_queues; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   693
  int*             hash_seed(int i) { return &_hash_seed[i]; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   694
  YieldingFlexibleWorkGang* conc_workers() { return _conc_workers; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   695
489c9b5090e2 Initial load
duke
parents:
diff changeset
   696
  // Support for parallelizing Eden rescan in CMS remark phase
489c9b5090e2 Initial load
duke
parents:
diff changeset
   697
  void sample_eden(); // ... sample Eden space top
489c9b5090e2 Initial load
duke
parents:
diff changeset
   698
489c9b5090e2 Initial load
duke
parents:
diff changeset
   699
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   700
  // Support for parallelizing young gen rescan in CMS remark phase
489c9b5090e2 Initial load
duke
parents:
diff changeset
   701
  Generation* _young_gen;  // the younger gen
489c9b5090e2 Initial load
duke
parents:
diff changeset
   702
  HeapWord** _top_addr;    // ... Top of Eden
489c9b5090e2 Initial load
duke
parents:
diff changeset
   703
  HeapWord** _end_addr;    // ... End of Eden
489c9b5090e2 Initial load
duke
parents:
diff changeset
   704
  HeapWord** _eden_chunk_array; // ... Eden partitioning array
489c9b5090e2 Initial load
duke
parents:
diff changeset
   705
  size_t     _eden_chunk_index; // ... top (exclusive) of array
489c9b5090e2 Initial load
duke
parents:
diff changeset
   706
  size_t     _eden_chunk_capacity;  // ... max entries in array
489c9b5090e2 Initial load
duke
parents:
diff changeset
   707
489c9b5090e2 Initial load
duke
parents:
diff changeset
   708
  // Support for parallelizing survivor space rescan
489c9b5090e2 Initial load
duke
parents:
diff changeset
   709
  HeapWord** _survivor_chunk_array;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   710
  size_t     _survivor_chunk_index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   711
  size_t     _survivor_chunk_capacity;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   712
  size_t*    _cursor;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   713
  ChunkArray* _survivor_plab_array;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   714
489c9b5090e2 Initial load
duke
parents:
diff changeset
   715
  // Support for marking stack overflow handling
489c9b5090e2 Initial load
duke
parents:
diff changeset
   716
  bool take_from_overflow_list(size_t num, CMSMarkStack* to_stack);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   717
  bool par_take_from_overflow_list(size_t num, OopTaskQueue* to_work_q);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   718
  void push_on_overflow_list(oop p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   719
  void par_push_on_overflow_list(oop p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   720
  // the following is, obviously, not, in general, "MT-stable"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   721
  bool overflow_list_is_empty() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   722
489c9b5090e2 Initial load
duke
parents:
diff changeset
   723
  void preserve_mark_if_necessary(oop p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   724
  void par_preserve_mark_if_necessary(oop p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   725
  void preserve_mark_work(oop p, markOop m);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   726
  void restore_preserved_marks_if_any();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   727
  NOT_PRODUCT(bool no_preserved_marks() const;)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   728
  // in support of testing overflow code
489c9b5090e2 Initial load
duke
parents:
diff changeset
   729
  NOT_PRODUCT(int _overflow_counter;)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   730
  NOT_PRODUCT(bool simulate_overflow();)       // sequential
489c9b5090e2 Initial load
duke
parents:
diff changeset
   731
  NOT_PRODUCT(bool par_simulate_overflow();)   // MT version
489c9b5090e2 Initial load
duke
parents:
diff changeset
   732
489c9b5090e2 Initial load
duke
parents:
diff changeset
   733
  // CMS work methods
489c9b5090e2 Initial load
duke
parents:
diff changeset
   734
  void checkpointRootsInitialWork(bool asynch); // initial checkpoint work
489c9b5090e2 Initial load
duke
parents:
diff changeset
   735
489c9b5090e2 Initial load
duke
parents:
diff changeset
   736
  // a return value of false indicates failure due to stack overflow
489c9b5090e2 Initial load
duke
parents:
diff changeset
   737
  bool markFromRootsWork(bool asynch);  // concurrent marking work
489c9b5090e2 Initial load
duke
parents:
diff changeset
   738
489c9b5090e2 Initial load
duke
parents:
diff changeset
   739
 public:   // FIX ME!!! only for testing
489c9b5090e2 Initial load
duke
parents:
diff changeset
   740
  bool do_marking_st(bool asynch);      // single-threaded marking
489c9b5090e2 Initial load
duke
parents:
diff changeset
   741
  bool do_marking_mt(bool asynch);      // multi-threaded  marking
489c9b5090e2 Initial load
duke
parents:
diff changeset
   742
489c9b5090e2 Initial load
duke
parents:
diff changeset
   743
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   744
489c9b5090e2 Initial load
duke
parents:
diff changeset
   745
  // concurrent precleaning work
489c9b5090e2 Initial load
duke
parents:
diff changeset
   746
  size_t preclean_mod_union_table(ConcurrentMarkSweepGeneration* gen,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   747
                                  ScanMarkedObjectsAgainCarefullyClosure* cl);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   748
  size_t preclean_card_table(ConcurrentMarkSweepGeneration* gen,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   749
                             ScanMarkedObjectsAgainCarefullyClosure* cl);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   750
  // Does precleaning work, returning a quantity indicative of
489c9b5090e2 Initial load
duke
parents:
diff changeset
   751
  // the amount of "useful work" done.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   752
  size_t preclean_work(bool clean_refs, bool clean_survivors);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   753
  void abortable_preclean(); // Preclean while looking for possible abort
489c9b5090e2 Initial load
duke
parents:
diff changeset
   754
  void initialize_sequential_subtasks_for_young_gen_rescan(int i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   755
  // Helper function for above; merge-sorts the per-thread plab samples
489c9b5090e2 Initial load
duke
parents:
diff changeset
   756
  void merge_survivor_plab_arrays(ContiguousSpace* surv);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   757
  // Resets (i.e. clears) the per-thread plab sample vectors
489c9b5090e2 Initial load
duke
parents:
diff changeset
   758
  void reset_survivor_plab_arrays();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   759
489c9b5090e2 Initial load
duke
parents:
diff changeset
   760
  // final (second) checkpoint work
489c9b5090e2 Initial load
duke
parents:
diff changeset
   761
  void checkpointRootsFinalWork(bool asynch, bool clear_all_soft_refs,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   762
                                bool init_mark_was_synchronous);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   763
  // work routine for parallel version of remark
489c9b5090e2 Initial load
duke
parents:
diff changeset
   764
  void do_remark_parallel();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   765
  // work routine for non-parallel version of remark
489c9b5090e2 Initial load
duke
parents:
diff changeset
   766
  void do_remark_non_parallel();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   767
  // reference processing work routine (during second checkpoint)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   768
  void refProcessingWork(bool asynch, bool clear_all_soft_refs);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   769
489c9b5090e2 Initial load
duke
parents:
diff changeset
   770
  // concurrent sweeping work
489c9b5090e2 Initial load
duke
parents:
diff changeset
   771
  void sweepWork(ConcurrentMarkSweepGeneration* gen, bool asynch);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   772
489c9b5090e2 Initial load
duke
parents:
diff changeset
   773
  // (concurrent) resetting of support data structures
489c9b5090e2 Initial load
duke
parents:
diff changeset
   774
  void reset(bool asynch);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   775
489c9b5090e2 Initial load
duke
parents:
diff changeset
   776
  // Clear _expansion_cause fields of constituent generations
489c9b5090e2 Initial load
duke
parents:
diff changeset
   777
  void clear_expansion_cause();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   778
489c9b5090e2 Initial load
duke
parents:
diff changeset
   779
  // An auxilliary method used to record the ends of
489c9b5090e2 Initial load
duke
parents:
diff changeset
   780
  // used regions of each generation to limit the extent of sweep
489c9b5090e2 Initial load
duke
parents:
diff changeset
   781
  void save_sweep_limits();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   782
489c9b5090e2 Initial load
duke
parents:
diff changeset
   783
  // Resize the generations included in the collector.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   784
  void compute_new_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   785
489c9b5090e2 Initial load
duke
parents:
diff changeset
   786
  // A work method used by foreground collection to determine
489c9b5090e2 Initial load
duke
parents:
diff changeset
   787
  // what type of collection (compacting or not, continuing or fresh)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   788
  // it should do.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   789
  void decide_foreground_collection_type(bool clear_all_soft_refs,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   790
    bool* should_compact, bool* should_start_over);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   791
489c9b5090e2 Initial load
duke
parents:
diff changeset
   792
  // A work method used by the foreground collector to do
489c9b5090e2 Initial load
duke
parents:
diff changeset
   793
  // a mark-sweep-compact.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   794
  void do_compaction_work(bool clear_all_soft_refs);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   795
489c9b5090e2 Initial load
duke
parents:
diff changeset
   796
  // A work method used by the foreground collector to do
489c9b5090e2 Initial load
duke
parents:
diff changeset
   797
  // a mark-sweep, after taking over from a possibly on-going
489c9b5090e2 Initial load
duke
parents:
diff changeset
   798
  // concurrent mark-sweep collection.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   799
  void do_mark_sweep_work(bool clear_all_soft_refs,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   800
    CollectorState first_state, bool should_start_over);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   801
489c9b5090e2 Initial load
duke
parents:
diff changeset
   802
  // If the backgrould GC is active, acquire control from the background
489c9b5090e2 Initial load
duke
parents:
diff changeset
   803
  // GC and do the collection.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   804
  void acquire_control_and_collect(bool   full, bool clear_all_soft_refs);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   805
489c9b5090e2 Initial load
duke
parents:
diff changeset
   806
  // For synchronizing passing of control from background to foreground
489c9b5090e2 Initial load
duke
parents:
diff changeset
   807
  // GC.  waitForForegroundGC() is called by the background
489c9b5090e2 Initial load
duke
parents:
diff changeset
   808
  // collector.  It if had to wait for a foreground collection,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   809
  // it returns true and the background collection should assume
489c9b5090e2 Initial load
duke
parents:
diff changeset
   810
  // that the collection was finished by the foreground
489c9b5090e2 Initial load
duke
parents:
diff changeset
   811
  // collector.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   812
  bool waitForForegroundGC();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   813
489c9b5090e2 Initial load
duke
parents:
diff changeset
   814
  // Incremental mode triggering:  recompute the icms duty cycle and set the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   815
  // allocation limits in the young gen.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   816
  void icms_update_allocation_limits();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   817
489c9b5090e2 Initial load
duke
parents:
diff changeset
   818
  size_t block_size_using_printezis_bits(HeapWord* addr) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   819
  size_t block_size_if_printezis_bits(HeapWord* addr) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   820
  HeapWord* next_card_start_after_block(HeapWord* addr) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   821
489c9b5090e2 Initial load
duke
parents:
diff changeset
   822
  void setup_cms_unloading_and_verification_state();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   823
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   824
  CMSCollector(ConcurrentMarkSweepGeneration* cmsGen,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   825
               ConcurrentMarkSweepGeneration* permGen,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   826
               CardTableRS*                   ct,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   827
               ConcurrentMarkSweepPolicy*     cp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   828
  ConcurrentMarkSweepThread* cmsThread() { return _cmsThread; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   829
489c9b5090e2 Initial load
duke
parents:
diff changeset
   830
  ReferenceProcessor* ref_processor() { return _ref_processor; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   831
  void ref_processor_init();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   832
489c9b5090e2 Initial load
duke
parents:
diff changeset
   833
  Mutex* bitMapLock()        const { return _markBitMap.lock();    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   834
  static CollectorState abstract_state() { return _collectorState;  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   835
489c9b5090e2 Initial load
duke
parents:
diff changeset
   836
  bool should_abort_preclean() const; // Whether preclean should be aborted.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   837
  size_t get_eden_used() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   838
  size_t get_eden_capacity() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   839
489c9b5090e2 Initial load
duke
parents:
diff changeset
   840
  ConcurrentMarkSweepGeneration* cmsGen() { return _cmsGen; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   841
489c9b5090e2 Initial load
duke
parents:
diff changeset
   842
  // locking checks
489c9b5090e2 Initial load
duke
parents:
diff changeset
   843
  NOT_PRODUCT(static bool have_cms_token();)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   844
489c9b5090e2 Initial load
duke
parents:
diff changeset
   845
  // XXXPERM bool should_collect(bool full, size_t size, bool tlab);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   846
  bool shouldConcurrentCollect();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   847
489c9b5090e2 Initial load
duke
parents:
diff changeset
   848
  void collect(bool   full,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   849
               bool   clear_all_soft_refs,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   850
               size_t size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   851
               bool   tlab);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   852
  void collect_in_background(bool clear_all_soft_refs);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   853
  void collect_in_foreground(bool clear_all_soft_refs);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   854
489c9b5090e2 Initial load
duke
parents:
diff changeset
   855
  // In support of ExplicitGCInvokesConcurrent
489c9b5090e2 Initial load
duke
parents:
diff changeset
   856
  static void request_full_gc(unsigned int full_gc_count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   857
  // Should we unload classes in a particular concurrent cycle?
341
6578aad59716 6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents: 1
diff changeset
   858
  bool should_unload_classes() const {
6578aad59716 6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents: 1
diff changeset
   859
    return _should_unload_classes;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   860
  }
341
6578aad59716 6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents: 1
diff changeset
   861
  bool update_should_unload_classes();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   862
489c9b5090e2 Initial load
duke
parents:
diff changeset
   863
  void direct_allocated(HeapWord* start, size_t size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   864
489c9b5090e2 Initial load
duke
parents:
diff changeset
   865
  // Object is dead if not marked and current phase is sweeping.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   866
  bool is_dead_obj(oop obj) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   867
489c9b5090e2 Initial load
duke
parents:
diff changeset
   868
  // After a promotion (of "start"), do any necessary marking.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   869
  // If "par", then it's being done by a parallel GC thread.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   870
  // The last two args indicate if we need precise marking
489c9b5090e2 Initial load
duke
parents:
diff changeset
   871
  // and if so the size of the object so it can be dirtied
489c9b5090e2 Initial load
duke
parents:
diff changeset
   872
  // in its entirety.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   873
  void promoted(bool par, HeapWord* start,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   874
                bool is_obj_array, size_t obj_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   875
489c9b5090e2 Initial load
duke
parents:
diff changeset
   876
  HeapWord* allocation_limit_reached(Space* space, HeapWord* top,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   877
                                     size_t word_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   878
489c9b5090e2 Initial load
duke
parents:
diff changeset
   879
  void getFreelistLocks() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   880
  void releaseFreelistLocks() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   881
  bool haveFreelistLocks() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   882
489c9b5090e2 Initial load
duke
parents:
diff changeset
   883
  // GC prologue and epilogue
489c9b5090e2 Initial load
duke
parents:
diff changeset
   884
  void gc_prologue(bool full);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   885
  void gc_epilogue(bool full);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   886
489c9b5090e2 Initial load
duke
parents:
diff changeset
   887
  jlong time_of_last_gc(jlong now) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   888
    if (_collectorState <= Idling) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   889
      // gc not in progress
489c9b5090e2 Initial load
duke
parents:
diff changeset
   890
      return _time_of_last_gc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   891
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   892
      // collection in progress
489c9b5090e2 Initial load
duke
parents:
diff changeset
   893
      return now;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   894
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   895
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   896
489c9b5090e2 Initial load
duke
parents:
diff changeset
   897
  // Support for parallel remark of survivor space
489c9b5090e2 Initial load
duke
parents:
diff changeset
   898
  void* get_data_recorder(int thr_num);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   899
489c9b5090e2 Initial load
duke
parents:
diff changeset
   900
  CMSBitMap* markBitMap()  { return &_markBitMap; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   901
  void directAllocated(HeapWord* start, size_t size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   902
489c9b5090e2 Initial load
duke
parents:
diff changeset
   903
  // main CMS steps and related support
489c9b5090e2 Initial load
duke
parents:
diff changeset
   904
  void checkpointRootsInitial(bool asynch);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   905
  bool markFromRoots(bool asynch);  // a return value of false indicates failure
489c9b5090e2 Initial load
duke
parents:
diff changeset
   906
                                    // due to stack overflow
489c9b5090e2 Initial load
duke
parents:
diff changeset
   907
  void preclean();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   908
  void checkpointRootsFinal(bool asynch, bool clear_all_soft_refs,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   909
                            bool init_mark_was_synchronous);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   910
  void sweep(bool asynch);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   911
489c9b5090e2 Initial load
duke
parents:
diff changeset
   912
  // Check that the currently executing thread is the expected
489c9b5090e2 Initial load
duke
parents:
diff changeset
   913
  // one (foreground collector or background collector).
4574
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 3690
diff changeset
   914
  static void check_correct_thread_executing() PRODUCT_RETURN;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   915
  // XXXPERM void print_statistics()           PRODUCT_RETURN;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   916
489c9b5090e2 Initial load
duke
parents:
diff changeset
   917
  bool is_cms_reachable(HeapWord* addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   918
489c9b5090e2 Initial load
duke
parents:
diff changeset
   919
  // Performance Counter Support
489c9b5090e2 Initial load
duke
parents:
diff changeset
   920
  CollectorCounters* counters()    { return _gc_counters; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   921
489c9b5090e2 Initial load
duke
parents:
diff changeset
   922
  // timer stuff
489c9b5090e2 Initial load
duke
parents:
diff changeset
   923
  void    startTimer() { assert(!_timer.is_active(), "Error"); _timer.start();   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   924
  void    stopTimer()  { assert( _timer.is_active(), "Error"); _timer.stop();    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   925
  void    resetTimer() { assert(!_timer.is_active(), "Error"); _timer.reset();   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   926
  double  timerValue() { assert(!_timer.is_active(), "Error"); return _timer.seconds(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   927
489c9b5090e2 Initial load
duke
parents:
diff changeset
   928
  int  yields()          { return _numYields; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   929
  void resetYields()     { _numYields = 0;    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   930
  void incrementYields() { _numYields++;      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   931
  void resetNumDirtyCards()               { _numDirtyCards = 0; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   932
  void incrementNumDirtyCards(size_t num) { _numDirtyCards += num; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   933
  size_t  numDirtyCards()                 { return _numDirtyCards; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   934
489c9b5090e2 Initial load
duke
parents:
diff changeset
   935
  static bool foregroundGCShouldWait() { return _foregroundGCShouldWait; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   936
  static void set_foregroundGCShouldWait(bool v) { _foregroundGCShouldWait = v; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   937
  static bool foregroundGCIsActive() { return _foregroundGCIsActive; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   938
  static void set_foregroundGCIsActive(bool v) { _foregroundGCIsActive = v; }
4574
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 3690
diff changeset
   939
  size_t sweep_count() const             { return _sweep_count; }
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 3690
diff changeset
   940
  void   increment_sweep_count()         { _sweep_count++; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   941
489c9b5090e2 Initial load
duke
parents:
diff changeset
   942
  // Timers/stats for gc scheduling and incremental mode pacing.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   943
  CMSStats& stats() { return _stats; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   944
489c9b5090e2 Initial load
duke
parents:
diff changeset
   945
  // Convenience methods that check whether CMSIncrementalMode is enabled and
489c9b5090e2 Initial load
duke
parents:
diff changeset
   946
  // forward to the corresponding methods in ConcurrentMarkSweepThread.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   947
  static void start_icms();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   948
  static void stop_icms();    // Called at the end of the cms cycle.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   949
  static void disable_icms(); // Called before a foreground collection.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   950
  static void enable_icms();  // Called after a foreground collection.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   951
  void icms_wait();          // Called at yield points.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   952
489c9b5090e2 Initial load
duke
parents:
diff changeset
   953
  // Adaptive size policy
489c9b5090e2 Initial load
duke
parents:
diff changeset
   954
  CMSAdaptiveSizePolicy* size_policy();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   955
  CMSGCAdaptivePolicyCounters* gc_adaptive_policy_counters();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   956
489c9b5090e2 Initial load
duke
parents:
diff changeset
   957
  // debugging
489c9b5090e2 Initial load
duke
parents:
diff changeset
   958
  void verify(bool);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   959
  bool verify_after_remark();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   960
  void verify_ok_to_terminate() const PRODUCT_RETURN;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   961
  void verify_work_stacks_empty() const PRODUCT_RETURN;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   962
  void verify_overflow_empty() const PRODUCT_RETURN;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   963
489c9b5090e2 Initial load
duke
parents:
diff changeset
   964
  // convenience methods in support of debugging
489c9b5090e2 Initial load
duke
parents:
diff changeset
   965
  static const size_t skip_header_HeapWords() PRODUCT_RETURN0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   966
  HeapWord* block_start(const void* p) const PRODUCT_RETURN0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   967
489c9b5090e2 Initial load
duke
parents:
diff changeset
   968
  // accessors
489c9b5090e2 Initial load
duke
parents:
diff changeset
   969
  CMSMarkStack* verification_mark_stack() { return &_markStack; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   970
  CMSBitMap*    verification_mark_bm()    { return &_verification_mark_bm; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   971
489c9b5090e2 Initial load
duke
parents:
diff changeset
   972
  // Get the bit map with a perm gen "deadness" information.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   973
  CMSBitMap* perm_gen_verify_bit_map()       { return &_perm_gen_verify_bit_map; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   974
489c9b5090e2 Initial load
duke
parents:
diff changeset
   975
  // Initialization errors
489c9b5090e2 Initial load
duke
parents:
diff changeset
   976
  bool completed_initialization() { return _completed_initialization; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   977
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   978
489c9b5090e2 Initial load
duke
parents:
diff changeset
   979
class CMSExpansionCause : public AllStatic  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   980
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   981
  enum Cause {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   982
    _no_expansion,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   983
    _satisfy_free_ratio,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   984
    _satisfy_promotion,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   985
    _satisfy_allocation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   986
    _allocate_par_lab,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   987
    _allocate_par_spooling_space,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   988
    _adaptive_size_policy
489c9b5090e2 Initial load
duke
parents:
diff changeset
   989
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   990
  // Return a string describing the cause of the expansion.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   991
  static const char* to_string(CMSExpansionCause::Cause cause);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   992
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   993
489c9b5090e2 Initial load
duke
parents:
diff changeset
   994
class ConcurrentMarkSweepGeneration: public CardGeneration {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   995
  friend class VMStructs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   996
  friend class ConcurrentMarkSweepThread;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   997
  friend class ConcurrentMarkSweep;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   998
  friend class CMSCollector;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   999
 protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1000
  static CMSCollector*       _collector; // the collector that collects us
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1001
  CompactibleFreeListSpace*  _cmsSpace;  // underlying space (only one for now)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1002
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1003
  // Performance Counters
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1004
  GenerationCounters*      _gen_counters;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1005
  GSpaceCounters*          _space_counters;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1006
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1007
  // Words directly allocated, used by CMSStats.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1008
  size_t _direct_allocated_words;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1009
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1010
  // Non-product stat counters
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1011
  NOT_PRODUCT(
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1012
    int _numObjectsPromoted;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1013
    int _numWordsPromoted;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1014
    int _numObjectsAllocated;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1015
    int _numWordsAllocated;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1016
  )
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1017
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1018
  // Used for sizing decisions
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1019
  bool _incremental_collection_failed;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1020
  bool incremental_collection_failed() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1021
    return _incremental_collection_failed;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1022
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1023
  void set_incremental_collection_failed() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1024
    _incremental_collection_failed = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1025
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1026
  void clear_incremental_collection_failed() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1027
    _incremental_collection_failed = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1028
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1029
341
6578aad59716 6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents: 1
diff changeset
  1030
  // accessors
6578aad59716 6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents: 1
diff changeset
  1031
  void set_expansion_cause(CMSExpansionCause::Cause v) { _expansion_cause = v;}
6578aad59716 6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents: 1
diff changeset
  1032
  CMSExpansionCause::Cause expansion_cause() const { return _expansion_cause; }
6578aad59716 6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents: 1
diff changeset
  1033
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1034
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1035
  // For parallel young-gen GC support.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1036
  CMSParGCThreadState** _par_gc_thread_states;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1037
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1038
  // Reason generation was expanded
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1039
  CMSExpansionCause::Cause _expansion_cause;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1040
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1041
  // In support of MinChunkSize being larger than min object size
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1042
  const double _dilatation_factor;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1043
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1044
  enum CollectionTypes {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1045
    Concurrent_collection_type          = 0,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1046
    MS_foreground_collection_type       = 1,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1047
    MSC_foreground_collection_type      = 2,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1048
    Unknown_collection_type             = 3
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1049
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1050
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1051
  CollectionTypes _debug_collection_type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1052
341
6578aad59716 6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents: 1
diff changeset
  1053
  // Fraction of current occupancy at which to start a CMS collection which
6578aad59716 6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents: 1
diff changeset
  1054
  // will collect this generation (at least).
6578aad59716 6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents: 1
diff changeset
  1055
  double _initiating_occupancy;
6578aad59716 6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents: 1
diff changeset
  1056
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1057
 protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1058
  // Shrink generation by specified size (returns false if unable to shrink)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1059
  virtual void shrink_by(size_t bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1060
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1061
  // Update statistics for GC
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1062
  virtual void update_gc_stats(int level, bool full);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1063
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1064
  // Maximum available space in the generation (including uncommitted)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1065
  // space.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1066
  size_t max_available() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1067
341
6578aad59716 6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents: 1
diff changeset
  1068
  // getter and initializer for _initiating_occupancy field.
6578aad59716 6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents: 1
diff changeset
  1069
  double initiating_occupancy() const { return _initiating_occupancy; }
6578aad59716 6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents: 1
diff changeset
  1070
  void   init_initiating_occupancy(intx io, intx tr);
6578aad59716 6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents: 1
diff changeset
  1071
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1072
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1073
  ConcurrentMarkSweepGeneration(ReservedSpace rs, size_t initial_byte_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1074
                                int level, CardTableRS* ct,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1075
                                bool use_adaptive_freelists,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1076
                                FreeBlockDictionary::DictionaryChoice);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1077
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1078
  // Accessors
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1079
  CMSCollector* collector() const { return _collector; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1080
  static void set_collector(CMSCollector* collector) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1081
    assert(_collector == NULL, "already set");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1082
    _collector = collector;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1083
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1084
  CompactibleFreeListSpace*  cmsSpace() const { return _cmsSpace;  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1085
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1086
  Mutex* freelistLock() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1087
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1088
  virtual Generation::Name kind() { return Generation::ConcurrentMarkSweep; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1089
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1090
  // Adaptive size policy
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1091
  CMSAdaptiveSizePolicy* size_policy();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1092
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1093
  bool refs_discovery_is_atomic() const { return false; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1094
  bool refs_discovery_is_mt()     const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1095
    // Note: CMS does MT-discovery during the parallel-remark
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1096
    // phases. Use ReferenceProcessorMTMutator to make refs
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1097
    // discovery MT-safe during such phases or other parallel
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1098
    // discovery phases in the future. This may all go away
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1099
    // if/when we decide that refs discovery is sufficiently
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1100
    // rare that the cost of the CAS's involved is in the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1101
    // noise. That's a measurement that should be done, and
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1102
    // the code simplified if that turns out to be the case.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1103
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1104
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1105
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1106
  // Override
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1107
  virtual void ref_processor_init();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1108
979
c9479f1e0a94 6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents: 670
diff changeset
  1109
  // Grow generation by specified size (returns false if unable to grow)
c9479f1e0a94 6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents: 670
diff changeset
  1110
  bool grow_by(size_t bytes);
c9479f1e0a94 6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents: 670
diff changeset
  1111
  // Grow generation to reserved size.
c9479f1e0a94 6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents: 670
diff changeset
  1112
  bool grow_to_reserved();
c9479f1e0a94 6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents: 670
diff changeset
  1113
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1114
  void clear_expansion_cause() { _expansion_cause = CMSExpansionCause::_no_expansion; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1115
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1116
  // Space enquiries
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1117
  size_t capacity() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1118
  size_t used() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1119
  size_t free() const;
341
6578aad59716 6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents: 1
diff changeset
  1120
  double occupancy() const { return ((double)used())/((double)capacity()); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1121
  size_t contiguous_available() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1122
  size_t unsafe_max_alloc_nogc() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1123
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1124
  // over-rides
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1125
  MemRegion used_region() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1126
  MemRegion used_region_at_save_marks() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1127
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1128
  // Does a "full" (forced) collection invoked on this generation collect
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1129
  // all younger generations as well? Note that the second conjunct is a
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1130
  // hack to allow the collection of the younger gen first if the flag is
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1131
  // set. This is better than using th policy's should_collect_gen0_first()
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1132
  // since that causes us to do an extra unnecessary pair of restart-&-stop-world.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1133
  virtual bool full_collects_younger_generations() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1134
    return UseCMSCompactAtFullCollection && !CollectGen0First;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1135
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1136
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1137
  void space_iterate(SpaceClosure* blk, bool usedOnly = false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1138
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1139
  // Support for compaction
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1140
  CompactibleSpace* first_compaction_space() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1141
  // Adjust quantites in the generation affected by
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1142
  // the compaction.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1143
  void reset_after_compaction();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1144
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1145
  // Allocation support
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1146
  HeapWord* allocate(size_t size, bool tlab);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1147
  HeapWord* have_lock_and_allocate(size_t size, bool tlab);
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 341
diff changeset
  1148
  oop       promote(oop obj, size_t obj_size);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1149
  HeapWord* par_allocate(size_t size, bool tlab) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1150
    return allocate(size, tlab);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1151
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1152
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1153
  // Incremental mode triggering.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1154
  HeapWord* allocation_limit_reached(Space* space, HeapWord* top,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1155
                                     size_t word_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1156
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1157
  // Used by CMSStats to track direct allocation.  The value is sampled and
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1158
  // reset after each young gen collection.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1159
  size_t direct_allocated_words() const { return _direct_allocated_words; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1160
  void reset_direct_allocated_words()   { _direct_allocated_words = 0; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1161
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1162
  // Overrides for parallel promotion.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1163
  virtual oop par_promote(int thread_num,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1164
                          oop obj, markOop m, size_t word_sz);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1165
  // This one should not be called for CMS.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1166
  virtual void par_promote_alloc_undo(int thread_num,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1167
                                      HeapWord* obj, size_t word_sz);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1168
  virtual void par_promote_alloc_done(int thread_num);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1169
  virtual void par_oop_since_save_marks_iterate_done(int thread_num);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1170
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1171
  virtual bool promotion_attempt_is_safe(size_t promotion_in_bytes,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1172
    bool younger_handles_promotion_failure) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1173
4574
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 3690
diff changeset
  1174
  // Inform this (non-young) generation that a promotion failure was
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 3690
diff changeset
  1175
  // encountered during a collection of a younger generation that
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 3690
diff changeset
  1176
  // promotes into this generation.
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 3690
diff changeset
  1177
  virtual void promotion_failure_occurred();
b2d5b0975515 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 3690
diff changeset
  1178
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1179
  bool should_collect(bool full, size_t size, bool tlab);
341
6578aad59716 6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents: 1
diff changeset
  1180
  virtual bool should_concurrent_collect() const;
6578aad59716 6634032: CMS: Need CMSInitiatingPermOccupancyFraction for perm, divorcing from CMSInitiatingOccupancyFraction
ysr
parents: 1
diff changeset
  1181
  virtual bool is_too_full() const;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1182
  void collect(bool   full,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1183
               bool   clear_all_soft_refs,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1184
               size_t size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1185
               bool   tlab);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1186
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1187
  HeapWord* expand_and_allocate(size_t word_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1188
                                bool tlab,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1189
                                bool parallel = false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1190
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1191
  // GC prologue and epilogue
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1192
  void gc_prologue(bool full);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1193
  void gc_prologue_work(bool full, bool registerClosure,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1194
                        ModUnionClosure* modUnionClosure);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1195
  void gc_epilogue(bool full);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1196
  void gc_epilogue_work(bool full);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1197
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1198
  // Time since last GC of this generation
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1199
  jlong time_of_last_gc(jlong now) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1200
    return collector()->time_of_last_gc(now);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1201
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1202
  void update_time_of_last_gc(jlong now) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1203
    collector()-> update_time_of_last_gc(now);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1204
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1205
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1206
  // Allocation failure
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1207
  void expand(size_t bytes, size_t expand_bytes,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1208
    CMSExpansionCause::Cause cause);
979
c9479f1e0a94 6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents: 670
diff changeset
  1209
  virtual bool expand(size_t bytes, size_t expand_bytes);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1210
  void shrink(size_t bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1211
  HeapWord* expand_and_par_lab_allocate(CMSParGCThreadState* ps, size_t word_sz);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1212
  bool expand_and_ensure_spooling_space(PromotionInfo* promo);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1213
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1214
  // Iteration support and related enquiries
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1215
  void save_marks();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1216
  bool no_allocs_since_save_marks();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1217
  void object_iterate_since_last_GC(ObjectClosure* cl);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1218
  void younger_refs_iterate(OopsInGenClosure* cl);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1219
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1220
  // Iteration support specific to CMS generations
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1221
  void save_sweep_limit();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1222
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1223
  // More iteration support
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1224
  virtual void oop_iterate(MemRegion mr, OopClosure* cl);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1225
  virtual void oop_iterate(OopClosure* cl);
1893
c82e388e17c5 6689653: JMapPerm fails with UseConcMarkSweepIncGC and compressed oops off
jmasa
parents: 1605
diff changeset
  1226
  virtual void safe_object_iterate(ObjectClosure* cl);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1227
  virtual void object_iterate(ObjectClosure* cl);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1228
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1229
  // Need to declare the full complement of closures, whether we'll
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1230
  // override them or not, or get message from the compiler:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1231
  //   oop_since_save_marks_iterate_nv hides virtual function...
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1232
  #define CMS_SINCE_SAVE_MARKS_DECL(OopClosureType, nv_suffix) \
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1233
    void oop_since_save_marks_iterate##nv_suffix(OopClosureType* cl);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1234
  ALL_SINCE_SAVE_MARKS_CLOSURES(CMS_SINCE_SAVE_MARKS_DECL)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1235
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1236
  // Smart allocation  XXX -- move to CFLSpace?
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1237
  void setNearLargestChunk();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1238
  bool isNearLargestChunk(HeapWord* addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1239
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1240
  // Get the chunk at the end of the space.  Delagates to
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1241
  // the space.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1242
  FreeChunk* find_chunk_at_end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1243
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1244
  // Overriding of unused functionality (sharing not yet supported with CMS)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1245
  void pre_adjust_pointers();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1246
  void post_compact();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1247
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1248
  // Debugging
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1249
  void prepare_for_verify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1250
  void verify(bool allow_dirty);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1251
  void print_statistics()               PRODUCT_RETURN;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1252
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1253
  // Performance Counters support
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1254
  virtual void update_counters();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1255
  virtual void update_counters(size_t used);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1256
  void initialize_performance_counters();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1257
  CollectorCounters* counters()  { return collector()->counters(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1258
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1259
  // Support for parallel remark of survivor space
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1260
  void* get_data_recorder(int thr_num) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1261
    //Delegate to collector
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1262
    return collector()->get_data_recorder(thr_num);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1263
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1264
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1265
  // Printing
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1266
  const char* name() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1267
  virtual const char* short_name() const { return "CMS"; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1268
  void        print() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1269
  void printOccupancy(const char* s);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1270
  bool must_be_youngest() const { return false; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1271
  bool must_be_oldest()   const { return true; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1272
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1273
  void compute_new_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1274
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1275
  CollectionTypes debug_collection_type() { return _debug_collection_type; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1276
  void rotate_debug_collection_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1277
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1278
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1279
class ASConcurrentMarkSweepGeneration : public ConcurrentMarkSweepGeneration {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1280
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1281
  // Return the size policy from the heap's collector
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1282
  // policy casted to CMSAdaptiveSizePolicy*.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1283
  CMSAdaptiveSizePolicy* cms_size_policy() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1284
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1285
  // Resize the generation based on the adaptive size
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1286
  // policy.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1287
  void resize(size_t cur_promo, size_t desired_promo);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1288
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1289
  // Return the GC counters from the collector policy
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1290
  CMSGCAdaptivePolicyCounters* gc_adaptive_policy_counters();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1291
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1292
  virtual void shrink_by(size_t bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1293
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1294
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1295
  virtual void compute_new_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1296
  ASConcurrentMarkSweepGeneration(ReservedSpace rs, size_t initial_byte_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1297
                                  int level, CardTableRS* ct,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1298
                                  bool use_adaptive_freelists,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1299
                                  FreeBlockDictionary::DictionaryChoice
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1300
                                    dictionaryChoice) :
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1301
    ConcurrentMarkSweepGeneration(rs, initial_byte_size, level, ct,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1302
      use_adaptive_freelists, dictionaryChoice) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1303
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1304
  virtual const char* short_name() const { return "ASCMS"; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1305
  virtual Generation::Name kind() { return Generation::ASConcurrentMarkSweep; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1306
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1307
  virtual void update_counters();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1308
  virtual void update_counters(size_t used);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1309
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1310
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1311
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1312
// Closures of various sorts used by CMS to accomplish its work
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1313
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1314
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1315
// This closure is used to check that a certain set of oops is empty.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1316
class FalseClosure: public OopClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1317
 public:
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 341
diff changeset
  1318
  void do_oop(oop* p)       { guarantee(false, "Should be an empty set"); }
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 341
diff changeset
  1319
  void do_oop(narrowOop* p) { guarantee(false, "Should be an empty set"); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1320
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1321
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1322
// This closure is used to do concurrent marking from the roots
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1323
// following the first checkpoint.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1324
class MarkFromRootsClosure: public BitMapClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1325
  CMSCollector*  _collector;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1326
  MemRegion      _span;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1327
  CMSBitMap*     _bitMap;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1328
  CMSBitMap*     _mut;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1329
  CMSMarkStack*  _markStack;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1330
  CMSMarkStack*  _revisitStack;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1331
  bool           _yield;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1332
  int            _skipBits;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1333
  HeapWord*      _finger;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1334
  HeapWord*      _threshold;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1335
  DEBUG_ONLY(bool _verifying;)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1336
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1337
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1338
  MarkFromRootsClosure(CMSCollector* collector, MemRegion span,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1339
                       CMSBitMap* bitMap,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1340
                       CMSMarkStack*  markStack,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1341
                       CMSMarkStack*  revisitStack,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1342
                       bool should_yield, bool verifying = false);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 390
diff changeset
  1343
  bool do_bit(size_t offset);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1344
  void reset(HeapWord* addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1345
  inline void do_yield_check();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1346
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1347
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1348
  void scanOopsInOop(HeapWord* ptr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1349
  void do_yield_work();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1350
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1351
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1352
// This closure is used to do concurrent multi-threaded
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1353
// marking from the roots following the first checkpoint.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1354
// XXX This should really be a subclass of The serial version
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1355
// above, but i have not had the time to refactor things cleanly.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1356
// That willbe done for Dolphin.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1357
class Par_MarkFromRootsClosure: public BitMapClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1358
  CMSCollector*  _collector;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1359
  MemRegion      _whole_span;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1360
  MemRegion      _span;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1361
  CMSBitMap*     _bit_map;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1362
  CMSBitMap*     _mut;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1363
  OopTaskQueue*  _work_queue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1364
  CMSMarkStack*  _overflow_stack;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1365
  CMSMarkStack*  _revisit_stack;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1366
  bool           _yield;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1367
  int            _skip_bits;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1368
  HeapWord*      _finger;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1369
  HeapWord*      _threshold;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1370
  CMSConcMarkingTask* _task;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1371
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1372
  Par_MarkFromRootsClosure(CMSConcMarkingTask* task, CMSCollector* collector,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1373
                       MemRegion span,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1374
                       CMSBitMap* bit_map,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1375
                       OopTaskQueue* work_queue,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1376
                       CMSMarkStack*  overflow_stack,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1377
                       CMSMarkStack*  revisit_stack,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1378
                       bool should_yield);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 390
diff changeset
  1379
  bool do_bit(size_t offset);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1380
  inline void do_yield_check();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1381
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1382
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1383
  void scan_oops_in_oop(HeapWord* ptr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1384
  void do_yield_work();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1385
  bool get_work_from_overflow_stack();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1386
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1387
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1388
// The following closures are used to do certain kinds of verification of
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1389
// CMS marking.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1390
class PushAndMarkVerifyClosure: public OopClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1391
  CMSCollector*    _collector;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1392
  MemRegion        _span;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1393
  CMSBitMap*       _verification_bm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1394
  CMSBitMap*       _cms_bm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1395
  CMSMarkStack*    _mark_stack;
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 341
diff changeset
  1396
 protected:
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 341
diff changeset
  1397
  void do_oop(oop p);
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 341
diff changeset
  1398
  template <class T> inline void do_oop_work(T *p) {
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 341
diff changeset
  1399
    oop obj = oopDesc::load_decode_heap_oop_not_null(p);
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 341
diff changeset
  1400
    do_oop(obj);
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 341
diff changeset
  1401
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1402
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1403
  PushAndMarkVerifyClosure(CMSCollector* cms_collector,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1404
                           MemRegion span,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1405
                           CMSBitMap* verification_bm,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1406
                           CMSBitMap* cms_bm,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1407
                           CMSMarkStack*  mark_stack);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1408
  void do_oop(oop* p);
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 341
diff changeset
  1409
  void do_oop(narrowOop* p);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1410
  // Deal with a stack overflow condition
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1411
  void handle_stack_overflow(HeapWord* lost);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1412
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1413
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1414
class MarkFromRootsVerifyClosure: public BitMapClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1415
  CMSCollector*  _collector;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1416
  MemRegion      _span;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1417
  CMSBitMap*     _verification_bm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1418
  CMSBitMap*     _cms_bm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1419
  CMSMarkStack*  _mark_stack;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1420
  HeapWord*      _finger;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1421
  PushAndMarkVerifyClosure _pam_verify_closure;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1422
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1423
  MarkFromRootsVerifyClosure(CMSCollector* collector, MemRegion span,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1424
                             CMSBitMap* verification_bm,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1425
                             CMSBitMap* cms_bm,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1426
                             CMSMarkStack*  mark_stack);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 390
diff changeset
  1427
  bool do_bit(size_t offset);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1428
  void reset(HeapWord* addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1429
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1430
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1431
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1432
// This closure is used to check that a certain set of bits is
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1433
// "empty" (i.e. the bit vector doesn't have any 1-bits).
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1434
class FalseBitMapClosure: public BitMapClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1435
 public:
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 390
diff changeset
  1436
  bool do_bit(size_t offset) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1437
    guarantee(false, "Should not have a 1 bit");
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 390
diff changeset
  1438
    return true;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1439
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1440
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1441
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1442
// This closure is used during the second checkpointing phase
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1443
// to rescan the marked objects on the dirty cards in the mod
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1444
// union table and the card table proper. It's invoked via
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1445
// MarkFromDirtyCardsClosure below. It uses either
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1446
// [Par_]MarkRefsIntoAndScanClosure (Par_ in the parallel case)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1447
// declared in genOopClosures.hpp to accomplish some of its work.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1448
// In the parallel case the bitMap is shared, so access to
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1449
// it needs to be suitably synchronized for updates by embedded
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1450
// closures that update it; however, this closure itself only
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1451
// reads the bit_map and because it is idempotent, is immune to
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1452
// reading stale values.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1453
class ScanMarkedObjectsAgainClosure: public UpwardsObjectClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1454
  #ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1455
    CMSCollector*          _collector;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1456
    MemRegion              _span;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1457
    union {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1458
      CMSMarkStack*        _mark_stack;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1459
      OopTaskQueue*        _work_queue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1460
    };
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1461
  #endif // ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1462
  bool                       _parallel;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1463
  CMSBitMap*                 _bit_map;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1464
  union {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1465
    MarkRefsIntoAndScanClosure*     _scan_closure;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1466
    Par_MarkRefsIntoAndScanClosure* _par_scan_closure;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1467
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1468
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1469
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1470
  ScanMarkedObjectsAgainClosure(CMSCollector* collector,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1471
                                MemRegion span,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1472
                                ReferenceProcessor* rp,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1473
                                CMSBitMap* bit_map,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1474
                                CMSMarkStack*  mark_stack,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1475
                                CMSMarkStack*  revisit_stack,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1476
                                MarkRefsIntoAndScanClosure* cl):
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1477
    #ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1478
      _collector(collector),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1479
      _span(span),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1480
      _mark_stack(mark_stack),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1481
    #endif // ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1482
    _parallel(false),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1483
    _bit_map(bit_map),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1484
    _scan_closure(cl) { }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1485
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1486
  ScanMarkedObjectsAgainClosure(CMSCollector* collector,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1487
                                MemRegion span,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1488
                                ReferenceProcessor* rp,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1489
                                CMSBitMap* bit_map,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1490
                                OopTaskQueue* work_queue,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1491
                                CMSMarkStack* revisit_stack,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1492
                                Par_MarkRefsIntoAndScanClosure* cl):
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1493
    #ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1494
      _collector(collector),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1495
      _span(span),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1496
      _work_queue(work_queue),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1497
    #endif // ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1498
    _parallel(true),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1499
    _bit_map(bit_map),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1500
    _par_scan_closure(cl) { }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1501
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1502
  void do_object(oop obj) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1503
    guarantee(false, "Call do_object_b(oop, MemRegion) instead");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1504
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1505
  bool do_object_b(oop obj) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1506
    guarantee(false, "Call do_object_b(oop, MemRegion) form instead");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1507
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1508
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1509
  bool do_object_bm(oop p, MemRegion mr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1510
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1511
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1512
// This closure is used during the second checkpointing phase
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1513
// to rescan the marked objects on the dirty cards in the mod
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1514
// union table and the card table proper. It invokes
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1515
// ScanMarkedObjectsAgainClosure above to accomplish much of its work.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1516
// In the parallel case, the bit map is shared and requires
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1517
// synchronized access.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1518
class MarkFromDirtyCardsClosure: public MemRegionClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1519
  CompactibleFreeListSpace*      _space;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1520
  ScanMarkedObjectsAgainClosure  _scan_cl;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1521
  size_t                         _num_dirty_cards;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1522
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1523
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1524
  MarkFromDirtyCardsClosure(CMSCollector* collector,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1525
                            MemRegion span,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1526
                            CompactibleFreeListSpace* space,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1527
                            CMSBitMap* bit_map,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1528
                            CMSMarkStack* mark_stack,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1529
                            CMSMarkStack* revisit_stack,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1530
                            MarkRefsIntoAndScanClosure* cl):
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1531
    _space(space),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1532
    _num_dirty_cards(0),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1533
    _scan_cl(collector, span, collector->ref_processor(), bit_map,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1534
                 mark_stack, revisit_stack, cl) { }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1535
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1536
  MarkFromDirtyCardsClosure(CMSCollector* collector,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1537
                            MemRegion span,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1538
                            CompactibleFreeListSpace* space,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1539
                            CMSBitMap* bit_map,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1540
                            OopTaskQueue* work_queue,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1541
                            CMSMarkStack* revisit_stack,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1542
                            Par_MarkRefsIntoAndScanClosure* cl):
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1543
    _space(space),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1544
    _num_dirty_cards(0),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1545
    _scan_cl(collector, span, collector->ref_processor(), bit_map,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1546
             work_queue, revisit_stack, cl) { }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1547
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1548
  void do_MemRegion(MemRegion mr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1549
  void set_space(CompactibleFreeListSpace* space) { _space = space; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1550
  size_t num_dirty_cards() { return _num_dirty_cards; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1551
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1552
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1553
// This closure is used in the non-product build to check
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1554
// that there are no MemRegions with a certain property.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1555
class FalseMemRegionClosure: public MemRegionClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1556
  void do_MemRegion(MemRegion mr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1557
    guarantee(!mr.is_empty(), "Shouldn't be empty");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1558
    guarantee(false, "Should never be here");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1559
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1560
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1561
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1562
// This closure is used during the precleaning phase
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1563
// to "carefully" rescan marked objects on dirty cards.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1564
// It uses MarkRefsIntoAndScanClosure declared in genOopClosures.hpp
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1565
// to accomplish some of its work.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1566
class ScanMarkedObjectsAgainCarefullyClosure: public ObjectClosureCareful {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1567
  CMSCollector*                  _collector;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1568
  MemRegion                      _span;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1569
  bool                           _yield;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1570
  Mutex*                         _freelistLock;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1571
  CMSBitMap*                     _bitMap;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1572
  CMSMarkStack*                  _markStack;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1573
  MarkRefsIntoAndScanClosure*    _scanningClosure;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1574
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1575
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1576
  ScanMarkedObjectsAgainCarefullyClosure(CMSCollector* collector,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1577
                                         MemRegion     span,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1578
                                         CMSBitMap* bitMap,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1579
                                         CMSMarkStack*  markStack,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1580
                                         CMSMarkStack*  revisitStack,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1581
                                         MarkRefsIntoAndScanClosure* cl,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1582
                                         bool should_yield):
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1583
    _collector(collector),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1584
    _span(span),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1585
    _yield(should_yield),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1586
    _bitMap(bitMap),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1587
    _markStack(markStack),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1588
    _scanningClosure(cl) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1589
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1590
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1591
  void do_object(oop p) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1592
    guarantee(false, "call do_object_careful instead");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1593
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1594
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1595
  size_t      do_object_careful(oop p) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1596
    guarantee(false, "Unexpected caller");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1597
    return 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1598
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1599
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1600
  size_t      do_object_careful_m(oop p, MemRegion mr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1601
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1602
  void setFreelistLock(Mutex* m) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1603
    _freelistLock = m;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1604
    _scanningClosure->set_freelistLock(m);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1605
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1606
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1607
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1608
  inline bool do_yield_check();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1609
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1610
  void do_yield_work();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1611
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1612
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1613
class SurvivorSpacePrecleanClosure: public ObjectClosureCareful {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1614
  CMSCollector*                  _collector;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1615
  MemRegion                      _span;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1616
  bool                           _yield;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1617
  CMSBitMap*                     _bit_map;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1618
  CMSMarkStack*                  _mark_stack;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1619
  PushAndMarkClosure*            _scanning_closure;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1620
  unsigned int                   _before_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1621
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1622
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1623
  SurvivorSpacePrecleanClosure(CMSCollector* collector,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1624
                               MemRegion     span,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1625
                               CMSBitMap*    bit_map,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1626
                               CMSMarkStack* mark_stack,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1627
                               PushAndMarkClosure* cl,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1628
                               unsigned int  before_count,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1629
                               bool          should_yield):
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1630
    _collector(collector),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1631
    _span(span),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1632
    _yield(should_yield),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1633
    _bit_map(bit_map),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1634
    _mark_stack(mark_stack),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1635
    _scanning_closure(cl),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1636
    _before_count(before_count)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1637
  { }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1638
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1639
  void do_object(oop p) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1640
    guarantee(false, "call do_object_careful instead");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1641
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1642
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1643
  size_t      do_object_careful(oop p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1644
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1645
  size_t      do_object_careful_m(oop p, MemRegion mr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1646
    guarantee(false, "Unexpected caller");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1647
    return 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1648
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1649
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1650
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1651
  inline void do_yield_check();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1652
  void do_yield_work();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1653
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1654
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1655
// This closure is used to accomplish the sweeping work
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1656
// after the second checkpoint but before the concurrent reset
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1657
// phase.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1658
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1659
// Terminology
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1660
//   left hand chunk (LHC) - block of one or more chunks currently being
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1661
//     coalesced.  The LHC is available for coalescing with a new chunk.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1662
//   right hand chunk (RHC) - block that is currently being swept that is
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1663
//     free or garbage that can be coalesced with the LHC.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1664
// _inFreeRange is true if there is currently a LHC
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1665
// _lastFreeRangeCoalesced is true if the LHC consists of more than one chunk.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1666
// _freeRangeInFreeLists is true if the LHC is in the free lists.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1667
// _freeFinger is the address of the current LHC
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1668
class SweepClosure: public BlkClosureCareful {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1669
  CMSCollector*                  _collector;  // collector doing the work
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1670
  ConcurrentMarkSweepGeneration* _g;    // Generation being swept
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1671
  CompactibleFreeListSpace*      _sp;   // Space being swept
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1672
  HeapWord*                      _limit;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1673
  Mutex*                         _freelistLock; // Free list lock (in space)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1674
  CMSBitMap*                     _bitMap;       // Marking bit map (in
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1675
                                                // generation)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1676
  bool                           _inFreeRange;  // Indicates if we are in the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1677
                                                // midst of a free run
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1678
  bool                           _freeRangeInFreeLists;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1679
                                        // Often, we have just found
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1680
                                        // a free chunk and started
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1681
                                        // a new free range; we do not
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1682
                                        // eagerly remove this chunk from
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1683
                                        // the free lists unless there is
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1684
                                        // a possibility of coalescing.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1685
                                        // When true, this flag indicates
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1686
                                        // that the _freeFinger below
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1687
                                        // points to a potentially free chunk
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1688
                                        // that may still be in the free lists
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1689
  bool                           _lastFreeRangeCoalesced;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1690
                                        // free range contains chunks
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1691
                                        // coalesced
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1692
  bool                           _yield;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1693
                                        // Whether sweeping should be
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1694
                                        // done with yields. For instance
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1695
                                        // when done by the foreground
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1696
                                        // collector we shouldn't yield.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1697
  HeapWord*                      _freeFinger;   // When _inFreeRange is set, the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1698
                                                // pointer to the "left hand
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1699
                                                // chunk"
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1700
  size_t                         _freeRangeSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1701
                                        // When _inFreeRange is set, this
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1702
                                        // indicates the accumulated size
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1703
                                        // of the "left hand chunk"
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1704
  NOT_PRODUCT(
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1705
    size_t                       _numObjectsFreed;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1706
    size_t                       _numWordsFreed;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1707
    size_t                       _numObjectsLive;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1708
    size_t                       _numWordsLive;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1709
    size_t                       _numObjectsAlreadyFree;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1710
    size_t                       _numWordsAlreadyFree;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1711
    FreeChunk*                   _last_fc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1712
  )
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1713
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1714
  // Code that is common to a free chunk or garbage when
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1715
  // encountered during sweeping.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1716
  void doPostIsFreeOrGarbageChunk(FreeChunk *fc,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1717
                                  size_t chunkSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1718
  // Process a free chunk during sweeping.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1719
  void doAlreadyFreeChunk(FreeChunk *fc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1720
  // Process a garbage chunk during sweeping.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1721
  size_t doGarbageChunk(FreeChunk *fc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1722
  // Process a live chunk during sweeping.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1723
  size_t doLiveChunk(FreeChunk* fc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1724
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1725
  // Accessors.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1726
  HeapWord* freeFinger() const          { return _freeFinger; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1727
  void set_freeFinger(HeapWord* v)      { _freeFinger = v; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1728
  size_t freeRangeSize() const          { return _freeRangeSize; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1729
  void set_freeRangeSize(size_t v)      { _freeRangeSize = v; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1730
  bool inFreeRange()    const           { return _inFreeRange; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1731
  void set_inFreeRange(bool v)          { _inFreeRange = v; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1732
  bool lastFreeRangeCoalesced() const    { return _lastFreeRangeCoalesced; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1733
  void set_lastFreeRangeCoalesced(bool v) { _lastFreeRangeCoalesced = v; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1734
  bool freeRangeInFreeLists() const     { return _freeRangeInFreeLists; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1735
  void set_freeRangeInFreeLists(bool v) { _freeRangeInFreeLists = v; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1736
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1737
  // Initialize a free range.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1738
  void initialize_free_range(HeapWord* freeFinger, bool freeRangeInFreeLists);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1739
  // Return this chunk to the free lists.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1740
  void flushCurFreeChunk(HeapWord* chunk, size_t size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1741
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1742
  // Check if we should yield and do so when necessary.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1743
  inline void do_yield_check(HeapWord* addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1744
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1745
  // Yield
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1746
  void do_yield_work(HeapWord* addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1747
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1748
  // Debugging/Printing
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1749
  void record_free_block_coalesced(FreeChunk* fc) const PRODUCT_RETURN;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1750
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1751
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1752
  SweepClosure(CMSCollector* collector, ConcurrentMarkSweepGeneration* g,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1753
               CMSBitMap* bitMap, bool should_yield);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1754
  ~SweepClosure();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1755
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1756
  size_t       do_blk_careful(HeapWord* addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1757
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1758
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1759
// Closures related to weak references processing
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1760
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1761
// During CMS' weak reference processing, this is a
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1762
// work-routine/closure used to complete transitive
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1763
// marking of objects as live after a certain point
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1764
// in which an initial set has been completely accumulated.
1605
6b43d186eb8d 6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents: 1388
diff changeset
  1765
// This closure is currently used both during the final
6b43d186eb8d 6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents: 1388
diff changeset
  1766
// remark stop-world phase, as well as during the concurrent
6b43d186eb8d 6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents: 1388
diff changeset
  1767
// precleaning of the discovered reference lists.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1768
class CMSDrainMarkingStackClosure: public VoidClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1769
  CMSCollector*        _collector;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1770
  MemRegion            _span;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1771
  CMSMarkStack*        _mark_stack;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1772
  CMSBitMap*           _bit_map;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1773
  CMSKeepAliveClosure* _keep_alive;
1605
6b43d186eb8d 6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents: 1388
diff changeset
  1774
  bool                 _concurrent_precleaning;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1775
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1776
  CMSDrainMarkingStackClosure(CMSCollector* collector, MemRegion span,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1777
                      CMSBitMap* bit_map, CMSMarkStack* mark_stack,
1605
6b43d186eb8d 6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents: 1388
diff changeset
  1778
                      CMSKeepAliveClosure* keep_alive,
6b43d186eb8d 6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents: 1388
diff changeset
  1779
                      bool cpc):
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1780
    _collector(collector),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1781
    _span(span),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1782
    _bit_map(bit_map),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1783
    _mark_stack(mark_stack),
1605
6b43d186eb8d 6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents: 1388
diff changeset
  1784
    _keep_alive(keep_alive),
6b43d186eb8d 6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents: 1388
diff changeset
  1785
    _concurrent_precleaning(cpc) {
6b43d186eb8d 6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents: 1388
diff changeset
  1786
    assert(_concurrent_precleaning == _keep_alive->concurrent_precleaning(),
6b43d186eb8d 6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents: 1388
diff changeset
  1787
           "Mismatch");
6b43d186eb8d 6722113: CMS: Incorrect overflow handling during precleaning of Reference lists
ysr
parents: 1388
diff changeset
  1788
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1789
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1790
  void do_void();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1791
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1792
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1793
// A parallel version of CMSDrainMarkingStackClosure above.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1794
class CMSParDrainMarkingStackClosure: public VoidClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1795
  CMSCollector*           _collector;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1796
  MemRegion               _span;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1797
  OopTaskQueue*           _work_queue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1798
  CMSBitMap*              _bit_map;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1799
  CMSInnerParMarkAndPushClosure _mark_and_push;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1800
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1801
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1802
  CMSParDrainMarkingStackClosure(CMSCollector* collector,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1803
                                 MemRegion span, CMSBitMap* bit_map,
3690
dba50b88bd50 6798898: CMS: bugs related to class unloading
jmasa
parents: 2885
diff changeset
  1804
                                 CMSMarkStack* revisit_stack,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1805
                                 OopTaskQueue* work_queue):
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1806
    _collector(collector),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1807
    _span(span),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1808
    _bit_map(bit_map),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1809
    _work_queue(work_queue),
3690
dba50b88bd50 6798898: CMS: bugs related to class unloading
jmasa
parents: 2885
diff changeset
  1810
    _mark_and_push(collector, span, bit_map, revisit_stack, work_queue) { }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1811
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1812
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1813
  void trim_queue(uint max);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1814
  void do_void();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1815
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1816
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1817
// Allow yielding or short-circuiting of reference list
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1818
// prelceaning work.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1819
class CMSPrecleanRefsYieldClosure: public YieldClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1820
  CMSCollector* _collector;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1821
  void do_yield_work();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1822
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1823
  CMSPrecleanRefsYieldClosure(CMSCollector* collector):
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1824
    _collector(collector) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1825
  virtual bool should_return();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1826
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1827
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1828
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1829
// Convenience class that locks free list locks for given CMS collector
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1830
class FreelistLocker: public StackObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1831
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1832
  CMSCollector* _collector;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1833
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1834
  FreelistLocker(CMSCollector* collector):
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1835
    _collector(collector) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1836
    _collector->getFreelistLocks();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1837
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1838
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1839
  ~FreelistLocker() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1840
    _collector->releaseFreelistLocks();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1841
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1842
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1843
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1844
// Mark all dead objects in a given space.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1845
class MarkDeadObjectsClosure: public BlkClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1846
  const CMSCollector*             _collector;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1847
  const CompactibleFreeListSpace* _sp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1848
  CMSBitMap*                      _live_bit_map;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1849
  CMSBitMap*                      _dead_bit_map;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1850
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1851
  MarkDeadObjectsClosure(const CMSCollector* collector,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1852
                         const CompactibleFreeListSpace* sp,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1853
                         CMSBitMap *live_bit_map,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1854
                         CMSBitMap *dead_bit_map) :
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1855
    _collector(collector),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1856
    _sp(sp),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1857
    _live_bit_map(live_bit_map),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1858
    _dead_bit_map(dead_bit_map) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1859
  size_t do_blk(HeapWord* addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1860
};