< prev index next >

src/hotspot/share/gc/z/zHeapIterator.cpp

Print this page




  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 #include "precompiled.hpp"
  25 #include "gc/z/zAddressRangeMap.inline.hpp"
  26 #include "gc/z/zBarrier.inline.hpp"
  27 #include "gc/z/zGlobals.hpp"
  28 #include "gc/z/zHeapIterator.hpp"
  29 #include "gc/z/zOop.inline.hpp"
  30 #include "gc/z/zRootsIterator.hpp"

  31 #include "oops/oop.inline.hpp"
  32 #include "utilities/bitMap.inline.hpp"
  33 #include "utilities/stack.inline.hpp"
  34 
  35 class ZHeapIteratorBitMap : public CHeapObj<mtGC> {
  36 private:
  37   CHeapBitMap _map;
  38 
  39 public:
  40   ZHeapIteratorBitMap(size_t size_in_bits) :
  41       _map(size_in_bits) {}
  42 
  43   bool try_set_bit(size_t index) {
  44     if (_map.at(index)) {
  45       return false;
  46     }
  47 
  48     _map.set_bit(index);
  49     return true;
  50   }


  56   ObjectClosure* const _cl;
  57 
  58 public:
  59   ZHeapIteratorRootOopClosure(ZHeapIterator* iter, ObjectClosure* cl) :
  60       _iter(iter),
  61       _cl(cl) {}
  62 
  63   virtual void do_oop(oop* p) {
  64     // Load barrier needed here for the same reason we
  65     // need fixup_partial_loads() in ZHeap::mark_end()
  66     const oop obj = ZBarrier::load_barrier_on_oop_field(p);
  67     _iter->push(obj);
  68     _iter->drain(_cl);
  69   }
  70 
  71   virtual void do_oop(narrowOop* p) {
  72     ShouldNotReachHere();
  73   }
  74 };
  75 
  76 class ZHeapIteratorPushOopClosure : public ExtendedOopClosure {
  77 private:
  78   ZHeapIterator* const _iter;
  79   const oop            _base;
  80 
  81 public:
  82   ZHeapIteratorPushOopClosure(ZHeapIterator* iter, oop base) :
  83       _iter(iter),
  84       _base(base) {}
  85 
  86   void do_oop_nv(oop* p) {
  87     const oop obj = HeapAccess<ON_UNKNOWN_OOP_REF>::oop_load_at(_base, _base->field_offset(p));
  88     _iter->push(obj);
  89   }
  90 
  91   void do_oop_nv(narrowOop* p) {
  92     ShouldNotReachHere();
  93   }
  94 
  95   virtual void do_oop(oop* p) {
  96     do_oop_nv(p);
  97   }
  98 
  99   virtual void do_oop(narrowOop* p) {
 100     do_oop_nv(p);
 101   }
 102 
 103 #ifdef ASSERT
 104   virtual bool should_verify_oops() {
 105     return false;
 106   }
 107 #endif
 108 };
 109 
 110 ZHeapIterator::ZHeapIterator() :
 111     _visit_stack(),
 112     _visit_map() {}
 113 
 114 ZHeapIterator::~ZHeapIterator() {
 115   ZVisitMapIterator iter(&_visit_map);
 116   for (ZHeapIteratorBitMap* map; iter.next(&map);) {
 117     delete map;
 118   }
 119 }
 120 




  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 #include "precompiled.hpp"
  25 #include "gc/z/zAddressRangeMap.inline.hpp"
  26 #include "gc/z/zBarrier.inline.hpp"
  27 #include "gc/z/zGlobals.hpp"
  28 #include "gc/z/zHeapIterator.hpp"
  29 #include "gc/z/zOop.inline.hpp"
  30 #include "gc/z/zRootsIterator.hpp"
  31 #include "memory/iterator.inline.hpp"
  32 #include "oops/oop.inline.hpp"
  33 #include "utilities/bitMap.inline.hpp"
  34 #include "utilities/stack.inline.hpp"
  35 
  36 class ZHeapIteratorBitMap : public CHeapObj<mtGC> {
  37 private:
  38   CHeapBitMap _map;
  39 
  40 public:
  41   ZHeapIteratorBitMap(size_t size_in_bits) :
  42       _map(size_in_bits) {}
  43 
  44   bool try_set_bit(size_t index) {
  45     if (_map.at(index)) {
  46       return false;
  47     }
  48 
  49     _map.set_bit(index);
  50     return true;
  51   }


  57   ObjectClosure* const _cl;
  58 
  59 public:
  60   ZHeapIteratorRootOopClosure(ZHeapIterator* iter, ObjectClosure* cl) :
  61       _iter(iter),
  62       _cl(cl) {}
  63 
  64   virtual void do_oop(oop* p) {
  65     // Load barrier needed here for the same reason we
  66     // need fixup_partial_loads() in ZHeap::mark_end()
  67     const oop obj = ZBarrier::load_barrier_on_oop_field(p);
  68     _iter->push(obj);
  69     _iter->drain(_cl);
  70   }
  71 
  72   virtual void do_oop(narrowOop* p) {
  73     ShouldNotReachHere();
  74   }
  75 };
  76 
  77 class ZHeapIteratorPushOopClosure : public BasicOopIterateClosure {
  78 private:
  79   ZHeapIterator* const _iter;
  80   const oop            _base;
  81 
  82 public:
  83   ZHeapIteratorPushOopClosure(ZHeapIterator* iter, oop base) :
  84       _iter(iter),
  85       _base(base) {}
  86 
  87   virtual void do_oop(oop* p) {
  88     const oop obj = HeapAccess<ON_UNKNOWN_OOP_REF>::oop_load_at(_base, _base->field_offset(p));
  89     _iter->push(obj);
  90   }
  91 








  92   virtual void do_oop(narrowOop* p) {
  93     ShouldNotReachHere();
  94   }
  95 
  96 #ifdef ASSERT
  97   virtual bool should_verify_oops() {
  98     return false;
  99   }
 100 #endif
 101 };
 102 
 103 ZHeapIterator::ZHeapIterator() :
 104     _visit_stack(),
 105     _visit_map() {}
 106 
 107 ZHeapIterator::~ZHeapIterator() {
 108   ZVisitMapIterator iter(&_visit_map);
 109   for (ZHeapIteratorBitMap* map; iter.next(&map);) {
 110     delete map;
 111   }
 112 }
 113 


< prev index next >