src/hotspot/share/oops/cpCache.cpp
changeset 50735 2f2af62dfac7
parent 50532 a18c60527166
child 51329 9c68699bebe5
equal deleted inserted replaced
50734:0828a0f6676b 50735:2f2af62dfac7
   172   assert(method->interpreter_entry() != NULL, "should have been set at this point");
   172   assert(method->interpreter_entry() != NULL, "should have been set at this point");
   173   assert(!method->is_obsolete(),  "attempt to write obsolete method to cpCache");
   173   assert(!method->is_obsolete(),  "attempt to write obsolete method to cpCache");
   174 
   174 
   175   int byte_no = -1;
   175   int byte_no = -1;
   176   bool change_to_virtual = false;
   176   bool change_to_virtual = false;
   177 
   177   InstanceKlass* holder = NULL;  // have to declare this outside the switch
   178   switch (invoke_code) {
   178   switch (invoke_code) {
   179     case Bytecodes::_invokeinterface:
   179     case Bytecodes::_invokeinterface:
   180       // We get here from InterpreterRuntime::resolve_invoke when an invokeinterface
   180       holder = method->method_holder();
   181       // instruction somehow links to a non-interface method (in Object).
   181       // check for private interface method invocations
   182       // In that case, the method has no itable index and must be invoked as a virtual.
   182       if (vtable_index == Method::nonvirtual_vtable_index && holder->is_interface() ) {
   183       // Set a flag to keep track of this corner case.
   183         assert(method->is_private(), "unexpected non-private method");
   184       assert(method->is_public(), "Calling non-public method in Object with invokeinterface");
   184         assert(method->can_be_statically_bound(), "unexpected non-statically-bound method");
   185       change_to_virtual = true;
   185         // set_f2_as_vfinal_method checks if is_vfinal flag is true.
   186 
   186         set_method_flags(as_TosState(method->result_type()),
   187       // ...and fall through as if we were handling invokevirtual:
   187                          (                             1      << is_vfinal_shift) |
       
   188                          ((method->is_final_method() ? 1 : 0) << is_final_shift),
       
   189                          method()->size_of_parameters());
       
   190         set_f2_as_vfinal_method(method());
       
   191         byte_no = 2;
       
   192         set_f1(holder); // interface klass*
       
   193         break;
       
   194       }
       
   195       else {
       
   196         // We get here from InterpreterRuntime::resolve_invoke when an invokeinterface
       
   197         // instruction links to a non-interface method (in Object). This can happen when
       
   198         // an interface redeclares an Object method (like CharSequence declaring toString())
       
   199         // or when invokeinterface is used explicitly.
       
   200         // In that case, the method has no itable index and must be invoked as a virtual.
       
   201         // Set a flag to keep track of this corner case.
       
   202         assert(holder->is_interface() || holder == SystemDictionary::Object_klass(), "unexpected holder class");
       
   203         assert(method->is_public(), "Calling non-public method in Object with invokeinterface");
       
   204         change_to_virtual = true;
       
   205 
       
   206         // ...and fall through as if we were handling invokevirtual:
       
   207       }
   188     case Bytecodes::_invokevirtual:
   208     case Bytecodes::_invokevirtual:
   189       {
   209       {
   190         if (!is_vtable_call) {
   210         if (!is_vtable_call) {
   191           assert(method->can_be_statically_bound(), "");
   211           assert(method->can_be_statically_bound(), "");
   192           // set_f2_as_vfinal_method checks if is_vfinal flag is true.
   212           // set_f2_as_vfinal_method checks if is_vfinal flag is true.
   235     // Don't mark invokespecial to method as resolved if sender is an interface.  The receiver
   255     // Don't mark invokespecial to method as resolved if sender is an interface.  The receiver
   236     // has to be checked that it is a subclass of the current class every time this bytecode
   256     // has to be checked that it is a subclass of the current class every time this bytecode
   237     // is executed.
   257     // is executed.
   238     if (invoke_code != Bytecodes::_invokespecial || !sender_is_interface ||
   258     if (invoke_code != Bytecodes::_invokespecial || !sender_is_interface ||
   239         method->name() == vmSymbols::object_initializer_name()) {
   259         method->name() == vmSymbols::object_initializer_name()) {
   240     set_bytecode_1(invoke_code);
   260       set_bytecode_1(invoke_code);
   241     }
   261     }
   242   } else if (byte_no == 2)  {
   262   } else if (byte_no == 2)  {
   243     if (change_to_virtual) {
   263     if (change_to_virtual) {
   244       assert(invoke_code == Bytecodes::_invokeinterface, "");
   264       assert(invoke_code == Bytecodes::_invokeinterface, "");
   245       // NOTE: THIS IS A HACK - BE VERY CAREFUL!!!
   265       // NOTE: THIS IS A HACK - BE VERY CAREFUL!!!
   255       // because the actual selected method may not be public.
   275       // because the actual selected method may not be public.
   256       //
   276       //
   257       // We set bytecode_2() to _invokevirtual.
   277       // We set bytecode_2() to _invokevirtual.
   258       // See also interpreterRuntime.cpp. (8/25/2000)
   278       // See also interpreterRuntime.cpp. (8/25/2000)
   259     } else {
   279     } else {
   260       assert(invoke_code == Bytecodes::_invokevirtual, "");
   280       assert(invoke_code == Bytecodes::_invokevirtual ||
       
   281              (invoke_code == Bytecodes::_invokeinterface &&
       
   282               ((method->is_private() ||
       
   283                 (method->is_final() && method->method_holder() == SystemDictionary::Object_klass())))),
       
   284              "unexpected invocation mode");
       
   285       if (invoke_code == Bytecodes::_invokeinterface &&
       
   286           (method->is_private() || method->is_final())) {
       
   287         // We set bytecode_1() to _invokeinterface, because that is the
       
   288         // bytecode # used by the interpreter to see if it is resolved.
       
   289         // We set bytecode_2() to _invokevirtual.
       
   290         set_bytecode_1(invoke_code);
       
   291       }
   261     }
   292     }
   262     // set up for invokevirtual, even if linking for invokeinterface also:
   293     // set up for invokevirtual, even if linking for invokeinterface also:
   263     set_bytecode_2(Bytecodes::_invokevirtual);
   294     set_bytecode_2(Bytecodes::_invokevirtual);
   264   } else {
   295   } else {
   265     ShouldNotReachHere();
   296     ShouldNotReachHere();