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_ZPAGEALLOCATOR_HPP 25 #define SHARE_GC_Z_ZPAGEALLOCATOR_HPP 26 27 #include "gc/z/zAllocationFlags.hpp" 28 #include "gc/z/zList.hpp" 29 #include "gc/z/zLock.hpp" 30 #include "gc/z/zPageCache.hpp" 31 #include "gc/z/zPhysicalMemory.hpp" 32 #include "gc/z/zPreMappedMemory.hpp" 33 #include "gc/z/zSafeDelete.hpp" 34 #include "gc/z/zVirtualMemory.hpp" 35 #include "memory/allocation.hpp" 36 37 class ZPageAllocRequest; 38 39 class ZPageAllocator { 40 friend class VMStructs; 41 42 private: 43 ZLock _lock; 44 ZVirtualMemoryManager _virtual; 45 ZPhysicalMemoryManager _physical; 46 ZPageCache _cache; 47 const size_t _max_reserve; 48 ZPreMappedMemory _pre_mapped; 49 size_t _used_high; 50 size_t _used_low; 51 size_t _used; 52 size_t _allocated; 53 ssize_t _reclaimed; 54 ZList<ZPageAllocRequest> _queue; 55 mutable ZSafeDelete<ZPage> _safe_delete; 56 57 static ZPage* const gc_marker; 58 59 void increase_used(size_t size, bool relocation); 60 void decrease_used(size_t size, bool reclaimed); 61 62 size_t max_available(bool no_reserve) const; 63 size_t try_ensure_unused(size_t size, bool no_reserve); 64 size_t try_ensure_unused_for_pre_mapped(size_t size); 65 66 ZPage* create_page(uint8_t type, size_t size); 67 void destroy_page(ZPage* page); 68 69 void flush_pre_mapped(); 70 void flush_cache(ZPageCacheFlushClosure* cl); 71 void evict_cache(size_t requested); 72 73 void check_out_of_memory_during_initialization(); 74 75 ZPage* alloc_page_common_inner(uint8_t type, size_t size, ZAllocationFlags flags); 76 ZPage* alloc_page_common(uint8_t type, size_t size, ZAllocationFlags flags); 77 ZPage* alloc_page_blocking(uint8_t type, size_t size, ZAllocationFlags flags); 78 ZPage* alloc_page_nonblocking(uint8_t type, size_t size, ZAllocationFlags flags); 79 80 void satisfy_alloc_queue(); 81 82 void detach_memory(const ZVirtualMemory& vmem, ZPhysicalMemory& pmem); 83 84 public: 85 ZPageAllocator(size_t min_capacity, size_t max_capacity, size_t max_reserve); 86 87 bool is_initialized() const; 88 89 size_t max_capacity() const; 90 size_t current_max_capacity() const; 91 size_t capacity() const; 92 size_t max_reserve() const; 93 size_t used_high() const; 94 size_t used_low() const; 95 size_t used() const; 96 size_t unused() const; 97 size_t allocated() const; 98 size_t reclaimed() const; 99 100 void reset_statistics(); 101 102 ZPage* alloc_page(uint8_t type, size_t size, ZAllocationFlags flags); 103 void free_page(ZPage* page, bool reclaimed); 104 105 void enable_deferred_delete() const; 106 void disable_deferred_delete() const; 107 108 void map_page(ZPage* page); 109 void unmap_all_pages(); 110 111 bool is_alloc_stalled() const; 112 void check_out_of_memory(); 113 }; 114 115 #endif // SHARE_GC_Z_ZPAGEALLOCATOR_HPP | 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_ZPAGEALLOCATOR_HPP 25 #define SHARE_GC_Z_ZPAGEALLOCATOR_HPP 26 27 #include "gc/z/zAllocationFlags.hpp" 28 #include "gc/z/zList.hpp" 29 #include "gc/z/zLock.hpp" 30 #include "gc/z/zPageCache.hpp" 31 #include "gc/z/zPhysicalMemory.hpp" 32 #include "gc/z/zSafeDelete.hpp" 33 #include "gc/z/zVirtualMemory.hpp" 34 #include "memory/allocation.hpp" 35 36 class ZPageAllocRequest; 37 38 class ZPageAllocator { 39 friend class VMStructs; 40 41 private: 42 ZLock _lock; 43 ZVirtualMemoryManager _virtual; 44 ZPhysicalMemoryManager _physical; 45 ZPageCache _cache; 46 const size_t _min_capacity; 47 const size_t _max_capacity; 48 const size_t _max_reserve; 49 size_t _current_max_capacity; 50 size_t _capacity; 51 size_t _used_high; 52 size_t _used_low; 53 size_t _used; 54 size_t _allocated; 55 ssize_t _reclaimed; 56 ZList<ZPageAllocRequest> _queue; 57 mutable ZSafeDelete<ZPage> _safe_delete; 58 bool _uncommit; 59 bool _initialized; 60 61 static ZPage* const gc_marker; 62 63 void prime_cache(size_t size); 64 65 void increase_used(size_t size, bool relocation); 66 void decrease_used(size_t size, bool reclaimed); 67 68 ZPage* create_page(uint8_t type, size_t size); 69 void destroy_page(ZPage* page); 70 71 size_t max_available(bool no_reserve) const; 72 bool ensure_available(size_t size, bool no_reserve); 73 void ensure_uncached_available(size_t size); 74 75 void check_out_of_memory_during_initialization(); 76 77 ZPage* alloc_page_common_inner(uint8_t type, size_t size, bool no_reserve); 78 ZPage* alloc_page_common(uint8_t type, size_t size, ZAllocationFlags flags); 79 ZPage* alloc_page_blocking(uint8_t type, size_t size, ZAllocationFlags flags); 80 ZPage* alloc_page_nonblocking(uint8_t type, size_t size, ZAllocationFlags flags); 81 82 size_t flush_cache(ZPageCacheFlushClosure* cl); 83 void flush_cache_for_allocation(size_t requested); 84 85 void satisfy_alloc_queue(); 86 87 public: 88 ZPageAllocator(size_t min_capacity, 89 size_t initial_capacity, 90 size_t max_capacity, 91 size_t max_reserve); 92 93 bool is_initialized() const; 94 95 size_t min_capacity() const; 96 size_t max_capacity() const; 97 size_t current_max_capacity() const; 98 size_t capacity() const; 99 size_t max_reserve() const; 100 size_t used_high() const; 101 size_t used_low() const; 102 size_t used() const; 103 size_t unused() const; 104 size_t allocated() const; 105 size_t reclaimed() const; 106 107 void reset_statistics(); 108 109 ZPage* alloc_page(uint8_t type, size_t size, ZAllocationFlags flags); 110 void free_page(ZPage* page, bool reclaimed); 111 112 uint64_t uncommit(uint64_t delay); 113 114 void enable_deferred_delete() const; 115 void disable_deferred_delete() const; 116 117 void map_page(ZPage* page); 118 void unmap_all_pages(); 119 120 bool is_alloc_stalled() const; 121 void check_out_of_memory(); 122 }; 123 124 #endif // SHARE_GC_Z_ZPAGEALLOCATOR_HPP |