565 ObjectLocker ol(this_oop, THREAD); |
565 ObjectLocker ol(this_oop, THREAD); |
566 this_oop->set_init_state(state); |
566 this_oop->set_init_state(state); |
567 ol.notify_all(CHECK); |
567 ol.notify_all(CHECK); |
568 } |
568 } |
569 |
569 |
|
570 // The embedded _implementor field can only record one implementor. |
|
571 // When there are more than one implementors, the _implementor field |
|
572 // is set to the interface klassOop itself. Following are the possible |
|
573 // values for the _implementor field: |
|
574 // NULL - no implementor |
|
575 // implementor klassOop - one implementor |
|
576 // self - more than one implementor |
|
577 // |
|
578 // The _implementor field only exists for interfaces. |
570 void instanceKlass::add_implementor(klassOop k) { |
579 void instanceKlass::add_implementor(klassOop k) { |
571 assert(Compile_lock->owned_by_self(), ""); |
580 assert(Compile_lock->owned_by_self(), ""); |
|
581 assert(is_interface(), "not interface"); |
572 // Filter out my subinterfaces. |
582 // Filter out my subinterfaces. |
573 // (Note: Interfaces are never on the subklass list.) |
583 // (Note: Interfaces are never on the subklass list.) |
574 if (instanceKlass::cast(k)->is_interface()) return; |
584 if (instanceKlass::cast(k)->is_interface()) return; |
575 |
585 |
576 // Filter out subclasses whose supers already implement me. |
586 // Filter out subclasses whose supers already implement me. |
581 // We only need to check one immediate superclass, since the |
591 // We only need to check one immediate superclass, since the |
582 // implements_interface query looks at transitive_interfaces. |
592 // implements_interface query looks at transitive_interfaces. |
583 // Any supers of the super have the same (or fewer) transitive_interfaces. |
593 // Any supers of the super have the same (or fewer) transitive_interfaces. |
584 return; |
594 return; |
585 |
595 |
586 // Update number of implementors |
596 klassOop ik = implementor(); |
587 int i = _nof_implementors++; |
597 if (ik == NULL) { |
588 |
598 set_implementor(k); |
589 // Record this implementor, if there are not too many already |
599 } else if (ik != this->as_klassOop()) { |
590 if (i < implementors_limit) { |
600 // There is already an implementor. Use itself as an indicator of |
591 assert(_implementors[i] == NULL, "should be exactly one implementor"); |
601 // more than one implementors. |
592 oop_store_without_check((oop*)&_implementors[i], k); |
602 set_implementor(this->as_klassOop()); |
593 } else if (i == implementors_limit) { |
|
594 // clear out the list on first overflow |
|
595 for (int i2 = 0; i2 < implementors_limit; i2++) |
|
596 oop_store_without_check((oop*)&_implementors[i2], NULL); |
|
597 } |
603 } |
598 |
604 |
599 // The implementor also implements the transitive_interfaces |
605 // The implementor also implements the transitive_interfaces |
600 for (int index = 0; index < local_interfaces()->length(); index++) { |
606 for (int index = 0; index < local_interfaces()->length(); index++) { |
601 instanceKlass::cast(klassOop(local_interfaces()->obj_at(index)))->add_implementor(k); |
607 instanceKlass::cast(klassOop(local_interfaces()->obj_at(index)))->add_implementor(k); |
602 } |
608 } |
603 } |
609 } |
604 |
610 |
605 void instanceKlass::init_implementor() { |
611 void instanceKlass::init_implementor() { |
606 for (int i = 0; i < implementors_limit; i++) |
612 if (is_interface()) { |
607 oop_store_without_check((oop*)&_implementors[i], NULL); |
613 set_implementor(NULL); |
608 _nof_implementors = 0; |
614 } |
609 } |
615 } |
610 |
616 |
611 |
617 |
612 void instanceKlass::process_interfaces(Thread *thread) { |
618 void instanceKlass::process_interfaces(Thread *thread) { |
613 // link this class into the implementors list of every interface it implements |
619 // link this class into the implementors list of every interface it implements |
1847 // Subklass and sibling links are handled by Klass::follow_weak_klass_links |
1853 // Subklass and sibling links are handled by Klass::follow_weak_klass_links |
1848 |
1854 |
1849 void instanceKlass::follow_weak_klass_links( |
1855 void instanceKlass::follow_weak_klass_links( |
1850 BoolObjectClosure* is_alive, OopClosure* keep_alive) { |
1856 BoolObjectClosure* is_alive, OopClosure* keep_alive) { |
1851 assert(is_alive->do_object_b(as_klassOop()), "this oop should be live"); |
1857 assert(is_alive->do_object_b(as_klassOop()), "this oop should be live"); |
1852 if (ClassUnloading) { |
1858 |
1853 for (int i = 0; i < implementors_limit; i++) { |
1859 if (is_interface()) { |
1854 klassOop impl = _implementors[i]; |
1860 if (ClassUnloading) { |
1855 if (impl == NULL) break; // no more in the list |
1861 klassOop impl = implementor(); |
1856 if (!is_alive->do_object_b(impl)) { |
1862 if (impl != NULL) { |
1857 // remove this guy from the list by overwriting him with the tail |
1863 if (!is_alive->do_object_b(impl)) { |
1858 int lasti = --_nof_implementors; |
1864 // remove this guy |
1859 assert(lasti >= i && lasti < implementors_limit, "just checking"); |
1865 *start_of_implementor() = NULL; |
1860 _implementors[i] = _implementors[lasti]; |
1866 } |
1861 _implementors[lasti] = NULL; |
|
1862 --i; // rerun the loop at this index |
|
1863 } |
1867 } |
1864 } |
1868 } else { |
1865 } else { |
1869 assert(adr_implementor() != NULL, "just checking"); |
1866 for (int i = 0; i < implementors_limit; i++) { |
1870 keep_alive->do_oop(adr_implementor()); |
1867 keep_alive->do_oop(&adr_implementors()[i]); |
1871 } |
1868 } |
1872 } |
1869 } |
1873 |
1870 Klass::follow_weak_klass_links(is_alive, keep_alive); |
1874 Klass::follow_weak_klass_links(is_alive, keep_alive); |
1871 } |
1875 } |
1872 |
1876 |
1873 void instanceKlass::remove_unshareable_info() { |
1877 void instanceKlass::remove_unshareable_info() { |
1874 Klass::remove_unshareable_info(); |
1878 Klass::remove_unshareable_info(); |