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