301
302 // First check in default method array
303 if (!resolved_method->is_abstract() &&
304 (InstanceKlass::cast(klass())->default_methods() != NULL)) {
305 int index = InstanceKlass::find_method_index(InstanceKlass::cast(klass())->default_methods(), name, signature);
306 if (index >= 0 ) {
307 vtable_index = InstanceKlass::cast(klass())->default_vtable_indices()->at(index);
308 }
309 }
310 if (vtable_index == Method::invalid_vtable_index) {
311 // get vtable_index for miranda methods
312 ResourceMark rm;
313 klassVtable *vt = InstanceKlass::cast(klass())->vtable();
314 vtable_index = vt->index_of_miranda(name, signature);
315 }
316 return vtable_index;
317 }
318
319 void LinkResolver::lookup_method_in_interfaces(methodHandle& result, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS) {
320 InstanceKlass *ik = InstanceKlass::cast(klass());
321 result = methodHandle(THREAD, ik->lookup_method_in_all_interfaces(name, signature));
322 }
323
324 void LinkResolver::lookup_polymorphic_method(methodHandle& result,
325 KlassHandle klass, Symbol* name, Symbol* full_signature,
326 KlassHandle current_klass,
327 Handle *appendix_result_or_null,
328 Handle *method_type_result,
329 TRAPS) {
330 vmIntrinsics::ID iid = MethodHandles::signature_polymorphic_name_id(name);
331 if (TraceMethodHandles) {
332 ResourceMark rm(THREAD);
333 tty->print_cr("lookup_polymorphic_method iid=%s %s.%s%s",
334 vmIntrinsics::name_at(iid), klass->external_name(),
335 name->as_C_string(), full_signature->as_C_string());
336 }
337 if (EnableInvokeDynamic &&
338 klass() == SystemDictionary::MethodHandle_klass() &&
339 iid != vmIntrinsics::_none) {
340 if (MethodHandles::is_signature_polymorphic_intrinsic(iid)) {
341 // Most of these do not need an up-call to Java to resolve, so can be done anywhere.
1270 // check if private interface method
1271 if (resolved_klass->is_interface() && resolved_method->is_private()) {
1272 ResourceMark rm(THREAD);
1273 char buf[200];
1274 jio_snprintf(buf, sizeof(buf), "private interface method requires invokespecial, not invokeinterface: method %s",
1275 Method::name_and_sig_as_C_string(resolved_klass(),
1276 resolved_method->name(),
1277 resolved_method->signature()));
1278 THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
1279 }
1280
1281 // check if receiver klass implements the resolved interface
1282 if (!recv_klass->is_subtype_of(resolved_klass())) {
1283 ResourceMark rm(THREAD);
1284 char buf[200];
1285 jio_snprintf(buf, sizeof(buf), "Class %s does not implement the requested interface %s",
1286 recv_klass()->external_name(),
1287 resolved_klass()->external_name());
1288 THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
1289 }
1290 // do lookup based on receiver klass
1291 methodHandle sel_method;
1292 lookup_instance_method_in_klasses(sel_method, recv_klass,
1293 resolved_method->name(),
1294 resolved_method->signature(), CHECK);
1295 if (sel_method.is_null() && !check_null_and_abstract) {
1296 // In theory this is a harmless placeholder value, but
1297 // in practice leaving in null affects the nsk default method tests.
1298 // This needs further study.
1299 sel_method = resolved_method;
1300 }
1301 // check if method exists
1302 if (sel_method.is_null()) {
1303 ResourceMark rm(THREAD);
1304 THROW_MSG(vmSymbols::java_lang_AbstractMethodError(),
1305 Method::name_and_sig_as_C_string(recv_klass(),
1306 resolved_method->name(),
1307 resolved_method->signature()));
1308 }
1309 // check access
1310 // Throw Illegal Access Error if sel_method is not public.
1311 if (!sel_method->is_public()) {
|
301
302 // First check in default method array
303 if (!resolved_method->is_abstract() &&
304 (InstanceKlass::cast(klass())->default_methods() != NULL)) {
305 int index = InstanceKlass::find_method_index(InstanceKlass::cast(klass())->default_methods(), name, signature);
306 if (index >= 0 ) {
307 vtable_index = InstanceKlass::cast(klass())->default_vtable_indices()->at(index);
308 }
309 }
310 if (vtable_index == Method::invalid_vtable_index) {
311 // get vtable_index for miranda methods
312 ResourceMark rm;
313 klassVtable *vt = InstanceKlass::cast(klass())->vtable();
314 vtable_index = vt->index_of_miranda(name, signature);
315 }
316 return vtable_index;
317 }
318
319 void LinkResolver::lookup_method_in_interfaces(methodHandle& result, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS) {
320 InstanceKlass *ik = InstanceKlass::cast(klass());
321
322 // Specify 'true' in order to skip default methods when searching the
323 // interfaces. Function lookup_method_in_klasses() already looked for
324 // the method in the default methods table.
325 result = methodHandle(THREAD, ik->lookup_method_in_all_interfaces(name, signature, true));
326 }
327
328 void LinkResolver::lookup_polymorphic_method(methodHandle& result,
329 KlassHandle klass, Symbol* name, Symbol* full_signature,
330 KlassHandle current_klass,
331 Handle *appendix_result_or_null,
332 Handle *method_type_result,
333 TRAPS) {
334 vmIntrinsics::ID iid = MethodHandles::signature_polymorphic_name_id(name);
335 if (TraceMethodHandles) {
336 ResourceMark rm(THREAD);
337 tty->print_cr("lookup_polymorphic_method iid=%s %s.%s%s",
338 vmIntrinsics::name_at(iid), klass->external_name(),
339 name->as_C_string(), full_signature->as_C_string());
340 }
341 if (EnableInvokeDynamic &&
342 klass() == SystemDictionary::MethodHandle_klass() &&
343 iid != vmIntrinsics::_none) {
344 if (MethodHandles::is_signature_polymorphic_intrinsic(iid)) {
345 // Most of these do not need an up-call to Java to resolve, so can be done anywhere.
1274 // check if private interface method
1275 if (resolved_klass->is_interface() && resolved_method->is_private()) {
1276 ResourceMark rm(THREAD);
1277 char buf[200];
1278 jio_snprintf(buf, sizeof(buf), "private interface method requires invokespecial, not invokeinterface: method %s",
1279 Method::name_and_sig_as_C_string(resolved_klass(),
1280 resolved_method->name(),
1281 resolved_method->signature()));
1282 THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
1283 }
1284
1285 // check if receiver klass implements the resolved interface
1286 if (!recv_klass->is_subtype_of(resolved_klass())) {
1287 ResourceMark rm(THREAD);
1288 char buf[200];
1289 jio_snprintf(buf, sizeof(buf), "Class %s does not implement the requested interface %s",
1290 recv_klass()->external_name(),
1291 resolved_klass()->external_name());
1292 THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
1293 }
1294
1295 // do lookup based on receiver klass
1296 methodHandle sel_method;
1297 // This search must match the linktime preparation search for itable initialization
1298 // to correctly enforce loader constraints for interface method inheritance
1299 lookup_instance_method_in_klasses(sel_method, recv_klass,
1300 resolved_method->name(),
1301 resolved_method->signature(), CHECK);
1302 if (sel_method.is_null() && !check_null_and_abstract) {
1303 // In theory this is a harmless placeholder value, but
1304 // in practice leaving in null affects the nsk default method tests.
1305 // This needs further study.
1306 sel_method = resolved_method;
1307 }
1308 // check if method exists
1309 if (sel_method.is_null()) {
1310 ResourceMark rm(THREAD);
1311 THROW_MSG(vmSymbols::java_lang_AbstractMethodError(),
1312 Method::name_and_sig_as_C_string(recv_klass(),
1313 resolved_method->name(),
1314 resolved_method->signature()));
1315 }
1316 // check access
1317 // Throw Illegal Access Error if sel_method is not public.
1318 if (!sel_method->is_public()) {
|