Thu, 11 Jul 2013 12:56:29 -0700
Merge
duke@435 | 1 | /* |
coleenp@4490 | 2 | * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. |
duke@435 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@435 | 4 | * |
duke@435 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@435 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@435 | 7 | * published by the Free Software Foundation. |
duke@435 | 8 | * |
duke@435 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@435 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@435 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@435 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@435 | 13 | * accompanied this code). |
duke@435 | 14 | * |
duke@435 | 15 | * You should have received a copy of the GNU General Public License version |
duke@435 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@435 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@435 | 18 | * |
trims@1907 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
trims@1907 | 20 | * or visit www.oracle.com if you need additional information or have any |
trims@1907 | 21 | * questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
stefank@2314 | 25 | #include "precompiled.hpp" |
kamg@4245 | 26 | #include "classfile/defaultMethods.hpp" |
stefank@2314 | 27 | #include "classfile/systemDictionary.hpp" |
stefank@2314 | 28 | #include "classfile/vmSymbols.hpp" |
stefank@2314 | 29 | #include "compiler/compileBroker.hpp" |
stefank@2314 | 30 | #include "gc_interface/collectedHeap.inline.hpp" |
stefank@2314 | 31 | #include "interpreter/bytecode.hpp" |
stefank@2314 | 32 | #include "interpreter/interpreterRuntime.hpp" |
stefank@2314 | 33 | #include "interpreter/linkResolver.hpp" |
stefank@2314 | 34 | #include "memory/resourceArea.hpp" |
stefank@2314 | 35 | #include "memory/universe.inline.hpp" |
stefank@2314 | 36 | #include "oops/instanceKlass.hpp" |
stefank@2314 | 37 | #include "oops/objArrayOop.hpp" |
stefank@2314 | 38 | #include "prims/methodHandles.hpp" |
stefank@2314 | 39 | #include "prims/nativeLookup.hpp" |
stefank@2314 | 40 | #include "runtime/compilationPolicy.hpp" |
stefank@2314 | 41 | #include "runtime/fieldDescriptor.hpp" |
stefank@2314 | 42 | #include "runtime/frame.inline.hpp" |
stefank@2314 | 43 | #include "runtime/handles.inline.hpp" |
stefank@2314 | 44 | #include "runtime/reflection.hpp" |
stefank@2314 | 45 | #include "runtime/signature.hpp" |
stefank@4299 | 46 | #include "runtime/thread.inline.hpp" |
stefank@2314 | 47 | #include "runtime/vmThread.hpp" |
duke@435 | 48 | |
duke@435 | 49 | //------------------------------------------------------------------------------------------------------------------------ |
duke@435 | 50 | // Implementation of FieldAccessInfo |
duke@435 | 51 | |
coleenp@2497 | 52 | void FieldAccessInfo::set(KlassHandle klass, Symbol* name, int field_index, int field_offset, |
duke@435 | 53 | BasicType field_type, AccessFlags access_flags) { |
duke@435 | 54 | _klass = klass; |
duke@435 | 55 | _name = name; |
duke@435 | 56 | _field_index = field_index; |
duke@435 | 57 | _field_offset = field_offset; |
duke@435 | 58 | _field_type = field_type; |
duke@435 | 59 | _access_flags = access_flags; |
duke@435 | 60 | } |
duke@435 | 61 | |
duke@435 | 62 | |
duke@435 | 63 | //------------------------------------------------------------------------------------------------------------------------ |
duke@435 | 64 | // Implementation of CallInfo |
duke@435 | 65 | |
duke@435 | 66 | |
duke@435 | 67 | void CallInfo::set_static(KlassHandle resolved_klass, methodHandle resolved_method, TRAPS) { |
coleenp@4037 | 68 | int vtable_index = Method::nonvirtual_vtable_index; |
duke@435 | 69 | set_common(resolved_klass, resolved_klass, resolved_method, resolved_method, vtable_index, CHECK); |
duke@435 | 70 | } |
duke@435 | 71 | |
duke@435 | 72 | |
duke@435 | 73 | void CallInfo::set_interface(KlassHandle resolved_klass, KlassHandle selected_klass, methodHandle resolved_method, methodHandle selected_method, TRAPS) { |
duke@435 | 74 | // This is only called for interface methods. If the resolved_method |
duke@435 | 75 | // comes from java/lang/Object, it can be the subject of a virtual call, so |
duke@435 | 76 | // we should pick the vtable index from the resolved method. |
duke@435 | 77 | // Other than that case, there is no valid vtable index to specify. |
coleenp@4037 | 78 | int vtable_index = Method::invalid_vtable_index; |
never@1577 | 79 | if (resolved_method->method_holder() == SystemDictionary::Object_klass()) { |
duke@435 | 80 | assert(resolved_method->vtable_index() == selected_method->vtable_index(), "sanity check"); |
duke@435 | 81 | vtable_index = resolved_method->vtable_index(); |
duke@435 | 82 | } |
duke@435 | 83 | set_common(resolved_klass, selected_klass, resolved_method, selected_method, vtable_index, CHECK); |
duke@435 | 84 | } |
duke@435 | 85 | |
duke@435 | 86 | void CallInfo::set_virtual(KlassHandle resolved_klass, KlassHandle selected_klass, methodHandle resolved_method, methodHandle selected_method, int vtable_index, TRAPS) { |
coleenp@4037 | 87 | assert(vtable_index >= 0 || vtable_index == Method::nonvirtual_vtable_index, "valid index"); |
duke@435 | 88 | set_common(resolved_klass, selected_klass, resolved_method, selected_method, vtable_index, CHECK); |
twisti@3969 | 89 | assert(!resolved_method->is_compiled_lambda_form(), "these must be handled via an invokehandle call"); |
duke@435 | 90 | } |
duke@435 | 91 | |
twisti@4133 | 92 | void CallInfo::set_handle(methodHandle resolved_method, Handle resolved_appendix, Handle resolved_method_type, TRAPS) { |
twisti@3969 | 93 | if (resolved_method.is_null()) { |
twisti@3969 | 94 | THROW_MSG(vmSymbols::java_lang_InternalError(), "resolved method is null"); |
twisti@3969 | 95 | } |
coleenp@4037 | 96 | KlassHandle resolved_klass = SystemDictionary::MethodHandle_klass(); |
twisti@3969 | 97 | assert(resolved_method->intrinsic_id() == vmIntrinsics::_invokeBasic || |
twisti@3969 | 98 | resolved_method->is_compiled_lambda_form(), |
twisti@3969 | 99 | "linkMethod must return one of these"); |
coleenp@4037 | 100 | int vtable_index = Method::nonvirtual_vtable_index; |
jrose@2015 | 101 | assert(resolved_method->vtable_index() == vtable_index, ""); |
twisti@3969 | 102 | set_common(resolved_klass, resolved_klass, resolved_method, resolved_method, vtable_index, CHECK); |
twisti@4133 | 103 | _resolved_appendix = resolved_appendix; |
twisti@4133 | 104 | _resolved_method_type = resolved_method_type; |
jrose@2015 | 105 | } |
jrose@2015 | 106 | |
duke@435 | 107 | void CallInfo::set_common(KlassHandle resolved_klass, KlassHandle selected_klass, methodHandle resolved_method, methodHandle selected_method, int vtable_index, TRAPS) { |
duke@435 | 108 | assert(resolved_method->signature() == selected_method->signature(), "signatures must correspond"); |
duke@435 | 109 | _resolved_klass = resolved_klass; |
duke@435 | 110 | _selected_klass = selected_klass; |
duke@435 | 111 | _resolved_method = resolved_method; |
duke@435 | 112 | _selected_method = selected_method; |
duke@435 | 113 | _vtable_index = vtable_index; |
twisti@3969 | 114 | _resolved_appendix = Handle(); |
iveresov@2138 | 115 | if (CompilationPolicy::must_be_compiled(selected_method)) { |
twisti@1570 | 116 | // This path is unusual, mostly used by the '-Xcomp' stress test mode. |
twisti@1570 | 117 | |
iveresov@2138 | 118 | // Note: with several active threads, the must_be_compiled may be true |
iveresov@2138 | 119 | // while can_be_compiled is false; remove assert |
iveresov@2138 | 120 | // assert(CompilationPolicy::can_be_compiled(selected_method), "cannot compile"); |
duke@435 | 121 | if (THREAD->is_Compiler_thread()) { |
duke@435 | 122 | // don't force compilation, resolve was on behalf of compiler |
duke@435 | 123 | return; |
duke@435 | 124 | } |
coleenp@4251 | 125 | if (selected_method->method_holder()->is_not_initialized()) { |
twisti@1570 | 126 | // 'is_not_initialized' means not only '!is_initialized', but also that |
twisti@1570 | 127 | // initialization has not been started yet ('!being_initialized') |
twisti@1570 | 128 | // Do not force compilation of methods in uninitialized classes. |
twisti@1570 | 129 | // Note that doing this would throw an assert later, |
twisti@1570 | 130 | // in CompileBroker::compile_method. |
twisti@1570 | 131 | // We sometimes use the link resolver to do reflective lookups |
twisti@1570 | 132 | // even before classes are initialized. |
twisti@1570 | 133 | return; |
twisti@1570 | 134 | } |
duke@435 | 135 | CompileBroker::compile_method(selected_method, InvocationEntryBci, |
iveresov@3035 | 136 | CompilationPolicy::policy()->initial_compile_level(), |
iveresov@2138 | 137 | methodHandle(), 0, "must_be_compiled", CHECK); |
duke@435 | 138 | } |
duke@435 | 139 | } |
duke@435 | 140 | |
duke@435 | 141 | |
duke@435 | 142 | //------------------------------------------------------------------------------------------------------------------------ |
duke@435 | 143 | // Klass resolution |
duke@435 | 144 | |
duke@435 | 145 | void LinkResolver::check_klass_accessability(KlassHandle ref_klass, KlassHandle sel_klass, TRAPS) { |
coleenp@4037 | 146 | if (!Reflection::verify_class_access(ref_klass(), |
coleenp@4037 | 147 | sel_klass(), |
duke@435 | 148 | true)) { |
duke@435 | 149 | ResourceMark rm(THREAD); |
duke@435 | 150 | Exceptions::fthrow( |
duke@435 | 151 | THREAD_AND_LOCATION, |
coleenp@2497 | 152 | vmSymbols::java_lang_IllegalAccessError(), |
duke@435 | 153 | "tried to access class %s from class %s", |
duke@435 | 154 | sel_klass->external_name(), |
duke@435 | 155 | ref_klass->external_name() |
duke@435 | 156 | ); |
duke@435 | 157 | return; |
duke@435 | 158 | } |
duke@435 | 159 | } |
duke@435 | 160 | |
duke@435 | 161 | void LinkResolver::resolve_klass(KlassHandle& result, constantPoolHandle pool, int index, TRAPS) { |
coleenp@4037 | 162 | Klass* result_oop = pool->klass_ref_at(index, CHECK); |
duke@435 | 163 | result = KlassHandle(THREAD, result_oop); |
duke@435 | 164 | } |
duke@435 | 165 | |
duke@435 | 166 | void LinkResolver::resolve_klass_no_update(KlassHandle& result, constantPoolHandle pool, int index, TRAPS) { |
coleenp@4037 | 167 | Klass* result_oop = |
coleenp@4037 | 168 | ConstantPool::klass_ref_at_if_loaded_check(pool, index, CHECK); |
duke@435 | 169 | result = KlassHandle(THREAD, result_oop); |
duke@435 | 170 | } |
duke@435 | 171 | |
duke@435 | 172 | |
duke@435 | 173 | //------------------------------------------------------------------------------------------------------------------------ |
duke@435 | 174 | // Method resolution |
duke@435 | 175 | // |
duke@435 | 176 | // According to JVM spec. $5.4.3c & $5.4.3d |
duke@435 | 177 | |
coleenp@2497 | 178 | void LinkResolver::lookup_method_in_klasses(methodHandle& result, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS) { |
coleenp@4037 | 179 | Method* result_oop = klass->uncached_lookup_method(name, signature); |
twisti@2698 | 180 | if (EnableInvokeDynamic && result_oop != NULL) { |
twisti@3969 | 181 | vmIntrinsics::ID iid = result_oop->intrinsic_id(); |
twisti@3969 | 182 | if (MethodHandles::is_signature_polymorphic(iid)) { |
twisti@3969 | 183 | // Do not link directly to these. The VM must produce a synthetic one using lookup_polymorphic_method. |
jrose@1862 | 184 | return; |
jrose@1862 | 185 | } |
jrose@1862 | 186 | } |
duke@435 | 187 | result = methodHandle(THREAD, result_oop); |
duke@435 | 188 | } |
duke@435 | 189 | |
duke@435 | 190 | // returns first instance method |
coleenp@2497 | 191 | void LinkResolver::lookup_instance_method_in_klasses(methodHandle& result, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS) { |
coleenp@4037 | 192 | Method* result_oop = klass->uncached_lookup_method(name, signature); |
duke@435 | 193 | result = methodHandle(THREAD, result_oop); |
duke@435 | 194 | while (!result.is_null() && result->is_static()) { |
hseigel@4278 | 195 | klass = KlassHandle(THREAD, result->method_holder()->super()); |
coleenp@2497 | 196 | result = methodHandle(THREAD, klass->uncached_lookup_method(name, signature)); |
duke@435 | 197 | } |
duke@435 | 198 | } |
duke@435 | 199 | |
duke@435 | 200 | |
coleenp@2497 | 201 | int LinkResolver::vtable_index_of_miranda_method(KlassHandle klass, Symbol* name, Symbol* signature, TRAPS) { |
duke@435 | 202 | ResourceMark rm(THREAD); |
coleenp@4037 | 203 | klassVtable *vt = InstanceKlass::cast(klass())->vtable(); |
coleenp@2497 | 204 | return vt->index_of_miranda(name, signature); |
duke@435 | 205 | } |
duke@435 | 206 | |
coleenp@2497 | 207 | void LinkResolver::lookup_method_in_interfaces(methodHandle& result, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS) { |
coleenp@4037 | 208 | InstanceKlass *ik = InstanceKlass::cast(klass()); |
coleenp@2497 | 209 | result = methodHandle(THREAD, ik->lookup_method_in_all_interfaces(name, signature)); |
duke@435 | 210 | } |
duke@435 | 211 | |
twisti@3969 | 212 | void LinkResolver::lookup_polymorphic_method(methodHandle& result, |
twisti@3969 | 213 | KlassHandle klass, Symbol* name, Symbol* full_signature, |
twisti@3969 | 214 | KlassHandle current_klass, |
twisti@4133 | 215 | Handle *appendix_result_or_null, |
twisti@4133 | 216 | Handle *method_type_result, |
twisti@3969 | 217 | TRAPS) { |
twisti@3969 | 218 | vmIntrinsics::ID iid = MethodHandles::signature_polymorphic_name_id(name); |
twisti@3969 | 219 | if (TraceMethodHandles) { |
kmo@4910 | 220 | ResourceMark rm(THREAD); |
twisti@3969 | 221 | tty->print_cr("lookup_polymorphic_method iid=%s %s.%s%s", |
twisti@3969 | 222 | vmIntrinsics::name_at(iid), klass->external_name(), |
twisti@3969 | 223 | name->as_C_string(), full_signature->as_C_string()); |
twisti@3969 | 224 | } |
twisti@2698 | 225 | if (EnableInvokeDynamic && |
jrose@1862 | 226 | klass() == SystemDictionary::MethodHandle_klass() && |
twisti@3969 | 227 | iid != vmIntrinsics::_none) { |
twisti@3969 | 228 | if (MethodHandles::is_signature_polymorphic_intrinsic(iid)) { |
twisti@3969 | 229 | // Most of these do not need an up-call to Java to resolve, so can be done anywhere. |
twisti@3969 | 230 | // Do not erase last argument type (MemberName) if it is a static linkTo method. |
twisti@3969 | 231 | bool keep_last_arg = MethodHandles::is_signature_polymorphic_static(iid); |
twisti@3969 | 232 | TempNewSymbol basic_signature = |
twisti@3969 | 233 | MethodHandles::lookup_basic_type_signature(full_signature, keep_last_arg, CHECK); |
twisti@3969 | 234 | if (TraceMethodHandles) { |
kmo@4910 | 235 | ResourceMark rm(THREAD); |
twisti@3969 | 236 | tty->print_cr("lookup_polymorphic_method %s %s => basic %s", |
twisti@3969 | 237 | name->as_C_string(), |
twisti@3969 | 238 | full_signature->as_C_string(), |
twisti@3969 | 239 | basic_signature->as_C_string()); |
jrose@2015 | 240 | } |
twisti@3969 | 241 | result = SystemDictionary::find_method_handle_intrinsic(iid, |
twisti@3969 | 242 | basic_signature, |
twisti@3969 | 243 | CHECK); |
twisti@3969 | 244 | if (result.not_null()) { |
twisti@3969 | 245 | assert(result->is_method_handle_intrinsic(), "MH.invokeBasic or MH.linkTo* intrinsic"); |
twisti@3969 | 246 | assert(result->intrinsic_id() != vmIntrinsics::_invokeGeneric, "wrong place to find this"); |
twisti@3969 | 247 | assert(basic_signature == result->signature(), "predict the result signature"); |
twisti@3969 | 248 | if (TraceMethodHandles) { |
twisti@3969 | 249 | tty->print("lookup_polymorphic_method => intrinsic "); |
twisti@3969 | 250 | result->print_on(tty); |
twisti@3969 | 251 | } |
twisti@3969 | 252 | return; |
twisti@3969 | 253 | } |
twisti@3969 | 254 | } else if (iid == vmIntrinsics::_invokeGeneric |
twisti@3969 | 255 | && !THREAD->is_Compiler_thread() |
twisti@3969 | 256 | && appendix_result_or_null != NULL) { |
twisti@3969 | 257 | // This is a method with type-checking semantics. |
twisti@3969 | 258 | // We will ask Java code to spin an adapter method for it. |
twisti@3969 | 259 | if (!MethodHandles::enabled()) { |
twisti@3969 | 260 | // Make sure the Java part of the runtime has been booted up. |
coleenp@4037 | 261 | Klass* natives = SystemDictionary::MethodHandleNatives_klass(); |
coleenp@4037 | 262 | if (natives == NULL || InstanceKlass::cast(natives)->is_not_initialized()) { |
twisti@3969 | 263 | SystemDictionary::resolve_or_fail(vmSymbols::java_lang_invoke_MethodHandleNatives(), |
twisti@3969 | 264 | Handle(), |
twisti@3969 | 265 | Handle(), |
twisti@3969 | 266 | true, |
twisti@3969 | 267 | CHECK); |
twisti@3969 | 268 | } |
twisti@3969 | 269 | } |
twisti@3969 | 270 | |
twisti@3969 | 271 | Handle appendix; |
twisti@4133 | 272 | Handle method_type; |
twisti@3969 | 273 | result = SystemDictionary::find_method_handle_invoker(name, |
twisti@3969 | 274 | full_signature, |
twisti@3969 | 275 | current_klass, |
twisti@3969 | 276 | &appendix, |
twisti@4133 | 277 | &method_type, |
twisti@3969 | 278 | CHECK); |
twisti@3969 | 279 | if (TraceMethodHandles) { |
twisti@3969 | 280 | tty->print("lookup_polymorphic_method => (via Java) "); |
twisti@3969 | 281 | result->print_on(tty); |
twisti@3969 | 282 | tty->print(" lookup_polymorphic_method => appendix = "); |
twisti@3969 | 283 | if (appendix.is_null()) tty->print_cr("(none)"); |
twisti@3969 | 284 | else appendix->print_on(tty); |
twisti@3969 | 285 | } |
twisti@3969 | 286 | if (result.not_null()) { |
twisti@3969 | 287 | #ifdef ASSERT |
kmo@4910 | 288 | ResourceMark rm(THREAD); |
kmo@4910 | 289 | |
twisti@3969 | 290 | TempNewSymbol basic_signature = |
twisti@3969 | 291 | MethodHandles::lookup_basic_type_signature(full_signature, CHECK); |
twisti@3969 | 292 | int actual_size_of_params = result->size_of_parameters(); |
twisti@3969 | 293 | int expected_size_of_params = ArgumentSizeComputer(basic_signature).size(); |
twisti@3969 | 294 | // +1 for MethodHandle.this, +1 for trailing MethodType |
twisti@3969 | 295 | if (!MethodHandles::is_signature_polymorphic_static(iid)) expected_size_of_params += 1; |
twisti@3969 | 296 | if (appendix.not_null()) expected_size_of_params += 1; |
twisti@3969 | 297 | if (actual_size_of_params != expected_size_of_params) { |
twisti@3969 | 298 | tty->print_cr("*** basic_signature=%s", basic_signature->as_C_string()); |
twisti@3969 | 299 | tty->print_cr("*** result for %s: ", vmIntrinsics::name_at(iid)); |
twisti@3969 | 300 | result->print(); |
twisti@3969 | 301 | } |
twisti@3969 | 302 | assert(actual_size_of_params == expected_size_of_params, |
twisti@3969 | 303 | err_msg("%d != %d", actual_size_of_params, expected_size_of_params)); |
twisti@3969 | 304 | #endif //ASSERT |
twisti@3969 | 305 | |
twisti@3969 | 306 | assert(appendix_result_or_null != NULL, ""); |
twisti@3969 | 307 | (*appendix_result_or_null) = appendix; |
twisti@4133 | 308 | (*method_type_result) = method_type; |
twisti@3969 | 309 | return; |
twisti@3969 | 310 | } |
jrose@1145 | 311 | } |
jrose@1145 | 312 | } |
jrose@1145 | 313 | } |
jrose@1145 | 314 | |
duke@435 | 315 | void LinkResolver::check_method_accessability(KlassHandle ref_klass, |
duke@435 | 316 | KlassHandle resolved_klass, |
duke@435 | 317 | KlassHandle sel_klass, |
duke@435 | 318 | methodHandle sel_method, |
duke@435 | 319 | TRAPS) { |
duke@435 | 320 | |
duke@435 | 321 | AccessFlags flags = sel_method->access_flags(); |
duke@435 | 322 | |
duke@435 | 323 | // Special case: arrays always override "clone". JVMS 2.15. |
duke@435 | 324 | // If the resolved klass is an array class, and the declaring class |
duke@435 | 325 | // is java.lang.Object and the method is "clone", set the flags |
duke@435 | 326 | // to public. |
duke@435 | 327 | // |
duke@435 | 328 | // We'll check for the method name first, as that's most likely |
duke@435 | 329 | // to be false (so we'll short-circuit out of these tests). |
duke@435 | 330 | if (sel_method->name() == vmSymbols::clone_name() && |
never@1577 | 331 | sel_klass() == SystemDictionary::Object_klass() && |
duke@435 | 332 | resolved_klass->oop_is_array()) { |
duke@435 | 333 | // We need to change "protected" to "public". |
duke@435 | 334 | assert(flags.is_protected(), "clone not protected?"); |
duke@435 | 335 | jint new_flags = flags.as_int(); |
duke@435 | 336 | new_flags = new_flags & (~JVM_ACC_PROTECTED); |
duke@435 | 337 | new_flags = new_flags | JVM_ACC_PUBLIC; |
duke@435 | 338 | flags.set_flags(new_flags); |
duke@435 | 339 | } |
twisti@3969 | 340 | // assert(extra_arg_result_or_null != NULL, "must be able to return extra argument"); |
duke@435 | 341 | |
coleenp@4037 | 342 | if (!Reflection::verify_field_access(ref_klass(), |
coleenp@4037 | 343 | resolved_klass(), |
coleenp@4037 | 344 | sel_klass(), |
duke@435 | 345 | flags, |
duke@435 | 346 | true)) { |
duke@435 | 347 | ResourceMark rm(THREAD); |
duke@435 | 348 | Exceptions::fthrow( |
duke@435 | 349 | THREAD_AND_LOCATION, |
coleenp@2497 | 350 | vmSymbols::java_lang_IllegalAccessError(), |
duke@435 | 351 | "tried to access method %s.%s%s from class %s", |
duke@435 | 352 | sel_klass->external_name(), |
duke@435 | 353 | sel_method->name()->as_C_string(), |
duke@435 | 354 | sel_method->signature()->as_C_string(), |
duke@435 | 355 | ref_klass->external_name() |
duke@435 | 356 | ); |
duke@435 | 357 | return; |
duke@435 | 358 | } |
duke@435 | 359 | } |
duke@435 | 360 | |
twisti@3969 | 361 | void LinkResolver::resolve_method_statically(methodHandle& resolved_method, KlassHandle& resolved_klass, |
twisti@3969 | 362 | Bytecodes::Code code, constantPoolHandle pool, int index, TRAPS) { |
duke@435 | 363 | |
duke@435 | 364 | // resolve klass |
twisti@3969 | 365 | if (code == Bytecodes::_invokedynamic) { |
coleenp@4037 | 366 | resolved_klass = SystemDictionary::MethodHandle_klass(); |
twisti@3969 | 367 | Symbol* method_name = vmSymbols::invoke_name(); |
twisti@3969 | 368 | Symbol* method_signature = pool->signature_ref_at(index); |
twisti@3969 | 369 | KlassHandle current_klass(THREAD, pool->pool_holder()); |
twisti@3969 | 370 | resolve_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, true, CHECK); |
twisti@3969 | 371 | return; |
twisti@3969 | 372 | } |
twisti@3969 | 373 | |
duke@435 | 374 | resolve_klass(resolved_klass, pool, index, CHECK); |
duke@435 | 375 | |
coleenp@2497 | 376 | Symbol* method_name = pool->name_ref_at(index); |
coleenp@2497 | 377 | Symbol* method_signature = pool->signature_ref_at(index); |
duke@435 | 378 | KlassHandle current_klass(THREAD, pool->pool_holder()); |
duke@435 | 379 | |
jrose@2982 | 380 | if (pool->has_preresolution() |
jrose@2982 | 381 | || (resolved_klass() == SystemDictionary::MethodHandle_klass() && |
twisti@3969 | 382 | MethodHandles::is_signature_polymorphic_name(resolved_klass(), method_name))) { |
coleenp@4037 | 383 | Method* result_oop = ConstantPool::method_at_if_loaded(pool, index); |
jrose@2982 | 384 | if (result_oop != NULL) { |
jrose@2982 | 385 | resolved_method = methodHandle(THREAD, result_oop); |
jrose@2982 | 386 | return; |
jrose@2982 | 387 | } |
jrose@2982 | 388 | } |
jrose@2982 | 389 | |
twisti@3969 | 390 | if (code == Bytecodes::_invokeinterface) { |
twisti@3969 | 391 | resolve_interface_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, true, CHECK); |
twisti@3969 | 392 | } else { |
twisti@3969 | 393 | resolve_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, true, CHECK); |
twisti@3969 | 394 | } |
duke@435 | 395 | } |
duke@435 | 396 | |
duke@435 | 397 | void LinkResolver::resolve_method(methodHandle& resolved_method, KlassHandle resolved_klass, |
coleenp@2497 | 398 | Symbol* method_name, Symbol* method_signature, |
duke@435 | 399 | KlassHandle current_klass, bool check_access, TRAPS) { |
duke@435 | 400 | |
twisti@3969 | 401 | Handle nested_exception; |
twisti@3969 | 402 | |
kamg@4245 | 403 | // 1. lookup method in resolved klass and its super klasses |
duke@435 | 404 | lookup_method_in_klasses(resolved_method, resolved_klass, method_name, method_signature, CHECK); |
duke@435 | 405 | |
duke@435 | 406 | if (resolved_method.is_null()) { // not found in the class hierarchy |
kamg@4245 | 407 | // 2. lookup method in all the interfaces implemented by the resolved klass |
duke@435 | 408 | lookup_method_in_interfaces(resolved_method, resolved_klass, method_name, method_signature, CHECK); |
duke@435 | 409 | |
duke@435 | 410 | if (resolved_method.is_null()) { |
twisti@3969 | 411 | // JSR 292: see if this is an implicitly generated method MethodHandle.linkToVirtual(*...), etc |
twisti@3969 | 412 | lookup_polymorphic_method(resolved_method, resolved_klass, method_name, method_signature, |
twisti@4133 | 413 | current_klass, (Handle*)NULL, (Handle*)NULL, THREAD); |
twisti@3969 | 414 | if (HAS_PENDING_EXCEPTION) { |
twisti@3969 | 415 | nested_exception = Handle(THREAD, PENDING_EXCEPTION); |
twisti@3969 | 416 | CLEAR_PENDING_EXCEPTION; |
twisti@3969 | 417 | } |
jrose@1145 | 418 | } |
jrose@1145 | 419 | |
jrose@1145 | 420 | if (resolved_method.is_null()) { |
kamg@4245 | 421 | // 3. method lookup failed |
duke@435 | 422 | ResourceMark rm(THREAD); |
twisti@3969 | 423 | THROW_MSG_CAUSE(vmSymbols::java_lang_NoSuchMethodError(), |
hseigel@4278 | 424 | Method::name_and_sig_as_C_string(resolved_klass(), |
twisti@3969 | 425 | method_name, |
twisti@3969 | 426 | method_signature), |
twisti@3969 | 427 | nested_exception); |
duke@435 | 428 | } |
duke@435 | 429 | } |
duke@435 | 430 | |
kamg@4245 | 431 | // 4. check if klass is not interface |
kamg@4245 | 432 | if (resolved_klass->is_interface() && resolved_method->is_abstract()) { |
kamg@4245 | 433 | ResourceMark rm(THREAD); |
kamg@4245 | 434 | char buf[200]; |
kamg@4245 | 435 | jio_snprintf(buf, sizeof(buf), "Found interface %s, but class was expected", |
kamg@4245 | 436 | resolved_klass()->external_name()); |
kamg@4245 | 437 | THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf); |
kamg@4245 | 438 | } |
kamg@4245 | 439 | |
duke@435 | 440 | // 5. check if method is concrete |
duke@435 | 441 | if (resolved_method->is_abstract() && !resolved_klass->is_abstract()) { |
duke@435 | 442 | ResourceMark rm(THREAD); |
duke@435 | 443 | THROW_MSG(vmSymbols::java_lang_AbstractMethodError(), |
hseigel@4278 | 444 | Method::name_and_sig_as_C_string(resolved_klass(), |
coleenp@2497 | 445 | method_name, |
coleenp@2497 | 446 | method_signature)); |
duke@435 | 447 | } |
duke@435 | 448 | |
duke@435 | 449 | // 6. access checks, access checking may be turned off when calling from within the VM. |
duke@435 | 450 | if (check_access) { |
duke@435 | 451 | assert(current_klass.not_null() , "current_klass should not be null"); |
duke@435 | 452 | |
duke@435 | 453 | // check if method can be accessed by the referring class |
duke@435 | 454 | check_method_accessability(current_klass, |
duke@435 | 455 | resolved_klass, |
duke@435 | 456 | KlassHandle(THREAD, resolved_method->method_holder()), |
duke@435 | 457 | resolved_method, |
duke@435 | 458 | CHECK); |
duke@435 | 459 | |
duke@435 | 460 | // check loader constraints |
coleenp@4037 | 461 | Handle loader (THREAD, InstanceKlass::cast(current_klass())->class_loader()); |
coleenp@4251 | 462 | Handle class_loader (THREAD, resolved_method->method_holder()->class_loader()); |
duke@435 | 463 | { |
duke@435 | 464 | ResourceMark rm(THREAD); |
acorn@4840 | 465 | Symbol* failed_type_symbol = |
duke@435 | 466 | SystemDictionary::check_signature_loaders(method_signature, loader, |
duke@435 | 467 | class_loader, true, CHECK); |
acorn@4840 | 468 | if (failed_type_symbol != NULL) { |
duke@435 | 469 | const char* msg = "loader constraint violation: when resolving method" |
duke@435 | 470 | " \"%s\" the class loader (instance of %s) of the current class, %s," |
acorn@4840 | 471 | " and the class loader (instance of %s) for the method's defining class, %s, have" |
duke@435 | 472 | " different Class objects for the type %s used in the signature"; |
hseigel@4278 | 473 | char* sig = Method::name_and_sig_as_C_string(resolved_klass(),method_name,method_signature); |
duke@435 | 474 | const char* loader1 = SystemDictionary::loader_name(loader()); |
coleenp@4037 | 475 | char* current = InstanceKlass::cast(current_klass())->name()->as_C_string(); |
duke@435 | 476 | const char* loader2 = SystemDictionary::loader_name(class_loader()); |
acorn@4840 | 477 | char* target = InstanceKlass::cast(resolved_method->method_holder()) |
acorn@4840 | 478 | ->name()->as_C_string(); |
acorn@4840 | 479 | char* failed_type_name = failed_type_symbol->as_C_string(); |
duke@435 | 480 | size_t buflen = strlen(msg) + strlen(sig) + strlen(loader1) + |
acorn@4840 | 481 | strlen(current) + strlen(loader2) + strlen(target) + |
acorn@4840 | 482 | strlen(failed_type_name) + 1; |
duke@435 | 483 | char* buf = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, buflen); |
duke@435 | 484 | jio_snprintf(buf, buflen, msg, sig, loader1, current, loader2, |
acorn@4840 | 485 | target, failed_type_name); |
duke@435 | 486 | THROW_MSG(vmSymbols::java_lang_LinkageError(), buf); |
duke@435 | 487 | } |
duke@435 | 488 | } |
duke@435 | 489 | } |
duke@435 | 490 | } |
duke@435 | 491 | |
duke@435 | 492 | void LinkResolver::resolve_interface_method(methodHandle& resolved_method, |
duke@435 | 493 | KlassHandle resolved_klass, |
coleenp@2497 | 494 | Symbol* method_name, |
coleenp@2497 | 495 | Symbol* method_signature, |
duke@435 | 496 | KlassHandle current_klass, |
duke@435 | 497 | bool check_access, TRAPS) { |
duke@435 | 498 | |
duke@435 | 499 | // check if klass is interface |
duke@435 | 500 | if (!resolved_klass->is_interface()) { |
jcoomes@2856 | 501 | ResourceMark rm(THREAD); |
duke@435 | 502 | char buf[200]; |
hseigel@4278 | 503 | jio_snprintf(buf, sizeof(buf), "Found class %s, but interface was expected", resolved_klass()->external_name()); |
duke@435 | 504 | THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf); |
duke@435 | 505 | } |
duke@435 | 506 | |
duke@435 | 507 | // lookup method in this interface or its super, java.lang.Object |
duke@435 | 508 | lookup_instance_method_in_klasses(resolved_method, resolved_klass, method_name, method_signature, CHECK); |
duke@435 | 509 | |
duke@435 | 510 | if (resolved_method.is_null()) { |
duke@435 | 511 | // lookup method in all the super-interfaces |
duke@435 | 512 | lookup_method_in_interfaces(resolved_method, resolved_klass, method_name, method_signature, CHECK); |
duke@435 | 513 | if (resolved_method.is_null()) { |
duke@435 | 514 | // no method found |
duke@435 | 515 | ResourceMark rm(THREAD); |
duke@435 | 516 | THROW_MSG(vmSymbols::java_lang_NoSuchMethodError(), |
hseigel@4278 | 517 | Method::name_and_sig_as_C_string(resolved_klass(), |
coleenp@2497 | 518 | method_name, |
coleenp@2497 | 519 | method_signature)); |
duke@435 | 520 | } |
duke@435 | 521 | } |
duke@435 | 522 | |
duke@435 | 523 | if (check_access) { |
duke@435 | 524 | HandleMark hm(THREAD); |
coleenp@4037 | 525 | Handle loader (THREAD, InstanceKlass::cast(current_klass())->class_loader()); |
coleenp@4251 | 526 | Handle class_loader (THREAD, resolved_method->method_holder()->class_loader()); |
duke@435 | 527 | { |
duke@435 | 528 | ResourceMark rm(THREAD); |
acorn@4840 | 529 | Symbol* failed_type_symbol = |
duke@435 | 530 | SystemDictionary::check_signature_loaders(method_signature, loader, |
duke@435 | 531 | class_loader, true, CHECK); |
acorn@4840 | 532 | if (failed_type_symbol != NULL) { |
duke@435 | 533 | const char* msg = "loader constraint violation: when resolving " |
duke@435 | 534 | "interface method \"%s\" the class loader (instance of %s) of the " |
duke@435 | 535 | "current class, %s, and the class loader (instance of %s) for " |
acorn@4840 | 536 | "the method's defining class, %s, have different Class objects for the type %s " |
duke@435 | 537 | "used in the signature"; |
hseigel@4278 | 538 | char* sig = Method::name_and_sig_as_C_string(resolved_klass(),method_name,method_signature); |
duke@435 | 539 | const char* loader1 = SystemDictionary::loader_name(loader()); |
coleenp@4037 | 540 | char* current = InstanceKlass::cast(current_klass())->name()->as_C_string(); |
duke@435 | 541 | const char* loader2 = SystemDictionary::loader_name(class_loader()); |
acorn@4840 | 542 | char* target = InstanceKlass::cast(resolved_method->method_holder()) |
acorn@4840 | 543 | ->name()->as_C_string(); |
acorn@4840 | 544 | char* failed_type_name = failed_type_symbol->as_C_string(); |
duke@435 | 545 | size_t buflen = strlen(msg) + strlen(sig) + strlen(loader1) + |
acorn@4840 | 546 | strlen(current) + strlen(loader2) + strlen(target) + |
acorn@4840 | 547 | strlen(failed_type_name) + 1; |
duke@435 | 548 | char* buf = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, buflen); |
duke@435 | 549 | jio_snprintf(buf, buflen, msg, sig, loader1, current, loader2, |
acorn@4840 | 550 | target, failed_type_name); |
duke@435 | 551 | THROW_MSG(vmSymbols::java_lang_LinkageError(), buf); |
duke@435 | 552 | } |
duke@435 | 553 | } |
duke@435 | 554 | } |
duke@435 | 555 | } |
duke@435 | 556 | |
duke@435 | 557 | //------------------------------------------------------------------------------------------------------------------------ |
duke@435 | 558 | // Field resolution |
duke@435 | 559 | |
duke@435 | 560 | void LinkResolver::check_field_accessability(KlassHandle ref_klass, |
duke@435 | 561 | KlassHandle resolved_klass, |
duke@435 | 562 | KlassHandle sel_klass, |
duke@435 | 563 | fieldDescriptor& fd, |
duke@435 | 564 | TRAPS) { |
coleenp@4037 | 565 | if (!Reflection::verify_field_access(ref_klass(), |
coleenp@4037 | 566 | resolved_klass(), |
coleenp@4037 | 567 | sel_klass(), |
duke@435 | 568 | fd.access_flags(), |
duke@435 | 569 | true)) { |
duke@435 | 570 | ResourceMark rm(THREAD); |
duke@435 | 571 | Exceptions::fthrow( |
duke@435 | 572 | THREAD_AND_LOCATION, |
coleenp@2497 | 573 | vmSymbols::java_lang_IllegalAccessError(), |
duke@435 | 574 | "tried to access field %s.%s from class %s", |
duke@435 | 575 | sel_klass->external_name(), |
duke@435 | 576 | fd.name()->as_C_string(), |
duke@435 | 577 | ref_klass->external_name() |
duke@435 | 578 | ); |
duke@435 | 579 | return; |
duke@435 | 580 | } |
duke@435 | 581 | } |
duke@435 | 582 | |
duke@435 | 583 | void LinkResolver::resolve_field(FieldAccessInfo& result, constantPoolHandle pool, int index, Bytecodes::Code byte, bool check_only, TRAPS) { |
duke@435 | 584 | resolve_field(result, pool, index, byte, check_only, true, CHECK); |
duke@435 | 585 | } |
duke@435 | 586 | |
duke@435 | 587 | void LinkResolver::resolve_field(FieldAccessInfo& result, constantPoolHandle pool, int index, Bytecodes::Code byte, bool check_only, bool update_pool, TRAPS) { |
duke@435 | 588 | assert(byte == Bytecodes::_getstatic || byte == Bytecodes::_putstatic || |
duke@435 | 589 | byte == Bytecodes::_getfield || byte == Bytecodes::_putfield, "bad bytecode"); |
duke@435 | 590 | |
duke@435 | 591 | bool is_static = (byte == Bytecodes::_getstatic || byte == Bytecodes::_putstatic); |
duke@435 | 592 | bool is_put = (byte == Bytecodes::_putfield || byte == Bytecodes::_putstatic); |
duke@435 | 593 | |
duke@435 | 594 | // resolve specified klass |
duke@435 | 595 | KlassHandle resolved_klass; |
duke@435 | 596 | if (update_pool) { |
duke@435 | 597 | resolve_klass(resolved_klass, pool, index, CHECK); |
duke@435 | 598 | } else { |
duke@435 | 599 | resolve_klass_no_update(resolved_klass, pool, index, CHECK); |
duke@435 | 600 | } |
duke@435 | 601 | // Load these early in case the resolve of the containing klass fails |
coleenp@2497 | 602 | Symbol* field = pool->name_ref_at(index); |
coleenp@2497 | 603 | Symbol* sig = pool->signature_ref_at(index); |
duke@435 | 604 | // Check if there's a resolved klass containing the field |
duke@435 | 605 | if( resolved_klass.is_null() ) { |
duke@435 | 606 | ResourceMark rm(THREAD); |
duke@435 | 607 | THROW_MSG(vmSymbols::java_lang_NoSuchFieldError(), field->as_C_string()); |
duke@435 | 608 | } |
duke@435 | 609 | |
duke@435 | 610 | // Resolve instance field |
duke@435 | 611 | fieldDescriptor fd; // find_field initializes fd if found |
coleenp@4037 | 612 | KlassHandle sel_klass(THREAD, InstanceKlass::cast(resolved_klass())->find_field(field, sig, &fd)); |
duke@435 | 613 | // check if field exists; i.e., if a klass containing the field def has been selected |
duke@435 | 614 | if (sel_klass.is_null()){ |
duke@435 | 615 | ResourceMark rm(THREAD); |
duke@435 | 616 | THROW_MSG(vmSymbols::java_lang_NoSuchFieldError(), field->as_C_string()); |
duke@435 | 617 | } |
duke@435 | 618 | |
duke@435 | 619 | // check access |
duke@435 | 620 | KlassHandle ref_klass(THREAD, pool->pool_holder()); |
duke@435 | 621 | check_field_accessability(ref_klass, resolved_klass, sel_klass, fd, CHECK); |
duke@435 | 622 | |
duke@435 | 623 | // check for errors |
duke@435 | 624 | if (is_static != fd.is_static()) { |
jcoomes@2856 | 625 | ResourceMark rm(THREAD); |
duke@435 | 626 | char msg[200]; |
hseigel@4278 | 627 | jio_snprintf(msg, sizeof(msg), "Expected %s field %s.%s", is_static ? "static" : "non-static", resolved_klass()->external_name(), fd.name()->as_C_string()); |
duke@435 | 628 | THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), msg); |
duke@435 | 629 | } |
duke@435 | 630 | |
duke@435 | 631 | // Final fields can only be accessed from its own class. |
duke@435 | 632 | if (is_put && fd.access_flags().is_final() && sel_klass() != pool->pool_holder()) { |
duke@435 | 633 | THROW(vmSymbols::java_lang_IllegalAccessError()); |
duke@435 | 634 | } |
duke@435 | 635 | |
duke@435 | 636 | // initialize resolved_klass if necessary |
duke@435 | 637 | // note 1: the klass which declared the field must be initialized (i.e, sel_klass) |
duke@435 | 638 | // according to the newest JVM spec (5.5, p.170) - was bug (gri 7/28/99) |
duke@435 | 639 | // |
duke@435 | 640 | // note 2: we don't want to force initialization if we are just checking |
duke@435 | 641 | // if the field access is legal; e.g., during compilation |
duke@435 | 642 | if (is_static && !check_only) { |
duke@435 | 643 | sel_klass->initialize(CHECK); |
duke@435 | 644 | } |
duke@435 | 645 | |
duke@435 | 646 | { |
duke@435 | 647 | HandleMark hm(THREAD); |
coleenp@4037 | 648 | Handle ref_loader (THREAD, InstanceKlass::cast(ref_klass())->class_loader()); |
coleenp@4037 | 649 | Handle sel_loader (THREAD, InstanceKlass::cast(sel_klass())->class_loader()); |
coleenp@2497 | 650 | Symbol* signature_ref = pool->signature_ref_at(index); |
duke@435 | 651 | { |
duke@435 | 652 | ResourceMark rm(THREAD); |
acorn@4840 | 653 | Symbol* failed_type_symbol = |
duke@435 | 654 | SystemDictionary::check_signature_loaders(signature_ref, |
duke@435 | 655 | ref_loader, sel_loader, |
duke@435 | 656 | false, |
duke@435 | 657 | CHECK); |
acorn@4840 | 658 | if (failed_type_symbol != NULL) { |
duke@435 | 659 | const char* msg = "loader constraint violation: when resolving field" |
duke@435 | 660 | " \"%s\" the class loader (instance of %s) of the referring class, " |
duke@435 | 661 | "%s, and the class loader (instance of %s) for the field's resolved " |
duke@435 | 662 | "type, %s, have different Class objects for that type"; |
coleenp@2497 | 663 | char* field_name = field->as_C_string(); |
duke@435 | 664 | const char* loader1 = SystemDictionary::loader_name(ref_loader()); |
coleenp@4037 | 665 | char* sel = InstanceKlass::cast(sel_klass())->name()->as_C_string(); |
duke@435 | 666 | const char* loader2 = SystemDictionary::loader_name(sel_loader()); |
acorn@4840 | 667 | char* failed_type_name = failed_type_symbol->as_C_string(); |
duke@435 | 668 | size_t buflen = strlen(msg) + strlen(field_name) + strlen(loader1) + |
acorn@4840 | 669 | strlen(sel) + strlen(loader2) + strlen(failed_type_name) + 1; |
duke@435 | 670 | char* buf = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, buflen); |
duke@435 | 671 | jio_snprintf(buf, buflen, msg, field_name, loader1, sel, loader2, |
duke@435 | 672 | failed_type_name); |
duke@435 | 673 | THROW_MSG(vmSymbols::java_lang_LinkageError(), buf); |
duke@435 | 674 | } |
duke@435 | 675 | } |
duke@435 | 676 | } |
duke@435 | 677 | |
duke@435 | 678 | // return information. note that the klass is set to the actual klass containing the |
duke@435 | 679 | // field, otherwise access of static fields in superclasses will not work. |
duke@435 | 680 | KlassHandle holder (THREAD, fd.field_holder()); |
coleenp@2497 | 681 | Symbol* name = fd.name(); |
duke@435 | 682 | result.set(holder, name, fd.index(), fd.offset(), fd.field_type(), fd.access_flags()); |
duke@435 | 683 | } |
duke@435 | 684 | |
duke@435 | 685 | |
duke@435 | 686 | //------------------------------------------------------------------------------------------------------------------------ |
duke@435 | 687 | // Invoke resolution |
duke@435 | 688 | // |
duke@435 | 689 | // Naming conventions: |
duke@435 | 690 | // |
duke@435 | 691 | // resolved_method the specified method (i.e., static receiver specified via constant pool index) |
duke@435 | 692 | // sel_method the selected method (selected via run-time lookup; e.g., based on dynamic receiver class) |
duke@435 | 693 | // resolved_klass the specified klass (i.e., specified via constant pool index) |
duke@435 | 694 | // recv_klass the receiver klass |
duke@435 | 695 | |
duke@435 | 696 | |
coleenp@2497 | 697 | void LinkResolver::resolve_static_call(CallInfo& result, KlassHandle& resolved_klass, Symbol* method_name, |
coleenp@2497 | 698 | Symbol* method_signature, KlassHandle current_klass, |
duke@435 | 699 | bool check_access, bool initialize_class, TRAPS) { |
duke@435 | 700 | methodHandle resolved_method; |
duke@435 | 701 | linktime_resolve_static_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, check_access, CHECK); |
hseigel@4278 | 702 | resolved_klass = KlassHandle(THREAD, resolved_method->method_holder()); |
duke@435 | 703 | |
duke@435 | 704 | // Initialize klass (this should only happen if everything is ok) |
duke@435 | 705 | if (initialize_class && resolved_klass->should_be_initialized()) { |
duke@435 | 706 | resolved_klass->initialize(CHECK); |
duke@435 | 707 | linktime_resolve_static_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, check_access, CHECK); |
duke@435 | 708 | } |
duke@435 | 709 | |
duke@435 | 710 | // setup result |
duke@435 | 711 | result.set_static(resolved_klass, resolved_method, CHECK); |
duke@435 | 712 | } |
duke@435 | 713 | |
duke@435 | 714 | // throws linktime exceptions |
duke@435 | 715 | void LinkResolver::linktime_resolve_static_method(methodHandle& resolved_method, KlassHandle resolved_klass, |
coleenp@2497 | 716 | Symbol* method_name, Symbol* method_signature, |
duke@435 | 717 | KlassHandle current_klass, bool check_access, TRAPS) { |
duke@435 | 718 | |
duke@435 | 719 | resolve_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, check_access, CHECK); |
duke@435 | 720 | assert(resolved_method->name() != vmSymbols::class_initializer_name(), "should have been checked in verifier"); |
duke@435 | 721 | |
duke@435 | 722 | // check if static |
duke@435 | 723 | if (!resolved_method->is_static()) { |
jcoomes@2856 | 724 | ResourceMark rm(THREAD); |
duke@435 | 725 | char buf[200]; |
hseigel@4278 | 726 | jio_snprintf(buf, sizeof(buf), "Expected static method %s", Method::name_and_sig_as_C_string(resolved_klass(), |
duke@435 | 727 | resolved_method->name(), |
duke@435 | 728 | resolved_method->signature())); |
duke@435 | 729 | THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf); |
duke@435 | 730 | } |
duke@435 | 731 | } |
duke@435 | 732 | |
duke@435 | 733 | |
coleenp@2497 | 734 | void LinkResolver::resolve_special_call(CallInfo& result, KlassHandle resolved_klass, Symbol* method_name, |
coleenp@2497 | 735 | Symbol* method_signature, KlassHandle current_klass, bool check_access, TRAPS) { |
duke@435 | 736 | methodHandle resolved_method; |
duke@435 | 737 | linktime_resolve_special_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, check_access, CHECK); |
duke@435 | 738 | runtime_resolve_special_method(result, resolved_method, resolved_klass, current_klass, check_access, CHECK); |
duke@435 | 739 | } |
duke@435 | 740 | |
duke@435 | 741 | // throws linktime exceptions |
duke@435 | 742 | void LinkResolver::linktime_resolve_special_method(methodHandle& resolved_method, KlassHandle resolved_klass, |
coleenp@2497 | 743 | Symbol* method_name, Symbol* method_signature, |
duke@435 | 744 | KlassHandle current_klass, bool check_access, TRAPS) { |
duke@435 | 745 | |
kamg@4245 | 746 | if (resolved_klass->is_interface() && current_klass() != NULL) { |
kamg@4245 | 747 | // If the target class is a direct interface, treat this as a "super" |
kamg@4245 | 748 | // default call. |
kamg@4245 | 749 | // |
kamg@4245 | 750 | // If the current method is an overpass that happens to call a direct |
kamg@4245 | 751 | // super-interface's method, then we'll end up rerunning the default method |
kamg@4245 | 752 | // analysis even though we don't need to, but that's ok since it will end |
kamg@4245 | 753 | // up with the same answer. |
kamg@4245 | 754 | InstanceKlass* ik = InstanceKlass::cast(current_klass()); |
kamg@4245 | 755 | Array<Klass*>* interfaces = ik->local_interfaces(); |
kamg@4245 | 756 | int num_interfaces = interfaces->length(); |
kamg@4245 | 757 | for (int index = 0; index < num_interfaces; index++) { |
kamg@4245 | 758 | if (interfaces->at(index) == resolved_klass()) { |
kamg@4245 | 759 | Method* method = DefaultMethods::find_super_default(current_klass(), |
kamg@4245 | 760 | resolved_klass(), method_name, method_signature, CHECK); |
kamg@4245 | 761 | resolved_method = methodHandle(THREAD, method); |
kamg@4245 | 762 | return; |
kamg@4245 | 763 | } |
kamg@4245 | 764 | } |
kamg@4245 | 765 | } |
kamg@4245 | 766 | |
duke@435 | 767 | resolve_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, check_access, CHECK); |
duke@435 | 768 | |
duke@435 | 769 | // check if method name is <init>, that it is found in same klass as static type |
duke@435 | 770 | if (resolved_method->name() == vmSymbols::object_initializer_name() && |
duke@435 | 771 | resolved_method->method_holder() != resolved_klass()) { |
duke@435 | 772 | ResourceMark rm(THREAD); |
duke@435 | 773 | Exceptions::fthrow( |
duke@435 | 774 | THREAD_AND_LOCATION, |
coleenp@2497 | 775 | vmSymbols::java_lang_NoSuchMethodError(), |
duke@435 | 776 | "%s: method %s%s not found", |
duke@435 | 777 | resolved_klass->external_name(), |
duke@435 | 778 | resolved_method->name()->as_C_string(), |
duke@435 | 779 | resolved_method->signature()->as_C_string() |
duke@435 | 780 | ); |
duke@435 | 781 | return; |
duke@435 | 782 | } |
duke@435 | 783 | |
duke@435 | 784 | // check if not static |
duke@435 | 785 | if (resolved_method->is_static()) { |
jcoomes@2856 | 786 | ResourceMark rm(THREAD); |
duke@435 | 787 | char buf[200]; |
duke@435 | 788 | jio_snprintf(buf, sizeof(buf), |
duke@435 | 789 | "Expecting non-static method %s", |
hseigel@4278 | 790 | Method::name_and_sig_as_C_string(resolved_klass(), |
duke@435 | 791 | resolved_method->name(), |
duke@435 | 792 | resolved_method->signature())); |
duke@435 | 793 | THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf); |
duke@435 | 794 | } |
duke@435 | 795 | } |
duke@435 | 796 | |
duke@435 | 797 | // throws runtime exceptions |
duke@435 | 798 | void LinkResolver::runtime_resolve_special_method(CallInfo& result, methodHandle resolved_method, KlassHandle resolved_klass, |
duke@435 | 799 | KlassHandle current_klass, bool check_access, TRAPS) { |
duke@435 | 800 | |
duke@435 | 801 | // resolved method is selected method unless we have an old-style lookup |
duke@435 | 802 | methodHandle sel_method(THREAD, resolved_method()); |
duke@435 | 803 | |
duke@435 | 804 | // check if this is an old-style super call and do a new lookup if so |
duke@435 | 805 | { KlassHandle method_klass = KlassHandle(THREAD, |
duke@435 | 806 | resolved_method->method_holder()); |
duke@435 | 807 | |
kamg@4245 | 808 | const bool direct_calling_default_method = |
kamg@4245 | 809 | resolved_klass() != NULL && resolved_method() != NULL && |
kamg@4245 | 810 | resolved_klass->is_interface() && !resolved_method->is_abstract(); |
kamg@4245 | 811 | |
kamg@4245 | 812 | if (!direct_calling_default_method && |
kamg@4245 | 813 | check_access && |
duke@435 | 814 | // a) check if ACC_SUPER flag is set for the current class |
kamg@4702 | 815 | (current_klass->is_super() || !AllowNonVirtualCalls) && |
duke@435 | 816 | // b) check if the method class is a superclass of the current class (superclass relation is not reflexive!) |
kamg@4245 | 817 | current_klass->is_subtype_of(method_klass()) && |
kamg@4245 | 818 | current_klass() != method_klass() && |
duke@435 | 819 | // c) check if the method is not <init> |
duke@435 | 820 | resolved_method->name() != vmSymbols::object_initializer_name()) { |
duke@435 | 821 | // Lookup super method |
duke@435 | 822 | KlassHandle super_klass(THREAD, current_klass->super()); |
duke@435 | 823 | lookup_instance_method_in_klasses(sel_method, super_klass, |
coleenp@2497 | 824 | resolved_method->name(), |
coleenp@2497 | 825 | resolved_method->signature(), CHECK); |
duke@435 | 826 | // check if found |
duke@435 | 827 | if (sel_method.is_null()) { |
duke@435 | 828 | ResourceMark rm(THREAD); |
duke@435 | 829 | THROW_MSG(vmSymbols::java_lang_AbstractMethodError(), |
hseigel@4278 | 830 | Method::name_and_sig_as_C_string(resolved_klass(), |
duke@435 | 831 | resolved_method->name(), |
duke@435 | 832 | resolved_method->signature())); |
duke@435 | 833 | } |
duke@435 | 834 | } |
duke@435 | 835 | } |
duke@435 | 836 | |
duke@435 | 837 | // check if not static |
duke@435 | 838 | if (sel_method->is_static()) { |
jcoomes@2856 | 839 | ResourceMark rm(THREAD); |
duke@435 | 840 | char buf[200]; |
hseigel@4278 | 841 | jio_snprintf(buf, sizeof(buf), "Expecting non-static method %s", Method::name_and_sig_as_C_string(resolved_klass(), |
duke@435 | 842 | resolved_method->name(), |
duke@435 | 843 | resolved_method->signature())); |
duke@435 | 844 | THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf); |
duke@435 | 845 | } |
duke@435 | 846 | |
duke@435 | 847 | // check if abstract |
duke@435 | 848 | if (sel_method->is_abstract()) { |
duke@435 | 849 | ResourceMark rm(THREAD); |
duke@435 | 850 | THROW_MSG(vmSymbols::java_lang_AbstractMethodError(), |
hseigel@4278 | 851 | Method::name_and_sig_as_C_string(resolved_klass(), |
duke@435 | 852 | sel_method->name(), |
duke@435 | 853 | sel_method->signature())); |
duke@435 | 854 | } |
duke@435 | 855 | |
duke@435 | 856 | // setup result |
duke@435 | 857 | result.set_static(resolved_klass, sel_method, CHECK); |
duke@435 | 858 | } |
duke@435 | 859 | |
duke@435 | 860 | void LinkResolver::resolve_virtual_call(CallInfo& result, Handle recv, KlassHandle receiver_klass, KlassHandle resolved_klass, |
coleenp@2497 | 861 | Symbol* method_name, Symbol* method_signature, KlassHandle current_klass, |
duke@435 | 862 | bool check_access, bool check_null_and_abstract, TRAPS) { |
duke@435 | 863 | methodHandle resolved_method; |
duke@435 | 864 | linktime_resolve_virtual_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, check_access, CHECK); |
duke@435 | 865 | runtime_resolve_virtual_method(result, resolved_method, resolved_klass, recv, receiver_klass, check_null_and_abstract, CHECK); |
duke@435 | 866 | } |
duke@435 | 867 | |
duke@435 | 868 | // throws linktime exceptions |
duke@435 | 869 | void LinkResolver::linktime_resolve_virtual_method(methodHandle &resolved_method, KlassHandle resolved_klass, |
coleenp@2497 | 870 | Symbol* method_name, Symbol* method_signature, |
duke@435 | 871 | KlassHandle current_klass, bool check_access, TRAPS) { |
duke@435 | 872 | // normal method resolution |
duke@435 | 873 | resolve_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, check_access, CHECK); |
duke@435 | 874 | |
duke@435 | 875 | assert(resolved_method->name() != vmSymbols::object_initializer_name(), "should have been checked in verifier"); |
duke@435 | 876 | assert(resolved_method->name() != vmSymbols::class_initializer_name (), "should have been checked in verifier"); |
duke@435 | 877 | |
duke@435 | 878 | // check if not static |
duke@435 | 879 | if (resolved_method->is_static()) { |
jcoomes@2856 | 880 | ResourceMark rm(THREAD); |
duke@435 | 881 | char buf[200]; |
hseigel@4278 | 882 | jio_snprintf(buf, sizeof(buf), "Expecting non-static method %s", Method::name_and_sig_as_C_string(resolved_klass(), |
duke@435 | 883 | resolved_method->name(), |
duke@435 | 884 | resolved_method->signature())); |
duke@435 | 885 | THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf); |
duke@435 | 886 | } |
duke@435 | 887 | } |
duke@435 | 888 | |
duke@435 | 889 | // throws runtime exceptions |
duke@435 | 890 | void LinkResolver::runtime_resolve_virtual_method(CallInfo& result, |
duke@435 | 891 | methodHandle resolved_method, |
duke@435 | 892 | KlassHandle resolved_klass, |
duke@435 | 893 | Handle recv, |
duke@435 | 894 | KlassHandle recv_klass, |
duke@435 | 895 | bool check_null_and_abstract, |
duke@435 | 896 | TRAPS) { |
duke@435 | 897 | |
duke@435 | 898 | // setup default return values |
coleenp@4037 | 899 | int vtable_index = Method::invalid_vtable_index; |
duke@435 | 900 | methodHandle selected_method; |
duke@435 | 901 | |
duke@435 | 902 | assert(recv.is_null() || recv->is_oop(), "receiver is not an oop"); |
duke@435 | 903 | |
duke@435 | 904 | // runtime method resolution |
duke@435 | 905 | if (check_null_and_abstract && recv.is_null()) { // check if receiver exists |
duke@435 | 906 | THROW(vmSymbols::java_lang_NullPointerException()); |
duke@435 | 907 | } |
duke@435 | 908 | |
coleenp@4037 | 909 | // Virtual methods cannot be resolved before its klass has been linked, for otherwise the Method*'s |
duke@435 | 910 | // has not been rewritten, and the vtable initialized. |
coleenp@4251 | 911 | assert(resolved_method->method_holder()->is_linked(), "must be linked"); |
duke@435 | 912 | |
coleenp@4037 | 913 | // Virtual methods cannot be resolved before its klass has been linked, for otherwise the Method*'s |
duke@435 | 914 | // has not been rewritten, and the vtable initialized. Make sure to do this after the nullcheck, since |
duke@435 | 915 | // a missing receiver might result in a bogus lookup. |
coleenp@4251 | 916 | assert(resolved_method->method_holder()->is_linked(), "must be linked"); |
duke@435 | 917 | |
duke@435 | 918 | // do lookup based on receiver klass using the vtable index |
coleenp@4037 | 919 | if (resolved_method->method_holder()->is_interface()) { // miranda method |
duke@435 | 920 | vtable_index = vtable_index_of_miranda_method(resolved_klass, |
coleenp@2497 | 921 | resolved_method->name(), |
coleenp@2497 | 922 | resolved_method->signature(), CHECK); |
duke@435 | 923 | assert(vtable_index >= 0 , "we should have valid vtable index at this point"); |
duke@435 | 924 | |
coleenp@4037 | 925 | InstanceKlass* inst = InstanceKlass::cast(recv_klass()); |
duke@435 | 926 | selected_method = methodHandle(THREAD, inst->method_at_vtable(vtable_index)); |
duke@435 | 927 | } else { |
duke@435 | 928 | // at this point we are sure that resolved_method is virtual and not |
duke@435 | 929 | // a miranda method; therefore, it must have a valid vtable index. |
duke@435 | 930 | vtable_index = resolved_method->vtable_index(); |
duke@435 | 931 | // We could get a negative vtable_index for final methods, |
duke@435 | 932 | // because as an optimization they are they are never put in the vtable, |
duke@435 | 933 | // unless they override an existing method. |
duke@435 | 934 | // If we do get a negative, it means the resolved method is the the selected |
duke@435 | 935 | // method, and it can never be changed by an override. |
coleenp@4037 | 936 | if (vtable_index == Method::nonvirtual_vtable_index) { |
duke@435 | 937 | assert(resolved_method->can_be_statically_bound(), "cannot override this method"); |
duke@435 | 938 | selected_method = resolved_method; |
duke@435 | 939 | } else { |
duke@435 | 940 | // recv_klass might be an arrayKlassOop but all vtables start at |
duke@435 | 941 | // the same place. The cast is to avoid virtual call and assertion. |
coleenp@4037 | 942 | InstanceKlass* inst = (InstanceKlass*)recv_klass(); |
duke@435 | 943 | selected_method = methodHandle(THREAD, inst->method_at_vtable(vtable_index)); |
duke@435 | 944 | } |
duke@435 | 945 | } |
duke@435 | 946 | |
duke@435 | 947 | // check if method exists |
duke@435 | 948 | if (selected_method.is_null()) { |
duke@435 | 949 | ResourceMark rm(THREAD); |
duke@435 | 950 | THROW_MSG(vmSymbols::java_lang_AbstractMethodError(), |
hseigel@4278 | 951 | Method::name_and_sig_as_C_string(resolved_klass(), |
duke@435 | 952 | resolved_method->name(), |
duke@435 | 953 | resolved_method->signature())); |
duke@435 | 954 | } |
duke@435 | 955 | |
duke@435 | 956 | // check if abstract |
duke@435 | 957 | if (check_null_and_abstract && selected_method->is_abstract()) { |
duke@435 | 958 | ResourceMark rm(THREAD); |
duke@435 | 959 | THROW_MSG(vmSymbols::java_lang_AbstractMethodError(), |
hseigel@4278 | 960 | Method::name_and_sig_as_C_string(resolved_klass(), |
duke@435 | 961 | selected_method->name(), |
duke@435 | 962 | selected_method->signature())); |
duke@435 | 963 | } |
duke@435 | 964 | |
duke@435 | 965 | // setup result |
duke@435 | 966 | result.set_virtual(resolved_klass, recv_klass, resolved_method, selected_method, vtable_index, CHECK); |
duke@435 | 967 | } |
duke@435 | 968 | |
duke@435 | 969 | void LinkResolver::resolve_interface_call(CallInfo& result, Handle recv, KlassHandle recv_klass, KlassHandle resolved_klass, |
coleenp@2497 | 970 | Symbol* method_name, Symbol* method_signature, KlassHandle current_klass, |
duke@435 | 971 | bool check_access, bool check_null_and_abstract, TRAPS) { |
duke@435 | 972 | methodHandle resolved_method; |
duke@435 | 973 | linktime_resolve_interface_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, check_access, CHECK); |
duke@435 | 974 | runtime_resolve_interface_method(result, resolved_method, resolved_klass, recv, recv_klass, check_null_and_abstract, CHECK); |
duke@435 | 975 | } |
duke@435 | 976 | |
duke@435 | 977 | // throws linktime exceptions |
coleenp@2497 | 978 | void LinkResolver::linktime_resolve_interface_method(methodHandle& resolved_method, KlassHandle resolved_klass, Symbol* method_name, |
coleenp@2497 | 979 | Symbol* method_signature, KlassHandle current_klass, bool check_access, TRAPS) { |
duke@435 | 980 | // normal interface method resolution |
duke@435 | 981 | resolve_interface_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, check_access, CHECK); |
duke@435 | 982 | |
duke@435 | 983 | assert(resolved_method->name() != vmSymbols::object_initializer_name(), "should have been checked in verifier"); |
duke@435 | 984 | assert(resolved_method->name() != vmSymbols::class_initializer_name (), "should have been checked in verifier"); |
duke@435 | 985 | } |
duke@435 | 986 | |
duke@435 | 987 | // throws runtime exceptions |
duke@435 | 988 | void LinkResolver::runtime_resolve_interface_method(CallInfo& result, methodHandle resolved_method, KlassHandle resolved_klass, |
duke@435 | 989 | Handle recv, KlassHandle recv_klass, bool check_null_and_abstract, TRAPS) { |
duke@435 | 990 | // check if receiver exists |
duke@435 | 991 | if (check_null_and_abstract && recv.is_null()) { |
duke@435 | 992 | THROW(vmSymbols::java_lang_NullPointerException()); |
duke@435 | 993 | } |
duke@435 | 994 | |
duke@435 | 995 | // check if receiver klass implements the resolved interface |
duke@435 | 996 | if (!recv_klass->is_subtype_of(resolved_klass())) { |
jcoomes@2856 | 997 | ResourceMark rm(THREAD); |
duke@435 | 998 | char buf[200]; |
duke@435 | 999 | jio_snprintf(buf, sizeof(buf), "Class %s does not implement the requested interface %s", |
hseigel@4278 | 1000 | recv_klass()->external_name(), |
hseigel@4278 | 1001 | resolved_klass()->external_name()); |
duke@435 | 1002 | THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf); |
duke@435 | 1003 | } |
duke@435 | 1004 | // do lookup based on receiver klass |
duke@435 | 1005 | methodHandle sel_method; |
duke@435 | 1006 | lookup_instance_method_in_klasses(sel_method, recv_klass, |
coleenp@2497 | 1007 | resolved_method->name(), |
coleenp@2497 | 1008 | resolved_method->signature(), CHECK); |
duke@435 | 1009 | // check if method exists |
duke@435 | 1010 | if (sel_method.is_null()) { |
duke@435 | 1011 | ResourceMark rm(THREAD); |
duke@435 | 1012 | THROW_MSG(vmSymbols::java_lang_AbstractMethodError(), |
hseigel@4278 | 1013 | Method::name_and_sig_as_C_string(recv_klass(), |
duke@435 | 1014 | resolved_method->name(), |
duke@435 | 1015 | resolved_method->signature())); |
duke@435 | 1016 | } |
bharadwaj@4960 | 1017 | // check access |
bharadwaj@4960 | 1018 | if (sel_method->method_holder()->is_interface()) { |
bharadwaj@4960 | 1019 | // Method holder is an interface. Throw Illegal Access Error if sel_method |
bharadwaj@4960 | 1020 | // is neither public nor private. |
bharadwaj@4960 | 1021 | if (!(sel_method->is_public() || sel_method->is_private())) { |
bharadwaj@4960 | 1022 | ResourceMark rm(THREAD); |
bharadwaj@4960 | 1023 | THROW_MSG(vmSymbols::java_lang_IllegalAccessError(), |
bharadwaj@4960 | 1024 | Method::name_and_sig_as_C_string(recv_klass(), |
bharadwaj@4960 | 1025 | sel_method->name(), |
bharadwaj@4960 | 1026 | sel_method->signature())); |
bharadwaj@4960 | 1027 | } |
bharadwaj@4960 | 1028 | } |
bharadwaj@4960 | 1029 | else { |
bharadwaj@4960 | 1030 | // Method holder is a class. Throw Illegal Access Error if sel_method |
bharadwaj@4960 | 1031 | // is not public. |
bharadwaj@4960 | 1032 | if (!sel_method->is_public()) { |
bharadwaj@4960 | 1033 | ResourceMark rm(THREAD); |
bharadwaj@4960 | 1034 | THROW_MSG(vmSymbols::java_lang_IllegalAccessError(), |
bharadwaj@4960 | 1035 | Method::name_and_sig_as_C_string(recv_klass(), |
bharadwaj@4960 | 1036 | sel_method->name(), |
bharadwaj@4960 | 1037 | sel_method->signature())); |
bharadwaj@4960 | 1038 | } |
duke@435 | 1039 | } |
duke@435 | 1040 | // check if abstract |
duke@435 | 1041 | if (check_null_and_abstract && sel_method->is_abstract()) { |
duke@435 | 1042 | ResourceMark rm(THREAD); |
duke@435 | 1043 | THROW_MSG(vmSymbols::java_lang_AbstractMethodError(), |
hseigel@4278 | 1044 | Method::name_and_sig_as_C_string(recv_klass(), |
duke@435 | 1045 | sel_method->name(), |
duke@435 | 1046 | sel_method->signature())); |
duke@435 | 1047 | } |
duke@435 | 1048 | // setup result |
duke@435 | 1049 | result.set_interface(resolved_klass, recv_klass, resolved_method, sel_method, CHECK); |
duke@435 | 1050 | } |
duke@435 | 1051 | |
duke@435 | 1052 | |
duke@435 | 1053 | methodHandle LinkResolver::linktime_resolve_interface_method_or_null( |
duke@435 | 1054 | KlassHandle resolved_klass, |
coleenp@2497 | 1055 | Symbol* method_name, |
coleenp@2497 | 1056 | Symbol* method_signature, |
duke@435 | 1057 | KlassHandle current_klass, |
duke@435 | 1058 | bool check_access) { |
duke@435 | 1059 | EXCEPTION_MARK; |
duke@435 | 1060 | methodHandle method_result; |
duke@435 | 1061 | linktime_resolve_interface_method(method_result, resolved_klass, method_name, method_signature, current_klass, check_access, THREAD); |
duke@435 | 1062 | if (HAS_PENDING_EXCEPTION) { |
duke@435 | 1063 | CLEAR_PENDING_EXCEPTION; |
duke@435 | 1064 | return methodHandle(); |
duke@435 | 1065 | } else { |
duke@435 | 1066 | return method_result; |
duke@435 | 1067 | } |
duke@435 | 1068 | } |
duke@435 | 1069 | |
duke@435 | 1070 | methodHandle LinkResolver::linktime_resolve_virtual_method_or_null( |
duke@435 | 1071 | KlassHandle resolved_klass, |
coleenp@2497 | 1072 | Symbol* method_name, |
coleenp@2497 | 1073 | Symbol* method_signature, |
duke@435 | 1074 | KlassHandle current_klass, |
duke@435 | 1075 | bool check_access) { |
duke@435 | 1076 | EXCEPTION_MARK; |
duke@435 | 1077 | methodHandle method_result; |
duke@435 | 1078 | linktime_resolve_virtual_method(method_result, resolved_klass, method_name, method_signature, current_klass, check_access, THREAD); |
duke@435 | 1079 | if (HAS_PENDING_EXCEPTION) { |
duke@435 | 1080 | CLEAR_PENDING_EXCEPTION; |
duke@435 | 1081 | return methodHandle(); |
duke@435 | 1082 | } else { |
duke@435 | 1083 | return method_result; |
duke@435 | 1084 | } |
duke@435 | 1085 | } |
duke@435 | 1086 | |
duke@435 | 1087 | methodHandle LinkResolver::resolve_virtual_call_or_null( |
duke@435 | 1088 | KlassHandle receiver_klass, |
duke@435 | 1089 | KlassHandle resolved_klass, |
coleenp@2497 | 1090 | Symbol* name, |
coleenp@2497 | 1091 | Symbol* signature, |
duke@435 | 1092 | KlassHandle current_klass) { |
duke@435 | 1093 | EXCEPTION_MARK; |
duke@435 | 1094 | CallInfo info; |
duke@435 | 1095 | resolve_virtual_call(info, Handle(), receiver_klass, resolved_klass, name, signature, current_klass, true, false, THREAD); |
duke@435 | 1096 | if (HAS_PENDING_EXCEPTION) { |
duke@435 | 1097 | CLEAR_PENDING_EXCEPTION; |
duke@435 | 1098 | return methodHandle(); |
duke@435 | 1099 | } |
duke@435 | 1100 | return info.selected_method(); |
duke@435 | 1101 | } |
duke@435 | 1102 | |
duke@435 | 1103 | methodHandle LinkResolver::resolve_interface_call_or_null( |
duke@435 | 1104 | KlassHandle receiver_klass, |
duke@435 | 1105 | KlassHandle resolved_klass, |
coleenp@2497 | 1106 | Symbol* name, |
coleenp@2497 | 1107 | Symbol* signature, |
duke@435 | 1108 | KlassHandle current_klass) { |
duke@435 | 1109 | EXCEPTION_MARK; |
duke@435 | 1110 | CallInfo info; |
duke@435 | 1111 | resolve_interface_call(info, Handle(), receiver_klass, resolved_klass, name, signature, current_klass, true, false, THREAD); |
duke@435 | 1112 | if (HAS_PENDING_EXCEPTION) { |
duke@435 | 1113 | CLEAR_PENDING_EXCEPTION; |
duke@435 | 1114 | return methodHandle(); |
duke@435 | 1115 | } |
duke@435 | 1116 | return info.selected_method(); |
duke@435 | 1117 | } |
duke@435 | 1118 | |
duke@435 | 1119 | int LinkResolver::resolve_virtual_vtable_index( |
duke@435 | 1120 | KlassHandle receiver_klass, |
duke@435 | 1121 | KlassHandle resolved_klass, |
coleenp@2497 | 1122 | Symbol* name, |
coleenp@2497 | 1123 | Symbol* signature, |
duke@435 | 1124 | KlassHandle current_klass) { |
duke@435 | 1125 | EXCEPTION_MARK; |
duke@435 | 1126 | CallInfo info; |
duke@435 | 1127 | resolve_virtual_call(info, Handle(), receiver_klass, resolved_klass, name, signature, current_klass, true, false, THREAD); |
duke@435 | 1128 | if (HAS_PENDING_EXCEPTION) { |
duke@435 | 1129 | CLEAR_PENDING_EXCEPTION; |
coleenp@4037 | 1130 | return Method::invalid_vtable_index; |
duke@435 | 1131 | } |
duke@435 | 1132 | return info.vtable_index(); |
duke@435 | 1133 | } |
duke@435 | 1134 | |
duke@435 | 1135 | methodHandle LinkResolver::resolve_static_call_or_null( |
duke@435 | 1136 | KlassHandle resolved_klass, |
coleenp@2497 | 1137 | Symbol* name, |
coleenp@2497 | 1138 | Symbol* signature, |
duke@435 | 1139 | KlassHandle current_klass) { |
duke@435 | 1140 | EXCEPTION_MARK; |
duke@435 | 1141 | CallInfo info; |
duke@435 | 1142 | resolve_static_call(info, resolved_klass, name, signature, current_klass, true, false, THREAD); |
duke@435 | 1143 | if (HAS_PENDING_EXCEPTION) { |
duke@435 | 1144 | CLEAR_PENDING_EXCEPTION; |
duke@435 | 1145 | return methodHandle(); |
duke@435 | 1146 | } |
duke@435 | 1147 | return info.selected_method(); |
duke@435 | 1148 | } |
duke@435 | 1149 | |
coleenp@2497 | 1150 | methodHandle LinkResolver::resolve_special_call_or_null(KlassHandle resolved_klass, Symbol* name, Symbol* signature, |
duke@435 | 1151 | KlassHandle current_klass) { |
duke@435 | 1152 | EXCEPTION_MARK; |
duke@435 | 1153 | CallInfo info; |
duke@435 | 1154 | resolve_special_call(info, resolved_klass, name, signature, current_klass, true, THREAD); |
duke@435 | 1155 | if (HAS_PENDING_EXCEPTION) { |
duke@435 | 1156 | CLEAR_PENDING_EXCEPTION; |
duke@435 | 1157 | return methodHandle(); |
duke@435 | 1158 | } |
duke@435 | 1159 | return info.selected_method(); |
duke@435 | 1160 | } |
duke@435 | 1161 | |
duke@435 | 1162 | |
duke@435 | 1163 | |
duke@435 | 1164 | //------------------------------------------------------------------------------------------------------------------------ |
duke@435 | 1165 | // ConstantPool entries |
duke@435 | 1166 | |
duke@435 | 1167 | void LinkResolver::resolve_invoke(CallInfo& result, Handle recv, constantPoolHandle pool, int index, Bytecodes::Code byte, TRAPS) { |
duke@435 | 1168 | switch (byte) { |
duke@435 | 1169 | case Bytecodes::_invokestatic : resolve_invokestatic (result, pool, index, CHECK); break; |
duke@435 | 1170 | case Bytecodes::_invokespecial : resolve_invokespecial (result, pool, index, CHECK); break; |
duke@435 | 1171 | case Bytecodes::_invokevirtual : resolve_invokevirtual (result, recv, pool, index, CHECK); break; |
twisti@3969 | 1172 | case Bytecodes::_invokehandle : resolve_invokehandle (result, pool, index, CHECK); break; |
jrose@1161 | 1173 | case Bytecodes::_invokedynamic : resolve_invokedynamic (result, pool, index, CHECK); break; |
duke@435 | 1174 | case Bytecodes::_invokeinterface: resolve_invokeinterface(result, recv, pool, index, CHECK); break; |
duke@435 | 1175 | } |
duke@435 | 1176 | return; |
duke@435 | 1177 | } |
duke@435 | 1178 | |
coleenp@2497 | 1179 | void LinkResolver::resolve_pool(KlassHandle& resolved_klass, Symbol*& method_name, Symbol*& method_signature, |
duke@435 | 1180 | KlassHandle& current_klass, constantPoolHandle pool, int index, TRAPS) { |
duke@435 | 1181 | // resolve klass |
duke@435 | 1182 | resolve_klass(resolved_klass, pool, index, CHECK); |
duke@435 | 1183 | |
duke@435 | 1184 | // Get name, signature, and static klass |
coleenp@2497 | 1185 | method_name = pool->name_ref_at(index); |
coleenp@2497 | 1186 | method_signature = pool->signature_ref_at(index); |
duke@435 | 1187 | current_klass = KlassHandle(THREAD, pool->pool_holder()); |
duke@435 | 1188 | } |
duke@435 | 1189 | |
duke@435 | 1190 | |
duke@435 | 1191 | void LinkResolver::resolve_invokestatic(CallInfo& result, constantPoolHandle pool, int index, TRAPS) { |
duke@435 | 1192 | KlassHandle resolved_klass; |
coleenp@2497 | 1193 | Symbol* method_name = NULL; |
coleenp@2497 | 1194 | Symbol* method_signature = NULL; |
duke@435 | 1195 | KlassHandle current_klass; |
duke@435 | 1196 | resolve_pool(resolved_klass, method_name, method_signature, current_klass, pool, index, CHECK); |
duke@435 | 1197 | resolve_static_call(result, resolved_klass, method_name, method_signature, current_klass, true, true, CHECK); |
duke@435 | 1198 | } |
duke@435 | 1199 | |
duke@435 | 1200 | |
duke@435 | 1201 | void LinkResolver::resolve_invokespecial(CallInfo& result, constantPoolHandle pool, int index, TRAPS) { |
duke@435 | 1202 | KlassHandle resolved_klass; |
coleenp@2497 | 1203 | Symbol* method_name = NULL; |
coleenp@2497 | 1204 | Symbol* method_signature = NULL; |
duke@435 | 1205 | KlassHandle current_klass; |
duke@435 | 1206 | resolve_pool(resolved_klass, method_name, method_signature, current_klass, pool, index, CHECK); |
duke@435 | 1207 | resolve_special_call(result, resolved_klass, method_name, method_signature, current_klass, true, CHECK); |
duke@435 | 1208 | } |
duke@435 | 1209 | |
duke@435 | 1210 | |
duke@435 | 1211 | void LinkResolver::resolve_invokevirtual(CallInfo& result, Handle recv, |
duke@435 | 1212 | constantPoolHandle pool, int index, |
duke@435 | 1213 | TRAPS) { |
duke@435 | 1214 | |
duke@435 | 1215 | KlassHandle resolved_klass; |
coleenp@2497 | 1216 | Symbol* method_name = NULL; |
coleenp@2497 | 1217 | Symbol* method_signature = NULL; |
duke@435 | 1218 | KlassHandle current_klass; |
duke@435 | 1219 | resolve_pool(resolved_klass, method_name, method_signature, current_klass, pool, index, CHECK); |
coleenp@4037 | 1220 | KlassHandle recvrKlass (THREAD, recv.is_null() ? (Klass*)NULL : recv->klass()); |
duke@435 | 1221 | resolve_virtual_call(result, recv, recvrKlass, resolved_klass, method_name, method_signature, current_klass, true, true, CHECK); |
duke@435 | 1222 | } |
duke@435 | 1223 | |
duke@435 | 1224 | |
duke@435 | 1225 | void LinkResolver::resolve_invokeinterface(CallInfo& result, Handle recv, constantPoolHandle pool, int index, TRAPS) { |
duke@435 | 1226 | KlassHandle resolved_klass; |
coleenp@2497 | 1227 | Symbol* method_name = NULL; |
coleenp@2497 | 1228 | Symbol* method_signature = NULL; |
duke@435 | 1229 | KlassHandle current_klass; |
duke@435 | 1230 | resolve_pool(resolved_klass, method_name, method_signature, current_klass, pool, index, CHECK); |
coleenp@4037 | 1231 | KlassHandle recvrKlass (THREAD, recv.is_null() ? (Klass*)NULL : recv->klass()); |
duke@435 | 1232 | resolve_interface_call(result, recv, recvrKlass, resolved_klass, method_name, method_signature, current_klass, true, true, CHECK); |
duke@435 | 1233 | } |
duke@435 | 1234 | |
jrose@1161 | 1235 | |
twisti@3969 | 1236 | void LinkResolver::resolve_invokehandle(CallInfo& result, constantPoolHandle pool, int index, TRAPS) { |
jrose@1161 | 1237 | assert(EnableInvokeDynamic, ""); |
twisti@3969 | 1238 | // This guy is reached from InterpreterRuntime::resolve_invokehandle. |
twisti@3969 | 1239 | KlassHandle resolved_klass; |
twisti@3969 | 1240 | Symbol* method_name = NULL; |
twisti@3969 | 1241 | Symbol* method_signature = NULL; |
twisti@3969 | 1242 | KlassHandle current_klass; |
twisti@3969 | 1243 | resolve_pool(resolved_klass, method_name, method_signature, current_klass, pool, index, CHECK); |
kmo@4910 | 1244 | if (TraceMethodHandles) { |
kmo@4910 | 1245 | ResourceMark rm(THREAD); |
twisti@3969 | 1246 | tty->print_cr("resolve_invokehandle %s %s", method_name->as_C_string(), method_signature->as_C_string()); |
kmo@4910 | 1247 | } |
twisti@3969 | 1248 | resolve_handle_call(result, resolved_klass, method_name, method_signature, current_klass, CHECK); |
twisti@3969 | 1249 | } |
jrose@1161 | 1250 | |
twisti@3969 | 1251 | void LinkResolver::resolve_handle_call(CallInfo& result, KlassHandle resolved_klass, |
twisti@3969 | 1252 | Symbol* method_name, Symbol* method_signature, |
twisti@3969 | 1253 | KlassHandle current_klass, |
twisti@3969 | 1254 | TRAPS) { |
twisti@3969 | 1255 | // JSR 292: this must be an implicitly generated method MethodHandle.invokeExact(*...) or similar |
twisti@3969 | 1256 | assert(resolved_klass() == SystemDictionary::MethodHandle_klass(), ""); |
twisti@3969 | 1257 | assert(MethodHandles::is_signature_polymorphic_name(method_name), ""); |
twisti@3969 | 1258 | methodHandle resolved_method; |
twisti@4133 | 1259 | Handle resolved_appendix; |
twisti@4133 | 1260 | Handle resolved_method_type; |
twisti@3969 | 1261 | lookup_polymorphic_method(resolved_method, resolved_klass, |
twisti@3969 | 1262 | method_name, method_signature, |
twisti@4133 | 1263 | current_klass, &resolved_appendix, &resolved_method_type, CHECK); |
twisti@4133 | 1264 | result.set_handle(resolved_method, resolved_appendix, resolved_method_type, CHECK); |
twisti@3969 | 1265 | } |
jrose@1161 | 1266 | |
jrose@1161 | 1267 | |
twisti@3969 | 1268 | void LinkResolver::resolve_invokedynamic(CallInfo& result, constantPoolHandle pool, int index, TRAPS) { |
twisti@3969 | 1269 | assert(EnableInvokeDynamic, ""); |
twisti@3969 | 1270 | |
twisti@4133 | 1271 | //resolve_pool(<resolved_klass>, method_name, method_signature, current_klass, pool, index, CHECK); |
twisti@3969 | 1272 | Symbol* method_name = pool->name_ref_at(index); |
twisti@3969 | 1273 | Symbol* method_signature = pool->signature_ref_at(index); |
twisti@3969 | 1274 | KlassHandle current_klass = KlassHandle(THREAD, pool->pool_holder()); |
twisti@3969 | 1275 | |
twisti@3969 | 1276 | // Resolve the bootstrap specifier (BSM + optional arguments). |
twisti@3969 | 1277 | Handle bootstrap_specifier; |
twisti@3969 | 1278 | // Check if CallSite has been bound already: |
coleenp@4037 | 1279 | ConstantPoolCacheEntry* cpce = pool->invokedynamic_cp_cache_entry_at(index); |
twisti@3969 | 1280 | if (cpce->is_f1_null()) { |
coleenp@4037 | 1281 | int pool_index = cpce->constant_pool_index(); |
twisti@3969 | 1282 | oop bsm_info = pool->resolve_bootstrap_specifier_at(pool_index, CHECK); |
twisti@3969 | 1283 | assert(bsm_info != NULL, ""); |
twisti@3969 | 1284 | // FIXME: Cache this once per BootstrapMethods entry, not once per CONSTANT_InvokeDynamic. |
twisti@3969 | 1285 | bootstrap_specifier = Handle(THREAD, bsm_info); |
twisti@3969 | 1286 | } |
twisti@3969 | 1287 | if (!cpce->is_f1_null()) { |
twisti@4133 | 1288 | methodHandle method( THREAD, cpce->f1_as_method()); |
twisti@4133 | 1289 | Handle appendix( THREAD, cpce->appendix_if_resolved(pool)); |
twisti@4133 | 1290 | Handle method_type(THREAD, cpce->method_type_if_resolved(pool)); |
twisti@4133 | 1291 | result.set_handle(method, appendix, method_type, CHECK); |
twisti@3969 | 1292 | return; |
twisti@3969 | 1293 | } |
twisti@3969 | 1294 | |
twisti@3969 | 1295 | if (TraceMethodHandles) { |
twisti@3969 | 1296 | tty->print_cr("resolve_invokedynamic #%d %s %s", |
coleenp@4037 | 1297 | ConstantPool::decode_invokedynamic_index(index), |
twisti@3969 | 1298 | method_name->as_C_string(), method_signature->as_C_string()); |
twisti@3969 | 1299 | tty->print(" BSM info: "); bootstrap_specifier->print(); |
twisti@3969 | 1300 | } |
twisti@3969 | 1301 | |
twisti@3969 | 1302 | resolve_dynamic_call(result, bootstrap_specifier, method_name, method_signature, current_klass, CHECK); |
twisti@3969 | 1303 | } |
twisti@3969 | 1304 | |
twisti@3969 | 1305 | void LinkResolver::resolve_dynamic_call(CallInfo& result, |
twisti@3969 | 1306 | Handle bootstrap_specifier, |
twisti@3969 | 1307 | Symbol* method_name, Symbol* method_signature, |
twisti@3969 | 1308 | KlassHandle current_klass, |
twisti@3969 | 1309 | TRAPS) { |
twisti@3969 | 1310 | // JSR 292: this must resolve to an implicitly generated method MH.linkToCallSite(*...) |
twisti@3969 | 1311 | // The appendix argument is likely to be a freshly-created CallSite. |
twisti@3969 | 1312 | Handle resolved_appendix; |
twisti@4133 | 1313 | Handle resolved_method_type; |
twisti@3969 | 1314 | methodHandle resolved_method = |
twisti@3969 | 1315 | SystemDictionary::find_dynamic_call_site_invoker(current_klass, |
twisti@3969 | 1316 | bootstrap_specifier, |
twisti@3969 | 1317 | method_name, method_signature, |
twisti@3969 | 1318 | &resolved_appendix, |
twisti@4133 | 1319 | &resolved_method_type, |
twisti@4041 | 1320 | THREAD); |
jrose@2941 | 1321 | if (HAS_PENDING_EXCEPTION) { |
twisti@3969 | 1322 | if (TraceMethodHandles) { |
twisti@3969 | 1323 | tty->print_cr("invokedynamic throws BSME for "INTPTR_FORMAT, PENDING_EXCEPTION); |
twisti@3969 | 1324 | PENDING_EXCEPTION->print(); |
twisti@3969 | 1325 | } |
jrose@2941 | 1326 | if (PENDING_EXCEPTION->is_a(SystemDictionary::BootstrapMethodError_klass())) { |
jrose@2941 | 1327 | // throw these guys, since they are already wrapped |
jrose@2941 | 1328 | return; |
jrose@2941 | 1329 | } |
jrose@2941 | 1330 | if (!PENDING_EXCEPTION->is_a(SystemDictionary::LinkageError_klass())) { |
jrose@2941 | 1331 | // intercept only LinkageErrors which might have failed to wrap |
jrose@2941 | 1332 | return; |
jrose@2941 | 1333 | } |
jrose@2941 | 1334 | // See the "Linking Exceptions" section for the invokedynamic instruction in the JVMS. |
twisti@3969 | 1335 | Handle nested_exception(THREAD, PENDING_EXCEPTION); |
jrose@2941 | 1336 | CLEAR_PENDING_EXCEPTION; |
twisti@4041 | 1337 | THROW_CAUSE(vmSymbols::java_lang_BootstrapMethodError(), nested_exception) |
jrose@2941 | 1338 | } |
twisti@4133 | 1339 | result.set_handle(resolved_method, resolved_appendix, resolved_method_type, CHECK); |
jrose@1161 | 1340 | } |
jrose@1161 | 1341 | |
duke@435 | 1342 | //------------------------------------------------------------------------------------------------------------------------ |
duke@435 | 1343 | #ifndef PRODUCT |
duke@435 | 1344 | |
duke@435 | 1345 | void FieldAccessInfo::print() { |
duke@435 | 1346 | ResourceMark rm; |
duke@435 | 1347 | tty->print_cr("Field %s@%d", name()->as_C_string(), field_offset()); |
duke@435 | 1348 | } |
duke@435 | 1349 | |
duke@435 | 1350 | #endif |