249 |
249 |
250 // Called for cases where a method does not override its superclass' vtable entry |
250 // Called for cases where a method does not override its superclass' vtable entry |
251 // For bytecodes not produced by javac together it is possible that a method does not override |
251 // For bytecodes not produced by javac together it is possible that a method does not override |
252 // the superclass's method, but might indirectly override a super-super class's vtable entry |
252 // the superclass's method, but might indirectly override a super-super class's vtable entry |
253 // If none found, return a null superk, else return the superk of the method this does override |
253 // If none found, return a null superk, else return the superk of the method this does override |
|
254 // For public and protected methods: if they override a superclass, they will |
|
255 // also be overridden themselves appropriately. |
|
256 // Private methods do not override and are not overridden. |
|
257 // Package Private methods are trickier: |
|
258 // e.g. P1.A, pub m |
|
259 // P2.B extends A, package private m |
|
260 // P1.C extends B, public m |
|
261 // P1.C.m needs to override P1.A.m and can not override P2.B.m |
|
262 // Therefore: all package private methods need their own vtable entries for |
|
263 // them to be the root of an inheritance overriding decision |
|
264 // Package private methods may also override other vtable entries |
254 InstanceKlass* klassVtable::find_transitive_override(InstanceKlass* initialsuper, methodHandle target_method, |
265 InstanceKlass* klassVtable::find_transitive_override(InstanceKlass* initialsuper, methodHandle target_method, |
255 int vtable_index, Handle target_loader, Symbol* target_classname, Thread * THREAD) { |
266 int vtable_index, Handle target_loader, Symbol* target_classname, Thread * THREAD) { |
256 InstanceKlass* superk = initialsuper; |
267 InstanceKlass* superk = initialsuper; |
257 while (superk != NULL && superk->super() != NULL) { |
268 while (superk != NULL && superk->super() != NULL) { |
258 InstanceKlass* supersuperklass = InstanceKlass::cast(superk->super()); |
269 InstanceKlass* supersuperklass = InstanceKlass::cast(superk->super()); |
396 && ((super_klass = find_transitive_override(super_klass, |
407 && ((super_klass = find_transitive_override(super_klass, |
397 target_method, i, target_loader, |
408 target_method, i, target_loader, |
398 target_classname, THREAD)) |
409 target_classname, THREAD)) |
399 != (InstanceKlass*)NULL)))) |
410 != (InstanceKlass*)NULL)))) |
400 { |
411 { |
401 // overriding, so no new entry |
412 // Package private methods always need a new entry to root their own |
402 allocate_new = false; |
413 // overriding. They may also override other methods. |
|
414 if (!target_method()->is_package_private()) { |
|
415 allocate_new = false; |
|
416 } |
403 |
417 |
404 if (checkconstraints) { |
418 if (checkconstraints) { |
405 // Override vtable entry if passes loader constraint check |
419 // Override vtable entry if passes loader constraint check |
406 // if loader constraint checking requested |
420 // if loader constraint checking requested |
407 // No need to visit his super, since he and his super |
421 // No need to visit his super, since he and his super |
541 Handle classloader, |
555 Handle classloader, |
542 Symbol* classname, |
556 Symbol* classname, |
543 AccessFlags class_flags, |
557 AccessFlags class_flags, |
544 TRAPS) { |
558 TRAPS) { |
545 if (class_flags.is_interface()) { |
559 if (class_flags.is_interface()) { |
546 // Interfaces do not use vtables, so there is no point to assigning |
560 // Interfaces do not use vtables, except for java.lang.Object methods, |
547 // a vtable index to any of their methods. If we refrain from doing this, |
561 // so there is no point to assigning |
|
562 // a vtable index to any of their local methods. If we refrain from doing this, |
548 // we can use Method::_vtable_index to hold the itable index |
563 // we can use Method::_vtable_index to hold the itable index |
549 return false; |
564 return false; |
550 } |
565 } |
551 |
566 |
552 if (target_method->is_final_method(class_flags) || |
567 if (target_method->is_final_method(class_flags) || |
577 // private methods in classes always have a new entry in the vtable |
592 // private methods in classes always have a new entry in the vtable |
578 // specification interpretation since classic has |
593 // specification interpretation since classic has |
579 // private methods not overriding |
594 // private methods not overriding |
580 // JDK8 adds private methods in interfaces which require invokespecial |
595 // JDK8 adds private methods in interfaces which require invokespecial |
581 if (target_method()->is_private()) { |
596 if (target_method()->is_private()) { |
|
597 return true; |
|
598 } |
|
599 |
|
600 // Package private methods always need a new entry to root their own |
|
601 // overriding. This allows transitive overriding to work. |
|
602 if (target_method()->is_package_private()) { |
582 return true; |
603 return true; |
583 } |
604 } |
584 |
605 |
585 // search through the super class hierarchy to see if we need |
606 // search through the super class hierarchy to see if we need |
586 // a new entry |
607 // a new entry |