1.1 --- a/src/share/vm/memory/compactingPermGenGen.cpp Fri Feb 29 20:03:58 2008 -0800 1.2 +++ b/src/share/vm/memory/compactingPermGenGen.cpp Wed Mar 12 18:06:50 2008 -0700 1.3 @@ -26,9 +26,27 @@ 1.4 #include "incls/_compactingPermGenGen.cpp.incl" 1.5 1.6 1.7 -// Recursively adjust all pointers in an object and all objects by 1.8 -// referenced it. Clear marks on objects in order to prevent visiting 1.9 -// any object twice. 1.10 +// An ObjectClosure helper: Recursively adjust all pointers in an object 1.11 +// and all objects by referenced it. Clear marks on objects in order to 1.12 +// prevent visiting any object twice. This helper is used when the 1.13 +// RedefineClasses() API has been called. 1.14 + 1.15 +class AdjustSharedObjectClosure : public ObjectClosure { 1.16 +public: 1.17 + void do_object(oop obj) { 1.18 + if (obj->is_shared_readwrite()) { 1.19 + if (obj->mark()->is_marked()) { 1.20 + obj->init_mark(); // Don't revisit this object. 1.21 + obj->adjust_pointers(); // Adjust this object's references. 1.22 + } 1.23 + } 1.24 + } 1.25 +}; 1.26 + 1.27 + 1.28 +// An OopClosure helper: Recursively adjust all pointers in an object 1.29 +// and all objects by referenced it. Clear marks on objects in order 1.30 +// to prevent visiting any object twice. 1.31 1.32 class RecursiveAdjustSharedObjectClosure : public OopClosure { 1.33 public: 1.34 @@ -274,15 +292,34 @@ 1.35 // objects in the space will page in more objects than we need. 1.36 // Instead, use the system dictionary as strong roots into the read 1.37 // write space. 1.38 +// 1.39 +// If a RedefineClasses() call has been made, then we have to iterate 1.40 +// over the entire shared read-write space in order to find all the 1.41 +// objects that need to be forwarded. For example, it is possible for 1.42 +// an nmethod to be found and marked in GC phase-1 only for the nmethod 1.43 +// to be freed by the time we reach GC phase-3. The underlying method 1.44 +// is still marked, but we can't (easily) find it in GC phase-3 so we 1.45 +// blow up in GC phase-4. With RedefineClasses() we want replaced code 1.46 +// (EMCP or obsolete) to go away (i.e., be collectible) once it is no 1.47 +// longer being executed by any thread so we keep minimal attachments 1.48 +// to the replaced code. However, we can't guarantee when those EMCP 1.49 +// or obsolete methods will be collected so they may still be out there 1.50 +// even after we've severed our minimal attachments. 1.51 1.52 void CompactingPermGenGen::pre_adjust_pointers() { 1.53 if (spec()->enable_shared_spaces()) { 1.54 - RecursiveAdjustSharedObjectClosure blk; 1.55 - Universe::oops_do(&blk); 1.56 - StringTable::oops_do(&blk); 1.57 - SystemDictionary::always_strong_classes_do(&blk); 1.58 - TraversePlaceholdersClosure tpc; 1.59 - SystemDictionary::placeholders_do(&tpc); 1.60 + if (JvmtiExport::has_redefined_a_class()) { 1.61 + // RedefineClasses() requires a brute force approach 1.62 + AdjustSharedObjectClosure blk; 1.63 + rw_space()->object_iterate(&blk); 1.64 + } else { 1.65 + RecursiveAdjustSharedObjectClosure blk; 1.66 + Universe::oops_do(&blk); 1.67 + StringTable::oops_do(&blk); 1.68 + SystemDictionary::always_strong_classes_do(&blk); 1.69 + TraversePlaceholdersClosure tpc; 1.70 + SystemDictionary::placeholders_do(&tpc); 1.71 + } 1.72 } 1.73 } 1.74