0N/A/*
2945N/A * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
0N/A *
0N/A */
0N/A
1879N/A#ifndef SHARE_VM_GC_IMPLEMENTATION_SHARED_MARKSWEEP_HPP
1879N/A#define SHARE_VM_GC_IMPLEMENTATION_SHARED_MARKSWEEP_HPP
1879N/A
1879N/A#include "gc_interface/collectedHeap.hpp"
1879N/A#include "memory/universe.hpp"
1879N/A#include "oops/markOop.hpp"
1879N/A#include "oops/oop.hpp"
1879N/A#include "runtime/timer.hpp"
1879N/A#include "utilities/growableArray.hpp"
1879N/A#include "utilities/stack.hpp"
1879N/A#include "utilities/taskqueue.hpp"
1879N/A
0N/Aclass ReferenceProcessor;
941N/Aclass DataLayout;
4141N/Aclass SerialOldTracer;
4141N/Aclass STWGCTimer;
0N/A
0N/A// MarkSweep takes care of global mark-compact garbage collection for a
0N/A// GenCollectedHeap using a four-phase pointer forwarding algorithm. All
0N/A// generations are assumed to support marking; those that can also support
0N/A// compaction.
0N/A//
0N/A// Class unloading will only occur when a full gc is invoked.
0N/A
0N/A// If VALIDATE_MARK_SWEEP is defined, the -XX:+ValidateMarkSweep flag will
0N/A// be operational, and will provide slow but comprehensive self-checks within
0N/A// the GC. This is not enabled by default in product or release builds,
0N/A// since the extra call to track_adjusted_pointer() in _adjust_pointer()
0N/A// would be too much overhead, and would disturb performance measurement.
0N/A// However, debug builds are sometimes way too slow to run GC tests!
0N/A#ifdef ASSERT
0N/A#define VALIDATE_MARK_SWEEP 1
0N/A#endif
0N/A#ifdef VALIDATE_MARK_SWEEP
0N/A#define VALIDATE_MARK_SWEEP_ONLY(code) code
0N/A#else
0N/A#define VALIDATE_MARK_SWEEP_ONLY(code)
0N/A#endif
0N/A
0N/A// declared at end
0N/Aclass PreservedMark;
0N/A
0N/Aclass MarkSweep : AllStatic {
0N/A //
113N/A // Inline closure decls
0N/A //
113N/A class FollowRootClosure: public OopsInGenClosure {
0N/A public:
113N/A virtual void do_oop(oop* p);
113N/A virtual void do_oop(narrowOop* p);
0N/A };
0N/A
0N/A class MarkAndPushClosure: public OopClosure {
0N/A public:
113N/A virtual void do_oop(oop* p);
113N/A virtual void do_oop(narrowOop* p);
941N/A virtual const bool should_remember_mdo() const { return true; }
941N/A virtual void remember_mdo(DataLayout* p) { MarkSweep::revisit_mdo(p); }
0N/A };
0N/A
0N/A class FollowStackClosure: public VoidClosure {
0N/A public:
113N/A virtual void do_void();
0N/A };
0N/A
0N/A class AdjustPointerClosure: public OopsInGenClosure {
113N/A private:
0N/A bool _is_root;
0N/A public:
0N/A AdjustPointerClosure(bool is_root) : _is_root(is_root) {}
113N/A virtual void do_oop(oop* p);
113N/A virtual void do_oop(narrowOop* p);
0N/A };
0N/A
0N/A // Used for java/lang/ref handling
0N/A class IsAliveClosure: public BoolObjectClosure {
0N/A public:
113N/A virtual void do_object(oop p);
113N/A virtual bool do_object_b(oop p);
0N/A };
0N/A
0N/A class KeepAliveClosure: public OopClosure {
113N/A protected:
113N/A template <class T> void do_oop_work(T* p);
0N/A public:
113N/A virtual void do_oop(oop* p);
113N/A virtual void do_oop(narrowOop* p);
0N/A };
0N/A
0N/A //
0N/A // Friend decls
0N/A //
0N/A friend class AdjustPointerClosure;
0N/A friend class KeepAliveClosure;
0N/A friend class VM_MarkSweep;
0N/A friend void marksweep_init();
0N/A
0N/A //
0N/A // Vars
0N/A //
0N/A protected:
1311N/A // Traversal stacks used during phase1
3863N/A static Stack<oop, mtGC> _marking_stack;
3863N/A static Stack<ObjArrayTask, mtGC> _objarray_stack;
0N/A // Stack for live klasses to revisit at end of marking phase
3863N/A static Stack<Klass*, mtGC> _revisit_klass_stack;
941N/A // Set (stack) of MDO's to revisit at end of marking phase
3863N/A static Stack<DataLayout*, mtGC> _revisit_mdo_stack;
0N/A
0N/A // Space for storing/restoring mark word
3863N/A static Stack<markOop, mtGC> _preserved_mark_stack;
3863N/A static Stack<oop, mtGC> _preserved_oop_stack;
0N/A static size_t _preserved_count;
0N/A static size_t _preserved_count_max;
0N/A static PreservedMark* _preserved_marks;
0N/A
0N/A // Reference processing (used in ...follow_contents)
0N/A static ReferenceProcessor* _ref_processor;
0N/A
4141N/A static STWGCTimer* _gc_timer;
4141N/A static SerialOldTracer* _gc_tracer;
4141N/A
0N/A#ifdef VALIDATE_MARK_SWEEP
113N/A static GrowableArray<void*>* _root_refs_stack;
0N/A static GrowableArray<oop> * _live_oops;
0N/A static GrowableArray<oop> * _live_oops_moved_to;
0N/A static GrowableArray<size_t>* _live_oops_size;
0N/A static size_t _live_oops_index;
0N/A static size_t _live_oops_index_at_perm;
113N/A static GrowableArray<void*>* _other_refs_stack;
113N/A static GrowableArray<void*>* _adjusted_pointers;
0N/A static bool _pointer_tracking;
0N/A static bool _root_tracking;
0N/A
0N/A // The following arrays are saved since the time of the last GC and
0N/A // assist in tracking down problems where someone has done an errant
0N/A // store into the heap, usually to an oop that wasn't properly
0N/A // handleized across a GC. If we crash or otherwise fail before the
0N/A // next GC, we can query these arrays to find out the object we had
0N/A // intended to do the store to (assuming it is still alive) and the
0N/A // offset within that object. Covered under RecordMarkSweepCompaction.
0N/A static GrowableArray<HeapWord*> * _cur_gc_live_oops;
0N/A static GrowableArray<HeapWord*> * _cur_gc_live_oops_moved_to;
0N/A static GrowableArray<size_t>* _cur_gc_live_oops_size;
0N/A static GrowableArray<HeapWord*> * _last_gc_live_oops;
0N/A static GrowableArray<HeapWord*> * _last_gc_live_oops_moved_to;
0N/A static GrowableArray<size_t>* _last_gc_live_oops_size;
0N/A#endif
0N/A
0N/A // Non public closures
113N/A static IsAliveClosure is_alive;
0N/A static KeepAliveClosure keep_alive;
0N/A
0N/A // Class unloading. Update subklass/sibling/implementor links at end of marking phase.
0N/A static void follow_weak_klass_links();
0N/A
941N/A // Class unloading. Clear weak refs in MDO's (ProfileData)
941N/A // at the end of the marking phase.
941N/A static void follow_mdo_weak_refs();
941N/A
0N/A // Debugging
0N/A static void trace(const char* msg) PRODUCT_RETURN;
0N/A
0N/A public:
0N/A // Public closures
113N/A static FollowRootClosure follow_root_closure;
989N/A static CodeBlobToOopClosure follow_code_root_closure; // => follow_root_closure
113N/A static MarkAndPushClosure mark_and_push_closure;
113N/A static FollowStackClosure follow_stack_closure;
0N/A static AdjustPointerClosure adjust_root_pointer_closure;
0N/A static AdjustPointerClosure adjust_pointer_closure;
0N/A
0N/A // Reference Processing
0N/A static ReferenceProcessor* const ref_processor() { return _ref_processor; }
0N/A
4141N/A static STWGCTimer* gc_timer() { return _gc_timer; }
4141N/A static SerialOldTracer* gc_tracer() { return _gc_tracer; }
4141N/A
0N/A // Call backs for marking
0N/A static void mark_object(oop obj);
113N/A // Mark pointer and follow contents. Empty marking stack afterwards.
113N/A template <class T> static inline void follow_root(T* p);
113N/A // Check mark and maybe push on marking stack
113N/A template <class T> static inline void mark_and_push(T* p);
1311N/A static inline void push_objarray(oop obj, size_t index);
0N/A
113N/A static void follow_stack(); // Empty marking stack.
0N/A
113N/A static void preserve_mark(oop p, markOop mark);
113N/A // Save the mark word so it can be restored later
113N/A static void adjust_marks(); // Adjust the pointers in the preserved marks table
113N/A static void restore_marks(); // Restore the marks that we saved in preserve_mark
0N/A
113N/A template <class T> static inline void adjust_pointer(T* p, bool isroot);
0N/A
113N/A static void adjust_root_pointer(oop* p) { adjust_pointer(p, true); }
113N/A static void adjust_pointer(oop* p) { adjust_pointer(p, false); }
113N/A static void adjust_pointer(narrowOop* p) { adjust_pointer(p, false); }
0N/A
0N/A#ifdef VALIDATE_MARK_SWEEP
113N/A static void track_adjusted_pointer(void* p, bool isroot);
113N/A static void check_adjust_pointer(void* p);
0N/A static void track_interior_pointers(oop obj);
0N/A static void check_interior_pointers();
0N/A
0N/A static void reset_live_oop_tracking(bool at_perm);
0N/A static void register_live_oop(oop p, size_t size);
0N/A static void validate_live_oop(oop p, size_t size);
0N/A static void live_oop_moved_to(HeapWord* q, size_t size, HeapWord* compaction_top);
0N/A static void compaction_complete();
0N/A
0N/A // Querying operation of RecordMarkSweepCompaction results.
0N/A // Finds and prints the current base oop and offset for a word
0N/A // within an oop that was live during the last GC. Helpful for
0N/A // tracking down heap stomps.
0N/A static void print_new_location_of_heap_address(HeapWord* q);
0N/A#endif
0N/A
0N/A // Call backs for class unloading
941N/A // Update subklass/sibling/implementor links at end of marking.
941N/A static void revisit_weak_klass_link(Klass* k);
941N/A // For weak refs clearing in MDO's
941N/A static void revisit_mdo(DataLayout* p);
0N/A};
0N/A
0N/Aclass PreservedMark VALUE_OBJ_CLASS_SPEC {
0N/Aprivate:
0N/A oop _obj;
0N/A markOop _mark;
0N/A
0N/Apublic:
0N/A void init(oop obj, markOop mark) {
0N/A _obj = obj;
0N/A _mark = mark;
0N/A }
0N/A
0N/A void adjust_pointer() {
0N/A MarkSweep::adjust_pointer(&_obj);
0N/A }
0N/A
0N/A void restore() {
0N/A _obj->set_mark(_mark);
0N/A }
0N/A};
1879N/A
1879N/A#endif // SHARE_VM_GC_IMPLEMENTATION_SHARED_MARKSWEEP_HPP