hotspot/src/share/vm/gc_implementation/parNew/asParNewGeneration.cpp
author jcoomes
Thu, 11 Dec 2008 12:05:08 -0800
changeset 1668 8ec481b8f514
parent 977 b90650e2a9f7
child 5402 c51fd0c1d005
permissions -rw-r--r--
6578152: fill_region_with_object has usability and safety issues Reviewed-by: apetrusenko, ysr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
670
ddf3e9583f2f 6719955: Update copyright year
xdono
parents: 186
diff changeset
     2
 * Copyright 2005-2008 Sun Microsystems, Inc.  All Rights Reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
# include "incls/_precompiled.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
# include "incls/_asParNewGeneration.cpp.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
ASParNewGeneration::ASParNewGeneration(ReservedSpace rs,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
                                       size_t initial_byte_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
                                       size_t min_byte_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
                                       int level) :
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
  ParNewGeneration(rs, initial_byte_size, level),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
  _min_gen_size(min_byte_size) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
const char* ASParNewGeneration::name() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
  return "adaptive size par new generation";
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
void ASParNewGeneration::adjust_desired_tenuring_threshold() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  assert(UseAdaptiveSizePolicy,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
    "Should only be used with UseAdaptiveSizePolicy");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
void ASParNewGeneration::resize(size_t eden_size, size_t survivor_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  // Resize the generation if needed. If the generation resize
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  // reports false, do not attempt to resize the spaces.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  if (resize_generation(eden_size, survivor_size)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
    // Then we lay out the spaces inside the generation
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
    resize_spaces(eden_size, survivor_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
    space_invariants();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
    if (PrintAdaptiveSizePolicy && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
      gclog_or_tty->print_cr("Young generation size: "
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
        "desired eden: " SIZE_FORMAT " survivor: " SIZE_FORMAT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
        " used: " SIZE_FORMAT " capacity: " SIZE_FORMAT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
        " gen limits: " SIZE_FORMAT " / " SIZE_FORMAT,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
        eden_size, survivor_size, used(), capacity(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
        max_gen_size(), min_gen_size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  }
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 ASParNewGeneration::available_to_min_gen() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  assert(virtual_space()->committed_size() >= min_gen_size(), "Invariant");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  return virtual_space()->committed_size() - min_gen_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
// This method assumes that from-space has live data and that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
// any shrinkage of the young gen is limited by location of
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
// from-space.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
size_t ASParNewGeneration::available_to_live() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
#undef SHRINKS_AT_END_OF_EDEN
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
#ifdef SHRINKS_AT_END_OF_EDEN
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  size_t delta_in_survivor = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
186
32e6c95f8d9b 6557851: CMS: ergonomics defaults are not set with FLAG_SET_ERGO
jmasa
parents: 1
diff changeset
    77
  const size_t space_alignment = heap->intra_heap_alignment();
32e6c95f8d9b 6557851: CMS: ergonomics defaults are not set with FLAG_SET_ERGO
jmasa
parents: 1
diff changeset
    78
  const size_t gen_alignment = heap->object_heap_alignment();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  MutableSpace* space_shrinking = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  if (from_space()->end() > to_space()->end()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
    space_shrinking = from_space();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
    space_shrinking = to_space();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  // Include any space that is committed but not included in
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  // the survivor spaces.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  assert(((HeapWord*)virtual_space()->high()) >= space_shrinking->end(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
    "Survivor space beyond high end");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  size_t unused_committed = pointer_delta(virtual_space()->high(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
    space_shrinking->end(), sizeof(char));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  if (space_shrinking->is_empty()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
    // Don't let the space shrink to 0
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
    assert(space_shrinking->capacity_in_bytes() >= space_alignment,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
      "Space is too small");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
    delta_in_survivor = space_shrinking->capacity_in_bytes() - space_alignment;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
    delta_in_survivor = pointer_delta(space_shrinking->end(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
                                      space_shrinking->top(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
                                      sizeof(char));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  size_t delta_in_bytes = unused_committed + delta_in_survivor;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  delta_in_bytes = align_size_down(delta_in_bytes, gen_alignment);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  return delta_in_bytes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  // The only space available for shrinking is in to-space if it
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  // is above from-space.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  if (to()->bottom() > from()->bottom()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
    const size_t alignment = os::vm_page_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
    if (to()->capacity() < alignment) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
      return 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
      return to()->capacity() - alignment;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  } else {
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
#endif
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 the number of bytes available for resizing down the young
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
// generation.  This is the minimum of
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
//      input "bytes"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
//      bytes to the minimum young gen size
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
//      bytes to the size currently being used + some small extra
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
size_t ASParNewGeneration::limit_gen_shrink (size_t bytes) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  // Allow shrinkage into the current eden but keep eden large enough
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  // to maintain the minimum young gen size
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  bytes = MIN3(bytes, available_to_min_gen(), available_to_live());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  return align_size_down(bytes, os::vm_page_size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
// Note that the the alignment used is the OS page size as
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
// opposed to an alignment associated with the virtual space
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
// (as is done in the ASPSYoungGen/ASPSOldGen)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
bool ASParNewGeneration::resize_generation(size_t eden_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
                                           size_t survivor_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  const size_t alignment = os::vm_page_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  size_t orig_size = virtual_space()->committed_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  bool size_changed = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  // There used to be this guarantee there.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  // guarantee ((eden_size + 2*survivor_size)  <= _max_gen_size, "incorrect input arguments");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  // Code below forces this requirement.  In addition the desired eden
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  // size and disired survivor sizes are desired goals and may
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  // exceed the total generation size.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  assert(min_gen_size() <= orig_size && orig_size <= max_gen_size(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
    "just checking");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  // Adjust new generation size
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  const size_t eden_plus_survivors =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
          align_size_up(eden_size + 2 * survivor_size, alignment);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  size_t desired_size = MAX2(MIN2(eden_plus_survivors, max_gen_size()),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
                             min_gen_size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  assert(desired_size <= max_gen_size(), "just checking");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
  if (desired_size > orig_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
    // Grow the generation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
    size_t change = desired_size - orig_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
    assert(change % alignment == 0, "just checking");
971
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   165
    if (expand(change)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
      return false; // Error if we fail to resize!
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
    size_changed = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  } else if (desired_size < orig_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
    size_t desired_change = orig_size - desired_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
    assert(desired_change % alignment == 0, "just checking");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
    desired_change = limit_gen_shrink(desired_change);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
    if (desired_change > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
      virtual_space()->shrink_by(desired_change);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
      reset_survivors_after_shrink();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
      size_changed = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
    if (Verbose && PrintGC) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
      if (orig_size == max_gen_size()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
        gclog_or_tty->print_cr("ASParNew generation size at maximum: "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
          SIZE_FORMAT "K", orig_size/K);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
      } else if (orig_size == min_gen_size()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
        gclog_or_tty->print_cr("ASParNew generation size at minium: "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
          SIZE_FORMAT "K", orig_size/K);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
  if (size_changed) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
    MemRegion cmr((HeapWord*)virtual_space()->low(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
                  (HeapWord*)virtual_space()->high());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
    GenCollectedHeap::heap()->barrier_set()->resize_covered_region(cmr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
    if (Verbose && PrintGC) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
      size_t current_size  = virtual_space()->committed_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
      gclog_or_tty->print_cr("ASParNew generation size changed: "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
                             SIZE_FORMAT "K->" SIZE_FORMAT "K",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
                             orig_size/K, current_size/K);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
  guarantee(eden_plus_survivors <= virtual_space()->committed_size() ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
            virtual_space()->committed_size() == max_gen_size(), "Sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
  return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
void ASParNewGeneration::reset_survivors_after_shrink() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
  GenCollectedHeap* gch = GenCollectedHeap::heap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
  HeapWord* new_end = (HeapWord*)virtual_space()->high();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
  if (from()->end() > to()->end()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
    assert(new_end >= from()->end(), "Shrinking past from-space");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
    assert(new_end >= to()->bottom(), "Shrink was too large");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
    // Was there a shrink of the survivor space?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
    if (new_end < to()->end()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
      MemRegion mr(to()->bottom(), new_end);
971
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   224
      to()->initialize(mr,
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   225
                       SpaceDecorator::DontClear,
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   226
                       SpaceDecorator::DontMangle);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
void ASParNewGeneration::resize_spaces(size_t requested_eden_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
                                       size_t requested_survivor_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
  assert(UseAdaptiveSizePolicy, "sanity check");
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
  CollectedHeap* heap = Universe::heap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
  assert(heap->kind() == CollectedHeap::GenCollectedHeap, "Sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
  // We require eden and to space to be empty
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
  if ((!eden()->is_empty()) || (!to()->is_empty())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
  size_t cur_eden_size = eden()->capacity();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
  if (PrintAdaptiveSizePolicy && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
    gclog_or_tty->print_cr("ASParNew::resize_spaces(requested_eden_size: "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
                  SIZE_FORMAT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
                  ", requested_survivor_size: " SIZE_FORMAT ")",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
                  requested_eden_size, requested_survivor_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
    gclog_or_tty->print_cr("    eden: [" PTR_FORMAT ".." PTR_FORMAT ") "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
                  SIZE_FORMAT,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
                  eden()->bottom(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
                  eden()->end(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
                  pointer_delta(eden()->end(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
                                eden()->bottom(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
                                sizeof(char)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
    gclog_or_tty->print_cr("    from: [" PTR_FORMAT ".." PTR_FORMAT ") "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
                  SIZE_FORMAT,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
                  from()->bottom(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
                  from()->end(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
                  pointer_delta(from()->end(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
                                from()->bottom(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
                                sizeof(char)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
    gclog_or_tty->print_cr("      to: [" PTR_FORMAT ".." PTR_FORMAT ") "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
                  SIZE_FORMAT,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
                  to()->bottom(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
                  to()->end(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
                  pointer_delta(  to()->end(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
                                  to()->bottom(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
                                  sizeof(char)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
  // There's nothing to do if the new sizes are the same as the current
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
  if (requested_survivor_size == to()->capacity() &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
      requested_survivor_size == from()->capacity() &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
      requested_eden_size == eden()->capacity()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
    if (PrintAdaptiveSizePolicy && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
      gclog_or_tty->print_cr("    capacities are the right sizes, returning");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
  char* eden_start = (char*)eden()->bottom();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
  char* eden_end   = (char*)eden()->end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
  char* from_start = (char*)from()->bottom();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
  char* from_end   = (char*)from()->end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
  char* to_start   = (char*)to()->bottom();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
  char* to_end     = (char*)to()->end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
  const size_t alignment = os::vm_page_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
  const bool maintain_minimum =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
    (requested_eden_size + 2 * requested_survivor_size) <= min_gen_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
  // Check whether from space is below to space
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
  if (from_start < to_start) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
    // Eden, from, to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
    if (PrintAdaptiveSizePolicy && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
      gclog_or_tty->print_cr("  Eden, from, to:");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
    // Set eden
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
    // "requested_eden_size" is a goal for the size of eden
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
    // and may not be attainable.  "eden_size" below is
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
    // calculated based on the location of from-space and
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
    // the goal for the size of eden.  from-space is
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
    // fixed in place because it contains live data.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
    // The calculation is done this way to avoid 32bit
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
    // overflow (i.e., eden_start + requested_eden_size
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
    // may too large for representation in 32bits).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
    size_t eden_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
    if (maintain_minimum) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
      // Only make eden larger than the requested size if
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
      // the minimum size of the generation has to be maintained.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
      // This could be done in general but policy at a higher
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
      // level is determining a requested size for eden and that
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
      // should be honored unless there is a fundamental reason.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
      eden_size = pointer_delta(from_start,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
                                eden_start,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
                                sizeof(char));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
      eden_size = MIN2(requested_eden_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
                       pointer_delta(from_start, eden_start, sizeof(char)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
    eden_size = align_size_down(eden_size, alignment);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
    eden_end = eden_start + eden_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
    assert(eden_end >= eden_start, "addition overflowed")
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
    // To may resize into from space as long as it is clear of live data.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
    // From space must remain page aligned, though, so we need to do some
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
    // extra calculations.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
    // First calculate an optimal to-space
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
    to_end   = (char*)virtual_space()->high();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
    to_start = (char*)pointer_delta(to_end, (char*)requested_survivor_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
                                    sizeof(char));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
    // Does the optimal to-space overlap from-space?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
    if (to_start < (char*)from()->end()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
      // Calculate the minimum offset possible for from_end
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
      size_t from_size = pointer_delta(from()->top(), from_start, sizeof(char));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
      // 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
   345
      if (from_size == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
        from_size = alignment;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
        from_size = align_size_up(from_size, alignment);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
      from_end = from_start + from_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
      assert(from_end > from_start, "addition overflow or from_size problem");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
      guarantee(from_end <= (char*)from()->end(), "from_end moved to the right");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
      // Now update to_start with the new from_end
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
      to_start = MAX2(from_end, to_start);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
      // If shrinking, move to-space down to abut the end of from-space
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
      // so that shrinking will move to-space down.  If not shrinking
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
      // to-space is moving up to allow for growth on the next expansion.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
      if (requested_eden_size <= cur_eden_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
        to_start = from_end;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
        if (to_start + requested_survivor_size > to_start) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
          to_end = to_start + requested_survivor_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
      // else leave to_end pointing to the high end of the virtual space.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
    guarantee(to_start != to_end, "to space is zero sized");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
    if (PrintAdaptiveSizePolicy && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
      gclog_or_tty->print_cr("    [eden_start .. eden_end): "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
                    "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
                    eden_start,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
                    eden_end,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
                    pointer_delta(eden_end, eden_start, sizeof(char)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
      gclog_or_tty->print_cr("    [from_start .. from_end): "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
                    "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
                    from_start,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
                    from_end,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
                    pointer_delta(from_end, from_start, sizeof(char)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
      gclog_or_tty->print_cr("    [  to_start ..   to_end): "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
                    "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
                    to_start,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
                    to_end,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
                    pointer_delta(  to_end,   to_start, sizeof(char)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
    // Eden, to, from
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
    if (PrintAdaptiveSizePolicy && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
      gclog_or_tty->print_cr("  Eden, to, from:");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
    // Calculate the to-space boundaries based on
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
    // the start of from-space.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
    to_end = from_start;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
    to_start = (char*)pointer_delta(from_start,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
                                    (char*)requested_survivor_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
                                    sizeof(char));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
    // Calculate the ideal eden boundaries.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
    // eden_end is already at the bottom of the generation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
    assert(eden_start == virtual_space()->low(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
      "Eden is not starting at the low end of the virtual space");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
    if (eden_start + requested_eden_size >= eden_start) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
      eden_end = eden_start + requested_eden_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
      eden_end = to_start;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
    // Does eden intrude into to-space?  to-space
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
    // gets priority but eden is not allowed to shrink
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
    // to 0.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
    if (eden_end > to_start) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
      eden_end = to_start;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
    // Don't let eden shrink down to 0 or less.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
    eden_end = MAX2(eden_end, eden_start + alignment);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
    assert(eden_start + alignment >= eden_start, "Overflow");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
    size_t eden_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
    if (maintain_minimum) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
      // Use all the space available.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
      eden_end = MAX2(eden_end, to_start);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
      eden_size = pointer_delta(eden_end, eden_start, sizeof(char));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
      eden_size = MIN2(eden_size, cur_eden_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
      eden_size = pointer_delta(eden_end, eden_start, sizeof(char));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
    eden_size = align_size_down(eden_size, alignment);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
    assert(maintain_minimum || eden_size <= requested_eden_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
      "Eden size is too large");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
    assert(eden_size >= alignment, "Eden size is too small");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
    eden_end = eden_start + eden_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
    // Move to-space down to eden.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
    if (requested_eden_size < cur_eden_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
      to_start = eden_end;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
      if (to_start + requested_survivor_size > to_start) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
        to_end = MIN2(from_start, to_start + requested_survivor_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
        to_end = from_start;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
    // eden_end may have moved so again make sure
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
    // the to-space and eden don't overlap.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
    to_start = MAX2(eden_end, to_start);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
    // from-space
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
    size_t from_used = from()->used();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
    if (requested_survivor_size > from_used) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
      if (from_start + requested_survivor_size >= from_start) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
        from_end = from_start + requested_survivor_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
      if (from_end > virtual_space()->high()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
        from_end = virtual_space()->high();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
    assert(to_start >= eden_end, "to-space should be above eden");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
    if (PrintAdaptiveSizePolicy && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
      gclog_or_tty->print_cr("    [eden_start .. eden_end): "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
                    "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
                    eden_start,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
                    eden_end,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
                    pointer_delta(eden_end, eden_start, sizeof(char)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
      gclog_or_tty->print_cr("    [  to_start ..   to_end): "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
                    "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
                    to_start,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
                    to_end,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
                    pointer_delta(  to_end,   to_start, sizeof(char)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
      gclog_or_tty->print_cr("    [from_start .. from_end): "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
                    "[" PTR_FORMAT " .. " PTR_FORMAT ") " SIZE_FORMAT,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
                    from_start,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
                    from_end,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
                    pointer_delta(from_end, from_start, sizeof(char)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
  guarantee((HeapWord*)from_start <= from()->bottom(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
            "from start moved to the right");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
  guarantee((HeapWord*)from_end >= from()->top(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
            "from end moved into live data");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
  assert(is_object_aligned((intptr_t)eden_start), "checking alignment");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
  assert(is_object_aligned((intptr_t)from_start), "checking alignment");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
  assert(is_object_aligned((intptr_t)to_start), "checking alignment");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
  MemRegion edenMR((HeapWord*)eden_start, (HeapWord*)eden_end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
  MemRegion toMR  ((HeapWord*)to_start,   (HeapWord*)to_end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
  MemRegion fromMR((HeapWord*)from_start, (HeapWord*)from_end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
  // Let's make sure the call to initialize doesn't reset "top"!
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
  HeapWord* old_from_top = from()->top();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
  // For PrintAdaptiveSizePolicy block  below
489c9b5090e2 Initial load
duke
parents:
diff changeset
   500
  size_t old_from = from()->capacity();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
  size_t old_to   = to()->capacity();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
971
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   503
  // If not clearing 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
   504
  // the spaces are already mangled.
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   505
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   506
  // 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
   507
  // the bottom or end of one space may have moved into another
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   508
  // a failure of the check may not correctly indicate which space
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   509
  // is not properly mangled.
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   510
  if (ZapUnusedHeapArea) {
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   511
    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
   512
    eden()->check_mangled_unused_area(limit);
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   513
    from()->check_mangled_unused_area(limit);
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   514
      to()->check_mangled_unused_area(limit);
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   515
  }
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   516
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   517
  // The call to initialize NULL's the next compaction space
971
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   518
  eden()->initialize(edenMR,
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   519
                     SpaceDecorator::Clear,
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   520
                     SpaceDecorator::DontMangle);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   521
  eden()->set_next_compaction_space(from());
971
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   522
    to()->initialize(toMR  ,
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   523
                     SpaceDecorator::Clear,
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   524
                     SpaceDecorator::DontMangle);
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   525
  from()->initialize(fromMR,
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   526
                     SpaceDecorator::DontClear,
f0b20be4165d 6672698: mangle_unused_area() should not remangle the entire heap at each collection.
jmasa
parents: 186
diff changeset
   527
                     SpaceDecorator::DontMangle);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   528
489c9b5090e2 Initial load
duke
parents:
diff changeset
   529
  assert(from()->top() == old_from_top, "from top changed!");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   530
489c9b5090e2 Initial load
duke
parents:
diff changeset
   531
  if (PrintAdaptiveSizePolicy) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   532
    GenCollectedHeap* gch = GenCollectedHeap::heap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   533
    assert(gch->kind() == CollectedHeap::GenCollectedHeap, "Sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   534
489c9b5090e2 Initial load
duke
parents:
diff changeset
   535
    gclog_or_tty->print("AdaptiveSizePolicy::survivor space sizes: "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   536
                  "collection: %d "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   537
                  "(" SIZE_FORMAT ", " SIZE_FORMAT ") -> "
489c9b5090e2 Initial load
duke
parents:
diff changeset
   538
                  "(" SIZE_FORMAT ", " SIZE_FORMAT ") ",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   539
                  gch->total_collections(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   540
                  old_from, old_to,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   541
                  from()->capacity(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   542
                  to()->capacity());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   543
    gclog_or_tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   544
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   545
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   546
489c9b5090e2 Initial load
duke
parents:
diff changeset
   547
void ASParNewGeneration::compute_new_size() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   548
  GenCollectedHeap* gch = GenCollectedHeap::heap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   549
  assert(gch->kind() == CollectedHeap::GenCollectedHeap,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   550
    "not a CMS generational heap");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   551
489c9b5090e2 Initial load
duke
parents:
diff changeset
   552
489c9b5090e2 Initial load
duke
parents:
diff changeset
   553
  CMSAdaptiveSizePolicy* size_policy =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   554
    (CMSAdaptiveSizePolicy*)gch->gen_policy()->size_policy();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   555
  assert(size_policy->is_gc_cms_adaptive_size_policy(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   556
    "Wrong type of size policy");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   557
489c9b5090e2 Initial load
duke
parents:
diff changeset
   558
  size_t survived = from()->used();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   559
  if (!survivor_overflow()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   560
    // Keep running averages on how much survived
489c9b5090e2 Initial load
duke
parents:
diff changeset
   561
    size_policy->avg_survived()->sample(survived);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   562
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   563
    size_t promoted =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   564
      (size_t) next_gen()->gc_stats()->avg_promoted()->last_sample();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   565
    assert(promoted < gch->capacity(), "Conversion problem?");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   566
    size_t survived_guess = survived + promoted;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   567
    size_policy->avg_survived()->sample(survived_guess);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   568
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   569
489c9b5090e2 Initial load
duke
parents:
diff changeset
   570
  size_t survivor_limit = max_survivor_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   571
  _tenuring_threshold =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   572
    size_policy->compute_survivor_space_size_and_threshold(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   573
                                                     _survivor_overflow,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   574
                                                     _tenuring_threshold,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   575
                                                     survivor_limit);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   576
  size_policy->avg_young_live()->sample(used());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   577
  size_policy->avg_eden_live()->sample(eden()->used());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   578
489c9b5090e2 Initial load
duke
parents:
diff changeset
   579
  size_policy->compute_young_generation_free_space(eden()->capacity(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   580
                                                   max_gen_size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   581
489c9b5090e2 Initial load
duke
parents:
diff changeset
   582
  resize(size_policy->calculated_eden_size_in_bytes(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   583
         size_policy->calculated_survivor_size_in_bytes());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   584
489c9b5090e2 Initial load
duke
parents:
diff changeset
   585
  if (UsePerfData) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   586
    CMSGCAdaptivePolicyCounters* counters =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   587
      (CMSGCAdaptivePolicyCounters*) gch->collector_policy()->counters();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   588
    assert(counters->kind() ==
489c9b5090e2 Initial load
duke
parents:
diff changeset
   589
           GCPolicyCounters::CMSGCAdaptivePolicyCountersKind,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   590
      "Wrong kind of counters");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   591
    counters->update_tenuring_threshold(_tenuring_threshold);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   592
    counters->update_survivor_overflowed(_survivor_overflow);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   593
    counters->update_young_capacity(capacity());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   594
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   595
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   596
489c9b5090e2 Initial load
duke
parents:
diff changeset
   597
489c9b5090e2 Initial load
duke
parents:
diff changeset
   598
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   599
// Changes from PSYoungGen version
489c9b5090e2 Initial load
duke
parents:
diff changeset
   600
//      value of "alignment"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   601
void ASParNewGeneration::space_invariants() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   602
  const size_t alignment = os::vm_page_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   603
489c9b5090e2 Initial load
duke
parents:
diff changeset
   604
  // Currently, our eden size cannot shrink to zero
489c9b5090e2 Initial load
duke
parents:
diff changeset
   605
  guarantee(eden()->capacity() >= alignment, "eden too small");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   606
  guarantee(from()->capacity() >= alignment, "from too small");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   607
  guarantee(to()->capacity() >= alignment, "to too small");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   608
489c9b5090e2 Initial load
duke
parents:
diff changeset
   609
  // Relationship of spaces to each other
489c9b5090e2 Initial load
duke
parents:
diff changeset
   610
  char* eden_start = (char*)eden()->bottom();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   611
  char* eden_end   = (char*)eden()->end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   612
  char* from_start = (char*)from()->bottom();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   613
  char* from_end   = (char*)from()->end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   614
  char* to_start   = (char*)to()->bottom();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   615
  char* to_end     = (char*)to()->end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   616
489c9b5090e2 Initial load
duke
parents:
diff changeset
   617
  guarantee(eden_start >= virtual_space()->low(), "eden bottom");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   618
  guarantee(eden_start < eden_end, "eden space consistency");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   619
  guarantee(from_start < from_end, "from space consistency");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   620
  guarantee(to_start < to_end, "to space consistency");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   621
489c9b5090e2 Initial load
duke
parents:
diff changeset
   622
  // Check whether from space is below to space
489c9b5090e2 Initial load
duke
parents:
diff changeset
   623
  if (from_start < to_start) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   624
    // Eden, from, to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   625
    guarantee(eden_end <= from_start, "eden/from boundary");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   626
    guarantee(from_end <= to_start,   "from/to boundary");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   627
    guarantee(to_end <= virtual_space()->high(), "to end");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   628
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   629
    // Eden, to, from
489c9b5090e2 Initial load
duke
parents:
diff changeset
   630
    guarantee(eden_end <= to_start, "eden/to boundary");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   631
    guarantee(to_end <= from_start, "to/from boundary");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   632
    guarantee(from_end <= virtual_space()->high(), "from end");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   633
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   634
489c9b5090e2 Initial load
duke
parents:
diff changeset
   635
  // More checks that the virtual space is consistent with the spaces
489c9b5090e2 Initial load
duke
parents:
diff changeset
   636
  assert(virtual_space()->committed_size() >=
489c9b5090e2 Initial load
duke
parents:
diff changeset
   637
    (eden()->capacity() +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   638
     to()->capacity() +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   639
     from()->capacity()), "Committed size is inconsistent");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   640
  assert(virtual_space()->committed_size() <= virtual_space()->reserved_size(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   641
    "Space invariant");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   642
  char* eden_top = (char*)eden()->top();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   643
  char* from_top = (char*)from()->top();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   644
  char* to_top = (char*)to()->top();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   645
  assert(eden_top <= virtual_space()->high(), "eden top");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   646
  assert(from_top <= virtual_space()->high(), "from top");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   647
  assert(to_top <= virtual_space()->high(), "to top");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   648
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   649
#endif