Mercurial > hg > graal-compiler
annotate src/share/vm/interpreter/linkResolver.cpp @ 1366:b9d85fcdf743
6940733: allocate non static oop fields in super and sub classes together
Summary: Use FieldsAllocationStyle=2 to allocate non static oop fields in super and sub classes together
Reviewed-by: twisti
author | kvn |
---|---|
date | Wed, 07 Apr 2010 10:35:56 -0700 |
parents | 4ce7240d622c |
children | cd5dbf694d45 |
rev | line source |
---|---|
0 | 1 /* |
710 | 2 * Copyright 1997-2009 Sun Microsystems, Inc. All Rights Reserved. |
0 | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | |
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 | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, | |
20 * CA 95054 USA or visit www.sun.com if you need additional information or | |
21 * have any questions. | |
22 * | |
23 */ | |
24 | |
25 #include "incls/_precompiled.incl" | |
26 #include "incls/_linkResolver.cpp.incl" | |
27 | |
28 //------------------------------------------------------------------------------------------------------------------------ | |
29 // Implementation of FieldAccessInfo | |
30 | |
31 void FieldAccessInfo::set(KlassHandle klass, symbolHandle name, int field_index, int field_offset, | |
32 BasicType field_type, AccessFlags access_flags) { | |
33 _klass = klass; | |
34 _name = name; | |
35 _field_index = field_index; | |
36 _field_offset = field_offset; | |
37 _field_type = field_type; | |
38 _access_flags = access_flags; | |
39 } | |
40 | |
41 | |
42 //------------------------------------------------------------------------------------------------------------------------ | |
43 // Implementation of CallInfo | |
44 | |
45 | |
46 void CallInfo::set_static(KlassHandle resolved_klass, methodHandle resolved_method, TRAPS) { | |
47 int vtable_index = methodOopDesc::nonvirtual_vtable_index; | |
48 set_common(resolved_klass, resolved_klass, resolved_method, resolved_method, vtable_index, CHECK); | |
49 } | |
50 | |
51 | |
52 void CallInfo::set_interface(KlassHandle resolved_klass, KlassHandle selected_klass, methodHandle resolved_method, methodHandle selected_method, TRAPS) { | |
53 // This is only called for interface methods. If the resolved_method | |
54 // comes from java/lang/Object, it can be the subject of a virtual call, so | |
55 // we should pick the vtable index from the resolved method. | |
56 // Other than that case, there is no valid vtable index to specify. | |
57 int vtable_index = methodOopDesc::invalid_vtable_index; | |
1142 | 58 if (resolved_method->method_holder() == SystemDictionary::Object_klass()) { |
0 | 59 assert(resolved_method->vtable_index() == selected_method->vtable_index(), "sanity check"); |
60 vtable_index = resolved_method->vtable_index(); | |
61 } | |
62 set_common(resolved_klass, selected_klass, resolved_method, selected_method, vtable_index, CHECK); | |
63 } | |
64 | |
65 void CallInfo::set_virtual(KlassHandle resolved_klass, KlassHandle selected_klass, methodHandle resolved_method, methodHandle selected_method, int vtable_index, TRAPS) { | |
66 assert(vtable_index >= 0 || vtable_index == methodOopDesc::nonvirtual_vtable_index, "valid index"); | |
67 set_common(resolved_klass, selected_klass, resolved_method, selected_method, vtable_index, CHECK); | |
68 } | |
69 | |
70 void CallInfo::set_common(KlassHandle resolved_klass, KlassHandle selected_klass, methodHandle resolved_method, methodHandle selected_method, int vtable_index, TRAPS) { | |
71 assert(resolved_method->signature() == selected_method->signature(), "signatures must correspond"); | |
72 _resolved_klass = resolved_klass; | |
73 _selected_klass = selected_klass; | |
74 _resolved_method = resolved_method; | |
75 _selected_method = selected_method; | |
76 _vtable_index = vtable_index; | |
77 if (CompilationPolicy::mustBeCompiled(selected_method)) { | |
1135
e66fd840cb6b
6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents:
1059
diff
changeset
|
78 // This path is unusual, mostly used by the '-Xcomp' stress test mode. |
e66fd840cb6b
6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents:
1059
diff
changeset
|
79 |
0 | 80 // Note: with several active threads, the mustBeCompiled may be true |
81 // while canBeCompiled is false; remove assert | |
82 // assert(CompilationPolicy::canBeCompiled(selected_method), "cannot compile"); | |
83 if (THREAD->is_Compiler_thread()) { | |
84 // don't force compilation, resolve was on behalf of compiler | |
85 return; | |
86 } | |
1135
e66fd840cb6b
6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents:
1059
diff
changeset
|
87 if (instanceKlass::cast(selected_method->method_holder())->is_not_initialized()) { |
e66fd840cb6b
6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents:
1059
diff
changeset
|
88 // 'is_not_initialized' means not only '!is_initialized', but also that |
e66fd840cb6b
6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents:
1059
diff
changeset
|
89 // initialization has not been started yet ('!being_initialized') |
e66fd840cb6b
6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents:
1059
diff
changeset
|
90 // Do not force compilation of methods in uninitialized classes. |
e66fd840cb6b
6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents:
1059
diff
changeset
|
91 // Note that doing this would throw an assert later, |
e66fd840cb6b
6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents:
1059
diff
changeset
|
92 // in CompileBroker::compile_method. |
e66fd840cb6b
6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents:
1059
diff
changeset
|
93 // We sometimes use the link resolver to do reflective lookups |
e66fd840cb6b
6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents:
1059
diff
changeset
|
94 // even before classes are initialized. |
e66fd840cb6b
6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents:
1059
diff
changeset
|
95 return; |
e66fd840cb6b
6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents:
1059
diff
changeset
|
96 } |
0 | 97 CompileBroker::compile_method(selected_method, InvocationEntryBci, |
98 methodHandle(), 0, "mustBeCompiled", CHECK); | |
99 } | |
100 } | |
101 | |
102 | |
103 //------------------------------------------------------------------------------------------------------------------------ | |
104 // Klass resolution | |
105 | |
106 void LinkResolver::check_klass_accessability(KlassHandle ref_klass, KlassHandle sel_klass, TRAPS) { | |
107 if (!Reflection::verify_class_access(ref_klass->as_klassOop(), | |
108 sel_klass->as_klassOop(), | |
109 true)) { | |
110 ResourceMark rm(THREAD); | |
111 Exceptions::fthrow( | |
112 THREAD_AND_LOCATION, | |
113 vmSymbolHandles::java_lang_IllegalAccessError(), | |
114 "tried to access class %s from class %s", | |
115 sel_klass->external_name(), | |
116 ref_klass->external_name() | |
117 ); | |
118 return; | |
119 } | |
120 } | |
121 | |
122 void LinkResolver::resolve_klass(KlassHandle& result, constantPoolHandle pool, int index, TRAPS) { | |
123 klassOop result_oop = pool->klass_ref_at(index, CHECK); | |
124 result = KlassHandle(THREAD, result_oop); | |
125 } | |
126 | |
127 void LinkResolver::resolve_klass_no_update(KlassHandle& result, constantPoolHandle pool, int index, TRAPS) { | |
128 klassOop result_oop = | |
129 constantPoolOopDesc::klass_ref_at_if_loaded_check(pool, index, CHECK); | |
130 result = KlassHandle(THREAD, result_oop); | |
131 } | |
132 | |
133 | |
134 //------------------------------------------------------------------------------------------------------------------------ | |
135 // Method resolution | |
136 // | |
137 // According to JVM spec. $5.4.3c & $5.4.3d | |
138 | |
139 void LinkResolver::lookup_method_in_klasses(methodHandle& result, KlassHandle klass, symbolHandle name, symbolHandle signature, TRAPS) { | |
140 methodOop result_oop = klass->uncached_lookup_method(name(), signature()); | |
141 result = methodHandle(THREAD, result_oop); | |
142 } | |
143 | |
144 // returns first instance method | |
145 void LinkResolver::lookup_instance_method_in_klasses(methodHandle& result, KlassHandle klass, symbolHandle name, symbolHandle signature, TRAPS) { | |
146 methodOop result_oop = klass->uncached_lookup_method(name(), signature()); | |
147 result = methodHandle(THREAD, result_oop); | |
148 while (!result.is_null() && result->is_static()) { | |
149 klass = KlassHandle(THREAD, Klass::cast(result->method_holder())->super()); | |
150 result = methodHandle(THREAD, klass->uncached_lookup_method(name(), signature())); | |
151 } | |
152 } | |
153 | |
154 | |
155 int LinkResolver::vtable_index_of_miranda_method(KlassHandle klass, symbolHandle name, symbolHandle signature, TRAPS) { | |
156 ResourceMark rm(THREAD); | |
157 klassVtable *vt = instanceKlass::cast(klass())->vtable(); | |
158 return vt->index_of_miranda(name(), signature()); | |
159 } | |
160 | |
161 void LinkResolver::lookup_method_in_interfaces(methodHandle& result, KlassHandle klass, symbolHandle name, symbolHandle signature, TRAPS) { | |
162 instanceKlass *ik = instanceKlass::cast(klass()); | |
163 result = methodHandle(THREAD, ik->lookup_method_in_all_interfaces(name(), signature())); | |
164 } | |
165 | |
710 | 166 void LinkResolver::lookup_implicit_method(methodHandle& result, KlassHandle klass, symbolHandle name, symbolHandle signature, TRAPS) { |
167 if (EnableMethodHandles && MethodHandles::enabled() && | |
168 name == vmSymbolHandles::invoke_name() && klass() == SystemDictionary::MethodHandle_klass()) { | |
169 methodOop result_oop = SystemDictionary::find_method_handle_invoke(signature, | |
170 Handle(), | |
171 Handle(), | |
172 CHECK); | |
173 if (result_oop != NULL) { | |
174 assert(result_oop->is_method_handle_invoke() && result_oop->signature() == signature(), "consistent"); | |
175 result = methodHandle(THREAD, result_oop); | |
176 } | |
177 } | |
178 } | |
179 | |
0 | 180 void LinkResolver::check_method_accessability(KlassHandle ref_klass, |
181 KlassHandle resolved_klass, | |
182 KlassHandle sel_klass, | |
183 methodHandle sel_method, | |
184 TRAPS) { | |
185 | |
186 AccessFlags flags = sel_method->access_flags(); | |
187 | |
188 // Special case: arrays always override "clone". JVMS 2.15. | |
189 // If the resolved klass is an array class, and the declaring class | |
190 // is java.lang.Object and the method is "clone", set the flags | |
191 // to public. | |
192 // | |
193 // We'll check for the method name first, as that's most likely | |
194 // to be false (so we'll short-circuit out of these tests). | |
195 if (sel_method->name() == vmSymbols::clone_name() && | |
1142 | 196 sel_klass() == SystemDictionary::Object_klass() && |
0 | 197 resolved_klass->oop_is_array()) { |
198 // We need to change "protected" to "public". | |
199 assert(flags.is_protected(), "clone not protected?"); | |
200 jint new_flags = flags.as_int(); | |
201 new_flags = new_flags & (~JVM_ACC_PROTECTED); | |
202 new_flags = new_flags | JVM_ACC_PUBLIC; | |
203 flags.set_flags(new_flags); | |
204 } | |
205 | |
206 if (!Reflection::verify_field_access(ref_klass->as_klassOop(), | |
207 resolved_klass->as_klassOop(), | |
208 sel_klass->as_klassOop(), | |
209 flags, | |
210 true)) { | |
211 ResourceMark rm(THREAD); | |
212 Exceptions::fthrow( | |
213 THREAD_AND_LOCATION, | |
214 vmSymbolHandles::java_lang_IllegalAccessError(), | |
215 "tried to access method %s.%s%s from class %s", | |
216 sel_klass->external_name(), | |
217 sel_method->name()->as_C_string(), | |
218 sel_method->signature()->as_C_string(), | |
219 ref_klass->external_name() | |
220 ); | |
221 return; | |
222 } | |
223 } | |
224 | |
225 void LinkResolver::resolve_method(methodHandle& resolved_method, KlassHandle& resolved_klass, | |
226 constantPoolHandle pool, int index, TRAPS) { | |
227 | |
228 // resolve klass | |
229 resolve_klass(resolved_klass, pool, index, CHECK); | |
230 | |
231 symbolHandle method_name (THREAD, pool->name_ref_at(index)); | |
232 symbolHandle method_signature (THREAD, pool->signature_ref_at(index)); | |
233 KlassHandle current_klass(THREAD, pool->pool_holder()); | |
234 | |
235 resolve_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, true, CHECK); | |
236 } | |
237 | |
1135
e66fd840cb6b
6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents:
1059
diff
changeset
|
238 void LinkResolver::resolve_dynamic_method(methodHandle& resolved_method, KlassHandle& resolved_klass, constantPoolHandle pool, int index, TRAPS) { |
e66fd840cb6b
6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents:
1059
diff
changeset
|
239 // The class is java.dyn.MethodHandle |
e66fd840cb6b
6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents:
1059
diff
changeset
|
240 resolved_klass = SystemDictionaryHandles::MethodHandle_klass(); |
e66fd840cb6b
6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents:
1059
diff
changeset
|
241 |
e66fd840cb6b
6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents:
1059
diff
changeset
|
242 symbolHandle method_name = vmSymbolHandles::invoke_name(); |
e66fd840cb6b
6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents:
1059
diff
changeset
|
243 |
e66fd840cb6b
6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents:
1059
diff
changeset
|
244 symbolHandle method_signature(THREAD, pool->signature_ref_at(index)); |
e66fd840cb6b
6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents:
1059
diff
changeset
|
245 KlassHandle current_klass (THREAD, pool->pool_holder()); |
e66fd840cb6b
6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents:
1059
diff
changeset
|
246 |
e66fd840cb6b
6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents:
1059
diff
changeset
|
247 resolve_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, true, CHECK); |
e66fd840cb6b
6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents:
1059
diff
changeset
|
248 } |
e66fd840cb6b
6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents:
1059
diff
changeset
|
249 |
0 | 250 void LinkResolver::resolve_interface_method(methodHandle& resolved_method, KlassHandle& resolved_klass, constantPoolHandle pool, int index, TRAPS) { |
251 | |
252 // resolve klass | |
253 resolve_klass(resolved_klass, pool, index, CHECK); | |
254 symbolHandle method_name (THREAD, pool->name_ref_at(index)); | |
255 symbolHandle method_signature (THREAD, pool->signature_ref_at(index)); | |
256 KlassHandle current_klass(THREAD, pool->pool_holder()); | |
257 | |
258 resolve_interface_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, true, CHECK); | |
259 } | |
260 | |
261 | |
262 void LinkResolver::resolve_method(methodHandle& resolved_method, KlassHandle resolved_klass, | |
263 symbolHandle method_name, symbolHandle method_signature, | |
264 KlassHandle current_klass, bool check_access, TRAPS) { | |
265 | |
266 // 1. check if klass is not interface | |
267 if (resolved_klass->is_interface()) { | |
268 char buf[200]; | |
269 jio_snprintf(buf, sizeof(buf), "Found interface %s, but class was expected", Klass::cast(resolved_klass())->external_name()); | |
270 THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf); | |
271 } | |
272 | |
273 // 2. lookup method in resolved klass and its super klasses | |
274 lookup_method_in_klasses(resolved_method, resolved_klass, method_name, method_signature, CHECK); | |
275 | |
276 if (resolved_method.is_null()) { // not found in the class hierarchy | |
277 // 3. lookup method in all the interfaces implemented by the resolved klass | |
278 lookup_method_in_interfaces(resolved_method, resolved_klass, method_name, method_signature, CHECK); | |
279 | |
280 if (resolved_method.is_null()) { | |
710 | 281 // JSR 292: see if this is an implicitly generated method MethodHandle.invoke(*...) |
282 lookup_implicit_method(resolved_method, resolved_klass, method_name, method_signature, CHECK); | |
283 } | |
284 | |
285 if (resolved_method.is_null()) { | |
0 | 286 // 4. method lookup failed |
287 ResourceMark rm(THREAD); | |
288 THROW_MSG(vmSymbols::java_lang_NoSuchMethodError(), | |
289 methodOopDesc::name_and_sig_as_C_string(Klass::cast(resolved_klass()), | |
290 method_name(), | |
291 method_signature())); | |
292 } | |
293 } | |
294 | |
295 // 5. check if method is concrete | |
296 if (resolved_method->is_abstract() && !resolved_klass->is_abstract()) { | |
297 ResourceMark rm(THREAD); | |
298 THROW_MSG(vmSymbols::java_lang_AbstractMethodError(), | |
299 methodOopDesc::name_and_sig_as_C_string(Klass::cast(resolved_klass()), | |
300 method_name(), | |
301 method_signature())); | |
302 } | |
303 | |
304 // 6. access checks, access checking may be turned off when calling from within the VM. | |
305 if (check_access) { | |
306 assert(current_klass.not_null() , "current_klass should not be null"); | |
307 | |
308 // check if method can be accessed by the referring class | |
309 check_method_accessability(current_klass, | |
310 resolved_klass, | |
311 KlassHandle(THREAD, resolved_method->method_holder()), | |
312 resolved_method, | |
313 CHECK); | |
314 | |
315 // check loader constraints | |
316 Handle loader (THREAD, instanceKlass::cast(current_klass())->class_loader()); | |
317 Handle class_loader (THREAD, instanceKlass::cast(resolved_method->method_holder())->class_loader()); | |
318 { | |
319 ResourceMark rm(THREAD); | |
320 char* failed_type_name = | |
321 SystemDictionary::check_signature_loaders(method_signature, loader, | |
322 class_loader, true, CHECK); | |
323 if (failed_type_name != NULL) { | |
324 const char* msg = "loader constraint violation: when resolving method" | |
325 " \"%s\" the class loader (instance of %s) of the current class, %s," | |
326 " and the class loader (instance of %s) for resolved class, %s, have" | |
327 " different Class objects for the type %s used in the signature"; | |
328 char* sig = methodOopDesc::name_and_sig_as_C_string(Klass::cast(resolved_klass()),method_name(),method_signature()); | |
329 const char* loader1 = SystemDictionary::loader_name(loader()); | |
330 char* current = instanceKlass::cast(current_klass())->name()->as_C_string(); | |
331 const char* loader2 = SystemDictionary::loader_name(class_loader()); | |
332 char* resolved = instanceKlass::cast(resolved_klass())->name()->as_C_string(); | |
333 size_t buflen = strlen(msg) + strlen(sig) + strlen(loader1) + | |
334 strlen(current) + strlen(loader2) + strlen(resolved) + | |
335 strlen(failed_type_name); | |
336 char* buf = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, buflen); | |
337 jio_snprintf(buf, buflen, msg, sig, loader1, current, loader2, | |
338 resolved, failed_type_name); | |
339 THROW_MSG(vmSymbols::java_lang_LinkageError(), buf); | |
340 } | |
341 } | |
342 } | |
343 } | |
344 | |
345 void LinkResolver::resolve_interface_method(methodHandle& resolved_method, | |
346 KlassHandle resolved_klass, | |
347 symbolHandle method_name, | |
348 symbolHandle method_signature, | |
349 KlassHandle current_klass, | |
350 bool check_access, TRAPS) { | |
351 | |
352 // check if klass is interface | |
353 if (!resolved_klass->is_interface()) { | |
354 char buf[200]; | |
355 jio_snprintf(buf, sizeof(buf), "Found class %s, but interface was expected", Klass::cast(resolved_klass())->external_name()); | |
356 THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf); | |
357 } | |
358 | |
359 // lookup method in this interface or its super, java.lang.Object | |
360 lookup_instance_method_in_klasses(resolved_method, resolved_klass, method_name, method_signature, CHECK); | |
361 | |
362 if (resolved_method.is_null()) { | |
363 // lookup method in all the super-interfaces | |
364 lookup_method_in_interfaces(resolved_method, resolved_klass, method_name, method_signature, CHECK); | |
365 if (resolved_method.is_null()) { | |
366 // no method found | |
367 ResourceMark rm(THREAD); | |
368 THROW_MSG(vmSymbols::java_lang_NoSuchMethodError(), | |
369 methodOopDesc::name_and_sig_as_C_string(Klass::cast(resolved_klass()), | |
370 method_name(), | |
371 method_signature())); | |
372 } | |
373 } | |
374 | |
375 if (check_access) { | |
376 HandleMark hm(THREAD); | |
377 Handle loader (THREAD, instanceKlass::cast(current_klass())->class_loader()); | |
378 Handle class_loader (THREAD, instanceKlass::cast(resolved_method->method_holder())->class_loader()); | |
379 { | |
380 ResourceMark rm(THREAD); | |
381 char* failed_type_name = | |
382 SystemDictionary::check_signature_loaders(method_signature, loader, | |
383 class_loader, true, CHECK); | |
384 if (failed_type_name != NULL) { | |
385 const char* msg = "loader constraint violation: when resolving " | |
386 "interface method \"%s\" the class loader (instance of %s) of the " | |
387 "current class, %s, and the class loader (instance of %s) for " | |
388 "resolved class, %s, have different Class objects for the type %s " | |
389 "used in the signature"; | |
390 char* sig = methodOopDesc::name_and_sig_as_C_string(Klass::cast(resolved_klass()),method_name(),method_signature()); | |
391 const char* loader1 = SystemDictionary::loader_name(loader()); | |
392 char* current = instanceKlass::cast(current_klass())->name()->as_C_string(); | |
393 const char* loader2 = SystemDictionary::loader_name(class_loader()); | |
394 char* resolved = instanceKlass::cast(resolved_klass())->name()->as_C_string(); | |
395 size_t buflen = strlen(msg) + strlen(sig) + strlen(loader1) + | |
396 strlen(current) + strlen(loader2) + strlen(resolved) + | |
397 strlen(failed_type_name); | |
398 char* buf = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, buflen); | |
399 jio_snprintf(buf, buflen, msg, sig, loader1, current, loader2, | |
400 resolved, failed_type_name); | |
401 THROW_MSG(vmSymbols::java_lang_LinkageError(), buf); | |
402 } | |
403 } | |
404 } | |
405 } | |
406 | |
407 //------------------------------------------------------------------------------------------------------------------------ | |
408 // Field resolution | |
409 | |
410 void LinkResolver::check_field_accessability(KlassHandle ref_klass, | |
411 KlassHandle resolved_klass, | |
412 KlassHandle sel_klass, | |
413 fieldDescriptor& fd, | |
414 TRAPS) { | |
415 if (!Reflection::verify_field_access(ref_klass->as_klassOop(), | |
416 resolved_klass->as_klassOop(), | |
417 sel_klass->as_klassOop(), | |
418 fd.access_flags(), | |
419 true)) { | |
420 ResourceMark rm(THREAD); | |
421 Exceptions::fthrow( | |
422 THREAD_AND_LOCATION, | |
423 vmSymbolHandles::java_lang_IllegalAccessError(), | |
424 "tried to access field %s.%s from class %s", | |
425 sel_klass->external_name(), | |
426 fd.name()->as_C_string(), | |
427 ref_klass->external_name() | |
428 ); | |
429 return; | |
430 } | |
431 } | |
432 | |
433 void LinkResolver::resolve_field(FieldAccessInfo& result, constantPoolHandle pool, int index, Bytecodes::Code byte, bool check_only, TRAPS) { | |
434 resolve_field(result, pool, index, byte, check_only, true, CHECK); | |
435 } | |
436 | |
437 void LinkResolver::resolve_field(FieldAccessInfo& result, constantPoolHandle pool, int index, Bytecodes::Code byte, bool check_only, bool update_pool, TRAPS) { | |
438 assert(byte == Bytecodes::_getstatic || byte == Bytecodes::_putstatic || | |
439 byte == Bytecodes::_getfield || byte == Bytecodes::_putfield, "bad bytecode"); | |
440 | |
441 bool is_static = (byte == Bytecodes::_getstatic || byte == Bytecodes::_putstatic); | |
442 bool is_put = (byte == Bytecodes::_putfield || byte == Bytecodes::_putstatic); | |
443 | |
444 // resolve specified klass | |
445 KlassHandle resolved_klass; | |
446 if (update_pool) { | |
447 resolve_klass(resolved_klass, pool, index, CHECK); | |
448 } else { | |
449 resolve_klass_no_update(resolved_klass, pool, index, CHECK); | |
450 } | |
451 // Load these early in case the resolve of the containing klass fails | |
452 symbolOop field = pool->name_ref_at(index); | |
453 symbolHandle field_h (THREAD, field); // preserve in case we need the name | |
454 symbolOop sig = pool->signature_ref_at(index); | |
455 // Check if there's a resolved klass containing the field | |
456 if( resolved_klass.is_null() ) { | |
457 ResourceMark rm(THREAD); | |
458 THROW_MSG(vmSymbols::java_lang_NoSuchFieldError(), field->as_C_string()); | |
459 } | |
460 | |
461 // Resolve instance field | |
462 fieldDescriptor fd; // find_field initializes fd if found | |
463 KlassHandle sel_klass(THREAD, instanceKlass::cast(resolved_klass())->find_field(field, sig, &fd)); | |
464 // check if field exists; i.e., if a klass containing the field def has been selected | |
465 if (sel_klass.is_null()){ | |
466 ResourceMark rm(THREAD); | |
467 THROW_MSG(vmSymbols::java_lang_NoSuchFieldError(), field->as_C_string()); | |
468 } | |
469 | |
470 // check access | |
471 KlassHandle ref_klass(THREAD, pool->pool_holder()); | |
472 check_field_accessability(ref_klass, resolved_klass, sel_klass, fd, CHECK); | |
473 | |
474 // check for errors | |
475 if (is_static != fd.is_static()) { | |
476 char msg[200]; | |
477 jio_snprintf(msg, sizeof(msg), "Expected %s field %s.%s", is_static ? "static" : "non-static", Klass::cast(resolved_klass())->external_name(), fd.name()->as_C_string()); | |
478 THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), msg); | |
479 } | |
480 | |
481 // Final fields can only be accessed from its own class. | |
482 if (is_put && fd.access_flags().is_final() && sel_klass() != pool->pool_holder()) { | |
483 THROW(vmSymbols::java_lang_IllegalAccessError()); | |
484 } | |
485 | |
486 // initialize resolved_klass if necessary | |
487 // note 1: the klass which declared the field must be initialized (i.e, sel_klass) | |
488 // according to the newest JVM spec (5.5, p.170) - was bug (gri 7/28/99) | |
489 // | |
490 // note 2: we don't want to force initialization if we are just checking | |
491 // if the field access is legal; e.g., during compilation | |
492 if (is_static && !check_only) { | |
493 sel_klass->initialize(CHECK); | |
494 } | |
495 | |
496 { | |
497 HandleMark hm(THREAD); | |
498 Handle ref_loader (THREAD, instanceKlass::cast(ref_klass())->class_loader()); | |
499 Handle sel_loader (THREAD, instanceKlass::cast(sel_klass())->class_loader()); | |
500 symbolHandle signature_ref (THREAD, pool->signature_ref_at(index)); | |
501 { | |
502 ResourceMark rm(THREAD); | |
503 char* failed_type_name = | |
504 SystemDictionary::check_signature_loaders(signature_ref, | |
505 ref_loader, sel_loader, | |
506 false, | |
507 CHECK); | |
508 if (failed_type_name != NULL) { | |
509 const char* msg = "loader constraint violation: when resolving field" | |
510 " \"%s\" the class loader (instance of %s) of the referring class, " | |
511 "%s, and the class loader (instance of %s) for the field's resolved " | |
512 "type, %s, have different Class objects for that type"; | |
513 char* field_name = field_h()->as_C_string(); | |
514 const char* loader1 = SystemDictionary::loader_name(ref_loader()); | |
515 char* sel = instanceKlass::cast(sel_klass())->name()->as_C_string(); | |
516 const char* loader2 = SystemDictionary::loader_name(sel_loader()); | |
517 size_t buflen = strlen(msg) + strlen(field_name) + strlen(loader1) + | |
518 strlen(sel) + strlen(loader2) + strlen(failed_type_name); | |
519 char* buf = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, buflen); | |
520 jio_snprintf(buf, buflen, msg, field_name, loader1, sel, loader2, | |
521 failed_type_name); | |
522 THROW_MSG(vmSymbols::java_lang_LinkageError(), buf); | |
523 } | |
524 } | |
525 } | |
526 | |
527 // return information. note that the klass is set to the actual klass containing the | |
528 // field, otherwise access of static fields in superclasses will not work. | |
529 KlassHandle holder (THREAD, fd.field_holder()); | |
530 symbolHandle name (THREAD, fd.name()); | |
531 result.set(holder, name, fd.index(), fd.offset(), fd.field_type(), fd.access_flags()); | |
532 } | |
533 | |
534 | |
535 //------------------------------------------------------------------------------------------------------------------------ | |
536 // Invoke resolution | |
537 // | |
538 // Naming conventions: | |
539 // | |
540 // resolved_method the specified method (i.e., static receiver specified via constant pool index) | |
541 // sel_method the selected method (selected via run-time lookup; e.g., based on dynamic receiver class) | |
542 // resolved_klass the specified klass (i.e., specified via constant pool index) | |
543 // recv_klass the receiver klass | |
544 | |
545 | |
546 void LinkResolver::resolve_static_call(CallInfo& result, KlassHandle& resolved_klass, symbolHandle method_name, | |
547 symbolHandle method_signature, KlassHandle current_klass, | |
548 bool check_access, bool initialize_class, TRAPS) { | |
549 methodHandle resolved_method; | |
550 linktime_resolve_static_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, check_access, CHECK); | |
551 resolved_klass = KlassHandle(THREAD, Klass::cast(resolved_method->method_holder())); | |
552 | |
553 // Initialize klass (this should only happen if everything is ok) | |
554 if (initialize_class && resolved_klass->should_be_initialized()) { | |
555 resolved_klass->initialize(CHECK); | |
556 linktime_resolve_static_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, check_access, CHECK); | |
557 } | |
558 | |
559 // setup result | |
560 result.set_static(resolved_klass, resolved_method, CHECK); | |
561 } | |
562 | |
563 // throws linktime exceptions | |
564 void LinkResolver::linktime_resolve_static_method(methodHandle& resolved_method, KlassHandle resolved_klass, | |
565 symbolHandle method_name, symbolHandle method_signature, | |
566 KlassHandle current_klass, bool check_access, TRAPS) { | |
567 | |
568 resolve_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, check_access, CHECK); | |
569 assert(resolved_method->name() != vmSymbols::class_initializer_name(), "should have been checked in verifier"); | |
570 | |
571 // check if static | |
572 if (!resolved_method->is_static()) { | |
573 char buf[200]; | |
574 jio_snprintf(buf, sizeof(buf), "Expected static method %s", methodOopDesc::name_and_sig_as_C_string(Klass::cast(resolved_klass()), | |
575 resolved_method->name(), | |
576 resolved_method->signature())); | |
577 THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf); | |
578 } | |
579 } | |
580 | |
581 | |
582 void LinkResolver::resolve_special_call(CallInfo& result, KlassHandle resolved_klass, symbolHandle method_name, | |
583 symbolHandle method_signature, KlassHandle current_klass, bool check_access, TRAPS) { | |
584 methodHandle resolved_method; | |
585 linktime_resolve_special_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, check_access, CHECK); | |
586 runtime_resolve_special_method(result, resolved_method, resolved_klass, current_klass, check_access, CHECK); | |
587 } | |
588 | |
589 // throws linktime exceptions | |
590 void LinkResolver::linktime_resolve_special_method(methodHandle& resolved_method, KlassHandle resolved_klass, | |
591 symbolHandle method_name, symbolHandle method_signature, | |
592 KlassHandle current_klass, bool check_access, TRAPS) { | |
593 | |
594 resolve_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, check_access, CHECK); | |
595 | |
596 // check if method name is <init>, that it is found in same klass as static type | |
597 if (resolved_method->name() == vmSymbols::object_initializer_name() && | |
598 resolved_method->method_holder() != resolved_klass()) { | |
599 ResourceMark rm(THREAD); | |
600 Exceptions::fthrow( | |
601 THREAD_AND_LOCATION, | |
602 vmSymbolHandles::java_lang_NoSuchMethodError(), | |
603 "%s: method %s%s not found", | |
604 resolved_klass->external_name(), | |
605 resolved_method->name()->as_C_string(), | |
606 resolved_method->signature()->as_C_string() | |
607 ); | |
608 return; | |
609 } | |
610 | |
611 // check if not static | |
612 if (resolved_method->is_static()) { | |
613 char buf[200]; | |
614 jio_snprintf(buf, sizeof(buf), | |
615 "Expecting non-static method %s", | |
616 methodOopDesc::name_and_sig_as_C_string(Klass::cast(resolved_klass()), | |
617 resolved_method->name(), | |
618 resolved_method->signature())); | |
619 THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf); | |
620 } | |
621 } | |
622 | |
623 // throws runtime exceptions | |
624 void LinkResolver::runtime_resolve_special_method(CallInfo& result, methodHandle resolved_method, KlassHandle resolved_klass, | |
625 KlassHandle current_klass, bool check_access, TRAPS) { | |
626 | |
627 // resolved method is selected method unless we have an old-style lookup | |
628 methodHandle sel_method(THREAD, resolved_method()); | |
629 | |
630 // check if this is an old-style super call and do a new lookup if so | |
631 { KlassHandle method_klass = KlassHandle(THREAD, | |
632 resolved_method->method_holder()); | |
633 | |
634 if (check_access && | |
635 // a) check if ACC_SUPER flag is set for the current class | |
636 current_klass->is_super() && | |
637 // b) check if the method class is a superclass of the current class (superclass relation is not reflexive!) | |
638 current_klass->is_subtype_of(method_klass()) && current_klass() != method_klass() && | |
639 // c) check if the method is not <init> | |
640 resolved_method->name() != vmSymbols::object_initializer_name()) { | |
641 // Lookup super method | |
642 KlassHandle super_klass(THREAD, current_klass->super()); | |
643 lookup_instance_method_in_klasses(sel_method, super_klass, | |
644 symbolHandle(THREAD, resolved_method->name()), | |
645 symbolHandle(THREAD, resolved_method->signature()), CHECK); | |
646 // check if found | |
647 if (sel_method.is_null()) { | |
648 ResourceMark rm(THREAD); | |
649 THROW_MSG(vmSymbols::java_lang_AbstractMethodError(), | |
650 methodOopDesc::name_and_sig_as_C_string(Klass::cast(resolved_klass()), | |
651 resolved_method->name(), | |
652 resolved_method->signature())); | |
653 } | |
654 } | |
655 } | |
656 | |
657 // check if not static | |
658 if (sel_method->is_static()) { | |
659 char buf[200]; | |
660 jio_snprintf(buf, sizeof(buf), "Expecting non-static method %s", methodOopDesc::name_and_sig_as_C_string(Klass::cast(resolved_klass()), | |
661 resolved_method->name(), | |
662 resolved_method->signature())); | |
663 THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf); | |
664 } | |
665 | |
666 // check if abstract | |
667 if (sel_method->is_abstract()) { | |
668 ResourceMark rm(THREAD); | |
669 THROW_MSG(vmSymbols::java_lang_AbstractMethodError(), | |
670 methodOopDesc::name_and_sig_as_C_string(Klass::cast(resolved_klass()), | |
671 sel_method->name(), | |
672 sel_method->signature())); | |
673 } | |
674 | |
675 // setup result | |
676 result.set_static(resolved_klass, sel_method, CHECK); | |
677 } | |
678 | |
679 void LinkResolver::resolve_virtual_call(CallInfo& result, Handle recv, KlassHandle receiver_klass, KlassHandle resolved_klass, | |
680 symbolHandle method_name, symbolHandle method_signature, KlassHandle current_klass, | |
681 bool check_access, bool check_null_and_abstract, TRAPS) { | |
682 methodHandle resolved_method; | |
683 linktime_resolve_virtual_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, check_access, CHECK); | |
684 runtime_resolve_virtual_method(result, resolved_method, resolved_klass, recv, receiver_klass, check_null_and_abstract, CHECK); | |
685 } | |
686 | |
687 // throws linktime exceptions | |
688 void LinkResolver::linktime_resolve_virtual_method(methodHandle &resolved_method, KlassHandle resolved_klass, | |
689 symbolHandle method_name, symbolHandle method_signature, | |
690 KlassHandle current_klass, bool check_access, TRAPS) { | |
691 // normal method resolution | |
692 resolve_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, check_access, CHECK); | |
693 | |
694 assert(resolved_method->name() != vmSymbols::object_initializer_name(), "should have been checked in verifier"); | |
695 assert(resolved_method->name() != vmSymbols::class_initializer_name (), "should have been checked in verifier"); | |
696 | |
697 // check if not static | |
698 if (resolved_method->is_static()) { | |
699 char buf[200]; | |
700 jio_snprintf(buf, sizeof(buf), "Expecting non-static method %s", methodOopDesc::name_and_sig_as_C_string(Klass::cast(resolved_klass()), | |
701 resolved_method->name(), | |
702 resolved_method->signature())); | |
703 THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf); | |
704 } | |
705 } | |
706 | |
707 // throws runtime exceptions | |
708 void LinkResolver::runtime_resolve_virtual_method(CallInfo& result, | |
709 methodHandle resolved_method, | |
710 KlassHandle resolved_klass, | |
711 Handle recv, | |
712 KlassHandle recv_klass, | |
713 bool check_null_and_abstract, | |
714 TRAPS) { | |
715 | |
716 // setup default return values | |
717 int vtable_index = methodOopDesc::invalid_vtable_index; | |
718 methodHandle selected_method; | |
719 | |
720 assert(recv.is_null() || recv->is_oop(), "receiver is not an oop"); | |
721 | |
722 // runtime method resolution | |
723 if (check_null_and_abstract && recv.is_null()) { // check if receiver exists | |
724 THROW(vmSymbols::java_lang_NullPointerException()); | |
725 } | |
726 | |
727 // Virtual methods cannot be resolved before its klass has been linked, for otherwise the methodOop's | |
728 // has not been rewritten, and the vtable initialized. | |
729 assert(instanceKlass::cast(resolved_method->method_holder())->is_linked(), "must be linked"); | |
730 | |
731 // Virtual methods cannot be resolved before its klass has been linked, for otherwise the methodOop's | |
732 // has not been rewritten, and the vtable initialized. Make sure to do this after the nullcheck, since | |
733 // a missing receiver might result in a bogus lookup. | |
734 assert(instanceKlass::cast(resolved_method->method_holder())->is_linked(), "must be linked"); | |
735 | |
736 // do lookup based on receiver klass using the vtable index | |
737 if (resolved_method->method_holder()->klass_part()->is_interface()) { // miranda method | |
738 vtable_index = vtable_index_of_miranda_method(resolved_klass, | |
739 symbolHandle(THREAD, resolved_method->name()), | |
740 symbolHandle(THREAD, resolved_method->signature()), CHECK); | |
741 assert(vtable_index >= 0 , "we should have valid vtable index at this point"); | |
742 | |
743 instanceKlass* inst = instanceKlass::cast(recv_klass()); | |
744 selected_method = methodHandle(THREAD, inst->method_at_vtable(vtable_index)); | |
745 } else { | |
746 // at this point we are sure that resolved_method is virtual and not | |
747 // a miranda method; therefore, it must have a valid vtable index. | |
748 vtable_index = resolved_method->vtable_index(); | |
749 // We could get a negative vtable_index for final methods, | |
750 // because as an optimization they are they are never put in the vtable, | |
751 // unless they override an existing method. | |
752 // If we do get a negative, it means the resolved method is the the selected | |
753 // method, and it can never be changed by an override. | |
754 if (vtable_index == methodOopDesc::nonvirtual_vtable_index) { | |
755 assert(resolved_method->can_be_statically_bound(), "cannot override this method"); | |
756 selected_method = resolved_method; | |
757 } else { | |
758 // recv_klass might be an arrayKlassOop but all vtables start at | |
759 // the same place. The cast is to avoid virtual call and assertion. | |
760 instanceKlass* inst = (instanceKlass*)recv_klass()->klass_part(); | |
761 selected_method = methodHandle(THREAD, inst->method_at_vtable(vtable_index)); | |
762 } | |
763 } | |
764 | |
765 // check if method exists | |
766 if (selected_method.is_null()) { | |
767 ResourceMark rm(THREAD); | |
768 THROW_MSG(vmSymbols::java_lang_AbstractMethodError(), | |
769 methodOopDesc::name_and_sig_as_C_string(Klass::cast(resolved_klass()), | |
770 resolved_method->name(), | |
771 resolved_method->signature())); | |
772 } | |
773 | |
774 // check if abstract | |
775 if (check_null_and_abstract && selected_method->is_abstract()) { | |
776 ResourceMark rm(THREAD); | |
777 THROW_MSG(vmSymbols::java_lang_AbstractMethodError(), | |
778 methodOopDesc::name_and_sig_as_C_string(Klass::cast(resolved_klass()), | |
779 selected_method->name(), | |
780 selected_method->signature())); | |
781 } | |
782 | |
783 // setup result | |
784 result.set_virtual(resolved_klass, recv_klass, resolved_method, selected_method, vtable_index, CHECK); | |
785 } | |
786 | |
787 void LinkResolver::resolve_interface_call(CallInfo& result, Handle recv, KlassHandle recv_klass, KlassHandle resolved_klass, | |
788 symbolHandle method_name, symbolHandle method_signature, KlassHandle current_klass, | |
789 bool check_access, bool check_null_and_abstract, TRAPS) { | |
790 methodHandle resolved_method; | |
791 linktime_resolve_interface_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, check_access, CHECK); | |
792 runtime_resolve_interface_method(result, resolved_method, resolved_klass, recv, recv_klass, check_null_and_abstract, CHECK); | |
793 } | |
794 | |
795 // throws linktime exceptions | |
796 void LinkResolver::linktime_resolve_interface_method(methodHandle& resolved_method, KlassHandle resolved_klass, symbolHandle method_name, | |
797 symbolHandle method_signature, KlassHandle current_klass, bool check_access, TRAPS) { | |
798 // normal interface method resolution | |
799 resolve_interface_method(resolved_method, resolved_klass, method_name, method_signature, current_klass, check_access, CHECK); | |
800 | |
801 assert(resolved_method->name() != vmSymbols::object_initializer_name(), "should have been checked in verifier"); | |
802 assert(resolved_method->name() != vmSymbols::class_initializer_name (), "should have been checked in verifier"); | |
803 } | |
804 | |
805 // throws runtime exceptions | |
806 void LinkResolver::runtime_resolve_interface_method(CallInfo& result, methodHandle resolved_method, KlassHandle resolved_klass, | |
807 Handle recv, KlassHandle recv_klass, bool check_null_and_abstract, TRAPS) { | |
808 // check if receiver exists | |
809 if (check_null_and_abstract && recv.is_null()) { | |
810 THROW(vmSymbols::java_lang_NullPointerException()); | |
811 } | |
812 | |
813 // check if receiver klass implements the resolved interface | |
814 if (!recv_klass->is_subtype_of(resolved_klass())) { | |
815 char buf[200]; | |
816 jio_snprintf(buf, sizeof(buf), "Class %s does not implement the requested interface %s", | |
817 (Klass::cast(recv_klass()))->external_name(), | |
818 (Klass::cast(resolved_klass()))->external_name()); | |
819 THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf); | |
820 } | |
821 // do lookup based on receiver klass | |
822 methodHandle sel_method; | |
823 lookup_instance_method_in_klasses(sel_method, recv_klass, | |
824 symbolHandle(THREAD, resolved_method->name()), | |
825 symbolHandle(THREAD, resolved_method->signature()), CHECK); | |
826 // check if method exists | |
827 if (sel_method.is_null()) { | |
828 ResourceMark rm(THREAD); | |
829 THROW_MSG(vmSymbols::java_lang_AbstractMethodError(), | |
830 methodOopDesc::name_and_sig_as_C_string(Klass::cast(recv_klass()), | |
831 resolved_method->name(), | |
832 resolved_method->signature())); | |
833 } | |
834 // check if public | |
835 if (!sel_method->is_public()) { | |
836 ResourceMark rm(THREAD); | |
837 THROW_MSG(vmSymbols::java_lang_IllegalAccessError(), | |
838 methodOopDesc::name_and_sig_as_C_string(Klass::cast(recv_klass()), | |
839 sel_method->name(), | |
840 sel_method->signature())); | |
841 } | |
842 // check if abstract | |
843 if (check_null_and_abstract && sel_method->is_abstract()) { | |
844 ResourceMark rm(THREAD); | |
845 THROW_MSG(vmSymbols::java_lang_AbstractMethodError(), | |
846 methodOopDesc::name_and_sig_as_C_string(Klass::cast(recv_klass()), | |
847 sel_method->name(), | |
848 sel_method->signature())); | |
849 } | |
850 // setup result | |
851 result.set_interface(resolved_klass, recv_klass, resolved_method, sel_method, CHECK); | |
852 } | |
853 | |
854 | |
855 methodHandle LinkResolver::linktime_resolve_interface_method_or_null( | |
856 KlassHandle resolved_klass, | |
857 symbolHandle method_name, | |
858 symbolHandle method_signature, | |
859 KlassHandle current_klass, | |
860 bool check_access) { | |
861 EXCEPTION_MARK; | |
862 methodHandle method_result; | |
863 linktime_resolve_interface_method(method_result, resolved_klass, method_name, method_signature, current_klass, check_access, THREAD); | |
864 if (HAS_PENDING_EXCEPTION) { | |
865 CLEAR_PENDING_EXCEPTION; | |
866 return methodHandle(); | |
867 } else { | |
868 return method_result; | |
869 } | |
870 } | |
871 | |
872 methodHandle LinkResolver::linktime_resolve_virtual_method_or_null( | |
873 KlassHandle resolved_klass, | |
874 symbolHandle method_name, | |
875 symbolHandle method_signature, | |
876 KlassHandle current_klass, | |
877 bool check_access) { | |
878 EXCEPTION_MARK; | |
879 methodHandle method_result; | |
880 linktime_resolve_virtual_method(method_result, resolved_klass, method_name, method_signature, current_klass, check_access, THREAD); | |
881 if (HAS_PENDING_EXCEPTION) { | |
882 CLEAR_PENDING_EXCEPTION; | |
883 return methodHandle(); | |
884 } else { | |
885 return method_result; | |
886 } | |
887 } | |
888 | |
889 methodHandle LinkResolver::resolve_virtual_call_or_null( | |
890 KlassHandle receiver_klass, | |
891 KlassHandle resolved_klass, | |
892 symbolHandle name, | |
893 symbolHandle signature, | |
894 KlassHandle current_klass) { | |
895 EXCEPTION_MARK; | |
896 CallInfo info; | |
897 resolve_virtual_call(info, Handle(), receiver_klass, resolved_klass, name, signature, current_klass, true, false, THREAD); | |
898 if (HAS_PENDING_EXCEPTION) { | |
899 CLEAR_PENDING_EXCEPTION; | |
900 return methodHandle(); | |
901 } | |
902 return info.selected_method(); | |
903 } | |
904 | |
905 methodHandle LinkResolver::resolve_interface_call_or_null( | |
906 KlassHandle receiver_klass, | |
907 KlassHandle resolved_klass, | |
908 symbolHandle name, | |
909 symbolHandle signature, | |
910 KlassHandle current_klass) { | |
911 EXCEPTION_MARK; | |
912 CallInfo info; | |
913 resolve_interface_call(info, Handle(), receiver_klass, resolved_klass, name, signature, current_klass, true, false, THREAD); | |
914 if (HAS_PENDING_EXCEPTION) { | |
915 CLEAR_PENDING_EXCEPTION; | |
916 return methodHandle(); | |
917 } | |
918 return info.selected_method(); | |
919 } | |
920 | |
921 int LinkResolver::resolve_virtual_vtable_index( | |
922 KlassHandle receiver_klass, | |
923 KlassHandle resolved_klass, | |
924 symbolHandle name, | |
925 symbolHandle signature, | |
926 KlassHandle current_klass) { | |
927 EXCEPTION_MARK; | |
928 CallInfo info; | |
929 resolve_virtual_call(info, Handle(), receiver_klass, resolved_klass, name, signature, current_klass, true, false, THREAD); | |
930 if (HAS_PENDING_EXCEPTION) { | |
931 CLEAR_PENDING_EXCEPTION; | |
932 return methodOopDesc::invalid_vtable_index; | |
933 } | |
934 return info.vtable_index(); | |
935 } | |
936 | |
937 methodHandle LinkResolver::resolve_static_call_or_null( | |
938 KlassHandle resolved_klass, | |
939 symbolHandle name, | |
940 symbolHandle signature, | |
941 KlassHandle current_klass) { | |
942 EXCEPTION_MARK; | |
943 CallInfo info; | |
944 resolve_static_call(info, resolved_klass, name, signature, current_klass, true, false, THREAD); | |
945 if (HAS_PENDING_EXCEPTION) { | |
946 CLEAR_PENDING_EXCEPTION; | |
947 return methodHandle(); | |
948 } | |
949 return info.selected_method(); | |
950 } | |
951 | |
952 methodHandle LinkResolver::resolve_special_call_or_null(KlassHandle resolved_klass, symbolHandle name, symbolHandle signature, | |
953 KlassHandle current_klass) { | |
954 EXCEPTION_MARK; | |
955 CallInfo info; | |
956 resolve_special_call(info, resolved_klass, name, signature, current_klass, true, THREAD); | |
957 if (HAS_PENDING_EXCEPTION) { | |
958 CLEAR_PENDING_EXCEPTION; | |
959 return methodHandle(); | |
960 } | |
961 return info.selected_method(); | |
962 } | |
963 | |
964 | |
965 | |
966 //------------------------------------------------------------------------------------------------------------------------ | |
967 // ConstantPool entries | |
968 | |
969 void LinkResolver::resolve_invoke(CallInfo& result, Handle recv, constantPoolHandle pool, int index, Bytecodes::Code byte, TRAPS) { | |
970 switch (byte) { | |
971 case Bytecodes::_invokestatic : resolve_invokestatic (result, pool, index, CHECK); break; | |
972 case Bytecodes::_invokespecial : resolve_invokespecial (result, pool, index, CHECK); break; | |
973 case Bytecodes::_invokevirtual : resolve_invokevirtual (result, recv, pool, index, CHECK); break; | |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
710
diff
changeset
|
974 case Bytecodes::_invokedynamic : resolve_invokedynamic (result, pool, index, CHECK); break; |
0 | 975 case Bytecodes::_invokeinterface: resolve_invokeinterface(result, recv, pool, index, CHECK); break; |
976 } | |
977 return; | |
978 } | |
979 | |
980 void LinkResolver::resolve_pool(KlassHandle& resolved_klass, symbolHandle& method_name, symbolHandle& method_signature, | |
981 KlassHandle& current_klass, constantPoolHandle pool, int index, TRAPS) { | |
982 // resolve klass | |
983 resolve_klass(resolved_klass, pool, index, CHECK); | |
984 | |
985 // Get name, signature, and static klass | |
986 method_name = symbolHandle(THREAD, pool->name_ref_at(index)); | |
987 method_signature = symbolHandle(THREAD, pool->signature_ref_at(index)); | |
988 current_klass = KlassHandle(THREAD, pool->pool_holder()); | |
989 } | |
990 | |
991 | |
992 void LinkResolver::resolve_invokestatic(CallInfo& result, constantPoolHandle pool, int index, TRAPS) { | |
993 KlassHandle resolved_klass; | |
994 symbolHandle method_name; | |
995 symbolHandle method_signature; | |
996 KlassHandle current_klass; | |
997 resolve_pool(resolved_klass, method_name, method_signature, current_klass, pool, index, CHECK); | |
998 resolve_static_call(result, resolved_klass, method_name, method_signature, current_klass, true, true, CHECK); | |
999 } | |
1000 | |
1001 | |
1002 void LinkResolver::resolve_invokespecial(CallInfo& result, constantPoolHandle pool, int index, TRAPS) { | |
1003 KlassHandle resolved_klass; | |
1004 symbolHandle method_name; | |
1005 symbolHandle method_signature; | |
1006 KlassHandle current_klass; | |
1007 resolve_pool(resolved_klass, method_name, method_signature, current_klass, pool, index, CHECK); | |
1008 resolve_special_call(result, resolved_klass, method_name, method_signature, current_klass, true, CHECK); | |
1009 } | |
1010 | |
1011 | |
1012 void LinkResolver::resolve_invokevirtual(CallInfo& result, Handle recv, | |
1013 constantPoolHandle pool, int index, | |
1014 TRAPS) { | |
1015 | |
1016 KlassHandle resolved_klass; | |
1017 symbolHandle method_name; | |
1018 symbolHandle method_signature; | |
1019 KlassHandle current_klass; | |
1020 resolve_pool(resolved_klass, method_name, method_signature, current_klass, pool, index, CHECK); | |
1021 KlassHandle recvrKlass (THREAD, recv.is_null() ? (klassOop)NULL : recv->klass()); | |
1022 resolve_virtual_call(result, recv, recvrKlass, resolved_klass, method_name, method_signature, current_klass, true, true, CHECK); | |
1023 } | |
1024 | |
1025 | |
1026 void LinkResolver::resolve_invokeinterface(CallInfo& result, Handle recv, constantPoolHandle pool, int index, TRAPS) { | |
1027 KlassHandle resolved_klass; | |
1028 symbolHandle method_name; | |
1029 symbolHandle method_signature; | |
1030 KlassHandle current_klass; | |
1031 resolve_pool(resolved_klass, method_name, method_signature, current_klass, pool, index, CHECK); | |
1032 KlassHandle recvrKlass (THREAD, recv.is_null() ? (klassOop)NULL : recv->klass()); | |
1033 resolve_interface_call(result, recv, recvrKlass, resolved_klass, method_name, method_signature, current_klass, true, true, CHECK); | |
1034 } | |
1035 | |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
710
diff
changeset
|
1036 |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
710
diff
changeset
|
1037 void LinkResolver::resolve_invokedynamic(CallInfo& result, constantPoolHandle pool, int raw_index, TRAPS) { |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
710
diff
changeset
|
1038 assert(EnableInvokeDynamic, ""); |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
710
diff
changeset
|
1039 |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
710
diff
changeset
|
1040 // This guy is reached from InterpreterRuntime::resolve_invokedynamic. |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
710
diff
changeset
|
1041 |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
710
diff
changeset
|
1042 // At this point, we only need the signature, and can ignore the name. |
1059
389049f3f393
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
726
diff
changeset
|
1043 symbolHandle method_signature(THREAD, pool->signature_ref_at(raw_index)); // raw_index works directly |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
710
diff
changeset
|
1044 symbolHandle method_name = vmSymbolHandles::invoke_name(); |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
710
diff
changeset
|
1045 KlassHandle resolved_klass = SystemDictionaryHandles::MethodHandle_klass(); |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
710
diff
changeset
|
1046 |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
710
diff
changeset
|
1047 // JSR 292: this must be an implicitly generated method MethodHandle.invoke(*...) |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
710
diff
changeset
|
1048 // The extra MH receiver will be inserted into the stack on every call. |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
710
diff
changeset
|
1049 methodHandle resolved_method; |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
710
diff
changeset
|
1050 lookup_implicit_method(resolved_method, resolved_klass, method_name, method_signature, CHECK); |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
710
diff
changeset
|
1051 if (resolved_method.is_null()) { |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
710
diff
changeset
|
1052 THROW(vmSymbols::java_lang_InternalError()); |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
710
diff
changeset
|
1053 } |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
710
diff
changeset
|
1054 result.set_virtual(resolved_klass, KlassHandle(), resolved_method, resolved_method, resolved_method->vtable_index(), CHECK); |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
710
diff
changeset
|
1055 } |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
710
diff
changeset
|
1056 |
0 | 1057 //------------------------------------------------------------------------------------------------------------------------ |
1058 #ifndef PRODUCT | |
1059 | |
1060 void FieldAccessInfo::print() { | |
1061 ResourceMark rm; | |
1062 tty->print_cr("Field %s@%d", name()->as_C_string(), field_offset()); | |
1063 } | |
1064 | |
1065 #endif |