Mercurial > hg > graal-compiler
comparison src/share/vm/oops/klassVtable.cpp @ 13102:f9f4503a4ab5
Merge
author | Christos Kotselidis <christos.kotselidis@oracle.com> |
---|---|
date | Thu, 21 Nov 2013 15:04:54 +0100 |
parents | fce21ac5968d |
children | 9d15b81d5d1b |
comparison
equal
deleted
inserted
replaced
13101:790ebab62d23 | 13102:f9f4503a4ab5 |
---|---|
81 } | 81 } |
82 } | 82 } |
83 | 83 |
84 GrowableArray<Method*> new_mirandas(20); | 84 GrowableArray<Method*> new_mirandas(20); |
85 // compute the number of mirandas methods that must be added to the end | 85 // compute the number of mirandas methods that must be added to the end |
86 get_mirandas(&new_mirandas, all_mirandas, super, methods, local_interfaces); | 86 get_mirandas(&new_mirandas, all_mirandas, super, methods, NULL, local_interfaces); |
87 *num_new_mirandas = new_mirandas.length(); | 87 *num_new_mirandas = new_mirandas.length(); |
88 | 88 |
89 vtable_length += *num_new_mirandas * vtableEntry::size(); | 89 // Interfaces do not need interface methods in their vtables |
90 // This includes miranda methods and during later processing, default methods | |
91 if (!class_flags.is_interface()) { | |
92 vtable_length += *num_new_mirandas * vtableEntry::size(); | |
93 } | |
90 | 94 |
91 if (Universe::is_bootstrapping() && vtable_length == 0) { | 95 if (Universe::is_bootstrapping() && vtable_length == 0) { |
92 // array classes don't have their superclass set correctly during | 96 // array classes don't have their superclass set correctly during |
93 // bootstrapping | 97 // bootstrapping |
94 vtable_length = Universe::base_vtable_size(); | 98 vtable_length = Universe::base_vtable_size(); |
184 // update_inherited_vtable can stop for gc - ensure using handles | 188 // update_inherited_vtable can stop for gc - ensure using handles |
185 HandleMark hm(THREAD); | 189 HandleMark hm(THREAD); |
186 assert(methods->at(i)->is_method(), "must be a Method*"); | 190 assert(methods->at(i)->is_method(), "must be a Method*"); |
187 methodHandle mh(THREAD, methods->at(i)); | 191 methodHandle mh(THREAD, methods->at(i)); |
188 | 192 |
189 bool needs_new_entry = update_inherited_vtable(ik(), mh, super_vtable_len, checkconstraints, CHECK); | 193 bool needs_new_entry = update_inherited_vtable(ik(), mh, super_vtable_len, -1, checkconstraints, CHECK); |
190 | 194 |
191 if (needs_new_entry) { | 195 if (needs_new_entry) { |
192 put_method_at(mh(), initialized); | 196 put_method_at(mh(), initialized); |
193 mh()->set_vtable_index(initialized); // set primary vtable index | 197 mh()->set_vtable_index(initialized); // set primary vtable index |
194 initialized++; | 198 initialized++; |
195 } | 199 } |
196 } | 200 } |
197 | 201 |
198 // add miranda methods to end of vtable. | 202 // update vtable with default_methods |
199 initialized = fill_in_mirandas(initialized); | 203 Array<Method*>* default_methods = ik()->default_methods(); |
204 if (default_methods != NULL) { | |
205 len = default_methods->length(); | |
206 if (len > 0) { | |
207 Array<int>* def_vtable_indices = NULL; | |
208 if ((def_vtable_indices = ik()->default_vtable_indices()) == NULL) { | |
209 def_vtable_indices = ik()->create_new_default_vtable_indices(len, CHECK); | |
210 } else { | |
211 assert(def_vtable_indices->length() == len, "reinit vtable len?"); | |
212 } | |
213 for (int i = 0; i < len; i++) { | |
214 HandleMark hm(THREAD); | |
215 assert(default_methods->at(i)->is_method(), "must be a Method*"); | |
216 methodHandle mh(THREAD, default_methods->at(i)); | |
217 | |
218 bool needs_new_entry = update_inherited_vtable(ik(), mh, super_vtable_len, i, checkconstraints, CHECK); | |
219 | |
220 // needs new entry | |
221 if (needs_new_entry) { | |
222 put_method_at(mh(), initialized); | |
223 def_vtable_indices->at_put(i, initialized); //set vtable index | |
224 initialized++; | |
225 } | |
226 } | |
227 } | |
228 } | |
229 | |
230 // add miranda methods; it will also return the updated initialized | |
231 // Interfaces do not need interface methods in their vtables | |
232 // This includes miranda methods and during later processing, default methods | |
233 if (!ik()->is_interface()) { | |
234 initialized = fill_in_mirandas(initialized); | |
235 } | |
200 | 236 |
201 // In class hierarchies where the accessibility is not increasing (i.e., going from private -> | 237 // In class hierarchies where the accessibility is not increasing (i.e., going from private -> |
202 // package_private -> public/protected), the vtable might actually be smaller than our initial | 238 // package_private -> public/protected), the vtable might actually be smaller than our initial |
203 // calculation. | 239 // calculation. |
204 assert(initialized <= _length, "vtable initialization failed"); | 240 assert(initialized <= _length, "vtable initialization failed"); |
228 #endif | 264 #endif |
229 if (supersuperklass->is_override(super_method, target_loader, target_classname, THREAD)) { | 265 if (supersuperklass->is_override(super_method, target_loader, target_classname, THREAD)) { |
230 #ifndef PRODUCT | 266 #ifndef PRODUCT |
231 if (PrintVtables && Verbose) { | 267 if (PrintVtables && Verbose) { |
232 ResourceMark rm(THREAD); | 268 ResourceMark rm(THREAD); |
269 char* sig = target_method()->name_and_sig_as_C_string(); | |
233 tty->print("transitive overriding superclass %s with %s::%s index %d, original flags: ", | 270 tty->print("transitive overriding superclass %s with %s::%s index %d, original flags: ", |
234 supersuperklass->internal_name(), | 271 supersuperklass->internal_name(), |
235 _klass->internal_name(), (target_method() != NULL) ? | 272 _klass->internal_name(), sig, vtable_index); |
236 target_method()->name()->as_C_string() : "<NULL>", vtable_index); | |
237 super_method->access_flags().print_on(tty); | 273 super_method->access_flags().print_on(tty); |
274 if (super_method->is_default_method()) { | |
275 tty->print("default "); | |
276 } | |
238 tty->print("overriders flags: "); | 277 tty->print("overriders flags: "); |
239 target_method->access_flags().print_on(tty); | 278 target_method->access_flags().print_on(tty); |
240 tty->cr(); | 279 if (target_method->is_default_method()) { |
280 tty->print("default "); | |
281 } | |
241 } | 282 } |
242 #endif /*PRODUCT*/ | 283 #endif /*PRODUCT*/ |
243 break; // return found superk | 284 break; // return found superk |
244 } | 285 } |
245 } else { | 286 } else { |
256 | 297 |
257 // Update child's copy of super vtable for overrides | 298 // Update child's copy of super vtable for overrides |
258 // OR return true if a new vtable entry is required. | 299 // OR return true if a new vtable entry is required. |
259 // Only called for InstanceKlass's, i.e. not for arrays | 300 // Only called for InstanceKlass's, i.e. not for arrays |
260 // If that changed, could not use _klass as handle for klass | 301 // If that changed, could not use _klass as handle for klass |
261 bool klassVtable::update_inherited_vtable(InstanceKlass* klass, methodHandle target_method, int super_vtable_len, | 302 bool klassVtable::update_inherited_vtable(InstanceKlass* klass, methodHandle target_method, |
262 bool checkconstraints, TRAPS) { | 303 int super_vtable_len, int default_index, |
304 bool checkconstraints, TRAPS) { | |
263 ResourceMark rm; | 305 ResourceMark rm; |
264 bool allocate_new = true; | 306 bool allocate_new = true; |
265 assert(klass->oop_is_instance(), "must be InstanceKlass"); | 307 assert(klass->oop_is_instance(), "must be InstanceKlass"); |
266 assert(klass == target_method()->method_holder(), "caller resp."); | 308 |
267 | 309 Array<int>* def_vtable_indices = NULL; |
268 // Initialize the method's vtable index to "nonvirtual". | 310 bool is_default = false; |
269 // If we allocate a vtable entry, we will update it to a non-negative number. | 311 // default methods are concrete methods in superinterfaces which are added to the vtable |
270 target_method()->set_vtable_index(Method::nonvirtual_vtable_index); | 312 // with their real method_holder |
313 // Since vtable and itable indices share the same storage, don't touch | |
314 // the default method's real vtable/itable index | |
315 // default_vtable_indices stores the vtable value relative to this inheritor | |
316 if (default_index >= 0 ) { | |
317 is_default = true; | |
318 def_vtable_indices = klass->default_vtable_indices(); | |
319 assert(def_vtable_indices != NULL, "def vtable alloc?"); | |
320 assert(default_index <= def_vtable_indices->length(), "def vtable len?"); | |
321 } else { | |
322 assert(klass == target_method()->method_holder(), "caller resp."); | |
323 // Initialize the method's vtable index to "nonvirtual". | |
324 // If we allocate a vtable entry, we will update it to a non-negative number. | |
325 target_method()->set_vtable_index(Method::nonvirtual_vtable_index); | |
326 } | |
271 | 327 |
272 // Static and <init> methods are never in | 328 // Static and <init> methods are never in |
273 if (target_method()->is_static() || target_method()->name() == vmSymbols::object_initializer_name()) { | 329 if (target_method()->is_static() || target_method()->name() == vmSymbols::object_initializer_name()) { |
274 return false; | 330 return false; |
275 } | 331 } |
282 } else if (klass->is_interface()) { | 338 } else if (klass->is_interface()) { |
283 allocate_new = false; // see note below in needs_new_vtable_entry | 339 allocate_new = false; // see note below in needs_new_vtable_entry |
284 // An interface never allocates new vtable slots, only inherits old ones. | 340 // An interface never allocates new vtable slots, only inherits old ones. |
285 // This method will either be assigned its own itable index later, | 341 // This method will either be assigned its own itable index later, |
286 // or be assigned an inherited vtable index in the loop below. | 342 // or be assigned an inherited vtable index in the loop below. |
287 target_method()->set_vtable_index(Method::pending_itable_index); | 343 // default methods inherited by classes store their vtable indices |
344 // in the inheritor's default_vtable_indices | |
345 // default methods inherited by interfaces may already have a | |
346 // valid itable index, if so, don't change it | |
347 // overpass methods in an interface will be assigned an itable index later | |
348 // by an inheriting class | |
349 if (!is_default || !target_method()->has_itable_index()) { | |
350 target_method()->set_vtable_index(Method::pending_itable_index); | |
351 } | |
288 } | 352 } |
289 | 353 |
290 // we need a new entry if there is no superclass | 354 // we need a new entry if there is no superclass |
291 if (klass->super() == NULL) { | 355 if (klass->super() == NULL) { |
292 return allocate_new; | 356 return allocate_new; |
305 // which can block for gc, once we are in this loop, use handles | 369 // which can block for gc, once we are in this loop, use handles |
306 // For classfiles built with >= jdk7, we now look for transitive overrides | 370 // For classfiles built with >= jdk7, we now look for transitive overrides |
307 | 371 |
308 Symbol* name = target_method()->name(); | 372 Symbol* name = target_method()->name(); |
309 Symbol* signature = target_method()->signature(); | 373 Symbol* signature = target_method()->signature(); |
310 Handle target_loader(THREAD, _klass()->class_loader()); | 374 |
311 Symbol* target_classname = _klass->name(); | 375 KlassHandle target_klass(THREAD, target_method()->method_holder()); |
376 if (target_klass == NULL) { | |
377 target_klass = _klass; | |
378 } | |
379 | |
380 Handle target_loader(THREAD, target_klass->class_loader()); | |
381 | |
382 Symbol* target_classname = target_klass->name(); | |
312 for(int i = 0; i < super_vtable_len; i++) { | 383 for(int i = 0; i < super_vtable_len; i++) { |
313 Method* super_method = method_at(i); | 384 Method* super_method = method_at(i); |
314 // Check if method name matches | 385 // Check if method name matches |
315 if (super_method->name() == name && super_method->signature() == signature) { | 386 if (super_method->name() == name && super_method->signature() == signature) { |
316 | 387 |
317 // get super_klass for method_holder for the found method | 388 // get super_klass for method_holder for the found method |
318 InstanceKlass* super_klass = super_method->method_holder(); | 389 InstanceKlass* super_klass = super_method->method_holder(); |
319 | 390 |
320 if ((super_klass->is_override(super_method, target_loader, target_classname, THREAD)) || | 391 if (is_default |
321 ((klass->major_version() >= VTABLE_TRANSITIVE_OVERRIDE_VERSION) | 392 || ((super_klass->is_override(super_method, target_loader, target_classname, THREAD)) |
322 && ((super_klass = find_transitive_override(super_klass, target_method, i, target_loader, | 393 || ((klass->major_version() >= VTABLE_TRANSITIVE_OVERRIDE_VERSION) |
323 target_classname, THREAD)) != (InstanceKlass*)NULL))) { | 394 && ((super_klass = find_transitive_override(super_klass, |
395 target_method, i, target_loader, | |
396 target_classname, THREAD)) | |
397 != (InstanceKlass*)NULL)))) | |
398 { | |
324 // overriding, so no new entry | 399 // overriding, so no new entry |
325 allocate_new = false; | 400 allocate_new = false; |
326 | 401 |
327 if (checkconstraints) { | 402 if (checkconstraints) { |
328 // Override vtable entry if passes loader constraint check | 403 // Override vtable entry if passes loader constraint check |
345 " of %s) of the current class, %s, and its superclass loader " | 420 " of %s) of the current class, %s, and its superclass loader " |
346 "(instance of %s), have different Class objects for the type " | 421 "(instance of %s), have different Class objects for the type " |
347 "%s used in the signature"; | 422 "%s used in the signature"; |
348 char* sig = target_method()->name_and_sig_as_C_string(); | 423 char* sig = target_method()->name_and_sig_as_C_string(); |
349 const char* loader1 = SystemDictionary::loader_name(target_loader()); | 424 const char* loader1 = SystemDictionary::loader_name(target_loader()); |
350 char* current = _klass->name()->as_C_string(); | 425 char* current = target_klass->name()->as_C_string(); |
351 const char* loader2 = SystemDictionary::loader_name(super_loader()); | 426 const char* loader2 = SystemDictionary::loader_name(super_loader()); |
352 char* failed_type_name = failed_type_symbol->as_C_string(); | 427 char* failed_type_name = failed_type_symbol->as_C_string(); |
353 size_t buflen = strlen(msg) + strlen(sig) + strlen(loader1) + | 428 size_t buflen = strlen(msg) + strlen(sig) + strlen(loader1) + |
354 strlen(current) + strlen(loader2) + strlen(failed_type_name); | 429 strlen(current) + strlen(loader2) + strlen(failed_type_name); |
355 char* buf = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, buflen); | 430 char* buf = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, buflen); |
358 THROW_MSG_(vmSymbols::java_lang_LinkageError(), buf, false); | 433 THROW_MSG_(vmSymbols::java_lang_LinkageError(), buf, false); |
359 } | 434 } |
360 } | 435 } |
361 } | 436 } |
362 | 437 |
363 put_method_at(target_method(), i); | 438 put_method_at(target_method(), i); |
364 target_method()->set_vtable_index(i); | 439 if (!is_default) { |
440 target_method()->set_vtable_index(i); | |
441 } else { | |
442 if (def_vtable_indices != NULL) { | |
443 def_vtable_indices->at_put(default_index, i); | |
444 } | |
445 assert(super_method->is_default_method() || super_method->is_overpass() | |
446 || super_method->is_abstract(), "default override error"); | |
447 } | |
448 | |
449 | |
365 #ifndef PRODUCT | 450 #ifndef PRODUCT |
366 if (PrintVtables && Verbose) { | 451 if (PrintVtables && Verbose) { |
452 ResourceMark rm(THREAD); | |
453 char* sig = target_method()->name_and_sig_as_C_string(); | |
367 tty->print("overriding with %s::%s index %d, original flags: ", | 454 tty->print("overriding with %s::%s index %d, original flags: ", |
368 _klass->internal_name(), (target_method() != NULL) ? | 455 target_klass->internal_name(), sig, i); |
369 target_method()->name()->as_C_string() : "<NULL>", i); | |
370 super_method->access_flags().print_on(tty); | 456 super_method->access_flags().print_on(tty); |
457 if (super_method->is_default_method()) { | |
458 tty->print("default "); | |
459 } | |
460 if (super_method->is_overpass()) { | |
461 tty->print("overpass"); | |
462 } | |
371 tty->print("overriders flags: "); | 463 tty->print("overriders flags: "); |
372 target_method->access_flags().print_on(tty); | 464 target_method->access_flags().print_on(tty); |
465 if (target_method->is_default_method()) { | |
466 tty->print("default "); | |
467 } | |
468 if (target_method->is_overpass()) { | |
469 tty->print("overpass"); | |
470 } | |
373 tty->cr(); | 471 tty->cr(); |
374 } | 472 } |
375 #endif /*PRODUCT*/ | 473 #endif /*PRODUCT*/ |
376 } else { | 474 } else { |
377 // allocate_new = true; default. We might override one entry, | 475 // allocate_new = true; default. We might override one entry, |
378 // but not override another. Once we override one, not need new | 476 // but not override another. Once we override one, not need new |
379 #ifndef PRODUCT | 477 #ifndef PRODUCT |
380 if (PrintVtables && Verbose) { | 478 if (PrintVtables && Verbose) { |
479 ResourceMark rm(THREAD); | |
480 char* sig = target_method()->name_and_sig_as_C_string(); | |
381 tty->print("NOT overriding with %s::%s index %d, original flags: ", | 481 tty->print("NOT overriding with %s::%s index %d, original flags: ", |
382 _klass->internal_name(), (target_method() != NULL) ? | 482 target_klass->internal_name(), sig,i); |
383 target_method()->name()->as_C_string() : "<NULL>", i); | |
384 super_method->access_flags().print_on(tty); | 483 super_method->access_flags().print_on(tty); |
484 if (super_method->is_default_method()) { | |
485 tty->print("default "); | |
486 } | |
487 if (super_method->is_overpass()) { | |
488 tty->print("overpass"); | |
489 } | |
385 tty->print("overriders flags: "); | 490 tty->print("overriders flags: "); |
386 target_method->access_flags().print_on(tty); | 491 target_method->access_flags().print_on(tty); |
492 if (target_method->is_default_method()) { | |
493 tty->print("default "); | |
494 } | |
495 if (target_method->is_overpass()) { | |
496 tty->print("overpass"); | |
497 } | |
387 tty->cr(); | 498 tty->cr(); |
388 } | 499 } |
389 #endif /*PRODUCT*/ | 500 #endif /*PRODUCT*/ |
390 } | 501 } |
391 } | 502 } |
395 | 506 |
396 void klassVtable::put_method_at(Method* m, int index) { | 507 void klassVtable::put_method_at(Method* m, int index) { |
397 #ifndef PRODUCT | 508 #ifndef PRODUCT |
398 if (PrintVtables && Verbose) { | 509 if (PrintVtables && Verbose) { |
399 ResourceMark rm; | 510 ResourceMark rm; |
400 tty->print_cr("adding %s::%s at index %d", _klass->internal_name(), | 511 const char* sig = (m != NULL) ? m->name_and_sig_as_C_string() : "<NULL>"; |
401 (m != NULL) ? m->name()->as_C_string() : "<NULL>", index); | 512 tty->print("adding %s at index %d, flags: ", sig, index); |
513 if (m != NULL) { | |
514 m->access_flags().print_on(tty); | |
515 if (m->is_default_method()) { | |
516 tty->print("default "); | |
517 } | |
518 if (m->is_overpass()) { | |
519 tty->print("overpass"); | |
520 } | |
521 } | |
522 tty->cr(); | |
402 } | 523 } |
403 #endif | 524 #endif |
404 table()[index].set(m); | 525 table()[index].set(m); |
405 } | 526 } |
406 | 527 |
436 // <init> is never called dynamically-bound | 557 // <init> is never called dynamically-bound |
437 ) { | 558 ) { |
438 return false; | 559 return false; |
439 } | 560 } |
440 | 561 |
562 // Concrete interface methods do not need new entries, they override | |
563 // abstract method entries using default inheritance rules | |
564 if (target_method()->method_holder() != NULL && | |
565 target_method()->method_holder()->is_interface() && | |
566 !target_method()->is_abstract() ) { | |
567 return false; | |
568 } | |
569 | |
441 // we need a new entry if there is no superclass | 570 // we need a new entry if there is no superclass |
442 if (super == NULL) { | 571 if (super == NULL) { |
443 return true; | 572 return true; |
444 } | 573 } |
445 | 574 |
446 // private methods in classes always have a new entry in the vtable | 575 // private methods in classes always have a new entry in the vtable |
447 // specification interpretation since classic has | 576 // specification interpretation since classic has |
448 // private methods not overriding | 577 // private methods not overriding |
449 // JDK8 adds private methods in interfaces which require invokespecial | 578 // JDK8 adds private methods in interfaces which require invokespecial |
450 if (target_method()->is_private()) { | 579 if (target_method()->is_private()) { |
451 return true; | 580 return true; |
452 } | 581 } |
453 | 582 |
454 // search through the super class hierarchy to see if we need | 583 // search through the super class hierarchy to see if we need |
524 | 653 |
525 // miranda methods are public abstract instance interface methods in a class's vtable | 654 // miranda methods are public abstract instance interface methods in a class's vtable |
526 if (mhk->is_interface()) { | 655 if (mhk->is_interface()) { |
527 assert(m->is_public(), "should be public"); | 656 assert(m->is_public(), "should be public"); |
528 assert(ik()->implements_interface(method_holder) , "this class should implement the interface"); | 657 assert(ik()->implements_interface(method_holder) , "this class should implement the interface"); |
529 assert(is_miranda(m, ik()->methods(), ik()->super()), "should be a miranda_method"); | 658 // the search could find a miranda or a default method |
530 return true; | 659 if (is_miranda(m, ik()->methods(), ik()->default_methods(), ik()->super())) { |
660 return true; | |
661 } | |
531 } | 662 } |
532 return false; | 663 return false; |
533 } | 664 } |
534 | 665 |
535 // check if a method is a miranda method, given a class's methods table and its super | 666 // check if a method is a miranda method, given a class's methods table, |
536 // "miranda" means not static, not defined by this class, and not defined | 667 // its default_method table and its super |
537 // in super unless it is private and therefore inaccessible to this class. | 668 // "miranda" means not static, not defined by this class. |
669 // private methods in interfaces do not belong in the miranda list. | |
538 // the caller must make sure that the method belongs to an interface implemented by the class | 670 // the caller must make sure that the method belongs to an interface implemented by the class |
539 // Miranda methods only include public interface instance methods | 671 // Miranda methods only include public interface instance methods |
540 // Not private methods, not static methods, not default = concrete abstract | 672 // Not private methods, not static methods, not default == concrete abstract |
541 bool klassVtable::is_miranda(Method* m, Array<Method*>* class_methods, Klass* super) { | 673 // Miranda methods also do not include overpass methods in interfaces |
542 if (m->is_static()) { | 674 bool klassVtable::is_miranda(Method* m, Array<Method*>* class_methods, |
675 Array<Method*>* default_methods, Klass* super) { | |
676 if (m->is_static() || m->is_private() || m->is_overpass()) { | |
543 return false; | 677 return false; |
544 } | 678 } |
545 Symbol* name = m->name(); | 679 Symbol* name = m->name(); |
546 Symbol* signature = m->signature(); | 680 Symbol* signature = m->signature(); |
547 if (InstanceKlass::find_method(class_methods, name, signature) == NULL) { | 681 if (InstanceKlass::find_method(class_methods, name, signature) == NULL) { |
548 // did not find it in the method table of the current class | 682 // did not find it in the method table of the current class |
549 if (super == NULL) { | 683 if ((default_methods == NULL) || |
550 // super doesn't exist | 684 InstanceKlass::find_method(default_methods, name, signature) == NULL) { |
551 return true; | 685 if (super == NULL) { |
552 } | 686 // super doesn't exist |
553 | 687 return true; |
554 Method* mo = InstanceKlass::cast(super)->lookup_method(name, signature); | 688 } |
555 if (mo == NULL || mo->access_flags().is_private() ) { | 689 |
556 // super class hierarchy does not implement it or protection is different | 690 Method* mo = InstanceKlass::cast(super)->lookup_method(name, signature); |
557 return true; | 691 if (mo == NULL || mo->access_flags().is_private() ) { |
692 // super class hierarchy does not implement it or protection is different | |
693 return true; | |
694 } | |
558 } | 695 } |
559 } | 696 } |
560 | 697 |
561 return false; | 698 return false; |
562 } | 699 } |
563 | 700 |
564 // Scans current_interface_methods for miranda methods that do not | 701 // Scans current_interface_methods for miranda methods that do not |
565 // already appear in new_mirandas and are also not defined-and-non-private | 702 // already appear in new_mirandas, or default methods, and are also not defined-and-non-private |
566 // in super (superclass). These mirandas are added to all_mirandas if it is | 703 // in super (superclass). These mirandas are added to all_mirandas if it is |
567 // not null; in addition, those that are not duplicates of miranda methods | 704 // not null; in addition, those that are not duplicates of miranda methods |
568 // inherited by super from its interfaces are added to new_mirandas. | 705 // inherited by super from its interfaces are added to new_mirandas. |
569 // Thus, new_mirandas will be the set of mirandas that this class introduces, | 706 // Thus, new_mirandas will be the set of mirandas that this class introduces, |
570 // all_mirandas will be the set of all mirandas applicable to this class | 707 // all_mirandas will be the set of all mirandas applicable to this class |
571 // including all defined in superclasses. | 708 // including all defined in superclasses. |
572 void klassVtable::add_new_mirandas_to_lists( | 709 void klassVtable::add_new_mirandas_to_lists( |
573 GrowableArray<Method*>* new_mirandas, GrowableArray<Method*>* all_mirandas, | 710 GrowableArray<Method*>* new_mirandas, GrowableArray<Method*>* all_mirandas, |
574 Array<Method*>* current_interface_methods, Array<Method*>* class_methods, | 711 Array<Method*>* current_interface_methods, Array<Method*>* class_methods, |
575 Klass* super) { | 712 Array<Method*>* default_methods, Klass* super) { |
713 | |
576 // iterate thru the current interface's method to see if it a miranda | 714 // iterate thru the current interface's method to see if it a miranda |
577 int num_methods = current_interface_methods->length(); | 715 int num_methods = current_interface_methods->length(); |
578 for (int i = 0; i < num_methods; i++) { | 716 for (int i = 0; i < num_methods; i++) { |
579 Method* im = current_interface_methods->at(i); | 717 Method* im = current_interface_methods->at(i); |
580 bool is_duplicate = false; | 718 bool is_duplicate = false; |
588 break; | 726 break; |
589 } | 727 } |
590 } | 728 } |
591 | 729 |
592 if (!is_duplicate) { // we don't want duplicate miranda entries in the vtable | 730 if (!is_duplicate) { // we don't want duplicate miranda entries in the vtable |
593 if (is_miranda(im, class_methods, super)) { // is it a miranda at all? | 731 if (is_miranda(im, class_methods, default_methods, super)) { // is it a miranda at all? |
594 InstanceKlass *sk = InstanceKlass::cast(super); | 732 InstanceKlass *sk = InstanceKlass::cast(super); |
595 // check if it is a duplicate of a super's miranda | 733 // check if it is a duplicate of a super's miranda |
596 if (sk->lookup_method_in_all_interfaces(im->name(), im->signature()) == NULL) { | 734 if (sk->lookup_method_in_all_interfaces(im->name(), im->signature()) == NULL) { |
597 new_mirandas->append(im); | 735 new_mirandas->append(im); |
598 } | 736 } |
605 } | 743 } |
606 | 744 |
607 void klassVtable::get_mirandas(GrowableArray<Method*>* new_mirandas, | 745 void klassVtable::get_mirandas(GrowableArray<Method*>* new_mirandas, |
608 GrowableArray<Method*>* all_mirandas, | 746 GrowableArray<Method*>* all_mirandas, |
609 Klass* super, Array<Method*>* class_methods, | 747 Klass* super, Array<Method*>* class_methods, |
748 Array<Method*>* default_methods, | |
610 Array<Klass*>* local_interfaces) { | 749 Array<Klass*>* local_interfaces) { |
611 assert((new_mirandas->length() == 0) , "current mirandas must be 0"); | 750 assert((new_mirandas->length() == 0) , "current mirandas must be 0"); |
612 | 751 |
613 // iterate thru the local interfaces looking for a miranda | 752 // iterate thru the local interfaces looking for a miranda |
614 int num_local_ifs = local_interfaces->length(); | 753 int num_local_ifs = local_interfaces->length(); |
615 for (int i = 0; i < num_local_ifs; i++) { | 754 for (int i = 0; i < num_local_ifs; i++) { |
616 InstanceKlass *ik = InstanceKlass::cast(local_interfaces->at(i)); | 755 InstanceKlass *ik = InstanceKlass::cast(local_interfaces->at(i)); |
617 add_new_mirandas_to_lists(new_mirandas, all_mirandas, | 756 add_new_mirandas_to_lists(new_mirandas, all_mirandas, |
618 ik->methods(), class_methods, super); | 757 ik->methods(), class_methods, |
758 default_methods, super); | |
619 // iterate thru each local's super interfaces | 759 // iterate thru each local's super interfaces |
620 Array<Klass*>* super_ifs = ik->transitive_interfaces(); | 760 Array<Klass*>* super_ifs = ik->transitive_interfaces(); |
621 int num_super_ifs = super_ifs->length(); | 761 int num_super_ifs = super_ifs->length(); |
622 for (int j = 0; j < num_super_ifs; j++) { | 762 for (int j = 0; j < num_super_ifs; j++) { |
623 InstanceKlass *sik = InstanceKlass::cast(super_ifs->at(j)); | 763 InstanceKlass *sik = InstanceKlass::cast(super_ifs->at(j)); |
624 add_new_mirandas_to_lists(new_mirandas, all_mirandas, | 764 add_new_mirandas_to_lists(new_mirandas, all_mirandas, |
625 sik->methods(), class_methods, super); | 765 sik->methods(), class_methods, |
766 default_methods, super); | |
626 } | 767 } |
627 } | 768 } |
628 } | 769 } |
629 | 770 |
630 // Discover miranda methods ("miranda" = "interface abstract, no binding"), | 771 // Discover miranda methods ("miranda" = "interface abstract, no binding"), |
631 // and append them into the vtable starting at index initialized, | 772 // and append them into the vtable starting at index initialized, |
632 // return the new value of initialized. | 773 // return the new value of initialized. |
774 // Miranda methods use vtable entries, but do not get assigned a vtable_index | |
775 // The vtable_index is discovered by searching from the end of the vtable | |
633 int klassVtable::fill_in_mirandas(int initialized) { | 776 int klassVtable::fill_in_mirandas(int initialized) { |
634 GrowableArray<Method*> mirandas(20); | 777 GrowableArray<Method*> mirandas(20); |
635 get_mirandas(&mirandas, NULL, ik()->super(), ik()->methods(), | 778 get_mirandas(&mirandas, NULL, ik()->super(), ik()->methods(), |
636 ik()->local_interfaces()); | 779 ik()->default_methods(), ik()->local_interfaces()); |
637 for (int i = 0; i < mirandas.length(); i++) { | 780 for (int i = 0; i < mirandas.length(); i++) { |
781 if (PrintVtables && Verbose) { | |
782 Method* meth = mirandas.at(i); | |
783 ResourceMark rm(Thread::current()); | |
784 if (meth != NULL) { | |
785 char* sig = meth->name_and_sig_as_C_string(); | |
786 tty->print("fill in mirandas with %s index %d, flags: ", | |
787 sig, initialized); | |
788 meth->access_flags().print_on(tty); | |
789 if (meth->is_default_method()) { | |
790 tty->print("default "); | |
791 } | |
792 tty->cr(); | |
793 } | |
794 } | |
638 put_method_at(mirandas.at(i), initialized); | 795 put_method_at(mirandas.at(i), initialized); |
639 ++initialized; | 796 ++initialized; |
640 } | 797 } |
641 return initialized; | 798 return initialized; |
642 } | 799 } |
646 void klassVtable::copy_vtable_to(vtableEntry* start) { | 803 void klassVtable::copy_vtable_to(vtableEntry* start) { |
647 Copy::disjoint_words((HeapWord*)table(), (HeapWord*)start, _length * vtableEntry::size()); | 804 Copy::disjoint_words((HeapWord*)table(), (HeapWord*)start, _length * vtableEntry::size()); |
648 } | 805 } |
649 | 806 |
650 #if INCLUDE_JVMTI | 807 #if INCLUDE_JVMTI |
808 bool klassVtable::adjust_default_method(int vtable_index, Method* old_method, Method* new_method) { | |
809 // If old_method is default, find this vtable index in default_vtable_indices | |
810 // and replace that method in the _default_methods list | |
811 bool updated = false; | |
812 | |
813 Array<Method*>* default_methods = ik()->default_methods(); | |
814 if (default_methods != NULL) { | |
815 int len = default_methods->length(); | |
816 for (int idx = 0; idx < len; idx++) { | |
817 if (vtable_index == ik()->default_vtable_indices()->at(idx)) { | |
818 if (default_methods->at(idx) == old_method) { | |
819 default_methods->at_put(idx, new_method); | |
820 updated = true; | |
821 } | |
822 break; | |
823 } | |
824 } | |
825 } | |
826 return updated; | |
827 } | |
651 void klassVtable::adjust_method_entries(Method** old_methods, Method** new_methods, | 828 void klassVtable::adjust_method_entries(Method** old_methods, Method** new_methods, |
652 int methods_length, bool * trace_name_printed) { | 829 int methods_length, bool * trace_name_printed) { |
653 // search the vtable for uses of either obsolete or EMCP methods | 830 // search the vtable for uses of either obsolete or EMCP methods |
654 for (int j = 0; j < methods_length; j++) { | 831 for (int j = 0; j < methods_length; j++) { |
655 Method* old_method = old_methods[j]; | 832 Method* old_method = old_methods[j]; |
661 // in sun.awt.X11.XFramePeer where methods occur more than once in the | 838 // in sun.awt.X11.XFramePeer where methods occur more than once in the |
662 // vtable, so, alas, we must do an exhaustive search. | 839 // vtable, so, alas, we must do an exhaustive search. |
663 for (int index = 0; index < length(); index++) { | 840 for (int index = 0; index < length(); index++) { |
664 if (unchecked_method_at(index) == old_method) { | 841 if (unchecked_method_at(index) == old_method) { |
665 put_method_at(new_method, index); | 842 put_method_at(new_method, index); |
843 // For default methods, need to update the _default_methods array | |
844 // which can only have one method entry for a given signature | |
845 bool updated_default = false; | |
846 if (old_method->is_default_method()) { | |
847 updated_default = adjust_default_method(index, old_method, new_method); | |
848 } | |
666 | 849 |
667 if (RC_TRACE_IN_RANGE(0x00100000, 0x00400000)) { | 850 if (RC_TRACE_IN_RANGE(0x00100000, 0x00400000)) { |
668 if (!(*trace_name_printed)) { | 851 if (!(*trace_name_printed)) { |
669 // RC_TRACE_MESG macro has an embedded ResourceMark | 852 // RC_TRACE_MESG macro has an embedded ResourceMark |
670 RC_TRACE_MESG(("adjust: name=%s", | 853 RC_TRACE_MESG(("adjust: klassname=%s for methods from name=%s", |
854 klass()->external_name(), | |
671 old_method->method_holder()->external_name())); | 855 old_method->method_holder()->external_name())); |
672 *trace_name_printed = true; | 856 *trace_name_printed = true; |
673 } | 857 } |
674 // RC_TRACE macro has an embedded ResourceMark | 858 // RC_TRACE macro has an embedded ResourceMark |
675 RC_TRACE(0x00100000, ("vtable method update: %s(%s)", | 859 RC_TRACE(0x00100000, ("vtable method update: %s(%s), updated default = %s", |
676 new_method->name()->as_C_string(), | 860 new_method->name()->as_C_string(), |
677 new_method->signature()->as_C_string())); | 861 new_method->signature()->as_C_string(), |
862 updated_default ? "true" : "false")); | |
678 } | 863 } |
679 // cannot 'break' here; see for-loop comment above. | 864 // cannot 'break' here; see for-loop comment above. |
680 } | 865 } |
681 } | 866 } |
682 } | 867 } |
699 for (int i = 0; i < length(); i++) { | 884 for (int i = 0; i < length(); i++) { |
700 Method* m = unchecked_method_at(i); | 885 Method* m = unchecked_method_at(i); |
701 if (m != NULL) { | 886 if (m != NULL) { |
702 tty->print(" (%5d) ", i); | 887 tty->print(" (%5d) ", i); |
703 m->access_flags().print_on(tty); | 888 m->access_flags().print_on(tty); |
889 if (m->is_default_method()) { | |
890 tty->print("default "); | |
891 } | |
892 if (m->is_overpass()) { | |
893 tty->print("overpass"); | |
894 } | |
704 tty->print(" -- "); | 895 tty->print(" -- "); |
705 m->print_name(tty); | 896 m->print_name(tty); |
706 tty->cr(); | 897 tty->cr(); |
707 } | 898 } |
708 } | 899 } |
755 static int initialize_count = 0; | 946 static int initialize_count = 0; |
756 | 947 |
757 // Initialization | 948 // Initialization |
758 void klassItable::initialize_itable(bool checkconstraints, TRAPS) { | 949 void klassItable::initialize_itable(bool checkconstraints, TRAPS) { |
759 if (_klass->is_interface()) { | 950 if (_klass->is_interface()) { |
760 // This needs to go after vtable indexes are assigned but | 951 // This needs to go after vtable indices are assigned but |
761 // before implementors need to know the number of itable indexes. | 952 // before implementors need to know the number of itable indices. |
762 assign_itable_indexes_for_interface(_klass()); | 953 assign_itable_indices_for_interface(_klass()); |
763 } | 954 } |
764 | 955 |
765 // Cannot be setup doing bootstrapping, interfaces don't have | 956 // Cannot be setup doing bootstrapping, interfaces don't have |
766 // itables, and klass with only ones entry have empty itables | 957 // itables, and klass with only ones entry have empty itables |
767 if (Universe::is_bootstrapping() || | 958 if (Universe::is_bootstrapping() || |
801 // e.g., CharSequence.toString (from initialize_vtable) | 992 // e.g., CharSequence.toString (from initialize_vtable) |
802 // if (m->has_vtable_index()) return false; // NO! | 993 // if (m->has_vtable_index()) return false; // NO! |
803 return true; | 994 return true; |
804 } | 995 } |
805 | 996 |
806 int klassItable::assign_itable_indexes_for_interface(Klass* klass) { | 997 int klassItable::assign_itable_indices_for_interface(Klass* klass) { |
807 // an interface does not have an itable, but its methods need to be numbered | 998 // an interface does not have an itable, but its methods need to be numbered |
808 if (TraceItables) tty->print_cr("%3d: Initializing itable for interface %s", ++initialize_count, | 999 if (TraceItables) tty->print_cr("%3d: Initializing itable for interface %s", ++initialize_count, |
809 klass->name()->as_C_string()); | 1000 klass->name()->as_C_string()); |
810 Array<Method*>* methods = InstanceKlass::cast(klass)->methods(); | 1001 Array<Method*>* methods = InstanceKlass::cast(klass)->methods(); |
811 int nof_methods = methods->length(); | 1002 int nof_methods = methods->length(); |
813 for (int i = 0; i < nof_methods; i++) { | 1004 for (int i = 0; i < nof_methods; i++) { |
814 Method* m = methods->at(i); | 1005 Method* m = methods->at(i); |
815 if (interface_method_needs_itable_index(m)) { | 1006 if (interface_method_needs_itable_index(m)) { |
816 assert(!m->is_final_method(), "no final interface methods"); | 1007 assert(!m->is_final_method(), "no final interface methods"); |
817 // If m is already assigned a vtable index, do not disturb it. | 1008 // If m is already assigned a vtable index, do not disturb it. |
1009 if (TraceItables && Verbose) { | |
1010 ResourceMark rm; | |
1011 const char* sig = (m != NULL) ? m->name_and_sig_as_C_string() : "<NULL>"; | |
1012 if (m->has_vtable_index()) { | |
1013 tty->print("itable index %d for method: %s, flags: ", m->vtable_index(), sig); | |
1014 } else { | |
1015 tty->print("itable index %d for method: %s, flags: ", ime_num, sig); | |
1016 } | |
1017 if (m != NULL) { | |
1018 m->access_flags().print_on(tty); | |
1019 if (m->is_default_method()) { | |
1020 tty->print("default "); | |
1021 } | |
1022 if (m->is_overpass()) { | |
1023 tty->print("overpass"); | |
1024 } | |
1025 } | |
1026 tty->cr(); | |
1027 } | |
818 if (!m->has_vtable_index()) { | 1028 if (!m->has_vtable_index()) { |
819 assert(m->vtable_index() == Method::pending_itable_index, "set by initialize_vtable"); | 1029 assert(m->vtable_index() == Method::pending_itable_index, "set by initialize_vtable"); |
820 m->set_itable_index(ime_num); | 1030 m->set_itable_index(ime_num); |
821 // Progress to next itable entry | 1031 // Progress to next itable entry |
822 ime_num++; | 1032 ime_num++; |
844 #endif //ASSERT | 1054 #endif //ASSERT |
845 return length; // return the rightmost itable index, plus one | 1055 return length; // return the rightmost itable index, plus one |
846 } | 1056 } |
847 nof_methods -= 1; | 1057 nof_methods -= 1; |
848 } | 1058 } |
849 // no methods have itable indexes | 1059 // no methods have itable indices |
850 return 0; | 1060 return 0; |
851 } | 1061 } |
852 | 1062 |
853 | 1063 |
854 void klassItable::initialize_itable_for_interface(int method_table_offset, KlassHandle interf_h, bool checkconstraints, TRAPS) { | 1064 void klassItable::initialize_itable_for_interface(int method_table_offset, KlassHandle interf_h, bool checkconstraints, TRAPS) { |
905 | 1115 |
906 // ime may have moved during GC so recalculate address | 1116 // ime may have moved during GC so recalculate address |
907 int ime_num = m->itable_index(); | 1117 int ime_num = m->itable_index(); |
908 assert(ime_num < ime_count, "oob"); | 1118 assert(ime_num < ime_count, "oob"); |
909 itableOffsetEntry::method_entry(_klass(), method_table_offset)[ime_num].initialize(target()); | 1119 itableOffsetEntry::method_entry(_klass(), method_table_offset)[ime_num].initialize(target()); |
1120 if (TraceItables && Verbose) { | |
1121 ResourceMark rm(THREAD); | |
1122 if (target() != NULL) { | |
1123 char* sig = target()->name_and_sig_as_C_string(); | |
1124 tty->print("interface: %s, ime_num: %d, target: %s, method_holder: %s ", | |
1125 interf_h()->internal_name(), ime_num, sig, | |
1126 target()->method_holder()->internal_name()); | |
1127 tty->print("target_method flags: "); | |
1128 target()->access_flags().print_on(tty); | |
1129 if (target()->is_default_method()) { | |
1130 tty->print("default "); | |
1131 } | |
1132 tty->cr(); | |
1133 } | |
1134 } | |
910 } | 1135 } |
911 } | 1136 } |
912 } | 1137 } |
913 | 1138 |
914 // Update entry for specific Method* | 1139 // Update entry for specific Method* |
978 for (int i = 0; i < _size_method_table; i++) { | 1203 for (int i = 0; i < _size_method_table; i++) { |
979 Method* m = ime->method(); | 1204 Method* m = ime->method(); |
980 if (m != NULL) { | 1205 if (m != NULL) { |
981 tty->print(" (%5d) ", i); | 1206 tty->print(" (%5d) ", i); |
982 m->access_flags().print_on(tty); | 1207 m->access_flags().print_on(tty); |
1208 if (m->is_default_method()) { | |
1209 tty->print("default "); | |
1210 } | |
983 tty->print(" -- "); | 1211 tty->print(" -- "); |
984 m->print_name(tty); | 1212 m->print_name(tty); |
985 tty->cr(); | 1213 tty->cr(); |
986 } | 1214 } |
987 ime++; | 1215 ime++; |
1114 assert(InstanceKlass::cast(intf)->is_interface(), "sanity check"); | 1342 assert(InstanceKlass::cast(intf)->is_interface(), "sanity check"); |
1115 assert(intf->verify_itable_index(itable_index), ""); | 1343 assert(intf->verify_itable_index(itable_index), ""); |
1116 Array<Method*>* methods = InstanceKlass::cast(intf)->methods(); | 1344 Array<Method*>* methods = InstanceKlass::cast(intf)->methods(); |
1117 | 1345 |
1118 if (itable_index < 0 || itable_index >= method_count_for_interface(intf)) | 1346 if (itable_index < 0 || itable_index >= method_count_for_interface(intf)) |
1119 return NULL; // help caller defend against bad indexes | 1347 return NULL; // help caller defend against bad indices |
1120 | 1348 |
1121 int index = itable_index; | 1349 int index = itable_index; |
1122 Method* m = methods->at(index); | 1350 Method* m = methods->at(index); |
1123 int index2 = -1; | 1351 int index2 = -1; |
1124 while (!m->has_itable_index() || | 1352 while (!m->has_itable_index() || |