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() {
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 OopCopyResult ZBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_copy_one(zpointer* dst, zpointer* src) {
332 const zaddress obj = oop_copy_one_barriers(dst, src);
333
334 // Future location for null-restriction check and failure reporting
335
336 AtomicAccess::store(dst, ZAddress::store_good(obj));
337
338 return OopCopyResult::ok;
339 }
340
341 template <DecoratorSet decorators, typename BarrierSetT>
342 inline OopCopyResult ZBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_copy_one_check_cast(zpointer* dst, zpointer* src, Klass* dst_klass) {
343 const zaddress obj = oop_copy_one_barriers(dst, src);
344
345 if (!oopDesc::is_instanceof_or_null(to_oop(obj), dst_klass)) {
346 // Check cast failed
347 return OopCopyResult::failed_check_class_cast;
348 }
349
350 AtomicAccess::store(dst, ZAddress::store_good(obj));
351
352 return OopCopyResult::ok;
353 }
354
355 template <DecoratorSet decorators, typename BarrierSetT>
356 inline OopCopyResult ZBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_arraycopy_in_heap_check_cast(zpointer* dst, zpointer* src, size_t length, Klass* dst_klass) {
357 // Check cast and copy each elements
358 for (const zpointer* const end = src + length; src < end; src++, dst++) {
359 const OopCopyResult result = oop_copy_one_check_cast(dst, src, dst_klass);
360 if (result != OopCopyResult::ok) {
361 return result;
362 }
363 }
364
400
401 template <DecoratorSet decorators, typename BarrierSetT>
402 inline OopCopyResult ZBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_arraycopy_in_heap(arrayOop src_obj, size_t src_offset_in_bytes, zpointer* src_raw,
403 arrayOop dst_obj, size_t dst_offset_in_bytes, zpointer* dst_raw,
404 size_t length) {
405 zpointer* const src = arrayOopDesc::obj_offset_to_raw(src_obj, src_offset_in_bytes, src_raw);
406 zpointer* const dst = arrayOopDesc::obj_offset_to_raw(dst_obj, dst_offset_in_bytes, dst_raw);
407
408 if (HasDecorator<decorators, ARRAYCOPY_CHECKCAST>::value) {
409 Klass* const dst_klass = objArrayOop(dst_obj)->element_klass();
410 return oop_arraycopy_in_heap_check_cast(dst, src, length, dst_klass);
411 } else {
412 return oop_arraycopy_in_heap_no_check_cast(dst, src, length);
413 }
414 }
415
416 template <DecoratorSet decorators, typename BarrierSetT>
417 inline void ZBarrierSet::AccessBarrier<decorators, BarrierSetT>::clone_in_heap(oop src, oop dst, size_t size) {
418 check_is_valid_zaddress(src);
419
420 if (dst->is_objArray()) {
421 // Cloning an object array is similar to performing array copy.
422 // If an array is large enough to have its allocation segmented,
423 // this operation might require GC barriers. However, the intrinsics
424 // for cloning arrays transform the clone to an optimized allocation
425 // and arraycopy sequence, so the performance of this runtime call
426 // does not matter for object arrays.
427 clone_obj_array(objArrayOop(src), objArrayOop(dst));
428 return;
429 }
430
431 // Fix the oops
432 ZBarrierSet::load_barrier_all(src, size);
433
434 // Clone the object
435 Raw::clone_in_heap(src, dst, size);
436
437 // Color store good before handing out
438 ZBarrierSet::color_store_good_all(dst, size);
439 }
440
441 //
442 // Not in heap
443 //
444 template <DecoratorSet decorators, typename BarrierSetT>
445 inline oop ZBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_load_not_in_heap(zpointer* p) {
446 verify_decorators_absent<ON_UNKNOWN_OOP_REF>();
447
448 const zpointer o = Raw::template load<zpointer>(p);
449 assert_is_valid(o);
450 return to_oop(load_barrier(p, o));
451 }
452
453 template <DecoratorSet decorators, typename BarrierSetT>
454 inline oop ZBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_load_not_in_heap(oop* p) {
455 verify_decorators_absent<ON_UNKNOWN_OOP_REF>();
456
457 return oop_load_not_in_heap((zpointer*)p);
458 }
459
460 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() {
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
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>
|