1213 method_holder->class_in_module_of_loader(false, true));
1214 THROW_MSG(vmSymbols::java_lang_LinkageError(), ss.as_string());
1215 }
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_object_initializer()) return false; // <init>
1235 if (m->is_static_initializer()) return false; // <clinit>
1236 if (m->is_private()) return false; // uses direct call
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);
1423 tty->print(" (%5d) ", i);
1424 m->access_flags().print_on(tty);
1425 if (m->is_default_method()) {
1426 tty->print("default ");
1427 }
1428 tty->print(" -- ");
1429 m->print_name(tty);
1430 tty->cr();
1431 }
1432 ime++;
1433 }
1434 }
1435 #endif // INCLUDE_JVMTI
1436
1437 // Setup
1438 class InterfaceVisiterClosure : public StackObj {
1439 public:
1440 virtual void doit(InstanceKlass* intf, int method_count) = 0;
1441 };
1442
1443 // Visit all interfaces with at least one itable method
1444 static void visit_all_interfaces(Array<InstanceKlass*>* transitive_intf, InterfaceVisiterClosure *blk) {
1445 // Handle array argument
1446 for(int i = 0; i < transitive_intf->length(); i++) {
1447 InstanceKlass* intf = transitive_intf->at(i);
1448 assert(intf->is_interface(), "sanity check");
1449
1450 // Find no. of itable methods
1451 int method_count = 0;
1452 // method_count = klassItable::method_count_for_interface(intf);
1453 Array<Method*>* methods = intf->methods();
1454 if (methods->length() > 0) {
1455 for (int i = methods->length(); --i >= 0; ) {
1456 if (interface_method_needs_itable_index(methods->at(i))) {
1457 method_count++;
1458 }
1459 }
1460 }
1461
1462 // Visit all interfaces which either have any methods or can participate in receiver type check.
|
1213 method_holder->class_in_module_of_loader(false, true));
1214 THROW_MSG(vmSymbols::java_lang_LinkageError(), ss.as_string());
1215 }
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);
1423 tty->print(" (%5d) ", i);
1424 m->access_flags().print_on(tty);
1425 if (m->is_default_method()) {
1426 tty->print("default ");
1427 }
1428 tty->print(" -- ");
1429 m->print_name(tty);
1430 tty->cr();
1431 }
1432 ime++;
1433 }
1434 }
1435 #endif // INCLUDE_JVMTI
1436
1437 // Setup
1438 class InterfaceVisiterClosure : public StackObj {
1439 public:
1440 virtual void doit(InstanceKlass* intf, int method_count) = 0;
1441 };
1442
1443 int count_interface_methods_needing_itable_index(Array<Method*>* methods) {
1444 int method_count = 0;
1445 if (methods->length() > 0) {
1446 for (int i = methods->length(); --i >= 0; ) {
1447 if (interface_method_needs_itable_index(methods->at(i))) {
1448 method_count++;
1449 }
1450 }
1451 }
1452 return method_count;
1453 }
1454
1455 // Visit all interfaces with at least one itable method
1456 static void visit_all_interfaces(Array<InstanceKlass*>* transitive_intf, InterfaceVisiterClosure *blk) {
1457 // Handle array argument
1458 for(int i = 0; i < transitive_intf->length(); i++) {
1459 InstanceKlass* intf = transitive_intf->at(i);
1460 assert(intf->is_interface(), "sanity check");
1461
1462 // Find no. of itable methods
1463 int method_count = 0;
1464 // method_count = klassItable::method_count_for_interface(intf);
1465 Array<Method*>* methods = intf->methods();
1466 if (methods->length() > 0) {
1467 for (int i = methods->length(); --i >= 0; ) {
1468 if (interface_method_needs_itable_index(methods->at(i))) {
1469 method_count++;
1470 }
1471 }
1472 }
1473
1474 // Visit all interfaces which either have any methods or can participate in receiver type check.
|