Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/memory/genOopClosures.hpp
32285 views
/*1* Copyright (c) 2001, 2014, 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_MEMORY_GENOOPCLOSURES_HPP25#define SHARE_VM_MEMORY_GENOOPCLOSURES_HPP2627#include "memory/iterator.hpp"28#include "oops/oop.hpp"2930class Generation;31class HeapWord;32class CardTableRS;33class CardTableModRefBS;34class DefNewGeneration;35class KlassRemSet;3637template<class E, MEMFLAGS F, unsigned int N> class GenericTaskQueue;38typedef GenericTaskQueue<oop, mtGC, TASKQUEUE_SIZE> OopTaskQueue;39template<class T, MEMFLAGS F> class GenericTaskQueueSet;40typedef GenericTaskQueueSet<OopTaskQueue, mtGC> OopTaskQueueSet;4142// Closure for iterating roots from a particular generation43// Note: all classes deriving from this MUST call this do_barrier44// method at the end of their own do_oop method!45// Note: no do_oop defined, this is an abstract class.4647class OopsInGenClosure : public ExtendedOopClosure {48private:49Generation* _orig_gen; // generation originally set in ctor50Generation* _gen; // generation being scanned5152protected:53// Some subtypes need access.54HeapWord* _gen_boundary; // start of generation55CardTableRS* _rs; // remembered set5657// For assertions58Generation* generation() { return _gen; }59CardTableRS* rs() { return _rs; }6061// Derived classes that modify oops so that they might be old-to-young62// pointers must call the method below.63template <class T> void do_barrier(T* p);6465// Version for use by closures that may be called in parallel code.66template <class T> void par_do_barrier(T* p);6768public:69OopsInGenClosure() : ExtendedOopClosure(NULL),70_orig_gen(NULL), _gen(NULL), _gen_boundary(NULL), _rs(NULL) {};7172OopsInGenClosure(Generation* gen);73void set_generation(Generation* gen);7475void reset_generation() { _gen = _orig_gen; }7677// Problem with static closures: must have _gen_boundary set at some point,78// but cannot do this until after the heap is initialized.79void set_orig_generation(Generation* gen) {80_orig_gen = gen;81set_generation(gen);82}8384HeapWord* gen_boundary() { return _gen_boundary; }8586};8788// Super class for scan closures. It contains code to dirty scanned Klasses.89class OopsInKlassOrGenClosure: public OopsInGenClosure {90Klass* _scanned_klass;91public:92OopsInKlassOrGenClosure(Generation* g) : OopsInGenClosure(g), _scanned_klass(NULL) {}93void set_scanned_klass(Klass* k) {94assert(k == NULL || _scanned_klass == NULL, "Must be");95_scanned_klass = k;96}97bool is_scanning_a_klass() { return _scanned_klass != NULL; }98void do_klass_barrier();99};100101// Closure for scanning DefNewGeneration.102//103// This closure will perform barrier store calls for ALL104// pointers in scanned oops.105class ScanClosure: public OopsInKlassOrGenClosure {106protected:107DefNewGeneration* _g;108HeapWord* _boundary;109bool _gc_barrier;110template <class T> inline void do_oop_work(T* p);111public:112ScanClosure(DefNewGeneration* g, bool gc_barrier);113virtual void do_oop(oop* p);114virtual void do_oop(narrowOop* p);115inline void do_oop_nv(oop* p);116inline void do_oop_nv(narrowOop* p);117Prefetch::style prefetch_style() {118return Prefetch::do_write;119}120};121122// Closure for scanning DefNewGeneration.123//124// This closure only performs barrier store calls on125// pointers into the DefNewGeneration. This is less126// precise, but faster, than a ScanClosure127class FastScanClosure: public OopsInKlassOrGenClosure {128protected:129DefNewGeneration* _g;130HeapWord* _boundary;131bool _gc_barrier;132template <class T> inline void do_oop_work(T* p);133public:134FastScanClosure(DefNewGeneration* g, bool gc_barrier);135virtual void do_oop(oop* p);136virtual void do_oop(narrowOop* p);137inline void do_oop_nv(oop* p);138inline void do_oop_nv(narrowOop* p);139Prefetch::style prefetch_style() {140return Prefetch::do_write;141}142};143144class KlassScanClosure: public KlassClosure {145OopsInKlassOrGenClosure* _scavenge_closure;146// true if the the modified oops state should be saved.147bool _accumulate_modified_oops;148public:149KlassScanClosure(OopsInKlassOrGenClosure* scavenge_closure,150KlassRemSet* klass_rem_set_policy);151void do_klass(Klass* k);152};153154class FilteringClosure: public ExtendedOopClosure {155private:156HeapWord* _boundary;157ExtendedOopClosure* _cl;158protected:159template <class T> inline void do_oop_work(T* p) {160T heap_oop = oopDesc::load_heap_oop(p);161if (!oopDesc::is_null(heap_oop)) {162oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);163if ((HeapWord*)obj < _boundary) {164_cl->do_oop(p);165}166}167}168public:169FilteringClosure(HeapWord* boundary, ExtendedOopClosure* cl) :170ExtendedOopClosure(cl->_ref_processor), _boundary(boundary),171_cl(cl) {}172virtual void do_oop(oop* p);173virtual void do_oop(narrowOop* p);174inline void do_oop_nv(oop* p) { FilteringClosure::do_oop_work(p); }175inline void do_oop_nv(narrowOop* p) { FilteringClosure::do_oop_work(p); }176virtual bool do_metadata() { return do_metadata_nv(); }177inline bool do_metadata_nv() { assert(!_cl->do_metadata(), "assumption broken, must change to 'return _cl->do_metadata()'"); return false; }178};179180// Closure for scanning DefNewGeneration's weak references.181// NOTE: very much like ScanClosure but not derived from182// OopsInGenClosure -- weak references are processed all183// at once, with no notion of which generation they were in.184class ScanWeakRefClosure: public OopClosure {185protected:186DefNewGeneration* _g;187HeapWord* _boundary;188template <class T> inline void do_oop_work(T* p);189public:190ScanWeakRefClosure(DefNewGeneration* g);191virtual void do_oop(oop* p);192virtual void do_oop(narrowOop* p);193inline void do_oop_nv(oop* p);194inline void do_oop_nv(narrowOop* p);195};196197class VerifyOopClosure: public OopClosure {198protected:199template <class T> inline void do_oop_work(T* p) {200oop obj = oopDesc::load_decode_heap_oop(p);201guarantee(obj->is_oop_or_null(), err_msg("invalid oop: " INTPTR_FORMAT, p2i((oopDesc*) obj)));202}203public:204virtual void do_oop(oop* p);205virtual void do_oop(narrowOop* p);206static VerifyOopClosure verify_oop;207};208209#endif // SHARE_VM_MEMORY_GENOOPCLOSURES_HPP210211212