8160360: Mismatched field loads are folded in LoadNode::Value
authorvlivanov
Wed, 06 Jul 2016 15:05:28 +0300
changeset 40047 124ad42f6e96
parent 40046 01e973266ee4
child 40048 7e816aed8ba8
8160360: Mismatched field loads are folded in LoadNode::Value Reviewed-by: kvn, thartmann
hotspot/src/share/vm/opto/library_call.cpp
hotspot/src/share/vm/opto/memnode.cpp
hotspot/src/share/vm/opto/type.hpp
--- a/hotspot/src/share/vm/opto/library_call.cpp	Tue Jul 05 17:57:20 2016 -0700
+++ b/hotspot/src/share/vm/opto/library_call.cpp	Wed Jul 06 15:05:28 2016 +0300
@@ -2337,6 +2337,8 @@
       return false;
     }
     mismatched = (bt != type);
+  } else if (alias_type->adr_type() == TypeOopPtr::BOTTOM) {
+    mismatched = true; // conservatively mark all "wide" on-heap accesses as mismatched
   }
 
   // First guess at the value type.
--- a/hotspot/src/share/vm/opto/memnode.cpp	Tue Jul 05 17:57:20 2016 -0700
+++ b/hotspot/src/share/vm/opto/memnode.cpp	Wed Jul 06 15:05:28 2016 +0300
@@ -1713,9 +1713,6 @@
       }
     }
   } else if (tp->base() == Type::InstPtr) {
-    ciEnv* env = C->env();
-    const TypeInstPtr* tinst = tp->is_instptr();
-    ciKlass* klass = tinst->klass();
     assert( off != Type::OffsetBot ||
             // arrays can be cast to Objects
             tp->is_oopptr()->klass()->is_java_lang_Object() ||
@@ -1723,9 +1720,11 @@
             C->has_unsafe_access(),
             "Field accesses must be precise" );
     // For oop loads, we expect the _type to be precise.
-    // Optimizations for constant objects
+
+    // Optimize loads from constant fields.
+    const TypeInstPtr* tinst = tp->is_instptr();
     ciObject* const_oop = tinst->const_oop();
-    if (const_oop != NULL && const_oop->is_instance()) {
+    if (!is_mismatched_access() && off != Type::OffsetBot && const_oop != NULL && const_oop->is_instance()) {
       const Type* con_type = Type::make_constant_from_field(const_oop->as_instance(), off, is_unsigned(), memory_type());
       if (con_type != NULL) {
         return con_type;
--- a/hotspot/src/share/vm/opto/type.hpp	Tue Jul 05 17:57:20 2016 -0700
+++ b/hotspot/src/share/vm/opto/type.hpp	Wed Jul 06 15:05:28 2016 +0300
@@ -936,7 +936,7 @@
 };
 
 //------------------------------TypeOopPtr-------------------------------------
-// Some kind of oop (Java pointer), either klass or instance or array.
+// Some kind of oop (Java pointer), either instance or array.
 class TypeOopPtr : public TypePtr {
 protected:
   TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset, int instance_id,