2018-12-10 15:47:44 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2015, 2018, Red Hat, Inc. All rights reserved.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2019-01-10 15:13:51 -05:00
|
|
|
#ifndef SHARE_GC_SHENANDOAH_SHENANDOAHBARRIERSET_INLINE_HPP
|
|
|
|
#define SHARE_GC_SHENANDOAH_SHENANDOAHBARRIERSET_INLINE_HPP
|
2018-12-10 15:47:44 +01:00
|
|
|
|
|
|
|
#include "gc/shared/barrierSet.hpp"
|
2019-07-15 11:23:05 -04:00
|
|
|
#include "gc/shenandoah/shenandoahAsserts.hpp"
|
2018-12-10 15:47:44 +01:00
|
|
|
#include "gc/shenandoah/shenandoahBarrierSet.hpp"
|
2019-09-18 20:56:19 +02:00
|
|
|
#include "gc/shenandoah/shenandoahCollectionSet.inline.hpp"
|
2019-05-08 20:45:30 +02:00
|
|
|
#include "gc/shenandoah/shenandoahForwarding.inline.hpp"
|
2018-12-10 15:47:44 +01:00
|
|
|
#include "gc/shenandoah/shenandoahHeap.inline.hpp"
|
2019-04-02 18:13:42 +02:00
|
|
|
#include "gc/shenandoah/shenandoahHeapRegion.hpp"
|
|
|
|
#include "gc/shenandoah/shenandoahMarkingContext.inline.hpp"
|
|
|
|
#include "gc/shenandoah/shenandoahThreadLocalData.hpp"
|
2019-09-18 20:56:19 +02:00
|
|
|
#include "memory/iterator.inline.hpp"
|
|
|
|
#include "oops/oop.inline.hpp"
|
2018-12-10 15:47:44 +01:00
|
|
|
|
|
|
|
inline oop ShenandoahBarrierSet::resolve_forwarded_not_null(oop p) {
|
2019-05-08 20:45:30 +02:00
|
|
|
return ShenandoahForwarding::get_forwardee(p);
|
2018-12-10 15:47:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
inline oop ShenandoahBarrierSet::resolve_forwarded(oop p) {
|
|
|
|
if (((HeapWord*) p) != NULL) {
|
|
|
|
return resolve_forwarded_not_null(p);
|
|
|
|
} else {
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <DecoratorSet decorators, typename BarrierSetT>
|
|
|
|
template <typename T>
|
2019-04-02 23:00:22 +02:00
|
|
|
inline oop ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_load_in_heap(T* addr) {
|
|
|
|
oop value = Raw::oop_load_in_heap(addr);
|
|
|
|
value = ShenandoahBarrierSet::barrier_set()->load_reference_barrier(value);
|
|
|
|
keep_alive_if_weak(decorators, value);
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <DecoratorSet decorators, typename BarrierSetT>
|
|
|
|
inline oop ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_load_in_heap_at(oop base, ptrdiff_t offset) {
|
|
|
|
oop value = Raw::oop_load_in_heap_at(base, offset);
|
|
|
|
value = ShenandoahBarrierSet::barrier_set()->load_reference_barrier(value);
|
|
|
|
keep_alive_if_weak(AccessBarrierSupport::resolve_possibly_unknown_oop_ref_strength<decorators>(base, offset), value);
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <DecoratorSet decorators, typename BarrierSetT>
|
|
|
|
template <typename T>
|
|
|
|
inline oop ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_load_not_in_heap(T* addr) {
|
|
|
|
oop value = Raw::oop_load_not_in_heap(addr);
|
2019-07-04 17:31:03 +02:00
|
|
|
value = ShenandoahBarrierSet::barrier_set()->oop_load_from_native_barrier(value);
|
2019-04-02 23:00:22 +02:00
|
|
|
keep_alive_if_weak(decorators, value);
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <DecoratorSet decorators, typename BarrierSetT>
|
|
|
|
template <typename T>
|
|
|
|
inline void ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_store_in_heap(T* addr, oop value) {
|
|
|
|
ShenandoahBarrierSet::barrier_set()->storeval_barrier(value);
|
|
|
|
const bool keep_alive = (decorators & AS_NO_KEEPALIVE) == 0;
|
|
|
|
if (keep_alive) {
|
|
|
|
ShenandoahBarrierSet::barrier_set()->write_ref_field_pre_work(addr, value);
|
|
|
|
}
|
|
|
|
Raw::oop_store_in_heap(addr, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <DecoratorSet decorators, typename BarrierSetT>
|
|
|
|
inline void ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_store_in_heap_at(oop base, ptrdiff_t offset, oop value) {
|
|
|
|
oop_store_in_heap(AccessInternal::oop_field_addr<decorators>(base, offset), value);
|
|
|
|
}
|
|
|
|
|
2019-07-15 11:23:05 -04:00
|
|
|
template <DecoratorSet decorators, typename BarrierSetT>
|
|
|
|
template <typename T>
|
|
|
|
inline void ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_store_not_in_heap(T* addr, oop value) {
|
|
|
|
shenandoah_assert_marked_if(NULL, value, !CompressedOops::is_null(value) && ShenandoahHeap::heap()->is_evacuation_in_progress());
|
|
|
|
Raw::oop_store(addr, value);
|
|
|
|
}
|
|
|
|
|
2019-04-02 23:00:22 +02:00
|
|
|
template <DecoratorSet decorators, typename BarrierSetT>
|
|
|
|
template <typename T>
|
|
|
|
inline oop ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_atomic_cmpxchg_not_in_heap(oop new_value, T* addr, oop compare_value) {
|
2018-12-10 15:47:44 +01:00
|
|
|
oop res;
|
|
|
|
oop expected = compare_value;
|
|
|
|
do {
|
|
|
|
compare_value = expected;
|
|
|
|
res = Raw::oop_atomic_cmpxchg(new_value, addr, compare_value);
|
|
|
|
expected = res;
|
2019-09-17 09:51:02 +02:00
|
|
|
} while ((compare_value != expected) && (resolve_forwarded(compare_value) == resolve_forwarded(expected)));
|
2019-04-02 23:00:22 +02:00
|
|
|
if (res != NULL) {
|
|
|
|
return ShenandoahBarrierSet::barrier_set()->load_reference_barrier_not_null(res);
|
|
|
|
} else {
|
|
|
|
return res;
|
2018-12-10 15:47:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <DecoratorSet decorators, typename BarrierSetT>
|
|
|
|
template <typename T>
|
2019-04-02 23:00:22 +02:00
|
|
|
inline oop ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_atomic_cmpxchg_in_heap_impl(oop new_value, T* addr, oop compare_value) {
|
|
|
|
ShenandoahBarrierSet::barrier_set()->storeval_barrier(new_value);
|
|
|
|
oop result = oop_atomic_cmpxchg_not_in_heap(new_value, addr, compare_value);
|
|
|
|
const bool keep_alive = (decorators & AS_NO_KEEPALIVE) == 0;
|
|
|
|
if (keep_alive && ShenandoahSATBBarrier && !CompressedOops::is_null(result) &&
|
2019-09-17 09:51:02 +02:00
|
|
|
(result == compare_value) &&
|
2019-04-02 23:00:22 +02:00
|
|
|
ShenandoahHeap::heap()->is_concurrent_mark_in_progress()) {
|
|
|
|
ShenandoahBarrierSet::barrier_set()->enqueue(result);
|
2018-12-10 15:47:44 +01:00
|
|
|
}
|
2019-04-02 23:00:22 +02:00
|
|
|
return result;
|
2018-12-10 15:47:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
template <DecoratorSet decorators, typename BarrierSetT>
|
|
|
|
template <typename T>
|
2019-04-02 23:00:22 +02:00
|
|
|
inline oop ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_atomic_cmpxchg_in_heap(oop new_value, T* addr, oop compare_value) {
|
|
|
|
oop result = oop_atomic_cmpxchg_in_heap_impl(new_value, addr, compare_value);
|
|
|
|
keep_alive_if_weak(decorators, result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <DecoratorSet decorators, typename BarrierSetT>
|
|
|
|
inline oop ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_atomic_cmpxchg_in_heap_at(oop new_value, oop base, ptrdiff_t offset, oop compare_value) {
|
|
|
|
oop result = oop_atomic_cmpxchg_in_heap_impl(new_value, AccessInternal::oop_field_addr<decorators>(base, offset), compare_value);
|
|
|
|
keep_alive_if_weak(AccessBarrierSupport::resolve_possibly_unknown_oop_ref_strength<decorators>(base, offset), result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <DecoratorSet decorators, typename BarrierSetT>
|
|
|
|
template <typename T>
|
|
|
|
inline oop ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_atomic_xchg_not_in_heap(oop new_value, T* addr) {
|
|
|
|
oop previous = Raw::oop_atomic_xchg(new_value, addr);
|
|
|
|
if (previous != NULL) {
|
|
|
|
return ShenandoahBarrierSet::barrier_set()->load_reference_barrier_not_null(previous);
|
|
|
|
} else {
|
|
|
|
return previous;
|
2018-12-10 15:47:44 +01:00
|
|
|
}
|
2019-04-02 23:00:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template <DecoratorSet decorators, typename BarrierSetT>
|
|
|
|
template <typename T>
|
|
|
|
inline oop ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_atomic_xchg_in_heap_impl(oop new_value, T* addr) {
|
|
|
|
ShenandoahBarrierSet::barrier_set()->storeval_barrier(new_value);
|
|
|
|
oop result = oop_atomic_xchg_not_in_heap(new_value, addr);
|
|
|
|
const bool keep_alive = (decorators & AS_NO_KEEPALIVE) == 0;
|
|
|
|
if (keep_alive && ShenandoahSATBBarrier && !CompressedOops::is_null(result) &&
|
|
|
|
ShenandoahHeap::heap()->is_concurrent_mark_in_progress()) {
|
|
|
|
ShenandoahBarrierSet::barrier_set()->enqueue(result);
|
2018-12-10 15:47:44 +01:00
|
|
|
}
|
2019-04-02 23:00:22 +02:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <DecoratorSet decorators, typename BarrierSetT>
|
|
|
|
template <typename T>
|
|
|
|
inline oop ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_atomic_xchg_in_heap(oop new_value, T* addr) {
|
|
|
|
oop result = oop_atomic_xchg_in_heap_impl(new_value, addr);
|
|
|
|
keep_alive_if_weak(addr, result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <DecoratorSet decorators, typename BarrierSetT>
|
|
|
|
inline oop ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::oop_atomic_xchg_in_heap_at(oop new_value, oop base, ptrdiff_t offset) {
|
|
|
|
oop result = oop_atomic_xchg_in_heap_impl(new_value, AccessInternal::oop_field_addr<decorators>(base, offset));
|
|
|
|
keep_alive_if_weak(AccessBarrierSupport::resolve_possibly_unknown_oop_ref_strength<decorators>(base, offset), result);
|
|
|
|
return result;
|
2018-12-10 15:47:44 +01:00
|
|
|
}
|
|
|
|
|
2019-09-18 20:56:19 +02:00
|
|
|
// Clone barrier support
|
|
|
|
template <DecoratorSet decorators, typename BarrierSetT>
|
|
|
|
void ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::clone_in_heap(oop src, oop dst, size_t size) {
|
|
|
|
if (ShenandoahCloneBarrier) {
|
2019-09-25 12:33:05 +02:00
|
|
|
ShenandoahBarrierSet::barrier_set()->clone_barrier_runtime(src);
|
2018-12-10 15:47:44 +01:00
|
|
|
}
|
2019-09-18 20:56:19 +02:00
|
|
|
Raw::clone(src, dst, size);
|
2018-12-10 15:47:44 +01:00
|
|
|
}
|
|
|
|
|
2019-09-18 20:56:19 +02:00
|
|
|
template <DecoratorSet decorators, typename BarrierSetT>
|
|
|
|
template <typename T>
|
|
|
|
bool ShenandoahBarrierSet::AccessBarrier<decorators, BarrierSetT>::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) {
|
|
|
|
ShenandoahBarrierSet* bs = ShenandoahBarrierSet::barrier_set();
|
|
|
|
bs->arraycopy_pre(arrayOopDesc::obj_offset_to_raw(src_obj, src_offset_in_bytes, src_raw),
|
|
|
|
arrayOopDesc::obj_offset_to_raw(dst_obj, dst_offset_in_bytes, dst_raw),
|
|
|
|
length);
|
|
|
|
return Raw::oop_arraycopy_in_heap(src_obj, src_offset_in_bytes, src_raw, dst_obj, dst_offset_in_bytes, dst_raw, length);
|
2018-12-10 15:47:44 +01:00
|
|
|
}
|
|
|
|
|
2019-09-18 20:56:19 +02:00
|
|
|
template <class T, bool HAS_FWD, bool EVAC, bool ENQUEUE>
|
|
|
|
void ShenandoahBarrierSet::arraycopy_work(T* src, size_t count) {
|
2018-12-10 15:47:44 +01:00
|
|
|
Thread* thread = Thread::current();
|
2019-09-18 20:56:19 +02:00
|
|
|
SATBMarkQueue& queue = ShenandoahThreadLocalData::satb_mark_queue(thread);
|
2019-04-02 18:13:42 +02:00
|
|
|
ShenandoahMarkingContext* ctx = _heap->marking_context();
|
2019-09-18 20:56:19 +02:00
|
|
|
const ShenandoahCollectionSet* const cset = _heap->collection_set();
|
|
|
|
T* end = src + count;
|
|
|
|
for (T* elem_ptr = src; elem_ptr < end; elem_ptr++) {
|
|
|
|
T o = RawAccess<>::oop_load(elem_ptr);
|
|
|
|
if (!CompressedOops::is_null(o)) {
|
|
|
|
oop obj = CompressedOops::decode_not_null(o);
|
|
|
|
if (HAS_FWD && cset->is_in((HeapWord *) obj)) {
|
|
|
|
assert(_heap->has_forwarded_objects(), "only get here with forwarded objects");
|
|
|
|
oop fwd = resolve_forwarded_not_null(obj);
|
|
|
|
if (EVAC && obj == fwd) {
|
|
|
|
fwd = _heap->evacuate_object(obj, thread);
|
|
|
|
}
|
|
|
|
assert(obj != fwd || _heap->cancelled_gc(), "must be forwarded");
|
|
|
|
oop witness = ShenandoahHeap::cas_oop(fwd, elem_ptr, o);
|
|
|
|
obj = fwd;
|
2018-12-10 15:47:44 +01:00
|
|
|
}
|
2019-09-18 20:56:19 +02:00
|
|
|
if (ENQUEUE && !ctx->is_marked(obj)) {
|
|
|
|
queue.enqueue_known_active(obj);
|
2018-12-10 15:47:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-18 20:56:19 +02:00
|
|
|
template <class T>
|
|
|
|
void ShenandoahBarrierSet::arraycopy_pre_work(T* src, T* dst, size_t count) {
|
|
|
|
if (_heap->is_concurrent_mark_in_progress()) {
|
|
|
|
if (_heap->has_forwarded_objects()) {
|
|
|
|
arraycopy_work<T, true, false, true>(dst, count);
|
|
|
|
} else {
|
|
|
|
arraycopy_work<T, false, false, true>(dst, count);
|
2018-12-10 15:47:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-18 20:56:19 +02:00
|
|
|
arraycopy_update_impl(src, count);
|
|
|
|
}
|
2018-12-10 15:47:44 +01:00
|
|
|
|
2019-09-18 20:56:19 +02:00
|
|
|
void ShenandoahBarrierSet::arraycopy_pre(oop* src, oop* dst, size_t count) {
|
|
|
|
arraycopy_pre_work(src, dst, count);
|
|
|
|
}
|
2018-12-10 15:47:44 +01:00
|
|
|
|
2019-09-18 20:56:19 +02:00
|
|
|
void ShenandoahBarrierSet::arraycopy_pre(narrowOop* src, narrowOop* dst, size_t count) {
|
|
|
|
arraycopy_pre_work(src, dst, count);
|
|
|
|
}
|
2018-12-10 15:47:44 +01:00
|
|
|
|
2019-09-18 20:56:19 +02:00
|
|
|
template <class T>
|
|
|
|
void ShenandoahBarrierSet::arraycopy_update_impl(T* src, size_t count) {
|
|
|
|
if (_heap->is_evacuation_in_progress()) {
|
|
|
|
ShenandoahEvacOOMScope oom_evac;
|
|
|
|
arraycopy_work<T, true, true, false>(src, count);
|
|
|
|
} else if (_heap->is_concurrent_traversal_in_progress()){
|
|
|
|
ShenandoahEvacOOMScope oom_evac;
|
|
|
|
arraycopy_work<T, true, true, true>(src, count);
|
|
|
|
} else if (_heap->has_forwarded_objects()) {
|
|
|
|
arraycopy_work<T, true, false, false>(src, count);
|
2018-12-10 15:47:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-18 20:56:19 +02:00
|
|
|
void ShenandoahBarrierSet::arraycopy_update(oop* src, size_t count) {
|
|
|
|
arraycopy_update_impl(src, count);
|
2018-12-10 15:47:44 +01:00
|
|
|
}
|
|
|
|
|
2019-09-18 20:56:19 +02:00
|
|
|
void ShenandoahBarrierSet::arraycopy_update(narrowOop* src, size_t count) {
|
|
|
|
arraycopy_update_impl(src, count);
|
|
|
|
}
|
|
|
|
|
2019-01-10 15:13:51 -05:00
|
|
|
#endif // SHARE_GC_SHENANDOAH_SHENANDOAHBARRIERSET_INLINE_HPP
|