1213 interf->class_in_module_of_loader(false, true),
1214 method_holder->class_in_module_of_loader(false, true));
1215 THROW_MSG(vmSymbols::java_lang_LinkageError(), ss.as_string());
1216 }
1217 }
1218 }
1219 ime++;
1220 }
1221 }
1222
1223 void klassItable::initialize_itable_and_check_constraints(TRAPS) {
1224 // Save a super interface from each itable entry to do constraint checking
1225 ResourceMark rm(THREAD);
1226 GrowableArray<Method*>* supers =
1227 new GrowableArray<Method*>(_size_method_table, _size_method_table, nullptr);
1228 initialize_itable(supers);
1229 check_constraints(supers, CHECK);
1230 }
1231
1232 inline bool interface_method_needs_itable_index(Method* m) {
1233 if (m->is_static()) return false; // e.g., Stream.empty
1234 if (m->is_initializer()) return false; // <init> or <clinit>
1235 if (m->is_private()) return false; // uses direct call
1236 // If an interface redeclares a method from java.lang.Object,
1237 // it should already have a vtable index, don't touch it.
1238 // e.g., CharSequence.toString (from initialize_vtable)
1239 // if (m->has_vtable_index()) return false; // NO!
1240 return true;
1241 }
1242
1243 int klassItable::assign_itable_indices_for_interface(InstanceKlass* klass) {
1244 // an interface does not have an itable, but its methods need to be numbered
1245 if (log_develop_is_enabled(Trace, itables)) {
1246 ResourceMark rm;
1247 log_develop_debug(itables)("%3d: Initializing itable indices for interface %s",
1248 ++initialize_count, klass->name()->as_C_string());
1249 }
1250
1251 Array<Method*>* methods = klass->methods();
1252 int nof_methods = methods->length();
1253 int ime_num = 0;
1254 for (int i = 0; i < nof_methods; i++) {
1255 Method* m = methods->at(i);
1424 tty->print(" (%5d) ", i);
1425 m->access_flags().print_on(tty);
1426 if (m->is_default_method()) {
1427 tty->print("default ");
1428 }
1429 tty->print(" -- ");
1430 m->print_name(tty);
1431 tty->cr();
1432 }
1433 ime++;
1434 }
1435 }
1436 #endif // INCLUDE_JVMTI
1437
1438 // Setup
1439 class InterfaceVisiterClosure : public StackObj {
1440 public:
1441 virtual void doit(InstanceKlass* intf, int method_count) = 0;
1442 };
1443
1444 // Visit all interfaces with at least one itable method
1445 static void visit_all_interfaces(Array<InstanceKlass*>* transitive_intf, InterfaceVisiterClosure *blk) {
1446 // Handle array argument
1447 for(int i = 0; i < transitive_intf->length(); i++) {
1448 InstanceKlass* intf = transitive_intf->at(i);
1449 assert(intf->is_interface(), "sanity check");
1450
1451 // Find no. of itable methods
1452 int method_count = 0;
1453 // method_count = klassItable::method_count_for_interface(intf);
1454 Array<Method*>* methods = intf->methods();
1455 if (methods->length() > 0) {
1456 for (int i = methods->length(); --i >= 0; ) {
1457 if (interface_method_needs_itable_index(methods->at(i))) {
1458 method_count++;
1459 }
1460 }
1461 }
1462
1463 // Visit all interfaces which either have any methods or can participate in receiver type check.
|
1213 interf->class_in_module_of_loader(false, true),
1214 method_holder->class_in_module_of_loader(false, true));
1215 THROW_MSG(vmSymbols::java_lang_LinkageError(), ss.as_string());
1216 }
1217 }
1218 }
1219 ime++;
1220 }
1221 }
1222
1223 void klassItable::initialize_itable_and_check_constraints(TRAPS) {
1224 // Save a super interface from each itable entry to do constraint checking
1225 ResourceMark rm(THREAD);
1226 GrowableArray<Method*>* supers =
1227 new GrowableArray<Method*>(_size_method_table, _size_method_table, nullptr);
1228 initialize_itable(supers);
1229 check_constraints(supers, CHECK);
1230 }
1231
1232 inline bool interface_method_needs_itable_index(Method* m) {
1233 if (m->is_static()) return false; // e.g., Stream.empty
1234 if (m->is_private()) return false; // uses direct call
1235 if (m->is_object_constructor()) return false; // <init>(...)V
1236 if (m->is_class_initializer()) return false; // <clinit>()V
1237 // If an interface redeclares a method from java.lang.Object,
1238 // it should already have a vtable index, don't touch it.
1239 // e.g., CharSequence.toString (from initialize_vtable)
1240 // if (m->has_vtable_index()) return false; // NO!
1241 return true;
1242 }
1243
1244 int klassItable::assign_itable_indices_for_interface(InstanceKlass* klass) {
1245 // an interface does not have an itable, but its methods need to be numbered
1246 if (log_develop_is_enabled(Trace, itables)) {
1247 ResourceMark rm;
1248 log_develop_debug(itables)("%3d: Initializing itable indices for interface %s",
1249 ++initialize_count, klass->name()->as_C_string());
1250 }
1251
1252 Array<Method*>* methods = klass->methods();
1253 int nof_methods = methods->length();
1254 int ime_num = 0;
1255 for (int i = 0; i < nof_methods; i++) {
1256 Method* m = methods->at(i);
1425 tty->print(" (%5d) ", i);
1426 m->access_flags().print_on(tty);
1427 if (m->is_default_method()) {
1428 tty->print("default ");
1429 }
1430 tty->print(" -- ");
1431 m->print_name(tty);
1432 tty->cr();
1433 }
1434 ime++;
1435 }
1436 }
1437 #endif // INCLUDE_JVMTI
1438
1439 // Setup
1440 class InterfaceVisiterClosure : public StackObj {
1441 public:
1442 virtual void doit(InstanceKlass* intf, int method_count) = 0;
1443 };
1444
1445 int count_interface_methods_needing_itable_index(Array<Method*>* methods) {
1446 int method_count = 0;
1447 if (methods->length() > 0) {
1448 for (int i = methods->length(); --i >= 0; ) {
1449 if (interface_method_needs_itable_index(methods->at(i))) {
1450 method_count++;
1451 }
1452 }
1453 }
1454 return method_count;
1455 }
1456
1457 // Visit all interfaces with at least one itable method
1458 static void visit_all_interfaces(Array<InstanceKlass*>* transitive_intf, InterfaceVisiterClosure *blk) {
1459 // Handle array argument
1460 for(int i = 0; i < transitive_intf->length(); i++) {
1461 InstanceKlass* intf = transitive_intf->at(i);
1462 assert(intf->is_interface(), "sanity check");
1463
1464 // Find no. of itable methods
1465 int method_count = 0;
1466 // method_count = klassItable::method_count_for_interface(intf);
1467 Array<Method*>* methods = intf->methods();
1468 if (methods->length() > 0) {
1469 for (int i = methods->length(); --i >= 0; ) {
1470 if (interface_method_needs_itable_index(methods->at(i))) {
1471 method_count++;
1472 }
1473 }
1474 }
1475
1476 // Visit all interfaces which either have any methods or can participate in receiver type check.
|