duke@435: /* sla@5237: * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. duke@435: * duke@435: */ duke@435: stefank@2314: #ifndef SHARE_VM_GC_IMPLEMENTATION_SHARED_MARKSWEEP_HPP stefank@2314: #define SHARE_VM_GC_IMPLEMENTATION_SHARED_MARKSWEEP_HPP stefank@2314: stefank@2314: #include "gc_interface/collectedHeap.hpp" stefank@2314: #include "memory/universe.hpp" stefank@2314: #include "oops/markOop.hpp" stefank@2314: #include "oops/oop.hpp" stefank@2314: #include "runtime/timer.hpp" stefank@2314: #include "utilities/growableArray.hpp" stefank@2314: #include "utilities/stack.hpp" stefank@2314: #include "utilities/taskqueue.hpp" stefank@2314: duke@435: class ReferenceProcessor; ysr@1376: class DataLayout; sla@5237: class SerialOldTracer; sla@5237: class STWGCTimer; duke@435: duke@435: // MarkSweep takes care of global mark-compact garbage collection for a duke@435: // GenCollectedHeap using a four-phase pointer forwarding algorithm. All duke@435: // generations are assumed to support marking; those that can also support duke@435: // compaction. duke@435: // duke@435: // Class unloading will only occur when a full gc is invoked. duke@435: duke@435: // declared at end duke@435: class PreservedMark; duke@435: duke@435: class MarkSweep : AllStatic { duke@435: // coleenp@548: // Inline closure decls duke@435: // coleenp@548: class FollowRootClosure: public OopsInGenClosure { duke@435: public: coleenp@548: virtual void do_oop(oop* p); coleenp@548: virtual void do_oop(narrowOop* p); duke@435: }; duke@435: duke@435: class MarkAndPushClosure: public OopClosure { duke@435: public: coleenp@548: virtual void do_oop(oop* p); coleenp@548: virtual void do_oop(narrowOop* p); coleenp@4037: }; coleenp@4037: coleenp@4037: // The one and only place to start following the classes. coleenp@4037: // Should only be applied to the ClassLoaderData klasses list. coleenp@4037: class FollowKlassClosure : public KlassClosure { coleenp@4037: public: coleenp@4037: void do_klass(Klass* klass); coleenp@4037: }; coleenp@4037: class AdjustKlassClosure : public KlassClosure { coleenp@4037: public: coleenp@4037: void do_klass(Klass* klass); duke@435: }; duke@435: duke@435: class FollowStackClosure: public VoidClosure { duke@435: public: coleenp@548: virtual void do_void(); duke@435: }; duke@435: duke@435: class AdjustPointerClosure: public OopsInGenClosure { duke@435: public: coleenp@548: virtual void do_oop(oop* p); coleenp@548: virtual void do_oop(narrowOop* p); duke@435: }; duke@435: duke@435: // Used for java/lang/ref handling duke@435: class IsAliveClosure: public BoolObjectClosure { duke@435: public: coleenp@548: virtual bool do_object_b(oop p); duke@435: }; duke@435: duke@435: class KeepAliveClosure: public OopClosure { coleenp@548: protected: coleenp@548: template void do_oop_work(T* p); duke@435: public: coleenp@548: virtual void do_oop(oop* p); coleenp@548: virtual void do_oop(narrowOop* p); duke@435: }; duke@435: duke@435: // duke@435: // Friend decls duke@435: // duke@435: friend class AdjustPointerClosure; duke@435: friend class KeepAliveClosure; duke@435: friend class VM_MarkSweep; duke@435: friend void marksweep_init(); duke@435: duke@435: // duke@435: // Vars duke@435: // duke@435: protected: coleenp@4037: // Total invocations of a MarkSweep collection tschatzl@5119: static uint _total_invocations; coleenp@4037: jcoomes@1746: // Traversal stacks used during phase1 zgu@3900: static Stack _marking_stack; zgu@3900: static Stack _objarray_stack; duke@435: duke@435: // Space for storing/restoring mark word zgu@3900: static Stack _preserved_mark_stack; zgu@3900: static Stack _preserved_oop_stack; duke@435: static size_t _preserved_count; duke@435: static size_t _preserved_count_max; duke@435: static PreservedMark* _preserved_marks; duke@435: duke@435: // Reference processing (used in ...follow_contents) duke@435: static ReferenceProcessor* _ref_processor; duke@435: sla@5237: static STWGCTimer* _gc_timer; sla@5237: static SerialOldTracer* _gc_tracer; sla@5237: duke@435: // Non public closures duke@435: static KeepAliveClosure keep_alive; duke@435: duke@435: // Debugging duke@435: static void trace(const char* msg) PRODUCT_RETURN; duke@435: duke@435: public: duke@435: // Public closures coleenp@4037: static IsAliveClosure is_alive; coleenp@548: static FollowRootClosure follow_root_closure; jrose@1424: static CodeBlobToOopClosure follow_code_root_closure; // => follow_root_closure coleenp@548: static MarkAndPushClosure mark_and_push_closure; coleenp@4037: static FollowKlassClosure follow_klass_closure; coleenp@548: static FollowStackClosure follow_stack_closure; duke@435: static AdjustPointerClosure adjust_pointer_closure; coleenp@4037: static AdjustKlassClosure adjust_klass_closure; coleenp@4037: coleenp@4037: // Accessors tschatzl@5119: static uint total_invocations() { return _total_invocations; } duke@435: duke@435: // Reference Processing duke@435: static ReferenceProcessor* const ref_processor() { return _ref_processor; } duke@435: sla@5237: static STWGCTimer* gc_timer() { return _gc_timer; } sla@5237: static SerialOldTracer* gc_tracer() { return _gc_tracer; } sla@5237: duke@435: // Call backs for marking duke@435: static void mark_object(oop obj); coleenp@548: // Mark pointer and follow contents. Empty marking stack afterwards. coleenp@548: template static inline void follow_root(T* p); coleenp@4037: coleenp@548: // Check mark and maybe push on marking stack coleenp@4037: template static void mark_and_push(T* p); coleenp@4037: jcoomes@1746: static inline void push_objarray(oop obj, size_t index); duke@435: coleenp@548: static void follow_stack(); // Empty marking stack. duke@435: coleenp@4037: static void follow_klass(Klass* klass); coleenp@4037: coleenp@4037: static void follow_class_loader(ClassLoaderData* cld); coleenp@4037: coleenp@548: static void preserve_mark(oop p, markOop mark); coleenp@548: // Save the mark word so it can be restored later coleenp@548: static void adjust_marks(); // Adjust the pointers in the preserved marks table coleenp@548: static void restore_marks(); // Restore the marks that we saved in preserve_mark duke@435: stefank@5011: template static inline void adjust_pointer(T* p); duke@435: }; duke@435: duke@435: class PreservedMark VALUE_OBJ_CLASS_SPEC { duke@435: private: duke@435: oop _obj; duke@435: markOop _mark; duke@435: duke@435: public: duke@435: void init(oop obj, markOop mark) { duke@435: _obj = obj; duke@435: _mark = mark; duke@435: } duke@435: duke@435: void adjust_pointer() { duke@435: MarkSweep::adjust_pointer(&_obj); duke@435: } duke@435: duke@435: void restore() { duke@435: _obj->set_mark(_mark); duke@435: } duke@435: }; stefank@2314: stefank@2314: #endif // SHARE_VM_GC_IMPLEMENTATION_SHARED_MARKSWEEP_HPP