src/hotspot/share/oops/instanceKlass.cpp
changeset 52784 621efe32eb0b
parent 52781 436097b038a1
child 53152 08db5aa02f7b
child 53225 b11483a74e5d
equal deleted inserted replaced
52783:5827f12ecbf0 52784:621efe32eb0b
  1068     set_init_state(state);
  1068     set_init_state(state);
  1069   }
  1069   }
  1070 }
  1070 }
  1071 
  1071 
  1072 Klass* InstanceKlass::implementor() const {
  1072 Klass* InstanceKlass::implementor() const {
  1073   assert_locked_or_safepoint(Compile_lock);
  1073   Klass* volatile* k = adr_implementor();
  1074   Klass** k = adr_implementor();
       
  1075   if (k == NULL) {
  1074   if (k == NULL) {
  1076     return NULL;
  1075     return NULL;
  1077   } else {
  1076   } else {
  1078     return *k;
  1077     // This load races with inserts, and therefore needs acquire.
  1079   }
  1078     Klass* kls = OrderAccess::load_acquire(k);
  1080 }
  1079     if (kls != NULL && !kls->is_loader_alive()) {
       
  1080       return NULL;  // don't return unloaded class
       
  1081     } else {
       
  1082       return kls;
       
  1083     }
       
  1084   }
       
  1085 }
       
  1086 
  1081 
  1087 
  1082 void InstanceKlass::set_implementor(Klass* k) {
  1088 void InstanceKlass::set_implementor(Klass* k) {
  1083   assert_lock_strong(Compile_lock);
  1089   assert_lock_strong(Compile_lock);
  1084   assert(is_interface(), "not interface");
  1090   assert(is_interface(), "not interface");
  1085   Klass** addr = adr_implementor();
  1091   Klass* volatile* addr = adr_implementor();
  1086   assert(addr != NULL, "null addr");
  1092   assert(addr != NULL, "null addr");
  1087   if (addr != NULL) {
  1093   if (addr != NULL) {
  1088     *addr = k;
  1094     OrderAccess::release_store(addr, k);
  1089   }
  1095   }
  1090 }
  1096 }
  1091 
  1097 
  1092 int  InstanceKlass::nof_implementors() const {
  1098 int  InstanceKlass::nof_implementors() const {
  1093   assert_lock_strong(Compile_lock);
       
  1094   Klass* k = implementor();
  1099   Klass* k = implementor();
  1095   if (k == NULL) {
  1100   if (k == NULL) {
  1096     return 0;
  1101     return 0;
  1097   } else if (k != this) {
  1102   } else if (k != this) {
  1098     return 1;
  1103     return 1;
  2153 }
  2158 }
  2154 
  2159 
  2155 void InstanceKlass::clean_implementors_list() {
  2160 void InstanceKlass::clean_implementors_list() {
  2156   assert(is_loader_alive(), "this klass should be live");
  2161   assert(is_loader_alive(), "this klass should be live");
  2157   if (is_interface()) {
  2162   if (is_interface()) {
  2158     if (ClassUnloading) {
  2163     assert (ClassUnloading, "only called for ClassUnloading");
  2159       Klass* impl = implementor();
  2164     for (;;) {
  2160       if (impl != NULL) {
  2165       // Use load_acquire due to competing with inserts
  2161         if (!impl->is_loader_alive()) {
  2166       Klass* impl = OrderAccess::load_acquire(adr_implementor());
  2162           // remove this guy
  2167       if (impl != NULL && !impl->is_loader_alive()) {
  2163           Klass** klass = adr_implementor();
  2168         // NULL this field, might be an unloaded klass or NULL
  2164           assert(klass != NULL, "null klass");
  2169         Klass* volatile* klass = adr_implementor();
  2165           if (klass != NULL) {
  2170         if (Atomic::cmpxchg((Klass*)NULL, klass, impl) == impl) {
  2166             *klass = NULL;
  2171           // Successfully unlinking implementor.
       
  2172           if (log_is_enabled(Trace, class, unload)) {
       
  2173             ResourceMark rm;
       
  2174             log_trace(class, unload)("unlinking class (implementor): %s", impl->external_name());
  2167           }
  2175           }
       
  2176           return;
  2168         }
  2177         }
       
  2178       } else {
       
  2179         return;
  2169       }
  2180       }
  2170     }
  2181     }
  2171   }
  2182   }
  2172 }
  2183 }
  2173 
  2184 
  3104   }
  3115   }
  3105   if (n >= MaxSubklassPrintSize) st->print("(" INTX_FORMAT " more klasses...)", n - MaxSubklassPrintSize);
  3116   if (n >= MaxSubklassPrintSize) st->print("(" INTX_FORMAT " more klasses...)", n - MaxSubklassPrintSize);
  3106   st->cr();
  3117   st->cr();
  3107 
  3118 
  3108   if (is_interface()) {
  3119   if (is_interface()) {
  3109     MutexLocker ml(Compile_lock);
       
  3110     st->print_cr(BULLET"nof implementors:  %d", nof_implementors());
  3120     st->print_cr(BULLET"nof implementors:  %d", nof_implementors());
  3111     if (nof_implementors() == 1) {
  3121     if (nof_implementors() == 1) {
  3112       st->print_cr(BULLET"implementor:    ");
  3122       st->print_cr(BULLET"implementor:    ");
  3113       st->print("   ");
  3123       st->print("   ");
  3114       implementor()->print_value_on(st);
  3124       implementor()->print_value_on(st);
  3511     }
  3521     }
  3512 
  3522 
  3513     guarantee(sib->is_klass(), "should be klass");
  3523     guarantee(sib->is_klass(), "should be klass");
  3514     guarantee(sib->super() == super, "siblings should have same superklass");
  3524     guarantee(sib->super() == super, "siblings should have same superklass");
  3515   }
  3525   }
  3516 
       
  3517   // Verify implementor fields requires the Compile_lock, but this is sometimes
       
  3518   // called inside a safepoint, so don't verify.
       
  3519 
  3526 
  3520   // Verify local interfaces
  3527   // Verify local interfaces
  3521   if (local_interfaces()) {
  3528   if (local_interfaces()) {
  3522     Array<InstanceKlass*>* local_interfaces = this->local_interfaces();
  3529     Array<InstanceKlass*>* local_interfaces = this->local_interfaces();
  3523     for (int j = 0; j < local_interfaces->length(); j++) {
  3530     for (int j = 0; j < local_interfaces->length(); j++) {