< prev index next >

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

Print this page

 47   return (from_offset - forwarding->start()) >> forwarding->object_alignment_shift();
 48 }
 49 
 50 static uintptr_t forwarding_find(ZForwarding* forwarding, uintptr_t from_addr, ZForwardingCursor* cursor) {
 51   const uintptr_t from_index = forwarding_index(forwarding, from_addr);
 52   const ZForwardingEntry entry = forwarding->find(from_index, cursor);
 53   return entry.populated() ? ZAddress::good(entry.to_offset()) : 0;
 54 }
 55 
 56 static uintptr_t forwarding_insert(ZForwarding* forwarding, uintptr_t from_addr, uintptr_t to_addr, ZForwardingCursor* cursor) {
 57   const uintptr_t from_index = forwarding_index(forwarding, from_addr);
 58   const uintptr_t to_offset = ZAddress::offset(to_addr);
 59   const uintptr_t to_offset_final = forwarding->insert(from_index, to_offset, cursor);
 60   return ZAddress::good(to_offset_final);
 61 }
 62 
 63 static uintptr_t relocate_object_inner(ZForwarding* forwarding, uintptr_t from_addr, ZForwardingCursor* cursor) {
 64   assert(ZHeap::heap()->is_object_live(from_addr), "Should be live");
 65 
 66   // Allocate object
 67   const size_t size = ZUtils::object_size(from_addr);
 68   const uintptr_t to_addr = ZHeap::heap()->alloc_object_for_relocation(size);
 69   if (to_addr == 0) {
 70     // Allocation failed
 71     return 0;
 72   }
 73 
 74   // Copy object
 75   ZUtils::object_copy_disjoint(from_addr, to_addr, size);
 76 
 77   // Insert forwarding
 78   const uintptr_t to_addr_final = forwarding_insert(forwarding, from_addr, to_addr, cursor);
 79   if (to_addr_final != to_addr) {
 80     // Already relocated, try undo allocation
 81     ZHeap::heap()->undo_alloc_object_for_relocation(to_addr, size);
 82   }
 83 
 84   return to_addr_final;
 85 }
 86 
 87 uintptr_t ZRelocate::relocate_object(ZForwarding* forwarding, uintptr_t from_addr) const {
 88   ZForwardingCursor cursor;
 89 
 90   // Lookup forwarding
 91   uintptr_t to_addr = forwarding_find(forwarding, from_addr, &cursor);
 92   if (to_addr != 0) {
 93     // Already relocated
 94     return to_addr;
 95   }

271   }
272 };
273 
274 template <typename Allocator>
275 class ZRelocateClosure : public ObjectClosure {
276 private:
277   Allocator* const _allocator;
278   ZForwarding*     _forwarding;
279   ZPage*           _target;
280 
281   bool relocate_object(uintptr_t from_addr) const {
282     ZForwardingCursor cursor;
283 
284     // Lookup forwarding
285     if (forwarding_find(_forwarding, from_addr, &cursor) != 0) {
286       // Already relocated
287       return true;
288     }
289 
290     // Allocate object
291     const size_t size = ZUtils::object_size(from_addr);
292     const uintptr_t to_addr = _allocator->alloc_object(_target, size);
293     if (to_addr == 0) {
294       // Allocation failed
295       return false;
296     }
297 
298     // Copy object. Use conjoint copying if we are relocating
299     // in-place and the new object overlapps with the old object.
300     if (_forwarding->in_place() && to_addr + size > from_addr) {
301       ZUtils::object_copy_conjoint(from_addr, to_addr, size);
302     } else {
303       ZUtils::object_copy_disjoint(from_addr, to_addr, size);
304     }
305 
306     // Insert forwarding
307     if (forwarding_insert(_forwarding, from_addr, to_addr, &cursor) != to_addr) {
308       // Already relocated, undo allocation
309       _allocator->undo_alloc_object(_target, to_addr, size);
310     }
311 
312     return true;
313   }
314 
315   virtual void do_object(oop obj) {
316     const uintptr_t addr = ZOop::to_address(obj);
317     assert(ZHeap::heap()->is_object_live(addr), "Should be live");
318 
319     while (!relocate_object(addr)) {
320       // Allocate a new target page, or if that fails, use the page being
321       // relocated as the new target, which will cause it to be relocated
322       // in-place.
323       _target = _allocator->alloc_target_page(_forwarding, _target);

 47   return (from_offset - forwarding->start()) >> forwarding->object_alignment_shift();
 48 }
 49 
 50 static uintptr_t forwarding_find(ZForwarding* forwarding, uintptr_t from_addr, ZForwardingCursor* cursor) {
 51   const uintptr_t from_index = forwarding_index(forwarding, from_addr);
 52   const ZForwardingEntry entry = forwarding->find(from_index, cursor);
 53   return entry.populated() ? ZAddress::good(entry.to_offset()) : 0;
 54 }
 55 
 56 static uintptr_t forwarding_insert(ZForwarding* forwarding, uintptr_t from_addr, uintptr_t to_addr, ZForwardingCursor* cursor) {
 57   const uintptr_t from_index = forwarding_index(forwarding, from_addr);
 58   const uintptr_t to_offset = ZAddress::offset(to_addr);
 59   const uintptr_t to_offset_final = forwarding->insert(from_index, to_offset, cursor);
 60   return ZAddress::good(to_offset_final);
 61 }
 62 
 63 static uintptr_t relocate_object_inner(ZForwarding* forwarding, uintptr_t from_addr, ZForwardingCursor* cursor) {
 64   assert(ZHeap::heap()->is_object_live(from_addr), "Should be live");
 65 
 66   // Allocate object
 67   const size_t size = ZUtils::object_compact_size(from_addr);
 68   const uintptr_t to_addr = ZHeap::heap()->alloc_object_for_relocation(size);
 69   if (to_addr == 0) {
 70     // Allocation failed
 71     return 0;
 72   }
 73 
 74   // Copy object
 75   ZUtils::object_copy_disjoint_compact(from_addr, to_addr, size);
 76 
 77   // Insert forwarding
 78   const uintptr_t to_addr_final = forwarding_insert(forwarding, from_addr, to_addr, cursor);
 79   if (to_addr_final != to_addr) {
 80     // Already relocated, try undo allocation
 81     ZHeap::heap()->undo_alloc_object_for_relocation(to_addr, size);
 82   }
 83 
 84   return to_addr_final;
 85 }
 86 
 87 uintptr_t ZRelocate::relocate_object(ZForwarding* forwarding, uintptr_t from_addr) const {
 88   ZForwardingCursor cursor;
 89 
 90   // Lookup forwarding
 91   uintptr_t to_addr = forwarding_find(forwarding, from_addr, &cursor);
 92   if (to_addr != 0) {
 93     // Already relocated
 94     return to_addr;
 95   }

271   }
272 };
273 
274 template <typename Allocator>
275 class ZRelocateClosure : public ObjectClosure {
276 private:
277   Allocator* const _allocator;
278   ZForwarding*     _forwarding;
279   ZPage*           _target;
280 
281   bool relocate_object(uintptr_t from_addr) const {
282     ZForwardingCursor cursor;
283 
284     // Lookup forwarding
285     if (forwarding_find(_forwarding, from_addr, &cursor) != 0) {
286       // Already relocated
287       return true;
288     }
289 
290     // Allocate object
291     const size_t size = ZUtils::object_compact_size(from_addr);
292     const uintptr_t to_addr = _allocator->alloc_object(_target, size);
293     if (to_addr == 0) {
294       // Allocation failed
295       return false;
296     }
297 
298     // Copy object. Use conjoint copying if we are relocating
299     // in-place and the new object overlapps with the old object.
300     if (_forwarding->in_place() && to_addr + size > from_addr) {
301       ZUtils::object_copy_conjoint_compact(from_addr, to_addr, size);
302     } else {
303       ZUtils::object_copy_disjoint_compact(from_addr, to_addr, size);
304     }
305 
306     // Insert forwarding
307     if (forwarding_insert(_forwarding, from_addr, to_addr, &cursor) != to_addr) {
308       // Already relocated, undo allocation
309       _allocator->undo_alloc_object(_target, to_addr, size);
310     }
311 
312     return true;
313   }
314 
315   virtual void do_object(oop obj) {
316     const uintptr_t addr = ZOop::to_address(obj);
317     assert(ZHeap::heap()->is_object_live(addr), "Should be live");
318 
319     while (!relocate_object(addr)) {
320       // Allocate a new target page, or if that fails, use the page being
321       // relocated as the new target, which will cause it to be relocated
322       // in-place.
323       _target = _allocator->alloc_target_page(_forwarding, _target);
< prev index next >