comparison src/share/vm/oops/objArrayOop.hpp @ 1095:7bfd295ec074

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 6aa7255741f3
children c18cbe5936b8
comparison
equal deleted inserted replaced
7:28a247a89416 8:5655e17ccfe9
56 old_res = length * HeapWordsPerOop; 56 old_res = length * HeapWordsPerOop;
57 } else { 57 } else {
58 old_res = align_size_up(length, OopsPerHeapWord)/OopsPerHeapWord; 58 old_res = align_size_up(length, OopsPerHeapWord)/OopsPerHeapWord;
59 } 59 }
60 #endif // ASSERT 60 #endif // ASSERT
61 int res = (length + OopsPerHeapWord - 1)/OopsPerHeapWord; 61 int res = ((uint)length + OopsPerHeapWord - 1)/OopsPerHeapWord;
62 assert(res == old_res, "Inconsistency between old and new."); 62 assert(res == old_res, "Inconsistency between old and new.");
63 return res; 63 return res;
64 } 64 }
65 65
66 public: 66 public:
94 static int header_size() { return arrayOopDesc::header_size(T_OBJECT); } 94 static int header_size() { return arrayOopDesc::header_size(T_OBJECT); }
95 int object_size() { return object_size(length()); } 95 int object_size() { return object_size(length()); }
96 96
97 static int object_size(int length) { 97 static int object_size(int length) {
98 // This returns the object size in HeapWords. 98 // This returns the object size in HeapWords.
99 return align_object_size(header_size() + array_size(length)); 99 uint asz = array_size(length);
100 uint osz = align_object_size(header_size() + asz);
101 assert(osz >= asz, "no overflow");
102 assert((int)osz > 0, "no overflow");
103 return (int)osz;
100 } 104 }
101 105
102 // special iterators for index ranges, returns size of object 106 // special iterators for index ranges, returns size of object
103 #define ObjArrayOop_OOP_ITERATE_DECL(OopClosureType, nv_suffix) \ 107 #define ObjArrayOop_OOP_ITERATE_DECL(OopClosureType, nv_suffix) \
104 int oop_iterate_range(OopClosureType* blk, int start, int end); 108 int oop_iterate_range(OopClosureType* blk, int start, int end);