< prev index next >

src/share/vm/classfile/symbolTable.cpp

Print this page




 704 
 705   HashtableEntry<oop, mtSymbol>* entry = new_entry(hashValue, string());
 706   add_entry(index, entry);
 707   return string();
 708 }
 709 
 710 
 711 oop StringTable::lookup(Symbol* symbol) {
 712   ResourceMark rm;
 713   int length;
 714   jchar* chars = symbol->as_unicode(length);
 715   return lookup(chars, length);
 716 }
 717 
 718 // Tell the GC that this string was looked up in the StringTable.
 719 static void ensure_string_alive(oop string) {
 720   // A lookup in the StringTable could return an object that was previously
 721   // considered dead. The SATB part of G1 needs to get notified about this
 722   // potential resurrection, otherwise the marking might not find the object.
 723 #if INCLUDE_ALL_GCS
 724   if (UseG1GC && string != NULL) {
 725     G1SATBCardTableModRefBS::enqueue(string);
 726   }
 727 #endif
 728 }
 729 
 730 oop StringTable::lookup(jchar* name, int len) {
 731   unsigned int hash = hash_string(name, len);
 732   int index = the_table()->hash_to_index(hash);
 733   oop string = the_table()->lookup(index, name, len, hash);
 734 
 735   ensure_string_alive(string);
 736 
 737   return string;
 738 }
 739 
 740 
 741 oop StringTable::intern(Handle string_or_null, jchar* name,
 742                         int len, TRAPS) {
 743   unsigned int hashValue = hash_string(name, len);
 744   int index = the_table()->hash_to_index(hashValue);


 905     }
 906   }
 907 }
 908 
 909 void StringTable::oops_do(OopClosure* f) {
 910   buckets_oops_do(f, 0, the_table()->table_size());
 911 }
 912 
 913 void StringTable::possibly_parallel_oops_do(OopClosure* f) {
 914   const int limit = the_table()->table_size();
 915 
 916   for (;;) {
 917     // Grab next set of buckets to scan
 918     int start_idx = Atomic::add(ClaimChunkSize, &_parallel_claimed_idx) - ClaimChunkSize;
 919     if (start_idx >= limit) {
 920       // End of table
 921       break;
 922     }
 923 
 924     int end_idx = MIN2(limit, start_idx + ClaimChunkSize);






















 925     buckets_oops_do(f, start_idx, end_idx);
 926   }
 927 }
 928 
 929 // This verification is part of Universe::verify() and needs to be quick.
 930 // See StringTable::verify_and_compare() below for exhaustive verification.
 931 void StringTable::verify() {
 932   for (int i = 0; i < the_table()->table_size(); ++i) {
 933     HashtableEntry<oop, mtSymbol>* p = the_table()->bucket(i);
 934     for ( ; p != NULL; p = p->next()) {
 935       oop s = p->literal();
 936       guarantee(s != NULL, "interned string is NULL");
 937       unsigned int h = java_lang_String::hash_string(s);
 938       guarantee(p->hash() == h, "broken hash in string table entry");
 939       guarantee(the_table()->hash_to_index(h) == i,
 940                 "wrong index in string table");
 941     }
 942   }
 943 }
 944 




 704 
 705   HashtableEntry<oop, mtSymbol>* entry = new_entry(hashValue, string());
 706   add_entry(index, entry);
 707   return string();
 708 }
 709 
 710 
 711 oop StringTable::lookup(Symbol* symbol) {
 712   ResourceMark rm;
 713   int length;
 714   jchar* chars = symbol->as_unicode(length);
 715   return lookup(chars, length);
 716 }
 717 
 718 // Tell the GC that this string was looked up in the StringTable.
 719 static void ensure_string_alive(oop string) {
 720   // A lookup in the StringTable could return an object that was previously
 721   // considered dead. The SATB part of G1 needs to get notified about this
 722   // potential resurrection, otherwise the marking might not find the object.
 723 #if INCLUDE_ALL_GCS
 724   if ((UseG1GC || (UseShenandoahGC && ShenandoahSATBBarrier)) && string != NULL) {
 725     G1SATBCardTableModRefBS::enqueue(string);
 726   }
 727 #endif
 728 }
 729 
 730 oop StringTable::lookup(jchar* name, int len) {
 731   unsigned int hash = hash_string(name, len);
 732   int index = the_table()->hash_to_index(hash);
 733   oop string = the_table()->lookup(index, name, len, hash);
 734 
 735   ensure_string_alive(string);
 736 
 737   return string;
 738 }
 739 
 740 
 741 oop StringTable::intern(Handle string_or_null, jchar* name,
 742                         int len, TRAPS) {
 743   unsigned int hashValue = hash_string(name, len);
 744   int index = the_table()->hash_to_index(hashValue);


 905     }
 906   }
 907 }
 908 
 909 void StringTable::oops_do(OopClosure* f) {
 910   buckets_oops_do(f, 0, the_table()->table_size());
 911 }
 912 
 913 void StringTable::possibly_parallel_oops_do(OopClosure* f) {
 914   const int limit = the_table()->table_size();
 915 
 916   for (;;) {
 917     // Grab next set of buckets to scan
 918     int start_idx = Atomic::add(ClaimChunkSize, &_parallel_claimed_idx) - ClaimChunkSize;
 919     if (start_idx >= limit) {
 920       // End of table
 921       break;
 922     }
 923 
 924     int end_idx = MIN2(limit, start_idx + ClaimChunkSize);
 925     buckets_oops_do(f, start_idx, end_idx);
 926   }
 927 }
 928 
 929 void StringTable::possibly_parallel_oops_do_shenandoah(OopClosure* f) {
 930   const int limit = the_table()->table_size();
 931 
 932   // ClaimChunkSize is too small for processing a String table during the pause
 933   // efficiently: the atomic add costs dominate on many reasonable string tables.
 934   // Recast the chunk size to give each GC worker about 10 chunks.
 935   assert(UseShenandoahGC, "Only for Shenandoah");
 936   const int chunk_size = MAX2<int>(ClaimChunkSize, limit / (ParallelGCThreads * 10));
 937 
 938   for (;;) {
 939     // Grab next set of buckets to scan
 940     int start_idx = Atomic::add(chunk_size, &_parallel_claimed_idx) - chunk_size;
 941     if (start_idx >= limit) {
 942       // End of table
 943       break;
 944     }
 945 
 946     int end_idx = MIN2(limit, start_idx + chunk_size);
 947     buckets_oops_do(f, start_idx, end_idx);
 948   }
 949 }
 950 
 951 // This verification is part of Universe::verify() and needs to be quick.
 952 // See StringTable::verify_and_compare() below for exhaustive verification.
 953 void StringTable::verify() {
 954   for (int i = 0; i < the_table()->table_size(); ++i) {
 955     HashtableEntry<oop, mtSymbol>* p = the_table()->bucket(i);
 956     for ( ; p != NULL; p = p->next()) {
 957       oop s = p->literal();
 958       guarantee(s != NULL, "interned string is NULL");
 959       unsigned int h = java_lang_String::hash_string(s);
 960       guarantee(p->hash() == h, "broken hash in string table entry");
 961       guarantee(the_table()->hash_to_index(h) == i,
 962                 "wrong index in string table");
 963     }
 964   }
 965 }
 966 


< prev index next >