src/share/vm/classfile/symbolTable.cpp

changeset 5743
63147986a428
parent 5277
01522ca68fc7
child 5775
461159cd7a91
child 5784
190899198332
equal deleted inserted replaced
5686:6f45933aef35 5743:63147986a428
805 int end_idx = MIN2(limit, start_idx + ClaimChunkSize); 805 int end_idx = MIN2(limit, start_idx + ClaimChunkSize);
806 buckets_do(f, start_idx, end_idx); 806 buckets_do(f, start_idx, end_idx);
807 } 807 }
808 } 808 }
809 809
810 // This verification is part of Universe::verify() and needs to be quick.
811 // See StringTable::verify_and_compare() below for exhaustive verification.
810 void StringTable::verify() { 812 void StringTable::verify() {
811 for (int i = 0; i < the_table()->table_size(); ++i) { 813 for (int i = 0; i < the_table()->table_size(); ++i) {
812 HashtableEntry<oop, mtSymbol>* p = the_table()->bucket(i); 814 HashtableEntry<oop, mtSymbol>* p = the_table()->bucket(i);
813 for ( ; p != NULL; p = p->next()) { 815 for ( ; p != NULL; p = p->next()) {
814 oop s = p->literal(); 816 oop s = p->literal();
823 825
824 void StringTable::dump(outputStream* st) { 826 void StringTable::dump(outputStream* st) {
825 the_table()->dump_table(st, "StringTable"); 827 the_table()->dump_table(st, "StringTable");
826 } 828 }
827 829
830 StringTable::VerifyRetTypes StringTable::compare_entries(
831 int bkt1, int e_cnt1,
832 HashtableEntry<oop, mtSymbol>* e_ptr1,
833 int bkt2, int e_cnt2,
834 HashtableEntry<oop, mtSymbol>* e_ptr2) {
835 // These entries are sanity checked by verify_and_compare_entries()
836 // before this function is called.
837 oop str1 = e_ptr1->literal();
838 oop str2 = e_ptr2->literal();
839
840 if (str1 == str2) {
841 tty->print_cr("ERROR: identical oop values (0x" PTR_FORMAT ") "
842 "in entry @ bucket[%d][%d] and entry @ bucket[%d][%d]",
843 str1, bkt1, e_cnt1, bkt2, e_cnt2);
844 return _verify_fail_continue;
845 }
846
847 if (java_lang_String::equals(str1, str2)) {
848 tty->print_cr("ERROR: identical String values in entry @ "
849 "bucket[%d][%d] and entry @ bucket[%d][%d]",
850 bkt1, e_cnt1, bkt2, e_cnt2);
851 return _verify_fail_continue;
852 }
853
854 return _verify_pass;
855 }
856
857 StringTable::VerifyRetTypes StringTable::verify_entry(int bkt, int e_cnt,
858 HashtableEntry<oop, mtSymbol>* e_ptr,
859 StringTable::VerifyMesgModes mesg_mode) {
860
861 VerifyRetTypes ret = _verify_pass; // be optimistic
862
863 oop str = e_ptr->literal();
864 if (str == NULL) {
865 if (mesg_mode == _verify_with_mesgs) {
866 tty->print_cr("ERROR: NULL oop value in entry @ bucket[%d][%d]", bkt,
867 e_cnt);
868 }
869 // NULL oop means no more verifications are possible
870 return _verify_fail_done;
871 }
872
873 if (str->klass() != SystemDictionary::String_klass()) {
874 if (mesg_mode == _verify_with_mesgs) {
875 tty->print_cr("ERROR: oop is not a String in entry @ bucket[%d][%d]",
876 bkt, e_cnt);
877 }
878 // not a String means no more verifications are possible
879 return _verify_fail_done;
880 }
881
882 unsigned int h = java_lang_String::hash_string(str);
883 if (e_ptr->hash() != h) {
884 if (mesg_mode == _verify_with_mesgs) {
885 tty->print_cr("ERROR: broken hash value in entry @ bucket[%d][%d], "
886 "bkt_hash=%d, str_hash=%d", bkt, e_cnt, e_ptr->hash(), h);
887 }
888 ret = _verify_fail_continue;
889 }
890
891 if (the_table()->hash_to_index(h) != bkt) {
892 if (mesg_mode == _verify_with_mesgs) {
893 tty->print_cr("ERROR: wrong index value for entry @ bucket[%d][%d], "
894 "str_hash=%d, hash_to_index=%d", bkt, e_cnt, h,
895 the_table()->hash_to_index(h));
896 }
897 ret = _verify_fail_continue;
898 }
899
900 return ret;
901 }
902
903 // See StringTable::verify() above for the quick verification that is
904 // part of Universe::verify(). This verification is exhaustive and
905 // reports on every issue that is found. StringTable::verify() only
906 // reports on the first issue that is found.
907 //
908 // StringTable::verify_entry() checks:
909 // - oop value != NULL (same as verify())
910 // - oop value is a String
911 // - hash(String) == hash in entry (same as verify())
912 // - index for hash == index of entry (same as verify())
913 //
914 // StringTable::compare_entries() checks:
915 // - oops are unique across all entries
916 // - String values are unique across all entries
917 //
918 int StringTable::verify_and_compare_entries() {
919 assert(StringTable_lock->is_locked(), "sanity check");
920
921 int fail_cnt = 0;
922
923 // first, verify all the entries individually:
924 for (int bkt = 0; bkt < the_table()->table_size(); bkt++) {
925 HashtableEntry<oop, mtSymbol>* e_ptr = the_table()->bucket(bkt);
926 for (int e_cnt = 0; e_ptr != NULL; e_ptr = e_ptr->next(), e_cnt++) {
927 VerifyRetTypes ret = verify_entry(bkt, e_cnt, e_ptr, _verify_with_mesgs);
928 if (ret != _verify_pass) {
929 fail_cnt++;
930 }
931 }
932 }
933
934 // Optimization: if the above check did not find any failures, then
935 // the comparison loop below does not need to call verify_entry()
936 // before calling compare_entries(). If there were failures, then we
937 // have to call verify_entry() to see if the entry can be passed to
938 // compare_entries() safely. When we call verify_entry() in the loop
939 // below, we do so quietly to void duplicate messages and we don't
940 // increment fail_cnt because the failures have already been counted.
941 bool need_entry_verify = (fail_cnt != 0);
942
943 // second, verify all entries relative to each other:
944 for (int bkt1 = 0; bkt1 < the_table()->table_size(); bkt1++) {
945 HashtableEntry<oop, mtSymbol>* e_ptr1 = the_table()->bucket(bkt1);
946 for (int e_cnt1 = 0; e_ptr1 != NULL; e_ptr1 = e_ptr1->next(), e_cnt1++) {
947 if (need_entry_verify) {
948 VerifyRetTypes ret = verify_entry(bkt1, e_cnt1, e_ptr1,
949 _verify_quietly);
950 if (ret == _verify_fail_done) {
951 // cannot use the current entry to compare against other entries
952 continue;
953 }
954 }
955
956 for (int bkt2 = bkt1; bkt2 < the_table()->table_size(); bkt2++) {
957 HashtableEntry<oop, mtSymbol>* e_ptr2 = the_table()->bucket(bkt2);
958 int e_cnt2;
959 for (e_cnt2 = 0; e_ptr2 != NULL; e_ptr2 = e_ptr2->next(), e_cnt2++) {
960 if (bkt1 == bkt2 && e_cnt2 <= e_cnt1) {
961 // skip the entries up to and including the one that
962 // we're comparing against
963 continue;
964 }
965
966 if (need_entry_verify) {
967 VerifyRetTypes ret = verify_entry(bkt2, e_cnt2, e_ptr2,
968 _verify_quietly);
969 if (ret == _verify_fail_done) {
970 // cannot compare against this entry
971 continue;
972 }
973 }
974
975 // compare two entries, report and count any failures:
976 if (compare_entries(bkt1, e_cnt1, e_ptr1, bkt2, e_cnt2, e_ptr2)
977 != _verify_pass) {
978 fail_cnt++;
979 }
980 }
981 }
982 }
983 }
984 return fail_cnt;
985 }
828 986
829 // Create a new table and using alternate hash code, populate the new table 987 // Create a new table and using alternate hash code, populate the new table
830 // with the existing strings. Set flag to use the alternate hash code afterwards. 988 // with the existing strings. Set flag to use the alternate hash code afterwards.
831 void StringTable::rehash_table() { 989 void StringTable::rehash_table() {
832 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint"); 990 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");

mercurial