< 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
 53   // logging barrier of narrow oop granularity, like the pre-barrier for G1
 54   // (mentioned here merely by way of example), we will need to change this

 80   BarrierSetT *bs = barrier_set_cast<BarrierSetT>(barrier_set());
 81   bs->template write_ref_field_pre<decorators>(addr);
 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 OopCopyResult 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         if (pd > 0) {
134           // Copied at least one element; call the barrier.
135           bs->write_ref_array((HeapWord*)dst_raw, pd);
136         }
137         return OopCopyResult::failed_check_class_cast;
138       }



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










































































154 #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/layoutKind.hpp"
 35 #include "oops/objArrayOop.hpp"
 36 #include "oops/oop.hpp"
 37 #include "utilities/debug.hpp"
 38 
 39 template <DecoratorSet decorators, typename T>
 40 inline void CardTableBarrierSet::write_ref_field_post(T* field) {
 41   volatile CardValue* byte = card_table()->byte_for(field);
 42   *byte = CardTable::dirty_card_val();
 43 }
 44 
 45 class Klass;
 46 
 47 // count is number of array elements being written
 48 void CardTableBarrierSet::write_ref_array(HeapWord* start, size_t count) {
 49   HeapWord* end = (HeapWord*)((char*)start + (count*heapOopSize));
 50   // In the case of compressed oops, start and end may potentially be misaligned;
 51   // so we need to conservatively align the first downward (this is not
 52   // strictly necessary for current uses, but a case of good hygiene and,
 53   // if you will, aesthetics) and the second upward (this is essential for
 54   // current uses) to a HeapWord boundary, so we mark all cards overlapping
 55   // this write. If this evolves in the future to calling a
 56   // logging barrier of narrow oop granularity, like the pre-barrier for G1
 57   // (mentioned here merely by way of example), we will need to change this

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





151         return OopCopyResult::failed_check_class_cast;
152       }
153       // write
154       bs->template write_ref_field_pre<decorators>(p);
155       *p = element;
156     }
157     bs->write_ref_array((HeapWord*)dst_raw, length);
158   }
159 
160   return OopCopyResult::ok;
161 }
162 
163 template <DecoratorSet decorators, typename BarrierSetT>
164 inline void CardTableBarrierSet::AccessBarrier<decorators, BarrierSetT>::
165 clone_in_heap(oop src, oop dst, size_t size) {
166   Raw::clone(src, dst, size);
167   BarrierSetT *bs = barrier_set_cast<BarrierSetT>(barrier_set());
168   bs->write_region(MemRegion((HeapWord*)(void*)dst, size));
169 }
170 
171 template <DecoratorSet decorators, typename BarrierSetT>
172 inline void CardTableBarrierSet::AccessBarrier<decorators, BarrierSetT>::
173 value_copy_in_heap(const ValuePayload& src, const ValuePayload& dst) {
174   precond(src.klass() == dst.klass());
175 
176   const InlineKlass* md = src.klass();
177   if (!md->contains_oops()) {
178     // If we do not have oops in the flat array, we can just do a raw copy.
179     Raw::value_copy(src, dst);
180   } else {
181     BarrierSetT* bs = barrier_set_cast<BarrierSetT>(BarrierSet::barrier_set());
182     // addr() points at the payload start, the oop map offset are relative to
183     // the object header, adjust address to account for this discrepancy.
184     const address oop_map_adjusted_dst_addr = dst.addr() - md->payload_offset();
185     typedef typename ValueOopType<decorators>::type OopType;
186 
187     // Pre-barriers...
188     if (!HasDecorator<decorators, IS_DEST_UNINITIALIZED>::value) {
189       OopMapBlock* map = md->start_of_nonstatic_oop_maps();
190       OopMapBlock* const end = map + md->nonstatic_oop_map_count();
191 
192       while (map != end) {
193         address doop_address = oop_map_adjusted_dst_addr + map->offset();
194 
195         bs->write_ref_array_pre((OopType*) doop_address, map->count());
196         map++;
197       }
198     }
199 
200     Raw::value_copy(src, dst);
201 
202     // Post-barriers...
203     OopMapBlock* map = md->start_of_nonstatic_oop_maps();
204     OopMapBlock* const end = map + md->nonstatic_oop_map_count();
205     while (map != end) {
206       address doop_address = oop_map_adjusted_dst_addr + map->offset();
207       // The post-barrier needs to be called for initialized and uninitialized destinations.
208       bs->write_ref_array((HeapWord*) doop_address, map->count());
209       map++;
210     }
211   }
212 }
213 
214 template <DecoratorSet decorators, typename BarrierSetT>
215 inline void CardTableBarrierSet::AccessBarrier<decorators, BarrierSetT>::
216 value_store_null_in_heap(const ValuePayload& dst) {
217   const InlineKlass* md = dst.klass();
218   if (!md->contains_oops()) {
219     // If we do not have oops in the flat array, we can just do a raw clear.
220     Raw::value_store_null(dst);
221   } else {
222     BarrierSetT* bs = barrier_set_cast<BarrierSetT>(BarrierSet::barrier_set());
223     // addr() points at the payload start, the oop map offset are relative to
224     // the object header, adjust address to account for this discrepancy.
225     const address oop_map_adjusted_dst_addr = dst.addr() - md->payload_offset();
226     typedef typename ValueOopType<decorators>::type OopType;
227 
228     // Pre-barriers...
229     if (!HasDecorator<decorators, IS_DEST_UNINITIALIZED>::value) {
230       OopMapBlock* map = md->start_of_nonstatic_oop_maps();
231       OopMapBlock* const end = map + md->nonstatic_oop_map_count();
232       while (map != end) {
233         address doop_address = oop_map_adjusted_dst_addr + map->offset();
234         bs->write_ref_array_pre((OopType*) doop_address, map->count());
235         map++;
236       }
237     }
238 
239     Raw::value_store_null(dst);
240 
241     // Storing null does not require post-barriers
242   }
243 }
244 
245 #endif // SHARE_GC_SHARED_CARDTABLEBARRIERSET_INLINE_HPP
< prev index next >