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