27
28 #include "memory/allocation.hpp"
29
30 #define hrt_assert_is_valid(tag) \
31 assert(is_valid((tag)), err_msg("invalid HR type: %u", (uint) (tag)))
32
33 class HeapRegionType VALUE_OBJ_CLASS_SPEC {
34 private:
35 // We encode the value of the heap region type so the generation can be
36 // determined quickly. The tag is split into two parts:
37 //
38 // major type (young, humongous) : top N-1 bits
39 // minor type (eden / survivor, starts / cont hum, etc.) : bottom 1 bit
40 //
41 // If there's need to increase the number of minor types in the
42 // future, we'll have to increase the size of the latter and hence
43 // decrease the size of the former.
44 //
45 // 0000 0 [ 0] Free
46 //
47 // 0001 0 Young Mask
48 // 0001 0 [ 2] Eden
49 // 0001 1 [ 3] Survivor
50 //
51 // 0010 0 Humongous Mask
52 // 0010 0 [ 4] Starts Humongous
53 // 0010 1 [ 5] Continues Humongous
54 //
55 // 01000 [ 8] Old
56 typedef enum {
57 FreeTag = 0,
58
59 YoungMask = 2,
60 EdenTag = YoungMask,
61 SurvTag = YoungMask + 1,
62
63 HumongousMask = 4,
64 StartsHumongousTag = HumongousMask,
65 ContinuesHumongousTag = HumongousMask + 1,
66
67 OldTag = 8
68 } Tag;
69
70 volatile Tag _tag;
71
72 static bool is_valid(Tag tag);
73
74 Tag get() const {
75 hrt_assert_is_valid(_tag);
76 return _tag;
77 }
78
79 // Sets the type to 'tag'.
80 void set(Tag tag) {
81 hrt_assert_is_valid(tag);
82 hrt_assert_is_valid(_tag);
83 _tag = tag;
84 }
85
86 // Sets the type to 'tag', expecting the type to be 'before'. This
87 // is available for when we want to add sanity checking to the type
91 hrt_assert_is_valid(before);
92 hrt_assert_is_valid(_tag);
93 assert(_tag == before,
94 err_msg("HR tag: %u, expected: %u new tag; %u", _tag, before, tag));
95 _tag = tag;
96 }
97
98 public:
99 // Queries
100
101 bool is_free() const { return get() == FreeTag; }
102
103 bool is_young() const { return (get() & YoungMask) != 0; }
104 bool is_eden() const { return get() == EdenTag; }
105 bool is_survivor() const { return get() == SurvTag; }
106
107 bool is_humongous() const { return (get() & HumongousMask) != 0; }
108 bool is_starts_humongous() const { return get() == StartsHumongousTag; }
109 bool is_continues_humongous() const { return get() == ContinuesHumongousTag; }
110
111 bool is_old() const { return get() == OldTag; }
112
113 // Setters
114
115 void set_free() { set(FreeTag); }
116
117 void set_eden() { set_from(EdenTag, FreeTag); }
118 void set_eden_pre_gc() { set_from(EdenTag, SurvTag); }
119 void set_survivor() { set_from(SurvTag, FreeTag); }
120
121 void set_starts_humongous() { set_from(StartsHumongousTag, FreeTag); }
122 void set_continues_humongous() { set_from(ContinuesHumongousTag, FreeTag); }
123
124 void set_old() { set(OldTag); }
125
126 // Misc
127
128 const char* get_str() const;
129 const char* get_short_str() const;
130
131 HeapRegionType() : _tag(FreeTag) { hrt_assert_is_valid(_tag); }
132 };
133
134 #endif // SHARE_VM_GC_G1_HEAPREGIONTYPE_HPP
|
27
28 #include "memory/allocation.hpp"
29
30 #define hrt_assert_is_valid(tag) \
31 assert(is_valid((tag)), err_msg("invalid HR type: %u", (uint) (tag)))
32
33 class HeapRegionType VALUE_OBJ_CLASS_SPEC {
34 private:
35 // We encode the value of the heap region type so the generation can be
36 // determined quickly. The tag is split into two parts:
37 //
38 // major type (young, humongous) : top N-1 bits
39 // minor type (eden / survivor, starts / cont hum, etc.) : bottom 1 bit
40 //
41 // If there's need to increase the number of minor types in the
42 // future, we'll have to increase the size of the latter and hence
43 // decrease the size of the former.
44 //
45 // 0000 0 [ 0] Free
46 //
47 // 0001 0 [ 2] Young Mask
48 // 0001 0 [ 2] Eden
49 // 0001 1 [ 3] Survivor
50 //
51 // 0010 0 [ 4] Humongous Mask
52 // 0100 0 [ 8] Pinned Mask
53 // 0110 0 [12] Starts Humongous
54 // 0110 1 [13] Continues Humongous
55 //
56 // 1000 0 [16] Old Mask
57 //
58 // 1100 0 [24] Archive
59 typedef enum {
60 FreeTag = 0,
61
62 YoungMask = 2,
63 EdenTag = YoungMask,
64 SurvTag = YoungMask + 1,
65
66 HumongousMask = 4,
67 PinnedMask = 8,
68 StartsHumongousTag = HumongousMask | PinnedMask,
69 ContinuesHumongousTag = HumongousMask | PinnedMask + 1,
70
71 OldMask = 16,
72 OldTag = OldMask,
73
74 ArchiveTag = PinnedMask | OldMask
75 } Tag;
76
77 volatile Tag _tag;
78
79 static bool is_valid(Tag tag);
80
81 Tag get() const {
82 hrt_assert_is_valid(_tag);
83 return _tag;
84 }
85
86 // Sets the type to 'tag'.
87 void set(Tag tag) {
88 hrt_assert_is_valid(tag);
89 hrt_assert_is_valid(_tag);
90 _tag = tag;
91 }
92
93 // Sets the type to 'tag', expecting the type to be 'before'. This
94 // is available for when we want to add sanity checking to the type
98 hrt_assert_is_valid(before);
99 hrt_assert_is_valid(_tag);
100 assert(_tag == before,
101 err_msg("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 // is_pinned regions may be archive or humongous
124 bool is_pinned() const { return (get() & PinnedMask) != 0; }
125
126 // Setters
127
128 void set_free() { set(FreeTag); }
129
130 void set_eden() { set_from(EdenTag, FreeTag); }
131 void set_eden_pre_gc() { set_from(EdenTag, SurvTag); }
132 void set_survivor() { set_from(SurvTag, FreeTag); }
133
134 void set_starts_humongous() { set_from(StartsHumongousTag, FreeTag); }
135 void set_continues_humongous() { set_from(ContinuesHumongousTag, FreeTag); }
136
137 void set_old() { set(OldTag); }
138
139 void set_archive() { set_from(ArchiveTag, FreeTag); }
140
141 // Misc
142
143 const char* get_str() const;
144 const char* get_short_str() const;
145
146 HeapRegionType() : _tag(FreeTag) { hrt_assert_is_valid(_tag); }
147 };
148
149 #endif // SHARE_VM_GC_G1_HEAPREGIONTYPE_HPP
|