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  *


 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  *


 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 // a vtable should never contain old or obsolete methods
 647 bool klassVtable::check_no_old_or_obsolete_entries() {
 648   for (int i = 0; i < length(); i++) {
 649     Method* m = unchecked_method_at(i);
 650     if (m != NULL && (!m->is_valid() || m->is_old() || m->is_obsolete())) {
 651       return false;
 652     }
 653   }
 654   return true;
 655 }
 656 
 657 void klassVtable::dump_vtable() {
 658   // adds a searchable prefix when RedefineClasses() tracing is enabled
 659   RC_TRACE_NO_CR(0x00004000, (""));
 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       RC_TRACE_NO_CR(0x00004000, (""));
 665       tty->print("      (%5d)  ", i);
 666       m->access_flags().print_on(tty);
 667       tty->print(" --  ");
 668       m->print_name(tty);
 669       tty->cr();
 670     }
 671   }
 672 }
 673 
 674 // CDS/RedefineClasses support - clear vtables so they can be reinitialized
 675 void klassVtable::clear_vtable() {
 676   for (int i = 0; i < _length; i++) table()[i].clear();
 677 }
 678 
 679 bool klassVtable::is_initialized() {
 680   return _length == 0 || table()[0].method() != NULL;
 681 }
 682 
 683 //-----------------------------------------------------------------------------------------
 684 // Itable code
 685 
 686 // Initialize a itableMethodEntry
 687 void itableMethodEntry::initialize(Method* m) {
 688   if (m == NULL) return;
 689 
 690   _method = m;
 691 }
 692 
 693 klassItable::klassItable(instanceKlassHandle klass) {


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


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





































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