Thu, 04 Oct 2012 10:40:23 -0700
7198873: NPG: VM Does not unload classes with UseConcMarkSweepGC
Reviewed-by: johnc, mgerdin, jwilhelm
duke@435 | 1 | /* |
coleenp@4037 | 2 | * Copyright (c) 1997, 2012, 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 | #ifndef SHARE_VM_GC_IMPLEMENTATION_SHARED_MARKSWEEP_HPP |
stefank@2314 | 26 | #define SHARE_VM_GC_IMPLEMENTATION_SHARED_MARKSWEEP_HPP |
stefank@2314 | 27 | |
stefank@2314 | 28 | #include "gc_interface/collectedHeap.hpp" |
stefank@2314 | 29 | #include "memory/universe.hpp" |
stefank@2314 | 30 | #include "oops/markOop.hpp" |
stefank@2314 | 31 | #include "oops/oop.hpp" |
stefank@2314 | 32 | #include "runtime/timer.hpp" |
stefank@2314 | 33 | #include "utilities/growableArray.hpp" |
stefank@2314 | 34 | #include "utilities/stack.hpp" |
stefank@2314 | 35 | #include "utilities/taskqueue.hpp" |
stefank@2314 | 36 | |
duke@435 | 37 | class ReferenceProcessor; |
ysr@1376 | 38 | class DataLayout; |
duke@435 | 39 | |
duke@435 | 40 | // MarkSweep takes care of global mark-compact garbage collection for a |
duke@435 | 41 | // GenCollectedHeap using a four-phase pointer forwarding algorithm. All |
duke@435 | 42 | // generations are assumed to support marking; those that can also support |
duke@435 | 43 | // compaction. |
duke@435 | 44 | // |
duke@435 | 45 | // Class unloading will only occur when a full gc is invoked. |
duke@435 | 46 | |
duke@435 | 47 | // If VALIDATE_MARK_SWEEP is defined, the -XX:+ValidateMarkSweep flag will |
duke@435 | 48 | // be operational, and will provide slow but comprehensive self-checks within |
duke@435 | 49 | // the GC. This is not enabled by default in product or release builds, |
duke@435 | 50 | // since the extra call to track_adjusted_pointer() in _adjust_pointer() |
duke@435 | 51 | // would be too much overhead, and would disturb performance measurement. |
duke@435 | 52 | // However, debug builds are sometimes way too slow to run GC tests! |
duke@435 | 53 | #ifdef ASSERT |
duke@435 | 54 | #define VALIDATE_MARK_SWEEP 1 |
duke@435 | 55 | #endif |
duke@435 | 56 | #ifdef VALIDATE_MARK_SWEEP |
duke@435 | 57 | #define VALIDATE_MARK_SWEEP_ONLY(code) code |
duke@435 | 58 | #else |
duke@435 | 59 | #define VALIDATE_MARK_SWEEP_ONLY(code) |
duke@435 | 60 | #endif |
duke@435 | 61 | |
duke@435 | 62 | // declared at end |
duke@435 | 63 | class PreservedMark; |
duke@435 | 64 | |
duke@435 | 65 | class MarkSweep : AllStatic { |
duke@435 | 66 | // |
coleenp@548 | 67 | // Inline closure decls |
duke@435 | 68 | // |
coleenp@548 | 69 | class FollowRootClosure: public OopsInGenClosure { |
duke@435 | 70 | public: |
coleenp@548 | 71 | virtual void do_oop(oop* p); |
coleenp@548 | 72 | virtual void do_oop(narrowOop* p); |
duke@435 | 73 | }; |
duke@435 | 74 | |
duke@435 | 75 | class MarkAndPushClosure: public OopClosure { |
duke@435 | 76 | public: |
coleenp@548 | 77 | virtual void do_oop(oop* p); |
coleenp@548 | 78 | virtual void do_oop(narrowOop* p); |
coleenp@4037 | 79 | }; |
coleenp@4037 | 80 | |
coleenp@4037 | 81 | // The one and only place to start following the classes. |
coleenp@4037 | 82 | // Should only be applied to the ClassLoaderData klasses list. |
coleenp@4037 | 83 | class FollowKlassClosure : public KlassClosure { |
coleenp@4037 | 84 | public: |
coleenp@4037 | 85 | void do_klass(Klass* klass); |
coleenp@4037 | 86 | }; |
coleenp@4037 | 87 | class AdjustKlassClosure : public KlassClosure { |
coleenp@4037 | 88 | public: |
coleenp@4037 | 89 | void do_klass(Klass* klass); |
duke@435 | 90 | }; |
duke@435 | 91 | |
duke@435 | 92 | class FollowStackClosure: public VoidClosure { |
duke@435 | 93 | public: |
coleenp@548 | 94 | virtual void do_void(); |
duke@435 | 95 | }; |
duke@435 | 96 | |
duke@435 | 97 | class AdjustPointerClosure: public OopsInGenClosure { |
coleenp@548 | 98 | private: |
duke@435 | 99 | bool _is_root; |
duke@435 | 100 | public: |
duke@435 | 101 | AdjustPointerClosure(bool is_root) : _is_root(is_root) {} |
coleenp@548 | 102 | virtual void do_oop(oop* p); |
coleenp@548 | 103 | virtual void do_oop(narrowOop* p); |
duke@435 | 104 | }; |
duke@435 | 105 | |
duke@435 | 106 | // Used for java/lang/ref handling |
duke@435 | 107 | class IsAliveClosure: public BoolObjectClosure { |
duke@435 | 108 | public: |
coleenp@548 | 109 | virtual void do_object(oop p); |
coleenp@548 | 110 | virtual bool do_object_b(oop p); |
duke@435 | 111 | }; |
duke@435 | 112 | |
duke@435 | 113 | class KeepAliveClosure: public OopClosure { |
coleenp@548 | 114 | protected: |
coleenp@548 | 115 | template <class T> void do_oop_work(T* p); |
duke@435 | 116 | public: |
coleenp@548 | 117 | virtual void do_oop(oop* p); |
coleenp@548 | 118 | virtual void do_oop(narrowOop* p); |
duke@435 | 119 | }; |
duke@435 | 120 | |
duke@435 | 121 | // |
duke@435 | 122 | // Friend decls |
duke@435 | 123 | // |
duke@435 | 124 | friend class AdjustPointerClosure; |
duke@435 | 125 | friend class KeepAliveClosure; |
duke@435 | 126 | friend class VM_MarkSweep; |
duke@435 | 127 | friend void marksweep_init(); |
duke@435 | 128 | |
duke@435 | 129 | // |
duke@435 | 130 | // Vars |
duke@435 | 131 | // |
duke@435 | 132 | protected: |
coleenp@4037 | 133 | // Total invocations of a MarkSweep collection |
coleenp@4037 | 134 | static unsigned int _total_invocations; |
coleenp@4037 | 135 | |
jcoomes@1746 | 136 | // Traversal stacks used during phase1 |
zgu@3900 | 137 | static Stack<oop, mtGC> _marking_stack; |
zgu@3900 | 138 | static Stack<ObjArrayTask, mtGC> _objarray_stack; |
duke@435 | 139 | |
duke@435 | 140 | // Space for storing/restoring mark word |
zgu@3900 | 141 | static Stack<markOop, mtGC> _preserved_mark_stack; |
zgu@3900 | 142 | static Stack<oop, mtGC> _preserved_oop_stack; |
duke@435 | 143 | static size_t _preserved_count; |
duke@435 | 144 | static size_t _preserved_count_max; |
duke@435 | 145 | static PreservedMark* _preserved_marks; |
duke@435 | 146 | |
duke@435 | 147 | // Reference processing (used in ...follow_contents) |
duke@435 | 148 | static ReferenceProcessor* _ref_processor; |
duke@435 | 149 | |
duke@435 | 150 | #ifdef VALIDATE_MARK_SWEEP |
coleenp@548 | 151 | static GrowableArray<void*>* _root_refs_stack; |
duke@435 | 152 | static GrowableArray<oop> * _live_oops; |
duke@435 | 153 | static GrowableArray<oop> * _live_oops_moved_to; |
duke@435 | 154 | static GrowableArray<size_t>* _live_oops_size; |
duke@435 | 155 | static size_t _live_oops_index; |
duke@435 | 156 | static size_t _live_oops_index_at_perm; |
coleenp@548 | 157 | static GrowableArray<void*>* _other_refs_stack; |
coleenp@548 | 158 | static GrowableArray<void*>* _adjusted_pointers; |
duke@435 | 159 | static bool _pointer_tracking; |
duke@435 | 160 | static bool _root_tracking; |
duke@435 | 161 | |
duke@435 | 162 | // The following arrays are saved since the time of the last GC and |
duke@435 | 163 | // assist in tracking down problems where someone has done an errant |
duke@435 | 164 | // store into the heap, usually to an oop that wasn't properly |
duke@435 | 165 | // handleized across a GC. If we crash or otherwise fail before the |
duke@435 | 166 | // next GC, we can query these arrays to find out the object we had |
duke@435 | 167 | // intended to do the store to (assuming it is still alive) and the |
duke@435 | 168 | // offset within that object. Covered under RecordMarkSweepCompaction. |
duke@435 | 169 | static GrowableArray<HeapWord*> * _cur_gc_live_oops; |
duke@435 | 170 | static GrowableArray<HeapWord*> * _cur_gc_live_oops_moved_to; |
duke@435 | 171 | static GrowableArray<size_t>* _cur_gc_live_oops_size; |
duke@435 | 172 | static GrowableArray<HeapWord*> * _last_gc_live_oops; |
duke@435 | 173 | static GrowableArray<HeapWord*> * _last_gc_live_oops_moved_to; |
duke@435 | 174 | static GrowableArray<size_t>* _last_gc_live_oops_size; |
duke@435 | 175 | #endif |
duke@435 | 176 | |
duke@435 | 177 | // Non public closures |
duke@435 | 178 | static KeepAliveClosure keep_alive; |
duke@435 | 179 | |
duke@435 | 180 | // Debugging |
duke@435 | 181 | static void trace(const char* msg) PRODUCT_RETURN; |
duke@435 | 182 | |
duke@435 | 183 | public: |
duke@435 | 184 | // Public closures |
coleenp@4037 | 185 | static IsAliveClosure is_alive; |
coleenp@548 | 186 | static FollowRootClosure follow_root_closure; |
jrose@1424 | 187 | static CodeBlobToOopClosure follow_code_root_closure; // => follow_root_closure |
coleenp@548 | 188 | static MarkAndPushClosure mark_and_push_closure; |
coleenp@4037 | 189 | static FollowKlassClosure follow_klass_closure; |
coleenp@548 | 190 | static FollowStackClosure follow_stack_closure; |
duke@435 | 191 | static AdjustPointerClosure adjust_root_pointer_closure; |
duke@435 | 192 | static AdjustPointerClosure adjust_pointer_closure; |
coleenp@4037 | 193 | static AdjustKlassClosure adjust_klass_closure; |
coleenp@4037 | 194 | |
coleenp@4037 | 195 | // Accessors |
coleenp@4037 | 196 | static unsigned int total_invocations() { return _total_invocations; } |
duke@435 | 197 | |
duke@435 | 198 | // Reference Processing |
duke@435 | 199 | static ReferenceProcessor* const ref_processor() { return _ref_processor; } |
duke@435 | 200 | |
duke@435 | 201 | // Call backs for marking |
duke@435 | 202 | static void mark_object(oop obj); |
coleenp@548 | 203 | // Mark pointer and follow contents. Empty marking stack afterwards. |
coleenp@548 | 204 | template <class T> static inline void follow_root(T* p); |
coleenp@4037 | 205 | |
coleenp@548 | 206 | // Check mark and maybe push on marking stack |
coleenp@4037 | 207 | template <class T> static void mark_and_push(T* p); |
coleenp@4037 | 208 | |
jcoomes@1746 | 209 | static inline void push_objarray(oop obj, size_t index); |
duke@435 | 210 | |
coleenp@548 | 211 | static void follow_stack(); // Empty marking stack. |
duke@435 | 212 | |
coleenp@4037 | 213 | static void follow_klass(Klass* klass); |
coleenp@4037 | 214 | static void adjust_klass(Klass* klass); |
coleenp@4037 | 215 | |
coleenp@4037 | 216 | static void follow_class_loader(ClassLoaderData* cld); |
coleenp@4037 | 217 | static void adjust_class_loader(ClassLoaderData* cld); |
coleenp@4037 | 218 | |
coleenp@548 | 219 | static void preserve_mark(oop p, markOop mark); |
coleenp@548 | 220 | // Save the mark word so it can be restored later |
coleenp@548 | 221 | static void adjust_marks(); // Adjust the pointers in the preserved marks table |
coleenp@548 | 222 | static void restore_marks(); // Restore the marks that we saved in preserve_mark |
duke@435 | 223 | |
coleenp@548 | 224 | template <class T> static inline void adjust_pointer(T* p, bool isroot); |
duke@435 | 225 | |
coleenp@548 | 226 | static void adjust_root_pointer(oop* p) { adjust_pointer(p, true); } |
coleenp@548 | 227 | static void adjust_pointer(oop* p) { adjust_pointer(p, false); } |
coleenp@548 | 228 | static void adjust_pointer(narrowOop* p) { adjust_pointer(p, false); } |
duke@435 | 229 | |
duke@435 | 230 | #ifdef VALIDATE_MARK_SWEEP |
coleenp@548 | 231 | static void track_adjusted_pointer(void* p, bool isroot); |
coleenp@548 | 232 | static void check_adjust_pointer(void* p); |
duke@435 | 233 | static void track_interior_pointers(oop obj); |
duke@435 | 234 | static void check_interior_pointers(); |
duke@435 | 235 | |
coleenp@4037 | 236 | static void reset_live_oop_tracking(); |
duke@435 | 237 | static void register_live_oop(oop p, size_t size); |
duke@435 | 238 | static void validate_live_oop(oop p, size_t size); |
duke@435 | 239 | static void live_oop_moved_to(HeapWord* q, size_t size, HeapWord* compaction_top); |
duke@435 | 240 | static void compaction_complete(); |
duke@435 | 241 | |
duke@435 | 242 | // Querying operation of RecordMarkSweepCompaction results. |
duke@435 | 243 | // Finds and prints the current base oop and offset for a word |
duke@435 | 244 | // within an oop that was live during the last GC. Helpful for |
duke@435 | 245 | // tracking down heap stomps. |
duke@435 | 246 | static void print_new_location_of_heap_address(HeapWord* q); |
duke@435 | 247 | #endif |
duke@435 | 248 | }; |
duke@435 | 249 | |
duke@435 | 250 | class PreservedMark VALUE_OBJ_CLASS_SPEC { |
duke@435 | 251 | private: |
duke@435 | 252 | oop _obj; |
duke@435 | 253 | markOop _mark; |
duke@435 | 254 | |
duke@435 | 255 | public: |
duke@435 | 256 | void init(oop obj, markOop mark) { |
duke@435 | 257 | _obj = obj; |
duke@435 | 258 | _mark = mark; |
duke@435 | 259 | } |
duke@435 | 260 | |
duke@435 | 261 | void adjust_pointer() { |
duke@435 | 262 | MarkSweep::adjust_pointer(&_obj); |
duke@435 | 263 | } |
duke@435 | 264 | |
duke@435 | 265 | void restore() { |
duke@435 | 266 | _obj->set_mark(_mark); |
duke@435 | 267 | } |
duke@435 | 268 | }; |
stefank@2314 | 269 | |
stefank@2314 | 270 | #endif // SHARE_VM_GC_IMPLEMENTATION_SHARED_MARKSWEEP_HPP |