Wed, 19 Jun 2019 16:36:26 +0100
8225716: G1 GC: Undefined behaviour in G1BlockOffsetTablePart::block_at_or_preceding
Reviewed-by: kbarrett, tschatzl
1.1 --- a/src/share/vm/gc_implementation/g1/g1BlockOffsetTable.cpp Wed Jun 05 05:15:56 2019 +0100 1.2 +++ b/src/share/vm/gc_implementation/g1/g1BlockOffsetTable.cpp Wed Jun 19 16:36:26 2019 +0100 1.3 @@ -447,8 +447,6 @@ 1.4 } 1.5 1.6 HeapWord* G1BlockOffsetArrayContigSpace::initialize_threshold_raw() { 1.7 - assert(!Universe::heap()->is_in_reserved(_array->_offset_array), 1.8 - "just checking"); 1.9 _next_offset_index = _array->index_for_raw(_bottom); 1.10 _next_offset_index++; 1.11 _next_offset_threshold = 1.12 @@ -457,8 +455,6 @@ 1.13 } 1.14 1.15 void G1BlockOffsetArrayContigSpace::zero_bottom_entry_raw() { 1.16 - assert(!Universe::heap()->is_in_reserved(_array->_offset_array), 1.17 - "just checking"); 1.18 size_t bottom_index = _array->index_for_raw(_bottom); 1.19 assert(_array->address_for_index_raw(bottom_index) == _bottom, 1.20 "Precondition of call"); 1.21 @@ -466,8 +462,6 @@ 1.22 } 1.23 1.24 HeapWord* G1BlockOffsetArrayContigSpace::initialize_threshold() { 1.25 - assert(!Universe::heap()->is_in_reserved(_array->_offset_array), 1.26 - "just checking"); 1.27 _next_offset_index = _array->index_for(_bottom); 1.28 _next_offset_index++; 1.29 _next_offset_threshold =
2.1 --- a/src/share/vm/gc_implementation/g1/g1BlockOffsetTable.hpp Wed Jun 05 05:15:56 2019 +0100 2.2 +++ b/src/share/vm/gc_implementation/g1/g1BlockOffsetTable.hpp Wed Jun 19 16:36:26 2019 +0100 2.3 @@ -145,7 +145,7 @@ 2.4 2.5 // Array for keeping offsets for retrieving object start fast given an 2.6 // address. 2.7 - u_char* _offset_array; // byte array keeping backwards offsets 2.8 + volatile u_char* _offset_array; // byte array keeping backwards offsets 2.9 2.10 void check_offset(size_t offset, const char* msg) const { 2.11 assert(offset <= N_words, 2.12 @@ -158,9 +158,7 @@ 2.13 // For performance these have to devolve to array accesses in product builds. 2.14 inline u_char offset_array(size_t index) const; 2.15 2.16 - void set_offset_array_raw(size_t index, u_char offset) { 2.17 - _offset_array[index] = offset; 2.18 - } 2.19 + inline void set_offset_array_raw(size_t index, u_char offset); 2.20 2.21 inline void set_offset_array(size_t index, u_char offset); 2.22
3.1 --- a/src/share/vm/gc_implementation/g1/g1BlockOffsetTable.inline.hpp Wed Jun 05 05:15:56 2019 +0100 3.2 +++ b/src/share/vm/gc_implementation/g1/g1BlockOffsetTable.inline.hpp Wed Jun 19 16:36:26 2019 +0100 3.3 @@ -63,6 +63,10 @@ 3.4 return _offset_array[index]; 3.5 } 3.6 3.7 +inline void G1BlockOffsetSharedArray::set_offset_array_raw(size_t index, u_char offset) { 3.8 + _offset_array[index] = offset; 3.9 +} 3.10 + 3.11 void G1BlockOffsetSharedArray::set_offset_array(size_t index, u_char offset) { 3.12 check_index(index, "index out of range"); 3.13 set_offset_array_raw(index, offset); 3.14 @@ -81,7 +85,7 @@ 3.15 assert(left <= right, "indexes out of order"); 3.16 size_t num_cards = right - left + 1; 3.17 if (UseMemSetInBOT) { 3.18 - memset(&_offset_array[left], offset, num_cards); 3.19 + memset(const_cast<u_char*> (&_offset_array[left]), offset, num_cards); 3.20 } else { 3.21 size_t i = left; 3.22 const size_t end = i + num_cards;