src/hotspot/share/oops/instanceKlass.cpp
changeset 51379 802f7e5e7e6b
parent 51338 aa3bfacc912c
child 51444 3e5d28e6de32
equal deleted inserted replaced
51378:5db166e5580b 51379:802f7e5e7e6b
  1049     assert(h_init_lock() != NULL, "The initialization state should never be set twice");
  1049     assert(h_init_lock() != NULL, "The initialization state should never be set twice");
  1050     set_init_state(state);
  1050     set_init_state(state);
  1051   }
  1051   }
  1052 }
  1052 }
  1053 
  1053 
       
  1054 Klass* InstanceKlass::implementor() const {
       
  1055   assert_locked_or_safepoint(Compile_lock);
       
  1056   Klass** k = adr_implementor();
       
  1057   if (k == NULL) {
       
  1058     return NULL;
       
  1059   } else {
       
  1060     return *k;
       
  1061   }
       
  1062 }
       
  1063 
       
  1064 void InstanceKlass::set_implementor(Klass* k) {
       
  1065   assert_lock_strong(Compile_lock);
       
  1066   assert(is_interface(), "not interface");
       
  1067   Klass** addr = adr_implementor();
       
  1068   assert(addr != NULL, "null addr");
       
  1069   if (addr != NULL) {
       
  1070     *addr = k;
       
  1071   }
       
  1072 }
       
  1073 
       
  1074 int  InstanceKlass::nof_implementors() const {
       
  1075   assert_lock_strong(Compile_lock);
       
  1076   Klass* k = implementor();
       
  1077   if (k == NULL) {
       
  1078     return 0;
       
  1079   } else if (k != this) {
       
  1080     return 1;
       
  1081   } else {
       
  1082     return 2;
       
  1083   }
       
  1084 }
       
  1085 
  1054 // The embedded _implementor field can only record one implementor.
  1086 // The embedded _implementor field can only record one implementor.
  1055 // When there are more than one implementors, the _implementor field
  1087 // When there are more than one implementors, the _implementor field
  1056 // is set to the interface Klass* itself. Following are the possible
  1088 // is set to the interface Klass* itself. Following are the possible
  1057 // values for the _implementor field:
  1089 // values for the _implementor field:
  1058 //   NULL                  - no implementor
  1090 //   NULL                  - no implementor
  1059 //   implementor Klass*    - one implementor
  1091 //   implementor Klass*    - one implementor
  1060 //   self                  - more than one implementor
  1092 //   self                  - more than one implementor
  1061 //
  1093 //
  1062 // The _implementor field only exists for interfaces.
  1094 // The _implementor field only exists for interfaces.
  1063 void InstanceKlass::add_implementor(Klass* k) {
  1095 void InstanceKlass::add_implementor(Klass* k) {
  1064   assert(Compile_lock->owned_by_self(), "");
  1096   assert_lock_strong(Compile_lock);
  1065   assert(is_interface(), "not interface");
  1097   assert(is_interface(), "not interface");
  1066   // Filter out my subinterfaces.
  1098   // Filter out my subinterfaces.
  1067   // (Note: Interfaces are never on the subklass list.)
  1099   // (Note: Interfaces are never on the subklass list.)
  1068   if (InstanceKlass::cast(k)->is_interface()) return;
  1100   if (InstanceKlass::cast(k)->is_interface()) return;
  1069 
  1101 
  2268 
  2300 
  2269   // Unlink the class
  2301   // Unlink the class
  2270   if (is_linked()) {
  2302   if (is_linked()) {
  2271     unlink_class();
  2303     unlink_class();
  2272   }
  2304   }
  2273   init_implementor();
  2305   {
       
  2306     MutexLocker ml(Compile_lock);
       
  2307     init_implementor();
       
  2308   }
  2274 
  2309 
  2275   constants()->remove_unshareable_info();
  2310   constants()->remove_unshareable_info();
  2276 
  2311 
  2277   for (int i = 0; i < methods()->length(); i++) {
  2312   for (int i = 0; i < methods()->length(); i++) {
  2278     Method* m = methods()->at(i);
  2313     Method* m = methods()->at(i);
  3087   }
  3122   }
  3088   if (n >= MaxSubklassPrintSize) st->print("(" INTX_FORMAT " more klasses...)", n - MaxSubklassPrintSize);
  3123   if (n >= MaxSubklassPrintSize) st->print("(" INTX_FORMAT " more klasses...)", n - MaxSubklassPrintSize);
  3089   st->cr();
  3124   st->cr();
  3090 
  3125 
  3091   if (is_interface()) {
  3126   if (is_interface()) {
       
  3127     MutexLocker ml(Compile_lock);
  3092     st->print_cr(BULLET"nof implementors:  %d", nof_implementors());
  3128     st->print_cr(BULLET"nof implementors:  %d", nof_implementors());
  3093     if (nof_implementors() == 1) {
  3129     if (nof_implementors() == 1) {
  3094       st->print_cr(BULLET"implementor:    ");
  3130       st->print_cr(BULLET"implementor:    ");
  3095       st->print("   ");
  3131       st->print("   ");
  3096       implementor()->print_value_on(st);
  3132       implementor()->print_value_on(st);
  3494 
  3530 
  3495     guarantee(sib->is_klass(), "should be klass");
  3531     guarantee(sib->is_klass(), "should be klass");
  3496     guarantee(sib->super() == super, "siblings should have same superklass");
  3532     guarantee(sib->super() == super, "siblings should have same superklass");
  3497   }
  3533   }
  3498 
  3534 
  3499   // Verify implementor fields
  3535   // Verify implementor fields requires the Compile_lock, but this is sometimes
  3500   Klass* im = implementor();
  3536   // called inside a safepoint, so don't verify.
  3501   if (im != NULL) {
       
  3502     guarantee(is_interface(), "only interfaces should have implementor set");
       
  3503     guarantee(im->is_klass(), "should be klass");
       
  3504     guarantee(!im->is_interface() || im == this,
       
  3505       "implementors cannot be interfaces");
       
  3506   }
       
  3507 
  3537 
  3508   // Verify local interfaces
  3538   // Verify local interfaces
  3509   if (local_interfaces()) {
  3539   if (local_interfaces()) {
  3510     Array<InstanceKlass*>* local_interfaces = this->local_interfaces();
  3540     Array<InstanceKlass*>* local_interfaces = this->local_interfaces();
  3511     for (int j = 0; j < local_interfaces->length(); j++) {
  3541     for (int j = 0; j < local_interfaces->length(); j++) {