RFR 8208163 [lworld] performance regression on String(char[]) constructor

Ioi Lam ioi.lam at oracle.com
Fri Aug 10 21:37:56 UTC 2018


https://bugs.openjdk.java.net/browse/JDK-8208163
http://cr.openjdk.java.net/~iklam/valhalla/8208163_string_charary_ctor_slowdown.v01/

In the following code:

http://hg.openjdk.java.net/valhalla/valhalla/annotate/7feb5ae0f3dc/src/hotspot/share/opto/graphKit.cpp#l3962

   const TypeInt* length_type = _gvn.find_int_type(length);
   const TypeOopPtr* ary_type = 
_gvn.type(klass_node)->is_klassptr()->as_instance_type();
   ....
   const TypeAryPtr* ary_ptr = ary_type->isa_aryptr();
   ciKlass* elem_klass = ary_ptr != NULL ? 
ary_ptr->klass()->as_array_klass()->element_klass() : NULL;
   ...
   } else if (EnableValhalla && (!layout_con || elem_klass == NULL ||
                 (elem_klass->is_java_lang_Object() && 
!ary_type->klass_is_exact()))) {

     InitializeNode* init = alloc->initialization();
     init->set_unknown_value();
   }

I think the intention of the (elem_klass == NULL) check is for cases 
like the following

   class compiler.valhalla.valuetypes.TestIntrinsics {
   public void test7(Class<?> componentType, int len, long hash) {
       Object[] va = (Object[])Array.newInstance(componentType, len);
       ...

The Array.newInstance call is inlined, but the array type is unknown --
newInstance returns an Object, so ary_type is java/lang/Object.

However, elem_klass is also NULL for primitive arrays. This is the root 
cause for JDK-8208163.

The fix is to replace elem_klass == NULL) with 
(!ary_type->isa_aryptr()), which
covers the Array.newInstance case without affecting primitive arrays.

Thanks
- Ioi




More information about the valhalla-dev mailing list