1.1 --- a/src/share/vm/oops/arrayOop.hpp Wed Nov 09 23:21:00 2011 +0100 1.2 +++ b/src/share/vm/oops/arrayOop.hpp Tue Nov 15 20:17:33 2011 +0100 1.3 @@ -110,10 +110,16 @@ 1.4 assert(type >= 0 && type < T_CONFLICT, "wrong type"); 1.5 assert(type2aelembytes(type) != 0, "wrong type"); 1.6 1.7 - const size_t max_element_words_per_size_t = align_size_down((SIZE_MAX/HeapWordSize - header_size(type)), MinObjAlignment); 1.8 - const size_t max_elements_per_size_t = HeapWordSize * max_element_words_per_size_t / type2aelembytes(type); 1.9 + const size_t max_element_words_per_size_t = 1.10 + align_size_down((SIZE_MAX/HeapWordSize - header_size(type)), MinObjAlignment); 1.11 + const size_t max_elements_per_size_t = 1.12 + HeapWordSize * max_element_words_per_size_t / type2aelembytes(type); 1.13 if ((size_t)max_jint < max_elements_per_size_t) { 1.14 - return max_jint; 1.15 + // It should be ok to return max_jint here, but parts of the code 1.16 + // (CollectedHeap, Klass::oop_oop_iterate(), and more) uses an int for 1.17 + // passing around the size (in words) of an object. So, we need to avoid 1.18 + // overflowing an int when we add the header. See CRs 4718400 and 7110613. 1.19 + return align_size_down(max_jint - header_size(type), MinObjAlignment); 1.20 } 1.21 return (int32_t)max_elements_per_size_t; 1.22 }