提交 6007e6de 编写于 作者: B brutisso

7110152: assert(size_in_words <= (julong)max_jint) failed: no overflow

Summary: Reduce what arrayOopDesc::max_array_length() returns to avoid int overflow
Reviewed-by: kvn, dholmes, tonyp
上级 6686a725
...@@ -110,10 +110,16 @@ class arrayOopDesc : public oopDesc { ...@@ -110,10 +110,16 @@ class arrayOopDesc : public oopDesc {
assert(type >= 0 && type < T_CONFLICT, "wrong type"); assert(type >= 0 && type < T_CONFLICT, "wrong type");
assert(type2aelembytes(type) != 0, "wrong type"); assert(type2aelembytes(type) != 0, "wrong type");
const size_t max_element_words_per_size_t = align_size_down((SIZE_MAX/HeapWordSize - header_size(type)), MinObjAlignment); const size_t max_element_words_per_size_t =
const size_t max_elements_per_size_t = HeapWordSize * max_element_words_per_size_t / type2aelembytes(type); align_size_down((SIZE_MAX/HeapWordSize - header_size(type)), MinObjAlignment);
const size_t max_elements_per_size_t =
HeapWordSize * max_element_words_per_size_t / type2aelembytes(type);
if ((size_t)max_jint < max_elements_per_size_t) { if ((size_t)max_jint < max_elements_per_size_t) {
return max_jint; // It should be ok to return max_jint here, but parts of the code
// (CollectedHeap, Klass::oop_oop_iterate(), and more) uses an int for
// passing around the size (in words) of an object. So, we need to avoid
// overflowing an int when we add the header. See CRs 4718400 and 7110613.
return align_size_down(max_jint - header_size(type), MinObjAlignment);
} }
return (int32_t)max_elements_per_size_t; return (int32_t)max_elements_per_size_t;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册