< prev index next >

src/share/vm/gc_implementation/shared/parGCAllocBuffer.cpp

Print this page


   1 /*
   2  * Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "gc_implementation/shared/parGCAllocBuffer.hpp"
  27 #include "memory/sharedHeap.hpp"
  28 #include "oops/arrayOop.hpp"
  29 #include "oops/oop.inline.hpp"
  30 #include "utilities/globalDefinitions.hpp"
  31 
  32 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC







  33 
  34 ParGCAllocBuffer::ParGCAllocBuffer(size_t desired_plab_sz_) :
  35   _word_sz(desired_plab_sz_), _bottom(NULL), _top(NULL),
  36   _end(NULL), _hard_end(NULL),
  37   _retained(false), _retained_filler(),
  38   _allocated(0), _wasted(0)
  39 {
  40   assert (min_size() > AlignmentReserve, "Inconsistency!");
  41   // arrayOopDesc::header_size depends on command line initialization.
  42   FillerHeaderSize = align_object_size(arrayOopDesc::header_size(T_INT));
  43   AlignmentReserve = oopDesc::header_size() > MinObjAlignment ? FillerHeaderSize : 0;
  44 }
  45 
  46 size_t ParGCAllocBuffer::FillerHeaderSize;
  47 
  48 // If the minimum object size is greater than MinObjAlignment, we can
  49 // end up with a shard at the end of the buffer that's smaller than
  50 // the smallest object.  We can't allow that because the buffer must
  51 // look like it's full of objects when we retire it, so we make
  52 // sure we have enough space for a filler int array object.
  53 size_t ParGCAllocBuffer::AlignmentReserve;
  54 
  55 void ParGCAllocBuffer::retire(bool end_of_gc, bool retain) {
  56   assert(!retain || end_of_gc, "Can only retain at GC end.");
  57   if (_retained) {
  58     // If the buffer had been retained shorten the previous filler object.
  59     assert(_retained_filler.end() <= _top, "INVARIANT");
  60     CollectedHeap::fill_with_object(_retained_filler);
  61     // Wasted space book-keeping, otherwise (normally) done in invalidate()
  62     _wasted += _retained_filler.word_size();
  63     _retained = false;
  64   }
  65   assert(!end_of_gc || !_retained, "At this point, end_of_gc ==> !_retained.");












  66   if (_top < _hard_end) {
  67     CollectedHeap::fill_with_object(_top, _hard_end);
  68     if (!retain) {
  69       invalidate();
  70     } else {
  71       // Is there wasted space we'd like to retain for the next GC?
  72       if (pointer_delta(_end, _top) > FillerHeaderSize) {
  73         _retained = true;
  74         _retained_filler = MemRegion(_top, FillerHeaderSize);
  75         _top = _top + FillerHeaderSize;
  76       } else {
  77         invalidate();
  78       }
  79     }
  80   }
  81 }
  82 
  83 void ParGCAllocBuffer::flush_stats(PLABStats* stats) {
  84   assert(ResizePLAB, "Wasted work");
  85   stats->add_allocated(_allocated);
  86   stats->add_wasted(_wasted);
  87   stats->add_unused(pointer_delta(_end, _top));
  88 }
  89 
  90 // Compute desired plab size and latch result for later
  91 // use. This should be called once at the end of parallel
  92 // scavenge; it clears the sensor accumulators.
  93 void PLABStats::adjust_desired_plab_sz(uint no_of_gc_workers) {
  94   assert(ResizePLAB, "Not set");
  95 
  96   assert(is_object_aligned(max_size()) && min_size() <= max_size(),
  97          "PLAB clipping computation may be incorrect");
  98 
  99   if (_allocated == 0) {
 100     assert(_unused == 0,
 101            err_msg("Inconsistency in PLAB stats: "
 102                    "_allocated: "SIZE_FORMAT", "
 103                    "_wasted: "SIZE_FORMAT", "
 104                    "_unused: "SIZE_FORMAT", "
 105                    "_used  : "SIZE_FORMAT,
 106                    _allocated, _wasted, _unused, _used));
 107 
 108     _allocated = 1;
 109   }
 110   double wasted_frac    = (double)_unused/(double)_allocated;
 111   size_t target_refills = (size_t)((wasted_frac*TargetSurvivorRatio)/
 112                                    TargetPLABWastePct);
 113   if (target_refills == 0) {
 114     target_refills = 1;
 115   }
 116   _used = _allocated - _wasted - _unused;
 117   size_t plab_sz = _used/(target_refills*no_of_gc_workers);
 118   if (PrintPLAB) gclog_or_tty->print(" (plab_sz = " SIZE_FORMAT " ", plab_sz);
 119   // Take historical weighted average
 120   _filter.sample(plab_sz);
 121   // Clip from above and below, and align to object boundary
 122   plab_sz = MAX2(min_size(), (size_t)_filter.average());
 123   plab_sz = MIN2(max_size(), plab_sz);
 124   plab_sz = align_object_size(plab_sz);
 125   // Latch the result
 126   if (PrintPLAB) gclog_or_tty->print(" desired_plab_sz = " SIZE_FORMAT ") ", plab_sz);
 127   _desired_plab_sz = plab_sz;
 128   // Now clear the accumulators for next round:
 129   // note this needs to be fixed in the case where we
 130   // are retaining across scavenges. FIX ME !!! XXX
 131   _allocated = 0;
 132   _wasted    = 0;
 133   _unused    = 0;
 134 }
 135 
 136 #ifndef PRODUCT
 137 void ParGCAllocBuffer::print() {
 138   gclog_or_tty->print("parGCAllocBuffer: _bottom: " PTR_FORMAT "  _top: " PTR_FORMAT
 139              "  _end: " PTR_FORMAT "  _hard_end: " PTR_FORMAT " _retained: %c"
 140              " _retained_filler: [" PTR_FORMAT "," PTR_FORMAT ")\n",
 141              _bottom, _top, _end, _hard_end,
 142              "FT"[_retained], _retained_filler.start(), _retained_filler.end());
 143 }
 144 #endif // !PRODUCT
   1 /*
   2  * Copyright (c) 2001, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "gc_implementation/shared/parGCAllocBuffer.hpp"
  27 #include "memory/threadLocalAllocBuffer.hpp"
  28 #include "oops/arrayOop.hpp"
  29 #include "oops/oop.inline.hpp"

  30 
  31 const size_t ParGCAllocBuffer::min_size() {
  32   // Make sure that we return something that is larger than AlignmentReserve
  33   return align_object_size(MAX2(MinTLABSize / HeapWordSize, (uintx)oopDesc::header_size())) + AlignmentReserve;
  34 }
  35 
  36 const size_t ParGCAllocBuffer::max_size() {
  37   return ThreadLocalAllocBuffer::max_size();
  38 }
  39 
  40 ParGCAllocBuffer::ParGCAllocBuffer(size_t desired_plab_sz_) :
  41   _word_sz(desired_plab_sz_), _bottom(NULL), _top(NULL),
  42   _end(NULL), _hard_end(NULL), _allocated(0), _wasted(0)


  43 {
  44   assert (min_size() > AlignmentReserve, "Inconsistency!");
  45   // ArrayOopDesc::header_size depends on command line initialization.
  46   AlignmentReserve = oopDesc::header_size() > MinObjAlignment ? align_object_size(arrayOopDesc::header_size(T_INT)) : 0;

  47 }
  48 


  49 // If the minimum object size is greater than MinObjAlignment, we can
  50 // end up with a shard at the end of the buffer that's smaller than
  51 // the smallest object.  We can't allow that because the buffer must
  52 // look like it's full of objects when we retire it, so we make
  53 // sure we have enough space for a filler int array object.
  54 size_t ParGCAllocBuffer::AlignmentReserve;
  55 
  56 void ParGCAllocBuffer::flush_and_retire_stats(PLABStats* stats) {
  57   // We want to distinguish between unused space in the last buffer and waste
  58   // created otherwise. Save the amount of unused space because retire() will
  59   // update the pointers we use.
  60   size_t unused = pointer_delta(_end, _top);
  61 
  62   // Retire the last allocation buffer.
  63   retire();
  64 
  65   stats->add_allocated(_allocated);
  66   // Retire() counts the unused space as wasted. So we need to remove it again
  67   // before updating the statistics.
  68   stats->add_wasted(_wasted - unused);
  69   stats->add_unused(unused);
  70 
  71   // Since we have flushed the stats we need to clear  the _allocated and _wasted
  72   // fields in case somebody retains an instance of this over GCs. Not doing so
  73   // will artifically inflate the values in the statistics.
  74   _allocated = 0;
  75   _wasted = 0;
  76 }
  77 
  78 void ParGCAllocBuffer::retire() {
  79   if (_top < _hard_end) {
  80     CollectedHeap::fill_with_object(_top, _hard_end);









  81     invalidate();
  82   }









  83 }
  84 
  85 // Compute desired plab size and latch result for later
  86 // use. This should be called once at the end of parallel
  87 // scavenge; it clears the sensor accumulators.
  88 void PLABStats::adjust_desired_plab_sz(uint no_of_gc_workers) {
  89   assert(ResizePLAB, "Not set");
  90 
  91   assert(is_object_aligned(max_size()) && min_size() <= max_size(),
  92          "PLAB clipping computation may be incorrect");
  93 
  94   if (_allocated == 0) {
  95     assert(_unused == 0,
  96            err_msg("Inconsistency in PLAB stats: "
  97                    "_allocated: "SIZE_FORMAT", "
  98                    "_wasted: "SIZE_FORMAT", "
  99                    "_unused: "SIZE_FORMAT,
 100                    _allocated, _wasted, _unused));

 101 
 102     _allocated = 1;
 103   }
 104   double wasted_frac    = (double)_unused / (double)_allocated;
 105   size_t target_refills = (size_t)((wasted_frac * TargetSurvivorRatio) / TargetPLABWastePct);

 106   if (target_refills == 0) {
 107     target_refills = 1;
 108   }
 109   size_t used = _allocated - _wasted - _unused;
 110   size_t recent_plab_sz = used / (target_refills * no_of_gc_workers);

 111   // Take historical weighted average
 112   _filter.sample(recent_plab_sz);
 113   // Clip from above and below, and align to object boundary
 114   size_t new_plab_sz = MAX2(min_size(), (size_t)_filter.average());
 115   new_plab_sz = MIN2(max_size(), new_plab_sz);
 116   new_plab_sz = align_object_size(new_plab_sz);
 117   // Latch the result
 118   if (PrintPLAB) {
 119     gclog_or_tty->print(" (plab_sz = " SIZE_FORMAT" desired_plab_sz = " SIZE_FORMAT") ", recent_plab_sz, new_plab_sz);
 120   }
 121   _desired_plab_sz = new_plab_sz;
 122 
 123   reset();


 124 }
 125 
 126 #ifndef PRODUCT
 127 void ParGCAllocBuffer::print() {
 128   gclog_or_tty->print_cr("parGCAllocBuffer: _bottom: " PTR_FORMAT "  _top: " PTR_FORMAT
 129     "  _end: " PTR_FORMAT "  _hard_end: " PTR_FORMAT ")",
 130     p2i(_bottom), p2i(_top), p2i(_end), p2i(_hard_end));


 131 }
 132 #endif // !PRODUCT
< prev index next >