File tree 3 files changed +21
-1
lines changed
3 files changed +21
-1
lines changed Original file line number Diff line number Diff line change 31
31
#include " memory/resourceArea.hpp"
32
32
#include " memory/universe.hpp"
33
33
#include " oops/oop.inline.hpp"
34
+ #include " runtime/atomic.hpp"
34
35
#include " runtime/perfData.hpp"
35
36
#include " runtime/thread.inline.hpp"
36
37
#include " runtime/threadSMR.hpp"
@@ -473,3 +474,11 @@ size_t ThreadLocalAllocBuffer::end_reserve() {
473
474
size_t reserve_size = Universe::heap ()->tlab_alloc_reserve ();
474
475
return MAX2 (reserve_size, (size_t )_reserve_for_allocation_prefetch);
475
476
}
477
+
478
+ const HeapWord* ThreadLocalAllocBuffer::start_relaxed () const {
479
+ return Atomic::load (&_start);
480
+ }
481
+
482
+ const HeapWord* ThreadLocalAllocBuffer::top_relaxed () const {
483
+ return Atomic::load (&_top);
484
+ }
Original file line number Diff line number Diff line change @@ -129,6 +129,10 @@ class ThreadLocalAllocBuffer: public CHeapObj<mtThread> {
129
129
size_t refill_waste_limit () const { return _refill_waste_limit; }
130
130
size_t bytes_since_last_sample_point () const { return _bytes_since_last_sample_point; }
131
131
132
+ // For external inspection.
133
+ const HeapWord* start_relaxed () const ;
134
+ const HeapWord* top_relaxed () const ;
135
+
132
136
// Allocate size HeapWords. The memory is NOT initialized to zero.
133
137
inline HeapWord* allocate (size_t size);
134
138
Original file line number Diff line number Diff line change 41
41
inline jlong Thread::cooked_allocated_bytes () {
42
42
jlong allocated_bytes = Atomic::load_acquire (&_allocated_bytes);
43
43
if (UseTLAB) {
44
- size_t used_bytes = tlab ().used_bytes ();
44
+ // These reads are unsynchronized and unordered with the thread updating its tlab pointers.
45
+ // Use only if top > start && used_bytes <= max_tlab_size_bytes.
46
+ const HeapWord* const top = tlab ().top_relaxed ();
47
+ const HeapWord* const start = tlab ().start_relaxed ();
48
+ if (top <= start) {
49
+ return allocated_bytes;
50
+ }
51
+ const size_t used_bytes = pointer_delta (top, start, 1 );
45
52
if (used_bytes <= ThreadLocalAllocBuffer::max_size_in_bytes ()) {
46
53
// Comparing used_bytes with the maximum allowed size will ensure
47
54
// that we don't add the used bytes from a semi-initialized TLAB
You can’t perform that action at this time.
0 commit comments