changeset 57204:54af3178cdbd

8231430: C2: Memory stomp in max_array_length() for T_ILLEGAL type Reviewed-by: kvn, thartmann
author vlivanov
date Tue, 03 Dec 2019 20:13:16 +0300
parents cfed0da56a7b
children 138b0f3fe18c
files src/hotspot/share/opto/type.cpp src/hotspot/share/opto/type.hpp
diffstat 2 files changed, 17 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/src/hotspot/share/opto/type.cpp	Tue Dec 03 16:13:37 2019 +0000
+++ b/src/hotspot/share/opto/type.cpp	Tue Dec 03 20:13:16 2019 +0300
@@ -4104,32 +4104,22 @@
 }
 
 
+//-----------------------------max_array_length-------------------------------
+// A wrapper around arrayOopDesc::max_array_length(etype) with some input normalization.
+jint TypeAryPtr::max_array_length(BasicType etype) {
+  if (!is_java_primitive(etype) && !is_reference_type(etype)) {
+    if (etype == T_NARROWOOP) {
+      etype = T_OBJECT;
+    } else if (etype == T_ILLEGAL) { // bottom[]
+      etype = T_BYTE; // will produce conservatively high value
+    } else {
+      fatal("not an element type: %s", type2name(etype));
+    }
+  }
+  return arrayOopDesc::max_array_length(etype);
+}
+
 //-----------------------------narrow_size_type-------------------------------
-// Local cache for arrayOopDesc::max_array_length(etype),
-// which is kind of slow (and cached elsewhere by other users).
-static jint max_array_length_cache[T_CONFLICT+1];
-static jint max_array_length(BasicType etype) {
-  jint& cache = max_array_length_cache[etype];
-  jint res = cache;
-  if (res == 0) {
-    switch (etype) {
-    case T_NARROWOOP:
-      etype = T_OBJECT;
-      break;
-    case T_NARROWKLASS:
-    case T_CONFLICT:
-    case T_ILLEGAL:
-    case T_VOID:
-      etype = T_BYTE;           // will produce conservatively high value
-      break;
-    default:
-      break;
-    }
-    cache = res = arrayOopDesc::max_array_length(etype);
-  }
-  return res;
-}
-
 // Narrow the given size type to the index range for the given array base type.
 // Return NULL if the resulting int type becomes empty.
 const TypeInt* TypeAryPtr::narrow_size_type(const TypeInt* size) const {
--- a/src/hotspot/share/opto/type.hpp	Tue Dec 03 16:13:37 2019 +0000
+++ b/src/hotspot/share/opto/type.hpp	Tue Dec 03 20:13:16 2019 +0300
@@ -455,7 +455,6 @@
 
 private:
   // support arrays
-  static const BasicType _basic_type[];
   static const Type*        _zero_type[T_CONFLICT+1];
   static const Type* _const_basic_type[T_CONFLICT+1];
 };
@@ -1225,6 +1224,8 @@
 
   const TypeAryPtr* cast_to_autobox_cache(bool cache) const;
 
+  static jint max_array_length(BasicType etype) ;
+
   // Convenience common pre-built types.
   static const TypeAryPtr *RANGE;
   static const TypeAryPtr *OOPS;