src/hotspot/share/gc/parallel/asPSYoungGen.cpp
author tschatzl
Fri, 22 Nov 2019 10:03:38 +0100
changeset 59221 cc3a82fc7bcb
parent 58980 47c20fc6a517
permissions -rw-r--r--
8233702: Introduce helper function to clamp value to range Reviewed-by: sjohanss, kbarrett
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) 2003, 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: 5402
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5402
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: 5402
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"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30173
diff changeset
    26
#include "gc/parallel/asPSYoungGen.hpp"
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/psMarkSweepDecorator.hpp"
35862
411842d0c882 8146395: Add inline qualifier in oop.hpp and fix inlining in gc files
goetz
parents: 35061
diff changeset
    29
#include "gc/parallel/psScavenge.inline.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30173
diff changeset
    30
#include "gc/parallel/psYoungGen.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30173
diff changeset
    31
#include "gc/shared/gcUtil.hpp"
54678
93f09ca4a7f8 8198505: Remove CollectorPolicy and its subclasses
stefank
parents: 49964
diff changeset
    32
#include "gc/shared/genArguments.hpp"
58980
47c20fc6a517 8189737: Make HeapRegion not derive from Space
tschatzl
parents: 54678
diff changeset
    33
#include "gc/shared/spaceDecorator.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    34
#include "oops/oop.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    35
#include "runtime/java.hpp"
46625
edefffab74e2 8183552: Move align functions to align.hpp
stefank
parents: 46619
diff changeset
    36
#include "utilities/align.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
ASPSYoungGen::ASPSYoungGen(size_t init_byte_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
                           size_t minimum_byte_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
                           size_t byte_size_limit) :
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  PSYoungGen(init_byte_size, minimum_byte_size, byte_size_limit),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  _gen_size_limit(byte_size_limit) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
ASPSYoungGen::ASPSYoungGen(PSVirtualSpace* vs,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
                           size_t init_byte_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
                           size_t minimum_byte_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
                           size_t byte_size_limit) :
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  //PSYoungGen(init_byte_size, minimum_byte_size, byte_size_limit),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  PSYoungGen(vs->committed_size(), minimum_byte_size, byte_size_limit),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  _gen_size_limit(byte_size_limit) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  assert(vs->committed_size() == init_byte_size, "Cannot replace with");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  _virtual_space = vs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
void ASPSYoungGen::initialize_virtual_space(ReservedSpace rs,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
                                            size_t alignment) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  assert(_init_gen_size != 0, "Should have a finite size");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  _virtual_space = new PSVirtualSpaceHighToLow(rs, alignment);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  if (!_virtual_space->expand_by(_init_gen_size)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
    vm_exit_during_initialization("Could not reserve enough space for "
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
                                  "object heap");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
void ASPSYoungGen::initialize(ReservedSpace rs, size_t alignment) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  initialize_virtual_space(rs, alignment);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  initialize_work();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
size_t ASPSYoungGen::available_for_expansion() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  size_t current_committed_size = virtual_space()->committed_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  assert((gen_size_limit() >= current_committed_size),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
    "generation size limit is wrong");
54678
93f09ca4a7f8 8198505: Remove CollectorPolicy and its subclasses
stefank
parents: 49964
diff changeset
    78
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  size_t result =  gen_size_limit() - current_committed_size;
54678
93f09ca4a7f8 8198505: Remove CollectorPolicy and its subclasses
stefank
parents: 49964
diff changeset
    80
  size_t result_aligned = align_down(result, GenAlignment);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  return result_aligned;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
// Return the number of bytes the young gen is willing give up.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
// Future implementations could check the survivors and if to_space is in the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
// right place (below from_space), take a chunk from to_space.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
size_t ASPSYoungGen::available_for_contraction() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  size_t uncommitted_bytes = virtual_space()->uncommitted_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  if (uncommitted_bytes != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
    return uncommitted_bytes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  if (eden_space()->is_empty()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
    // Respect the minimum size for eden and for the young gen as a whole.
30173
13cf7580b000 8077413: Avoid use of Universe::heap() inside collectors
pliden
parents: 24424
diff changeset
    96
    ParallelScavengeHeap* heap = ParallelScavengeHeap::heap();
54678
93f09ca4a7f8 8198505: Remove CollectorPolicy and its subclasses
stefank
parents: 49964
diff changeset
    97
    const size_t eden_alignment = SpaceAlignment;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
    assert(eden_space()->capacity_in_bytes() >= eden_alignment,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
      "Alignment is wrong");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
    size_t eden_avail = eden_space()->capacity_in_bytes() - eden_alignment;
54678
93f09ca4a7f8 8198505: Remove CollectorPolicy and its subclasses
stefank
parents: 49964
diff changeset
   102
    eden_avail = align_down(eden_avail, GenAlignment);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
    assert(virtual_space()->committed_size() >= min_gen_size(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
      "minimum gen size is wrong");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
    size_t gen_avail = virtual_space()->committed_size() - min_gen_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
    assert(virtual_space()->is_aligned(gen_avail), "not aligned");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
    const size_t max_contraction = MIN2(eden_avail, gen_avail);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
    // See comment for ASPSOldGen::available_for_contraction()
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
    // for reasons the "increment" fraction is used.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
    PSAdaptiveSizePolicy* policy = heap->size_policy();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
    size_t result = policy->eden_increment_aligned_down(max_contraction);
54678
93f09ca4a7f8 8198505: Remove CollectorPolicy and its subclasses
stefank
parents: 49964
diff changeset
   114
    size_t result_aligned = align_down(result, GenAlignment);
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   115
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   116
    log_trace(gc, ergo)("ASPSYoungGen::available_for_contraction: " SIZE_FORMAT " K", result_aligned/K);
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   117
    log_trace(gc, ergo)("  max_contraction " SIZE_FORMAT " K", max_contraction/K);
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   118
    log_trace(gc, ergo)("  eden_avail " SIZE_FORMAT " K", eden_avail/K);
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   119
    log_trace(gc, ergo)("  gen_avail " SIZE_FORMAT " K", gen_avail/K);
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   120
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
    return result_aligned;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  return 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
// The current implementation only considers to the end of eden.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
// If to_space is below from_space, to_space is not considered.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
// to_space can be.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
size_t ASPSYoungGen::available_to_live() {
54678
93f09ca4a7f8 8198505: Remove CollectorPolicy and its subclasses
stefank
parents: 49964
diff changeset
   131
  const size_t alignment = SpaceAlignment;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  // Include any space that is committed but is not in eden.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  size_t available = pointer_delta(eden_space()->bottom(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
                                   virtual_space()->low(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
                                   sizeof(char));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  const size_t eden_capacity = eden_space()->capacity_in_bytes();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  if (eden_space()->is_empty() && eden_capacity > alignment) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
    available += eden_capacity - alignment;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  return available;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
// Similar to PSYoungGen::resize_generation() but
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
//  allows sum of eden_size and 2 * survivor_size to exceed _max_gen_size
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
//  expands at the low end of the virtual space
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
//  moves the boundary between the generations in order to expand
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
//  some additional diagnostics
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
// If no additional changes are required, this can be deleted
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
// and the changes factored back into PSYoungGen::resize_generation().
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
bool ASPSYoungGen::resize_generation(size_t eden_size, size_t survivor_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  const size_t alignment = virtual_space()->alignment();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  size_t orig_size = virtual_space()->committed_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  bool size_changed = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  // There used to be a guarantee here that
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  //   (eden_size + 2*survivor_size)  <= _max_gen_size
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  // This requirement is enforced by the calculation of desired_size
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  // below.  It may not be true on entry since the size of the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
  // eden_size is no bounded by the generation size.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  assert(max_size() == reserved().byte_size(), "max gen size problem?");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
  assert(min_gen_size() <= orig_size && orig_size <= max_size(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
         "just checking");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
  // Adjust new generation size
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  const size_t eden_plus_survivors =
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46565
diff changeset
   169
    align_up(eden_size + 2 * survivor_size, alignment);
59221
cc3a82fc7bcb 8233702: Introduce helper function to clamp value to range
tschatzl
parents: 58980
diff changeset
   170
  size_t desired_size = clamp(eden_plus_survivors, min_gen_size(), gen_size_limit());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
  assert(desired_size <= gen_size_limit(), "just checking");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  if (desired_size > orig_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
    // Grow the generation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
    size_t change = desired_size - orig_size;
971
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   176
    HeapWord* prev_low = (HeapWord*) virtual_space()->low();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
    if (!virtual_space()->expand_by(change)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
      return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
    }
971
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   180
    if (ZapUnusedHeapArea) {
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   181
      // Mangle newly committed space immediately because it
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   182
      // can be done here more simply that after the new
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   183
      // spaces have been computed.
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   184
      HeapWord* new_low = (HeapWord*) virtual_space()->low();
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   185
      assert(new_low < prev_low, "Did not grow");
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   186
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   187
      MemRegion mangle_region(new_low, prev_low);
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   188
      SpaceMangler::mangle_region(mangle_region);
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   189
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
    size_changed = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
  } else if (desired_size < orig_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
    size_t desired_change = orig_size - desired_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
    // How much is available for shrinking.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
    size_t available_bytes = limit_gen_shrink(desired_change);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
    size_t change = MIN2(desired_change, available_bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
    virtual_space()->shrink_by(change);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
    size_changed = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
  } else {
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   200
    if (orig_size == gen_size_limit()) {
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   201
      log_trace(gc)("ASPSYoung generation size at maximum: " SIZE_FORMAT "K", orig_size/K);
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   202
    } else if (orig_size == min_gen_size()) {
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   203
      log_trace(gc)("ASPSYoung generation size at minium: " SIZE_FORMAT "K", orig_size/K);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
  if (size_changed) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
    reset_after_change();
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   209
    log_trace(gc)("ASPSYoung generation size changed: " SIZE_FORMAT "K->" SIZE_FORMAT "K",
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   210
                  orig_size/K, virtual_space()->committed_size()/K);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
  guarantee(eden_plus_survivors <= virtual_space()->committed_size() ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
            virtual_space()->committed_size() == max_size(), "Sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
  return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
// Similar to PSYoungGen::resize_spaces() but
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
//  eden always starts at the low end of the committed virtual space
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
//  current implementation does not allow holes between the spaces
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
//  _young_generation_boundary has to be reset because it changes.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
//  so additional verification
971
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   224
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
void ASPSYoungGen::resize_spaces(size_t requested_eden_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
                                 size_t requested_survivor_size) {
971
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   227
  assert(UseAdaptiveSizePolicy, "sanity check");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
  assert(requested_eden_size > 0 && requested_survivor_size > 0,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
         "just checking");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
  space_invariants();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
  // We require eden and to space to be empty
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
  if ((!eden_space()->is_empty()) || (!to_space()->is_empty())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   238
  log_trace(gc, ergo)("PSYoungGen::resize_spaces(requested_eden_size: "
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   239
                      SIZE_FORMAT
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   240
                      ", requested_survivor_size: " SIZE_FORMAT ")",
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   241
                      requested_eden_size, requested_survivor_size);
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   242
  log_trace(gc, ergo)("    eden: [" PTR_FORMAT ".." PTR_FORMAT ") "
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   243
                      SIZE_FORMAT,
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   244
                      p2i(eden_space()->bottom()),
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   245
                      p2i(eden_space()->end()),
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   246
                      pointer_delta(eden_space()->end(), eden_space()->bottom(), sizeof(char)));
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   247
  log_trace(gc, ergo)("    from: [" PTR_FORMAT ".." PTR_FORMAT ") "
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   248
                      SIZE_FORMAT,
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   249
                      p2i(from_space()->bottom()),
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   250
                      p2i(from_space()->end()),
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   251
                      pointer_delta(from_space()->end(), from_space()->bottom(), sizeof(char)));
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   252
  log_trace(gc, ergo)("      to: [" PTR_FORMAT ".." PTR_FORMAT ") "
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   253
                      SIZE_FORMAT,
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   254
                      p2i(to_space()->bottom()),
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   255
                      p2i(to_space()->end()),
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   256
                      pointer_delta(  to_space()->end(), to_space()->bottom(), sizeof(char)));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
  // There's nothing to do if the new sizes are the same as the current
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
  if (requested_survivor_size == to_space()->capacity_in_bytes() &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
      requested_survivor_size == from_space()->capacity_in_bytes() &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
      requested_eden_size == eden_space()->capacity_in_bytes()) {
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   262
    log_trace(gc, ergo)("    capacities are the right sizes, returning");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
  char* eden_start = (char*)virtual_space()->low();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
  char* eden_end   = (char*)eden_space()->end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
  char* from_start = (char*)from_space()->bottom();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
  char* from_end   = (char*)from_space()->end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
  char* to_start   = (char*)to_space()->bottom();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
  char* to_end     = (char*)to_space()->end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
  assert(eden_start < from_start, "Cannot push into from_space");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
30173
13cf7580b000 8077413: Avoid use of Universe::heap() inside collectors
pliden
parents: 24424
diff changeset
   275
  ParallelScavengeHeap* heap = ParallelScavengeHeap::heap();
971
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   276
  const bool maintain_minimum =
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   277
    (requested_eden_size + 2 * requested_survivor_size) <= min_gen_size();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
971
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   279
  bool eden_from_to_order = from_start < to_start;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
  // Check whether from space is below to space
971
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   281
  if (eden_from_to_order) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
    // Eden, from, to
971
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   283
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   284
    log_trace(gc, ergo)("  Eden, from, to:");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
    // Set eden
971
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   287
    // "requested_eden_size" is a goal for the size of eden
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   288
    // and may not be attainable.  "eden_size" below is
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   289
    // calculated based on the location of from-space and
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   290
    // the goal for the size of eden.  from-space is
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   291
    // fixed in place because it contains live data.
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   292
    // The calculation is done this way to avoid 32bit
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   293
    // overflow (i.e., eden_start + requested_eden_size
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   294
    // may too large for representation in 32bits).
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   295
    size_t eden_size;
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   296
    if (maintain_minimum) {
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   297
      // Only make eden larger than the requested size if
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   298
      // the minimum size of the generation has to be maintained.
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   299
      // This could be done in general but policy at a higher
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   300
      // level is determining a requested size for eden and that
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   301
      // should be honored unless there is a fundamental reason.
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   302
      eden_size = pointer_delta(from_start,
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   303
                                eden_start,
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   304
                                sizeof(char));
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   305
    } else {
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   306
      eden_size = MIN2(requested_eden_size,
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   307
                       pointer_delta(from_start, eden_start, sizeof(char)));
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   308
    }
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   309
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
    eden_end = eden_start + eden_size;
5402
c51fd0c1d005 6888953: some calls to function-like macros are missing semicolons
jcoomes
parents: 977
diff changeset
   311
    assert(eden_end >= eden_start, "addition overflowed");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
    // To may resize into from space as long as it is clear of live data.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
    // From space must remain page aligned, though, so we need to do some
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
    // extra calculations.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
    // First calculate an optimal to-space
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
    to_end   = (char*)virtual_space()->high();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
    to_start = (char*)pointer_delta(to_end,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
                                    (char*)requested_survivor_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
                                    sizeof(char));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
    // Does the optimal to-space overlap from-space?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
    if (to_start < (char*)from_space()->end()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
      // Calculate the minimum offset possible for from_end
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
      size_t from_size =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
        pointer_delta(from_space()->top(), from_start, sizeof(char));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
      // Should we be in this method if from_space is empty? Why not the set_space method? FIX ME!
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
      if (from_size == 0) {
54678
93f09ca4a7f8 8198505: Remove CollectorPolicy and its subclasses
stefank
parents: 49964
diff changeset
   331
        from_size = SpaceAlignment;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
      } else {
54678
93f09ca4a7f8 8198505: Remove CollectorPolicy and its subclasses
stefank
parents: 49964
diff changeset
   333
        from_size = align_up(from_size, SpaceAlignment);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
      from_end = from_start + from_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
      assert(from_end > from_start, "addition overflow or from_size problem");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
      guarantee(from_end <= (char*)from_space()->end(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
        "from_end moved to the right");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
      // Now update to_start with the new from_end
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
      to_start = MAX2(from_end, to_start);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
    guarantee(to_start != to_end, "to space is zero sized");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   348
    log_trace(gc, ergo)("    [eden_start .. eden_end): "
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   349
                        "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT,
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   350
                        p2i(eden_start),
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   351
                        p2i(eden_end),
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   352
                        pointer_delta(eden_end, eden_start, sizeof(char)));
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   353
    log_trace(gc, ergo)("    [from_start .. from_end): "
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   354
                        "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT,
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   355
                        p2i(from_start),
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   356
                        p2i(from_end),
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   357
                        pointer_delta(from_end, from_start, sizeof(char)));
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   358
    log_trace(gc, ergo)("    [  to_start ..   to_end): "
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   359
                        "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT,
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   360
                        p2i(to_start),
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   361
                        p2i(to_end),
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   362
                        pointer_delta(  to_end,   to_start, sizeof(char)));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
    // Eden, to, from
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   365
    log_trace(gc, ergo)("  Eden, to, from:");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
    // To space gets priority over eden resizing. Note that we position
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
    // to space as if we were able to resize from space, even though from
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
    // space is not modified.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
    // Giving eden priority was tried and gave poorer performance.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
    to_end   = (char*)pointer_delta(virtual_space()->high(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
                                    (char*)requested_survivor_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
                                    sizeof(char));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
    to_end   = MIN2(to_end, from_start);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
    to_start = (char*)pointer_delta(to_end, (char*)requested_survivor_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
                                    sizeof(char));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
    // if the space sizes are to be increased by several times then
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
    // 'to_start' will point beyond the young generation. In this case
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
    // 'to_start' should be adjusted.
54678
93f09ca4a7f8 8198505: Remove CollectorPolicy and its subclasses
stefank
parents: 49964
diff changeset
   380
    to_start = MAX2(to_start, eden_start + SpaceAlignment);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
    // Compute how big eden can be, then adjust end.
971
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   383
    // See  comments above on calculating eden_end.
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   384
    size_t eden_size;
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   385
    if (maintain_minimum) {
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   386
      eden_size = pointer_delta(to_start, eden_start, sizeof(char));
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   387
    } else {
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   388
      eden_size = MIN2(requested_eden_size,
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   389
                       pointer_delta(to_start, eden_start, sizeof(char)));
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   390
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
    eden_end = eden_start + eden_size;
5402
c51fd0c1d005 6888953: some calls to function-like macros are missing semicolons
jcoomes
parents: 977
diff changeset
   392
    assert(eden_end >= eden_start, "addition overflowed");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
    // Don't let eden shrink down to 0 or less.
54678
93f09ca4a7f8 8198505: Remove CollectorPolicy and its subclasses
stefank
parents: 49964
diff changeset
   395
    eden_end = MAX2(eden_end, eden_start + SpaceAlignment);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
    to_start = MAX2(to_start, eden_end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   398
    log_trace(gc, ergo)("    [eden_start .. eden_end): "
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   399
                        "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT,
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   400
                        p2i(eden_start),
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   401
                        p2i(eden_end),
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   402
                        pointer_delta(eden_end, eden_start, sizeof(char)));
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   403
    log_trace(gc, ergo)("    [  to_start ..   to_end): "
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   404
                        "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT,
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   405
                        p2i(to_start),
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   406
                        p2i(to_end),
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   407
                        pointer_delta(  to_end,   to_start, sizeof(char)));
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   408
    log_trace(gc, ergo)("    [from_start .. from_end): "
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   409
                        "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT,
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   410
                        p2i(from_start),
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   411
                        p2i(from_end),
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   412
                        pointer_delta(from_end, from_start, sizeof(char)));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
  guarantee((HeapWord*)from_start <= from_space()->bottom(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
            "from start moved to the right");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
  guarantee((HeapWord*)from_end >= from_space()->top(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
            "from end moved into live data");
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46565
diff changeset
   420
  assert(is_object_aligned(eden_start), "checking alignment");
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46565
diff changeset
   421
  assert(is_object_aligned(from_start), "checking alignment");
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46565
diff changeset
   422
  assert(is_object_aligned(to_start), "checking alignment");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
  MemRegion edenMR((HeapWord*)eden_start, (HeapWord*)eden_end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
  MemRegion toMR  ((HeapWord*)to_start,   (HeapWord*)to_end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
  MemRegion fromMR((HeapWord*)from_start, (HeapWord*)from_end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
  // Let's make sure the call to initialize doesn't reset "top"!
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
  DEBUG_ONLY(HeapWord* old_from_top = from_space()->top();)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   431
  // For logging block  below
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
  size_t old_from = from_space()->capacity_in_bytes();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
  size_t old_to   = to_space()->capacity_in_bytes();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
971
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   435
  if (ZapUnusedHeapArea) {
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   436
    // NUMA is a special case because a numa space is not mangled
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   437
    // in order to not prematurely bind its address to memory to
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   438
    // the wrong memory (i.e., don't want the GC thread to first
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   439
    // touch the memory).  The survivor spaces are not numa
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   440
    // spaces and are mangled.
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   441
    if (UseNUMA) {
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   442
      if (eden_from_to_order) {
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   443
        mangle_survivors(from_space(), fromMR, to_space(), toMR);
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   444
      } else {
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   445
        mangle_survivors(to_space(), toMR, from_space(), fromMR);
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   446
      }
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   447
    }
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   448
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   449
    // If not mangling the spaces, do some checking to verify that
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   450
    // the spaces are already mangled.
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   451
    // The spaces should be correctly mangled at this point so
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   452
    // do some checking here. Note that they are not being mangled
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   453
    // in the calls to initialize().
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   454
    // Must check mangling before the spaces are reshaped.  Otherwise,
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   455
    // the bottom or end of one space may have moved into an area
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   456
    // covered by another space and a failure of the check may
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   457
    // not correctly indicate which space is not properly mangled.
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   458
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   459
    HeapWord* limit = (HeapWord*) virtual_space()->high();
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   460
    eden_space()->check_mangled_unused_area(limit);
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   461
    from_space()->check_mangled_unused_area(limit);
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   462
      to_space()->check_mangled_unused_area(limit);
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   463
  }
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   464
  // When an existing space is being initialized, it is not
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   465
  // mangled because the space has been previously mangled.
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   466
  eden_space()->initialize(edenMR,
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   467
                           SpaceDecorator::Clear,
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   468
                           SpaceDecorator::DontMangle);
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   469
    to_space()->initialize(toMR,
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   470
                           SpaceDecorator::Clear,
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   471
                           SpaceDecorator::DontMangle);
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   472
  from_space()->initialize(fromMR,
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   473
                           SpaceDecorator::DontClear,
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   474
                           SpaceDecorator::DontMangle);
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   475
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
  PSScavenge::set_young_generation_boundary(eden_space()->bottom());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
  assert(from_space()->top() == old_from_top, "from top changed!");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   480
  log_trace(gc, ergo)("AdaptiveSizePolicy::survivor space sizes: "
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   481
                "collection: %d "
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   482
                "(" SIZE_FORMAT ", " SIZE_FORMAT ") -> "
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   483
                "(" SIZE_FORMAT ", " SIZE_FORMAT ") ",
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   484
                ParallelScavengeHeap::heap()->total_collections(),
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   485
                old_from, old_to,
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   486
                from_space()->capacity_in_bytes(),
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   487
                to_space()->capacity_in_bytes());
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   488
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   489
    space_invariants();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
void ASPSYoungGen::reset_after_change() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
  assert_locked_or_safepoint(Heap_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
  _reserved = MemRegion((HeapWord*)virtual_space()->low_boundary(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
                        (HeapWord*)virtual_space()->high_boundary());
49964
99e698e94cc7 8201492: Properly implement non-contiguous generations for Reference discovery
tschatzl
parents: 49164
diff changeset
   496
  PSScavenge::set_subject_to_discovery_span(_reserved);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
  HeapWord* new_eden_bottom = (HeapWord*)virtual_space()->low();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
  HeapWord* eden_bottom = eden_space()->bottom();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   500
  if (new_eden_bottom != eden_bottom) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
    MemRegion eden_mr(new_eden_bottom, eden_space()->end());
971
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   502
    eden_space()->initialize(eden_mr,
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   503
                             SpaceDecorator::Clear,
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   504
                             SpaceDecorator::Mangle);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
    PSScavenge::set_young_generation_boundary(eden_space()->bottom());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
  MemRegion cmr((HeapWord*)virtual_space()->low(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
                (HeapWord*)virtual_space()->high());
49164
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 47216
diff changeset
   509
  ParallelScavengeHeap::heap()->barrier_set()->card_table()->resize_covered_region(cmr);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   510
489c9b5090e2 Initial load
duke
parents:
diff changeset
   511
  space_invariants();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   512
}