96 assert(p >= _reserved.start(), "just checking"); |
97 assert(p >= _reserved.start(), "just checking"); |
97 size_t delta = pointer_delta(p, _reserved.start()); |
98 size_t delta = pointer_delta(p, _reserved.start()); |
98 return (delta & right_n_bits(LogN_words)) == (size_t)NoBits; |
99 return (delta & right_n_bits(LogN_words)) == (size_t)NoBits; |
99 } |
100 } |
100 |
101 |
|
102 void G1BlockOffsetSharedArray::set_offset_array(HeapWord* left, HeapWord* right, u_char offset) { |
|
103 check_index(index_for(right - 1), "right address out of range"); |
|
104 assert(left < right, "Heap addresses out of order"); |
|
105 size_t num_cards = pointer_delta(right, left) >> LogN_words; |
|
106 if (UseMemSetInBOT) { |
|
107 memset(&_offset_array[index_for(left)], offset, num_cards); |
|
108 } else { |
|
109 size_t i = index_for(left); |
|
110 const size_t end = i + num_cards; |
|
111 for (; i < end; i++) { |
|
112 _offset_array[i] = offset; |
|
113 } |
|
114 } |
|
115 } |
101 |
116 |
102 ////////////////////////////////////////////////////////////////////// |
117 ////////////////////////////////////////////////////////////////////// |
103 // G1BlockOffsetArray |
118 // G1BlockOffsetArray |
104 ////////////////////////////////////////////////////////////////////// |
119 ////////////////////////////////////////////////////////////////////// |
105 |
120 |
106 G1BlockOffsetArray::G1BlockOffsetArray(G1BlockOffsetSharedArray* array, |
121 G1BlockOffsetArray::G1BlockOffsetArray(G1BlockOffsetSharedArray* array, |
107 MemRegion mr, bool init_to_zero) : |
122 MemRegion mr, bool init_to_zero) : |
108 G1BlockOffsetTable(mr.start(), mr.end()), |
123 G1BlockOffsetTable(mr.start(), mr.end()), |
109 _unallocated_block(_bottom), |
124 _unallocated_block(_bottom), |
110 _array(array), _csp(NULL), |
125 _array(array), _gsp(NULL), |
111 _init_to_zero(init_to_zero) { |
126 _init_to_zero(init_to_zero) { |
112 assert(_bottom <= _end, "arguments out of order"); |
127 assert(_bottom <= _end, "arguments out of order"); |
113 if (!_init_to_zero) { |
128 if (!_init_to_zero) { |
114 // initialize cards to point back to mr.start() |
129 // initialize cards to point back to mr.start() |
115 set_remainder_to_point_to_start(mr.start() + N_words, mr.end()); |
130 set_remainder_to_point_to_start(mr.start() + N_words, mr.end()); |
116 _array->set_offset_array(0, 0); // set first card to 0 |
131 _array->set_offset_array(0, 0); // set first card to 0 |
117 } |
132 } |
118 } |
133 } |
119 |
134 |
120 void G1BlockOffsetArray::set_space(Space* sp) { |
135 void G1BlockOffsetArray::set_space(G1OffsetTableContigSpace* sp) { |
121 _sp = sp; |
136 _gsp = sp; |
122 _csp = sp->toContiguousSpace(); |
|
123 } |
137 } |
124 |
138 |
125 // The arguments follow the normal convention of denoting |
139 // The arguments follow the normal convention of denoting |
126 // a right-open interval: [start, end) |
140 // a right-open interval: [start, end) |
127 void |
141 void |
376 assert(ub < _end, "tautology (see above)"); |
390 assert(ub < _end, "tautology (see above)"); |
377 return ub; |
391 return ub; |
378 } |
392 } |
379 // Otherwise, find the block start using the table. |
393 // Otherwise, find the block start using the table. |
380 HeapWord* q = block_at_or_preceding(addr, false, 0); |
394 HeapWord* q = block_at_or_preceding(addr, false, 0); |
381 HeapWord* n = q + _sp->block_size(q); |
395 HeapWord* n = q + block_size(q); |
382 return forward_to_block_containing_addr_const(q, n, addr); |
396 return forward_to_block_containing_addr_const(q, n, addr); |
383 } |
397 } |
384 |
398 |
385 |
399 |
386 HeapWord* |
400 HeapWord* |
404 (n_index == next_index ? 0 : N_words); |
418 (n_index == next_index ? 0 : N_words); |
405 assert(next_boundary <= _array->_end, |
419 assert(next_boundary <= _array->_end, |
406 err_msg("next_boundary is beyond the end of the covered region " |
420 err_msg("next_boundary is beyond the end of the covered region " |
407 " next_boundary " PTR_FORMAT " _array->_end " PTR_FORMAT, |
421 " next_boundary " PTR_FORMAT " _array->_end " PTR_FORMAT, |
408 next_boundary, _array->_end)); |
422 next_boundary, _array->_end)); |
409 if (csp() != NULL) { |
423 if (addr >= gsp()->top()) return gsp()->top(); |
410 if (addr >= csp()->top()) return csp()->top(); |
424 while (next_boundary < addr) { |
411 while (next_boundary < addr) { |
425 while (n <= next_boundary) { |
412 while (n <= next_boundary) { |
426 q = n; |
413 q = n; |
427 oop obj = oop(q); |
414 oop obj = oop(q); |
428 if (obj->klass_or_null() == NULL) return q; |
415 if (obj->klass_or_null() == NULL) return q; |
429 n += obj->size(); |
416 n += obj->size(); |
430 } |
417 } |
431 assert(q <= next_boundary && n > next_boundary, "Consequence of loop"); |
418 assert(q <= next_boundary && n > next_boundary, "Consequence of loop"); |
432 // [q, n) is the block that crosses the boundary. |
419 // [q, n) is the block that crosses the boundary. |
433 alloc_block_work2(&next_boundary, &next_index, q, n); |
420 alloc_block_work2(&next_boundary, &next_index, q, n); |
|
421 } |
|
422 } else { |
|
423 while (next_boundary < addr) { |
|
424 while (n <= next_boundary) { |
|
425 q = n; |
|
426 oop obj = oop(q); |
|
427 if (obj->klass_or_null() == NULL) return q; |
|
428 n += _sp->block_size(q); |
|
429 } |
|
430 assert(q <= next_boundary && n > next_boundary, "Consequence of loop"); |
|
431 // [q, n) is the block that crosses the boundary. |
|
432 alloc_block_work2(&next_boundary, &next_index, q, n); |
|
433 } |
|
434 } |
434 } |
435 return forward_to_block_containing_addr_const(q, n, addr); |
435 return forward_to_block_containing_addr_const(q, n, addr); |
436 } |
436 } |
437 |
437 |
438 HeapWord* G1BlockOffsetArray::block_start_careful(const void* addr) const { |
438 HeapWord* G1BlockOffsetArray::block_start_careful(const void* addr) const { |
635 G1BlockOffsetArrayContigSpace:: |
635 G1BlockOffsetArrayContigSpace:: |
636 block_start_unsafe_const(const void* addr) const { |
636 block_start_unsafe_const(const void* addr) const { |
637 assert(_bottom <= addr && addr < _end, |
637 assert(_bottom <= addr && addr < _end, |
638 "addr must be covered by this Array"); |
638 "addr must be covered by this Array"); |
639 HeapWord* q = block_at_or_preceding(addr, true, _next_offset_index-1); |
639 HeapWord* q = block_at_or_preceding(addr, true, _next_offset_index-1); |
640 HeapWord* n = q + _sp->block_size(q); |
640 HeapWord* n = q + block_size(q); |
641 return forward_to_block_containing_addr_const(q, n, addr); |
641 return forward_to_block_containing_addr_const(q, n, addr); |
642 } |
642 } |
643 |
643 |
644 G1BlockOffsetArrayContigSpace:: |
644 G1BlockOffsetArrayContigSpace:: |
645 G1BlockOffsetArrayContigSpace(G1BlockOffsetSharedArray* array, |
645 G1BlockOffsetArrayContigSpace(G1BlockOffsetSharedArray* array, |