From 1aaad3e2666c3cc928319281b2dcff8884e1c3d9 Mon Sep 17 00:00:00 2001 From: ysr Date: Tue, 8 Dec 2009 15:12:17 -0800 Subject: [PATCH] 6908208: UseCompressedOops: array_size() returns incorrect size for MAX_INT object array following 6906727 Summary: In array_size() cast to an unsigned to avoid overflow of intermediate value. Reviewed-by: kvn, tonyp, jmasa, jcoomes, coleenp --- src/share/vm/oops/objArrayOop.hpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/share/vm/oops/objArrayOop.hpp b/src/share/vm/oops/objArrayOop.hpp index a00eb7c1a..1c1764a87 100644 --- a/src/share/vm/oops/objArrayOop.hpp +++ b/src/share/vm/oops/objArrayOop.hpp @@ -58,7 +58,7 @@ private: old_res = align_size_up(length, OopsPerHeapWord)/OopsPerHeapWord; } #endif // ASSERT - int res = (length + OopsPerHeapWord - 1)/OopsPerHeapWord; + int res = ((uint)length + OopsPerHeapWord - 1)/OopsPerHeapWord; assert(res == old_res, "Inconsistency between old and new."); return res; } @@ -96,7 +96,11 @@ private: static int object_size(int length) { // This returns the object size in HeapWords. - return align_object_size(header_size() + array_size(length)); + uint asz = array_size(length); + uint osz = align_object_size(header_size() + asz); + assert(osz >= asz, "no overflow"); + assert((int)osz > 0, "no overflow"); + return (int)osz; } // special iterators for index ranges, returns size of object -- GitLab