Thu, 27 May 2010 19:08:38 -0700
6941466: Oracle rebranding changes for Hotspot repositories
Summary: Change all the Sun copyrights to Oracle copyright
Reviewed-by: ohair
1 /*
2 * Copyright (c) 1997, 2009, 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 *
23 */
25 #include "incls/_precompiled.incl"
26 #include "incls/_markSweep.cpp.incl"
28 GrowableArray<oop>* MarkSweep::_marking_stack = NULL;
29 GrowableArray<ObjArrayTask>* MarkSweep::_objarray_stack = NULL;
30 GrowableArray<Klass*>* MarkSweep::_revisit_klass_stack = NULL;
31 GrowableArray<DataLayout*>* MarkSweep::_revisit_mdo_stack = NULL;
33 GrowableArray<oop>* MarkSweep::_preserved_oop_stack = NULL;
34 GrowableArray<markOop>* MarkSweep::_preserved_mark_stack= NULL;
35 size_t MarkSweep::_preserved_count = 0;
36 size_t MarkSweep::_preserved_count_max = 0;
37 PreservedMark* MarkSweep::_preserved_marks = NULL;
38 ReferenceProcessor* MarkSweep::_ref_processor = NULL;
40 #ifdef VALIDATE_MARK_SWEEP
41 GrowableArray<void*>* MarkSweep::_root_refs_stack = NULL;
42 GrowableArray<oop> * MarkSweep::_live_oops = NULL;
43 GrowableArray<oop> * MarkSweep::_live_oops_moved_to = NULL;
44 GrowableArray<size_t>* MarkSweep::_live_oops_size = NULL;
45 size_t MarkSweep::_live_oops_index = 0;
46 size_t MarkSweep::_live_oops_index_at_perm = 0;
47 GrowableArray<void*>* MarkSweep::_other_refs_stack = NULL;
48 GrowableArray<void*>* MarkSweep::_adjusted_pointers = NULL;
49 bool MarkSweep::_pointer_tracking = false;
50 bool MarkSweep::_root_tracking = true;
52 GrowableArray<HeapWord*>* MarkSweep::_cur_gc_live_oops = NULL;
53 GrowableArray<HeapWord*>* MarkSweep::_cur_gc_live_oops_moved_to = NULL;
54 GrowableArray<size_t> * MarkSweep::_cur_gc_live_oops_size = NULL;
55 GrowableArray<HeapWord*>* MarkSweep::_last_gc_live_oops = NULL;
56 GrowableArray<HeapWord*>* MarkSweep::_last_gc_live_oops_moved_to = NULL;
57 GrowableArray<size_t> * MarkSweep::_last_gc_live_oops_size = NULL;
58 #endif
60 void MarkSweep::revisit_weak_klass_link(Klass* k) {
61 _revisit_klass_stack->push(k);
62 }
64 void MarkSweep::follow_weak_klass_links() {
65 // All klasses on the revisit stack are marked at this point.
66 // Update and follow all subklass, sibling and implementor links.
67 if (PrintRevisitStats) {
68 gclog_or_tty->print_cr("#classes in system dictionary = %d", SystemDictionary::number_of_classes());
69 gclog_or_tty->print_cr("Revisit klass stack length = %d", _revisit_klass_stack->length());
70 }
71 for (int i = 0; i < _revisit_klass_stack->length(); i++) {
72 _revisit_klass_stack->at(i)->follow_weak_klass_links(&is_alive,&keep_alive);
73 }
74 follow_stack();
75 }
77 void MarkSweep::revisit_mdo(DataLayout* p) {
78 _revisit_mdo_stack->push(p);
79 }
81 void MarkSweep::follow_mdo_weak_refs() {
82 // All strongly reachable oops have been marked at this point;
83 // we can visit and clear any weak references from MDO's which
84 // we memoized during the strong marking phase.
85 assert(_marking_stack->is_empty(), "Marking stack should be empty");
86 if (PrintRevisitStats) {
87 gclog_or_tty->print_cr("#classes in system dictionary = %d", SystemDictionary::number_of_classes());
88 gclog_or_tty->print_cr("Revisit MDO stack length = %d", _revisit_mdo_stack->length());
89 }
90 for (int i = 0; i < _revisit_mdo_stack->length(); i++) {
91 _revisit_mdo_stack->at(i)->follow_weak_refs(&is_alive);
92 }
93 follow_stack();
94 }
96 MarkSweep::FollowRootClosure MarkSweep::follow_root_closure;
97 CodeBlobToOopClosure MarkSweep::follow_code_root_closure(&MarkSweep::follow_root_closure, /*do_marking=*/ true);
99 void MarkSweep::FollowRootClosure::do_oop(oop* p) { follow_root(p); }
100 void MarkSweep::FollowRootClosure::do_oop(narrowOop* p) { follow_root(p); }
102 MarkSweep::MarkAndPushClosure MarkSweep::mark_and_push_closure;
104 void MarkSweep::MarkAndPushClosure::do_oop(oop* p) { mark_and_push(p); }
105 void MarkSweep::MarkAndPushClosure::do_oop(narrowOop* p) { mark_and_push(p); }
107 void MarkSweep::follow_stack() {
108 do {
109 while (!_marking_stack->is_empty()) {
110 oop obj = _marking_stack->pop();
111 assert (obj->is_gc_marked(), "p must be marked");
112 obj->follow_contents();
113 }
114 // Process ObjArrays one at a time to avoid marking stack bloat.
115 if (!_objarray_stack->is_empty()) {
116 ObjArrayTask task = _objarray_stack->pop();
117 objArrayKlass* const k = (objArrayKlass*)task.obj()->blueprint();
118 k->oop_follow_contents(task.obj(), task.index());
119 }
120 } while (!_marking_stack->is_empty() || !_objarray_stack->is_empty());
121 }
123 MarkSweep::FollowStackClosure MarkSweep::follow_stack_closure;
125 void MarkSweep::FollowStackClosure::do_void() { follow_stack(); }
127 // We preserve the mark which should be replaced at the end and the location that it
128 // will go. Note that the object that this markOop belongs to isn't currently at that
129 // address but it will be after phase4
130 void MarkSweep::preserve_mark(oop obj, markOop mark) {
131 // we try to store preserved marks in the to space of the new generation since this
132 // is storage which should be available. Most of the time this should be sufficient
133 // space for the marks we need to preserve but if it isn't we fall back in using
134 // GrowableArrays to keep track of the overflow.
135 if (_preserved_count < _preserved_count_max) {
136 _preserved_marks[_preserved_count++].init(obj, mark);
137 } else {
138 if (_preserved_mark_stack == NULL) {
139 _preserved_mark_stack = new (ResourceObj::C_HEAP) GrowableArray<markOop>(40, true);
140 _preserved_oop_stack = new (ResourceObj::C_HEAP) GrowableArray<oop>(40, true);
141 }
142 _preserved_mark_stack->push(mark);
143 _preserved_oop_stack->push(obj);
144 }
145 }
147 MarkSweep::AdjustPointerClosure MarkSweep::adjust_root_pointer_closure(true);
148 MarkSweep::AdjustPointerClosure MarkSweep::adjust_pointer_closure(false);
150 void MarkSweep::AdjustPointerClosure::do_oop(oop* p) { adjust_pointer(p, _is_root); }
151 void MarkSweep::AdjustPointerClosure::do_oop(narrowOop* p) { adjust_pointer(p, _is_root); }
153 void MarkSweep::adjust_marks() {
154 assert(_preserved_oop_stack == NULL ||
155 _preserved_oop_stack->length() == _preserved_mark_stack->length(),
156 "inconsistent preserved oop stacks");
158 // adjust the oops we saved earlier
159 for (size_t i = 0; i < _preserved_count; i++) {
160 _preserved_marks[i].adjust_pointer();
161 }
163 // deal with the overflow stack
164 if (_preserved_oop_stack) {
165 for (int i = 0; i < _preserved_oop_stack->length(); i++) {
166 oop* p = _preserved_oop_stack->adr_at(i);
167 adjust_pointer(p);
168 }
169 }
170 }
172 void MarkSweep::restore_marks() {
173 assert(_preserved_oop_stack == NULL ||
174 _preserved_oop_stack->length() == _preserved_mark_stack->length(),
175 "inconsistent preserved oop stacks");
176 if (PrintGC && Verbose) {
177 gclog_or_tty->print_cr("Restoring %d marks", _preserved_count +
178 (_preserved_oop_stack ? _preserved_oop_stack->length() : 0));
179 }
181 // restore the marks we saved earlier
182 for (size_t i = 0; i < _preserved_count; i++) {
183 _preserved_marks[i].restore();
184 }
186 // deal with the overflow
187 if (_preserved_oop_stack) {
188 for (int i = 0; i < _preserved_oop_stack->length(); i++) {
189 oop obj = _preserved_oop_stack->at(i);
190 markOop mark = _preserved_mark_stack->at(i);
191 obj->set_mark(mark);
192 }
193 }
194 }
196 #ifdef VALIDATE_MARK_SWEEP
198 void MarkSweep::track_adjusted_pointer(void* p, bool isroot) {
199 if (!ValidateMarkSweep)
200 return;
202 if (!isroot) {
203 if (_pointer_tracking) {
204 guarantee(_adjusted_pointers->contains(p), "should have seen this pointer");
205 _adjusted_pointers->remove(p);
206 }
207 } else {
208 ptrdiff_t index = _root_refs_stack->find(p);
209 if (index != -1) {
210 int l = _root_refs_stack->length();
211 if (l > 0 && l - 1 != index) {
212 void* last = _root_refs_stack->pop();
213 assert(last != p, "should be different");
214 _root_refs_stack->at_put(index, last);
215 } else {
216 _root_refs_stack->remove(p);
217 }
218 }
219 }
220 }
222 void MarkSweep::check_adjust_pointer(void* p) {
223 _adjusted_pointers->push(p);
224 }
226 class AdjusterTracker: public OopClosure {
227 public:
228 AdjusterTracker() {}
229 void do_oop(oop* o) { MarkSweep::check_adjust_pointer(o); }
230 void do_oop(narrowOop* o) { MarkSweep::check_adjust_pointer(o); }
231 };
233 void MarkSweep::track_interior_pointers(oop obj) {
234 if (ValidateMarkSweep) {
235 _adjusted_pointers->clear();
236 _pointer_tracking = true;
238 AdjusterTracker checker;
239 obj->oop_iterate(&checker);
240 }
241 }
243 void MarkSweep::check_interior_pointers() {
244 if (ValidateMarkSweep) {
245 _pointer_tracking = false;
246 guarantee(_adjusted_pointers->length() == 0, "should have processed the same pointers");
247 }
248 }
250 void MarkSweep::reset_live_oop_tracking(bool at_perm) {
251 if (ValidateMarkSweep) {
252 guarantee((size_t)_live_oops->length() == _live_oops_index, "should be at end of live oops");
253 _live_oops_index = at_perm ? _live_oops_index_at_perm : 0;
254 }
255 }
257 void MarkSweep::register_live_oop(oop p, size_t size) {
258 if (ValidateMarkSweep) {
259 _live_oops->push(p);
260 _live_oops_size->push(size);
261 _live_oops_index++;
262 }
263 }
265 void MarkSweep::validate_live_oop(oop p, size_t size) {
266 if (ValidateMarkSweep) {
267 oop obj = _live_oops->at((int)_live_oops_index);
268 guarantee(obj == p, "should be the same object");
269 guarantee(_live_oops_size->at((int)_live_oops_index) == size, "should be the same size");
270 _live_oops_index++;
271 }
272 }
274 void MarkSweep::live_oop_moved_to(HeapWord* q, size_t size,
275 HeapWord* compaction_top) {
276 assert(oop(q)->forwardee() == NULL || oop(q)->forwardee() == oop(compaction_top),
277 "should be moved to forwarded location");
278 if (ValidateMarkSweep) {
279 MarkSweep::validate_live_oop(oop(q), size);
280 _live_oops_moved_to->push(oop(compaction_top));
281 }
282 if (RecordMarkSweepCompaction) {
283 _cur_gc_live_oops->push(q);
284 _cur_gc_live_oops_moved_to->push(compaction_top);
285 _cur_gc_live_oops_size->push(size);
286 }
287 }
289 void MarkSweep::compaction_complete() {
290 if (RecordMarkSweepCompaction) {
291 GrowableArray<HeapWord*>* _tmp_live_oops = _cur_gc_live_oops;
292 GrowableArray<HeapWord*>* _tmp_live_oops_moved_to = _cur_gc_live_oops_moved_to;
293 GrowableArray<size_t> * _tmp_live_oops_size = _cur_gc_live_oops_size;
295 _cur_gc_live_oops = _last_gc_live_oops;
296 _cur_gc_live_oops_moved_to = _last_gc_live_oops_moved_to;
297 _cur_gc_live_oops_size = _last_gc_live_oops_size;
298 _last_gc_live_oops = _tmp_live_oops;
299 _last_gc_live_oops_moved_to = _tmp_live_oops_moved_to;
300 _last_gc_live_oops_size = _tmp_live_oops_size;
301 }
302 }
304 void MarkSweep::print_new_location_of_heap_address(HeapWord* q) {
305 if (!RecordMarkSweepCompaction) {
306 tty->print_cr("Requires RecordMarkSweepCompaction to be enabled");
307 return;
308 }
310 if (_last_gc_live_oops == NULL) {
311 tty->print_cr("No compaction information gathered yet");
312 return;
313 }
315 for (int i = 0; i < _last_gc_live_oops->length(); i++) {
316 HeapWord* old_oop = _last_gc_live_oops->at(i);
317 size_t sz = _last_gc_live_oops_size->at(i);
318 if (old_oop <= q && q < (old_oop + sz)) {
319 HeapWord* new_oop = _last_gc_live_oops_moved_to->at(i);
320 size_t offset = (q - old_oop);
321 tty->print_cr("Address " PTR_FORMAT, q);
322 tty->print_cr(" Was in oop " PTR_FORMAT ", size " SIZE_FORMAT ", at offset " SIZE_FORMAT, old_oop, sz, offset);
323 tty->print_cr(" Now in oop " PTR_FORMAT ", actual address " PTR_FORMAT, new_oop, new_oop + offset);
324 return;
325 }
326 }
328 tty->print_cr("Address " PTR_FORMAT " not found in live oop information from last GC", q);
329 }
330 #endif //VALIDATE_MARK_SWEEP
332 MarkSweep::IsAliveClosure MarkSweep::is_alive;
334 void MarkSweep::IsAliveClosure::do_object(oop p) { ShouldNotReachHere(); }
335 bool MarkSweep::IsAliveClosure::do_object_b(oop p) { return p->is_gc_marked(); }
337 MarkSweep::KeepAliveClosure MarkSweep::keep_alive;
339 void MarkSweep::KeepAliveClosure::do_oop(oop* p) { MarkSweep::KeepAliveClosure::do_oop_work(p); }
340 void MarkSweep::KeepAliveClosure::do_oop(narrowOop* p) { MarkSweep::KeepAliveClosure::do_oop_work(p); }
342 void marksweep_init() { /* empty */ }
344 #ifndef PRODUCT
346 void MarkSweep::trace(const char* msg) {
347 if (TraceMarkSweep)
348 gclog_or_tty->print("%s", msg);
349 }
351 #endif