/* * Copyright (c) 2018, Red Hat, Inc. and/or its affiliates. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. * */ #ifndef SHARE_VM_GC_SHENANDOAH_SHENANDOAHLRBBARRIERSET_INLINE_HPP #define SHARE_VM_GC_SHENANDOAH_SHENANDOAHLRBBARRIERSET_INLINE_HPP #include "gc/shared/accessBarrierSupport.hpp" #include "gc/shenandoah/shenandoahLRBBarrierSet.hpp" template template inline oop ShenandoahLRBBarrierSet::AccessBarrier::oop_load_in_heap(T* addr) { oop obj = Raw::oop_load_in_heap(addr); obj = ShenandoahBaseBarrierSet::barrier_set()->write_barrier(obj); ShenandoahBaseBarrierSet::keep_alive_if_weak(decorators, obj); return obj; } template inline oop ShenandoahLRBBarrierSet::AccessBarrier::oop_load_in_heap_at(oop base, ptrdiff_t offset) { oop obj = Raw::oop_load_in_heap_at(base, offset); obj = ShenandoahBaseBarrierSet::barrier_set()->write_barrier(obj); keep_alive_if_weak(AccessBarrierSupport::resolve_possibly_unknown_oop_ref_strength(base, offset), obj); return obj; } template template inline void ShenandoahLRBBarrierSet::AccessBarrier::oop_store_in_heap(T* addr, oop value) { ShenandoahBaseBarrierSet::barrier_set()->write_ref_field_pre_work(addr, value); ShenandoahBaseBarrierSet::barrier_set()->enqueue_barrier(value); Raw::oop_store_in_heap(addr, value); } template template inline oop ShenandoahLRBBarrierSet::AccessBarrier::oop_atomic_cmpxchg_in_heap(oop new_value, T* addr, oop compare_value) { ShenandoahBaseBarrierSet::barrier_set()->enqueue_barrier(new_value); oop res; oop expected = compare_value; do { compare_value = expected; res = Raw::oop_atomic_cmpxchg(new_value, addr, compare_value); expected = res; } while ((! oopDesc::unsafe_equals(compare_value, expected)) && oopDesc::unsafe_equals(resolve_forwarded(compare_value), resolve_forwarded(expected))); if (oopDesc::unsafe_equals(expected, compare_value)) { if (ShenandoahSATBBarrier && !CompressedOops::is_null(compare_value)) { ShenandoahBarrierSet::barrier_set()->enqueue(compare_value); } } res = ShenandoahBaseBarrierSet::barrier_set()->write_barrier(res); ShenandoahBaseBarrierSet::keep_alive_if_weak(decorators, res); return res; } template inline oop ShenandoahLRBBarrierSet::AccessBarrier::oop_atomic_cmpxchg_in_heap_at(oop new_value, oop base, ptrdiff_t offset, oop compare_value) { ShenandoahBaseBarrierSet::barrier_set()->enqueue_barrier(new_value); oop res; oop expected = compare_value; do { compare_value = expected; res = Raw::oop_atomic_cmpxchg_at(new_value, base, offset, compare_value); expected = res; } while ((! oopDesc::unsafe_equals(compare_value, expected)) && oopDesc::unsafe_equals(resolve_forwarded(compare_value), resolve_forwarded(expected))); if (oopDesc::unsafe_equals(expected, compare_value)) { if (ShenandoahSATBBarrier && !CompressedOops::is_null(compare_value)) { ShenandoahBarrierSet::barrier_set()->enqueue(compare_value); } } res = ShenandoahBaseBarrierSet::barrier_set()->write_barrier(res); keep_alive_if_weak(AccessBarrierSupport::resolve_possibly_unknown_oop_ref_strength(base, offset), res); return res; } template template inline oop ShenandoahLRBBarrierSet::AccessBarrier::oop_atomic_xchg_in_heap(oop new_value, T* addr) { ShenandoahBaseBarrierSet::barrier_set()->write_ref_field_pre_work(addr, new_value); ShenandoahBaseBarrierSet::barrier_set()->enqueue_barrier(new_value); oop obj = Raw::oop_atomic_xchg_in_heap(new_value, addr); obj = ShenandoahBaseBarrierSet::barrier_set()->write_barrier(obj); ShenandoahBaseBarrierSet::keep_alive_if_weak(decorators, obj); return obj; } template inline oop ShenandoahLRBBarrierSet::AccessBarrier::oop_atomic_xchg_in_heap_at(oop new_value, oop base, ptrdiff_t offset) { ShenandoahBaseBarrierSet::barrier_set()->write_ref_field_pre_work(AccessInternal::oop_field_addr(base, offset), new_value); ShenandoahBaseBarrierSet::barrier_set()->enqueue_barrier(new_value); oop obj = Raw::oop_atomic_xchg_in_heap_at(new_value, base, offset); obj = ShenandoahBaseBarrierSet::barrier_set()->write_barrier(obj); keep_alive_if_weak(AccessBarrierSupport::resolve_possibly_unknown_oop_ref_strength(base, offset), obj); return obj; } template template inline oop ShenandoahLRBBarrierSet::AccessBarrier::oop_load_not_in_heap(T* addr) { oop obj = Raw::oop_load_not_in_heap(addr); obj = ShenandoahBaseBarrierSet::barrier_set()->write_barrier(obj); ShenandoahBaseBarrierSet::keep_alive_if_weak(decorators, obj); return obj; } template template inline oop ShenandoahLRBBarrierSet::AccessBarrier::oop_atomic_cmpxchg_not_in_heap(oop new_value, T* addr, oop compare_value) { oop obj = Raw::oop_atomic_cmpxchg_not_in_heap(new_value, addr, compare_value); obj = ShenandoahBaseBarrierSet::barrier_set()->write_barrier(obj); ShenandoahBaseBarrierSet::keep_alive_if_weak(decorators, obj); return obj; } template template inline oop ShenandoahLRBBarrierSet::AccessBarrier::oop_atomic_xchg_not_in_heap(oop new_value, T* addr) { oop obj = Raw::oop_atomic_xchg_not_in_heap(new_value, addr); obj = ShenandoahBaseBarrierSet::barrier_set()->write_barrier(obj); ShenandoahBaseBarrierSet::keep_alive_if_weak(decorators, obj); return obj; } template template bool ShenandoahLRBBarrierSet::AccessBarrier::oop_arraycopy_in_heap(arrayOop src_obj, size_t src_offset_in_bytes, T* src_raw, arrayOop dst_obj, size_t dst_offset_in_bytes, T* dst_raw, size_t length) { ShenandoahHeap* heap = ShenandoahHeap::heap(); bool satb = ShenandoahSATBBarrier && heap->is_concurrent_mark_in_progress(); bool checkcast = HasDecorator::value; ArrayCopyStoreValMode storeval_mode; if (heap->has_forwarded_objects()) { if (heap->is_concurrent_traversal_in_progress()) { storeval_mode = WRITE_BARRIER; } else if (heap->is_concurrent_mark_in_progress() || heap->is_update_refs_in_progress()) { storeval_mode = READ_BARRIER; } else { assert(heap->is_idle() || heap->is_evacuation_in_progress(), "must not have anything in progress"); storeval_mode = NONE; // E.g. during evac or outside cycle } } else { assert(heap->is_stable() || heap->is_concurrent_mark_in_progress(), "must not have anything in progress"); storeval_mode = NONE; } if (!satb && !checkcast && storeval_mode == NONE) { // Short-circuit to bulk copy. return Raw::oop_arraycopy(src_obj, src_offset_in_bytes, src_raw, dst_obj, dst_offset_in_bytes, dst_raw, length); } src_raw = arrayOopDesc::obj_offset_to_raw(src_obj, src_offset_in_bytes, src_raw); dst_raw = arrayOopDesc::obj_offset_to_raw(dst_obj, dst_offset_in_bytes, dst_raw); Klass* bound = objArrayOop(dst_obj)->element_klass(); ShenandoahBaseBarrierSet* bs = ShenandoahBaseBarrierSet::barrier_set(); return bs->arraycopy_loop_1(src_raw, dst_raw, length, bound, checkcast, satb, storeval_mode); } template void ShenandoahLRBBarrierSet::AccessBarrier::clone_in_heap(oop src, oop dst, size_t size) { Raw::clone(src, dst, size); ShenandoahBarrierSet::barrier_set()->write_region(MemRegion((HeapWord*) dst, size)); } #endif // SHARE_VM_GC_SHENANDOAH_SHENANDOAHLRBBARRIERSET_INLINE_HPP