1 /*
2  * Copyright (c) 2015, 2019, 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_ZHEAP_INLINE_HPP
25 #define SHARE_GC_Z_ZHEAP_INLINE_HPP
26 
27 #include "gc/z/zAddress.inline.hpp"
28 #include "gc/z/zForwarding.inline.hpp"
29 #include "gc/z/zForwardingTable.inline.hpp"
30 #include "gc/z/zHash.inline.hpp"
31 #include "gc/z/zHeap.hpp"
32 #include "gc/z/zMark.inline.hpp"
33 #include "gc/z/zOop.inline.hpp"
34 #include "gc/z/zPage.inline.hpp"
35 #include "gc/z/zPageTable.inline.hpp"
36 #include "utilities/debug.hpp"
37 
heap()38 inline ZHeap* ZHeap::heap() {
39   assert(_heap != NULL, "Not initialized");
40   return _heap;
41 }
42 
reference_discoverer()43 inline ReferenceDiscoverer* ZHeap::reference_discoverer() {
44   return &_reference_processor;
45 }
46 
hash_oop(uintptr_t addr) const47 inline uint32_t ZHeap::hash_oop(uintptr_t addr) const {
48   const uintptr_t offset = ZAddress::offset(addr);
49   return ZHash::address_to_uint32(offset);
50 }
51 
is_object_live(uintptr_t addr) const52 inline bool ZHeap::is_object_live(uintptr_t addr) const {
53   ZPage* page = _page_table.get(addr);
54   return page->is_object_live(addr);
55 }
56 
is_object_strongly_live(uintptr_t addr) const57 inline bool ZHeap::is_object_strongly_live(uintptr_t addr) const {
58   ZPage* page = _page_table.get(addr);
59   return page->is_object_strongly_live(addr);
60 }
61 
62 template <bool follow, bool finalizable, bool publish>
mark_object(uintptr_t addr)63 inline void ZHeap::mark_object(uintptr_t addr) {
64   assert(ZGlobalPhase == ZPhaseMark, "Mark not allowed");
65   _mark.mark_object<follow, finalizable, publish>(addr);
66 }
67 
alloc_tlab(size_t size)68 inline uintptr_t ZHeap::alloc_tlab(size_t size) {
69   guarantee(size <= max_tlab_size(), "TLAB too large");
70   return _object_allocator.alloc_object(size);
71 }
72 
alloc_object(size_t size)73 inline uintptr_t ZHeap::alloc_object(size_t size) {
74   uintptr_t addr = _object_allocator.alloc_object(size);
75   assert(ZAddress::is_good_or_null(addr), "Bad address");
76 
77   if (addr == 0) {
78     out_of_memory();
79   }
80 
81   return addr;
82 }
83 
alloc_object_for_relocation(size_t size)84 inline uintptr_t ZHeap::alloc_object_for_relocation(size_t size) {
85   uintptr_t addr = _object_allocator.alloc_object_for_relocation(size);
86   assert(ZAddress::is_good_or_null(addr), "Bad address");
87   return addr;
88 }
89 
undo_alloc_object_for_relocation(uintptr_t addr,size_t size)90 inline void ZHeap::undo_alloc_object_for_relocation(uintptr_t addr, size_t size) {
91   ZPage* const page = _page_table.get(addr);
92   _object_allocator.undo_alloc_object_for_relocation(page, addr, size);
93 }
94 
relocate_object(uintptr_t addr)95 inline uintptr_t ZHeap::relocate_object(uintptr_t addr) {
96   assert(ZGlobalPhase == ZPhaseRelocate, "Relocate not allowed");
97 
98   ZForwarding* const forwarding = _forwarding_table.get(addr);
99   if (forwarding == NULL) {
100     // Not forwarding
101     return ZAddress::good(addr);
102   }
103 
104   // Relocate object
105   const bool retained = forwarding->retain_page();
106   const uintptr_t new_addr = _relocate.relocate_object(forwarding, addr);
107   if (retained) {
108     forwarding->release_page();
109   }
110 
111   return new_addr;
112 }
113 
remap_object(uintptr_t addr)114 inline uintptr_t ZHeap::remap_object(uintptr_t addr) {
115   assert(ZGlobalPhase == ZPhaseMark ||
116          ZGlobalPhase == ZPhaseMarkCompleted, "Forward not allowed");
117 
118   ZForwarding* const forwarding = _forwarding_table.get(addr);
119   if (forwarding == NULL) {
120     // Not forwarding
121     return ZAddress::good(addr);
122   }
123 
124   // Forward object
125   return _relocate.forward_object(forwarding, addr);
126 }
127 
is_alloc_stalled() const128 inline bool ZHeap::is_alloc_stalled() const {
129   return _page_allocator.is_alloc_stalled();
130 }
131 
check_out_of_memory()132 inline void ZHeap::check_out_of_memory() {
133   _page_allocator.check_out_of_memory();
134 }
135 
is_oop(uintptr_t addr) const136 inline bool ZHeap::is_oop(uintptr_t addr) const {
137   return ZAddress::is_good(addr) && is_object_aligned(addr) && is_in(addr);
138 }
139 
140 #endif // SHARE_GC_Z_ZHEAP_INLINE_HPP
141