43 void ThreadLocalAllocBuffer::clear_before_allocation() { |
43 void ThreadLocalAllocBuffer::clear_before_allocation() { |
44 _slow_refill_waste += (unsigned)remaining(); |
44 _slow_refill_waste += (unsigned)remaining(); |
45 make_parsable(true); // also retire the TLAB |
45 make_parsable(true); // also retire the TLAB |
46 } |
46 } |
47 |
47 |
|
48 size_t ThreadLocalAllocBuffer::remaining() { |
|
49 if (end() == NULL) { |
|
50 return 0; |
|
51 } |
|
52 |
|
53 return pointer_delta(hard_end(), top()); |
|
54 } |
|
55 |
48 void ThreadLocalAllocBuffer::accumulate_statistics_before_gc() { |
56 void ThreadLocalAllocBuffer::accumulate_statistics_before_gc() { |
49 global_stats()->initialize(); |
57 global_stats()->initialize(); |
50 |
58 |
51 for (JavaThreadIteratorWithHandle jtiwh; JavaThread *thread = jtiwh.next(); ) { |
59 for (JavaThreadIteratorWithHandle jtiwh; JavaThread *thread = jtiwh.next(); ) { |
52 thread->tlab().accumulate_statistics(); |
60 thread->tlab().accumulate_statistics(); |
119 if (retire || ZeroTLAB) { // "Reset" the TLAB |
127 if (retire || ZeroTLAB) { // "Reset" the TLAB |
120 set_start(NULL); |
128 set_start(NULL); |
121 set_top(NULL); |
129 set_top(NULL); |
122 set_pf_top(NULL); |
130 set_pf_top(NULL); |
123 set_end(NULL); |
131 set_end(NULL); |
|
132 set_allocation_end(NULL); |
124 } |
133 } |
125 } |
134 } |
126 assert(!(retire || ZeroTLAB) || |
135 assert(!(retire || ZeroTLAB) || |
127 (start() == NULL && end() == NULL && top() == NULL), |
136 (start() == NULL && end() == NULL && top() == NULL && |
|
137 _allocation_end == NULL), |
128 "TLAB must be reset"); |
138 "TLAB must be reset"); |
129 } |
139 } |
130 |
140 |
131 void ThreadLocalAllocBuffer::resize_all_tlabs() { |
141 void ThreadLocalAllocBuffer::resize_all_tlabs() { |
132 if (ResizeTLAB) { |
142 if (ResizeTLAB) { |
170 size_t new_size) { |
180 size_t new_size) { |
171 _number_of_refills++; |
181 _number_of_refills++; |
172 _allocated_size += new_size; |
182 _allocated_size += new_size; |
173 print_stats("fill"); |
183 print_stats("fill"); |
174 assert(top <= start + new_size - alignment_reserve(), "size too small"); |
184 assert(top <= start + new_size - alignment_reserve(), "size too small"); |
|
185 |
175 initialize(start, top, start + new_size - alignment_reserve()); |
186 initialize(start, top, start + new_size - alignment_reserve()); |
|
187 |
|
188 if (ThreadHeapSampler::enabled()) { |
|
189 set_sample_end(); |
|
190 } |
176 |
191 |
177 // Reset amount of internal fragmentation |
192 // Reset amount of internal fragmentation |
178 set_refill_waste_limit(initial_refill_waste_limit()); |
193 set_refill_waste_limit(initial_refill_waste_limit()); |
179 } |
194 } |
180 |
195 |
304 p += oop(p)->size(); |
320 p += oop(p)->size(); |
305 } |
321 } |
306 guarantee(p == top(), "end of last object must match end of space"); |
322 guarantee(p == top(), "end of last object must match end of space"); |
307 } |
323 } |
308 |
324 |
|
325 void ThreadLocalAllocBuffer::set_sample_end() { |
|
326 size_t heap_words_remaining = pointer_delta(_end, _top); |
|
327 size_t bytes_until_sample = myThread()->heap_sampler().bytes_until_sample(); |
|
328 size_t words_until_sample = bytes_until_sample / HeapWordSize;; |
|
329 |
|
330 if (heap_words_remaining > words_until_sample) { |
|
331 HeapWord* new_end = _top + words_until_sample; |
|
332 set_end(new_end); |
|
333 _bytes_since_last_sample_point = bytes_until_sample; |
|
334 } else { |
|
335 _bytes_since_last_sample_point = heap_words_remaining * HeapWordSize;; |
|
336 } |
|
337 } |
|
338 |
309 Thread* ThreadLocalAllocBuffer::myThread() { |
339 Thread* ThreadLocalAllocBuffer::myThread() { |
310 return (Thread*)(((char *)this) + |
340 return (Thread*)(((char *)this) + |
311 in_bytes(start_offset()) - |
341 in_bytes(start_offset()) - |
312 in_bytes(Thread::tlab_start_offset())); |
342 in_bytes(Thread::tlab_start_offset())); |
313 } |
343 } |
314 |
344 |
|
345 void ThreadLocalAllocBuffer::set_back_allocation_end() { |
|
346 _end = _allocation_end; |
|
347 } |
|
348 |
|
349 HeapWord* ThreadLocalAllocBuffer::allocate_sampled_object(size_t size) { |
|
350 set_back_allocation_end(); |
|
351 HeapWord* result = allocate(size); |
|
352 |
|
353 if (result) { |
|
354 myThread()->heap_sampler().check_for_sampling(result, size * HeapWordSize, _bytes_since_last_sample_point); |
|
355 set_sample_end(); |
|
356 } |
|
357 |
|
358 return result; |
|
359 } |
|
360 |
|
361 HeapWord* ThreadLocalAllocBuffer::hard_end() { |
|
362 return _allocation_end + alignment_reserve(); |
|
363 } |
315 |
364 |
316 GlobalTLABStats::GlobalTLABStats() : |
365 GlobalTLABStats::GlobalTLABStats() : |
317 _allocating_threads_avg(TLABAllocationWeight) { |
366 _allocating_threads_avg(TLABAllocationWeight) { |
318 |
367 |
319 initialize(); |
368 initialize(); |