src/share/vm/oops/klassVtable.cpp

Print this page


   1 /*
   2  * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


 621     // by using:  old_method->vtable_index()
 622     // However, there are rare cases, eg. sun.awt.X11.XDecoratedPeer.getX()
 623     // in sun.awt.X11.XFramePeer where methods occur more than once in the
 624     // vtable, so, alas, we must do an exhaustive search.
 625     for (int index = 0; index < length(); index++) {
 626       if (unchecked_method_at(index) == old_method) {
 627         put_method_at(new_method, index);
 628 
 629         if (RC_TRACE_IN_RANGE(0x00100000, 0x00400000)) {
 630           if (!(*trace_name_printed)) {
 631             // RC_TRACE_MESG macro has an embedded ResourceMark
 632             RC_TRACE_MESG(("adjust: name=%s",
 633                            old_method->method_holder()->external_name()));
 634             *trace_name_printed = true;
 635           }
 636           // RC_TRACE macro has an embedded ResourceMark
 637           RC_TRACE(0x00100000, ("vtable method update: %s(%s)",
 638                                 new_method->name()->as_C_string(),
 639                                 new_method->signature()->as_C_string()));
 640         }

 641       }
 642     }
 643   }
 644 }
 645 


























 646 // CDS/RedefineClasses support - clear vtables so they can be reinitialized
 647 void klassVtable::clear_vtable() {
 648   for (int i = 0; i < _length; i++) table()[i].clear();
 649 }
 650 
 651 bool klassVtable::is_initialized() {
 652   return _length == 0 || table()[0].method() != NULL;
 653 }
 654 
 655 //-----------------------------------------------------------------------------------------
 656 // Itable code
 657 
 658 // Initialize a itableMethodEntry
 659 void itableMethodEntry::initialize(Method* m) {
 660   if (m == NULL) return;
 661 
 662   _method = m;
 663 }
 664 
 665 klassItable::klassItable(instanceKlassHandle klass) {


 816     // The itable can describe more than one interface and the same
 817     // method signature can be specified by more than one interface.
 818     // This means we have to do an exhaustive search to find all the
 819     // old_method references.
 820     for (int i = 0; i < _size_method_table; i++) {
 821       if (ime->method() == old_method) {
 822         ime->initialize(new_method);
 823 
 824         if (RC_TRACE_IN_RANGE(0x00100000, 0x00400000)) {
 825           if (!(*trace_name_printed)) {
 826             // RC_TRACE_MESG macro has an embedded ResourceMark
 827             RC_TRACE_MESG(("adjust: name=%s",
 828               old_method->method_holder()->external_name()));
 829             *trace_name_printed = true;
 830           }
 831           // RC_TRACE macro has an embedded ResourceMark
 832           RC_TRACE(0x00200000, ("itable method update: %s(%s)",
 833             new_method->name()->as_C_string(),
 834             new_method->signature()->as_C_string()));
 835         }
 836         // Cannot break because there might be another entry for this method
 837       }
 838       ime++;
 839     }
 840   }
 841 }
 842 













 843 

















 844 // Setup
 845 class InterfaceVisiterClosure : public StackObj {
 846  public:
 847   virtual void doit(Klass* intf, int method_count) = 0;
 848 };
 849 
 850 // Visit all interfaces with at-least one method (excluding <clinit>)
 851 void visit_all_interfaces(Array<Klass*>* transitive_intf, InterfaceVisiterClosure *blk) {
 852   // Handle array argument
 853   for(int i = 0; i < transitive_intf->length(); i++) {
 854     Klass* intf = transitive_intf->at(i);
 855     assert(intf->is_interface(), "sanity check");
 856 
 857     // Find no. of methods excluding a <clinit>
 858     int method_count = InstanceKlass::cast(intf)->methods()->length();
 859     if (method_count > 0) {
 860       Method* m = InstanceKlass::cast(intf)->methods()->at(0);
 861       assert(m != NULL && m->is_method(), "sanity check");
 862       if (m->name() == vmSymbols::object_initializer_name()) {
 863         method_count--;


1109 int VtableStats::sum_of_vtable_len = 0;
1110 int VtableStats::sum_of_array_vtable_len = 0;
1111 int VtableStats::fixed = 0;
1112 int VtableStats::filler = 0;
1113 int VtableStats::entries = 0;
1114 int VtableStats::array_entries = 0;
1115 
1116 void klassVtable::print_statistics() {
1117   ResourceMark rm;
1118   HandleMark hm;
1119   VtableStats::compute();
1120   tty->print_cr("vtable statistics:");
1121   tty->print_cr("%6d classes (%d instance, %d array)", VtableStats::no_klasses, VtableStats::no_instance_klasses, VtableStats::no_array_klasses);
1122   int total = VtableStats::fixed + VtableStats::filler + VtableStats::entries;
1123   tty->print_cr("%6d bytes fixed overhead (refs + vtable object header)", VtableStats::fixed);
1124   tty->print_cr("%6d bytes filler overhead", VtableStats::filler);
1125   tty->print_cr("%6d bytes for vtable entries (%d for arrays)", VtableStats::entries, VtableStats::array_entries);
1126   tty->print_cr("%6d bytes total", total);
1127 }
1128 
1129 bool klassVtable::check_no_old_entries() {
1130   // Check that there really is no entry
1131   for (int i = 0; i < length(); i++) {
1132     Method* m = unchecked_method_at(i);
1133     if (m != NULL) {
1134         if (!m->is_valid() || m->is_old()) {
1135             return false;
1136         }
1137     }
1138   }
1139   return true;
1140 }
1141 
1142 void klassVtable::dump_vtable() {
1143   tty->print_cr("vtable dump --");
1144   for (int i = 0; i < length(); i++) {
1145     Method* m = unchecked_method_at(i);
1146     if (m != NULL) {
1147       tty->print("      (%5d)  ", i);
1148       m->access_flags().print_on(tty);
1149       tty->print(" --  ");
1150       m->print_name(tty);
1151       tty->cr();
1152     }
1153   }
1154 }
1155 
1156 bool klassItable::check_no_old_entries() {
1157   itableMethodEntry* ime = method_entry(0);
1158   for(int i = 0; i < _size_method_table; i++) {
1159     Method* m = ime->method();
1160     if (m != NULL && (!m->is_valid() || m->is_old())) return false;
1161     ime++;
1162   }
1163   return true;
1164 }
1165 
1166 int  klassItable::_total_classes;   // Total no. of classes with itables
1167 long klassItable::_total_size;      // Total no. of bytes used for itables
1168 
1169 void klassItable::print_statistics() {
1170  tty->print_cr("itable statistics:");
1171  tty->print_cr("%6d classes with itables", _total_classes);
1172  tty->print_cr("%6d K uses for itables (average by class: %d bytes)", _total_size / K, _total_size / _total_classes);
1173 }
1174 
1175 #endif // PRODUCT
   1 /*
   2  * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


 621     // by using:  old_method->vtable_index()
 622     // However, there are rare cases, eg. sun.awt.X11.XDecoratedPeer.getX()
 623     // in sun.awt.X11.XFramePeer where methods occur more than once in the
 624     // vtable, so, alas, we must do an exhaustive search.
 625     for (int index = 0; index < length(); index++) {
 626       if (unchecked_method_at(index) == old_method) {
 627         put_method_at(new_method, index);
 628 
 629         if (RC_TRACE_IN_RANGE(0x00100000, 0x00400000)) {
 630           if (!(*trace_name_printed)) {
 631             // RC_TRACE_MESG macro has an embedded ResourceMark
 632             RC_TRACE_MESG(("adjust: name=%s",
 633                            old_method->method_holder()->external_name()));
 634             *trace_name_printed = true;
 635           }
 636           // RC_TRACE macro has an embedded ResourceMark
 637           RC_TRACE(0x00100000, ("vtable method update: %s(%s)",
 638                                 new_method->name()->as_C_string(),
 639                                 new_method->signature()->as_C_string()));
 640         }
 641         // cannot 'break' here; see for-loop comment above.
 642       }
 643     }
 644   }
 645 }
 646 
 647 // a vtable should never contain old or obsolete methods
 648 bool klassVtable::check_no_old_or_obsolete_entries() {
 649   for (int i = 0; i < length(); i++) {
 650     Method* m = unchecked_method_at(i);
 651     if (m != NULL &&
 652         (NOT_PRODUCT(!m->is_valid() ||) m->is_old() || m->is_obsolete())) {
 653       return false;
 654     }
 655   }
 656   return true;
 657 }
 658 
 659 void klassVtable::dump_vtable() {
 660   tty->print_cr("vtable dump --");
 661   for (int i = 0; i < length(); i++) {
 662     Method* m = unchecked_method_at(i);
 663     if (m != NULL) {
 664       tty->print("      (%5d)  ", i);
 665       m->access_flags().print_on(tty);
 666       tty->print(" --  ");
 667       m->print_name(tty);
 668       tty->cr();
 669     }
 670   }
 671 }
 672 
 673 // CDS/RedefineClasses support - clear vtables so they can be reinitialized
 674 void klassVtable::clear_vtable() {
 675   for (int i = 0; i < _length; i++) table()[i].clear();
 676 }
 677 
 678 bool klassVtable::is_initialized() {
 679   return _length == 0 || table()[0].method() != NULL;
 680 }
 681 
 682 //-----------------------------------------------------------------------------------------
 683 // Itable code
 684 
 685 // Initialize a itableMethodEntry
 686 void itableMethodEntry::initialize(Method* m) {
 687   if (m == NULL) return;
 688 
 689   _method = m;
 690 }
 691 
 692 klassItable::klassItable(instanceKlassHandle klass) {


 843     // The itable can describe more than one interface and the same
 844     // method signature can be specified by more than one interface.
 845     // This means we have to do an exhaustive search to find all the
 846     // old_method references.
 847     for (int i = 0; i < _size_method_table; i++) {
 848       if (ime->method() == old_method) {
 849         ime->initialize(new_method);
 850 
 851         if (RC_TRACE_IN_RANGE(0x00100000, 0x00400000)) {
 852           if (!(*trace_name_printed)) {
 853             // RC_TRACE_MESG macro has an embedded ResourceMark
 854             RC_TRACE_MESG(("adjust: name=%s",
 855               old_method->method_holder()->external_name()));
 856             *trace_name_printed = true;
 857           }
 858           // RC_TRACE macro has an embedded ResourceMark
 859           RC_TRACE(0x00200000, ("itable method update: %s(%s)",
 860             new_method->name()->as_C_string(),
 861             new_method->signature()->as_C_string()));
 862         }
 863         // cannot 'break' here; see for-loop comment above.
 864       }
 865       ime++;
 866     }
 867   }
 868 }
 869 
 870 // an itable should never contain old or obsolete methods
 871 bool klassItable::check_no_old_or_obsolete_entries() {
 872   itableMethodEntry* ime = method_entry(0);
 873   for (int i = 0; i < _size_method_table; i++) {
 874     Method* m = ime->method();
 875     if (m != NULL &&
 876         (NOT_PRODUCT(!m->is_valid() ||) m->is_old() || m->is_obsolete())) {
 877       return false;
 878     }
 879     ime++;
 880   }
 881   return true;
 882 }
 883 
 884 void klassItable::dump_itable() {
 885   itableMethodEntry* ime = method_entry(0);
 886   tty->print_cr("itable dump --");
 887   for (int i = 0; i < _size_method_table; i++) {
 888     Method* m = ime->method();
 889     if (m != NULL) {
 890       tty->print("      (%5d)  ", i);
 891       m->access_flags().print_on(tty);
 892       tty->print(" --  ");
 893       m->print_name(tty);
 894       tty->cr();
 895     }
 896     ime++;
 897   }
 898 }
 899 
 900 
 901 // Setup
 902 class InterfaceVisiterClosure : public StackObj {
 903  public:
 904   virtual void doit(Klass* intf, int method_count) = 0;
 905 };
 906 
 907 // Visit all interfaces with at-least one method (excluding <clinit>)
 908 void visit_all_interfaces(Array<Klass*>* transitive_intf, InterfaceVisiterClosure *blk) {
 909   // Handle array argument
 910   for(int i = 0; i < transitive_intf->length(); i++) {
 911     Klass* intf = transitive_intf->at(i);
 912     assert(intf->is_interface(), "sanity check");
 913 
 914     // Find no. of methods excluding a <clinit>
 915     int method_count = InstanceKlass::cast(intf)->methods()->length();
 916     if (method_count > 0) {
 917       Method* m = InstanceKlass::cast(intf)->methods()->at(0);
 918       assert(m != NULL && m->is_method(), "sanity check");
 919       if (m->name() == vmSymbols::object_initializer_name()) {
 920         method_count--;


1166 int VtableStats::sum_of_vtable_len = 0;
1167 int VtableStats::sum_of_array_vtable_len = 0;
1168 int VtableStats::fixed = 0;
1169 int VtableStats::filler = 0;
1170 int VtableStats::entries = 0;
1171 int VtableStats::array_entries = 0;
1172 
1173 void klassVtable::print_statistics() {
1174   ResourceMark rm;
1175   HandleMark hm;
1176   VtableStats::compute();
1177   tty->print_cr("vtable statistics:");
1178   tty->print_cr("%6d classes (%d instance, %d array)", VtableStats::no_klasses, VtableStats::no_instance_klasses, VtableStats::no_array_klasses);
1179   int total = VtableStats::fixed + VtableStats::filler + VtableStats::entries;
1180   tty->print_cr("%6d bytes fixed overhead (refs + vtable object header)", VtableStats::fixed);
1181   tty->print_cr("%6d bytes filler overhead", VtableStats::filler);
1182   tty->print_cr("%6d bytes for vtable entries (%d for arrays)", VtableStats::entries, VtableStats::array_entries);
1183   tty->print_cr("%6d bytes total", total);
1184 }
1185 





































1186 int  klassItable::_total_classes;   // Total no. of classes with itables
1187 long klassItable::_total_size;      // Total no. of bytes used for itables
1188 
1189 void klassItable::print_statistics() {
1190  tty->print_cr("itable statistics:");
1191  tty->print_cr("%6d classes with itables", _total_classes);
1192  tty->print_cr("%6d K uses for itables (average by class: %d bytes)", _total_size / K, _total_size / _total_classes);
1193 }
1194 
1195 #endif // PRODUCT