25
#include "precompiled.hpp"
26
#include "gc/shared/collectedHeap.hpp"
27
#include "gc/shared/gc_globals.hpp"
28
#include "gc/shared/plab.inline.hpp"
29
#include "gc/shared/threadLocalAllocBuffer.hpp"
30
#include "gc/shared/tlab_globals.hpp"
31
#include "logging/log.hpp"
32
#include "memory/universe.hpp"
33
#include "oops/oop.inline.hpp"
34
#include "runtime/globals_extension.hpp"
36
size_t PLAB::min_size() {
38
return align_object_size(MAX2(MinTLABSize / HeapWordSize, (size_t)oopDesc::header_size())) + CollectedHeap::lab_alignment_reserve();
41
size_t PLAB::max_size() {
42
return ThreadLocalAllocBuffer::max_size();
45
void PLAB::startup_initialization() {
46
if (!FLAG_IS_DEFAULT(MinTLABSize)) {
47
if (FLAG_IS_DEFAULT(YoungPLABSize)) {
48
FLAG_SET_ERGO(YoungPLABSize, MAX2(ThreadLocalAllocBuffer::min_size(), YoungPLABSize));
50
if (FLAG_IS_DEFAULT(OldPLABSize)) {
51
FLAG_SET_ERGO(OldPLABSize, MAX2(ThreadLocalAllocBuffer::min_size(), OldPLABSize));
54
uint obj_alignment = checked_cast<uint>(ObjectAlignmentInBytes / HeapWordSize);
55
if (!is_aligned(YoungPLABSize, obj_alignment)) {
56
FLAG_SET_ERGO(YoungPLABSize, align_up(YoungPLABSize, obj_alignment));
58
if (!is_aligned(OldPLABSize, obj_alignment)) {
59
FLAG_SET_ERGO(OldPLABSize, align_up(OldPLABSize, obj_alignment));
63
PLAB::PLAB(size_t desired_plab_sz_) :
64
_word_sz(desired_plab_sz_), _bottom(nullptr), _top(nullptr),
65
_end(nullptr), _hard_end(nullptr), _allocated(0), _wasted(0), _undo_wasted(0)
67
assert(min_size() > CollectedHeap::lab_alignment_reserve(),
68
"Minimum PLAB size " SIZE_FORMAT " must be larger than alignment reserve " SIZE_FORMAT " "
69
"to be able to contain objects", min_size(), CollectedHeap::lab_alignment_reserve());
72
void PLAB::flush_and_retire_stats(PLABStats* stats) {
74
size_t unused = retire_internal();
77
stats->add_allocated(_allocated);
78
stats->add_wasted(_wasted);
79
stats->add_undo_wasted(_undo_wasted);
80
stats->add_unused(unused);
91
_wasted += retire_internal();
94
size_t PLAB::retire_internal() {
96
if (_top < _hard_end) {
97
Universe::heap()->fill_with_dummy_object(_top, _hard_end, true);
98
result += invalidate();
103
void PLAB::add_undo_waste(HeapWord* obj, size_t word_sz) {
104
Universe::heap()->fill_with_dummy_object(obj, obj + word_sz, true);
105
_undo_wasted += word_sz;
108
void PLAB::undo_last_allocation(HeapWord* obj, size_t word_sz) {
109
assert(pointer_delta(_top, _bottom) >= word_sz, "Bad undo");
110
assert(pointer_delta(_top, obj) == word_sz, "Bad undo");
114
void PLAB::undo_allocation(HeapWord* obj, size_t word_sz) {
117
assert(contains(obj + word_sz - 1),
118
"should contain whole object");
119
undo_last_allocation(obj, word_sz);
121
add_undo_waste(obj, word_sz);