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

Mon, 06 Aug 2012 12:20:14 -0700

author
johnc
date
Mon, 06 Aug 2012 12:20:14 -0700
changeset 3982
aaf61e68b255
parent 3900
d2a62e0f25eb
child 4037
da91efe96a93
permissions
-rw-r--r--

6818524: G1: use ergonomic resizing of PLABs
Summary: Employ PLABStats instances to record information about survivor and old PLABs, and use the recorded stats to adjust the sizes of survivor and old PLABS.
Reviewed-by: johnc, ysr
Contributed-by: Brandon Mitchell <brandon@twitter.com>

duke@435 1 /*
jmasa@3298 2 * Copyright (c) 1997, 2011, 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);
ysr@1376 79 virtual const bool should_remember_mdo() const { return true; }
ysr@1376 80 virtual void remember_mdo(DataLayout* p) { MarkSweep::revisit_mdo(p); }
duke@435 81 };
duke@435 82
duke@435 83 class FollowStackClosure: public VoidClosure {
duke@435 84 public:
coleenp@548 85 virtual void do_void();
duke@435 86 };
duke@435 87
duke@435 88 class AdjustPointerClosure: public OopsInGenClosure {
coleenp@548 89 private:
duke@435 90 bool _is_root;
duke@435 91 public:
duke@435 92 AdjustPointerClosure(bool is_root) : _is_root(is_root) {}
coleenp@548 93 virtual void do_oop(oop* p);
coleenp@548 94 virtual void do_oop(narrowOop* p);
duke@435 95 };
duke@435 96
duke@435 97 // Used for java/lang/ref handling
duke@435 98 class IsAliveClosure: public BoolObjectClosure {
duke@435 99 public:
coleenp@548 100 virtual void do_object(oop p);
coleenp@548 101 virtual bool do_object_b(oop p);
duke@435 102 };
duke@435 103
duke@435 104 class KeepAliveClosure: public OopClosure {
coleenp@548 105 protected:
coleenp@548 106 template <class T> void do_oop_work(T* p);
duke@435 107 public:
coleenp@548 108 virtual void do_oop(oop* p);
coleenp@548 109 virtual void do_oop(narrowOop* p);
duke@435 110 };
duke@435 111
duke@435 112 //
duke@435 113 // Friend decls
duke@435 114 //
duke@435 115 friend class AdjustPointerClosure;
duke@435 116 friend class KeepAliveClosure;
duke@435 117 friend class VM_MarkSweep;
duke@435 118 friend void marksweep_init();
duke@435 119
duke@435 120 //
duke@435 121 // Vars
duke@435 122 //
duke@435 123 protected:
jcoomes@1746 124 // Traversal stacks used during phase1
zgu@3900 125 static Stack<oop, mtGC> _marking_stack;
zgu@3900 126 static Stack<ObjArrayTask, mtGC> _objarray_stack;
duke@435 127 // Stack for live klasses to revisit at end of marking phase
zgu@3900 128 static Stack<Klass*, mtGC> _revisit_klass_stack;
ysr@1376 129 // Set (stack) of MDO's to revisit at end of marking phase
zgu@3900 130 static Stack<DataLayout*, mtGC> _revisit_mdo_stack;
duke@435 131
duke@435 132 // Space for storing/restoring mark word
zgu@3900 133 static Stack<markOop, mtGC> _preserved_mark_stack;
zgu@3900 134 static Stack<oop, mtGC> _preserved_oop_stack;
duke@435 135 static size_t _preserved_count;
duke@435 136 static size_t _preserved_count_max;
duke@435 137 static PreservedMark* _preserved_marks;
duke@435 138
duke@435 139 // Reference processing (used in ...follow_contents)
duke@435 140 static ReferenceProcessor* _ref_processor;
duke@435 141
duke@435 142 #ifdef VALIDATE_MARK_SWEEP
coleenp@548 143 static GrowableArray<void*>* _root_refs_stack;
duke@435 144 static GrowableArray<oop> * _live_oops;
duke@435 145 static GrowableArray<oop> * _live_oops_moved_to;
duke@435 146 static GrowableArray<size_t>* _live_oops_size;
duke@435 147 static size_t _live_oops_index;
duke@435 148 static size_t _live_oops_index_at_perm;
coleenp@548 149 static GrowableArray<void*>* _other_refs_stack;
coleenp@548 150 static GrowableArray<void*>* _adjusted_pointers;
duke@435 151 static bool _pointer_tracking;
duke@435 152 static bool _root_tracking;
duke@435 153
duke@435 154 // The following arrays are saved since the time of the last GC and
duke@435 155 // assist in tracking down problems where someone has done an errant
duke@435 156 // store into the heap, usually to an oop that wasn't properly
duke@435 157 // handleized across a GC. If we crash or otherwise fail before the
duke@435 158 // next GC, we can query these arrays to find out the object we had
duke@435 159 // intended to do the store to (assuming it is still alive) and the
duke@435 160 // offset within that object. Covered under RecordMarkSweepCompaction.
duke@435 161 static GrowableArray<HeapWord*> * _cur_gc_live_oops;
duke@435 162 static GrowableArray<HeapWord*> * _cur_gc_live_oops_moved_to;
duke@435 163 static GrowableArray<size_t>* _cur_gc_live_oops_size;
duke@435 164 static GrowableArray<HeapWord*> * _last_gc_live_oops;
duke@435 165 static GrowableArray<HeapWord*> * _last_gc_live_oops_moved_to;
duke@435 166 static GrowableArray<size_t>* _last_gc_live_oops_size;
duke@435 167 #endif
duke@435 168
duke@435 169 // Non public closures
coleenp@548 170 static IsAliveClosure is_alive;
duke@435 171 static KeepAliveClosure keep_alive;
duke@435 172
duke@435 173 // Class unloading. Update subklass/sibling/implementor links at end of marking phase.
duke@435 174 static void follow_weak_klass_links();
duke@435 175
ysr@1376 176 // Class unloading. Clear weak refs in MDO's (ProfileData)
ysr@1376 177 // at the end of the marking phase.
ysr@1376 178 static void follow_mdo_weak_refs();
ysr@1376 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@548 185 static FollowRootClosure follow_root_closure;
jrose@1424 186 static CodeBlobToOopClosure follow_code_root_closure; // => follow_root_closure
coleenp@548 187 static MarkAndPushClosure mark_and_push_closure;
coleenp@548 188 static FollowStackClosure follow_stack_closure;
duke@435 189 static AdjustPointerClosure adjust_root_pointer_closure;
duke@435 190 static AdjustPointerClosure adjust_pointer_closure;
duke@435 191
duke@435 192 // Reference Processing
duke@435 193 static ReferenceProcessor* const ref_processor() { return _ref_processor; }
duke@435 194
duke@435 195 // Call backs for marking
duke@435 196 static void mark_object(oop obj);
coleenp@548 197 // Mark pointer and follow contents. Empty marking stack afterwards.
coleenp@548 198 template <class T> static inline void follow_root(T* p);
coleenp@548 199 // Check mark and maybe push on marking stack
coleenp@548 200 template <class T> static inline void mark_and_push(T* p);
jcoomes@1746 201 static inline void push_objarray(oop obj, size_t index);
duke@435 202
coleenp@548 203 static void follow_stack(); // Empty marking stack.
duke@435 204
coleenp@548 205 static void preserve_mark(oop p, markOop mark);
coleenp@548 206 // Save the mark word so it can be restored later
coleenp@548 207 static void adjust_marks(); // Adjust the pointers in the preserved marks table
coleenp@548 208 static void restore_marks(); // Restore the marks that we saved in preserve_mark
duke@435 209
coleenp@548 210 template <class T> static inline void adjust_pointer(T* p, bool isroot);
duke@435 211
coleenp@548 212 static void adjust_root_pointer(oop* p) { adjust_pointer(p, true); }
coleenp@548 213 static void adjust_pointer(oop* p) { adjust_pointer(p, false); }
coleenp@548 214 static void adjust_pointer(narrowOop* p) { adjust_pointer(p, false); }
duke@435 215
duke@435 216 #ifdef VALIDATE_MARK_SWEEP
coleenp@548 217 static void track_adjusted_pointer(void* p, bool isroot);
coleenp@548 218 static void check_adjust_pointer(void* p);
duke@435 219 static void track_interior_pointers(oop obj);
duke@435 220 static void check_interior_pointers();
duke@435 221
duke@435 222 static void reset_live_oop_tracking(bool at_perm);
duke@435 223 static void register_live_oop(oop p, size_t size);
duke@435 224 static void validate_live_oop(oop p, size_t size);
duke@435 225 static void live_oop_moved_to(HeapWord* q, size_t size, HeapWord* compaction_top);
duke@435 226 static void compaction_complete();
duke@435 227
duke@435 228 // Querying operation of RecordMarkSweepCompaction results.
duke@435 229 // Finds and prints the current base oop and offset for a word
duke@435 230 // within an oop that was live during the last GC. Helpful for
duke@435 231 // tracking down heap stomps.
duke@435 232 static void print_new_location_of_heap_address(HeapWord* q);
duke@435 233 #endif
duke@435 234
duke@435 235 // Call backs for class unloading
ysr@1376 236 // Update subklass/sibling/implementor links at end of marking.
ysr@1376 237 static void revisit_weak_klass_link(Klass* k);
ysr@1376 238 // For weak refs clearing in MDO's
ysr@1376 239 static void revisit_mdo(DataLayout* p);
duke@435 240 };
duke@435 241
duke@435 242 class PreservedMark VALUE_OBJ_CLASS_SPEC {
duke@435 243 private:
duke@435 244 oop _obj;
duke@435 245 markOop _mark;
duke@435 246
duke@435 247 public:
duke@435 248 void init(oop obj, markOop mark) {
duke@435 249 _obj = obj;
duke@435 250 _mark = mark;
duke@435 251 }
duke@435 252
duke@435 253 void adjust_pointer() {
duke@435 254 MarkSweep::adjust_pointer(&_obj);
duke@435 255 }
duke@435 256
duke@435 257 void restore() {
duke@435 258 _obj->set_mark(_mark);
duke@435 259 }
duke@435 260 };
stefank@2314 261
stefank@2314 262 #endif // SHARE_VM_GC_IMPLEMENTATION_SHARED_MARKSWEEP_HPP

mercurial