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 *
593 sik->methods(), class_methods, super);
594 }
595 }
596 }
597
598 // fill in mirandas
599 void klassVtable::fill_in_mirandas(int* initialized) {
600 GrowableArray<Method*> mirandas(20);
601 get_mirandas(&mirandas, NULL, ik()->super(), ik()->methods(),
602 ik()->local_interfaces());
603 for (int i = 0; i < mirandas.length(); i++) {
604 put_method_at(mirandas.at(i), *initialized);
605 ++(*initialized);
606 }
607 }
608
609 void klassVtable::copy_vtable_to(vtableEntry* start) {
610 Copy::disjoint_words((HeapWord*)table(), (HeapWord*)start, _length * vtableEntry::size());
611 }
612
613 void klassVtable::adjust_method_entries(Method** old_methods, Method** new_methods,
614 int methods_length, bool * trace_name_printed) {
615 // search the vtable for uses of either obsolete or EMCP methods
616 for (int j = 0; j < methods_length; j++) {
617 Method* old_method = old_methods[j];
618 Method* new_method = new_methods[j];
619
620 // In the vast majority of cases we could get the vtable index
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) {
788
789 // ime may have moved during GC so recalculate address
790 itableOffsetEntry::method_entry(_klass(), method_table_offset)[ime_num].initialize(target_h());
791 }
792 // Progress to next entry
793 ime_num++;
794 }
795 }
796
797 // Update entry for specific Method*
798 void klassItable::initialize_with_method(Method* m) {
799 itableMethodEntry* ime = method_entry(0);
800 for(int i = 0; i < _size_method_table; i++) {
801 if (ime->method() == m) {
802 ime->initialize(m);
803 }
804 ime++;
805 }
806 }
807
808 void klassItable::adjust_method_entries(Method** old_methods, Method** new_methods,
809 int methods_length, bool * trace_name_printed) {
810 // search the itable for uses of either obsolete or EMCP methods
811 for (int j = 0; j < methods_length; j++) {
812 Method* old_method = old_methods[j];
813 Method* new_method = new_methods[j];
814 itableMethodEntry* ime = method_entry(0);
815
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 *
593 sik->methods(), class_methods, super);
594 }
595 }
596 }
597
598 // fill in mirandas
599 void klassVtable::fill_in_mirandas(int* initialized) {
600 GrowableArray<Method*> mirandas(20);
601 get_mirandas(&mirandas, NULL, ik()->super(), ik()->methods(),
602 ik()->local_interfaces());
603 for (int i = 0; i < mirandas.length(); i++) {
604 put_method_at(mirandas.at(i), *initialized);
605 ++(*initialized);
606 }
607 }
608
609 void klassVtable::copy_vtable_to(vtableEntry* start) {
610 Copy::disjoint_words((HeapWord*)table(), (HeapWord*)start, _length * vtableEntry::size());
611 }
612
613 #if INCLUDE_JVMTI
614 void klassVtable::adjust_method_entries(Method** old_methods, Method** new_methods,
615 int methods_length, bool * trace_name_printed) {
616 // search the vtable for uses of either obsolete or EMCP methods
617 for (int j = 0; j < methods_length; j++) {
618 Method* old_method = old_methods[j];
619 Method* new_method = new_methods[j];
620
621 // In the vast majority of cases we could get the vtable index
622 // by using: old_method->vtable_index()
623 // However, there are rare cases, eg. sun.awt.X11.XDecoratedPeer.getX()
624 // in sun.awt.X11.XFramePeer where methods occur more than once in the
625 // vtable, so, alas, we must do an exhaustive search.
626 for (int index = 0; index < length(); index++) {
627 if (unchecked_method_at(index) == old_method) {
628 put_method_at(new_method, index);
629
630 if (RC_TRACE_IN_RANGE(0x00100000, 0x00400000)) {
631 if (!(*trace_name_printed)) {
632 // RC_TRACE_MESG macro has an embedded ResourceMark
633 RC_TRACE_MESG(("adjust: name=%s",
634 old_method->method_holder()->external_name()));
635 *trace_name_printed = true;
636 }
637 // RC_TRACE macro has an embedded ResourceMark
638 RC_TRACE(0x00100000, ("vtable method update: %s(%s)",
639 new_method->name()->as_C_string(),
640 new_method->signature()->as_C_string()));
641 }
642 // cannot 'break' here; see for-loop comment above.
643 }
644 }
645 }
646 }
647
648 // a vtable should never contain old or obsolete methods
649 bool klassVtable::check_no_old_or_obsolete_entries() {
650 for (int i = 0; i < length(); i++) {
651 Method* m = unchecked_method_at(i);
652 if (m != NULL &&
653 (NOT_PRODUCT(!m->is_valid() ||) m->is_old() || m->is_obsolete())) {
654 return false;
655 }
656 }
657 return true;
658 }
659
660 void klassVtable::dump_vtable() {
661 tty->print_cr("vtable dump --");
662 for (int i = 0; i < length(); i++) {
663 Method* m = unchecked_method_at(i);
664 if (m != NULL) {
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 #endif // INCLUDE_JVMTI
674
675 // CDS/RedefineClasses support - clear vtables so they can be reinitialized
676 void klassVtable::clear_vtable() {
677 for (int i = 0; i < _length; i++) table()[i].clear();
678 }
679
680 bool klassVtable::is_initialized() {
681 return _length == 0 || table()[0].method() != NULL;
682 }
683
684 //-----------------------------------------------------------------------------------------
685 // Itable code
686
687 // Initialize a itableMethodEntry
688 void itableMethodEntry::initialize(Method* m) {
689 if (m == NULL) return;
690
691 _method = m;
692 }
693
694 klassItable::klassItable(instanceKlassHandle klass) {
817
818 // ime may have moved during GC so recalculate address
819 itableOffsetEntry::method_entry(_klass(), method_table_offset)[ime_num].initialize(target_h());
820 }
821 // Progress to next entry
822 ime_num++;
823 }
824 }
825
826 // Update entry for specific Method*
827 void klassItable::initialize_with_method(Method* m) {
828 itableMethodEntry* ime = method_entry(0);
829 for(int i = 0; i < _size_method_table; i++) {
830 if (ime->method() == m) {
831 ime->initialize(m);
832 }
833 ime++;
834 }
835 }
836
837 #if INCLUDE_JVMTI
838 void klassItable::adjust_method_entries(Method** old_methods, Method** new_methods,
839 int methods_length, bool * trace_name_printed) {
840 // search the itable for uses of either obsolete or EMCP methods
841 for (int j = 0; j < methods_length; j++) {
842 Method* old_method = old_methods[j];
843 Method* new_method = new_methods[j];
844 itableMethodEntry* ime = method_entry(0);
845
846 // The itable can describe more than one interface and the same
847 // method signature can be specified by more than one interface.
848 // This means we have to do an exhaustive search to find all the
849 // old_method references.
850 for (int i = 0; i < _size_method_table; i++) {
851 if (ime->method() == old_method) {
852 ime->initialize(new_method);
853
854 if (RC_TRACE_IN_RANGE(0x00100000, 0x00400000)) {
855 if (!(*trace_name_printed)) {
856 // RC_TRACE_MESG macro has an embedded ResourceMark
857 RC_TRACE_MESG(("adjust: name=%s",
858 old_method->method_holder()->external_name()));
859 *trace_name_printed = true;
860 }
861 // RC_TRACE macro has an embedded ResourceMark
862 RC_TRACE(0x00200000, ("itable method update: %s(%s)",
863 new_method->name()->as_C_string(),
864 new_method->signature()->as_C_string()));
865 }
866 // cannot 'break' here; see for-loop comment above.
867 }
868 ime++;
869 }
870 }
871 }
872
873 // an itable should never contain old or obsolete methods
874 bool klassItable::check_no_old_or_obsolete_entries() {
875 itableMethodEntry* ime = method_entry(0);
876 for (int i = 0; i < _size_method_table; i++) {
877 Method* m = ime->method();
878 if (m != NULL &&
879 (NOT_PRODUCT(!m->is_valid() ||) m->is_old() || m->is_obsolete())) {
880 return false;
881 }
882 ime++;
883 }
884 return true;
885 }
886
887 void klassItable::dump_itable() {
888 itableMethodEntry* ime = method_entry(0);
889 tty->print_cr("itable dump --");
890 for (int i = 0; i < _size_method_table; i++) {
891 Method* m = ime->method();
892 if (m != NULL) {
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 #endif // INCLUDE_JVMTI
903
904
905 // Setup
906 class InterfaceVisiterClosure : public StackObj {
907 public:
908 virtual void doit(Klass* intf, int method_count) = 0;
909 };
910
911 // Visit all interfaces with at-least one method (excluding <clinit>)
912 void visit_all_interfaces(Array<Klass*>* transitive_intf, InterfaceVisiterClosure *blk) {
913 // Handle array argument
914 for(int i = 0; i < transitive_intf->length(); i++) {
915 Klass* intf = transitive_intf->at(i);
916 assert(intf->is_interface(), "sanity check");
917
918 // Find no. of methods excluding a <clinit>
919 int method_count = InstanceKlass::cast(intf)->methods()->length();
920 if (method_count > 0) {
921 Method* m = InstanceKlass::cast(intf)->methods()->at(0);
922 assert(m != NULL && m->is_method(), "sanity check");
923 if (m->name() == vmSymbols::object_initializer_name()) {
924 method_count--;
1170 int VtableStats::sum_of_vtable_len = 0;
1171 int VtableStats::sum_of_array_vtable_len = 0;
1172 int VtableStats::fixed = 0;
1173 int VtableStats::filler = 0;
1174 int VtableStats::entries = 0;
1175 int VtableStats::array_entries = 0;
1176
1177 void klassVtable::print_statistics() {
1178 ResourceMark rm;
1179 HandleMark hm;
1180 VtableStats::compute();
1181 tty->print_cr("vtable statistics:");
1182 tty->print_cr("%6d classes (%d instance, %d array)", VtableStats::no_klasses, VtableStats::no_instance_klasses, VtableStats::no_array_klasses);
1183 int total = VtableStats::fixed + VtableStats::filler + VtableStats::entries;
1184 tty->print_cr("%6d bytes fixed overhead (refs + vtable object header)", VtableStats::fixed);
1185 tty->print_cr("%6d bytes filler overhead", VtableStats::filler);
1186 tty->print_cr("%6d bytes for vtable entries (%d for arrays)", VtableStats::entries, VtableStats::array_entries);
1187 tty->print_cr("%6d bytes total", total);
1188 }
1189
1190 int klassItable::_total_classes; // Total no. of classes with itables
1191 long klassItable::_total_size; // Total no. of bytes used for itables
1192
1193 void klassItable::print_statistics() {
1194 tty->print_cr("itable statistics:");
1195 tty->print_cr("%6d classes with itables", _total_classes);
1196 tty->print_cr("%6d K uses for itables (average by class: %d bytes)", _total_size / K, _total_size / _total_classes);
1197 }
1198
1199 #endif // PRODUCT
|