13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "gc/shared/genCollectedHeap.hpp"
27 #include "gc/shared/threadLocalAllocBuffer.inline.hpp"
28 #include "logging/log.hpp"
29 #include "memory/resourceArea.hpp"
30 #include "memory/universe.inline.hpp"
31 #include "oops/oop.inline.hpp"
32 #include "runtime/thread.inline.hpp"
33 #include "utilities/copy.hpp"
34
35 // Thread-Local Edens support
36
37 // static member initialization
38 size_t ThreadLocalAllocBuffer::_max_size = 0;
39 int ThreadLocalAllocBuffer::_reserve_for_allocation_prefetch = 0;
40 unsigned ThreadLocalAllocBuffer::_target_refills = 0;
41 GlobalTLABStats* ThreadLocalAllocBuffer::_global_stats = NULL;
42
43 void ThreadLocalAllocBuffer::clear_before_allocation() {
44 _slow_refill_waste += (unsigned)remaining();
45 make_parsable(true); // also retire the TLAB
46 }
47
48 void ThreadLocalAllocBuffer::accumulate_statistics_before_gc() {
49 global_stats()->initialize();
50
51 for (JavaThread *thread = Threads::first(); thread != NULL; thread = thread->next()) {
52 thread->tlab().accumulate_statistics();
53 thread->tlab().initialize_statistics();
54 }
55
56 // Publish new stats if some allocation occurred.
57 if (global_stats()->allocation() != 0) {
58 global_stats()->publish();
59 global_stats()->print();
60 }
61 }
62
63 void ThreadLocalAllocBuffer::accumulate_statistics() {
64 Thread* thread = myThread();
65 size_t capacity = Universe::heap()->tlab_capacity(thread);
66 size_t used = Universe::heap()->tlab_used(thread);
67
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;
113 if (retire) {
114 myThread()->incr_allocated_bytes(used_bytes());
115 }
116
117 CollectedHeap::fill_with_object(top(), hard_end(), retire && zap);
118
119 if (retire || ZeroTLAB) { // "Reset" the TLAB
120 set_start(NULL);
121 set_top(NULL);
122 set_pf_top(NULL);
123 set_end(NULL);
124 }
125 }
126 assert(!(retire || ZeroTLAB) ||
127 (start() == NULL && end() == NULL && top() == NULL),
128 "TLAB must be reset");
129 }
130
131 void ThreadLocalAllocBuffer::resize_all_tlabs() {
132 if (ResizeTLAB) {
133 for (JavaThread *thread = Threads::first(); thread != NULL; thread = thread->next()) {
134 thread->tlab().resize();
135 }
136 }
137 }
138
139 void ThreadLocalAllocBuffer::resize() {
140 // Compute the next tlab size using expected allocation amount
141 assert(ResizeTLAB, "Should not call this otherwise");
142 size_t alloc = (size_t)(_allocation_fraction.average() *
143 (Universe::heap()->tlab_capacity(myThread()) / HeapWordSize));
144 size_t new_size = alloc / _target_refills;
145
146 new_size = MIN2(MAX2(new_size, min_size()), max_size());
147
148 size_t aligned_new_size = align_object_size(new_size);
149
150 log_trace(gc, tlab)("TLAB new size: thread: " INTPTR_FORMAT " [id: %2d]"
151 " refills %d alloc: %8.6f desired_size: " SIZE_FORMAT " -> " SIZE_FORMAT,
152 p2i(myThread()), myThread()->osthread()->thread_id(),
153 _target_refills, _allocation_fraction.average(), desired_size(), aligned_new_size);
|
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "gc/shared/genCollectedHeap.hpp"
27 #include "gc/shared/threadLocalAllocBuffer.inline.hpp"
28 #include "logging/log.hpp"
29 #include "memory/resourceArea.hpp"
30 #include "memory/universe.inline.hpp"
31 #include "oops/oop.inline.hpp"
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;
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);
|