src/share/vm/classfile/compactHashtable.hpp

Print this page
rev 9593 : 8143615: compactHashtable.hpp includes .inline.hpp file
Reviewed-by: xxx, yyy


  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  *
  23  */
  24 
  25 #ifndef SHARE_VM_CLASSFILE_COMPACTHASHTABLE_HPP
  26 #define SHARE_VM_CLASSFILE_COMPACTHASHTABLE_HPP
  27 
  28 #include "classfile/stringTable.hpp"
  29 #include "classfile/symbolTable.hpp"
  30 #include "memory/allocation.inline.hpp"
  31 #include "oops/oop.inline.hpp"
  32 #include "oops/symbol.hpp"
  33 #include "services/diagnosticCommand.hpp"
  34 #include "utilities/hashtable.hpp"
  35 
  36 class NumberSeq;
  37 
  38 // Stats for symbol tables in the CDS archive
  39 class CompactHashtableStats VALUE_OBJ_CLASS_SPEC {
  40 public:
  41   int hashentry_count;
  42   int hashentry_bytes;
  43   int bucket_count;
  44   int bucket_bytes;
  45 };
  46 
  47 /////////////////////////////////////////////////////////////////////////
  48 //
  49 // The compact hash table writer. Used at dump time for writing out
  50 // the compact table to the shared archive.
  51 //


 202 // dump time.
 203 //
 204 template <class T, class N> class CompactHashtable VALUE_OBJ_CLASS_SPEC {
 205   friend class VMStructs;
 206 
 207  public:
 208   enum CompactHashtableType {
 209     _symbol_table = 0,
 210     _string_table = 1
 211   };
 212 
 213 private:
 214   CompactHashtableType _type;
 215   uintx  _base_address;
 216   juint  _entry_count;
 217   juint  _bucket_count;
 218   juint  _table_end_offset;
 219   juint* _buckets;
 220 
 221   inline Symbol* lookup_entry(CompactHashtable<Symbol*, char>* const t,
 222                               juint* addr, const char* name, int len) {
 223     Symbol* sym = (Symbol*)((void*)(_base_address + *addr));
 224     if (sym->equals(name, len)) {
 225       assert(sym->refcount() == -1, "must be shared");
 226       return sym;
 227     }
 228 
 229     return NULL;
 230   }
 231 
 232   inline oop lookup_entry(CompactHashtable<oop, char>* const t,
 233                         juint* addr, const char* name, int len) {
 234     narrowOop obj = (narrowOop)(*addr);
 235     oop string = oopDesc::decode_heap_oop(obj);
 236     if (java_lang_String::equals(string, (jchar*)name, len)) {
 237       return string;
 238     }
 239 
 240     return NULL;
 241   }
 242 
 243 public:
 244   CompactHashtable() {
 245     _entry_count = 0;
 246     _bucket_count = 0;
 247     _table_end_offset = 0;
 248     _buckets = 0;
 249   }
 250   const char* init(CompactHashtableType type, const char *buffer);
 251 
 252   void reset() {
 253     _entry_count = 0;
 254     _bucket_count = 0;
 255     _table_end_offset = 0;
 256     _buckets = 0;
 257   }
 258 
 259   // Lookup an entry from the compact table
 260   inline T lookup(const N* name, unsigned int hash, int len) {
 261     if (_entry_count > 0) {
 262       assert(!DumpSharedSpaces, "run-time only");
 263       int index = hash % _bucket_count;
 264       juint bucket_info = _buckets[index];
 265       juint bucket_offset = BUCKET_OFFSET(bucket_info);
 266       int   bucket_type = BUCKET_TYPE(bucket_info);
 267       juint* bucket = _buckets + bucket_offset;
 268       juint* bucket_end = _buckets;
 269 
 270       if (bucket_type == COMPACT_BUCKET_TYPE) {
 271         // the compact bucket has one entry with entry offset only
 272         T res = lookup_entry(this, &bucket[0], name, len);
 273         if (res != NULL) {
 274           return res;
 275         }
 276       } else {
 277         // This is a regular bucket, which has more than one
 278         // entries. Each entry is a pair of entry (hash, offset).
 279         // Seek until the end of the bucket.
 280         bucket_end += BUCKET_OFFSET(_buckets[index + 1]);
 281         while (bucket < bucket_end) {
 282           unsigned int h = (unsigned int)(bucket[0]);
 283           if (h == hash) {
 284             T res = lookup_entry(this, &bucket[1], name, len);
 285             if (res != NULL) {
 286               return res;
 287             }
 288           }
 289           bucket += 2;
 290         }
 291       }
 292     }
 293     return NULL;
 294   }
 295 
 296   // iterate over symbols
 297   void symbols_do(SymbolClosure *cl);
 298 
 299   // iterate over strings
 300   void oops_do(OopClosure* f);
 301 };
 302 
 303 ////////////////////////////////////////////////////////////////////////
 304 //
 305 // Read/Write the contents of a hashtable textual dump (created by
 306 // SymbolTable::dump and StringTable::dump).
 307 // Because the dump file may be big (hundred of MB in extreme cases),
 308 // we use mmap for fast access when reading it.
 309 //
 310 class HashtableTextDump VALUE_OBJ_CLASS_SPEC {
 311   int _fd;
 312   const char* _base;
 313   const char* _p;
 314   const char* _end;




  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  *
  23  */
  24 
  25 #ifndef SHARE_VM_CLASSFILE_COMPACTHASHTABLE_HPP
  26 #define SHARE_VM_CLASSFILE_COMPACTHASHTABLE_HPP
  27 
  28 #include "classfile/stringTable.hpp"
  29 #include "classfile/symbolTable.hpp"
  30 #include "memory/allocation.inline.hpp"

  31 #include "oops/symbol.hpp"
  32 #include "services/diagnosticCommand.hpp"
  33 #include "utilities/hashtable.hpp"
  34 
  35 class NumberSeq;
  36 
  37 // Stats for symbol tables in the CDS archive
  38 class CompactHashtableStats VALUE_OBJ_CLASS_SPEC {
  39 public:
  40   int hashentry_count;
  41   int hashentry_bytes;
  42   int bucket_count;
  43   int bucket_bytes;
  44 };
  45 
  46 /////////////////////////////////////////////////////////////////////////
  47 //
  48 // The compact hash table writer. Used at dump time for writing out
  49 // the compact table to the shared archive.
  50 //


 201 // dump time.
 202 //
 203 template <class T, class N> class CompactHashtable VALUE_OBJ_CLASS_SPEC {
 204   friend class VMStructs;
 205 
 206  public:
 207   enum CompactHashtableType {
 208     _symbol_table = 0,
 209     _string_table = 1
 210   };
 211 
 212 private:
 213   CompactHashtableType _type;
 214   uintx  _base_address;
 215   juint  _entry_count;
 216   juint  _bucket_count;
 217   juint  _table_end_offset;
 218   juint* _buckets;
 219 
 220   inline Symbol* lookup_entry(CompactHashtable<Symbol*, char>* const t,
 221                               juint* addr, const char* name, int len);








 222 
 223   inline oop lookup_entry(CompactHashtable<oop, char>* const t,
 224                           juint* addr, const char* name, int len);









 225 public:
 226   CompactHashtable() {
 227     _entry_count = 0;
 228     _bucket_count = 0;
 229     _table_end_offset = 0;
 230     _buckets = 0;
 231   }
 232   const char* init(CompactHashtableType type, const char *buffer);
 233 
 234   void reset() {
 235     _entry_count = 0;
 236     _bucket_count = 0;
 237     _table_end_offset = 0;
 238     _buckets = 0;
 239   }
 240 
 241   // Lookup an entry from the compact table
 242   inline T lookup(const N* name, unsigned int hash, int len);


































 243 
 244   // iterate over symbols
 245   void symbols_do(SymbolClosure *cl);
 246 
 247   // iterate over strings
 248   void oops_do(OopClosure* f);
 249 };
 250 
 251 ////////////////////////////////////////////////////////////////////////
 252 //
 253 // Read/Write the contents of a hashtable textual dump (created by
 254 // SymbolTable::dump and StringTable::dump).
 255 // Because the dump file may be big (hundred of MB in extreme cases),
 256 // we use mmap for fast access when reading it.
 257 //
 258 class HashtableTextDump VALUE_OBJ_CLASS_SPEC {
 259   int _fd;
 260   const char* _base;
 261   const char* _p;
 262   const char* _end;