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_ZPHYSICALMEMORY_HPP 25 #define SHARE_GC_Z_ZPHYSICALMEMORY_HPP 26 27 #include "memory/allocation.hpp" 28 #include OS_CPU_HEADER(zPhysicalMemoryBacking) 29 30 class ZPhysicalMemorySegment VALUE_OBJ_CLASS_SPEC { 31 private: 32 uintptr_t _start; 33 uintptr_t _end; 34 35 public: 36 ZPhysicalMemorySegment(uintptr_t start, size_t size); 37 38 uintptr_t start() const; 39 uintptr_t end() const; 40 size_t size() const; 41 42 void expand(size_t size); 43 ZPhysicalMemorySegment split(size_t size); 44 }; 45 46 class ZPhysicalMemory VALUE_OBJ_CLASS_SPEC { 47 private: 48 size_t _nsegments; 49 ZPhysicalMemorySegment* _segments; 50 51 public: 52 ZPhysicalMemory(); 53 ZPhysicalMemory(size_t size); 54 ZPhysicalMemory(const ZPhysicalMemorySegment& segment); 55 56 bool is_null() const; 57 size_t size() const; 58 59 size_t nsegments() const; 60 ZPhysicalMemorySegment segment(size_t index) const; 61 void add_segment(ZPhysicalMemorySegment segment); 62 63 ZPhysicalMemory split(size_t size); 64 void clear(); 65 }; 66 67 class ZPhysicalMemoryManager VALUE_OBJ_CLASS_SPEC { 68 private: 69 ZPhysicalMemoryBacking _backing; 70 const size_t _max_capacity; 71 size_t _capacity; 72 size_t _used; 73 74 bool ensure_available(size_t size); 75 76 void nmt_commit(ZPhysicalMemory pmem, uintptr_t offset); 77 void nmt_uncommit(ZPhysicalMemory pmem, uintptr_t offset); 78 79 public: 80 ZPhysicalMemoryManager(size_t max_capacity, size_t granule_size); 81 82 bool is_initialized() const; 83 84 size_t max_capacity() const; 85 size_t capacity() const; 86 size_t used() const; 87 size_t available() const; 88 89 ZPhysicalMemory alloc(size_t size); 90 void free(ZPhysicalMemory pmem); 91 92 void map(ZPhysicalMemory pmem, uintptr_t offset); 93 void unmap(ZPhysicalMemory pmem, uintptr_t offset); 94 void flip(ZPhysicalMemory pmem, uintptr_t offset); 95 }; 96 97 #endif // SHARE_GC_Z_ZPHYSICALMEMORY_HPP