Tue, 18 Mar 2014 19:07:22 +0100
8029075: String deduplication in G1
Summary: Implementation of JEP 192, http://openjdk.java.net/jeps/192
Reviewed-by: brutisso, tschatzl, coleenp
duke@435 | 1 | /* |
sla@5237 | 2 | * Copyright (c) 1997, 2013, 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; |
sla@5237 | 39 | class SerialOldTracer; |
sla@5237 | 40 | class STWGCTimer; |
duke@435 | 41 | |
duke@435 | 42 | // MarkSweep takes care of global mark-compact garbage collection for a |
duke@435 | 43 | // GenCollectedHeap using a four-phase pointer forwarding algorithm. All |
duke@435 | 44 | // generations are assumed to support marking; those that can also support |
duke@435 | 45 | // compaction. |
duke@435 | 46 | // |
duke@435 | 47 | // Class unloading will only occur when a full gc is invoked. |
duke@435 | 48 | |
duke@435 | 49 | // declared at end |
duke@435 | 50 | class PreservedMark; |
duke@435 | 51 | |
duke@435 | 52 | class MarkSweep : AllStatic { |
duke@435 | 53 | // |
coleenp@548 | 54 | // Inline closure decls |
duke@435 | 55 | // |
coleenp@548 | 56 | class FollowRootClosure: public OopsInGenClosure { |
duke@435 | 57 | public: |
coleenp@548 | 58 | virtual void do_oop(oop* p); |
coleenp@548 | 59 | virtual void do_oop(narrowOop* p); |
duke@435 | 60 | }; |
duke@435 | 61 | |
duke@435 | 62 | class MarkAndPushClosure: public OopClosure { |
duke@435 | 63 | public: |
coleenp@548 | 64 | virtual void do_oop(oop* p); |
coleenp@548 | 65 | virtual void do_oop(narrowOop* p); |
coleenp@4037 | 66 | }; |
coleenp@4037 | 67 | |
coleenp@4037 | 68 | // The one and only place to start following the classes. |
coleenp@4037 | 69 | // Should only be applied to the ClassLoaderData klasses list. |
coleenp@4037 | 70 | class FollowKlassClosure : public KlassClosure { |
coleenp@4037 | 71 | public: |
coleenp@4037 | 72 | void do_klass(Klass* klass); |
coleenp@4037 | 73 | }; |
coleenp@4037 | 74 | class AdjustKlassClosure : public KlassClosure { |
coleenp@4037 | 75 | public: |
coleenp@4037 | 76 | void do_klass(Klass* klass); |
duke@435 | 77 | }; |
duke@435 | 78 | |
duke@435 | 79 | class FollowStackClosure: public VoidClosure { |
duke@435 | 80 | public: |
coleenp@548 | 81 | virtual void do_void(); |
duke@435 | 82 | }; |
duke@435 | 83 | |
duke@435 | 84 | class AdjustPointerClosure: public OopsInGenClosure { |
duke@435 | 85 | public: |
coleenp@548 | 86 | virtual void do_oop(oop* p); |
coleenp@548 | 87 | virtual void do_oop(narrowOop* p); |
duke@435 | 88 | }; |
duke@435 | 89 | |
duke@435 | 90 | // Used for java/lang/ref handling |
duke@435 | 91 | class IsAliveClosure: public BoolObjectClosure { |
duke@435 | 92 | public: |
coleenp@548 | 93 | virtual bool do_object_b(oop p); |
duke@435 | 94 | }; |
duke@435 | 95 | |
duke@435 | 96 | class KeepAliveClosure: public OopClosure { |
coleenp@548 | 97 | protected: |
coleenp@548 | 98 | template <class T> void do_oop_work(T* p); |
duke@435 | 99 | public: |
coleenp@548 | 100 | virtual void do_oop(oop* p); |
coleenp@548 | 101 | virtual void do_oop(narrowOop* p); |
duke@435 | 102 | }; |
duke@435 | 103 | |
duke@435 | 104 | // |
duke@435 | 105 | // Friend decls |
duke@435 | 106 | // |
duke@435 | 107 | friend class AdjustPointerClosure; |
duke@435 | 108 | friend class KeepAliveClosure; |
duke@435 | 109 | friend class VM_MarkSweep; |
duke@435 | 110 | friend void marksweep_init(); |
duke@435 | 111 | |
duke@435 | 112 | // |
duke@435 | 113 | // Vars |
duke@435 | 114 | // |
duke@435 | 115 | protected: |
coleenp@4037 | 116 | // Total invocations of a MarkSweep collection |
tschatzl@5119 | 117 | static uint _total_invocations; |
coleenp@4037 | 118 | |
jcoomes@1746 | 119 | // Traversal stacks used during phase1 |
zgu@3900 | 120 | static Stack<oop, mtGC> _marking_stack; |
zgu@3900 | 121 | static Stack<ObjArrayTask, mtGC> _objarray_stack; |
duke@435 | 122 | |
duke@435 | 123 | // Space for storing/restoring mark word |
zgu@3900 | 124 | static Stack<markOop, mtGC> _preserved_mark_stack; |
zgu@3900 | 125 | static Stack<oop, mtGC> _preserved_oop_stack; |
duke@435 | 126 | static size_t _preserved_count; |
duke@435 | 127 | static size_t _preserved_count_max; |
duke@435 | 128 | static PreservedMark* _preserved_marks; |
duke@435 | 129 | |
duke@435 | 130 | // Reference processing (used in ...follow_contents) |
duke@435 | 131 | static ReferenceProcessor* _ref_processor; |
duke@435 | 132 | |
sla@5237 | 133 | static STWGCTimer* _gc_timer; |
sla@5237 | 134 | static SerialOldTracer* _gc_tracer; |
sla@5237 | 135 | |
duke@435 | 136 | // Non public closures |
duke@435 | 137 | static KeepAliveClosure keep_alive; |
duke@435 | 138 | |
duke@435 | 139 | // Debugging |
duke@435 | 140 | static void trace(const char* msg) PRODUCT_RETURN; |
duke@435 | 141 | |
duke@435 | 142 | public: |
duke@435 | 143 | // Public closures |
coleenp@4037 | 144 | static IsAliveClosure is_alive; |
coleenp@548 | 145 | static FollowRootClosure follow_root_closure; |
jrose@1424 | 146 | static CodeBlobToOopClosure follow_code_root_closure; // => follow_root_closure |
coleenp@548 | 147 | static MarkAndPushClosure mark_and_push_closure; |
coleenp@4037 | 148 | static FollowKlassClosure follow_klass_closure; |
coleenp@548 | 149 | static FollowStackClosure follow_stack_closure; |
duke@435 | 150 | static AdjustPointerClosure adjust_pointer_closure; |
coleenp@4037 | 151 | static AdjustKlassClosure adjust_klass_closure; |
coleenp@4037 | 152 | |
coleenp@4037 | 153 | // Accessors |
tschatzl@5119 | 154 | static uint total_invocations() { return _total_invocations; } |
duke@435 | 155 | |
duke@435 | 156 | // Reference Processing |
duke@435 | 157 | static ReferenceProcessor* const ref_processor() { return _ref_processor; } |
duke@435 | 158 | |
sla@5237 | 159 | static STWGCTimer* gc_timer() { return _gc_timer; } |
sla@5237 | 160 | static SerialOldTracer* gc_tracer() { return _gc_tracer; } |
sla@5237 | 161 | |
duke@435 | 162 | // Call backs for marking |
duke@435 | 163 | static void mark_object(oop obj); |
coleenp@548 | 164 | // Mark pointer and follow contents. Empty marking stack afterwards. |
coleenp@548 | 165 | template <class T> static inline void follow_root(T* p); |
coleenp@4037 | 166 | |
coleenp@548 | 167 | // Check mark and maybe push on marking stack |
coleenp@4037 | 168 | template <class T> static void mark_and_push(T* p); |
coleenp@4037 | 169 | |
jcoomes@1746 | 170 | static inline void push_objarray(oop obj, size_t index); |
duke@435 | 171 | |
coleenp@548 | 172 | static void follow_stack(); // Empty marking stack. |
duke@435 | 173 | |
coleenp@4037 | 174 | static void follow_klass(Klass* klass); |
coleenp@4037 | 175 | |
coleenp@4037 | 176 | static void follow_class_loader(ClassLoaderData* cld); |
coleenp@4037 | 177 | |
coleenp@548 | 178 | static void preserve_mark(oop p, markOop mark); |
coleenp@548 | 179 | // Save the mark word so it can be restored later |
coleenp@548 | 180 | static void adjust_marks(); // Adjust the pointers in the preserved marks table |
coleenp@548 | 181 | static void restore_marks(); // Restore the marks that we saved in preserve_mark |
duke@435 | 182 | |
stefank@5011 | 183 | template <class T> static inline void adjust_pointer(T* p); |
duke@435 | 184 | }; |
duke@435 | 185 | |
duke@435 | 186 | class PreservedMark VALUE_OBJ_CLASS_SPEC { |
duke@435 | 187 | private: |
duke@435 | 188 | oop _obj; |
duke@435 | 189 | markOop _mark; |
duke@435 | 190 | |
duke@435 | 191 | public: |
duke@435 | 192 | void init(oop obj, markOop mark) { |
duke@435 | 193 | _obj = obj; |
duke@435 | 194 | _mark = mark; |
duke@435 | 195 | } |
duke@435 | 196 | |
duke@435 | 197 | void adjust_pointer() { |
duke@435 | 198 | MarkSweep::adjust_pointer(&_obj); |
duke@435 | 199 | } |
duke@435 | 200 | |
duke@435 | 201 | void restore() { |
duke@435 | 202 | _obj->set_mark(_mark); |
duke@435 | 203 | } |
duke@435 | 204 | }; |
stefank@2314 | 205 | |
stefank@2314 | 206 | #endif // SHARE_VM_GC_IMPLEMENTATION_SHARED_MARKSWEEP_HPP |