src/share/vm/classfile/symbolTable.hpp

Print this page
rev 4769 : 8015237: Parallelize string table scanning during strong root processing
Summary: Parallelize the scanning of the intern string table by having each GC worker claim a given number of buckets.
Reviewed-by:
   1 /*
   2  * Copyright (c) 1997, 2012, 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  *


 229   }
 230   static void reverse(void* boundary = NULL) {
 231     the_table()->Hashtable<Symbol*, mtSymbol>::reverse(boundary);
 232   }
 233 
 234   // Rehash the symbol table if it gets out of balance
 235   static void rehash_table();
 236   static bool needs_rehashing()         { return _needs_rehashing; }
 237 };
 238 
 239 class StringTable : public Hashtable<oop, mtSymbol> {
 240   friend class VMStructs;
 241 
 242 private:
 243   // The string table
 244   static StringTable* _the_table;
 245 
 246   // Set if one bucket is out of balance due to hash algorithm deficiency
 247   static bool _needs_rehashing;
 248 



 249   static oop intern(Handle string_or_null, jchar* chars, int length, TRAPS);
 250   oop basic_add(int index, Handle string_or_null, jchar* name, int len,
 251                 unsigned int hashValue, TRAPS);
 252 
 253   oop lookup(int index, jchar* chars, int length, unsigned int hashValue);
 254 




 255   StringTable() : Hashtable<oop, mtSymbol>((int)StringTableSize,
 256                               sizeof (HashtableEntry<oop, mtSymbol>)) {}
 257 
 258   StringTable(HashtableBucket<mtSymbol>* t, int number_of_entries)
 259     : Hashtable<oop, mtSymbol>((int)StringTableSize, sizeof (HashtableEntry<oop, mtSymbol>), t,
 260                      number_of_entries) {}
 261 public:
 262   // The string table
 263   static StringTable* the_table() { return _the_table; }
 264 
 265   // Size of one bucket in the string table.  Used when checking for rollover.
 266   static uint bucket_size() { return sizeof(HashtableBucket<mtSymbol>); }
 267 
 268   static void create_table() {
 269     assert(_the_table == NULL, "One string table allowed.");
 270     _the_table = new StringTable();
 271   }
 272 
 273   // GC support
 274   //   Delete pointers to otherwise-unreachable objects.
 275   static void unlink_or_oops_do(BoolObjectClosure* cl, OopClosure* f);
 276   static void unlink(BoolObjectClosure* cl) {
 277     unlink_or_oops_do(cl, NULL);
 278   }
 279 
 280   // Invoke "f->do_oop" on the locations of all oops in the table.
 281   static void oops_do(OopClosure* f);
 282 



 283   // Hashing algorithm, used as the hash value used by the
 284   //     StringTable for bucket selection and comparison (stored in the
 285   //     HashtableEntry structures).  This is used in the String.intern() method.
 286   static unsigned int hash_string(const jchar* s, int len);
 287 
 288   // Internal test.
 289   static void test_alt_hash() PRODUCT_RETURN;
 290 
 291   // Probing
 292   static oop lookup(Symbol* symbol);
 293   static oop lookup(jchar* chars, int length);
 294 
 295   // Interning
 296   static oop intern(Symbol* symbol, TRAPS);
 297   static oop intern(oop string, TRAPS);
 298   static oop intern(const char *utf8_string, TRAPS);
 299 
 300   // Debugging
 301   static void verify();
 302   static void dump(outputStream* st);
 303 
 304   // Sharing
 305   static void copy_buckets(char** top, char*end) {
 306     the_table()->Hashtable<oop, mtSymbol>::copy_buckets(top, end);
 307   }
 308   static void copy_table(char** top, char*end) {
 309     the_table()->Hashtable<oop, mtSymbol>::copy_table(top, end);
 310   }
 311   static void reverse() {
 312     the_table()->Hashtable<oop, mtSymbol>::reverse();
 313   }
 314 
 315   // Rehash the symbol table if it gets out of balance
 316   static void rehash_table();
 317   static bool needs_rehashing() { return _needs_rehashing; }



 318 };
 319 #endif // SHARE_VM_CLASSFILE_SYMBOLTABLE_HPP
   1 /*
   2  * Copyright (c) 1997, 2013, 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  *


 229   }
 230   static void reverse(void* boundary = NULL) {
 231     the_table()->Hashtable<Symbol*, mtSymbol>::reverse(boundary);
 232   }
 233 
 234   // Rehash the symbol table if it gets out of balance
 235   static void rehash_table();
 236   static bool needs_rehashing()         { return _needs_rehashing; }
 237 };
 238 
 239 class StringTable : public Hashtable<oop, mtSymbol> {
 240   friend class VMStructs;
 241 
 242 private:
 243   // The string table
 244   static StringTable* _the_table;
 245 
 246   // Set if one bucket is out of balance due to hash algorithm deficiency
 247   static bool _needs_rehashing;
 248 
 249   // Claimed high water mark for parallel chunked scanning
 250   static volatile int _par_claimed_idx;
 251 
 252   static oop intern(Handle string_or_null, jchar* chars, int length, TRAPS);
 253   oop basic_add(int index, Handle string_or_null, jchar* name, int len,
 254                 unsigned int hashValue, TRAPS);
 255 
 256   oop lookup(int index, jchar* chars, int length, unsigned int hashValue);
 257 
 258   // Apply the give oop closure to the entries to the buckets
 259   // in the range [start_idx, end_idx).
 260   static void buckets_do(OopClosure* f, int start_idx, int end_idx);
 261 
 262   StringTable() : Hashtable<oop, mtSymbol>((int)StringTableSize,
 263                               sizeof (HashtableEntry<oop, mtSymbol>)) {}
 264 
 265   StringTable(HashtableBucket<mtSymbol>* t, int number_of_entries)
 266     : Hashtable<oop, mtSymbol>((int)StringTableSize, sizeof (HashtableEntry<oop, mtSymbol>), t,
 267                      number_of_entries) {}
 268 public:
 269   // The string table
 270   static StringTable* the_table() { return _the_table; }
 271 
 272   // Size of one bucket in the string table.  Used when checking for rollover.
 273   static uint bucket_size() { return sizeof(HashtableBucket<mtSymbol>); }
 274 
 275   static void create_table() {
 276     assert(_the_table == NULL, "One string table allowed.");
 277     _the_table = new StringTable();
 278   }
 279 
 280   // GC support
 281   //   Delete pointers to otherwise-unreachable objects.
 282   static void unlink_or_oops_do(BoolObjectClosure* cl, OopClosure* f);
 283   static void unlink(BoolObjectClosure* cl) {
 284     unlink_or_oops_do(cl, NULL);
 285   }
 286 
 287   // Serially invoke "f->do_oop" on the locations of all oops in the table.
 288   static void oops_do(OopClosure* f);
 289 
 290   // Possibly parallel version of the above
 291   static void possibly_parallel_oops_do(OopClosure* f);
 292 
 293   // Hashing algorithm, used as the hash value used by the
 294   //     StringTable for bucket selection and comparison (stored in the
 295   //     HashtableEntry structures).  This is used in the String.intern() method.
 296   static unsigned int hash_string(const jchar* s, int len);
 297 
 298   // Internal test.
 299   static void test_alt_hash() PRODUCT_RETURN;
 300 
 301   // Probing
 302   static oop lookup(Symbol* symbol);
 303   static oop lookup(jchar* chars, int length);
 304 
 305   // Interning
 306   static oop intern(Symbol* symbol, TRAPS);
 307   static oop intern(oop string, TRAPS);
 308   static oop intern(const char *utf8_string, TRAPS);
 309 
 310   // Debugging
 311   static void verify();
 312   static void dump(outputStream* st);
 313 
 314   // Sharing
 315   static void copy_buckets(char** top, char*end) {
 316     the_table()->Hashtable<oop, mtSymbol>::copy_buckets(top, end);
 317   }
 318   static void copy_table(char** top, char*end) {
 319     the_table()->Hashtable<oop, mtSymbol>::copy_table(top, end);
 320   }
 321   static void reverse() {
 322     the_table()->Hashtable<oop, mtSymbol>::reverse();
 323   }
 324 
 325   // Rehash the symbol table if it gets out of balance
 326   static void rehash_table();
 327   static bool needs_rehashing() { return _needs_rehashing; }
 328 
 329   // Parallel chunked scanning
 330   static void clear_par_claimed_index() { _par_claimed_idx = 0; }
 331 };
 332 #endif // SHARE_VM_CLASSFILE_SYMBOLTABLE_HPP