hotspot/src/share/vm/gc_implementation/parallelScavenge/psOldGen.cpp
author sjohanss
Wed, 27 Aug 2014 09:47:06 +0200
changeset 26324 6b9c12e15535
parent 24424 2658d7834c6e
child 29325 0e86e64c66e5
permissions -rw-r--r--
8028787: tmtools/jstat/gcoldcapacity/jstat_gcoldcapacity02 fails nsk.share.Failure: OGC < OGCMN in RT_Baseline Summary: Passing the min and max size of the generation into the counter instead of using the space to estimate sizes. Reviewed-by: stefank, tschatzl
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 22551
diff changeset
     2
 * Copyright (c) 2001, 2014, 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: 2105
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 2105
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: 2105
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
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    25
#include "precompiled.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    26
#include "gc_implementation/parallelScavenge/parallelScavengeHeap.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
#include "gc_implementation/parallelScavenge/psAdaptiveSizePolicy.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "gc_implementation/parallelScavenge/psMarkSweepDecorator.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
#include "gc_implementation/parallelScavenge/psOldGen.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    30
#include "gc_implementation/shared/spaceDecorator.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    31
#include "memory/cardTableModRefBS.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    32
#include "memory/gcLocker.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    33
#include "oops/oop.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    34
#include "runtime/java.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 22551
diff changeset
    36
PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 22551
diff changeset
    37
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
inline const char* PSOldGen::select_name() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  return UseParallelOldGC ? "ParOldGen" : "PSOldGen";
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
PSOldGen::PSOldGen(ReservedSpace rs, size_t alignment,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
                   size_t initial_size, size_t min_size, size_t max_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
                   const char* perf_data_name, int level):
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  _name(select_name()), _init_gen_size(initial_size), _min_gen_size(min_size),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  _max_gen_size(max_size)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  initialize(rs, alignment, perf_data_name, level);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
PSOldGen::PSOldGen(size_t initial_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
                   size_t min_size, size_t max_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
                   const char* perf_data_name, int level):
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  _name(select_name()), _init_gen_size(initial_size), _min_gen_size(min_size),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  _max_gen_size(max_size)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
{}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
void PSOldGen::initialize(ReservedSpace rs, size_t alignment,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
                          const char* perf_data_name, int level) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  initialize_virtual_space(rs, alignment);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  initialize_work(perf_data_name, level);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 12379
diff changeset
    62
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  // The old gen can grow to gen_size_limit().  _reserve reflects only
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  // the current maximum that can be committed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  assert(_reserved.byte_size() <= gen_size_limit(), "Consistency check");
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 12379
diff changeset
    66
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 12379
diff changeset
    67
  initialize_performance_counters(perf_data_name, level);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
void PSOldGen::initialize_virtual_space(ReservedSpace rs, size_t alignment) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  _virtual_space = new PSVirtualSpace(rs, alignment);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  if (!_virtual_space->expand_by(_init_gen_size)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
    vm_exit_during_initialization("Could not reserve enough space for "
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
                                  "object heap");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
void PSOldGen::initialize_work(const char* perf_data_name, int level) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  // Basic memory initialization
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  MemRegion limit_reserved((HeapWord*)virtual_space()->low_boundary(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
    heap_word_size(_max_gen_size));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  assert(limit_reserved.byte_size() == _max_gen_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
    "word vs bytes confusion");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  // Object start stuff
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  start_array()->initialize(limit_reserved);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  _reserved = MemRegion((HeapWord*)virtual_space()->low_boundary(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
                        (HeapWord*)virtual_space()->high_boundary());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  // Card table stuff
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  MemRegion cmr((HeapWord*)virtual_space()->low(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
                (HeapWord*)virtual_space()->high());
971
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 1
diff changeset
   103
  if (ZapUnusedHeapArea) {
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 1
diff changeset
   104
    // Mangle newly committed space immediately rather than
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 1
diff changeset
   105
    // waiting for the initialization of the space even though
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 1
diff changeset
   106
    // mangling is related to spaces.  Doing it here eliminates
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 1
diff changeset
   107
    // the need to carry along information that a complete mangling
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 1
diff changeset
   108
    // (bottom to end) needs to be done.
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 1
diff changeset
   109
    SpaceMangler::mangle_region(cmr);
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 1
diff changeset
   110
  }
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 1
diff changeset
   111
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  Universe::heap()->barrier_set()->resize_covered_region(cmr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  CardTableModRefBS* _ct = (CardTableModRefBS*)Universe::heap()->barrier_set();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  assert (_ct->kind() == BarrierSet::CardTableModRef, "Sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  // Verify that the start and end of this generation is the start of a card.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  // If this wasn't true, a single card could span more than one generation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  // which would cause problems when we commit/uncommit memory, and when we
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  // clear and dirty cards.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  guarantee(_ct->is_card_aligned(_reserved.start()), "generation must be card aligned");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  if (_reserved.end() != Universe::heap()->reserved_region().end()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
    // Don't check at the very end of the heap as we'll assert that we're probing off
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
    // the end if we try.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
    guarantee(_ct->is_card_aligned(_reserved.end()), "generation must be card aligned");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  // ObjectSpace stuff
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
1911
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 1412
diff changeset
   132
  _object_space = new MutableSpace(virtual_space()->alignment());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  if (_object_space == NULL)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
    vm_exit_during_initialization("Could not allocate an old gen space");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
971
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 1
diff changeset
   137
  object_space()->initialize(cmr,
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 1
diff changeset
   138
                             SpaceDecorator::Clear,
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 1
diff changeset
   139
                             SpaceDecorator::Mangle);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  _object_mark_sweep = new PSMarkSweepDecorator(_object_space, start_array(), MarkSweepDeadRatio);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  if (_object_mark_sweep == NULL)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
    vm_exit_during_initialization("Could not complete allocation of old generation");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  // Update the start_array
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  start_array()->set_covered_region(cmr);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 12379
diff changeset
   148
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 12379
diff changeset
   150
void PSOldGen::initialize_performance_counters(const char* perf_data_name, int level) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  // Generation Counters, generation 'level', 1 subspace
26324
6b9c12e15535 8028787: tmtools/jstat/gcoldcapacity/jstat_gcoldcapacity02 fails nsk.share.Failure: OGC < OGCMN in RT_Baseline
sjohanss
parents: 24424
diff changeset
   152
  _gen_counters = new PSGenerationCounters(perf_data_name, level, 1, _min_gen_size,
6b9c12e15535 8028787: tmtools/jstat/gcoldcapacity/jstat_gcoldcapacity02 fails nsk.share.Failure: OGC < OGCMN in RT_Baseline
sjohanss
parents: 24424
diff changeset
   153
                                           _max_gen_size, virtual_space());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  _space_counters = new SpaceCounters(perf_data_name, 0,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
                                      virtual_space()->reserved_size(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
                                      _object_space, _gen_counters);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
// Assume that the generation has been allocated if its
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
// reserved size is not 0.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
bool  PSOldGen::is_allocated() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
  return virtual_space()->reserved_size() != 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
void PSOldGen::precompact() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
  ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
  assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  // Reset start array first.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
  start_array()->reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
  object_mark_sweep()->precompact();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
  // Now compact the young gen
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
  heap->young_gen()->precompact();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
void PSOldGen::adjust_pointers() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
  object_mark_sweep()->adjust_pointers();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
void PSOldGen::compact() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
  object_mark_sweep()->compact(ZapUnusedHeapArea);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
size_t PSOldGen::contiguous_available() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
  return object_space()->free_in_bytes() + virtual_space()->uncommitted_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
// Allocation. We report all successful allocations to the size policy
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
// Note that the perm gen does not use this method, and should not!
9997
b75b7939f448 6994322: Remove the is_tlab and is_noref / is_large_noref parameters from the CollectedHeap
tonyp
parents: 9423
diff changeset
   192
HeapWord* PSOldGen::allocate(size_t word_size) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
  assert_locked_or_safepoint(Heap_lock);
9997
b75b7939f448 6994322: Remove the is_tlab and is_noref / is_large_noref parameters from the CollectedHeap
tonyp
parents: 9423
diff changeset
   194
  HeapWord* res = allocate_noexpand(word_size);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
  if (res == NULL) {
9997
b75b7939f448 6994322: Remove the is_tlab and is_noref / is_large_noref parameters from the CollectedHeap
tonyp
parents: 9423
diff changeset
   197
    res = expand_and_allocate(word_size);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
  // Allocations in the old generation need to be reported
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
  if (res != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
    ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
    heap->size_policy()->tenured_allocation(word_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
  return res;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
9997
b75b7939f448 6994322: Remove the is_tlab and is_noref / is_large_noref parameters from the CollectedHeap
tonyp
parents: 9423
diff changeset
   209
HeapWord* PSOldGen::expand_and_allocate(size_t word_size) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
  expand(word_size*HeapWordSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
  if (GCExpandToAllocateDelayMillis > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
    os::sleep(Thread::current(), GCExpandToAllocateDelayMillis, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
  }
9997
b75b7939f448 6994322: Remove the is_tlab and is_noref / is_large_noref parameters from the CollectedHeap
tonyp
parents: 9423
diff changeset
   214
  return allocate_noexpand(word_size);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
HeapWord* PSOldGen::expand_and_cas_allocate(size_t word_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
  expand(word_size*HeapWordSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
  if (GCExpandToAllocateDelayMillis > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
    os::sleep(Thread::current(), GCExpandToAllocateDelayMillis, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
  return cas_allocate_noexpand(word_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
void PSOldGen::expand(size_t bytes) {
979
c9479f1e0a94 6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents: 971
diff changeset
   226
  if (bytes == 0) {
c9479f1e0a94 6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents: 971
diff changeset
   227
    return;
c9479f1e0a94 6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents: 971
diff changeset
   228
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
  MutexLocker x(ExpandHeap_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
  const size_t alignment = virtual_space()->alignment();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
  size_t aligned_bytes  = align_size_up(bytes, alignment);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
  size_t aligned_expand_bytes = align_size_up(MinHeapDeltaBytes, alignment);
9423
a977bd202cec 7041501: NUMA: Expand the old gen more aggressively
iveresov
parents: 9178
diff changeset
   233
a977bd202cec 7041501: NUMA: Expand the old gen more aggressively
iveresov
parents: 9178
diff changeset
   234
  if (UseNUMA) {
a977bd202cec 7041501: NUMA: Expand the old gen more aggressively
iveresov
parents: 9178
diff changeset
   235
    // With NUMA we use round-robin page allocation for the old gen. Expand by at least
a977bd202cec 7041501: NUMA: Expand the old gen more aggressively
iveresov
parents: 9178
diff changeset
   236
    // providing a page per lgroup. Alignment is larger or equal to the page size.
a977bd202cec 7041501: NUMA: Expand the old gen more aggressively
iveresov
parents: 9178
diff changeset
   237
    aligned_expand_bytes = MAX2(aligned_expand_bytes, alignment * os::numa_get_groups_num());
a977bd202cec 7041501: NUMA: Expand the old gen more aggressively
iveresov
parents: 9178
diff changeset
   238
  }
979
c9479f1e0a94 6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents: 971
diff changeset
   239
  if (aligned_bytes == 0){
c9479f1e0a94 6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents: 971
diff changeset
   240
    // The alignment caused the number of bytes to wrap.  An expand_by(0) will
c9479f1e0a94 6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents: 971
diff changeset
   241
    // return true with the implication that and expansion was done when it
c9479f1e0a94 6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents: 971
diff changeset
   242
    // was not.  A call to expand implies a best effort to expand by "bytes"
c9479f1e0a94 6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents: 971
diff changeset
   243
    // but not a guarantee.  Align down to give a best effort.  This is likely
c9479f1e0a94 6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents: 971
diff changeset
   244
    // the most that the generation can expand since it has some capacity to
c9479f1e0a94 6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents: 971
diff changeset
   245
    // start with.
c9479f1e0a94 6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents: 971
diff changeset
   246
    aligned_bytes = align_size_down(bytes, alignment);
c9479f1e0a94 6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents: 971
diff changeset
   247
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
  bool success = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
  if (aligned_expand_bytes > aligned_bytes) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
    success = expand_by(aligned_expand_bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
  if (!success) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
    success = expand_by(aligned_bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
  if (!success) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
    success = expand_to_reserved();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
979
c9479f1e0a94 6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents: 971
diff changeset
   260
  if (PrintGC && Verbose) {
16608
9dd420de589b 8005857: assert in GC_locker from PSOldGen::expand with -XX:+PrintGCDetails and Verbose
tschatzl
parents: 13728
diff changeset
   261
    if (success && GC_locker::is_active_and_needs_gc()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
      gclog_or_tty->print_cr("Garbage collection disabled, expanded heap instead");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
bool PSOldGen::expand_by(size_t bytes) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
  assert_lock_strong(ExpandHeap_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
  assert_locked_or_safepoint(Heap_lock);
979
c9479f1e0a94 6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents: 971
diff changeset
   270
  if (bytes == 0) {
c9479f1e0a94 6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents: 971
diff changeset
   271
    return true;  // That's what virtual_space()->expand_by(0) would return
c9479f1e0a94 6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents: 971
diff changeset
   272
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
  bool result = virtual_space()->expand_by(bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
  if (result) {
971
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 1
diff changeset
   275
    if (ZapUnusedHeapArea) {
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 1
diff changeset
   276
      // We need to mangle the newly expanded area. The memregion spans
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 1
diff changeset
   277
      // end -> new_end, we assume that top -> end is already mangled.
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 1
diff changeset
   278
      // Do the mangling before post_resize() is called because
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 1
diff changeset
   279
      // the space is available for allocation after post_resize();
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 1
diff changeset
   280
      HeapWord* const virtual_space_high = (HeapWord*) virtual_space()->high();
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 1
diff changeset
   281
      assert(object_space()->end() < virtual_space_high,
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 1
diff changeset
   282
        "Should be true before post_resize()");
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 1
diff changeset
   283
      MemRegion mangle_region(object_space()->end(), virtual_space_high);
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 1
diff changeset
   284
      // Note that the object space has not yet been updated to
22551
9bf46d16dcc6 8025856: Fix typos in the GC code
jwilhelm
parents: 22234
diff changeset
   285
      // coincide with the new underlying virtual space.
971
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 1
diff changeset
   286
      SpaceMangler::mangle_region(mangle_region);
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 1
diff changeset
   287
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
    post_resize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
    if (UsePerfData) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
      _space_counters->update_capacity();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
      _gen_counters->update_all();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
  if (result && Verbose && PrintGC) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
    size_t new_mem_size = virtual_space()->committed_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
    size_t old_mem_size = new_mem_size - bytes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
    gclog_or_tty->print_cr("Expanding %s from " SIZE_FORMAT "K by "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
                                       SIZE_FORMAT "K to "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
                                       SIZE_FORMAT "K",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
                    name(), old_mem_size/K, bytes/K, new_mem_size/K);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
  return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
bool PSOldGen::expand_to_reserved() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
  assert_lock_strong(ExpandHeap_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
  assert_locked_or_safepoint(Heap_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
  bool result = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
  const size_t remaining_bytes = virtual_space()->uncommitted_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
  if (remaining_bytes > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
    result = expand_by(remaining_bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
    DEBUG_ONLY(if (!result) warning("grow to reserve failed"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
  return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
void PSOldGen::shrink(size_t bytes) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
  assert_lock_strong(ExpandHeap_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
  assert_locked_or_safepoint(Heap_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
  size_t size = align_size_down(bytes, virtual_space()->alignment());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
  if (size > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
    assert_lock_strong(ExpandHeap_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
    virtual_space()->shrink_by(bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
    post_resize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
    if (Verbose && PrintGC) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
      size_t new_mem_size = virtual_space()->committed_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
      size_t old_mem_size = new_mem_size + bytes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
      gclog_or_tty->print_cr("Shrinking %s from " SIZE_FORMAT "K by "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
                                         SIZE_FORMAT "K to "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
                                         SIZE_FORMAT "K",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
                      name(), old_mem_size/K, bytes/K, new_mem_size/K);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
void PSOldGen::resize(size_t desired_free_space) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
  const size_t alignment = virtual_space()->alignment();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
  const size_t size_before = virtual_space()->committed_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
  size_t new_size = used_in_bytes() + desired_free_space;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
  if (new_size < used_in_bytes()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
    // Overflowed the addition.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
    new_size = gen_size_limit();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
  // Adjust according to our min and max
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
  new_size = MAX2(MIN2(new_size, gen_size_limit()), min_gen_size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
  assert(gen_size_limit() >= reserved().byte_size(), "max new size problem?");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
  new_size = align_size_up(new_size, alignment);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
  const size_t current_size = capacity_in_bytes();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
  if (PrintAdaptiveSizePolicy && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
    gclog_or_tty->print_cr("AdaptiveSizePolicy::old generation size: "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
      "desired free: " SIZE_FORMAT " used: " SIZE_FORMAT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
      " new size: " SIZE_FORMAT " current size " SIZE_FORMAT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
      " gen limits: " SIZE_FORMAT " / " SIZE_FORMAT,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
      desired_free_space, used_in_bytes(), new_size, current_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
      gen_size_limit(), min_gen_size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
  if (new_size == current_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
    // No change requested
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
  if (new_size > current_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
    size_t change_bytes = new_size - current_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
    expand(change_bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
    size_t change_bytes = current_size - new_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
    // shrink doesn't grab this lock, expand does. Is that right?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
    MutexLocker x(ExpandHeap_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
    shrink(change_bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
  if (PrintAdaptiveSizePolicy) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
    ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
    assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
    gclog_or_tty->print_cr("AdaptiveSizePolicy::old generation size: "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
                  "collection: %d "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
                  "(" SIZE_FORMAT ") -> (" SIZE_FORMAT ") ",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
                  heap->total_collections(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
                  size_before, virtual_space()->committed_size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
// NOTE! We need to be careful about resizing. During a GC, multiple
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
// allocators may be active during heap expansion. If we allow the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
// heap resizing to become visible before we have correctly resized
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
// all heap related data structures, we may cause program failures.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
void PSOldGen::post_resize() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
  // First construct a memregion representing the new size
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
  MemRegion new_memregion((HeapWord*)virtual_space()->low(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
    (HeapWord*)virtual_space()->high());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
  size_t new_word_size = new_memregion.word_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
  start_array()->set_covered_region(new_memregion);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
  Universe::heap()->barrier_set()->resize_covered_region(new_memregion);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
  // ALWAYS do this last!!
1911
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 1412
diff changeset
   405
  object_space()->initialize(new_memregion,
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 1412
diff changeset
   406
                             SpaceDecorator::DontClear,
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 1412
diff changeset
   407
                             SpaceDecorator::DontMangle);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
  assert(new_word_size == heap_word_size(object_space()->capacity_in_bytes()),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
    "Sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
size_t PSOldGen::gen_size_limit() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
  return _max_gen_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
void PSOldGen::reset_after_change() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
  ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
  return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
size_t PSOldGen::available_for_expansion() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
  ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
  return 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
size_t PSOldGen::available_for_contraction() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
  ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
  return 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
void PSOldGen::print() const { print_on(tty);}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
void PSOldGen::print_on(outputStream* st) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
  st->print(" %-15s", name());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
  if (PrintGCDetails && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
    st->print(" total " SIZE_FORMAT ", used " SIZE_FORMAT,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
                capacity_in_bytes(), used_in_bytes());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
    st->print(" total " SIZE_FORMAT "K, used " SIZE_FORMAT "K",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
                capacity_in_bytes()/K, used_in_bytes()/K);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
  st->print_cr(" [" INTPTR_FORMAT ", " INTPTR_FORMAT ", " INTPTR_FORMAT ")",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
                virtual_space()->low_boundary(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
                virtual_space()->high(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
                virtual_space()->high_boundary());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
  st->print("  object"); object_space()->print_on(st);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
void PSOldGen::print_used_change(size_t prev_used) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
  gclog_or_tty->print(" [%s:", name());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
  gclog_or_tty->print(" "  SIZE_FORMAT "K"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
                      "->" SIZE_FORMAT "K"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
                      "("  SIZE_FORMAT "K)",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
                      prev_used / K, used_in_bytes() / K,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
                      capacity_in_bytes() / K);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
  gclog_or_tty->print("]");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
void PSOldGen::update_counters() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
  if (UsePerfData) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
    _space_counters->update_all();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
    _gen_counters->update_all();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
void PSOldGen::space_invariants() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
  assert(object_space()->end() == (HeapWord*) virtual_space()->high(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
    "Space invariant");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
  assert(object_space()->bottom() == (HeapWord*) virtual_space()->low(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
    "Space invariant");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
  assert(virtual_space()->low_boundary() <= virtual_space()->low(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
    "Space invariant");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
  assert(virtual_space()->high_boundary() >= virtual_space()->high(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
    "Space invariant");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
  assert(virtual_space()->low_boundary() == (char*) _reserved.start(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
    "Space invariant");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
  assert(virtual_space()->high_boundary() == (char*) _reserved.end(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
    "Space invariant");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
  assert(virtual_space()->committed_size() <= virtual_space()->reserved_size(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
    "Space invariant");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
12379
2cf45b79ce3a 4988100: oop_verify_old_oop appears to be dead
brutisso
parents: 9997
diff changeset
   487
void PSOldGen::verify() {
2cf45b79ce3a 4988100: oop_verify_old_oop appears to be dead
brutisso
parents: 9997
diff changeset
   488
  object_space()->verify();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
class VerifyObjectStartArrayClosure : public ObjectClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
  PSOldGen* _gen;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
  ObjectStartArray* _start_array;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
  VerifyObjectStartArrayClosure(PSOldGen* gen, ObjectStartArray* start_array) :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
    _gen(gen), _start_array(start_array) { }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
  virtual void do_object(oop obj) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
    HeapWord* test_addr = (HeapWord*)obj + 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   500
    guarantee(_start_array->object_start(test_addr) == (HeapWord*)obj, "ObjectStartArray cannot find start of object");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
    guarantee(_start_array->is_block_allocated((HeapWord*)obj), "ObjectStartArray missing block allocation");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
void PSOldGen::verify_object_start_array() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
  VerifyObjectStartArrayClosure check( this, &_start_array );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
  object_iterate(&check);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
}
971
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 1
diff changeset
   509
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 1
diff changeset
   510
#ifndef PRODUCT
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 1
diff changeset
   511
void PSOldGen::record_spaces_top() {
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 1
diff changeset
   512
  assert(ZapUnusedHeapArea, "Not mangling unused space");
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 1
diff changeset
   513
  object_space()->set_top_for_allocations();
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 1
diff changeset
   514
}
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 1
diff changeset
   515
#endif