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