< prev index next >

src/hotspot/share/gc/z/zBarrierSet.inline.hpp

Print this page

  7  * published by the Free Software Foundation.
  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 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 #ifndef SHARE_GC_Z_ZBARRIERSET_INLINE_HPP
 25 #define SHARE_GC_Z_ZBARRIERSET_INLINE_HPP
 26 

 27 #include "gc/z/zBarrierSet.hpp"
 28 
 29 #include "gc/shared/accessBarrierSupport.inline.hpp"
 30 #include "gc/z/zAddress.inline.hpp"
 31 #include "gc/z/zBarrier.inline.hpp"
 32 #include "gc/z/zIterator.inline.hpp"
 33 #include "gc/z/zNMethod.hpp"
 34 #include "memory/iterator.inline.hpp"

 35 #include "utilities/debug.hpp"
 36 
 37 template <DecoratorSet decorators, typename BarrierSetT>
 38 template <DecoratorSet expected>
 39 inline void ZBarrierSet::AccessBarrier<decorators, BarrierSetT>::verify_decorators_present() {
 40   if ((decorators & expected) == 0) {
 41     fatal("Using unsupported access decorators");
 42   }
 43 }
 44 
 45 template <DecoratorSet decorators, typename BarrierSetT>
 46 template <DecoratorSet expected>
 47 inline void ZBarrierSet::AccessBarrier<decorators, BarrierSetT>::verify_decorators_absent() {
 48   if ((decorators & expected) != 0) {
 49     fatal("Using unsupported access decorators");
 50   }
 51 }
 52 
 53 template <DecoratorSet decorators, typename BarrierSetT>
 54 inline void ZBarrierSet::AccessBarrier<decorators, BarrierSetT>::unsupported() {

312   verify_decorators_absent<AS_NO_KEEPALIVE>();
313 
314   zpointer* const p = field_addr(base, offset);
315 
316   store_barrier_heap_with_healing(p);
317 
318   const zpointer o = Raw::atomic_xchg_in_heap(p, store_good(new_value));
319   assert_is_valid(o);
320 
321   return to_oop(ZPointer::uncolor_store_good(o));
322 }
323 
324 template <DecoratorSet decorators, typename BarrierSetT>
325 inline zaddress ZBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_copy_one_barriers(zpointer* dst, zpointer* src) {
326   store_barrier_heap_without_healing(dst);
327 
328   return ZBarrier::load_barrier_on_oop_field(src);
329 }
330 
331 template <DecoratorSet decorators, typename BarrierSetT>
332 inline void ZBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_copy_one(zpointer* dst, zpointer* src) {
333   const zaddress obj = oop_copy_one_barriers(dst, src);
334 




335   Atomic::store(dst, ZAddress::store_good(obj));

336 }
337 
338 template <DecoratorSet decorators, typename BarrierSetT>
339 inline bool ZBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_copy_one_check_cast(zpointer* dst, zpointer* src, Klass* dst_klass) {
340   const zaddress obj = oop_copy_one_barriers(dst, src);

341 
342   if (!oopDesc::is_instanceof_or_null(to_oop(obj), dst_klass)) {



343     // Check cast failed
344     return false;
345   }
346 
347   Atomic::store(dst, ZAddress::store_good(obj));
348 
349   return true;
350 }
351 
352 
353 template <DecoratorSet decorators, typename BarrierSetT>
354 inline bool ZBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_arraycopy_in_heap_check_cast(zpointer* dst, zpointer* src, size_t length, Klass* dst_klass) {
355   // Check cast and copy each elements
356   for (const zpointer* const end = src + length; src < end; src++, dst++) {
357     if (!oop_copy_one_check_cast(dst, src, dst_klass)) {
358       // Check cast failed
359       return false;
360     }
361   }
362 
363   return true;
364 }
365 
366 template <DecoratorSet decorators, typename BarrierSetT>
367 inline bool ZBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_arraycopy_in_heap_no_check_cast(zpointer* dst, zpointer* src, size_t length) {
368   const bool is_disjoint = HasDecorator<decorators, ARRAYCOPY_DISJOINT>::value;
369 
370   if (is_disjoint || src > dst) {
371     for (const zpointer* const end = src + length; src < end; src++, dst++) {
372       oop_copy_one(dst, src);
373     }
374     return true;
375   }
376 
377   if (src < dst) {
378     const zpointer* const end = src;
379     src += length - 1;
380     dst += length - 1;
381     for ( ; src >= end; src--, dst--) {
382       oop_copy_one(dst, src);
383     }
384     return true;
385   }
386 
387   // src and dst are the same; nothing to do
388   return true;
389 }
390 
391 template <DecoratorSet decorators, typename BarrierSetT>
392 inline bool ZBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_arraycopy_in_heap(arrayOop src_obj, size_t src_offset_in_bytes, zpointer* src_raw,
393                                                                                        arrayOop dst_obj, size_t dst_offset_in_bytes, zpointer* dst_raw,
394                                                                                        size_t length) {
395   zpointer* const src = arrayOopDesc::obj_offset_to_raw(src_obj, src_offset_in_bytes, src_raw);
396   zpointer* const dst = arrayOopDesc::obj_offset_to_raw(dst_obj, dst_offset_in_bytes, dst_raw);

397 
398   if (HasDecorator<decorators, ARRAYCOPY_CHECKCAST>::value) {
399     Klass* const dst_klass = objArrayOop(dst_obj)->element_klass();
400     return oop_arraycopy_in_heap_check_cast(dst, src, length, dst_klass);


401   }
402 
403   return oop_arraycopy_in_heap_no_check_cast(dst, src, length);












404 }
405 
406 class ZColorStoreGoodOopClosure : public BasicOopIterateClosure {
407 public:
408   virtual void do_oop(oop* p_) {
409     volatile zpointer* const p = (volatile zpointer*)p_;
410     const zpointer ptr = ZBarrier::load_atomic(p);
411     const zaddress addr = ZPointer::uncolor(ptr);
412     Atomic::store(p, ZAddress::store_good(addr));
413   }
414 
415   virtual void do_oop(narrowOop* p) {
416     ShouldNotReachHere();
417   }
418 };
419 
420 class ZLoadBarrierOopClosure : public BasicOopIterateClosure {
421 public:
422   virtual void do_oop(oop* p) {
423     ZBarrier::load_barrier_on_oop_field((zpointer*)p);

440     // and arraycopy sequence, so the performance of this runtime call
441     // does not matter for object arrays.
442     clone_obj_array(objArrayOop(src), objArrayOop(dst));
443     return;
444   }
445 
446   // Fix the oops
447   ZLoadBarrierOopClosure cl;
448   ZIterator::oop_iterate(src, &cl);
449 
450   // Clone the object
451   Raw::clone_in_heap(src, dst, size);
452 
453   assert(dst->is_typeArray() || ZHeap::heap()->is_young(to_zaddress(dst)), "ZColorStoreGoodOopClosure is only valid for young objects");
454 
455   // Color store good before handing out
456   ZColorStoreGoodOopClosure cl_sg;
457   ZIterator::oop_iterate(dst, &cl_sg);
458 }
459 

















































460 //
461 // Not in heap
462 //
463 template <DecoratorSet decorators, typename BarrierSetT>
464 inline oop ZBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_load_not_in_heap(zpointer* p) {
465   verify_decorators_absent<ON_UNKNOWN_OOP_REF>();
466 
467   const zpointer o = Raw::template load<zpointer>(p);
468   assert_is_valid(o);
469   return to_oop(load_barrier(p, o));
470 }
471 
472 template <DecoratorSet decorators, typename BarrierSetT>
473 inline oop ZBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_load_not_in_heap(oop* p) {
474   verify_decorators_absent<ON_UNKNOWN_OOP_REF>();
475 
476   if (HasDecorator<decorators, IN_NMETHOD>::value) {
477     return ZNMethod::load_oop(p, decorators);
478   } else {
479     return oop_load_not_in_heap((zpointer*)p);

  7  * published by the Free Software Foundation.
  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 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 #ifndef SHARE_GC_Z_ZBARRIERSET_INLINE_HPP
 25 #define SHARE_GC_Z_ZBARRIERSET_INLINE_HPP
 26 
 27 #include "gc/z/zAddress.hpp"
 28 #include "gc/z/zBarrierSet.hpp"
 29 
 30 #include "gc/shared/accessBarrierSupport.inline.hpp"
 31 #include "gc/z/zAddress.inline.hpp"
 32 #include "gc/z/zBarrier.inline.hpp"
 33 #include "gc/z/zIterator.inline.hpp"
 34 #include "gc/z/zNMethod.hpp"
 35 #include "memory/iterator.inline.hpp"
 36 #include "oops/inlineKlass.inline.hpp"
 37 #include "utilities/debug.hpp"
 38 
 39 template <DecoratorSet decorators, typename BarrierSetT>
 40 template <DecoratorSet expected>
 41 inline void ZBarrierSet::AccessBarrier<decorators, BarrierSetT>::verify_decorators_present() {
 42   if ((decorators & expected) == 0) {
 43     fatal("Using unsupported access decorators");
 44   }
 45 }
 46 
 47 template <DecoratorSet decorators, typename BarrierSetT>
 48 template <DecoratorSet expected>
 49 inline void ZBarrierSet::AccessBarrier<decorators, BarrierSetT>::verify_decorators_absent() {
 50   if ((decorators & expected) != 0) {
 51     fatal("Using unsupported access decorators");
 52   }
 53 }
 54 
 55 template <DecoratorSet decorators, typename BarrierSetT>
 56 inline void ZBarrierSet::AccessBarrier<decorators, BarrierSetT>::unsupported() {

314   verify_decorators_absent<AS_NO_KEEPALIVE>();
315 
316   zpointer* const p = field_addr(base, offset);
317 
318   store_barrier_heap_with_healing(p);
319 
320   const zpointer o = Raw::atomic_xchg_in_heap(p, store_good(new_value));
321   assert_is_valid(o);
322 
323   return to_oop(ZPointer::uncolor_store_good(o));
324 }
325 
326 template <DecoratorSet decorators, typename BarrierSetT>
327 inline zaddress ZBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_copy_one_barriers(zpointer* dst, zpointer* src) {
328   store_barrier_heap_without_healing(dst);
329 
330   return ZBarrier::load_barrier_on_oop_field(src);
331 }
332 
333 template <DecoratorSet decorators, typename BarrierSetT>
334 inline ZBarrierSet::OopCopyCheckStatus ZBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_copy_one(zpointer* dst, zpointer* src) {
335   const zaddress obj = oop_copy_one_barriers(dst, src);
336 
337   if (HasDecorator<decorators, ARRAYCOPY_NOTNULL>::value && is_null(obj)) {
338     return oop_copy_check_null;
339   }
340 
341   Atomic::store(dst, ZAddress::store_good(obj));
342   return oop_copy_check_ok;
343 }
344 
345 template <DecoratorSet decorators, typename BarrierSetT>
346 inline ZBarrierSet::OopCopyCheckStatus ZBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_copy_one_check_cast(zpointer* dst, zpointer* src, Klass* dst_klass) {
347   const zaddress obj = oop_copy_one_barriers(dst, src);
348   const bool null_check = HasDecorator<decorators, ARRAYCOPY_NOTNULL>::value;
349 
350   if (null_check && is_null(obj)) {
351     return oop_copy_check_null;
352   }
353   else if (!oopDesc::is_instanceof_or_null(to_oop(obj), dst_klass)) {
354     // Check cast failed
355     return oop_copy_check_class_cast;
356   }
357 
358   Atomic::store(dst, ZAddress::store_good(obj));
359 
360   return oop_copy_check_ok;
361 }
362 
363 
364 template <DecoratorSet decorators, typename BarrierSetT>
365 inline ZBarrierSet::OopCopyCheckStatus ZBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_arraycopy_in_heap_check_cast(zpointer* dst, zpointer* src, size_t length, Klass* dst_klass) {
366   // Check cast and copy each elements
367   OopCopyCheckStatus check_status = oop_copy_check_ok;
368   for (const zpointer* const end = src + length; (check_status == oop_copy_check_ok) && (src < end); src++, dst++) {
369     check_status = oop_copy_one_check_cast(dst, src, dst_klass);


370   }
371   return check_status;

372 }
373 
374 template <DecoratorSet decorators, typename BarrierSetT>
375 inline ZBarrierSet::OopCopyCheckStatus ZBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_arraycopy_in_heap_no_check_cast(zpointer* dst, zpointer* src, size_t length) {
376   const bool is_disjoint = HasDecorator<decorators, ARRAYCOPY_DISJOINT>::value;
377   OopCopyCheckStatus check_status = oop_copy_check_ok;
378   if (is_disjoint || src > dst) {
379     for (const zpointer* const end = src + length; (check_status == oop_copy_check_ok) && (src < end); src++, dst++) {
380       check_status = oop_copy_one(dst, src);
381     }
382     return check_status;
383   }
384 
385   if (src < dst) {
386     const zpointer* const end = src;
387     src += length - 1;
388     dst += length - 1;
389     for ( ; (check_status == oop_copy_check_ok) && (src >= end); src--, dst--) {
390       check_status = oop_copy_one(dst, src);
391     }
392     return check_status;
393   }
394 
395   // src and dst are the same; nothing to do
396   return check_status;
397 }
398 
399 template <DecoratorSet decorators, typename BarrierSetT>
400 inline void ZBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_arraycopy_in_heap(arrayOop src_obj, size_t src_offset_in_bytes, zpointer* src_raw,
401                                                                                        arrayOop dst_obj, size_t dst_offset_in_bytes, zpointer* dst_raw,
402                                                                                        size_t length) {
403   zpointer* const src = arrayOopDesc::obj_offset_to_raw(src_obj, src_offset_in_bytes, src_raw);
404   zpointer* const dst = arrayOopDesc::obj_offset_to_raw(dst_obj, dst_offset_in_bytes, dst_raw);
405   OopCopyCheckStatus check_status;
406 
407   if (HasDecorator<decorators, ARRAYCOPY_CHECKCAST>::value) {
408     Klass* const dst_klass = objArrayOop(dst_obj)->element_klass();
409     check_status = oop_arraycopy_in_heap_check_cast(dst, src, length, dst_klass);
410   } else {
411     check_status = oop_arraycopy_in_heap_no_check_cast(dst, src, length);
412   }
413 
414   switch (check_status) {
415   case oop_copy_check_ok:
416     return;
417   case oop_copy_check_class_cast:
418     throw_array_store_exception(src_obj, dst_obj, JavaThread::current());
419     break;
420   case oop_copy_check_null:
421     throw_array_null_pointer_store_exception(src_obj, dst_obj, JavaThread::current());
422     break;
423   default:
424     ShouldNotReachHere();
425     return;
426   }
427 }
428 
429 class ZColorStoreGoodOopClosure : public BasicOopIterateClosure {
430 public:
431   virtual void do_oop(oop* p_) {
432     volatile zpointer* const p = (volatile zpointer*)p_;
433     const zpointer ptr = ZBarrier::load_atomic(p);
434     const zaddress addr = ZPointer::uncolor(ptr);
435     Atomic::store(p, ZAddress::store_good(addr));
436   }
437 
438   virtual void do_oop(narrowOop* p) {
439     ShouldNotReachHere();
440   }
441 };
442 
443 class ZLoadBarrierOopClosure : public BasicOopIterateClosure {
444 public:
445   virtual void do_oop(oop* p) {
446     ZBarrier::load_barrier_on_oop_field((zpointer*)p);

463     // and arraycopy sequence, so the performance of this runtime call
464     // does not matter for object arrays.
465     clone_obj_array(objArrayOop(src), objArrayOop(dst));
466     return;
467   }
468 
469   // Fix the oops
470   ZLoadBarrierOopClosure cl;
471   ZIterator::oop_iterate(src, &cl);
472 
473   // Clone the object
474   Raw::clone_in_heap(src, dst, size);
475 
476   assert(dst->is_typeArray() || ZHeap::heap()->is_young(to_zaddress(dst)), "ZColorStoreGoodOopClosure is only valid for young objects");
477 
478   // Color store good before handing out
479   ZColorStoreGoodOopClosure cl_sg;
480   ZIterator::oop_iterate(dst, &cl_sg);
481 }
482 
483 static inline void copy_primitive_payload(const void* src, const void* dst, const size_t payload_size_bytes, size_t& copied_bytes) {
484   if (payload_size_bytes == 0) {
485     return;
486   }
487   void* src_payload = (void*)(address(src) + copied_bytes);
488   void* dst_payload = (void*)(address(dst) + copied_bytes);
489   Copy::copy_value_content(src_payload, dst_payload, payload_size_bytes);
490   copied_bytes += payload_size_bytes;
491 }
492 
493 template <DecoratorSet decorators, typename BarrierSetT>
494 inline void ZBarrierSet::AccessBarrier<decorators, BarrierSetT>::value_copy_in_heap(void* src, void* dst, InlineKlass* md, LayoutKind lk) {
495   if (md->contains_oops()) {
496     // Iterate over each oop map, performing:
497     //   1) possibly raw copy for any primitive payload before each map
498     //   2) load and store barrier for each oop
499     //   3) possibly raw copy for any primitive payload trailer
500 
501     // src/dst may not be oops, need offset to adjust oop map offset
502     const address src_oop_addr_offset = ((address) src) - md->first_field_offset();
503     OopMapBlock* map = md->start_of_nonstatic_oop_maps();
504     const OopMapBlock* const end = map + md->nonstatic_oop_map_count();
505     size_t size_in_bytes = md->layout_size_in_bytes(lk);
506     size_t copied_bytes = 0;
507     while (map != end) {
508       zpointer *src_p = (zpointer*)(src_oop_addr_offset + map->offset());
509       const uintptr_t oop_offset = uintptr_t(src_p) - uintptr_t(src);
510       zpointer *dst_p = (zpointer*)(uintptr_t(dst) + oop_offset);
511 
512       // Copy any leading primitive payload before every cluster of oops
513       assert(copied_bytes < oop_offset || copied_bytes == oop_offset, "Negative sized leading payload segment");
514       copy_primitive_payload(src, dst, oop_offset - copied_bytes, copied_bytes);
515 
516       // Copy a cluster of oops
517       for (const zpointer* const src_end = src_p + map->count(); src_p < src_end; src_p++, dst_p++) {
518         oop_copy_one(dst_p, src_p);
519         copied_bytes += sizeof(zpointer);
520       }
521       map++;
522     }
523 
524     // Copy trailing primitive payload after potential oops
525     assert(copied_bytes < size_in_bytes || copied_bytes == size_in_bytes, "Negative sized trailing payload segment");
526     copy_primitive_payload(src, dst, size_in_bytes - copied_bytes, copied_bytes);
527   } else {
528     Raw::value_copy_in_heap(src, dst, md, lk);
529   }
530 }
531 
532 //
533 // Not in heap
534 //
535 template <DecoratorSet decorators, typename BarrierSetT>
536 inline oop ZBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_load_not_in_heap(zpointer* p) {
537   verify_decorators_absent<ON_UNKNOWN_OOP_REF>();
538 
539   const zpointer o = Raw::template load<zpointer>(p);
540   assert_is_valid(o);
541   return to_oop(load_barrier(p, o));
542 }
543 
544 template <DecoratorSet decorators, typename BarrierSetT>
545 inline oop ZBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_load_not_in_heap(oop* p) {
546   verify_decorators_absent<ON_UNKNOWN_OOP_REF>();
547 
548   if (HasDecorator<decorators, IN_NMETHOD>::value) {
549     return ZNMethod::load_oop(p, decorators);
550   } else {
551     return oop_load_not_in_heap((zpointer*)p);
< prev index next >