hotspot/src/share/vm/gc/shared/plab.cpp
author aharlap
Thu, 23 Feb 2017 12:50:49 -0500
changeset 46290 3c4c1591507d
parent 37068 fd8357c31be4
child 46618 d503911aa948
permissions -rw-r--r--
8151045: Remove code duplication in PLABStats/G1EvacStats::adjust_desired_plab_sz Summary: Move class specific code to the helper method Reviewed-by: kbarrett, tschatzl
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
30275
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
     1
/*
46290
3c4c1591507d 8151045: Remove code duplication in PLABStats/G1EvacStats::adjust_desired_plab_sz
aharlap
parents: 37068
diff changeset
     2
 * Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved.
30275
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
     4
 *
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
     7
 * published by the Free Software Foundation.
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
     8
 *
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    13
 * accompanied this code).
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    14
 *
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    18
 *
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    21
 * questions.
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    22
 *
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    23
 */
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    24
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    25
#include "precompiled.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30586
diff changeset
    26
#include "gc/shared/collectedHeap.hpp"
32378
8dd0e7359751 8133470: Uses of Atomic methods in plab.hpp should be moved to .inline.hpp file
tschatzl
parents: 31632
diff changeset
    27
#include "gc/shared/plab.inline.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30586
diff changeset
    28
#include "gc/shared/threadLocalAllocBuffer.hpp"
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33105
diff changeset
    29
#include "logging/log.hpp"
30275
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    30
#include "oops/arrayOop.hpp"
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    31
#include "oops/oop.inline.hpp"
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    32
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    33
size_t PLAB::min_size() {
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    34
  // Make sure that we return something that is larger than AlignmentReserve
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    35
  return align_object_size(MAX2(MinTLABSize / HeapWordSize, (uintx)oopDesc::header_size())) + AlignmentReserve;
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    36
}
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    37
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    38
size_t PLAB::max_size() {
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    39
  return ThreadLocalAllocBuffer::max_size();
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    40
}
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    41
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    42
PLAB::PLAB(size_t desired_plab_sz_) :
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    43
  _word_sz(desired_plab_sz_), _bottom(NULL), _top(NULL),
30564
a37d98a1eb54 8071462: Remove G1ParGCAllocator::alloc_buffer_waste
tschatzl
parents: 30276
diff changeset
    44
  _end(NULL), _hard_end(NULL), _allocated(0), _wasted(0), _undo_wasted(0)
30275
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    45
{
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    46
  // ArrayOopDesc::header_size depends on command line initialization.
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    47
  AlignmentReserve = oopDesc::header_size() > MinObjAlignment ? align_object_size(arrayOopDesc::header_size(T_INT)) : 0;
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    48
  assert(min_size() > AlignmentReserve,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32378
diff changeset
    49
         "Minimum PLAB size " SIZE_FORMAT " must be larger than alignment reserve " SIZE_FORMAT " "
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32378
diff changeset
    50
         "to be able to contain objects", min_size(), AlignmentReserve);
30275
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    51
}
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    52
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    53
// If the minimum object size is greater than MinObjAlignment, we can
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    54
// end up with a shard at the end of the buffer that's smaller than
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    55
// the smallest object.  We can't allow that because the buffer must
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    56
// look like it's full of objects when we retire it, so we make
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    57
// sure we have enough space for a filler int array object.
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    58
size_t PLAB::AlignmentReserve;
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    59
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    60
void PLAB::flush_and_retire_stats(PLABStats* stats) {
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    61
  // Retire the last allocation buffer.
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    62
  size_t unused = retire_internal();
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    63
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    64
  // Now flush the statistics.
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    65
  stats->add_allocated(_allocated);
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    66
  stats->add_wasted(_wasted);
30564
a37d98a1eb54 8071462: Remove G1ParGCAllocator::alloc_buffer_waste
tschatzl
parents: 30276
diff changeset
    67
  stats->add_undo_wasted(_undo_wasted);
30275
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    68
  stats->add_unused(unused);
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    69
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    70
  // Since we have flushed the stats we need to clear  the _allocated and _wasted
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    71
  // fields in case somebody retains an instance of this over GCs. Not doing so
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    72
  // will artifically inflate the values in the statistics.
30564
a37d98a1eb54 8071462: Remove G1ParGCAllocator::alloc_buffer_waste
tschatzl
parents: 30276
diff changeset
    73
  _allocated   = 0;
a37d98a1eb54 8071462: Remove G1ParGCAllocator::alloc_buffer_waste
tschatzl
parents: 30276
diff changeset
    74
  _wasted      = 0;
a37d98a1eb54 8071462: Remove G1ParGCAllocator::alloc_buffer_waste
tschatzl
parents: 30276
diff changeset
    75
  _undo_wasted = 0;
30275
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    76
}
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    77
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    78
void PLAB::retire() {
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    79
  _wasted += retire_internal();
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    80
}
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    81
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    82
size_t PLAB::retire_internal() {
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    83
  size_t result = 0;
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    84
  if (_top < _hard_end) {
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    85
    CollectedHeap::fill_with_object(_top, _hard_end);
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    86
    result += invalidate();
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    87
  }
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    88
  return result;
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    89
}
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
    90
30564
a37d98a1eb54 8071462: Remove G1ParGCAllocator::alloc_buffer_waste
tschatzl
parents: 30276
diff changeset
    91
void PLAB::add_undo_waste(HeapWord* obj, size_t word_sz) {
a37d98a1eb54 8071462: Remove G1ParGCAllocator::alloc_buffer_waste
tschatzl
parents: 30276
diff changeset
    92
  CollectedHeap::fill_with_object(obj, word_sz);
a37d98a1eb54 8071462: Remove G1ParGCAllocator::alloc_buffer_waste
tschatzl
parents: 30276
diff changeset
    93
  _undo_wasted += word_sz;
a37d98a1eb54 8071462: Remove G1ParGCAllocator::alloc_buffer_waste
tschatzl
parents: 30276
diff changeset
    94
}
a37d98a1eb54 8071462: Remove G1ParGCAllocator::alloc_buffer_waste
tschatzl
parents: 30276
diff changeset
    95
a37d98a1eb54 8071462: Remove G1ParGCAllocator::alloc_buffer_waste
tschatzl
parents: 30276
diff changeset
    96
void PLAB::undo_last_allocation(HeapWord* obj, size_t word_sz) {
a37d98a1eb54 8071462: Remove G1ParGCAllocator::alloc_buffer_waste
tschatzl
parents: 30276
diff changeset
    97
  assert(pointer_delta(_top, _bottom) >= word_sz, "Bad undo");
a37d98a1eb54 8071462: Remove G1ParGCAllocator::alloc_buffer_waste
tschatzl
parents: 30276
diff changeset
    98
  assert(pointer_delta(_top, obj) == word_sz, "Bad undo");
a37d98a1eb54 8071462: Remove G1ParGCAllocator::alloc_buffer_waste
tschatzl
parents: 30276
diff changeset
    99
  _top = obj;
a37d98a1eb54 8071462: Remove G1ParGCAllocator::alloc_buffer_waste
tschatzl
parents: 30276
diff changeset
   100
}
a37d98a1eb54 8071462: Remove G1ParGCAllocator::alloc_buffer_waste
tschatzl
parents: 30276
diff changeset
   101
a37d98a1eb54 8071462: Remove G1ParGCAllocator::alloc_buffer_waste
tschatzl
parents: 30276
diff changeset
   102
void PLAB::undo_allocation(HeapWord* obj, size_t word_sz) {
a37d98a1eb54 8071462: Remove G1ParGCAllocator::alloc_buffer_waste
tschatzl
parents: 30276
diff changeset
   103
  // Is the alloc in the current alloc buffer?
a37d98a1eb54 8071462: Remove G1ParGCAllocator::alloc_buffer_waste
tschatzl
parents: 30276
diff changeset
   104
  if (contains(obj)) {
a37d98a1eb54 8071462: Remove G1ParGCAllocator::alloc_buffer_waste
tschatzl
parents: 30276
diff changeset
   105
    assert(contains(obj + word_sz - 1),
a37d98a1eb54 8071462: Remove G1ParGCAllocator::alloc_buffer_waste
tschatzl
parents: 30276
diff changeset
   106
      "should contain whole object");
a37d98a1eb54 8071462: Remove G1ParGCAllocator::alloc_buffer_waste
tschatzl
parents: 30276
diff changeset
   107
    undo_last_allocation(obj, word_sz);
a37d98a1eb54 8071462: Remove G1ParGCAllocator::alloc_buffer_waste
tschatzl
parents: 30276
diff changeset
   108
  } else {
a37d98a1eb54 8071462: Remove G1ParGCAllocator::alloc_buffer_waste
tschatzl
parents: 30276
diff changeset
   109
    add_undo_waste(obj, word_sz);
a37d98a1eb54 8071462: Remove G1ParGCAllocator::alloc_buffer_waste
tschatzl
parents: 30276
diff changeset
   110
  }
a37d98a1eb54 8071462: Remove G1ParGCAllocator::alloc_buffer_waste
tschatzl
parents: 30276
diff changeset
   111
}
a37d98a1eb54 8071462: Remove G1ParGCAllocator::alloc_buffer_waste
tschatzl
parents: 30276
diff changeset
   112
36390
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35061
diff changeset
   113
void PLABStats::log_plab_allocation() {
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35061
diff changeset
   114
  log_debug(gc, plab)("%s PLAB allocation: "
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35061
diff changeset
   115
                      "allocated: " SIZE_FORMAT "B, "
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35061
diff changeset
   116
                      "wasted: " SIZE_FORMAT "B, "
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35061
diff changeset
   117
                      "unused: " SIZE_FORMAT "B, "
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35061
diff changeset
   118
                      "used: " SIZE_FORMAT "B, "
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35061
diff changeset
   119
                      "undo waste: " SIZE_FORMAT "B, ",
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35061
diff changeset
   120
                      _description,
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35061
diff changeset
   121
                      _allocated * HeapWordSize,
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35061
diff changeset
   122
                      _wasted * HeapWordSize,
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35061
diff changeset
   123
                      _unused * HeapWordSize,
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35061
diff changeset
   124
                      used() * HeapWordSize,
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35061
diff changeset
   125
                      _undo_wasted * HeapWordSize);
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35061
diff changeset
   126
}
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35061
diff changeset
   127
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35061
diff changeset
   128
void PLABStats::log_sizing(size_t calculated_words, size_t net_desired_words) {
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35061
diff changeset
   129
  log_debug(gc, plab)("%s sizing: "
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35061
diff changeset
   130
                      "calculated: " SIZE_FORMAT "B, "
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35061
diff changeset
   131
                      "actual: " SIZE_FORMAT "B",
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35061
diff changeset
   132
                      _description,
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35061
diff changeset
   133
                      calculated_words * HeapWordSize,
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35061
diff changeset
   134
                      net_desired_words * HeapWordSize);
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35061
diff changeset
   135
}
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35061
diff changeset
   136
31632
d041b34dd3e7 8079555: REDO - Determining the desired PLAB size adjusts to the the number of threads at the wrong place
sangheki
parents: 31592
diff changeset
   137
// Calculates plab size for current number of gc worker threads.
d041b34dd3e7 8079555: REDO - Determining the desired PLAB size adjusts to the the number of threads at the wrong place
sangheki
parents: 31592
diff changeset
   138
size_t PLABStats::desired_plab_sz(uint no_of_gc_workers) {
37068
fd8357c31be4 8150952: Net PLAB size is clipped to max PLAB size as a whole, not on a per thread basis
tschatzl
parents: 36390
diff changeset
   139
  return (size_t)align_object_size(MIN2(MAX2(min_size(), _desired_net_plab_sz / no_of_gc_workers), max_size()));
31632
d041b34dd3e7 8079555: REDO - Determining the desired PLAB size adjusts to the the number of threads at the wrong place
sangheki
parents: 31592
diff changeset
   140
}
d041b34dd3e7 8079555: REDO - Determining the desired PLAB size adjusts to the the number of threads at the wrong place
sangheki
parents: 31592
diff changeset
   141
d041b34dd3e7 8079555: REDO - Determining the desired PLAB size adjusts to the the number of threads at the wrong place
sangheki
parents: 31592
diff changeset
   142
// Compute desired plab size for one gc worker thread and latch result for later
30275
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   143
// use. This should be called once at the end of parallel
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   144
// scavenge; it clears the sensor accumulators.
31632
d041b34dd3e7 8079555: REDO - Determining the desired PLAB size adjusts to the the number of threads at the wrong place
sangheki
parents: 31592
diff changeset
   145
void PLABStats::adjust_desired_plab_sz() {
36390
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35061
diff changeset
   146
  log_plab_allocation();
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35061
diff changeset
   147
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35061
diff changeset
   148
  if (!ResizePLAB) {
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35061
diff changeset
   149
    // Clear accumulators for next round.
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35061
diff changeset
   150
    reset();
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35061
diff changeset
   151
    return;
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35061
diff changeset
   152
  }
30275
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   153
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   154
  assert(is_object_aligned(max_size()) && min_size() <= max_size(),
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   155
         "PLAB clipping computation may be incorrect");
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   156
46290
3c4c1591507d 8151045: Remove code duplication in PLABStats/G1EvacStats::adjust_desired_plab_sz
aharlap
parents: 37068
diff changeset
   157
  assert(_allocated != 0 || _unused == 0,
3c4c1591507d 8151045: Remove code duplication in PLABStats/G1EvacStats::adjust_desired_plab_sz
aharlap
parents: 37068
diff changeset
   158
         "Inconsistency in PLAB stats: "
3c4c1591507d 8151045: Remove code duplication in PLABStats/G1EvacStats::adjust_desired_plab_sz
aharlap
parents: 37068
diff changeset
   159
         "_allocated: " SIZE_FORMAT ", "
3c4c1591507d 8151045: Remove code duplication in PLABStats/G1EvacStats::adjust_desired_plab_sz
aharlap
parents: 37068
diff changeset
   160
         "_wasted: " SIZE_FORMAT ", "
3c4c1591507d 8151045: Remove code duplication in PLABStats/G1EvacStats::adjust_desired_plab_sz
aharlap
parents: 37068
diff changeset
   161
         "_unused: " SIZE_FORMAT ", "
3c4c1591507d 8151045: Remove code duplication in PLABStats/G1EvacStats::adjust_desired_plab_sz
aharlap
parents: 37068
diff changeset
   162
         "_undo_wasted: " SIZE_FORMAT,
3c4c1591507d 8151045: Remove code duplication in PLABStats/G1EvacStats::adjust_desired_plab_sz
aharlap
parents: 37068
diff changeset
   163
         _allocated, _wasted, _unused, _undo_wasted);
30275
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   164
46290
3c4c1591507d 8151045: Remove code duplication in PLABStats/G1EvacStats::adjust_desired_plab_sz
aharlap
parents: 37068
diff changeset
   165
  size_t plab_sz = compute_desired_plab_sz();
3c4c1591507d 8151045: Remove code duplication in PLABStats/G1EvacStats::adjust_desired_plab_sz
aharlap
parents: 37068
diff changeset
   166
  // Take historical weighted average
3c4c1591507d 8151045: Remove code duplication in PLABStats/G1EvacStats::adjust_desired_plab_sz
aharlap
parents: 37068
diff changeset
   167
  _filter.sample(plab_sz);
3c4c1591507d 8151045: Remove code duplication in PLABStats/G1EvacStats::adjust_desired_plab_sz
aharlap
parents: 37068
diff changeset
   168
  _desired_net_plab_sz = MAX2(min_size(), (size_t)_filter.average());
3c4c1591507d 8151045: Remove code duplication in PLABStats/G1EvacStats::adjust_desired_plab_sz
aharlap
parents: 37068
diff changeset
   169
3c4c1591507d 8151045: Remove code duplication in PLABStats/G1EvacStats::adjust_desired_plab_sz
aharlap
parents: 37068
diff changeset
   170
  log_sizing(plab_sz, _desired_net_plab_sz);
3c4c1591507d 8151045: Remove code duplication in PLABStats/G1EvacStats::adjust_desired_plab_sz
aharlap
parents: 37068
diff changeset
   171
  // Clear accumulators for next round
3c4c1591507d 8151045: Remove code duplication in PLABStats/G1EvacStats::adjust_desired_plab_sz
aharlap
parents: 37068
diff changeset
   172
  reset();
3c4c1591507d 8151045: Remove code duplication in PLABStats/G1EvacStats::adjust_desired_plab_sz
aharlap
parents: 37068
diff changeset
   173
}
3c4c1591507d 8151045: Remove code duplication in PLABStats/G1EvacStats::adjust_desired_plab_sz
aharlap
parents: 37068
diff changeset
   174
3c4c1591507d 8151045: Remove code duplication in PLABStats/G1EvacStats::adjust_desired_plab_sz
aharlap
parents: 37068
diff changeset
   175
size_t PLABStats::compute_desired_plab_sz() {
3c4c1591507d 8151045: Remove code duplication in PLABStats/G1EvacStats::adjust_desired_plab_sz
aharlap
parents: 37068
diff changeset
   176
  size_t allocated      = MAX2(_allocated, size_t(1));
3c4c1591507d 8151045: Remove code duplication in PLABStats/G1EvacStats::adjust_desired_plab_sz
aharlap
parents: 37068
diff changeset
   177
  double wasted_frac    = (double)_unused / (double)allocated;
30275
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   178
  size_t target_refills = (size_t)((wasted_frac * TargetSurvivorRatio) / TargetPLABWastePct);
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   179
  if (target_refills == 0) {
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   180
    target_refills = 1;
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   181
  }
46290
3c4c1591507d 8151045: Remove code duplication in PLABStats/G1EvacStats::adjust_desired_plab_sz
aharlap
parents: 37068
diff changeset
   182
  size_t used = allocated - _wasted - _unused;
31632
d041b34dd3e7 8079555: REDO - Determining the desired PLAB size adjusts to the the number of threads at the wrong place
sangheki
parents: 31592
diff changeset
   183
  // Assumed to have 1 gc worker thread
d041b34dd3e7 8079555: REDO - Determining the desired PLAB size adjusts to the the number of threads at the wrong place
sangheki
parents: 31592
diff changeset
   184
  size_t recent_plab_sz = used / target_refills;
46290
3c4c1591507d 8151045: Remove code duplication in PLABStats/G1EvacStats::adjust_desired_plab_sz
aharlap
parents: 37068
diff changeset
   185
  return recent_plab_sz;
30275
41fef3a62cc8 8074546: Rename and clean up the ParGCAllocBuffer class
jprovino
parents:
diff changeset
   186
}