src/share/vm/memory/iterator.hpp

changeset 1370
05f89f00a864
parent 791
1ee8caae33af
child 1376
8b46c4d82093
     1.1 --- a/src/share/vm/memory/iterator.hpp	Fri Aug 14 13:44:15 2009 -0700
     1.2 +++ b/src/share/vm/memory/iterator.hpp	Mon Aug 24 10:36:31 2009 -0700
     1.3 @@ -54,7 +54,12 @@
     1.4  
     1.5    // In support of post-processing of weak links of KlassKlass objects;
     1.6    // see KlassKlass::oop_oop_iterate().
     1.7 -  virtual const bool should_remember_klasses() const { return false;    }
     1.8 +
     1.9 +  virtual const bool should_remember_klasses() const {
    1.10 +    assert(!must_remember_klasses(), "Should have overriden this method.");
    1.11 +    return false;
    1.12 +  }
    1.13 +
    1.14    virtual void remember_klass(Klass* k) { /* do nothing */ }
    1.15  
    1.16    // If "true", invoke on nmethods (when scanning compiled frames).
    1.17 @@ -74,6 +79,12 @@
    1.18    // location without an intervening "major reset" (like the end of a GC).
    1.19    virtual bool idempotent() { return false; }
    1.20    virtual bool apply_to_weak_ref_discovered_field() { return false; }
    1.21 +
    1.22 +#ifdef ASSERT
    1.23 +  static bool _must_remember_klasses;
    1.24 +  static bool must_remember_klasses();
    1.25 +  static void set_must_remember_klasses(bool v);
    1.26 +#endif
    1.27  };
    1.28  
    1.29  // ObjectClosure is used for iterating through an object space
    1.30 @@ -219,3 +230,38 @@
    1.31    // correct length.
    1.32    virtual void do_tag(int tag) = 0;
    1.33  };
    1.34 +
    1.35 +#ifdef ASSERT
    1.36 +// This class is used to flag phases of a collection that
    1.37 +// can unload classes and which should override the
    1.38 +// should_remember_klasses() and remember_klass() of OopClosure.
    1.39 +// The _must_remember_klasses is set in the contructor and restored
    1.40 +// in the destructor.  _must_remember_klasses is checked in assertions
    1.41 +// in the OopClosure implementations of should_remember_klasses() and
    1.42 +// remember_klass() and the expectation is that the OopClosure
    1.43 +// implementation should not be in use if _must_remember_klasses is set.
    1.44 +// Instances of RememberKlassesChecker can be place in
    1.45 +// marking phases of collections which can do class unloading.
    1.46 +// RememberKlassesChecker can be passed "false" to turn off checking.
    1.47 +// It is used by CMS when CMS yields to a different collector.
    1.48 +class RememberKlassesChecker: StackObj {
    1.49 + bool _state;
    1.50 + bool _skip;
    1.51 + public:
    1.52 +  RememberKlassesChecker(bool checking_on) : _state(false), _skip(false) {
    1.53 +    _skip = !(ClassUnloading && !UseConcMarkSweepGC ||
    1.54 +              CMSClassUnloadingEnabled && UseConcMarkSweepGC);
    1.55 +    if (_skip) {
    1.56 +      return;
    1.57 +    }
    1.58 +    _state = OopClosure::must_remember_klasses();
    1.59 +    OopClosure::set_must_remember_klasses(checking_on);
    1.60 +  }
    1.61 +  ~RememberKlassesChecker() {
    1.62 +    if (_skip) {
    1.63 +      return;
    1.64 +    }
    1.65 +    OopClosure::set_must_remember_klasses(_state);
    1.66 +  }
    1.67 +};
    1.68 +#endif  // ASSERT

mercurial