Mercurial > hg > truffle
comparison src/share/vm/interpreter/linkResolver.cpp @ 14909:4ca6dc0799b6
Backout jdk9 merge
author | Gilles Duboscq <duboscq@ssw.jku.at> |
---|---|
date | Tue, 01 Apr 2014 13:57:07 +0200 |
parents | d8041d695d19 |
children | a20be10ad437 |
comparison
equal
deleted
inserted
replaced
14908:8db6e76cb658 | 14909:4ca6dc0799b6 |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. | 2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | 4 * |
5 * This code is free software; you can redistribute it and/or modify it | 5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as | 6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
298 int vtable_index = Method::invalid_vtable_index; | 298 int vtable_index = Method::invalid_vtable_index; |
299 Symbol* name = resolved_method->name(); | 299 Symbol* name = resolved_method->name(); |
300 Symbol* signature = resolved_method->signature(); | 300 Symbol* signature = resolved_method->signature(); |
301 | 301 |
302 // First check in default method array | 302 // First check in default method array |
303 if (!resolved_method->is_abstract() && | 303 if (!resolved_method->is_abstract() && |
304 (InstanceKlass::cast(klass())->default_methods() != NULL)) { | 304 (InstanceKlass::cast(klass())->default_methods() != NULL)) { |
305 int index = InstanceKlass::find_method_index(InstanceKlass::cast(klass())->default_methods(), name, signature); | 305 int index = InstanceKlass::find_method_index(InstanceKlass::cast(klass())->default_methods(), name, signature); |
306 if (index >= 0 ) { | 306 if (index >= 0 ) { |
307 vtable_index = InstanceKlass::cast(klass())->default_vtable_indices()->at(index); | 307 vtable_index = InstanceKlass::cast(klass())->default_vtable_indices()->at(index); |
308 } | 308 } |
316 return vtable_index; | 316 return vtable_index; |
317 } | 317 } |
318 | 318 |
319 void LinkResolver::lookup_method_in_interfaces(methodHandle& result, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS) { | 319 void LinkResolver::lookup_method_in_interfaces(methodHandle& result, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS) { |
320 InstanceKlass *ik = InstanceKlass::cast(klass()); | 320 InstanceKlass *ik = InstanceKlass::cast(klass()); |
321 | 321 result = methodHandle(THREAD, ik->lookup_method_in_all_interfaces(name, signature)); |
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 } | 322 } |
327 | 323 |
328 void LinkResolver::lookup_polymorphic_method(methodHandle& result, | 324 void LinkResolver::lookup_polymorphic_method(methodHandle& result, |
329 KlassHandle klass, Symbol* name, Symbol* full_signature, | 325 KlassHandle klass, Symbol* name, Symbol* full_signature, |
330 KlassHandle current_klass, | 326 KlassHandle current_klass, |
562 method_signature), | 558 method_signature), |
563 nested_exception); | 559 nested_exception); |
564 } | 560 } |
565 } | 561 } |
566 | 562 |
567 // 5. access checks, access checking may be turned off when calling from within the VM. | 563 // 5. check if method is concrete |
564 if (resolved_method->is_abstract() && !resolved_klass->is_abstract()) { | |
565 ResourceMark rm(THREAD); | |
566 THROW_MSG(vmSymbols::java_lang_AbstractMethodError(), | |
567 Method::name_and_sig_as_C_string(resolved_klass(), | |
568 method_name, | |
569 method_signature)); | |
570 } | |
571 | |
572 // 6. access checks, access checking may be turned off when calling from within the VM. | |
568 if (check_access) { | 573 if (check_access) { |
569 assert(current_klass.not_null() , "current_klass should not be null"); | 574 assert(current_klass.not_null() , "current_klass should not be null"); |
570 | 575 |
571 // check if method can be accessed by the referring class | 576 // check if method can be accessed by the referring class |
572 check_method_accessability(current_klass, | 577 check_method_accessability(current_klass, |
613 Symbol* method_signature, | 618 Symbol* method_signature, |
614 KlassHandle current_klass, | 619 KlassHandle current_klass, |
615 bool check_access, | 620 bool check_access, |
616 bool nostatics, TRAPS) { | 621 bool nostatics, TRAPS) { |
617 | 622 |
618 // check if klass is interface | 623 // check if klass is interface |
619 if (!resolved_klass->is_interface()) { | 624 if (!resolved_klass->is_interface()) { |
620 ResourceMark rm(THREAD); | 625 ResourceMark rm(THREAD); |
621 char buf[200]; | 626 char buf[200]; |
622 jio_snprintf(buf, sizeof(buf), "Found class %s, but interface was expected", resolved_klass()->external_name()); | 627 jio_snprintf(buf, sizeof(buf), "Found class %s, but interface was expected", resolved_klass()->external_name()); |
623 THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf); | 628 THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf); |
637 Method::name_and_sig_as_C_string(resolved_klass(), | 642 Method::name_and_sig_as_C_string(resolved_klass(), |
638 method_name, | 643 method_name, |
639 method_signature)); | 644 method_signature)); |
640 } | 645 } |
641 } | 646 } |
647 | |
648 if (nostatics && resolved_method->is_static()) { | |
649 ResourceMark rm(THREAD); | |
650 char buf[200]; | |
651 jio_snprintf(buf, sizeof(buf), "Expected instance not static method %s", Method::name_and_sig_as_C_string(resolved_klass(), | |
652 resolved_method->name(), | |
653 resolved_method->signature())); | |
654 THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf); | |
655 } | |
656 | |
642 | 657 |
643 if (check_access) { | 658 if (check_access) { |
644 // JDK8 adds non-public interface methods, and accessability check requirement | 659 // JDK8 adds non-public interface methods, and accessability check requirement |
645 assert(current_klass.not_null() , "current_klass should not be null"); | 660 assert(current_klass.not_null() , "current_klass should not be null"); |
646 | 661 |
681 THROW_MSG(vmSymbols::java_lang_LinkageError(), buf); | 696 THROW_MSG(vmSymbols::java_lang_LinkageError(), buf); |
682 } | 697 } |
683 } | 698 } |
684 } | 699 } |
685 | 700 |
686 if (nostatics && resolved_method->is_static()) { | |
687 ResourceMark rm(THREAD); | |
688 char buf[200]; | |
689 jio_snprintf(buf, sizeof(buf), "Expected instance not static method %s", | |
690 Method::name_and_sig_as_C_string(resolved_klass(), | |
691 resolved_method->name(), resolved_method->signature())); | |
692 THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf); | |
693 } | |
694 | |
695 if (TraceItables && Verbose) { | 701 if (TraceItables && Verbose) { |
696 ResourceMark rm(THREAD); | 702 ResourceMark rm(THREAD); |
697 tty->print("invokeinterface resolved method: caller-class:%s, compile-time-class:%s, method:%s, method_holder:%s, access_flags: ", | 703 tty->print("invokeinterface resolved method: caller-class:%s, compile-time-class:%s, method:%s, method_holder:%s, access_flags: ", |
698 (current_klass.is_null() ? "<NULL>" : current_klass->internal_name()), | 704 (current_klass.is_null() ? "<NULL>" : current_klass->internal_name()), |
699 (resolved_klass.is_null() ? "<NULL>" : resolved_klass->internal_name()), | 705 (resolved_klass.is_null() ? "<NULL>" : resolved_klass->internal_name()), |
1283 jio_snprintf(buf, sizeof(buf), "Class %s does not implement the requested interface %s", | 1289 jio_snprintf(buf, sizeof(buf), "Class %s does not implement the requested interface %s", |
1284 recv_klass()->external_name(), | 1290 recv_klass()->external_name(), |
1285 resolved_klass()->external_name()); | 1291 resolved_klass()->external_name()); |
1286 THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf); | 1292 THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf); |
1287 } | 1293 } |
1288 | |
1289 // do lookup based on receiver klass | 1294 // do lookup based on receiver klass |
1290 methodHandle sel_method; | 1295 methodHandle sel_method; |
1291 // This search must match the linktime preparation search for itable initialization | |
1292 // to correctly enforce loader constraints for interface method inheritance | |
1293 lookup_instance_method_in_klasses(sel_method, recv_klass, | 1296 lookup_instance_method_in_klasses(sel_method, recv_klass, |
1294 resolved_method->name(), | 1297 resolved_method->name(), |
1295 resolved_method->signature(), CHECK); | 1298 resolved_method->signature(), CHECK); |
1296 if (sel_method.is_null() && !check_null_and_abstract) { | 1299 if (sel_method.is_null() && !check_null_and_abstract) { |
1297 // In theory this is a harmless placeholder value, but | 1300 // In theory this is a harmless placeholder value, but |