< prev index next >

src/share/vm/classfile/symbolTable.cpp

Print this page


   1 /*
   2  * Copyright (c) 1997, 2017, 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  *


 232 // We take care not to be blocking while holding the
 233 // SymbolTable_lock. Otherwise, the system might deadlock, since the
 234 // symboltable is used during compilation (VM_thread) The lock free
 235 // synchronization is simplified by the fact that we do not delete
 236 // entries in the symbol table during normal execution (only during
 237 // safepoints).
 238 
 239 Symbol* SymbolTable::lookup(const char* name, int len, TRAPS) {
 240   unsigned int hashValue = hash_symbol(name, len);
 241   int index = the_table()->hash_to_index(hashValue);
 242 
 243   Symbol* s = the_table()->lookup(index, name, len, hashValue);
 244 
 245   // Found
 246   if (s != NULL) return s;
 247 
 248   // Grab SymbolTable_lock first.
 249   MutexLocker ml(SymbolTable_lock, THREAD);
 250 
 251   // Otherwise, add to symbol to table
 252   return the_table()->basic_add(index, (u1*)name, len, hashValue, true, CHECK_NULL);
 253 }
 254 
 255 Symbol* SymbolTable::lookup(const Symbol* sym, int begin, int end, TRAPS) {
 256   char* buffer;
 257   int index, len;
 258   unsigned int hashValue;
 259   char* name;
 260   {
 261     debug_only(No_Safepoint_Verifier nsv;)
 262 
 263     name = (char*)sym->base() + begin;
 264     len = end - begin;
 265     hashValue = hash_symbol(name, len);
 266     index = the_table()->hash_to_index(hashValue);
 267     Symbol* s = the_table()->lookup(index, name, len, hashValue);
 268 
 269     // Found
 270     if (s != NULL) return s;
 271   }
 272 
 273   // Otherwise, add to symbol to table. Copy to a C string first.
 274   char stack_buf[128];
 275   ResourceMark rm(THREAD);
 276   if (len <= 128) {
 277     buffer = stack_buf;
 278   } else {
 279     buffer = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, len);
 280   }
 281   for (int i=0; i<len; i++) {
 282     buffer[i] = name[i];
 283   }
 284   // Make sure there is no safepoint in the code above since name can't move.
 285   // We can't include the code in No_Safepoint_Verifier because of the
 286   // ResourceMark.
 287 
 288   // Grab SymbolTable_lock first.
 289   MutexLocker ml(SymbolTable_lock, THREAD);
 290 
 291   return the_table()->basic_add(index, (u1*)buffer, len, hashValue, true, CHECK_NULL);
 292 }
 293 
 294 Symbol* SymbolTable::lookup_only(const char* name, int len,
 295                                    unsigned int& hash) {
 296   hash = hash_symbol(name, len);
 297   int index = the_table()->hash_to_index(hash);
 298 
 299   Symbol* s = the_table()->lookup(index, name, len, hash);
 300   return s;
 301 }
 302 
 303 // Look up the address of the literal in the SymbolTable for this Symbol*
 304 // Do not create any new symbols
 305 // Do not increment the reference count to keep this alive
 306 Symbol** SymbolTable::lookup_symbol_addr(Symbol* sym){
 307   unsigned int hash = hash_symbol((char*)sym->bytes(), sym->utf8_length());
 308   int index = the_table()->hash_to_index(hash);
 309 
 310   for (HashtableEntry<Symbol*, mtSymbol>* e = the_table()->bucket(index); e != NULL; e = e->next()) {
 311     if (e->hash() == hash) {


   1 /*
   2  * Copyright (c) 1997, 2019, 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  *


 232 // We take care not to be blocking while holding the
 233 // SymbolTable_lock. Otherwise, the system might deadlock, since the
 234 // symboltable is used during compilation (VM_thread) The lock free
 235 // synchronization is simplified by the fact that we do not delete
 236 // entries in the symbol table during normal execution (only during
 237 // safepoints).
 238 
 239 Symbol* SymbolTable::lookup(const char* name, int len, TRAPS) {
 240   unsigned int hashValue = hash_symbol(name, len);
 241   int index = the_table()->hash_to_index(hashValue);
 242 
 243   Symbol* s = the_table()->lookup(index, name, len, hashValue);
 244 
 245   // Found
 246   if (s != NULL) return s;
 247 
 248   // Grab SymbolTable_lock first.
 249   MutexLocker ml(SymbolTable_lock, THREAD);
 250 
 251   // Otherwise, add to symbol to table
 252   return the_table()->basic_add(index, (u1*)name, len, hashValue, true, THREAD);
 253 }
 254 
 255 Symbol* SymbolTable::lookup(const Symbol* sym, int begin, int end, TRAPS) {
 256   char* buffer;
 257   int index, len;
 258   unsigned int hashValue;
 259   char* name;
 260   {
 261     debug_only(No_Safepoint_Verifier nsv;)
 262 
 263     name = (char*)sym->base() + begin;
 264     len = end - begin;
 265     hashValue = hash_symbol(name, len);
 266     index = the_table()->hash_to_index(hashValue);
 267     Symbol* s = the_table()->lookup(index, name, len, hashValue);
 268 
 269     // Found
 270     if (s != NULL) return s;
 271   }
 272 
 273   // Otherwise, add to symbol to table. Copy to a C string first.
 274   char stack_buf[128];
 275   ResourceMark rm(THREAD);
 276   if (len <= 128) {
 277     buffer = stack_buf;
 278   } else {
 279     buffer = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, len);
 280   }
 281   for (int i=0; i<len; i++) {
 282     buffer[i] = name[i];
 283   }
 284   // Make sure there is no safepoint in the code above since name can't move.
 285   // We can't include the code in No_Safepoint_Verifier because of the
 286   // ResourceMark.
 287 
 288   // Grab SymbolTable_lock first.
 289   MutexLocker ml(SymbolTable_lock, THREAD);
 290 
 291   return the_table()->basic_add(index, (u1*)buffer, len, hashValue, true, THREAD);
 292 }
 293 
 294 Symbol* SymbolTable::lookup_only(const char* name, int len,
 295                                    unsigned int& hash) {
 296   hash = hash_symbol(name, len);
 297   int index = the_table()->hash_to_index(hash);
 298 
 299   Symbol* s = the_table()->lookup(index, name, len, hash);
 300   return s;
 301 }
 302 
 303 // Look up the address of the literal in the SymbolTable for this Symbol*
 304 // Do not create any new symbols
 305 // Do not increment the reference count to keep this alive
 306 Symbol** SymbolTable::lookup_symbol_addr(Symbol* sym){
 307   unsigned int hash = hash_symbol((char*)sym->bytes(), sym->utf8_length());
 308   int index = the_table()->hash_to_index(hash);
 309 
 310   for (HashtableEntry<Symbol*, mtSymbol>* e = the_table()->bucket(index); e != NULL; e = e->next()) {
 311     if (e->hash() == hash) {


< prev index next >