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