annotate src/share/vm/gc/g1/g1EvacStats.cpp @ 9295:05be144c3f45

8135209: Avoid abutting string literals and identifiers Summary: Add spaces between string literals and identifiers. Reviewed-by: brutisso, pliden
author kbarrett
date Wed, 09 Sep 2015 14:31:12 -0400
parents be685a5356a4
children e144340c417a
rev   line source
tschatzl@9171 1 /*
tschatzl@9171 2 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
tschatzl@9171 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
tschatzl@9171 4 *
tschatzl@9171 5 * This code is free software; you can redistribute it and/or modify it
tschatzl@9171 6 * under the terms of the GNU General Public License version 2 only, as
tschatzl@9171 7 * published by the Free Software Foundation.
tschatzl@9171 8 *
tschatzl@9171 9 * This code is distributed in the hope that it will be useful, but WITHOUT
tschatzl@9171 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
tschatzl@9171 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
tschatzl@9171 12 * version 2 for more details (a copy is included in the LICENSE file that
tschatzl@9171 13 * accompanied this code).
tschatzl@9171 14 *
tschatzl@9171 15 * You should have received a copy of the GNU General Public License version
tschatzl@9171 16 * 2 along with this work; if not, write to the Free Software Foundation,
tschatzl@9171 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
tschatzl@9171 18 *
tschatzl@9171 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
tschatzl@9171 20 * or visit www.oracle.com if you need additional information or have any
tschatzl@9171 21 * questions.
tschatzl@9171 22 *
tschatzl@9171 23 */
tschatzl@9171 24
tschatzl@9171 25 #include "precompiled.hpp"
tschatzl@9171 26 #include "gc/g1/g1EvacStats.hpp"
tschatzl@9171 27 #include "gc/shared/gcId.hpp"
tschatzl@9171 28 #include "trace/tracing.hpp"
tschatzl@9171 29
tschatzl@9171 30 void G1EvacStats::adjust_desired_plab_sz() {
tschatzl@9171 31 if (PrintPLAB) {
tschatzl@9171 32 gclog_or_tty->print(" (allocated = " SIZE_FORMAT " wasted = " SIZE_FORMAT " "
tschatzl@9171 33 "unused = " SIZE_FORMAT " used = " SIZE_FORMAT " "
tschatzl@9171 34 "undo_waste = " SIZE_FORMAT " region_end_waste = " SIZE_FORMAT " "
tschatzl@9171 35 "regions filled = %u direct_allocated = " SIZE_FORMAT " "
tschatzl@9171 36 "failure_used = " SIZE_FORMAT " failure_waste = " SIZE_FORMAT ") ",
tschatzl@9171 37 _allocated, _wasted, _unused, used(), _undo_wasted, _region_end_waste,
tschatzl@9171 38 _regions_filled, _direct_allocated, _failure_used, _failure_waste);
tschatzl@9171 39 }
tschatzl@9171 40
tschatzl@9171 41 if (ResizePLAB) {
tschatzl@9171 42
tschatzl@9171 43 assert(is_object_aligned(max_size()) && min_size() <= max_size(),
tschatzl@9171 44 "PLAB clipping computation may be incorrect");
tschatzl@9171 45
tschatzl@9171 46 if (_allocated == 0) {
tschatzl@9171 47 assert((_unused == 0),
tschatzl@9171 48 err_msg("Inconsistency in PLAB stats: "
kbarrett@9295 49 "_allocated: " SIZE_FORMAT ", "
kbarrett@9295 50 "_wasted: " SIZE_FORMAT ", "
kbarrett@9295 51 "_region_end_waste: " SIZE_FORMAT ", "
kbarrett@9295 52 "_unused: " SIZE_FORMAT ", "
kbarrett@9295 53 "_used : " SIZE_FORMAT,
tschatzl@9171 54 _allocated, _wasted, _region_end_waste, _unused, used()));
tschatzl@9171 55 _allocated = 1;
tschatzl@9171 56 }
tschatzl@9243 57 // The size of the PLAB caps the amount of space that can be wasted at the
tschatzl@9243 58 // end of the collection. In the worst case the last PLAB could be completely
tschatzl@9243 59 // empty.
tschatzl@9243 60 // This allows us to calculate the new PLAB size to achieve the
tschatzl@9243 61 // TargetPLABWastePct given the latest memory usage and that the last buffer
tschatzl@9243 62 // will be G1LastPLABAverageOccupancy full.
tschatzl@9243 63 //
tschatzl@9243 64 // E.g. assume that if in the current GC 100 words were allocated and a
tschatzl@9243 65 // TargetPLABWastePct of 10 had been set.
tschatzl@9243 66 //
tschatzl@9243 67 // So we could waste up to 10 words to meet that percentage. Given that we
tschatzl@9243 68 // also assume that that buffer is typically half-full, the new desired PLAB
tschatzl@9243 69 // size is set to 20 words.
tschatzl@9243 70 //
tschatzl@9243 71 // The amount of allocation performed should be independent of the number of
tschatzl@9243 72 // threads, so should the maximum waste we can spend in total. So if
tschatzl@9243 73 // we used n threads to allocate, each of them can spend maximum waste/n words in
tschatzl@9243 74 // a first rough approximation. The number of threads only comes into play later
tschatzl@9243 75 // when actually retrieving the actual desired PLAB size.
tschatzl@9243 76 //
tschatzl@9243 77 // After calculating this optimal PLAB size the algorithm applies the usual
tschatzl@9243 78 // exponential decaying average over this value to guess the next PLAB size.
tschatzl@9243 79 //
tschatzl@9243 80 // We account region end waste fully to PLAB allocation (in the calculation of
tschatzl@9243 81 // what we consider as "used_for_waste_calculation" below). This is not
tschatzl@9243 82 // completely fair, but is a conservative assumption because PLABs may be sized
tschatzl@9243 83 // flexibly while we cannot adjust inline allocations.
tschatzl@9243 84 // Allocation during GC will try to minimize region end waste so this impact
tschatzl@9243 85 // should be minimal.
tschatzl@9243 86 //
tschatzl@9243 87 // We need to cover overflow when calculating the amount of space actually used
tschatzl@9243 88 // by objects in PLABs when subtracting the region end waste.
tschatzl@9243 89 // Region end waste may be higher than actual allocation. This may occur if many
tschatzl@9243 90 // threads do not allocate anything but a few rather large objects. In this
tschatzl@9243 91 // degenerate case the PLAB size would simply quickly tend to minimum PLAB size,
tschatzl@9243 92 // which is an okay reaction.
tschatzl@9243 93 size_t const used_for_waste_calculation = used() > _region_end_waste ? used() - _region_end_waste : 0;
tschatzl@9243 94
tschatzl@9243 95 size_t const total_waste_allowed = used_for_waste_calculation * TargetPLABWastePct;
tschatzl@9243 96 size_t const cur_plab_sz = (double)total_waste_allowed / G1LastPLABAverageOccupancy;
tschatzl@9171 97 // Take historical weighted average
tschatzl@9171 98 _filter.sample(cur_plab_sz);
tschatzl@9171 99 // Clip from above and below, and align to object boundary
tschatzl@9171 100 size_t plab_sz;
tschatzl@9171 101 plab_sz = MAX2(min_size(), (size_t)_filter.average());
tschatzl@9171 102 plab_sz = MIN2(max_size(), plab_sz);
tschatzl@9171 103 plab_sz = align_object_size(plab_sz);
tschatzl@9171 104 // Latch the result
tschatzl@9171 105 _desired_net_plab_sz = plab_sz;
tschatzl@9171 106 if (PrintPLAB) {
tschatzl@9171 107 gclog_or_tty->print_cr(" (plab_sz = " SIZE_FORMAT " desired_plab_sz = " SIZE_FORMAT ") ", cur_plab_sz, plab_sz);
tschatzl@9171 108 }
tschatzl@9171 109 }
tschatzl@9171 110 // Clear accumulators for next round.
tschatzl@9171 111 reset();
tschatzl@9171 112 }
tschatzl@9171 113