< prev index next >

src/hotspot/share/oops/klassVtable.cpp

Print this page

1212                    interf->class_in_module_of_loader(false, true),
1213                    method_holder->class_in_module_of_loader(false, true));
1214           THROW_MSG(vmSymbols::java_lang_LinkageError(), ss.as_string());
1215         }
1216       }
1217     }
1218     ime++;
1219   }
1220 }
1221 
1222 void klassItable::initialize_itable_and_check_constraints(TRAPS) {
1223   // Save a super interface from each itable entry to do constraint checking
1224   ResourceMark rm(THREAD);
1225   GrowableArray<Method*>* supers =
1226     new GrowableArray<Method*>(_size_method_table, _size_method_table, nullptr);
1227   initialize_itable(supers);
1228   check_constraints(supers, CHECK);
1229 }
1230 
1231 inline bool interface_method_needs_itable_index(Method* m) {
1232   if (m->is_static())             return false; // e.g., Stream.empty
1233   if (m->is_object_initializer()) return false; // <init>
1234   if (m->is_static_initializer()) return false; // <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.

1212                    interf->class_in_module_of_loader(false, true),
1213                    method_holder->class_in_module_of_loader(false, true));
1214           THROW_MSG(vmSymbols::java_lang_LinkageError(), ss.as_string());
1215         }
1216       }
1217     }
1218     ime++;
1219   }
1220 }
1221 
1222 void klassItable::initialize_itable_and_check_constraints(TRAPS) {
1223   // Save a super interface from each itable entry to do constraint checking
1224   ResourceMark rm(THREAD);
1225   GrowableArray<Method*>* supers =
1226     new GrowableArray<Method*>(_size_method_table, _size_method_table, nullptr);
1227   initialize_itable(supers);
1228   check_constraints(supers, CHECK);
1229 }
1230 
1231 inline bool interface_method_needs_itable_index(Method* m) {
1232   if (m->is_static())             return false;   // e.g., Stream.empty
1233   if (m->is_private())            return false;   // uses direct call
1234   if (m->is_object_constructor()) return false;   // <init>(...)V
1235   if (m->is_class_initializer())  return false;   // <clinit>()V
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 int count_interface_methods_needing_itable_index(Array<Method*>* methods) {
1445   int method_count = 0;
1446   if (methods->length() > 0) {
1447     for (int i = methods->length(); --i >= 0; ) {
1448       if (interface_method_needs_itable_index(methods->at(i))) {
1449         method_count++;
1450       }
1451     }
1452   }
1453   return method_count;
1454 }
1455 
1456 // Visit all interfaces with at least one itable method
1457 static void visit_all_interfaces(Array<InstanceKlass*>* transitive_intf, InterfaceVisiterClosure *blk) {
1458   // Handle array argument
1459   for(int i = 0; i < transitive_intf->length(); i++) {
1460     InstanceKlass* intf = transitive_intf->at(i);
1461     assert(intf->is_interface(), "sanity check");
1462 
1463     // Find no. of itable methods
1464     int method_count = 0;
1465     // method_count = klassItable::method_count_for_interface(intf);
1466     Array<Method*>* methods = intf->methods();
1467     if (methods->length() > 0) {
1468       for (int i = methods->length(); --i >= 0; ) {
1469         if (interface_method_needs_itable_index(methods->at(i))) {
1470           method_count++;
1471         }
1472       }
1473     }
1474 
1475     // Visit all interfaces which either have any methods or can participate in receiver type check.
< prev index next >