5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
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 #include "precompiled.hpp"
25 #include "gc/shared/threadLocalAllocBuffer.inline.hpp"
26 #include "gc/z/zCollectedHeap.hpp"
27 #include "gc/z/zGlobals.hpp"
28 #include "gc/z/zHeap.inline.hpp"
29 #include "gc/z/zObjectAllocator.hpp"
30 #include "gc/z/zPage.inline.hpp"
31 #include "gc/z/zStat.hpp"
32 #include "gc/z/zThread.hpp"
33 #include "gc/z/zUtils.inline.hpp"
34 #include "logging/log.hpp"
35 #include "runtime/atomic.hpp"
36 #include "runtime/safepoint.hpp"
37 #include "runtime/thread.hpp"
38 #include "runtime/threadSMR.hpp"
39 #include "utilities/align.hpp"
40 #include "utilities/debug.hpp"
41
42 static const ZStatCounter ZCounterUndoObjectAllocationSucceeded("Memory", "Undo Object Allocation Succeeded", ZStatUnitOpsPerSecond);
43 static const ZStatCounter ZCounterUndoObjectAllocationFailed("Memory", "Undo Object Allocation Failed", ZStatUnitOpsPerSecond);
44 static const ZStatSubPhase ZSubPhasePauseRetireTLABS("Pause Retire TLABS");
45 static const ZStatSubPhase ZSubPhasePauseRemapTLABS("Pause Remap TLABS");
46
47 ZObjectAllocator::ZObjectAllocator(uint nworkers) :
48 _nworkers(nworkers),
49 _used(0),
50 _shared_medium_page(NULL),
51 _shared_small_page(NULL),
52 _worker_small_page(NULL) {}
53
54 ZPage* ZObjectAllocator::alloc_page(uint8_t type, size_t size, ZAllocationFlags flags) {
55 ZPage* const page = ZHeap::heap()->alloc_page(type, size, flags);
56 if (page != NULL) {
57 // Increment used bytes
58 Atomic::add(size, _used.addr());
59 }
60
61 return page;
62 }
63
64 uintptr_t ZObjectAllocator::alloc_object_in_shared_page(ZPage** shared_page,
65 uint8_t page_type,
276
277 ZPerCPUConstIterator<size_t> iter(&_used);
278 for (const size_t* cpu_used; iter.next(&cpu_used);) {
279 total_used += *cpu_used;
280 }
281
282 return total_used;
283 }
284
285 size_t ZObjectAllocator::remaining() const {
286 assert(ZThread::is_java(), "Should be a Java thread");
287
288 ZPage* page = _shared_small_page.get();
289 if (page != NULL) {
290 return page->remaining();
291 }
292
293 return 0;
294 }
295
296 void ZObjectAllocator::retire_tlabs() {
297 ZStatTimer timer(ZSubPhasePauseRetireTLABS);
298 assert(SafepointSynchronize::is_at_safepoint(), "Should be at safepoint");
299
300 // Retire TLABs
301 if (UseTLAB) {
302 ZCollectedHeap* heap = ZCollectedHeap::heap();
303 heap->ensure_parsability(true /* retire_tlabs */);
304 heap->resize_all_tlabs();
305 }
306
307 // Reset used
308 _used.set_all(0);
309
310 // Reset allocation pages
311 _shared_medium_page.set(NULL);
312 _shared_small_page.set_all(NULL);
313 _worker_small_page.set_all(NULL);
314 }
315
316 static void remap_tlab_address(HeapWord** p) {
317 *p = (HeapWord*)ZAddress::good_or_null((uintptr_t)*p);
318 }
319
320 void ZObjectAllocator::remap_tlabs() {
321 ZStatTimer timer(ZSubPhasePauseRemapTLABS);
322 assert(SafepointSynchronize::is_at_safepoint(), "Should be at safepoint");
323
324 if (UseTLAB) {
325 for (JavaThreadIteratorWithHandle iter; JavaThread* thread = iter.next(); ) {
326 thread->tlab().addresses_do(remap_tlab_address);
327 }
328 }
329 }
|
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
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 #include "precompiled.hpp"
25 #include "gc/z/zCollectedHeap.hpp"
26 #include "gc/z/zGlobals.hpp"
27 #include "gc/z/zHeap.inline.hpp"
28 #include "gc/z/zObjectAllocator.hpp"
29 #include "gc/z/zPage.inline.hpp"
30 #include "gc/z/zStat.hpp"
31 #include "gc/z/zThread.hpp"
32 #include "gc/z/zUtils.inline.hpp"
33 #include "logging/log.hpp"
34 #include "runtime/atomic.hpp"
35 #include "runtime/safepoint.hpp"
36 #include "runtime/thread.hpp"
37 #include "runtime/threadSMR.hpp"
38 #include "utilities/align.hpp"
39 #include "utilities/debug.hpp"
40
41 static const ZStatCounter ZCounterUndoObjectAllocationSucceeded("Memory", "Undo Object Allocation Succeeded", ZStatUnitOpsPerSecond);
42 static const ZStatCounter ZCounterUndoObjectAllocationFailed("Memory", "Undo Object Allocation Failed", ZStatUnitOpsPerSecond);
43
44 ZObjectAllocator::ZObjectAllocator(uint nworkers) :
45 _nworkers(nworkers),
46 _used(0),
47 _shared_medium_page(NULL),
48 _shared_small_page(NULL),
49 _worker_small_page(NULL) {}
50
51 ZPage* ZObjectAllocator::alloc_page(uint8_t type, size_t size, ZAllocationFlags flags) {
52 ZPage* const page = ZHeap::heap()->alloc_page(type, size, flags);
53 if (page != NULL) {
54 // Increment used bytes
55 Atomic::add(size, _used.addr());
56 }
57
58 return page;
59 }
60
61 uintptr_t ZObjectAllocator::alloc_object_in_shared_page(ZPage** shared_page,
62 uint8_t page_type,
273
274 ZPerCPUConstIterator<size_t> iter(&_used);
275 for (const size_t* cpu_used; iter.next(&cpu_used);) {
276 total_used += *cpu_used;
277 }
278
279 return total_used;
280 }
281
282 size_t ZObjectAllocator::remaining() const {
283 assert(ZThread::is_java(), "Should be a Java thread");
284
285 ZPage* page = _shared_small_page.get();
286 if (page != NULL) {
287 return page->remaining();
288 }
289
290 return 0;
291 }
292
293 void ZObjectAllocator::retire_pages() {
294 assert(SafepointSynchronize::is_at_safepoint(), "Should be at safepoint");
295
296 // Reset used
297 _used.set_all(0);
298
299 // Reset allocation pages
300 _shared_medium_page.set(NULL);
301 _shared_small_page.set_all(NULL);
302 _worker_small_page.set_all(NULL);
303 }
|