hotspot/src/share/vm/oops/klassVtable.cpp
changeset 189 4248c8e21063
parent 1 489c9b5090e2
child 360 21d113ecbf6a
equal deleted inserted replaced
21:c5b9e3a56692 189:4248c8e21063
   733       assert(_table_offset >= 0 && _size_offset_table >= 0 && _size_method_table >= 0, "wrong computation");
   733       assert(_table_offset >= 0 && _size_offset_table >= 0 && _size_method_table >= 0, "wrong computation");
   734       return;
   734       return;
   735     }
   735     }
   736   }
   736   }
   737 
   737 
   738   // This lenght of the itable was either zero, or it has not yet been initialized.
   738   // The length of the itable was either zero, or it has not yet been initialized.
   739   _table_offset      = 0;
   739   _table_offset      = 0;
   740   _size_offset_table = 0;
   740   _size_offset_table = 0;
   741   _size_method_table = 0;
   741   _size_method_table = 0;
   742 }
   742 }
   743 
   743 
   868 
   868 
   869 static int initialize_count = 0;
   869 static int initialize_count = 0;
   870 
   870 
   871 // Initialization
   871 // Initialization
   872 void klassItable::initialize_itable(bool checkconstraints, TRAPS) {
   872 void klassItable::initialize_itable(bool checkconstraints, TRAPS) {
   873   // Cannot be setup doing bootstrapping
   873   // Cannot be setup doing bootstrapping, interfaces don't have
   874   if (Universe::is_bootstrapping()) return;
   874   // itables, and klass with only ones entry have empty itables
   875 
   875   if (Universe::is_bootstrapping() ||
   876   int num_interfaces = nof_interfaces();
   876       _klass->is_interface() ||
       
   877       _klass->itable_length() == itableOffsetEntry::size()) return;
       
   878 
       
   879   // There's alway an extra itable entry so we can null-terminate it.
       
   880   guarantee(size_offset_table() >= 1, "too small");
       
   881   int num_interfaces = size_offset_table() - 1;
   877   if (num_interfaces > 0) {
   882   if (num_interfaces > 0) {
   878     if (TraceItables) tty->print_cr("%3d: Initializing itables for %s", ++initialize_count, _klass->name()->as_C_string());
   883     if (TraceItables) tty->print_cr("%3d: Initializing itables for %s", ++initialize_count,
   879 
   884                                     _klass->name()->as_C_string());
   880     // In debug mode, we got an extra NULL/NULL entry
   885 
   881     debug_only(num_interfaces--);
       
   882     assert(num_interfaces > 0, "to few interfaces in offset itable");
       
   883 
   886 
   884     // Interate through all interfaces
   887     // Interate through all interfaces
   885     int i;
   888     int i;
   886     for(i = 0; i < num_interfaces; i++) {
   889     for(i = 0; i < num_interfaces; i++) {
   887       itableOffsetEntry* ioe = offset_entry(i);
   890       itableOffsetEntry* ioe = offset_entry(i);
   888       KlassHandle interf_h (THREAD, ioe->interface_klass());
   891       KlassHandle interf_h (THREAD, ioe->interface_klass());
   889       assert(interf_h() != NULL && ioe->offset() != 0, "bad offset entry in itable");
   892       assert(interf_h() != NULL && ioe->offset() != 0, "bad offset entry in itable");
   890       initialize_itable_for_interface(ioe->offset(), interf_h, checkconstraints, CHECK);
   893       initialize_itable_for_interface(ioe->offset(), interf_h, checkconstraints, CHECK);
   891     }
   894     }
   892 
   895 
   893 #ifdef ASSERT
   896   }
   894     // Check that the last entry is empty
   897   // Check that the last entry is empty
   895     itableOffsetEntry* ioe = offset_entry(i);
   898   itableOffsetEntry* ioe = offset_entry(size_offset_table() - 1);
   896     assert(ioe->interface_klass() == NULL && ioe->offset() == 0, "terminator entry missing");
   899   guarantee(ioe->interface_klass() == NULL && ioe->offset() == 0, "terminator entry missing");
   897 #endif
       
   898   }
       
   899 }
   900 }
   900 
   901 
   901 
   902 
   902 void klassItable::initialize_itable_for_interface(int method_table_offset, KlassHandle interf_h, bool checkconstraints, TRAPS) {
   903 void klassItable::initialize_itable_for_interface(int method_table_offset, KlassHandle interf_h, bool checkconstraints, TRAPS) {
   903   objArrayHandle methods(THREAD, instanceKlass::cast(interf_h())->methods());
   904   objArrayHandle methods(THREAD, instanceKlass::cast(interf_h())->methods());
   970     // Progress to next entry
   971     // Progress to next entry
   971     ime_num++;
   972     ime_num++;
   972   }
   973   }
   973 }
   974 }
   974 
   975 
   975 // Update entry for specic methodOop
   976 // Update entry for specific methodOop
   976 void klassItable::initialize_with_method(methodOop m) {
   977 void klassItable::initialize_with_method(methodOop m) {
   977   itableMethodEntry* ime = method_entry(0);
   978   itableMethodEntry* ime = method_entry(0);
   978   for(int i = 0; i < _size_method_table; i++) {
   979   for(int i = 0; i < _size_method_table; i++) {
   979     if (ime->method() == m) {
   980     if (ime->method() == m) {
   980       ime->initialize(m);
   981       ime->initialize(m);
  1083 int klassItable::compute_itable_size(objArrayHandle transitive_interfaces) {
  1084 int klassItable::compute_itable_size(objArrayHandle transitive_interfaces) {
  1084   // Count no of interfaces and total number of interface methods
  1085   // Count no of interfaces and total number of interface methods
  1085   CountInterfacesClosure cic;
  1086   CountInterfacesClosure cic;
  1086   visit_all_interfaces(transitive_interfaces(), &cic);
  1087   visit_all_interfaces(transitive_interfaces(), &cic);
  1087 
  1088 
  1088   // Add one extra entry in debug mode, so we can null-terminate the table
  1089   // There's alway an extra itable entry so we can null-terminate it.
  1089   int nof_methods    = cic.nof_methods();
  1090   int itable_size = calc_itable_size(cic.nof_interfaces() + 1, cic.nof_methods());
  1090   int nof_interfaces = cic.nof_interfaces();
       
  1091   debug_only(if (nof_interfaces > 0) nof_interfaces++);
       
  1092 
       
  1093   int itable_size = calc_itable_size(nof_interfaces, nof_methods);
       
  1094 
  1091 
  1095   // Statistics
  1092   // Statistics
  1096   update_stats(itable_size * HeapWordSize);
  1093   update_stats(itable_size * HeapWordSize);
  1097 
  1094 
  1098   return itable_size;
  1095   return itable_size;
  1108   CountInterfacesClosure cic;
  1105   CountInterfacesClosure cic;
  1109   visit_all_interfaces(klass->transitive_interfaces(), &cic);
  1106   visit_all_interfaces(klass->transitive_interfaces(), &cic);
  1110   int nof_methods    = cic.nof_methods();
  1107   int nof_methods    = cic.nof_methods();
  1111   int nof_interfaces = cic.nof_interfaces();
  1108   int nof_interfaces = cic.nof_interfaces();
  1112 
  1109 
  1113   // Add one extra entry in debug mode, so we can null-terminate the table
  1110   // Add one extra entry so we can null-terminate the table
  1114   debug_only(if (nof_interfaces > 0) nof_interfaces++);
  1111   nof_interfaces++;
  1115 
  1112 
  1116   assert(compute_itable_size(objArrayHandle(klass->transitive_interfaces())) ==
  1113   assert(compute_itable_size(objArrayHandle(klass->transitive_interfaces())) ==
  1117          calc_itable_size(nof_interfaces, nof_methods),
  1114          calc_itable_size(nof_interfaces, nof_methods),
  1118          "mismatch calculation of itable size");
  1115          "mismatch calculation of itable size");
  1119 
  1116