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_GC_SHARED_MODREFBARRIERSET_INLINE_HPP
26 #define SHARE_GC_SHARED_MODREFBARRIERSET_INLINE_HPP
27
28 #include "gc/shared/modRefBarrierSet.hpp"
29
30 #include "gc/shared/barrierSet.hpp"
31 #include "oops/compressedOops.inline.hpp"
32 #include "oops/objArrayOop.hpp"
33 #include "oops/oop.hpp"
34 #include "runtime/thread.hpp"
35
36 class Klass;
37
38 // count is number of array elements being written
39 void ModRefBarrierSet::write_ref_array(HeapWord* start, size_t count) {
40 HeapWord* end = (HeapWord*)((char*)start + (count*heapOopSize));
41 // In the case of compressed oops, start and end may potentially be misaligned;
42 // so we need to conservatively align the first downward (this is not
43 // strictly necessary for current uses, but a case of good hygiene and,
44 // if you will, aesthetics) and the second upward (this is essential for
45 // current uses) to a HeapWord boundary, so we mark all cards overlapping
46 // this write. If this evolves in the future to calling a
47 // logging barrier of narrow oop granularity, like the pre-barrier for G1
48 // (mentioned here merely by way of example), we will need to change this
49 // interface, so it is "exactly precise" (if i may be allowed the adverbial
50 // redundancy for emphasis) and does not include narrow oop slots not
51 // included in the original write interval.
52 HeapWord* aligned_start = align_down(start, HeapWordSize);
53 HeapWord* aligned_end = align_up (end, HeapWordSize);
76 oop result = Raw::oop_atomic_cmpxchg(addr, compare_value, new_value);
77 if (result == compare_value) {
78 bs->template write_ref_field_post<decorators>(addr);
79 }
80 return result;
81 }
82
83 template <DecoratorSet decorators, typename BarrierSetT>
84 template <typename T>
85 inline oop ModRefBarrierSet::AccessBarrier<decorators, BarrierSetT>::
86 oop_atomic_xchg_in_heap(T* addr, oop new_value) {
87 BarrierSetT *bs = barrier_set_cast<BarrierSetT>(barrier_set());
88 bs->template write_ref_field_pre<decorators>(addr);
89 oop result = Raw::oop_atomic_xchg(addr, new_value);
90 bs->template write_ref_field_post<decorators>(addr);
91 return result;
92 }
93
94 template <DecoratorSet decorators, typename BarrierSetT>
95 template <typename T>
96 inline bool ModRefBarrierSet::AccessBarrier<decorators, BarrierSetT>::
97 oop_arraycopy_in_heap(arrayOop src_obj, size_t src_offset_in_bytes, T* src_raw,
98 arrayOop dst_obj, size_t dst_offset_in_bytes, T* dst_raw,
99 size_t length) {
100 BarrierSetT *bs = barrier_set_cast<BarrierSetT>(barrier_set());
101
102 src_raw = arrayOopDesc::obj_offset_to_raw(src_obj, src_offset_in_bytes, src_raw);
103 dst_raw = arrayOopDesc::obj_offset_to_raw(dst_obj, dst_offset_in_bytes, dst_raw);
104
105 if (!HasDecorator<decorators, ARRAYCOPY_CHECKCAST>::value) {
106 // Optimized covariant case
107 bs->write_ref_array_pre(dst_raw, length,
108 HasDecorator<decorators, IS_DEST_UNINITIALIZED>::value);
109 Raw::oop_arraycopy(nullptr, 0, src_raw, nullptr, 0, dst_raw, length);
110 bs->write_ref_array((HeapWord*)dst_raw, length);
111 } else {
112 assert(dst_obj != nullptr, "better have an actual oop");
113 Klass* bound = objArrayOop(dst_obj)->element_klass();
114 T* from = const_cast<T*>(src_raw);
115 T* end = from + length;
116 for (T* p = dst_raw; from < end; from++, p++) {
117 T element = *from;
118 if (oopDesc::is_instanceof_or_null(CompressedOops::decode(element), bound)) {
119 bs->template write_ref_field_pre<decorators>(p);
120 *p = element;
121 } else {
122 // We must do a barrier to cover the partial copy.
123 const size_t pd = pointer_delta(p, dst_raw, (size_t)heapOopSize);
124 // pointer delta is scaled to number of elements (length field in
125 // objArrayOop) which we assume is 32 bit.
126 assert(pd == (size_t)(int)pd, "length field overflow");
127 bs->write_ref_array((HeapWord*)dst_raw, pd);
128 return false;
129 }
130 }
131 bs->write_ref_array((HeapWord*)dst_raw, length);
132 }
133 return true;
134 }
135
136 template <DecoratorSet decorators, typename BarrierSetT>
137 inline void ModRefBarrierSet::AccessBarrier<decorators, BarrierSetT>::
138 clone_in_heap(oop src, oop dst, size_t size) {
139 Raw::clone(src, dst, size);
140 BarrierSetT *bs = barrier_set_cast<BarrierSetT>(barrier_set());
141 bs->write_region(MemRegion((HeapWord*)(void*)dst, size));
142 }
143
144 #endif // SHARE_GC_SHARED_MODREFBARRIERSET_INLINE_HPP
|
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_GC_SHARED_MODREFBARRIERSET_INLINE_HPP
26 #define SHARE_GC_SHARED_MODREFBARRIERSET_INLINE_HPP
27
28 #include "gc/shared/modRefBarrierSet.hpp"
29
30 #include "gc/shared/barrierSet.hpp"
31 #include "oops/compressedOops.inline.hpp"
32 #include "oops/objArrayOop.hpp"
33 #include "oops/oop.hpp"
34 #include "oops/inlineKlass.inline.hpp"
35 #include "runtime/thread.hpp"
36
37 class Klass;
38
39 // count is number of array elements being written
40 void ModRefBarrierSet::write_ref_array(HeapWord* start, size_t count) {
41 HeapWord* end = (HeapWord*)((char*)start + (count*heapOopSize));
42 // In the case of compressed oops, start and end may potentially be misaligned;
43 // so we need to conservatively align the first downward (this is not
44 // strictly necessary for current uses, but a case of good hygiene and,
45 // if you will, aesthetics) and the second upward (this is essential for
46 // current uses) to a HeapWord boundary, so we mark all cards overlapping
47 // this write. If this evolves in the future to calling a
48 // logging barrier of narrow oop granularity, like the pre-barrier for G1
49 // (mentioned here merely by way of example), we will need to change this
50 // interface, so it is "exactly precise" (if i may be allowed the adverbial
51 // redundancy for emphasis) and does not include narrow oop slots not
52 // included in the original write interval.
53 HeapWord* aligned_start = align_down(start, HeapWordSize);
54 HeapWord* aligned_end = align_up (end, HeapWordSize);
77 oop result = Raw::oop_atomic_cmpxchg(addr, compare_value, new_value);
78 if (result == compare_value) {
79 bs->template write_ref_field_post<decorators>(addr);
80 }
81 return result;
82 }
83
84 template <DecoratorSet decorators, typename BarrierSetT>
85 template <typename T>
86 inline oop ModRefBarrierSet::AccessBarrier<decorators, BarrierSetT>::
87 oop_atomic_xchg_in_heap(T* addr, oop new_value) {
88 BarrierSetT *bs = barrier_set_cast<BarrierSetT>(barrier_set());
89 bs->template write_ref_field_pre<decorators>(addr);
90 oop result = Raw::oop_atomic_xchg(addr, new_value);
91 bs->template write_ref_field_post<decorators>(addr);
92 return result;
93 }
94
95 template <DecoratorSet decorators, typename BarrierSetT>
96 template <typename T>
97 inline void ModRefBarrierSet::AccessBarrier<decorators, BarrierSetT>::
98 oop_arraycopy_partial_barrier(BarrierSetT *bs, T* dst_raw, T* p) {
99 const size_t pd = pointer_delta(p, dst_raw, (size_t)heapOopSize);
100 // pointer delta is scaled to number of elements (length field in
101 // objArrayOop) which we assume is 32 bit.
102 assert(pd == (size_t)(int)pd, "length field overflow");
103 bs->write_ref_array((HeapWord*)dst_raw, pd);
104 }
105
106 template <DecoratorSet decorators, typename BarrierSetT>
107 template <typename T>
108 inline void ModRefBarrierSet::AccessBarrier<decorators, BarrierSetT>::
109 oop_arraycopy_in_heap(arrayOop src_obj, size_t src_offset_in_bytes, T* src_raw,
110 arrayOop dst_obj, size_t dst_offset_in_bytes, T* dst_raw,
111 size_t length) {
112 BarrierSetT *bs = barrier_set_cast<BarrierSetT>(barrier_set());
113
114 src_raw = arrayOopDesc::obj_offset_to_raw(src_obj, src_offset_in_bytes, src_raw);
115 dst_raw = arrayOopDesc::obj_offset_to_raw(dst_obj, dst_offset_in_bytes, dst_raw);
116
117 if ((!HasDecorator<decorators, ARRAYCOPY_CHECKCAST>::value) &&
118 (!HasDecorator<decorators, ARRAYCOPY_NOTNULL>::value)) {
119 // Optimized covariant case
120 bs->write_ref_array_pre(dst_raw, length,
121 HasDecorator<decorators, IS_DEST_UNINITIALIZED>::value);
122 Raw::oop_arraycopy(nullptr, 0, src_raw, nullptr, 0, dst_raw, length);
123 bs->write_ref_array((HeapWord*)dst_raw, length);
124 } else {
125 assert(dst_obj != nullptr, "better have an actual oop");
126 Klass* bound = objArrayOop(dst_obj)->element_klass();
127 T* from = const_cast<T*>(src_raw);
128 T* end = from + length;
129 for (T* p = dst_raw; from < end; from++, p++) {
130 T element = *from;
131 // Apply any required checks
132 if (HasDecorator<decorators, ARRAYCOPY_NOTNULL>::value && CompressedOops::is_null(element)) {
133 oop_arraycopy_partial_barrier(bs, dst_raw, p);
134 throw_array_null_pointer_store_exception(src_obj, dst_obj, JavaThread::current());
135 return;
136 }
137 if (HasDecorator<decorators, ARRAYCOPY_CHECKCAST>::value &&
138 (!oopDesc::is_instanceof_or_null(CompressedOops::decode(element), bound))) {
139 oop_arraycopy_partial_barrier(bs, dst_raw, p);
140 throw_array_store_exception(src_obj, dst_obj, JavaThread::current());
141 return;
142 }
143 // write
144 bs->template write_ref_field_pre<decorators>(p);
145 *p = element;
146 }
147 bs->write_ref_array((HeapWord*)dst_raw, length);
148 }
149 }
150
151 template <DecoratorSet decorators, typename BarrierSetT>
152 inline void ModRefBarrierSet::AccessBarrier<decorators, BarrierSetT>::
153 clone_in_heap(oop src, oop dst, size_t size) {
154 Raw::clone(src, dst, size);
155 BarrierSetT *bs = barrier_set_cast<BarrierSetT>(barrier_set());
156 bs->write_region(MemRegion((HeapWord*)(void*)dst, size));
157 }
158
159 template <DecoratorSet decorators, typename BarrierSetT>
160 inline void ModRefBarrierSet::AccessBarrier<decorators, BarrierSetT>::
161 value_copy_in_heap(void* src, void* dst, InlineKlass* md, LayoutKind lk) {
162 if (HasDecorator<decorators, IS_DEST_UNINITIALIZED>::value || (!md->contains_oops())) {
163 Raw::value_copy(src, dst, md, lk);
164 } else {
165 BarrierSetT* bs = barrier_set_cast<BarrierSetT>(BarrierSet::barrier_set());
166 // src/dst aren't oops, need offset to adjust oop map offset
167 const address dst_oop_addr_offset = ((address) dst) - md->first_field_offset();
168 typedef typename ValueOopType<decorators>::type OopType;
169
170 // Pre-barriers...
171 OopMapBlock* map = md->start_of_nonstatic_oop_maps();
172 OopMapBlock* const end = map + md->nonstatic_oop_map_count();
173 while (map != end) {
174 address doop_address = dst_oop_addr_offset + map->offset();
175 bs->write_ref_array_pre((OopType*) doop_address, map->count(), false);
176 map++;
177 }
178
179 Raw::value_copy(src, dst, md, lk);
180
181 // Post-barriers...
182 map = md->start_of_nonstatic_oop_maps();
183 while (map != end) {
184 address doop_address = dst_oop_addr_offset + map->offset();
185 bs->write_ref_array((HeapWord*) doop_address, map->count());
186 map++;
187 }
188 }
189 }
190
191 #endif // SHARE_GC_SHARED_MODREFBARRIERSET_INLINE_HPP
|