src/hotspot/share/gc/parallel/asPSOldGen.cpp
author eosterlund
Mon, 19 Mar 2018 07:38:18 +0100
changeset 49455 848864ed9b17
parent 47216 71c04702a3d5
child 54678 93f09ca4a7f8
permissions -rw-r--r--
8199604: Rename CardTableModRefBS to CardTableBarrierSet Reviewed-by: stefank, pliden
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
30173
13cf7580b000 8077413: Avoid use of Universe::heap() inside collectors
pliden
parents: 24092
diff changeset
     2
 * Copyright (c) 2003, 2015, 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
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    25
#include "precompiled.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30173
diff changeset
    26
#include "gc/parallel/asPSOldGen.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30173
diff changeset
    27
#include "gc/parallel/parallelScavengeHeap.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30173
diff changeset
    28
#include "gc/parallel/psAdaptiveSizePolicy.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30173
diff changeset
    29
#include "gc/parallel/psMarkSweepDecorator.hpp"
49455
848864ed9b17 8199604: Rename CardTableModRefBS to CardTableBarrierSet
eosterlund
parents: 47216
diff changeset
    30
#include "gc/shared/cardTableBarrierSet.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    31
#include "oops/oop.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    32
#include "runtime/java.hpp"
46625
edefffab74e2 8183552: Move align functions to align.hpp
stefank
parents: 46619
diff changeset
    33
#include "utilities/align.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
// Whereas PSOldGen takes the maximum size of the generation
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
// (which doesn't change in the case of PSOldGen) as a parameter,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
// ASPSOldGen takes the upper limit on the size of
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
// the generation as a parameter.  In ASPSOldGen the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
// maximum size of the generation can change as the boundary
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
// moves.  The "maximum size of the generation" is still a valid
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
// concept since the generation can grow and shrink within that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
// maximum.  There are lots of useful checks that use that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
// maximum.  In PSOldGen the method max_gen_size() returns
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
// _max_gen_size (as set by the PSOldGen constructor).  This
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
// is how it always worked.  In ASPSOldGen max_gen_size()
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
// returned the size of the reserved space for the generation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
// That can change as the boundary moves.  Below the limit of
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
// the size of the generation is passed to the PSOldGen constructor
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
// for "_max_gen_size" (have to pass something) but it is not used later.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
ASPSOldGen::ASPSOldGen(size_t initial_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
                       size_t min_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
                       size_t size_limit,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
                       const char* gen_name,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
                       int level) :
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  PSOldGen(initial_size, min_size, size_limit, gen_name, level),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  _gen_size_limit(size_limit)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
{}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
ASPSOldGen::ASPSOldGen(PSVirtualSpace* vs,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
                       size_t initial_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
                       size_t min_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
                       size_t size_limit,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
                       const char* gen_name,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
                       int level) :
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  PSOldGen(initial_size, min_size, size_limit, gen_name, level),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  _gen_size_limit(size_limit)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  _virtual_space = vs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
18443
ca4b3427b7c7 8014851: UseAdaptiveGCBoundary is broken
jmasa
parents: 7397
diff changeset
    72
void ASPSOldGen::initialize_work(const char* perf_data_name, int level) {
ca4b3427b7c7 8014851: UseAdaptiveGCBoundary is broken
jmasa
parents: 7397
diff changeset
    73
  PSOldGen::initialize_work(perf_data_name, level);
ca4b3427b7c7 8014851: UseAdaptiveGCBoundary is broken
jmasa
parents: 7397
diff changeset
    74
ca4b3427b7c7 8014851: UseAdaptiveGCBoundary is broken
jmasa
parents: 7397
diff changeset
    75
  // The old gen can grow to gen_size_limit().  _reserve reflects only
ca4b3427b7c7 8014851: UseAdaptiveGCBoundary is broken
jmasa
parents: 7397
diff changeset
    76
  // the current maximum that can be committed.
ca4b3427b7c7 8014851: UseAdaptiveGCBoundary is broken
jmasa
parents: 7397
diff changeset
    77
  assert(_reserved.byte_size() <= gen_size_limit(), "Consistency check");
ca4b3427b7c7 8014851: UseAdaptiveGCBoundary is broken
jmasa
parents: 7397
diff changeset
    78
ca4b3427b7c7 8014851: UseAdaptiveGCBoundary is broken
jmasa
parents: 7397
diff changeset
    79
  initialize_performance_counters(perf_data_name, level);
ca4b3427b7c7 8014851: UseAdaptiveGCBoundary is broken
jmasa
parents: 7397
diff changeset
    80
}
ca4b3427b7c7 8014851: UseAdaptiveGCBoundary is broken
jmasa
parents: 7397
diff changeset
    81
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
void ASPSOldGen::reset_after_change() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  _reserved = MemRegion((HeapWord*)virtual_space()->low_boundary(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
                        (HeapWord*)virtual_space()->high_boundary());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  post_resize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
size_t ASPSOldGen::available_for_expansion() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  assert(virtual_space()->is_aligned(gen_size_limit()), "not aligned");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  assert(gen_size_limit() >= virtual_space()->committed_size(), "bad gen size");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
30173
13cf7580b000 8077413: Avoid use of Universe::heap() inside collectors
pliden
parents: 24092
diff changeset
    93
  ParallelScavengeHeap* heap = ParallelScavengeHeap::heap();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  size_t result =  gen_size_limit() - virtual_space()->committed_size();
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 37242
diff changeset
    95
  size_t result_aligned = align_down(result, heap->generation_alignment());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  return result_aligned;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
size_t ASPSOldGen::available_for_contraction() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  size_t uncommitted_bytes = virtual_space()->uncommitted_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  if (uncommitted_bytes != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
    return uncommitted_bytes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
30173
13cf7580b000 8077413: Avoid use of Universe::heap() inside collectors
pliden
parents: 24092
diff changeset
   105
  ParallelScavengeHeap* heap = ParallelScavengeHeap::heap();
21561
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents: 21560
diff changeset
   106
  const size_t gen_alignment = heap->generation_alignment();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  PSAdaptiveSizePolicy* policy = heap->size_policy();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  const size_t working_size =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
    used_in_bytes() + (size_t) policy->avg_promoted()->padded_average();
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 37242
diff changeset
   110
  const size_t working_aligned = align_up(working_size, gen_alignment);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  const size_t working_or_min = MAX2(working_aligned, min_gen_size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  if (working_or_min > reserved().byte_size()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
    // If the used or minimum gen size (aligned up) is greater
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
    // than the total reserved size, then the space available
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
    // for contraction should (after proper alignment) be 0
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
    return 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  const size_t max_contraction =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
    reserved().byte_size() - working_or_min;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  // Use the "increment" fraction instead of the "decrement" fraction
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  // to allow the other gen to expand more aggressively.  The
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  // "decrement" fraction is conservative because its intent is to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  // only reduce the footprint.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  size_t result = policy->promo_increment_aligned_down(max_contraction);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  // Also adjust for inter-generational alignment
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 37242
diff changeset
   128
  size_t result_aligned = align_down(result, gen_alignment);
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   129
37242
91e5f98fff6f 8152632: Rename LogHandle(...) to Log(...)
stefank
parents: 35061
diff changeset
   130
  Log(gc, ergo) log;
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   131
  if (log.is_trace()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
    size_t working_promoted = (size_t) policy->avg_promoted()->padded_average();
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   133
    size_t promo_increment = policy->promo_increment(max_contraction);
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   134
    log.trace("ASPSOldGen::available_for_contraction: " SIZE_FORMAT " K / " SIZE_FORMAT_HEX, result_aligned/K, result_aligned);
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   135
    log.trace(" reserved().byte_size() " SIZE_FORMAT " K / " SIZE_FORMAT_HEX, reserved().byte_size()/K, reserved().byte_size());
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   136
    log.trace(" padded promoted " SIZE_FORMAT " K / " SIZE_FORMAT_HEX, working_promoted/K, working_promoted);
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   137
    log.trace(" used " SIZE_FORMAT " K / " SIZE_FORMAT_HEX, used_in_bytes()/K, used_in_bytes());
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   138
    log.trace(" min_gen_size() " SIZE_FORMAT " K / " SIZE_FORMAT_HEX, min_gen_size()/K, min_gen_size());
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   139
    log.trace(" max_contraction " SIZE_FORMAT " K / " SIZE_FORMAT_HEX, max_contraction/K, max_contraction);
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   140
    log.trace("    without alignment " SIZE_FORMAT " K / " SIZE_FORMAT_HEX, promo_increment/K, promo_increment);
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   141
    log.trace(" alignment " SIZE_FORMAT_HEX, gen_alignment);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  }
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   143
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  assert(result_aligned <= max_contraction, "arithmetic is wrong");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  return result_aligned;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
}