hotspot/src/share/vm/gc/shared/cardGeneration.cpp
author jwilhelm
Wed, 17 Jun 2015 14:44:54 +0200
changeset 31358 693058672cc6
parent 30870 3050fdcdc60b
child 33212 906b3d079b13
permissions -rw-r--r--
8077842: Remove the level parameter passed around in GenCollectedHeap Reviewed-by: kbarrett, mgerdin
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
28031
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
     1
/*
30173
13cf7580b000 8077413: Avoid use of Universe::heap() inside collectors
pliden
parents: 28033
diff changeset
     2
 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
28031
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
     4
 *
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
     7
 * published by the Free Software Foundation.
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
     8
 *
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
    13
 * accompanied this code).
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
    14
 *
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
    18
 *
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
    21
 * questions.
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
    22
 *
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
    23
 */
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
    24
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
    25
#include "precompiled.hpp"
28033
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
    26
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30173
diff changeset
    27
#include "gc/shared/blockOffsetTable.inline.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30173
diff changeset
    28
#include "gc/shared/cardGeneration.inline.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30173
diff changeset
    29
#include "gc/shared/gcLocker.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30173
diff changeset
    30
#include "gc/shared/genOopClosures.inline.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30173
diff changeset
    31
#include "gc/shared/genRemSet.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30173
diff changeset
    32
#include "gc/shared/generationSpec.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30173
diff changeset
    33
#include "gc/shared/space.inline.hpp"
28031
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
    34
#include "memory/iterator.hpp"
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
    35
#include "memory/memRegion.hpp"
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
    36
#include "runtime/java.hpp"
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
    37
31358
693058672cc6 8077842: Remove the level parameter passed around in GenCollectedHeap
jwilhelm
parents: 30870
diff changeset
    38
CardGeneration::CardGeneration(ReservedSpace rs,
693058672cc6 8077842: Remove the level parameter passed around in GenCollectedHeap
jwilhelm
parents: 30870
diff changeset
    39
                               size_t initial_byte_size,
28031
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
    40
                               GenRemSet* remset) :
31358
693058672cc6 8077842: Remove the level parameter passed around in GenCollectedHeap
jwilhelm
parents: 30870
diff changeset
    41
  Generation(rs, initial_byte_size), _rs(remset),
28031
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
    42
  _shrink_factor(0), _min_heap_delta_bytes(), _capacity_at_prologue(),
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
    43
  _used_at_prologue()
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
    44
{
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
    45
  HeapWord* start = (HeapWord*)rs.base();
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
    46
  size_t reserved_byte_size = rs.size();
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
    47
  assert((uintptr_t(start) & 3) == 0, "bad alignment");
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
    48
  assert((reserved_byte_size & 3) == 0, "bad alignment");
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
    49
  MemRegion reserved_mr(start, heap_word_size(reserved_byte_size));
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
    50
  _bts = new BlockOffsetSharedArray(reserved_mr,
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
    51
                                    heap_word_size(initial_byte_size));
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
    52
  MemRegion committed_mr(start, heap_word_size(initial_byte_size));
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
    53
  _rs->resize_covered_region(committed_mr);
28033
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
    54
  if (_bts == NULL) {
28031
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
    55
    vm_exit_during_initialization("Could not allocate a BlockOffsetArray");
28033
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
    56
  }
28031
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
    57
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
    58
  // Verify that the start and end of this generation is the start of a card.
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
    59
  // If this wasn't true, a single card could span more than on generation,
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
    60
  // which would cause problems when we commit/uncommit memory, and when we
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
    61
  // clear and dirty cards.
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
    62
  guarantee(_rs->is_aligned(reserved_mr.start()), "generation must be card aligned");
30173
13cf7580b000 8077413: Avoid use of Universe::heap() inside collectors
pliden
parents: 28033
diff changeset
    63
  if (reserved_mr.end() != GenCollectedHeap::heap()->reserved_region().end()) {
28031
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
    64
    // Don't check at the very end of the heap as we'll assert that we're probing off
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
    65
    // the end if we try.
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
    66
    guarantee(_rs->is_aligned(reserved_mr.end()), "generation must be card aligned");
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
    67
  }
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
    68
  _min_heap_delta_bytes = MinHeapDeltaBytes;
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
    69
  _capacity_at_prologue = initial_byte_size;
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
    70
  _used_at_prologue = 0;
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
    71
}
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
    72
28033
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
    73
bool CardGeneration::grow_by(size_t bytes) {
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
    74
  assert_correct_size_change_locking();
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
    75
  bool result = _virtual_space.expand_by(bytes);
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
    76
  if (result) {
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
    77
    size_t new_word_size =
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
    78
       heap_word_size(_virtual_space.committed_size());
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
    79
    MemRegion mr(space()->bottom(), new_word_size);
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
    80
    // Expand card table
30173
13cf7580b000 8077413: Avoid use of Universe::heap() inside collectors
pliden
parents: 28033
diff changeset
    81
    GenCollectedHeap::heap()->barrier_set()->resize_covered_region(mr);
28033
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
    82
    // Expand shared block offset array
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
    83
    _bts->resize(new_word_size);
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
    84
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
    85
    // Fix for bug #4668531
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
    86
    if (ZapUnusedHeapArea) {
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
    87
      MemRegion mangle_region(space()->end(),
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
    88
      (HeapWord*)_virtual_space.high());
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
    89
      SpaceMangler::mangle_region(mangle_region);
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
    90
    }
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
    91
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
    92
    // Expand space -- also expands space's BOT
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
    93
    // (which uses (part of) shared array above)
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
    94
    space()->set_end((HeapWord*)_virtual_space.high());
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
    95
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
    96
    // update the space and generation capacity counters
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
    97
    update_counters();
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
    98
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
    99
    if (Verbose && PrintGC) {
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
   100
      size_t new_mem_size = _virtual_space.committed_size();
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
   101
      size_t old_mem_size = new_mem_size - bytes;
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
   102
      gclog_or_tty->print_cr("Expanding %s from " SIZE_FORMAT "K by "
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
   103
                      SIZE_FORMAT "K to " SIZE_FORMAT "K",
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
   104
                      name(), old_mem_size/K, bytes/K, new_mem_size/K);
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
   105
    }
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
   106
  }
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
   107
  return result;
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
   108
}
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
   109
28031
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   110
bool CardGeneration::expand(size_t bytes, size_t expand_bytes) {
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   111
  assert_locked_or_safepoint(Heap_lock);
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   112
  if (bytes == 0) {
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   113
    return true;  // That's what grow_by(0) would return
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   114
  }
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   115
  size_t aligned_bytes  = ReservedSpace::page_align_size_up(bytes);
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   116
  if (aligned_bytes == 0){
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   117
    // The alignment caused the number of bytes to wrap.  An expand_by(0) will
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   118
    // return true with the implication that an expansion was done when it
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   119
    // was not.  A call to expand implies a best effort to expand by "bytes"
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   120
    // but not a guarantee.  Align down to give a best effort.  This is likely
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   121
    // the most that the generation can expand since it has some capacity to
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   122
    // start with.
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   123
    aligned_bytes = ReservedSpace::page_align_size_down(bytes);
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   124
  }
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   125
  size_t aligned_expand_bytes = ReservedSpace::page_align_size_up(expand_bytes);
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   126
  bool success = false;
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   127
  if (aligned_expand_bytes > aligned_bytes) {
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   128
    success = grow_by(aligned_expand_bytes);
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   129
  }
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   130
  if (!success) {
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   131
    success = grow_by(aligned_bytes);
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   132
  }
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   133
  if (!success) {
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   134
    success = grow_to_reserved();
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   135
  }
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   136
  if (PrintGC && Verbose) {
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   137
    if (success && GC_locker::is_active_and_needs_gc()) {
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   138
      gclog_or_tty->print_cr("Garbage collection disabled, expanded heap instead");
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   139
    }
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   140
  }
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   141
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   142
  return success;
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   143
}
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   144
28033
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
   145
bool CardGeneration::grow_to_reserved() {
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
   146
  assert_correct_size_change_locking();
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
   147
  bool success = true;
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
   148
  const size_t remaining_bytes = _virtual_space.uncommitted_size();
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
   149
  if (remaining_bytes > 0) {
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
   150
    success = grow_by(remaining_bytes);
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
   151
    DEBUG_ONLY(if (!success) warning("grow to reserved failed");)
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
   152
  }
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
   153
  return success;
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
   154
}
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
   155
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
   156
void CardGeneration::shrink(size_t bytes) {
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
   157
  assert_correct_size_change_locking();
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
   158
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
   159
  size_t size = ReservedSpace::page_align_size_down(bytes);
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
   160
  if (size == 0) {
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
   161
    return;
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
   162
  }
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
   163
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
   164
  // Shrink committed space
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
   165
  _virtual_space.shrink_by(size);
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
   166
  // Shrink space; this also shrinks the space's BOT
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
   167
  space()->set_end((HeapWord*) _virtual_space.high());
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
   168
  size_t new_word_size = heap_word_size(space()->capacity());
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
   169
  // Shrink the shared block offset array
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
   170
  _bts->resize(new_word_size);
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
   171
  MemRegion mr(space()->bottom(), new_word_size);
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
   172
  // Shrink the card table
30173
13cf7580b000 8077413: Avoid use of Universe::heap() inside collectors
pliden
parents: 28033
diff changeset
   173
  GenCollectedHeap::heap()->barrier_set()->resize_covered_region(mr);
28033
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
   174
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
   175
  if (Verbose && PrintGC) {
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
   176
    size_t new_mem_size = _virtual_space.committed_size();
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
   177
    size_t old_mem_size = new_mem_size + size;
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
   178
    gclog_or_tty->print_cr("Shrinking %s from " SIZE_FORMAT "K to " SIZE_FORMAT "K",
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
   179
                  name(), old_mem_size/K, new_mem_size/K);
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
   180
  }
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
   181
}
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
   182
28031
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   183
// No young generation references, clear this generation's cards.
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   184
void CardGeneration::clear_remembered_set() {
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   185
  _rs->clear(reserved());
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   186
}
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   187
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   188
// Objects in this generation may have moved, invalidate this
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   189
// generation's cards.
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   190
void CardGeneration::invalidate_remembered_set() {
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   191
  _rs->invalidate(used_region());
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   192
}
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   193
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   194
void CardGeneration::compute_new_size() {
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   195
  assert(_shrink_factor <= 100, "invalid shrink factor");
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   196
  size_t current_shrink_factor = _shrink_factor;
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   197
  _shrink_factor = 0;
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   198
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   199
  // We don't have floating point command-line arguments
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   200
  // Note:  argument processing ensures that MinHeapFreeRatio < 100.
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   201
  const double minimum_free_percentage = MinHeapFreeRatio / 100.0;
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   202
  const double maximum_used_percentage = 1.0 - minimum_free_percentage;
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   203
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   204
  // Compute some numbers about the state of the heap.
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   205
  const size_t used_after_gc = used();
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   206
  const size_t capacity_after_gc = capacity();
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   207
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   208
  const double min_tmp = used_after_gc / maximum_used_percentage;
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   209
  size_t minimum_desired_capacity = (size_t)MIN2(min_tmp, double(max_uintx));
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   210
  // Don't shrink less than the initial generation size
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   211
  minimum_desired_capacity = MAX2(minimum_desired_capacity,
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   212
                                  spec()->init_size());
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   213
  assert(used_after_gc <= minimum_desired_capacity, "sanity check");
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   214
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   215
  if (PrintGC && Verbose) {
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   216
    const size_t free_after_gc = free();
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   217
    const double free_percentage = ((double)free_after_gc) / capacity_after_gc;
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   218
    gclog_or_tty->print_cr("TenuredGeneration::compute_new_size: ");
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   219
    gclog_or_tty->print_cr("  "
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   220
                  "  minimum_free_percentage: %6.2f"
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   221
                  "  maximum_used_percentage: %6.2f",
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   222
                  minimum_free_percentage,
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   223
                  maximum_used_percentage);
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   224
    gclog_or_tty->print_cr("  "
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   225
                  "   free_after_gc   : %6.1fK"
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   226
                  "   used_after_gc   : %6.1fK"
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   227
                  "   capacity_after_gc   : %6.1fK",
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   228
                  free_after_gc / (double) K,
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   229
                  used_after_gc / (double) K,
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   230
                  capacity_after_gc / (double) K);
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   231
    gclog_or_tty->print_cr("  "
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   232
                  "   free_percentage: %6.2f",
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   233
                  free_percentage);
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   234
  }
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   235
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   236
  if (capacity_after_gc < minimum_desired_capacity) {
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   237
    // If we have less free space than we want then expand
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   238
    size_t expand_bytes = minimum_desired_capacity - capacity_after_gc;
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   239
    // Don't expand unless it's significant
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   240
    if (expand_bytes >= _min_heap_delta_bytes) {
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   241
      expand(expand_bytes, 0); // safe if expansion fails
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   242
    }
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   243
    if (PrintGC && Verbose) {
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   244
      gclog_or_tty->print_cr("    expanding:"
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   245
                    "  minimum_desired_capacity: %6.1fK"
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   246
                    "  expand_bytes: %6.1fK"
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   247
                    "  _min_heap_delta_bytes: %6.1fK",
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   248
                    minimum_desired_capacity / (double) K,
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   249
                    expand_bytes / (double) K,
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   250
                    _min_heap_delta_bytes / (double) K);
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   251
    }
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   252
    return;
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   253
  }
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   254
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   255
  // No expansion, now see if we want to shrink
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   256
  size_t shrink_bytes = 0;
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   257
  // We would never want to shrink more than this
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   258
  size_t max_shrink_bytes = capacity_after_gc - minimum_desired_capacity;
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   259
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   260
  if (MaxHeapFreeRatio < 100) {
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   261
    const double maximum_free_percentage = MaxHeapFreeRatio / 100.0;
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   262
    const double minimum_used_percentage = 1.0 - maximum_free_percentage;
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   263
    const double max_tmp = used_after_gc / minimum_used_percentage;
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   264
    size_t maximum_desired_capacity = (size_t)MIN2(max_tmp, double(max_uintx));
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   265
    maximum_desired_capacity = MAX2(maximum_desired_capacity,
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   266
                                    spec()->init_size());
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   267
    if (PrintGC && Verbose) {
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   268
      gclog_or_tty->print_cr("  "
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   269
                             "  maximum_free_percentage: %6.2f"
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   270
                             "  minimum_used_percentage: %6.2f",
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   271
                             maximum_free_percentage,
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   272
                             minimum_used_percentage);
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   273
      gclog_or_tty->print_cr("  "
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   274
                             "  _capacity_at_prologue: %6.1fK"
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   275
                             "  minimum_desired_capacity: %6.1fK"
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   276
                             "  maximum_desired_capacity: %6.1fK",
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   277
                             _capacity_at_prologue / (double) K,
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   278
                             minimum_desired_capacity / (double) K,
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   279
                             maximum_desired_capacity / (double) K);
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   280
    }
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   281
    assert(minimum_desired_capacity <= maximum_desired_capacity,
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   282
           "sanity check");
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   283
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   284
    if (capacity_after_gc > maximum_desired_capacity) {
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   285
      // Capacity too large, compute shrinking size
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   286
      shrink_bytes = capacity_after_gc - maximum_desired_capacity;
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   287
      // We don't want shrink all the way back to initSize if people call
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   288
      // System.gc(), because some programs do that between "phases" and then
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   289
      // we'd just have to grow the heap up again for the next phase.  So we
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   290
      // damp the shrinking: 0% on the first call, 10% on the second call, 40%
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   291
      // on the third call, and 100% by the fourth call.  But if we recompute
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   292
      // size without shrinking, it goes back to 0%.
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   293
      shrink_bytes = shrink_bytes / 100 * current_shrink_factor;
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   294
      assert(shrink_bytes <= max_shrink_bytes, "invalid shrink size");
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   295
      if (current_shrink_factor == 0) {
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   296
        _shrink_factor = 10;
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   297
      } else {
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   298
        _shrink_factor = MIN2(current_shrink_factor * 4, (size_t) 100);
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   299
      }
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   300
      if (PrintGC && Verbose) {
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   301
        gclog_or_tty->print_cr("  "
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   302
                      "  shrinking:"
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   303
                      "  initSize: %.1fK"
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   304
                      "  maximum_desired_capacity: %.1fK",
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   305
                      spec()->init_size() / (double) K,
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   306
                      maximum_desired_capacity / (double) K);
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   307
        gclog_or_tty->print_cr("  "
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   308
                      "  shrink_bytes: %.1fK"
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   309
                      "  current_shrink_factor: " SIZE_FORMAT
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   310
                      "  new shrink factor: " SIZE_FORMAT
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   311
                      "  _min_heap_delta_bytes: %.1fK",
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   312
                      shrink_bytes / (double) K,
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   313
                      current_shrink_factor,
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   314
                      _shrink_factor,
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   315
                      _min_heap_delta_bytes / (double) K);
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   316
      }
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   317
    }
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   318
  }
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   319
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   320
  if (capacity_after_gc > _capacity_at_prologue) {
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   321
    // We might have expanded for promotions, in which case we might want to
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   322
    // take back that expansion if there's room after GC.  That keeps us from
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   323
    // stretching the heap with promotions when there's plenty of room.
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   324
    size_t expansion_for_promotion = capacity_after_gc - _capacity_at_prologue;
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   325
    expansion_for_promotion = MIN2(expansion_for_promotion, max_shrink_bytes);
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   326
    // We have two shrinking computations, take the largest
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   327
    shrink_bytes = MAX2(shrink_bytes, expansion_for_promotion);
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   328
    assert(shrink_bytes <= max_shrink_bytes, "invalid shrink size");
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   329
    if (PrintGC && Verbose) {
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   330
      gclog_or_tty->print_cr("  "
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   331
                             "  aggressive shrinking:"
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   332
                             "  _capacity_at_prologue: %.1fK"
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   333
                             "  capacity_after_gc: %.1fK"
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   334
                             "  expansion_for_promotion: %.1fK"
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   335
                             "  shrink_bytes: %.1fK",
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   336
                             capacity_after_gc / (double) K,
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   337
                             _capacity_at_prologue / (double) K,
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   338
                             expansion_for_promotion / (double) K,
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   339
                             shrink_bytes / (double) K);
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   340
    }
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   341
  }
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   342
  // Don't shrink unless it's significant
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   343
  if (shrink_bytes >= _min_heap_delta_bytes) {
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   344
    shrink(shrink_bytes);
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   345
  }
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   346
}
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   347
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   348
// Currently nothing to do.
10aec24d2b61 8066780: Split CardGeneration out to its own file
brutisso
parents:
diff changeset
   349
void CardGeneration::prepare_for_verify() {}
28033
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
   350
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
   351
void CardGeneration::space_iterate(SpaceClosure* blk,
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
   352
                                                 bool usedOnly) {
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
   353
  blk->do_space(space());
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
   354
}
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
   355
30870
3050fdcdc60b 8080112: Replace and remove the last usages of CollectedHeap::n_par_threads()
stefank
parents: 30764
diff changeset
   356
void CardGeneration::younger_refs_iterate(OopsInGenClosure* blk, uint n_threads) {
28033
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
   357
  blk->set_generation(this);
30870
3050fdcdc60b 8080112: Replace and remove the last usages of CollectedHeap::n_par_threads()
stefank
parents: 30764
diff changeset
   358
  younger_refs_in_space_iterate(space(), blk, n_threads);
28033
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
   359
  blk->reset_generation();
ab63acbd99ec 8066782: Move common code from CMSGeneration and TenuredGeneration to CardGeneration
brutisso
parents: 28031
diff changeset
   360
}