src/share/vm/classfile/stringTable.cpp

Print this page




   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  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "classfile/altHashing.hpp"

  27 #include "classfile/javaClasses.hpp"
  28 #include "classfile/stringTable.hpp"
  29 #include "classfile/systemDictionary.hpp"
  30 #include "gc_interface/collectedHeap.inline.hpp"
  31 #include "memory/allocation.inline.hpp"
  32 #include "memory/filemap.hpp"
  33 #include "memory/gcLocker.inline.hpp"
  34 #include "oops/oop.inline.hpp"
  35 #include "oops/oop.inline2.hpp"
  36 #include "runtime/atomic.inline.hpp"
  37 #include "runtime/mutexLocker.hpp"
  38 #include "utilities/hashtable.inline.hpp"
  39 #if INCLUDE_ALL_GCS
  40 #include "gc_implementation/g1/g1SATBCardTableModRefBS.hpp"
  41 #include "gc_implementation/g1/g1StringDedup.hpp"
  42 #endif
  43 
  44 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
  45 
  46 // the number of buckets a thread claims


 361     buckets_oops_do(f, start_idx, end_idx);
 362   }
 363 }
 364 
 365 // This verification is part of Universe::verify() and needs to be quick.
 366 // See StringTable::verify_and_compare() below for exhaustive verification.
 367 void StringTable::verify() {
 368   for (int i = 0; i < the_table()->table_size(); ++i) {
 369     HashtableEntry<oop, mtSymbol>* p = the_table()->bucket(i);
 370     for ( ; p != NULL; p = p->next()) {
 371       oop s = p->literal();
 372       guarantee(s != NULL, "interned string is NULL");
 373       unsigned int h = java_lang_String::hash_string(s);
 374       guarantee(p->hash() == h, "broken hash in string table entry");
 375       guarantee(the_table()->hash_to_index(h) == i,
 376                 "wrong index in string table");
 377     }
 378   }
 379 }
 380 
 381 void StringTable::dump(outputStream* st) {

 382   the_table()->dump_table(st, "StringTable");



























 383 }
 384 
 385 StringTable::VerifyRetTypes StringTable::compare_entries(
 386                                       int bkt1, int e_cnt1,
 387                                       HashtableEntry<oop, mtSymbol>* e_ptr1,
 388                                       int bkt2, int e_cnt2,
 389                                       HashtableEntry<oop, mtSymbol>* e_ptr2) {
 390   // These entries are sanity checked by verify_and_compare_entries()
 391   // before this function is called.
 392   oop str1 = e_ptr1->literal();
 393   oop str2 = e_ptr2->literal();
 394 
 395   if (str1 == str2) {
 396     tty->print_cr("ERROR: identical oop values (0x" PTR_FORMAT ") "
 397                   "in entry @ bucket[%d][%d] and entry @ bucket[%d][%d]",
 398                   (void *)str1, bkt1, e_cnt1, bkt2, e_cnt2);
 399     return _verify_fail_continue;
 400   }
 401 
 402   if (java_lang_String::equals(str1, str2)) {


 539   return fail_cnt;
 540 }
 541 
 542 // Create a new table and using alternate hash code, populate the new table
 543 // with the existing strings.   Set flag to use the alternate hash code afterwards.
 544 void StringTable::rehash_table() {
 545   assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
 546   // This should never happen with -Xshare:dump but it might in testing mode.
 547   if (DumpSharedSpaces) return;
 548   StringTable* new_table = new StringTable();
 549 
 550   // Rehash the table
 551   the_table()->move_to(new_table);
 552 
 553   // Delete the table and buckets (entries are reused in new table).
 554   delete _the_table;
 555   // Don't check if we need rehashing until the table gets unbalanced again.
 556   // Then rehash with a new global seed.
 557   _needs_rehashing = false;
 558   _the_table = new_table;

























 559 }


   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  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "classfile/altHashing.hpp"
  27 #include "classfile/compactHashtable.hpp"
  28 #include "classfile/javaClasses.hpp"
  29 #include "classfile/stringTable.hpp"
  30 #include "classfile/systemDictionary.hpp"
  31 #include "gc_interface/collectedHeap.inline.hpp"
  32 #include "memory/allocation.inline.hpp"
  33 #include "memory/filemap.hpp"
  34 #include "memory/gcLocker.inline.hpp"
  35 #include "oops/oop.inline.hpp"
  36 #include "oops/oop.inline2.hpp"
  37 #include "runtime/atomic.inline.hpp"
  38 #include "runtime/mutexLocker.hpp"
  39 #include "utilities/hashtable.inline.hpp"
  40 #if INCLUDE_ALL_GCS
  41 #include "gc_implementation/g1/g1SATBCardTableModRefBS.hpp"
  42 #include "gc_implementation/g1/g1StringDedup.hpp"
  43 #endif
  44 
  45 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
  46 
  47 // the number of buckets a thread claims


 362     buckets_oops_do(f, start_idx, end_idx);
 363   }
 364 }
 365 
 366 // This verification is part of Universe::verify() and needs to be quick.
 367 // See StringTable::verify_and_compare() below for exhaustive verification.
 368 void StringTable::verify() {
 369   for (int i = 0; i < the_table()->table_size(); ++i) {
 370     HashtableEntry<oop, mtSymbol>* p = the_table()->bucket(i);
 371     for ( ; p != NULL; p = p->next()) {
 372       oop s = p->literal();
 373       guarantee(s != NULL, "interned string is NULL");
 374       unsigned int h = java_lang_String::hash_string(s);
 375       guarantee(p->hash() == h, "broken hash in string table entry");
 376       guarantee(the_table()->hash_to_index(h) == i,
 377                 "wrong index in string table");
 378     }
 379   }
 380 }
 381 
 382 void StringTable::dump(outputStream* st, bool verbose) {
 383   if (!verbose) {
 384     the_table()->dump_table(st, "StringTable");
 385   } else {
 386     Thread* THREAD = Thread::current();
 387     st->print_cr("VERSION: 1.1");
 388     for (int i = 0; i < the_table()->table_size(); ++i) {
 389       HashtableEntry<oop, mtSymbol>* p = the_table()->bucket(i);
 390       for ( ; p != NULL; p = p->next()) {
 391         oop s = p->literal();
 392         typeArrayOop value  = java_lang_String::value(s);
 393         int          offset = java_lang_String::offset(s);
 394         int          length = java_lang_String::length(s);
 395 
 396         if (length <= 0) {
 397           st->print("%d: ", length);
 398         } else {
 399           ResourceMark rm(THREAD);
 400           jchar* chars = (jchar*)value->char_at_addr(offset);
 401           int utf8_length = UNICODE::utf8_length(chars, length);
 402           char* utf8_string = NEW_RESOURCE_ARRAY(char, utf8_length + 1);
 403           UNICODE::convert_to_utf8(chars, length, utf8_string);
 404 
 405           st->print("%d: ", utf8_length);
 406           HashtableTextDump::put_utf8(st, utf8_string, utf8_length);
 407         }
 408         st->cr();
 409       }
 410     }
 411   }
 412 }
 413 
 414 StringTable::VerifyRetTypes StringTable::compare_entries(
 415                                       int bkt1, int e_cnt1,
 416                                       HashtableEntry<oop, mtSymbol>* e_ptr1,
 417                                       int bkt2, int e_cnt2,
 418                                       HashtableEntry<oop, mtSymbol>* e_ptr2) {
 419   // These entries are sanity checked by verify_and_compare_entries()
 420   // before this function is called.
 421   oop str1 = e_ptr1->literal();
 422   oop str2 = e_ptr2->literal();
 423 
 424   if (str1 == str2) {
 425     tty->print_cr("ERROR: identical oop values (0x" PTR_FORMAT ") "
 426                   "in entry @ bucket[%d][%d] and entry @ bucket[%d][%d]",
 427                   (void *)str1, bkt1, e_cnt1, bkt2, e_cnt2);
 428     return _verify_fail_continue;
 429   }
 430 
 431   if (java_lang_String::equals(str1, str2)) {


 568   return fail_cnt;
 569 }
 570 
 571 // Create a new table and using alternate hash code, populate the new table
 572 // with the existing strings.   Set flag to use the alternate hash code afterwards.
 573 void StringTable::rehash_table() {
 574   assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
 575   // This should never happen with -Xshare:dump but it might in testing mode.
 576   if (DumpSharedSpaces) return;
 577   StringTable* new_table = new StringTable();
 578 
 579   // Rehash the table
 580   the_table()->move_to(new_table);
 581 
 582   // Delete the table and buckets (entries are reused in new table).
 583   delete _the_table;
 584   // Don't check if we need rehashing until the table gets unbalanced again.
 585   // Then rehash with a new global seed.
 586   _needs_rehashing = false;
 587   _the_table = new_table;
 588 }
 589 
 590 // Utility for dumping strings
 591 StringtableDCmd::StringtableDCmd(outputStream* output, bool heap) :
 592                                  DCmdWithParser(output, heap),
 593   _verbose("-verbose", "Dump the content of each string in the table",
 594            "BOOLEAN", false, "false") {
 595   _dcmdparser.add_dcmd_option(&_verbose);
 596 }
 597 
 598 void StringtableDCmd::execute(DCmdSource source, TRAPS) {
 599   VM_DumpHashtable dumper(output(), VM_DumpHashtable::DumpStrings,
 600                          _verbose.value());
 601   VMThread::execute(&dumper);
 602 }
 603 
 604 int StringtableDCmd::num_arguments() {
 605   ResourceMark rm;
 606   StringtableDCmd* dcmd = new StringtableDCmd(NULL, false);
 607   if (dcmd != NULL) {
 608     DCmdMark mark(dcmd);
 609     return dcmd->_dcmdparser.num_arguments();
 610   } else {
 611     return 0;
 612   }
 613 }