8150933: System::arraycopy intrinsic doesn't mark mismatched loads
authorvlivanov
Tue, 01 Mar 2016 20:06:47 +0300
changeset 36342 7e8c466d9ffe
parent 36341 8a6e7a5607a8
child 36344 5b16931563ac
8150933: System::arraycopy intrinsic doesn't mark mismatched loads Reviewed-by: kvn, shade
hotspot/src/share/vm/opto/macroArrayCopy.cpp
hotspot/src/share/vm/opto/memnode.cpp
--- a/hotspot/src/share/vm/opto/macroArrayCopy.cpp	Fri Feb 19 17:12:14 2016 +0800
+++ b/hotspot/src/share/vm/opto/macroArrayCopy.cpp	Tue Mar 01 20:06:47 2016 +0300
@@ -880,8 +880,14 @@
       Node* sptr = basic_plus_adr(src,  src_off);
       Node* dptr = basic_plus_adr(dest, dest_off);
       uint alias_idx = C->get_alias_index(adr_type);
-      Node* sval = transform_later(LoadNode::make(_igvn, *ctrl, (*mem)->memory_at(alias_idx), sptr, adr_type, TypeInt::INT, T_INT, MemNode::unordered));
-      Node* st = transform_later(StoreNode::make(_igvn, *ctrl, (*mem)->memory_at(alias_idx), dptr, adr_type, sval, T_INT, MemNode::unordered));
+      bool is_mismatched = (basic_elem_type != T_INT);
+      Node* sval = transform_later(
+          LoadNode::make(_igvn, *ctrl, (*mem)->memory_at(alias_idx), sptr, adr_type,
+                         TypeInt::INT, T_INT, MemNode::unordered, LoadNode::DependsOnlyOnTest,
+                         false /*unaligned*/, is_mismatched));
+      Node* st = transform_later(
+          StoreNode::make(_igvn, *ctrl, (*mem)->memory_at(alias_idx), dptr, adr_type,
+                          sval, T_INT, MemNode::unordered));
       (*mem)->set_memory_at(alias_idx, st);
       src_off += BytesPerInt;
       dest_off += BytesPerInt;
--- a/hotspot/src/share/vm/opto/memnode.cpp	Fri Feb 19 17:12:14 2016 +0800
+++ b/hotspot/src/share/vm/opto/memnode.cpp	Tue Mar 01 20:06:47 2016 +0300
@@ -1582,7 +1582,6 @@
   return NULL;
 }
 
-#ifdef ASSERT
 static bool is_mismatched_access(ciConstant con, BasicType loadbt) {
   BasicType conbt = con.basic_type();
   switch (conbt) {
@@ -1597,7 +1596,6 @@
   }
   return (conbt != loadbt);
 }
-#endif // ASSERT
 
 // Try to constant-fold a stable array element.
 static const Type* fold_stable_ary_elem(const TypeAryPtr* ary, int off, BasicType loadbt) {
@@ -1608,10 +1606,11 @@
   ciArray* aobj = ary->const_oop()->as_array();
   ciConstant con = aobj->element_value_by_offset(off);
   if (con.basic_type() != T_ILLEGAL && !con.is_null_or_zero()) {
-    assert(!is_mismatched_access(con, loadbt),
-           "conbt=%s; loadbt=%s", type2name(con.basic_type()), type2name(loadbt));
+    bool is_mismatched = is_mismatched_access(con, loadbt);
+    assert(!is_mismatched, "conbt=%s; loadbt=%s", type2name(con.basic_type()), type2name(loadbt));
     const Type* con_type = Type::make_from_constant(con);
-    if (con_type != NULL) {
+    // Guard against erroneous constant folding.
+    if (!is_mismatched && con_type != NULL) {
       if (con_type->isa_aryptr()) {
         // Join with the array element type, in case it is also stable.
         int dim = ary->stable_dimension();