changeset 8902:c530a118f715

8134758: Final String field values should be trusted as stable Reviewed-by: kvn, thartmann
author shade
date Tue, 01 Sep 2015 19:48:10 +0300
parents 7df0e3f7ad65
children da1c9ea76ce5
files src/share/vm/opto/memnode.cpp
diffstat 1 files changed, 10 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/vm/opto/memnode.cpp	Wed Aug 26 17:13:59 2015 +0100
+++ b/src/share/vm/opto/memnode.cpp	Tue Sep 01 19:48:10 2015 +0300
@@ -1677,6 +1677,9 @@
     if (klass == env->String_klass() &&
         adr->is_AddP() && off != Type::OffsetBot) {
       // For constant Strings treat the final fields as compile time constants.
+      // While we can list what field types java.lang.String has, it is more
+      // future-proof to handle all possible field types, anticipating future
+      // changes and experiments in String code.
       Node* base = adr->in(AddPNode::Base);
       const TypeOopPtr* t = phase->type(base)->isa_oopptr();
       if (t != NULL && t->singleton()) {
@@ -1684,14 +1687,13 @@
         if (field != NULL && field->is_final()) {
           ciObject* string = t->const_oop();
           ciConstant constant = string->as_instance()->field_value(field);
-          if (constant.basic_type() == T_INT) {
-            return TypeInt::make(constant.as_int());
-          } else if (constant.basic_type() == T_ARRAY) {
-            if (adr->bottom_type()->is_ptr_to_narrowoop()) {
-              return TypeNarrowOop::make_from_constant(constant.as_object(), true);
-            } else {
-              return TypeOopPtr::make_from_constant(constant.as_object(), true);
-            }
+          // Type::make_from_constant does not handle narrow oops, so handle it here.
+          // Everything else can use the factory method.
+          if ((constant.basic_type() == T_ARRAY || constant.basic_type() == T_OBJECT)
+                  && adr->bottom_type()->is_ptr_to_narrowoop()) {
+            return TypeNarrowOop::make_from_constant(constant.as_object(), true);
+          } else {
+            return Type::make_from_constant(constant, true);
           }
         }
       }