< prev index next >

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

Print this page

 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/zHeap.hpp"
 32 #include "gc/z/zNMethod.hpp"

 33 #include "oops/objArrayOop.hpp"

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

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




334   AtomicAccess::store(dst, ZAddress::store_good(obj));


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




341   if (!oopDesc::is_instanceof_or_null(to_oop(obj), dst_klass)) {
342     // Check cast failed
343     return false;
344   }
345 
346   AtomicAccess::store(dst, ZAddress::store_good(obj));
347 
348   return true;
349 }
350 
351 template <DecoratorSet decorators, typename BarrierSetT>
352 inline bool ZBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_arraycopy_in_heap_check_cast(zpointer* dst, zpointer* src, size_t length, Klass* dst_klass) {
353   // Check cast and copy each elements
354   for (const zpointer* const end = src + length; src < end; src++, dst++) {
355     if (!oop_copy_one_check_cast(dst, src, dst_klass)) {
356       // Check cast failed
357       return false;
358     }
359   }
360 
361   return true;
362 }
363 
364 template <DecoratorSet decorators, typename BarrierSetT>
365 inline bool ZBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_arraycopy_in_heap_no_check_cast(zpointer* dst, zpointer* src, size_t length) {
366   const bool is_disjoint = HasDecorator<decorators, ARRAYCOPY_DISJOINT>::value;
367 
368   if (is_disjoint || src > dst) {
369     for (const zpointer* const end = src + length; src < end; src++, dst++) {
370       oop_copy_one(dst, src);



371     }
372     return true;

373   }
374 
375   if (src < dst) {
376     const zpointer* const end = src;
377     src += length - 1;
378     dst += length - 1;
379     for ( ; src >= end; src--, dst--) {
380       oop_copy_one(dst, src);



381     }
382     return true;

383   }
384 
385   // src and dst are the same; nothing to do
386   return true;
387 }
388 
389 template <DecoratorSet decorators, typename BarrierSetT>
390 inline bool ZBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_arraycopy_in_heap(arrayOop src_obj, size_t src_offset_in_bytes, zpointer* src_raw,
391                                                                                        arrayOop dst_obj, size_t dst_offset_in_bytes, zpointer* dst_raw,
392                                                                                        size_t length) {
393   zpointer* const src = arrayOopDesc::obj_offset_to_raw(src_obj, src_offset_in_bytes, src_raw);
394   zpointer* const dst = arrayOopDesc::obj_offset_to_raw(dst_obj, dst_offset_in_bytes, dst_raw);
395 
396   if (HasDecorator<decorators, ARRAYCOPY_CHECKCAST>::value) {
397     Klass* const dst_klass = objArrayOop(dst_obj)->element_klass();
398     return oop_arraycopy_in_heap_check_cast(dst, src, length, dst_klass);


399   }
400 
401   return oop_arraycopy_in_heap_no_check_cast(dst, src, length);
402 }
403 
404 template <DecoratorSet decorators, typename BarrierSetT>
405 inline void ZBarrierSet::AccessBarrier<decorators, BarrierSetT>::clone_in_heap(oop src, oop dst, size_t size) {
406   check_is_valid_zaddress(src);
407 
408   if (dst->is_objArray()) {
409     // Cloning an object array is similar to performing array copy.
410     // If an array is large enough to have its allocation segmented,
411     // this operation might require GC barriers. However, the intrinsics
412     // for cloning arrays transform the clone to an optimized allocation
413     // and arraycopy sequence, so the performance of this runtime call
414     // does not matter for object arrays.
415     clone_obj_array(objArrayOop(src), objArrayOop(dst));
416     return;
417   }
418 
419   // Fix the oops
420   ZBarrierSet::load_barrier_all(src, size);
421 
422   // Clone the object
423   Raw::clone_in_heap(src, dst, size);
424 
425   // Color store good before handing out
426   ZBarrierSet::color_store_good_all(dst, size);
427 }
428 

















































429 //
430 // Not in heap
431 //
432 template <DecoratorSet decorators, typename BarrierSetT>
433 inline oop ZBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_load_not_in_heap(zpointer* p) {
434   verify_decorators_absent<ON_UNKNOWN_OOP_REF>();
435 
436   const zpointer o = Raw::template load<zpointer>(p);
437   assert_is_valid(o);
438   return to_oop(load_barrier(p, o));
439 }
440 
441 template <DecoratorSet decorators, typename BarrierSetT>
442 inline oop ZBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_load_not_in_heap(oop* p) {
443   verify_decorators_absent<ON_UNKNOWN_OOP_REF>();
444 
445   return oop_load_not_in_heap((zpointer*)p);
446 }
447 
448 template <DecoratorSet decorators, typename BarrierSetT>

 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.hpp"
 31 #include "gc/z/zAddress.inline.hpp"
 32 #include "gc/z/zHeap.hpp"
 33 #include "gc/z/zNMethod.hpp"
 34 #include "oops/inlineKlass.inline.hpp"
 35 #include "oops/objArrayOop.hpp"
 36 #include "utilities/copy.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 ZBarrierSet::load_barrier_on_oop_field(src);
331 }
332 
333 template <DecoratorSet decorators, typename BarrierSetT>
334 inline OopCopyResult 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 OopCopyResult::failed_check_null;
339   }
340 
341   AtomicAccess::store(dst, ZAddress::store_good(obj));
342 
343   return OopCopyResult::ok;
344 }
345 
346 template <DecoratorSet decorators, typename BarrierSetT>
347 inline OopCopyResult ZBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_copy_one_check_cast(zpointer* dst, zpointer* src, Klass* dst_klass) {
348   const zaddress obj = oop_copy_one_barriers(dst, src);
349 
350   if (HasDecorator<decorators, ARRAYCOPY_NOTNULL>::value && is_null(obj)) {
351     return OopCopyResult::failed_check_null;
352   }
353 
354   if (!oopDesc::is_instanceof_or_null(to_oop(obj), dst_klass)) {
355     // Check cast failed
356     return OopCopyResult::failed_check_class_cast;
357   }
358 
359   AtomicAccess::store(dst, ZAddress::store_good(obj));
360 
361   return OopCopyResult::ok;
362 }
363 
364 template <DecoratorSet decorators, typename BarrierSetT>
365 inline OopCopyResult 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   for (const zpointer* const end = src + length; src < end; src++, dst++) {
368     const OopCopyResult result = oop_copy_one_check_cast(dst, src, dst_klass);
369     if (result != OopCopyResult::ok) {
370       return result;
371     }
372   }
373 
374   return OopCopyResult::ok;
375 }
376 
377 template <DecoratorSet decorators, typename BarrierSetT>
378 inline OopCopyResult ZBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_arraycopy_in_heap_no_check_cast(zpointer* dst, zpointer* src, size_t length) {
379   const bool is_disjoint = HasDecorator<decorators, ARRAYCOPY_DISJOINT>::value;
380 
381   if (is_disjoint || src > dst) {
382     for (const zpointer* const end = src + length; src < end; src++, dst++) {
383       const OopCopyResult result = oop_copy_one(dst, src);
384       if (result != OopCopyResult::ok) {
385         return result;
386       }
387     }
388 
389     return OopCopyResult::ok;
390   }
391 
392   if (src < dst) {
393     const zpointer* const end = src;
394     src += length - 1;
395     dst += length - 1;
396     for ( ; src >= end; src--, dst--) {
397       const OopCopyResult result = oop_copy_one(dst, src);
398       if (result != OopCopyResult::ok) {
399         return result;
400       }
401     }
402 
403     return OopCopyResult::ok;
404   }
405 
406   // src and dst are the same; nothing to do
407   return OopCopyResult::ok;
408 }
409 
410 template <DecoratorSet decorators, typename BarrierSetT>
411 inline OopCopyResult ZBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_arraycopy_in_heap(arrayOop src_obj, size_t src_offset_in_bytes, zpointer* src_raw,
412                                                                                                 arrayOop dst_obj, size_t dst_offset_in_bytes, zpointer* dst_raw,
413                                                                                                 size_t length) {
414   zpointer* const src = arrayOopDesc::obj_offset_to_raw(src_obj, src_offset_in_bytes, src_raw);
415   zpointer* const dst = arrayOopDesc::obj_offset_to_raw(dst_obj, dst_offset_in_bytes, dst_raw);
416 
417   if (HasDecorator<decorators, ARRAYCOPY_CHECKCAST>::value) {
418     Klass* const dst_klass = objArrayOop(dst_obj)->element_klass();
419     return oop_arraycopy_in_heap_check_cast(dst, src, length, dst_klass);
420   } else {
421     return oop_arraycopy_in_heap_no_check_cast(dst, src, length);
422   }


423 }
424 
425 template <DecoratorSet decorators, typename BarrierSetT>
426 inline void ZBarrierSet::AccessBarrier<decorators, BarrierSetT>::clone_in_heap(oop src, oop dst, size_t size) {
427   check_is_valid_zaddress(src);
428 
429   if (dst->is_refArray()) {
430     // Cloning an object array is similar to performing array copy.
431     // If an array is large enough to have its allocation segmented,
432     // this operation might require GC barriers. However, the intrinsics
433     // for cloning arrays transform the clone to an optimized allocation
434     // and arraycopy sequence, so the performance of this runtime call
435     // does not matter for object arrays.
436     clone_obj_array(objArrayOop(src), objArrayOop(dst));
437     return;
438   }
439 
440   // Fix the oops
441   ZBarrierSet::load_barrier_all(src, size);
442 
443   // Clone the object
444   Raw::clone_in_heap(src, dst, size);
445 
446   // Color store good before handing out
447   ZBarrierSet::color_store_good_all(dst, size);
448 }
449 
450 static inline void copy_primitive_payload(const void* src, const void* dst, const size_t payload_size_bytes, size_t& copied_bytes) {
451   if (payload_size_bytes == 0) {
452     return;
453   }
454   void* src_payload = (void*)(address(src) + copied_bytes);
455   void* dst_payload = (void*)(address(dst) + copied_bytes);
456   Copy::copy_value_content(src_payload, dst_payload, payload_size_bytes);
457   copied_bytes += payload_size_bytes;
458 }
459 
460 template <DecoratorSet decorators, typename BarrierSetT>
461 inline void ZBarrierSet::AccessBarrier<decorators, BarrierSetT>::value_copy_in_heap(void* src, void* dst, InlineKlass* md, LayoutKind lk) {
462   if (md->contains_oops()) {
463     // Iterate over each oop map, performing:
464     //   1) possibly raw copy for any primitive payload before each map
465     //   2) load and store barrier for each oop
466     //   3) possibly raw copy for any primitive payload trailer
467 
468     // src/dst may not be oops, need offset to adjust oop map offset
469     const address src_oop_addr_offset = ((address) src) - md->payload_offset();
470     OopMapBlock* map = md->start_of_nonstatic_oop_maps();
471     const OopMapBlock* const end = map + md->nonstatic_oop_map_count();
472     size_t size_in_bytes = md->layout_size_in_bytes(lk);
473     size_t copied_bytes = 0;
474     while (map != end) {
475       zpointer *src_p = (zpointer*)(src_oop_addr_offset + map->offset());
476       const uintptr_t oop_offset = uintptr_t(src_p) - uintptr_t(src);
477       zpointer *dst_p = (zpointer*)(uintptr_t(dst) + oop_offset);
478 
479       // Copy any leading primitive payload before every cluster of oops
480       assert(copied_bytes < oop_offset || copied_bytes == oop_offset, "Negative sized leading payload segment");
481       copy_primitive_payload(src, dst, oop_offset - copied_bytes, copied_bytes);
482 
483       // Copy a cluster of oops
484       for (const zpointer* const src_end = src_p + map->count(); src_p < src_end; src_p++, dst_p++) {
485         oop_copy_one(dst_p, src_p);
486         copied_bytes += sizeof(zpointer);
487       }
488       map++;
489     }
490 
491     // Copy trailing primitive payload after potential oops
492     assert(copied_bytes < size_in_bytes || copied_bytes == size_in_bytes, "Negative sized trailing payload segment");
493     copy_primitive_payload(src, dst, size_in_bytes - copied_bytes, copied_bytes);
494   } else {
495     Raw::value_copy_in_heap(src, dst, md, lk);
496   }
497 }
498 
499 //
500 // Not in heap
501 //
502 template <DecoratorSet decorators, typename BarrierSetT>
503 inline oop ZBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_load_not_in_heap(zpointer* p) {
504   verify_decorators_absent<ON_UNKNOWN_OOP_REF>();
505 
506   const zpointer o = Raw::template load<zpointer>(p);
507   assert_is_valid(o);
508   return to_oop(load_barrier(p, o));
509 }
510 
511 template <DecoratorSet decorators, typename BarrierSetT>
512 inline oop ZBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_load_not_in_heap(oop* p) {
513   verify_decorators_absent<ON_UNKNOWN_OOP_REF>();
514 
515   return oop_load_not_in_heap((zpointer*)p);
516 }
517 
518 template <DecoratorSet decorators, typename BarrierSetT>
< prev index next >