src/hotspot/share/oops/klassVtable.cpp
changeset 55655 419420eb5230
parent 54432 532e88de77eb
child 58177 4932dce35882
equal deleted inserted replaced
55654:92ab031d6540 55655:419420eb5230
   636   Symbol* signature = target_method()->signature();
   636   Symbol* signature = target_method()->signature();
   637   const Klass* k = super;
   637   const Klass* k = super;
   638   Method* super_method = NULL;
   638   Method* super_method = NULL;
   639   InstanceKlass *holder = NULL;
   639   InstanceKlass *holder = NULL;
   640   Method* recheck_method =  NULL;
   640   Method* recheck_method =  NULL;
       
   641   bool found_pkg_prvt_method = false;
   641   while (k != NULL) {
   642   while (k != NULL) {
   642     // lookup through the hierarchy for a method with matching name and sign.
   643     // lookup through the hierarchy for a method with matching name and sign.
   643     super_method = InstanceKlass::cast(k)->lookup_method(name, signature);
   644     super_method = InstanceKlass::cast(k)->lookup_method(name, signature);
   644     if (super_method == NULL) {
   645     if (super_method == NULL) {
   645       break; // we still have to search for a matching miranda method
   646       break; // we still have to search for a matching miranda method
   657        (!super_method->is_private())) {
   658        (!super_method->is_private())) {
   658       if (superk->is_override(super_method, classloader, classname, THREAD)) {
   659       if (superk->is_override(super_method, classloader, classname, THREAD)) {
   659         return false;
   660         return false;
   660       // else keep looking for transitive overrides
   661       // else keep looking for transitive overrides
   661       }
   662       }
       
   663       // If we get here then one of the super classes has a package private method
       
   664       // that will not get overridden because it is in a different package.  But,
       
   665       // that package private method does "override" any matching methods in super
       
   666       // interfaces, so there will be no miranda vtable entry created.  So, set flag
       
   667       // to TRUE for use below, in case there are no methods in super classes that
       
   668       // this target method overrides.
       
   669       assert(super_method->is_package_private(), "super_method must be package private");
       
   670       assert(!superk->is_same_class_package(classloader(), classname),
       
   671              "Must be different packages");
       
   672       found_pkg_prvt_method = true;
   662     }
   673     }
   663 
   674 
   664     // Start with lookup result and continue to search up, for versions supporting transitive override
   675     // Start with lookup result and continue to search up, for versions supporting transitive override
   665     if (major_version >= VTABLE_TRANSITIVE_OVERRIDE_VERSION) {
   676     if (major_version >= VTABLE_TRANSITIVE_OVERRIDE_VERSION) {
   666       k = superk->super(); // haven't found an override match yet; continue to look
   677       k = superk->super(); // haven't found an override match yet; continue to look
   667     } else {
   678     } else {
   668       break;
   679       break;
   669     }
   680     }
       
   681   }
       
   682 
       
   683   // If found_pkg_prvt_method is set, then the ONLY matching method in the
       
   684   // superclasses is package private in another package. That matching method will
       
   685   // prevent a miranda vtable entry from being created. Because the target method can not
       
   686   // override the package private method in another package, then it needs to be the root
       
   687   // for its own vtable entry.
       
   688   if (found_pkg_prvt_method) {
       
   689      return true;
   670   }
   690   }
   671 
   691 
   672   // if the target method is public or protected it may have a matching
   692   // 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.
   693   // miranda method in the super, whose entry it should re-use.
   674   // Actually, to handle cases that javac would not generate, we need
   694   // Actually, to handle cases that javac would not generate, we need
   675   // this check for all access permissions.
   695   // this check for all access permissions.
   676   const InstanceKlass *sk = InstanceKlass::cast(super);
   696   const InstanceKlass *sk = InstanceKlass::cast(super);
   677   if (sk->has_miranda_methods()) {
   697   if (sk->has_miranda_methods()) {
   678     if (sk->lookup_method_in_all_interfaces(name, signature, Klass::find_defaults) != NULL) {
   698     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
   699       return false; // found a matching miranda; we do not need a new entry
   680     }
   700     }
   681   }
   701   }
   682   return true; // found no match; we need a new entry
   702   return true; // found no match; we need a new entry
   683 }
   703 }
   684 
   704