hotspot/src/share/vm/gc_implementation/parallelScavenge/adjoiningGenerations.cpp
author jcoomes
Tue, 30 Sep 2008 11:49:31 -0700
changeset 1406 e5e2b519fc11
parent 1 489c9b5090e2
child 5547 f4b087cbb361
permissions -rw-r--r--
6716466: par compact - remove VerifyParallelOldWithMarkSweep code Reviewed-by: jmasa
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2003 Sun Microsystems, Inc.  All Rights Reserved.
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/_adjoiningGenerations.cpp.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
// If boundary moving is being used, create the young gen and old
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
// gen with ASPSYoungGen and ASPSOldGen, respectively.  Revert to
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
// the old behavior otherwise (with PSYoungGen and PSOldGen).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
AdjoiningGenerations::AdjoiningGenerations(ReservedSpace old_young_rs,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
                                           size_t init_low_byte_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
                                           size_t min_low_byte_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
                                           size_t max_low_byte_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
                                           size_t init_high_byte_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
                                           size_t min_high_byte_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
                                           size_t max_high_byte_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
                                           size_t alignment) :
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  _virtual_spaces(old_young_rs, min_low_byte_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
                  min_high_byte_size, alignment) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  assert(min_low_byte_size <= init_low_byte_size &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
         init_low_byte_size <= max_low_byte_size, "Parameter check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  assert(min_high_byte_size <= init_high_byte_size &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
         init_high_byte_size <= max_high_byte_size, "Parameter check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  // Create the generations differently based on the option to
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  // move the boundary.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  if (UseAdaptiveGCBoundary) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
    // Initialize the adjoining virtual spaces.  Then pass the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
    // a virtual to each generation for initialization of the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
    // generation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
    // Does the actual creation of the virtual spaces
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
    _virtual_spaces.initialize(max_low_byte_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
                               init_low_byte_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
                               init_high_byte_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
    // Place the young gen at the high end.  Passes in the virtual space.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
    _young_gen = new ASPSYoungGen(_virtual_spaces.high(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
                                  _virtual_spaces.high()->committed_size(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
                                  min_high_byte_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
                                  _virtual_spaces.high_byte_size_limit());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
    // Place the old gen at the low end. Passes in the virtual space.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
    _old_gen = new ASPSOldGen(_virtual_spaces.low(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
                              _virtual_spaces.low()->committed_size(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
                              min_low_byte_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
                              _virtual_spaces.low_byte_size_limit(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
                              "old", 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
    young_gen()->initialize_work();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
    assert(young_gen()->reserved().byte_size() <= young_gen()->gen_size_limit(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
     "Consistency check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
    assert(old_young_rs.size() >= young_gen()->gen_size_limit(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
     "Consistency check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
    old_gen()->initialize_work("old", 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
    assert(old_gen()->reserved().byte_size() <= old_gen()->gen_size_limit(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
     "Consistency check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
    assert(old_young_rs.size() >= old_gen()->gen_size_limit(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
     "Consistency check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
    // Layout the reserved space for the generations.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
    ReservedSpace old_rs   =
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
      virtual_spaces()->reserved_space().first_part(max_low_byte_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
    ReservedSpace heap_rs  =
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
      virtual_spaces()->reserved_space().last_part(max_low_byte_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
    ReservedSpace young_rs = heap_rs.first_part(max_high_byte_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
    assert(young_rs.size() == heap_rs.size(), "Didn't reserve all of the heap");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
    // Create the generations.  Virtual spaces are not passed in.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
    _young_gen = new PSYoungGen(init_high_byte_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
                                min_high_byte_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
                                max_high_byte_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
    _old_gen = new PSOldGen(init_low_byte_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
                            min_low_byte_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
                            max_low_byte_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
                            "old", 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
    // The virtual spaces are created by the initialization of the gens.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
    _young_gen->initialize(young_rs, alignment);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
    assert(young_gen()->gen_size_limit() == young_rs.size(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
      "Consistency check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
    _old_gen->initialize(old_rs, alignment, "old", 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
    assert(old_gen()->gen_size_limit() == old_rs.size(), "Consistency check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
size_t AdjoiningGenerations::reserved_byte_size() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  return virtual_spaces()->reserved_space().size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
// Make checks on the current sizes of the generations and
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
// the contraints on the sizes of the generations.  Push
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
// up the boundary within the contraints.  A partial
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
// push can occur.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
void AdjoiningGenerations::request_old_gen_expansion(size_t expand_in_bytes) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  assert(UseAdaptiveSizePolicy && UseAdaptiveGCBoundary, "runtime check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  assert_lock_strong(ExpandHeap_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  assert_locked_or_safepoint(Heap_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  // These sizes limit the amount the boundaries can move.  Effectively,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  // the generation says how much it is willing to yield to the other
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  // generation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  const size_t young_gen_available = young_gen()->available_for_contraction();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  const size_t old_gen_available = old_gen()->available_for_expansion();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  const size_t alignment = virtual_spaces()->alignment();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  size_t change_in_bytes = MIN3(young_gen_available,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
                                old_gen_available,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
                                align_size_up_(expand_in_bytes, alignment));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  if (change_in_bytes == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  if (TraceAdaptiveGCBoundary) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
    gclog_or_tty->print_cr("Before expansion of old gen with boundary move");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
    gclog_or_tty->print_cr("  Requested change: 0x%x  Attempted change: 0x%x",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
      expand_in_bytes, change_in_bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
    if (!PrintHeapAtGC) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
      Universe::print_on(gclog_or_tty);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
    gclog_or_tty->print_cr("  PSOldGen max size: " SIZE_FORMAT "K",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
      old_gen()->max_gen_size()/K);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  // Move the boundary between the generations up (smaller young gen).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  if (virtual_spaces()->adjust_boundary_up(change_in_bytes)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
    young_gen()->reset_after_change();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
    old_gen()->reset_after_change();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
  // The total reserved for the generations should match the sum
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  // of the two even if the boundary is moving.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  assert(reserved_byte_size() ==
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
         old_gen()->max_gen_size() + young_gen()->max_size(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
         "Space is missing");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
  young_gen()->space_invariants();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
  old_gen()->space_invariants();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
  if (TraceAdaptiveGCBoundary) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
    gclog_or_tty->print_cr("After expansion of old gen with boundary move");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
    if (!PrintHeapAtGC) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
      Universe::print_on(gclog_or_tty);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
    gclog_or_tty->print_cr("  PSOldGen max size: " SIZE_FORMAT "K",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
      old_gen()->max_gen_size()/K);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
// See comments on request_old_gen_expansion()
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
bool AdjoiningGenerations::request_young_gen_expansion(size_t expand_in_bytes) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
  assert(UseAdaptiveSizePolicy && UseAdaptiveGCBoundary, "runtime check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
  // If eden is not empty, the boundary can be moved but no advantage
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
  // can be made of the move since eden cannot be moved.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
  if (!young_gen()->eden_space()->is_empty()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
  bool result = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
  const size_t young_gen_available = young_gen()->available_for_expansion();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
  const size_t old_gen_available = old_gen()->available_for_contraction();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
  const size_t alignment = virtual_spaces()->alignment();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
  size_t change_in_bytes = MIN3(young_gen_available,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
                                old_gen_available,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
                                align_size_up_(expand_in_bytes, alignment));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
  if (change_in_bytes == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
  if (TraceAdaptiveGCBoundary) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
    gclog_or_tty->print_cr("Before expansion of young gen with boundary move");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
    gclog_or_tty->print_cr("  Requested change: 0x%x  Attempted change: 0x%x",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
      expand_in_bytes, change_in_bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
    if (!PrintHeapAtGC) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
      Universe::print_on(gclog_or_tty);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
    gclog_or_tty->print_cr("  PSYoungGen max size: " SIZE_FORMAT "K",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
      young_gen()->max_size()/K);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
  // Move the boundary between the generations down (smaller old gen).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
  MutexLocker x(ExpandHeap_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
  if (virtual_spaces()->adjust_boundary_down(change_in_bytes)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
    young_gen()->reset_after_change();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
    old_gen()->reset_after_change();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
    result = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
  // The total reserved for the generations should match the sum
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
  // of the two even if the boundary is moving.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
  assert(reserved_byte_size() ==
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
         old_gen()->max_gen_size() + young_gen()->max_size(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
         "Space is missing");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
  young_gen()->space_invariants();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
  old_gen()->space_invariants();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
  if (TraceAdaptiveGCBoundary) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
    gclog_or_tty->print_cr("After expansion of young gen with boundary move");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
    if (!PrintHeapAtGC) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
      Universe::print_on(gclog_or_tty);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
    gclog_or_tty->print_cr("  PSYoungGen max size: " SIZE_FORMAT "K",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
      young_gen()->max_size()/K);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
  return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
// Additional space is needed in the old generation.  Try to move the boundary
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
// up to meet the need.  Moves boundary up only
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
void AdjoiningGenerations::adjust_boundary_for_old_gen_needs(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
  size_t desired_free_space) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
  assert(UseAdaptiveSizePolicy && UseAdaptiveGCBoundary, "runtime check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
  // Stress testing.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
  if (PSAdaptiveSizePolicyResizeVirtualSpaceAlot == 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
    MutexLocker x(ExpandHeap_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
    request_old_gen_expansion(virtual_spaces()->alignment() * 3 / 2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
  // Expand only if the entire generation is already committed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
  if (old_gen()->virtual_space()->uncommitted_size() == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
    if (old_gen()->free_in_bytes() < desired_free_space) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
      MutexLocker x(ExpandHeap_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
      request_old_gen_expansion(desired_free_space);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
// See comment on adjust_boundary_for_old_gen_needss().
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
// Adjust boundary down only.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
void AdjoiningGenerations::adjust_boundary_for_young_gen_needs(size_t eden_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
    size_t survivor_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
  assert(UseAdaptiveSizePolicy && UseAdaptiveGCBoundary, "runtime check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
  // Stress testing.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
  if (PSAdaptiveSizePolicyResizeVirtualSpaceAlot == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
    request_young_gen_expansion(virtual_spaces()->alignment() * 3 / 2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
    eden_size = young_gen()->eden_space()->capacity_in_bytes();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
  // Expand only if the entire generation is already committed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
  if (young_gen()->virtual_space()->uncommitted_size() == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
    size_t desired_size = eden_size + 2 * survivor_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
    const size_t committed = young_gen()->virtual_space()->committed_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
    if (desired_size > committed) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
      request_young_gen_expansion(desired_size - committed);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
}