src/share/vm/interpreter/linkResolver.cpp

Sun, 25 Sep 2011 16:03:29 -0700

author
never
date
Sun, 25 Sep 2011 16:03:29 -0700
changeset 3156
f08d439fab8c
parent 3035
43f9d800f276
child 3969
1d7922586cf6
permissions
-rw-r--r--

7089790: integrate bsd-port changes
Reviewed-by: kvn, twisti, jrose
Contributed-by: Kurt Miller <kurt@intricatesoftware.com>, Greg Lewis <glewis@eyesbeyond.com>, Jung-uk Kim <jkim@freebsd.org>, Christos Zoulas <christos@zoulas.com>, Landon Fuller <landonf@plausible.coop>, The FreeBSD Foundation <board@freebsdfoundation.org>, Michael Franz <mvfranz@gmail.com>, Roger Hoover <rhoover@apple.com>, Alexander Strange <astrange@apple.com>

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

mercurial