src/share/vm/classfile/symbolTable.hpp

Print this page
rev 4551 : 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. Changes were also reviewed by Per Liden <per.liden@oracle.com>.
Reviewed-by: tschatzl, stefank, twisti
   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  *


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



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




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



 284   // Hashing algorithm, used as the hash value used by the
 285   //     StringTable for bucket selection and comparison (stored in the
 286   //     HashtableEntry structures).  This is used in the String.intern() method.
 287   static unsigned int hash_string(const jchar* s, int len);
 288 
 289   // Internal test.
 290   static void test_alt_hash() PRODUCT_RETURN;
 291 
 292   // Probing
 293   static oop lookup(Symbol* symbol);
 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  *


 228   }
 229   static void reverse(void* boundary = NULL) {
 230     the_table()->Hashtable<Symbol*, mtSymbol>::reverse(boundary);
 231   }
 232 
 233   // Rehash the symbol table if it gets out of balance
 234   static void rehash_table();
 235   static bool needs_rehashing()         { return _needs_rehashing; }
 236 };
 237 
 238 class StringTable : public Hashtable<oop, mtSymbol> {
 239   friend class VMStructs;
 240 
 241 private:
 242   // The string table
 243   static StringTable* _the_table;
 244 
 245   // Set if one bucket is out of balance due to hash algorithm deficiency
 246   static bool _needs_rehashing;
 247 
 248   // Claimed high water mark for parallel chunked scanning
 249   static volatile int _parallel_claimed_idx;
 250 
 251   static oop intern(Handle string_or_null, jchar* chars, int length, TRAPS);
 252   oop basic_add(int index, Handle string_or_null, jchar* name, int len,
 253                 unsigned int hashValue, TRAPS);
 254 
 255   oop lookup(int index, jchar* chars, int length, unsigned int hashValue);
 256 
 257   // Apply the give oop closure to the entries to the buckets
 258   // in the range [start_idx, end_idx).
 259   static void buckets_do(OopClosure* f, int start_idx, int end_idx);
 260 
 261   StringTable() : Hashtable<oop, mtSymbol>((int)StringTableSize,
 262                               sizeof (HashtableEntry<oop, mtSymbol>)) {}
 263 
 264   StringTable(HashtableBucket<mtSymbol>* t, int number_of_entries)
 265     : Hashtable<oop, mtSymbol>((int)StringTableSize, sizeof (HashtableEntry<oop, mtSymbol>), t,
 266                      number_of_entries) {}
 267 public:
 268   // The string table
 269   static StringTable* the_table() { return _the_table; }
 270 
 271   static void create_table() {
 272     assert(_the_table == NULL, "One string table allowed.");
 273     _the_table = new StringTable();
 274   }
 275 
 276   static void create_table(HashtableBucket<mtSymbol>* t, int length,
 277                            int number_of_entries) {
 278     assert(_the_table == NULL, "One string table allowed.");
 279     assert((size_t)length == StringTableSize * sizeof(HashtableBucket<mtSymbol>),
 280            "bad shared string size.");
 281     _the_table = new StringTable(t, number_of_entries);
 282   }
 283 
 284   // GC support
 285   //   Delete pointers to otherwise-unreachable objects.
 286   static void unlink(BoolObjectClosure* cl);
 287 
 288   // Serially invoke "f->do_oop" on the locations of all oops in the table.
 289   static void oops_do(OopClosure* f);
 290 
 291   // Possibly parallel version of the above
 292   static void possibly_parallel_oops_do(OopClosure* f);
 293 
 294   // Hashing algorithm, used as the hash value used by the
 295   //     StringTable for bucket selection and comparison (stored in the
 296   //     HashtableEntry structures).  This is used in the String.intern() method.
 297   static unsigned int hash_string(const jchar* s, int len);
 298 
 299   // Internal test.
 300   static void test_alt_hash() PRODUCT_RETURN;
 301 
 302   // Probing
 303   static oop lookup(Symbol* symbol);
 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_parallel_claimed_index() { _parallel_claimed_idx = 0; }
 331 };
 332 #endif // SHARE_VM_CLASSFILE_SYMBOLTABLE_HPP