hotspot/src/share/vm/classfile/symbolTable.cpp
changeset 37995 92aec042a43b
parent 37248 11a660dbbb8e
child 39713 29ece76096cb
equal deleted inserted replaced
37994:1a816b464178 37995:92aec042a43b
   535       }
   535       }
   536     }
   536     }
   537   }
   537   }
   538 }
   538 }
   539 
   539 
   540 bool SymbolTable::copy_compact_table(char** top, char*end) {
   540 void SymbolTable::serialize(SerializeClosure* soc) {
   541 #if INCLUDE_CDS
   541 #if INCLUDE_CDS
   542   CompactHashtableWriter ch_table(CompactHashtable<Symbol*, char>::_symbol_table,
   542   _shared_table.reset();
   543                                   the_table()->number_of_entries(),
   543   if (soc->writing()) {
   544                                   &MetaspaceShared::stats()->symbol);
   544     int num_buckets = the_table()->number_of_entries() /
   545   if (*top + ch_table.get_required_bytes() > end) {
   545                             SharedSymbolTableBucketSize;
   546     // not enough space left
   546     CompactSymbolTableWriter writer(num_buckets,
   547     return false;
   547                                     &MetaspaceShared::stats()->symbol);
   548   }
   548     for (int i = 0; i < the_table()->table_size(); ++i) {
   549 
   549       HashtableEntry<Symbol*, mtSymbol>* p = the_table()->bucket(i);
   550   for (int i = 0; i < the_table()->table_size(); ++i) {
   550       for ( ; p != NULL; p = p->next()) {
   551     HashtableEntry<Symbol*, mtSymbol>* p = the_table()->bucket(i);
   551         Symbol* s = (Symbol*)(p->literal());
   552     for ( ; p != NULL; p = p->next()) {
       
   553       Symbol* s = (Symbol*)(p->literal());
       
   554       unsigned int fixed_hash =  hash_shared_symbol((char*)s->bytes(), s->utf8_length());
   552       unsigned int fixed_hash =  hash_shared_symbol((char*)s->bytes(), s->utf8_length());
   555       assert(fixed_hash == p->hash(), "must not rehash during dumping");
   553         assert(fixed_hash == p->hash(), "must not rehash during dumping");
   556       ch_table.add(fixed_hash, s);
   554         writer.add(fixed_hash, s);
   557     }
   555       }
   558   }
   556     }
   559 
   557 
   560   ch_table.dump(top, end);
   558     writer.dump(&_shared_table);
   561 
   559   }
   562   *top = (char*)align_ptr_up(*top, sizeof(void*));
   560 
       
   561   _shared_table.set_type(CompactHashtable<Symbol*, char>::_symbol_table);
       
   562   _shared_table.serialize(soc);
       
   563 
       
   564   if (soc->writing()) {
       
   565     // Verify table is correct
       
   566     Symbol* sym = vmSymbols::java_lang_Object();
       
   567     const char* name = (const char*)sym->bytes();
       
   568     int len = sym->utf8_length();
       
   569     unsigned int hash = hash_symbol(name, len);
       
   570     assert(sym == _shared_table.lookup(name, hash, len), "sanity");
       
   571 
       
   572     // Sanity. Make sure we don't use the shared table at dump time
       
   573     _shared_table.reset();
       
   574   }
   563 #endif
   575 #endif
   564   return true;
       
   565 }
       
   566 
       
   567 const char* SymbolTable::init_shared_table(const char* buffer) {
       
   568   const char* end = _shared_table.init(
       
   569           CompactHashtable<Symbol*, char>::_symbol_table, buffer);
       
   570   return (const char*)align_ptr_up(end, sizeof(void*));
       
   571 }
   576 }
   572 
   577 
   573 //---------------------------------------------------------------------------
   578 //---------------------------------------------------------------------------
   574 // Non-product code
   579 // Non-product code
   575 
   580