src/hotspot/share/gc/parallel/psOldGen.cpp
author sangheki
Fri, 21 Dec 2018 08:23:55 -0800
changeset 53117 37930c6ba6d7
parent 49982 9042ffe5b7fe
child 54678 93f09ca4a7f8
permissions -rw-r--r--
8211424: Allocation of old generation of java heap on alternate memory devices - Parallel GC 8202286: Allocation of old generation of Java heap on alternate memory devices Summary: Enable an experimental feature in HotSpot JVM to allocate old generation of Parallel GC on an alternative memory device, such as NV-DIMMs. Reviewed-by: sangheki, sjohanss Contributed-by: kishor.kharbas@intel.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
49164
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 47216
diff changeset
     2
 * Copyright (c) 2001, 2018, 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"
35862
411842d0c882 8146395: Add inline qualifier in oop.hpp and fix inlining in gc files
goetz
parents: 35492
diff changeset
    26
#include "gc/parallel/objectStartArray.inline.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30173
diff changeset
    27
#include "gc/parallel/parallelScavengeHeap.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30173
diff changeset
    28
#include "gc/parallel/psAdaptiveSizePolicy.hpp"
49164
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 47216
diff changeset
    29
#include "gc/parallel/psCardTable.hpp"
53117
37930c6ba6d7 8211424: Allocation of old generation of java heap on alternate memory devices - Parallel GC
sangheki
parents: 49982
diff changeset
    30
#include "gc/parallel/psFileBackedVirtualspace.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30173
diff changeset
    31
#include "gc/parallel/psMarkSweepDecorator.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30173
diff changeset
    32
#include "gc/parallel/psOldGen.hpp"
49455
848864ed9b17 8199604: Rename CardTableModRefBS to CardTableBarrierSet
eosterlund
parents: 49164
diff changeset
    33
#include "gc/shared/cardTableBarrierSet.hpp"
49594
898ef81cbc0e 8200106: Move NoSafepointVerifier out from gcLocker.hpp
stefank
parents: 49455
diff changeset
    34
#include "gc/shared/gcLocker.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30173
diff changeset
    35
#include "gc/shared/spaceDecorator.hpp"
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
    36
#include "logging/log.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    37
#include "oops/oop.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    38
#include "runtime/java.hpp"
46625
edefffab74e2 8183552: Move align functions to align.hpp
stefank
parents: 46619
diff changeset
    39
#include "utilities/align.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
inline const char* PSOldGen::select_name() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  return UseParallelOldGC ? "ParOldGen" : "PSOldGen";
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
PSOldGen::PSOldGen(ReservedSpace rs, size_t alignment,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
                   size_t initial_size, size_t min_size, size_t max_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
                   const char* perf_data_name, int level):
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  _name(select_name()), _init_gen_size(initial_size), _min_gen_size(min_size),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  _max_gen_size(max_size)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  initialize(rs, alignment, perf_data_name, level);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
PSOldGen::PSOldGen(size_t initial_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
                   size_t min_size, size_t max_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
                   const char* perf_data_name, int level):
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  _name(select_name()), _init_gen_size(initial_size), _min_gen_size(min_size),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  _max_gen_size(max_size)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
{}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
void PSOldGen::initialize(ReservedSpace rs, size_t alignment,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
                          const char* perf_data_name, int level) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  initialize_virtual_space(rs, alignment);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  initialize_work(perf_data_name, level);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 12379
diff changeset
    65
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  // The old gen can grow to gen_size_limit().  _reserve reflects only
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  // the current maximum that can be committed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  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
    69
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 12379
diff changeset
    70
  initialize_performance_counters(perf_data_name, level);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
void PSOldGen::initialize_virtual_space(ReservedSpace rs, size_t alignment) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
53117
37930c6ba6d7 8211424: Allocation of old generation of java heap on alternate memory devices - Parallel GC
sangheki
parents: 49982
diff changeset
    75
  if(ParallelScavengeHeap::heap()->ps_collector_policy()->is_hetero_heap()) {
37930c6ba6d7 8211424: Allocation of old generation of java heap on alternate memory devices - Parallel GC
sangheki
parents: 49982
diff changeset
    76
    _virtual_space = new PSFileBackedVirtualSpace(rs, alignment, AllocateOldGenAt);
37930c6ba6d7 8211424: Allocation of old generation of java heap on alternate memory devices - Parallel GC
sangheki
parents: 49982
diff changeset
    77
    if (!(static_cast <PSFileBackedVirtualSpace*>(_virtual_space))->initialize()) {
37930c6ba6d7 8211424: Allocation of old generation of java heap on alternate memory devices - Parallel GC
sangheki
parents: 49982
diff changeset
    78
      vm_exit_during_initialization("Could not map space for PSOldGen at given AllocateOldGenAt path");
37930c6ba6d7 8211424: Allocation of old generation of java heap on alternate memory devices - Parallel GC
sangheki
parents: 49982
diff changeset
    79
    }
37930c6ba6d7 8211424: Allocation of old generation of java heap on alternate memory devices - Parallel GC
sangheki
parents: 49982
diff changeset
    80
  } else {
37930c6ba6d7 8211424: Allocation of old generation of java heap on alternate memory devices - Parallel GC
sangheki
parents: 49982
diff changeset
    81
    _virtual_space = new PSVirtualSpace(rs, alignment);
37930c6ba6d7 8211424: Allocation of old generation of java heap on alternate memory devices - Parallel GC
sangheki
parents: 49982
diff changeset
    82
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  if (!_virtual_space->expand_by(_init_gen_size)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
    vm_exit_during_initialization("Could not reserve enough space for "
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
                                  "object heap");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
void PSOldGen::initialize_work(const char* perf_data_name, int level) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  // Basic memory initialization
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  MemRegion limit_reserved((HeapWord*)virtual_space()->low_boundary(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
    heap_word_size(_max_gen_size));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  assert(limit_reserved.byte_size() == _max_gen_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
    "word vs bytes confusion");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  // Object start stuff
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  start_array()->initialize(limit_reserved);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  _reserved = MemRegion((HeapWord*)virtual_space()->low_boundary(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
                        (HeapWord*)virtual_space()->high_boundary());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  // Card table stuff
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  MemRegion cmr((HeapWord*)virtual_space()->low(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
                (HeapWord*)virtual_space()->high());
971
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 1
diff changeset
   113
  if (ZapUnusedHeapArea) {
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 1
diff changeset
   114
    // 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
   115
    // 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
   116
    // 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
   117
    // 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
   118
    // (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
   119
    SpaceMangler::mangle_region(cmr);
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 1
diff changeset
   120
  }
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 1
diff changeset
   121
30173
13cf7580b000 8077413: Avoid use of Universe::heap() inside collectors
pliden
parents: 29798
diff changeset
   122
  ParallelScavengeHeap* heap = ParallelScavengeHeap::heap();
49164
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 47216
diff changeset
   123
  PSCardTable* ct = heap->card_table();
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 47216
diff changeset
   124
  ct->resize_covered_region(cmr);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  // Verify that the start and end of this generation is the start of a card.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  // If this wasn't true, a single card could span more than one generation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  // which would cause problems when we commit/uncommit memory, and when we
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  // clear and dirty cards.
30173
13cf7580b000 8077413: Avoid use of Universe::heap() inside collectors
pliden
parents: 29798
diff changeset
   130
  guarantee(ct->is_card_aligned(_reserved.start()), "generation must be card aligned");
13cf7580b000 8077413: Avoid use of Universe::heap() inside collectors
pliden
parents: 29798
diff changeset
   131
  if (_reserved.end() != heap->reserved_region().end()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
    // 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
   133
    // the end if we try.
30173
13cf7580b000 8077413: Avoid use of Universe::heap() inside collectors
pliden
parents: 29798
diff changeset
   134
    guarantee(ct->is_card_aligned(_reserved.end()), "generation must be card aligned");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  // ObjectSpace stuff
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
1911
b7cfe7eb809c 6783381: NUMA allocator: don't pretouch eden space with UseNUMA
iveresov
parents: 1412
diff changeset
   141
  _object_space = new MutableSpace(virtual_space()->alignment());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  if (_object_space == NULL)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
    vm_exit_during_initialization("Could not allocate an old gen space");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
971
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 1
diff changeset
   146
  object_space()->initialize(cmr,
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 1
diff changeset
   147
                             SpaceDecorator::Clear,
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 1
diff changeset
   148
                             SpaceDecorator::Mangle);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
49982
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49594
diff changeset
   150
#if INCLUDE_SERIALGC
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  _object_mark_sweep = new PSMarkSweepDecorator(_object_space, start_array(), MarkSweepDeadRatio);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
49982
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49594
diff changeset
   153
  if (_object_mark_sweep == NULL) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
    vm_exit_during_initialization("Could not complete allocation of old generation");
49982
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49594
diff changeset
   155
  }
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49594
diff changeset
   156
#endif // INCLUDE_SERIALGC
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  // Update the start_array
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  start_array()->set_covered_region(cmr);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 12379
diff changeset
   160
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 12379
diff changeset
   162
void PSOldGen::initialize_performance_counters(const char* perf_data_name, int level) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  // 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
   164
  _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
   165
                                           _max_gen_size, virtual_space());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
  _space_counters = new SpaceCounters(perf_data_name, 0,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
                                      virtual_space()->reserved_size(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
                                      _object_space, _gen_counters);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
// Assume that the generation has been allocated if its
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
// reserved size is not 0.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
bool  PSOldGen::is_allocated() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
  return virtual_space()->reserved_size() != 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
49982
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49594
diff changeset
   177
#if INCLUDE_SERIALGC
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49594
diff changeset
   178
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
void PSOldGen::precompact() {
30173
13cf7580b000 8077413: Avoid use of Universe::heap() inside collectors
pliden
parents: 29798
diff changeset
   180
  ParallelScavengeHeap* heap = ParallelScavengeHeap::heap();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
  // Reset start array first.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
  start_array()->reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
  object_mark_sweep()->precompact();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
  // Now compact the young gen
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
  heap->young_gen()->precompact();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
void PSOldGen::adjust_pointers() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
  object_mark_sweep()->adjust_pointers();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
void PSOldGen::compact() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
  object_mark_sweep()->compact(ZapUnusedHeapArea);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
49982
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49594
diff changeset
   199
#endif // INCLUDE_SERIALGC
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49594
diff changeset
   200
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
size_t PSOldGen::contiguous_available() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
  return object_space()->free_in_bytes() + virtual_space()->uncommitted_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
// Allocation. We report all successful allocations to the size policy
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
// 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
   207
HeapWord* PSOldGen::allocate(size_t word_size) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
  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
   209
  HeapWord* res = allocate_noexpand(word_size);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
  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
   212
    res = expand_and_allocate(word_size);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
  // Allocations in the old generation need to be reported
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
  if (res != NULL) {
30173
13cf7580b000 8077413: Avoid use of Universe::heap() inside collectors
pliden
parents: 29798
diff changeset
   217
    ParallelScavengeHeap* heap = ParallelScavengeHeap::heap();
31359
e9d8d21c21f3 7169803: Usage of pretenured value is not correct
david
parents: 30764
diff changeset
   218
    heap->size_policy()->tenured_allocation(word_size * HeapWordSize);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
  return res;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
9997
b75b7939f448 6994322: Remove the is_tlab and is_noref / is_large_noref parameters from the CollectedHeap
tonyp
parents: 9423
diff changeset
   224
HeapWord* PSOldGen::expand_and_allocate(size_t word_size) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
  expand(word_size*HeapWordSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
  if (GCExpandToAllocateDelayMillis > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
    os::sleep(Thread::current(), GCExpandToAllocateDelayMillis, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
  }
9997
b75b7939f448 6994322: Remove the is_tlab and is_noref / is_large_noref parameters from the CollectedHeap
tonyp
parents: 9423
diff changeset
   229
  return allocate_noexpand(word_size);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
HeapWord* PSOldGen::expand_and_cas_allocate(size_t word_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
  expand(word_size*HeapWordSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
  if (GCExpandToAllocateDelayMillis > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
    os::sleep(Thread::current(), GCExpandToAllocateDelayMillis, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
  return cas_allocate_noexpand(word_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
void PSOldGen::expand(size_t bytes) {
979
c9479f1e0a94 6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents: 971
diff changeset
   241
  if (bytes == 0) {
c9479f1e0a94 6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents: 971
diff changeset
   242
    return;
c9479f1e0a94 6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents: 971
diff changeset
   243
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
  MutexLocker x(ExpandHeap_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
  const size_t alignment = virtual_space()->alignment();
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 37073
diff changeset
   246
  size_t aligned_bytes  = align_up(bytes, alignment);
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 37073
diff changeset
   247
  size_t aligned_expand_bytes = align_up(MinHeapDeltaBytes, alignment);
9423
a977bd202cec 7041501: NUMA: Expand the old gen more aggressively
iveresov
parents: 9178
diff changeset
   248
a977bd202cec 7041501: NUMA: Expand the old gen more aggressively
iveresov
parents: 9178
diff changeset
   249
  if (UseNUMA) {
a977bd202cec 7041501: NUMA: Expand the old gen more aggressively
iveresov
parents: 9178
diff changeset
   250
    // 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
   251
    // 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
   252
    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
   253
  }
979
c9479f1e0a94 6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents: 971
diff changeset
   254
  if (aligned_bytes == 0){
c9479f1e0a94 6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents: 971
diff changeset
   255
    // 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
   256
    // 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
   257
    // 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
   258
    // 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
   259
    // 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
   260
    // start with.
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 37073
diff changeset
   261
    aligned_bytes = align_down(bytes, alignment);
979
c9479f1e0a94 6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents: 971
diff changeset
   262
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
  bool success = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
  if (aligned_expand_bytes > aligned_bytes) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
    success = expand_by(aligned_expand_bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
  if (!success) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
    success = expand_by(aligned_bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
  if (!success) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
    success = expand_to_reserved();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
35492
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 35061
diff changeset
   275
  if (success && GCLocker::is_active_and_needs_gc()) {
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   276
    log_debug(gc)("Garbage collection disabled, expanded heap instead");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
bool PSOldGen::expand_by(size_t bytes) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
  assert_lock_strong(ExpandHeap_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
  assert_locked_or_safepoint(Heap_lock);
979
c9479f1e0a94 6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents: 971
diff changeset
   283
  if (bytes == 0) {
c9479f1e0a94 6730514: assertion failure in mangling code when expanding by 0 bytes
jmasa
parents: 971
diff changeset
   284
    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
   285
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
  bool result = virtual_space()->expand_by(bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
  if (result) {
971
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 1
diff changeset
   288
    if (ZapUnusedHeapArea) {
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 1
diff changeset
   289
      // 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
   290
      // 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
   291
      // 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
   292
      // 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
   293
      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
   294
      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
   295
        "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
   296
      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
   297
      // 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
   298
      // 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
   299
      SpaceMangler::mangle_region(mangle_region);
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 1
diff changeset
   300
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
    post_resize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
    if (UsePerfData) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
      _space_counters->update_capacity();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
      _gen_counters->update_all();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   308
  if (result) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
    size_t new_mem_size = virtual_space()->committed_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
    size_t old_mem_size = new_mem_size - bytes;
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   311
    log_debug(gc)("Expanding %s from " SIZE_FORMAT "K by " SIZE_FORMAT "K to " SIZE_FORMAT "K",
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   312
                  name(), old_mem_size/K, bytes/K, new_mem_size/K);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
  return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
bool PSOldGen::expand_to_reserved() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
  assert_lock_strong(ExpandHeap_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
  assert_locked_or_safepoint(Heap_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
  bool result = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
  const size_t remaining_bytes = virtual_space()->uncommitted_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
  if (remaining_bytes > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
    result = expand_by(remaining_bytes);
37073
c39d0903390b 8151605: Change warning() to log_warning(gc) in the GC code
brutisso
parents: 35862
diff changeset
   326
    DEBUG_ONLY(if (!result) log_warning(gc)("grow to reserve failed"));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
  return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
void PSOldGen::shrink(size_t bytes) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
  assert_lock_strong(ExpandHeap_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
  assert_locked_or_safepoint(Heap_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 37073
diff changeset
   335
  size_t size = align_down(bytes, virtual_space()->alignment());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
  if (size > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
    assert_lock_strong(ExpandHeap_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
    virtual_space()->shrink_by(bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
    post_resize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   341
    size_t new_mem_size = virtual_space()->committed_size();
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   342
    size_t old_mem_size = new_mem_size + bytes;
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   343
    log_debug(gc)("Shrinking %s from " SIZE_FORMAT "K by " SIZE_FORMAT "K to " SIZE_FORMAT "K",
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   344
                  name(), old_mem_size/K, bytes/K, new_mem_size/K);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
void PSOldGen::resize(size_t desired_free_space) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
  const size_t alignment = virtual_space()->alignment();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
  const size_t size_before = virtual_space()->committed_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
  size_t new_size = used_in_bytes() + desired_free_space;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
  if (new_size < used_in_bytes()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
    // Overflowed the addition.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
    new_size = gen_size_limit();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
  // Adjust according to our min and max
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
  new_size = MAX2(MIN2(new_size, gen_size_limit()), min_gen_size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
  assert(gen_size_limit() >= reserved().byte_size(), "max new size problem?");
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 37073
diff changeset
   360
  new_size = align_up(new_size, alignment);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
  const size_t current_size = capacity_in_bytes();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   364
  log_trace(gc, ergo)("AdaptiveSizePolicy::old generation size: "
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   365
    "desired free: " SIZE_FORMAT " used: " SIZE_FORMAT
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   366
    " new size: " SIZE_FORMAT " current size " SIZE_FORMAT
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   367
    " gen limits: " SIZE_FORMAT " / " SIZE_FORMAT,
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   368
    desired_free_space, used_in_bytes(), new_size, current_size,
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   369
    gen_size_limit(), min_gen_size());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
  if (new_size == current_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
    // No change requested
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
  if (new_size > current_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
    size_t change_bytes = new_size - current_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
    expand(change_bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
    size_t change_bytes = current_size - new_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
    // shrink doesn't grab this lock, expand does. Is that right?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
    MutexLocker x(ExpandHeap_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
    shrink(change_bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   385
  log_trace(gc, ergo)("AdaptiveSizePolicy::old generation size: collection: %d (" SIZE_FORMAT ") -> (" SIZE_FORMAT ") ",
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   386
                      ParallelScavengeHeap::heap()->total_collections(),
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   387
                      size_before,
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   388
                      virtual_space()->committed_size());
1
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);
49164
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 47216
diff changeset
   402
  ParallelScavengeHeap::heap()->card_table()->resize_covered_region(new_memregion);
1
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());
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   435
  st->print(" total " SIZE_FORMAT "K, used " SIZE_FORMAT "K",
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   436
              capacity_in_bytes()/K, used_in_bytes()/K);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
  st->print_cr(" [" INTPTR_FORMAT ", " INTPTR_FORMAT ", " INTPTR_FORMAT ")",
29798
451c73fdf690 8076071: parallelScavenge: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 29325
diff changeset
   438
                p2i(virtual_space()->low_boundary()),
451c73fdf690 8076071: parallelScavenge: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 29325
diff changeset
   439
                p2i(virtual_space()->high()),
451c73fdf690 8076071: parallelScavenge: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 29325
diff changeset
   440
                p2i(virtual_space()->high_boundary()));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
  st->print("  object"); object_space()->print_on(st);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
void PSOldGen::print_used_change(size_t prev_used) const {
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   446
  log_info(gc, heap)("%s: "  SIZE_FORMAT "K->" SIZE_FORMAT "K("  SIZE_FORMAT "K)",
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 32623
diff changeset
   447
      name(), prev_used / K, used_in_bytes() / K, capacity_in_bytes() / K);
1
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::update_counters() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
  if (UsePerfData) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
    _space_counters->update_all();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
    _gen_counters->update_all();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
void PSOldGen::space_invariants() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
  assert(object_space()->end() == (HeapWord*) virtual_space()->high(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
    "Space invariant");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
  assert(object_space()->bottom() == (HeapWord*) virtual_space()->low(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
    "Space invariant");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
  assert(virtual_space()->low_boundary() <= virtual_space()->low(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
    "Space invariant");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
  assert(virtual_space()->high_boundary() >= virtual_space()->high(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
    "Space invariant");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
  assert(virtual_space()->low_boundary() == (char*) _reserved.start(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
    "Space invariant");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
  assert(virtual_space()->high_boundary() == (char*) _reserved.end(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
    "Space invariant");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
  assert(virtual_space()->committed_size() <= virtual_space()->reserved_size(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
    "Space invariant");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
12379
2cf45b79ce3a 4988100: oop_verify_old_oop appears to be dead
brutisso
parents: 9997
diff changeset
   477
void PSOldGen::verify() {
2cf45b79ce3a 4988100: oop_verify_old_oop appears to be dead
brutisso
parents: 9997
diff changeset
   478
  object_space()->verify();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
class VerifyObjectStartArrayClosure : public ObjectClosure {
32623
390a27af5657 8134626: Misc cleanups after generation array removal
jwilhelm
parents: 31359
diff changeset
   481
  PSOldGen* _old_gen;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
  ObjectStartArray* _start_array;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
 public:
32623
390a27af5657 8134626: Misc cleanups after generation array removal
jwilhelm
parents: 31359
diff changeset
   485
  VerifyObjectStartArrayClosure(PSOldGen* old_gen, ObjectStartArray* start_array) :
390a27af5657 8134626: Misc cleanups after generation array removal
jwilhelm
parents: 31359
diff changeset
   486
    _old_gen(old_gen), _start_array(start_array) { }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
  virtual void do_object(oop obj) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
    HeapWord* test_addr = (HeapWord*)obj + 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
    guarantee(_start_array->object_start(test_addr) == (HeapWord*)obj, "ObjectStartArray cannot find start of object");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
    guarantee(_start_array->is_block_allocated((HeapWord*)obj), "ObjectStartArray missing block allocation");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
void PSOldGen::verify_object_start_array() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
  VerifyObjectStartArrayClosure check( this, &_start_array );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
  object_iterate(&check);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
}
971
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 1
diff changeset
   499
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 1
diff changeset
   500
#ifndef PRODUCT
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 1
diff changeset
   501
void PSOldGen::record_spaces_top() {
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 1
diff changeset
   502
  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
   503
  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
   504
}
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 1
diff changeset
   505
#endif