1 /*
2 * Copyright (c) 2018, 2022, Red Hat, Inc. 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
25 #ifndef SHARE_GC_SHENANDOAH_SHENANDOAHTHREADLOCALDATA_HPP
26 #define SHARE_GC_SHENANDOAH_SHENANDOAHTHREADLOCALDATA_HPP
27
28 #include "gc/shared/plab.hpp"
29 #include "gc/shared/gcThreadLocalData.hpp"
30 #include "gc/shared/gc_globals.hpp"
31 #include "gc/shenandoah/shenandoahBarrierSet.hpp"
32 #include "gc/shenandoah/shenandoahCodeRoots.hpp"
33 #include "gc/shenandoah/shenandoahSATBMarkQueueSet.hpp"
34 #include "runtime/javaThread.hpp"
35 #include "utilities/debug.hpp"
36 #include "utilities/sizes.hpp"
37
38 class ShenandoahThreadLocalData {
39 private:
40 char _gc_state;
41 // Evacuation OOM state
42 uint8_t _oom_scope_nesting_level;
43 bool _oom_during_evac;
44 SATBMarkQueue _satb_mark_queue;
45 PLAB* _gclab;
46 size_t _gclab_size;
47 double _paced_time;
48
49 ShenandoahThreadLocalData() :
50 _gc_state(0),
51 _oom_scope_nesting_level(0),
52 _oom_during_evac(false),
53 _satb_mark_queue(&ShenandoahBarrierSet::satb_mark_queue_set()),
54 _gclab(nullptr),
55 _gclab_size(0),
56 _paced_time(0) {
57 }
58
59 ~ShenandoahThreadLocalData() {
60 if (_gclab != nullptr) {
61 delete _gclab;
62 }
63 }
64
65 static ShenandoahThreadLocalData* data(Thread* thread) {
66 assert(UseShenandoahGC, "Sanity");
67 return thread->gc_data<ShenandoahThreadLocalData>();
68 }
69
70 static ByteSize satb_mark_queue_offset() {
71 return Thread::gc_data_offset() + byte_offset_of(ShenandoahThreadLocalData, _satb_mark_queue);
72 }
73
74 public:
75 static void create(Thread* thread) {
76 new (data(thread)) ShenandoahThreadLocalData();
77 }
78
79 static void destroy(Thread* thread) {
80 data(thread)->~ShenandoahThreadLocalData();
81 }
82
83 static SATBMarkQueue& satb_mark_queue(Thread* thread) {
84 return data(thread)->_satb_mark_queue;
85 }
86
87 static void set_gc_state(Thread* thread, char gc_state) {
88 data(thread)->_gc_state = gc_state;
89 }
90
91 static char gc_state(Thread* thread) {
92 assert(thread->is_Java_thread(), "GC state is only synchronized to java threads");
93 return data(thread)->_gc_state;
94 }
95
96 static void initialize_gclab(Thread* thread) {
97 assert (thread->is_Java_thread() || thread->is_Worker_thread(), "Only Java and GC worker threads are allowed to get GCLABs");
98 assert(data(thread)->_gclab == nullptr, "Only initialize once");
99 data(thread)->_gclab = new PLAB(PLAB::min_size());
100 data(thread)->_gclab_size = 0;
101 }
102
103 static PLAB* gclab(Thread* thread) {
104 return data(thread)->_gclab;
105 }
106
107 static size_t gclab_size(Thread* thread) {
108 return data(thread)->_gclab_size;
109 }
110
111 static void set_gclab_size(Thread* thread, size_t v) {
112 data(thread)->_gclab_size = v;
113 }
114
115 static void add_paced_time(Thread* thread, double v) {
116 data(thread)->_paced_time += v;
117 }
118
119 static double paced_time(Thread* thread) {
120 return data(thread)->_paced_time;
121 }
122
123 static void reset_paced_time(Thread* thread) {
124 data(thread)->_paced_time = 0;
125 }
126
127 // Evacuation OOM handling
128 static bool is_oom_during_evac(Thread* thread) {
129 return data(thread)->_oom_during_evac;
130 }
131
132 static void set_oom_during_evac(Thread* thread, bool oom) {
133 data(thread)->_oom_during_evac = oom;
134 }
|
1 /*
2 * Copyright (c) 2018, 2022, Red Hat, Inc. All rights reserved.
3 * Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 *
6 * This code is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 only, as
8 * published by the Free Software Foundation.
9 *
10 * This code is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * version 2 for more details (a copy is included in the LICENSE file that
14 * accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License version
17 * 2 along with this work; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
23 *
24 */
25
26 #ifndef SHARE_GC_SHENANDOAH_SHENANDOAHTHREADLOCALDATA_HPP
27 #define SHARE_GC_SHENANDOAH_SHENANDOAHTHREADLOCALDATA_HPP
28
29 #include "gc/shared/plab.hpp"
30 #include "gc/shared/gcThreadLocalData.hpp"
31 #include "gc/shared/gc_globals.hpp"
32 #include "gc/shenandoah/shenandoahBarrierSet.hpp"
33 #include "gc/shenandoah/shenandoahCodeRoots.hpp"
34 #include "gc/shenandoah/shenandoahGenerationalHeap.hpp"
35 #include "gc/shenandoah/shenandoahEvacTracker.hpp"
36 #include "gc/shenandoah/shenandoahSATBMarkQueueSet.hpp"
37 #include "gc/shenandoah/mode/shenandoahMode.hpp"
38 #include "runtime/javaThread.hpp"
39 #include "utilities/debug.hpp"
40 #include "utilities/sizes.hpp"
41
42 class ShenandoahThreadLocalData {
43 private:
44 char _gc_state;
45 // Evacuation OOM state
46 uint8_t _oom_scope_nesting_level;
47 bool _oom_during_evac;
48
49 SATBMarkQueue _satb_mark_queue;
50
51 // Thread-local allocation buffer for object evacuations.
52 // In generational mode, it is exclusive to the young generation.
53 PLAB* _gclab;
54 size_t _gclab_size;
55
56 double _paced_time;
57
58 // Thread-local allocation buffer only used in generational mode.
59 // Used both by mutator threads and by GC worker threads
60 // for evacuations within the old generation and
61 // for promotions from the young generation into the old generation.
62 PLAB* _plab;
63 size_t _plab_size;
64
65 size_t _plab_evacuated;
66 size_t _plab_promoted;
67 size_t _plab_preallocated_promoted;
68 bool _plab_allows_promotion; // If false, no more promotion by this thread during this evacuation phase.
69 bool _plab_retries_enabled;
70
71 ShenandoahEvacuationStats* _evacuation_stats;
72
73 ShenandoahThreadLocalData();
74 ~ShenandoahThreadLocalData();
75
76 static ShenandoahThreadLocalData* data(Thread* thread) {
77 assert(UseShenandoahGC, "Sanity");
78 return thread->gc_data<ShenandoahThreadLocalData>();
79 }
80
81 static ByteSize satb_mark_queue_offset() {
82 return Thread::gc_data_offset() + byte_offset_of(ShenandoahThreadLocalData, _satb_mark_queue);
83 }
84
85 public:
86 static void create(Thread* thread) {
87 new (data(thread)) ShenandoahThreadLocalData();
88 }
89
90 static void destroy(Thread* thread) {
91 data(thread)->~ShenandoahThreadLocalData();
92 }
93
94 static SATBMarkQueue& satb_mark_queue(Thread* thread) {
95 return data(thread)->_satb_mark_queue;
96 }
97
98 static void set_gc_state(Thread* thread, char gc_state) {
99 data(thread)->_gc_state = gc_state;
100 }
101
102 static char gc_state(Thread* thread) {
103 assert(thread->is_Java_thread(), "GC state is only synchronized to java threads");
104 return data(thread)->_gc_state;
105 }
106
107 static void initialize_gclab(Thread* thread) {
108 assert (thread->is_Java_thread() || thread->is_Worker_thread(), "Only Java and GC worker threads are allowed to get GCLABs");
109 assert(data(thread)->_gclab == nullptr, "Only initialize once");
110 data(thread)->_gclab = new PLAB(PLAB::min_size());
111 data(thread)->_gclab_size = 0;
112
113 // TODO:
114 // Only initialize _plab if (!Universe::is_fully_initialized() || ShenandoahHeap::heap()->mode()->is_generational())
115 // Otherwise, set _plab to nullptr
116 // Problem is there is code sprinkled throughout that asserts (plab != nullptr) that need to be fixed up. Perhaps
117 // those assertions are overzealous.
118
119 // In theory, plabs are only need if heap->mode()->is_generational(). However, some threads
120 // instantiated before we are able to answer that question.
121 if (ShenandoahHeap::heap()->mode()->is_generational()) {
122 data(thread)->_plab = new PLAB(align_up(PLAB::min_size(), CardTable::card_size_in_words()));
123 data(thread)->_plab_size = 0;
124 }
125 }
126
127 static PLAB* gclab(Thread* thread) {
128 return data(thread)->_gclab;
129 }
130
131 static size_t gclab_size(Thread* thread) {
132 return data(thread)->_gclab_size;
133 }
134
135 static void set_gclab_size(Thread* thread, size_t v) {
136 data(thread)->_gclab_size = v;
137 }
138
139 static void begin_evacuation(Thread* thread, size_t bytes) {
140 data(thread)->_evacuation_stats->begin_evacuation(bytes);
141 }
142
143 static void end_evacuation(Thread* thread, size_t bytes) {
144 data(thread)->_evacuation_stats->end_evacuation(bytes);
145 }
146
147 static void record_age(Thread* thread, size_t bytes, uint age) {
148 data(thread)->_evacuation_stats->record_age(bytes, age);
149 }
150
151 static ShenandoahEvacuationStats* evacuation_stats(Thread* thread) {
152 return data(thread)->_evacuation_stats;
153 }
154
155 static PLAB* plab(Thread* thread) {
156 return data(thread)->_plab;
157 }
158
159 static size_t plab_size(Thread* thread) {
160 return data(thread)->_plab_size;
161 }
162
163 static void set_plab_size(Thread* thread, size_t v) {
164 data(thread)->_plab_size = v;
165 }
166
167 static void enable_plab_retries(Thread* thread) {
168 data(thread)->_plab_retries_enabled = true;
169 }
170
171 static void disable_plab_retries(Thread* thread) {
172 data(thread)->_plab_retries_enabled = false;
173 }
174
175 static bool plab_retries_enabled(Thread* thread) {
176 return data(thread)->_plab_retries_enabled;
177 }
178
179 static void enable_plab_promotions(Thread* thread) {
180 data(thread)->_plab_allows_promotion = true;
181 }
182
183 static void disable_plab_promotions(Thread* thread) {
184 data(thread)->_plab_allows_promotion = false;
185 }
186
187 static bool allow_plab_promotions(Thread* thread) {
188 return data(thread)->_plab_allows_promotion;
189 }
190
191 static void reset_plab_evacuated(Thread* thread) {
192 data(thread)->_plab_evacuated = 0;
193 }
194
195 static void add_to_plab_evacuated(Thread* thread, size_t increment) {
196 data(thread)->_plab_evacuated += increment;
197 }
198
199 static void subtract_from_plab_evacuated(Thread* thread, size_t increment) {
200 // TODO: Assert underflow
201 data(thread)->_plab_evacuated -= increment;
202 }
203
204 static size_t get_plab_evacuated(Thread* thread) {
205 return data(thread)->_plab_evacuated;
206 }
207
208 static void reset_plab_promoted(Thread* thread) {
209 data(thread)->_plab_promoted = 0;
210 }
211
212 static void add_to_plab_promoted(Thread* thread, size_t increment) {
213 data(thread)->_plab_promoted += increment;
214 }
215
216 static void subtract_from_plab_promoted(Thread* thread, size_t increment) {
217 // TODO: Assert underflow
218 data(thread)->_plab_promoted -= increment;
219 }
220
221 static size_t get_plab_promoted(Thread* thread) {
222 return data(thread)->_plab_promoted;
223 }
224
225 static void set_plab_preallocated_promoted(Thread* thread, size_t value) {
226 data(thread)->_plab_preallocated_promoted = value;
227 }
228
229 static size_t get_plab_preallocated_promoted(Thread* thread) {
230 return data(thread)->_plab_preallocated_promoted;
231 }
232
233 static void add_paced_time(Thread* thread, double v) {
234 data(thread)->_paced_time += v;
235 }
236
237 static double paced_time(Thread* thread) {
238 return data(thread)->_paced_time;
239 }
240
241 static void reset_paced_time(Thread* thread) {
242 data(thread)->_paced_time = 0;
243 }
244
245 // Evacuation OOM handling
246 static bool is_oom_during_evac(Thread* thread) {
247 return data(thread)->_oom_during_evac;
248 }
249
250 static void set_oom_during_evac(Thread* thread, bool oom) {
251 data(thread)->_oom_during_evac = oom;
252 }
|