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