Mercurial > hg > graal-compiler
diff src/share/vm/opto/memnode.cpp @ 1080:7c57aead6d3e
6892658: C2 should optimize some stringbuilder patterns
Reviewed-by: kvn, twisti
author | never |
---|---|
date | Thu, 12 Nov 2009 09:24:21 -0800 |
parents | dcdcc8c16e20 |
children | f96a1a986f7b |
line wrap: on
line diff
--- a/src/share/vm/opto/memnode.cpp Fri Nov 27 07:56:58 2009 -0800 +++ b/src/share/vm/opto/memnode.cpp Thu Nov 12 09:24:21 2009 -0800 @@ -1503,6 +1503,8 @@ } } } else if (tp->base() == Type::InstPtr) { + 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() || @@ -1510,6 +1512,25 @@ phase->C->has_unsafe_access(), "Field accesses must be precise" ); // For oop loads, we expect the _type to be precise + if (OptimizeStringConcat && klass == phase->C->env()->String_klass() && + adr->is_AddP() && off != Type::OffsetBot) { + // For constant Strings treat the fields as compile time constants. + Node* base = adr->in(AddPNode::Base); + if (base->Opcode() == Op_ConP) { + const TypeOopPtr* t = phase->type(base)->isa_oopptr(); + ciObject* string = t->const_oop(); + ciConstant constant = string->as_instance()->field_value_by_offset(off); + 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()); + } else { + return TypeOopPtr::make_from_constant(constant.as_object()); + } + } + } + } } else if (tp->base() == Type::KlassPtr) { assert( off != Type::OffsetBot || // arrays can be cast to Objects