Mon, 07 Jul 2014 10:12:40 +0200
8049421: G1 Class Unloading after completing a concurrent mark cycle
Reviewed-by: tschatzl, ehelin, brutisso, coleenp, roland, iveresov
Contributed-by: stefan.karlsson@oracle.com, mikael.gerdin@oracle.com
duke@435 | 1 | /* |
drchase@6680 | 2 | * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. |
duke@435 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@435 | 4 | * |
duke@435 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@435 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@435 | 7 | * published by the Free Software Foundation. |
duke@435 | 8 | * |
duke@435 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@435 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@435 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@435 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@435 | 13 | * accompanied this code). |
duke@435 | 14 | * |
duke@435 | 15 | * You should have received a copy of the GNU General Public License version |
duke@435 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@435 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@435 | 18 | * |
trims@1907 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
trims@1907 | 20 | * or visit www.oracle.com if you need additional information or have any |
trims@1907 | 21 | * questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
stefank@2314 | 25 | #include "precompiled.hpp" |
stefank@2314 | 26 | #include "compiler/compileBroker.hpp" |
sla@5237 | 27 | #include "gc_implementation/shared/gcTimer.hpp" |
sla@5237 | 28 | #include "gc_implementation/shared/gcTrace.hpp" |
stefank@2314 | 29 | #include "gc_implementation/shared/markSweep.inline.hpp" |
stefank@2314 | 30 | #include "gc_interface/collectedHeap.inline.hpp" |
coleenp@4037 | 31 | #include "oops/methodData.hpp" |
stefank@2314 | 32 | #include "oops/objArrayKlass.inline.hpp" |
stefank@2314 | 33 | #include "oops/oop.inline.hpp" |
duke@435 | 34 | |
drchase@6680 | 35 | PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC |
drchase@6680 | 36 | |
tschatzl@5119 | 37 | uint MarkSweep::_total_invocations = 0; |
coleenp@4037 | 38 | |
zgu@3900 | 39 | Stack<oop, mtGC> MarkSweep::_marking_stack; |
zgu@3900 | 40 | Stack<ObjArrayTask, mtGC> MarkSweep::_objarray_stack; |
duke@435 | 41 | |
zgu@3900 | 42 | Stack<oop, mtGC> MarkSweep::_preserved_oop_stack; |
zgu@3900 | 43 | Stack<markOop, mtGC> MarkSweep::_preserved_mark_stack; |
duke@435 | 44 | size_t MarkSweep::_preserved_count = 0; |
duke@435 | 45 | size_t MarkSweep::_preserved_count_max = 0; |
duke@435 | 46 | PreservedMark* MarkSweep::_preserved_marks = NULL; |
duke@435 | 47 | ReferenceProcessor* MarkSweep::_ref_processor = NULL; |
sla@5237 | 48 | STWGCTimer* MarkSweep::_gc_timer = NULL; |
sla@5237 | 49 | SerialOldTracer* MarkSweep::_gc_tracer = NULL; |
duke@435 | 50 | |
coleenp@548 | 51 | MarkSweep::FollowRootClosure MarkSweep::follow_root_closure; |
duke@435 | 52 | |
coleenp@548 | 53 | void MarkSweep::FollowRootClosure::do_oop(oop* p) { follow_root(p); } |
coleenp@548 | 54 | void MarkSweep::FollowRootClosure::do_oop(narrowOop* p) { follow_root(p); } |
duke@435 | 55 | |
duke@435 | 56 | MarkSweep::MarkAndPushClosure MarkSweep::mark_and_push_closure; |
stefank@6992 | 57 | CLDToOopClosure MarkSweep::follow_cld_closure(&mark_and_push_closure); |
stefank@6992 | 58 | CLDToOopClosure MarkSweep::adjust_cld_closure(&adjust_pointer_closure); |
duke@435 | 59 | |
coleenp@4037 | 60 | void MarkSweep::MarkAndPushClosure::do_oop(oop* p) { mark_and_push(p); } |
coleenp@548 | 61 | void MarkSweep::MarkAndPushClosure::do_oop(narrowOop* p) { mark_and_push(p); } |
duke@435 | 62 | |
coleenp@4037 | 63 | void MarkSweep::follow_class_loader(ClassLoaderData* cld) { |
stefank@6992 | 64 | MarkSweep::follow_cld_closure.do_cld(cld); |
coleenp@4037 | 65 | } |
coleenp@4037 | 66 | |
duke@435 | 67 | void MarkSweep::follow_stack() { |
jcoomes@1746 | 68 | do { |
jcoomes@2191 | 69 | while (!_marking_stack.is_empty()) { |
jcoomes@2191 | 70 | oop obj = _marking_stack.pop(); |
jcoomes@1746 | 71 | assert (obj->is_gc_marked(), "p must be marked"); |
jcoomes@1746 | 72 | obj->follow_contents(); |
jcoomes@1746 | 73 | } |
jcoomes@1750 | 74 | // Process ObjArrays one at a time to avoid marking stack bloat. |
jcoomes@2191 | 75 | if (!_objarray_stack.is_empty()) { |
jcoomes@2191 | 76 | ObjArrayTask task = _objarray_stack.pop(); |
minqi@5097 | 77 | ObjArrayKlass* k = (ObjArrayKlass*)task.obj()->klass(); |
jcoomes@1746 | 78 | k->oop_follow_contents(task.obj(), task.index()); |
jcoomes@1746 | 79 | } |
jcoomes@2191 | 80 | } while (!_marking_stack.is_empty() || !_objarray_stack.is_empty()); |
duke@435 | 81 | } |
duke@435 | 82 | |
duke@435 | 83 | MarkSweep::FollowStackClosure MarkSweep::follow_stack_closure; |
duke@435 | 84 | |
coleenp@548 | 85 | void MarkSweep::FollowStackClosure::do_void() { follow_stack(); } |
duke@435 | 86 | |
jcoomes@2191 | 87 | // We preserve the mark which should be replaced at the end and the location |
jcoomes@2191 | 88 | // that it will go. Note that the object that this markOop belongs to isn't |
jcoomes@2191 | 89 | // currently at that address but it will be after phase4 |
duke@435 | 90 | void MarkSweep::preserve_mark(oop obj, markOop mark) { |
jcoomes@2191 | 91 | // We try to store preserved marks in the to space of the new generation since |
jcoomes@2191 | 92 | // this is storage which should be available. Most of the time this should be |
jcoomes@2191 | 93 | // sufficient space for the marks we need to preserve but if it isn't we fall |
jcoomes@2191 | 94 | // back to using Stacks to keep track of the overflow. |
duke@435 | 95 | if (_preserved_count < _preserved_count_max) { |
duke@435 | 96 | _preserved_marks[_preserved_count++].init(obj, mark); |
duke@435 | 97 | } else { |
jcoomes@2191 | 98 | _preserved_mark_stack.push(mark); |
jcoomes@2191 | 99 | _preserved_oop_stack.push(obj); |
duke@435 | 100 | } |
duke@435 | 101 | } |
duke@435 | 102 | |
stefank@5011 | 103 | MarkSweep::AdjustPointerClosure MarkSweep::adjust_pointer_closure; |
duke@435 | 104 | |
stefank@5011 | 105 | void MarkSweep::AdjustPointerClosure::do_oop(oop* p) { adjust_pointer(p); } |
stefank@5011 | 106 | void MarkSweep::AdjustPointerClosure::do_oop(narrowOop* p) { adjust_pointer(p); } |
coleenp@548 | 107 | |
duke@435 | 108 | void MarkSweep::adjust_marks() { |
jcoomes@2191 | 109 | assert( _preserved_oop_stack.size() == _preserved_mark_stack.size(), |
duke@435 | 110 | "inconsistent preserved oop stacks"); |
duke@435 | 111 | |
duke@435 | 112 | // adjust the oops we saved earlier |
duke@435 | 113 | for (size_t i = 0; i < _preserved_count; i++) { |
duke@435 | 114 | _preserved_marks[i].adjust_pointer(); |
duke@435 | 115 | } |
duke@435 | 116 | |
duke@435 | 117 | // deal with the overflow stack |
zgu@3900 | 118 | StackIterator<oop, mtGC> iter(_preserved_oop_stack); |
jcoomes@2191 | 119 | while (!iter.is_empty()) { |
jcoomes@2191 | 120 | oop* p = iter.next_addr(); |
jcoomes@2191 | 121 | adjust_pointer(p); |
duke@435 | 122 | } |
duke@435 | 123 | } |
duke@435 | 124 | |
duke@435 | 125 | void MarkSweep::restore_marks() { |
jcoomes@2191 | 126 | assert(_preserved_oop_stack.size() == _preserved_mark_stack.size(), |
duke@435 | 127 | "inconsistent preserved oop stacks"); |
duke@435 | 128 | if (PrintGC && Verbose) { |
jcoomes@2191 | 129 | gclog_or_tty->print_cr("Restoring %d marks", |
jcoomes@2191 | 130 | _preserved_count + _preserved_oop_stack.size()); |
duke@435 | 131 | } |
duke@435 | 132 | |
duke@435 | 133 | // restore the marks we saved earlier |
duke@435 | 134 | for (size_t i = 0; i < _preserved_count; i++) { |
duke@435 | 135 | _preserved_marks[i].restore(); |
duke@435 | 136 | } |
duke@435 | 137 | |
duke@435 | 138 | // deal with the overflow |
jcoomes@2191 | 139 | while (!_preserved_oop_stack.is_empty()) { |
jcoomes@2191 | 140 | oop obj = _preserved_oop_stack.pop(); |
jcoomes@2191 | 141 | markOop mark = _preserved_mark_stack.pop(); |
jcoomes@2191 | 142 | obj->set_mark(mark); |
duke@435 | 143 | } |
duke@435 | 144 | } |
duke@435 | 145 | |
coleenp@548 | 146 | MarkSweep::IsAliveClosure MarkSweep::is_alive; |
duke@435 | 147 | |
coleenp@548 | 148 | bool MarkSweep::IsAliveClosure::do_object_b(oop p) { return p->is_gc_marked(); } |
duke@435 | 149 | |
duke@435 | 150 | MarkSweep::KeepAliveClosure MarkSweep::keep_alive; |
duke@435 | 151 | |
coleenp@548 | 152 | void MarkSweep::KeepAliveClosure::do_oop(oop* p) { MarkSweep::KeepAliveClosure::do_oop_work(p); } |
coleenp@548 | 153 | void MarkSweep::KeepAliveClosure::do_oop(narrowOop* p) { MarkSweep::KeepAliveClosure::do_oop_work(p); } |
coleenp@548 | 154 | |
sla@5237 | 155 | void marksweep_init() { |
sla@5237 | 156 | MarkSweep::_gc_timer = new (ResourceObj::C_HEAP, mtGC) STWGCTimer(); |
sla@5237 | 157 | MarkSweep::_gc_tracer = new (ResourceObj::C_HEAP, mtGC) SerialOldTracer(); |
sla@5237 | 158 | } |
duke@435 | 159 | |
duke@435 | 160 | #ifndef PRODUCT |
duke@435 | 161 | |
duke@435 | 162 | void MarkSweep::trace(const char* msg) { |
duke@435 | 163 | if (TraceMarkSweep) |
duke@435 | 164 | gclog_or_tty->print("%s", msg); |
duke@435 | 165 | } |
duke@435 | 166 | |
duke@435 | 167 | #endif |