Mercurial > hg > truffle
comparison src/share/vm/interpreter/linkResolver.cpp @ 12355:cefad50507d8
Merge with hs25-b53
author | Gilles Duboscq <duboscq@ssw.jku.at> |
---|---|
date | Fri, 11 Oct 2013 10:38:03 +0200 |
parents | 36b97be47bde |
children | 359f7e70ae7f ac9cb1d5a202 |
comparison
equal
deleted
inserted
replaced
12058:ccb4f2af2319 | 12355:cefad50507d8 |
---|---|
1 /* | 1 /* |
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. | 2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | 3 * |
5 * This code is free software; you can redistribute it and/or modify it | 4 * 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 | 5 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. | 6 * published by the Free Software Foundation. |
44 #include "runtime/reflection.hpp" | 43 #include "runtime/reflection.hpp" |
45 #include "runtime/signature.hpp" | 44 #include "runtime/signature.hpp" |
46 #include "runtime/thread.inline.hpp" | 45 #include "runtime/thread.inline.hpp" |
47 #include "runtime/vmThread.hpp" | 46 #include "runtime/vmThread.hpp" |
48 | 47 |
49 //------------------------------------------------------------------------------------------------------------------------ | |
50 // Implementation of FieldAccessInfo | |
51 | |
52 void FieldAccessInfo::set(KlassHandle klass, Symbol* name, int field_index, int field_offset, | |
53 BasicType field_type, AccessFlags access_flags) { | |
54 _klass = klass; | |
55 _name = name; | |
56 _field_index = field_index; | |
57 _field_offset = field_offset; | |
58 _field_type = field_type; | |
59 _access_flags = access_flags; | |
60 } | |
61 | |
62 | 48 |
63 //------------------------------------------------------------------------------------------------------------------------ | 49 //------------------------------------------------------------------------------------------------------------------------ |
64 // Implementation of CallInfo | 50 // Implementation of CallInfo |
65 | 51 |
66 | 52 |
67 void CallInfo::set_static(KlassHandle resolved_klass, methodHandle resolved_method, TRAPS) { | 53 void CallInfo::set_static(KlassHandle resolved_klass, methodHandle resolved_method, TRAPS) { |
68 int vtable_index = Method::nonvirtual_vtable_index; | 54 int vtable_index = Method::nonvirtual_vtable_index; |
69 set_common(resolved_klass, resolved_klass, resolved_method, resolved_method, vtable_index, CHECK); | 55 set_common(resolved_klass, resolved_klass, resolved_method, resolved_method, CallInfo::direct_call, vtable_index, CHECK); |
70 } | 56 } |
71 | 57 |
72 | 58 |
73 void CallInfo::set_interface(KlassHandle resolved_klass, KlassHandle selected_klass, methodHandle resolved_method, methodHandle selected_method, TRAPS) { | 59 void CallInfo::set_interface(KlassHandle resolved_klass, KlassHandle selected_klass, methodHandle resolved_method, methodHandle selected_method, int itable_index, TRAPS) { |
74 // This is only called for interface methods. If the resolved_method | 60 // This is only called for interface methods. If the resolved_method |
75 // comes from java/lang/Object, it can be the subject of a virtual call, so | 61 // comes from java/lang/Object, it can be the subject of a virtual call, so |
76 // we should pick the vtable index from the resolved method. | 62 // we should pick the vtable index from the resolved method. |
77 // Other than that case, there is no valid vtable index to specify. | 63 // In that case, the caller must call set_virtual instead of set_interface. |
78 int vtable_index = Method::invalid_vtable_index; | 64 assert(resolved_method->method_holder()->is_interface(), ""); |
79 if (resolved_method->method_holder() == SystemDictionary::Object_klass()) { | 65 assert(itable_index == resolved_method()->itable_index(), ""); |
80 assert(resolved_method->vtable_index() == selected_method->vtable_index(), "sanity check"); | 66 set_common(resolved_klass, selected_klass, resolved_method, selected_method, CallInfo::itable_call, itable_index, CHECK); |
81 vtable_index = resolved_method->vtable_index(); | |
82 } | |
83 set_common(resolved_klass, selected_klass, resolved_method, selected_method, vtable_index, CHECK); | |
84 } | 67 } |
85 | 68 |
86 void CallInfo::set_virtual(KlassHandle resolved_klass, KlassHandle selected_klass, methodHandle resolved_method, methodHandle selected_method, int vtable_index, TRAPS) { | 69 void CallInfo::set_virtual(KlassHandle resolved_klass, KlassHandle selected_klass, methodHandle resolved_method, methodHandle selected_method, int vtable_index, TRAPS) { |
87 assert(vtable_index >= 0 || vtable_index == Method::nonvirtual_vtable_index, "valid index"); | 70 assert(vtable_index >= 0 || vtable_index == Method::nonvirtual_vtable_index, "valid index"); |
88 set_common(resolved_klass, selected_klass, resolved_method, selected_method, vtable_index, CHECK); | 71 assert(vtable_index < 0 || !resolved_method->has_vtable_index() || vtable_index == resolved_method->vtable_index(), ""); |
72 CallKind kind = (vtable_index >= 0 && !resolved_method->can_be_statically_bound() ? CallInfo::vtable_call : CallInfo::direct_call); | |
73 set_common(resolved_klass, selected_klass, resolved_method, selected_method, kind, vtable_index, CHECK); | |
89 assert(!resolved_method->is_compiled_lambda_form(), "these must be handled via an invokehandle call"); | 74 assert(!resolved_method->is_compiled_lambda_form(), "these must be handled via an invokehandle call"); |
90 } | 75 } |
91 | 76 |
92 void CallInfo::set_handle(methodHandle resolved_method, Handle resolved_appendix, Handle resolved_method_type, TRAPS) { | 77 void CallInfo::set_handle(methodHandle resolved_method, Handle resolved_appendix, Handle resolved_method_type, TRAPS) { |
93 if (resolved_method.is_null()) { | 78 if (resolved_method.is_null()) { |
96 KlassHandle resolved_klass = SystemDictionary::MethodHandle_klass(); | 81 KlassHandle resolved_klass = SystemDictionary::MethodHandle_klass(); |
97 assert(resolved_method->intrinsic_id() == vmIntrinsics::_invokeBasic || | 82 assert(resolved_method->intrinsic_id() == vmIntrinsics::_invokeBasic || |
98 resolved_method->is_compiled_lambda_form(), | 83 resolved_method->is_compiled_lambda_form(), |
99 "linkMethod must return one of these"); | 84 "linkMethod must return one of these"); |
100 int vtable_index = Method::nonvirtual_vtable_index; | 85 int vtable_index = Method::nonvirtual_vtable_index; |
101 assert(resolved_method->vtable_index() == vtable_index, ""); | 86 assert(!resolved_method->has_vtable_index(), ""); |
102 set_common(resolved_klass, resolved_klass, resolved_method, resolved_method, vtable_index, CHECK); | 87 set_common(resolved_klass, resolved_klass, resolved_method, resolved_method, CallInfo::direct_call, vtable_index, CHECK); |
103 _resolved_appendix = resolved_appendix; | 88 _resolved_appendix = resolved_appendix; |
104 _resolved_method_type = resolved_method_type; | 89 _resolved_method_type = resolved_method_type; |
105 } | 90 } |
106 | 91 |
107 void CallInfo::set_common(KlassHandle resolved_klass, KlassHandle selected_klass, methodHandle resolved_method, methodHandle selected_method, int vtable_index, TRAPS) { | 92 void CallInfo::set_common(KlassHandle resolved_klass, |
93 KlassHandle selected_klass, | |
94 methodHandle resolved_method, | |
95 methodHandle selected_method, | |
96 CallKind kind, | |
97 int index, | |
98 TRAPS) { | |
108 assert(resolved_method->signature() == selected_method->signature(), "signatures must correspond"); | 99 assert(resolved_method->signature() == selected_method->signature(), "signatures must correspond"); |
109 _resolved_klass = resolved_klass; | 100 _resolved_klass = resolved_klass; |
110 _selected_klass = selected_klass; | 101 _selected_klass = selected_klass; |
111 _resolved_method = resolved_method; | 102 _resolved_method = resolved_method; |
112 _selected_method = selected_method; | 103 _selected_method = selected_method; |
113 _vtable_index = vtable_index; | 104 _call_kind = kind; |
105 _call_index = index; | |
114 _resolved_appendix = Handle(); | 106 _resolved_appendix = Handle(); |
107 DEBUG_ONLY(verify()); // verify before making side effects | |
108 | |
115 if (CompilationPolicy::must_be_compiled(selected_method)) { | 109 if (CompilationPolicy::must_be_compiled(selected_method)) { |
116 // This path is unusual, mostly used by the '-Xcomp' stress test mode. | 110 // This path is unusual, mostly used by the '-Xcomp' stress test mode. |
117 | 111 |
118 // Note: with several active threads, the must_be_compiled may be true | 112 // Note: with several active threads, the must_be_compiled may be true |
119 // while can_be_compiled is false; remove assert | 113 // while can_be_compiled is false; remove assert |
136 CompilationPolicy::policy()->initial_compile_level(), | 130 CompilationPolicy::policy()->initial_compile_level(), |
137 methodHandle(), 0, "must_be_compiled", CHECK); | 131 methodHandle(), 0, "must_be_compiled", CHECK); |
138 } | 132 } |
139 } | 133 } |
140 | 134 |
135 // utility query for unreflecting a method | |
136 CallInfo::CallInfo(Method* resolved_method, Klass* resolved_klass) { | |
137 Klass* resolved_method_holder = resolved_method->method_holder(); | |
138 if (resolved_klass == NULL) { // 2nd argument defaults to holder of 1st | |
139 resolved_klass = resolved_method_holder; | |
140 } | |
141 _resolved_klass = resolved_klass; | |
142 _selected_klass = resolved_klass; | |
143 _resolved_method = resolved_method; | |
144 _selected_method = resolved_method; | |
145 // classify: | |
146 CallKind kind = CallInfo::unknown_kind; | |
147 int index = resolved_method->vtable_index(); | |
148 if (resolved_method->can_be_statically_bound()) { | |
149 kind = CallInfo::direct_call; | |
150 } else if (!resolved_method_holder->is_interface()) { | |
151 // Could be an Object method inherited into an interface, but still a vtable call. | |
152 kind = CallInfo::vtable_call; | |
153 } else if (!resolved_klass->is_interface()) { | |
154 // A miranda method. Compute the vtable index. | |
155 ResourceMark rm; | |
156 klassVtable* vt = InstanceKlass::cast(resolved_klass)->vtable(); | |
157 index = vt->index_of_miranda(resolved_method->name(), | |
158 resolved_method->signature()); | |
159 kind = CallInfo::vtable_call; | |
160 } else { | |
161 // A regular interface call. | |
162 kind = CallInfo::itable_call; | |
163 index = resolved_method->itable_index(); | |
164 } | |
165 assert(index == Method::nonvirtual_vtable_index || index >= 0, err_msg("bad index %d", index)); | |
166 _call_kind = kind; | |
167 _call_index = index; | |
168 _resolved_appendix = Handle(); | |
169 DEBUG_ONLY(verify()); | |
170 } | |
171 | |
172 #ifdef ASSERT | |
173 void CallInfo::verify() { | |
174 switch (call_kind()) { // the meaning and allowed value of index depends on kind | |
175 case CallInfo::direct_call: | |
176 if (_call_index == Method::nonvirtual_vtable_index) break; | |
177 // else fall through to check vtable index: | |
178 case CallInfo::vtable_call: | |
179 assert(resolved_klass()->verify_vtable_index(_call_index), ""); | |
180 break; | |
181 case CallInfo::itable_call: | |
182 assert(resolved_method()->method_holder()->verify_itable_index(_call_index), ""); | |
183 break; | |
184 case CallInfo::unknown_kind: | |
185 assert(call_kind() != CallInfo::unknown_kind, "CallInfo must be set"); | |
186 break; | |
187 default: | |
188 fatal(err_msg_res("Unexpected call kind %d", call_kind())); | |
189 } | |
190 } | |
191 #endif //ASSERT | |
192 | |
193 | |
141 | 194 |
142 //------------------------------------------------------------------------------------------------------------------------ | 195 //------------------------------------------------------------------------------------------------------------------------ |
143 // Klass resolution | 196 // Klass resolution |
144 | 197 |
145 void LinkResolver::check_klass_accessability(KlassHandle ref_klass, KlassHandle sel_klass, TRAPS) { | 198 void LinkResolver::check_klass_accessability(KlassHandle ref_klass, KlassHandle sel_klass, TRAPS) { |
160 | 213 |
161 void LinkResolver::resolve_klass(KlassHandle& result, constantPoolHandle pool, int index, TRAPS) { | 214 void LinkResolver::resolve_klass(KlassHandle& result, constantPoolHandle pool, int index, TRAPS) { |
162 Klass* result_oop = pool->klass_ref_at(index, CHECK); | 215 Klass* result_oop = pool->klass_ref_at(index, CHECK); |
163 result = KlassHandle(THREAD, result_oop); | 216 result = KlassHandle(THREAD, result_oop); |
164 } | 217 } |
165 | |
166 void LinkResolver::resolve_klass_no_update(KlassHandle& result, constantPoolHandle pool, int index, TRAPS) { | |
167 Klass* result_oop = | |
168 ConstantPool::klass_ref_at_if_loaded_check(pool, index, CHECK); | |
169 result = KlassHandle(THREAD, result_oop); | |
170 } | |
171 | |
172 | 218 |
173 //------------------------------------------------------------------------------------------------------------------------ | 219 //------------------------------------------------------------------------------------------------------------------------ |
174 // Method resolution | 220 // Method resolution |
175 // | 221 // |
176 // According to JVM spec. $5.4.3c & $5.4.3d | 222 // According to JVM spec. $5.4.3c & $5.4.3d |
358 } | 404 } |
359 } | 405 } |
360 | 406 |
361 void LinkResolver::resolve_method_statically(methodHandle& resolved_method, KlassHandle& resolved_klass, | 407 void LinkResolver::resolve_method_statically(methodHandle& resolved_method, KlassHandle& resolved_klass, |
362 Bytecodes::Code code, constantPoolHandle pool, int index, TRAPS) { | 408 Bytecodes::Code code, constantPoolHandle pool, int index, TRAPS) { |
363 | 409 // This method is used only |
410 // (1) in C2 from InlineTree::ok_to_inline (via ciMethod::check_call), | |
411 // and | |
412 // (2) in Bytecode_invoke::static_target | |
413 // It appears to fail when applied to an invokeinterface call site. | |
414 // FIXME: Remove this method and ciMethod::check_call; refactor to use the other LinkResolver entry points. | |
364 // resolve klass | 415 // resolve klass |
365 if (code == Bytecodes::_invokedynamic) { | 416 if (code == Bytecodes::_invokedynamic) { |
366 resolved_klass = SystemDictionary::MethodHandle_klass(); | 417 resolved_klass = SystemDictionary::MethodHandle_klass(); |
367 Symbol* method_name = vmSymbols::invoke_name(); | 418 Symbol* method_name = vmSymbols::invoke_name(); |
368 Symbol* method_signature = pool->signature_ref_at(index); | 419 Symbol* method_signature = pool->signature_ref_at(index); |
519 method_signature)); | 570 method_signature)); |
520 } | 571 } |
521 } | 572 } |
522 | 573 |
523 if (check_access) { | 574 if (check_access) { |
575 // JDK8 adds non-public interface methods, and accessability check requirement | |
576 assert(current_klass.not_null() , "current_klass should not be null"); | |
577 | |
578 // check if method can be accessed by the referring class | |
579 check_method_accessability(current_klass, | |
580 resolved_klass, | |
581 KlassHandle(THREAD, resolved_method->method_holder()), | |
582 resolved_method, | |
583 CHECK); | |
584 | |
524 HandleMark hm(THREAD); | 585 HandleMark hm(THREAD); |
525 Handle loader (THREAD, InstanceKlass::cast(current_klass())->class_loader()); | 586 Handle loader (THREAD, InstanceKlass::cast(current_klass())->class_loader()); |
526 Handle class_loader (THREAD, resolved_method->method_holder()->class_loader()); | 587 Handle class_loader (THREAD, resolved_method->method_holder()->class_loader()); |
527 { | 588 { |
528 ResourceMark rm(THREAD); | 589 ResourceMark rm(THREAD); |
550 target, failed_type_name); | 611 target, failed_type_name); |
551 THROW_MSG(vmSymbols::java_lang_LinkageError(), buf); | 612 THROW_MSG(vmSymbols::java_lang_LinkageError(), buf); |
552 } | 613 } |
553 } | 614 } |
554 } | 615 } |
616 | |
617 if (TraceItables && Verbose) { | |
618 ResourceMark rm(THREAD); | |
619 tty->print("invokeinterface resolved method: caller-class:%s, compile-time-class:%s, method:%s, method_holder:%s, access_flags: ", | |
620 (current_klass.is_null() ? "<NULL>" : current_klass->internal_name()), | |
621 (resolved_klass.is_null() ? "<NULL>" : resolved_klass->internal_name()), | |
622 Method::name_and_sig_as_C_string(resolved_klass(), | |
623 resolved_method->name(), | |
624 resolved_method->signature()), | |
625 resolved_method->method_holder()->internal_name() | |
626 ); | |
627 resolved_method->access_flags().print_on(tty); | |
628 tty->cr(); | |
629 } | |
555 } | 630 } |
556 | 631 |
557 //------------------------------------------------------------------------------------------------------------------------ | 632 //------------------------------------------------------------------------------------------------------------------------ |
558 // Field resolution | 633 // Field resolution |
559 | 634 |
578 ); | 653 ); |
579 return; | 654 return; |
580 } | 655 } |
581 } | 656 } |
582 | 657 |
583 void LinkResolver::resolve_field(FieldAccessInfo& result, constantPoolHandle pool, int index, Bytecodes::Code byte, bool check_only, TRAPS) { | 658 void LinkResolver::resolve_field_access(fieldDescriptor& result, constantPoolHandle pool, int index, Bytecodes::Code byte, TRAPS) { |
584 resolve_field(result, pool, index, byte, check_only, true, CHECK); | |
585 } | |
586 | |
587 void LinkResolver::resolve_field(FieldAccessInfo& result, constantPoolHandle pool, int index, Bytecodes::Code byte, bool check_only, bool update_pool, TRAPS) { | |
588 assert(byte == Bytecodes::_getstatic || byte == Bytecodes::_putstatic || | |
589 byte == Bytecodes::_getfield || byte == Bytecodes::_putfield, "bad bytecode"); | |
590 | |
591 bool is_static = (byte == Bytecodes::_getstatic || byte == Bytecodes::_putstatic); | |
592 bool is_put = (byte == Bytecodes::_putfield || byte == Bytecodes::_putstatic); | |
593 | |
594 // resolve specified klass | |
595 KlassHandle resolved_klass; | |
596 if (update_pool) { | |
597 resolve_klass(resolved_klass, pool, index, CHECK); | |
598 } else { | |
599 resolve_klass_no_update(resolved_klass, pool, index, CHECK); | |
600 } | |
601 // Load these early in case the resolve of the containing klass fails | 659 // Load these early in case the resolve of the containing klass fails |
602 Symbol* field = pool->name_ref_at(index); | 660 Symbol* field = pool->name_ref_at(index); |
603 Symbol* sig = pool->signature_ref_at(index); | 661 Symbol* sig = pool->signature_ref_at(index); |
662 | |
663 // resolve specified klass | |
664 KlassHandle resolved_klass; | |
665 resolve_klass(resolved_klass, pool, index, CHECK); | |
666 | |
667 KlassHandle current_klass(THREAD, pool->pool_holder()); | |
668 resolve_field(result, resolved_klass, field, sig, current_klass, byte, true, true, CHECK); | |
669 } | |
670 | |
671 void LinkResolver::resolve_field(fieldDescriptor& fd, KlassHandle resolved_klass, Symbol* field, Symbol* sig, | |
672 KlassHandle current_klass, Bytecodes::Code byte, bool check_access, bool initialize_class, | |
673 TRAPS) { | |
674 assert(byte == Bytecodes::_getstatic || byte == Bytecodes::_putstatic || | |
675 byte == Bytecodes::_getfield || byte == Bytecodes::_putfield || | |
676 (byte == Bytecodes::_nop && !check_access), "bad field access bytecode"); | |
677 | |
678 bool is_static = (byte == Bytecodes::_getstatic || byte == Bytecodes::_putstatic); | |
679 bool is_put = (byte == Bytecodes::_putfield || byte == Bytecodes::_putstatic); | |
680 | |
604 // Check if there's a resolved klass containing the field | 681 // Check if there's a resolved klass containing the field |
605 if( resolved_klass.is_null() ) { | 682 if (resolved_klass.is_null()) { |
606 ResourceMark rm(THREAD); | 683 ResourceMark rm(THREAD); |
607 THROW_MSG(vmSymbols::java_lang_NoSuchFieldError(), field->as_C_string()); | 684 THROW_MSG(vmSymbols::java_lang_NoSuchFieldError(), field->as_C_string()); |
608 } | 685 } |
609 | 686 |
610 // Resolve instance field | 687 // Resolve instance field |
611 fieldDescriptor fd; // find_field initializes fd if found | |
612 KlassHandle sel_klass(THREAD, InstanceKlass::cast(resolved_klass())->find_field(field, sig, &fd)); | 688 KlassHandle sel_klass(THREAD, InstanceKlass::cast(resolved_klass())->find_field(field, sig, &fd)); |
613 // check if field exists; i.e., if a klass containing the field def has been selected | 689 // check if field exists; i.e., if a klass containing the field def has been selected |
614 if (sel_klass.is_null()){ | 690 if (sel_klass.is_null()) { |
615 ResourceMark rm(THREAD); | 691 ResourceMark rm(THREAD); |
616 THROW_MSG(vmSymbols::java_lang_NoSuchFieldError(), field->as_C_string()); | 692 THROW_MSG(vmSymbols::java_lang_NoSuchFieldError(), field->as_C_string()); |
617 } | 693 } |
618 | 694 |
695 if (!check_access) | |
696 // Access checking may be turned off when calling from within the VM. | |
697 return; | |
698 | |
619 // check access | 699 // check access |
620 KlassHandle ref_klass(THREAD, pool->pool_holder()); | 700 check_field_accessability(current_klass, resolved_klass, sel_klass, fd, CHECK); |
621 check_field_accessability(ref_klass, resolved_klass, sel_klass, fd, CHECK); | |
622 | 701 |
623 // check for errors | 702 // check for errors |
624 if (is_static != fd.is_static()) { | 703 if (is_static != fd.is_static()) { |
625 ResourceMark rm(THREAD); | 704 ResourceMark rm(THREAD); |
626 char msg[200]; | 705 char msg[200]; |
627 jio_snprintf(msg, sizeof(msg), "Expected %s field %s.%s", is_static ? "static" : "non-static", resolved_klass()->external_name(), fd.name()->as_C_string()); | 706 jio_snprintf(msg, sizeof(msg), "Expected %s field %s.%s", is_static ? "static" : "non-static", resolved_klass()->external_name(), fd.name()->as_C_string()); |
628 THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), msg); | 707 THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), msg); |
629 } | 708 } |
630 | 709 |
631 // Final fields can only be accessed from its own class. | 710 // Final fields can only be accessed from its own class. |
632 if (is_put && fd.access_flags().is_final() && sel_klass() != pool->pool_holder()) { | 711 if (is_put && fd.access_flags().is_final() && sel_klass() != current_klass()) { |
633 THROW(vmSymbols::java_lang_IllegalAccessError()); | 712 THROW(vmSymbols::java_lang_IllegalAccessError()); |
634 } | 713 } |
635 | 714 |
636 // initialize resolved_klass if necessary | 715 // initialize resolved_klass if necessary |
637 // note 1: the klass which declared the field must be initialized (i.e, sel_klass) | 716 // note 1: the klass which declared the field must be initialized (i.e, sel_klass) |
638 // according to the newest JVM spec (5.5, p.170) - was bug (gri 7/28/99) | 717 // according to the newest JVM spec (5.5, p.170) - was bug (gri 7/28/99) |
639 // | 718 // |
640 // note 2: we don't want to force initialization if we are just checking | 719 // note 2: we don't want to force initialization if we are just checking |
641 // if the field access is legal; e.g., during compilation | 720 // if the field access is legal; e.g., during compilation |
642 if (is_static && !check_only) { | 721 if (is_static && initialize_class) { |
643 sel_klass->initialize(CHECK); | 722 sel_klass->initialize(CHECK); |
644 } | 723 } |
645 | 724 |
646 { | 725 if (sel_klass() != current_klass()) { |
647 HandleMark hm(THREAD); | 726 HandleMark hm(THREAD); |
648 Handle ref_loader (THREAD, InstanceKlass::cast(ref_klass())->class_loader()); | 727 Handle ref_loader (THREAD, InstanceKlass::cast(current_klass())->class_loader()); |
649 Handle sel_loader (THREAD, InstanceKlass::cast(sel_klass())->class_loader()); | 728 Handle sel_loader (THREAD, InstanceKlass::cast(sel_klass())->class_loader()); |
650 Symbol* signature_ref = pool->signature_ref_at(index); | |
651 { | 729 { |
652 ResourceMark rm(THREAD); | 730 ResourceMark rm(THREAD); |
653 Symbol* failed_type_symbol = | 731 Symbol* failed_type_symbol = |
654 SystemDictionary::check_signature_loaders(signature_ref, | 732 SystemDictionary::check_signature_loaders(sig, |
655 ref_loader, sel_loader, | 733 ref_loader, sel_loader, |
656 false, | 734 false, |
657 CHECK); | 735 CHECK); |
658 if (failed_type_symbol != NULL) { | 736 if (failed_type_symbol != NULL) { |
659 const char* msg = "loader constraint violation: when resolving field" | 737 const char* msg = "loader constraint violation: when resolving field" |
675 } | 753 } |
676 } | 754 } |
677 | 755 |
678 // return information. note that the klass is set to the actual klass containing the | 756 // return information. note that the klass is set to the actual klass containing the |
679 // field, otherwise access of static fields in superclasses will not work. | 757 // field, otherwise access of static fields in superclasses will not work. |
680 KlassHandle holder (THREAD, fd.field_holder()); | |
681 Symbol* name = fd.name(); | |
682 result.set(holder, name, fd.index(), fd.offset(), fd.field_type(), fd.access_flags()); | |
683 } | 758 } |
684 | 759 |
685 | 760 |
686 //------------------------------------------------------------------------------------------------------------------------ | 761 //------------------------------------------------------------------------------------------------------------------------ |
687 // Invoke resolution | 762 // Invoke resolution |
741 // throws linktime exceptions | 816 // throws linktime exceptions |
742 void LinkResolver::linktime_resolve_special_method(methodHandle& resolved_method, KlassHandle resolved_klass, | 817 void LinkResolver::linktime_resolve_special_method(methodHandle& resolved_method, KlassHandle resolved_klass, |
743 Symbol* method_name, Symbol* method_signature, | 818 Symbol* method_name, Symbol* method_signature, |
744 KlassHandle current_klass, bool check_access, TRAPS) { | 819 KlassHandle current_klass, bool check_access, TRAPS) { |
745 | 820 |
746 if (resolved_klass->is_interface() && current_klass() != NULL) { | 821 // Invokespecial is called for multiple special reasons: |
747 // If the target class is a direct interface, treat this as a "super" | 822 // <init> |
748 // default call. | 823 // local private method invocation, for classes and interfaces |
749 // | 824 // superclass.method, which can also resolve to a default method |
750 // If the current method is an overpass that happens to call a direct | 825 // and the selected method is recalculated relative to the direct superclass |
751 // super-interface's method, then we'll end up rerunning the default method | 826 // superinterface.method, which explicitly does not check shadowing |
752 // analysis even though we don't need to, but that's ok since it will end | |
753 // up with the same answer. | |
754 InstanceKlass* ik = InstanceKlass::cast(current_klass()); | |
755 Array<Klass*>* interfaces = ik->local_interfaces(); | |
756 int num_interfaces = interfaces->length(); | |
757 for (int index = 0; index < num_interfaces; index++) { | |
758 if (interfaces->at(index) == resolved_klass()) { | |
759 Method* method = DefaultMethods::find_super_default(current_klass(), | |
760 resolved_klass(), method_name, method_signature, CHECK); | |
761 resolved_method = methodHandle(THREAD, method); | |
762 return; | |
763 } | |
764 } | |
765 } | |
766 | 827 |
767 resolve_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, check_access, CHECK); | 828 resolve_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, check_access, CHECK); |
768 | 829 |
769 // check if method name is <init>, that it is found in same klass as static type | 830 // check if method name is <init>, that it is found in same klass as static type |
770 if (resolved_method->name() == vmSymbols::object_initializer_name() && | 831 if (resolved_method->name() == vmSymbols::object_initializer_name() && |
790 Method::name_and_sig_as_C_string(resolved_klass(), | 851 Method::name_and_sig_as_C_string(resolved_klass(), |
791 resolved_method->name(), | 852 resolved_method->name(), |
792 resolved_method->signature())); | 853 resolved_method->signature())); |
793 THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf); | 854 THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf); |
794 } | 855 } |
856 if (TraceItables && Verbose) { | |
857 ResourceMark rm(THREAD); | |
858 tty->print("invokespecial resolved method: caller-class:%s, compile-time-class:%s, method:%s, method_holder:%s, access_flags: ", | |
859 (current_klass.is_null() ? "<NULL>" : current_klass->internal_name()), | |
860 (resolved_klass.is_null() ? "<NULL>" : resolved_klass->internal_name()), | |
861 Method::name_and_sig_as_C_string(resolved_klass(), | |
862 resolved_method->name(), | |
863 resolved_method->signature()), | |
864 resolved_method->method_holder()->internal_name() | |
865 ); | |
866 resolved_method->access_flags().print_on(tty); | |
867 if (resolved_method->method_holder()->is_interface() && | |
868 !resolved_method->is_abstract()) { | |
869 tty->print("default"); | |
870 } | |
871 if (resolved_method->is_overpass()) { | |
872 tty->print("overpass"); | |
873 } | |
874 tty->cr(); | |
875 } | |
795 } | 876 } |
796 | 877 |
797 // throws runtime exceptions | 878 // throws runtime exceptions |
798 void LinkResolver::runtime_resolve_special_method(CallInfo& result, methodHandle resolved_method, KlassHandle resolved_klass, | 879 void LinkResolver::runtime_resolve_special_method(CallInfo& result, methodHandle resolved_method, KlassHandle resolved_klass, |
799 KlassHandle current_klass, bool check_access, TRAPS) { | 880 KlassHandle current_klass, bool check_access, TRAPS) { |
800 | 881 |
801 // resolved method is selected method unless we have an old-style lookup | 882 // resolved method is selected method unless we have an old-style lookup |
883 // for a superclass method | |
884 // Invokespecial for a superinterface, resolved method is selected method, | |
885 // no checks for shadowing | |
802 methodHandle sel_method(THREAD, resolved_method()); | 886 methodHandle sel_method(THREAD, resolved_method()); |
803 | 887 |
804 // check if this is an old-style super call and do a new lookup if so | 888 // check if this is an old-style super call and do a new lookup if so |
805 { KlassHandle method_klass = KlassHandle(THREAD, | 889 { KlassHandle method_klass = KlassHandle(THREAD, |
806 resolved_method->method_holder()); | 890 resolved_method->method_holder()); |
807 | 891 |
808 const bool direct_calling_default_method = | 892 if (check_access && |
809 resolved_klass() != NULL && resolved_method() != NULL && | |
810 resolved_klass->is_interface() && !resolved_method->is_abstract(); | |
811 | |
812 if (!direct_calling_default_method && | |
813 check_access && | |
814 // a) check if ACC_SUPER flag is set for the current class | 893 // a) check if ACC_SUPER flag is set for the current class |
815 (current_klass->is_super() || !AllowNonVirtualCalls) && | 894 (current_klass->is_super() || !AllowNonVirtualCalls) && |
816 // b) check if the method class is a superclass of the current class (superclass relation is not reflexive!) | 895 // b) check if the class of the resolved_klass is a superclass |
817 current_klass->is_subtype_of(method_klass()) && | 896 // (not supertype in order to exclude interface classes) of the current class. |
818 current_klass() != method_klass() && | 897 // This check is not performed for super.invoke for interface methods |
898 // in super interfaces. | |
899 current_klass->is_subclass_of(resolved_klass()) && | |
900 current_klass() != resolved_klass() && | |
819 // c) check if the method is not <init> | 901 // c) check if the method is not <init> |
820 resolved_method->name() != vmSymbols::object_initializer_name()) { | 902 resolved_method->name() != vmSymbols::object_initializer_name()) { |
821 // Lookup super method | 903 // Lookup super method |
822 KlassHandle super_klass(THREAD, current_klass->super()); | 904 KlassHandle super_klass(THREAD, current_klass->super()); |
823 lookup_instance_method_in_klasses(sel_method, super_klass, | 905 lookup_instance_method_in_klasses(sel_method, super_klass, |
851 Method::name_and_sig_as_C_string(resolved_klass(), | 933 Method::name_and_sig_as_C_string(resolved_klass(), |
852 sel_method->name(), | 934 sel_method->name(), |
853 sel_method->signature())); | 935 sel_method->signature())); |
854 } | 936 } |
855 | 937 |
938 if (TraceItables && Verbose) { | |
939 ResourceMark rm(THREAD); | |
940 tty->print("invokespecial selected method: resolved-class:%s, method:%s, method_holder:%s, access_flags: ", | |
941 (resolved_klass.is_null() ? "<NULL>" : resolved_klass->internal_name()), | |
942 Method::name_and_sig_as_C_string(resolved_klass(), | |
943 sel_method->name(), | |
944 sel_method->signature()), | |
945 sel_method->method_holder()->internal_name() | |
946 ); | |
947 sel_method->access_flags().print_on(tty); | |
948 if (sel_method->method_holder()->is_interface() && | |
949 !sel_method->is_abstract()) { | |
950 tty->print("default"); | |
951 } | |
952 tty->cr(); | |
953 } | |
954 | |
856 // setup result | 955 // setup result |
857 result.set_static(resolved_klass, sel_method, CHECK); | 956 result.set_static(resolved_klass, sel_method, CHECK); |
858 } | 957 } |
859 | 958 |
860 void LinkResolver::resolve_virtual_call(CallInfo& result, Handle recv, KlassHandle receiver_klass, KlassHandle resolved_klass, | 959 void LinkResolver::resolve_virtual_call(CallInfo& result, Handle recv, KlassHandle receiver_klass, KlassHandle resolved_klass, |
873 resolve_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, check_access, CHECK); | 972 resolve_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, check_access, CHECK); |
874 | 973 |
875 assert(resolved_method->name() != vmSymbols::object_initializer_name(), "should have been checked in verifier"); | 974 assert(resolved_method->name() != vmSymbols::object_initializer_name(), "should have been checked in verifier"); |
876 assert(resolved_method->name() != vmSymbols::class_initializer_name (), "should have been checked in verifier"); | 975 assert(resolved_method->name() != vmSymbols::class_initializer_name (), "should have been checked in verifier"); |
877 | 976 |
977 // check if private interface method | |
978 if (resolved_klass->is_interface() && resolved_method->is_private()) { | |
979 ResourceMark rm(THREAD); | |
980 char buf[200]; | |
981 jio_snprintf(buf, sizeof(buf), "private interface method requires invokespecial, not invokevirtual: method %s, caller-class:%s", | |
982 Method::name_and_sig_as_C_string(resolved_klass(), | |
983 resolved_method->name(), | |
984 resolved_method->signature()), | |
985 (current_klass.is_null() ? "<NULL>" : current_klass->internal_name())); | |
986 THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf); | |
987 } | |
988 | |
878 // check if not static | 989 // check if not static |
879 if (resolved_method->is_static()) { | 990 if (resolved_method->is_static()) { |
880 ResourceMark rm(THREAD); | 991 ResourceMark rm(THREAD); |
881 char buf[200]; | 992 char buf[200]; |
882 jio_snprintf(buf, sizeof(buf), "Expecting non-static method %s", Method::name_and_sig_as_C_string(resolved_klass(), | 993 jio_snprintf(buf, sizeof(buf), "Expecting non-static method %s", Method::name_and_sig_as_C_string(resolved_klass(), |
883 resolved_method->name(), | 994 resolved_method->name(), |
884 resolved_method->signature())); | 995 resolved_method->signature())); |
885 THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf); | 996 THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf); |
886 } | 997 } |
998 | |
999 if (PrintVtables && Verbose) { | |
1000 ResourceMark rm(THREAD); | |
1001 tty->print("invokevirtual resolved method: caller-class:%s, compile-time-class:%s, method:%s, method_holder:%s, access_flags: ", | |
1002 (current_klass.is_null() ? "<NULL>" : current_klass->internal_name()), | |
1003 (resolved_klass.is_null() ? "<NULL>" : resolved_klass->internal_name()), | |
1004 Method::name_and_sig_as_C_string(resolved_klass(), | |
1005 resolved_method->name(), | |
1006 resolved_method->signature()), | |
1007 resolved_method->method_holder()->internal_name() | |
1008 ); | |
1009 resolved_method->access_flags().print_on(tty); | |
1010 if (resolved_method->method_holder()->is_interface() && | |
1011 !resolved_method->is_abstract()) { | |
1012 tty->print("default"); | |
1013 } | |
1014 if (resolved_method->is_overpass()) { | |
1015 tty->print("overpass"); | |
1016 } | |
1017 tty->cr(); | |
1018 } | |
887 } | 1019 } |
888 | 1020 |
889 // throws runtime exceptions | 1021 // throws runtime exceptions |
890 void LinkResolver::runtime_resolve_virtual_method(CallInfo& result, | 1022 void LinkResolver::runtime_resolve_virtual_method(CallInfo& result, |
891 methodHandle resolved_method, | 1023 methodHandle resolved_method, |
905 if (check_null_and_abstract && recv.is_null()) { // check if receiver exists | 1037 if (check_null_and_abstract && recv.is_null()) { // check if receiver exists |
906 THROW(vmSymbols::java_lang_NullPointerException()); | 1038 THROW(vmSymbols::java_lang_NullPointerException()); |
907 } | 1039 } |
908 | 1040 |
909 // Virtual methods cannot be resolved before its klass has been linked, for otherwise the Method*'s | 1041 // Virtual methods cannot be resolved before its klass has been linked, for otherwise the Method*'s |
910 // has not been rewritten, and the vtable initialized. | |
911 assert(resolved_method->method_holder()->is_linked(), "must be linked"); | |
912 | |
913 // Virtual methods cannot be resolved before its klass has been linked, for otherwise the Method*'s | |
914 // has not been rewritten, and the vtable initialized. Make sure to do this after the nullcheck, since | 1042 // has not been rewritten, and the vtable initialized. Make sure to do this after the nullcheck, since |
915 // a missing receiver might result in a bogus lookup. | 1043 // a missing receiver might result in a bogus lookup. |
916 assert(resolved_method->method_holder()->is_linked(), "must be linked"); | 1044 assert(resolved_method->method_holder()->is_linked(), "must be linked"); |
917 | 1045 |
918 // do lookup based on receiver klass using the vtable index | 1046 // do lookup based on receiver klass using the vtable index |
919 if (resolved_method->method_holder()->is_interface()) { // miranda method | 1047 if (resolved_method->method_holder()->is_interface()) { // miranda method |
920 vtable_index = vtable_index_of_miranda_method(resolved_klass, | 1048 vtable_index = vtable_index_of_miranda_method(resolved_klass, |
921 resolved_method->name(), | 1049 resolved_method->name(), |
922 resolved_method->signature(), CHECK); | 1050 resolved_method->signature(), CHECK); |
1051 | |
923 assert(vtable_index >= 0 , "we should have valid vtable index at this point"); | 1052 assert(vtable_index >= 0 , "we should have valid vtable index at this point"); |
924 | 1053 |
925 InstanceKlass* inst = InstanceKlass::cast(recv_klass()); | 1054 InstanceKlass* inst = InstanceKlass::cast(recv_klass()); |
926 selected_method = methodHandle(THREAD, inst->method_at_vtable(vtable_index)); | 1055 selected_method = methodHandle(THREAD, inst->method_at_vtable(vtable_index)); |
927 } else { | 1056 } else { |
928 // at this point we are sure that resolved_method is virtual and not | 1057 // at this point we are sure that resolved_method is virtual and not |
929 // a miranda method; therefore, it must have a valid vtable index. | 1058 // a miranda method; therefore, it must have a valid vtable index. |
1059 assert(!resolved_method->has_itable_index(), ""); | |
930 vtable_index = resolved_method->vtable_index(); | 1060 vtable_index = resolved_method->vtable_index(); |
931 // We could get a negative vtable_index for final methods, | 1061 // We could get a negative vtable_index for final methods, |
932 // because as an optimization they are they are never put in the vtable, | 1062 // because as an optimization they are they are never put in the vtable, |
933 // unless they override an existing method. | 1063 // unless they override an existing method. |
934 // If we do get a negative, it means the resolved method is the the selected | 1064 // If we do get a negative, it means the resolved method is the the selected |
960 Method::name_and_sig_as_C_string(resolved_klass(), | 1090 Method::name_and_sig_as_C_string(resolved_klass(), |
961 selected_method->name(), | 1091 selected_method->name(), |
962 selected_method->signature())); | 1092 selected_method->signature())); |
963 } | 1093 } |
964 | 1094 |
1095 if (PrintVtables && Verbose) { | |
1096 ResourceMark rm(THREAD); | |
1097 tty->print("invokevirtual selected method: receiver-class:%s, resolved-class:%s, method:%s, method_holder:%s, vtable_index:%d, access_flags: ", | |
1098 (recv_klass.is_null() ? "<NULL>" : recv_klass->internal_name()), | |
1099 (resolved_klass.is_null() ? "<NULL>" : resolved_klass->internal_name()), | |
1100 Method::name_and_sig_as_C_string(resolved_klass(), | |
1101 resolved_method->name(), | |
1102 resolved_method->signature()), | |
1103 selected_method->method_holder()->internal_name(), | |
1104 vtable_index | |
1105 ); | |
1106 selected_method->access_flags().print_on(tty); | |
1107 if (selected_method->method_holder()->is_interface() && | |
1108 !selected_method->is_abstract()) { | |
1109 tty->print("default"); | |
1110 } | |
1111 if (resolved_method->is_overpass()) { | |
1112 tty->print("overpass"); | |
1113 } | |
1114 tty->cr(); | |
1115 } | |
965 // setup result | 1116 // setup result |
966 result.set_virtual(resolved_klass, recv_klass, resolved_method, selected_method, vtable_index, CHECK); | 1117 result.set_virtual(resolved_klass, recv_klass, resolved_method, selected_method, vtable_index, CHECK); |
967 } | 1118 } |
968 | 1119 |
969 void LinkResolver::resolve_interface_call(CallInfo& result, Handle recv, KlassHandle recv_klass, KlassHandle resolved_klass, | 1120 void LinkResolver::resolve_interface_call(CallInfo& result, Handle recv, KlassHandle recv_klass, KlassHandle resolved_klass, |
990 // check if receiver exists | 1141 // check if receiver exists |
991 if (check_null_and_abstract && recv.is_null()) { | 1142 if (check_null_and_abstract && recv.is_null()) { |
992 THROW(vmSymbols::java_lang_NullPointerException()); | 1143 THROW(vmSymbols::java_lang_NullPointerException()); |
993 } | 1144 } |
994 | 1145 |
1146 // check if private interface method | |
1147 if (resolved_klass->is_interface() && resolved_method->is_private()) { | |
1148 ResourceMark rm(THREAD); | |
1149 char buf[200]; | |
1150 jio_snprintf(buf, sizeof(buf), "private interface method requires invokespecial, not invokeinterface: method %s", | |
1151 Method::name_and_sig_as_C_string(resolved_klass(), | |
1152 resolved_method->name(), | |
1153 resolved_method->signature())); | |
1154 THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf); | |
1155 } | |
1156 | |
995 // check if receiver klass implements the resolved interface | 1157 // check if receiver klass implements the resolved interface |
996 if (!recv_klass->is_subtype_of(resolved_klass())) { | 1158 if (!recv_klass->is_subtype_of(resolved_klass())) { |
997 ResourceMark rm(THREAD); | 1159 ResourceMark rm(THREAD); |
998 char buf[200]; | 1160 char buf[200]; |
999 jio_snprintf(buf, sizeof(buf), "Class %s does not implement the requested interface %s", | 1161 jio_snprintf(buf, sizeof(buf), "Class %s does not implement the requested interface %s", |
1004 // do lookup based on receiver klass | 1166 // do lookup based on receiver klass |
1005 methodHandle sel_method; | 1167 methodHandle sel_method; |
1006 lookup_instance_method_in_klasses(sel_method, recv_klass, | 1168 lookup_instance_method_in_klasses(sel_method, recv_klass, |
1007 resolved_method->name(), | 1169 resolved_method->name(), |
1008 resolved_method->signature(), CHECK); | 1170 resolved_method->signature(), CHECK); |
1171 if (sel_method.is_null() && !check_null_and_abstract) { | |
1172 // In theory this is a harmless placeholder value, but | |
1173 // in practice leaving in null affects the nsk default method tests. | |
1174 // This needs further study. | |
1175 sel_method = resolved_method; | |
1176 } | |
1009 // check if method exists | 1177 // check if method exists |
1010 if (sel_method.is_null()) { | 1178 if (sel_method.is_null()) { |
1011 ResourceMark rm(THREAD); | 1179 ResourceMark rm(THREAD); |
1012 THROW_MSG(vmSymbols::java_lang_AbstractMethodError(), | 1180 THROW_MSG(vmSymbols::java_lang_AbstractMethodError(), |
1013 Method::name_and_sig_as_C_string(recv_klass(), | 1181 Method::name_and_sig_as_C_string(recv_klass(), |
1014 resolved_method->name(), | 1182 resolved_method->name(), |
1015 resolved_method->signature())); | 1183 resolved_method->signature())); |
1016 } | 1184 } |
1017 // check access | 1185 // check access |
1018 if (sel_method->method_holder()->is_interface()) { | 1186 // Throw Illegal Access Error if sel_method is not public. |
1019 // Method holder is an interface. Throw Illegal Access Error if sel_method | 1187 if (!sel_method->is_public()) { |
1020 // is neither public nor private. | 1188 ResourceMark rm(THREAD); |
1021 if (!(sel_method->is_public() || sel_method->is_private())) { | 1189 THROW_MSG(vmSymbols::java_lang_IllegalAccessError(), |
1022 ResourceMark rm(THREAD); | 1190 Method::name_and_sig_as_C_string(recv_klass(), |
1023 THROW_MSG(vmSymbols::java_lang_IllegalAccessError(), | 1191 sel_method->name(), |
1024 Method::name_and_sig_as_C_string(recv_klass(), | 1192 sel_method->signature())); |
1025 sel_method->name(), | 1193 } |
1026 sel_method->signature())); | 1194 |
1027 } | |
1028 } | |
1029 else { | |
1030 // Method holder is a class. Throw Illegal Access Error if sel_method | |
1031 // is not public. | |
1032 if (!sel_method->is_public()) { | |
1033 ResourceMark rm(THREAD); | |
1034 THROW_MSG(vmSymbols::java_lang_IllegalAccessError(), | |
1035 Method::name_and_sig_as_C_string(recv_klass(), | |
1036 sel_method->name(), | |
1037 sel_method->signature())); | |
1038 } | |
1039 } | |
1040 // check if abstract | 1195 // check if abstract |
1041 if (check_null_and_abstract && sel_method->is_abstract()) { | 1196 if (check_null_and_abstract && sel_method->is_abstract()) { |
1042 ResourceMark rm(THREAD); | 1197 ResourceMark rm(THREAD); |
1043 THROW_MSG(vmSymbols::java_lang_AbstractMethodError(), | 1198 THROW_MSG(vmSymbols::java_lang_AbstractMethodError(), |
1044 Method::name_and_sig_as_C_string(recv_klass(), | 1199 Method::name_and_sig_as_C_string(recv_klass(), |
1045 sel_method->name(), | 1200 sel_method->name(), |
1046 sel_method->signature())); | 1201 sel_method->signature())); |
1047 } | 1202 } |
1048 // setup result | 1203 // setup result |
1049 result.set_interface(resolved_klass, recv_klass, resolved_method, sel_method, CHECK); | 1204 if (!resolved_method->has_itable_index()) { |
1205 int vtable_index = resolved_method->vtable_index(); | |
1206 assert(vtable_index == sel_method->vtable_index(), "sanity check"); | |
1207 result.set_virtual(resolved_klass, recv_klass, resolved_method, sel_method, vtable_index, CHECK); | |
1208 return; | |
1209 } | |
1210 int itable_index = resolved_method()->itable_index(); | |
1211 | |
1212 if (TraceItables && Verbose) { | |
1213 ResourceMark rm(THREAD); | |
1214 tty->print("invokeinterface selected method: receiver-class:%s, resolved-class:%s, method:%s, method_holder:%s, access_flags: ", | |
1215 (recv_klass.is_null() ? "<NULL>" : recv_klass->internal_name()), | |
1216 (resolved_klass.is_null() ? "<NULL>" : resolved_klass->internal_name()), | |
1217 Method::name_and_sig_as_C_string(resolved_klass(), | |
1218 resolved_method->name(), | |
1219 resolved_method->signature()), | |
1220 sel_method->method_holder()->internal_name() | |
1221 ); | |
1222 sel_method->access_flags().print_on(tty); | |
1223 if (sel_method->method_holder()->is_interface() && | |
1224 !sel_method->is_abstract()) { | |
1225 tty->print("default"); | |
1226 } | |
1227 if (resolved_method->is_overpass()) { | |
1228 tty->print("overpass"); | |
1229 } | |
1230 tty->cr(); | |
1231 } | |
1232 result.set_interface(resolved_klass, recv_klass, resolved_method, sel_method, itable_index, CHECK); | |
1050 } | 1233 } |
1051 | 1234 |
1052 | 1235 |
1053 methodHandle LinkResolver::linktime_resolve_interface_method_or_null( | 1236 methodHandle LinkResolver::linktime_resolve_interface_method_or_null( |
1054 KlassHandle resolved_klass, | 1237 KlassHandle resolved_klass, |
1291 result.set_handle(method, appendix, method_type, CHECK); | 1474 result.set_handle(method, appendix, method_type, CHECK); |
1292 return; | 1475 return; |
1293 } | 1476 } |
1294 | 1477 |
1295 if (TraceMethodHandles) { | 1478 if (TraceMethodHandles) { |
1296 tty->print_cr("resolve_invokedynamic #%d %s %s", | 1479 ResourceMark rm(THREAD); |
1480 tty->print_cr("resolve_invokedynamic #%d %s %s", | |
1297 ConstantPool::decode_invokedynamic_index(index), | 1481 ConstantPool::decode_invokedynamic_index(index), |
1298 method_name->as_C_string(), method_signature->as_C_string()); | 1482 method_name->as_C_string(), method_signature->as_C_string()); |
1299 tty->print(" BSM info: "); bootstrap_specifier->print(); | 1483 tty->print(" BSM info: "); bootstrap_specifier->print(); |
1300 } | 1484 } |
1301 | 1485 |
1318 &resolved_appendix, | 1502 &resolved_appendix, |
1319 &resolved_method_type, | 1503 &resolved_method_type, |
1320 THREAD); | 1504 THREAD); |
1321 if (HAS_PENDING_EXCEPTION) { | 1505 if (HAS_PENDING_EXCEPTION) { |
1322 if (TraceMethodHandles) { | 1506 if (TraceMethodHandles) { |
1323 tty->print_cr("invokedynamic throws BSME for "INTPTR_FORMAT, PENDING_EXCEPTION); | 1507 tty->print_cr("invokedynamic throws BSME for "INTPTR_FORMAT, (void *)PENDING_EXCEPTION); |
1324 PENDING_EXCEPTION->print(); | 1508 PENDING_EXCEPTION->print(); |
1325 } | 1509 } |
1326 if (PENDING_EXCEPTION->is_a(SystemDictionary::BootstrapMethodError_klass())) { | 1510 if (PENDING_EXCEPTION->is_a(SystemDictionary::BootstrapMethodError_klass())) { |
1327 // throw these guys, since they are already wrapped | 1511 // throw these guys, since they are already wrapped |
1328 return; | 1512 return; |
1340 } | 1524 } |
1341 | 1525 |
1342 //------------------------------------------------------------------------------------------------------------------------ | 1526 //------------------------------------------------------------------------------------------------------------------------ |
1343 #ifndef PRODUCT | 1527 #ifndef PRODUCT |
1344 | 1528 |
1345 void FieldAccessInfo::print() { | 1529 void CallInfo::print() { |
1346 ResourceMark rm; | 1530 ResourceMark rm; |
1347 tty->print_cr("Field %s@%d", name()->as_C_string(), field_offset()); | 1531 const char* kindstr = "unknown"; |
1532 switch (_call_kind) { | |
1533 case direct_call: kindstr = "direct"; break; | |
1534 case vtable_call: kindstr = "vtable"; break; | |
1535 case itable_call: kindstr = "itable"; break; | |
1536 } | |
1537 tty->print_cr("Call %s@%d %s", kindstr, _call_index, | |
1538 _resolved_method.is_null() ? "(none)" : _resolved_method->name_and_sig_as_C_string()); | |
1348 } | 1539 } |
1349 | 1540 |
1350 #endif | 1541 #endif |