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