1 /* |
1 /* |
2 * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
23 |
23 |
24 #include "precompiled.hpp" |
24 #include "precompiled.hpp" |
25 #include "gc/z/zCollectedHeap.hpp" |
25 #include "gc/z/zCollectedHeap.hpp" |
26 #include "gc/z/zGlobals.hpp" |
26 #include "gc/z/zGlobals.hpp" |
27 #include "gc/z/zHeap.inline.hpp" |
27 #include "gc/z/zHeap.inline.hpp" |
|
28 #include "gc/z/zHeuristics.hpp" |
28 #include "gc/z/zObjectAllocator.hpp" |
29 #include "gc/z/zObjectAllocator.hpp" |
29 #include "gc/z/zPage.inline.hpp" |
30 #include "gc/z/zPage.inline.hpp" |
30 #include "gc/z/zStat.hpp" |
31 #include "gc/z/zStat.hpp" |
31 #include "gc/z/zThread.inline.hpp" |
32 #include "gc/z/zThread.inline.hpp" |
32 #include "gc/z/zUtils.inline.hpp" |
33 #include "gc/z/zUtils.inline.hpp" |
41 |
42 |
42 static const ZStatCounter ZCounterUndoObjectAllocationSucceeded("Memory", "Undo Object Allocation Succeeded", ZStatUnitOpsPerSecond); |
43 static const ZStatCounter ZCounterUndoObjectAllocationSucceeded("Memory", "Undo Object Allocation Succeeded", ZStatUnitOpsPerSecond); |
43 static const ZStatCounter ZCounterUndoObjectAllocationFailed("Memory", "Undo Object Allocation Failed", ZStatUnitOpsPerSecond); |
44 static const ZStatCounter ZCounterUndoObjectAllocationFailed("Memory", "Undo Object Allocation Failed", ZStatUnitOpsPerSecond); |
44 |
45 |
45 ZObjectAllocator::ZObjectAllocator() : |
46 ZObjectAllocator::ZObjectAllocator() : |
|
47 _use_per_cpu_shared_small_pages(ZHeuristics::use_per_cpu_shared_small_pages()), |
46 _used(0), |
48 _used(0), |
47 _undone(0), |
49 _undone(0), |
48 _shared_medium_page(NULL), |
50 _shared_medium_page(NULL), |
49 _shared_small_page(NULL), |
51 _shared_small_page(NULL), |
50 _worker_small_page(NULL) {} |
52 _worker_small_page(NULL) {} |
|
53 |
|
54 ZPage** ZObjectAllocator::shared_small_page_addr() { |
|
55 return _use_per_cpu_shared_small_pages ? _shared_small_page.addr() : _shared_small_page.addr(0); |
|
56 } |
|
57 |
|
58 ZPage* const* ZObjectAllocator::shared_small_page_addr() const { |
|
59 return _use_per_cpu_shared_small_pages ? _shared_small_page.addr() : _shared_small_page.addr(0); |
|
60 } |
51 |
61 |
52 ZPage* ZObjectAllocator::alloc_page(uint8_t type, size_t size, ZAllocationFlags flags) { |
62 ZPage* ZObjectAllocator::alloc_page(uint8_t type, size_t size, ZAllocationFlags flags) { |
53 ZPage* const page = ZHeap::heap()->alloc_page(type, size, flags); |
63 ZPage* const page = ZHeap::heap()->alloc_page(type, size, flags); |
54 if (page != NULL) { |
64 if (page != NULL) { |
55 // Increment used bytes |
65 // Increment used bytes |
140 "Should be a Java, VM or Runtime worker thread"); |
150 "Should be a Java, VM or Runtime worker thread"); |
141 |
151 |
142 // Non-worker small page allocation can never use the reserve |
152 // Non-worker small page allocation can never use the reserve |
143 flags.set_no_reserve(); |
153 flags.set_no_reserve(); |
144 |
154 |
145 return alloc_object_in_shared_page(_shared_small_page.addr(), ZPageTypeSmall, ZPageSizeSmall, size, flags); |
155 return alloc_object_in_shared_page(shared_small_page_addr(), ZPageTypeSmall, ZPageSizeSmall, size, flags); |
146 } |
156 } |
147 |
157 |
148 uintptr_t ZObjectAllocator::alloc_small_object_from_worker(size_t size, ZAllocationFlags flags) { |
158 uintptr_t ZObjectAllocator::alloc_small_object_from_worker(size_t size, ZAllocationFlags flags) { |
149 assert(ZThread::is_worker(), "Should be a worker thread"); |
159 assert(ZThread::is_worker(), "Should be a worker thread"); |
150 |
160 |