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 #include "precompiled.hpp"
26 #include "gc/g1/g1CollectedHeap.hpp"
27 #include "gc/g1/g1CollectorPolicy.hpp"
28 #include "gc/g1/heapRegion.hpp"
29 #include "gc/g1/heapRegion.inline.hpp"
30 #include "gc/g1/heapRegionRemSet.hpp"
31 #include "gc/g1/youngList.hpp"
32 #include "logging/log.hpp"
33 #include "utilities/ostream.hpp"
34
35 YoungList::YoungList(G1CollectedHeap* g1h) :
36 _g1h(g1h), _head(NULL), _length(0), _last_sampled_rs_lengths(0),
37 _survivor_head(NULL), _survivor_tail(NULL), _survivor_length(0) {
38 guarantee(check_list_empty(false), "just making sure...");
39 }
40
41 void YoungList::push_region(HeapRegion *hr) {
42 assert(!hr->is_young(), "should not already be young");
43 assert(hr->get_next_young_region() == NULL, "cause it should!");
44
45 hr->set_next_young_region(_head);
46 _head = hr;
47
48 _g1h->g1_policy()->set_region_eden(hr, (int) _length);
49 ++_length;
50 }
51
52 void YoungList::add_survivor_region(HeapRegion* hr) {
53 assert(hr->is_survivor(), "should be flagged as survivor region");
54 assert(hr->get_next_young_region() == NULL, "cause it should!");
55
56 hr->set_next_young_region(_survivor_head);
57 if (_survivor_head == NULL) {
58 _survivor_tail = hr;
69 // This is called before a Full GC and all the non-empty /
70 // non-humongous regions at the end of the Full GC will end up as
71 // old anyway.
72 list->set_old();
73 list = next;
74 }
75 }
76
77 void YoungList::empty_list() {
78 assert(check_list_well_formed(), "young list should be well formed");
79
80 empty_list(_head);
81 _head = NULL;
82 _length = 0;
83
84 empty_list(_survivor_head);
85 _survivor_head = NULL;
86 _survivor_tail = NULL;
87 _survivor_length = 0;
88
89 _last_sampled_rs_lengths = 0;
90
91 assert(check_list_empty(false), "just making sure...");
92 }
93
94 bool YoungList::check_list_well_formed() {
95 bool ret = true;
96
97 uint length = 0;
98 HeapRegion* curr = _head;
99 HeapRegion* last = NULL;
100 while (curr != NULL) {
101 if (!curr->is_young()) {
102 log_error(gc, verify)("### YOUNG REGION " PTR_FORMAT "-" PTR_FORMAT " "
103 "incorrectly tagged (y: %d, surv: %d)",
104 p2i(curr->bottom()), p2i(curr->end()),
105 curr->is_young(), curr->is_survivor());
106 ret = false;
107 }
108 ++length;
109 last = curr;
110 curr = curr->get_next_young_region();
111 }
112 ret = ret && (length == _length);
113
114 if (!ret) {
115 log_error(gc, verify)("### YOUNG LIST seems not well formed!");
116 log_error(gc, verify)("### list has %u entries, _length is %u", length, _length);
117 }
118
119 return ret;
120 }
121
122 bool YoungList::check_list_empty(bool check_sample) {
123 bool ret = true;
124
125 if (_length != 0) {
126 log_error(gc, verify)("### YOUNG LIST should have 0 length, not %u", _length);
127 ret = false;
128 }
129 if (check_sample && _last_sampled_rs_lengths != 0) {
130 log_error(gc, verify)("### YOUNG LIST has non-zero last sampled RS lengths");
131 ret = false;
132 }
133 if (_head != NULL) {
134 log_error(gc, verify)("### YOUNG LIST does not have a NULL head");
135 ret = false;
136 }
137 if (!ret) {
138 log_error(gc, verify)("### YOUNG LIST does not seem empty");
139 }
140
141 return ret;
142 }
143
144 void
145 YoungList::rs_length_sampling_init() {
146 _sampled_rs_lengths = 0;
147 _curr = _head;
148 }
149
150 bool
151 YoungList::rs_length_sampling_more() {
152 return _curr != NULL;
153 }
154
155 void
156 YoungList::rs_length_sampling_next() {
157 assert( _curr != NULL, "invariant" );
158 size_t rs_length = _curr->rem_set()->occupied();
159
160 _sampled_rs_lengths += rs_length;
161
162 // The current region may not yet have been added to the
163 // incremental collection set (it gets added when it is
164 // retired as the current allocation region).
165 if (_curr->in_collection_set()) {
166 // Update the collection set policy information for this region
167 _g1h->g1_policy()->update_incremental_cset_info(_curr, rs_length);
168 }
169
170 _curr = _curr->get_next_young_region();
171 if (_curr == NULL) {
172 _last_sampled_rs_lengths = _sampled_rs_lengths;
173 }
174 }
175
176 void
177 YoungList::reset_auxilary_lists() {
178 guarantee( is_empty(), "young list should be empty" );
179 assert(check_list_well_formed(), "young list should be well formed");
180
181 // Add survivor regions to SurvRateGroup.
182 _g1h->g1_policy()->note_start_adding_survivor_regions();
183 _g1h->g1_policy()->finished_recalculating_age_indexes(true /* is_survivors */);
184
185 int young_index_in_cset = 0;
186 for (HeapRegion* curr = _survivor_head;
187 curr != NULL;
188 curr = curr->get_next_young_region()) {
189 _g1h->g1_policy()->set_region_survivor(curr, young_index_in_cset);
190
191 // The region is a non-empty survivor so let's add it to
192 // the incremental collection set for the next evacuation
193 // pause.
|
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 #include "precompiled.hpp"
26 #include "gc/g1/g1CollectedHeap.hpp"
27 #include "gc/g1/g1CollectorPolicy.hpp"
28 #include "gc/g1/heapRegion.hpp"
29 #include "gc/g1/heapRegion.inline.hpp"
30 #include "gc/g1/heapRegionRemSet.hpp"
31 #include "gc/g1/youngList.hpp"
32 #include "logging/log.hpp"
33 #include "utilities/ostream.hpp"
34
35 YoungList::YoungList(G1CollectedHeap* g1h) :
36 _g1h(g1h), _head(NULL), _length(0),
37 _survivor_head(NULL), _survivor_tail(NULL), _survivor_length(0) {
38 guarantee(check_list_empty(), "just making sure...");
39 }
40
41 void YoungList::push_region(HeapRegion *hr) {
42 assert(!hr->is_young(), "should not already be young");
43 assert(hr->get_next_young_region() == NULL, "cause it should!");
44
45 hr->set_next_young_region(_head);
46 _head = hr;
47
48 _g1h->g1_policy()->set_region_eden(hr, (int) _length);
49 ++_length;
50 }
51
52 void YoungList::add_survivor_region(HeapRegion* hr) {
53 assert(hr->is_survivor(), "should be flagged as survivor region");
54 assert(hr->get_next_young_region() == NULL, "cause it should!");
55
56 hr->set_next_young_region(_survivor_head);
57 if (_survivor_head == NULL) {
58 _survivor_tail = hr;
69 // This is called before a Full GC and all the non-empty /
70 // non-humongous regions at the end of the Full GC will end up as
71 // old anyway.
72 list->set_old();
73 list = next;
74 }
75 }
76
77 void YoungList::empty_list() {
78 assert(check_list_well_formed(), "young list should be well formed");
79
80 empty_list(_head);
81 _head = NULL;
82 _length = 0;
83
84 empty_list(_survivor_head);
85 _survivor_head = NULL;
86 _survivor_tail = NULL;
87 _survivor_length = 0;
88
89 assert(check_list_empty(), "just making sure...");
90 }
91
92 bool YoungList::check_list_well_formed() {
93 bool ret = true;
94
95 uint length = 0;
96 HeapRegion* curr = _head;
97 HeapRegion* last = NULL;
98 while (curr != NULL) {
99 if (!curr->is_young()) {
100 log_error(gc, verify)("### YOUNG REGION " PTR_FORMAT "-" PTR_FORMAT " "
101 "incorrectly tagged (y: %d, surv: %d)",
102 p2i(curr->bottom()), p2i(curr->end()),
103 curr->is_young(), curr->is_survivor());
104 ret = false;
105 }
106 ++length;
107 last = curr;
108 curr = curr->get_next_young_region();
109 }
110 ret = ret && (length == _length);
111
112 if (!ret) {
113 log_error(gc, verify)("### YOUNG LIST seems not well formed!");
114 log_error(gc, verify)("### list has %u entries, _length is %u", length, _length);
115 }
116
117 return ret;
118 }
119
120 bool YoungList::check_list_empty() {
121 bool ret = true;
122
123 if (_length != 0) {
124 log_error(gc, verify)("### YOUNG LIST should have 0 length, not %u", _length);
125 ret = false;
126 }
127 if (_head != NULL) {
128 log_error(gc, verify)("### YOUNG LIST does not have a NULL head");
129 ret = false;
130 }
131 if (!ret) {
132 log_error(gc, verify)("### YOUNG LIST does not seem empty");
133 }
134
135 return ret;
136 }
137
138 void
139 YoungList::reset_auxilary_lists() {
140 guarantee( is_empty(), "young list should be empty" );
141 assert(check_list_well_formed(), "young list should be well formed");
142
143 // Add survivor regions to SurvRateGroup.
144 _g1h->g1_policy()->note_start_adding_survivor_regions();
145 _g1h->g1_policy()->finished_recalculating_age_indexes(true /* is_survivors */);
146
147 int young_index_in_cset = 0;
148 for (HeapRegion* curr = _survivor_head;
149 curr != NULL;
150 curr = curr->get_next_young_region()) {
151 _g1h->g1_policy()->set_region_survivor(curr, young_index_in_cset);
152
153 // The region is a non-empty survivor so let's add it to
154 // the incremental collection set for the next evacuation
155 // pause.
|