src/share/vm/gc_implementation/shared/markSweep.hpp

Wed, 23 Sep 2009 23:56:15 -0700

author
jrose
date
Wed, 23 Sep 2009 23:56:15 -0700
changeset 1428
54b3b351d6f9
parent 1424
148e5441d916
parent 1376
8b46c4d82093
child 1429
753cf9794df9
permissions
-rw-r--r--

Merge

duke@435 1 /*
xdono@631 2 * Copyright 1997-2008 Sun Microsystems, Inc. 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 *
duke@435 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@435 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@435 21 * have any questions.
duke@435 22 *
duke@435 23 */
duke@435 24
duke@435 25 class ReferenceProcessor;
ysr@1376 26 class DataLayout;
duke@435 27
duke@435 28 // MarkSweep takes care of global mark-compact garbage collection for a
duke@435 29 // GenCollectedHeap using a four-phase pointer forwarding algorithm. All
duke@435 30 // generations are assumed to support marking; those that can also support
duke@435 31 // compaction.
duke@435 32 //
duke@435 33 // Class unloading will only occur when a full gc is invoked.
duke@435 34
duke@435 35 // If VALIDATE_MARK_SWEEP is defined, the -XX:+ValidateMarkSweep flag will
duke@435 36 // be operational, and will provide slow but comprehensive self-checks within
duke@435 37 // the GC. This is not enabled by default in product or release builds,
duke@435 38 // since the extra call to track_adjusted_pointer() in _adjust_pointer()
duke@435 39 // would be too much overhead, and would disturb performance measurement.
duke@435 40 // However, debug builds are sometimes way too slow to run GC tests!
duke@435 41 #ifdef ASSERT
duke@435 42 #define VALIDATE_MARK_SWEEP 1
duke@435 43 #endif
duke@435 44 #ifdef VALIDATE_MARK_SWEEP
duke@435 45 #define VALIDATE_MARK_SWEEP_ONLY(code) code
duke@435 46 #else
duke@435 47 #define VALIDATE_MARK_SWEEP_ONLY(code)
duke@435 48 #endif
duke@435 49
duke@435 50 // declared at end
duke@435 51 class PreservedMark;
duke@435 52
duke@435 53 class MarkSweep : AllStatic {
duke@435 54 //
coleenp@548 55 // Inline closure decls
duke@435 56 //
coleenp@548 57 class FollowRootClosure: public OopsInGenClosure {
duke@435 58 public:
coleenp@548 59 virtual void do_oop(oop* p);
coleenp@548 60 virtual void do_oop(narrowOop* p);
duke@435 61 };
duke@435 62
duke@435 63 class MarkAndPushClosure: public OopClosure {
duke@435 64 public:
coleenp@548 65 virtual void do_oop(oop* p);
coleenp@548 66 virtual void do_oop(narrowOop* p);
duke@435 67 virtual const bool do_nmethods() const { return true; }
ysr@1376 68 virtual const bool should_remember_mdo() const { return true; }
ysr@1376 69 virtual void remember_mdo(DataLayout* p) { MarkSweep::revisit_mdo(p); }
duke@435 70 };
duke@435 71
duke@435 72 class FollowStackClosure: public VoidClosure {
duke@435 73 public:
coleenp@548 74 virtual void do_void();
duke@435 75 };
duke@435 76
duke@435 77 class AdjustPointerClosure: public OopsInGenClosure {
coleenp@548 78 private:
duke@435 79 bool _is_root;
duke@435 80 public:
duke@435 81 AdjustPointerClosure(bool is_root) : _is_root(is_root) {}
coleenp@548 82 virtual void do_oop(oop* p);
coleenp@548 83 virtual void do_oop(narrowOop* p);
duke@435 84 };
duke@435 85
duke@435 86 // Used for java/lang/ref handling
duke@435 87 class IsAliveClosure: public BoolObjectClosure {
duke@435 88 public:
coleenp@548 89 virtual void do_object(oop p);
coleenp@548 90 virtual bool do_object_b(oop p);
duke@435 91 };
duke@435 92
duke@435 93 class KeepAliveClosure: public OopClosure {
coleenp@548 94 protected:
coleenp@548 95 template <class T> void do_oop_work(T* p);
duke@435 96 public:
coleenp@548 97 virtual void do_oop(oop* p);
coleenp@548 98 virtual void do_oop(narrowOop* p);
duke@435 99 };
duke@435 100
duke@435 101 //
duke@435 102 // Friend decls
duke@435 103 //
duke@435 104 friend class AdjustPointerClosure;
duke@435 105 friend class KeepAliveClosure;
duke@435 106 friend class VM_MarkSweep;
duke@435 107 friend void marksweep_init();
ysr@1376 108 friend class DataLayout;
duke@435 109
duke@435 110 //
duke@435 111 // Vars
duke@435 112 //
duke@435 113 protected:
duke@435 114 // Traversal stack used during phase1
duke@435 115 static GrowableArray<oop>* _marking_stack;
duke@435 116 // Stack for live klasses to revisit at end of marking phase
duke@435 117 static GrowableArray<Klass*>* _revisit_klass_stack;
ysr@1376 118 // Set (stack) of MDO's to revisit at end of marking phase
ysr@1376 119 static GrowableArray<DataLayout*>* _revisit_mdo_stack;
duke@435 120
duke@435 121 // Space for storing/restoring mark word
duke@435 122 static GrowableArray<markOop>* _preserved_mark_stack;
duke@435 123 static GrowableArray<oop>* _preserved_oop_stack;
duke@435 124 static size_t _preserved_count;
duke@435 125 static size_t _preserved_count_max;
duke@435 126 static PreservedMark* _preserved_marks;
duke@435 127
duke@435 128 // Reference processing (used in ...follow_contents)
duke@435 129 static ReferenceProcessor* _ref_processor;
duke@435 130
duke@435 131 #ifdef VALIDATE_MARK_SWEEP
coleenp@548 132 static GrowableArray<void*>* _root_refs_stack;
duke@435 133 static GrowableArray<oop> * _live_oops;
duke@435 134 static GrowableArray<oop> * _live_oops_moved_to;
duke@435 135 static GrowableArray<size_t>* _live_oops_size;
duke@435 136 static size_t _live_oops_index;
duke@435 137 static size_t _live_oops_index_at_perm;
coleenp@548 138 static GrowableArray<void*>* _other_refs_stack;
coleenp@548 139 static GrowableArray<void*>* _adjusted_pointers;
duke@435 140 static bool _pointer_tracking;
duke@435 141 static bool _root_tracking;
duke@435 142
duke@435 143 // The following arrays are saved since the time of the last GC and
duke@435 144 // assist in tracking down problems where someone has done an errant
duke@435 145 // store into the heap, usually to an oop that wasn't properly
duke@435 146 // handleized across a GC. If we crash or otherwise fail before the
duke@435 147 // next GC, we can query these arrays to find out the object we had
duke@435 148 // intended to do the store to (assuming it is still alive) and the
duke@435 149 // offset within that object. Covered under RecordMarkSweepCompaction.
duke@435 150 static GrowableArray<HeapWord*> * _cur_gc_live_oops;
duke@435 151 static GrowableArray<HeapWord*> * _cur_gc_live_oops_moved_to;
duke@435 152 static GrowableArray<size_t>* _cur_gc_live_oops_size;
duke@435 153 static GrowableArray<HeapWord*> * _last_gc_live_oops;
duke@435 154 static GrowableArray<HeapWord*> * _last_gc_live_oops_moved_to;
duke@435 155 static GrowableArray<size_t>* _last_gc_live_oops_size;
duke@435 156 #endif
duke@435 157
duke@435 158 // Non public closures
coleenp@548 159 static IsAliveClosure is_alive;
duke@435 160 static KeepAliveClosure keep_alive;
duke@435 161
duke@435 162 // Class unloading. Update subklass/sibling/implementor links at end of marking phase.
duke@435 163 static void follow_weak_klass_links();
duke@435 164
ysr@1376 165 // Class unloading. Clear weak refs in MDO's (ProfileData)
ysr@1376 166 // at the end of the marking phase.
ysr@1376 167 static void follow_mdo_weak_refs();
ysr@1376 168
duke@435 169 // Debugging
duke@435 170 static void trace(const char* msg) PRODUCT_RETURN;
duke@435 171
duke@435 172 public:
duke@435 173 // Public closures
coleenp@548 174 static FollowRootClosure follow_root_closure;
jrose@1424 175 static CodeBlobToOopClosure follow_code_root_closure; // => follow_root_closure
coleenp@548 176 static MarkAndPushClosure mark_and_push_closure;
coleenp@548 177 static FollowStackClosure follow_stack_closure;
duke@435 178 static AdjustPointerClosure adjust_root_pointer_closure;
duke@435 179 static AdjustPointerClosure adjust_pointer_closure;
duke@435 180
duke@435 181 // Reference Processing
duke@435 182 static ReferenceProcessor* const ref_processor() { return _ref_processor; }
duke@435 183
duke@435 184 // Call backs for marking
duke@435 185 static void mark_object(oop obj);
coleenp@548 186 // Mark pointer and follow contents. Empty marking stack afterwards.
coleenp@548 187 template <class T> static inline void follow_root(T* p);
coleenp@548 188 // Mark pointer and follow contents.
coleenp@548 189 template <class T> static inline void mark_and_follow(T* p);
coleenp@548 190 // Check mark and maybe push on marking stack
coleenp@548 191 template <class T> static inline void mark_and_push(T* p);
duke@435 192
coleenp@548 193 static void follow_stack(); // Empty marking stack.
duke@435 194
coleenp@548 195 static void preserve_mark(oop p, markOop mark);
coleenp@548 196 // Save the mark word so it can be restored later
coleenp@548 197 static void adjust_marks(); // Adjust the pointers in the preserved marks table
coleenp@548 198 static void restore_marks(); // Restore the marks that we saved in preserve_mark
duke@435 199
coleenp@548 200 template <class T> static inline void adjust_pointer(T* p, bool isroot);
duke@435 201
coleenp@548 202 static void adjust_root_pointer(oop* p) { adjust_pointer(p, true); }
coleenp@548 203 static void adjust_pointer(oop* p) { adjust_pointer(p, false); }
coleenp@548 204 static void adjust_pointer(narrowOop* p) { adjust_pointer(p, false); }
duke@435 205
duke@435 206 #ifdef VALIDATE_MARK_SWEEP
coleenp@548 207 static void track_adjusted_pointer(void* p, bool isroot);
coleenp@548 208 static void check_adjust_pointer(void* p);
duke@435 209 static void track_interior_pointers(oop obj);
duke@435 210 static void check_interior_pointers();
duke@435 211
duke@435 212 static void reset_live_oop_tracking(bool at_perm);
duke@435 213 static void register_live_oop(oop p, size_t size);
duke@435 214 static void validate_live_oop(oop p, size_t size);
duke@435 215 static void live_oop_moved_to(HeapWord* q, size_t size, HeapWord* compaction_top);
duke@435 216 static void compaction_complete();
duke@435 217
duke@435 218 // Querying operation of RecordMarkSweepCompaction results.
duke@435 219 // Finds and prints the current base oop and offset for a word
duke@435 220 // within an oop that was live during the last GC. Helpful for
duke@435 221 // tracking down heap stomps.
duke@435 222 static void print_new_location_of_heap_address(HeapWord* q);
duke@435 223 #endif
duke@435 224
duke@435 225 // Call backs for class unloading
ysr@1376 226 // Update subklass/sibling/implementor links at end of marking.
ysr@1376 227 static void revisit_weak_klass_link(Klass* k);
ysr@1376 228 // For weak refs clearing in MDO's
ysr@1376 229 static void revisit_mdo(DataLayout* p);
duke@435 230 };
duke@435 231
duke@435 232 class PreservedMark VALUE_OBJ_CLASS_SPEC {
duke@435 233 private:
duke@435 234 oop _obj;
duke@435 235 markOop _mark;
duke@435 236
duke@435 237 public:
duke@435 238 void init(oop obj, markOop mark) {
duke@435 239 _obj = obj;
duke@435 240 _mark = mark;
duke@435 241 }
duke@435 242
duke@435 243 void adjust_pointer() {
duke@435 244 MarkSweep::adjust_pointer(&_obj);
duke@435 245 }
duke@435 246
duke@435 247 void restore() {
duke@435 248 _obj->set_mark(_mark);
duke@435 249 }
duke@435 250 };

mercurial