hotspot/src/share/vm/opto/memnode.cpp
changeset 32573 e0c433df24e0
parent 32372 b82e88dcb26c
child 33105 294e48b4f704
child 33077 55f205e96044
--- a/hotspot/src/share/vm/opto/memnode.cpp	Wed Aug 26 17:13:59 2015 +0100
+++ b/hotspot/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);
           }
         }
       }