1 /*
  2  * Copyright (c) 2015, 2021, 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/zArray.hpp"
 29 #include "gc/z/zForwardingTable.hpp"
 30 #include "gc/z/zMark.hpp"
 31 #include "gc/z/zObjectAllocator.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 class ZPage;
 44 class ZRelocationSetSelector;
 45 
 46 class ZHeap {
 47   friend class VMStructs;
 48 
 49 private:
 50   static ZHeap*       _heap;
 51 
 52   ZWorkers            _workers;
 53   ZObjectAllocator    _object_allocator;
 54   ZPageAllocator      _page_allocator;
 55   ZPageTable          _page_table;
 56   ZForwardingTable    _forwarding_table;
 57   ZMark               _mark;
 58   ZReferenceProcessor _reference_processor;
 59   ZWeakRootsProcessor _weak_roots_processor;
 60   ZRelocate           _relocate;
 61   ZRelocationSet      _relocation_set;
 62   ZUnload             _unload;
 63   ZServiceability     _serviceability;
 64 
 65   void flip_to_marked();
 66   void flip_to_remapped();
 67 
 68   void free_empty_pages(ZRelocationSetSelector* selector, int bulk);
 69 
 70   void out_of_memory();
 71 
 72 public:
 73   static ZHeap* heap();
 74 
 75   ZHeap();
 76 
 77   bool is_initialized() const;
 78 
 79   // Heap metrics
 80   size_t min_capacity() const;
 81   size_t max_capacity() const;
 82   size_t soft_max_capacity() const;
 83   size_t capacity() const;
 84   size_t used() const;
 85   size_t unused() const;
 86 
 87   size_t tlab_capacity() const;
 88   size_t tlab_used() const;
 89   size_t max_tlab_size() const;
 90   size_t unsafe_max_tlab_alloc() const;
 91 
 92   bool is_in(uintptr_t addr) const;
 93   uint32_t hash_oop(uintptr_t addr) const;
 94 
 95   // Threads
 96   uint active_workers() const;
 97   void set_active_workers(uint nworkers);
 98   void threads_do(ThreadClosure* tc) const;
 99 
100   // Reference processing
101   ReferenceDiscoverer* reference_discoverer();
102   void set_soft_reference_policy(bool clear);
103 
104   // Non-strong reference processing
105   void process_non_strong_references();
106 
107   // Page allocation
108   ZPage* alloc_page(uint8_t type, size_t size, ZAllocationFlags flags);
109   void undo_alloc_page(ZPage* page);
110   void free_page(ZPage* page, bool reclaimed);
111   void free_pages(const ZArray<ZPage*>* pages, bool reclaimed);
112 
113   // Object allocation
114   uintptr_t alloc_tlab(size_t size);
115   uintptr_t alloc_object(size_t size);
116   uintptr_t alloc_object_for_relocation(size_t size);
117   void undo_alloc_object_for_relocation(uintptr_t addr, size_t size);
118   bool has_alloc_stalled() const;
119   void check_out_of_memory();
120 
121   // Marking
122   bool is_object_live(uintptr_t addr) const;
123   bool is_object_strongly_live(uintptr_t addr) const;
124   template <bool gc_thread, bool follow, bool finalizable, bool publish> void mark_object(uintptr_t addr);
125   void mark_start();
126   void mark(bool initial);
127   void mark_flush_and_free(Thread* thread);
128   bool mark_end();
129   void mark_free();
130   void keep_alive(oop obj);
131 
132   // Relocation set
133   void select_relocation_set();
134   void reset_relocation_set();
135 
136   // Relocation
137   void relocate_start();
138   uintptr_t relocate_object(uintptr_t addr);
139   uintptr_t remap_object(uintptr_t addr);
140   void relocate();
141 
142   // Continuations
143   bool is_allocating(uintptr_t addr) const;
144 
145   // Iteration
146   void object_iterate(ObjectClosure* cl, bool visit_weaks);
147   ParallelObjectIterator* parallel_object_iterator(uint nworkers, bool visit_weaks);
148   void pages_do(ZPageClosure* cl);
149 
150   // Serviceability
151   void serviceability_initialize();
152   GCMemoryManager* serviceability_cycle_memory_manager();
153   GCMemoryManager* serviceability_pause_memory_manager();
154   MemoryPool* serviceability_memory_pool();
155   ZServiceabilityCounters* serviceability_counters();
156 
157   // Printing
158   void print_on(outputStream* st) const;
159   void print_extended_on(outputStream* st) const;
160   bool print_location(outputStream* st, uintptr_t addr) const;
161 
162   // Verification
163   bool is_oop(uintptr_t addr) const;
164   void verify();
165 };
166 
167 #endif // SHARE_GC_Z_ZHEAP_HPP
--- EOF ---