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_ZPAGE_HPP 25 #define SHARE_GC_Z_ZPAGE_HPP 26 27 #include "gc/z/zForwardingTable.hpp" 28 #include "gc/z/zList.hpp" 29 #include "gc/z/zLiveMap.hpp" 30 #include "gc/z/zPhysicalMemory.hpp" 31 #include "gc/z/zVirtualMemory.hpp" 32 #include "memory/allocation.hpp" 33 34 class ZPage : public CHeapObj<mtGC> { 35 friend class ZList<ZPage>; 36 37 private: 38 // First cacheline (always hot) 39 const uint8_t _type; // Page type 40 volatile uint8_t _pinned; // Pinned flag 41 uint8_t _numa_id; // NUMA node affinity 42 uint32_t _seqnum; // Allocation sequence number 43 const ZVirtualMemory _virtual; // Virtual start/end address 44 volatile uintptr_t _top; // Virtual top address 45 ZLiveMap _livemap; // Live map 46 47 // Second cacheline (hot when relocated and cached) 48 volatile uint32_t _refcount; // Page reference count 49 ZForwardingTable _forwarding; // Forwarding table 50 ZPhysicalMemory _physical; // Physical memory for page 51 ZListNode<ZPage> _node; // Page list node 52 53 const char* type_to_string() const; 54 uint32_t object_max_count() const; 55 uintptr_t relocate_object_inner(uintptr_t from_index, uintptr_t from_offset); 56 57 bool is_object_marked(uintptr_t addr) const; 58 bool is_object_strongly_marked(uintptr_t addr) const; 59 60 public: 61 ZPage(uint8_t type, ZVirtualMemory vmem, ZPhysicalMemory pmem); 62 ~ZPage(); 63 64 size_t object_alignment_shift() const; 65 size_t object_alignment() const; 66 67 uint8_t type() const; 68 uintptr_t start() const; 69 uintptr_t end() const; 70 size_t size() const; 71 uintptr_t top() const; 72 size_t remaining() const; 73 74 uint8_t numa_id(); 75 76 ZPhysicalMemory& physical_memory(); 77 const ZVirtualMemory& virtual_memory() const; 78 79 void reset(); 80 81 bool inc_refcount(); 82 bool dec_refcount(); 83 84 bool is_in(uintptr_t addr) const; 85 86 uintptr_t block_start(uintptr_t addr) const; 87 size_t block_size(uintptr_t addr) const; 88 bool block_is_obj(uintptr_t addr) const; 89 90 bool is_active() const; 91 bool is_allocating() const; 92 bool is_relocatable() const; 93 bool is_detached() const; 94 95 bool is_mapped() const; 96 void set_pre_mapped(); 97 98 bool is_pinned() const; 99 void set_pinned(); 100 101 bool is_forwarding() const; 102 void set_forwarding(); 103 void reset_forwarding(); 104 void verify_forwarding() const; 105 106 bool is_marked() const; 107 bool is_object_live(uintptr_t addr) const; 108 bool is_object_strongly_live(uintptr_t addr) const; 109 bool mark_object(uintptr_t addr, bool finalizable, bool& inc_live); 110 111 void inc_live_atomic(uint32_t objects, size_t bytes); 112 size_t live_bytes() const; 113 114 void object_iterate(ObjectClosure* cl); 115 116 uintptr_t alloc_object(size_t size); 117 uintptr_t alloc_object_atomic(size_t size); 118 119 bool undo_alloc_object(uintptr_t addr, size_t size); 120 bool undo_alloc_object_atomic(uintptr_t addr, size_t size); 121 122 uintptr_t relocate_object(uintptr_t from); 123 uintptr_t forward_object(uintptr_t from); 124 125 void print_on(outputStream* out) const; 126 void print() const; 127 }; 128 129 #endif // SHARE_GC_Z_ZPAGE_HPP