Path: blob/jdk8u272-b10-aarch32-20201026/hotspot/src/share/vm/gc_implementation/shared/markSweep.hpp
48726 views
/*1* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_VM_GC_IMPLEMENTATION_SHARED_MARKSWEEP_HPP25#define SHARE_VM_GC_IMPLEMENTATION_SHARED_MARKSWEEP_HPP2627#include "gc_interface/collectedHeap.hpp"28#include "memory/universe.hpp"29#include "oops/markOop.hpp"30#include "oops/oop.hpp"31#include "runtime/timer.hpp"32#include "utilities/growableArray.hpp"33#include "utilities/stack.hpp"34#include "utilities/taskqueue.hpp"3536class ReferenceProcessor;37class DataLayout;38class SerialOldTracer;39class STWGCTimer;4041// MarkSweep takes care of global mark-compact garbage collection for a42// GenCollectedHeap using a four-phase pointer forwarding algorithm. All43// generations are assumed to support marking; those that can also support44// compaction.45//46// Class unloading will only occur when a full gc is invoked.4748// declared at end49class PreservedMark;5051class MarkSweep : AllStatic {52//53// Inline closure decls54//55class FollowRootClosure: public OopsInGenClosure {56public:57virtual void do_oop(oop* p);58virtual void do_oop(narrowOop* p);59};6061class MarkAndPushClosure: public OopClosure {62public:63virtual void do_oop(oop* p);64virtual void do_oop(narrowOop* p);65};6667class FollowStackClosure: public VoidClosure {68public:69virtual void do_void();70};7172class AdjustPointerClosure: public OopsInGenClosure {73public:74virtual void do_oop(oop* p);75virtual void do_oop(narrowOop* p);76};7778// Used for java/lang/ref handling79class IsAliveClosure: public BoolObjectClosure {80public:81virtual bool do_object_b(oop p);82};8384class KeepAliveClosure: public OopClosure {85protected:86template <class T> void do_oop_work(T* p);87public:88virtual void do_oop(oop* p);89virtual void do_oop(narrowOop* p);90};9192//93// Friend decls94//95friend class AdjustPointerClosure;96friend class KeepAliveClosure;97friend class VM_MarkSweep;98friend void marksweep_init();99100//101// Vars102//103protected:104// Total invocations of a MarkSweep collection105static uint _total_invocations;106107// Traversal stacks used during phase1108static Stack<oop, mtGC> _marking_stack;109static Stack<ObjArrayTask, mtGC> _objarray_stack;110111// Space for storing/restoring mark word112static Stack<markOop, mtGC> _preserved_mark_stack;113static Stack<oop, mtGC> _preserved_oop_stack;114static size_t _preserved_count;115static size_t _preserved_count_max;116static PreservedMark* _preserved_marks;117118// Reference processing (used in ...follow_contents)119static ReferenceProcessor* _ref_processor;120121static STWGCTimer* _gc_timer;122static SerialOldTracer* _gc_tracer;123124// Non public closures125static KeepAliveClosure keep_alive;126127// Debugging128static void trace(const char* msg) PRODUCT_RETURN;129130public:131// Public closures132static IsAliveClosure is_alive;133static FollowRootClosure follow_root_closure;134static MarkAndPushClosure mark_and_push_closure;135static FollowStackClosure follow_stack_closure;136static CLDToOopClosure follow_cld_closure;137static AdjustPointerClosure adjust_pointer_closure;138static CLDToOopClosure adjust_cld_closure;139140// Accessors141static uint total_invocations() { return _total_invocations; }142143// Reference Processing144static ReferenceProcessor* const ref_processor() { return _ref_processor; }145146static STWGCTimer* gc_timer() { return _gc_timer; }147static SerialOldTracer* gc_tracer() { return _gc_tracer; }148149// Call backs for marking150static void mark_object(oop obj);151// Mark pointer and follow contents. Empty marking stack afterwards.152template <class T> static inline void follow_root(T* p);153154// Check mark and maybe push on marking stack155template <class T> static void mark_and_push(T* p);156157static inline void push_objarray(oop obj, size_t index);158159static void follow_stack(); // Empty marking stack.160161static void follow_klass(Klass* klass);162163static void follow_class_loader(ClassLoaderData* cld);164165static void preserve_mark(oop p, markOop mark);166// Save the mark word so it can be restored later167static void adjust_marks(); // Adjust the pointers in the preserved marks table168static void restore_marks(); // Restore the marks that we saved in preserve_mark169170template <class T> static inline void adjust_pointer(T* p);171};172173class PreservedMark VALUE_OBJ_CLASS_SPEC {174private:175oop _obj;176markOop _mark;177178public:179void init(oop obj, markOop mark) {180_obj = obj;181_mark = mark;182}183184void adjust_pointer() {185MarkSweep::adjust_pointer(&_obj);186}187188void restore() {189_obj->set_mark(_mark);190}191};192193#endif // SHARE_VM_GC_IMPLEMENTATION_SHARED_MARKSWEEP_HPP194195196