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, NULL);
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_initializer()) return false; // <init> or <clinit>
1234 if (m->is_private()) return false; // uses direct call
1235 // If an interface redeclares a method from java.lang.Object,
1236 // it should already have a vtable index, don't touch it.
1237 // e.g., CharSequence.toString (from initialize_vtable)
1238 // if (m->has_vtable_index()) return false; // NO!
1239 return true;
1240 }
1241
1242 int klassItable::assign_itable_indices_for_interface(InstanceKlass* klass) {
1243 // an interface does not have an itable, but its methods need to be numbered
1244 if (log_develop_is_enabled(Trace, itables)) {
1245 ResourceMark rm;
1246 log_develop_debug(itables)("%3d: Initializing itable indices for interface %s",
1247 ++initialize_count, klass->name()->as_C_string());
1248 }
1249
1250 Array<Method*>* methods = klass->methods();
1251 int nof_methods = methods->length();
1252 int ime_num = 0;
1253 for (int i = 0; i < nof_methods; i++) {
1254 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 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.
1491 _klass_begin = klass_begin;
1492 _offset_entry = offset_entry;
1493 _method_entry = method_entry;
1494 }
1495
1496 itableMethodEntry* method_entry() const { return _method_entry; }
1497
1498 void doit(InstanceKlass* intf, int method_count) {
1499 int offset = ((address)_method_entry) - _klass_begin;
1500 _offset_entry->initialize(intf, offset);
1501 _offset_entry++;
1502 _method_entry += method_count;
1503 }
1504 };
1505
1506 int klassItable::compute_itable_size(Array<InstanceKlass*>* transitive_interfaces) {
1507 // Count no of interfaces and total number of interface methods
1508 CountInterfacesClosure cic;
1509 visit_all_interfaces(transitive_interfaces, &cic);
1510
1511 // There's alway an extra itable entry so we can null-terminate it.
1512 int itable_size = calc_itable_size(cic.nof_interfaces() + 1, cic.nof_methods());
1513
1514 return itable_size;
1515 }
1516
1517
1518 // Fill out offset table and interface klasses into the itable space
1519 void klassItable::setup_itable_offset_table(InstanceKlass* klass) {
1520 if (klass->itable_length() == 0) return;
1521 assert(!klass->is_interface(), "Should have zero length itable");
1522
1523 // Count no of interfaces and total number of interface methods
1524 CountInterfacesClosure cic;
1525 visit_all_interfaces(klass->transitive_interfaces(), &cic);
1526 int nof_methods = cic.nof_methods();
1527 int nof_interfaces = cic.nof_interfaces();
1528
1529 // Add one extra entry so we can null-terminate the table
1530 nof_interfaces++;
1531
|
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, NULL);
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 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.
1504 _klass_begin = klass_begin;
1505 _offset_entry = offset_entry;
1506 _method_entry = method_entry;
1507 }
1508
1509 itableMethodEntry* method_entry() const { return _method_entry; }
1510
1511 void doit(InstanceKlass* intf, int method_count) {
1512 int offset = ((address)_method_entry) - _klass_begin;
1513 _offset_entry->initialize(intf, offset);
1514 _offset_entry++;
1515 _method_entry += method_count;
1516 }
1517 };
1518
1519 int klassItable::compute_itable_size(Array<InstanceKlass*>* transitive_interfaces) {
1520 // Count no of interfaces and total number of interface methods
1521 CountInterfacesClosure cic;
1522 visit_all_interfaces(transitive_interfaces, &cic);
1523
1524 // There's always an extra itable entry so we can null-terminate it.
1525 int itable_size = calc_itable_size(cic.nof_interfaces() + 1, cic.nof_methods());
1526
1527 return itable_size;
1528 }
1529
1530
1531 // Fill out offset table and interface klasses into the itable space
1532 void klassItable::setup_itable_offset_table(InstanceKlass* klass) {
1533 if (klass->itable_length() == 0) return;
1534 assert(!klass->is_interface(), "Should have zero length itable");
1535
1536 // Count no of interfaces and total number of interface methods
1537 CountInterfacesClosure cic;
1538 visit_all_interfaces(klass->transitive_interfaces(), &cic);
1539 int nof_methods = cic.nof_methods();
1540 int nof_interfaces = cic.nof_interfaces();
1541
1542 // Add one extra entry so we can null-terminate the table
1543 nof_interfaces++;
1544
|