src/hotspot/share/runtime/reflection.cpp
changeset 51444 3e5d28e6de32
parent 50735 2f2af62dfac7
child 51467 12997ebbc0d8
equal deleted inserted replaced
51443:cdffba164671 51444:3e5d28e6de32
   422   assert(oopDesc::equals(result, result2), "results must be consistent");
   422   assert(oopDesc::equals(result, result2), "results must be consistent");
   423 #endif //ASSERT
   423 #endif //ASSERT
   424   return result;
   424   return result;
   425 }
   425 }
   426 
   426 
   427 static bool under_host_klass(const InstanceKlass* ik, const InstanceKlass* host_klass) {
   427 static bool under_unsafe_anonymous_host(const InstanceKlass* ik, const InstanceKlass* unsafe_anonymous_host) {
   428   DEBUG_ONLY(int inf_loop_check = 1000 * 1000 * 1000);
   428   DEBUG_ONLY(int inf_loop_check = 1000 * 1000 * 1000);
   429   for (;;) {
   429   for (;;) {
   430     const InstanceKlass* hc = ik->host_klass();
   430     const InstanceKlass* hc = ik->unsafe_anonymous_host();
   431     if (hc == NULL)        return false;
   431     if (hc == NULL)        return false;
   432     if (hc == host_klass)  return true;
   432     if (hc == unsafe_anonymous_host)  return true;
   433     ik = hc;
   433     ik = hc;
   434 
   434 
   435     // There's no way to make a host class loop short of patching memory.
   435     // There's no way to make a host class loop short of patching memory.
   436     // Therefore there cannot be a loop here unless there's another bug.
   436     // Therefore there cannot be a loop here unless there's another bug.
   437     // Still, let's check for it.
   437     // Still, let's check for it.
   438     assert(--inf_loop_check > 0, "no host_klass loop");
   438     assert(--inf_loop_check > 0, "no unsafe_anonymous_host loop");
   439   }
   439   }
   440 }
   440 }
   441 
   441 
   442 static bool can_relax_access_check_for(const Klass* accessor,
   442 static bool can_relax_access_check_for(const Klass* accessor,
   443                                        const Klass* accessee,
   443                                        const Klass* accessee,
   444                                        bool classloader_only) {
   444                                        bool classloader_only) {
   445 
   445 
   446   const InstanceKlass* accessor_ik = InstanceKlass::cast(accessor);
   446   const InstanceKlass* accessor_ik = InstanceKlass::cast(accessor);
   447   const InstanceKlass* accessee_ik = InstanceKlass::cast(accessee);
   447   const InstanceKlass* accessee_ik = InstanceKlass::cast(accessee);
   448 
   448 
   449   // If either is on the other's host_klass chain, access is OK,
   449   // If either is on the other's unsafe_anonymous_host chain, access is OK,
   450   // because one is inside the other.
   450   // because one is inside the other.
   451   if (under_host_klass(accessor_ik, accessee_ik) ||
   451   if (under_unsafe_anonymous_host(accessor_ik, accessee_ik) ||
   452     under_host_klass(accessee_ik, accessor_ik))
   452     under_unsafe_anonymous_host(accessee_ik, accessor_ik))
   453     return true;
   453     return true;
   454 
   454 
   455   if ((RelaxAccessControlCheck &&
   455   if ((RelaxAccessControlCheck &&
   456     accessor_ik->major_version() < Verifier::NO_RELAX_ACCESS_CTRL_CHECK_VERSION &&
   456     accessor_ik->major_version() < Verifier::NO_RELAX_ACCESS_CTRL_CHECK_VERSION &&
   457     accessee_ik->major_version() < Verifier::NO_RELAX_ACCESS_CTRL_CHECK_VERSION) ||
   457     accessee_ik->major_version() < Verifier::NO_RELAX_ACCESS_CTRL_CHECK_VERSION) ||
   674       access.is_public()) {
   674       access.is_public()) {
   675     return true;
   675     return true;
   676   }
   676   }
   677 
   677 
   678   const Klass* host_class = current_class;
   678   const Klass* host_class = current_class;
   679   if (host_class->is_instance_klass() &&
   679   if (current_class->is_instance_klass() &&
   680       InstanceKlass::cast(host_class)->is_anonymous()) {
   680       InstanceKlass::cast(current_class)->is_unsafe_anonymous()) {
   681     host_class = InstanceKlass::cast(host_class)->host_klass();
   681     host_class = InstanceKlass::cast(current_class)->unsafe_anonymous_host();
   682     assert(host_class != NULL, "Anonymous class has null host class");
   682     assert(host_class != NULL, "Unsafe anonymous class has null host class");
   683     assert(!(host_class->is_instance_klass() &&
   683     assert(!(host_class->is_instance_klass() &&
   684            InstanceKlass::cast(host_class)->is_anonymous()),
   684            InstanceKlass::cast(host_class)->is_unsafe_anonymous()),
   685            "host_class should not be anonymous");
   685            "unsafe_anonymous_host should not be unsafe anonymous itself");
   686   }
   686   }
   687   if (host_class == member_class) {
   687   if (host_class == member_class) {
   688     return true;
   688     return true;
   689   }
   689   }
   690 
   690 
   708   if (!access.is_private() && is_same_class_package(current_class, member_class)) {
   708   if (!access.is_private() && is_same_class_package(current_class, member_class)) {
   709     return true;
   709     return true;
   710   }
   710   }
   711 
   711 
   712   // private access between different classes needs a nestmate check, but
   712   // private access between different classes needs a nestmate check, but
   713   // not for anonymous classes - so check host_class
   713   // not for unsafe anonymous classes - so check host_class
   714   if (access.is_private() && host_class == current_class) {
   714   if (access.is_private() && host_class == current_class) {
   715     if (current_class->is_instance_klass() && member_class->is_instance_klass() ) {
   715     if (current_class->is_instance_klass() && member_class->is_instance_klass() ) {
   716       InstanceKlass* cur_ik = const_cast<InstanceKlass*>(InstanceKlass::cast(current_class));
   716       InstanceKlass* cur_ik = const_cast<InstanceKlass*>(InstanceKlass::cast(current_class));
   717       InstanceKlass* field_ik = const_cast<InstanceKlass*>(InstanceKlass::cast(member_class));
   717       InstanceKlass* field_ik = const_cast<InstanceKlass*>(InstanceKlass::cast(member_class));
   718       // Nestmate access checks may require resolution and validation of the nest-host.
   718       // Nestmate access checks may require resolution and validation of the nest-host.
   740 }
   740 }
   741 
   741 
   742 // Checks that the 'outer' klass has declared 'inner' as being an inner klass. If not,
   742 // Checks that the 'outer' klass has declared 'inner' as being an inner klass. If not,
   743 // throw an incompatible class change exception
   743 // throw an incompatible class change exception
   744 // If inner_is_member, require the inner to be a member of the outer.
   744 // If inner_is_member, require the inner to be a member of the outer.
   745 // If !inner_is_member, require the inner to be anonymous (a non-member).
   745 // If !inner_is_member, require the inner to be unsafe anonymous (a non-member).
   746 // Caller is responsible for figuring out in advance which case must be true.
   746 // Caller is responsible for figuring out in advance which case must be true.
   747 void Reflection::check_for_inner_class(const InstanceKlass* outer, const InstanceKlass* inner,
   747 void Reflection::check_for_inner_class(const InstanceKlass* outer, const InstanceKlass* inner,
   748                                        bool inner_is_member, TRAPS) {
   748                                        bool inner_is_member, TRAPS) {
   749   InnerClassesIterator iter(outer);
   749   InnerClassesIterator iter(outer);
   750   constantPoolHandle cp   (THREAD, outer->constants());
   750   constantPoolHandle cp   (THREAD, outer->constants());