1 /*
2 * Copyright (c) 2014, 2016, 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 *
26 #define SHARE_VM_GC_G1_HEAPREGIONTYPE_HPP
27
28 #include "gc/g1/g1HeapRegionTraceType.hpp"
29 #include "memory/allocation.hpp"
30
31 #define hrt_assert_is_valid(tag) \
32 assert(is_valid((tag)), "invalid HR type: %u", (uint) (tag))
33
34 class HeapRegionType VALUE_OBJ_CLASS_SPEC {
35 private:
36 // We encode the value of the heap region type so the generation can be
37 // determined quickly. The tag is split into two parts:
38 //
39 // major type (young, old, humongous, archive) : top N-1 bits
40 // minor type (eden / survivor, starts / cont hum, etc.) : bottom 1 bit
41 //
42 // If there's need to increase the number of minor types in the
43 // future, we'll have to increase the size of the latter and hence
44 // decrease the size of the former.
45 //
46 // 0000 0 [ 0] Free
47 //
48 // 0001 0 [ 2] Young Mask
49 // 0001 0 [ 2] Eden
50 // 0001 1 [ 3] Survivor
51 //
52 // 0010 0 [ 4] Humongous Mask
53 // 0100 0 [ 8] Pinned Mask
54 // 0110 0 [12] Starts Humongous
55 // 0110 1 [13] Continues Humongous
56 //
57 // 1000 0 [16] Old Mask
58 //
59 // 1100 0 [24] Archive
60 typedef enum {
61 FreeTag = 0,
62
63 YoungMask = 2,
64 EdenTag = YoungMask,
65 SurvTag = YoungMask + 1,
66
67 HumongousMask = 4,
68 PinnedMask = 8,
69 StartsHumongousTag = HumongousMask | PinnedMask,
70 ContinuesHumongousTag = HumongousMask | PinnedMask + 1,
71
72 OldMask = 16,
73 OldTag = OldMask,
74
75 ArchiveTag = PinnedMask | OldMask
76 } Tag;
77
78 volatile Tag _tag;
79
80 static bool is_valid(Tag tag);
81
82 Tag get() const {
83 hrt_assert_is_valid(_tag);
84 return _tag;
85 }
86
87 // Sets the type to 'tag'.
88 void set(Tag tag) {
89 hrt_assert_is_valid(tag);
90 hrt_assert_is_valid(_tag);
91 _tag = tag;
92 }
93
94 // Sets the type to 'tag', expecting the type to be 'before'. This
95 // is available for when we want to add sanity checking to the type
98 hrt_assert_is_valid(tag);
99 hrt_assert_is_valid(before);
100 hrt_assert_is_valid(_tag);
101 assert(_tag == before, "HR tag: %u, expected: %u new tag; %u", _tag, before, tag);
102 _tag = tag;
103 }
104
105 public:
106 // Queries
107
108 bool is_free() const { return get() == FreeTag; }
109
110 bool is_young() const { return (get() & YoungMask) != 0; }
111 bool is_eden() const { return get() == EdenTag; }
112 bool is_survivor() const { return get() == SurvTag; }
113
114 bool is_humongous() const { return (get() & HumongousMask) != 0; }
115 bool is_starts_humongous() const { return get() == StartsHumongousTag; }
116 bool is_continues_humongous() const { return get() == ContinuesHumongousTag; }
117
118 bool is_archive() const { return get() == ArchiveTag; }
119
120 // is_old regions may or may not also be pinned
121 bool is_old() const { return (get() & OldMask) != 0; }
122
123 bool is_old_or_humongous() const { return (get() & (OldMask | HumongousMask)) != 0; }
124
125 // is_pinned regions may be archive or humongous
126 bool is_pinned() const { return (get() & PinnedMask) != 0; }
127
128 // Setters
129
130 void set_free() { set(FreeTag); }
131
132 void set_eden() { set_from(EdenTag, FreeTag); }
133 void set_eden_pre_gc() { set_from(EdenTag, SurvTag); }
134 void set_survivor() { set_from(SurvTag, FreeTag); }
135
136 void set_starts_humongous() { set_from(StartsHumongousTag, FreeTag); }
137 void set_continues_humongous() { set_from(ContinuesHumongousTag, FreeTag); }
138
139 void set_old() { set(OldTag); }
140
141 void set_archive() { set_from(ArchiveTag, FreeTag); }
142
143 // Misc
144
145 const char* get_str() const;
146 const char* get_short_str() const;
147 G1HeapRegionTraceType::Type get_trace_type();
148
149 HeapRegionType() : _tag(FreeTag) { hrt_assert_is_valid(_tag); }
150 };
151
152 #endif // SHARE_VM_GC_G1_HEAPREGIONTYPE_HPP
|
1 /*
2 * Copyright (c) 2014, 2017, 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 *
26 #define SHARE_VM_GC_G1_HEAPREGIONTYPE_HPP
27
28 #include "gc/g1/g1HeapRegionTraceType.hpp"
29 #include "memory/allocation.hpp"
30
31 #define hrt_assert_is_valid(tag) \
32 assert(is_valid((tag)), "invalid HR type: %u", (uint) (tag))
33
34 class HeapRegionType VALUE_OBJ_CLASS_SPEC {
35 private:
36 // We encode the value of the heap region type so the generation can be
37 // determined quickly. The tag is split into two parts:
38 //
39 // major type (young, old, humongous, archive) : top N-1 bits
40 // minor type (eden / survivor, starts / cont hum, etc.) : bottom 1 bit
41 //
42 // If there's need to increase the number of minor types in the
43 // future, we'll have to increase the size of the latter and hence
44 // decrease the size of the former.
45 //
46 // 00000 0 [ 0] Free
47 //
48 // 00001 0 [ 2] Young Mask
49 // 00001 0 [ 2] Eden
50 // 00001 1 [ 3] Survivor
51 //
52 // 00010 0 [ 4] Humongous Mask
53 // 00100 0 [ 8] Pinned Mask
54 // 00110 0 [12] Starts Humongous
55 // 00110 1 [13] Continues Humongous
56 //
57 // 01000 0 [16] Old Mask
58 //
59 // 10000 0 [32] Archive Mask
60 // 11100 0 [56] Open Archive
61 // 11100 1 [57] Closed Archive
62 //
63 typedef enum {
64 FreeTag = 0,
65
66 YoungMask = 2,
67 EdenTag = YoungMask,
68 SurvTag = YoungMask + 1,
69
70 HumongousMask = 4,
71 PinnedMask = 8,
72 StartsHumongousTag = HumongousMask | PinnedMask,
73 ContinuesHumongousTag = HumongousMask | PinnedMask + 1,
74
75 OldMask = 16,
76 OldTag = OldMask,
77
78 // Archive regions are regions with immutable content (i.e. not reclaimed, and
79 // not allocated into during regular operation). They differ in the kind of references
80 // allowed for the contained objects:
81 // - Closed archive regions form a separate self-contained (closed) object graph
82 // within the set of all of these regions. No references outside of closed
83 // archive regions are allowed.
84 // - Open archive regions have no restrictions on the references of their objects.
85 // Objects within these regions are allowed to have references to objects
86 // contained in any other kind of regions.
87 ArchiveMask = 32,
88 OpenArchiveTag = ArchiveMask | PinnedMask | OldMask,
89 ClosedArchiveTag = ArchiveMask | PinnedMask | OldMask + 1
90 } Tag;
91
92 volatile Tag _tag;
93
94 static bool is_valid(Tag tag);
95
96 Tag get() const {
97 hrt_assert_is_valid(_tag);
98 return _tag;
99 }
100
101 // Sets the type to 'tag'.
102 void set(Tag tag) {
103 hrt_assert_is_valid(tag);
104 hrt_assert_is_valid(_tag);
105 _tag = tag;
106 }
107
108 // Sets the type to 'tag', expecting the type to be 'before'. This
109 // is available for when we want to add sanity checking to the type
112 hrt_assert_is_valid(tag);
113 hrt_assert_is_valid(before);
114 hrt_assert_is_valid(_tag);
115 assert(_tag == before, "HR tag: %u, expected: %u new tag; %u", _tag, before, tag);
116 _tag = tag;
117 }
118
119 public:
120 // Queries
121
122 bool is_free() const { return get() == FreeTag; }
123
124 bool is_young() const { return (get() & YoungMask) != 0; }
125 bool is_eden() const { return get() == EdenTag; }
126 bool is_survivor() const { return get() == SurvTag; }
127
128 bool is_humongous() const { return (get() & HumongousMask) != 0; }
129 bool is_starts_humongous() const { return get() == StartsHumongousTag; }
130 bool is_continues_humongous() const { return get() == ContinuesHumongousTag; }
131
132 bool is_archive() const { return (get() & ArchiveMask) != 0; }
133 bool is_open_archive() const { return get() == OpenArchiveTag; }
134 bool is_closed_archive() const { return get() == ClosedArchiveTag; }
135
136 // is_old regions may or may not also be pinned
137 bool is_old() const { return (get() & OldMask) != 0; }
138
139 bool is_old_or_humongous() const { return (get() & (OldMask | HumongousMask)) != 0; }
140
141 // is_pinned regions may be archive or humongous
142 bool is_pinned() const { return (get() & PinnedMask) != 0; }
143
144 // Setters
145
146 void set_free() { set(FreeTag); }
147
148 void set_eden() { set_from(EdenTag, FreeTag); }
149 void set_eden_pre_gc() { set_from(EdenTag, SurvTag); }
150 void set_survivor() { set_from(SurvTag, FreeTag); }
151
152 void set_starts_humongous() { set_from(StartsHumongousTag, FreeTag); }
153 void set_continues_humongous() { set_from(ContinuesHumongousTag, FreeTag); }
154
155 void set_old() { set(OldTag); }
156
157 // Change the current region type to be of an old region type if not already done so.
158 // Returns whether the region type has been changed or not.
159 bool relabel_as_old() {
160 //assert(!is_free(), "Should not try to move Free region");
161 assert(!is_humongous(), "Should not try to move Humongous region");
162 if (is_old()) {
163 return false;
164 }
165 if (is_eden()) {
166 set_from(OldTag, EdenTag);
167 return true;
168 } else if (is_free()) {
169 set_from(OldTag, FreeTag);
170 return true;
171 } else {
172 set_from(OldTag, SurvTag);
173 return true;
174 }
175 ShouldNotReachHere();
176 return false;
177 }
178 void set_open_archive() { set_from(OpenArchiveTag, FreeTag); }
179 void set_closed_archive() { set_from(ClosedArchiveTag, FreeTag); }
180
181 // Misc
182
183 const char* get_str() const;
184 const char* get_short_str() const;
185 G1HeapRegionTraceType::Type get_trace_type();
186
187 HeapRegionType() : _tag(FreeTag) { hrt_assert_is_valid(_tag); }
188 };
189
190 #endif // SHARE_VM_GC_G1_HEAPREGIONTYPE_HPP
|