< prev index next >
src/share/vm/gc/shared/threadLocalAllocBuffer.cpp
Print this page
rev 8961 : [mq]: diff-shenandoah.patch
@@ -49,10 +49,12 @@
for (JavaThread *thread = Threads::first(); thread != NULL; thread = thread->next()) {
thread->tlab().accumulate_statistics();
thread->tlab().initialize_statistics();
}
+ Universe::heap()->accumulate_statistics_all_gclabs();
+
// Publish new stats if some allocation occurred.
if (global_stats()->allocation() != 0) {
global_stats()->publish();
if (PrintTLAB) {
global_stats()->print();
@@ -64,11 +66,11 @@
Thread* thread = myThread();
size_t capacity = Universe::heap()->tlab_capacity(thread);
size_t used = Universe::heap()->tlab_used(thread);
_gc_waste += (unsigned)remaining();
- size_t total_allocated = thread->allocated_bytes();
+ size_t total_allocated = _gclab ? thread->allocated_bytes_gclab() : thread->allocated_bytes();
size_t allocated_since_last_gc = total_allocated - _allocated_before_last_gc;
_allocated_before_last_gc = total_allocated;
if (PrintTLAB && (_number_of_refills > 0 || Verbose)) {
print_stats("gc");
@@ -111,14 +113,19 @@
void ThreadLocalAllocBuffer::make_parsable(bool retire) {
if (end() != NULL) {
invariants();
if (retire) {
+ if (_gclab) {
+ myThread()->incr_allocated_bytes_gclab(used_bytes());
+ } else {
myThread()->incr_allocated_bytes(used_bytes());
}
+ }
- CollectedHeap::fill_with_object(top(), hard_end(), retire);
+ HeapWord* obj = Universe::heap()->tlab_post_allocation_setup(top());
+ CollectedHeap::fill_with_object(obj, hard_end(), retire);
if (retire || ZeroTLAB) { // "Reset" the TLAB
set_start(NULL);
set_top(NULL);
set_pf_top(NULL);
@@ -189,11 +196,12 @@
set_pf_top(top);
set_end(end);
invariants();
}
-void ThreadLocalAllocBuffer::initialize() {
+void ThreadLocalAllocBuffer::initialize(bool gclab) {
+ _gclab = gclab;
initialize(NULL, // start
NULL, // top
NULL); // end
set_desired_size(initial_desired_size());
@@ -222,11 +230,12 @@
_global_stats = new GlobalTLABStats();
// During jvm startup, the main (primordial) thread is initialized
// before the heap is initialized. So reinitialize it now.
guarantee(Thread::current()->is_Java_thread(), "tlab initialization thread not Java thread");
- Thread::current()->tlab().initialize();
+ Thread::current()->tlab().initialize(false);
+ Thread::current()->gclab().initialize(true);
if (PrintTLAB && Verbose) {
gclog_or_tty->print("TLAB min: " SIZE_FORMAT " initial: " SIZE_FORMAT " max: " SIZE_FORMAT "\n",
min_size(), Thread::current()->tlab().initial_desired_size(), max_size());
}
@@ -254,16 +263,16 @@
size_t waste = _gc_waste + _slow_refill_waste + _fast_refill_waste;
size_t alloc = _number_of_refills * _desired_size;
double waste_percent = alloc == 0 ? 0.0 :
100.0 * waste / alloc;
size_t tlab_used = Universe::heap()->tlab_used(thrd);
- gclog_or_tty->print("TLAB: %s thread: " INTPTR_FORMAT " [id: %2d]"
+ gclog_or_tty->print("TLAB: %s %s thread: " INTPTR_FORMAT " [id: %2d]"
" desired_size: " SIZE_FORMAT "KB"
" slow allocs: %d refill waste: " SIZE_FORMAT "B"
" alloc:%8.5f %8.0fKB refills: %d waste %4.1f%% gc: %dB"
" slow: %dB fast: %dB\n",
- tag, p2i(thrd), thrd->osthread()->thread_id(),
+ tag, _gclab ? "gclab" : "tlab ", p2i(thrd), thrd->osthread()->thread_id(),
_desired_size / (K / HeapWordSize),
_slow_allocations, _refill_waste_limit * HeapWordSize,
_allocation_fraction.average(),
_allocation_fraction.average() * tlab_used / K,
_number_of_refills, waste_percent,
@@ -283,13 +292,31 @@
}
guarantee(p == top(), "end of last object must match end of space");
}
Thread* ThreadLocalAllocBuffer::myThread() {
- return (Thread*)(((char *)this) +
- in_bytes(start_offset()) -
- in_bytes(Thread::tlab_start_offset()));
+ ByteSize gclab_offset = Thread::gclab_start_offset();
+ ByteSize tlab_offset = Thread::tlab_start_offset();
+ ByteSize offs = _gclab ? gclab_offset : tlab_offset;
+ Thread* thread = (Thread*)(((char *)this) +
+ in_bytes(start_offset()) - in_bytes(offs));
+#ifdef ASSERT
+ assert(this == (_gclab ? &thread->gclab() : &thread->tlab()), "must be");
+#endif
+ return thread;
+}
+
+size_t ThreadLocalAllocBuffer::end_reserve() {
+ int reserve_size = typeArrayOopDesc::header_size(T_INT) + Universe::heap()->oop_extra_words();
+ return MAX2(reserve_size, VM_Version::reserve_for_allocation_prefetch());
+}
+
+void ThreadLocalAllocBuffer::rollback(size_t size) {
+ HeapWord* old_top = top();
+ if (old_top != NULL) { // Pathological case: we accept that we can't rollback.
+ set_top(old_top - size);
+ }
}
GlobalTLABStats::GlobalTLABStats() :
_allocating_threads_avg(TLABAllocationWeight) {
< prev index next >