src/hotspot/share/opto/doCall.cpp
changeset 53595 8462b295c08b
parent 53511 898dd0dc7ac0
child 53625 0a9dfdbb01d1
equal deleted inserted replaced
53594:47a8fdf84424 53595:8462b295c08b
   290             }
   290             }
   291           }
   291           }
   292         }
   292         }
   293       }
   293       }
   294     }
   294     }
       
   295 
       
   296     // If there is only one implementor of this interface then we
       
   297     // may be able to bind this invoke directly to the implementing
       
   298     // klass but we need both a dependence on the single interface
       
   299     // and on the method we bind to. Additionally since all we know
       
   300     // about the receiver type is that it's supposed to implement the
       
   301     // interface we have to insert a check that it's the class we
       
   302     // expect.  Interface types are not checked by the verifier so
       
   303     // they are roughly equivalent to Object.
       
   304     // The number of implementors for declared_interface is less or
       
   305     // equal to the number of implementors for target->holder() so
       
   306     // if number of implementors of target->holder() == 1 then
       
   307     // number of implementors for decl_interface is 0 or 1. If
       
   308     // it's 0 then no class implements decl_interface and there's
       
   309     // no point in inlining.
       
   310     if (call_does_dispatch && bytecode == Bytecodes::_invokeinterface) {
       
   311       ciInstanceKlass* declared_interface =
       
   312           caller->get_declared_method_holder_at_bci(bci)->as_instance_klass();
       
   313 
       
   314       if (declared_interface->nof_implementors() == 1 &&
       
   315           (!callee->is_default_method() || callee->is_overpass()) /* CHA doesn't support default methods yet */) {
       
   316         ciInstanceKlass* singleton = declared_interface->implementor();
       
   317         ciMethod* cha_monomorphic_target =
       
   318             callee->find_monomorphic_target(caller->holder(), declared_interface, singleton);
       
   319 
       
   320         if (cha_monomorphic_target != NULL &&
       
   321             cha_monomorphic_target->holder() != env()->Object_klass()) { // subtype check against Object is useless
       
   322           ciKlass* holder = cha_monomorphic_target->holder();
       
   323 
       
   324           // Try to inline the method found by CHA. Inlined method is guarded by the type check.
       
   325           CallGenerator* hit_cg = call_generator(cha_monomorphic_target,
       
   326               vtable_index, !call_does_dispatch, jvms, allow_inline, prof_factor);
       
   327 
       
   328           // Deoptimize on type check fail. The interpreter will throw ICCE for us.
       
   329           CallGenerator* miss_cg = CallGenerator::for_uncommon_trap(callee,
       
   330               Deoptimization::Reason_class_check, Deoptimization::Action_none);
       
   331 
       
   332           CallGenerator* cg = CallGenerator::for_guarded_call(holder, miss_cg, hit_cg);
       
   333           if (hit_cg != NULL && cg != NULL) {
       
   334             dependencies()->assert_unique_concrete_method(declared_interface, cha_monomorphic_target);
       
   335             return cg;
       
   336           }
       
   337         }
       
   338       }
       
   339     }
   295   }
   340   }
   296 
   341 
   297   // Nothing claimed the intrinsic, we go with straight-forward inlining
   342   // Nothing claimed the intrinsic, we go with straight-forward inlining
   298   // for already discovered intrinsic.
   343   // for already discovered intrinsic.
   299   if (allow_inline && allow_intrinsics && cg_intrinsic != NULL) {
   344   if (allow_inline && allow_intrinsics && cg_intrinsic != NULL) {