< prev index next >

src/hotspot/share/oops/klassVtable.cpp

Print this page

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_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);

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 // Visit all interfaces with at least one itable method
1446 static void visit_all_interfaces(Array<InstanceKlass*>* transitive_intf, InterfaceVisiterClosure *blk) {
1447   // Handle array argument
1448   for(int i = 0; i < transitive_intf->length(); i++) {
1449     InstanceKlass* intf = transitive_intf->at(i);
1450     assert(intf->is_interface(), "sanity check");
1451 
1452     // Find no. of itable methods
1453     int method_count = 0;
1454     // method_count = klassItable::method_count_for_interface(intf);
1455     Array<Method*>* methods = intf->methods();
1456     if (methods->length() > 0) {
1457       for (int i = methods->length(); --i >= 0; ) {
1458         if (interface_method_needs_itable_index(methods->at(i))) {
1459           method_count++;
1460         }
1461       }
1462     }
1463 
1464     // 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.
< prev index next >