1 /* 2 * Copyright (c) 2015, 2017, 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 VALUE_OBJ_CLASS_SPEC { 39 private: 40 ZLock _lock; 41 ZVirtualMemoryManager _virtual; 42 ZPhysicalMemoryManager _physical; 43 ZPageCache _cache; 44 ZPreMappedMemory _pre_mapped; 45 const size_t _max_reserve; 46 size_t _used_high; 47 size_t _used_low; 48 size_t _used; 49 size_t _allocated; 50 ssize_t _reclaimed; 51 ZList<ZPageAllocRequest> _queue; 52 ZList<ZPage> _detached; 53 54 static ZPage* const gc_marker; 55 56 void increase_used(size_t size, bool relocation); 57 void decrease_used(size_t size, bool reclaimed); 58 59 size_t available(ZAllocationFlags flags) const; 60 61 ZPage* create_page(uint8_t type, size_t size); 62 void map_page(ZPage* page); 63 void detach_page(ZPage* page); 64 void flush_pre_mapped(); 65 void flush_cache(size_t size); 66 67 void check_out_of_memory_during_initialization(); 68 69 ZPage* alloc_page_common_inner(uint8_t type, size_t size, ZAllocationFlags flags); 70 ZPage* alloc_page_common(uint8_t type, size_t size, ZAllocationFlags flags); 71 ZPage* alloc_page_blocking(uint8_t type, size_t size, ZAllocationFlags flags); 72 ZPage* alloc_page_nonblocking(uint8_t type, size_t size, ZAllocationFlags flags); 73 74 void satisfy_alloc_queue(); 75 76 void detach_memory(const ZVirtualMemory& vmem, ZPhysicalMemory& pmem); 77 78 public: 79 ZPageAllocator(size_t min_capacity, size_t max_capacity, size_t max_reserve); 80 81 bool is_initialized() const; 82 83 size_t max_capacity() const; 84 size_t capacity() const; 85 size_t max_reserve() const; 86 size_t used_high() const; 87 size_t used_low() const; 88 size_t used() const; 89 size_t allocated() const; 90 size_t reclaimed() const; 91 92 void reset_statistics(); 93 94 ZPage* alloc_page(uint8_t type, size_t size, ZAllocationFlags flags); 95 void flip_page(ZPage* page); 96 void free_page(ZPage* page, bool reclaimed); 97 void destroy_page(ZPage* page); 98 99 void flush_detached_pages(ZList<ZPage>* list); 100 101 void flip_pre_mapped(); 102 103 void check_out_of_memory(); 104 }; 105 106 #endif // SHARE_GC_Z_ZPAGEALLOCATOR_HPP