< prev index next >

src/hotspot/share/gc/shared/cardTableBarrierSet.inline.hpp

Print this page

 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_GC_SHARED_CARDTABLEBARRIERSET_INLINE_HPP
 26 #define SHARE_GC_SHARED_CARDTABLEBARRIERSET_INLINE_HPP
 27 
 28 #include "gc/shared/cardTableBarrierSet.hpp"
 29 
 30 #include "gc/shared/barrierSet.hpp"
 31 #include "gc/shared/cardTable.hpp"
 32 #include "oops/compressedOops.inline.hpp"

 33 #include "oops/objArrayOop.hpp"
 34 #include "oops/oop.hpp"
 35 
 36 template <DecoratorSet decorators, typename T>
 37 inline void CardTableBarrierSet::write_ref_field_post(T* field) {
 38   volatile CardValue* byte = _card_table->byte_for(field);
 39   *byte = CardTable::dirty_card_val();
 40 }
 41 
 42 class Klass;
 43 
 44 // count is number of array elements being written
 45 void CardTableBarrierSet::write_ref_array(HeapWord* start, size_t count) {
 46   HeapWord* end = (HeapWord*)((char*)start + (count*heapOopSize));
 47   // In the case of compressed oops, start and end may potentially be misaligned;
 48   // so we need to conservatively align the first downward (this is not
 49   // strictly necessary for current uses, but a case of good hygiene and,
 50   // if you will, aesthetics) and the second upward (this is essential for
 51   // current uses) to a HeapWord boundary, so we mark all cards overlapping
 52   // this write. If this evolves in the future to calling a

 82   oop result = Raw::oop_atomic_cmpxchg(addr, compare_value, new_value);
 83   if (result == compare_value) {
 84     bs->template write_ref_field_post<decorators>(addr);
 85   }
 86   return result;
 87 }
 88 
 89 template <DecoratorSet decorators, typename BarrierSetT>
 90 template <typename T>
 91 inline oop CardTableBarrierSet::AccessBarrier<decorators, BarrierSetT>::
 92 oop_atomic_xchg_in_heap(T* addr, oop new_value) {
 93   BarrierSetT *bs = barrier_set_cast<BarrierSetT>(barrier_set());
 94   bs->template write_ref_field_pre<decorators>(addr);
 95   oop result = Raw::oop_atomic_xchg(addr, new_value);
 96   bs->template write_ref_field_post<decorators>(addr);
 97   return result;
 98 }
 99 
100 template <DecoratorSet decorators, typename BarrierSetT>
101 template <typename T>
102 inline bool CardTableBarrierSet::AccessBarrier<decorators, BarrierSetT>::











103 oop_arraycopy_in_heap(arrayOop src_obj, size_t src_offset_in_bytes, T* src_raw,
104                       arrayOop dst_obj, size_t dst_offset_in_bytes, T* dst_raw,
105                       size_t length) {
106   BarrierSetT *bs = barrier_set_cast<BarrierSetT>(barrier_set());
107 
108   src_raw = arrayOopDesc::obj_offset_to_raw(src_obj, src_offset_in_bytes, src_raw);
109   dst_raw = arrayOopDesc::obj_offset_to_raw(dst_obj, dst_offset_in_bytes, dst_raw);
110 
111   if (!HasDecorator<decorators, ARRAYCOPY_CHECKCAST>::value) {

112     // Optimized covariant case
113     bs->write_ref_array_pre(dst_raw, length,
114                             HasDecorator<decorators, IS_DEST_UNINITIALIZED>::value);
115     Raw::oop_arraycopy(nullptr, 0, src_raw, nullptr, 0, dst_raw, length);
116     bs->write_ref_array((HeapWord*)dst_raw, length);
117   } else {
118     assert(dst_obj != nullptr, "better have an actual oop");
119     Klass* bound = objArrayOop(dst_obj)->element_klass();
120     T* from = const_cast<T*>(src_raw);
121     T* end = from + length;
122     for (T* p = dst_raw; from < end; from++, p++) {
123       T element = *from;
124       if (oopDesc::is_instanceof_or_null(CompressedOops::decode(element), bound)) {
125         bs->template write_ref_field_pre<decorators>(p);
126         *p = element;
127       } else {
128         // We must do a barrier to cover the partial copy.
129         const size_t pd = pointer_delta(p, dst_raw, (size_t)heapOopSize);
130         // pointer delta is scaled to number of elements (length field in
131         // objArrayOop) which we assume is 32 bit.
132         assert(pd == (size_t)(int)pd, "length field overflow");
133         bs->write_ref_array((HeapWord*)dst_raw, pd);
134         return false;
135       }



136     }
137     bs->write_ref_array((HeapWord*)dst_raw, length);
138   }
139   return true;
140 }
141 
142 template <DecoratorSet decorators, typename BarrierSetT>
143 inline void CardTableBarrierSet::AccessBarrier<decorators, BarrierSetT>::
144 clone_in_heap(oop src, oop dst, size_t size) {
145   Raw::clone(src, dst, size);
146   BarrierSetT *bs = barrier_set_cast<BarrierSetT>(barrier_set());
147   bs->write_region(MemRegion((HeapWord*)(void*)dst, size));
148 }
149 






































150 #endif // SHARE_GC_SHARED_CARDTABLEBARRIERSET_INLINE_HPP

 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_GC_SHARED_CARDTABLEBARRIERSET_INLINE_HPP
 26 #define SHARE_GC_SHARED_CARDTABLEBARRIERSET_INLINE_HPP
 27 
 28 #include "gc/shared/cardTableBarrierSet.hpp"
 29 
 30 #include "gc/shared/barrierSet.hpp"
 31 #include "gc/shared/cardTable.hpp"
 32 #include "oops/compressedOops.inline.hpp"
 33 #include "oops/inlineKlass.inline.hpp"
 34 #include "oops/objArrayOop.hpp"
 35 #include "oops/oop.hpp"
 36 
 37 template <DecoratorSet decorators, typename T>
 38 inline void CardTableBarrierSet::write_ref_field_post(T* field) {
 39   volatile CardValue* byte = _card_table->byte_for(field);
 40   *byte = CardTable::dirty_card_val();
 41 }
 42 
 43 class Klass;
 44 
 45 // count is number of array elements being written
 46 void CardTableBarrierSet::write_ref_array(HeapWord* start, size_t count) {
 47   HeapWord* end = (HeapWord*)((char*)start + (count*heapOopSize));
 48   // In the case of compressed oops, start and end may potentially be misaligned;
 49   // so we need to conservatively align the first downward (this is not
 50   // strictly necessary for current uses, but a case of good hygiene and,
 51   // if you will, aesthetics) and the second upward (this is essential for
 52   // current uses) to a HeapWord boundary, so we mark all cards overlapping
 53   // this write. If this evolves in the future to calling a

 83   oop result = Raw::oop_atomic_cmpxchg(addr, compare_value, new_value);
 84   if (result == compare_value) {
 85     bs->template write_ref_field_post<decorators>(addr);
 86   }
 87   return result;
 88 }
 89 
 90 template <DecoratorSet decorators, typename BarrierSetT>
 91 template <typename T>
 92 inline oop CardTableBarrierSet::AccessBarrier<decorators, BarrierSetT>::
 93 oop_atomic_xchg_in_heap(T* addr, oop new_value) {
 94   BarrierSetT *bs = barrier_set_cast<BarrierSetT>(barrier_set());
 95   bs->template write_ref_field_pre<decorators>(addr);
 96   oop result = Raw::oop_atomic_xchg(addr, new_value);
 97   bs->template write_ref_field_post<decorators>(addr);
 98   return result;
 99 }
100 
101 template <DecoratorSet decorators, typename BarrierSetT>
102 template <typename T>
103 inline void CardTableBarrierSet::AccessBarrier<decorators, BarrierSetT>::
104 oop_arraycopy_partial_barrier(BarrierSetT *bs, T* dst_raw, T* p) {
105   const size_t pd = pointer_delta(p, dst_raw, (size_t)heapOopSize);
106   // pointer delta is scaled to number of elements (length field in
107   // objArrayOop) which we assume is 32 bit.
108   assert(pd == (size_t)(int)pd, "length field overflow");
109   bs->write_ref_array((HeapWord*)dst_raw, pd);
110 }
111 
112 template <DecoratorSet decorators, typename BarrierSetT>
113 template <typename T>
114 inline void CardTableBarrierSet::AccessBarrier<decorators, BarrierSetT>::
115 oop_arraycopy_in_heap(arrayOop src_obj, size_t src_offset_in_bytes, T* src_raw,
116                       arrayOop dst_obj, size_t dst_offset_in_bytes, T* dst_raw,
117                       size_t length) {
118   BarrierSetT *bs = barrier_set_cast<BarrierSetT>(barrier_set());
119 
120   src_raw = arrayOopDesc::obj_offset_to_raw(src_obj, src_offset_in_bytes, src_raw);
121   dst_raw = arrayOopDesc::obj_offset_to_raw(dst_obj, dst_offset_in_bytes, dst_raw);
122 
123   if ((!HasDecorator<decorators, ARRAYCOPY_CHECKCAST>::value) &&
124       (!HasDecorator<decorators, ARRAYCOPY_NOTNULL>::value)) {
125     // Optimized covariant case
126     bs->write_ref_array_pre(dst_raw, length,
127                             HasDecorator<decorators, IS_DEST_UNINITIALIZED>::value);
128     Raw::oop_arraycopy(nullptr, 0, src_raw, nullptr, 0, dst_raw, length);
129     bs->write_ref_array((HeapWord*)dst_raw, length);
130   } else {
131     assert(dst_obj != nullptr, "better have an actual oop");
132     Klass* bound = objArrayOop(dst_obj)->element_klass();
133     T* from = const_cast<T*>(src_raw);
134     T* end = from + length;
135     for (T* p = dst_raw; from < end; from++, p++) {
136       T element = *from;
137       // Apply any required checks
138       if (HasDecorator<decorators, ARRAYCOPY_NOTNULL>::value && CompressedOops::is_null(element)) {
139         oop_arraycopy_partial_barrier(bs, dst_raw, p);
140         throw_array_null_pointer_store_exception(src_obj, dst_obj, JavaThread::current());
141         return;
142       }
143       if (HasDecorator<decorators, ARRAYCOPY_CHECKCAST>::value &&
144           (!oopDesc::is_instanceof_or_null(CompressedOops::decode(element), bound))) {
145         oop_arraycopy_partial_barrier(bs, dst_raw, p);
146         throw_array_store_exception(src_obj, dst_obj, JavaThread::current());
147         return;
148       }
149       // write
150       bs->template write_ref_field_pre<decorators>(p);
151       *p = element;
152     }
153     bs->write_ref_array((HeapWord*)dst_raw, length);
154   }

155 }
156 
157 template <DecoratorSet decorators, typename BarrierSetT>
158 inline void CardTableBarrierSet::AccessBarrier<decorators, BarrierSetT>::
159 clone_in_heap(oop src, oop dst, size_t size) {
160   Raw::clone(src, dst, size);
161   BarrierSetT *bs = barrier_set_cast<BarrierSetT>(barrier_set());
162   bs->write_region(MemRegion((HeapWord*)(void*)dst, size));
163 }
164 
165 template <DecoratorSet decorators, typename BarrierSetT>
166 inline void CardTableBarrierSet::AccessBarrier<decorators, BarrierSetT>::
167 value_copy_in_heap(void* src, void* dst, InlineKlass* md, LayoutKind lk) {
168   if (!md->contains_oops()) {
169     // If we do not have oops in the flat array, we can just do a raw copy.
170     Raw::value_copy(src, dst, md, lk);
171   } else {
172     BarrierSetT* bs = barrier_set_cast<BarrierSetT>(BarrierSet::barrier_set());
173     // src/dst aren't oops, need offset to adjust oop map offset
174     const address dst_oop_addr_offset = ((address) dst) - md->payload_offset();
175     typedef typename ValueOopType<decorators>::type OopType;
176 
177     // Pre-barriers...
178     OopMapBlock* map = md->start_of_nonstatic_oop_maps();
179     OopMapBlock* const end = map + md->nonstatic_oop_map_count();
180     bool is_uninitialized = HasDecorator<decorators, IS_DEST_UNINITIALIZED>::value;
181     while (map != end) {
182       address doop_address = dst_oop_addr_offset + map->offset();
183       // The pre-barrier only impacts G1, which will emit a barrier if the destination is
184       // initialized. Note that we should not emit a barrier if the destination is uninitialized,
185       // as doing so will fill the SATB queue with garbage data.
186       bs->write_ref_array_pre((OopType*) doop_address, map->count(), is_uninitialized);
187       map++;
188     }
189 
190     Raw::value_copy(src, dst, md, lk);
191 
192     // Post-barriers...
193     map = md->start_of_nonstatic_oop_maps();
194     while (map != end) {
195       address doop_address = dst_oop_addr_offset + map->offset();
196       // The post-barrier needs to be called for initialized and uninitialized destinations.
197       bs->write_ref_array((HeapWord*) doop_address, map->count());
198       map++;
199     }
200   }
201 }
202 
203 #endif // SHARE_GC_SHARED_CARDTABLEBARRIERSET_INLINE_HPP
< prev index next >