38 class CallInfo : public StackObj {
39 public:
40 // Ways that a method call might be selected (or not) based on receiver type.
41 // Note that an invokevirtual instruction might be linked with no_dispatch,
42 // and an invokeinterface instruction might be linked with any of the three options
43 enum CallKind {
44 direct_call, // jump into resolved_method (must be concrete)
45 vtable_call, // select recv.klass.method_at_vtable(index)
46 itable_call, // select recv.klass.method_at_itable(resolved_method.holder, index)
47 unknown_kind = -1
48 };
49 private:
50 Klass* _resolved_klass; // static receiver klass, resolved from a symbolic reference
51 Klass* _selected_klass; // dynamic receiver class (same as static, or subklass)
52 methodHandle _resolved_method; // static target method
53 methodHandle _selected_method; // dynamic (actual) target method
54 CallKind _call_kind; // kind of call (static(=bytecode static/special +
55 // others inferred), vtable, itable)
56 int _call_index; // vtable or itable index of selected class method (if any)
57 Handle _resolved_appendix; // extra argument in constant pool (if CPCE::has_appendix)
58 Handle _resolved_method_type; // MethodType (for invokedynamic and invokehandle call sites)
59 Handle _resolved_method_name; // Object holding the ResolvedMethodName
60
61 void set_static(Klass* resolved_klass, const methodHandle& resolved_method, TRAPS);
62 void set_interface(Klass* resolved_klass, Klass* selected_klass,
63 const methodHandle& resolved_method,
64 const methodHandle& selected_method,
65 int itable_index, TRAPS);
66 void set_virtual(Klass* resolved_klass, Klass* selected_klass,
67 const methodHandle& resolved_method,
68 const methodHandle& selected_method,
69 int vtable_index, TRAPS);
70 void set_handle(const methodHandle& resolved_method,
71 Handle resolved_appendix, Handle resolved_method_type, TRAPS);
72 void set_handle(Klass* resolved_klass,
73 const methodHandle& resolved_method,
74 Handle resolved_appendix, Handle resolved_method_type, TRAPS);
75 void set_common(Klass* resolved_klass, Klass* selected_klass,
76 const methodHandle& resolved_method,
77 const methodHandle& selected_method,
78 CallKind kind,
79 int index, TRAPS);
80
81 friend class LinkResolver;
82
83 public:
84 CallInfo() {
85 #ifndef PRODUCT
86 _call_kind = CallInfo::unknown_kind;
87 _call_index = Method::garbage_vtable_index;
88 #endif //PRODUCT
89 }
90
91 // utility to extract an effective CallInfo from a method and an optional receiver limit
92 // does not queue the method for compilation. This also creates a ResolvedMethodName
93 // object for the resolved_method.
94 CallInfo(Method* resolved_method, Klass* resolved_klass, TRAPS);
95
96 Klass* resolved_klass() const { return _resolved_klass; }
97 Klass* selected_klass() const { return _selected_klass; }
98 methodHandle resolved_method() const { return _resolved_method; }
99 methodHandle selected_method() const { return _selected_method; }
100 Handle resolved_appendix() const { return _resolved_appendix; }
101 Handle resolved_method_type() const { return _resolved_method_type; }
102 Handle resolved_method_name() const { return _resolved_method_name; }
103 // Materialize a java.lang.invoke.ResolvedMethodName for this resolved_method
104 void set_resolved_method_name(TRAPS);
105
106 BasicType result_type() const { return selected_method()->result_type(); }
107 CallKind call_kind() const { return _call_kind; }
108 int call_index() const { return _call_index; }
109 int vtable_index() const {
110 // Even for interface calls the vtable index could be non-negative.
111 // See CallInfo::set_interface.
112 assert(has_vtable_index() || is_statically_bound(), "");
113 assert(call_kind() == vtable_call || call_kind() == direct_call, "");
114 // The returned value is < 0 if the call is statically bound.
115 // But, the returned value may be >= 0 even if the kind is direct_call.
116 // It is up to the caller to decide which way to go.
117 return _call_index;
118 }
119 int itable_index() const {
120 assert(call_kind() == itable_call, "");
121 // The returned value is always >= 0, a valid itable index.
122 return _call_index;
123 }
124
125 // debugging
126 #ifdef ASSERT
127 bool has_vtable_index() const { return _call_index >= 0 && _call_kind != CallInfo::itable_call; }
128 bool is_statically_bound() const { return _call_index == Method::nonvirtual_vtable_index; }
129 #endif //ASSERT
130 void verify() PRODUCT_RETURN;
131 void print() PRODUCT_RETURN;
132 };
133
134
135 // Condensed information from constant pool to use to resolve the method or field.
136 // resolved_klass = specified class (i.e., static receiver class)
137 // current_klass = sending method holder (i.e., class containing the method
138 // containing the call being resolved)
139 // current_method = sending method (relevant for field resolution)
140 class LinkInfo : public StackObj {
141 Symbol* _name; // extracted from JVM_CONSTANT_NameAndType
142 Symbol* _signature;
143 Klass* _resolved_klass; // class that the constant pool entry points to
144 Klass* _current_klass; // class that owns the constant pool
145 methodHandle _current_method; // sending method
146 bool _check_access;
147 constantTag _tag;
148
149 public:
150 enum AccessCheck {
151 needs_access_check,
152 skip_access_check
153 };
190 };
191
192 // Link information for getfield/putfield & getstatic/putstatic bytecodes
193 // is represented using a fieldDescriptor.
194
195 // The LinkResolver is used to resolve constant-pool references at run-time.
196 // It does all necessary link-time checks & throws exceptions if necessary.
197
198 class LinkResolver: AllStatic {
199 friend class klassVtable;
200 friend class klassItable;
201
202 private:
203
204 static Method* lookup_method_in_klasses(const LinkInfo& link_info,
205 bool checkpolymorphism,
206 bool in_imethod_resolve);
207 static Method* lookup_method_in_interfaces(const LinkInfo& link_info);
208
209 static methodHandle lookup_polymorphic_method(const LinkInfo& link_info,
210 Handle *appendix_result_or_null,
211 Handle *method_type_result, TRAPS);
212 JVMCI_ONLY(public:) // Needed for CompilerToVM.resolveMethod()
213 // Not Linktime so doesn't take LinkInfo
214 static methodHandle lookup_instance_method_in_klasses (Klass* klass, Symbol* name, Symbol* signature,
215 Klass::PrivateLookupMode private_mode, TRAPS);
216 JVMCI_ONLY(private:)
217
218 // Similar loader constraint checking functions that throw
219 // LinkageError with descriptive message.
220 static void check_method_loader_constraints(const LinkInfo& link_info,
221 const methodHandle& resolved_method,
222 const char* method_type, TRAPS);
223 static void check_field_loader_constraints(Symbol* field, Symbol* sig,
224 Klass* current_klass,
225 Klass* sel_klass, TRAPS);
226
227 static methodHandle resolve_interface_method(const LinkInfo& link_info, Bytecodes::Code code, TRAPS);
228 static methodHandle resolve_method (const LinkInfo& link_info, Bytecodes::Code code, TRAPS);
229
230 static methodHandle linktime_resolve_static_method (const LinkInfo& link_info, TRAPS);
231 static methodHandle linktime_resolve_special_method (const LinkInfo& link_info, TRAPS);
298 Bytecodes::Code byte, TRAPS);
299 static void resolve_field(fieldDescriptor& result, const LinkInfo& link_info,
300 Bytecodes::Code access_kind,
301 bool initialize_class, TRAPS);
302
303 static void resolve_static_call (CallInfo& result,
304 const LinkInfo& link_info,
305 bool initialize_klass, TRAPS);
306 static void resolve_special_call (CallInfo& result,
307 Handle recv,
308 const LinkInfo& link_info,
309 TRAPS);
310 static void resolve_virtual_call (CallInfo& result, Handle recv, Klass* recv_klass,
311 const LinkInfo& link_info,
312 bool check_null_and_abstract, TRAPS);
313 static void resolve_interface_call(CallInfo& result, Handle recv, Klass* recv_klass,
314 const LinkInfo& link_info,
315 bool check_null_and_abstract, TRAPS);
316 static void resolve_handle_call (CallInfo& result,
317 const LinkInfo& link_info, TRAPS);
318 static void resolve_dynamic_call (CallInfo& result, int pool_index, Handle bootstrap_specifier,
319 Symbol* method_name, Symbol* method_signature,
320 Klass* current_klass, TRAPS);
321
322 // same as above for compile-time resolution; but returns null handle instead of throwing
323 // an exception on error also, does not initialize klass (i.e., no side effects)
324 static methodHandle resolve_virtual_call_or_null (Klass* receiver_klass,
325 const LinkInfo& link_info);
326 static methodHandle resolve_interface_call_or_null(Klass* receiver_klass,
327 const LinkInfo& link_info);
328 static methodHandle resolve_static_call_or_null (const LinkInfo& link_info);
329 static methodHandle resolve_special_call_or_null (const LinkInfo& link_info);
330
331 static int vtable_index_of_interface_method(Klass* klass, const methodHandle& resolved_method);
332
333 // same as above for compile-time resolution; returns vtable_index if current_klass if linked
334 static int resolve_virtual_vtable_index (Klass* receiver_klass,
335 const LinkInfo& link_info);
336
337 // static resolving for compiler (does not throw exceptions, returns null handle if unsuccessful)
338 static methodHandle linktime_resolve_virtual_method_or_null (const LinkInfo& link_info);
339 static methodHandle linktime_resolve_interface_method_or_null(const LinkInfo& link_info);
340
|
38 class CallInfo : public StackObj {
39 public:
40 // Ways that a method call might be selected (or not) based on receiver type.
41 // Note that an invokevirtual instruction might be linked with no_dispatch,
42 // and an invokeinterface instruction might be linked with any of the three options
43 enum CallKind {
44 direct_call, // jump into resolved_method (must be concrete)
45 vtable_call, // select recv.klass.method_at_vtable(index)
46 itable_call, // select recv.klass.method_at_itable(resolved_method.holder, index)
47 unknown_kind = -1
48 };
49 private:
50 Klass* _resolved_klass; // static receiver klass, resolved from a symbolic reference
51 Klass* _selected_klass; // dynamic receiver class (same as static, or subklass)
52 methodHandle _resolved_method; // static target method
53 methodHandle _selected_method; // dynamic (actual) target method
54 CallKind _call_kind; // kind of call (static(=bytecode static/special +
55 // others inferred), vtable, itable)
56 int _call_index; // vtable or itable index of selected class method (if any)
57 Handle _resolved_appendix; // extra argument in constant pool (if CPCE::has_appendix)
58 bool _has_local_sig; // use signature from call site, which differs from that of the method itself
59 Handle _resolved_method_name; // Object holding the ResolvedMethodName
60
61 void set_static(Klass* resolved_klass, const methodHandle& resolved_method, TRAPS);
62 void set_interface(Klass* resolved_klass, Klass* selected_klass,
63 const methodHandle& resolved_method,
64 const methodHandle& selected_method,
65 int itable_index, TRAPS);
66 void set_virtual(Klass* resolved_klass, Klass* selected_klass,
67 const methodHandle& resolved_method,
68 const methodHandle& selected_method,
69 int vtable_index, TRAPS);
70 void set_handle(const methodHandle& resolved_method,
71 Handle resolved_appendix, bool has_local_sig, TRAPS);
72 void set_handle(Klass* resolved_klass,
73 const methodHandle& resolved_method,
74 Handle resolved_appendix, bool has_local_sig, TRAPS);
75 void set_common(Klass* resolved_klass, Klass* selected_klass,
76 const methodHandle& resolved_method,
77 const methodHandle& selected_method,
78 CallKind kind,
79 int index, TRAPS);
80
81 friend class LinkResolver;
82 friend class BootstrapInfo;
83
84 public:
85 CallInfo() {
86 #ifndef PRODUCT
87 _call_kind = CallInfo::unknown_kind;
88 _call_index = Method::garbage_vtable_index;
89 #endif //PRODUCT
90 }
91
92 // utility to extract an effective CallInfo from a method and an optional receiver limit
93 // does not queue the method for compilation. This also creates a ResolvedMethodName
94 // object for the resolved_method.
95 CallInfo(Method* resolved_method, Klass* resolved_klass, TRAPS);
96
97 Klass* resolved_klass() const { return _resolved_klass; }
98 Klass* selected_klass() const { return _selected_klass; }
99 methodHandle resolved_method() const { return _resolved_method; }
100 methodHandle selected_method() const { return _selected_method; }
101 Handle resolved_appendix() const { return _resolved_appendix; }
102 bool has_local_signature() const { return _has_local_sig; }
103 Handle resolved_method_name() const { return _resolved_method_name; }
104 // Materialize a java.lang.invoke.ResolvedMethodName for this resolved_method
105 void set_resolved_method_name(TRAPS);
106
107 BasicType result_type() const { return selected_method()->result_type(); }
108 CallKind call_kind() const { return _call_kind; }
109 int call_index() const { return _call_index; }
110 int vtable_index() const {
111 // Even for interface calls the vtable index could be non-negative.
112 // See CallInfo::set_interface.
113 assert(has_vtable_index() || is_statically_bound(), "");
114 assert(call_kind() == vtable_call || call_kind() == direct_call, "");
115 // The returned value is < 0 if the call is statically bound.
116 // But, the returned value may be >= 0 even if the kind is direct_call.
117 // It is up to the caller to decide which way to go.
118 return _call_index;
119 }
120 int itable_index() const {
121 assert(call_kind() == itable_call, "");
122 // The returned value is always >= 0, a valid itable index.
123 return _call_index;
124 }
125
126 // debugging
127 #ifdef ASSERT
128 bool has_vtable_index() const { return _call_index >= 0 && _call_kind != CallInfo::itable_call; }
129 bool is_statically_bound() const { return _call_index == Method::nonvirtual_vtable_index; }
130 #endif //ASSERT
131 void verify() PRODUCT_RETURN;
132 void print() PRODUCT_RETURN;
133 };
134
135 // Condensed information from constant pool to use to invoke a bootstrap method.
136 class BootstrapInfo : public StackObj {
137 constantPoolHandle _pool; // constant pool containing the bootstrap specifier
138 const int _bss_index; // index of bootstrap specifier in CP (condy or indy)
139 const int _indy_index; // internal index of indy call site, or -1 if a condy call
140 const bool _is_method_call; // are we resolving a method (indy) or a value (condy)?
141 const int _argc; // number of static arguments
142 Symbol* _name; // extracted from JVM_CONSTANT_NameAndType
143 Symbol* _signature;
144
145 // pre-bootstrap resolution state:
146 Handle _bsm; // resolved bootstrap method
147 Handle _name_arg; // resolved String
148 Handle _type_arg; // resolved Class or MethodType
149 typeArrayHandle _arg_indexes; // int[] array of static arguments, as CP indexes
150 objArrayHandle _arg_values; // Object[] array of static arguments; null for unresolved
151
152 // post-bootstrap resolution state:
153 bool _is_resolved; // set true when any of the next fields are set
154 Handle _resolved_value; // bind this as condy constant
155 methodHandle _resolved_method; // bind this as indy behavior
156 Handle _resolved_appendix; // extra opaque static argument for _resolved_method
157
158 int nat_ref_index() const { return _pool->bootstrap_name_and_type_ref_index_at(_bss_index); }
159
160 public:
161 BootstrapInfo(const constantPoolHandle& pool, int bss_index, int indy_index = 0);
162
163 // accessors
164 const constantPoolHandle& pool() const{ return _pool; }
165 int bss_index() const { return _bss_index; }
166 int indy_index() const { return _indy_index; }
167 int argc() const { return _argc; }
168 bool is_method_call() const { return _is_method_call; }
169 Symbol* name() const { return _name; }
170 Symbol* signature() const { return _signature; }
171
172 // accessors to lazy state
173 Handle bsm() const { return _bsm; }
174 Handle name_arg() const { return _name_arg; }
175 Handle type_arg() const { return _type_arg; }
176 typeArrayHandle arg_indexes() const { return _arg_indexes; }
177 objArrayHandle arg_values() const { return _arg_values; }
178 bool is_resolved() const { return _is_resolved; }
179 Handle resolved_value() const { assert(!is_method_call(), ""); return _resolved_value; }
180 methodHandle resolved_method() const { assert(is_method_call(), ""); return _resolved_method; }
181 Handle resolved_appendix() const { assert(is_method_call(), ""); return _resolved_appendix; }
182
183 // derived accessors
184 InstanceKlass* caller() const { return _pool->pool_holder(); }
185 oop caller_mirror() const { return caller()->java_mirror(); }
186 int decode_indy_index() const { return ConstantPool::decode_invokedynamic_index(_indy_index); }
187 int name_index() const { return _pool->name_ref_index_at(nat_ref_index()); }
188 int signature_index() const { return _pool->signature_ref_index_at(nat_ref_index()); }
189 int bsms_attr_index() const { return _pool->bootstrap_methods_attribute_index(_bss_index); }
190 int bsm_index() const { return _pool->bootstrap_method_ref_index_at(_bss_index); }
191 //int argc() is eagerly cached in _argc
192 int arg_index(int i) const { return _pool->bootstrap_argument_index_at(_bss_index, i); }
193 oop arg_value(int i) const; // pull oop from _arg_values, safely, NULL if not present
194
195 enum BSMMode { _unknown, _metadata, _bsci, _expression };
196 BSMMode bsm_mode() const;
197
198 // CP cache entry for call site (indy only)
199 ConstantPoolCacheEntry* invokedynamic_cp_cache_entry() const {
200 assert(is_method_call(), "");
201 return _pool->invokedynamic_cp_cache_entry_at(_indy_index);
202 }
203
204 // If there is evidence this call site was already linked, set the
205 // existing linkage data into result, or throw previouos exception.
206 // Return true if either action is taken, else false.
207 bool resolve_previously_linked_invokedynamic(CallInfo& result, TRAPS);
208 bool save_and_throw_indy_exc(TRAPS);
209 void resolve_newly_linked_invokedynamic(CallInfo& result, TRAPS);
210
211 // argument location and resolution
212 // Null returns from these are real, actual null condy constants.
213 // They never produce Universe::the_null_sentinel.
214 oop find_arg_oop(int i, Handle if_not_present, TRAPS) {
215 // Don't pass if_not_present as null unless you are OK with confusing
216 // "not present" with "present but null".
217 bool found_it = false;
218 oop result = _pool->find_cached_constant_at(arg_index(i), found_it, THREAD);
219 return (found_it ? result : if_not_present()); // OK to execute during exception
220 }
221 oop resolve_arg_oop(int i, TRAPS) {
222 return _pool->resolve_possibly_cached_constant_at(arg_index(i), THREAD);
223 }
224
225 // pre-bootstrap resolution actions:
226 Handle resolve_bsm(TRAPS); // lazily compute _bsm and return it
227 void resolve_metadata(TRAPS); // lazily compute _name/_type
228 void resolve_args(ConstantPool::BootstrapArgumentReferenceMode resolving, TRAPS); // compute arguments
229
230 // setters for post-bootstrap results:
231 void set_resolved_value(Handle value) {
232 assert(!is_resolved() && !is_method_call(), "");
233 _is_resolved = true;
234 _resolved_value = value;
235 }
236 void set_resolved_method(methodHandle method, Handle appendix) {
237 assert(!is_resolved() && is_method_call(), "");
238 _is_resolved = true;
239 _resolved_method = method;
240 _resolved_appendix = appendix;
241 }
242
243 void print() { print_msg_on(tty); }
244 void print_msg_on(outputStream* st, const char* msg = NULL);
245 };
246
247 // Condensed information from constant pool to use to resolve the method or field.
248 // resolved_klass = specified class (i.e., static receiver class)
249 // current_klass = sending method holder (i.e., class containing the method
250 // containing the call being resolved)
251 // current_method = sending method (relevant for field resolution)
252 class LinkInfo : public StackObj {
253 Symbol* _name; // extracted from JVM_CONSTANT_NameAndType
254 Symbol* _signature;
255 Klass* _resolved_klass; // class that the constant pool entry points to
256 Klass* _current_klass; // class that owns the constant pool
257 methodHandle _current_method; // sending method
258 bool _check_access;
259 constantTag _tag;
260
261 public:
262 enum AccessCheck {
263 needs_access_check,
264 skip_access_check
265 };
302 };
303
304 // Link information for getfield/putfield & getstatic/putstatic bytecodes
305 // is represented using a fieldDescriptor.
306
307 // The LinkResolver is used to resolve constant-pool references at run-time.
308 // It does all necessary link-time checks & throws exceptions if necessary.
309
310 class LinkResolver: AllStatic {
311 friend class klassVtable;
312 friend class klassItable;
313
314 private:
315
316 static Method* lookup_method_in_klasses(const LinkInfo& link_info,
317 bool checkpolymorphism,
318 bool in_imethod_resolve);
319 static Method* lookup_method_in_interfaces(const LinkInfo& link_info);
320
321 static methodHandle lookup_polymorphic_method(const LinkInfo& link_info,
322 Handle *appendix_result_or_null, TRAPS);
323 JVMCI_ONLY(public:) // Needed for CompilerToVM.resolveMethod()
324 // Not Linktime so doesn't take LinkInfo
325 static methodHandle lookup_instance_method_in_klasses (Klass* klass, Symbol* name, Symbol* signature,
326 Klass::PrivateLookupMode private_mode, TRAPS);
327 JVMCI_ONLY(private:)
328
329 // Similar loader constraint checking functions that throw
330 // LinkageError with descriptive message.
331 static void check_method_loader_constraints(const LinkInfo& link_info,
332 const methodHandle& resolved_method,
333 const char* method_type, TRAPS);
334 static void check_field_loader_constraints(Symbol* field, Symbol* sig,
335 Klass* current_klass,
336 Klass* sel_klass, TRAPS);
337
338 static methodHandle resolve_interface_method(const LinkInfo& link_info, Bytecodes::Code code, TRAPS);
339 static methodHandle resolve_method (const LinkInfo& link_info, Bytecodes::Code code, TRAPS);
340
341 static methodHandle linktime_resolve_static_method (const LinkInfo& link_info, TRAPS);
342 static methodHandle linktime_resolve_special_method (const LinkInfo& link_info, TRAPS);
409 Bytecodes::Code byte, TRAPS);
410 static void resolve_field(fieldDescriptor& result, const LinkInfo& link_info,
411 Bytecodes::Code access_kind,
412 bool initialize_class, TRAPS);
413
414 static void resolve_static_call (CallInfo& result,
415 const LinkInfo& link_info,
416 bool initialize_klass, TRAPS);
417 static void resolve_special_call (CallInfo& result,
418 Handle recv,
419 const LinkInfo& link_info,
420 TRAPS);
421 static void resolve_virtual_call (CallInfo& result, Handle recv, Klass* recv_klass,
422 const LinkInfo& link_info,
423 bool check_null_and_abstract, TRAPS);
424 static void resolve_interface_call(CallInfo& result, Handle recv, Klass* recv_klass,
425 const LinkInfo& link_info,
426 bool check_null_and_abstract, TRAPS);
427 static void resolve_handle_call (CallInfo& result,
428 const LinkInfo& link_info, TRAPS);
429 static void resolve_dynamic_call (CallInfo& result,
430 BootstrapInfo& bootstrap_specifier, TRAPS);
431
432 // same as above for compile-time resolution; but returns null handle instead of throwing
433 // an exception on error also, does not initialize klass (i.e., no side effects)
434 static methodHandle resolve_virtual_call_or_null (Klass* receiver_klass,
435 const LinkInfo& link_info);
436 static methodHandle resolve_interface_call_or_null(Klass* receiver_klass,
437 const LinkInfo& link_info);
438 static methodHandle resolve_static_call_or_null (const LinkInfo& link_info);
439 static methodHandle resolve_special_call_or_null (const LinkInfo& link_info);
440
441 static int vtable_index_of_interface_method(Klass* klass, const methodHandle& resolved_method);
442
443 // same as above for compile-time resolution; returns vtable_index if current_klass if linked
444 static int resolve_virtual_vtable_index (Klass* receiver_klass,
445 const LinkInfo& link_info);
446
447 // static resolving for compiler (does not throw exceptions, returns null handle if unsuccessful)
448 static methodHandle linktime_resolve_virtual_method_or_null (const LinkInfo& link_info);
449 static methodHandle linktime_resolve_interface_method_or_null(const LinkInfo& link_info);
450
|