1 /* 2 * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 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 #ifndef SHARE_GC_Z_ZHEAP_HPP 25 #define SHARE_GC_Z_ZHEAP_HPP 26 27 #include "gc/shared/gcTimer.hpp" 28 #include "gc/z/zAllocationFlags.hpp" 29 #include "gc/z/zArray.hpp" 30 #include "gc/z/zList.hpp" 31 #include "gc/z/zLock.hpp" 32 #include "gc/z/zMark.hpp" 33 #include "gc/z/zObjectAllocator.hpp" 34 #include "gc/z/zPage.hpp" 35 #include "gc/z/zPageAllocator.hpp" 36 #include "gc/z/zPageTable.hpp" 37 #include "gc/z/zReferenceProcessor.hpp" 38 #include "gc/z/zRelocate.hpp" 39 #include "gc/z/zRelocationSet.hpp" 40 #include "gc/z/zRelocationSetSelector.hpp" 41 #include "gc/z/zRootsIterator.hpp" 42 #include "gc/z/zWeakRootsProcessor.hpp" 43 #include "gc/z/zServiceability.hpp" 44 #include "gc/z/zUnload.hpp" 45 #include "gc/z/zWorkers.hpp" 46 #include "memory/allocation.hpp" 47 48 class ZHeap { 49 friend class VMStructs; 50 51 private: 52 static ZHeap* _heap; 53 54 ZWorkers _workers; 55 ZObjectAllocator _object_allocator; 56 ZPageAllocator _page_allocator; 57 ZPageTable _pagetable; 58 ZMark _mark; 59 ZReferenceProcessor _reference_processor; 60 ZWeakRootsProcessor _weak_roots_processor; 61 ZRelocate _relocate; 62 ZRelocationSet _relocation_set; 63 ZUnload _unload; 64 ZServiceability _serviceability; 65 66 size_t heap_min_size() const; 67 size_t heap_max_size() const; 68 size_t heap_max_reserve_size() const; 69 70 void before_flip(); 71 void after_flip(); 72 73 void flip_to_marked(); 74 void flip_to_remapped(); 75 76 void out_of_memory(); 77 void fixup_partial_loads(); 78 79 public: 80 static ZHeap* heap(); 81 82 ZHeap(); 83 84 bool is_initialized() const; 85 86 // Heap metrics 87 size_t min_capacity() const; 88 size_t max_capacity() const; 89 size_t current_max_capacity() const; 90 size_t capacity() const; 91 size_t max_reserve() const; 92 size_t used_high() const; 93 size_t used_low() const; 94 size_t used() const; 95 size_t allocated() const; 96 size_t reclaimed() const; 97 98 size_t tlab_capacity() const; 99 size_t tlab_used() const; 100 size_t max_tlab_size() const; 101 size_t unsafe_max_tlab_alloc() const; 102 103 bool is_in(uintptr_t addr) const; 104 105 // Block 106 uintptr_t block_start(uintptr_t addr) const; 107 bool block_is_obj(uintptr_t addr) const; 108 109 // Workers 110 uint nconcurrent_worker_threads() const; 111 uint nconcurrent_no_boost_worker_threads() const; 112 void set_boost_worker_threads(bool boost); 113 void worker_threads_do(ThreadClosure* tc) const; 114 void print_worker_threads_on(outputStream* st) const; 115 116 // Reference processing 117 ReferenceDiscoverer* reference_discoverer(); 118 void set_soft_reference_policy(bool clear); 119 120 // Non-strong reference processing 121 void process_non_strong_references(); 122 123 // Page allocation 124 ZPage* alloc_page(uint8_t type, size_t size, ZAllocationFlags flags); 125 void undo_alloc_page(ZPage* page); 126 bool retain_page(ZPage* page); 127 void release_page(ZPage* page, bool reclaimed); 128 129 // Object allocation 130 uintptr_t alloc_tlab(size_t size); 131 uintptr_t alloc_object(size_t size); 132 uintptr_t alloc_object_for_relocation(size_t size); 133 void undo_alloc_object_for_relocation(uintptr_t addr, size_t size); 134 bool is_alloc_stalled() const; 135 void check_out_of_memory(); 136 137 // Marking 138 bool is_object_live(uintptr_t addr) const; 139 bool is_object_strongly_live(uintptr_t addr) const; 140 template <bool finalizable, bool publish> void mark_object(uintptr_t addr); 141 void mark_start(); 142 void mark(bool initial); 143 void mark_flush_and_free(Thread* thread); 144 bool mark_end(); 145 146 // Post-marking & Pre-relocation 147 void destroy_detached_pages(); 148 149 // Relocation set 150 void select_relocation_set(); 151 void prepare_relocation_set(); 152 void reset_relocation_set(); 153 154 // Relocation 155 bool is_relocating(uintptr_t addr) const; 156 void relocate_start(); 157 uintptr_t relocate_object(uintptr_t addr); 158 uintptr_t forward_object(uintptr_t addr); 159 void relocate(); 160 161 // Iteration 162 void object_iterate(ObjectClosure* cl, bool visit_referents); 163 164 // Serviceability 165 void serviceability_initialize(); 166 GCMemoryManager* serviceability_memory_manager(); 167 MemoryPool* serviceability_memory_pool(); 168 ZServiceabilityCounters* serviceability_counters(); 169 170 // Printing 171 void print_on(outputStream* st) const; 172 void print_extended_on(outputStream* st) const; 173 174 // Verification 175 bool is_oop(oop object) const; 176 void verify(); 177 }; 178 179 #endif // SHARE_GC_Z_ZHEAP_HPP