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 55 CollectedHeap::Name ZCollectedHeap::kind() const { 56 return CollectedHeap::Z; 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 "runtime/interfaceSupport.inline.hpp" 37 #include "runtime/mutexLocker.hpp" 38 39 class PinAllocating { 40 private: 41 const HeapWord* _mem; 42 public: 43 PinAllocating(HeapWord* mem) : 44 _mem(mem) { 45 ZHeap::heap()->pin_allocating((uintptr_t)_mem); 46 } 47 48 ~PinAllocating() { 49 ZHeap::heap()->unpin_allocating((uintptr_t)_mem); 50 } 51 }; 52 53 class ZObjArrayAllocator: public ObjArrayAllocator { 54 private: 55 const bool _is_large; 56 const size_t _chunk_size; 57 58 void mem_clear_large(HeapWord* mem) const { 59 log_info(gc)("ZMemClearer " PTR_FORMAT " " SIZE_FORMAT " M", p2i(mem), _word_size * BytesPerWord / M); 60 assert(mem != NULL, "cannot initialize NULL object"); 61 const size_t hs = oopDesc::header_size(); 62 assert(_word_size >= hs, "unexpected object size"); 63 oopDesc::set_klass_gap(mem, 0); 64 65 PinAllocating pin_allocating(mem); 66 67 size_t offset = hs; 68 while (offset + _chunk_size < _word_size) { 69 Copy::fill_to_aligned_words(mem + offset, _chunk_size); 70 offset += _chunk_size; 71 72 { 73 ThreadBlockInVM tbivm(JavaThread::current()); 74 } 75 76 // Fix colors 77 mem = (HeapWord*)ZAddress::good((uintptr_t)mem); 78 } 79 80 if (offset < _word_size) { 81 Copy::fill_to_aligned_words(mem + offset, _word_size - offset); 82 } 83 } 84 85 protected: 86 virtual HeapWord* mem_clear(HeapWord* mem) const { 87 if (_is_large) { 88 mem_clear_large(mem); 89 } else { 90 mem = ObjArrayAllocator::mem_clear(mem); 91 } 92 return (HeapWord*)ZAddress::good((uintptr_t)mem); 93 } 94 95 public: 96 ZObjArrayAllocator(Klass* klass, size_t word_size, int length, bool do_zero, 97 Thread* thread = Thread::current()) : 98 ObjArrayAllocator(klass, word_size, length, do_zero, thread), 99 _is_large(static_cast<size_t>(length) > ZObjectSizeLimitMedium), 100 _chunk_size(ZObjectSizeLimitMedium / BytesPerWord) 101 {} 102 }; 103 104 ZCollectedHeap* ZCollectedHeap::heap() { 105 CollectedHeap* heap = Universe::heap(); 106 assert(heap != NULL, "Uninitialized access to ZCollectedHeap::heap()"); 107 assert(heap->kind() == CollectedHeap::Z, "Invalid name"); 108 return (ZCollectedHeap*)heap; 109 } 110 111 ZCollectedHeap::ZCollectedHeap() : 112 _soft_ref_policy(), 113 _barrier_set(), 114 _initialize(&_barrier_set), 115 _heap(), 116 _director(new ZDirector()), 117 _driver(new ZDriver()), 118 _uncommitter(new ZUncommitter()), 119 _stat(new ZStat()), 120 _runtime_workers() {} 121 122 CollectedHeap::Name ZCollectedHeap::kind() const { 123 return CollectedHeap::Z; 175 return false; 176 } 177 178 bool ZCollectedHeap::is_in(const void* p) const { 179 return _heap.is_in((uintptr_t)p); 180 } 181 182 uint32_t ZCollectedHeap::hash_oop(oop obj) const { 183 return _heap.hash_oop(obj); 184 } 185 186 HeapWord* ZCollectedHeap::allocate_new_tlab(size_t min_size, size_t requested_size, size_t* actual_size) { 187 const size_t size_in_bytes = ZUtils::words_to_bytes(align_object_size(requested_size)); 188 const uintptr_t addr = _heap.alloc_tlab(size_in_bytes); 189 190 if (addr != 0) { 191 *actual_size = requested_size; 192 } 193 194 return (HeapWord*)addr; 195 } 196 197 oop ZCollectedHeap::array_allocate(Klass* klass, int size, int length, bool do_zero, TRAPS) { 198 ZObjArrayAllocator allocator(klass, size, length, do_zero, THREAD); 199 return allocator.allocate(); 200 } 201 202 HeapWord* ZCollectedHeap::mem_allocate(size_t size, bool* gc_overhead_limit_was_exceeded) { 203 const size_t size_in_bytes = ZUtils::words_to_bytes(align_object_size(size)); 204 return (HeapWord*)_heap.alloc_object(size_in_bytes); 205 } 206 207 MetaWord* ZCollectedHeap::satisfy_failed_metadata_allocation(ClassLoaderData* loader_data, 208 size_t size, 209 Metaspace::MetadataType mdtype) { 210 MetaWord* result; 211 212 // Start asynchronous GC 213 collect(GCCause::_metadata_GC_threshold); 214 215 // Expand and retry allocation 216 result = loader_data->metaspace_non_null()->expand_and_allocate(size, mdtype); 217 if (result != NULL) { 218 return result; 219 } |