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_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/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 _max_reserve; 47 ZPreMappedMemory _pre_mapped; 48 size_t _used_high; 49 size_t _used_low; 50 size_t _used; 51 size_t _allocated; 52 ssize_t _reclaimed; 53 ZList<ZPageAllocRequest> _queue; 54 ZList<ZPage> _detached; 55 56 static ZPage* const gc_marker; 57 58 void increase_used(size_t size, bool relocation); 59 void decrease_used(size_t size, bool reclaimed); 60 61 size_t max_available(bool no_reserve) const; 62 size_t try_ensure_unused(size_t size, bool no_reserve); 63 size_t try_ensure_unused_for_pre_mapped(size_t size); 64 65 ZPage* create_page(uint8_t type, size_t size); 66 void detach_page(ZPage* page); 67 void flush_pre_mapped(); 68 void flush_cache(size_t size); 69 70 void check_out_of_memory_during_initialization(); 71 72 ZPage* alloc_page_common_inner(uint8_t type, size_t size, ZAllocationFlags flags); 73 ZPage* alloc_page_common(uint8_t type, size_t size, ZAllocationFlags flags); 74 ZPage* alloc_page_blocking(uint8_t type, size_t size, ZAllocationFlags flags); 75 ZPage* alloc_page_nonblocking(uint8_t type, size_t size, ZAllocationFlags flags); 76 77 void satisfy_alloc_queue(); 78 79 void detach_memory(const ZVirtualMemory& vmem, ZPhysicalMemory& pmem); 80 81 public: 82 ZPageAllocator(size_t min_capacity, size_t max_capacity, size_t max_reserve); 83 84 bool is_initialized() const; 85 86 size_t max_capacity() const; 87 size_t current_max_capacity() const; 88 size_t capacity() const; 89 size_t max_reserve() const; 90 size_t used_high() const; 91 size_t used_low() const; 92 size_t used() const; 93 size_t allocated() const; 94 size_t reclaimed() const; 95 96 void reset_statistics(); 97 98 ZPage* alloc_page(uint8_t type, size_t size, ZAllocationFlags flags); 99 void free_page(ZPage* page, bool reclaimed); 100 void destroy_page(ZPage* page); 101 102 void map_page(ZPage* page); 103 void unmap_all_pages(); 104 105 void flush_detached_pages(ZList<ZPage>* list); 106 107 bool is_alloc_stalled() const; 108 void check_out_of_memory(); 109 }; 110 111 #endif // SHARE_GC_Z_ZPAGEALLOCATOR_HPP