|
1 /* |
|
2 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
5 * This code is free software; you can redistribute it and/or modify it |
|
6 * under the terms of the GNU General Public License version 2 only, as |
|
7 * published by the Free Software Foundation. |
|
8 * |
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
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 |
|
25 #ifndef SHARE_VM_GC_SHARED_MODREFBARRIERSET_INLINE_HPP |
|
26 #define SHARE_VM_GC_SHARED_MODREFBARRIERSET_INLINE_HPP |
|
27 |
|
28 #include "gc/shared/modRefBarrierSet.hpp" |
|
29 #include "oops/klass.inline.hpp" |
|
30 #include "oops/objArrayOop.hpp" |
|
31 #include "oops/oop.hpp" |
|
32 |
|
33 template <DecoratorSet decorators, typename BarrierSetT> |
|
34 template <typename T> |
|
35 inline void ModRefBarrierSet::AccessBarrier<decorators, BarrierSetT>:: |
|
36 oop_store_in_heap(T* addr, oop value) { |
|
37 BarrierSetT *bs = barrier_set_cast<BarrierSetT>(barrier_set()); |
|
38 bs->template write_ref_field_pre<decorators>(addr); |
|
39 Raw::oop_store(addr, value); |
|
40 bs->template write_ref_field_post<decorators>(addr, value); |
|
41 } |
|
42 |
|
43 template <DecoratorSet decorators, typename BarrierSetT> |
|
44 template <typename T> |
|
45 inline oop ModRefBarrierSet::AccessBarrier<decorators, BarrierSetT>:: |
|
46 oop_atomic_cmpxchg_in_heap(oop new_value, T* addr, oop compare_value) { |
|
47 BarrierSetT *bs = barrier_set_cast<BarrierSetT>(barrier_set()); |
|
48 bs->template write_ref_field_pre<decorators>(addr); |
|
49 oop result = Raw::oop_atomic_cmpxchg(new_value, addr, compare_value); |
|
50 if (result == compare_value) { |
|
51 bs->template write_ref_field_post<decorators>(addr, new_value); |
|
52 } |
|
53 return result; |
|
54 } |
|
55 |
|
56 template <DecoratorSet decorators, typename BarrierSetT> |
|
57 template <typename T> |
|
58 inline oop ModRefBarrierSet::AccessBarrier<decorators, BarrierSetT>:: |
|
59 oop_atomic_xchg_in_heap(oop new_value, T* addr) { |
|
60 BarrierSetT *bs = barrier_set_cast<BarrierSetT>(barrier_set()); |
|
61 bs->template write_ref_field_pre<decorators>(addr); |
|
62 oop result = Raw::oop_atomic_xchg(new_value, addr); |
|
63 bs->template write_ref_field_post<decorators>(addr, new_value); |
|
64 return result; |
|
65 } |
|
66 |
|
67 template <DecoratorSet decorators, typename BarrierSetT> |
|
68 template <typename T> |
|
69 inline bool ModRefBarrierSet::AccessBarrier<decorators, BarrierSetT>:: |
|
70 oop_arraycopy_in_heap(arrayOop src_obj, arrayOop dst_obj, T* src, T* dst, size_t length) { |
|
71 BarrierSetT *bs = barrier_set_cast<BarrierSetT>(barrier_set()); |
|
72 |
|
73 if (!HasDecorator<decorators, ARRAYCOPY_CHECKCAST>::value) { |
|
74 // Optimized covariant case |
|
75 bs->write_ref_array_pre(dst, (int)length, |
|
76 HasDecorator<decorators, ARRAYCOPY_DEST_NOT_INITIALIZED>::value); |
|
77 Raw::oop_arraycopy(src_obj, dst_obj, src, dst, length); |
|
78 bs->write_ref_array((HeapWord*)dst, length); |
|
79 } else { |
|
80 Klass* bound = objArrayOop(dst_obj)->element_klass(); |
|
81 T* from = src; |
|
82 T* end = from + length; |
|
83 for (T* p = dst; from < end; from++, p++) { |
|
84 T element = *from; |
|
85 if (bound->is_instanceof_or_null(element)) { |
|
86 bs->template write_ref_field_pre<decorators>(p); |
|
87 *p = element; |
|
88 } else { |
|
89 // We must do a barrier to cover the partial copy. |
|
90 const size_t pd = pointer_delta(p, dst, (size_t)heapOopSize); |
|
91 // pointer delta is scaled to number of elements (length field in |
|
92 // objArrayOop) which we assume is 32 bit. |
|
93 assert(pd == (size_t)(int)pd, "length field overflow"); |
|
94 bs->write_ref_array((HeapWord*)dst, pd); |
|
95 return false; |
|
96 } |
|
97 } |
|
98 bs->write_ref_array((HeapWord*)dst, length); |
|
99 } |
|
100 return true; |
|
101 } |
|
102 |
|
103 template <DecoratorSet decorators, typename BarrierSetT> |
|
104 inline void ModRefBarrierSet::AccessBarrier<decorators, BarrierSetT>:: |
|
105 clone_in_heap(oop src, oop dst, size_t size) { |
|
106 Raw::clone(src, dst, size); |
|
107 BarrierSetT *bs = barrier_set_cast<BarrierSetT>(barrier_set()); |
|
108 bs->write_region(MemRegion((HeapWord*)(void*)dst, size)); |
|
109 } |
|
110 |
|
111 #endif // SHARE_VM_GC_SHARED_MODREFBARRIERSET_INLINE_HPP |