hotspot/src/share/vm/runtime/reflection.cpp
changeset 1550 be2fc37a817f
parent 670 ddf3e9583f2f
child 2332 5c7b6f4ce0a1
equal deleted inserted replaced
1549:710f8deef989 1550:be2fc37a817f
   454   }
   454   }
   455 
   455 
   456   return can_relax_access_check_for(current_class, new_class, classloader_only);
   456   return can_relax_access_check_for(current_class, new_class, classloader_only);
   457 }
   457 }
   458 
   458 
       
   459 static bool under_host_klass(instanceKlass* ik, klassOop host_klass) {
       
   460   DEBUG_ONLY(int inf_loop_check = 1000 * 1000 * 1000);
       
   461   for (;;) {
       
   462     klassOop hc = (klassOop) ik->host_klass();
       
   463     if (hc == NULL)        return false;
       
   464     if (hc == host_klass)  return true;
       
   465     ik = instanceKlass::cast(hc);
       
   466 
       
   467     // There's no way to make a host class loop short of patching memory.
       
   468     // Therefore there cannot be a loop here unles there's another bug.
       
   469     // Still, let's check for it.
       
   470     assert(--inf_loop_check > 0, "no host_klass loop");
       
   471   }
       
   472 }
       
   473 
   459 bool Reflection::can_relax_access_check_for(
   474 bool Reflection::can_relax_access_check_for(
   460     klassOop accessor, klassOop accessee, bool classloader_only) {
   475     klassOop accessor, klassOop accessee, bool classloader_only) {
   461   instanceKlass* accessor_ik = instanceKlass::cast(accessor);
   476   instanceKlass* accessor_ik = instanceKlass::cast(accessor);
   462   instanceKlass* accessee_ik  = instanceKlass::cast(accessee);
   477   instanceKlass* accessee_ik  = instanceKlass::cast(accessee);
       
   478 
       
   479   // If either is on the other's host_klass chain, access is OK,
       
   480   // because one is inside the other.
       
   481   if (under_host_klass(accessor_ik, accessee) ||
       
   482       under_host_klass(accessee_ik, accessor))
       
   483     return true;
       
   484 
   463   if (RelaxAccessControlCheck ||
   485   if (RelaxAccessControlCheck ||
   464       (accessor_ik->major_version() < JAVA_1_5_VERSION &&
   486       (accessor_ik->major_version() < JAVA_1_5_VERSION &&
   465        accessee_ik->major_version() < JAVA_1_5_VERSION)) {
   487        accessee_ik->major_version() < JAVA_1_5_VERSION)) {
   466     return classloader_only &&
   488     return classloader_only &&
   467       Verifier::relax_verify_for(accessor_ik->class_loader()) &&
   489       Verifier::relax_verify_for(accessor_ik->class_loader()) &&