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/shared/collectedHeap.hpp"
27 #include "gc/shared/plab.inline.hpp"
28 #include "gc/shared/threadLocalAllocBuffer.hpp"
29 #include "oops/arrayOop.hpp"
30 #include "oops/oop.inline.hpp"
31
32 size_t PLAB::min_size() {
33 // Make sure that we return something that is larger than AlignmentReserve
34 return align_object_size(MAX2(MinTLABSize / HeapWordSize, (uintx)oopDesc::header_size())) + AlignmentReserve;
35 }
36
37 size_t PLAB::max_size() {
38 return ThreadLocalAllocBuffer::max_size();
39 }
40
41 PLAB::PLAB(size_t desired_plab_sz_) :
42 _word_sz(desired_plab_sz_), _bottom(NULL), _top(NULL),
43 _end(NULL), _hard_end(NULL), _allocated(0), _wasted(0), _undo_wasted(0)
44 {
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 assert(min_size() > AlignmentReserve,
48 "Minimum PLAB size " SIZE_FORMAT " must be larger than alignment reserve " SIZE_FORMAT " "
132 "_undo_wasted: " SIZE_FORMAT,
133 _allocated, _wasted, _unused, _undo_wasted);
134
135 _allocated = 1;
136 }
137 double wasted_frac = (double)_unused / (double)_allocated;
138 size_t target_refills = (size_t)((wasted_frac * TargetSurvivorRatio) / TargetPLABWastePct);
139 if (target_refills == 0) {
140 target_refills = 1;
141 }
142 size_t used = _allocated - _wasted - _unused;
143 // Assumed to have 1 gc worker thread
144 size_t recent_plab_sz = used / target_refills;
145 // Take historical weighted average
146 _filter.sample(recent_plab_sz);
147 // Clip from above and below, and align to object boundary
148 size_t new_plab_sz = MAX2(min_size(), (size_t)_filter.average());
149 new_plab_sz = MIN2(max_size(), new_plab_sz);
150 new_plab_sz = align_object_size(new_plab_sz);
151 // Latch the result
152 if (PrintPLAB) {
153 gclog_or_tty->print(" (plab_sz = " SIZE_FORMAT " desired_net_plab_sz = " SIZE_FORMAT ") ", recent_plab_sz, new_plab_sz);
154 }
155 _desired_net_plab_sz = new_plab_sz;
156
157 reset();
158 }
159
160 #ifndef PRODUCT
161 void PLAB::print() {
162 gclog_or_tty->print_cr("PLAB: _bottom: " PTR_FORMAT " _top: " PTR_FORMAT
163 " _end: " PTR_FORMAT " _hard_end: " PTR_FORMAT ")",
164 p2i(_bottom), p2i(_top), p2i(_end), p2i(_hard_end));
165 }
166 #endif // !PRODUCT
|
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/shared/collectedHeap.hpp"
27 #include "gc/shared/plab.inline.hpp"
28 #include "gc/shared/threadLocalAllocBuffer.hpp"
29 #include "logging/log.hpp"
30 #include "oops/arrayOop.hpp"
31 #include "oops/oop.inline.hpp"
32
33 size_t PLAB::min_size() {
34 // Make sure that we return something that is larger than AlignmentReserve
35 return align_object_size(MAX2(MinTLABSize / HeapWordSize, (uintx)oopDesc::header_size())) + AlignmentReserve;
36 }
37
38 size_t PLAB::max_size() {
39 return ThreadLocalAllocBuffer::max_size();
40 }
41
42 PLAB::PLAB(size_t desired_plab_sz_) :
43 _word_sz(desired_plab_sz_), _bottom(NULL), _top(NULL),
44 _end(NULL), _hard_end(NULL), _allocated(0), _wasted(0), _undo_wasted(0)
45 {
46 // ArrayOopDesc::header_size depends on command line initialization.
47 AlignmentReserve = oopDesc::header_size() > MinObjAlignment ? align_object_size(arrayOopDesc::header_size(T_INT)) : 0;
48 assert(min_size() > AlignmentReserve,
49 "Minimum PLAB size " SIZE_FORMAT " must be larger than alignment reserve " SIZE_FORMAT " "
133 "_undo_wasted: " SIZE_FORMAT,
134 _allocated, _wasted, _unused, _undo_wasted);
135
136 _allocated = 1;
137 }
138 double wasted_frac = (double)_unused / (double)_allocated;
139 size_t target_refills = (size_t)((wasted_frac * TargetSurvivorRatio) / TargetPLABWastePct);
140 if (target_refills == 0) {
141 target_refills = 1;
142 }
143 size_t used = _allocated - _wasted - _unused;
144 // Assumed to have 1 gc worker thread
145 size_t recent_plab_sz = used / target_refills;
146 // Take historical weighted average
147 _filter.sample(recent_plab_sz);
148 // Clip from above and below, and align to object boundary
149 size_t new_plab_sz = MAX2(min_size(), (size_t)_filter.average());
150 new_plab_sz = MIN2(max_size(), new_plab_sz);
151 new_plab_sz = align_object_size(new_plab_sz);
152 // Latch the result
153 log_trace(gc, plab)("plab_size = " SIZE_FORMAT " desired_net_plab_sz = " SIZE_FORMAT ") ", recent_plab_sz, new_plab_sz);
154 _desired_net_plab_sz = new_plab_sz;
155
156 reset();
157 }
|