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 #include "precompiled.hpp"
26 #include "gc_implementation/g1/g1CollectedHeap.inline.hpp"
27 #include "gc_implementation/g1/g1SATBCardTableModRefBS.hpp"
28 #include "gc_implementation/g1/heapRegion.hpp"
29 #include "gc_implementation/g1/satbQueue.hpp"
30 #include "oops/oop.inline.hpp"
31 #include "runtime/atomic.inline.hpp"
32 #include "runtime/mutexLocker.hpp"
33 #include "runtime/orderAccess.inline.hpp"
34 #include "runtime/thread.inline.hpp"
35
36 G1SATBCardTableModRefBS::G1SATBCardTableModRefBS(MemRegion whole_heap, BarrierSet::Name kind) :
37 CardTableModRefBS(whole_heap, kind) { }
38
39 void G1SATBCardTableModRefBS::enqueue(oop pre_val) {
40 // Nulls should have been already filtered.
41 assert(pre_val->is_oop(true), "Error");
42
43 if (!JavaThread::satb_mark_queue_set().is_active()) return;
44 Thread* thr = Thread::current();
45 if (thr->is_Java_thread()) {
46 JavaThread* jt = (JavaThread*)thr;
47 jt->satb_mark_queue().enqueue(pre_val);
48 } else {
49 MutexLockerEx x(Shared_SATB_Q_lock, Mutex::_no_safepoint_check_flag);
50 JavaThread::satb_mark_queue_set().shared_satb_queue()->enqueue(pre_val);
51 }
52 }
53
54 template <class T> void
55 G1SATBCardTableModRefBS::write_ref_array_pre_work(T* dst, int count) {
56 if (!JavaThread::satb_mark_queue_set().is_active()) return;
57 T* elem_ptr = dst;
113 for (jbyte* i = first; i < last; i++) {
114 *i = g1_young_gen;
115 }
116 }
117 }
118
119 #ifndef PRODUCT
120 void G1SATBCardTableModRefBS::verify_g1_young_region(MemRegion mr) {
121 verify_region(mr, g1_young_gen, true);
122 }
123 #endif
124
125 void G1SATBCardTableLoggingModRefBSChangedListener::on_commit(uint start_idx, size_t num_regions, bool zero_filled) {
126 // Default value for a clean card on the card table is -1. So we cannot take advantage of the zero_filled parameter.
127 MemRegion mr(G1CollectedHeap::heap()->bottom_addr_for_region(start_idx), num_regions * HeapRegion::GrainWords);
128 _card_table->clear(mr);
129 }
130
131 G1SATBCardTableLoggingModRefBS::
132 G1SATBCardTableLoggingModRefBS(MemRegion whole_heap) :
133 G1SATBCardTableModRefBS(whole_heap, BarrierSet::G1SATBCTLogging),
134 _dcqs(JavaThread::dirty_card_queue_set()),
135 _listener()
136 {
137 _listener.set_card_table(this);
138 }
139
140 void G1SATBCardTableLoggingModRefBS::initialize(G1RegionToSpaceMapper* mapper) {
141 mapper->set_mapping_changed_listener(&_listener);
142
143 _byte_map_size = mapper->reserved().byte_size();
144
145 _guard_index = cards_required(_whole_heap.word_size()) - 1;
146 _last_valid_index = _guard_index - 1;
147
148 HeapWord* low_bound = _whole_heap.start();
149 HeapWord* high_bound = _whole_heap.end();
150
151 _cur_covered_regions = 1;
152 _covered[0] = _whole_heap;
153
186 jt->dirty_card_queue().enqueue(byte);
187 } else {
188 MutexLockerEx x(Shared_DirtyCardQ_lock,
189 Mutex::_no_safepoint_check_flag);
190 _dcqs.shared_dirty_card_queue()->enqueue(byte);
191 }
192 }
193 }
194
195 void
196 G1SATBCardTableLoggingModRefBS::write_ref_field_static(void* field,
197 oop new_val) {
198 uintptr_t field_uint = (uintptr_t)field;
199 uintptr_t new_val_uint = cast_from_oop<uintptr_t>(new_val);
200 uintptr_t comb = field_uint ^ new_val_uint;
201 comb = comb >> HeapRegion::LogOfHRGrainBytes;
202 if (comb == 0) return;
203 if (new_val == NULL) return;
204 // Otherwise, log it.
205 G1SATBCardTableLoggingModRefBS* g1_bs =
206 (G1SATBCardTableLoggingModRefBS*)Universe::heap()->barrier_set();
207 g1_bs->write_ref_field_work(field, new_val);
208 }
209
210 void
211 G1SATBCardTableLoggingModRefBS::invalidate(MemRegion mr, bool whole_heap) {
212 volatile jbyte* byte = byte_for(mr.start());
213 jbyte* last_byte = byte_for(mr.last());
214 Thread* thr = Thread::current();
215 if (whole_heap) {
216 while (byte <= last_byte) {
217 *byte = dirty_card;
218 byte++;
219 }
220 } else {
221 // skip all consecutive young cards
222 for (; byte <= last_byte && *byte == g1_young_gen; byte++);
223
224 if (byte <= last_byte) {
225 OrderAccess::storeload();
226 // Enqueue if necessary.
|
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 #include "precompiled.hpp"
26 #include "gc_implementation/g1/g1CollectedHeap.inline.hpp"
27 #include "gc_implementation/g1/g1SATBCardTableModRefBS.hpp"
28 #include "gc_implementation/g1/heapRegion.hpp"
29 #include "gc_implementation/g1/satbQueue.hpp"
30 #include "oops/oop.inline.hpp"
31 #include "runtime/atomic.inline.hpp"
32 #include "runtime/mutexLocker.hpp"
33 #include "runtime/orderAccess.inline.hpp"
34 #include "runtime/thread.inline.hpp"
35
36 G1SATBCardTableModRefBS::G1SATBCardTableModRefBS(
37 MemRegion whole_heap,
38 const BarrierSet::FakeRtti& fake_rtti) :
39 CardTableModRefBS(whole_heap, fake_rtti.add_tag(BarrierSet::G1SATBCT))
40 { }
41
42 void G1SATBCardTableModRefBS::enqueue(oop pre_val) {
43 // Nulls should have been already filtered.
44 assert(pre_val->is_oop(true), "Error");
45
46 if (!JavaThread::satb_mark_queue_set().is_active()) return;
47 Thread* thr = Thread::current();
48 if (thr->is_Java_thread()) {
49 JavaThread* jt = (JavaThread*)thr;
50 jt->satb_mark_queue().enqueue(pre_val);
51 } else {
52 MutexLockerEx x(Shared_SATB_Q_lock, Mutex::_no_safepoint_check_flag);
53 JavaThread::satb_mark_queue_set().shared_satb_queue()->enqueue(pre_val);
54 }
55 }
56
57 template <class T> void
58 G1SATBCardTableModRefBS::write_ref_array_pre_work(T* dst, int count) {
59 if (!JavaThread::satb_mark_queue_set().is_active()) return;
60 T* elem_ptr = dst;
116 for (jbyte* i = first; i < last; i++) {
117 *i = g1_young_gen;
118 }
119 }
120 }
121
122 #ifndef PRODUCT
123 void G1SATBCardTableModRefBS::verify_g1_young_region(MemRegion mr) {
124 verify_region(mr, g1_young_gen, true);
125 }
126 #endif
127
128 void G1SATBCardTableLoggingModRefBSChangedListener::on_commit(uint start_idx, size_t num_regions, bool zero_filled) {
129 // Default value for a clean card on the card table is -1. So we cannot take advantage of the zero_filled parameter.
130 MemRegion mr(G1CollectedHeap::heap()->bottom_addr_for_region(start_idx), num_regions * HeapRegion::GrainWords);
131 _card_table->clear(mr);
132 }
133
134 G1SATBCardTableLoggingModRefBS::
135 G1SATBCardTableLoggingModRefBS(MemRegion whole_heap) :
136 G1SATBCardTableModRefBS(whole_heap, BarrierSet::FakeRtti(G1SATBCTLogging)),
137 _dcqs(JavaThread::dirty_card_queue_set()),
138 _listener()
139 {
140 _listener.set_card_table(this);
141 }
142
143 void G1SATBCardTableLoggingModRefBS::initialize(G1RegionToSpaceMapper* mapper) {
144 mapper->set_mapping_changed_listener(&_listener);
145
146 _byte_map_size = mapper->reserved().byte_size();
147
148 _guard_index = cards_required(_whole_heap.word_size()) - 1;
149 _last_valid_index = _guard_index - 1;
150
151 HeapWord* low_bound = _whole_heap.start();
152 HeapWord* high_bound = _whole_heap.end();
153
154 _cur_covered_regions = 1;
155 _covered[0] = _whole_heap;
156
189 jt->dirty_card_queue().enqueue(byte);
190 } else {
191 MutexLockerEx x(Shared_DirtyCardQ_lock,
192 Mutex::_no_safepoint_check_flag);
193 _dcqs.shared_dirty_card_queue()->enqueue(byte);
194 }
195 }
196 }
197
198 void
199 G1SATBCardTableLoggingModRefBS::write_ref_field_static(void* field,
200 oop new_val) {
201 uintptr_t field_uint = (uintptr_t)field;
202 uintptr_t new_val_uint = cast_from_oop<uintptr_t>(new_val);
203 uintptr_t comb = field_uint ^ new_val_uint;
204 comb = comb >> HeapRegion::LogOfHRGrainBytes;
205 if (comb == 0) return;
206 if (new_val == NULL) return;
207 // Otherwise, log it.
208 G1SATBCardTableLoggingModRefBS* g1_bs =
209 barrier_set_cast<G1SATBCardTableLoggingModRefBS>(Universe::heap()->barrier_set());
210 g1_bs->write_ref_field_work(field, new_val);
211 }
212
213 void
214 G1SATBCardTableLoggingModRefBS::invalidate(MemRegion mr, bool whole_heap) {
215 volatile jbyte* byte = byte_for(mr.start());
216 jbyte* last_byte = byte_for(mr.last());
217 Thread* thr = Thread::current();
218 if (whole_heap) {
219 while (byte <= last_byte) {
220 *byte = dirty_card;
221 byte++;
222 }
223 } else {
224 // skip all consecutive young cards
225 for (; byte <= last_byte && *byte == g1_young_gen; byte++);
226
227 if (byte <= last_byte) {
228 OrderAccess::storeload();
229 // Enqueue if necessary.
|