1 /*
2 * Copyright (c) 2015, 2025, 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/zGenerationId.hpp"
28 #include "gc/z/zLiveMap.hpp"
29 #include "gc/z/zPageAge.hpp"
30 #include "gc/z/zPageType.hpp"
31 #include "gc/z/zRememberedSet.hpp"
32 #include "gc/z/zVirtualMemory.hpp"
33 #include "memory/allocation.hpp"
34 #include "oops/oopsHierarchy.hpp"
35
36 class ZGeneration;
37 class ZMultiPartitionTracker;
38
39 class ZPage : public CHeapObj<mtGC> {
40 friend class VMStructs;
41 friend class ZForwardingTest;
42
43 private:
44 const ZPageType _type;
45 ZGenerationId _generation_id;
46 ZPageAge _age;
47 uint32_t _seqnum;
48 uint32_t _seqnum_other;
49 const uint32_t _single_partition_id;
50 const ZVirtualMemory _virtual;
51 volatile zoffset_end _top;
52 ZLiveMap _livemap;
53 ZRememberedSet _remembered_set;
54 ZMultiPartitionTracker* const _multi_partition_tracker;
55 volatile bool _relocate_promoted;
56
57 const char* type_to_string() const;
58
59 BitMap::idx_t bit_index(zaddress addr) const;
60 zoffset offset_from_bit_index(BitMap::idx_t index) const;
61 oop object_from_bit_index(BitMap::idx_t index) const;
62
63 bool is_live_bit_set(zaddress addr) const;
64 bool is_strong_bit_set(zaddress addr) const;
65
66 ZGeneration* generation();
67 const ZGeneration* generation() const;
68
69 void reset_seqnum();
70
71 ZPage(ZPageType type, ZPageAge age, const ZVirtualMemory& vmem, ZMultiPartitionTracker* multi_partition_tracker, uint32_t partition_id);
72
73 public:
74 ZPage(ZPageType type, ZPageAge age, const ZVirtualMemory& vmem, uint32_t partition_id);
75 ZPage(ZPageType type, ZPageAge age, const ZVirtualMemory& vmem, ZMultiPartitionTracker* multi_partition_tracker);
76
77 ZPage* clone_for_promotion() const;
78
79 uint32_t object_max_count() const;
80 size_t object_alignment_shift() const;
81 size_t object_alignment() const;
82
83 ZPageType type() const;
84
85 bool is_small() const;
86 bool is_medium() const;
87 bool is_large() const;
88
89 ZGenerationId generation_id() const;
90 bool is_young() const;
91 bool is_old() const;
92 zoffset start() const;
93 zoffset_end end() const;
94 size_t size() const;
95 zoffset_end top() const;
96 size_t remaining() const;
97 size_t used() const;
98
99 const ZVirtualMemory& virtual_memory() const;
100
101 uint32_t single_partition_id() const;
102 bool is_multi_partition() const;
103 ZMultiPartitionTracker* multi_partition_tracker() const;
104
105 ZPageAge age() const;
106
107 bool allows_raw_null() const;
108 void set_is_relocate_promoted();
109
110 uint32_t seqnum() const;
111 bool is_allocating() const;
112 bool is_relocatable() const;
113
114 ZPage* reset(ZPageAge age);
115 void reset_livemap();
116 void reset_top_for_allocation();
117
118 bool is_in(zoffset offset) const;
119 bool is_in(zaddress addr) const;
120
121 uintptr_t local_offset(zoffset offset) const;
122 uintptr_t local_offset(zoffset_end offset) const;
123 uintptr_t local_offset(zaddress addr) const;
124 uintptr_t local_offset(zaddress_unsafe addr) const;
125
126 zoffset global_offset(uintptr_t local_offset) const;
127
128 bool is_object_live(zaddress addr) const;
129 bool is_object_strongly_live(zaddress addr) const;
130
131 bool is_marked() const;
132 bool is_object_marked_live(zaddress addr) const;
133 bool is_object_marked_strong(zaddress addr) const;
134 bool is_object_marked(zaddress addr, bool finalizable) const;
135 bool mark_object(zaddress addr, bool finalizable, bool& inc_live);
136
137 void inc_live(uint32_t objects, size_t bytes);
138 void inc_will_expand(uint32_t objects);
139 uint32_t live_objects() const;
140 size_t live_bytes() const;
141
142 template <typename Function>
143 void object_iterate(Function function);
144
145 void remember(volatile zpointer* p);
146
147 // In-place relocation support
148 void clear_remset_bit_non_par_current(uintptr_t l_offset);
149 void clear_remset_range_non_par_current(uintptr_t l_offset, size_t size);
150 void swap_remset_bitmaps();
151
152 void remset_alloc();
153
154 ZBitMap::ReverseIterator remset_reverse_iterator_previous();
155 BitMap::Iterator remset_iterator_limited_current(uintptr_t l_offset, size_t size);
156 BitMap::Iterator remset_iterator_limited_previous(uintptr_t l_offset, size_t size);
157
158 zaddress_unsafe find_base_unsafe(volatile zpointer* p);
159 zaddress_unsafe find_base(volatile zpointer* p);
160
161 template <typename Function>
162 void oops_do_remembered(Function function);
163
164 // Only visits remembered set entries for live objects
165 template <typename Function>
166 void oops_do_remembered_in_live(Function function);
167
168 template <typename Function>
169 void oops_do_current_remembered(Function function);
170
171 bool is_remset_cleared_current() const;
172 bool is_remset_cleared_previous() const;
173
174 void verify_remset_cleared_current() const;
175 void verify_remset_cleared_previous() const;
176
177 void clear_remset_previous();
178
179 void* remset_current();
180
181 zaddress alloc_object(size_t size);
182 zaddress alloc_object_atomic(size_t size);
183
184 bool undo_alloc_object(zaddress addr, size_t size);
185 bool undo_alloc_object_atomic(zaddress addr, size_t size);
186
187 void log_msg(const char* msg_format, ...) const ATTRIBUTE_PRINTF(2, 3);
188
189 void print_on_msg(outputStream* st, const char* msg) const;
190 void print_on(outputStream* st) const;
191 void print() const;
192
193 // Verification
194 bool was_remembered(volatile zpointer* p);
195 bool is_remembered(volatile zpointer* p);
196 void verify_live(uint32_t live_objects, size_t live_bytes, uint32_t no_move_expand_count, bool in_place) const;
197
198 void fatal_msg(const char* msg) const;
199 };
200
201 class ZPageClosure {
202 public:
203 virtual void do_page(const ZPage* page) = 0;
204 };
205
206 #endif // SHARE_GC_Z_ZPAGE_HPP