@@ -62,6 +62,7 @@ ZHeap::ZHeap()
6262 _serviceability(InitialHeapSize, min_capacity(), max_capacity()),
6363 _old(&_page_table, &_page_allocator),
6464 _young(&_page_table, _old.forwarding_table(), &_page_allocator),
65+ _tlab_usage(),
6566 _initialized(false ) {
6667
6768 // Install global heap instance
@@ -131,11 +132,11 @@ size_t ZHeap::unused() const {
131132}
132133
133134size_t ZHeap::tlab_capacity () const {
134- return capacity ();
135+ return _tlab_usage. tlab_capacity ();
135136}
136137
137138size_t ZHeap::tlab_used () const {
138- return _allocator_eden .tlab_used ();
139+ return _tlab_usage .tlab_used ();
139140}
140141
141142size_t ZHeap::max_tlab_size () const {
@@ -156,6 +157,9 @@ size_t ZHeap::unsafe_max_tlab_alloc() const {
156157
157158 return MIN2 (size, max_tlab_size ());
158159}
160+ void ZHeap::reset_tlab_used () {
161+ _tlab_usage.reset ();
162+ }
159163
160164bool ZHeap::is_in (uintptr_t addr) const {
161165 if (addr == 0 ) {
@@ -219,11 +223,38 @@ void ZHeap::out_of_memory() {
219223 log_info (gc)(" Out Of Memory (%s)" , Thread::current ()->name ());
220224}
221225
226+ static bool is_small_eden_page (ZPage* page) {
227+ return page->type () == ZPageType::small && page->age () == ZPageAge::eden;
228+ }
229+
230+ void ZHeap::account_alloc_page (ZPage* page) {
231+ // Do TLAB accounting for small eden pages
232+ if (is_small_eden_page (page)) {
233+ _tlab_usage.increase_used (page->size ());
234+ }
235+ }
236+
237+ void ZHeap::account_undo_alloc_page (ZPage* page) {
238+ // Increase the undo counter
239+ ZStatInc (ZCounterUndoPageAllocation);
240+
241+ // Undo TLAB accounting for small eden pages
242+ if (is_small_eden_page (page)) {
243+ _tlab_usage.decrease_used (page->size ());
244+ }
245+
246+ log_trace (gc)(" Undo page allocation, thread: " PTR_FORMAT " (%s), page: " PTR_FORMAT " , size: %zu" ,
247+ p2i (Thread::current ()), ZUtils::thread_name (), p2i (page), page->size ());
248+ }
249+
222250ZPage* ZHeap::alloc_page (ZPageType type, size_t size, ZAllocationFlags flags, ZPageAge age) {
223251 ZPage* const page = _page_allocator.alloc_page (type, size, flags, age);
224252 if (page != nullptr ) {
225253 // Insert page table entry
226254 _page_table.insert (page);
255+
256+ // Do accounting for the allocated page
257+ account_alloc_page (page);
227258 }
228259
229260 return page;
@@ -232,9 +263,8 @@ ZPage* ZHeap::alloc_page(ZPageType type, size_t size, ZAllocationFlags flags, ZP
232263void ZHeap::undo_alloc_page (ZPage* page) {
233264 assert (page->is_allocating (), " Invalid page state" );
234265
235- ZStatInc (ZCounterUndoPageAllocation);
236- log_trace (gc)(" Undo page allocation, thread: " PTR_FORMAT " (%s), page: " PTR_FORMAT " , size: %zu" ,
237- p2i (Thread::current ()), ZUtils::thread_name (), p2i (page), page->size ());
266+ // Undo accounting for the page being freed
267+ account_undo_alloc_page (page);
238268
239269 free_page (page);
240270}
0 commit comments