1 /* 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. 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/z/zAllocationFlags.hpp" 28 #include "gc/z/zForwardingTable.hpp" 29 #include "gc/z/zMark.hpp" 30 #include "gc/z/zObjectAllocator.hpp" 31 #include "gc/z/zPage.hpp" 32 #include "gc/z/zPageAllocator.hpp" 33 #include "gc/z/zPageTable.hpp" 34 #include "gc/z/zReferenceProcessor.hpp" 35 #include "gc/z/zRelocate.hpp" 36 #include "gc/z/zRelocationSet.hpp" 37 #include "gc/z/zWeakRootsProcessor.hpp" 38 #include "gc/z/zServiceability.hpp" 39 #include "gc/z/zUnload.hpp" 40 #include "gc/z/zWorkers.hpp" 41 42 class ThreadClosure; 43 44 class ZHeap { 45 friend class VMStructs; 46 47 private: 48 static ZHeap* _heap; 49 50 ZWorkers _workers; 51 ZObjectAllocator _object_allocator; 52 ZPageAllocator _page_allocator; 53 ZPageTable _page_table; 54 ZForwardingTable _forwarding_table; 55 ZMark _mark; 56 ZReferenceProcessor _reference_processor; 57 ZWeakRootsProcessor _weak_roots_processor; 58 ZRelocate _relocate; 59 ZRelocationSet _relocation_set; 60 ZUnload _unload; 61 ZServiceability _serviceability; 62 63 size_t heap_min_size() const; 64 size_t heap_initial_size() const; 65 size_t heap_max_size() const; 66 size_t heap_max_reserve_size() const; 67 68 void flip_to_marked(); 69 void flip_to_remapped(); 70 71 void out_of_memory(); 72 void fixup_partial_loads(); 73 74 public: 75 static ZHeap* heap(); 76 77 ZHeap(); 78 79 bool is_initialized() const; 80 81 // Heap metrics 82 size_t min_capacity() const; 83 size_t max_capacity() const; 84 size_t soft_max_capacity() const; 85 size_t capacity() const; 86 size_t max_reserve() const; 87 size_t used_high() const; 88 size_t used_low() const; 89 size_t used() const; 90 size_t unused() const; 91 size_t allocated() const; 92 size_t reclaimed() const; 93 94 size_t tlab_capacity() const; 95 size_t tlab_used() const; 96 size_t max_tlab_size() const; 97 size_t unsafe_max_tlab_alloc() const; 98 99 bool is_in(uintptr_t addr) const; 100 uint32_t hash_oop(uintptr_t addr) const; 101 102 // Workers 103 uint nconcurrent_worker_threads() const; 104 uint nconcurrent_no_boost_worker_threads() const; 105 void set_boost_worker_threads(bool boost); 106 void worker_threads_do(ThreadClosure* tc) const; 107 void print_worker_threads_on(outputStream* st) const; 108 // Runs the given AbstractGangTask with the current active workers, returning the 109 // total time taken. 110 Tickspan run_task(AbstractGangTask* task); 111 112 113 // Reference processing 114 ReferenceDiscoverer* reference_discoverer(); 115 void set_soft_reference_policy(bool clear); 116 117 // Non-strong reference processing 118 void process_non_strong_references(); 119 120 // Page allocation 121 ZPage* alloc_page(uint8_t type, size_t size, ZAllocationFlags flags); 122 void undo_alloc_page(ZPage* page); 123 void free_page(ZPage* page, bool reclaimed); 124 125 // Uncommit memory 126 uint64_t uncommit(uint64_t delay); 127 128 // Object allocation 129 uintptr_t alloc_tlab(size_t size); 130 uintptr_t alloc_object(size_t size); 131 uintptr_t alloc_object_for_relocation(size_t size); 132 void undo_alloc_object_for_relocation(uintptr_t addr, size_t size); 133 bool is_alloc_stalled() const; 134 void check_out_of_memory(); 135 136 // Marking 137 bool is_object_live(uintptr_t addr) const; 138 bool is_object_strongly_live(uintptr_t addr) const; 139 template <bool follow, bool finalizable, bool publish> void mark_object(uintptr_t addr); 140 void mark_start(); 141 void mark(bool initial); 142 void mark_flush_and_free(Thread* thread); 143 bool mark_end(); 144 void keep_alive(oop obj); 145 146 // Relocation set 147 void select_relocation_set(); 148 void reset_relocation_set(); 149 150 // Relocation 151 void relocate_start(); 152 uintptr_t relocate_object(uintptr_t addr); 153 uintptr_t remap_object(uintptr_t addr); 154 void relocate(); 155 156 // Iteration 157 void object_iterate(ObjectClosure* cl, bool visit_weaks); 158 void pages_do(ZPageClosure* cl); 159 160 // Serviceability 161 void serviceability_initialize(); 162 GCMemoryManager* serviceability_memory_manager(); 163 MemoryPool* serviceability_memory_pool(); 164 ZServiceabilityCounters* serviceability_counters(); 165 166 // Printing 167 void print_on(outputStream* st) const; 168 void print_extended_on(outputStream* st) const; 169 bool print_location(outputStream* st, uintptr_t addr) const; 170 171 // Verification 172 bool is_oop(uintptr_t addr) const; 173 void verify(); 174 }; 175 176 #endif // SHARE_GC_Z_ZHEAP_HPP