56 // typeArrayOop::object_size(scale, length, header_size) without causing an |
56 // typeArrayOop::object_size(scale, length, header_size) without causing an |
57 // overflow. We substract an extra 2*wordSize to guard against double word |
57 // overflow. We substract an extra 2*wordSize to guard against double word |
58 // alignments. It gets the scale from the type2aelembytes array. |
58 // alignments. It gets the scale from the type2aelembytes array. |
59 static int32_t max_array_length(BasicType type) { |
59 static int32_t max_array_length(BasicType type) { |
60 assert(type >= 0 && type < T_CONFLICT, "wrong type"); |
60 assert(type >= 0 && type < T_CONFLICT, "wrong type"); |
61 assert(type2aelembytes[type] != 0, "wrong type"); |
61 assert(type2aelembytes(type) != 0, "wrong type"); |
62 // We use max_jint, since object_size is internally represented by an 'int' |
62 // We use max_jint, since object_size is internally represented by an 'int' |
63 // This gives us an upper bound of max_jint words for the size of the oop. |
63 // This gives us an upper bound of max_jint words for the size of the oop. |
64 int32_t max_words = (max_jint - header_size(type) - 2); |
64 int32_t max_words = (max_jint - header_size(type) - 2); |
65 int elembytes = (type == T_OBJECT) ? T_OBJECT_aelem_bytes : type2aelembytes[type]; |
65 int elembytes = (type == T_OBJECT) ? T_OBJECT_aelem_bytes : type2aelembytes(type); |
66 jlong len = ((jlong)max_words * HeapWordSize) / elembytes; |
66 jlong len = ((jlong)max_words * HeapWordSize) / elembytes; |
67 return (len > max_jint) ? max_jint : (int32_t)len; |
67 return (len > max_jint) ? max_jint : (int32_t)len; |
68 } |
68 } |
69 |
69 |
70 }; |
70 }; |