1 /* 2 * Copyright (c) 1997, 2010, 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/systemDictionary.hpp" 27 #include "classfile/vmSymbols.hpp" 28 #include "compiler/compileBroker.hpp" 29 #include "gc_interface/collectedHeap.inline.hpp" 30 #include "interpreter/bytecode.hpp" 31 #include "interpreter/interpreterRuntime.hpp" 32 #include "interpreter/linkResolver.hpp" 33 #include "memory/resourceArea.hpp" 34 #include "memory/universe.inline.hpp" 35 #include "oops/instanceKlass.hpp" 36 #include "oops/objArrayOop.hpp" 37 #include "prims/methodHandles.hpp" 38 #include "prims/nativeLookup.hpp" 39 #include "runtime/compilationPolicy.hpp" 40 #include "runtime/fieldDescriptor.hpp" 41 #include "runtime/frame.inline.hpp" 42 #include "runtime/handles.inline.hpp" 43 #include "runtime/reflection.hpp" 44 #include "runtime/signature.hpp" 45 #include "runtime/vmThread.hpp" 46 #ifdef TARGET_OS_FAMILY_linux 47 # include "thread_linux.inline.hpp" 48 #endif 49 #ifdef TARGET_OS_FAMILY_solaris 50 # include "thread_solaris.inline.hpp" 51 #endif 52 #ifdef TARGET_OS_FAMILY_windows 53 # include "thread_windows.inline.hpp" 54 #endif 55 56 //------------------------------------------------------------------------------------------------------------------------ 57 // Implementation of FieldAccessInfo 58 59 void FieldAccessInfo::set(KlassHandle klass, symbolHandle name, int field_index, int field_offset, 60 BasicType field_type, AccessFlags access_flags) { 61 _klass = klass; 62 _name = name; 63 _field_index = field_index; 64 _field_offset = field_offset; 65 _field_type = field_type; 66 _access_flags = access_flags; 67 } 68 69 70 //------------------------------------------------------------------------------------------------------------------------ 71 // Implementation of CallInfo 72 73 74 void CallInfo::set_static(KlassHandle resolved_klass, methodHandle resolved_method, TRAPS) { 75 int vtable_index = methodOopDesc::nonvirtual_vtable_index; 76 set_common(resolved_klass, resolved_klass, resolved_method, resolved_method, vtable_index, CHECK); 77 } 78 79 80 void CallInfo::set_interface(KlassHandle resolved_klass, KlassHandle selected_klass, methodHandle resolved_method, methodHandle selected_method, TRAPS) { 81 // This is only called for interface methods. If the resolved_method 82 // comes from java/lang/Object, it can be the subject of a virtual call, so 83 // we should pick the vtable index from the resolved method. 84 // Other than that case, there is no valid vtable index to specify. 85 int vtable_index = methodOopDesc::invalid_vtable_index; 86 if (resolved_method->method_holder() == SystemDictionary::Object_klass()) { 87 assert(resolved_method->vtable_index() == selected_method->vtable_index(), "sanity check"); 88 vtable_index = resolved_method->vtable_index(); 89 } 90 set_common(resolved_klass, selected_klass, resolved_method, selected_method, vtable_index, CHECK); 91 } 92 93 void CallInfo::set_virtual(KlassHandle resolved_klass, KlassHandle selected_klass, methodHandle resolved_method, methodHandle selected_method, int vtable_index, TRAPS) { 94 assert(vtable_index >= 0 || vtable_index == methodOopDesc::nonvirtual_vtable_index, "valid index"); 95 set_common(resolved_klass, selected_klass, resolved_method, selected_method, vtable_index, CHECK); 96 } 97 98 void CallInfo::set_dynamic(methodHandle resolved_method, TRAPS) { 99 assert(resolved_method->is_method_handle_invoke(), ""); 100 KlassHandle resolved_klass = SystemDictionaryHandles::MethodHandle_klass(); 101 assert(resolved_klass == resolved_method->method_holder(), ""); 102 int vtable_index = methodOopDesc::nonvirtual_vtable_index; 103 assert(resolved_method->vtable_index() == vtable_index, ""); 104 set_common(resolved_klass, KlassHandle(), resolved_method, resolved_method, vtable_index, CHECK); 105 } 106 107 void CallInfo::set_common(KlassHandle resolved_klass, KlassHandle selected_klass, methodHandle resolved_method, methodHandle selected_method, int vtable_index, TRAPS) { 108 assert(resolved_method->signature() == selected_method->signature(), "signatures must correspond"); 109 _resolved_klass = resolved_klass; 110 _selected_klass = selected_klass; 111 _resolved_method = resolved_method; 112 _selected_method = selected_method; 113 _vtable_index = vtable_index; 114 if (CompilationPolicy::must_be_compiled(selected_method)) { 115 // This path is unusual, mostly used by the '-Xcomp' stress test mode. 116 117 // Note: with several active threads, the must_be_compiled may be true 118 // while can_be_compiled is false; remove assert 119 // assert(CompilationPolicy::can_be_compiled(selected_method), "cannot compile"); 120 if (THREAD->is_Compiler_thread()) { 121 // don't force compilation, resolve was on behalf of compiler 122 return; 123 } 124 if (instanceKlass::cast(selected_method->method_holder())->is_not_initialized()) { 125 // 'is_not_initialized' means not only '!is_initialized', but also that 126 // initialization has not been started yet ('!being_initialized') 127 // Do not force compilation of methods in uninitialized classes. 128 // Note that doing this would throw an assert later, 129 // in CompileBroker::compile_method. 130 // We sometimes use the link resolver to do reflective lookups 131 // even before classes are initialized. 132 return; 133 } 134 CompileBroker::compile_method(selected_method, InvocationEntryBci, 135 CompLevel_initial_compile, 136 methodHandle(), 0, "must_be_compiled", CHECK); 137 } 138 } 139 140 141 //------------------------------------------------------------------------------------------------------------------------ 142 // Klass resolution 143 144 void LinkResolver::check_klass_accessability(KlassHandle ref_klass, KlassHandle sel_klass, TRAPS) { 145 if (!Reflection::verify_class_access(ref_klass->as_klassOop(), 146 sel_klass->as_klassOop(), 147 true)) { 148 ResourceMark rm(THREAD); 149 Exceptions::fthrow( 150 THREAD_AND_LOCATION, 151 vmSymbolHandles::java_lang_IllegalAccessError(), 152 "tried to access class %s from class %s", 153 sel_klass->external_name(), 154 ref_klass->external_name() 155 ); 156 return; 157 } 158 } 159 160 void LinkResolver::resolve_klass(KlassHandle& result, constantPoolHandle pool, int index, TRAPS) { 161 klassOop result_oop = pool->klass_ref_at(index, CHECK); 162 result = KlassHandle(THREAD, result_oop); 163 } 164 165 void LinkResolver::resolve_klass_no_update(KlassHandle& result, constantPoolHandle pool, int index, TRAPS) { 166 klassOop result_oop = 167 constantPoolOopDesc::klass_ref_at_if_loaded_check(pool, index, CHECK); 168 result = KlassHandle(THREAD, result_oop); 169 } 170 171 172 //------------------------------------------------------------------------------------------------------------------------ 173 // Method resolution 174 // 175 // According to JVM spec. $5.4.3c & $5.4.3d 176 177 void LinkResolver::lookup_method_in_klasses(methodHandle& result, KlassHandle klass, symbolHandle name, symbolHandle signature, TRAPS) { 178 methodOop result_oop = klass->uncached_lookup_method(name(), signature()); 179 if (EnableMethodHandles && result_oop != NULL) { 180 switch (result_oop->intrinsic_id()) { 181 case vmIntrinsics::_invokeExact: 182 case vmIntrinsics::_invokeGeneric: 183 case vmIntrinsics::_invokeDynamic: 184 // Do not link directly to these. The VM must produce a synthetic one using lookup_implicit_method. 185 return; 186 } 187 } 188 result = methodHandle(THREAD, result_oop); 189 } 190 191 // returns first instance method 192 void LinkResolver::lookup_instance_method_in_klasses(methodHandle& result, KlassHandle klass, symbolHandle name, symbolHandle signature, TRAPS) { 193 methodOop result_oop = klass->uncached_lookup_method(name(), signature()); 194 result = methodHandle(THREAD, result_oop); 195 while (!result.is_null() && result->is_static()) { 196 klass = KlassHandle(THREAD, Klass::cast(result->method_holder())->super()); 197 result = methodHandle(THREAD, klass->uncached_lookup_method(name(), signature())); 198 } 199 } 200 201 202 int LinkResolver::vtable_index_of_miranda_method(KlassHandle klass, symbolHandle name, symbolHandle signature, TRAPS) { 203 ResourceMark rm(THREAD); 204 klassVtable *vt = instanceKlass::cast(klass())->vtable(); 205 return vt->index_of_miranda(name(), signature()); 206 } 207 208 void LinkResolver::lookup_method_in_interfaces(methodHandle& result, KlassHandle klass, symbolHandle name, symbolHandle signature, TRAPS) { 209 instanceKlass *ik = instanceKlass::cast(klass()); 210 result = methodHandle(THREAD, ik->lookup_method_in_all_interfaces(name(), signature())); 211 } 212 213 void LinkResolver::lookup_implicit_method(methodHandle& result, 214 KlassHandle klass, symbolHandle name, symbolHandle signature, 215 KlassHandle current_klass, 216 TRAPS) { 217 if (EnableMethodHandles && 218 klass() == SystemDictionary::MethodHandle_klass() && 219 methodOopDesc::is_method_handle_invoke_name(name())) { 220 if (!MethodHandles::enabled()) { 221 // Make sure the Java part of the runtime has been booted up. 222 klassOop natives = SystemDictionary::MethodHandleNatives_klass(); 223 if (natives == NULL || instanceKlass::cast(natives)->is_not_initialized()) { 224 SystemDictionary::resolve_or_fail(vmSymbolHandles::sun_dyn_MethodHandleNatives(), 225 Handle(), 226 Handle(), 227 true, 228 CHECK); 229 } 230 } 231 methodOop result_oop = SystemDictionary::find_method_handle_invoke(name, 232 signature, 233 current_klass, 234 CHECK); 235 if (result_oop != NULL) { 236 assert(result_oop->is_method_handle_invoke() && result_oop->signature() == signature(), "consistent"); 237 result = methodHandle(THREAD, result_oop); 238 } 239 } 240 } 241 242 void LinkResolver::check_method_accessability(KlassHandle ref_klass, 243 KlassHandle resolved_klass, 244 KlassHandle sel_klass, 245 methodHandle sel_method, 246 TRAPS) { 247 248 AccessFlags flags = sel_method->access_flags(); 249 250 // Special case: arrays always override "clone". JVMS 2.15. 251 // If the resolved klass is an array class, and the declaring class 252 // is java.lang.Object and the method is "clone", set the flags 253 // to public. 254 // 255 // We'll check for the method name first, as that's most likely 256 // to be false (so we'll short-circuit out of these tests). 257 if (sel_method->name() == vmSymbols::clone_name() && 258 sel_klass() == SystemDictionary::Object_klass() && 259 resolved_klass->oop_is_array()) { 260 // We need to change "protected" to "public". 261 assert(flags.is_protected(), "clone not protected?"); 262 jint new_flags = flags.as_int(); 263 new_flags = new_flags & (~JVM_ACC_PROTECTED); 264 new_flags = new_flags | JVM_ACC_PUBLIC; 265 flags.set_flags(new_flags); 266 } 267 268 if (!Reflection::verify_field_access(ref_klass->as_klassOop(), 269 resolved_klass->as_klassOop(), 270 sel_klass->as_klassOop(), 271 flags, 272 true)) { 273 ResourceMark rm(THREAD); 274 Exceptions::fthrow( 275 THREAD_AND_LOCATION, 276 vmSymbolHandles::java_lang_IllegalAccessError(), 277 "tried to access method %s.%s%s from class %s", 278 sel_klass->external_name(), 279 sel_method->name()->as_C_string(), 280 sel_method->signature()->as_C_string(), 281 ref_klass->external_name() 282 ); 283 return; 284 } 285 } 286 287 void LinkResolver::resolve_method(methodHandle& resolved_method, KlassHandle& resolved_klass, 288 constantPoolHandle pool, int index, TRAPS) { 289 290 // resolve klass 291 resolve_klass(resolved_klass, pool, index, CHECK); 292 293 symbolHandle method_name (THREAD, pool->name_ref_at(index)); 294 symbolHandle method_signature (THREAD, pool->signature_ref_at(index)); 295 KlassHandle current_klass(THREAD, pool->pool_holder()); 296 297 resolve_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, true, CHECK); 298 } 299 300 void LinkResolver::resolve_dynamic_method(methodHandle& resolved_method, KlassHandle& resolved_klass, constantPoolHandle pool, int index, TRAPS) { 301 // The class is java.dyn.MethodHandle 302 resolved_klass = SystemDictionaryHandles::MethodHandle_klass(); 303 304 symbolHandle method_name = vmSymbolHandles::invokeExact_name(); 305 306 symbolHandle method_signature(THREAD, pool->signature_ref_at(index)); 307 KlassHandle current_klass (THREAD, pool->pool_holder()); 308 309 resolve_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, true, CHECK); 310 } 311 312 void LinkResolver::resolve_interface_method(methodHandle& resolved_method, KlassHandle& resolved_klass, constantPoolHandle pool, int index, TRAPS) { 313 314 // resolve klass 315 resolve_klass(resolved_klass, pool, index, CHECK); 316 symbolHandle method_name (THREAD, pool->name_ref_at(index)); 317 symbolHandle method_signature (THREAD, pool->signature_ref_at(index)); 318 KlassHandle current_klass(THREAD, pool->pool_holder()); 319 320 resolve_interface_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, true, CHECK); 321 } 322 323 324 void LinkResolver::resolve_method(methodHandle& resolved_method, KlassHandle resolved_klass, 325 symbolHandle method_name, symbolHandle method_signature, 326 KlassHandle current_klass, bool check_access, TRAPS) { 327 328 // 1. check if klass is not interface 329 if (resolved_klass->is_interface()) { 330 char buf[200]; 331 jio_snprintf(buf, sizeof(buf), "Found interface %s, but class was expected", Klass::cast(resolved_klass())->external_name()); 332 THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf); 333 } 334 335 // 2. lookup method in resolved klass and its super klasses 336 lookup_method_in_klasses(resolved_method, resolved_klass, method_name, method_signature, CHECK); 337 338 if (resolved_method.is_null()) { // not found in the class hierarchy 339 // 3. lookup method in all the interfaces implemented by the resolved klass 340 lookup_method_in_interfaces(resolved_method, resolved_klass, method_name, method_signature, CHECK); 341 342 if (resolved_method.is_null()) { 343 // JSR 292: see if this is an implicitly generated method MethodHandle.invoke(*...) 344 lookup_implicit_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, CHECK); 345 } 346 347 if (resolved_method.is_null()) { 348 // 4. method lookup failed 349 ResourceMark rm(THREAD); 350 THROW_MSG(vmSymbols::java_lang_NoSuchMethodError(), 351 methodOopDesc::name_and_sig_as_C_string(Klass::cast(resolved_klass()), 352 method_name(), 353 method_signature())); 354 } 355 } 356 357 // 5. check if method is concrete 358 if (resolved_method->is_abstract() && !resolved_klass->is_abstract()) { 359 ResourceMark rm(THREAD); 360 THROW_MSG(vmSymbols::java_lang_AbstractMethodError(), 361 methodOopDesc::name_and_sig_as_C_string(Klass::cast(resolved_klass()), 362 method_name(), 363 method_signature())); 364 } 365 366 // 6. access checks, access checking may be turned off when calling from within the VM. 367 if (check_access) { 368 assert(current_klass.not_null() , "current_klass should not be null"); 369 370 // check if method can be accessed by the referring class 371 check_method_accessability(current_klass, 372 resolved_klass, 373 KlassHandle(THREAD, resolved_method->method_holder()), 374 resolved_method, 375 CHECK); 376 377 // check loader constraints 378 Handle loader (THREAD, instanceKlass::cast(current_klass())->class_loader()); 379 Handle class_loader (THREAD, instanceKlass::cast(resolved_method->method_holder())->class_loader()); 380 { 381 ResourceMark rm(THREAD); 382 char* failed_type_name = 383 SystemDictionary::check_signature_loaders(method_signature, loader, 384 class_loader, true, CHECK); 385 if (failed_type_name != NULL) { 386 const char* msg = "loader constraint violation: when resolving method" 387 " \"%s\" the class loader (instance of %s) of the current class, %s," 388 " and the class loader (instance of %s) for resolved class, %s, have" 389 " different Class objects for the type %s used in the signature"; 390 char* sig = methodOopDesc::name_and_sig_as_C_string(Klass::cast(resolved_klass()),method_name(),method_signature()); 391 const char* loader1 = SystemDictionary::loader_name(loader()); 392 char* current = instanceKlass::cast(current_klass())->name()->as_C_string(); 393 const char* loader2 = SystemDictionary::loader_name(class_loader()); 394 char* resolved = instanceKlass::cast(resolved_klass())->name()->as_C_string(); 395 size_t buflen = strlen(msg) + strlen(sig) + strlen(loader1) + 396 strlen(current) + strlen(loader2) + strlen(resolved) + 397 strlen(failed_type_name); 398 char* buf = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, buflen); 399 jio_snprintf(buf, buflen, msg, sig, loader1, current, loader2, 400 resolved, failed_type_name); 401 THROW_MSG(vmSymbols::java_lang_LinkageError(), buf); 402 } 403 } 404 } 405 } 406 407 void LinkResolver::resolve_interface_method(methodHandle& resolved_method, 408 KlassHandle resolved_klass, 409 symbolHandle method_name, 410 symbolHandle method_signature, 411 KlassHandle current_klass, 412 bool check_access, TRAPS) { 413 414 // check if klass is interface 415 if (!resolved_klass->is_interface()) { 416 char buf[200]; 417 jio_snprintf(buf, sizeof(buf), "Found class %s, but interface was expected", Klass::cast(resolved_klass())->external_name()); 418 THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf); 419 } 420 421 // lookup method in this interface or its super, java.lang.Object 422 lookup_instance_method_in_klasses(resolved_method, resolved_klass, method_name, method_signature, CHECK); 423 424 if (resolved_method.is_null()) { 425 // lookup method in all the super-interfaces 426 lookup_method_in_interfaces(resolved_method, resolved_klass, method_name, method_signature, CHECK); 427 if (resolved_method.is_null()) { 428 // no method found 429 ResourceMark rm(THREAD); 430 THROW_MSG(vmSymbols::java_lang_NoSuchMethodError(), 431 methodOopDesc::name_and_sig_as_C_string(Klass::cast(resolved_klass()), 432 method_name(), 433 method_signature())); 434 } 435 } 436 437 if (check_access) { 438 HandleMark hm(THREAD); 439 Handle loader (THREAD, instanceKlass::cast(current_klass())->class_loader()); 440 Handle class_loader (THREAD, instanceKlass::cast(resolved_method->method_holder())->class_loader()); 441 { 442 ResourceMark rm(THREAD); 443 char* failed_type_name = 444 SystemDictionary::check_signature_loaders(method_signature, loader, 445 class_loader, true, CHECK); 446 if (failed_type_name != NULL) { 447 const char* msg = "loader constraint violation: when resolving " 448 "interface method \"%s\" the class loader (instance of %s) of the " 449 "current class, %s, and the class loader (instance of %s) for " 450 "resolved class, %s, have different Class objects for the type %s " 451 "used in the signature"; 452 char* sig = methodOopDesc::name_and_sig_as_C_string(Klass::cast(resolved_klass()),method_name(),method_signature()); 453 const char* loader1 = SystemDictionary::loader_name(loader()); 454 char* current = instanceKlass::cast(current_klass())->name()->as_C_string(); 455 const char* loader2 = SystemDictionary::loader_name(class_loader()); 456 char* resolved = instanceKlass::cast(resolved_klass())->name()->as_C_string(); 457 size_t buflen = strlen(msg) + strlen(sig) + strlen(loader1) + 458 strlen(current) + strlen(loader2) + strlen(resolved) + 459 strlen(failed_type_name); 460 char* buf = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, buflen); 461 jio_snprintf(buf, buflen, msg, sig, loader1, current, loader2, 462 resolved, failed_type_name); 463 THROW_MSG(vmSymbols::java_lang_LinkageError(), buf); 464 } 465 } 466 } 467 } 468 469 //------------------------------------------------------------------------------------------------------------------------ 470 // Field resolution 471 472 void LinkResolver::check_field_accessability(KlassHandle ref_klass, 473 KlassHandle resolved_klass, 474 KlassHandle sel_klass, 475 fieldDescriptor& fd, 476 TRAPS) { 477 if (!Reflection::verify_field_access(ref_klass->as_klassOop(), 478 resolved_klass->as_klassOop(), 479 sel_klass->as_klassOop(), 480 fd.access_flags(), 481 true)) { 482 ResourceMark rm(THREAD); 483 Exceptions::fthrow( 484 THREAD_AND_LOCATION, 485 vmSymbolHandles::java_lang_IllegalAccessError(), 486 "tried to access field %s.%s from class %s", 487 sel_klass->external_name(), 488 fd.name()->as_C_string(), 489 ref_klass->external_name() 490 ); 491 return; 492 } 493 } 494 495 void LinkResolver::resolve_field(FieldAccessInfo& result, constantPoolHandle pool, int index, Bytecodes::Code byte, bool check_only, TRAPS) { 496 resolve_field(result, pool, index, byte, check_only, true, CHECK); 497 } 498 499 void LinkResolver::resolve_field(FieldAccessInfo& result, constantPoolHandle pool, int index, Bytecodes::Code byte, bool check_only, bool update_pool, TRAPS) { 500 assert(byte == Bytecodes::_getstatic || byte == Bytecodes::_putstatic || 501 byte == Bytecodes::_getfield || byte == Bytecodes::_putfield, "bad bytecode"); 502 503 bool is_static = (byte == Bytecodes::_getstatic || byte == Bytecodes::_putstatic); 504 bool is_put = (byte == Bytecodes::_putfield || byte == Bytecodes::_putstatic); 505 506 // resolve specified klass 507 KlassHandle resolved_klass; 508 if (update_pool) { 509 resolve_klass(resolved_klass, pool, index, CHECK); 510 } else { 511 resolve_klass_no_update(resolved_klass, pool, index, CHECK); 512 } 513 // Load these early in case the resolve of the containing klass fails 514 symbolOop field = pool->name_ref_at(index); 515 symbolHandle field_h (THREAD, field); // preserve in case we need the name 516 symbolOop sig = pool->signature_ref_at(index); 517 // Check if there's a resolved klass containing the field 518 if( resolved_klass.is_null() ) { 519 ResourceMark rm(THREAD); 520 THROW_MSG(vmSymbols::java_lang_NoSuchFieldError(), field->as_C_string()); 521 } 522 523 // Resolve instance field 524 fieldDescriptor fd; // find_field initializes fd if found 525 KlassHandle sel_klass(THREAD, instanceKlass::cast(resolved_klass())->find_field(field, sig, &fd)); 526 // check if field exists; i.e., if a klass containing the field def has been selected 527 if (sel_klass.is_null()){ 528 ResourceMark rm(THREAD); 529 THROW_MSG(vmSymbols::java_lang_NoSuchFieldError(), field->as_C_string()); 530 } 531 532 // check access 533 KlassHandle ref_klass(THREAD, pool->pool_holder()); 534 check_field_accessability(ref_klass, resolved_klass, sel_klass, fd, CHECK); 535 536 // check for errors 537 if (is_static != fd.is_static()) { 538 char msg[200]; 539 jio_snprintf(msg, sizeof(msg), "Expected %s field %s.%s", is_static ? "static" : "non-static", Klass::cast(resolved_klass())->external_name(), fd.name()->as_C_string()); 540 THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), msg); 541 } 542 543 // Final fields can only be accessed from its own class. 544 if (is_put && fd.access_flags().is_final() && sel_klass() != pool->pool_holder()) { 545 THROW(vmSymbols::java_lang_IllegalAccessError()); 546 } 547 548 // initialize resolved_klass if necessary 549 // note 1: the klass which declared the field must be initialized (i.e, sel_klass) 550 // according to the newest JVM spec (5.5, p.170) - was bug (gri 7/28/99) 551 // 552 // note 2: we don't want to force initialization if we are just checking 553 // if the field access is legal; e.g., during compilation 554 if (is_static && !check_only) { 555 sel_klass->initialize(CHECK); 556 } 557 558 { 559 HandleMark hm(THREAD); 560 Handle ref_loader (THREAD, instanceKlass::cast(ref_klass())->class_loader()); 561 Handle sel_loader (THREAD, instanceKlass::cast(sel_klass())->class_loader()); 562 symbolHandle signature_ref (THREAD, pool->signature_ref_at(index)); 563 { 564 ResourceMark rm(THREAD); 565 char* failed_type_name = 566 SystemDictionary::check_signature_loaders(signature_ref, 567 ref_loader, sel_loader, 568 false, 569 CHECK); 570 if (failed_type_name != NULL) { 571 const char* msg = "loader constraint violation: when resolving field" 572 " \"%s\" the class loader (instance of %s) of the referring class, " 573 "%s, and the class loader (instance of %s) for the field's resolved " 574 "type, %s, have different Class objects for that type"; 575 char* field_name = field_h()->as_C_string(); 576 const char* loader1 = SystemDictionary::loader_name(ref_loader()); 577 char* sel = instanceKlass::cast(sel_klass())->name()->as_C_string(); 578 const char* loader2 = SystemDictionary::loader_name(sel_loader()); 579 size_t buflen = strlen(msg) + strlen(field_name) + strlen(loader1) + 580 strlen(sel) + strlen(loader2) + strlen(failed_type_name); 581 char* buf = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, buflen); 582 jio_snprintf(buf, buflen, msg, field_name, loader1, sel, loader2, 583 failed_type_name); 584 THROW_MSG(vmSymbols::java_lang_LinkageError(), buf); 585 } 586 } 587 } 588 589 // return information. note that the klass is set to the actual klass containing the 590 // field, otherwise access of static fields in superclasses will not work. 591 KlassHandle holder (THREAD, fd.field_holder()); 592 symbolHandle name (THREAD, fd.name()); 593 result.set(holder, name, fd.index(), fd.offset(), fd.field_type(), fd.access_flags()); 594 } 595 596 597 //------------------------------------------------------------------------------------------------------------------------ 598 // Invoke resolution 599 // 600 // Naming conventions: 601 // 602 // resolved_method the specified method (i.e., static receiver specified via constant pool index) 603 // sel_method the selected method (selected via run-time lookup; e.g., based on dynamic receiver class) 604 // resolved_klass the specified klass (i.e., specified via constant pool index) 605 // recv_klass the receiver klass 606 607 608 void LinkResolver::resolve_static_call(CallInfo& result, KlassHandle& resolved_klass, symbolHandle method_name, 609 symbolHandle method_signature, KlassHandle current_klass, 610 bool check_access, bool initialize_class, TRAPS) { 611 methodHandle resolved_method; 612 linktime_resolve_static_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, check_access, CHECK); 613 resolved_klass = KlassHandle(THREAD, Klass::cast(resolved_method->method_holder())); 614 615 // Initialize klass (this should only happen if everything is ok) 616 if (initialize_class && resolved_klass->should_be_initialized()) { 617 resolved_klass->initialize(CHECK); 618 linktime_resolve_static_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, check_access, CHECK); 619 } 620 621 // setup result 622 result.set_static(resolved_klass, resolved_method, CHECK); 623 } 624 625 // throws linktime exceptions 626 void LinkResolver::linktime_resolve_static_method(methodHandle& resolved_method, KlassHandle resolved_klass, 627 symbolHandle method_name, symbolHandle method_signature, 628 KlassHandle current_klass, bool check_access, TRAPS) { 629 630 resolve_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, check_access, CHECK); 631 assert(resolved_method->name() != vmSymbols::class_initializer_name(), "should have been checked in verifier"); 632 633 // check if static 634 if (!resolved_method->is_static()) { 635 char buf[200]; 636 jio_snprintf(buf, sizeof(buf), "Expected static method %s", methodOopDesc::name_and_sig_as_C_string(Klass::cast(resolved_klass()), 637 resolved_method->name(), 638 resolved_method->signature())); 639 THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf); 640 } 641 } 642 643 644 void LinkResolver::resolve_special_call(CallInfo& result, KlassHandle resolved_klass, symbolHandle method_name, 645 symbolHandle method_signature, KlassHandle current_klass, bool check_access, TRAPS) { 646 methodHandle resolved_method; 647 linktime_resolve_special_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, check_access, CHECK); 648 runtime_resolve_special_method(result, resolved_method, resolved_klass, current_klass, check_access, CHECK); 649 } 650 651 // throws linktime exceptions 652 void LinkResolver::linktime_resolve_special_method(methodHandle& resolved_method, KlassHandle resolved_klass, 653 symbolHandle method_name, symbolHandle method_signature, 654 KlassHandle current_klass, bool check_access, TRAPS) { 655 656 resolve_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, check_access, CHECK); 657 658 // check if method name is <init>, that it is found in same klass as static type 659 if (resolved_method->name() == vmSymbols::object_initializer_name() && 660 resolved_method->method_holder() != resolved_klass()) { 661 ResourceMark rm(THREAD); 662 Exceptions::fthrow( 663 THREAD_AND_LOCATION, 664 vmSymbolHandles::java_lang_NoSuchMethodError(), 665 "%s: method %s%s not found", 666 resolved_klass->external_name(), 667 resolved_method->name()->as_C_string(), 668 resolved_method->signature()->as_C_string() 669 ); 670 return; 671 } 672 673 // check if not static 674 if (resolved_method->is_static()) { 675 char buf[200]; 676 jio_snprintf(buf, sizeof(buf), 677 "Expecting non-static method %s", 678 methodOopDesc::name_and_sig_as_C_string(Klass::cast(resolved_klass()), 679 resolved_method->name(), 680 resolved_method->signature())); 681 THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf); 682 } 683 } 684 685 // throws runtime exceptions 686 void LinkResolver::runtime_resolve_special_method(CallInfo& result, methodHandle resolved_method, KlassHandle resolved_klass, 687 KlassHandle current_klass, bool check_access, TRAPS) { 688 689 // resolved method is selected method unless we have an old-style lookup 690 methodHandle sel_method(THREAD, resolved_method()); 691 692 // check if this is an old-style super call and do a new lookup if so 693 { KlassHandle method_klass = KlassHandle(THREAD, 694 resolved_method->method_holder()); 695 696 if (check_access && 697 // a) check if ACC_SUPER flag is set for the current class 698 current_klass->is_super() && 699 // b) check if the method class is a superclass of the current class (superclass relation is not reflexive!) 700 current_klass->is_subtype_of(method_klass()) && current_klass() != method_klass() && 701 // c) check if the method is not <init> 702 resolved_method->name() != vmSymbols::object_initializer_name()) { 703 // Lookup super method 704 KlassHandle super_klass(THREAD, current_klass->super()); 705 lookup_instance_method_in_klasses(sel_method, super_klass, 706 symbolHandle(THREAD, resolved_method->name()), 707 symbolHandle(THREAD, resolved_method->signature()), CHECK); 708 // check if found 709 if (sel_method.is_null()) { 710 ResourceMark rm(THREAD); 711 THROW_MSG(vmSymbols::java_lang_AbstractMethodError(), 712 methodOopDesc::name_and_sig_as_C_string(Klass::cast(resolved_klass()), 713 resolved_method->name(), 714 resolved_method->signature())); 715 } 716 } 717 } 718 719 // check if not static 720 if (sel_method->is_static()) { 721 char buf[200]; 722 jio_snprintf(buf, sizeof(buf), "Expecting non-static method %s", methodOopDesc::name_and_sig_as_C_string(Klass::cast(resolved_klass()), 723 resolved_method->name(), 724 resolved_method->signature())); 725 THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf); 726 } 727 728 // check if abstract 729 if (sel_method->is_abstract()) { 730 ResourceMark rm(THREAD); 731 THROW_MSG(vmSymbols::java_lang_AbstractMethodError(), 732 methodOopDesc::name_and_sig_as_C_string(Klass::cast(resolved_klass()), 733 sel_method->name(), 734 sel_method->signature())); 735 } 736 737 // setup result 738 result.set_static(resolved_klass, sel_method, CHECK); 739 } 740 741 void LinkResolver::resolve_virtual_call(CallInfo& result, Handle recv, KlassHandle receiver_klass, KlassHandle resolved_klass, 742 symbolHandle method_name, symbolHandle method_signature, KlassHandle current_klass, 743 bool check_access, bool check_null_and_abstract, TRAPS) { 744 methodHandle resolved_method; 745 linktime_resolve_virtual_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, check_access, CHECK); 746 runtime_resolve_virtual_method(result, resolved_method, resolved_klass, recv, receiver_klass, check_null_and_abstract, CHECK); 747 } 748 749 // throws linktime exceptions 750 void LinkResolver::linktime_resolve_virtual_method(methodHandle &resolved_method, KlassHandle resolved_klass, 751 symbolHandle method_name, symbolHandle method_signature, 752 KlassHandle current_klass, bool check_access, TRAPS) { 753 // normal method resolution 754 resolve_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, check_access, CHECK); 755 756 assert(resolved_method->name() != vmSymbols::object_initializer_name(), "should have been checked in verifier"); 757 assert(resolved_method->name() != vmSymbols::class_initializer_name (), "should have been checked in verifier"); 758 759 // check if not static 760 if (resolved_method->is_static()) { 761 char buf[200]; 762 jio_snprintf(buf, sizeof(buf), "Expecting non-static method %s", methodOopDesc::name_and_sig_as_C_string(Klass::cast(resolved_klass()), 763 resolved_method->name(), 764 resolved_method->signature())); 765 THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf); 766 } 767 } 768 769 // throws runtime exceptions 770 void LinkResolver::runtime_resolve_virtual_method(CallInfo& result, 771 methodHandle resolved_method, 772 KlassHandle resolved_klass, 773 Handle recv, 774 KlassHandle recv_klass, 775 bool check_null_and_abstract, 776 TRAPS) { 777 778 // setup default return values 779 int vtable_index = methodOopDesc::invalid_vtable_index; 780 methodHandle selected_method; 781 782 assert(recv.is_null() || recv->is_oop(), "receiver is not an oop"); 783 784 // runtime method resolution 785 if (check_null_and_abstract && recv.is_null()) { // check if receiver exists 786 THROW(vmSymbols::java_lang_NullPointerException()); 787 } 788 789 // Virtual methods cannot be resolved before its klass has been linked, for otherwise the methodOop's 790 // has not been rewritten, and the vtable initialized. 791 assert(instanceKlass::cast(resolved_method->method_holder())->is_linked(), "must be linked"); 792 793 // Virtual methods cannot be resolved before its klass has been linked, for otherwise the methodOop's 794 // has not been rewritten, and the vtable initialized. Make sure to do this after the nullcheck, since 795 // a missing receiver might result in a bogus lookup. 796 assert(instanceKlass::cast(resolved_method->method_holder())->is_linked(), "must be linked"); 797 798 // do lookup based on receiver klass using the vtable index 799 if (resolved_method->method_holder()->klass_part()->is_interface()) { // miranda method 800 vtable_index = vtable_index_of_miranda_method(resolved_klass, 801 symbolHandle(THREAD, resolved_method->name()), 802 symbolHandle(THREAD, resolved_method->signature()), CHECK); 803 assert(vtable_index >= 0 , "we should have valid vtable index at this point"); 804 805 instanceKlass* inst = instanceKlass::cast(recv_klass()); 806 selected_method = methodHandle(THREAD, inst->method_at_vtable(vtable_index)); 807 } else { 808 // at this point we are sure that resolved_method is virtual and not 809 // a miranda method; therefore, it must have a valid vtable index. 810 vtable_index = resolved_method->vtable_index(); 811 // We could get a negative vtable_index for final methods, 812 // because as an optimization they are they are never put in the vtable, 813 // unless they override an existing method. 814 // If we do get a negative, it means the resolved method is the the selected 815 // method, and it can never be changed by an override. 816 if (vtable_index == methodOopDesc::nonvirtual_vtable_index) { 817 assert(resolved_method->can_be_statically_bound(), "cannot override this method"); 818 selected_method = resolved_method; 819 } else { 820 // recv_klass might be an arrayKlassOop but all vtables start at 821 // the same place. The cast is to avoid virtual call and assertion. 822 instanceKlass* inst = (instanceKlass*)recv_klass()->klass_part(); 823 selected_method = methodHandle(THREAD, inst->method_at_vtable(vtable_index)); 824 } 825 } 826 827 // check if method exists 828 if (selected_method.is_null()) { 829 ResourceMark rm(THREAD); 830 THROW_MSG(vmSymbols::java_lang_AbstractMethodError(), 831 methodOopDesc::name_and_sig_as_C_string(Klass::cast(resolved_klass()), 832 resolved_method->name(), 833 resolved_method->signature())); 834 } 835 836 // check if abstract 837 if (check_null_and_abstract && selected_method->is_abstract()) { 838 ResourceMark rm(THREAD); 839 THROW_MSG(vmSymbols::java_lang_AbstractMethodError(), 840 methodOopDesc::name_and_sig_as_C_string(Klass::cast(resolved_klass()), 841 selected_method->name(), 842 selected_method->signature())); 843 } 844 845 // setup result 846 result.set_virtual(resolved_klass, recv_klass, resolved_method, selected_method, vtable_index, CHECK); 847 } 848 849 void LinkResolver::resolve_interface_call(CallInfo& result, Handle recv, KlassHandle recv_klass, KlassHandle resolved_klass, 850 symbolHandle method_name, symbolHandle method_signature, KlassHandle current_klass, 851 bool check_access, bool check_null_and_abstract, TRAPS) { 852 methodHandle resolved_method; 853 linktime_resolve_interface_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, check_access, CHECK); 854 runtime_resolve_interface_method(result, resolved_method, resolved_klass, recv, recv_klass, check_null_and_abstract, CHECK); 855 } 856 857 // throws linktime exceptions 858 void LinkResolver::linktime_resolve_interface_method(methodHandle& resolved_method, KlassHandle resolved_klass, symbolHandle method_name, 859 symbolHandle method_signature, KlassHandle current_klass, bool check_access, TRAPS) { 860 // normal interface method resolution 861 resolve_interface_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, check_access, CHECK); 862 863 assert(resolved_method->name() != vmSymbols::object_initializer_name(), "should have been checked in verifier"); 864 assert(resolved_method->name() != vmSymbols::class_initializer_name (), "should have been checked in verifier"); 865 } 866 867 // throws runtime exceptions 868 void LinkResolver::runtime_resolve_interface_method(CallInfo& result, methodHandle resolved_method, KlassHandle resolved_klass, 869 Handle recv, KlassHandle recv_klass, bool check_null_and_abstract, TRAPS) { 870 // check if receiver exists 871 if (check_null_and_abstract && recv.is_null()) { 872 THROW(vmSymbols::java_lang_NullPointerException()); 873 } 874 875 // check if receiver klass implements the resolved interface 876 if (!recv_klass->is_subtype_of(resolved_klass())) { 877 char buf[200]; 878 jio_snprintf(buf, sizeof(buf), "Class %s does not implement the requested interface %s", 879 (Klass::cast(recv_klass()))->external_name(), 880 (Klass::cast(resolved_klass()))->external_name()); 881 THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf); 882 } 883 // do lookup based on receiver klass 884 methodHandle sel_method; 885 lookup_instance_method_in_klasses(sel_method, recv_klass, 886 symbolHandle(THREAD, resolved_method->name()), 887 symbolHandle(THREAD, resolved_method->signature()), CHECK); 888 // check if method exists 889 if (sel_method.is_null()) { 890 ResourceMark rm(THREAD); 891 THROW_MSG(vmSymbols::java_lang_AbstractMethodError(), 892 methodOopDesc::name_and_sig_as_C_string(Klass::cast(recv_klass()), 893 resolved_method->name(), 894 resolved_method->signature())); 895 } 896 // check if public 897 if (!sel_method->is_public()) { 898 ResourceMark rm(THREAD); 899 THROW_MSG(vmSymbols::java_lang_IllegalAccessError(), 900 methodOopDesc::name_and_sig_as_C_string(Klass::cast(recv_klass()), 901 sel_method->name(), 902 sel_method->signature())); 903 } 904 // check if abstract 905 if (check_null_and_abstract && sel_method->is_abstract()) { 906 ResourceMark rm(THREAD); 907 THROW_MSG(vmSymbols::java_lang_AbstractMethodError(), 908 methodOopDesc::name_and_sig_as_C_string(Klass::cast(recv_klass()), 909 sel_method->name(), 910 sel_method->signature())); 911 } 912 // setup result 913 result.set_interface(resolved_klass, recv_klass, resolved_method, sel_method, CHECK); 914 } 915 916 917 methodHandle LinkResolver::linktime_resolve_interface_method_or_null( 918 KlassHandle resolved_klass, 919 symbolHandle method_name, 920 symbolHandle method_signature, 921 KlassHandle current_klass, 922 bool check_access) { 923 EXCEPTION_MARK; 924 methodHandle method_result; 925 linktime_resolve_interface_method(method_result, resolved_klass, method_name, method_signature, current_klass, check_access, THREAD); 926 if (HAS_PENDING_EXCEPTION) { 927 CLEAR_PENDING_EXCEPTION; 928 return methodHandle(); 929 } else { 930 return method_result; 931 } 932 } 933 934 methodHandle LinkResolver::linktime_resolve_virtual_method_or_null( 935 KlassHandle resolved_klass, 936 symbolHandle method_name, 937 symbolHandle method_signature, 938 KlassHandle current_klass, 939 bool check_access) { 940 EXCEPTION_MARK; 941 methodHandle method_result; 942 linktime_resolve_virtual_method(method_result, resolved_klass, method_name, method_signature, current_klass, check_access, THREAD); 943 if (HAS_PENDING_EXCEPTION) { 944 CLEAR_PENDING_EXCEPTION; 945 return methodHandle(); 946 } else { 947 return method_result; 948 } 949 } 950 951 methodHandle LinkResolver::resolve_virtual_call_or_null( 952 KlassHandle receiver_klass, 953 KlassHandle resolved_klass, 954 symbolHandle name, 955 symbolHandle signature, 956 KlassHandle current_klass) { 957 EXCEPTION_MARK; 958 CallInfo info; 959 resolve_virtual_call(info, Handle(), receiver_klass, resolved_klass, name, signature, current_klass, true, false, THREAD); 960 if (HAS_PENDING_EXCEPTION) { 961 CLEAR_PENDING_EXCEPTION; 962 return methodHandle(); 963 } 964 return info.selected_method(); 965 } 966 967 methodHandle LinkResolver::resolve_interface_call_or_null( 968 KlassHandle receiver_klass, 969 KlassHandle resolved_klass, 970 symbolHandle name, 971 symbolHandle signature, 972 KlassHandle current_klass) { 973 EXCEPTION_MARK; 974 CallInfo info; 975 resolve_interface_call(info, Handle(), receiver_klass, resolved_klass, name, signature, current_klass, true, false, THREAD); 976 if (HAS_PENDING_EXCEPTION) { 977 CLEAR_PENDING_EXCEPTION; 978 return methodHandle(); 979 } 980 return info.selected_method(); 981 } 982 983 int LinkResolver::resolve_virtual_vtable_index( 984 KlassHandle receiver_klass, 985 KlassHandle resolved_klass, 986 symbolHandle name, 987 symbolHandle signature, 988 KlassHandle current_klass) { 989 EXCEPTION_MARK; 990 CallInfo info; 991 resolve_virtual_call(info, Handle(), receiver_klass, resolved_klass, name, signature, current_klass, true, false, THREAD); 992 if (HAS_PENDING_EXCEPTION) { 993 CLEAR_PENDING_EXCEPTION; 994 return methodOopDesc::invalid_vtable_index; 995 } 996 return info.vtable_index(); 997 } 998 999 methodHandle LinkResolver::resolve_static_call_or_null( 1000 KlassHandle resolved_klass, 1001 symbolHandle name, 1002 symbolHandle signature, 1003 KlassHandle current_klass) { 1004 EXCEPTION_MARK; 1005 CallInfo info; 1006 resolve_static_call(info, resolved_klass, name, signature, current_klass, true, false, THREAD); 1007 if (HAS_PENDING_EXCEPTION) { 1008 CLEAR_PENDING_EXCEPTION; 1009 return methodHandle(); 1010 } 1011 return info.selected_method(); 1012 } 1013 1014 methodHandle LinkResolver::resolve_special_call_or_null(KlassHandle resolved_klass, symbolHandle name, symbolHandle signature, 1015 KlassHandle current_klass) { 1016 EXCEPTION_MARK; 1017 CallInfo info; 1018 resolve_special_call(info, resolved_klass, name, signature, current_klass, true, THREAD); 1019 if (HAS_PENDING_EXCEPTION) { 1020 CLEAR_PENDING_EXCEPTION; 1021 return methodHandle(); 1022 } 1023 return info.selected_method(); 1024 } 1025 1026 1027 1028 //------------------------------------------------------------------------------------------------------------------------ 1029 // ConstantPool entries 1030 1031 void LinkResolver::resolve_invoke(CallInfo& result, Handle recv, constantPoolHandle pool, int index, Bytecodes::Code byte, TRAPS) { 1032 switch (byte) { 1033 case Bytecodes::_invokestatic : resolve_invokestatic (result, pool, index, CHECK); break; 1034 case Bytecodes::_invokespecial : resolve_invokespecial (result, pool, index, CHECK); break; 1035 case Bytecodes::_invokevirtual : resolve_invokevirtual (result, recv, pool, index, CHECK); break; 1036 case Bytecodes::_invokedynamic : resolve_invokedynamic (result, pool, index, CHECK); break; 1037 case Bytecodes::_invokeinterface: resolve_invokeinterface(result, recv, pool, index, CHECK); break; 1038 } 1039 return; 1040 } 1041 1042 void LinkResolver::resolve_pool(KlassHandle& resolved_klass, symbolHandle& method_name, symbolHandle& method_signature, 1043 KlassHandle& current_klass, constantPoolHandle pool, int index, TRAPS) { 1044 // resolve klass 1045 resolve_klass(resolved_klass, pool, index, CHECK); 1046 1047 // Get name, signature, and static klass 1048 method_name = symbolHandle(THREAD, pool->name_ref_at(index)); 1049 method_signature = symbolHandle(THREAD, pool->signature_ref_at(index)); 1050 current_klass = KlassHandle(THREAD, pool->pool_holder()); 1051 } 1052 1053 1054 void LinkResolver::resolve_invokestatic(CallInfo& result, constantPoolHandle pool, int index, TRAPS) { 1055 KlassHandle resolved_klass; 1056 symbolHandle method_name; 1057 symbolHandle method_signature; 1058 KlassHandle current_klass; 1059 resolve_pool(resolved_klass, method_name, method_signature, current_klass, pool, index, CHECK); 1060 resolve_static_call(result, resolved_klass, method_name, method_signature, current_klass, true, true, CHECK); 1061 } 1062 1063 1064 void LinkResolver::resolve_invokespecial(CallInfo& result, constantPoolHandle pool, int index, TRAPS) { 1065 KlassHandle resolved_klass; 1066 symbolHandle method_name; 1067 symbolHandle method_signature; 1068 KlassHandle current_klass; 1069 resolve_pool(resolved_klass, method_name, method_signature, current_klass, pool, index, CHECK); 1070 resolve_special_call(result, resolved_klass, method_name, method_signature, current_klass, true, CHECK); 1071 } 1072 1073 1074 void LinkResolver::resolve_invokevirtual(CallInfo& result, Handle recv, 1075 constantPoolHandle pool, int index, 1076 TRAPS) { 1077 1078 KlassHandle resolved_klass; 1079 symbolHandle method_name; 1080 symbolHandle method_signature; 1081 KlassHandle current_klass; 1082 resolve_pool(resolved_klass, method_name, method_signature, current_klass, pool, index, CHECK); 1083 KlassHandle recvrKlass (THREAD, recv.is_null() ? (klassOop)NULL : recv->klass()); 1084 resolve_virtual_call(result, recv, recvrKlass, resolved_klass, method_name, method_signature, current_klass, true, true, CHECK); 1085 } 1086 1087 1088 void LinkResolver::resolve_invokeinterface(CallInfo& result, Handle recv, constantPoolHandle pool, int index, TRAPS) { 1089 KlassHandle resolved_klass; 1090 symbolHandle method_name; 1091 symbolHandle method_signature; 1092 KlassHandle current_klass; 1093 resolve_pool(resolved_klass, method_name, method_signature, current_klass, pool, index, CHECK); 1094 KlassHandle recvrKlass (THREAD, recv.is_null() ? (klassOop)NULL : recv->klass()); 1095 resolve_interface_call(result, recv, recvrKlass, resolved_klass, method_name, method_signature, current_klass, true, true, CHECK); 1096 } 1097 1098 1099 void LinkResolver::resolve_invokedynamic(CallInfo& result, constantPoolHandle pool, int raw_index, TRAPS) { 1100 assert(EnableInvokeDynamic, ""); 1101 1102 // This guy is reached from InterpreterRuntime::resolve_invokedynamic. 1103 1104 // At this point, we only need the signature, and can ignore the name. 1105 symbolHandle method_signature(THREAD, pool->signature_ref_at(raw_index)); // raw_index works directly 1106 symbolHandle method_name = vmSymbolHandles::invokeExact_name(); 1107 KlassHandle resolved_klass = SystemDictionaryHandles::MethodHandle_klass(); 1108 1109 // JSR 292: this must be an implicitly generated method MethodHandle.invokeExact(*...) 1110 // The extra MH receiver will be inserted into the stack on every call. 1111 methodHandle resolved_method; 1112 KlassHandle current_klass(THREAD, pool->pool_holder()); 1113 lookup_implicit_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, CHECK); 1114 if (resolved_method.is_null()) { 1115 THROW(vmSymbols::java_lang_InternalError()); 1116 } 1117 result.set_dynamic(resolved_method, CHECK); 1118 } 1119 1120 //------------------------------------------------------------------------------------------------------------------------ 1121 #ifndef PRODUCT 1122 1123 void FieldAccessInfo::print() { 1124 ResourceMark rm; 1125 tty->print_cr("Field %s@%d", name()->as_C_string(), field_offset()); 1126 } 1127 1128 #endif