1 /* 2 * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #include "precompiled.hpp" 26 #include "classfile/defaultMethods.hpp" 27 #include "classfile/symbolTable.hpp" 28 #include "classfile/systemDictionary.hpp" 29 #include "classfile/vmSymbols.hpp" 30 #include "compiler/compileBroker.hpp" 31 #include "gc/shared/collectedHeap.inline.hpp" 32 #include "interpreter/bytecode.hpp" 33 #include "interpreter/interpreterRuntime.hpp" 34 #include "interpreter/linkResolver.hpp" 35 #include "logging/log.hpp" 36 #include "memory/resourceArea.hpp" 37 #include "memory/universe.inline.hpp" 38 #include "oops/instanceKlass.hpp" 39 #include "oops/method.hpp" 40 #include "oops/objArrayOop.hpp" 41 #include "oops/oop.inline.hpp" 42 #include "prims/methodHandles.hpp" 43 #include "prims/nativeLookup.hpp" 44 #include "runtime/compilationPolicy.hpp" 45 #include "runtime/fieldDescriptor.hpp" 46 #include "runtime/frame.inline.hpp" 47 #include "runtime/handles.inline.hpp" 48 #include "runtime/reflection.hpp" 49 #include "runtime/signature.hpp" 50 #include "runtime/thread.inline.hpp" 51 #include "runtime/vmThread.hpp" 52 53 54 //------------------------------------------------------------------------------------------------------------------------ 55 // Implementation of CallInfo 56 57 58 void CallInfo::set_static(KlassHandle resolved_klass, const methodHandle& resolved_method, TRAPS) { 59 int vtable_index = Method::nonvirtual_vtable_index; 60 set_common(resolved_klass, resolved_klass, resolved_method, resolved_method, CallInfo::direct_call, vtable_index, CHECK); 61 } 62 63 64 void CallInfo::set_interface(KlassHandle resolved_klass, 65 KlassHandle selected_klass, 66 const methodHandle& resolved_method, 67 const methodHandle& selected_method, 68 int itable_index, TRAPS) { 69 // This is only called for interface methods. If the resolved_method 70 // comes from java/lang/Object, it can be the subject of a virtual call, so 71 // we should pick the vtable index from the resolved method. 72 // In that case, the caller must call set_virtual instead of set_interface. 73 assert(resolved_method->method_holder()->is_interface(), ""); 74 assert(itable_index == resolved_method()->itable_index(), ""); 75 set_common(resolved_klass, selected_klass, resolved_method, selected_method, CallInfo::itable_call, itable_index, CHECK); 76 } 77 78 void CallInfo::set_virtual(KlassHandle resolved_klass, 79 KlassHandle selected_klass, 80 const methodHandle& resolved_method, 81 const methodHandle& selected_method, 82 int vtable_index, TRAPS) { 83 assert(vtable_index >= 0 || vtable_index == Method::nonvirtual_vtable_index, "valid index"); 84 assert(vtable_index < 0 || !resolved_method->has_vtable_index() || vtable_index == resolved_method->vtable_index(), ""); 85 CallKind kind = (vtable_index >= 0 && !resolved_method->can_be_statically_bound() ? CallInfo::vtable_call : CallInfo::direct_call); 86 set_common(resolved_klass, selected_klass, resolved_method, selected_method, kind, vtable_index, CHECK); 87 assert(!resolved_method->is_compiled_lambda_form(), "these must be handled via an invokehandle call"); 88 } 89 90 void CallInfo::set_handle(const methodHandle& resolved_method, 91 Handle resolved_appendix, 92 Handle resolved_method_type, TRAPS) { 93 set_handle(SystemDictionary::MethodHandle_klass(), resolved_method, resolved_appendix, resolved_method_type, CHECK); 94 } 95 96 void CallInfo::set_handle(KlassHandle resolved_klass, 97 const methodHandle& resolved_method, 98 Handle resolved_appendix, 99 Handle resolved_method_type, TRAPS) { 100 if (resolved_method.is_null()) { 101 THROW_MSG(vmSymbols::java_lang_InternalError(), "resolved method is null"); 102 } 103 assert(resolved_method->intrinsic_id() == vmIntrinsics::_invokeBasic || 104 resolved_method->is_compiled_lambda_form(), 105 "linkMethod must return one of these"); 106 int vtable_index = Method::nonvirtual_vtable_index; 107 assert(!resolved_method->has_vtable_index(), ""); 108 set_common(resolved_klass, resolved_klass, resolved_method, resolved_method, CallInfo::direct_call, vtable_index, CHECK); 109 _resolved_appendix = resolved_appendix; 110 _resolved_method_type = resolved_method_type; 111 } 112 113 void CallInfo::set_common(KlassHandle resolved_klass, 114 KlassHandle selected_klass, 115 const methodHandle& resolved_method, 116 const methodHandle& selected_method, 117 CallKind kind, 118 int index, 119 TRAPS) { 120 assert(resolved_method->signature() == selected_method->signature(), "signatures must correspond"); 121 _resolved_klass = resolved_klass; 122 _selected_klass = selected_klass; 123 _resolved_method = resolved_method; 124 _selected_method = selected_method; 125 _call_kind = kind; 126 _call_index = index; 127 _resolved_appendix = Handle(); 128 DEBUG_ONLY(verify()); // verify before making side effects 129 130 CompilationPolicy::compile_if_required(selected_method, THREAD); 131 } 132 133 // utility query for unreflecting a method 134 CallInfo::CallInfo(Method* resolved_method, Klass* resolved_klass) { 135 Klass* resolved_method_holder = resolved_method->method_holder(); 136 if (resolved_klass == NULL) { // 2nd argument defaults to holder of 1st 137 resolved_klass = resolved_method_holder; 138 } 139 _resolved_klass = resolved_klass; 140 _selected_klass = resolved_klass; 141 _resolved_method = resolved_method; 142 _selected_method = resolved_method; 143 // classify: 144 CallKind kind = CallInfo::unknown_kind; 145 int index = resolved_method->vtable_index(); 146 if (resolved_method->can_be_statically_bound()) { 147 kind = CallInfo::direct_call; 148 } else if (!resolved_method_holder->is_interface()) { 149 // Could be an Object method inherited into an interface, but still a vtable call. 150 kind = CallInfo::vtable_call; 151 } else if (!resolved_klass->is_interface()) { 152 // A default or miranda method. Compute the vtable index. 153 ResourceMark rm; 154 klassVtable* vt = resolved_klass->vtable(); 155 index = LinkResolver::vtable_index_of_interface_method(resolved_klass, 156 resolved_method); 157 assert(index >= 0 , "we should have valid vtable index at this point"); 158 159 kind = CallInfo::vtable_call; 160 } else if (resolved_method->has_vtable_index()) { 161 // Can occur if an interface redeclares a method of Object. 162 163 #ifdef ASSERT 164 // Ensure that this is really the case. 165 KlassHandle object_klass = SystemDictionary::Object_klass(); 166 Method * object_resolved_method = object_klass()->vtable()->method_at(index); 167 assert(object_resolved_method->name() == resolved_method->name(), 168 "Object and interface method names should match at vtable index %d, %s != %s", 169 index, object_resolved_method->name()->as_C_string(), resolved_method->name()->as_C_string()); 170 assert(object_resolved_method->signature() == resolved_method->signature(), 171 "Object and interface method signatures should match at vtable index %d, %s != %s", 172 index, object_resolved_method->signature()->as_C_string(), resolved_method->signature()->as_C_string()); 173 #endif // ASSERT 174 175 kind = CallInfo::vtable_call; 176 } else { 177 // A regular interface call. 178 kind = CallInfo::itable_call; 179 index = resolved_method->itable_index(); 180 } 181 assert(index == Method::nonvirtual_vtable_index || index >= 0, "bad index %d", index); 182 _call_kind = kind; 183 _call_index = index; 184 _resolved_appendix = Handle(); 185 DEBUG_ONLY(verify()); 186 } 187 188 #ifdef ASSERT 189 void CallInfo::verify() { 190 switch (call_kind()) { // the meaning and allowed value of index depends on kind 191 case CallInfo::direct_call: 192 if (_call_index == Method::nonvirtual_vtable_index) break; 193 // else fall through to check vtable index: 194 case CallInfo::vtable_call: 195 assert(resolved_klass()->verify_vtable_index(_call_index), ""); 196 break; 197 case CallInfo::itable_call: 198 assert(resolved_method()->method_holder()->verify_itable_index(_call_index), ""); 199 break; 200 case CallInfo::unknown_kind: 201 assert(call_kind() != CallInfo::unknown_kind, "CallInfo must be set"); 202 break; 203 default: 204 fatal("Unexpected call kind %d", call_kind()); 205 } 206 } 207 #endif //ASSERT 208 209 #ifndef PRODUCT 210 void CallInfo::print() { 211 ResourceMark rm; 212 const char* kindstr = "unknown"; 213 switch (_call_kind) { 214 case direct_call: kindstr = "direct"; break; 215 case vtable_call: kindstr = "vtable"; break; 216 case itable_call: kindstr = "itable"; break; 217 } 218 tty->print_cr("Call %s@%d %s", kindstr, _call_index, 219 _resolved_method.is_null() ? "(none)" : _resolved_method->name_and_sig_as_C_string()); 220 } 221 #endif 222 223 //------------------------------------------------------------------------------------------------------------------------ 224 // Implementation of LinkInfo 225 226 LinkInfo::LinkInfo(const constantPoolHandle& pool, int index, methodHandle current_method, TRAPS) { 227 // resolve klass 228 Klass* result = pool->klass_ref_at(index, CHECK); 229 _resolved_klass = KlassHandle(THREAD, result); 230 231 // Get name, signature, and static klass 232 _name = pool->name_ref_at(index); 233 _signature = pool->signature_ref_at(index); 234 _tag = pool->tag_ref_at(index); 235 _current_klass = KlassHandle(THREAD, pool->pool_holder()); 236 _current_method = current_method; 237 238 // Coming from the constant pool always checks access 239 _check_access = true; 240 } 241 242 LinkInfo::LinkInfo(const constantPoolHandle& pool, int index, TRAPS) { 243 // resolve klass 244 Klass* result = pool->klass_ref_at(index, CHECK); 245 _resolved_klass = KlassHandle(THREAD, result); 246 247 // Get name, signature, and static klass 248 _name = pool->name_ref_at(index); 249 _signature = pool->signature_ref_at(index); 250 _tag = pool->tag_ref_at(index); 251 _current_klass = KlassHandle(THREAD, pool->pool_holder()); 252 _current_method = methodHandle(); 253 254 // Coming from the constant pool always checks access 255 _check_access = true; 256 } 257 258 char* LinkInfo::method_string() const { 259 return Method::name_and_sig_as_C_string(_resolved_klass(), _name, _signature); 260 } 261 262 #ifndef PRODUCT 263 void LinkInfo::print() { 264 ResourceMark rm; 265 tty->print_cr("Link resolved_klass=%s name=%s signature=%s current_klass=%s check_access=%s", 266 _resolved_klass->name()->as_C_string(), 267 _name->as_C_string(), 268 _signature->as_C_string(), 269 _current_klass.is_null() ? "(none)" : _current_klass->name()->as_C_string(), 270 _check_access ? "true" : "false"); 271 } 272 #endif // PRODUCT 273 //------------------------------------------------------------------------------------------------------------------------ 274 // Klass resolution 275 276 void LinkResolver::check_klass_accessability(KlassHandle ref_klass, KlassHandle sel_klass, TRAPS) { 277 Reflection::VerifyClassAccessResults vca_result = 278 Reflection::verify_class_access(ref_klass(), InstanceKlass::cast(sel_klass()), true); 279 if (vca_result != Reflection::ACCESS_OK) { 280 ResourceMark rm(THREAD); 281 char* msg = Reflection::verify_class_access_msg(ref_klass(), 282 InstanceKlass::cast(sel_klass()), 283 vca_result); 284 if (msg == NULL) { 285 Exceptions::fthrow( 286 THREAD_AND_LOCATION, 287 vmSymbols::java_lang_IllegalAccessError(), 288 "failed to access class %s from class %s", 289 sel_klass->external_name(), 290 ref_klass->external_name()); 291 } else { 292 // Use module specific message returned by verify_class_access_msg(). 293 Exceptions::fthrow( 294 THREAD_AND_LOCATION, 295 vmSymbols::java_lang_IllegalAccessError(), 296 "%s", msg); 297 } 298 } 299 } 300 301 //------------------------------------------------------------------------------------------------------------------------ 302 // Method resolution 303 // 304 // According to JVM spec. $5.4.3c & $5.4.3d 305 306 // Look up method in klasses, including static methods 307 // Then look up local default methods 308 methodHandle LinkResolver::lookup_method_in_klasses(const LinkInfo& link_info, 309 bool checkpolymorphism, 310 bool in_imethod_resolve, TRAPS) { 311 KlassHandle klass = link_info.resolved_klass(); 312 Symbol* name = link_info.name(); 313 Symbol* signature = link_info.signature(); 314 315 // Ignore overpasses so statics can be found during resolution 316 Method* result = klass->uncached_lookup_method(name, signature, Klass::skip_overpass); 317 318 if (klass->is_array_klass()) { 319 // Only consider klass and super klass for arrays 320 return methodHandle(THREAD, result); 321 } 322 323 InstanceKlass* ik = InstanceKlass::cast(klass()); 324 325 // JDK 8, JVMS 5.4.3.4: Interface method resolution should 326 // ignore static and non-public methods of java.lang.Object, 327 // like clone, finalize, registerNatives. 328 if (in_imethod_resolve && 329 result != NULL && 330 ik->is_interface() && 331 (result->is_static() || !result->is_public()) && 332 result->method_holder() == SystemDictionary::Object_klass()) { 333 result = NULL; 334 } 335 336 // Before considering default methods, check for an overpass in the 337 // current class if a method has not been found. 338 if (result == NULL) { 339 result = ik->find_method(name, signature); 340 } 341 342 if (result == NULL) { 343 Array<Method*>* default_methods = ik->default_methods(); 344 if (default_methods != NULL) { 345 result = InstanceKlass::find_method(default_methods, name, signature); 346 } 347 } 348 349 if (checkpolymorphism && result != NULL) { 350 vmIntrinsics::ID iid = result->intrinsic_id(); 351 if (MethodHandles::is_signature_polymorphic(iid)) { 352 // Do not link directly to these. The VM must produce a synthetic one using lookup_polymorphic_method. 353 return NULL; 354 } 355 } 356 return methodHandle(THREAD, result); 357 } 358 359 // returns first instance method 360 // Looks up method in classes, then looks up local default methods 361 methodHandle LinkResolver::lookup_instance_method_in_klasses(KlassHandle klass, 362 Symbol* name, 363 Symbol* signature, TRAPS) { 364 Method* result = klass->uncached_lookup_method(name, signature, Klass::find_overpass); 365 366 while (result != NULL && result->is_static() && result->method_holder()->super() != NULL) { 367 Klass* super_klass = result->method_holder()->super(); 368 result = super_klass->uncached_lookup_method(name, signature, Klass::find_overpass); 369 } 370 371 if (klass->is_array_klass()) { 372 // Only consider klass and super klass for arrays 373 return methodHandle(THREAD, result); 374 } 375 376 if (result == NULL) { 377 Array<Method*>* default_methods = InstanceKlass::cast(klass())->default_methods(); 378 if (default_methods != NULL) { 379 result = InstanceKlass::find_method(default_methods, name, signature); 380 assert(result == NULL || !result->is_static(), "static defaults not allowed"); 381 } 382 } 383 return methodHandle(THREAD, result); 384 } 385 386 int LinkResolver::vtable_index_of_interface_method(KlassHandle klass, 387 const methodHandle& resolved_method) { 388 389 int vtable_index = Method::invalid_vtable_index; 390 Symbol* name = resolved_method->name(); 391 Symbol* signature = resolved_method->signature(); 392 InstanceKlass* ik = InstanceKlass::cast(klass()); 393 394 // First check in default method array 395 if (!resolved_method->is_abstract() && ik->default_methods() != NULL) { 396 int index = InstanceKlass::find_method_index(ik->default_methods(), 397 name, signature, Klass::find_overpass, 398 Klass::find_static, Klass::find_private); 399 if (index >= 0 ) { 400 vtable_index = ik->default_vtable_indices()->at(index); 401 } 402 } 403 if (vtable_index == Method::invalid_vtable_index) { 404 // get vtable_index for miranda methods 405 ResourceMark rm; 406 klassVtable *vt = ik->vtable(); 407 vtable_index = vt->index_of_miranda(name, signature); 408 } 409 return vtable_index; 410 } 411 412 methodHandle LinkResolver::lookup_method_in_interfaces(const LinkInfo& cp_info, TRAPS) { 413 InstanceKlass *ik = InstanceKlass::cast(cp_info.resolved_klass()()); 414 415 // Specify 'true' in order to skip default methods when searching the 416 // interfaces. Function lookup_method_in_klasses() already looked for 417 // the method in the default methods table. 418 return methodHandle(THREAD, 419 ik->lookup_method_in_all_interfaces(cp_info.name(), cp_info.signature(), 420 Klass::skip_defaults)); 421 } 422 423 methodHandle LinkResolver::lookup_polymorphic_method( 424 const LinkInfo& link_info, 425 Handle *appendix_result_or_null, 426 Handle *method_type_result, 427 TRAPS) { 428 KlassHandle klass = link_info.resolved_klass(); 429 Symbol* name = link_info.name(); 430 Symbol* full_signature = link_info.signature(); 431 432 vmIntrinsics::ID iid = MethodHandles::signature_polymorphic_name_id(name); 433 if (TraceMethodHandles) { 434 ResourceMark rm(THREAD); 435 tty->print_cr("lookup_polymorphic_method iid=%s %s.%s%s", 436 vmIntrinsics::name_at(iid), klass->external_name(), 437 name->as_C_string(), full_signature->as_C_string()); 438 } 439 if ((klass() == SystemDictionary::MethodHandle_klass() || 440 klass() == SystemDictionary::VarHandle_klass()) && 441 iid != vmIntrinsics::_none) { 442 if (MethodHandles::is_signature_polymorphic_intrinsic(iid)) { 443 // Most of these do not need an up-call to Java to resolve, so can be done anywhere. 444 // Do not erase last argument type (MemberName) if it is a static linkTo method. 445 bool keep_last_arg = MethodHandles::is_signature_polymorphic_static(iid); 446 TempNewSymbol basic_signature = 447 MethodHandles::lookup_basic_type_signature(full_signature, keep_last_arg, CHECK_NULL); 448 if (TraceMethodHandles) { 449 ResourceMark rm(THREAD); 450 tty->print_cr("lookup_polymorphic_method %s %s => basic %s", 451 name->as_C_string(), 452 full_signature->as_C_string(), 453 basic_signature->as_C_string()); 454 } 455 methodHandle result = SystemDictionary::find_method_handle_intrinsic(iid, 456 basic_signature, 457 CHECK_NULL); 458 if (result.not_null()) { 459 assert(result->is_method_handle_intrinsic(), "MH.invokeBasic or MH.linkTo* intrinsic"); 460 assert(result->intrinsic_id() != vmIntrinsics::_invokeGeneric, "wrong place to find this"); 461 assert(basic_signature == result->signature(), "predict the result signature"); 462 if (TraceMethodHandles) { 463 ttyLocker ttyl; 464 tty->print("lookup_polymorphic_method => intrinsic "); 465 result->print_on(tty); 466 } 467 } 468 return result; 469 } else if (iid == vmIntrinsics::_invokeGeneric 470 && THREAD->can_call_java() 471 && appendix_result_or_null != NULL) { 472 // This is a method with type-checking semantics. 473 // We will ask Java code to spin an adapter method for it. 474 if (!MethodHandles::enabled()) { 475 // Make sure the Java part of the runtime has been booted up. 476 Klass* natives = SystemDictionary::MethodHandleNatives_klass(); 477 if (natives == NULL || InstanceKlass::cast(natives)->is_not_initialized()) { 478 SystemDictionary::resolve_or_fail(vmSymbols::java_lang_invoke_MethodHandleNatives(), 479 Handle(), 480 Handle(), 481 true, 482 CHECK_NULL); 483 } 484 } 485 486 Handle appendix; 487 Handle method_type; 488 methodHandle result = SystemDictionary::find_method_handle_invoker( 489 klass, 490 name, 491 full_signature, 492 link_info.current_klass(), 493 &appendix, 494 &method_type, 495 CHECK_NULL); 496 if (TraceMethodHandles) { 497 ttyLocker ttyl; 498 tty->print("lookup_polymorphic_method => (via Java) "); 499 result->print_on(tty); 500 tty->print(" lookup_polymorphic_method => appendix = "); 501 if (appendix.is_null()) tty->print_cr("(none)"); 502 else appendix->print_on(tty); 503 } 504 if (result.not_null()) { 505 #ifdef ASSERT 506 ResourceMark rm(THREAD); 507 508 TempNewSymbol basic_signature = 509 MethodHandles::lookup_basic_type_signature(full_signature, CHECK_NULL); 510 int actual_size_of_params = result->size_of_parameters(); 511 int expected_size_of_params = ArgumentSizeComputer(basic_signature).size(); 512 // +1 for MethodHandle.this, +1 for trailing MethodType 513 if (!MethodHandles::is_signature_polymorphic_static(iid)) expected_size_of_params += 1; 514 if (appendix.not_null()) expected_size_of_params += 1; 515 if (actual_size_of_params != expected_size_of_params) { 516 tty->print_cr("*** basic_signature=%s", basic_signature->as_C_string()); 517 tty->print_cr("*** result for %s: ", vmIntrinsics::name_at(iid)); 518 result->print(); 519 } 520 assert(actual_size_of_params == expected_size_of_params, 521 "%d != %d", actual_size_of_params, expected_size_of_params); 522 #endif //ASSERT 523 524 assert(appendix_result_or_null != NULL, ""); 525 (*appendix_result_or_null) = appendix; 526 (*method_type_result) = method_type; 527 } 528 return result; 529 } 530 } 531 return NULL; 532 } 533 534 void LinkResolver::check_method_accessability(KlassHandle ref_klass, 535 KlassHandle resolved_klass, 536 KlassHandle sel_klass, 537 const methodHandle& sel_method, 538 TRAPS) { 539 540 AccessFlags flags = sel_method->access_flags(); 541 542 // Special case: arrays always override "clone". JVMS 2.15. 543 // If the resolved klass is an array class, and the declaring class 544 // is java.lang.Object and the method is "clone", set the flags 545 // to public. 546 // 547 // We'll check for the method name first, as that's most likely 548 // to be false (so we'll short-circuit out of these tests). 549 if (sel_method->name() == vmSymbols::clone_name() && 550 sel_klass() == SystemDictionary::Object_klass() && 551 resolved_klass->is_array_klass()) { 552 // We need to change "protected" to "public". 553 assert(flags.is_protected(), "clone not protected?"); 554 jint new_flags = flags.as_int(); 555 new_flags = new_flags & (~JVM_ACC_PROTECTED); 556 new_flags = new_flags | JVM_ACC_PUBLIC; 557 flags.set_flags(new_flags); 558 } 559 // assert(extra_arg_result_or_null != NULL, "must be able to return extra argument"); 560 561 if (!Reflection::verify_field_access(ref_klass(), 562 resolved_klass(), 563 sel_klass(), 564 flags, 565 true)) { 566 ResourceMark rm(THREAD); 567 Exceptions::fthrow( 568 THREAD_AND_LOCATION, 569 vmSymbols::java_lang_IllegalAccessError(), 570 "tried to access method %s.%s%s from class %s", 571 sel_klass->external_name(), 572 sel_method->name()->as_C_string(), 573 sel_method->signature()->as_C_string(), 574 ref_klass->external_name() 575 ); 576 return; 577 } 578 } 579 580 methodHandle LinkResolver::resolve_method_statically(Bytecodes::Code code, 581 const constantPoolHandle& pool, int index, TRAPS) { 582 // This method is used only 583 // (1) in C2 from InlineTree::ok_to_inline (via ciMethod::check_call), 584 // and 585 // (2) in Bytecode_invoke::static_target 586 // It appears to fail when applied to an invokeinterface call site. 587 // FIXME: Remove this method and ciMethod::check_call; refactor to use the other LinkResolver entry points. 588 // resolve klass 589 KlassHandle resolved_klass; 590 if (code == Bytecodes::_invokedynamic) { 591 resolved_klass = SystemDictionary::MethodHandle_klass(); 592 Symbol* method_name = vmSymbols::invoke_name(); 593 Symbol* method_signature = pool->signature_ref_at(index); 594 KlassHandle current_klass(THREAD, pool->pool_holder()); 595 LinkInfo link_info(resolved_klass, method_name, method_signature, current_klass); 596 return resolve_method(link_info, code, THREAD); 597 } 598 599 LinkInfo link_info(pool, index, methodHandle(), CHECK_NULL); 600 resolved_klass = link_info.resolved_klass(); 601 602 if (pool->has_preresolution() 603 || (resolved_klass() == SystemDictionary::MethodHandle_klass() && 604 MethodHandles::is_signature_polymorphic_name(resolved_klass(), link_info.name()))) { 605 Method* result = ConstantPool::method_at_if_loaded(pool, index); 606 if (result != NULL) { 607 return methodHandle(THREAD, result); 608 } 609 } 610 611 if (code == Bytecodes::_invokeinterface) { 612 return resolve_interface_method(link_info, code, THREAD); 613 } else if (code == Bytecodes::_invokevirtual) { 614 return resolve_method(link_info, code, THREAD); 615 } else if (!resolved_klass->is_interface()) { 616 return resolve_method(link_info, code, THREAD); 617 } else { 618 return resolve_interface_method(link_info, code, THREAD); 619 } 620 } 621 622 // Check and print a loader constraint violation message for method or interface method 623 void LinkResolver::check_method_loader_constraints(const LinkInfo& link_info, 624 const methodHandle& resolved_method, 625 const char* method_type, TRAPS) { 626 Handle current_loader(THREAD, link_info.current_klass()->class_loader()); 627 Handle resolved_loader(THREAD, resolved_method->method_holder()->class_loader()); 628 629 ResourceMark rm(THREAD); 630 Symbol* failed_type_symbol = 631 SystemDictionary::check_signature_loaders(link_info.signature(), current_loader, 632 resolved_loader, true, CHECK); 633 if (failed_type_symbol != NULL) { 634 const char* msg = "loader constraint violation: when resolving %s" 635 " \"%s\" the class loader (instance of %s) of the current class, %s," 636 " and the class loader (instance of %s) for the method's defining class, %s, have" 637 " different Class objects for the type %s used in the signature"; 638 char* sig = link_info.method_string(); 639 const char* loader1_name = SystemDictionary::loader_name(current_loader()); 640 char* current = link_info.current_klass()->name()->as_C_string(); 641 const char* loader2_name = SystemDictionary::loader_name(resolved_loader()); 642 char* target = resolved_method->method_holder()->name()->as_C_string(); 643 char* failed_type_name = failed_type_symbol->as_C_string(); 644 size_t buflen = strlen(msg) + strlen(sig) + strlen(loader1_name) + 645 strlen(current) + strlen(loader2_name) + strlen(target) + 646 strlen(failed_type_name) + strlen(method_type) + 1; 647 char* buf = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, buflen); 648 jio_snprintf(buf, buflen, msg, method_type, sig, loader1_name, current, loader2_name, 649 target, failed_type_name); 650 THROW_MSG(vmSymbols::java_lang_LinkageError(), buf); 651 } 652 } 653 654 void LinkResolver::check_field_loader_constraints(Symbol* field, Symbol* sig, 655 KlassHandle current_klass, 656 KlassHandle sel_klass, TRAPS) { 657 Handle ref_loader(THREAD, current_klass->class_loader()); 658 Handle sel_loader(THREAD, sel_klass->class_loader()); 659 660 ResourceMark rm(THREAD); // needed for check_signature_loaders 661 Symbol* failed_type_symbol = 662 SystemDictionary::check_signature_loaders(sig, 663 ref_loader, sel_loader, 664 false, 665 CHECK); 666 if (failed_type_symbol != NULL) { 667 const char* msg = "loader constraint violation: when resolving field" 668 " \"%s\" the class loader (instance of %s) of the referring class, " 669 "%s, and the class loader (instance of %s) for the field's resolved " 670 "type, %s, have different Class objects for that type"; 671 char* field_name = field->as_C_string(); 672 const char* loader1_name = SystemDictionary::loader_name(ref_loader()); 673 char* sel = sel_klass->name()->as_C_string(); 674 const char* loader2_name = SystemDictionary::loader_name(sel_loader()); 675 char* failed_type_name = failed_type_symbol->as_C_string(); 676 size_t buflen = strlen(msg) + strlen(field_name) + strlen(loader1_name) + 677 strlen(sel) + strlen(loader2_name) + strlen(failed_type_name) + 1; 678 char* buf = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, buflen); 679 jio_snprintf(buf, buflen, msg, field_name, loader1_name, sel, loader2_name, 680 failed_type_name); 681 THROW_MSG(vmSymbols::java_lang_LinkageError(), buf); 682 } 683 } 684 685 methodHandle LinkResolver::resolve_method(const LinkInfo& link_info, 686 Bytecodes::Code code, TRAPS) { 687 688 Handle nested_exception; 689 KlassHandle resolved_klass = link_info.resolved_klass(); 690 691 // 1. For invokevirtual, cannot call an interface method 692 if (code == Bytecodes::_invokevirtual && resolved_klass->is_interface()) { 693 ResourceMark rm(THREAD); 694 char buf[200]; 695 jio_snprintf(buf, sizeof(buf), "Found interface %s, but class was expected", 696 resolved_klass()->external_name()); 697 THROW_MSG_NULL(vmSymbols::java_lang_IncompatibleClassChangeError(), buf); 698 } 699 700 // 2. check constant pool tag for called method - must be JVM_CONSTANT_Methodref 701 if (!link_info.tag().is_invalid() && !link_info.tag().is_method()) { 702 ResourceMark rm(THREAD); 703 char buf[200]; 704 jio_snprintf(buf, sizeof(buf), "Method %s must be Methodref constant", link_info.method_string()); 705 THROW_MSG_NULL(vmSymbols::java_lang_IncompatibleClassChangeError(), buf); 706 } 707 708 709 // 3. lookup method in resolved klass and its super klasses 710 methodHandle resolved_method = lookup_method_in_klasses(link_info, true, false, CHECK_NULL); 711 712 // 4. lookup method in all the interfaces implemented by the resolved klass 713 if (resolved_method.is_null() && !resolved_klass->is_array_klass()) { // not found in the class hierarchy 714 resolved_method = lookup_method_in_interfaces(link_info, CHECK_NULL); 715 716 if (resolved_method.is_null()) { 717 // JSR 292: see if this is an implicitly generated method MethodHandle.linkToVirtual(*...), etc 718 resolved_method = lookup_polymorphic_method(link_info, (Handle*)NULL, (Handle*)NULL, THREAD); 719 if (HAS_PENDING_EXCEPTION) { 720 nested_exception = Handle(THREAD, PENDING_EXCEPTION); 721 CLEAR_PENDING_EXCEPTION; 722 } 723 } 724 } 725 726 // 5. method lookup failed 727 if (resolved_method.is_null()) { 728 ResourceMark rm(THREAD); 729 THROW_MSG_CAUSE_(vmSymbols::java_lang_NoSuchMethodError(), 730 Method::name_and_sig_as_C_string(resolved_klass(), 731 link_info.name(), 732 link_info.signature()), 733 nested_exception, NULL); 734 } 735 736 // 6. access checks, access checking may be turned off when calling from within the VM. 737 KlassHandle current_klass = link_info.current_klass(); 738 if (link_info.check_access()) { 739 assert(current_klass.not_null() , "current_klass should not be null"); 740 741 // check if method can be accessed by the referring class 742 check_method_accessability(current_klass, 743 resolved_klass, 744 KlassHandle(THREAD, resolved_method->method_holder()), 745 resolved_method, 746 CHECK_NULL); 747 748 // check loader constraints 749 check_method_loader_constraints(link_info, resolved_method, "method", CHECK_NULL); 750 } 751 752 return resolved_method; 753 } 754 755 static void trace_method_resolution(const char* prefix, 756 KlassHandle klass, 757 KlassHandle resolved_klass, 758 const methodHandle& method, 759 bool logitables, 760 int index = -1) { 761 #ifndef PRODUCT 762 ResourceMark rm; 763 outputStream* st; 764 if (logitables) { 765 st = Log(itables)::trace_stream(); 766 } else { 767 st = Log(vtables)::trace_stream(); 768 } 769 st->print("%s%s, compile-time-class:%s, method:%s, method_holder:%s, access_flags: ", 770 prefix, 771 (klass.is_null() ? "<NULL>" : klass->internal_name()), 772 (resolved_klass.is_null() ? "<NULL>" : resolved_klass->internal_name()), 773 Method::name_and_sig_as_C_string(resolved_klass(), 774 method->name(), 775 method->signature()), 776 method->method_holder()->internal_name()); 777 method->print_linkage_flags(st); 778 if (index != -1) { 779 st->print("vtable_index:%d", index); 780 } 781 st->cr(); 782 #endif // PRODUCT 783 } 784 785 // Do linktime resolution of a method in the interface within the context of the specied bytecode. 786 methodHandle LinkResolver::resolve_interface_method(const LinkInfo& link_info, Bytecodes::Code code, TRAPS) { 787 788 KlassHandle resolved_klass = link_info.resolved_klass(); 789 790 // check if klass is interface 791 if (!resolved_klass->is_interface()) { 792 ResourceMark rm(THREAD); 793 char buf[200]; 794 jio_snprintf(buf, sizeof(buf), "Found class %s, but interface was expected", resolved_klass()->external_name()); 795 THROW_MSG_NULL(vmSymbols::java_lang_IncompatibleClassChangeError(), buf); 796 } 797 798 // check constant pool tag for called method - must be JVM_CONSTANT_InterfaceMethodref 799 if (!link_info.tag().is_invalid() && !link_info.tag().is_interface_method()) { 800 ResourceMark rm(THREAD); 801 char buf[200]; 802 jio_snprintf(buf, sizeof(buf), "Method %s must be InterfaceMethodref constant", link_info.method_string()); 803 THROW_MSG_NULL(vmSymbols::java_lang_IncompatibleClassChangeError(), buf); 804 } 805 806 // lookup method in this interface or its super, java.lang.Object 807 // JDK8: also look for static methods 808 methodHandle resolved_method = lookup_method_in_klasses(link_info, false, true, CHECK_NULL); 809 810 if (resolved_method.is_null() && !resolved_klass->is_array_klass()) { 811 // lookup method in all the super-interfaces 812 resolved_method = lookup_method_in_interfaces(link_info, CHECK_NULL); 813 } 814 815 if (resolved_method.is_null()) { 816 // no method found 817 ResourceMark rm(THREAD); 818 THROW_MSG_NULL(vmSymbols::java_lang_NoSuchMethodError(), 819 Method::name_and_sig_as_C_string(resolved_klass(), 820 link_info.name(), 821 link_info.signature())); 822 } 823 824 if (link_info.check_access()) { 825 // JDK8 adds non-public interface methods, and accessability check requirement 826 KlassHandle current_klass = link_info.current_klass(); 827 828 assert(current_klass.not_null() , "current_klass should not be null"); 829 830 // check if method can be accessed by the referring class 831 check_method_accessability(current_klass, 832 resolved_klass, 833 KlassHandle(THREAD, resolved_method->method_holder()), 834 resolved_method, 835 CHECK_NULL); 836 837 check_method_loader_constraints(link_info, resolved_method, "interface method", CHECK_NULL); 838 } 839 840 if (code != Bytecodes::_invokestatic && resolved_method->is_static()) { 841 ResourceMark rm(THREAD); 842 char buf[200]; 843 jio_snprintf(buf, sizeof(buf), "Expected instance not static method %s", 844 Method::name_and_sig_as_C_string(resolved_klass(), 845 resolved_method->name(), resolved_method->signature())); 846 THROW_MSG_NULL(vmSymbols::java_lang_IncompatibleClassChangeError(), buf); 847 } 848 849 if (code == Bytecodes::_invokeinterface && resolved_method->is_private()) { 850 ResourceMark rm(THREAD); 851 char buf[200]; 852 853 KlassHandle current_klass = link_info.current_klass(); 854 jio_snprintf(buf, sizeof(buf), "private interface method requires invokespecial, not invokeinterface: method %s, caller-class:%s", 855 Method::name_and_sig_as_C_string(resolved_klass(), 856 resolved_method->name(), 857 resolved_method->signature()), 858 (current_klass.is_null() ? "<NULL>" : current_klass->internal_name())); 859 THROW_MSG_NULL(vmSymbols::java_lang_IncompatibleClassChangeError(), buf); 860 } 861 862 if (log_develop_is_enabled(Trace, itables)) { 863 char buf[200]; 864 jio_snprintf(buf, sizeof(buf), "%s resolved interface method: caller-class:", 865 Bytecodes::name(code)); 866 trace_method_resolution(buf, link_info.current_klass(), resolved_klass, 867 resolved_method, true); 868 } 869 870 return resolved_method; 871 } 872 873 //------------------------------------------------------------------------------------------------------------------------ 874 // Field resolution 875 876 void LinkResolver::check_field_accessability(KlassHandle ref_klass, 877 KlassHandle resolved_klass, 878 KlassHandle sel_klass, 879 const fieldDescriptor& fd, 880 TRAPS) { 881 if (!Reflection::verify_field_access(ref_klass(), 882 resolved_klass(), 883 sel_klass(), 884 fd.access_flags(), 885 true)) { 886 ResourceMark rm(THREAD); 887 Exceptions::fthrow( 888 THREAD_AND_LOCATION, 889 vmSymbols::java_lang_IllegalAccessError(), 890 "tried to access field %s.%s from class %s", 891 sel_klass->external_name(), 892 fd.name()->as_C_string(), 893 ref_klass->external_name() 894 ); 895 return; 896 } 897 } 898 899 void LinkResolver::resolve_field_access(fieldDescriptor& fd, const constantPoolHandle& pool, int index, const methodHandle& method, Bytecodes::Code byte, TRAPS) { 900 LinkInfo link_info(pool, index, method, CHECK); 901 resolve_field(fd, link_info, byte, true, CHECK); 902 } 903 904 void LinkResolver::resolve_field(fieldDescriptor& fd, 905 const LinkInfo& link_info, 906 Bytecodes::Code byte, bool initialize_class, 907 TRAPS) { 908 assert(byte == Bytecodes::_getstatic || byte == Bytecodes::_putstatic || 909 byte == Bytecodes::_getfield || byte == Bytecodes::_putfield || 910 byte == Bytecodes::_nofast_getfield || byte == Bytecodes::_nofast_putfield || 911 (byte == Bytecodes::_nop && !link_info.check_access()), "bad field access bytecode"); 912 913 bool is_static = (byte == Bytecodes::_getstatic || byte == Bytecodes::_putstatic); 914 bool is_put = (byte == Bytecodes::_putfield || byte == Bytecodes::_putstatic || byte == Bytecodes::_nofast_putfield); 915 // Check if there's a resolved klass containing the field 916 KlassHandle resolved_klass = link_info.resolved_klass(); 917 Symbol* field = link_info.name(); 918 Symbol* sig = link_info.signature(); 919 920 if (resolved_klass.is_null()) { 921 ResourceMark rm(THREAD); 922 THROW_MSG(vmSymbols::java_lang_NoSuchFieldError(), field->as_C_string()); 923 } 924 925 // Resolve instance field 926 KlassHandle sel_klass(THREAD, resolved_klass->find_field(field, sig, &fd)); 927 // check if field exists; i.e., if a klass containing the field def has been selected 928 if (sel_klass.is_null()) { 929 ResourceMark rm(THREAD); 930 THROW_MSG(vmSymbols::java_lang_NoSuchFieldError(), field->as_C_string()); 931 } 932 933 if (!link_info.check_access()) 934 // Access checking may be turned off when calling from within the VM. 935 return; 936 937 // check access 938 KlassHandle current_klass = link_info.current_klass(); 939 check_field_accessability(current_klass, resolved_klass, sel_klass, fd, CHECK); 940 941 // check for errors 942 if (is_static != fd.is_static()) { 943 ResourceMark rm(THREAD); 944 char msg[200]; 945 jio_snprintf(msg, sizeof(msg), "Expected %s field %s.%s", is_static ? "static" : "non-static", resolved_klass()->external_name(), fd.name()->as_C_string()); 946 THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), msg); 947 } 948 949 // A final field can be modified only 950 // (1) by methods declared in the class declaring the field and 951 // (2) by the <clinit> method (in case of a static field) 952 // or by the <init> method (in case of an instance field). 953 if (is_put && fd.access_flags().is_final()) { 954 ResourceMark rm(THREAD); 955 stringStream ss; 956 957 if (sel_klass() != current_klass()) { 958 ss.print("Update to %s final field %s.%s attempted from a different class (%s) than the field's declaring class", 959 is_static ? "static" : "non-static", resolved_klass()->external_name(), fd.name()->as_C_string(), 960 current_klass()->external_name()); 961 THROW_MSG(vmSymbols::java_lang_IllegalAccessError(), ss.as_string()); 962 } 963 964 if (fd.constants()->pool_holder()->major_version() >= 53) { 965 methodHandle m = link_info.current_method(); 966 assert(!m.is_null(), "information about the current method must be available for 'put' bytecodes"); 967 bool is_initialized_static_final_update = (byte == Bytecodes::_putstatic && 968 fd.is_static() && 969 !m()->is_static_initializer()); 970 bool is_initialized_instance_final_update = ((byte == Bytecodes::_putfield || byte == Bytecodes::_nofast_putfield) && 971 !fd.is_static() && 972 !m->is_object_initializer()); 973 974 if (is_initialized_static_final_update || is_initialized_instance_final_update) { 975 ss.print("Update to %s final field %s.%s attempted from a different method (%s) than the initializer method %s ", 976 is_static ? "static" : "non-static", resolved_klass()->external_name(), fd.name()->as_C_string(), 977 m()->name()->as_C_string(), 978 is_static ? "<clinit>" : "<init>"); 979 THROW_MSG(vmSymbols::java_lang_IllegalAccessError(), ss.as_string()); 980 } 981 } 982 } 983 984 // initialize resolved_klass if necessary 985 // note 1: the klass which declared the field must be initialized (i.e, sel_klass) 986 // according to the newest JVM spec (5.5, p.170) - was bug (gri 7/28/99) 987 // 988 // note 2: we don't want to force initialization if we are just checking 989 // if the field access is legal; e.g., during compilation 990 if (is_static && initialize_class) { 991 sel_klass->initialize(CHECK); 992 } 993 994 if (sel_klass() != current_klass()) { 995 check_field_loader_constraints(field, sig, current_klass, sel_klass, CHECK); 996 } 997 998 // return information. note that the klass is set to the actual klass containing the 999 // field, otherwise access of static fields in superclasses will not work. 1000 } 1001 1002 1003 //------------------------------------------------------------------------------------------------------------------------ 1004 // Invoke resolution 1005 // 1006 // Naming conventions: 1007 // 1008 // resolved_method the specified method (i.e., static receiver specified via constant pool index) 1009 // sel_method the selected method (selected via run-time lookup; e.g., based on dynamic receiver class) 1010 // resolved_klass the specified klass (i.e., specified via constant pool index) 1011 // recv_klass the receiver klass 1012 1013 1014 void LinkResolver::resolve_static_call(CallInfo& result, 1015 const LinkInfo& link_info, 1016 bool initialize_class, TRAPS) { 1017 methodHandle resolved_method = linktime_resolve_static_method(link_info, CHECK); 1018 1019 // The resolved class can change as a result of this resolution. 1020 KlassHandle resolved_klass(THREAD, resolved_method->method_holder()); 1021 1022 // Initialize klass (this should only happen if everything is ok) 1023 if (initialize_class && resolved_klass->should_be_initialized()) { 1024 resolved_klass->initialize(CHECK); 1025 // Use updated LinkInfo to reresolve with resolved method holder 1026 LinkInfo new_info(resolved_klass, link_info.name(), link_info.signature(), 1027 link_info.current_klass(), 1028 link_info.check_access() ? LinkInfo::needs_access_check : LinkInfo::skip_access_check); 1029 resolved_method = linktime_resolve_static_method(new_info, CHECK); 1030 } 1031 1032 // setup result 1033 result.set_static(resolved_klass, resolved_method, CHECK); 1034 } 1035 1036 // throws linktime exceptions 1037 methodHandle LinkResolver::linktime_resolve_static_method(const LinkInfo& link_info, TRAPS) { 1038 1039 KlassHandle resolved_klass = link_info.resolved_klass(); 1040 methodHandle resolved_method; 1041 if (!resolved_klass->is_interface()) { 1042 resolved_method = resolve_method(link_info, Bytecodes::_invokestatic, CHECK_NULL); 1043 } else { 1044 resolved_method = resolve_interface_method(link_info, Bytecodes::_invokestatic, CHECK_NULL); 1045 } 1046 assert(resolved_method->name() != vmSymbols::class_initializer_name(), "should have been checked in verifier"); 1047 1048 // check if static 1049 if (!resolved_method->is_static()) { 1050 ResourceMark rm(THREAD); 1051 char buf[200]; 1052 jio_snprintf(buf, sizeof(buf), "Expected static method %s", Method::name_and_sig_as_C_string(resolved_klass(), 1053 resolved_method->name(), 1054 resolved_method->signature())); 1055 THROW_MSG_NULL(vmSymbols::java_lang_IncompatibleClassChangeError(), buf); 1056 } 1057 return resolved_method; 1058 } 1059 1060 1061 void LinkResolver::resolve_special_call(CallInfo& result, 1062 const LinkInfo& link_info, 1063 TRAPS) { 1064 methodHandle resolved_method = linktime_resolve_special_method(link_info, CHECK); 1065 runtime_resolve_special_method(result, resolved_method, 1066 link_info.resolved_klass(), 1067 link_info.current_klass(), 1068 link_info.check_access(), CHECK); 1069 } 1070 1071 // throws linktime exceptions 1072 methodHandle LinkResolver::linktime_resolve_special_method(const LinkInfo& link_info, 1073 TRAPS) { 1074 1075 // Invokespecial is called for multiple special reasons: 1076 // <init> 1077 // local private method invocation, for classes and interfaces 1078 // superclass.method, which can also resolve to a default method 1079 // and the selected method is recalculated relative to the direct superclass 1080 // superinterface.method, which explicitly does not check shadowing 1081 KlassHandle resolved_klass = link_info.resolved_klass(); 1082 methodHandle resolved_method; 1083 1084 if (!resolved_klass->is_interface()) { 1085 resolved_method = resolve_method(link_info, Bytecodes::_invokespecial, CHECK_NULL); 1086 } else { 1087 resolved_method = resolve_interface_method(link_info, Bytecodes::_invokespecial, CHECK_NULL); 1088 } 1089 1090 // check if method name is <init>, that it is found in same klass as static type 1091 if (resolved_method->name() == vmSymbols::object_initializer_name() && 1092 resolved_method->method_holder() != resolved_klass()) { 1093 ResourceMark rm(THREAD); 1094 Exceptions::fthrow( 1095 THREAD_AND_LOCATION, 1096 vmSymbols::java_lang_NoSuchMethodError(), 1097 "%s: method %s%s not found", 1098 resolved_klass->external_name(), 1099 resolved_method->name()->as_C_string(), 1100 resolved_method->signature()->as_C_string() 1101 ); 1102 return NULL; 1103 } 1104 1105 // check if invokespecial's interface method reference is in an indirect superinterface 1106 KlassHandle current_klass = link_info.current_klass(); 1107 if (!current_klass.is_null() && resolved_klass->is_interface()) { 1108 Klass *klass_to_check = !InstanceKlass::cast(current_klass())->is_anonymous() ? 1109 current_klass() : 1110 InstanceKlass::cast(current_klass())->host_klass(); 1111 // Disable verification for the dynamically-generated reflection bytecodes. 1112 bool is_reflect = klass_to_check->is_subclass_of( 1113 SystemDictionary::reflect_MagicAccessorImpl_klass()); 1114 1115 if (!is_reflect && 1116 !InstanceKlass::cast(klass_to_check)->is_same_or_direct_interface(resolved_klass())) { 1117 ResourceMark rm(THREAD); 1118 char buf[200]; 1119 jio_snprintf(buf, sizeof(buf), 1120 "Interface method reference: %s, is in an indirect superinterface of %s", 1121 Method::name_and_sig_as_C_string(resolved_klass(), 1122 resolved_method->name(), 1123 resolved_method->signature()), 1124 current_klass->external_name()); 1125 THROW_MSG_NULL(vmSymbols::java_lang_IncompatibleClassChangeError(), buf); 1126 } 1127 } 1128 1129 // check if not static 1130 if (resolved_method->is_static()) { 1131 ResourceMark rm(THREAD); 1132 char buf[200]; 1133 jio_snprintf(buf, sizeof(buf), 1134 "Expecting non-static method %s", 1135 Method::name_and_sig_as_C_string(resolved_klass(), 1136 resolved_method->name(), 1137 resolved_method->signature())); 1138 THROW_MSG_NULL(vmSymbols::java_lang_IncompatibleClassChangeError(), buf); 1139 } 1140 1141 if (log_develop_is_enabled(Trace, itables)) { 1142 trace_method_resolution("invokespecial resolved method: caller-class:", 1143 current_klass, resolved_klass, resolved_method, true); 1144 } 1145 1146 return resolved_method; 1147 } 1148 1149 // throws runtime exceptions 1150 void LinkResolver::runtime_resolve_special_method(CallInfo& result, 1151 const methodHandle& resolved_method, 1152 KlassHandle resolved_klass, 1153 KlassHandle current_klass, 1154 bool check_access, TRAPS) { 1155 1156 // resolved method is selected method unless we have an old-style lookup 1157 // for a superclass method 1158 // Invokespecial for a superinterface, resolved method is selected method, 1159 // no checks for shadowing 1160 methodHandle sel_method(THREAD, resolved_method()); 1161 1162 // check if this is an old-style super call and do a new lookup if so 1163 { KlassHandle method_klass = KlassHandle(THREAD, 1164 resolved_method->method_holder()); 1165 1166 if (check_access && 1167 // a) check if ACC_SUPER flag is set for the current class 1168 (current_klass->is_super() || !AllowNonVirtualCalls) && 1169 // b) check if the class of the resolved_klass is a superclass 1170 // (not supertype in order to exclude interface classes) of the current class. 1171 // This check is not performed for super.invoke for interface methods 1172 // in super interfaces. 1173 current_klass->is_subclass_of(resolved_klass()) && 1174 current_klass() != resolved_klass() && 1175 // c) check if the method is not <init> 1176 resolved_method->name() != vmSymbols::object_initializer_name()) { 1177 // Lookup super method 1178 KlassHandle super_klass(THREAD, current_klass->super()); 1179 sel_method = lookup_instance_method_in_klasses(super_klass, 1180 resolved_method->name(), 1181 resolved_method->signature(), CHECK); 1182 // check if found 1183 if (sel_method.is_null()) { 1184 ResourceMark rm(THREAD); 1185 THROW_MSG(vmSymbols::java_lang_AbstractMethodError(), 1186 Method::name_and_sig_as_C_string(resolved_klass(), 1187 resolved_method->name(), 1188 resolved_method->signature())); 1189 } 1190 } 1191 } 1192 1193 // check if not static 1194 if (sel_method->is_static()) { 1195 ResourceMark rm(THREAD); 1196 char buf[200]; 1197 jio_snprintf(buf, sizeof(buf), "Expecting non-static method %s", Method::name_and_sig_as_C_string(resolved_klass(), 1198 resolved_method->name(), 1199 resolved_method->signature())); 1200 THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf); 1201 } 1202 1203 // check if abstract 1204 if (sel_method->is_abstract()) { 1205 ResourceMark rm(THREAD); 1206 THROW_MSG(vmSymbols::java_lang_AbstractMethodError(), 1207 Method::name_and_sig_as_C_string(resolved_klass(), 1208 sel_method->name(), 1209 sel_method->signature())); 1210 } 1211 1212 if (log_develop_is_enabled(Trace, itables)) { 1213 trace_method_resolution("invokespecial selected method: resolved-class:", 1214 resolved_klass, resolved_klass, sel_method, true); 1215 } 1216 1217 // setup result 1218 result.set_static(resolved_klass, sel_method, CHECK); 1219 } 1220 1221 void LinkResolver::resolve_virtual_call(CallInfo& result, Handle recv, KlassHandle receiver_klass, 1222 const LinkInfo& link_info, 1223 bool check_null_and_abstract, TRAPS) { 1224 methodHandle resolved_method = linktime_resolve_virtual_method(link_info, CHECK); 1225 runtime_resolve_virtual_method(result, resolved_method, 1226 link_info.resolved_klass(), 1227 recv, receiver_klass, 1228 check_null_and_abstract, CHECK); 1229 } 1230 1231 // throws linktime exceptions 1232 methodHandle LinkResolver::linktime_resolve_virtual_method(const LinkInfo& link_info, 1233 TRAPS) { 1234 // normal method resolution 1235 methodHandle resolved_method = resolve_method(link_info, Bytecodes::_invokevirtual, CHECK_NULL); 1236 1237 assert(resolved_method->name() != vmSymbols::object_initializer_name(), "should have been checked in verifier"); 1238 assert(resolved_method->name() != vmSymbols::class_initializer_name (), "should have been checked in verifier"); 1239 1240 // check if private interface method 1241 KlassHandle resolved_klass = link_info.resolved_klass(); 1242 KlassHandle current_klass = link_info.current_klass(); 1243 1244 // This is impossible, if resolve_klass is an interface, we've thrown icce in resolve_method 1245 if (resolved_klass->is_interface() && resolved_method->is_private()) { 1246 ResourceMark rm(THREAD); 1247 char buf[200]; 1248 jio_snprintf(buf, sizeof(buf), "private interface method requires invokespecial, not invokevirtual: method %s, caller-class:%s", 1249 Method::name_and_sig_as_C_string(resolved_klass(), 1250 resolved_method->name(), 1251 resolved_method->signature()), 1252 (current_klass.is_null() ? "<NULL>" : current_klass->internal_name())); 1253 THROW_MSG_NULL(vmSymbols::java_lang_IncompatibleClassChangeError(), buf); 1254 } 1255 1256 // check if not static 1257 if (resolved_method->is_static()) { 1258 ResourceMark rm(THREAD); 1259 char buf[200]; 1260 jio_snprintf(buf, sizeof(buf), "Expecting non-static method %s", Method::name_and_sig_as_C_string(resolved_klass(), 1261 resolved_method->name(), 1262 resolved_method->signature())); 1263 THROW_MSG_NULL(vmSymbols::java_lang_IncompatibleClassChangeError(), buf); 1264 } 1265 1266 if (log_develop_is_enabled(Trace, vtables)) { 1267 trace_method_resolution("invokevirtual resolved method: caller-class:", 1268 current_klass, resolved_klass, resolved_method, false); 1269 } 1270 1271 return resolved_method; 1272 } 1273 1274 // throws runtime exceptions 1275 void LinkResolver::runtime_resolve_virtual_method(CallInfo& result, 1276 const methodHandle& resolved_method, 1277 KlassHandle resolved_klass, 1278 Handle recv, 1279 KlassHandle recv_klass, 1280 bool check_null_and_abstract, 1281 TRAPS) { 1282 1283 // setup default return values 1284 int vtable_index = Method::invalid_vtable_index; 1285 methodHandle selected_method; 1286 1287 assert(recv.is_null() || recv->is_oop(), "receiver is not an oop"); 1288 1289 // runtime method resolution 1290 if (check_null_and_abstract && recv.is_null()) { // check if receiver exists 1291 THROW(vmSymbols::java_lang_NullPointerException()); 1292 } 1293 1294 // Virtual methods cannot be resolved before its klass has been linked, for otherwise the Method*'s 1295 // has not been rewritten, and the vtable initialized. Make sure to do this after the nullcheck, since 1296 // a missing receiver might result in a bogus lookup. 1297 assert(resolved_method->method_holder()->is_linked(), "must be linked"); 1298 1299 // do lookup based on receiver klass using the vtable index 1300 if (resolved_method->method_holder()->is_interface()) { // default or miranda method 1301 vtable_index = vtable_index_of_interface_method(resolved_klass, 1302 resolved_method); 1303 assert(vtable_index >= 0 , "we should have valid vtable index at this point"); 1304 1305 selected_method = methodHandle(THREAD, recv_klass->method_at_vtable(vtable_index)); 1306 } else { 1307 // at this point we are sure that resolved_method is virtual and not 1308 // a default or miranda method; therefore, it must have a valid vtable index. 1309 assert(!resolved_method->has_itable_index(), ""); 1310 vtable_index = resolved_method->vtable_index(); 1311 // We could get a negative vtable_index for final methods, 1312 // because as an optimization they are they are never put in the vtable, 1313 // unless they override an existing method. 1314 // If we do get a negative, it means the resolved method is the the selected 1315 // method, and it can never be changed by an override. 1316 if (vtable_index == Method::nonvirtual_vtable_index) { 1317 assert(resolved_method->can_be_statically_bound(), "cannot override this method"); 1318 selected_method = resolved_method; 1319 } else { 1320 selected_method = methodHandle(THREAD, recv_klass->method_at_vtable(vtable_index)); 1321 } 1322 } 1323 1324 // check if method exists 1325 if (selected_method.is_null()) { 1326 ResourceMark rm(THREAD); 1327 THROW_MSG(vmSymbols::java_lang_AbstractMethodError(), 1328 Method::name_and_sig_as_C_string(resolved_klass(), 1329 resolved_method->name(), 1330 resolved_method->signature())); 1331 } 1332 1333 // check if abstract 1334 if (check_null_and_abstract && selected_method->is_abstract()) { 1335 ResourceMark rm(THREAD); 1336 THROW_MSG(vmSymbols::java_lang_AbstractMethodError(), 1337 Method::name_and_sig_as_C_string(resolved_klass(), 1338 selected_method->name(), 1339 selected_method->signature())); 1340 } 1341 1342 if (log_develop_is_enabled(Trace, vtables)) { 1343 trace_method_resolution("invokevirtual selected method: receiver-class:", 1344 recv_klass, resolved_klass, selected_method, 1345 false, vtable_index); 1346 } 1347 // setup result 1348 result.set_virtual(resolved_klass, recv_klass, resolved_method, selected_method, vtable_index, CHECK); 1349 } 1350 1351 void LinkResolver::resolve_interface_call(CallInfo& result, Handle recv, KlassHandle recv_klass, 1352 const LinkInfo& link_info, 1353 bool check_null_and_abstract, TRAPS) { 1354 // throws linktime exceptions 1355 methodHandle resolved_method = linktime_resolve_interface_method(link_info, CHECK); 1356 runtime_resolve_interface_method(result, resolved_method,link_info.resolved_klass(), 1357 recv, recv_klass, check_null_and_abstract, CHECK); 1358 } 1359 1360 methodHandle LinkResolver::linktime_resolve_interface_method(const LinkInfo& link_info, 1361 TRAPS) { 1362 // normal interface method resolution 1363 methodHandle resolved_method = resolve_interface_method(link_info, Bytecodes::_invokeinterface, CHECK_NULL); 1364 assert(resolved_method->name() != vmSymbols::object_initializer_name(), "should have been checked in verifier"); 1365 assert(resolved_method->name() != vmSymbols::class_initializer_name (), "should have been checked in verifier"); 1366 1367 return resolved_method; 1368 } 1369 1370 // throws runtime exceptions 1371 void LinkResolver::runtime_resolve_interface_method(CallInfo& result, 1372 const methodHandle& resolved_method, 1373 KlassHandle resolved_klass, 1374 Handle recv, 1375 KlassHandle recv_klass, 1376 bool check_null_and_abstract, TRAPS) { 1377 // check if receiver exists 1378 if (check_null_and_abstract && recv.is_null()) { 1379 THROW(vmSymbols::java_lang_NullPointerException()); 1380 } 1381 1382 // check if receiver klass implements the resolved interface 1383 if (!recv_klass->is_subtype_of(resolved_klass())) { 1384 ResourceMark rm(THREAD); 1385 char buf[200]; 1386 jio_snprintf(buf, sizeof(buf), "Class %s does not implement the requested interface %s", 1387 recv_klass()->external_name(), 1388 resolved_klass()->external_name()); 1389 THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf); 1390 } 1391 1392 // do lookup based on receiver klass 1393 // This search must match the linktime preparation search for itable initialization 1394 // to correctly enforce loader constraints for interface method inheritance 1395 methodHandle sel_method = lookup_instance_method_in_klasses(recv_klass, 1396 resolved_method->name(), 1397 resolved_method->signature(), CHECK); 1398 if (sel_method.is_null() && !check_null_and_abstract) { 1399 // In theory this is a harmless placeholder value, but 1400 // in practice leaving in null affects the nsk default method tests. 1401 // This needs further study. 1402 sel_method = resolved_method; 1403 } 1404 // check if method exists 1405 if (sel_method.is_null()) { 1406 ResourceMark rm(THREAD); 1407 THROW_MSG(vmSymbols::java_lang_AbstractMethodError(), 1408 Method::name_and_sig_as_C_string(recv_klass(), 1409 resolved_method->name(), 1410 resolved_method->signature())); 1411 } 1412 // check access 1413 // Throw Illegal Access Error if sel_method is not public. 1414 if (!sel_method->is_public()) { 1415 ResourceMark rm(THREAD); 1416 THROW_MSG(vmSymbols::java_lang_IllegalAccessError(), 1417 Method::name_and_sig_as_C_string(recv_klass(), 1418 sel_method->name(), 1419 sel_method->signature())); 1420 } 1421 // check if abstract 1422 if (check_null_and_abstract && sel_method->is_abstract()) { 1423 ResourceMark rm(THREAD); 1424 THROW_MSG(vmSymbols::java_lang_AbstractMethodError(), 1425 Method::name_and_sig_as_C_string(recv_klass(), 1426 sel_method->name(), 1427 sel_method->signature())); 1428 } 1429 1430 if (log_develop_is_enabled(Trace, itables)) { 1431 trace_method_resolution("invokeinterface selected method: receiver-class:", 1432 recv_klass, resolved_klass, sel_method, true); 1433 } 1434 // setup result 1435 if (!resolved_method->has_itable_index()) { 1436 int vtable_index = resolved_method->vtable_index(); 1437 assert(vtable_index == sel_method->vtable_index(), "sanity check"); 1438 result.set_virtual(resolved_klass, recv_klass, resolved_method, sel_method, vtable_index, CHECK); 1439 } else { 1440 int itable_index = resolved_method()->itable_index(); 1441 result.set_interface(resolved_klass, recv_klass, resolved_method, sel_method, itable_index, CHECK); 1442 } 1443 } 1444 1445 1446 methodHandle LinkResolver::linktime_resolve_interface_method_or_null( 1447 const LinkInfo& link_info) { 1448 EXCEPTION_MARK; 1449 methodHandle method_result = linktime_resolve_interface_method(link_info, THREAD); 1450 if (HAS_PENDING_EXCEPTION) { 1451 CLEAR_PENDING_EXCEPTION; 1452 return methodHandle(); 1453 } else { 1454 return method_result; 1455 } 1456 } 1457 1458 methodHandle LinkResolver::linktime_resolve_virtual_method_or_null( 1459 const LinkInfo& link_info) { 1460 EXCEPTION_MARK; 1461 methodHandle method_result = linktime_resolve_virtual_method(link_info, THREAD); 1462 if (HAS_PENDING_EXCEPTION) { 1463 CLEAR_PENDING_EXCEPTION; 1464 return methodHandle(); 1465 } else { 1466 return method_result; 1467 } 1468 } 1469 1470 methodHandle LinkResolver::resolve_virtual_call_or_null( 1471 KlassHandle receiver_klass, 1472 const LinkInfo& link_info) { 1473 EXCEPTION_MARK; 1474 CallInfo info; 1475 resolve_virtual_call(info, Handle(), receiver_klass, link_info, false, THREAD); 1476 if (HAS_PENDING_EXCEPTION) { 1477 CLEAR_PENDING_EXCEPTION; 1478 return methodHandle(); 1479 } 1480 return info.selected_method(); 1481 } 1482 1483 methodHandle LinkResolver::resolve_interface_call_or_null( 1484 KlassHandle receiver_klass, 1485 const LinkInfo& link_info) { 1486 EXCEPTION_MARK; 1487 CallInfo info; 1488 resolve_interface_call(info, Handle(), receiver_klass, link_info, false, THREAD); 1489 if (HAS_PENDING_EXCEPTION) { 1490 CLEAR_PENDING_EXCEPTION; 1491 return methodHandle(); 1492 } 1493 return info.selected_method(); 1494 } 1495 1496 int LinkResolver::resolve_virtual_vtable_index(KlassHandle receiver_klass, 1497 const LinkInfo& link_info) { 1498 EXCEPTION_MARK; 1499 CallInfo info; 1500 resolve_virtual_call(info, Handle(), receiver_klass, link_info, 1501 /*check_null_or_abstract*/false, THREAD); 1502 if (HAS_PENDING_EXCEPTION) { 1503 CLEAR_PENDING_EXCEPTION; 1504 return Method::invalid_vtable_index; 1505 } 1506 return info.vtable_index(); 1507 } 1508 1509 methodHandle LinkResolver::resolve_static_call_or_null(const LinkInfo& link_info) { 1510 EXCEPTION_MARK; 1511 CallInfo info; 1512 resolve_static_call(info, link_info, /*initialize_class*/false, THREAD); 1513 if (HAS_PENDING_EXCEPTION) { 1514 CLEAR_PENDING_EXCEPTION; 1515 return methodHandle(); 1516 } 1517 return info.selected_method(); 1518 } 1519 1520 methodHandle LinkResolver::resolve_special_call_or_null(const LinkInfo& link_info) { 1521 EXCEPTION_MARK; 1522 CallInfo info; 1523 resolve_special_call(info, link_info, THREAD); 1524 if (HAS_PENDING_EXCEPTION) { 1525 CLEAR_PENDING_EXCEPTION; 1526 return methodHandle(); 1527 } 1528 return info.selected_method(); 1529 } 1530 1531 1532 1533 //------------------------------------------------------------------------------------------------------------------------ 1534 // ConstantPool entries 1535 1536 void LinkResolver::resolve_invoke(CallInfo& result, Handle recv, const constantPoolHandle& pool, int index, Bytecodes::Code byte, TRAPS) { 1537 switch (byte) { 1538 case Bytecodes::_invokestatic : resolve_invokestatic (result, pool, index, CHECK); break; 1539 case Bytecodes::_invokespecial : resolve_invokespecial (result, pool, index, CHECK); break; 1540 case Bytecodes::_invokevirtual : resolve_invokevirtual (result, recv, pool, index, CHECK); break; 1541 case Bytecodes::_invokehandle : resolve_invokehandle (result, pool, index, CHECK); break; 1542 case Bytecodes::_invokedynamic : resolve_invokedynamic (result, pool, index, CHECK); break; 1543 case Bytecodes::_invokeinterface: resolve_invokeinterface(result, recv, pool, index, CHECK); break; 1544 } 1545 return; 1546 } 1547 1548 void LinkResolver::resolve_invoke(CallInfo& result, Handle& recv, 1549 const methodHandle& attached_method, 1550 Bytecodes::Code byte, TRAPS) { 1551 KlassHandle defc = attached_method->method_holder(); 1552 Symbol* name = attached_method->name(); 1553 Symbol* type = attached_method->signature(); 1554 LinkInfo link_info(defc, name, type); 1555 switch(byte) { 1556 case Bytecodes::_invokevirtual: 1557 resolve_virtual_call(result, recv, recv->klass(), link_info, 1558 /*check_null_and_abstract=*/true, CHECK); 1559 break; 1560 case Bytecodes::_invokeinterface: 1561 resolve_interface_call(result, recv, recv->klass(), link_info, 1562 /*check_null_and_abstract=*/true, CHECK); 1563 break; 1564 case Bytecodes::_invokestatic: 1565 resolve_static_call(result, link_info, /*initialize_class=*/false, CHECK); 1566 break; 1567 case Bytecodes::_invokespecial: 1568 resolve_special_call(result, link_info, CHECK); 1569 break; 1570 default: 1571 fatal("bad call: %s", Bytecodes::name(byte)); 1572 } 1573 } 1574 1575 void LinkResolver::resolve_invokestatic(CallInfo& result, const constantPoolHandle& pool, int index, TRAPS) { 1576 LinkInfo link_info(pool, index, CHECK); 1577 resolve_static_call(result, link_info, /*initialize_class*/true, CHECK); 1578 } 1579 1580 1581 void LinkResolver::resolve_invokespecial(CallInfo& result, const constantPoolHandle& pool, int index, TRAPS) { 1582 LinkInfo link_info(pool, index, CHECK); 1583 resolve_special_call(result, link_info, CHECK); 1584 } 1585 1586 1587 void LinkResolver::resolve_invokevirtual(CallInfo& result, Handle recv, 1588 const constantPoolHandle& pool, int index, 1589 TRAPS) { 1590 1591 LinkInfo link_info(pool, index, CHECK); 1592 KlassHandle recvrKlass (THREAD, recv.is_null() ? (Klass*)NULL : recv->klass()); 1593 resolve_virtual_call(result, recv, recvrKlass, link_info, /*check_null_or_abstract*/true, CHECK); 1594 } 1595 1596 1597 void LinkResolver::resolve_invokeinterface(CallInfo& result, Handle recv, const constantPoolHandle& pool, int index, TRAPS) { 1598 LinkInfo link_info(pool, index, CHECK); 1599 KlassHandle recvrKlass (THREAD, recv.is_null() ? (Klass*)NULL : recv->klass()); 1600 resolve_interface_call(result, recv, recvrKlass, link_info, true, CHECK); 1601 } 1602 1603 1604 void LinkResolver::resolve_invokehandle(CallInfo& result, const constantPoolHandle& pool, int index, TRAPS) { 1605 // This guy is reached from InterpreterRuntime::resolve_invokehandle. 1606 LinkInfo link_info(pool, index, CHECK); 1607 if (TraceMethodHandles) { 1608 ResourceMark rm(THREAD); 1609 tty->print_cr("resolve_invokehandle %s %s", link_info.name()->as_C_string(), 1610 link_info.signature()->as_C_string()); 1611 } 1612 resolve_handle_call(result, link_info, CHECK); 1613 } 1614 1615 void LinkResolver::resolve_handle_call(CallInfo& result, 1616 const LinkInfo& link_info, 1617 TRAPS) { 1618 // JSR 292: this must be an implicitly generated method MethodHandle.invokeExact(*...) or similar 1619 KlassHandle resolved_klass = link_info.resolved_klass(); 1620 assert(resolved_klass() == SystemDictionary::MethodHandle_klass() || 1621 resolved_klass() == SystemDictionary::VarHandle_klass(), ""); 1622 assert(MethodHandles::is_signature_polymorphic_name(link_info.name()), ""); 1623 Handle resolved_appendix; 1624 Handle resolved_method_type; 1625 methodHandle resolved_method = lookup_polymorphic_method(link_info, 1626 &resolved_appendix, &resolved_method_type, CHECK); 1627 result.set_handle(resolved_klass, resolved_method, resolved_appendix, resolved_method_type, CHECK); 1628 } 1629 1630 static void wrap_invokedynamic_exception(TRAPS) { 1631 if (HAS_PENDING_EXCEPTION) { 1632 // See the "Linking Exceptions" section for the invokedynamic instruction 1633 // in JVMS 6.5. 1634 if (PENDING_EXCEPTION->is_a(SystemDictionary::Error_klass())) { 1635 // Pass through an Error, including BootstrapMethodError, any other form 1636 // of linkage error, or say ThreadDeath/OutOfMemoryError 1637 if (TraceMethodHandles) { 1638 tty->print_cr("invokedynamic passes through an Error for " INTPTR_FORMAT, p2i((void *)PENDING_EXCEPTION)); 1639 PENDING_EXCEPTION->print(); 1640 } 1641 return; 1642 } 1643 1644 // Otherwise wrap the exception in a BootstrapMethodError 1645 if (TraceMethodHandles) { 1646 tty->print_cr("invokedynamic throws BSME for " INTPTR_FORMAT, p2i((void *)PENDING_EXCEPTION)); 1647 PENDING_EXCEPTION->print(); 1648 } 1649 Handle nested_exception(THREAD, PENDING_EXCEPTION); 1650 CLEAR_PENDING_EXCEPTION; 1651 THROW_CAUSE(vmSymbols::java_lang_BootstrapMethodError(), nested_exception) 1652 } 1653 } 1654 1655 void LinkResolver::resolve_invokedynamic(CallInfo& result, const constantPoolHandle& pool, int index, TRAPS) { 1656 Symbol* method_name = pool->name_ref_at(index); 1657 Symbol* method_signature = pool->signature_ref_at(index); 1658 KlassHandle current_klass = KlassHandle(THREAD, pool->pool_holder()); 1659 1660 // Resolve the bootstrap specifier (BSM + optional arguments). 1661 Handle bootstrap_specifier; 1662 // Check if CallSite has been bound already: 1663 ConstantPoolCacheEntry* cpce = pool->invokedynamic_cp_cache_entry_at(index); 1664 if (cpce->is_f1_null()) { 1665 int pool_index = cpce->constant_pool_index(); 1666 oop bsm_info = pool->resolve_bootstrap_specifier_at(pool_index, THREAD); 1667 wrap_invokedynamic_exception(CHECK); 1668 assert(bsm_info != NULL, ""); 1669 // FIXME: Cache this once per BootstrapMethods entry, not once per CONSTANT_InvokeDynamic. 1670 bootstrap_specifier = Handle(THREAD, bsm_info); 1671 } 1672 if (!cpce->is_f1_null()) { 1673 methodHandle method( THREAD, cpce->f1_as_method()); 1674 Handle appendix( THREAD, cpce->appendix_if_resolved(pool)); 1675 Handle method_type(THREAD, cpce->method_type_if_resolved(pool)); 1676 result.set_handle(method, appendix, method_type, THREAD); 1677 wrap_invokedynamic_exception(CHECK); 1678 return; 1679 } 1680 1681 if (TraceMethodHandles) { 1682 ResourceMark rm(THREAD); 1683 tty->print_cr("resolve_invokedynamic #%d %s %s in %s", 1684 ConstantPool::decode_invokedynamic_index(index), 1685 method_name->as_C_string(), method_signature->as_C_string(), 1686 current_klass->name()->as_C_string()); 1687 tty->print(" BSM info: "); bootstrap_specifier->print(); 1688 } 1689 1690 resolve_dynamic_call(result, bootstrap_specifier, method_name, method_signature, current_klass, CHECK); 1691 } 1692 1693 void LinkResolver::resolve_dynamic_call(CallInfo& result, 1694 Handle bootstrap_specifier, 1695 Symbol* method_name, Symbol* method_signature, 1696 KlassHandle current_klass, 1697 TRAPS) { 1698 // JSR 292: this must resolve to an implicitly generated method MH.linkToCallSite(*...) 1699 // The appendix argument is likely to be a freshly-created CallSite. 1700 Handle resolved_appendix; 1701 Handle resolved_method_type; 1702 methodHandle resolved_method = 1703 SystemDictionary::find_dynamic_call_site_invoker(current_klass, 1704 bootstrap_specifier, 1705 method_name, method_signature, 1706 &resolved_appendix, 1707 &resolved_method_type, 1708 THREAD); 1709 wrap_invokedynamic_exception(CHECK); 1710 result.set_handle(resolved_method, resolved_appendix, resolved_method_type, THREAD); 1711 wrap_invokedynamic_exception(CHECK); 1712 } --- EOF ---