32 #include "runtime/thread.inline.hpp"
33 #include "runtime/threadSMR.hpp"
34 #include "utilities/copy.hpp"
35
36 // Thread-Local Edens support
37
38 // static member initialization
39 size_t ThreadLocalAllocBuffer::_max_size = 0;
40 int ThreadLocalAllocBuffer::_reserve_for_allocation_prefetch = 0;
41 unsigned ThreadLocalAllocBuffer::_target_refills = 0;
42 GlobalTLABStats* ThreadLocalAllocBuffer::_global_stats = NULL;
43
44 void ThreadLocalAllocBuffer::clear_before_allocation() {
45 _slow_refill_waste += (unsigned)remaining();
46 make_parsable(true); // also retire the TLAB
47 }
48
49 void ThreadLocalAllocBuffer::accumulate_statistics_before_gc() {
50 global_stats()->initialize();
51
52 {
53 ThreadsListHandle tlh;
54 JavaThreadIterator jti(tlh.list());
55 for (JavaThread *thread = jti.first(); thread != NULL; thread = jti.next()) {
56 thread->tlab().accumulate_statistics();
57 thread->tlab().initialize_statistics();
58 }
59 }
60
61 // Publish new stats if some allocation occurred.
62 if (global_stats()->allocation() != 0) {
63 global_stats()->publish();
64 global_stats()->print();
65 }
66 }
67
68 void ThreadLocalAllocBuffer::accumulate_statistics() {
69 Thread* thread = myThread();
70 size_t capacity = Universe::heap()->tlab_capacity(thread);
71 size_t used = Universe::heap()->tlab_used(thread);
72
73 _gc_waste += (unsigned)remaining();
74 size_t total_allocated = thread->allocated_bytes();
75 size_t allocated_since_last_gc = total_allocated - _allocated_before_last_gc;
76 _allocated_before_last_gc = total_allocated;
77
78 print_stats("gc");
79
118 if (retire) {
119 myThread()->incr_allocated_bytes(used_bytes());
120 }
121
122 CollectedHeap::fill_with_object(top(), hard_end(), retire && zap);
123
124 if (retire || ZeroTLAB) { // "Reset" the TLAB
125 set_start(NULL);
126 set_top(NULL);
127 set_pf_top(NULL);
128 set_end(NULL);
129 }
130 }
131 assert(!(retire || ZeroTLAB) ||
132 (start() == NULL && end() == NULL && top() == NULL),
133 "TLAB must be reset");
134 }
135
136 void ThreadLocalAllocBuffer::resize_all_tlabs() {
137 if (ResizeTLAB) {
138 ThreadsListHandle tlh;
139 JavaThreadIterator jti(tlh.list());
140 for (JavaThread *thread = jti.first(); thread != NULL; thread = jti.next()) {
141 thread->tlab().resize();
142 }
143 }
144 }
145
146 void ThreadLocalAllocBuffer::resize() {
147 // Compute the next tlab size using expected allocation amount
148 assert(ResizeTLAB, "Should not call this otherwise");
149 size_t alloc = (size_t)(_allocation_fraction.average() *
150 (Universe::heap()->tlab_capacity(myThread()) / HeapWordSize));
151 size_t new_size = alloc / _target_refills;
152
153 new_size = MIN2(MAX2(new_size, min_size()), max_size());
154
155 size_t aligned_new_size = align_object_size(new_size);
156
157 log_trace(gc, tlab)("TLAB new size: thread: " INTPTR_FORMAT " [id: %2d]"
158 " refills %d alloc: %8.6f desired_size: " SIZE_FORMAT " -> " SIZE_FORMAT,
159 p2i(myThread()), myThread()->osthread()->thread_id(),
160 _target_refills, _allocation_fraction.average(), desired_size(), aligned_new_size);
|
32 #include "runtime/thread.inline.hpp"
33 #include "runtime/threadSMR.hpp"
34 #include "utilities/copy.hpp"
35
36 // Thread-Local Edens support
37
38 // static member initialization
39 size_t ThreadLocalAllocBuffer::_max_size = 0;
40 int ThreadLocalAllocBuffer::_reserve_for_allocation_prefetch = 0;
41 unsigned ThreadLocalAllocBuffer::_target_refills = 0;
42 GlobalTLABStats* ThreadLocalAllocBuffer::_global_stats = NULL;
43
44 void ThreadLocalAllocBuffer::clear_before_allocation() {
45 _slow_refill_waste += (unsigned)remaining();
46 make_parsable(true); // also retire the TLAB
47 }
48
49 void ThreadLocalAllocBuffer::accumulate_statistics_before_gc() {
50 global_stats()->initialize();
51
52 for (JavaThreadIteratorWithHandle jtiwh; JavaThread *thread = jtiwh.next(); ) {
53 thread->tlab().accumulate_statistics();
54 thread->tlab().initialize_statistics();
55 }
56
57 // Publish new stats if some allocation occurred.
58 if (global_stats()->allocation() != 0) {
59 global_stats()->publish();
60 global_stats()->print();
61 }
62 }
63
64 void ThreadLocalAllocBuffer::accumulate_statistics() {
65 Thread* thread = myThread();
66 size_t capacity = Universe::heap()->tlab_capacity(thread);
67 size_t used = Universe::heap()->tlab_used(thread);
68
69 _gc_waste += (unsigned)remaining();
70 size_t total_allocated = thread->allocated_bytes();
71 size_t allocated_since_last_gc = total_allocated - _allocated_before_last_gc;
72 _allocated_before_last_gc = total_allocated;
73
74 print_stats("gc");
75
114 if (retire) {
115 myThread()->incr_allocated_bytes(used_bytes());
116 }
117
118 CollectedHeap::fill_with_object(top(), hard_end(), retire && zap);
119
120 if (retire || ZeroTLAB) { // "Reset" the TLAB
121 set_start(NULL);
122 set_top(NULL);
123 set_pf_top(NULL);
124 set_end(NULL);
125 }
126 }
127 assert(!(retire || ZeroTLAB) ||
128 (start() == NULL && end() == NULL && top() == NULL),
129 "TLAB must be reset");
130 }
131
132 void ThreadLocalAllocBuffer::resize_all_tlabs() {
133 if (ResizeTLAB) {
134 for (JavaThreadIteratorWithHandle jtiwh; JavaThread *thread = jtiwh.next(); ) {
135 thread->tlab().resize();
136 }
137 }
138 }
139
140 void ThreadLocalAllocBuffer::resize() {
141 // Compute the next tlab size using expected allocation amount
142 assert(ResizeTLAB, "Should not call this otherwise");
143 size_t alloc = (size_t)(_allocation_fraction.average() *
144 (Universe::heap()->tlab_capacity(myThread()) / HeapWordSize));
145 size_t new_size = alloc / _target_refills;
146
147 new_size = MIN2(MAX2(new_size, min_size()), max_size());
148
149 size_t aligned_new_size = align_object_size(new_size);
150
151 log_trace(gc, tlab)("TLAB new size: thread: " INTPTR_FORMAT " [id: %2d]"
152 " refills %d alloc: %8.6f desired_size: " SIZE_FORMAT " -> " SIZE_FORMAT,
153 p2i(myThread()), myThread()->osthread()->thread_id(),
154 _target_refills, _allocation_fraction.average(), desired_size(), aligned_new_size);
|