Tue, 08 Aug 2017 15:57:29 +0800
merge
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 4 | * |
aoqi@0 | 5 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 6 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 7 | * published by the Free Software Foundation. |
aoqi@0 | 8 | * |
aoqi@0 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 13 | * accompanied this code). |
aoqi@0 | 14 | * |
aoqi@0 | 15 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 18 | * |
aoqi@0 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 20 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 21 | * questions. |
aoqi@0 | 22 | * |
aoqi@0 | 23 | */ |
aoqi@0 | 24 | |
aoqi@0 | 25 | #ifndef SHARE_VM_GC_IMPLEMENTATION_SHARED_MARKSWEEP_HPP |
aoqi@0 | 26 | #define SHARE_VM_GC_IMPLEMENTATION_SHARED_MARKSWEEP_HPP |
aoqi@0 | 27 | |
aoqi@0 | 28 | #include "gc_interface/collectedHeap.hpp" |
aoqi@0 | 29 | #include "memory/universe.hpp" |
aoqi@0 | 30 | #include "oops/markOop.hpp" |
aoqi@0 | 31 | #include "oops/oop.hpp" |
aoqi@0 | 32 | #include "runtime/timer.hpp" |
aoqi@0 | 33 | #include "utilities/growableArray.hpp" |
aoqi@0 | 34 | #include "utilities/stack.hpp" |
aoqi@0 | 35 | #include "utilities/taskqueue.hpp" |
aoqi@0 | 36 | |
aoqi@0 | 37 | class ReferenceProcessor; |
aoqi@0 | 38 | class DataLayout; |
aoqi@0 | 39 | class SerialOldTracer; |
aoqi@0 | 40 | class STWGCTimer; |
aoqi@0 | 41 | |
aoqi@0 | 42 | // MarkSweep takes care of global mark-compact garbage collection for a |
aoqi@0 | 43 | // GenCollectedHeap using a four-phase pointer forwarding algorithm. All |
aoqi@0 | 44 | // generations are assumed to support marking; those that can also support |
aoqi@0 | 45 | // compaction. |
aoqi@0 | 46 | // |
aoqi@0 | 47 | // Class unloading will only occur when a full gc is invoked. |
aoqi@0 | 48 | |
aoqi@0 | 49 | // declared at end |
aoqi@0 | 50 | class PreservedMark; |
aoqi@0 | 51 | |
aoqi@0 | 52 | class MarkSweep : AllStatic { |
aoqi@0 | 53 | // |
aoqi@0 | 54 | // Inline closure decls |
aoqi@0 | 55 | // |
aoqi@0 | 56 | class FollowRootClosure: public OopsInGenClosure { |
aoqi@0 | 57 | public: |
aoqi@0 | 58 | virtual void do_oop(oop* p); |
aoqi@0 | 59 | virtual void do_oop(narrowOop* p); |
aoqi@0 | 60 | }; |
aoqi@0 | 61 | |
aoqi@0 | 62 | class MarkAndPushClosure: public OopClosure { |
aoqi@0 | 63 | public: |
aoqi@0 | 64 | virtual void do_oop(oop* p); |
aoqi@0 | 65 | virtual void do_oop(narrowOop* p); |
aoqi@0 | 66 | }; |
aoqi@0 | 67 | |
aoqi@0 | 68 | // The one and only place to start following the classes. |
aoqi@0 | 69 | // Should only be applied to the ClassLoaderData klasses list. |
aoqi@0 | 70 | class FollowKlassClosure : public KlassClosure { |
aoqi@0 | 71 | public: |
aoqi@0 | 72 | void do_klass(Klass* klass); |
aoqi@0 | 73 | }; |
aoqi@0 | 74 | class AdjustKlassClosure : public KlassClosure { |
aoqi@0 | 75 | public: |
aoqi@0 | 76 | void do_klass(Klass* klass); |
aoqi@0 | 77 | }; |
aoqi@0 | 78 | |
aoqi@0 | 79 | class FollowStackClosure: public VoidClosure { |
aoqi@0 | 80 | public: |
aoqi@0 | 81 | virtual void do_void(); |
aoqi@0 | 82 | }; |
aoqi@0 | 83 | |
aoqi@0 | 84 | class AdjustPointerClosure: public OopsInGenClosure { |
aoqi@0 | 85 | public: |
aoqi@0 | 86 | virtual void do_oop(oop* p); |
aoqi@0 | 87 | virtual void do_oop(narrowOop* p); |
aoqi@0 | 88 | }; |
aoqi@0 | 89 | |
aoqi@0 | 90 | // Used for java/lang/ref handling |
aoqi@0 | 91 | class IsAliveClosure: public BoolObjectClosure { |
aoqi@0 | 92 | public: |
aoqi@0 | 93 | virtual bool do_object_b(oop p); |
aoqi@0 | 94 | }; |
aoqi@0 | 95 | |
aoqi@0 | 96 | class KeepAliveClosure: public OopClosure { |
aoqi@0 | 97 | protected: |
aoqi@0 | 98 | template <class T> void do_oop_work(T* p); |
aoqi@0 | 99 | public: |
aoqi@0 | 100 | virtual void do_oop(oop* p); |
aoqi@0 | 101 | virtual void do_oop(narrowOop* p); |
aoqi@0 | 102 | }; |
aoqi@0 | 103 | |
aoqi@0 | 104 | // |
aoqi@0 | 105 | // Friend decls |
aoqi@0 | 106 | // |
aoqi@0 | 107 | friend class AdjustPointerClosure; |
aoqi@0 | 108 | friend class KeepAliveClosure; |
aoqi@0 | 109 | friend class VM_MarkSweep; |
aoqi@0 | 110 | friend void marksweep_init(); |
aoqi@0 | 111 | |
aoqi@0 | 112 | // |
aoqi@0 | 113 | // Vars |
aoqi@0 | 114 | // |
aoqi@0 | 115 | protected: |
aoqi@0 | 116 | // Total invocations of a MarkSweep collection |
aoqi@0 | 117 | static uint _total_invocations; |
aoqi@0 | 118 | |
aoqi@0 | 119 | // Traversal stacks used during phase1 |
aoqi@0 | 120 | static Stack<oop, mtGC> _marking_stack; |
aoqi@0 | 121 | static Stack<ObjArrayTask, mtGC> _objarray_stack; |
aoqi@0 | 122 | |
aoqi@0 | 123 | // Space for storing/restoring mark word |
aoqi@0 | 124 | static Stack<markOop, mtGC> _preserved_mark_stack; |
aoqi@0 | 125 | static Stack<oop, mtGC> _preserved_oop_stack; |
aoqi@0 | 126 | static size_t _preserved_count; |
aoqi@0 | 127 | static size_t _preserved_count_max; |
aoqi@0 | 128 | static PreservedMark* _preserved_marks; |
aoqi@0 | 129 | |
aoqi@0 | 130 | // Reference processing (used in ...follow_contents) |
aoqi@0 | 131 | static ReferenceProcessor* _ref_processor; |
aoqi@0 | 132 | |
aoqi@0 | 133 | static STWGCTimer* _gc_timer; |
aoqi@0 | 134 | static SerialOldTracer* _gc_tracer; |
aoqi@0 | 135 | |
aoqi@0 | 136 | // Non public closures |
aoqi@0 | 137 | static KeepAliveClosure keep_alive; |
aoqi@0 | 138 | |
aoqi@0 | 139 | // Debugging |
aoqi@0 | 140 | static void trace(const char* msg) PRODUCT_RETURN; |
aoqi@0 | 141 | |
aoqi@0 | 142 | public: |
aoqi@0 | 143 | // Public closures |
aoqi@0 | 144 | static IsAliveClosure is_alive; |
aoqi@0 | 145 | static FollowRootClosure follow_root_closure; |
aoqi@0 | 146 | static CodeBlobToOopClosure follow_code_root_closure; // => follow_root_closure |
aoqi@0 | 147 | static MarkAndPushClosure mark_and_push_closure; |
aoqi@0 | 148 | static FollowKlassClosure follow_klass_closure; |
aoqi@0 | 149 | static FollowStackClosure follow_stack_closure; |
aoqi@0 | 150 | static AdjustPointerClosure adjust_pointer_closure; |
aoqi@0 | 151 | static AdjustKlassClosure adjust_klass_closure; |
aoqi@0 | 152 | |
aoqi@0 | 153 | // Accessors |
aoqi@0 | 154 | static uint total_invocations() { return _total_invocations; } |
aoqi@0 | 155 | |
aoqi@0 | 156 | // Reference Processing |
aoqi@0 | 157 | static ReferenceProcessor* const ref_processor() { return _ref_processor; } |
aoqi@0 | 158 | |
aoqi@0 | 159 | static STWGCTimer* gc_timer() { return _gc_timer; } |
aoqi@0 | 160 | static SerialOldTracer* gc_tracer() { return _gc_tracer; } |
aoqi@0 | 161 | |
aoqi@0 | 162 | // Call backs for marking |
aoqi@0 | 163 | static void mark_object(oop obj); |
aoqi@0 | 164 | // Mark pointer and follow contents. Empty marking stack afterwards. |
aoqi@0 | 165 | template <class T> static inline void follow_root(T* p); |
aoqi@0 | 166 | |
aoqi@0 | 167 | // Check mark and maybe push on marking stack |
aoqi@0 | 168 | template <class T> static void mark_and_push(T* p); |
aoqi@0 | 169 | |
aoqi@0 | 170 | static inline void push_objarray(oop obj, size_t index); |
aoqi@0 | 171 | |
aoqi@0 | 172 | static void follow_stack(); // Empty marking stack. |
aoqi@0 | 173 | |
aoqi@0 | 174 | static void follow_klass(Klass* klass); |
aoqi@0 | 175 | |
aoqi@0 | 176 | static void follow_class_loader(ClassLoaderData* cld); |
aoqi@0 | 177 | |
aoqi@0 | 178 | static void preserve_mark(oop p, markOop mark); |
aoqi@0 | 179 | // Save the mark word so it can be restored later |
aoqi@0 | 180 | static void adjust_marks(); // Adjust the pointers in the preserved marks table |
aoqi@0 | 181 | static void restore_marks(); // Restore the marks that we saved in preserve_mark |
aoqi@0 | 182 | |
aoqi@0 | 183 | template <class T> static inline void adjust_pointer(T* p); |
aoqi@0 | 184 | }; |
aoqi@0 | 185 | |
aoqi@0 | 186 | class PreservedMark VALUE_OBJ_CLASS_SPEC { |
aoqi@0 | 187 | private: |
aoqi@0 | 188 | oop _obj; |
aoqi@0 | 189 | markOop _mark; |
aoqi@0 | 190 | |
aoqi@0 | 191 | public: |
aoqi@0 | 192 | void init(oop obj, markOop mark) { |
aoqi@0 | 193 | _obj = obj; |
aoqi@0 | 194 | _mark = mark; |
aoqi@0 | 195 | } |
aoqi@0 | 196 | |
aoqi@0 | 197 | void adjust_pointer() { |
aoqi@0 | 198 | MarkSweep::adjust_pointer(&_obj); |
aoqi@0 | 199 | } |
aoqi@0 | 200 | |
aoqi@0 | 201 | void restore() { |
aoqi@0 | 202 | _obj->set_mark(_mark); |
aoqi@0 | 203 | } |
aoqi@0 | 204 | }; |
aoqi@0 | 205 | |
aoqi@0 | 206 | #endif // SHARE_VM_GC_IMPLEMENTATION_SHARED_MARKSWEEP_HPP |