Mon, 09 Jun 2008 07:18:59 -0700
6711930: NUMA allocator: ParOld can create a hole less than minimal object size in the lgrp chunk
Summary: The fix takes care of three issues that can create a hole less a minimal object in the lgrp chunk
Reviewed-by: ysr, apetrusenko
1 /*
2 * Copyright 1997-2005 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 *
23 */
25 #include "incls/_precompiled.incl"
26 #include "incls/_markSweep.cpp.incl"
28 GrowableArray<oop>* MarkSweep::_marking_stack = NULL;
29 GrowableArray<Klass*>* MarkSweep::_revisit_klass_stack = NULL;
31 GrowableArray<oop>* MarkSweep::_preserved_oop_stack = NULL;
32 GrowableArray<markOop>* MarkSweep::_preserved_mark_stack= NULL;
33 size_t MarkSweep::_preserved_count = 0;
34 size_t MarkSweep::_preserved_count_max = 0;
35 PreservedMark* MarkSweep::_preserved_marks = NULL;
36 ReferenceProcessor* MarkSweep::_ref_processor = NULL;
38 #ifdef VALIDATE_MARK_SWEEP
39 GrowableArray<void*>* MarkSweep::_root_refs_stack = NULL;
40 GrowableArray<oop> * MarkSweep::_live_oops = NULL;
41 GrowableArray<oop> * MarkSweep::_live_oops_moved_to = NULL;
42 GrowableArray<size_t>* MarkSweep::_live_oops_size = NULL;
43 size_t MarkSweep::_live_oops_index = 0;
44 size_t MarkSweep::_live_oops_index_at_perm = 0;
45 GrowableArray<void*>* MarkSweep::_other_refs_stack = NULL;
46 GrowableArray<void*>* MarkSweep::_adjusted_pointers = NULL;
47 bool MarkSweep::_pointer_tracking = false;
48 bool MarkSweep::_root_tracking = true;
50 GrowableArray<HeapWord*>* MarkSweep::_cur_gc_live_oops = NULL;
51 GrowableArray<HeapWord*>* MarkSweep::_cur_gc_live_oops_moved_to = NULL;
52 GrowableArray<size_t> * MarkSweep::_cur_gc_live_oops_size = NULL;
53 GrowableArray<HeapWord*>* MarkSweep::_last_gc_live_oops = NULL;
54 GrowableArray<HeapWord*>* MarkSweep::_last_gc_live_oops_moved_to = NULL;
55 GrowableArray<size_t> * MarkSweep::_last_gc_live_oops_size = NULL;
56 #endif
58 void MarkSweep::revisit_weak_klass_link(Klass* k) {
59 _revisit_klass_stack->push(k);
60 }
62 void MarkSweep::follow_weak_klass_links() {
63 // All klasses on the revisit stack are marked at this point.
64 // Update and follow all subklass, sibling and implementor links.
65 for (int i = 0; i < _revisit_klass_stack->length(); i++) {
66 _revisit_klass_stack->at(i)->follow_weak_klass_links(&is_alive,&keep_alive);
67 }
68 follow_stack();
69 }
71 MarkSweep::FollowRootClosure MarkSweep::follow_root_closure;
73 void MarkSweep::FollowRootClosure::do_oop(oop* p) { follow_root(p); }
74 void MarkSweep::FollowRootClosure::do_oop(narrowOop* p) { follow_root(p); }
76 MarkSweep::MarkAndPushClosure MarkSweep::mark_and_push_closure;
78 void MarkSweep::MarkAndPushClosure::do_oop(oop* p) { mark_and_push(p); }
79 void MarkSweep::MarkAndPushClosure::do_oop(narrowOop* p) { mark_and_push(p); }
81 void MarkSweep::follow_stack() {
82 while (!_marking_stack->is_empty()) {
83 oop obj = _marking_stack->pop();
84 assert (obj->is_gc_marked(), "p must be marked");
85 obj->follow_contents();
86 }
87 }
89 MarkSweep::FollowStackClosure MarkSweep::follow_stack_closure;
91 void MarkSweep::FollowStackClosure::do_void() { follow_stack(); }
93 // We preserve the mark which should be replaced at the end and the location that it
94 // will go. Note that the object that this markOop belongs to isn't currently at that
95 // address but it will be after phase4
96 void MarkSweep::preserve_mark(oop obj, markOop mark) {
97 // we try to store preserved marks in the to space of the new generation since this
98 // is storage which should be available. Most of the time this should be sufficient
99 // space for the marks we need to preserve but if it isn't we fall back in using
100 // GrowableArrays to keep track of the overflow.
101 if (_preserved_count < _preserved_count_max) {
102 _preserved_marks[_preserved_count++].init(obj, mark);
103 } else {
104 if (_preserved_mark_stack == NULL) {
105 _preserved_mark_stack = new (ResourceObj::C_HEAP) GrowableArray<markOop>(40, true);
106 _preserved_oop_stack = new (ResourceObj::C_HEAP) GrowableArray<oop>(40, true);
107 }
108 _preserved_mark_stack->push(mark);
109 _preserved_oop_stack->push(obj);
110 }
111 }
113 MarkSweep::AdjustPointerClosure MarkSweep::adjust_root_pointer_closure(true);
114 MarkSweep::AdjustPointerClosure MarkSweep::adjust_pointer_closure(false);
116 void MarkSweep::AdjustPointerClosure::do_oop(oop* p) { adjust_pointer(p, _is_root); }
117 void MarkSweep::AdjustPointerClosure::do_oop(narrowOop* p) { adjust_pointer(p, _is_root); }
119 void MarkSweep::adjust_marks() {
120 assert(_preserved_oop_stack == NULL ||
121 _preserved_oop_stack->length() == _preserved_mark_stack->length(),
122 "inconsistent preserved oop stacks");
124 // adjust the oops we saved earlier
125 for (size_t i = 0; i < _preserved_count; i++) {
126 _preserved_marks[i].adjust_pointer();
127 }
129 // deal with the overflow stack
130 if (_preserved_oop_stack) {
131 for (int i = 0; i < _preserved_oop_stack->length(); i++) {
132 oop* p = _preserved_oop_stack->adr_at(i);
133 adjust_pointer(p);
134 }
135 }
136 }
138 void MarkSweep::restore_marks() {
139 assert(_preserved_oop_stack == NULL ||
140 _preserved_oop_stack->length() == _preserved_mark_stack->length(),
141 "inconsistent preserved oop stacks");
142 if (PrintGC && Verbose) {
143 gclog_or_tty->print_cr("Restoring %d marks", _preserved_count +
144 (_preserved_oop_stack ? _preserved_oop_stack->length() : 0));
145 }
147 // restore the marks we saved earlier
148 for (size_t i = 0; i < _preserved_count; i++) {
149 _preserved_marks[i].restore();
150 }
152 // deal with the overflow
153 if (_preserved_oop_stack) {
154 for (int i = 0; i < _preserved_oop_stack->length(); i++) {
155 oop obj = _preserved_oop_stack->at(i);
156 markOop mark = _preserved_mark_stack->at(i);
157 obj->set_mark(mark);
158 }
159 }
160 }
162 #ifdef VALIDATE_MARK_SWEEP
164 void MarkSweep::track_adjusted_pointer(void* p, bool isroot) {
165 if (!ValidateMarkSweep)
166 return;
168 if (!isroot) {
169 if (_pointer_tracking) {
170 guarantee(_adjusted_pointers->contains(p), "should have seen this pointer");
171 _adjusted_pointers->remove(p);
172 }
173 } else {
174 ptrdiff_t index = _root_refs_stack->find(p);
175 if (index != -1) {
176 int l = _root_refs_stack->length();
177 if (l > 0 && l - 1 != index) {
178 void* last = _root_refs_stack->pop();
179 assert(last != p, "should be different");
180 _root_refs_stack->at_put(index, last);
181 } else {
182 _root_refs_stack->remove(p);
183 }
184 }
185 }
186 }
188 void MarkSweep::check_adjust_pointer(void* p) {
189 _adjusted_pointers->push(p);
190 }
192 class AdjusterTracker: public OopClosure {
193 public:
194 AdjusterTracker() {}
195 void do_oop(oop* o) { MarkSweep::check_adjust_pointer(o); }
196 void do_oop(narrowOop* o) { MarkSweep::check_adjust_pointer(o); }
197 };
199 void MarkSweep::track_interior_pointers(oop obj) {
200 if (ValidateMarkSweep) {
201 _adjusted_pointers->clear();
202 _pointer_tracking = true;
204 AdjusterTracker checker;
205 obj->oop_iterate(&checker);
206 }
207 }
209 void MarkSweep::check_interior_pointers() {
210 if (ValidateMarkSweep) {
211 _pointer_tracking = false;
212 guarantee(_adjusted_pointers->length() == 0, "should have processed the same pointers");
213 }
214 }
216 void MarkSweep::reset_live_oop_tracking(bool at_perm) {
217 if (ValidateMarkSweep) {
218 guarantee((size_t)_live_oops->length() == _live_oops_index, "should be at end of live oops");
219 _live_oops_index = at_perm ? _live_oops_index_at_perm : 0;
220 }
221 }
223 void MarkSweep::register_live_oop(oop p, size_t size) {
224 if (ValidateMarkSweep) {
225 _live_oops->push(p);
226 _live_oops_size->push(size);
227 _live_oops_index++;
228 }
229 }
231 void MarkSweep::validate_live_oop(oop p, size_t size) {
232 if (ValidateMarkSweep) {
233 oop obj = _live_oops->at((int)_live_oops_index);
234 guarantee(obj == p, "should be the same object");
235 guarantee(_live_oops_size->at((int)_live_oops_index) == size, "should be the same size");
236 _live_oops_index++;
237 }
238 }
240 void MarkSweep::live_oop_moved_to(HeapWord* q, size_t size,
241 HeapWord* compaction_top) {
242 assert(oop(q)->forwardee() == NULL || oop(q)->forwardee() == oop(compaction_top),
243 "should be moved to forwarded location");
244 if (ValidateMarkSweep) {
245 MarkSweep::validate_live_oop(oop(q), size);
246 _live_oops_moved_to->push(oop(compaction_top));
247 }
248 if (RecordMarkSweepCompaction) {
249 _cur_gc_live_oops->push(q);
250 _cur_gc_live_oops_moved_to->push(compaction_top);
251 _cur_gc_live_oops_size->push(size);
252 }
253 }
255 void MarkSweep::compaction_complete() {
256 if (RecordMarkSweepCompaction) {
257 GrowableArray<HeapWord*>* _tmp_live_oops = _cur_gc_live_oops;
258 GrowableArray<HeapWord*>* _tmp_live_oops_moved_to = _cur_gc_live_oops_moved_to;
259 GrowableArray<size_t> * _tmp_live_oops_size = _cur_gc_live_oops_size;
261 _cur_gc_live_oops = _last_gc_live_oops;
262 _cur_gc_live_oops_moved_to = _last_gc_live_oops_moved_to;
263 _cur_gc_live_oops_size = _last_gc_live_oops_size;
264 _last_gc_live_oops = _tmp_live_oops;
265 _last_gc_live_oops_moved_to = _tmp_live_oops_moved_to;
266 _last_gc_live_oops_size = _tmp_live_oops_size;
267 }
268 }
270 void MarkSweep::print_new_location_of_heap_address(HeapWord* q) {
271 if (!RecordMarkSweepCompaction) {
272 tty->print_cr("Requires RecordMarkSweepCompaction to be enabled");
273 return;
274 }
276 if (_last_gc_live_oops == NULL) {
277 tty->print_cr("No compaction information gathered yet");
278 return;
279 }
281 for (int i = 0; i < _last_gc_live_oops->length(); i++) {
282 HeapWord* old_oop = _last_gc_live_oops->at(i);
283 size_t sz = _last_gc_live_oops_size->at(i);
284 if (old_oop <= q && q < (old_oop + sz)) {
285 HeapWord* new_oop = _last_gc_live_oops_moved_to->at(i);
286 size_t offset = (q - old_oop);
287 tty->print_cr("Address " PTR_FORMAT, q);
288 tty->print_cr(" Was in oop " PTR_FORMAT ", size " SIZE_FORMAT ", at offset " SIZE_FORMAT, old_oop, sz, offset);
289 tty->print_cr(" Now in oop " PTR_FORMAT ", actual address " PTR_FORMAT, new_oop, new_oop + offset);
290 return;
291 }
292 }
294 tty->print_cr("Address " PTR_FORMAT " not found in live oop information from last GC", q);
295 }
296 #endif //VALIDATE_MARK_SWEEP
298 MarkSweep::IsAliveClosure MarkSweep::is_alive;
300 void MarkSweep::IsAliveClosure::do_object(oop p) { ShouldNotReachHere(); }
301 bool MarkSweep::IsAliveClosure::do_object_b(oop p) { return p->is_gc_marked(); }
303 MarkSweep::KeepAliveClosure MarkSweep::keep_alive;
305 void MarkSweep::KeepAliveClosure::do_oop(oop* p) { MarkSweep::KeepAliveClosure::do_oop_work(p); }
306 void MarkSweep::KeepAliveClosure::do_oop(narrowOop* p) { MarkSweep::KeepAliveClosure::do_oop_work(p); }
308 void marksweep_init() { /* empty */ }
310 #ifndef PRODUCT
312 void MarkSweep::trace(const char* msg) {
313 if (TraceMarkSweep)
314 gclog_or_tty->print("%s", msg);
315 }
317 #endif