6908208: UseCompressedOops: array_size() returns incorrect size for MAX_INT object array following 6906727

Tue, 08 Dec 2009 15:12:17 -0800

author
ysr
date
Tue, 08 Dec 2009 15:12:17 -0800
changeset 1530
7bfd295ec074
parent 1529
9118860519b6
child 1531
84a2da7f454c
child 1538
9dc2adf2cbe0

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 file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/vm/oops/objArrayOop.hpp	Mon Dec 07 14:22:34 2009 -0500
     1.2 +++ b/src/share/vm/oops/objArrayOop.hpp	Tue Dec 08 15:12:17 2009 -0800
     1.3 @@ -58,7 +58,7 @@
     1.4        old_res = align_size_up(length, OopsPerHeapWord)/OopsPerHeapWord;
     1.5      }
     1.6  #endif  // ASSERT
     1.7 -    int res = (length + OopsPerHeapWord - 1)/OopsPerHeapWord;
     1.8 +    int res = ((uint)length + OopsPerHeapWord - 1)/OopsPerHeapWord;
     1.9      assert(res == old_res, "Inconsistency between old and new.");
    1.10      return res;
    1.11    }
    1.12 @@ -96,7 +96,11 @@
    1.13  
    1.14    static int object_size(int length) {
    1.15      // This returns the object size in HeapWords.
    1.16 -    return align_object_size(header_size() + array_size(length));
    1.17 +    uint asz = array_size(length);
    1.18 +    uint osz = align_object_size(header_size() + asz);
    1.19 +    assert(osz >= asz,   "no overflow");
    1.20 +    assert((int)osz > 0, "no overflow");
    1.21 +    return (int)osz;
    1.22    }
    1.23  
    1.24    // special iterators for index ranges, returns size of object

mercurial