Path: blob/master/src/hotspot/share/gc/serial/markSweep.hpp
41149 views
/*1* Copyright (c) 1997, 2019, 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_GC_SERIAL_MARKSWEEP_HPP25#define SHARE_GC_SERIAL_MARKSWEEP_HPP2627#include "gc/shared/collectedHeap.hpp"28#include "gc/shared/genOopClosures.hpp"29#include "gc/shared/taskqueue.hpp"30#include "memory/iterator.hpp"31#include "oops/markWord.hpp"32#include "oops/oop.hpp"33#include "runtime/timer.hpp"34#include "utilities/growableArray.hpp"35#include "utilities/stack.hpp"3637class ReferenceProcessor;38class DataLayout;39class SerialOldTracer;40class STWGCTimer;4142// MarkSweep takes care of global mark-compact garbage collection for a43// GenCollectedHeap using a four-phase pointer forwarding algorithm. All44// generations are assumed to support marking; those that can also support45// compaction.46//47// Class unloading will only occur when a full gc is invoked.4849// declared at end50class PreservedMark;51class MarkAndPushClosure;52class AdjustPointerClosure;5354class MarkSweep : AllStatic {55//56// Inline closure decls57//58class FollowRootClosure: public BasicOopIterateClosure {59public:60virtual void do_oop(oop* p);61virtual void do_oop(narrowOop* p);62};6364class FollowStackClosure: public VoidClosure {65public:66virtual void do_void();67};6869// Used for java/lang/ref handling70class IsAliveClosure: public BoolObjectClosure {71public:72virtual bool do_object_b(oop p);73};7475class KeepAliveClosure: public OopClosure {76protected:77template <class T> void do_oop_work(T* p);78public:79virtual void do_oop(oop* p);80virtual void do_oop(narrowOop* p);81};8283//84// Friend decls85//86friend class AdjustPointerClosure;87friend class KeepAliveClosure;88friend class VM_MarkSweep;8990//91// Vars92//93protected:94// Total invocations of a MarkSweep collection95static uint _total_invocations;9697// Traversal stacks used during phase198static Stack<oop, mtGC> _marking_stack;99static Stack<ObjArrayTask, mtGC> _objarray_stack;100101// Space for storing/restoring mark word102static Stack<markWord, mtGC> _preserved_mark_stack;103static Stack<oop, mtGC> _preserved_oop_stack;104static size_t _preserved_count;105static size_t _preserved_count_max;106static PreservedMark* _preserved_marks;107108// Reference processing (used in ...follow_contents)109static ReferenceProcessor* _ref_processor;110111static STWGCTimer* _gc_timer;112static SerialOldTracer* _gc_tracer;113114// Non public closures115static KeepAliveClosure keep_alive;116117public:118static void initialize();119120// Public closures121static IsAliveClosure is_alive;122static FollowRootClosure follow_root_closure;123static MarkAndPushClosure mark_and_push_closure;124static FollowStackClosure follow_stack_closure;125static CLDToOopClosure follow_cld_closure;126static AdjustPointerClosure adjust_pointer_closure;127static CLDToOopClosure adjust_cld_closure;128129// Accessors130static uint total_invocations() { return _total_invocations; }131132// Reference Processing133static ReferenceProcessor* const ref_processor() { return _ref_processor; }134static void set_ref_processor(ReferenceProcessor* rp);135136static STWGCTimer* gc_timer() { return _gc_timer; }137static SerialOldTracer* gc_tracer() { return _gc_tracer; }138139static void preserve_mark(oop p, markWord mark);140// Save the mark word so it can be restored later141static void adjust_marks(); // Adjust the pointers in the preserved marks table142static void restore_marks(); // Restore the marks that we saved in preserve_mark143144static int adjust_pointers(oop obj);145146static void follow_stack(); // Empty marking stack.147148static void follow_klass(Klass* klass);149150static void follow_cld(ClassLoaderData* cld);151152template <class T> static inline void adjust_pointer(T* p);153154// Check mark and maybe push on marking stack155template <class T> static void mark_and_push(T* p);156157private:158// Call backs for marking159static void mark_object(oop obj);160// Mark pointer and follow contents. Empty marking stack afterwards.161template <class T> static inline void follow_root(T* p);162163static inline void push_objarray(oop obj, size_t index);164165static void follow_object(oop obj);166167static void follow_array(objArrayOop array);168169static void follow_array_chunk(objArrayOop array, int index);170};171172class MarkAndPushClosure: public OopIterateClosure {173public:174template <typename T> void do_oop_work(T* p);175virtual void do_oop(oop* p);176virtual void do_oop(narrowOop* p);177178virtual bool do_metadata() { return true; }179virtual void do_klass(Klass* k);180virtual void do_cld(ClassLoaderData* cld);181182void set_ref_discoverer(ReferenceDiscoverer* rd) {183set_ref_discoverer_internal(rd);184}185};186187class AdjustPointerClosure: public BasicOopIterateClosure {188public:189template <typename T> void do_oop_work(T* p);190virtual void do_oop(oop* p);191virtual void do_oop(narrowOop* p);192virtual ReferenceIterationMode reference_iteration_mode() { return DO_FIELDS; }193};194195class PreservedMark {196private:197oop _obj;198markWord _mark;199200public:201void init(oop obj, markWord mark) {202_obj = obj;203_mark = mark;204}205206void adjust_pointer();207void restore();208};209210#endif // SHARE_GC_SERIAL_MARKSWEEP_HPP211212213