src/share/vm/memory/genOopClosures.hpp

changeset 0
f90c822e73f8
child 6876
710a3c8b516e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/memory/genOopClosures.hpp	Wed Apr 27 01:25:04 2016 +0800
     1.3 @@ -0,0 +1,210 @@
     1.4 +/*
     1.5 + * Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +#ifndef SHARE_VM_MEMORY_GENOOPCLOSURES_HPP
    1.29 +#define SHARE_VM_MEMORY_GENOOPCLOSURES_HPP
    1.30 +
    1.31 +#include "memory/iterator.hpp"
    1.32 +#include "oops/oop.hpp"
    1.33 +
    1.34 +class Generation;
    1.35 +class HeapWord;
    1.36 +class CardTableRS;
    1.37 +class CardTableModRefBS;
    1.38 +class DefNewGeneration;
    1.39 +class KlassRemSet;
    1.40 +
    1.41 +template<class E, MEMFLAGS F, unsigned int N> class GenericTaskQueue;
    1.42 +typedef GenericTaskQueue<oop, mtGC, TASKQUEUE_SIZE> OopTaskQueue;
    1.43 +template<class T, MEMFLAGS F> class GenericTaskQueueSet;
    1.44 +typedef GenericTaskQueueSet<OopTaskQueue, mtGC> OopTaskQueueSet;
    1.45 +
    1.46 +// Closure for iterating roots from a particular generation
    1.47 +// Note: all classes deriving from this MUST call this do_barrier
    1.48 +// method at the end of their own do_oop method!
    1.49 +// Note: no do_oop defined, this is an abstract class.
    1.50 +
    1.51 +class OopsInGenClosure : public ExtendedOopClosure {
    1.52 + private:
    1.53 +  Generation*  _orig_gen;     // generation originally set in ctor
    1.54 +  Generation*  _gen;          // generation being scanned
    1.55 +
    1.56 + protected:
    1.57 +  // Some subtypes need access.
    1.58 +  HeapWord*    _gen_boundary; // start of generation
    1.59 +  CardTableRS* _rs;           // remembered set
    1.60 +
    1.61 +  // For assertions
    1.62 +  Generation* generation() { return _gen; }
    1.63 +  CardTableRS* rs() { return _rs; }
    1.64 +
    1.65 +  // Derived classes that modify oops so that they might be old-to-young
    1.66 +  // pointers must call the method below.
    1.67 +  template <class T> void do_barrier(T* p);
    1.68 +
    1.69 +  // Version for use by closures that may be called in parallel code.
    1.70 +  template <class T> void par_do_barrier(T* p);
    1.71 +
    1.72 + public:
    1.73 +  OopsInGenClosure() : ExtendedOopClosure(NULL),
    1.74 +    _orig_gen(NULL), _gen(NULL), _gen_boundary(NULL), _rs(NULL) {};
    1.75 +
    1.76 +  OopsInGenClosure(Generation* gen);
    1.77 +  void set_generation(Generation* gen);
    1.78 +
    1.79 +  void reset_generation() { _gen = _orig_gen; }
    1.80 +
    1.81 +  // Problem with static closures: must have _gen_boundary set at some point,
    1.82 +  // but cannot do this until after the heap is initialized.
    1.83 +  void set_orig_generation(Generation* gen) {
    1.84 +    _orig_gen = gen;
    1.85 +    set_generation(gen);
    1.86 +  }
    1.87 +
    1.88 +  HeapWord* gen_boundary() { return _gen_boundary; }
    1.89 +
    1.90 +};
    1.91 +
    1.92 +// Super class for scan closures. It contains code to dirty scanned Klasses.
    1.93 +class OopsInKlassOrGenClosure: public OopsInGenClosure {
    1.94 +  Klass* _scanned_klass;
    1.95 + public:
    1.96 +  OopsInKlassOrGenClosure(Generation* g) : OopsInGenClosure(g), _scanned_klass(NULL) {}
    1.97 +  void set_scanned_klass(Klass* k) {
    1.98 +    assert(k == NULL || _scanned_klass == NULL, "Must be");
    1.99 +    _scanned_klass = k;
   1.100 +  }
   1.101 +  bool is_scanning_a_klass() { return _scanned_klass != NULL; }
   1.102 +  void do_klass_barrier();
   1.103 +};
   1.104 +
   1.105 +// Closure for scanning DefNewGeneration.
   1.106 +//
   1.107 +// This closure will perform barrier store calls for ALL
   1.108 +// pointers in scanned oops.
   1.109 +class ScanClosure: public OopsInKlassOrGenClosure {
   1.110 + protected:
   1.111 +  DefNewGeneration* _g;
   1.112 +  HeapWord*         _boundary;
   1.113 +  bool              _gc_barrier;
   1.114 +  template <class T> inline void do_oop_work(T* p);
   1.115 + public:
   1.116 +  ScanClosure(DefNewGeneration* g, bool gc_barrier);
   1.117 +  virtual void do_oop(oop* p);
   1.118 +  virtual void do_oop(narrowOop* p);
   1.119 +  inline void do_oop_nv(oop* p);
   1.120 +  inline void do_oop_nv(narrowOop* p);
   1.121 +  Prefetch::style prefetch_style() {
   1.122 +    return Prefetch::do_write;
   1.123 +  }
   1.124 +};
   1.125 +
   1.126 +// Closure for scanning DefNewGeneration.
   1.127 +//
   1.128 +// This closure only performs barrier store calls on
   1.129 +// pointers into the DefNewGeneration. This is less
   1.130 +// precise, but faster, than a ScanClosure
   1.131 +class FastScanClosure: public OopsInKlassOrGenClosure {
   1.132 + protected:
   1.133 +  DefNewGeneration* _g;
   1.134 +  HeapWord*         _boundary;
   1.135 +  bool              _gc_barrier;
   1.136 +  template <class T> inline void do_oop_work(T* p);
   1.137 + public:
   1.138 +  FastScanClosure(DefNewGeneration* g, bool gc_barrier);
   1.139 +  virtual void do_oop(oop* p);
   1.140 +  virtual void do_oop(narrowOop* p);
   1.141 +  inline void do_oop_nv(oop* p);
   1.142 +  inline void do_oop_nv(narrowOop* p);
   1.143 +  Prefetch::style prefetch_style() {
   1.144 +    return Prefetch::do_write;
   1.145 +  }
   1.146 +};
   1.147 +
   1.148 +class KlassScanClosure: public KlassClosure {
   1.149 +  OopsInKlassOrGenClosure* _scavenge_closure;
   1.150 +  // true if the the modified oops state should be saved.
   1.151 +  bool                     _accumulate_modified_oops;
   1.152 + public:
   1.153 +  KlassScanClosure(OopsInKlassOrGenClosure* scavenge_closure,
   1.154 +                   KlassRemSet* klass_rem_set_policy);
   1.155 +  void do_klass(Klass* k);
   1.156 +};
   1.157 +
   1.158 +class FilteringClosure: public ExtendedOopClosure {
   1.159 + private:
   1.160 +  HeapWord*   _boundary;
   1.161 +  ExtendedOopClosure* _cl;
   1.162 + protected:
   1.163 +  template <class T> inline void do_oop_work(T* p) {
   1.164 +    T heap_oop = oopDesc::load_heap_oop(p);
   1.165 +    if (!oopDesc::is_null(heap_oop)) {
   1.166 +      oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);
   1.167 +      if ((HeapWord*)obj < _boundary) {
   1.168 +        _cl->do_oop(p);
   1.169 +      }
   1.170 +    }
   1.171 +  }
   1.172 + public:
   1.173 +  FilteringClosure(HeapWord* boundary, ExtendedOopClosure* cl) :
   1.174 +    ExtendedOopClosure(cl->_ref_processor), _boundary(boundary),
   1.175 +    _cl(cl) {}
   1.176 +  virtual void do_oop(oop* p);
   1.177 +  virtual void do_oop(narrowOop* p);
   1.178 +  inline void do_oop_nv(oop* p)       { FilteringClosure::do_oop_work(p); }
   1.179 +  inline void do_oop_nv(narrowOop* p) { FilteringClosure::do_oop_work(p); }
   1.180 +  virtual bool do_metadata()          { return do_metadata_nv(); }
   1.181 +  inline bool do_metadata_nv()        { assert(!_cl->do_metadata(), "assumption broken, must change to 'return _cl->do_metadata()'"); return false; }
   1.182 +};
   1.183 +
   1.184 +// Closure for scanning DefNewGeneration's weak references.
   1.185 +// NOTE: very much like ScanClosure but not derived from
   1.186 +//  OopsInGenClosure -- weak references are processed all
   1.187 +//  at once, with no notion of which generation they were in.
   1.188 +class ScanWeakRefClosure: public OopClosure {
   1.189 + protected:
   1.190 +  DefNewGeneration* _g;
   1.191 +  HeapWord*         _boundary;
   1.192 +  template <class T> inline void do_oop_work(T* p);
   1.193 + public:
   1.194 +  ScanWeakRefClosure(DefNewGeneration* g);
   1.195 +  virtual void do_oop(oop* p);
   1.196 +  virtual void do_oop(narrowOop* p);
   1.197 +  inline void do_oop_nv(oop* p);
   1.198 +  inline void do_oop_nv(narrowOop* p);
   1.199 +};
   1.200 +
   1.201 +class VerifyOopClosure: public OopClosure {
   1.202 + protected:
   1.203 +  template <class T> inline void do_oop_work(T* p) {
   1.204 +    oop obj = oopDesc::load_decode_heap_oop(p);
   1.205 +    guarantee(obj->is_oop_or_null(), err_msg("invalid oop: " INTPTR_FORMAT, p2i((oopDesc*) obj)));
   1.206 +  }
   1.207 + public:
   1.208 +  virtual void do_oop(oop* p);
   1.209 +  virtual void do_oop(narrowOop* p);
   1.210 +  static VerifyOopClosure verify_oop;
   1.211 +};
   1.212 +
   1.213 +#endif // SHARE_VM_MEMORY_GENOOPCLOSURES_HPP

mercurial