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 "memory/universe.hpp"
33 #include "utilities/sizes.hpp"
34
35 class VMStructs;
36
37 class ShenandoahHeapRegion : public ContiguousSpace {
38 friend class VMStructs;
39 private:
40 /*
41 Region state is described by a state machine. Transitions are guarded by
42 heap lock, which allows changing the state of several regions atomically.
43 Region states can be logically aggregated in groups.
44
45 "Empty":
46 .................................................................
47 . .
48 . .
49 . Uncommitted <------- Committed <------------------------\
50 . | | . |
51 . \---------v-----------/ . |
52 . | . |
53 .........................|....................................... |
54 | |
55 "Active": | |
56 .........................|....................................... |
57 . | . |
58 . /-----------------^-------------------\ . |
99 e) Pinned cannot go CSet, thus it never moves;
100 f) Humongous cannot be used for regular allocations;
101 g) Humongous cannot go CSet, thus it never moves;
102 h) Humongous start can go pinned, and thus can be protected from moves (humongous continuations should
103 follow associated humongous starts, not pinnable/movable by themselves);
104 i) Empty cannot go Trash, avoiding useless work;
105 j) ...
106 */
107
108 enum RegionState {
109 _empty_uncommitted, // region is empty and has memory uncommitted
110 _empty_committed, // region is empty and has memory committed
111 _regular, // region is for regular allocations
112 _humongous_start, // region is the humongous start
113 _humongous_cont, // region is the humongous continuation
114 _pinned_humongous_start, // region is both humongous start and pinned
115 _cset, // region is in collection set
116 _pinned, // region is pinned
117 _pinned_cset, // region is pinned and in cset (evac failure path)
118 _trash, // region contains only trash
119 };
120
121 const char* region_state_to_string(RegionState s) const {
122 switch (s) {
123 case _empty_uncommitted: return "Empty Uncommitted";
124 case _empty_committed: return "Empty Committed";
125 case _regular: return "Regular";
126 case _humongous_start: return "Humongous Start";
127 case _humongous_cont: return "Humongous Continuation";
128 case _pinned_humongous_start: return "Humongous Start, Pinned";
129 case _cset: return "Collection Set";
130 case _pinned: return "Pinned";
131 case _pinned_cset: return "Collection Set, Pinned";
132 case _trash: return "Trash";
133 default:
134 ShouldNotReachHere();
135 return "";
136 }
137 }
138
139 // This method protects from accidental changes in enum order:
140 int region_state_to_ordinal(RegionState s) const {
141 switch (s) {
142 case _empty_uncommitted: return 0;
143 case _empty_committed: return 1;
144 case _regular: return 2;
145 case _humongous_start: return 3;
146 case _humongous_cont: return 4;
147 case _cset: return 5;
148 case _pinned: return 6;
149 case _trash: return 7;
150 case _pinned_cset: return 8;
151 case _pinned_humongous_start: return 9;
152 default:
153 ShouldNotReachHere();
154 return -1;
155 }
156 }
157
158 void report_illegal_transition(const char* method);
159
160 public:
161 // Allowed transitions from the outside code:
162 void make_regular_allocation();
163 void make_regular_bypass();
164 void make_humongous_start();
165 void make_humongous_cont();
166 void make_humongous_start_bypass();
167 void make_humongous_cont_bypass();
168 void make_pinned();
169 void make_unpinned();
170 void make_cset();
171 void make_trash();
172 void make_trash_immediate();
173 void make_empty();
174 void make_uncommitted();
175 void make_committed_bypass();
176
177 // Individual states:
178 bool is_empty_uncommitted() const { return _state == _empty_uncommitted; }
179 bool is_empty_committed() const { return _state == _empty_committed; }
180 bool is_regular() const { return _state == _regular; }
409 uint64_t seqnum_last_alloc_mutator() const {
410 return _seqnum_last_alloc_mutator;
411 }
412
413 uint64_t seqnum_first_alloc_gc() const {
414 return _seqnum_first_alloc_gc;
415 }
416
417 uint64_t seqnum_last_alloc_gc() const {
418 return _seqnum_last_alloc_gc;
419 }
420
421 private:
422 void do_commit();
423 void do_uncommit();
424
425 void oop_iterate_objects(OopIterateClosure* cl);
426 void oop_iterate_humongous(OopIterateClosure* cl);
427
428 inline void internal_increase_live_data(size_t s);
429 };
430
431 #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 "memory/universe.hpp"
33 #include "utilities/sizes.hpp"
34
35 class VMStructs;
36 class ShenandoahHeapRegionStateConstant;
37
38 class ShenandoahHeapRegion : public ContiguousSpace {
39 friend class VMStructs;
40 friend class ShenandoahHeapRegionStateConstant;
41 private:
42 /*
43 Region state is described by a state machine. Transitions are guarded by
44 heap lock, which allows changing the state of several regions atomically.
45 Region states can be logically aggregated in groups.
46
47 "Empty":
48 .................................................................
49 . .
50 . .
51 . Uncommitted <------- Committed <------------------------\
52 . | | . |
53 . \---------v-----------/ . |
54 . | . |
55 .........................|....................................... |
56 | |
57 "Active": | |
58 .........................|....................................... |
59 . | . |
60 . /-----------------^-------------------\ . |
101 e) Pinned cannot go CSet, thus it never moves;
102 f) Humongous cannot be used for regular allocations;
103 g) Humongous cannot go CSet, thus it never moves;
104 h) Humongous start can go pinned, and thus can be protected from moves (humongous continuations should
105 follow associated humongous starts, not pinnable/movable by themselves);
106 i) Empty cannot go Trash, avoiding useless work;
107 j) ...
108 */
109
110 enum RegionState {
111 _empty_uncommitted, // region is empty and has memory uncommitted
112 _empty_committed, // region is empty and has memory committed
113 _regular, // region is for regular allocations
114 _humongous_start, // region is the humongous start
115 _humongous_cont, // region is the humongous continuation
116 _pinned_humongous_start, // region is both humongous start and pinned
117 _cset, // region is in collection set
118 _pinned, // region is pinned
119 _pinned_cset, // region is pinned and in cset (evac failure path)
120 _trash, // region contains only trash
121 _REGION_STATES_NUM, // last
122 };
123
124 static const char* region_state_to_string(RegionState s) {
125 switch (s) {
126 case _empty_uncommitted: return "Empty Uncommitted";
127 case _empty_committed: return "Empty Committed";
128 case _regular: return "Regular";
129 case _humongous_start: return "Humongous Start";
130 case _humongous_cont: return "Humongous Continuation";
131 case _pinned_humongous_start: return "Humongous Start, Pinned";
132 case _cset: return "Collection Set";
133 case _pinned: return "Pinned";
134 case _pinned_cset: return "Collection Set, Pinned";
135 case _trash: return "Trash";
136 default:
137 ShouldNotReachHere();
138 return "";
139 }
140 }
141
142 // This method protects from accidental changes in enum order:
143 int region_state_to_ordinal(RegionState s) const {
144 switch (s) {
145 case _empty_uncommitted: return 0;
146 case _empty_committed: return 1;
147 case _regular: return 2;
148 case _humongous_start: return 3;
149 case _humongous_cont: return 4;
150 case _cset: return 5;
151 case _pinned: return 6;
152 case _trash: return 7;
153 case _pinned_cset: return 8;
154 case _pinned_humongous_start: return 9;
155 default:
156 ShouldNotReachHere();
157 return -1;
158 }
159 }
160
161 void report_illegal_transition(const char* method);
162
163 public:
164 static const int region_states_num() {
165 return _REGION_STATES_NUM;
166 }
167
168 // Allowed transitions from the outside code:
169 void make_regular_allocation();
170 void make_regular_bypass();
171 void make_humongous_start();
172 void make_humongous_cont();
173 void make_humongous_start_bypass();
174 void make_humongous_cont_bypass();
175 void make_pinned();
176 void make_unpinned();
177 void make_cset();
178 void make_trash();
179 void make_trash_immediate();
180 void make_empty();
181 void make_uncommitted();
182 void make_committed_bypass();
183
184 // Individual states:
185 bool is_empty_uncommitted() const { return _state == _empty_uncommitted; }
186 bool is_empty_committed() const { return _state == _empty_committed; }
187 bool is_regular() const { return _state == _regular; }
416 uint64_t seqnum_last_alloc_mutator() const {
417 return _seqnum_last_alloc_mutator;
418 }
419
420 uint64_t seqnum_first_alloc_gc() const {
421 return _seqnum_first_alloc_gc;
422 }
423
424 uint64_t seqnum_last_alloc_gc() const {
425 return _seqnum_last_alloc_gc;
426 }
427
428 private:
429 void do_commit();
430 void do_uncommit();
431
432 void oop_iterate_objects(OopIterateClosure* cl);
433 void oop_iterate_humongous(OopIterateClosure* cl);
434
435 inline void internal_increase_live_data(size_t s);
436
437 void set_state(RegionState to);
438 };
439
440 #endif // SHARE_GC_SHENANDOAH_SHENANDOAHHEAPREGION_HPP
|