Skip to content

Commit c7bc0f7

Browse files
author
Vladimir Ivanov
committedDec 3, 2019
8231430: C2: Memory stomp in max_array_length() for T_ILLEGAL type
Reviewed-by: kvn, thartmann
1 parent 22ea33c commit c7bc0f7

File tree

2 files changed

+13
-22
lines changed

2 files changed

+13
-22
lines changed
 

‎src/hotspot/share/opto/type.cpp

+11-21
Original file line numberDiff line numberDiff line change
@@ -4104,32 +4104,22 @@ const TypeOopPtr *TypeAryPtr::cast_to_nonconst() const {
41044104
}
41054105

41064106

4107-
//-----------------------------narrow_size_type-------------------------------
4108-
// Local cache for arrayOopDesc::max_array_length(etype),
4109-
// which is kind of slow (and cached elsewhere by other users).
4110-
static jint max_array_length_cache[T_CONFLICT+1];
4111-
static jint max_array_length(BasicType etype) {
4112-
jint& cache = max_array_length_cache[etype];
4113-
jint res = cache;
4114-
if (res == 0) {
4115-
switch (etype) {
4116-
case T_NARROWOOP:
4107+
//-----------------------------max_array_length-------------------------------
4108+
// A wrapper around arrayOopDesc::max_array_length(etype) with some input normalization.
4109+
jint TypeAryPtr::max_array_length(BasicType etype) {
4110+
if (!is_java_primitive(etype) && !is_reference_type(etype)) {
4111+
if (etype == T_NARROWOOP) {
41174112
etype = T_OBJECT;
4118-
break;
4119-
case T_NARROWKLASS:
4120-
case T_CONFLICT:
4121-
case T_ILLEGAL:
4122-
case T_VOID:
4123-
etype = T_BYTE; // will produce conservatively high value
4124-
break;
4125-
default:
4126-
break;
4113+
} else if (etype == T_ILLEGAL) { // bottom[]
4114+
etype = T_BYTE; // will produce conservatively high value
4115+
} else {
4116+
fatal("not an element type: %s", type2name(etype));
41274117
}
4128-
cache = res = arrayOopDesc::max_array_length(etype);
41294118
}
4130-
return res;
4119+
return arrayOopDesc::max_array_length(etype);
41314120
}
41324121

4122+
//-----------------------------narrow_size_type-------------------------------
41334123
// Narrow the given size type to the index range for the given array base type.
41344124
// Return NULL if the resulting int type becomes empty.
41354125
const TypeInt* TypeAryPtr::narrow_size_type(const TypeInt* size) const {

‎src/hotspot/share/opto/type.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,6 @@ class Type {
455455

456456
private:
457457
// support arrays
458-
static const BasicType _basic_type[];
459458
static const Type* _zero_type[T_CONFLICT+1];
460459
static const Type* _const_basic_type[T_CONFLICT+1];
461460
};
@@ -1225,6 +1224,8 @@ class TypeAryPtr : public TypeOopPtr {
12251224

12261225
const TypeAryPtr* cast_to_autobox_cache(bool cache) const;
12271226

1227+
static jint max_array_length(BasicType etype) ;
1228+
12281229
// Convenience common pre-built types.
12291230
static const TypeAryPtr *RANGE;
12301231
static const TypeAryPtr *OOPS;

0 commit comments

Comments
 (0)
Please sign in to comment.