@@ -107,22 +107,28 @@ void G1BarrierSet::invalidate(MemRegion mr) {
107
107
}
108
108
volatile CardValue* byte = _card_table->byte_for (mr.start ());
109
109
CardValue* last_byte = _card_table->byte_for (mr.last ());
110
- // skip initial young cards
111
- for (; byte <= last_byte && *byte == G1CardTable::g1_young_card_val (); byte++);
112
110
113
- if (byte <= last_byte) {
114
- OrderAccess::storeload ();
115
- // Enqueue if necessary.
116
- Thread* thr = Thread::current ();
117
- G1DirtyCardQueueSet& qset = G1BarrierSet::dirty_card_queue_set ();
118
- G1DirtyCardQueue& queue = G1ThreadLocalData::dirty_card_queue (thr);
119
- for (; byte <= last_byte; byte++) {
120
- CardValue bv = *byte;
121
- if ((bv != G1CardTable::g1_young_card_val ()) &&
122
- (bv != G1CardTable::dirty_card_val ())) {
123
- *byte = G1CardTable::dirty_card_val ();
124
- qset.enqueue (queue, byte);
125
- }
111
+ // skip young gen cards
112
+ if (*byte == G1CardTable::g1_young_card_val ()) {
113
+ // MemRegion should not span multiple regions for the young gen.
114
+ DEBUG_ONLY (HeapRegion* containing_hr = G1CollectedHeap::heap ()->heap_region_containing (mr.start ());)
115
+ assert (containing_hr->is_young (), " it should be young" );
116
+ assert (containing_hr->is_in (mr.start ()), " it should contain start" );
117
+ assert (containing_hr->is_in (mr.last ()), " it should also contain last" );
118
+ return ;
119
+ }
120
+
121
+ OrderAccess::storeload ();
122
+ // Enqueue if necessary.
123
+ Thread* thr = Thread::current ();
124
+ G1DirtyCardQueueSet& qset = G1BarrierSet::dirty_card_queue_set ();
125
+ G1DirtyCardQueue& queue = G1ThreadLocalData::dirty_card_queue (thr);
126
+ for (; byte <= last_byte; byte++) {
127
+ CardValue bv = *byte;
128
+ assert (bv != G1CardTable::g1_young_card_val (), " Invalid card" );
129
+ if (bv != G1CardTable::dirty_card_val ()) {
130
+ *byte = G1CardTable::dirty_card_val ();
131
+ qset.enqueue (queue, byte);
126
132
}
127
133
}
128
134
}
0 commit comments