1.1 --- a/src/share/vm/memory/iterator.hpp Fri Sep 18 09:57:47 2009 -0700 1.2 +++ b/src/share/vm/memory/iterator.hpp Wed Sep 23 23:56:15 2009 -0700 1.3 @@ -26,6 +26,7 @@ 1.4 1.5 class CodeBlob; 1.6 class ReferenceProcessor; 1.7 +class DataLayout; 1.8 1.9 // Closure provides abortability. 1.10 1.11 @@ -55,9 +56,23 @@ 1.12 1.13 // In support of post-processing of weak links of KlassKlass objects; 1.14 // see KlassKlass::oop_oop_iterate(). 1.15 - virtual const bool should_remember_klasses() const { return false; } 1.16 + 1.17 + virtual const bool should_remember_klasses() const { 1.18 + assert(!must_remember_klasses(), "Should have overriden this method."); 1.19 + return false; 1.20 + } 1.21 + 1.22 virtual void remember_klass(Klass* k) { /* do nothing */ } 1.23 1.24 + // In support of post-processing of weak references in 1.25 + // ProfileData (MethodDataOop) objects; see, for example, 1.26 + // VirtualCallData::oop_iterate(). 1.27 + virtual const bool should_remember_mdo() const { return false; } 1.28 + virtual void remember_mdo(DataLayout* v) { /* do nothing */ } 1.29 + 1.30 + // If "true", invoke on nmethods (when scanning compiled frames). 1.31 + virtual const bool do_nmethods() const { return false; } 1.32 + 1.33 // The methods below control how object iterations invoking this closure 1.34 // should be performed: 1.35 1.36 @@ -72,6 +87,12 @@ 1.37 // location without an intervening "major reset" (like the end of a GC). 1.38 virtual bool idempotent() { return false; } 1.39 virtual bool apply_to_weak_ref_discovered_field() { return false; } 1.40 + 1.41 +#ifdef ASSERT 1.42 + static bool _must_remember_klasses; 1.43 + static bool must_remember_klasses(); 1.44 + static void set_must_remember_klasses(bool v); 1.45 +#endif 1.46 }; 1.47 1.48 // ObjectClosure is used for iterating through an object space 1.49 @@ -262,3 +283,38 @@ 1.50 // correct length. 1.51 virtual void do_tag(int tag) = 0; 1.52 }; 1.53 + 1.54 +#ifdef ASSERT 1.55 +// This class is used to flag phases of a collection that 1.56 +// can unload classes and which should override the 1.57 +// should_remember_klasses() and remember_klass() of OopClosure. 1.58 +// The _must_remember_klasses is set in the contructor and restored 1.59 +// in the destructor. _must_remember_klasses is checked in assertions 1.60 +// in the OopClosure implementations of should_remember_klasses() and 1.61 +// remember_klass() and the expectation is that the OopClosure 1.62 +// implementation should not be in use if _must_remember_klasses is set. 1.63 +// Instances of RememberKlassesChecker can be place in 1.64 +// marking phases of collections which can do class unloading. 1.65 +// RememberKlassesChecker can be passed "false" to turn off checking. 1.66 +// It is used by CMS when CMS yields to a different collector. 1.67 +class RememberKlassesChecker: StackObj { 1.68 + bool _state; 1.69 + bool _skip; 1.70 + public: 1.71 + RememberKlassesChecker(bool checking_on) : _state(false), _skip(false) { 1.72 + _skip = !(ClassUnloading && !UseConcMarkSweepGC || 1.73 + CMSClassUnloadingEnabled && UseConcMarkSweepGC); 1.74 + if (_skip) { 1.75 + return; 1.76 + } 1.77 + _state = OopClosure::must_remember_klasses(); 1.78 + OopClosure::set_must_remember_klasses(checking_on); 1.79 + } 1.80 + ~RememberKlassesChecker() { 1.81 + if (_skip) { 1.82 + return; 1.83 + } 1.84 + OopClosure::set_must_remember_klasses(_state); 1.85 + } 1.86 +}; 1.87 +#endif // ASSERT