124 } |
124 } |
125 assert(vtable_length % vtableEntry::size() == 0, "bad vtable length"); |
125 assert(vtable_length % vtableEntry::size() == 0, "bad vtable length"); |
126 assert(vtable_length >= Universe::base_vtable_size(), "vtable too small"); |
126 assert(vtable_length >= Universe::base_vtable_size(), "vtable too small"); |
127 |
127 |
128 *vtable_length_ret = vtable_length; |
128 *vtable_length_ret = vtable_length; |
129 } |
|
130 |
|
131 int klassVtable::index_of(Method* m, int len) const { |
|
132 assert(m->has_vtable_index(), "do not ask this of non-vtable methods"); |
|
133 return m->vtable_index(); |
|
134 } |
129 } |
135 |
130 |
136 // Copy super class's vtable to the first part (prefix) of this class's vtable, |
131 // Copy super class's vtable to the first part (prefix) of this class's vtable, |
137 // and return the number of entries copied. Expects that 'super' is the Java |
132 // and return the number of entries copied. Expects that 'super' is the Java |
138 // super class (arrays can have "array" super classes that must be skipped). |
133 // super class (arrays can have "array" super classes that must be skipped). |
167 // Revised lookup semantics introduced 1.3 (Kestrel beta) |
162 // Revised lookup semantics introduced 1.3 (Kestrel beta) |
168 void klassVtable::initialize_vtable(bool checkconstraints, TRAPS) { |
163 void klassVtable::initialize_vtable(bool checkconstraints, TRAPS) { |
169 |
164 |
170 // Note: Arrays can have intermediate array supers. Use java_super to skip them. |
165 // Note: Arrays can have intermediate array supers. Use java_super to skip them. |
171 InstanceKlass* super = _klass->java_super(); |
166 InstanceKlass* super = _klass->java_super(); |
172 int nofNewEntries = 0; |
|
173 |
167 |
174 bool is_shared = _klass->is_shared(); |
168 bool is_shared = _klass->is_shared(); |
175 |
169 |
176 if (!_klass->is_array_klass()) { |
170 if (!_klass->is_array_klass()) { |
177 ResourceMark rm(THREAD); |
171 ResourceMark rm(THREAD); |
489 // have already made any needed loader constraints. |
483 // have already made any needed loader constraints. |
490 // Since loader constraints are transitive, it is enough |
484 // Since loader constraints are transitive, it is enough |
491 // to link to the first super, and we get all the others. |
485 // to link to the first super, and we get all the others. |
492 Handle super_loader(THREAD, super_klass->class_loader()); |
486 Handle super_loader(THREAD, super_klass->class_loader()); |
493 |
487 |
494 if (!oopDesc::equals(target_loader(), super_loader())) { |
488 if (target_loader() != super_loader()) { |
495 ResourceMark rm(THREAD); |
489 ResourceMark rm(THREAD); |
496 Symbol* failed_type_symbol = |
490 Symbol* failed_type_symbol = |
497 SystemDictionary::check_signature_loaders(signature, target_loader, |
491 SystemDictionary::check_signature_loaders(signature, target_loader, |
498 super_loader, true, |
492 super_loader, true, |
499 CHECK_(false)); |
493 CHECK_(false)); |
636 Symbol* signature = target_method()->signature(); |
630 Symbol* signature = target_method()->signature(); |
637 const Klass* k = super; |
631 const Klass* k = super; |
638 Method* super_method = NULL; |
632 Method* super_method = NULL; |
639 InstanceKlass *holder = NULL; |
633 InstanceKlass *holder = NULL; |
640 Method* recheck_method = NULL; |
634 Method* recheck_method = NULL; |
|
635 bool found_pkg_prvt_method = false; |
641 while (k != NULL) { |
636 while (k != NULL) { |
642 // lookup through the hierarchy for a method with matching name and sign. |
637 // lookup through the hierarchy for a method with matching name and sign. |
643 super_method = InstanceKlass::cast(k)->lookup_method(name, signature); |
638 super_method = InstanceKlass::cast(k)->lookup_method(name, signature); |
644 if (super_method == NULL) { |
639 if (super_method == NULL) { |
645 break; // we still have to search for a matching miranda method |
640 break; // we still have to search for a matching miranda method |
657 (!super_method->is_private())) { |
652 (!super_method->is_private())) { |
658 if (superk->is_override(super_method, classloader, classname, THREAD)) { |
653 if (superk->is_override(super_method, classloader, classname, THREAD)) { |
659 return false; |
654 return false; |
660 // else keep looking for transitive overrides |
655 // else keep looking for transitive overrides |
661 } |
656 } |
|
657 // If we get here then one of the super classes has a package private method |
|
658 // that will not get overridden because it is in a different package. But, |
|
659 // that package private method does "override" any matching methods in super |
|
660 // interfaces, so there will be no miranda vtable entry created. So, set flag |
|
661 // to TRUE for use below, in case there are no methods in super classes that |
|
662 // this target method overrides. |
|
663 assert(super_method->is_package_private(), "super_method must be package private"); |
|
664 assert(!superk->is_same_class_package(classloader(), classname), |
|
665 "Must be different packages"); |
|
666 found_pkg_prvt_method = true; |
662 } |
667 } |
663 |
668 |
664 // Start with lookup result and continue to search up, for versions supporting transitive override |
669 // Start with lookup result and continue to search up, for versions supporting transitive override |
665 if (major_version >= VTABLE_TRANSITIVE_OVERRIDE_VERSION) { |
670 if (major_version >= VTABLE_TRANSITIVE_OVERRIDE_VERSION) { |
666 k = superk->super(); // haven't found an override match yet; continue to look |
671 k = superk->super(); // haven't found an override match yet; continue to look |
667 } else { |
672 } else { |
668 break; |
673 break; |
669 } |
674 } |
|
675 } |
|
676 |
|
677 // If found_pkg_prvt_method is set, then the ONLY matching method in the |
|
678 // superclasses is package private in another package. That matching method will |
|
679 // prevent a miranda vtable entry from being created. Because the target method can not |
|
680 // override the package private method in another package, then it needs to be the root |
|
681 // for its own vtable entry. |
|
682 if (found_pkg_prvt_method) { |
|
683 return true; |
670 } |
684 } |
671 |
685 |
672 // if the target method is public or protected it may have a matching |
686 // if the target method is public or protected it may have a matching |
673 // miranda method in the super, whose entry it should re-use. |
687 // miranda method in the super, whose entry it should re-use. |
674 // Actually, to handle cases that javac would not generate, we need |
688 // Actually, to handle cases that javac would not generate, we need |
675 // this check for all access permissions. |
689 // this check for all access permissions. |
676 const InstanceKlass *sk = InstanceKlass::cast(super); |
690 const InstanceKlass *sk = InstanceKlass::cast(super); |
677 if (sk->has_miranda_methods()) { |
691 if (sk->has_miranda_methods()) { |
678 if (sk->lookup_method_in_all_interfaces(name, signature, Klass::find_defaults) != NULL) { |
692 if (sk->lookup_method_in_all_interfaces(name, signature, Klass::find_defaults) != NULL) { |
679 return false; // found a matching miranda; we do not need a new entry |
693 return false; // found a matching miranda; we do not need a new entry |
680 } |
694 } |
681 } |
695 } |
682 return true; // found no match; we need a new entry |
696 return true; // found no match; we need a new entry |
683 } |
697 } |
684 |
698 |
1007 } |
1021 } |
1008 } |
1022 } |
1009 } |
1023 } |
1010 #endif // INCLUDE_JVMTI |
1024 #endif // INCLUDE_JVMTI |
1011 |
1025 |
1012 // CDS/RedefineClasses support - clear vtables so they can be reinitialized |
|
1013 void klassVtable::clear_vtable() { |
|
1014 for (int i = 0; i < _length; i++) table()[i].clear(); |
|
1015 } |
|
1016 |
|
1017 bool klassVtable::is_initialized() { |
|
1018 return _length == 0 || table()[0].method() != NULL; |
|
1019 } |
|
1020 |
|
1021 //----------------------------------------------------------------------------------------- |
1026 //----------------------------------------------------------------------------------------- |
1022 // Itable code |
1027 // Itable code |
1023 |
1028 |
1024 // Initialize a itableMethodEntry |
1029 // Initialize a itableMethodEntry |
1025 void itableMethodEntry::initialize(Method* m) { |
1030 void itableMethodEntry::initialize(Method* m) { |
1215 } else { |
1220 } else { |
1216 // Entry did resolve, check loader constraints before initializing |
1221 // Entry did resolve, check loader constraints before initializing |
1217 // if checkconstraints requested |
1222 // if checkconstraints requested |
1218 if (checkconstraints) { |
1223 if (checkconstraints) { |
1219 Handle method_holder_loader (THREAD, target->method_holder()->class_loader()); |
1224 Handle method_holder_loader (THREAD, target->method_holder()->class_loader()); |
1220 if (!oopDesc::equals(method_holder_loader(), interface_loader())) { |
1225 if (method_holder_loader() != interface_loader()) { |
1221 ResourceMark rm(THREAD); |
1226 ResourceMark rm(THREAD); |
1222 Symbol* failed_type_symbol = |
1227 Symbol* failed_type_symbol = |
1223 SystemDictionary::check_signature_loaders(m->signature(), |
1228 SystemDictionary::check_signature_loaders(m->signature(), |
1224 method_holder_loader, |
1229 method_holder_loader, |
1225 interface_loader, |
1230 interface_loader, |
1446 oop* v = (oop*) klass->end_of_itable(); |
1451 oop* v = (oop*) klass->end_of_itable(); |
1447 assert( (oop*)(ime) == v, "wrong offset calculation (2)"); |
1452 assert( (oop*)(ime) == v, "wrong offset calculation (2)"); |
1448 #endif |
1453 #endif |
1449 } |
1454 } |
1450 |
1455 |
1451 |
|
1452 // inverse to itable_index |
|
1453 Method* klassItable::method_for_itable_index(InstanceKlass* intf, int itable_index) { |
|
1454 assert(intf->is_interface(), "sanity check"); |
|
1455 assert(intf->verify_itable_index(itable_index), ""); |
|
1456 Array<Method*>* methods = InstanceKlass::cast(intf)->methods(); |
|
1457 |
|
1458 if (itable_index < 0 || itable_index >= method_count_for_interface(intf)) |
|
1459 return NULL; // help caller defend against bad indices |
|
1460 |
|
1461 int index = itable_index; |
|
1462 Method* m = methods->at(index); |
|
1463 int index2 = -1; |
|
1464 while (!m->has_itable_index() || |
|
1465 (index2 = m->itable_index()) != itable_index) { |
|
1466 assert(index2 < itable_index, "monotonic"); |
|
1467 if (++index == methods->length()) |
|
1468 return NULL; |
|
1469 m = methods->at(index); |
|
1470 } |
|
1471 assert(m->itable_index() == itable_index, "correct inverse"); |
|
1472 |
|
1473 return m; |
|
1474 } |
|
1475 |
|
1476 void klassVtable::verify(outputStream* st, bool forced) { |
1456 void klassVtable::verify(outputStream* st, bool forced) { |
1477 // make sure table is initialized |
1457 // make sure table is initialized |
1478 if (!Universe::is_fully_initialized()) return; |
1458 if (!Universe::is_fully_initialized()) return; |
1479 #ifndef PRODUCT |
1459 #ifndef PRODUCT |
1480 // avoid redundant verifies |
1460 // avoid redundant verifies |
1519 } |
1499 } |
1520 } |
1500 } |
1521 #endif |
1501 #endif |
1522 |
1502 |
1523 void vtableEntry::verify(klassVtable* vt, outputStream* st) { |
1503 void vtableEntry::verify(klassVtable* vt, outputStream* st) { |
1524 NOT_PRODUCT(FlagSetting fs(IgnoreLockingAssertions, true)); |
|
1525 Klass* vtklass = vt->klass(); |
1504 Klass* vtklass = vt->klass(); |
1526 if (vtklass->is_instance_klass() && |
1505 if (vtklass->is_instance_klass() && |
1527 (InstanceKlass::cast(vtklass)->major_version() >= klassVtable::VTABLE_TRANSITIVE_OVERRIDE_VERSION)) { |
1506 (InstanceKlass::cast(vtklass)->major_version() >= klassVtable::VTABLE_TRANSITIVE_OVERRIDE_VERSION)) { |
1528 assert(method() != NULL, "must have set method"); |
1507 assert(method() != NULL, "must have set method"); |
1529 } |
1508 } |