< prev index next >

src/hotspot/share/gc/parallel/psScavenge.inline.hpp

Print this page




  68 class PSRootsClosure: public OopClosure {
  69  private:
  70   PSPromotionManager* _promotion_manager;
  71 
  72  protected:
  73   template <class T> void do_oop_work(T *p) {
  74     if (PSScavenge::should_scavenge(p)) {
  75       // We never card mark roots, maybe call a func without test?
  76       _promotion_manager->copy_and_push_safe_barrier<T, promote_immediately>(p);
  77     }
  78   }
  79  public:
  80   PSRootsClosure(PSPromotionManager* pm) : _promotion_manager(pm) { }
  81   void do_oop(oop* p)       { PSRootsClosure::do_oop_work(p); }
  82   void do_oop(narrowOop* p) { PSRootsClosure::do_oop_work(p); }
  83 };
  84 
  85 typedef PSRootsClosure</*promote_immediately=*/false> PSScavengeRootsClosure;
  86 typedef PSRootsClosure</*promote_immediately=*/true> PSPromoteRootsClosure;
  87 
  88 // Scavenges a single oop in a Klass.
  89 class PSScavengeFromKlassClosure: public OopClosure {
  90  private:
  91   PSPromotionManager* _pm;
  92   // Used to redirty a scanned klass if it has oops
  93   // pointing to the young generation after being scanned.
  94   Klass*             _scanned_klass;
  95  public:
  96   PSScavengeFromKlassClosure(PSPromotionManager* pm) : _pm(pm), _scanned_klass(NULL) { }
  97   void do_oop(narrowOop* p) { ShouldNotReachHere(); }
  98   void do_oop(oop* p)       {
  99     ParallelScavengeHeap* psh = ParallelScavengeHeap::heap();
 100     assert(!psh->is_in_reserved(p), "GC barrier needed");
 101     if (PSScavenge::should_scavenge(p)) {
 102       assert(PSScavenge::should_scavenge(p, true), "revisiting object?");
 103 
 104       oop o = *p;
 105       oop new_obj;
 106       if (o->is_forwarded()) {
 107         new_obj = o->forwardee();
 108       } else {
 109         new_obj = _pm->copy_to_survivor_space</*promote_immediately=*/false>(o);
 110       }
 111       oopDesc::encode_store_heap_oop_not_null(p, new_obj);
 112 
 113       if (PSScavenge::is_obj_in_young(new_obj)) {
 114         do_klass_barrier();
 115       }
 116     }
 117   }
 118 
 119   void set_scanned_klass(Klass* klass) {
 120     assert(_scanned_klass == NULL || klass == NULL, "Should always only handling one klass at a time");
 121     _scanned_klass = klass;
 122   }
 123 
 124  private:
 125   void do_klass_barrier() {
 126     assert(_scanned_klass != NULL, "Should not be called without having a scanned klass");
 127     _scanned_klass->record_modified_oops();
 128   }
 129 
 130 };
 131 
 132 // Scavenges the oop in a Klass.
 133 class PSScavengeKlassClosure: public KlassClosure {
 134  private:
 135   PSScavengeFromKlassClosure _oop_closure;
 136  protected:
 137  public:
 138   PSScavengeKlassClosure(PSPromotionManager* pm) : _oop_closure(pm) { }
 139   void do_klass(Klass* klass) {
 140     // If the klass has not been dirtied we know that there's
 141     // no references into  the young gen and we can skip it.
 142 
 143     if (klass->has_modified_oops()) {
 144       // Clean the klass since we're going to scavenge all the metadata.
 145       klass->clear_modified_oops();
 146 
 147       // Setup the promotion manager to redirty this klass
 148       // if references are left in the young gen.
 149       _oop_closure.set_scanned_klass(klass);
 150 
 151       klass->oops_do(&_oop_closure);

 152 
 153       _oop_closure.set_scanned_klass(NULL);
 154     }
 155   }
 156 };

 157 
 158 #endif // SHARE_VM_GC_PARALLEL_PSSCAVENGE_INLINE_HPP


  68 class PSRootsClosure: public OopClosure {
  69  private:
  70   PSPromotionManager* _promotion_manager;
  71 
  72  protected:
  73   template <class T> void do_oop_work(T *p) {
  74     if (PSScavenge::should_scavenge(p)) {
  75       // We never card mark roots, maybe call a func without test?
  76       _promotion_manager->copy_and_push_safe_barrier<T, promote_immediately>(p);
  77     }
  78   }
  79  public:
  80   PSRootsClosure(PSPromotionManager* pm) : _promotion_manager(pm) { }
  81   void do_oop(oop* p)       { PSRootsClosure::do_oop_work(p); }
  82   void do_oop(narrowOop* p) { PSRootsClosure::do_oop_work(p); }
  83 };
  84 
  85 typedef PSRootsClosure</*promote_immediately=*/false> PSScavengeRootsClosure;
  86 typedef PSRootsClosure</*promote_immediately=*/true> PSPromoteRootsClosure;
  87 
  88 // Scavenges a single oop in a ClassLoaderData.
  89 class PSScavengeFromCLDClosure: public OopClosure {
  90  private:
  91   PSPromotionManager* _pm;
  92   // Used to redirty a scanned cld if it has oops
  93   // pointing to the young generation after being scanned.
  94   ClassLoaderData*             _scanned_cld;
  95  public:
  96   PSScavengeFromCLDClosure(PSPromotionManager* pm) : _pm(pm), _scanned_cld(NULL) { }
  97   void do_oop(narrowOop* p) { ShouldNotReachHere(); }
  98   void do_oop(oop* p)       {
  99     ParallelScavengeHeap* psh = ParallelScavengeHeap::heap();
 100     assert(!psh->is_in_reserved(p), "GC barrier needed");
 101     if (PSScavenge::should_scavenge(p)) {
 102       assert(PSScavenge::should_scavenge(p, true), "revisiting object?");
 103 
 104       oop o = *p;
 105       oop new_obj;
 106       if (o->is_forwarded()) {
 107         new_obj = o->forwardee();
 108       } else {
 109         new_obj = _pm->copy_to_survivor_space</*promote_immediately=*/false>(o);
 110       }
 111       oopDesc::encode_store_heap_oop_not_null(p, new_obj);
 112 
 113       if (PSScavenge::is_obj_in_young(new_obj)) {
 114         do_cld_barrier();
 115       }
 116     }
 117   }
 118 
 119   void set_scanned_cld(ClassLoaderData* cld) {
 120     assert(_scanned_cld == NULL || cld == NULL, "Should always only handling one cld at a time");
 121     _scanned_cld = cld;
 122   }
 123 
 124  private:
 125   void do_cld_barrier() {
 126     assert(_scanned_cld != NULL, "Should not be called without having a scanned cld");
 127     _scanned_cld->record_modified_oops();
 128   }

 129 };
 130 
 131 // Scavenges the oop in a ClassLoaderData.
 132 class PSScavengeCLDClosure: public CLDClosure {
 133  private:
 134   PSScavengeFromCLDClosure _oop_closure;
 135  protected:
 136  public:
 137   PSScavengeCLDClosure(PSPromotionManager* pm) : _oop_closure(pm) { }
 138   void do_cld(ClassLoaderData* cld) {
 139     // If the cld has not been dirtied we know that there's
 140     // no references into  the young gen and we can skip it.
 141 
 142     if (cld->has_modified_oops()) {
 143       // Setup the promotion manager to redirty this cld



 144       // if references are left in the young gen.
 145       _oop_closure.set_scanned_cld(cld);
 146 
 147       // Clean the cld since we're going to scavenge all the metadata.
 148       cld->oops_do(&_oop_closure, false, /*clear_modified_oops*/true);
 149 
 150       _oop_closure.set_scanned_cld(NULL);
 151     }
 152   }
 153 };
 154 
 155 
 156 #endif // SHARE_VM_GC_PARALLEL_PSSCAVENGE_INLINE_HPP
< prev index next >