hotspot/src/share/vm/gc_implementation/parallelScavenge/asPSYoungGen.cpp
author trims
Thu, 27 May 2010 19:08:38 -0700
changeset 5547 f4b087cbb361
parent 5402 c51fd0c1d005
child 7397 5b173b4ca846
permissions -rw-r--r--
6941466: Oracle rebranding changes for Hotspot repositories Summary: Change all the Sun copyrights to Oracle copyright Reviewed-by: ohair
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5402
diff changeset
     2
 * Copyright (c) 2003, 2008, 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
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
# include "incls/_precompiled.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
# include "incls/_asPSYoungGen.cpp.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
ASPSYoungGen::ASPSYoungGen(size_t init_byte_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
                           size_t minimum_byte_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
                           size_t byte_size_limit) :
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
  PSYoungGen(init_byte_size, minimum_byte_size, byte_size_limit),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
  _gen_size_limit(byte_size_limit) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
ASPSYoungGen::ASPSYoungGen(PSVirtualSpace* vs,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
                           size_t init_byte_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
                           size_t minimum_byte_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
                           size_t byte_size_limit) :
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  //PSYoungGen(init_byte_size, minimum_byte_size, byte_size_limit),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  PSYoungGen(vs->committed_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
  assert(vs->committed_size() == init_byte_size, "Cannot replace with");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  _virtual_space = vs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
void ASPSYoungGen::initialize_virtual_space(ReservedSpace rs,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
                                            size_t alignment) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  assert(_init_gen_size != 0, "Should have a finite size");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  _virtual_space = new PSVirtualSpaceHighToLow(rs, alignment);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  if (!_virtual_space->expand_by(_init_gen_size)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
    vm_exit_during_initialization("Could not reserve enough space for "
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
                                  "object heap");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  }
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(ReservedSpace rs, size_t alignment) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  initialize_virtual_space(rs, alignment);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  initialize_work();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
size_t ASPSYoungGen::available_for_expansion() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  size_t current_committed_size = virtual_space()->committed_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  assert((gen_size_limit() >= current_committed_size),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
    "generation size limit is wrong");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  size_t result =  gen_size_limit() - current_committed_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  size_t result_aligned = align_size_down(result, heap->young_gen_alignment());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  return result_aligned;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
// Return the number of bytes the young gen is willing give up.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
// Future implementations could check the survivors and if to_space is in the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
// right place (below from_space), take a chunk from to_space.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
size_t ASPSYoungGen::available_for_contraction() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  size_t uncommitted_bytes = virtual_space()->uncommitted_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  if (uncommitted_bytes != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
    return uncommitted_bytes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  if (eden_space()->is_empty()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
    // Respect the minimum size for eden and for the young gen as a whole.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
    ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
186
32e6c95f8d9b 6557851: CMS: ergonomics defaults are not set with FLAG_SET_ERGO
jmasa
parents: 1
diff changeset
    89
    const size_t eden_alignment = heap->intra_heap_alignment();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
    const size_t gen_alignment = heap->young_gen_alignment();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
    assert(eden_space()->capacity_in_bytes() >= eden_alignment,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
      "Alignment is wrong");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
    size_t eden_avail = eden_space()->capacity_in_bytes() - eden_alignment;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
    eden_avail = align_size_down(eden_avail, gen_alignment);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
    assert(virtual_space()->committed_size() >= min_gen_size(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
      "minimum gen size is wrong");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
    size_t gen_avail = virtual_space()->committed_size() - min_gen_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
    assert(virtual_space()->is_aligned(gen_avail), "not aligned");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
    const size_t max_contraction = MIN2(eden_avail, gen_avail);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
    // See comment for ASPSOldGen::available_for_contraction()
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
    // for reasons the "increment" fraction is used.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
    PSAdaptiveSizePolicy* policy = heap->size_policy();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
    size_t result = policy->eden_increment_aligned_down(max_contraction);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
    size_t result_aligned = align_size_down(result, gen_alignment);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
    if (PrintAdaptiveSizePolicy && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
      gclog_or_tty->print_cr("ASPSYoungGen::available_for_contraction: %d K",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
        result_aligned/K);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
      gclog_or_tty->print_cr("  max_contraction %d K", max_contraction/K);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
      gclog_or_tty->print_cr("  eden_avail %d K", eden_avail/K);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
      gclog_or_tty->print_cr("  gen_avail %d K", gen_avail/K);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
    return result_aligned;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  return 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
// The current implementation only considers to the end of eden.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
// If to_space is below from_space, to_space is not considered.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
// to_space can be.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
size_t ASPSYoungGen::available_to_live() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
186
32e6c95f8d9b 6557851: CMS: ergonomics defaults are not set with FLAG_SET_ERGO
jmasa
parents: 1
diff changeset
   127
  const size_t alignment = heap->intra_heap_alignment();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  // Include any space that is committed but is not in eden.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  size_t available = pointer_delta(eden_space()->bottom(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
                                   virtual_space()->low(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
                                   sizeof(char));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  const size_t eden_capacity = eden_space()->capacity_in_bytes();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  if (eden_space()->is_empty() && eden_capacity > alignment) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
    available += eden_capacity - alignment;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  return available;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
// Similar to PSYoungGen::resize_generation() but
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
//  allows sum of eden_size and 2 * survivor_size to exceed _max_gen_size
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
//  expands at the low end of the virtual space
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
//  moves the boundary between the generations in order to expand
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
//  some additional diagnostics
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
// If no additional changes are required, this can be deleted
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
// and the changes factored back into PSYoungGen::resize_generation().
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
bool ASPSYoungGen::resize_generation(size_t eden_size, size_t survivor_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  const size_t alignment = virtual_space()->alignment();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  size_t orig_size = virtual_space()->committed_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  bool size_changed = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  // There used to be a guarantee here that
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  //   (eden_size + 2*survivor_size)  <= _max_gen_size
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  // This requirement is enforced by the calculation of desired_size
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
  // below.  It may not be true on entry since the size of the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  // eden_size is no bounded by the generation size.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  assert(max_size() == reserved().byte_size(), "max gen size problem?");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  assert(min_gen_size() <= orig_size && orig_size <= max_size(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
         "just checking");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  // Adjust new generation size
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
  const size_t eden_plus_survivors =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
    align_size_up(eden_size + 2 * survivor_size, alignment);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
  size_t desired_size = MAX2(MIN2(eden_plus_survivors, gen_size_limit()),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
                             min_gen_size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  assert(desired_size <= gen_size_limit(), "just checking");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
  if (desired_size > orig_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
    // Grow the generation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
    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
   173
    HeapWord* prev_low = (HeapWord*) virtual_space()->low();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
    if (!virtual_space()->expand_by(change)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
      return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
    }
971
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   177
    if (ZapUnusedHeapArea) {
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   178
      // 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
   179
      // 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
   180
      // spaces have been computed.
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   181
      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
   182
      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
   183
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   184
      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
   185
      SpaceMangler::mangle_region(mangle_region);
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   186
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
    size_changed = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
  } else if (desired_size < orig_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
    size_t desired_change = orig_size - desired_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
    // How much is available for shrinking.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
    size_t available_bytes = limit_gen_shrink(desired_change);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
    size_t change = MIN2(desired_change, available_bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
    virtual_space()->shrink_by(change);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
    size_changed = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
    if (Verbose && PrintGC) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
      if (orig_size == gen_size_limit()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
        gclog_or_tty->print_cr("ASPSYoung generation size at maximum: "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
          SIZE_FORMAT "K", orig_size/K);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
      } else if (orig_size == min_gen_size()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
        gclog_or_tty->print_cr("ASPSYoung generation size at minium: "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
          SIZE_FORMAT "K", orig_size/K);
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
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
  if (size_changed) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
    reset_after_change();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
    if (Verbose && PrintGC) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
      size_t current_size  = virtual_space()->committed_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
      gclog_or_tty->print_cr("ASPSYoung generation size changed: "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
        SIZE_FORMAT "K->" SIZE_FORMAT "K",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
        orig_size/K, current_size/K);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
  guarantee(eden_plus_survivors <= virtual_space()->committed_size() ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
            virtual_space()->committed_size() == max_size(), "Sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
  return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
// Similar to PSYoungGen::resize_spaces() but
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
//  eden always starts at the low end of the committed virtual space
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
//  current implementation does not allow holes between the spaces
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
//  _young_generation_boundary has to be reset because it changes.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
//  so additional verification
971
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   229
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
void ASPSYoungGen::resize_spaces(size_t requested_eden_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
                                 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
   232
  assert(UseAdaptiveSizePolicy, "sanity check");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
  assert(requested_eden_size > 0 && requested_survivor_size > 0,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
         "just checking");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
  space_invariants();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
  // We require eden and to space to be empty
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
  if ((!eden_space()->is_empty()) || (!to_space()->is_empty())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
  if (PrintAdaptiveSizePolicy && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
    gclog_or_tty->print_cr("PSYoungGen::resize_spaces(requested_eden_size: "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
                  SIZE_FORMAT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
                  ", requested_survivor_size: " SIZE_FORMAT ")",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
                  requested_eden_size, requested_survivor_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
    gclog_or_tty->print_cr("    eden: [" PTR_FORMAT ".." PTR_FORMAT ") "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
                  SIZE_FORMAT,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
                  eden_space()->bottom(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
                  eden_space()->end(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
                  pointer_delta(eden_space()->end(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
                                eden_space()->bottom(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
                                sizeof(char)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
    gclog_or_tty->print_cr("    from: [" PTR_FORMAT ".." PTR_FORMAT ") "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
                  SIZE_FORMAT,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
                  from_space()->bottom(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
                  from_space()->end(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
                  pointer_delta(from_space()->end(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
                                from_space()->bottom(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
                                sizeof(char)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
    gclog_or_tty->print_cr("      to: [" PTR_FORMAT ".." PTR_FORMAT ") "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
                  SIZE_FORMAT,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
                  to_space()->bottom(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
                  to_space()->end(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
                  pointer_delta(  to_space()->end(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
                                  to_space()->bottom(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
                                  sizeof(char)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
  // There's nothing to do if the new sizes are the same as the current
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
  if (requested_survivor_size == to_space()->capacity_in_bytes() &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
      requested_survivor_size == from_space()->capacity_in_bytes() &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
      requested_eden_size == eden_space()->capacity_in_bytes()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
    if (PrintAdaptiveSizePolicy && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
      gclog_or_tty->print_cr("    capacities are the right sizes, returning");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
  char* eden_start = (char*)virtual_space()->low();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
  char* eden_end   = (char*)eden_space()->end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
  char* from_start = (char*)from_space()->bottom();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
  char* from_end   = (char*)from_space()->end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
  char* to_start   = (char*)to_space()->bottom();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
  char* to_end     = (char*)to_space()->end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
  assert(eden_start < from_start, "Cannot push into from_space");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
  ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
186
32e6c95f8d9b 6557851: CMS: ergonomics defaults are not set with FLAG_SET_ERGO
jmasa
parents: 1
diff changeset
   291
  const size_t alignment = heap->intra_heap_alignment();
971
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   292
  const bool maintain_minimum =
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   293
    (requested_eden_size + 2 * requested_survivor_size) <= min_gen_size();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
971
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   295
  bool eden_from_to_order = from_start < to_start;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
  // 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
   297
  if (eden_from_to_order) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
    // Eden, from, to
971
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   299
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
    if (PrintAdaptiveSizePolicy && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
      gclog_or_tty->print_cr("  Eden, from, to:");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
    // Set eden
971
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   305
    // "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
   306
    // 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
   307
    // 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
   308
    // 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
   309
    // 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
   310
    // 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
   311
    // 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
   312
    // 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
   313
    size_t eden_size;
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   314
    if (maintain_minimum) {
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   315
      // 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
   316
      // 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
   317
      // 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
   318
      // 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
   319
      // 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
   320
      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
   321
                                eden_start,
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   322
                                sizeof(char));
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   323
    } else {
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   324
      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
   325
                       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
   326
    }
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   327
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
    eden_end = eden_start + eden_size;
5402
c51fd0c1d005 6888953: some calls to function-like macros are missing semicolons
jcoomes
parents: 977
diff changeset
   329
    assert(eden_end >= eden_start, "addition overflowed");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
    // To may resize into from space as long as it is clear of live data.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
    // From space must remain page aligned, though, so we need to do some
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
    // extra calculations.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
    // First calculate an optimal to-space
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
    to_end   = (char*)virtual_space()->high();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
    to_start = (char*)pointer_delta(to_end,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
                                    (char*)requested_survivor_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
                                    sizeof(char));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
    // Does the optimal to-space overlap from-space?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
    if (to_start < (char*)from_space()->end()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
      assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
      // Calculate the minimum offset possible for from_end
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
      size_t from_size =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
        pointer_delta(from_space()->top(), from_start, sizeof(char));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
      // 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
   350
      if (from_size == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
        from_size = alignment;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
        from_size = align_size_up(from_size, alignment);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
      from_end = from_start + from_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
      assert(from_end > from_start, "addition overflow or from_size problem");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
      guarantee(from_end <= (char*)from_space()->end(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
        "from_end moved to the right");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
      // Now update to_start with the new from_end
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
      to_start = MAX2(from_end, to_start);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
    guarantee(to_start != to_end, "to space is zero sized");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
    if (PrintAdaptiveSizePolicy && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
      gclog_or_tty->print_cr("    [eden_start .. eden_end): "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
                    "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
                    eden_start,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
                    eden_end,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
                    pointer_delta(eden_end, eden_start, sizeof(char)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
      gclog_or_tty->print_cr("    [from_start .. from_end): "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
                    "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
                    from_start,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
                    from_end,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
                    pointer_delta(from_end, from_start, sizeof(char)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
      gclog_or_tty->print_cr("    [  to_start ..   to_end): "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
                    "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
                    to_start,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
                    to_end,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
                    pointer_delta(  to_end,   to_start, sizeof(char)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
    // Eden, to, from
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
    if (PrintAdaptiveSizePolicy && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
      gclog_or_tty->print_cr("  Eden, to, from:");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
    // To space gets priority over eden resizing. Note that we position
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
    // to space as if we were able to resize from space, even though from
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
    // space is not modified.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
    // Giving eden priority was tried and gave poorer performance.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
    to_end   = (char*)pointer_delta(virtual_space()->high(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
                                    (char*)requested_survivor_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
                                    sizeof(char));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
    to_end   = MIN2(to_end, from_start);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
    to_start = (char*)pointer_delta(to_end, (char*)requested_survivor_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
                                    sizeof(char));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
    // if the space sizes are to be increased by several times then
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
    // 'to_start' will point beyond the young generation. In this case
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
    // 'to_start' should be adjusted.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
    to_start = MAX2(to_start, eden_start + alignment);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
    // 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
   407
    // 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
   408
    size_t eden_size;
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   409
    if (maintain_minimum) {
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   410
      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
   411
    } else {
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   412
      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
   413
                       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
   414
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
    eden_end = eden_start + eden_size;
5402
c51fd0c1d005 6888953: some calls to function-like macros are missing semicolons
jcoomes
parents: 977
diff changeset
   416
    assert(eden_end >= eden_start, "addition overflowed");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
    // Don't let eden shrink down to 0 or less.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
    eden_end = MAX2(eden_end, eden_start + alignment);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
    to_start = MAX2(to_start, eden_end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
    if (PrintAdaptiveSizePolicy && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
      gclog_or_tty->print_cr("    [eden_start .. eden_end): "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
                    "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
                    eden_start,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
                    eden_end,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
                    pointer_delta(eden_end, eden_start, sizeof(char)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
      gclog_or_tty->print_cr("    [  to_start ..   to_end): "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
                    "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
                    to_start,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
                    to_end,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
                    pointer_delta(  to_end,   to_start, sizeof(char)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
      gclog_or_tty->print_cr("    [from_start .. from_end): "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
                    "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
                    from_start,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
                    from_end,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
                    pointer_delta(from_end, from_start, sizeof(char)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
  guarantee((HeapWord*)from_start <= from_space()->bottom(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
            "from start moved to the right");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
  guarantee((HeapWord*)from_end >= from_space()->top(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
            "from end moved into live data");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
  assert(is_object_aligned((intptr_t)eden_start), "checking alignment");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
  assert(is_object_aligned((intptr_t)from_start), "checking alignment");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
  assert(is_object_aligned((intptr_t)to_start), "checking alignment");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
  MemRegion edenMR((HeapWord*)eden_start, (HeapWord*)eden_end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
  MemRegion toMR  ((HeapWord*)to_start,   (HeapWord*)to_end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
  MemRegion fromMR((HeapWord*)from_start, (HeapWord*)from_end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
  // Let's make sure the call to initialize doesn't reset "top"!
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
  DEBUG_ONLY(HeapWord* old_from_top = from_space()->top();)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
  // For PrintAdaptiveSizePolicy block  below
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
  size_t old_from = from_space()->capacity_in_bytes();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
  size_t old_to   = to_space()->capacity_in_bytes();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
971
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   461
  if (ZapUnusedHeapArea) {
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   462
    // 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
   463
    // 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
   464
    // 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
   465
    // 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
   466
    // spaces and are mangled.
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   467
    if (UseNUMA) {
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   468
      if (eden_from_to_order) {
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   469
        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
   470
      } else {
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   471
        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
   472
      }
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   473
    }
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   474
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   475
    // 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
   476
    // the spaces are already mangled.
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   477
    // 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
   478
    // 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
   479
    // in the calls to initialize().
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   480
    // 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
   481
    // 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
   482
    // 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
   483
    // 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
   484
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   485
    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
   486
    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
   487
    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
   488
      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
   489
  }
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   490
  // 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
   491
  // 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
   492
  eden_space()->initialize(edenMR,
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   493
                           SpaceDecorator::Clear,
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   494
                           SpaceDecorator::DontMangle);
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   495
    to_space()->initialize(toMR,
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   496
                           SpaceDecorator::Clear,
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   497
                           SpaceDecorator::DontMangle);
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   498
  from_space()->initialize(fromMR,
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   499
                           SpaceDecorator::DontClear,
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   500
                           SpaceDecorator::DontMangle);
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   501
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
  PSScavenge::set_young_generation_boundary(eden_space()->bottom());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
  assert(from_space()->top() == old_from_top, "from top changed!");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
  if (PrintAdaptiveSizePolicy) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
    ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
    assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   509
489c9b5090e2 Initial load
duke
parents:
diff changeset
   510
    gclog_or_tty->print("AdaptiveSizePolicy::survivor space sizes: "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   511
                  "collection: %d "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   512
                  "(" SIZE_FORMAT ", " SIZE_FORMAT ") -> "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   513
                  "(" SIZE_FORMAT ", " SIZE_FORMAT ") ",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   514
                  heap->total_collections(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
                  old_from, old_to,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   516
                  from_space()->capacity_in_bytes(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   517
                  to_space()->capacity_in_bytes());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   518
    gclog_or_tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   519
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   520
  space_invariants();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   521
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   522
void ASPSYoungGen::reset_after_change() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   523
  assert_locked_or_safepoint(Heap_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   524
489c9b5090e2 Initial load
duke
parents:
diff changeset
   525
  _reserved = MemRegion((HeapWord*)virtual_space()->low_boundary(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
                        (HeapWord*)virtual_space()->high_boundary());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   527
  PSScavenge::reference_processor()->set_span(_reserved);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   528
489c9b5090e2 Initial load
duke
parents:
diff changeset
   529
  HeapWord* new_eden_bottom = (HeapWord*)virtual_space()->low();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   530
  HeapWord* eden_bottom = eden_space()->bottom();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   531
  if (new_eden_bottom != eden_bottom) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   532
    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
   533
    eden_space()->initialize(eden_mr,
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   534
                             SpaceDecorator::Clear,
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   535
                             SpaceDecorator::Mangle);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   536
    PSScavenge::set_young_generation_boundary(eden_space()->bottom());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   537
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   538
  MemRegion cmr((HeapWord*)virtual_space()->low(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   539
                (HeapWord*)virtual_space()->high());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   540
  Universe::heap()->barrier_set()->resize_covered_region(cmr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   541
489c9b5090e2 Initial load
duke
parents:
diff changeset
   542
  space_invariants();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   543
}