src/share/vm/classfile/symbolTable.cpp

Print this page




 324     }
 325   }
 326 }
 327 
 328 Symbol* SymbolTable::new_permanent_symbol(const char* name, TRAPS) {
 329   unsigned int hash;
 330   Symbol* result = SymbolTable::lookup_only((char*)name, (int)strlen(name), hash);
 331   if (result != NULL) {
 332     return result;
 333   }
 334   // Grab SymbolTable_lock first.
 335   MutexLocker ml(SymbolTable_lock, THREAD);
 336 
 337   SymbolTable* table = the_table();
 338   int index = table->hash_to_index(hash);
 339   return table->basic_add(index, (u1*)name, (int)strlen(name), hash, false, THREAD);
 340 }
 341 
 342 Symbol* SymbolTable::basic_add(int index_arg, u1 *name, int len,
 343                                unsigned int hashValue_arg, bool c_heap, TRAPS) {
 344   assert(!Universe::heap()->is_in_reserved(name) || GC_locker::is_active(),
 345          "proposed name of symbol must be stable");
 346 
 347   // Don't allow symbols to be created which cannot fit in a Symbol*.
 348   if (len > Symbol::max_length()) {
 349     THROW_MSG_0(vmSymbols::java_lang_InternalError(),
 350                 "name is too long to represent");
 351   }
 352 
 353   // Cannot hit a safepoint in this function because the "this" pointer can move.
 354   No_Safepoint_Verifier nsv;
 355 
 356   // Check if the symbol table has been rehashed, if so, need to recalculate
 357   // the hash value and index.
 358   unsigned int hashValue;
 359   int index;
 360   if (use_alternate_hashcode()) {
 361     hashValue = hash_symbol((const char*)name, len);
 362     index = hash_to_index(hashValue);
 363   } else {
 364     hashValue = hashValue_arg;


 668 }
 669 
 670 
 671 oop StringTable::lookup(jchar* name, int len) {
 672   unsigned int hash = hash_string(name, len);
 673   int index = the_table()->hash_to_index(hash);
 674   return the_table()->lookup(index, name, len, hash);
 675 }
 676 
 677 
 678 oop StringTable::intern(Handle string_or_null, jchar* name,
 679                         int len, TRAPS) {
 680   unsigned int hashValue = hash_string(name, len);
 681   int index = the_table()->hash_to_index(hashValue);
 682   oop found_string = the_table()->lookup(index, name, len, hashValue);
 683 
 684   // Found
 685   if (found_string != NULL) return found_string;
 686 
 687   debug_only(StableMemoryChecker smc(name, len * sizeof(name[0])));
 688   assert(!Universe::heap()->is_in_reserved(name) || GC_locker::is_active(),
 689          "proposed name of symbol must be stable");
 690 
 691   Handle string;
 692   // try to reuse the string if possible
 693   if (!string_or_null.is_null()) {
 694     string = string_or_null;
 695   } else {
 696     string = java_lang_String::create_from_unicode(name, len, CHECK_NULL);
 697   }
 698 
 699   // Grab the StringTable_lock before getting the_table() because it could
 700   // change at safepoint.
 701   MutexLocker ml(StringTable_lock, THREAD);
 702 
 703   // Otherwise, add to symbol to table
 704   return the_table()->basic_add(index, string, name, len,
 705                                 hashValue, CHECK_NULL);
 706 }
 707 
 708 oop StringTable::intern(Symbol* symbol, TRAPS) {




 324     }
 325   }
 326 }
 327 
 328 Symbol* SymbolTable::new_permanent_symbol(const char* name, TRAPS) {
 329   unsigned int hash;
 330   Symbol* result = SymbolTable::lookup_only((char*)name, (int)strlen(name), hash);
 331   if (result != NULL) {
 332     return result;
 333   }
 334   // Grab SymbolTable_lock first.
 335   MutexLocker ml(SymbolTable_lock, THREAD);
 336 
 337   SymbolTable* table = the_table();
 338   int index = table->hash_to_index(hash);
 339   return table->basic_add(index, (u1*)name, (int)strlen(name), hash, false, THREAD);
 340 }
 341 
 342 Symbol* SymbolTable::basic_add(int index_arg, u1 *name, int len,
 343                                unsigned int hashValue_arg, bool c_heap, TRAPS) {
 344   assert(!Universe::heap()->is_in_reserved(name),
 345          "proposed name of symbol must be stable");
 346 
 347   // Don't allow symbols to be created which cannot fit in a Symbol*.
 348   if (len > Symbol::max_length()) {
 349     THROW_MSG_0(vmSymbols::java_lang_InternalError(),
 350                 "name is too long to represent");
 351   }
 352 
 353   // Cannot hit a safepoint in this function because the "this" pointer can move.
 354   No_Safepoint_Verifier nsv;
 355 
 356   // Check if the symbol table has been rehashed, if so, need to recalculate
 357   // the hash value and index.
 358   unsigned int hashValue;
 359   int index;
 360   if (use_alternate_hashcode()) {
 361     hashValue = hash_symbol((const char*)name, len);
 362     index = hash_to_index(hashValue);
 363   } else {
 364     hashValue = hashValue_arg;


 668 }
 669 
 670 
 671 oop StringTable::lookup(jchar* name, int len) {
 672   unsigned int hash = hash_string(name, len);
 673   int index = the_table()->hash_to_index(hash);
 674   return the_table()->lookup(index, name, len, hash);
 675 }
 676 
 677 
 678 oop StringTable::intern(Handle string_or_null, jchar* name,
 679                         int len, TRAPS) {
 680   unsigned int hashValue = hash_string(name, len);
 681   int index = the_table()->hash_to_index(hashValue);
 682   oop found_string = the_table()->lookup(index, name, len, hashValue);
 683 
 684   // Found
 685   if (found_string != NULL) return found_string;
 686 
 687   debug_only(StableMemoryChecker smc(name, len * sizeof(name[0])));
 688   assert(!Universe::heap()->is_in_reserved(name),
 689          "proposed name of symbol must be stable");
 690 
 691   Handle string;
 692   // try to reuse the string if possible
 693   if (!string_or_null.is_null()) {
 694     string = string_or_null;
 695   } else {
 696     string = java_lang_String::create_from_unicode(name, len, CHECK_NULL);
 697   }
 698 
 699   // Grab the StringTable_lock before getting the_table() because it could
 700   // change at safepoint.
 701   MutexLocker ml(StringTable_lock, THREAD);
 702 
 703   // Otherwise, add to symbol to table
 704   return the_table()->basic_add(index, string, name, len,
 705                                 hashValue, CHECK_NULL);
 706 }
 707 
 708 oop StringTable::intern(Symbol* symbol, TRAPS) {