/* * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * 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_SHARED_MODREFBARRIERSET_INLINE_HPP #define SHARE_VM_GC_SHARED_MODREFBARRIERSET_INLINE_HPP #include "gc/shared/barrierSet.inline.hpp" #include "gc/shared/modRefBarrierSet.hpp" #include "oops/compressedOops.inline.hpp" #include "oops/klass.inline.hpp" #include "oops/objArrayOop.hpp" #include "oops/oop.hpp" template template inline void ModRefBarrierSet::AccessBarrier:: oop_store_in_heap(T* addr, oop value) { BarrierSetT *bs = barrier_set_cast(barrier_set()); bs->template write_ref_field_pre(addr); Raw::oop_store(addr, value); bs->template write_ref_field_post(addr, value); } template template inline oop ModRefBarrierSet::AccessBarrier:: oop_atomic_cmpxchg_in_heap(oop new_value, T* addr, oop compare_value) { BarrierSetT *bs = barrier_set_cast(barrier_set()); bs->template write_ref_field_pre(addr); oop result = Raw::oop_atomic_cmpxchg(new_value, addr, compare_value); if (result == compare_value) { bs->template write_ref_field_post(addr, new_value); } return result; } template template inline oop ModRefBarrierSet::AccessBarrier:: oop_atomic_xchg_in_heap(oop new_value, T* addr) { BarrierSetT *bs = barrier_set_cast(barrier_set()); bs->template write_ref_field_pre(addr); oop result = Raw::oop_atomic_xchg(new_value, addr); bs->template write_ref_field_post(addr, new_value); return result; } template template inline bool ModRefBarrierSet::AccessBarrier:: oop_arraycopy_in_heap(arrayOop src_obj, arrayOop dst_obj, T* src, T* dst, size_t length) { BarrierSetT *bs = barrier_set_cast(barrier_set()); if (!HasDecorator::value) { // Optimized covariant case bs->write_ref_array_pre(dst, (int)length, HasDecorator::value); Raw::oop_arraycopy(src_obj, dst_obj, src, dst, length); bs->write_ref_array((HeapWord*)dst, length); } else { Klass* bound = objArrayOop(dst_obj)->element_klass(); T* from = src; T* end = from + length; for (T* p = dst; from < end; from++, p++) { T element = *from; if (oopDesc::is_instanceof_or_null(CompressedOops::decode(element), bound)) { bs->template write_ref_field_pre(p); *p = element; } else { // We must do a barrier to cover the partial copy. const size_t pd = pointer_delta(p, dst, (size_t)heapOopSize); // pointer delta is scaled to number of elements (length field in // objArrayOop) which we assume is 32 bit. assert(pd == (size_t)(int)pd, "length field overflow"); bs->write_ref_array((HeapWord*)dst, pd); return false; } } bs->write_ref_array((HeapWord*)dst, length); } return true; } template inline void ModRefBarrierSet::AccessBarrier:: clone_in_heap(oop src, oop dst, size_t size) { Raw::clone(src, dst, size); BarrierSetT *bs = barrier_set_cast(barrier_set()); bs->write_region(MemRegion((HeapWord*)(void*)dst, size)); } #endif // SHARE_VM_GC_SHARED_MODREFBARRIERSET_INLINE_HPP