1 /*
2 * Copyright (c) 2018, 2019, 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_SHENANDOAHALLOCREQUEST_HPP
26 #define SHARE_GC_SHENANDOAH_SHENANDOAHALLOCREQUEST_HPP
27
28 #include "memory/allocation.hpp"
29
30 class ShenandoahAllocRequest : StackObj {
31 public:
32 enum Type {
33 _alloc_shared, // Allocate common, outside of TLAB
34 _alloc_shared_gc, // Allocate common, outside of GCLAB
35 _alloc_tlab, // Allocate TLAB
36 _alloc_gclab, // Allocate GCLAB
37 _ALLOC_LIMIT
38 };
39
40 static const char* alloc_type_to_string(Type type) {
41 switch (type) {
42 case _alloc_shared:
43 return "Shared";
44 case _alloc_shared_gc:
45 return "Shared GC";
46 case _alloc_tlab:
47 return "TLAB";
48 case _alloc_gclab:
49 return "GCLAB";
50 default:
51 ShouldNotReachHere();
52 return "";
53 }
54 }
55
56 private:
57 size_t _min_size;
58 size_t _requested_size;
59 size_t _actual_size;
60 Type _alloc_type;
61 #ifdef ASSERT
62 bool _actual_size_set;
63 #endif
64
65 ShenandoahAllocRequest(size_t _min_size, size_t _requested_size, Type _alloc_type) :
66 _min_size(_min_size), _requested_size(_requested_size),
67 _actual_size(0), _alloc_type(_alloc_type)
68 #ifdef ASSERT
69 , _actual_size_set(false)
70 #endif
71 {}
72
73 public:
74 static inline ShenandoahAllocRequest for_tlab(size_t min_size, size_t requested_size) {
75 return ShenandoahAllocRequest(min_size, requested_size, _alloc_tlab);
76 }
77
78 static inline ShenandoahAllocRequest for_gclab(size_t min_size, size_t requested_size) {
79 return ShenandoahAllocRequest(min_size, requested_size, _alloc_gclab);
80 }
81
82 static inline ShenandoahAllocRequest for_shared_gc(size_t requested_size) {
83 return ShenandoahAllocRequest(0, requested_size, _alloc_shared_gc);
84 }
85
86 static inline ShenandoahAllocRequest for_shared(size_t requested_size) {
87 return ShenandoahAllocRequest(0, requested_size, _alloc_shared);
88 }
89
90 inline size_t size() {
91 return _requested_size;
92 }
93
94 inline Type type() {
95 return _alloc_type;
96 }
97
98 inline const char* type_string() {
99 return alloc_type_to_string(_alloc_type);
100 }
101
102 inline size_t min_size() {
103 assert (is_lab_alloc(), "Only access for LAB allocs");
104 return _min_size;
105 }
106
107 inline size_t actual_size() {
108 assert (_actual_size_set, "Should be set");
109 return _actual_size;
110 }
111
112 inline void set_actual_size(size_t v) {
113 #ifdef ASSERT
114 assert (!_actual_size_set, "Should not be set");
115 _actual_size_set = true;
116 #endif
117 _actual_size = v;
118 }
119
120 inline bool is_mutator_alloc() {
121 switch (_alloc_type) {
122 case _alloc_tlab:
123 case _alloc_shared:
124 return true;
125 case _alloc_gclab:
126 case _alloc_shared_gc:
127 return false;
128 default:
129 ShouldNotReachHere();
130 return false;
131 }
132 }
133
134 inline bool is_gc_alloc() {
135 switch (_alloc_type) {
136 case _alloc_tlab:
137 case _alloc_shared:
138 return false;
139 case _alloc_gclab:
140 case _alloc_shared_gc:
141 return true;
142 default:
143 ShouldNotReachHere();
144 return false;
145 }
146 }
147
148 inline bool is_lab_alloc() {
149 switch (_alloc_type) {
150 case _alloc_tlab:
151 case _alloc_gclab:
152 return true;
153 case _alloc_shared:
154 case _alloc_shared_gc:
155 return false;
156 default:
157 ShouldNotReachHere();
158 return false;
159 }
160 }
161 };
162
163 #endif // SHARE_GC_SHENANDOAH_SHENANDOAHALLOCREQUEST_HPP
|
1 /*
2 * Copyright (c) 2018, 2019, 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_SHENANDOAHALLOCREQUEST_HPP
27 #define SHARE_GC_SHENANDOAH_SHENANDOAHALLOCREQUEST_HPP
28
29 #include "gc/shenandoah/shenandoahAffiliation.hpp"
30 #include "memory/allocation.hpp"
31
32 class ShenandoahAllocRequest : StackObj {
33 public:
34 enum Type {
35 _alloc_shared, // Allocate common, outside of TLAB
36 _alloc_shared_gc, // Allocate common, outside of GCLAB/PLAB
37 _alloc_tlab, // Allocate TLAB
38 _alloc_gclab, // Allocate GCLAB
39 _alloc_plab, // Allocate PLAB
40 _ALLOC_LIMIT
41 };
42
43 static const char* alloc_type_to_string(Type type) {
44 switch (type) {
45 case _alloc_shared:
46 return "Shared";
47 case _alloc_shared_gc:
48 return "Shared GC";
49 case _alloc_tlab:
50 return "TLAB";
51 case _alloc_gclab:
52 return "GCLAB";
53 case _alloc_plab:
54 return "PLAB";
55 default:
56 ShouldNotReachHere();
57 return "";
58 }
59 }
60
61 private:
62 // When ShenandoahElasticTLAB is enabled, the request cannot be made smaller than _min_size.
63 size_t _min_size;
64
65 // The size of the request in words.
66 size_t _requested_size;
67
68 // The allocation may be increased for padding or decreased to fit in the remaining space of a region.
69 size_t _actual_size;
70
71 // For a humongous object, the _waste is the amount of free memory in the last region.
72 // For other requests, the _waste will be non-zero if the request enountered one or more regions
73 // with less memory than _min_size. This waste does not contribute to the used memory for
74 // the heap, but it does contribute to the allocation rate for heuristics.
75 size_t _waste;
76
77 // This is the type of the request.
78 Type _alloc_type;
79
80 // This is the generation which the request is targeting.
81 ShenandoahAffiliation const _affiliation;
82
83 // True if this request is trying to copy any object from young to old (promote).
84 bool _is_promotion;
85
86 #ifdef ASSERT
87 // Check that this is set before being read.
88 bool _actual_size_set;
89 #endif
90
91 ShenandoahAllocRequest(size_t _min_size, size_t _requested_size, Type _alloc_type, ShenandoahAffiliation affiliation, bool is_promotion = false) :
92 _min_size(_min_size), _requested_size(_requested_size),
93 _actual_size(0), _waste(0), _alloc_type(_alloc_type), _affiliation(affiliation), _is_promotion(is_promotion)
94 #ifdef ASSERT
95 , _actual_size_set(false)
96 #endif
97 {}
98
99 public:
100 static inline ShenandoahAllocRequest for_tlab(size_t min_size, size_t requested_size) {
101 return ShenandoahAllocRequest(min_size, requested_size, _alloc_tlab, ShenandoahAffiliation::YOUNG_GENERATION);
102 }
103
104 static inline ShenandoahAllocRequest for_gclab(size_t min_size, size_t requested_size) {
105 return ShenandoahAllocRequest(min_size, requested_size, _alloc_gclab, ShenandoahAffiliation::YOUNG_GENERATION);
106 }
107
108 static inline ShenandoahAllocRequest for_plab(size_t min_size, size_t requested_size) {
109 return ShenandoahAllocRequest(min_size, requested_size, _alloc_plab, ShenandoahAffiliation::OLD_GENERATION);
110 }
111
112 static inline ShenandoahAllocRequest for_shared_gc(size_t requested_size, ShenandoahAffiliation affiliation, bool is_promotion = false) {
113 if (is_promotion) {
114 assert(affiliation == ShenandoahAffiliation::OLD_GENERATION, "Should only promote to old generation");
115 return ShenandoahAllocRequest(0, requested_size, _alloc_shared_gc, affiliation, true);
116 }
117 return ShenandoahAllocRequest(0, requested_size, _alloc_shared_gc, affiliation);
118 }
119
120 static inline ShenandoahAllocRequest for_shared(size_t requested_size) {
121 return ShenandoahAllocRequest(0, requested_size, _alloc_shared, ShenandoahAffiliation::YOUNG_GENERATION);
122 }
123
124 inline size_t size() const {
125 return _requested_size;
126 }
127
128 inline Type type() const {
129 return _alloc_type;
130 }
131
132 inline const char* type_string() const {
133 return alloc_type_to_string(_alloc_type);
134 }
135
136 inline size_t min_size() const {
137 assert (is_lab_alloc(), "Only access for LAB allocs");
138 return _min_size;
139 }
140
141 inline size_t actual_size() const {
142 assert (_actual_size_set, "Should be set");
143 return _actual_size;
144 }
145
146 inline void set_actual_size(size_t v) {
147 #ifdef ASSERT
148 assert (!_actual_size_set, "Should not be set");
149 _actual_size_set = true;
150 #endif
151 _actual_size = v;
152 }
153
154 inline size_t waste() const {
155 return _waste;
156 }
157
158 inline void set_waste(size_t v) {
159 _waste = v;
160 }
161
162 inline bool is_mutator_alloc() const {
163 switch (_alloc_type) {
164 case _alloc_tlab:
165 case _alloc_shared:
166 return true;
167 case _alloc_gclab:
168 case _alloc_plab:
169 case _alloc_shared_gc:
170 return false;
171 default:
172 ShouldNotReachHere();
173 return false;
174 }
175 }
176
177 inline bool is_gc_alloc() const {
178 switch (_alloc_type) {
179 case _alloc_tlab:
180 case _alloc_shared:
181 return false;
182 case _alloc_gclab:
183 case _alloc_plab:
184 case _alloc_shared_gc:
185 return true;
186 default:
187 ShouldNotReachHere();
188 return false;
189 }
190 }
191
192 inline bool is_lab_alloc() const {
193 switch (_alloc_type) {
194 case _alloc_tlab:
195 case _alloc_gclab:
196 case _alloc_plab:
197 return true;
198 case _alloc_shared:
199 case _alloc_shared_gc:
200 return false;
201 default:
202 ShouldNotReachHere();
203 return false;
204 }
205 }
206
207 bool is_old() const {
208 return _affiliation == OLD_GENERATION;
209 }
210
211 bool is_young() const {
212 return _affiliation == YOUNG_GENERATION;
213 }
214
215 ShenandoahAffiliation affiliation() const {
216 return _affiliation;
217 }
218
219 const char* affiliation_name() const {
220 return shenandoah_affiliation_name(_affiliation);
221 }
222
223 bool is_promotion() const {
224 return _is_promotion;
225 }
226 };
227
228 #endif // SHARE_GC_SHENANDOAH_SHENANDOAHALLOCREQUEST_HPP
|