mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-18 18:14:38 +02:00
8210857: Allow retiring TLABs and collecting statistics in parallel
Reviewed-by: sjohanss, eosterlund
This commit is contained in:
parent
92575fc3f0
commit
c0d0cbc4f1
5 changed files with 236 additions and 283 deletions
|
@ -468,37 +468,23 @@ oop CollectedHeap::class_allocate(Klass* klass, int size, TRAPS) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void CollectedHeap::ensure_parsability(bool retire_tlabs) {
|
void CollectedHeap::ensure_parsability(bool retire_tlabs) {
|
||||||
// The second disjunct in the assertion below makes a concession
|
|
||||||
// for the start-up verification done while the VM is being
|
|
||||||
// created. Callers be careful that you know that mutators
|
|
||||||
// aren't going to interfere -- for instance, this is permissible
|
|
||||||
// if we are still single-threaded and have either not yet
|
|
||||||
// started allocating (nothing much to verify) or we have
|
|
||||||
// started allocating but are now a full-fledged JavaThread
|
|
||||||
// (and have thus made our TLAB's) available for filling.
|
|
||||||
assert(SafepointSynchronize::is_at_safepoint() || !is_init_completed(),
|
assert(SafepointSynchronize::is_at_safepoint() || !is_init_completed(),
|
||||||
"Should only be called at a safepoint or at start-up"
|
"Should only be called at a safepoint or at start-up");
|
||||||
" otherwise concurrent mutator activity may make heap "
|
|
||||||
" unparsable again");
|
|
||||||
|
|
||||||
if (UseTLAB && retire_tlabs) {
|
ThreadLocalAllocStats stats;
|
||||||
// Accumulate statistics before retiring
|
|
||||||
ThreadLocalAllocBuffer::accumulate_statistics_before_gc();
|
|
||||||
}
|
|
||||||
|
|
||||||
// The main thread starts allocating via a TLAB even before it
|
for (JavaThreadIteratorWithHandle jtiwh; JavaThread *thread = jtiwh.next();) {
|
||||||
// has added itself to the threads list at vm boot-up.
|
BarrierSet::barrier_set()->make_parsable(thread);
|
||||||
JavaThreadIteratorWithHandle jtiwh;
|
|
||||||
assert(jtiwh.length() > 0,
|
|
||||||
"Attempt to fill tlabs before main thread has been added"
|
|
||||||
" to threads list is doomed to failure!");
|
|
||||||
BarrierSet *bs = BarrierSet::barrier_set();
|
|
||||||
for (; JavaThread *thread = jtiwh.next(); ) {
|
|
||||||
if (UseTLAB) {
|
if (UseTLAB) {
|
||||||
thread->tlab().make_parsable(retire_tlabs);
|
if (retire_tlabs) {
|
||||||
|
thread->tlab().retire(&stats);
|
||||||
|
} else {
|
||||||
|
thread->tlab().make_parsable();
|
||||||
}
|
}
|
||||||
bs->make_parsable(thread);
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stats.publish();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CollectedHeap::resize_all_tlabs() {
|
void CollectedHeap::resize_all_tlabs() {
|
||||||
|
|
|
@ -320,7 +320,7 @@ HeapWord* MemAllocator::allocate_inside_tlab_slow(Allocation& allocation) const
|
||||||
// To minimize fragmentation, the last TLAB may be smaller than the rest.
|
// To minimize fragmentation, the last TLAB may be smaller than the rest.
|
||||||
size_t new_tlab_size = tlab.compute_size(_word_size);
|
size_t new_tlab_size = tlab.compute_size(_word_size);
|
||||||
|
|
||||||
tlab.clear_before_allocation();
|
tlab.retire_before_allocation();
|
||||||
|
|
||||||
if (new_tlab_size == 0) {
|
if (new_tlab_size == 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
@ -32,18 +32,9 @@
|
||||||
#include "runtime/threadSMR.hpp"
|
#include "runtime/threadSMR.hpp"
|
||||||
#include "utilities/copy.hpp"
|
#include "utilities/copy.hpp"
|
||||||
|
|
||||||
// Thread-Local Edens support
|
|
||||||
|
|
||||||
// static member initialization
|
|
||||||
size_t ThreadLocalAllocBuffer::_max_size = 0;
|
size_t ThreadLocalAllocBuffer::_max_size = 0;
|
||||||
int ThreadLocalAllocBuffer::_reserve_for_allocation_prefetch = 0;
|
int ThreadLocalAllocBuffer::_reserve_for_allocation_prefetch = 0;
|
||||||
unsigned ThreadLocalAllocBuffer::_target_refills = 0;
|
unsigned int ThreadLocalAllocBuffer::_target_refills = 0;
|
||||||
GlobalTLABStats* ThreadLocalAllocBuffer::_global_stats = NULL;
|
|
||||||
|
|
||||||
void ThreadLocalAllocBuffer::clear_before_allocation() {
|
|
||||||
_slow_refill_waste += (unsigned)remaining();
|
|
||||||
make_parsable(true); // also retire the TLAB
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t ThreadLocalAllocBuffer::remaining() {
|
size_t ThreadLocalAllocBuffer::remaining() {
|
||||||
if (end() == NULL) {
|
if (end() == NULL) {
|
||||||
|
@ -53,22 +44,7 @@ size_t ThreadLocalAllocBuffer::remaining() {
|
||||||
return pointer_delta(hard_end(), top());
|
return pointer_delta(hard_end(), top());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ThreadLocalAllocBuffer::accumulate_statistics_before_gc() {
|
void ThreadLocalAllocBuffer::accumulate_and_reset_statistics(ThreadLocalAllocStats* stats) {
|
||||||
global_stats()->initialize();
|
|
||||||
|
|
||||||
for (JavaThreadIteratorWithHandle jtiwh; JavaThread *thread = jtiwh.next(); ) {
|
|
||||||
thread->tlab().accumulate_statistics();
|
|
||||||
thread->tlab().initialize_statistics();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Publish new stats if some allocation occurred.
|
|
||||||
if (global_stats()->allocation() != 0) {
|
|
||||||
global_stats()->publish();
|
|
||||||
global_stats()->print();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ThreadLocalAllocBuffer::accumulate_statistics() {
|
|
||||||
Thread* thr = thread();
|
Thread* thr = thread();
|
||||||
size_t capacity = Universe::heap()->tlab_capacity(thr);
|
size_t capacity = Universe::heap()->tlab_capacity(thr);
|
||||||
size_t used = Universe::heap()->tlab_used(thr);
|
size_t used = Universe::heap()->tlab_used(thr);
|
||||||
|
@ -95,47 +71,55 @@ void ThreadLocalAllocBuffer::accumulate_statistics() {
|
||||||
double alloc_frac = MIN2(1.0, (double) allocated_since_last_gc / used);
|
double alloc_frac = MIN2(1.0, (double) allocated_since_last_gc / used);
|
||||||
_allocation_fraction.sample(alloc_frac);
|
_allocation_fraction.sample(alloc_frac);
|
||||||
}
|
}
|
||||||
global_stats()->update_allocating_threads();
|
|
||||||
global_stats()->update_number_of_refills(_number_of_refills);
|
|
||||||
global_stats()->update_allocation(_allocated_size);
|
|
||||||
global_stats()->update_gc_waste(_gc_waste);
|
|
||||||
global_stats()->update_slow_refill_waste(_slow_refill_waste);
|
|
||||||
global_stats()->update_fast_refill_waste(_fast_refill_waste);
|
|
||||||
|
|
||||||
|
stats->update_fast_allocations(_number_of_refills,
|
||||||
|
_allocated_size,
|
||||||
|
_gc_waste,
|
||||||
|
_fast_refill_waste,
|
||||||
|
_slow_refill_waste);
|
||||||
} else {
|
} else {
|
||||||
assert(_number_of_refills == 0 && _fast_refill_waste == 0 &&
|
assert(_number_of_refills == 0 && _fast_refill_waste == 0 &&
|
||||||
_slow_refill_waste == 0 && _gc_waste == 0,
|
_slow_refill_waste == 0 && _gc_waste == 0,
|
||||||
"tlab stats == 0");
|
"tlab stats == 0");
|
||||||
}
|
}
|
||||||
global_stats()->update_slow_allocations(_slow_allocations);
|
|
||||||
|
stats->update_slow_allocations(_slow_allocations);
|
||||||
|
|
||||||
|
reset_statistics();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fills the current tlab with a dummy filler array to create
|
void ThreadLocalAllocBuffer::insert_filler() {
|
||||||
// an illusion of a contiguous Eden and optionally retires the tlab.
|
assert(end() != NULL, "Must not be retired");
|
||||||
// Waste accounting should be done in caller as appropriate; see,
|
Universe::heap()->fill_with_dummy_object(top(), hard_end(), true);
|
||||||
// for example, clear_before_allocation().
|
}
|
||||||
void ThreadLocalAllocBuffer::make_parsable(bool retire, bool zap) {
|
|
||||||
|
void ThreadLocalAllocBuffer::make_parsable() {
|
||||||
if (end() != NULL) {
|
if (end() != NULL) {
|
||||||
invariants();
|
invariants();
|
||||||
|
if (ZeroTLAB) {
|
||||||
|
retire();
|
||||||
|
} else {
|
||||||
|
insert_filler();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (retire) {
|
void ThreadLocalAllocBuffer::retire(ThreadLocalAllocStats* stats) {
|
||||||
|
if (stats != NULL) {
|
||||||
|
accumulate_and_reset_statistics(stats);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (end() != NULL) {
|
||||||
|
invariants();
|
||||||
thread()->incr_allocated_bytes(used_bytes());
|
thread()->incr_allocated_bytes(used_bytes());
|
||||||
|
insert_filler();
|
||||||
|
initialize(NULL, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Universe::heap()->fill_with_dummy_object(top(), hard_end(), retire && zap);
|
void ThreadLocalAllocBuffer::retire_before_allocation() {
|
||||||
|
_slow_refill_waste += (unsigned int)remaining();
|
||||||
if (retire || ZeroTLAB) { // "Reset" the TLAB
|
retire();
|
||||||
set_start(NULL);
|
|
||||||
set_top(NULL);
|
|
||||||
set_pf_top(NULL);
|
|
||||||
set_end(NULL);
|
|
||||||
set_allocation_end(NULL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
assert(!(retire || ZeroTLAB) ||
|
|
||||||
(start() == NULL && end() == NULL && top() == NULL &&
|
|
||||||
_allocation_end == NULL),
|
|
||||||
"TLAB must be reset");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ThreadLocalAllocBuffer::resize() {
|
void ThreadLocalAllocBuffer::resize() {
|
||||||
|
@ -158,7 +142,7 @@ void ThreadLocalAllocBuffer::resize() {
|
||||||
set_refill_waste_limit(initial_refill_waste_limit());
|
set_refill_waste_limit(initial_refill_waste_limit());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ThreadLocalAllocBuffer::initialize_statistics() {
|
void ThreadLocalAllocBuffer::reset_statistics() {
|
||||||
_number_of_refills = 0;
|
_number_of_refills = 0;
|
||||||
_fast_refill_waste = 0;
|
_fast_refill_waste = 0;
|
||||||
_slow_refill_waste = 0;
|
_slow_refill_waste = 0;
|
||||||
|
@ -199,21 +183,17 @@ void ThreadLocalAllocBuffer::initialize() {
|
||||||
|
|
||||||
set_desired_size(initial_desired_size());
|
set_desired_size(initial_desired_size());
|
||||||
|
|
||||||
// Following check is needed because at startup the main
|
|
||||||
// thread is initialized before the heap is. The initialization for
|
|
||||||
// this thread is redone in startup_initialization below.
|
|
||||||
if (Universe::heap() != NULL) {
|
|
||||||
size_t capacity = Universe::heap()->tlab_capacity(thread()) / HeapWordSize;
|
size_t capacity = Universe::heap()->tlab_capacity(thread()) / HeapWordSize;
|
||||||
double alloc_frac = desired_size() * target_refills() / (double) capacity;
|
double alloc_frac = desired_size() * target_refills() / (double) capacity;
|
||||||
_allocation_fraction.sample(alloc_frac);
|
_allocation_fraction.sample(alloc_frac);
|
||||||
}
|
|
||||||
|
|
||||||
set_refill_waste_limit(initial_refill_waste_limit());
|
set_refill_waste_limit(initial_refill_waste_limit());
|
||||||
|
|
||||||
initialize_statistics();
|
reset_statistics();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ThreadLocalAllocBuffer::startup_initialization() {
|
void ThreadLocalAllocBuffer::startup_initialization() {
|
||||||
|
ThreadLocalAllocStats::initialize();
|
||||||
|
|
||||||
// Assuming each thread's active tlab is, on average,
|
// Assuming each thread's active tlab is, on average,
|
||||||
// 1/2 full at a GC
|
// 1/2 full at a GC
|
||||||
|
@ -222,8 +202,6 @@ void ThreadLocalAllocBuffer::startup_initialization() {
|
||||||
// abort during VM initialization.
|
// abort during VM initialization.
|
||||||
_target_refills = MAX2(_target_refills, 2U);
|
_target_refills = MAX2(_target_refills, 2U);
|
||||||
|
|
||||||
_global_stats = new GlobalTLABStats();
|
|
||||||
|
|
||||||
#ifdef COMPILER2
|
#ifdef COMPILER2
|
||||||
// If the C2 compiler is present, extra space is needed at the end of
|
// If the C2 compiler is present, extra space is needed at the end of
|
||||||
// TLABs, otherwise prefetching instructions generated by the C2
|
// TLABs, otherwise prefetching instructions generated by the C2
|
||||||
|
@ -262,9 +240,9 @@ size_t ThreadLocalAllocBuffer::initial_desired_size() {
|
||||||
|
|
||||||
if (TLABSize > 0) {
|
if (TLABSize > 0) {
|
||||||
init_sz = TLABSize / HeapWordSize;
|
init_sz = TLABSize / HeapWordSize;
|
||||||
} else if (global_stats() != NULL) {
|
} else {
|
||||||
// Initial size is a function of the average number of allocating threads.
|
// Initial size is a function of the average number of allocating threads.
|
||||||
unsigned nof_threads = global_stats()->allocating_threads_avg();
|
unsigned int nof_threads = ThreadLocalAllocStats::allocating_threads_avg();
|
||||||
|
|
||||||
init_sz = (Universe::heap()->tlab_capacity(thread()) / HeapWordSize) /
|
init_sz = (Universe::heap()->tlab_capacity(thread()) / HeapWordSize) /
|
||||||
(nof_threads * target_refills());
|
(nof_threads * target_refills());
|
||||||
|
@ -338,123 +316,148 @@ HeapWord* ThreadLocalAllocBuffer::hard_end() {
|
||||||
return _allocation_end + alignment_reserve();
|
return _allocation_end + alignment_reserve();
|
||||||
}
|
}
|
||||||
|
|
||||||
GlobalTLABStats::GlobalTLABStats() :
|
PerfVariable* ThreadLocalAllocStats::_perf_allocating_threads;
|
||||||
_allocating_threads_avg(TLABAllocationWeight) {
|
PerfVariable* ThreadLocalAllocStats::_perf_total_refills;
|
||||||
|
PerfVariable* ThreadLocalAllocStats::_perf_max_refills;
|
||||||
|
PerfVariable* ThreadLocalAllocStats::_perf_total_allocations;
|
||||||
|
PerfVariable* ThreadLocalAllocStats::_perf_total_gc_waste;
|
||||||
|
PerfVariable* ThreadLocalAllocStats::_perf_max_gc_waste;
|
||||||
|
PerfVariable* ThreadLocalAllocStats::_perf_total_slow_refill_waste;
|
||||||
|
PerfVariable* ThreadLocalAllocStats::_perf_max_slow_refill_waste;
|
||||||
|
PerfVariable* ThreadLocalAllocStats::_perf_total_fast_refill_waste;
|
||||||
|
PerfVariable* ThreadLocalAllocStats::_perf_max_fast_refill_waste;
|
||||||
|
PerfVariable* ThreadLocalAllocStats::_perf_total_slow_allocations;
|
||||||
|
PerfVariable* ThreadLocalAllocStats::_perf_max_slow_allocations;
|
||||||
|
AdaptiveWeightedAverage ThreadLocalAllocStats::_allocating_threads_avg(0);
|
||||||
|
|
||||||
initialize();
|
static PerfVariable* create_perf_variable(const char* name, PerfData::Units unit, TRAPS) {
|
||||||
|
ResourceMark rm;
|
||||||
|
return PerfDataManager::create_variable(SUN_GC, PerfDataManager::counter_name("tlab", name), unit, THREAD);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ThreadLocalAllocStats::initialize() {
|
||||||
|
_allocating_threads_avg = AdaptiveWeightedAverage(TLABAllocationWeight);
|
||||||
_allocating_threads_avg.sample(1); // One allocating thread at startup
|
_allocating_threads_avg.sample(1); // One allocating thread at startup
|
||||||
|
|
||||||
if (UsePerfData) {
|
if (UsePerfData) {
|
||||||
|
|
||||||
EXCEPTION_MARK;
|
EXCEPTION_MARK;
|
||||||
ResourceMark rm;
|
_perf_allocating_threads = create_perf_variable("allocThreads", PerfData::U_None, CHECK);
|
||||||
|
_perf_total_refills = create_perf_variable("fills", PerfData::U_None, CHECK);
|
||||||
char* cname = PerfDataManager::counter_name("tlab", "allocThreads");
|
_perf_max_refills = create_perf_variable("maxFills", PerfData::U_None, CHECK);
|
||||||
_perf_allocating_threads =
|
_perf_total_allocations = create_perf_variable("alloc", PerfData::U_Bytes, CHECK);
|
||||||
PerfDataManager::create_variable(SUN_GC, cname, PerfData::U_None, CHECK);
|
_perf_total_gc_waste = create_perf_variable("gcWaste", PerfData::U_Bytes, CHECK);
|
||||||
|
_perf_max_gc_waste = create_perf_variable("maxGcWaste", PerfData::U_Bytes, CHECK);
|
||||||
cname = PerfDataManager::counter_name("tlab", "fills");
|
_perf_total_slow_refill_waste = create_perf_variable("slowWaste", PerfData::U_Bytes, CHECK);
|
||||||
_perf_total_refills =
|
_perf_max_slow_refill_waste = create_perf_variable("maxSlowWaste", PerfData::U_Bytes, CHECK);
|
||||||
PerfDataManager::create_variable(SUN_GC, cname, PerfData::U_None, CHECK);
|
_perf_total_fast_refill_waste = create_perf_variable("fastWaste", PerfData::U_Bytes, CHECK);
|
||||||
|
_perf_max_fast_refill_waste = create_perf_variable("maxFastWaste", PerfData::U_Bytes, CHECK);
|
||||||
cname = PerfDataManager::counter_name("tlab", "maxFills");
|
_perf_total_slow_allocations = create_perf_variable("slowAlloc", PerfData::U_None, CHECK);
|
||||||
_perf_max_refills =
|
_perf_max_slow_allocations = create_perf_variable("maxSlowAlloc", PerfData::U_None, CHECK);
|
||||||
PerfDataManager::create_variable(SUN_GC, cname, PerfData::U_None, CHECK);
|
|
||||||
|
|
||||||
cname = PerfDataManager::counter_name("tlab", "alloc");
|
|
||||||
_perf_allocation =
|
|
||||||
PerfDataManager::create_variable(SUN_GC, cname, PerfData::U_Bytes, CHECK);
|
|
||||||
|
|
||||||
cname = PerfDataManager::counter_name("tlab", "gcWaste");
|
|
||||||
_perf_gc_waste =
|
|
||||||
PerfDataManager::create_variable(SUN_GC, cname, PerfData::U_Bytes, CHECK);
|
|
||||||
|
|
||||||
cname = PerfDataManager::counter_name("tlab", "maxGcWaste");
|
|
||||||
_perf_max_gc_waste =
|
|
||||||
PerfDataManager::create_variable(SUN_GC, cname, PerfData::U_Bytes, CHECK);
|
|
||||||
|
|
||||||
cname = PerfDataManager::counter_name("tlab", "slowWaste");
|
|
||||||
_perf_slow_refill_waste =
|
|
||||||
PerfDataManager::create_variable(SUN_GC, cname, PerfData::U_Bytes, CHECK);
|
|
||||||
|
|
||||||
cname = PerfDataManager::counter_name("tlab", "maxSlowWaste");
|
|
||||||
_perf_max_slow_refill_waste =
|
|
||||||
PerfDataManager::create_variable(SUN_GC, cname, PerfData::U_Bytes, CHECK);
|
|
||||||
|
|
||||||
cname = PerfDataManager::counter_name("tlab", "fastWaste");
|
|
||||||
_perf_fast_refill_waste =
|
|
||||||
PerfDataManager::create_variable(SUN_GC, cname, PerfData::U_Bytes, CHECK);
|
|
||||||
|
|
||||||
cname = PerfDataManager::counter_name("tlab", "maxFastWaste");
|
|
||||||
_perf_max_fast_refill_waste =
|
|
||||||
PerfDataManager::create_variable(SUN_GC, cname, PerfData::U_Bytes, CHECK);
|
|
||||||
|
|
||||||
cname = PerfDataManager::counter_name("tlab", "slowAlloc");
|
|
||||||
_perf_slow_allocations =
|
|
||||||
PerfDataManager::create_variable(SUN_GC, cname, PerfData::U_None, CHECK);
|
|
||||||
|
|
||||||
cname = PerfDataManager::counter_name("tlab", "maxSlowAlloc");
|
|
||||||
_perf_max_slow_allocations =
|
|
||||||
PerfDataManager::create_variable(SUN_GC, cname, PerfData::U_None, CHECK);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GlobalTLABStats::initialize() {
|
ThreadLocalAllocStats::ThreadLocalAllocStats() :
|
||||||
// Clear counters summarizing info from all threads
|
_allocating_threads(0),
|
||||||
|
_total_refills(0),
|
||||||
|
_max_refills(0),
|
||||||
|
_total_allocations(0),
|
||||||
|
_total_gc_waste(0),
|
||||||
|
_max_gc_waste(0),
|
||||||
|
_total_fast_refill_waste(0),
|
||||||
|
_max_fast_refill_waste(0),
|
||||||
|
_total_slow_refill_waste(0),
|
||||||
|
_max_slow_refill_waste(0),
|
||||||
|
_total_slow_allocations(0),
|
||||||
|
_max_slow_allocations(0) {}
|
||||||
|
|
||||||
|
unsigned int ThreadLocalAllocStats::allocating_threads_avg() {
|
||||||
|
return MAX2((unsigned int)(_allocating_threads_avg.average() + 0.5), 1U);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ThreadLocalAllocStats::update_fast_allocations(unsigned int refills,
|
||||||
|
size_t allocations,
|
||||||
|
size_t gc_waste,
|
||||||
|
size_t fast_refill_waste,
|
||||||
|
size_t slow_refill_waste) {
|
||||||
|
_allocating_threads += 1;
|
||||||
|
_total_refills += refills;
|
||||||
|
_max_refills = MAX2(_max_refills, refills);
|
||||||
|
_total_allocations += allocations;
|
||||||
|
_total_gc_waste += gc_waste;
|
||||||
|
_max_gc_waste = MAX2(_max_gc_waste, gc_waste);
|
||||||
|
_total_fast_refill_waste += fast_refill_waste;
|
||||||
|
_max_fast_refill_waste = MAX2(_max_fast_refill_waste, fast_refill_waste);
|
||||||
|
_total_slow_refill_waste += slow_refill_waste;
|
||||||
|
_max_slow_refill_waste = MAX2(_max_slow_refill_waste, slow_refill_waste);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ThreadLocalAllocStats::update_slow_allocations(unsigned int allocations) {
|
||||||
|
_total_slow_allocations += allocations;
|
||||||
|
_max_slow_allocations = MAX2(_max_slow_allocations, allocations);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ThreadLocalAllocStats::update(const ThreadLocalAllocStats& other) {
|
||||||
|
_allocating_threads += other._allocating_threads;
|
||||||
|
_total_refills += other._total_refills;
|
||||||
|
_max_refills = MAX2(_max_refills, other._max_refills);
|
||||||
|
_total_allocations += other._total_allocations;
|
||||||
|
_total_gc_waste += other._total_gc_waste;
|
||||||
|
_max_gc_waste = MAX2(_max_gc_waste, other._max_gc_waste);
|
||||||
|
_total_fast_refill_waste += other._total_fast_refill_waste;
|
||||||
|
_max_fast_refill_waste = MAX2(_max_fast_refill_waste, other._max_fast_refill_waste);
|
||||||
|
_total_slow_refill_waste += other._total_slow_refill_waste;
|
||||||
|
_max_slow_refill_waste = MAX2(_max_slow_refill_waste, other._max_slow_refill_waste);
|
||||||
|
_total_slow_allocations += other._total_slow_allocations;
|
||||||
|
_max_slow_allocations = MAX2(_max_slow_allocations, other._max_slow_allocations);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ThreadLocalAllocStats::reset() {
|
||||||
_allocating_threads = 0;
|
_allocating_threads = 0;
|
||||||
_total_refills = 0;
|
_total_refills = 0;
|
||||||
_max_refills = 0;
|
_max_refills = 0;
|
||||||
_total_allocation = 0;
|
_total_allocations = 0;
|
||||||
_total_gc_waste = 0;
|
_total_gc_waste = 0;
|
||||||
_max_gc_waste = 0;
|
_max_gc_waste = 0;
|
||||||
_total_slow_refill_waste = 0;
|
|
||||||
_max_slow_refill_waste = 0;
|
|
||||||
_total_fast_refill_waste = 0;
|
_total_fast_refill_waste = 0;
|
||||||
_max_fast_refill_waste = 0;
|
_max_fast_refill_waste = 0;
|
||||||
|
_total_slow_refill_waste = 0;
|
||||||
|
_max_slow_refill_waste = 0;
|
||||||
_total_slow_allocations = 0;
|
_total_slow_allocations = 0;
|
||||||
_max_slow_allocations = 0;
|
_max_slow_allocations = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GlobalTLABStats::publish() {
|
void ThreadLocalAllocStats::publish() {
|
||||||
_allocating_threads_avg.sample(_allocating_threads);
|
if (_total_allocations == 0) {
|
||||||
if (UsePerfData) {
|
|
||||||
_perf_allocating_threads ->set_value(_allocating_threads);
|
|
||||||
_perf_total_refills ->set_value(_total_refills);
|
|
||||||
_perf_max_refills ->set_value(_max_refills);
|
|
||||||
_perf_allocation ->set_value(_total_allocation);
|
|
||||||
_perf_gc_waste ->set_value(_total_gc_waste);
|
|
||||||
_perf_max_gc_waste ->set_value(_max_gc_waste);
|
|
||||||
_perf_slow_refill_waste ->set_value(_total_slow_refill_waste);
|
|
||||||
_perf_max_slow_refill_waste->set_value(_max_slow_refill_waste);
|
|
||||||
_perf_fast_refill_waste ->set_value(_total_fast_refill_waste);
|
|
||||||
_perf_max_fast_refill_waste->set_value(_max_fast_refill_waste);
|
|
||||||
_perf_slow_allocations ->set_value(_total_slow_allocations);
|
|
||||||
_perf_max_slow_allocations ->set_value(_max_slow_allocations);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void GlobalTLABStats::print() {
|
|
||||||
Log(gc, tlab) log;
|
|
||||||
if (!log.is_debug()) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t waste = _total_gc_waste + _total_slow_refill_waste + _total_fast_refill_waste;
|
_allocating_threads_avg.sample(_allocating_threads);
|
||||||
double waste_percent = percent_of(waste, _total_allocation);
|
|
||||||
log.debug("TLAB totals: thrds: %d refills: %d max: %d"
|
const size_t waste = _total_gc_waste + _total_slow_refill_waste + _total_fast_refill_waste;
|
||||||
|
const double waste_percent = percent_of(waste, _total_allocations);
|
||||||
|
log_debug(gc, tlab)("TLAB totals: thrds: %d refills: %d max: %d"
|
||||||
" slow allocs: %d max %d waste: %4.1f%%"
|
" slow allocs: %d max %d waste: %4.1f%%"
|
||||||
" gc: " SIZE_FORMAT "B max: " SIZE_FORMAT "B"
|
" gc: " SIZE_FORMAT "B max: " SIZE_FORMAT "B"
|
||||||
" slow: " SIZE_FORMAT "B max: " SIZE_FORMAT "B"
|
" slow: " SIZE_FORMAT "B max: " SIZE_FORMAT "B"
|
||||||
" fast: " SIZE_FORMAT "B max: " SIZE_FORMAT "B",
|
" fast: " SIZE_FORMAT "B max: " SIZE_FORMAT "B",
|
||||||
_allocating_threads,
|
_allocating_threads, _total_refills, _max_refills,
|
||||||
_total_refills, _max_refills,
|
_total_slow_allocations, _max_slow_allocations, waste_percent,
|
||||||
_total_slow_allocations, _max_slow_allocations,
|
_total_gc_waste * HeapWordSize, _max_gc_waste * HeapWordSize,
|
||||||
waste_percent,
|
_total_slow_refill_waste * HeapWordSize, _max_slow_refill_waste * HeapWordSize,
|
||||||
_total_gc_waste * HeapWordSize,
|
_total_fast_refill_waste * HeapWordSize, _max_fast_refill_waste * HeapWordSize);
|
||||||
_max_gc_waste * HeapWordSize,
|
|
||||||
_total_slow_refill_waste * HeapWordSize,
|
if (UsePerfData) {
|
||||||
_max_slow_refill_waste * HeapWordSize,
|
_perf_allocating_threads ->set_value(_allocating_threads);
|
||||||
_total_fast_refill_waste * HeapWordSize,
|
_perf_total_refills ->set_value(_total_refills);
|
||||||
_max_fast_refill_waste * HeapWordSize);
|
_perf_max_refills ->set_value(_max_refills);
|
||||||
|
_perf_total_allocations ->set_value(_total_allocations);
|
||||||
|
_perf_total_gc_waste ->set_value(_total_gc_waste);
|
||||||
|
_perf_max_gc_waste ->set_value(_max_gc_waste);
|
||||||
|
_perf_total_slow_refill_waste ->set_value(_total_slow_refill_waste);
|
||||||
|
_perf_max_slow_refill_waste ->set_value(_max_slow_refill_waste);
|
||||||
|
_perf_total_fast_refill_waste ->set_value(_total_fast_refill_waste);
|
||||||
|
_perf_max_fast_refill_waste ->set_value(_max_fast_refill_waste);
|
||||||
|
_perf_total_slow_allocations ->set_value(_total_slow_allocations);
|
||||||
|
_perf_max_slow_allocations ->set_value(_max_slow_allocations);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
#include "runtime/perfData.hpp"
|
#include "runtime/perfData.hpp"
|
||||||
#include "runtime/vm_version.hpp"
|
#include "runtime/vm_version.hpp"
|
||||||
|
|
||||||
class GlobalTLABStats;
|
class ThreadLocalAllocStats;
|
||||||
|
|
||||||
// ThreadLocalAllocBuffer: a descriptor for thread-local storage used by
|
// ThreadLocalAllocBuffer: a descriptor for thread-local storage used by
|
||||||
// the threads for allocation.
|
// the threads for allocation.
|
||||||
|
@ -71,8 +71,7 @@ private:
|
||||||
|
|
||||||
AdaptiveWeightedAverage _allocation_fraction; // fraction of eden allocated in tlabs
|
AdaptiveWeightedAverage _allocation_fraction; // fraction of eden allocated in tlabs
|
||||||
|
|
||||||
void accumulate_statistics();
|
void reset_statistics();
|
||||||
void initialize_statistics();
|
|
||||||
|
|
||||||
void set_start(HeapWord* start) { _start = start; }
|
void set_start(HeapWord* start) { _start = start; }
|
||||||
void set_end(HeapWord* end) { _end = end; }
|
void set_end(HeapWord* end) { _end = end; }
|
||||||
|
@ -96,6 +95,10 @@ private:
|
||||||
|
|
||||||
void initialize(HeapWord* start, HeapWord* top, HeapWord* end);
|
void initialize(HeapWord* start, HeapWord* top, HeapWord* end);
|
||||||
|
|
||||||
|
void insert_filler();
|
||||||
|
|
||||||
|
void accumulate_and_reset_statistics(ThreadLocalAllocStats* stats);
|
||||||
|
|
||||||
void print_stats(const char* tag);
|
void print_stats(const char* tag);
|
||||||
|
|
||||||
Thread* thread();
|
Thread* thread();
|
||||||
|
@ -108,9 +111,6 @@ private:
|
||||||
int gc_waste() const { return _gc_waste; }
|
int gc_waste() const { return _gc_waste; }
|
||||||
int slow_allocations() const { return _slow_allocations; }
|
int slow_allocations() const { return _slow_allocations; }
|
||||||
|
|
||||||
static GlobalTLABStats* _global_stats;
|
|
||||||
static GlobalTLABStats* global_stats() { return _global_stats; }
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ThreadLocalAllocBuffer() : _allocated_before_last_gc(0), _allocation_fraction(TLABAllocationWeight) {
|
ThreadLocalAllocBuffer() : _allocated_before_last_gc(0), _allocation_fraction(TLABAllocationWeight) {
|
||||||
// do nothing. tlabs must be inited by initialize() calls
|
// do nothing. tlabs must be inited by initialize() calls
|
||||||
|
@ -159,18 +159,18 @@ public:
|
||||||
// Initialization at startup
|
// Initialization at startup
|
||||||
static void startup_initialization();
|
static void startup_initialization();
|
||||||
|
|
||||||
// Make an in-use tlab parsable, optionally retiring and/or zapping it.
|
// Make an in-use tlab parsable.
|
||||||
void make_parsable(bool retire, bool zap = true);
|
void make_parsable();
|
||||||
|
|
||||||
|
// Retire an in-use tlab and optionally collect statistics.
|
||||||
|
void retire(ThreadLocalAllocStats* stats = NULL);
|
||||||
|
|
||||||
// Retire in-use tlab before allocation of a new tlab
|
// Retire in-use tlab before allocation of a new tlab
|
||||||
void clear_before_allocation();
|
void retire_before_allocation();
|
||||||
|
|
||||||
// Resize based on amount of allocation, etc.
|
// Resize based on amount of allocation, etc.
|
||||||
void resize();
|
void resize();
|
||||||
|
|
||||||
// Accumulate statistics across all tlabs before gc
|
|
||||||
static void accumulate_statistics_before_gc();
|
|
||||||
|
|
||||||
void fill(HeapWord* start, HeapWord* top, size_t new_size);
|
void fill(HeapWord* start, HeapWord* top, size_t new_size);
|
||||||
void initialize();
|
void initialize();
|
||||||
|
|
||||||
|
@ -196,88 +196,52 @@ public:
|
||||||
void verify();
|
void verify();
|
||||||
};
|
};
|
||||||
|
|
||||||
class GlobalTLABStats: public CHeapObj<mtThread> {
|
class ThreadLocalAllocStats : public StackObj {
|
||||||
private:
|
private:
|
||||||
|
static PerfVariable* _perf_allocating_threads;
|
||||||
|
static PerfVariable* _perf_total_refills;
|
||||||
|
static PerfVariable* _perf_max_refills;
|
||||||
|
static PerfVariable* _perf_total_allocations;
|
||||||
|
static PerfVariable* _perf_total_gc_waste;
|
||||||
|
static PerfVariable* _perf_max_gc_waste;
|
||||||
|
static PerfVariable* _perf_total_slow_refill_waste;
|
||||||
|
static PerfVariable* _perf_max_slow_refill_waste;
|
||||||
|
static PerfVariable* _perf_total_fast_refill_waste;
|
||||||
|
static PerfVariable* _perf_max_fast_refill_waste;
|
||||||
|
static PerfVariable* _perf_total_slow_allocations;
|
||||||
|
static PerfVariable* _perf_max_slow_allocations;
|
||||||
|
|
||||||
// Accumulate perfdata in private variables because
|
static AdaptiveWeightedAverage _allocating_threads_avg;
|
||||||
// PerfData should be write-only for security reasons
|
|
||||||
// (see perfData.hpp)
|
unsigned int _allocating_threads;
|
||||||
unsigned _allocating_threads;
|
unsigned int _total_refills;
|
||||||
unsigned _total_refills;
|
unsigned int _max_refills;
|
||||||
unsigned _max_refills;
|
size_t _total_allocations;
|
||||||
size_t _total_allocation;
|
|
||||||
size_t _total_gc_waste;
|
size_t _total_gc_waste;
|
||||||
size_t _max_gc_waste;
|
size_t _max_gc_waste;
|
||||||
size_t _total_slow_refill_waste;
|
|
||||||
size_t _max_slow_refill_waste;
|
|
||||||
size_t _total_fast_refill_waste;
|
size_t _total_fast_refill_waste;
|
||||||
size_t _max_fast_refill_waste;
|
size_t _max_fast_refill_waste;
|
||||||
unsigned _total_slow_allocations;
|
size_t _total_slow_refill_waste;
|
||||||
unsigned _max_slow_allocations;
|
size_t _max_slow_refill_waste;
|
||||||
|
unsigned int _total_slow_allocations;
|
||||||
PerfVariable* _perf_allocating_threads;
|
unsigned int _max_slow_allocations;
|
||||||
PerfVariable* _perf_total_refills;
|
|
||||||
PerfVariable* _perf_max_refills;
|
|
||||||
PerfVariable* _perf_allocation;
|
|
||||||
PerfVariable* _perf_gc_waste;
|
|
||||||
PerfVariable* _perf_max_gc_waste;
|
|
||||||
PerfVariable* _perf_slow_refill_waste;
|
|
||||||
PerfVariable* _perf_max_slow_refill_waste;
|
|
||||||
PerfVariable* _perf_fast_refill_waste;
|
|
||||||
PerfVariable* _perf_max_fast_refill_waste;
|
|
||||||
PerfVariable* _perf_slow_allocations;
|
|
||||||
PerfVariable* _perf_max_slow_allocations;
|
|
||||||
|
|
||||||
AdaptiveWeightedAverage _allocating_threads_avg;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GlobalTLABStats();
|
static void initialize();
|
||||||
|
static unsigned int allocating_threads_avg();
|
||||||
|
|
||||||
// Initialize all counters
|
ThreadLocalAllocStats();
|
||||||
void initialize();
|
|
||||||
|
|
||||||
// Write all perf counters to the perf_counters
|
void update_fast_allocations(unsigned int refills,
|
||||||
|
size_t allocations,
|
||||||
|
size_t gc_waste,
|
||||||
|
size_t fast_refill_waste,
|
||||||
|
size_t slow_refill_waste);
|
||||||
|
void update_slow_allocations(unsigned int allocations);
|
||||||
|
void update(const ThreadLocalAllocStats& other);
|
||||||
|
|
||||||
|
void reset();
|
||||||
void publish();
|
void publish();
|
||||||
|
|
||||||
void print();
|
|
||||||
|
|
||||||
// Accessors
|
|
||||||
unsigned allocating_threads_avg() {
|
|
||||||
return MAX2((unsigned)(_allocating_threads_avg.average() + 0.5), 1U);
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t allocation() {
|
|
||||||
return _total_allocation;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update methods
|
|
||||||
|
|
||||||
void update_allocating_threads() {
|
|
||||||
_allocating_threads++;
|
|
||||||
}
|
|
||||||
void update_number_of_refills(unsigned value) {
|
|
||||||
_total_refills += value;
|
|
||||||
_max_refills = MAX2(_max_refills, value);
|
|
||||||
}
|
|
||||||
void update_allocation(size_t value) {
|
|
||||||
_total_allocation += value;
|
|
||||||
}
|
|
||||||
void update_gc_waste(size_t value) {
|
|
||||||
_total_gc_waste += value;
|
|
||||||
_max_gc_waste = MAX2(_max_gc_waste, value);
|
|
||||||
}
|
|
||||||
void update_fast_refill_waste(size_t value) {
|
|
||||||
_total_fast_refill_waste += value;
|
|
||||||
_max_fast_refill_waste = MAX2(_max_fast_refill_waste, value);
|
|
||||||
}
|
|
||||||
void update_slow_refill_waste(size_t value) {
|
|
||||||
_total_slow_refill_waste += value;
|
|
||||||
_max_slow_refill_waste = MAX2(_max_slow_refill_waste, value);
|
|
||||||
}
|
|
||||||
void update_slow_allocations(unsigned value) {
|
|
||||||
_total_slow_allocations += value;
|
|
||||||
_max_slow_allocations = MAX2(_max_slow_allocations, value);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SHARE_VM_GC_SHARED_THREADLOCALALLOCBUFFER_HPP
|
#endif // SHARE_VM_GC_SHARED_THREADLOCALALLOCBUFFER_HPP
|
||||||
|
|
|
@ -1989,7 +1989,7 @@ void JavaThread::exit(bool destroy_vm, ExitType exit_type) {
|
||||||
remove_stack_guard_pages();
|
remove_stack_guard_pages();
|
||||||
|
|
||||||
if (UseTLAB) {
|
if (UseTLAB) {
|
||||||
tlab().make_parsable(true); // retire TLAB
|
tlab().retire();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (JvmtiEnv::environments_might_exist()) {
|
if (JvmtiEnv::environments_might_exist()) {
|
||||||
|
@ -2045,7 +2045,7 @@ void JavaThread::cleanup_failed_attach_current_thread() {
|
||||||
remove_stack_guard_pages();
|
remove_stack_guard_pages();
|
||||||
|
|
||||||
if (UseTLAB) {
|
if (UseTLAB) {
|
||||||
tlab().make_parsable(true); // retire TLAB, if any
|
tlab().retire();
|
||||||
}
|
}
|
||||||
|
|
||||||
BarrierSet::barrier_set()->on_thread_detach(this);
|
BarrierSet::barrier_set()->on_thread_detach(this);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue