hotspot/src/share/vm/gc_implementation/parallelScavenge/psOldGen.cpp
author trims
Tue, 07 Oct 2008 11:01:35 -0700
changeset 1412 2bb3fe3e00ea
parent 1406 e5e2b519fc11
parent 1217 5eb97f366a6a
child 1911 b7cfe7eb809c
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
1217
5eb97f366a6a 6754988: Update copyright year
xdono
parents: 979
diff changeset
     2
 * Copyright 2001-2008 Sun Microsystems, Inc.  All Rights Reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
# include "incls/_precompiled.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
# include "incls/_psOldGen.cpp.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
inline const char* PSOldGen::select_name() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
  return UseParallelOldGC ? "ParOldGen" : "PSOldGen";
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
PSOldGen::PSOldGen(ReservedSpace rs, size_t alignment,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
                   size_t initial_size, size_t min_size, size_t max_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
                   const char* perf_data_name, int level):
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
  _name(select_name()), _init_gen_size(initial_size), _min_gen_size(min_size),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
  _max_gen_size(max_size)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  initialize(rs, alignment, perf_data_name, level);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
PSOldGen::PSOldGen(size_t initial_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
                   size_t min_size, size_t max_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
                   const char* perf_data_name, int level):
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  _name(select_name()), _init_gen_size(initial_size), _min_gen_size(min_size),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  _max_gen_size(max_size)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
{}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
void PSOldGen::initialize(ReservedSpace rs, size_t alignment,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
                          const char* perf_data_name, int level) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  initialize_virtual_space(rs, alignment);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  initialize_work(perf_data_name, level);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  // The old gen can grow to gen_size_limit().  _reserve reflects only
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  // the current maximum that can be committed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  assert(_reserved.byte_size() <= gen_size_limit(), "Consistency check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
void PSOldGen::initialize_virtual_space(ReservedSpace rs, size_t alignment) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  _virtual_space = new PSVirtualSpace(rs, alignment);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  if (!_virtual_space->expand_by(_init_gen_size)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
    vm_exit_during_initialization("Could not reserve enough space for "
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
                                  "object heap");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
void PSOldGen::initialize_work(const char* perf_data_name, int level) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  // Basic memory initialization
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  MemRegion limit_reserved((HeapWord*)virtual_space()->low_boundary(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
    heap_word_size(_max_gen_size));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  assert(limit_reserved.byte_size() == _max_gen_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
    "word vs bytes confusion");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  // Object start stuff
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  start_array()->initialize(limit_reserved);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  _reserved = MemRegion((HeapWord*)virtual_space()->low_boundary(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
                        (HeapWord*)virtual_space()->high_boundary());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  // Card table stuff
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  MemRegion cmr((HeapWord*)virtual_space()->low(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
                (HeapWord*)virtual_space()->high());
971
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 1
diff changeset
    90
  if (ZapUnusedHeapArea) {
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 1
diff changeset
    91
    // 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
    92
    // 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
    93
    // 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
    94
    // 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
    95
    // (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
    96
    SpaceMangler::mangle_region(cmr);
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 1
diff changeset
    97
  }
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 1
diff changeset
    98
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  Universe::heap()->barrier_set()->resize_covered_region(cmr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  CardTableModRefBS* _ct = (CardTableModRefBS*)Universe::heap()->barrier_set();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  assert (_ct->kind() == BarrierSet::CardTableModRef, "Sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  // Verify that the start and end of this generation is the start of a card.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  // If this wasn't true, a single card could span more than one generation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  // which would cause problems when we commit/uncommit memory, and when we
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  // clear and dirty cards.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  guarantee(_ct->is_card_aligned(_reserved.start()), "generation must be card aligned");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  if (_reserved.end() != Universe::heap()->reserved_region().end()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
    // 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
   111
    // the end if we try.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
    guarantee(_ct->is_card_aligned(_reserved.end()), "generation must be card aligned");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  // ObjectSpace stuff
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  _object_space = new MutableSpace();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  if (_object_space == NULL)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
    vm_exit_during_initialization("Could not allocate an old gen space");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
971
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 1
diff changeset
   124
  object_space()->initialize(cmr,
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 1
diff changeset
   125
                             SpaceDecorator::Clear,
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 1
diff changeset
   126
                             SpaceDecorator::Mangle);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  _object_mark_sweep = new PSMarkSweepDecorator(_object_space, start_array(), MarkSweepDeadRatio);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  if (_object_mark_sweep == NULL)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
    vm_exit_during_initialization("Could not complete allocation of old generation");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  // Update the start_array
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  start_array()->set_covered_region(cmr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  // Generation Counters, generation 'level', 1 subspace
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  _gen_counters = new PSGenerationCounters(perf_data_name, level, 1,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
                                           virtual_space());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  _space_counters = new SpaceCounters(perf_data_name, 0,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
                                      virtual_space()->reserved_size(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
                                      _object_space, _gen_counters);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
// Assume that the generation has been allocated if its
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
// reserved size is not 0.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
bool  PSOldGen::is_allocated() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  return virtual_space()->reserved_size() != 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
void PSOldGen::precompact() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  // Reset start array first.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  start_array()->reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  object_mark_sweep()->precompact();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  // Now compact the young gen
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  heap->young_gen()->precompact();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
void PSOldGen::adjust_pointers() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
  object_mark_sweep()->adjust_pointers();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
void PSOldGen::compact() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  object_mark_sweep()->compact(ZapUnusedHeapArea);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
void PSOldGen::move_and_update(ParCompactionManager* cm) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
  PSParallelCompact::move_and_update(cm, PSParallelCompact::old_space_id);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
size_t PSOldGen::contiguous_available() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
  return object_space()->free_in_bytes() + virtual_space()->uncommitted_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
// Allocation. We report all successful allocations to the size policy
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
// Note that the perm gen does not use this method, and should not!
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
HeapWord* PSOldGen::allocate(size_t word_size, bool is_tlab) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
  assert_locked_or_safepoint(Heap_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
  HeapWord* res = allocate_noexpand(word_size, is_tlab);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
  if (res == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
    res = expand_and_allocate(word_size, is_tlab);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
  // Allocations in the old generation need to be reported
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  if (res != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
    ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
    heap->size_policy()->tenured_allocation(word_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
  return res;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
HeapWord* PSOldGen::expand_and_allocate(size_t word_size, bool is_tlab) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
  assert(!is_tlab, "TLAB's are not supported in PSOldGen");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
  expand(word_size*HeapWordSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
  if (GCExpandToAllocateDelayMillis > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
    os::sleep(Thread::current(), GCExpandToAllocateDelayMillis, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
  return allocate_noexpand(word_size, is_tlab);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
HeapWord* PSOldGen::expand_and_cas_allocate(size_t word_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
  expand(word_size*HeapWordSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
  if (GCExpandToAllocateDelayMillis > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
    os::sleep(Thread::current(), GCExpandToAllocateDelayMillis, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
  return cas_allocate_noexpand(word_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
void PSOldGen::expand(size_t bytes) {
979
c9479f1e0a94 6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents: 971
diff changeset
   216
  if (bytes == 0) {
c9479f1e0a94 6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents: 971
diff changeset
   217
    return;
c9479f1e0a94 6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents: 971
diff changeset
   218
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
  MutexLocker x(ExpandHeap_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
  const size_t alignment = virtual_space()->alignment();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
  size_t aligned_bytes  = align_size_up(bytes, alignment);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
  size_t aligned_expand_bytes = align_size_up(MinHeapDeltaBytes, alignment);
979
c9479f1e0a94 6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents: 971
diff changeset
   223
  if (aligned_bytes == 0){
c9479f1e0a94 6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents: 971
diff changeset
   224
    // 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
   225
    // 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
   226
    // 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
   227
    // 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
   228
    // 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
   229
    // start with.
c9479f1e0a94 6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents: 971
diff changeset
   230
    aligned_bytes = align_size_down(bytes, alignment);
c9479f1e0a94 6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents: 971
diff changeset
   231
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
  bool success = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
  if (aligned_expand_bytes > aligned_bytes) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
    success = expand_by(aligned_expand_bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
  if (!success) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
    success = expand_by(aligned_bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
  if (!success) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
    success = expand_to_reserved();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
979
c9479f1e0a94 6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents: 971
diff changeset
   244
  if (PrintGC && Verbose) {
c9479f1e0a94 6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents: 971
diff changeset
   245
    if (success && GC_locker::is_active()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
      gclog_or_tty->print_cr("Garbage collection disabled, expanded heap instead");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
bool PSOldGen::expand_by(size_t bytes) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
  assert_lock_strong(ExpandHeap_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
  assert_locked_or_safepoint(Heap_lock);
979
c9479f1e0a94 6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents: 971
diff changeset
   254
  if (bytes == 0) {
c9479f1e0a94 6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents: 971
diff changeset
   255
    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
   256
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
  bool result = virtual_space()->expand_by(bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
  if (result) {
971
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 1
diff changeset
   259
    if (ZapUnusedHeapArea) {
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 1
diff changeset
   260
      // 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
   261
      // 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
   262
      // 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
   263
      // 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
   264
      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
   265
      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
   266
        "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
   267
      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
   268
      // Note that the object space has not yet been updated to
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 1
diff changeset
   269
      // coincede with the new underlying virtual space.
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 1
diff changeset
   270
      SpaceMangler::mangle_region(mangle_region);
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 1
diff changeset
   271
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
    post_resize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
    if (UsePerfData) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
      _space_counters->update_capacity();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
      _gen_counters->update_all();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
  if (result && Verbose && PrintGC) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
    size_t new_mem_size = virtual_space()->committed_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
    size_t old_mem_size = new_mem_size - bytes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
    gclog_or_tty->print_cr("Expanding %s from " SIZE_FORMAT "K by "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
                                       SIZE_FORMAT "K to "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
                                       SIZE_FORMAT "K",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
                    name(), old_mem_size/K, bytes/K, new_mem_size/K);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
  return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
bool PSOldGen::expand_to_reserved() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
  assert_lock_strong(ExpandHeap_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
  assert_locked_or_safepoint(Heap_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
  bool result = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
  const size_t remaining_bytes = virtual_space()->uncommitted_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
  if (remaining_bytes > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
    result = expand_by(remaining_bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
    DEBUG_ONLY(if (!result) warning("grow to reserve failed"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
  return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
void PSOldGen::shrink(size_t bytes) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
  assert_lock_strong(ExpandHeap_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
  assert_locked_or_safepoint(Heap_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
  size_t size = align_size_down(bytes, virtual_space()->alignment());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
  if (size > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
    assert_lock_strong(ExpandHeap_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
    virtual_space()->shrink_by(bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
    post_resize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
    if (Verbose && PrintGC) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
      size_t new_mem_size = virtual_space()->committed_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
      size_t old_mem_size = new_mem_size + bytes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
      gclog_or_tty->print_cr("Shrinking %s from " SIZE_FORMAT "K by "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
                                         SIZE_FORMAT "K to "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
                                         SIZE_FORMAT "K",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
                      name(), old_mem_size/K, bytes/K, new_mem_size/K);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
void PSOldGen::resize(size_t desired_free_space) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
  const size_t alignment = virtual_space()->alignment();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
  const size_t size_before = virtual_space()->committed_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
  size_t new_size = used_in_bytes() + desired_free_space;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
  if (new_size < used_in_bytes()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
    // Overflowed the addition.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
    new_size = gen_size_limit();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
  // Adjust according to our min and max
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
  new_size = MAX2(MIN2(new_size, gen_size_limit()), min_gen_size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
  assert(gen_size_limit() >= reserved().byte_size(), "max new size problem?");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
  new_size = align_size_up(new_size, alignment);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
  const size_t current_size = capacity_in_bytes();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
  if (PrintAdaptiveSizePolicy && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
    gclog_or_tty->print_cr("AdaptiveSizePolicy::old generation size: "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
      "desired free: " SIZE_FORMAT " used: " SIZE_FORMAT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
      " new size: " SIZE_FORMAT " current size " SIZE_FORMAT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
      " gen limits: " SIZE_FORMAT " / " SIZE_FORMAT,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
      desired_free_space, used_in_bytes(), new_size, current_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
      gen_size_limit(), min_gen_size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
  if (new_size == current_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
    // No change requested
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
  if (new_size > current_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
    size_t change_bytes = new_size - current_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
    expand(change_bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
    size_t change_bytes = current_size - new_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
    // shrink doesn't grab this lock, expand does. Is that right?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
    MutexLocker x(ExpandHeap_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
    shrink(change_bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
  if (PrintAdaptiveSizePolicy) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
    ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
    assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
    gclog_or_tty->print_cr("AdaptiveSizePolicy::old generation size: "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
                  "collection: %d "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
                  "(" SIZE_FORMAT ") -> (" SIZE_FORMAT ") ",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
                  heap->total_collections(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
                  size_before, virtual_space()->committed_size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
// NOTE! We need to be careful about resizing. During a GC, multiple
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
// allocators may be active during heap expansion. If we allow the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
// heap resizing to become visible before we have correctly resized
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
// all heap related data structures, we may cause program failures.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
void PSOldGen::post_resize() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
  // First construct a memregion representing the new size
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
  MemRegion new_memregion((HeapWord*)virtual_space()->low(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
    (HeapWord*)virtual_space()->high());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
  size_t new_word_size = new_memregion.word_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
  start_array()->set_covered_region(new_memregion);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
  Universe::heap()->barrier_set()->resize_covered_region(new_memregion);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
  HeapWord* const virtual_space_high = (HeapWord*) virtual_space()->high();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
  // ALWAYS do this last!!
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
  object_space()->set_end(virtual_space_high);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
  assert(new_word_size == heap_word_size(object_space()->capacity_in_bytes()),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
    "Sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
size_t PSOldGen::gen_size_limit() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
  return _max_gen_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
void PSOldGen::reset_after_change() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
  ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
  return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
size_t PSOldGen::available_for_expansion() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
  ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
  return 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
size_t PSOldGen::available_for_contraction() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
  ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
  return 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
void PSOldGen::print() const { print_on(tty);}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
void PSOldGen::print_on(outputStream* st) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
  st->print(" %-15s", name());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
  if (PrintGCDetails && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
    st->print(" total " SIZE_FORMAT ", used " SIZE_FORMAT,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
                capacity_in_bytes(), used_in_bytes());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
    st->print(" total " SIZE_FORMAT "K, used " SIZE_FORMAT "K",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
                capacity_in_bytes()/K, used_in_bytes()/K);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
  st->print_cr(" [" INTPTR_FORMAT ", " INTPTR_FORMAT ", " INTPTR_FORMAT ")",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
                virtual_space()->low_boundary(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
                virtual_space()->high(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
                virtual_space()->high_boundary());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
  st->print("  object"); object_space()->print_on(st);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
void PSOldGen::print_used_change(size_t prev_used) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
  gclog_or_tty->print(" [%s:", name());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
  gclog_or_tty->print(" "  SIZE_FORMAT "K"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
                      "->" SIZE_FORMAT "K"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
                      "("  SIZE_FORMAT "K)",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
                      prev_used / K, used_in_bytes() / K,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
                      capacity_in_bytes() / K);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
  gclog_or_tty->print("]");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
void PSOldGen::update_counters() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
  if (UsePerfData) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
    _space_counters->update_all();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
    _gen_counters->update_all();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
void PSOldGen::space_invariants() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
  assert(object_space()->end() == (HeapWord*) virtual_space()->high(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
    "Space invariant");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
  assert(object_space()->bottom() == (HeapWord*) virtual_space()->low(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
    "Space invariant");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
  assert(virtual_space()->low_boundary() <= virtual_space()->low(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
    "Space invariant");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
  assert(virtual_space()->high_boundary() >= virtual_space()->high(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
    "Space invariant");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
  assert(virtual_space()->low_boundary() == (char*) _reserved.start(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
    "Space invariant");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
  assert(virtual_space()->high_boundary() == (char*) _reserved.end(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
    "Space invariant");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
  assert(virtual_space()->committed_size() <= virtual_space()->reserved_size(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
    "Space invariant");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
void PSOldGen::verify(bool allow_dirty) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
  object_space()->verify(allow_dirty);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
class VerifyObjectStartArrayClosure : public ObjectClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
  PSOldGen* _gen;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
  ObjectStartArray* _start_array;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
  VerifyObjectStartArrayClosure(PSOldGen* gen, ObjectStartArray* start_array) :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
    _gen(gen), _start_array(start_array) { }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
  virtual void do_object(oop obj) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
    HeapWord* test_addr = (HeapWord*)obj + 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
    guarantee(_start_array->object_start(test_addr) == (HeapWord*)obj, "ObjectStartArray cannot find start of object");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
    guarantee(_start_array->is_block_allocated((HeapWord*)obj), "ObjectStartArray missing block allocation");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
void PSOldGen::verify_object_start_array() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
  VerifyObjectStartArrayClosure check( this, &_start_array );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
  object_iterate(&check);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
}
971
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 1
diff changeset
   493
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 1
diff changeset
   494
#ifndef PRODUCT
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 1
diff changeset
   495
void PSOldGen::record_spaces_top() {
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 1
diff changeset
   496
  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
   497
  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
   498
}
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 1
diff changeset
   499
#endif