64 // treated as any other public method in C for method over-ride purposes. |
64 // treated as any other public method in C for method over-ride purposes. |
65 void klassVtable::compute_vtable_size_and_num_mirandas( |
65 void klassVtable::compute_vtable_size_and_num_mirandas( |
66 int* vtable_length_ret, int* num_new_mirandas, |
66 int* vtable_length_ret, int* num_new_mirandas, |
67 GrowableArray<Method*>* all_mirandas, const Klass* super, |
67 GrowableArray<Method*>* all_mirandas, const Klass* super, |
68 Array<Method*>* methods, AccessFlags class_flags, u2 major_version, |
68 Array<Method*>* methods, AccessFlags class_flags, u2 major_version, |
69 Handle classloader, Symbol* classname, Array<Klass*>* local_interfaces, |
69 Handle classloader, Symbol* classname, Array<InstanceKlass*>* local_interfaces, |
70 TRAPS) { |
70 TRAPS) { |
71 NoSafepointVerifier nsv; |
71 NoSafepointVerifier nsv; |
72 |
72 |
73 // set up default result values |
73 // set up default result values |
74 int vtable_length = 0; |
74 int vtable_length = 0; |
164 // |
164 // |
165 // Revised lookup semantics introduced 1.3 (Kestrel beta) |
165 // Revised lookup semantics introduced 1.3 (Kestrel beta) |
166 void klassVtable::initialize_vtable(bool checkconstraints, TRAPS) { |
166 void klassVtable::initialize_vtable(bool checkconstraints, TRAPS) { |
167 |
167 |
168 // Note: Arrays can have intermediate array supers. Use java_super to skip them. |
168 // Note: Arrays can have intermediate array supers. Use java_super to skip them. |
169 Klass* super = _klass->java_super(); |
169 InstanceKlass* super = _klass->java_super(); |
170 int nofNewEntries = 0; |
170 int nofNewEntries = 0; |
171 |
171 |
172 bool is_shared = _klass->is_shared(); |
172 bool is_shared = _klass->is_shared(); |
173 |
173 |
174 if (!_klass->is_array_klass()) { |
174 if (!_klass->is_array_klass()) { |
869 void klassVtable::get_mirandas(GrowableArray<Method*>* new_mirandas, |
869 void klassVtable::get_mirandas(GrowableArray<Method*>* new_mirandas, |
870 GrowableArray<Method*>* all_mirandas, |
870 GrowableArray<Method*>* all_mirandas, |
871 const Klass* super, |
871 const Klass* super, |
872 Array<Method*>* class_methods, |
872 Array<Method*>* class_methods, |
873 Array<Method*>* default_methods, |
873 Array<Method*>* default_methods, |
874 Array<Klass*>* local_interfaces, |
874 Array<InstanceKlass*>* local_interfaces, |
875 bool is_interface) { |
875 bool is_interface) { |
876 assert((new_mirandas->length() == 0) , "current mirandas must be 0"); |
876 assert((new_mirandas->length() == 0) , "current mirandas must be 0"); |
877 |
877 |
878 // iterate thru the local interfaces looking for a miranda |
878 // iterate thru the local interfaces looking for a miranda |
879 int num_local_ifs = local_interfaces->length(); |
879 int num_local_ifs = local_interfaces->length(); |
881 InstanceKlass *ik = InstanceKlass::cast(local_interfaces->at(i)); |
881 InstanceKlass *ik = InstanceKlass::cast(local_interfaces->at(i)); |
882 add_new_mirandas_to_lists(new_mirandas, all_mirandas, |
882 add_new_mirandas_to_lists(new_mirandas, all_mirandas, |
883 ik->methods(), class_methods, |
883 ik->methods(), class_methods, |
884 default_methods, super, is_interface); |
884 default_methods, super, is_interface); |
885 // iterate thru each local's super interfaces |
885 // iterate thru each local's super interfaces |
886 Array<Klass*>* super_ifs = ik->transitive_interfaces(); |
886 Array<InstanceKlass*>* super_ifs = ik->transitive_interfaces(); |
887 int num_super_ifs = super_ifs->length(); |
887 int num_super_ifs = super_ifs->length(); |
888 for (int j = 0; j < num_super_ifs; j++) { |
888 for (int j = 0; j < num_super_ifs; j++) { |
889 InstanceKlass *sik = InstanceKlass::cast(super_ifs->at(j)); |
889 InstanceKlass *sik = super_ifs->at(j); |
890 add_new_mirandas_to_lists(new_mirandas, all_mirandas, |
890 add_new_mirandas_to_lists(new_mirandas, all_mirandas, |
891 sik->methods(), class_methods, |
891 sik->methods(), class_methods, |
892 default_methods, super, is_interface); |
892 default_methods, super, is_interface); |
893 } |
893 } |
894 } |
894 } |
1080 // Initialization |
1080 // Initialization |
1081 void klassItable::initialize_itable(bool checkconstraints, TRAPS) { |
1081 void klassItable::initialize_itable(bool checkconstraints, TRAPS) { |
1082 if (_klass->is_interface()) { |
1082 if (_klass->is_interface()) { |
1083 // This needs to go after vtable indices are assigned but |
1083 // This needs to go after vtable indices are assigned but |
1084 // before implementors need to know the number of itable indices. |
1084 // before implementors need to know the number of itable indices. |
1085 assign_itable_indices_for_interface(_klass, THREAD); |
1085 assign_itable_indices_for_interface(InstanceKlass::cast(_klass), THREAD); |
1086 } |
1086 } |
1087 |
1087 |
1088 // Cannot be setup doing bootstrapping, interfaces don't have |
1088 // Cannot be setup doing bootstrapping, interfaces don't have |
1089 // itables, and klass with only ones entry have empty itables |
1089 // itables, and klass with only ones entry have empty itables |
1090 if (Universe::is_bootstrapping() || |
1090 if (Universe::is_bootstrapping() || |
1105 for(i = 0; i < num_interfaces; i++) { |
1105 for(i = 0; i < num_interfaces; i++) { |
1106 itableOffsetEntry* ioe = offset_entry(i); |
1106 itableOffsetEntry* ioe = offset_entry(i); |
1107 HandleMark hm(THREAD); |
1107 HandleMark hm(THREAD); |
1108 Klass* interf = ioe->interface_klass(); |
1108 Klass* interf = ioe->interface_klass(); |
1109 assert(interf != NULL && ioe->offset() != 0, "bad offset entry in itable"); |
1109 assert(interf != NULL && ioe->offset() != 0, "bad offset entry in itable"); |
1110 initialize_itable_for_interface(ioe->offset(), interf, checkconstraints, CHECK); |
1110 initialize_itable_for_interface(ioe->offset(), InstanceKlass::cast(interf), checkconstraints, CHECK); |
1111 } |
1111 } |
1112 |
1112 |
1113 } |
1113 } |
1114 // Check that the last entry is empty |
1114 // Check that the last entry is empty |
1115 itableOffsetEntry* ioe = offset_entry(size_offset_table() - 1); |
1115 itableOffsetEntry* ioe = offset_entry(size_offset_table() - 1); |
1126 // e.g., CharSequence.toString (from initialize_vtable) |
1126 // e.g., CharSequence.toString (from initialize_vtable) |
1127 // if (m->has_vtable_index()) return false; // NO! |
1127 // if (m->has_vtable_index()) return false; // NO! |
1128 return true; |
1128 return true; |
1129 } |
1129 } |
1130 |
1130 |
1131 int klassItable::assign_itable_indices_for_interface(Klass* klass, TRAPS) { |
1131 int klassItable::assign_itable_indices_for_interface(InstanceKlass* klass, TRAPS) { |
1132 // an interface does not have an itable, but its methods need to be numbered |
1132 // an interface does not have an itable, but its methods need to be numbered |
1133 ResourceMark rm(THREAD); |
1133 ResourceMark rm(THREAD); |
1134 log_develop_debug(itables)("%3d: Initializing itable indices for interface %s", |
1134 log_develop_debug(itables)("%3d: Initializing itable indices for interface %s", |
1135 ++initialize_count, klass->name()->as_C_string()); |
1135 ++initialize_count, klass->name()->as_C_string()); |
1136 Array<Method*>* methods = InstanceKlass::cast(klass)->methods(); |
1136 Array<Method*>* methods = klass->methods(); |
1137 int nof_methods = methods->length(); |
1137 int nof_methods = methods->length(); |
1138 int ime_num = 0; |
1138 int ime_num = 0; |
1139 for (int i = 0; i < nof_methods; i++) { |
1139 for (int i = 0; i < nof_methods; i++) { |
1140 Method* m = methods->at(i); |
1140 Method* m = methods->at(i); |
1141 if (interface_method_needs_itable_index(m)) { |
1141 if (interface_method_needs_itable_index(m)) { |
1168 } |
1168 } |
1169 assert(ime_num == method_count_for_interface(klass), "proper sizing"); |
1169 assert(ime_num == method_count_for_interface(klass), "proper sizing"); |
1170 return ime_num; |
1170 return ime_num; |
1171 } |
1171 } |
1172 |
1172 |
1173 int klassItable::method_count_for_interface(Klass* interf) { |
1173 int klassItable::method_count_for_interface(InstanceKlass* interf) { |
1174 assert(interf->is_instance_klass(), "must be"); |
|
1175 assert(interf->is_interface(), "must be"); |
1174 assert(interf->is_interface(), "must be"); |
1176 Array<Method*>* methods = InstanceKlass::cast(interf)->methods(); |
1175 Array<Method*>* methods = interf->methods(); |
1177 int nof_methods = methods->length(); |
1176 int nof_methods = methods->length(); |
1178 int length = 0; |
1177 int length = 0; |
1179 while (nof_methods > 0) { |
1178 while (nof_methods > 0) { |
1180 Method* m = methods->at(nof_methods-1); |
1179 Method* m = methods->at(nof_methods-1); |
1181 if (m->has_itable_index()) { |
1180 if (m->has_itable_index()) { |
1195 // itable indices |
1194 // itable indices |
1196 return length; |
1195 return length; |
1197 } |
1196 } |
1198 |
1197 |
1199 |
1198 |
1200 void klassItable::initialize_itable_for_interface(int method_table_offset, Klass* interf, bool checkconstraints, TRAPS) { |
1199 void klassItable::initialize_itable_for_interface(int method_table_offset, InstanceKlass* interf, bool checkconstraints, TRAPS) { |
1201 Array<Method*>* methods = InstanceKlass::cast(interf)->methods(); |
1200 assert(interf->is_interface(), "must be"); |
|
1201 Array<Method*>* methods = interf->methods(); |
1202 int nof_methods = methods->length(); |
1202 int nof_methods = methods->length(); |
1203 HandleMark hm; |
1203 HandleMark hm; |
1204 Handle interface_loader (THREAD, InstanceKlass::cast(interf)->class_loader()); |
1204 Handle interface_loader (THREAD, interf->class_loader()); |
1205 |
1205 |
1206 int ime_count = method_count_for_interface(interf); |
1206 int ime_count = method_count_for_interface(interf); |
1207 for (int i = 0; i < nof_methods; i++) { |
1207 for (int i = 0; i < nof_methods; i++) { |
1208 Method* m = methods->at(i); |
1208 Method* m = methods->at(i); |
1209 methodHandle target; |
1209 methodHandle target; |
1347 #endif // INCLUDE_JVMTI |
1347 #endif // INCLUDE_JVMTI |
1348 |
1348 |
1349 // Setup |
1349 // Setup |
1350 class InterfaceVisiterClosure : public StackObj { |
1350 class InterfaceVisiterClosure : public StackObj { |
1351 public: |
1351 public: |
1352 virtual void doit(Klass* intf, int method_count) = 0; |
1352 virtual void doit(InstanceKlass* intf, int method_count) = 0; |
1353 }; |
1353 }; |
1354 |
1354 |
1355 // Visit all interfaces with at least one itable method |
1355 // Visit all interfaces with at least one itable method |
1356 void visit_all_interfaces(Array<Klass*>* transitive_intf, InterfaceVisiterClosure *blk) { |
1356 void visit_all_interfaces(Array<InstanceKlass*>* transitive_intf, InterfaceVisiterClosure *blk) { |
1357 // Handle array argument |
1357 // Handle array argument |
1358 for(int i = 0; i < transitive_intf->length(); i++) { |
1358 for(int i = 0; i < transitive_intf->length(); i++) { |
1359 Klass* intf = transitive_intf->at(i); |
1359 InstanceKlass* intf = transitive_intf->at(i); |
1360 assert(intf->is_interface(), "sanity check"); |
1360 assert(intf->is_interface(), "sanity check"); |
1361 |
1361 |
1362 // Find no. of itable methods |
1362 // Find no. of itable methods |
1363 int method_count = 0; |
1363 int method_count = 0; |
1364 // method_count = klassItable::method_count_for_interface(intf); |
1364 // method_count = klassItable::method_count_for_interface(intf); |
1365 Array<Method*>* methods = InstanceKlass::cast(intf)->methods(); |
1365 Array<Method*>* methods = intf->methods(); |
1366 if (methods->length() > 0) { |
1366 if (methods->length() > 0) { |
1367 for (int i = methods->length(); --i >= 0; ) { |
1367 for (int i = methods->length(); --i >= 0; ) { |
1368 if (interface_method_needs_itable_index(methods->at(i))) { |
1368 if (interface_method_needs_itable_index(methods->at(i))) { |
1369 method_count++; |
1369 method_count++; |
1370 } |
1370 } |
1372 } |
1372 } |
1373 |
1373 |
1374 // Visit all interfaces which either have any methods or can participate in receiver type check. |
1374 // Visit all interfaces which either have any methods or can participate in receiver type check. |
1375 // We do not bother to count methods in transitive interfaces, although that would allow us to skip |
1375 // We do not bother to count methods in transitive interfaces, although that would allow us to skip |
1376 // this step in the rare case of a zero-method interface extending another zero-method interface. |
1376 // this step in the rare case of a zero-method interface extending another zero-method interface. |
1377 if (method_count > 0 || InstanceKlass::cast(intf)->transitive_interfaces()->length() > 0) { |
1377 if (method_count > 0 || intf->transitive_interfaces()->length() > 0) { |
1378 blk->doit(intf, method_count); |
1378 blk->doit(intf, method_count); |
1379 } |
1379 } |
1380 } |
1380 } |
1381 } |
1381 } |
1382 |
1382 |
1388 CountInterfacesClosure() { _nof_methods = 0; _nof_interfaces = 0; } |
1388 CountInterfacesClosure() { _nof_methods = 0; _nof_interfaces = 0; } |
1389 |
1389 |
1390 int nof_methods() const { return _nof_methods; } |
1390 int nof_methods() const { return _nof_methods; } |
1391 int nof_interfaces() const { return _nof_interfaces; } |
1391 int nof_interfaces() const { return _nof_interfaces; } |
1392 |
1392 |
1393 void doit(Klass* intf, int method_count) { _nof_methods += method_count; _nof_interfaces++; } |
1393 void doit(InstanceKlass* intf, int method_count) { _nof_methods += method_count; _nof_interfaces++; } |
1394 }; |
1394 }; |
1395 |
1395 |
1396 class SetupItableClosure : public InterfaceVisiterClosure { |
1396 class SetupItableClosure : public InterfaceVisiterClosure { |
1397 private: |
1397 private: |
1398 itableOffsetEntry* _offset_entry; |
1398 itableOffsetEntry* _offset_entry; |
1405 _method_entry = method_entry; |
1405 _method_entry = method_entry; |
1406 } |
1406 } |
1407 |
1407 |
1408 itableMethodEntry* method_entry() const { return _method_entry; } |
1408 itableMethodEntry* method_entry() const { return _method_entry; } |
1409 |
1409 |
1410 void doit(Klass* intf, int method_count) { |
1410 void doit(InstanceKlass* intf, int method_count) { |
1411 int offset = ((address)_method_entry) - _klass_begin; |
1411 int offset = ((address)_method_entry) - _klass_begin; |
1412 _offset_entry->initialize(intf, offset); |
1412 _offset_entry->initialize(intf, offset); |
1413 _offset_entry++; |
1413 _offset_entry++; |
1414 _method_entry += method_count; |
1414 _method_entry += method_count; |
1415 } |
1415 } |
1416 }; |
1416 }; |
1417 |
1417 |
1418 int klassItable::compute_itable_size(Array<Klass*>* transitive_interfaces) { |
1418 int klassItable::compute_itable_size(Array<InstanceKlass*>* transitive_interfaces) { |
1419 // Count no of interfaces and total number of interface methods |
1419 // Count no of interfaces and total number of interface methods |
1420 CountInterfacesClosure cic; |
1420 CountInterfacesClosure cic; |
1421 visit_all_interfaces(transitive_interfaces, &cic); |
1421 visit_all_interfaces(transitive_interfaces, &cic); |
1422 |
1422 |
1423 // There's alway an extra itable entry so we can null-terminate it. |
1423 // There's alway an extra itable entry so we can null-terminate it. |
1466 #endif |
1466 #endif |
1467 } |
1467 } |
1468 |
1468 |
1469 |
1469 |
1470 // inverse to itable_index |
1470 // inverse to itable_index |
1471 Method* klassItable::method_for_itable_index(Klass* intf, int itable_index) { |
1471 Method* klassItable::method_for_itable_index(InstanceKlass* intf, int itable_index) { |
1472 assert(InstanceKlass::cast(intf)->is_interface(), "sanity check"); |
1472 assert(intf->is_interface(), "sanity check"); |
1473 assert(intf->verify_itable_index(itable_index), ""); |
1473 assert(intf->verify_itable_index(itable_index), ""); |
1474 Array<Method*>* methods = InstanceKlass::cast(intf)->methods(); |
1474 Array<Method*>* methods = InstanceKlass::cast(intf)->methods(); |
1475 |
1475 |
1476 if (itable_index < 0 || itable_index >= method_count_for_interface(intf)) |
1476 if (itable_index < 0 || itable_index >= method_count_for_interface(intf)) |
1477 return NULL; // help caller defend against bad indices |
1477 return NULL; // help caller defend against bad indices |