< prev index next >

src/hotspot/share/oops/cpCache.cpp

Print this page

194     if (do_resolve) {
195       method_entry->set_bytecode1(invoke_code);
196     }
197   } else if (byte_no == 2)  {
198     if (change_to_virtual) {
199       assert(invoke_code == Bytecodes::_invokeinterface, "");
200       // NOTE: THIS IS A HACK - BE VERY CAREFUL!!!
201       //
202       // Workaround for the case where we encounter an invokeinterface, but we
203       // should really have an _invokevirtual since the resolved method is a
204       // virtual method in java.lang.Object. This is a corner case in the spec
205       // but is presumably legal. javac does not generate this code.
206       //
207       // We do not set bytecode_1() to _invokeinterface, because that is the
208       // bytecode # used by the interpreter to see if it is resolved.  In this
209       // case, the method gets reresolved with caller for each interface call
210       // because the actual selected method may not be public.
211       //
212       // We set bytecode_2() to _invokevirtual.
213       // See also interpreterRuntime.cpp. (8/25/2000)

214     } else {
215       assert(invoke_code == Bytecodes::_invokevirtual ||
216              (invoke_code == Bytecodes::_invokeinterface &&
217               ((method->is_private() ||
218                 (method->is_final() && method->method_holder() == vmClasses::Object_klass())))),
219              "unexpected invocation mode");
220       if (invoke_code == Bytecodes::_invokeinterface &&
221           (method->is_private() || method->is_final())) {
222         // We set bytecode_1() to _invokeinterface, because that is the
223         // bytecode # used by the interpreter to see if it is resolved.
224         // We set bytecode_2() to _invokevirtual.
225         method_entry->set_bytecode1(invoke_code);
226       }
227     }
228     // set up for invokevirtual, even if linking for invokeinterface also:
229     method_entry->set_bytecode2(Bytecodes::_invokevirtual);
230   } else {
231     ShouldNotReachHere();
232   }
233 }
234 
235 void ConstantPoolCache::set_direct_call(Bytecodes::Code invoke_code, int method_index, const methodHandle& method,
236                                         bool sender_is_interface) {
237   int index = Method::nonvirtual_vtable_index;
238   // index < 0; FIXME: inline and customize set_direct_or_vtable_call
239   set_direct_or_vtable_call(invoke_code, method_index, method, index, sender_is_interface);
240 }
241 
242 void ConstantPoolCache::set_vtable_call(Bytecodes::Code invoke_code, int method_index, const methodHandle& method, int index) {
243   // either the method is a miranda or its holder should accept the given index
244   assert(method->method_holder()->is_interface() || method->method_holder()->verify_vtable_index(index), "");
245   // index >= 0; FIXME: inline and customize set_direct_or_vtable_call
246   set_direct_or_vtable_call(invoke_code, method_index, method, index, false);
247 }
248 
249 void ConstantPoolCache::set_itable_call(Bytecodes::Code invoke_code,

259   method_entry->set_klass(static_cast<InstanceKlass*>(referenced_klass));
260   method_entry->set_method(method());
261   method_entry->fill_in((u1)as_TosState(method->result_type()), (u2)method()->size_of_parameters());
262   method_entry->set_bytecode1(Bytecodes::_invokeinterface);
263 }
264 
265 ResolvedMethodEntry* ConstantPoolCache::set_method_handle(int method_index, const CallInfo &call_info) {
266   // NOTE: This method entry can be the subject of data races.
267   // There are three words to update: flags, refs[appendix_index], method (in that order).
268   // Writers must store all other values before method.
269   // Readers must test the method first for non-null before reading other fields.
270   // Competing writers must acquire exclusive access via a lock.
271   // A losing writer waits on the lock until the winner writes the method and leaves
272   // the lock, so that when the losing writer returns, he can use the linked
273   // cache entry.
274 
275   // Lock fields to write
276   Bytecodes::Code invoke_code = Bytecodes::_invokehandle;
277 
278   JavaThread* current = JavaThread::current();
279   objArrayHandle resolved_references(current, constant_pool()->resolved_references());
280   // Use the resolved_references() lock for this cpCache entry.
281   // resolved_references are created for all classes with Invokedynamic, MethodHandle
282   // or MethodType constant pool cache entries.
283   assert(resolved_references() != nullptr,
284          "a resolved_references array should have been created for this class");
285   ObjectLocker ol(resolved_references, current);
286 
287   ResolvedMethodEntry* method_entry = resolved_method_entry_at(method_index);
288   if (method_entry->is_resolved(invoke_code)) {
289     return method_entry;
290   }
291 
292   Method* adapter            = call_info.resolved_method();
293   const Handle appendix      = call_info.resolved_appendix();
294   const bool has_appendix    = appendix.not_null();
295 
296   // Write the flags.
297   // MHs are always sig-poly and have a local signature.
298   method_entry->fill_in((u1)as_TosState(adapter->result_type()), (u2)adapter->size_of_parameters());
299   method_entry->set_flags(((has_appendix    ? 1 : 0) << ResolvedMethodEntry::has_appendix_shift        ) |

776   }
777   ResourceMark rm(THREAD);
778   Symbol* error = PENDING_EXCEPTION->klass()->name();
779   const char* message = java_lang_Throwable::message_as_utf8(PENDING_EXCEPTION);
780 
781   int encoded_index = ResolutionErrorTable::encode_indy_index(index);
782   SystemDictionary::add_resolution_error(cpool, encoded_index, error, message);
783   resolved_indy_entry_at(index)->set_resolution_failed();
784   return true;
785 }
786 
787 oop ConstantPoolCache::set_dynamic_call(const CallInfo &call_info, int index) {
788   ResourceMark rm;
789 
790   // Use the resolved_references() lock for this cpCache entry.
791   // resolved_references are created for all classes with Invokedynamic, MethodHandle
792   // or MethodType constant pool cache entries.
793   JavaThread* current = JavaThread::current();
794   constantPoolHandle cp(current, constant_pool());
795 
796   objArrayHandle resolved_references(current, cp->resolved_references());
797   assert(resolved_references() != nullptr,
798          "a resolved_references array should have been created for this class");
799   ObjectLocker ol(resolved_references, current);
800   assert(index >= 0, "Indy index must be positive at this point");
801 
802   if (resolved_indy_entry_at(index)->method() != nullptr) {
803     return cp->resolved_reference_from_indy(index);
804   }
805 
806   if (resolved_indy_entry_at(index)->resolution_failed()) {
807     // Before we got here, another thread got a LinkageError exception during
808     // resolution.  Ignore our success and throw their exception.
809     guarantee(index >= 0, "Invalid indy index");
810     int encoded_index = ResolutionErrorTable::encode_indy_index(index);
811     ConstantPool::throw_resolution_error(cp, encoded_index, current);
812     return nullptr;
813   }
814 
815   Method* adapter            = call_info.resolved_method();
816   const Handle appendix      = call_info.resolved_appendix();

194     if (do_resolve) {
195       method_entry->set_bytecode1(invoke_code);
196     }
197   } else if (byte_no == 2)  {
198     if (change_to_virtual) {
199       assert(invoke_code == Bytecodes::_invokeinterface, "");
200       // NOTE: THIS IS A HACK - BE VERY CAREFUL!!!
201       //
202       // Workaround for the case where we encounter an invokeinterface, but we
203       // should really have an _invokevirtual since the resolved method is a
204       // virtual method in java.lang.Object. This is a corner case in the spec
205       // but is presumably legal. javac does not generate this code.
206       //
207       // We do not set bytecode_1() to _invokeinterface, because that is the
208       // bytecode # used by the interpreter to see if it is resolved.  In this
209       // case, the method gets reresolved with caller for each interface call
210       // because the actual selected method may not be public.
211       //
212       // We set bytecode_2() to _invokevirtual.
213       // See also interpreterRuntime.cpp. (8/25/2000)
214       invoke_code = Bytecodes::_invokevirtual;
215     } else {
216       assert(invoke_code == Bytecodes::_invokevirtual ||
217              (invoke_code == Bytecodes::_invokeinterface &&
218               ((method->is_private() ||
219                 (method->is_final() && method->method_holder() == vmClasses::Object_klass())))),
220              "unexpected invocation mode");
221       if (invoke_code == Bytecodes::_invokeinterface &&
222           (method->is_private() || method->is_final())) {
223         // We set bytecode_1() to _invokeinterface, because that is the
224         // bytecode # used by the interpreter to see if it is resolved.
225         // We set bytecode_2() to _invokevirtual.
226         method_entry->set_bytecode1(invoke_code);
227       }
228     }
229     // set up for invokevirtual, even if linking for invokeinterface also:
230     method_entry->set_bytecode2(invoke_code);
231   } else {
232     ShouldNotReachHere();
233   }
234 }
235 
236 void ConstantPoolCache::set_direct_call(Bytecodes::Code invoke_code, int method_index, const methodHandle& method,
237                                         bool sender_is_interface) {
238   int index = Method::nonvirtual_vtable_index;
239   // index < 0; FIXME: inline and customize set_direct_or_vtable_call
240   set_direct_or_vtable_call(invoke_code, method_index, method, index, sender_is_interface);
241 }
242 
243 void ConstantPoolCache::set_vtable_call(Bytecodes::Code invoke_code, int method_index, const methodHandle& method, int index) {
244   // either the method is a miranda or its holder should accept the given index
245   assert(method->method_holder()->is_interface() || method->method_holder()->verify_vtable_index(index), "");
246   // index >= 0; FIXME: inline and customize set_direct_or_vtable_call
247   set_direct_or_vtable_call(invoke_code, method_index, method, index, false);
248 }
249 
250 void ConstantPoolCache::set_itable_call(Bytecodes::Code invoke_code,

260   method_entry->set_klass(static_cast<InstanceKlass*>(referenced_klass));
261   method_entry->set_method(method());
262   method_entry->fill_in((u1)as_TosState(method->result_type()), (u2)method()->size_of_parameters());
263   method_entry->set_bytecode1(Bytecodes::_invokeinterface);
264 }
265 
266 ResolvedMethodEntry* ConstantPoolCache::set_method_handle(int method_index, const CallInfo &call_info) {
267   // NOTE: This method entry can be the subject of data races.
268   // There are three words to update: flags, refs[appendix_index], method (in that order).
269   // Writers must store all other values before method.
270   // Readers must test the method first for non-null before reading other fields.
271   // Competing writers must acquire exclusive access via a lock.
272   // A losing writer waits on the lock until the winner writes the method and leaves
273   // the lock, so that when the losing writer returns, he can use the linked
274   // cache entry.
275 
276   // Lock fields to write
277   Bytecodes::Code invoke_code = Bytecodes::_invokehandle;
278 
279   JavaThread* current = JavaThread::current();
280   refArrayHandle resolved_references(current, constant_pool()->resolved_references());
281   // Use the resolved_references() lock for this cpCache entry.
282   // resolved_references are created for all classes with Invokedynamic, MethodHandle
283   // or MethodType constant pool cache entries.
284   assert(resolved_references() != nullptr,
285          "a resolved_references array should have been created for this class");
286   ObjectLocker ol(resolved_references, current);
287 
288   ResolvedMethodEntry* method_entry = resolved_method_entry_at(method_index);
289   if (method_entry->is_resolved(invoke_code)) {
290     return method_entry;
291   }
292 
293   Method* adapter            = call_info.resolved_method();
294   const Handle appendix      = call_info.resolved_appendix();
295   const bool has_appendix    = appendix.not_null();
296 
297   // Write the flags.
298   // MHs are always sig-poly and have a local signature.
299   method_entry->fill_in((u1)as_TosState(adapter->result_type()), (u2)adapter->size_of_parameters());
300   method_entry->set_flags(((has_appendix    ? 1 : 0) << ResolvedMethodEntry::has_appendix_shift        ) |

777   }
778   ResourceMark rm(THREAD);
779   Symbol* error = PENDING_EXCEPTION->klass()->name();
780   const char* message = java_lang_Throwable::message_as_utf8(PENDING_EXCEPTION);
781 
782   int encoded_index = ResolutionErrorTable::encode_indy_index(index);
783   SystemDictionary::add_resolution_error(cpool, encoded_index, error, message);
784   resolved_indy_entry_at(index)->set_resolution_failed();
785   return true;
786 }
787 
788 oop ConstantPoolCache::set_dynamic_call(const CallInfo &call_info, int index) {
789   ResourceMark rm;
790 
791   // Use the resolved_references() lock for this cpCache entry.
792   // resolved_references are created for all classes with Invokedynamic, MethodHandle
793   // or MethodType constant pool cache entries.
794   JavaThread* current = JavaThread::current();
795   constantPoolHandle cp(current, constant_pool());
796 
797   refArrayHandle resolved_references(current, cp->resolved_references());
798   assert(resolved_references() != nullptr,
799          "a resolved_references array should have been created for this class");
800   ObjectLocker ol(resolved_references, current);
801   assert(index >= 0, "Indy index must be positive at this point");
802 
803   if (resolved_indy_entry_at(index)->method() != nullptr) {
804     return cp->resolved_reference_from_indy(index);
805   }
806 
807   if (resolved_indy_entry_at(index)->resolution_failed()) {
808     // Before we got here, another thread got a LinkageError exception during
809     // resolution.  Ignore our success and throw their exception.
810     guarantee(index >= 0, "Invalid indy index");
811     int encoded_index = ResolutionErrorTable::encode_indy_index(index);
812     ConstantPool::throw_resolution_error(cp, encoded_index, current);
813     return nullptr;
814   }
815 
816   Method* adapter            = call_info.resolved_method();
817   const Handle appendix      = call_info.resolved_appendix();
< prev index next >