868 |
868 |
869 static int initialize_count = 0; |
869 static int initialize_count = 0; |
870 |
870 |
871 // Initialization |
871 // Initialization |
872 void klassItable::initialize_itable(bool checkconstraints, TRAPS) { |
872 void klassItable::initialize_itable(bool checkconstraints, TRAPS) { |
873 // Cannot be setup doing bootstrapping |
873 // Cannot be setup doing bootstrapping, interfaces don't have |
874 if (Universe::is_bootstrapping()) return; |
874 // itables, and klass with only ones entry have empty itables |
875 |
875 if (Universe::is_bootstrapping() || |
876 int num_interfaces = nof_interfaces(); |
876 _klass->is_interface() || |
|
877 _klass->itable_length() == itableOffsetEntry::size()) return; |
|
878 |
|
879 // There's alway an extra itable entry so we can null-terminate it. |
|
880 guarantee(size_offset_table() >= 1, "too small"); |
|
881 int num_interfaces = size_offset_table() - 1; |
877 if (num_interfaces > 0) { |
882 if (num_interfaces > 0) { |
878 if (TraceItables) tty->print_cr("%3d: Initializing itables for %s", ++initialize_count, _klass->name()->as_C_string()); |
883 if (TraceItables) tty->print_cr("%3d: Initializing itables for %s", ++initialize_count, |
879 |
884 _klass->name()->as_C_string()); |
880 // In debug mode, we got an extra NULL/NULL entry |
885 |
881 debug_only(num_interfaces--); |
|
882 assert(num_interfaces > 0, "to few interfaces in offset itable"); |
|
883 |
886 |
884 // Interate through all interfaces |
887 // Interate through all interfaces |
885 int i; |
888 int i; |
886 for(i = 0; i < num_interfaces; i++) { |
889 for(i = 0; i < num_interfaces; i++) { |
887 itableOffsetEntry* ioe = offset_entry(i); |
890 itableOffsetEntry* ioe = offset_entry(i); |
888 KlassHandle interf_h (THREAD, ioe->interface_klass()); |
891 KlassHandle interf_h (THREAD, ioe->interface_klass()); |
889 assert(interf_h() != NULL && ioe->offset() != 0, "bad offset entry in itable"); |
892 assert(interf_h() != NULL && ioe->offset() != 0, "bad offset entry in itable"); |
890 initialize_itable_for_interface(ioe->offset(), interf_h, checkconstraints, CHECK); |
893 initialize_itable_for_interface(ioe->offset(), interf_h, checkconstraints, CHECK); |
891 } |
894 } |
892 |
895 |
893 #ifdef ASSERT |
896 } |
894 // Check that the last entry is empty |
897 // Check that the last entry is empty |
895 itableOffsetEntry* ioe = offset_entry(i); |
898 itableOffsetEntry* ioe = offset_entry(size_offset_table() - 1); |
896 assert(ioe->interface_klass() == NULL && ioe->offset() == 0, "terminator entry missing"); |
899 guarantee(ioe->interface_klass() == NULL && ioe->offset() == 0, "terminator entry missing"); |
897 #endif |
|
898 } |
|
899 } |
900 } |
900 |
901 |
901 |
902 |
902 void klassItable::initialize_itable_for_interface(int method_table_offset, KlassHandle interf_h, bool checkconstraints, TRAPS) { |
903 void klassItable::initialize_itable_for_interface(int method_table_offset, KlassHandle interf_h, bool checkconstraints, TRAPS) { |
903 objArrayHandle methods(THREAD, instanceKlass::cast(interf_h())->methods()); |
904 objArrayHandle methods(THREAD, instanceKlass::cast(interf_h())->methods()); |
1083 int klassItable::compute_itable_size(objArrayHandle transitive_interfaces) { |
1084 int klassItable::compute_itable_size(objArrayHandle transitive_interfaces) { |
1084 // Count no of interfaces and total number of interface methods |
1085 // Count no of interfaces and total number of interface methods |
1085 CountInterfacesClosure cic; |
1086 CountInterfacesClosure cic; |
1086 visit_all_interfaces(transitive_interfaces(), &cic); |
1087 visit_all_interfaces(transitive_interfaces(), &cic); |
1087 |
1088 |
1088 // Add one extra entry in debug mode, so we can null-terminate the table |
1089 // There's alway an extra itable entry so we can null-terminate it. |
1089 int nof_methods = cic.nof_methods(); |
1090 int itable_size = calc_itable_size(cic.nof_interfaces() + 1, cic.nof_methods()); |
1090 int nof_interfaces = cic.nof_interfaces(); |
|
1091 debug_only(if (nof_interfaces > 0) nof_interfaces++); |
|
1092 |
|
1093 int itable_size = calc_itable_size(nof_interfaces, nof_methods); |
|
1094 |
1091 |
1095 // Statistics |
1092 // Statistics |
1096 update_stats(itable_size * HeapWordSize); |
1093 update_stats(itable_size * HeapWordSize); |
1097 |
1094 |
1098 return itable_size; |
1095 return itable_size; |
1108 CountInterfacesClosure cic; |
1105 CountInterfacesClosure cic; |
1109 visit_all_interfaces(klass->transitive_interfaces(), &cic); |
1106 visit_all_interfaces(klass->transitive_interfaces(), &cic); |
1110 int nof_methods = cic.nof_methods(); |
1107 int nof_methods = cic.nof_methods(); |
1111 int nof_interfaces = cic.nof_interfaces(); |
1108 int nof_interfaces = cic.nof_interfaces(); |
1112 |
1109 |
1113 // Add one extra entry in debug mode, so we can null-terminate the table |
1110 // Add one extra entry so we can null-terminate the table |
1114 debug_only(if (nof_interfaces > 0) nof_interfaces++); |
1111 nof_interfaces++; |
1115 |
1112 |
1116 assert(compute_itable_size(objArrayHandle(klass->transitive_interfaces())) == |
1113 assert(compute_itable_size(objArrayHandle(klass->transitive_interfaces())) == |
1117 calc_itable_size(nof_interfaces, nof_methods), |
1114 calc_itable_size(nof_interfaces, nof_methods), |
1118 "mismatch calculation of itable size"); |
1115 "mismatch calculation of itable size"); |
1119 |
1116 |