< prev index next >

src/hotspot/share/gc/shenandoah/shenandoahBarrierSet.inline.hpp

Print this page




   4  * This code is free software; you can redistribute it and/or modify it
   5  * under the terms of the GNU General Public License version 2 only, as
   6  * published by the Free Software Foundation.
   7  *
   8  * This code is distributed in the hope that it will be useful, but WITHOUT
   9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  11  * version 2 for more details (a copy is included in the LICENSE file that
  12  * accompanied this code).
  13  *
  14  * You should have received a copy of the GNU General Public License version
  15  * 2 along with this work; if not, write to the Free Software Foundation,
  16  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  17  *
  18  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  19  * or visit www.oracle.com if you need additional information or have any
  20  * questions.
  21  *
  22  */
  23 
  24 #ifndef SHARE_VM_GC_SHENANDOAH_SHENANDOAHBARRIERSET_INLINE_HPP
  25 #define SHARE_VM_GC_SHENANDOAH_SHENANDOAHBARRIERSET_INLINE_HPP
  26 
  27 #include "gc/shared/barrierSet.hpp"
  28 #include "gc/shenandoah/shenandoahBarrierSet.hpp"
  29 #include "gc/shenandoah/shenandoahBrooksPointer.inline.hpp"
  30 #include "gc/shenandoah/shenandoahHeap.inline.hpp"
  31 
  32 bool ShenandoahBarrierSet::need_update_refs_barrier() {
  33   return _heap->is_update_refs_in_progress() ||
  34          _heap->is_concurrent_traversal_in_progress() ||
  35          (_heap->is_concurrent_mark_in_progress() && _heap->has_forwarded_objects());
  36 }
  37 
  38 inline oop ShenandoahBarrierSet::resolve_forwarded_not_null(oop p) {
  39   return ShenandoahBrooksPointer::forwardee(p);
  40 }
  41 
  42 inline oop ShenandoahBarrierSet::resolve_forwarded(oop p) {
  43   if (((HeapWord*) p) != NULL) {
  44     return resolve_forwarded_not_null(p);
  45   } else {
  46     return p;
  47   }
  48 }
  49 
  50 template <DecoratorSet decorators, typename BarrierSetT>
  51 template <typename T>
  52 inline oop ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_atomic_cmpxchg_in_heap(oop new_value, T* addr, oop compare_value) {










































  53   oop res;
  54   oop expected = compare_value;
  55   do {
  56     compare_value = expected;
  57     res = Raw::oop_atomic_cmpxchg(new_value, addr, compare_value);
  58     expected = res;
  59   } while ((! oopDesc::equals_raw(compare_value, expected)) && oopDesc::equals_raw(resolve_forwarded(compare_value), resolve_forwarded(expected)));
  60   if (oopDesc::equals_raw(expected, compare_value)) {
  61     if (ShenandoahSATBBarrier && !CompressedOops::is_null(compare_value)) {
  62       ShenandoahBarrierSet::barrier_set()->enqueue(compare_value);
  63     }
  64   }
  65   return res;
  66 }
  67 
  68 template <DecoratorSet decorators, typename BarrierSetT>
  69 template <typename T>
  70 inline oop ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_atomic_xchg_in_heap(oop new_value, T* addr) {
  71   oop previous = Raw::oop_atomic_xchg(new_value, addr);
  72   if (ShenandoahSATBBarrier) {
  73     if (!CompressedOops::is_null(previous)) {
  74       ShenandoahBarrierSet::barrier_set()->enqueue(previous);
  75     }

  76   }
  77   return previous;
  78 }
  79 
  80 template <DecoratorSet decorators, typename BarrierSetT>
  81 template <typename T>
  82 void ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::arraycopy_in_heap(arrayOop src_obj, size_t src_offset_in_bytes, T* src_raw,
  83                                                                                      arrayOop dst_obj, size_t dst_offset_in_bytes, T* dst_raw,
  84                                                                                      size_t length) {
  85   if (!CompressedOops::is_null(src_obj)) {
  86     src_obj = arrayOop(ShenandoahBarrierSet::barrier_set()->read_barrier(src_obj));
















  87   }
  88   if (!CompressedOops::is_null(dst_obj)) {
  89     dst_obj = arrayOop(ShenandoahBarrierSet::barrier_set()->write_barrier(dst_obj));








  90   }
  91   Raw::arraycopy(src_obj, src_offset_in_bytes, src_raw, dst_obj, dst_offset_in_bytes, dst_raw, length);















  92 }
  93 
  94 template <typename T>
  95 bool ShenandoahBarrierSet::arraycopy_loop_1(T* src, T* dst, size_t length, Klass* bound,
  96                                             bool checkcast, bool satb, bool disjoint,
  97                                             ShenandoahBarrierSet::ArrayCopyStoreValMode storeval_mode) {
  98   if (checkcast) {
  99     return arraycopy_loop_2<T, true>(src, dst, length, bound, satb, disjoint, storeval_mode);
 100   } else {
 101     return arraycopy_loop_2<T, false>(src, dst, length, bound, satb, disjoint, storeval_mode);
 102   }
 103 }
 104 
 105 template <typename T, bool CHECKCAST>
 106 bool ShenandoahBarrierSet::arraycopy_loop_2(T* src, T* dst, size_t length, Klass* bound,
 107                                             bool satb, bool disjoint,
 108                                             ShenandoahBarrierSet::ArrayCopyStoreValMode storeval_mode) {
 109   if (satb) {
 110     return arraycopy_loop_3<T, CHECKCAST, true>(src, dst, length, bound, disjoint, storeval_mode);
 111   } else {


 212         }
 213         obj = forw;
 214       }
 215       enqueue(obj);
 216       break;
 217     default:
 218       ShouldNotReachHere();
 219     }
 220 
 221     RawAccess<IS_NOT_NULL>::oop_store(cur_dst, obj);
 222   } else {
 223     // Store null.
 224     RawAccess<>::oop_store(cur_dst, o);
 225   }
 226   return true;
 227 }
 228 
 229 // Clone barrier support
 230 template <DecoratorSet decorators, typename BarrierSetT>
 231 void ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::clone_in_heap(oop src, oop dst, size_t size) {
 232   src = arrayOop(ShenandoahBarrierSet::barrier_set()->read_barrier(src));
 233   dst = arrayOop(ShenandoahBarrierSet::barrier_set()->write_barrier(dst));
 234   Raw::clone(src, dst, size);
 235   ShenandoahBarrierSet::barrier_set()->write_region(MemRegion((HeapWord*) dst, size));
 236 }
 237 
 238 template <DecoratorSet decorators, typename BarrierSetT>
 239 template <typename T>
 240 bool ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_arraycopy_in_heap(arrayOop src_obj, size_t src_offset_in_bytes, T* src_raw,
 241                                                                                          arrayOop dst_obj, size_t dst_offset_in_bytes, T* dst_raw,
 242                                                                                          size_t length) {
 243   ShenandoahHeap* heap = ShenandoahHeap::heap();
 244   if (!CompressedOops::is_null(src_obj)) {
 245     src_obj = arrayOop(ShenandoahBarrierSet::barrier_set()->read_barrier(src_obj));
 246   }
 247   if (!CompressedOops::is_null(dst_obj)) {
 248     dst_obj = arrayOop(ShenandoahBarrierSet::barrier_set()->write_barrier(dst_obj));
 249   }
 250 
 251   bool satb = ShenandoahSATBBarrier && heap->is_concurrent_mark_in_progress();
 252   bool checkcast = HasDecorator<decorators, ARRAYCOPY_CHECKCAST>::value;
 253   bool disjoint = HasDecorator<decorators, ARRAYCOPY_DISJOINT>::value;
 254   ArrayCopyStoreValMode storeval_mode;
 255   if (heap->has_forwarded_objects()) {
 256     if (heap->is_concurrent_traversal_in_progress()) {
 257       storeval_mode = WRITE_BARRIER;
 258     } else if (heap->is_concurrent_mark_in_progress() || heap->is_update_refs_in_progress()) {
 259       storeval_mode = READ_BARRIER;
 260     } else {
 261       assert(heap->is_idle() || heap->is_evacuation_in_progress(), "must not have anything in progress");
 262       storeval_mode = NONE; // E.g. during evac or outside cycle
 263     }
 264   } else {
 265     assert(heap->is_stable() || heap->is_concurrent_mark_in_progress(), "must not have anything in progress");
 266     storeval_mode = NONE;
 267   }
 268 
 269   if (!satb && !checkcast && storeval_mode == NONE) {
 270     // Short-circuit to bulk copy.
 271     return Raw::oop_arraycopy(src_obj, src_offset_in_bytes, src_raw, dst_obj, dst_offset_in_bytes, dst_raw, length);
 272   }
 273 
 274   src_raw = arrayOopDesc::obj_offset_to_raw(src_obj, src_offset_in_bytes, src_raw);
 275   dst_raw = arrayOopDesc::obj_offset_to_raw(dst_obj, dst_offset_in_bytes, dst_raw);
 276 
 277   Klass* bound = objArrayOop(dst_obj)->element_klass();
 278   ShenandoahBarrierSet* bs = ShenandoahBarrierSet::barrier_set();
 279   return bs->arraycopy_loop_1(src_raw, dst_raw, length, bound, checkcast, satb, disjoint, storeval_mode);
 280 }
 281 
 282 #endif //SHARE_VM_GC_SHENANDOAH_SHENANDOAHBARRIERSET_INLINE_HPP


   4  * This code is free software; you can redistribute it and/or modify it
   5  * under the terms of the GNU General Public License version 2 only, as
   6  * published by the Free Software Foundation.
   7  *
   8  * This code is distributed in the hope that it will be useful, but WITHOUT
   9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  11  * version 2 for more details (a copy is included in the LICENSE file that
  12  * accompanied this code).
  13  *
  14  * You should have received a copy of the GNU General Public License version
  15  * 2 along with this work; if not, write to the Free Software Foundation,
  16  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  17  *
  18  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  19  * or visit www.oracle.com if you need additional information or have any
  20  * questions.
  21  *
  22  */
  23 
  24 #ifndef SHARE_GC_SHENANDOAH_SHENANDOAHBARRIERSET_INLINE_HPP
  25 #define SHARE_GC_SHENANDOAH_SHENANDOAHBARRIERSET_INLINE_HPP
  26 
  27 #include "gc/shared/barrierSet.hpp"
  28 #include "gc/shenandoah/shenandoahBarrierSet.hpp"
  29 #include "gc/shenandoah/shenandoahBrooksPointer.inline.hpp"
  30 #include "gc/shenandoah/shenandoahHeap.inline.hpp"
  31 
  32 bool ShenandoahBarrierSet::need_update_refs_barrier() {
  33   return _heap->is_update_refs_in_progress() ||
  34          _heap->is_concurrent_traversal_in_progress() ||
  35          (_heap->is_concurrent_mark_in_progress() && _heap->has_forwarded_objects());
  36 }
  37 
  38 inline oop ShenandoahBarrierSet::resolve_forwarded_not_null(oop p) {
  39   return ShenandoahBrooksPointer::forwardee(p);
  40 }
  41 
  42 inline oop ShenandoahBarrierSet::resolve_forwarded(oop p) {
  43   if (((HeapWord*) p) != NULL) {
  44     return resolve_forwarded_not_null(p);
  45   } else {
  46     return p;
  47   }
  48 }
  49 
  50 template <DecoratorSet decorators, typename BarrierSetT>
  51 template <typename T>
  52 inline oop ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_load_in_heap(T* addr) {
  53   oop value = Raw::oop_load_in_heap(addr);
  54   value = ShenandoahBarrierSet::barrier_set()->load_reference_barrier(value);
  55   keep_alive_if_weak(decorators, value);
  56   return value;
  57 }
  58 
  59 template <DecoratorSet decorators, typename BarrierSetT>
  60 inline oop ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_load_in_heap_at(oop base, ptrdiff_t offset) {
  61   oop value = Raw::oop_load_in_heap_at(base, offset);
  62   value = ShenandoahBarrierSet::barrier_set()->load_reference_barrier(value);
  63   keep_alive_if_weak(AccessBarrierSupport::resolve_possibly_unknown_oop_ref_strength<decorators>(base, offset), value);
  64   return value;
  65 }
  66 
  67 template <DecoratorSet decorators, typename BarrierSetT>
  68 template <typename T>
  69 inline oop ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_load_not_in_heap(T* addr) {
  70   oop value = Raw::oop_load_not_in_heap(addr);
  71   value = ShenandoahBarrierSet::barrier_set()->load_reference_barrier(value);
  72   keep_alive_if_weak(decorators, value);
  73   return value;
  74 }
  75 
  76 template <DecoratorSet decorators, typename BarrierSetT>
  77 template <typename T>
  78 inline void ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_store_in_heap(T* addr, oop value) {
  79   ShenandoahBarrierSet::barrier_set()->storeval_barrier(value);
  80   const bool keep_alive = (decorators & AS_NO_KEEPALIVE) == 0;
  81   if (keep_alive) {
  82     ShenandoahBarrierSet::barrier_set()->write_ref_field_pre_work(addr, value);
  83   }
  84   Raw::oop_store_in_heap(addr, value);
  85 }
  86 
  87 template <DecoratorSet decorators, typename BarrierSetT>
  88 inline void ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_store_in_heap_at(oop base, ptrdiff_t offset, oop value) {
  89   oop_store_in_heap(AccessInternal::oop_field_addr<decorators>(base, offset), value);
  90 }
  91 
  92 template <DecoratorSet decorators, typename BarrierSetT>
  93 template <typename T>
  94 inline oop ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_atomic_cmpxchg_not_in_heap(oop new_value, T* addr, oop compare_value) {
  95   oop res;
  96   oop expected = compare_value;
  97   do {
  98     compare_value = expected;
  99     res = Raw::oop_atomic_cmpxchg(new_value, addr, compare_value);
 100     expected = res;
 101   } while ((! oopDesc::equals_raw(compare_value, expected)) && oopDesc::equals_raw(resolve_forwarded(compare_value), resolve_forwarded(expected)));
 102   if (res != NULL) {
 103     return ShenandoahBarrierSet::barrier_set()->load_reference_barrier_not_null(res);
 104   } else {
 105     return res;
 106   }

 107 }
 108 
 109 template <DecoratorSet decorators, typename BarrierSetT>
 110 template <typename T>
 111 inline oop ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_atomic_cmpxchg_in_heap_impl(oop new_value, T* addr, oop compare_value) {
 112   ShenandoahBarrierSet::barrier_set()->storeval_barrier(new_value);
 113   oop result = oop_atomic_cmpxchg_not_in_heap(new_value, addr, compare_value);
 114   const bool keep_alive = (decorators & AS_NO_KEEPALIVE) == 0;
 115   if (keep_alive && ShenandoahSATBBarrier && !CompressedOops::is_null(result) &&
 116       oopDesc::equals_raw(result, compare_value)) {
 117     ShenandoahBarrierSet::barrier_set()->enqueue(result);
 118   }
 119   return result;
 120 }
 121 
 122 template <DecoratorSet decorators, typename BarrierSetT>
 123 template <typename T>
 124 inline oop ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_atomic_cmpxchg_in_heap(oop new_value, T* addr, oop compare_value) {
 125   oop result = oop_atomic_cmpxchg_in_heap_impl(new_value, addr, compare_value);
 126   keep_alive_if_weak(decorators, result);
 127   return result;
 128 }
 129 
 130 template <DecoratorSet decorators, typename BarrierSetT>
 131 inline oop ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_atomic_cmpxchg_in_heap_at(oop new_value, oop base, ptrdiff_t offset, oop compare_value) {
 132   oop result = oop_atomic_cmpxchg_in_heap_impl(new_value, AccessInternal::oop_field_addr<decorators>(base, offset), compare_value);
 133   keep_alive_if_weak(AccessBarrierSupport::resolve_possibly_unknown_oop_ref_strength<decorators>(base, offset), result);
 134   return result;
 135 }
 136 
 137 template <DecoratorSet decorators, typename BarrierSetT>
 138 template <typename T>
 139 inline oop ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_atomic_xchg_not_in_heap(oop new_value, T* addr) {
 140   oop previous = Raw::oop_atomic_xchg(new_value, addr);
 141   if (previous != NULL) {
 142     return ShenandoahBarrierSet::barrier_set()->load_reference_barrier_not_null(previous);
 143   } else {
 144     return previous;
 145   }
 146 }
 147 
 148 template <DecoratorSet decorators, typename BarrierSetT>
 149 template <typename T>
 150 inline oop ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_atomic_xchg_in_heap_impl(oop new_value, T* addr) {
 151   ShenandoahBarrierSet::barrier_set()->storeval_barrier(new_value);
 152   oop result = oop_atomic_xchg_not_in_heap(new_value, addr);
 153   const bool keep_alive = (decorators & AS_NO_KEEPALIVE) == 0;
 154   if (keep_alive && ShenandoahSATBBarrier && !CompressedOops::is_null(result)) {
 155     ShenandoahBarrierSet::barrier_set()->enqueue(result);
 156   }
 157   return result;
 158 }
 159 
 160 template <DecoratorSet decorators, typename BarrierSetT>
 161 template <typename T>
 162 inline oop ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_atomic_xchg_in_heap(oop new_value, T* addr) {
 163   oop result = oop_atomic_xchg_in_heap_impl(new_value, addr);
 164   keep_alive_if_weak(addr, result);
 165   return result;
 166 }
 167 
 168 template <DecoratorSet decorators, typename BarrierSetT>
 169 inline oop ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_atomic_xchg_in_heap_at(oop new_value, oop base, ptrdiff_t offset) {
 170   oop result = oop_atomic_xchg_in_heap_impl(new_value, AccessInternal::oop_field_addr<decorators>(base, offset));
 171   keep_alive_if_weak(AccessBarrierSupport::resolve_possibly_unknown_oop_ref_strength<decorators>(base, offset), result);
 172   return result;
 173 }
 174 
 175 template <typename T>
 176 bool ShenandoahBarrierSet::arraycopy_loop_1(T* src, T* dst, size_t length, Klass* bound,
 177                                             bool checkcast, bool satb, bool disjoint,
 178                                             ShenandoahBarrierSet::ArrayCopyStoreValMode storeval_mode) {
 179   if (checkcast) {
 180     return arraycopy_loop_2<T, true>(src, dst, length, bound, satb, disjoint, storeval_mode);
 181   } else {
 182     return arraycopy_loop_2<T, false>(src, dst, length, bound, satb, disjoint, storeval_mode);
 183   }
 184 }
 185 
 186 template <typename T, bool CHECKCAST>
 187 bool ShenandoahBarrierSet::arraycopy_loop_2(T* src, T* dst, size_t length, Klass* bound,
 188                                             bool satb, bool disjoint,
 189                                             ShenandoahBarrierSet::ArrayCopyStoreValMode storeval_mode) {
 190   if (satb) {
 191     return arraycopy_loop_3<T, CHECKCAST, true>(src, dst, length, bound, disjoint, storeval_mode);
 192   } else {


 293         }
 294         obj = forw;
 295       }
 296       enqueue(obj);
 297       break;
 298     default:
 299       ShouldNotReachHere();
 300     }
 301 
 302     RawAccess<IS_NOT_NULL>::oop_store(cur_dst, obj);
 303   } else {
 304     // Store null.
 305     RawAccess<>::oop_store(cur_dst, o);
 306   }
 307   return true;
 308 }
 309 
 310 // Clone barrier support
 311 template <DecoratorSet decorators, typename BarrierSetT>
 312 void ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::clone_in_heap(oop src, oop dst, size_t size) {


 313   Raw::clone(src, dst, size);
 314   ShenandoahBarrierSet::barrier_set()->write_region(MemRegion((HeapWord*) dst, size));
 315 }
 316 
 317 template <DecoratorSet decorators, typename BarrierSetT>
 318 template <typename T>
 319 bool ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_arraycopy_in_heap(arrayOop src_obj, size_t src_offset_in_bytes, T* src_raw,
 320                                                                                          arrayOop dst_obj, size_t dst_offset_in_bytes, T* dst_raw,
 321                                                                                          size_t length) {
 322   ShenandoahHeap* heap = ShenandoahHeap::heap();







 323   bool satb = ShenandoahSATBBarrier && heap->is_concurrent_mark_in_progress();
 324   bool checkcast = HasDecorator<decorators, ARRAYCOPY_CHECKCAST>::value;
 325   bool disjoint = HasDecorator<decorators, ARRAYCOPY_DISJOINT>::value;
 326   ArrayCopyStoreValMode storeval_mode;
 327   if (heap->has_forwarded_objects()) {
 328     if (heap->is_concurrent_traversal_in_progress()) {
 329       storeval_mode = WRITE_BARRIER;
 330     } else if (heap->is_concurrent_mark_in_progress() || heap->is_update_refs_in_progress()) {
 331       storeval_mode = READ_BARRIER;
 332     } else {
 333       assert(heap->is_idle() || heap->is_evacuation_in_progress(), "must not have anything in progress");
 334       storeval_mode = NONE; // E.g. during evac or outside cycle
 335     }
 336   } else {
 337     assert(heap->is_stable() || heap->is_concurrent_mark_in_progress(), "must not have anything in progress");
 338     storeval_mode = NONE;
 339   }
 340 
 341   if (!satb && !checkcast && storeval_mode == NONE) {
 342     // Short-circuit to bulk copy.
 343     return Raw::oop_arraycopy(src_obj, src_offset_in_bytes, src_raw, dst_obj, dst_offset_in_bytes, dst_raw, length);
 344   }
 345 
 346   src_raw = arrayOopDesc::obj_offset_to_raw(src_obj, src_offset_in_bytes, src_raw);
 347   dst_raw = arrayOopDesc::obj_offset_to_raw(dst_obj, dst_offset_in_bytes, dst_raw);
 348 
 349   Klass* bound = objArrayOop(dst_obj)->element_klass();
 350   ShenandoahBarrierSet* bs = ShenandoahBarrierSet::barrier_set();
 351   return bs->arraycopy_loop_1(src_raw, dst_raw, length, bound, checkcast, satb, disjoint, storeval_mode);
 352 }
 353 
 354 #endif // SHARE_GC_SHENANDOAH_SHENANDOAHBARRIERSET_INLINE_HPP
< prev index next >