hotspot/src/share/vm/gc_implementation/parallelScavenge/asPSOldGen.cpp
author tonyp
Thu, 22 Jul 2010 10:27:41 -0400
changeset 6248 2e661807cef0
parent 5547 f4b087cbb361
child 7397 5b173b4ca846
permissions -rw-r--r--
6962589: remove breadth first scanning code from parallel gc Summary: Remove the breadth-first copying order from ParallelScavenge and use depth-first by default. Reviewed-by: jcoomes, ysr, johnc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
     2
 * Copyright (c) 2003, 2006, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
# include "incls/_precompiled.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
# include "incls/_asPSOldGen.cpp.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
// Whereas PSOldGen takes the maximum size of the generation
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
// (which doesn't change in the case of PSOldGen) as a parameter,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
// ASPSOldGen takes the upper limit on the size of
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
// the generation as a parameter.  In ASPSOldGen the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
// maximum size of the generation can change as the boundary
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
// moves.  The "maximum size of the generation" is still a valid
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
// concept since the generation can grow and shrink within that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
// maximum.  There are lots of useful checks that use that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
// maximum.  In PSOldGen the method max_gen_size() returns
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
// _max_gen_size (as set by the PSOldGen constructor).  This
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
// is how it always worked.  In ASPSOldGen max_gen_size()
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
// returned the size of the reserved space for the generation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
// That can change as the boundary moves.  Below the limit of
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
// the size of the generation is passed to the PSOldGen constructor
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
// for "_max_gen_size" (have to pass something) but it is not used later.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
ASPSOldGen::ASPSOldGen(size_t initial_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
                       size_t min_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
                       size_t size_limit,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
                       const char* gen_name,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
                       int level) :
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  PSOldGen(initial_size, min_size, size_limit, gen_name, level),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  _gen_size_limit(size_limit)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
{}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
ASPSOldGen::ASPSOldGen(PSVirtualSpace* vs,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
                       size_t initial_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
                       size_t min_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
                       size_t size_limit,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
                       const char* gen_name,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
                       int level) :
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  PSOldGen(initial_size, min_size, size_limit, gen_name, level),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  _gen_size_limit(size_limit)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  _virtual_space = vs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
void ASPSOldGen::reset_after_change() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  _reserved = MemRegion((HeapWord*)virtual_space()->low_boundary(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
                        (HeapWord*)virtual_space()->high_boundary());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  post_resize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
size_t ASPSOldGen::available_for_expansion() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  assert(virtual_space()->is_aligned(gen_size_limit()), "not aligned");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  assert(gen_size_limit() >= virtual_space()->committed_size(), "bad gen size");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  size_t result =  gen_size_limit() - virtual_space()->committed_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  size_t result_aligned = align_size_down(result, heap->old_gen_alignment());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  return result_aligned;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
size_t ASPSOldGen::available_for_contraction() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  size_t uncommitted_bytes = virtual_space()->uncommitted_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  if (uncommitted_bytes != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
    return uncommitted_bytes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  const size_t gen_alignment = heap->old_gen_alignment();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  PSAdaptiveSizePolicy* policy = heap->size_policy();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  const size_t working_size =
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
    used_in_bytes() + (size_t) policy->avg_promoted()->padded_average();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  const size_t working_aligned = align_size_up(working_size, gen_alignment);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  const size_t working_or_min = MAX2(working_aligned, min_gen_size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  if (working_or_min > reserved().byte_size()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
    // If the used or minimum gen size (aligned up) is greater
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
    // than the total reserved size, then the space available
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
    // for contraction should (after proper alignment) be 0
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
    return 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  const size_t max_contraction =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
    reserved().byte_size() - working_or_min;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  // Use the "increment" fraction instead of the "decrement" fraction
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  // to allow the other gen to expand more aggressively.  The
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  // "decrement" fraction is conservative because its intent is to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  // only reduce the footprint.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  size_t result = policy->promo_increment_aligned_down(max_contraction);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  // Also adjust for inter-generational alignment
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  size_t result_aligned = align_size_down(result, gen_alignment);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  if (PrintAdaptiveSizePolicy && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
    gclog_or_tty->print_cr("\nASPSOldGen::available_for_contraction:"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
      " %d K / 0x%x", result_aligned/K, result_aligned);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
    gclog_or_tty->print_cr(" reserved().byte_size() %d K / 0x%x ",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
      reserved().byte_size()/K, reserved().byte_size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
    size_t working_promoted = (size_t) policy->avg_promoted()->padded_average();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
    gclog_or_tty->print_cr(" padded promoted %d K / 0x%x",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
      working_promoted/K, working_promoted);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
    gclog_or_tty->print_cr(" used %d K / 0x%x",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
      used_in_bytes()/K, used_in_bytes());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
    gclog_or_tty->print_cr(" min_gen_size() %d K / 0x%x",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
      min_gen_size()/K, min_gen_size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
    gclog_or_tty->print_cr(" max_contraction %d K / 0x%x",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
      max_contraction/K, max_contraction);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
    gclog_or_tty->print_cr("    without alignment %d K / 0x%x",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
      policy->promo_increment(max_contraction)/K,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
      policy->promo_increment(max_contraction));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
    gclog_or_tty->print_cr(" alignment 0x%x", gen_alignment);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  assert(result_aligned <= max_contraction, "arithmetic is wrong");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  return result_aligned;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
}