1 /*
2 * Copyright (c) 2013, 2018, Red Hat, Inc. All rights reserved.
3 *
4 * This code is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 2 only, as
6 * published by the Free Software Foundation.
7 *
8 * This code is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
11 * version 2 for more details (a copy is included in the LICENSE file that
12 * accompanied this code).
13 *
14 * You should have received a copy of the GNU General Public License version
15 * 2 along with this work; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
17 *
18 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
19 * or visit www.oracle.com if you need additional information or have any
20 * questions.
21 *
22 */
23
24 #ifndef SHARE_GC_SHENANDOAH_SHENANDOAHHEAPREGION_HPP
25 #define SHARE_GC_SHENANDOAH_SHENANDOAHHEAPREGION_HPP
26
27 #include "gc/shared/space.hpp"
28 #include "gc/shenandoah/shenandoahAllocRequest.hpp"
29 #include "gc/shenandoah/shenandoahAsserts.hpp"
30 #include "gc/shenandoah/shenandoahHeap.hpp"
31 #include "gc/shenandoah/shenandoahPacer.hpp"
32 #include "utilities/sizes.hpp"
33
34 class VMStructs;
35
36 class ShenandoahHeapRegion : public ContiguousSpace {
37 friend class VMStructs;
38 private:
39 /*
40 Region state is described by a state machine. Transitions are guarded by
41 heap lock, which allows changing the state of several regions atomically.
42 Region states can be logically aggregated in groups.
43
44 "Empty":
45 .................................................................
46 . .
47 . .
48 . Uncommitted <------- Committed <------------------------\
49 . | | . |
50 . \---------v-----------/ . |
51 . | . |
52 .........................|....................................... |
53 | |
54 "Active": | |
55 .........................|....................................... |
56 . | . |
57 . /-----------------^-------------------\ . |
98 e) Pinned cannot go CSet, thus it never moves;
99 f) Humongous cannot be used for regular allocations;
100 g) Humongous cannot go CSet, thus it never moves;
101 h) Humongous start can go pinned, and thus can be protected from moves (humongous continuations should
102 follow associated humongous starts, not pinnable/movable by themselves);
103 i) Empty cannot go Trash, avoiding useless work;
104 j) ...
105 */
106
107 enum RegionState {
108 _empty_uncommitted, // region is empty and has memory uncommitted
109 _empty_committed, // region is empty and has memory committed
110 _regular, // region is for regular allocations
111 _humongous_start, // region is the humongous start
112 _humongous_cont, // region is the humongous continuation
113 _pinned_humongous_start, // region is both humongous start and pinned
114 _cset, // region is in collection set
115 _pinned, // region is pinned
116 _pinned_cset, // region is pinned and in cset (evac failure path)
117 _trash, // region contains only trash
118 };
119
120 const char* region_state_to_string(RegionState s) const {
121 switch (s) {
122 case _empty_uncommitted: return "Empty Uncommitted";
123 case _empty_committed: return "Empty Committed";
124 case _regular: return "Regular";
125 case _humongous_start: return "Humongous Start";
126 case _humongous_cont: return "Humongous Continuation";
127 case _pinned_humongous_start: return "Humongous Start, Pinned";
128 case _cset: return "Collection Set";
129 case _pinned: return "Pinned";
130 case _pinned_cset: return "Collection Set, Pinned";
131 case _trash: return "Trash";
132 default:
133 ShouldNotReachHere();
134 return "";
135 }
136 }
137
138 // This method protects from accidental changes in enum order:
139 int region_state_to_ordinal(RegionState s) const {
140 switch (s) {
141 case _empty_uncommitted: return 0;
142 case _empty_committed: return 1;
143 case _regular: return 2;
144 case _humongous_start: return 3;
145 case _humongous_cont: return 4;
146 case _cset: return 5;
147 case _pinned: return 6;
148 case _trash: return 7;
149 case _pinned_cset: return 8;
150 case _pinned_humongous_start: return 9;
151 default:
152 ShouldNotReachHere();
153 return -1;
154 }
155 }
156
157 void report_illegal_transition(const char* method);
158
159 public:
160 // Allowed transitions from the outside code:
161 void make_regular_allocation();
162 void make_regular_bypass();
163 void make_humongous_start();
164 void make_humongous_cont();
165 void make_humongous_start_bypass();
166 void make_humongous_cont_bypass();
167 void make_pinned();
168 void make_unpinned();
169 void make_cset();
170 void make_trash();
171 void make_trash_immediate();
172 void make_empty();
173 void make_uncommitted();
174 void make_committed_bypass();
175
176 // Individual states:
177 bool is_empty_uncommitted() const { return _state == _empty_uncommitted; }
178 bool is_empty_committed() const { return _state == _empty_committed; }
179 bool is_regular() const { return _state == _regular; }
407 uint64_t seqnum_last_alloc_mutator() const {
408 return _seqnum_last_alloc_mutator;
409 }
410
411 uint64_t seqnum_first_alloc_gc() const {
412 return _seqnum_first_alloc_gc;
413 }
414
415 uint64_t seqnum_last_alloc_gc() const {
416 return _seqnum_last_alloc_gc;
417 }
418
419 private:
420 void do_commit();
421 void do_uncommit();
422
423 void oop_iterate_objects(OopIterateClosure* cl);
424 void oop_iterate_humongous(OopIterateClosure* cl);
425
426 inline void internal_increase_live_data(size_t s);
427 };
428
429 #endif // SHARE_GC_SHENANDOAH_SHENANDOAHHEAPREGION_HPP
|
1 /*
2 * Copyright (c) 2013, 2019, Red Hat, Inc. All rights reserved.
3 *
4 * This code is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 2 only, as
6 * published by the Free Software Foundation.
7 *
8 * This code is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
11 * version 2 for more details (a copy is included in the LICENSE file that
12 * accompanied this code).
13 *
14 * You should have received a copy of the GNU General Public License version
15 * 2 along with this work; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
17 *
18 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
19 * or visit www.oracle.com if you need additional information or have any
20 * questions.
21 *
22 */
23
24 #ifndef SHARE_GC_SHENANDOAH_SHENANDOAHHEAPREGION_HPP
25 #define SHARE_GC_SHENANDOAH_SHENANDOAHHEAPREGION_HPP
26
27 #include "gc/shared/space.hpp"
28 #include "gc/shenandoah/shenandoahAllocRequest.hpp"
29 #include "gc/shenandoah/shenandoahAsserts.hpp"
30 #include "gc/shenandoah/shenandoahHeap.hpp"
31 #include "gc/shenandoah/shenandoahPacer.hpp"
32 #include "utilities/sizes.hpp"
33
34 class VMStructs;
35 class ShenandoahHeapRegionStateConstant;
36
37 class ShenandoahHeapRegion : public ContiguousSpace {
38 friend class VMStructs;
39 friend class ShenandoahHeapRegionStateConstant;
40 private:
41 /*
42 Region state is described by a state machine. Transitions are guarded by
43 heap lock, which allows changing the state of several regions atomically.
44 Region states can be logically aggregated in groups.
45
46 "Empty":
47 .................................................................
48 . .
49 . .
50 . Uncommitted <------- Committed <------------------------\
51 . | | . |
52 . \---------v-----------/ . |
53 . | . |
54 .........................|....................................... |
55 | |
56 "Active": | |
57 .........................|....................................... |
58 . | . |
59 . /-----------------^-------------------\ . |
100 e) Pinned cannot go CSet, thus it never moves;
101 f) Humongous cannot be used for regular allocations;
102 g) Humongous cannot go CSet, thus it never moves;
103 h) Humongous start can go pinned, and thus can be protected from moves (humongous continuations should
104 follow associated humongous starts, not pinnable/movable by themselves);
105 i) Empty cannot go Trash, avoiding useless work;
106 j) ...
107 */
108
109 enum RegionState {
110 _empty_uncommitted, // region is empty and has memory uncommitted
111 _empty_committed, // region is empty and has memory committed
112 _regular, // region is for regular allocations
113 _humongous_start, // region is the humongous start
114 _humongous_cont, // region is the humongous continuation
115 _pinned_humongous_start, // region is both humongous start and pinned
116 _cset, // region is in collection set
117 _pinned, // region is pinned
118 _pinned_cset, // region is pinned and in cset (evac failure path)
119 _trash, // region contains only trash
120 _REGION_STATES_NUM, // last
121 };
122
123 static const char* region_state_to_string(RegionState s) {
124 switch (s) {
125 case _empty_uncommitted: return "Empty Uncommitted";
126 case _empty_committed: return "Empty Committed";
127 case _regular: return "Regular";
128 case _humongous_start: return "Humongous Start";
129 case _humongous_cont: return "Humongous Continuation";
130 case _pinned_humongous_start: return "Humongous Start, Pinned";
131 case _cset: return "Collection Set";
132 case _pinned: return "Pinned";
133 case _pinned_cset: return "Collection Set, Pinned";
134 case _trash: return "Trash";
135 default:
136 ShouldNotReachHere();
137 return "";
138 }
139 }
140
141 // This method protects from accidental changes in enum order:
142 int region_state_to_ordinal(RegionState s) const {
143 switch (s) {
144 case _empty_uncommitted: return 0;
145 case _empty_committed: return 1;
146 case _regular: return 2;
147 case _humongous_start: return 3;
148 case _humongous_cont: return 4;
149 case _cset: return 5;
150 case _pinned: return 6;
151 case _trash: return 7;
152 case _pinned_cset: return 8;
153 case _pinned_humongous_start: return 9;
154 default:
155 ShouldNotReachHere();
156 return -1;
157 }
158 }
159
160 void report_illegal_transition(const char* method);
161
162 public:
163 static const int region_states_num() {
164 return _REGION_STATES_NUM;
165 }
166
167 // Allowed transitions from the outside code:
168 void make_regular_allocation();
169 void make_regular_bypass();
170 void make_humongous_start();
171 void make_humongous_cont();
172 void make_humongous_start_bypass();
173 void make_humongous_cont_bypass();
174 void make_pinned();
175 void make_unpinned();
176 void make_cset();
177 void make_trash();
178 void make_trash_immediate();
179 void make_empty();
180 void make_uncommitted();
181 void make_committed_bypass();
182
183 // Individual states:
184 bool is_empty_uncommitted() const { return _state == _empty_uncommitted; }
185 bool is_empty_committed() const { return _state == _empty_committed; }
186 bool is_regular() const { return _state == _regular; }
414 uint64_t seqnum_last_alloc_mutator() const {
415 return _seqnum_last_alloc_mutator;
416 }
417
418 uint64_t seqnum_first_alloc_gc() const {
419 return _seqnum_first_alloc_gc;
420 }
421
422 uint64_t seqnum_last_alloc_gc() const {
423 return _seqnum_last_alloc_gc;
424 }
425
426 private:
427 void do_commit();
428 void do_uncommit();
429
430 void oop_iterate_objects(OopIterateClosure* cl);
431 void oop_iterate_humongous(OopIterateClosure* cl);
432
433 inline void internal_increase_live_data(size_t s);
434
435 void set_state(RegionState to);
436 };
437
438 #endif // SHARE_GC_SHENANDOAH_SHENANDOAHHEAPREGION_HPP
|