< prev index next >

src/hotspot/share/oops/cpCache.cpp

Print this page




 156   // bother trying to update it once it's nonzero but always make
 157   // sure that the final parameter size agrees with what was passed.
 158   if (_flags == 0) {
 159     intx newflags = (value & parameter_size_mask);
 160     Atomic::cmpxchg(newflags, &_flags, (intx)0);
 161   }
 162   guarantee(parameter_size() == value,
 163             "size must not change: parameter_size=%d, value=%d", parameter_size(), value);
 164 }
 165 
 166 void ConstantPoolCacheEntry::set_direct_or_vtable_call(Bytecodes::Code invoke_code,
 167                                                        const methodHandle& method,
 168                                                        int vtable_index,
 169                                                        bool sender_is_interface) {
 170   bool is_vtable_call = (vtable_index >= 0);  // FIXME: split this method on this boolean
 171   assert(method->interpreter_entry() != NULL, "should have been set at this point");
 172   assert(!method->is_obsolete(),  "attempt to write obsolete method to cpCache");
 173 
 174   int byte_no = -1;
 175   bool change_to_virtual = false;
 176 
 177   switch (invoke_code) {
 178     case Bytecodes::_invokeinterface:
















 179       // We get here from InterpreterRuntime::resolve_invoke when an invokeinterface
 180       // instruction somehow links to a non-interface method (in Object).


 181       // In that case, the method has no itable index and must be invoked as a virtual.
 182       // Set a flag to keep track of this corner case.

 183       assert(method->is_public(), "Calling non-public method in Object with invokeinterface");
 184       change_to_virtual = true;
 185 
 186       // ...and fall through as if we were handling invokevirtual:

 187     case Bytecodes::_invokevirtual:
 188       {
 189         if (!is_vtable_call) {
 190           assert(method->can_be_statically_bound(), "");
 191           // set_f2_as_vfinal_method checks if is_vfinal flag is true.
 192           set_method_flags(as_TosState(method->result_type()),
 193                            (                             1      << is_vfinal_shift) |
 194                            ((method->is_final_method() ? 1 : 0) << is_final_shift)  |
 195                            ((change_to_virtual         ? 1 : 0) << is_forced_virtual_shift),
 196                            method()->size_of_parameters());
 197           set_f2_as_vfinal_method(method());
 198         } else {
 199           assert(!method->can_be_statically_bound(), "");
 200           assert(vtable_index >= 0, "valid index");
 201           assert(!method->is_final_method(), "sanity");
 202           set_method_flags(as_TosState(method->result_type()),
 203                            ((change_to_virtual ? 1 : 0) << is_forced_virtual_shift),
 204                            method()->size_of_parameters());
 205           set_f2(vtable_index);
 206         }


 239     set_bytecode_1(invoke_code);
 240     }
 241   } else if (byte_no == 2)  {
 242     if (change_to_virtual) {
 243       assert(invoke_code == Bytecodes::_invokeinterface, "");
 244       // NOTE: THIS IS A HACK - BE VERY CAREFUL!!!
 245       //
 246       // Workaround for the case where we encounter an invokeinterface, but we
 247       // should really have an _invokevirtual since the resolved method is a
 248       // virtual method in java.lang.Object. This is a corner case in the spec
 249       // but is presumably legal. javac does not generate this code.
 250       //
 251       // We do not set bytecode_1() to _invokeinterface, because that is the
 252       // bytecode # used by the interpreter to see if it is resolved.  In this
 253       // case, the method gets reresolved with caller for each interface call
 254       // because the actual selected method may not be public.
 255       //
 256       // We set bytecode_2() to _invokevirtual.
 257       // See also interpreterRuntime.cpp. (8/25/2000)
 258     } else {
 259       assert(invoke_code == Bytecodes::_invokevirtual, "");











 260     }
 261     // set up for invokevirtual, even if linking for invokeinterface also:
 262     set_bytecode_2(Bytecodes::_invokevirtual);
 263   } else {
 264     ShouldNotReachHere();
 265   }
 266   NOT_PRODUCT(verify(tty));
 267 }
 268 
 269 void ConstantPoolCacheEntry::set_direct_call(Bytecodes::Code invoke_code, const methodHandle& method,
 270                                              bool sender_is_interface) {
 271   int index = Method::nonvirtual_vtable_index;
 272   // index < 0; FIXME: inline and customize set_direct_or_vtable_call
 273   set_direct_or_vtable_call(invoke_code, method, index, sender_is_interface);
 274 }
 275 
 276 void ConstantPoolCacheEntry::set_vtable_call(Bytecodes::Code invoke_code, const methodHandle& method, int index) {
 277   // either the method is a miranda or its holder should accept the given index
 278   assert(method->method_holder()->is_interface() || method->method_holder()->verify_vtable_index(index), "");
 279   // index >= 0; FIXME: inline and customize set_direct_or_vtable_call




 156   // bother trying to update it once it's nonzero but always make
 157   // sure that the final parameter size agrees with what was passed.
 158   if (_flags == 0) {
 159     intx newflags = (value & parameter_size_mask);
 160     Atomic::cmpxchg(newflags, &_flags, (intx)0);
 161   }
 162   guarantee(parameter_size() == value,
 163             "size must not change: parameter_size=%d, value=%d", parameter_size(), value);
 164 }
 165 
 166 void ConstantPoolCacheEntry::set_direct_or_vtable_call(Bytecodes::Code invoke_code,
 167                                                        const methodHandle& method,
 168                                                        int vtable_index,
 169                                                        bool sender_is_interface) {
 170   bool is_vtable_call = (vtable_index >= 0);  // FIXME: split this method on this boolean
 171   assert(method->interpreter_entry() != NULL, "should have been set at this point");
 172   assert(!method->is_obsolete(),  "attempt to write obsolete method to cpCache");
 173 
 174   int byte_no = -1;
 175   bool change_to_virtual = false;
 176   InstanceKlass* holder = NULL;  // have to declare this outside the switch
 177   switch (invoke_code) {
 178     case Bytecodes::_invokeinterface:
 179       holder = method->method_holder();
 180       // check for private interface method invocations
 181       if (vtable_index == Method::nonvirtual_vtable_index && holder->is_interface() ) {
 182         assert(method->is_private(), "unexpected non-private method");
 183         assert(method->can_be_statically_bound(), "unexpected non-statically-bound method");
 184         // set_f2_as_vfinal_method checks if is_vfinal flag is true.
 185         set_method_flags(as_TosState(method->result_type()),
 186                          (                             1      << is_vfinal_shift) |
 187                          ((method->is_final_method() ? 1 : 0) << is_final_shift),
 188                          method()->size_of_parameters());
 189         set_f2_as_vfinal_method(method());
 190         byte_no = 2;
 191         set_f1(holder); // interface klass*
 192         break;
 193       }
 194       else {
 195         // We get here from InterpreterRuntime::resolve_invoke when an invokeinterface
 196         // instruction links to a non-interface method (in Object). This can happen when
 197         // an interface redeclares an Object method (like CharSequence declaring toString())
 198         // or when invokeinterface is used explicitly.
 199         // In that case, the method has no itable index and must be invoked as a virtual.
 200         // Set a flag to keep track of this corner case.
 201         assert(holder->is_interface() || holder == SystemDictionary::Object_klass(), "unexpected holder class");
 202         assert(method->is_public(), "Calling non-public method in Object with invokeinterface");
 203         change_to_virtual = true;
 204 
 205         // ...and fall through as if we were handling invokevirtual:
 206       }
 207     case Bytecodes::_invokevirtual:
 208       {
 209         if (!is_vtable_call) {
 210           assert(method->can_be_statically_bound(), "");
 211           // set_f2_as_vfinal_method checks if is_vfinal flag is true.
 212           set_method_flags(as_TosState(method->result_type()),
 213                            (                             1      << is_vfinal_shift) |
 214                            ((method->is_final_method() ? 1 : 0) << is_final_shift)  |
 215                            ((change_to_virtual         ? 1 : 0) << is_forced_virtual_shift),
 216                            method()->size_of_parameters());
 217           set_f2_as_vfinal_method(method());
 218         } else {
 219           assert(!method->can_be_statically_bound(), "");
 220           assert(vtable_index >= 0, "valid index");
 221           assert(!method->is_final_method(), "sanity");
 222           set_method_flags(as_TosState(method->result_type()),
 223                            ((change_to_virtual ? 1 : 0) << is_forced_virtual_shift),
 224                            method()->size_of_parameters());
 225           set_f2(vtable_index);
 226         }


 259       set_bytecode_1(invoke_code);
 260     }
 261   } else if (byte_no == 2)  {
 262     if (change_to_virtual) {
 263       assert(invoke_code == Bytecodes::_invokeinterface, "");
 264       // NOTE: THIS IS A HACK - BE VERY CAREFUL!!!
 265       //
 266       // Workaround for the case where we encounter an invokeinterface, but we
 267       // should really have an _invokevirtual since the resolved method is a
 268       // virtual method in java.lang.Object. This is a corner case in the spec
 269       // but is presumably legal. javac does not generate this code.
 270       //
 271       // We do not set bytecode_1() to _invokeinterface, because that is the
 272       // bytecode # used by the interpreter to see if it is resolved.  In this
 273       // case, the method gets reresolved with caller for each interface call
 274       // because the actual selected method may not be public.
 275       //
 276       // We set bytecode_2() to _invokevirtual.
 277       // See also interpreterRuntime.cpp. (8/25/2000)
 278     } else {
 279       assert(invoke_code == Bytecodes::_invokevirtual ||
 280              (invoke_code == Bytecodes::_invokeinterface &&
 281               ((method->is_private() ||
 282                 (method->is_final() && method->method_holder() == SystemDictionary::Object_klass())))),
 283              "unexpected invocation mode");
 284       if (invoke_code == Bytecodes::_invokeinterface &&
 285           (method->is_private() || method->is_final())) {
 286         // We set bytecode_1() to _invokeinterface, because that is the
 287         // bytecode # used by the interpreter to see if it is resolved.
 288         // We set bytecode_2() to _invokevirtual.
 289         set_bytecode_1(invoke_code);
 290       }
 291     }
 292     // set up for invokevirtual, even if linking for invokeinterface also:
 293     set_bytecode_2(Bytecodes::_invokevirtual);
 294   } else {
 295     ShouldNotReachHere();
 296   }
 297   NOT_PRODUCT(verify(tty));
 298 }
 299 
 300 void ConstantPoolCacheEntry::set_direct_call(Bytecodes::Code invoke_code, const methodHandle& method,
 301                                              bool sender_is_interface) {
 302   int index = Method::nonvirtual_vtable_index;
 303   // index < 0; FIXME: inline and customize set_direct_or_vtable_call
 304   set_direct_or_vtable_call(invoke_code, method, index, sender_is_interface);
 305 }
 306 
 307 void ConstantPoolCacheEntry::set_vtable_call(Bytecodes::Code invoke_code, const methodHandle& method, int index) {
 308   // either the method is a miranda or its holder should accept the given index
 309   assert(method->method_holder()->is_interface() || method->method_holder()->verify_vtable_index(index), "");
 310   // index >= 0; FIXME: inline and customize set_direct_or_vtable_call


< prev index next >