Mercurial > hg > truffle
comparison src/share/vm/memory/threadLocalAllocBuffer.cpp @ 14518:d8041d695d19
Merged with jdk9/dev/hotspot changeset 3812c088b945
author | twisti |
---|---|
date | Tue, 11 Mar 2014 18:45:59 -0700 |
parents | 86b4965f0c9a 1e1c8d358b52 |
children | 4ca6dc0799b6 |
comparison
equal
deleted
inserted
replaced
14141:f97c5ec83832 | 14518:d8041d695d19 |
---|---|
32 #include "utilities/copy.hpp" | 32 #include "utilities/copy.hpp" |
33 | 33 |
34 // Thread-Local Edens support | 34 // Thread-Local Edens support |
35 | 35 |
36 // static member initialization | 36 // static member initialization |
37 size_t ThreadLocalAllocBuffer::_max_size = 0; | |
37 unsigned ThreadLocalAllocBuffer::_target_refills = 0; | 38 unsigned ThreadLocalAllocBuffer::_target_refills = 0; |
38 GlobalTLABStats* ThreadLocalAllocBuffer::_global_stats = NULL; | 39 GlobalTLABStats* ThreadLocalAllocBuffer::_global_stats = NULL; |
39 | 40 |
40 void ThreadLocalAllocBuffer::clear_before_allocation() { | 41 void ThreadLocalAllocBuffer::clear_before_allocation() { |
41 _slow_refill_waste += (unsigned)remaining(); | 42 _slow_refill_waste += (unsigned)remaining(); |
43 } | 44 } |
44 | 45 |
45 void ThreadLocalAllocBuffer::accumulate_statistics_before_gc() { | 46 void ThreadLocalAllocBuffer::accumulate_statistics_before_gc() { |
46 global_stats()->initialize(); | 47 global_stats()->initialize(); |
47 | 48 |
48 for(JavaThread *thread = Threads::first(); thread; thread = thread->next()) { | 49 for (JavaThread *thread = Threads::first(); thread != NULL; thread = thread->next()) { |
49 thread->tlab().accumulate_statistics(); | 50 thread->tlab().accumulate_statistics(); |
50 thread->tlab().initialize_statistics(); | 51 thread->tlab().initialize_statistics(); |
51 } | 52 } |
52 | 53 |
53 // Publish new stats if some allocation occurred. | 54 // Publish new stats if some allocation occurred. |
58 } | 59 } |
59 } | 60 } |
60 } | 61 } |
61 | 62 |
62 void ThreadLocalAllocBuffer::accumulate_statistics() { | 63 void ThreadLocalAllocBuffer::accumulate_statistics() { |
63 size_t capacity = Universe::heap()->tlab_capacity(myThread()) / HeapWordSize; | 64 Thread* thread = myThread(); |
64 size_t unused = Universe::heap()->unsafe_max_tlab_alloc(myThread()) / HeapWordSize; | 65 size_t capacity = Universe::heap()->tlab_capacity(thread); |
65 size_t used = capacity - unused; | 66 size_t used = Universe::heap()->tlab_used(thread); |
66 | |
67 // Update allocation history if a reasonable amount of eden was allocated. | |
68 bool update_allocation_history = used > 0.5 * capacity; | |
69 | 67 |
70 _gc_waste += (unsigned)remaining(); | 68 _gc_waste += (unsigned)remaining(); |
69 size_t total_allocated = thread->allocated_bytes(); | |
70 size_t allocated_since_last_gc = total_allocated - _allocated_before_last_gc; | |
71 _allocated_before_last_gc = total_allocated; | |
71 | 72 |
72 if (PrintTLAB && (_number_of_refills > 0 || Verbose)) { | 73 if (PrintTLAB && (_number_of_refills > 0 || Verbose)) { |
73 print_stats("gc"); | 74 print_stats("gc"); |
74 } | 75 } |
75 | 76 |
76 if (_number_of_refills > 0) { | 77 if (_number_of_refills > 0) { |
78 // Update allocation history if a reasonable amount of eden was allocated. | |
79 bool update_allocation_history = used > 0.5 * capacity; | |
77 | 80 |
78 if (update_allocation_history) { | 81 if (update_allocation_history) { |
79 // Average the fraction of eden allocated in a tlab by this | 82 // Average the fraction of eden allocated in a tlab by this |
80 // thread for use in the next resize operation. | 83 // thread for use in the next resize operation. |
81 // _gc_waste is not subtracted because it's included in | 84 // _gc_waste is not subtracted because it's included in |
82 // "used". | 85 // "used". |
83 size_t allocation = _number_of_refills * desired_size(); | 86 // The result can be larger than 1.0 due to direct to old allocations. |
84 double alloc_frac = allocation / (double) used; | 87 // These allocations should ideally not be counted but since it is not possible |
88 // to filter them out here we just cap the fraction to be at most 1.0. | |
89 double alloc_frac = MIN2(1.0, (double) allocated_since_last_gc / used); | |
85 _allocation_fraction.sample(alloc_frac); | 90 _allocation_fraction.sample(alloc_frac); |
86 } | 91 } |
87 global_stats()->update_allocating_threads(); | 92 global_stats()->update_allocating_threads(); |
88 global_stats()->update_number_of_refills(_number_of_refills); | 93 global_stats()->update_number_of_refills(_number_of_refills); |
89 global_stats()->update_allocation(_number_of_refills * desired_size()); | 94 global_stats()->update_allocation(_number_of_refills * desired_size()); |
125 (start() == NULL && end() == NULL && top() == NULL), | 130 (start() == NULL && end() == NULL && top() == NULL), |
126 "TLAB must be reset"); | 131 "TLAB must be reset"); |
127 } | 132 } |
128 | 133 |
129 void ThreadLocalAllocBuffer::resize_all_tlabs() { | 134 void ThreadLocalAllocBuffer::resize_all_tlabs() { |
130 for(JavaThread *thread = Threads::first(); thread; thread = thread->next()) { | 135 if (ResizeTLAB) { |
131 thread->tlab().resize(); | 136 for (JavaThread *thread = Threads::first(); thread != NULL; thread = thread->next()) { |
137 thread->tlab().resize(); | |
138 } | |
132 } | 139 } |
133 } | 140 } |
134 | 141 |
135 void ThreadLocalAllocBuffer::resize() { | 142 void ThreadLocalAllocBuffer::resize() { |
136 | 143 // Compute the next tlab size using expected allocation amount |
137 if (ResizeTLAB) { | 144 assert(ResizeTLAB, "Should not call this otherwise"); |
138 // Compute the next tlab size using expected allocation amount | 145 size_t alloc = (size_t)(_allocation_fraction.average() * |
139 size_t alloc = (size_t)(_allocation_fraction.average() * | 146 (Universe::heap()->tlab_capacity(myThread()) / HeapWordSize)); |
140 (Universe::heap()->tlab_capacity(myThread()) / HeapWordSize)); | 147 size_t new_size = alloc / _target_refills; |
141 size_t new_size = alloc / _target_refills; | 148 |
142 | 149 new_size = MIN2(MAX2(new_size, min_size()), max_size()); |
143 new_size = MIN2(MAX2(new_size, min_size()), max_size()); | 150 |
144 | 151 size_t aligned_new_size = align_object_size(new_size); |
145 size_t aligned_new_size = align_object_size(new_size); | 152 |
146 | 153 if (PrintTLAB && Verbose) { |
147 if (PrintTLAB && Verbose) { | 154 gclog_or_tty->print("TLAB new size: thread: " INTPTR_FORMAT " [id: %2d]" |
148 gclog_or_tty->print("TLAB new size: thread: " INTPTR_FORMAT " [id: %2d]" | 155 " refills %d alloc: %8.6f desired_size: " SIZE_FORMAT " -> " SIZE_FORMAT "\n", |
149 " refills %d alloc: %8.6f desired_size: " SIZE_FORMAT " -> " SIZE_FORMAT "\n", | 156 myThread(), myThread()->osthread()->thread_id(), |
150 myThread(), myThread()->osthread()->thread_id(), | 157 _target_refills, _allocation_fraction.average(), desired_size(), aligned_new_size); |
151 _target_refills, _allocation_fraction.average(), desired_size(), aligned_new_size); | 158 } |
152 } | 159 set_desired_size(aligned_new_size); |
153 set_desired_size(aligned_new_size); | 160 set_refill_waste_limit(initial_refill_waste_limit()); |
154 | |
155 set_refill_waste_limit(initial_refill_waste_limit()); | |
156 } | |
157 } | 161 } |
158 | 162 |
159 void ThreadLocalAllocBuffer::initialize_statistics() { | 163 void ThreadLocalAllocBuffer::initialize_statistics() { |
160 _number_of_refills = 0; | 164 _number_of_refills = 0; |
161 _fast_refill_waste = 0; | 165 _fast_refill_waste = 0; |
247 init_sz = MIN2(MAX2(init_sz, min_size()), max_size()); | 251 init_sz = MIN2(MAX2(init_sz, min_size()), max_size()); |
248 } | 252 } |
249 return init_sz; | 253 return init_sz; |
250 } | 254 } |
251 | 255 |
252 const size_t ThreadLocalAllocBuffer::max_size() { | |
253 | |
254 // TLABs can't be bigger than we can fill with a int[Integer.MAX_VALUE]. | |
255 // This restriction could be removed by enabling filling with multiple arrays. | |
256 // If we compute that the reasonable way as | |
257 // header_size + ((sizeof(jint) * max_jint) / HeapWordSize) | |
258 // we'll overflow on the multiply, so we do the divide first. | |
259 // We actually lose a little by dividing first, | |
260 // but that just makes the TLAB somewhat smaller than the biggest array, | |
261 // which is fine, since we'll be able to fill that. | |
262 | |
263 size_t unaligned_max_size = typeArrayOopDesc::header_size(T_INT) + | |
264 sizeof(jint) * | |
265 ((juint) max_jint / (size_t) HeapWordSize); | |
266 return align_size_down(unaligned_max_size, MinObjAlignment); | |
267 } | |
268 | |
269 void ThreadLocalAllocBuffer::print_stats(const char* tag) { | 256 void ThreadLocalAllocBuffer::print_stats(const char* tag) { |
270 Thread* thrd = myThread(); | 257 Thread* thrd = myThread(); |
271 size_t waste = _gc_waste + _slow_refill_waste + _fast_refill_waste; | 258 size_t waste = _gc_waste + _slow_refill_waste + _fast_refill_waste; |
272 size_t alloc = _number_of_refills * _desired_size; | 259 size_t alloc = _number_of_refills * _desired_size; |
273 double waste_percent = alloc == 0 ? 0.0 : | 260 double waste_percent = alloc == 0 ? 0.0 : |
274 100.0 * waste / alloc; | 261 100.0 * waste / alloc; |
275 size_t tlab_used = Universe::heap()->tlab_capacity(thrd) - | 262 size_t tlab_used = Universe::heap()->tlab_used(thrd); |
276 Universe::heap()->unsafe_max_tlab_alloc(thrd); | |
277 gclog_or_tty->print("TLAB: %s thread: " INTPTR_FORMAT " [id: %2d]" | 263 gclog_or_tty->print("TLAB: %s thread: " INTPTR_FORMAT " [id: %2d]" |
278 " desired_size: " SIZE_FORMAT "KB" | 264 " desired_size: " SIZE_FORMAT "KB" |
279 " slow allocs: %d refill waste: " SIZE_FORMAT "B" | 265 " slow allocs: %d refill waste: " SIZE_FORMAT "B" |
280 " alloc:%8.5f %8.0fKB refills: %d waste %4.1f%% gc: %dB" | 266 " alloc:%8.5f %8.0fKB refills: %d waste %4.1f%% gc: %dB" |
281 " slow: %dB fast: %dB\n", | 267 " slow: %dB fast: %dB\n", |