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/gcHeapSummary.hpp" 26 #include "gc/shared/suspendibleThreadSet.hpp" 27 #include "gc/z/zCollectedHeap.hpp" 28 #include "gc/z/zGlobals.hpp" 29 #include "gc/z/zHeap.inline.hpp" 30 #include "gc/z/zNMethod.hpp" 31 #include "gc/z/zServiceability.hpp" 32 #include "gc/z/zStat.hpp" 33 #include "gc/z/zUtils.inline.hpp" 34 #include "memory/universe.hpp" 35 #include "runtime/mutexLocker.hpp" 36 37 ZCollectedHeap* ZCollectedHeap::heap() { 38 CollectedHeap* heap = Universe::heap(); 39 assert(heap != NULL, "Uninitialized access to ZCollectedHeap::heap()"); 40 assert(heap->kind() == CollectedHeap::Z, "Invalid name"); 41 return (ZCollectedHeap*)heap; 42 } 43 44 ZCollectedHeap::ZCollectedHeap() : 45 _soft_ref_policy(), 46 _barrier_set(), 47 _initialize(&_barrier_set), 48 _heap(), 49 _director(new ZDirector()), 50 _driver(new ZDriver()), 51 _uncommitter(new ZUncommitter()), 52 _stat(new ZStat()), 53 _runtime_workers() {} 54 108 return false; 109 } 110 111 bool ZCollectedHeap::is_in(const void* p) const { 112 return _heap.is_in((uintptr_t)p); 113 } 114 115 uint32_t ZCollectedHeap::hash_oop(oop obj) const { 116 return _heap.hash_oop(obj); 117 } 118 119 HeapWord* ZCollectedHeap::allocate_new_tlab(size_t min_size, size_t requested_size, size_t* actual_size) { 120 const size_t size_in_bytes = ZUtils::words_to_bytes(align_object_size(requested_size)); 121 const uintptr_t addr = _heap.alloc_tlab(size_in_bytes); 122 123 if (addr != 0) { 124 *actual_size = requested_size; 125 } 126 127 return (HeapWord*)addr; 128 } 129 130 HeapWord* ZCollectedHeap::mem_allocate(size_t size, bool* gc_overhead_limit_was_exceeded) { 131 const size_t size_in_bytes = ZUtils::words_to_bytes(align_object_size(size)); 132 return (HeapWord*)_heap.alloc_object(size_in_bytes); 133 } 134 135 MetaWord* ZCollectedHeap::satisfy_failed_metadata_allocation(ClassLoaderData* loader_data, 136 size_t size, 137 Metaspace::MetadataType mdtype) { 138 MetaWord* result; 139 140 // Start asynchronous GC 141 collect(GCCause::_metadata_GC_threshold); 142 143 // Expand and retry allocation 144 result = loader_data->metaspace_non_null()->expand_and_allocate(size, mdtype); 145 if (result != NULL) { 146 return result; 147 } | 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/gcHeapSummary.hpp" 26 #include "gc/shared/memAllocator.hpp" 27 #include "gc/shared/suspendibleThreadSet.hpp" 28 #include "gc/z/zCollectedHeap.hpp" 29 #include "gc/z/zGlobals.hpp" 30 #include "gc/z/zHeap.inline.hpp" 31 #include "gc/z/zNMethod.hpp" 32 #include "gc/z/zServiceability.hpp" 33 #include "gc/z/zStat.hpp" 34 #include "gc/z/zUtils.inline.hpp" 35 #include "memory/universe.hpp" 36 #include "oops/arrayKlass.hpp" 37 #include "runtime/interfaceSupport.inline.hpp" 38 #include "runtime/mutexLocker.hpp" 39 40 ZCollectedHeap* ZCollectedHeap::heap() { 41 CollectedHeap* heap = Universe::heap(); 42 assert(heap != NULL, "Uninitialized access to ZCollectedHeap::heap()"); 43 assert(heap->kind() == CollectedHeap::Z, "Invalid name"); 44 return (ZCollectedHeap*)heap; 45 } 46 47 ZCollectedHeap::ZCollectedHeap() : 48 _soft_ref_policy(), 49 _barrier_set(), 50 _initialize(&_barrier_set), 51 _heap(), 52 _director(new ZDirector()), 53 _driver(new ZDriver()), 54 _uncommitter(new ZUncommitter()), 55 _stat(new ZStat()), 56 _runtime_workers() {} 57 111 return false; 112 } 113 114 bool ZCollectedHeap::is_in(const void* p) const { 115 return _heap.is_in((uintptr_t)p); 116 } 117 118 uint32_t ZCollectedHeap::hash_oop(oop obj) const { 119 return _heap.hash_oop(obj); 120 } 121 122 HeapWord* ZCollectedHeap::allocate_new_tlab(size_t min_size, size_t requested_size, size_t* actual_size) { 123 const size_t size_in_bytes = ZUtils::words_to_bytes(align_object_size(requested_size)); 124 const uintptr_t addr = _heap.alloc_tlab(size_in_bytes); 125 126 if (addr != 0) { 127 *actual_size = requested_size; 128 } 129 130 return (HeapWord*)addr; 131 } 132 133 oop ZCollectedHeap::array_allocate(Klass* klass, int size, int length, bool do_zero, TRAPS) { 134 // To avoid delaying safepoints, clearing of arrays is split up in segments 135 // with safepoint polling inbetween. However, we can't have a not-yet-cleared 136 // array of oops on the heap when we safepoint since the GC will then stumble 137 // across uninitialized oops. To avoid this we let an array of oops be an 138 // array of longs until the clearing has completed. We use longs as substitue 139 // for oops because they have the same size and alignment when using ZGC (i.e. 140 // compressed oops is disabled). 141 142 HandleMark hm; 143 144 ArrayKlass* const temp_klass = (do_zero && klass == Universe::objectArrayKlassObj()) ? 145 ArrayKlass::cast(Universe::longArrayKlassObj()) : 146 ArrayKlass::cast(klass); 147 148 // Allocate array 149 ObjArrayAllocator allocator(temp_klass, size, length, false /* do_zero */, THREAD); 150 Handle array(THREAD, allocator.allocate()); 151 152 if (!array.is_null() && do_zero) { 153 // Clear array 154 const size_t segment_max = ZUtils::bytes_to_words(os::vm_page_size()); 155 const size_t skip = arrayOopDesc::header_size(temp_klass->element_type()); 156 size_t remaining = size - skip; 157 158 while (remaining > 0) { 159 // Clear segment 160 const size_t segment = MIN2(remaining, segment_max); 161 Copy::zero_to_words((HeapWord*)array() + (size - remaining), segment); 162 remaining -= segment; 163 164 // Safepoint 165 ThreadBlockInVM tbivm((JavaThread*)THREAD); 166 } 167 168 if (klass != temp_klass) { 169 // Set actual klass 170 oopDesc::release_set_klass((HeapWord*)array(), klass); 171 } 172 } 173 174 return array(); 175 } 176 177 HeapWord* ZCollectedHeap::mem_allocate(size_t size, bool* gc_overhead_limit_was_exceeded) { 178 const size_t size_in_bytes = ZUtils::words_to_bytes(align_object_size(size)); 179 return (HeapWord*)_heap.alloc_object(size_in_bytes); 180 } 181 182 MetaWord* ZCollectedHeap::satisfy_failed_metadata_allocation(ClassLoaderData* loader_data, 183 size_t size, 184 Metaspace::MetadataType mdtype) { 185 MetaWord* result; 186 187 // Start asynchronous GC 188 collect(GCCause::_metadata_GC_threshold); 189 190 // Expand and retry allocation 191 result = loader_data->metaspace_non_null()->expand_and_allocate(size, mdtype); 192 if (result != NULL) { 193 return result; 194 } |