changeset 984:62926c7f67a3 hs16-b13

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
author ysr
date Tue, 08 Dec 2009 15:12:17 -0800
parents 9adb2f184e47
children 4ebd3f8407eb
files src/share/vm/oops/objArrayOop.hpp
diffstat 1 files changed, 6 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/vm/oops/objArrayOop.hpp	Thu Dec 03 15:01:57 2009 -0800
+++ b/src/share/vm/oops/objArrayOop.hpp	Tue Dec 08 15:12:17 2009 -0800
@@ -58,7 +58,7 @@
       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 @@
 
   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