hotspot/src/share/vm/gc_implementation/shared/parGCAllocBuffer.cpp
author brutisso
Fri, 28 Nov 2014 08:20:52 +0100
changeset 27899 17754211a7ab
parent 24424 2658d7834c6e
child 29327 b539902e30f8
permissions -rw-r--r--
8066133: Fix missing reivew changes for JDK-8065972 Reviewed-by: mgerdin, stefank
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 24098
diff changeset
     2
 * Copyright (c) 2001, 2014, 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: 2105
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 2105
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: 2105
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"
13466
9fdf353d5f4c 6818524: G1: use ergonomic resizing of PLABs
johnc
parents: 7397
diff changeset
    26
#include "gc_implementation/shared/parGCAllocBuffer.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
#include "memory/sharedHeap.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "oops/arrayOop.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
#include "oops/oop.inline.hpp"
24098
48f07e2c74de 8039957: Replace the last few %p usages with PTR_FORMAT in the GC code
stefank
parents: 24092
diff changeset
    30
#include "utilities/globalDefinitions.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 24098
diff changeset
    32
PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 24098
diff changeset
    33
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
ParGCAllocBuffer::ParGCAllocBuffer(size_t desired_plab_sz_) :
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
  _word_sz(desired_plab_sz_), _bottom(NULL), _top(NULL),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
  _end(NULL), _hard_end(NULL),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
  _retained(false), _retained_filler(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  _allocated(0), _wasted(0)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  assert (min_size() > AlignmentReserve, "Inconsistency!");
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    41
  // arrayOopDesc::header_size depends on command line initialization.
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    42
  FillerHeaderSize = align_object_size(arrayOopDesc::header_size(T_INT));
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    43
  AlignmentReserve = oopDesc::header_size() > MinObjAlignment ? FillerHeaderSize : 0;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    46
size_t ParGCAllocBuffer::FillerHeaderSize;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
// If the minimum object size is greater than MinObjAlignment, we can
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
// end up with a shard at the end of the buffer that's smaller than
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
// the smallest object.  We can't allow that because the buffer must
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
// look like it's full of objects when we retire it, so we make
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
// sure we have enough space for a filler int array object.
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    53
size_t ParGCAllocBuffer::AlignmentReserve;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
void ParGCAllocBuffer::retire(bool end_of_gc, bool retain) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  assert(!retain || end_of_gc, "Can only retain at GC end.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  if (_retained) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
    // If the buffer had been retained shorten the previous filler object.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
    assert(_retained_filler.end() <= _top, "INVARIANT");
1668
8ec481b8f514 6578152: fill_region_with_object has usability and safety issues
jcoomes
parents: 1063
diff changeset
    60
    CollectedHeap::fill_with_object(_retained_filler);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
    // Wasted space book-keeping, otherwise (normally) done in invalidate()
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
    _wasted += _retained_filler.word_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
    _retained = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  assert(!end_of_gc || !_retained, "At this point, end_of_gc ==> !_retained.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  if (_top < _hard_end) {
1668
8ec481b8f514 6578152: fill_region_with_object has usability and safety issues
jcoomes
parents: 1063
diff changeset
    67
    CollectedHeap::fill_with_object(_top, _hard_end);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
    if (!retain) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
      invalidate();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
      // Is there wasted space we'd like to retain for the next GC?
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
      if (pointer_delta(_end, _top) > FillerHeaderSize) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
        _retained = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
        _retained_filler = MemRegion(_top, FillerHeaderSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
        _top = _top + FillerHeaderSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
        invalidate();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
void ParGCAllocBuffer::flush_stats(PLABStats* stats) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  assert(ResizePLAB, "Wasted work");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  stats->add_allocated(_allocated);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  stats->add_wasted(_wasted);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  stats->add_unused(pointer_delta(_end, _top));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
// Compute desired plab size and latch result for later
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
// use. This should be called once at the end of parallel
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
// scavenge; it clears the sensor accumulators.
13926
289339903fcf 8000311: G1: ParallelGCThreads==0 broken
johnc
parents: 13758
diff changeset
    93
void PLABStats::adjust_desired_plab_sz(uint no_of_gc_workers) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  assert(ResizePLAB, "Not set");
22552
a29022212180 8030177: G1: Enable TLAB resizing
brutisso
parents: 22551
diff changeset
    95
a29022212180 8030177: G1: Enable TLAB resizing
brutisso
parents: 22551
diff changeset
    96
  assert(is_object_aligned(max_size()) && min_size() <= max_size(),
a29022212180 8030177: G1: Enable TLAB resizing
brutisso
parents: 22551
diff changeset
    97
         "PLAB clipping computation may be incorrect");
a29022212180 8030177: G1: Enable TLAB resizing
brutisso
parents: 22551
diff changeset
    98
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  if (_allocated == 0) {
13758
692e37683d34 7190666: G1: assert(_unused == 0) failed: Inconsistency in PLAB stats
johnc
parents: 13466
diff changeset
   100
    assert(_unused == 0,
692e37683d34 7190666: G1: assert(_unused == 0) failed: Inconsistency in PLAB stats
johnc
parents: 13466
diff changeset
   101
           err_msg("Inconsistency in PLAB stats: "
692e37683d34 7190666: G1: assert(_unused == 0) failed: Inconsistency in PLAB stats
johnc
parents: 13466
diff changeset
   102
                   "_allocated: "SIZE_FORMAT", "
692e37683d34 7190666: G1: assert(_unused == 0) failed: Inconsistency in PLAB stats
johnc
parents: 13466
diff changeset
   103
                   "_wasted: "SIZE_FORMAT", "
692e37683d34 7190666: G1: assert(_unused == 0) failed: Inconsistency in PLAB stats
johnc
parents: 13466
diff changeset
   104
                   "_unused: "SIZE_FORMAT", "
692e37683d34 7190666: G1: assert(_unused == 0) failed: Inconsistency in PLAB stats
johnc
parents: 13466
diff changeset
   105
                   "_used  : "SIZE_FORMAT,
692e37683d34 7190666: G1: assert(_unused == 0) failed: Inconsistency in PLAB stats
johnc
parents: 13466
diff changeset
   106
                   _allocated, _wasted, _unused, _used));
692e37683d34 7190666: G1: assert(_unused == 0) failed: Inconsistency in PLAB stats
johnc
parents: 13466
diff changeset
   107
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
    _allocated = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  double wasted_frac    = (double)_unused/(double)_allocated;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  size_t target_refills = (size_t)((wasted_frac*TargetSurvivorRatio)/
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
                                   TargetPLABWastePct);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  if (target_refills == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
    target_refills = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  _used = _allocated - _wasted - _unused;
13926
289339903fcf 8000311: G1: ParallelGCThreads==0 broken
johnc
parents: 13758
diff changeset
   117
  size_t plab_sz = _used/(target_refills*no_of_gc_workers);
24092
e274d864545a 8039743: Use correct format specifier to print size_t values and pointers in the GC code
stefank
parents: 22552
diff changeset
   118
  if (PrintPLAB) gclog_or_tty->print(" (plab_sz = " SIZE_FORMAT " ", plab_sz);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  // Take historical weighted average
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  _filter.sample(plab_sz);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  // Clip from above and below, and align to object boundary
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  plab_sz = MAX2(min_size(), (size_t)_filter.average());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  plab_sz = MIN2(max_size(), plab_sz);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  plab_sz = align_object_size(plab_sz);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  // Latch the result
24092
e274d864545a 8039743: Use correct format specifier to print size_t values and pointers in the GC code
stefank
parents: 22552
diff changeset
   126
  if (PrintPLAB) gclog_or_tty->print(" desired_plab_sz = " SIZE_FORMAT ") ", plab_sz);
13466
9fdf353d5f4c 6818524: G1: use ergonomic resizing of PLABs
johnc
parents: 7397
diff changeset
   127
  _desired_plab_sz = plab_sz;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  // Now clear the accumulators for next round:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  // note this needs to be fixed in the case where we
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  // are retaining across scavenges. FIX ME !!! XXX
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  _allocated = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  _wasted    = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  _unused    = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
void ParGCAllocBuffer::print() {
24098
48f07e2c74de 8039957: Replace the last few %p usages with PTR_FORMAT in the GC code
stefank
parents: 24092
diff changeset
   138
  gclog_or_tty->print("parGCAllocBuffer: _bottom: " PTR_FORMAT "  _top: " PTR_FORMAT
48f07e2c74de 8039957: Replace the last few %p usages with PTR_FORMAT in the GC code
stefank
parents: 24092
diff changeset
   139
             "  _end: " PTR_FORMAT "  _hard_end: " PTR_FORMAT " _retained: %c"
48f07e2c74de 8039957: Replace the last few %p usages with PTR_FORMAT in the GC code
stefank
parents: 24092
diff changeset
   140
             " _retained_filler: [" PTR_FORMAT "," PTR_FORMAT ")\n",
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
             _bottom, _top, _end, _hard_end,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
             "FT"[_retained], _retained_filler.start(), _retained_filler.end());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
#endif // !PRODUCT