< prev index next >

src/hotspot/share/classfile/stringTable.cpp

Print this page


 802     return s;
 803   }
 804 
 805   oop new_s = NULL;
 806   typeArrayOop v = java_lang_String::value_no_keepalive(s);
 807   typeArrayOop new_v =
 808     (typeArrayOop)MetaspaceShared::archive_heap_object(v, THREAD);
 809   if (new_v == NULL) {
 810     return NULL;
 811   }
 812   new_s = MetaspaceShared::archive_heap_object(s, THREAD);
 813   if (new_s == NULL) {
 814     return NULL;
 815   }
 816 
 817   // adjust the pointer to the 'value' field in the new String oop
 818   java_lang_String::set_value_raw(new_s, new_v);
 819   return new_s;
 820 }
 821 
 822 class CompactStringTableWriter: public CompactHashtableWriter {
 823 public:
 824   CompactStringTableWriter(int num_entries, CompactHashtableStats* stats) :
 825     CompactHashtableWriter(num_entries, stats) {}
 826   void add(unsigned int hash, oop string) {
 827     CompactHashtableWriter::add(hash, CompressedOops::encode(string));
 828   }
 829 };
 830 
 831 struct CopyToArchive : StackObj {
 832   CompactStringTableWriter* _writer;
 833   CopyToArchive(CompactStringTableWriter* writer) : _writer(writer) {}
 834   bool operator()(WeakHandle<vm_string_table_data>* val) {
 835     oop s = val->peek();
 836     if (s == NULL) {
 837       return true;
 838     }
 839     unsigned int hash = java_lang_String::hash_code(s);
 840     if (hash == 0) {

 841       return true;
 842     }
 843 
 844     java_lang_String::set_hash(s, hash);
 845     oop new_s = StringTable::create_archived_string(s, Thread::current());
 846     if (new_s == NULL) {
 847       return true;
 848     }
 849 
 850     val->replace(new_s);
 851     // add to the compact table
 852     _writer->add(hash, new_s);
 853     return true;
 854   }
 855 };
 856 
 857 void StringTable::copy_shared_string_table(CompactStringTableWriter* writer) {
 858   assert(MetaspaceShared::is_heap_object_archiving_allowed(), "must be");
 859 
 860   CopyToArchive copy(writer);
 861   StringTable::the_table()->_local_table->do_scan(Thread::current(), copy);
 862 }
 863 
 864 void StringTable::write_to_archive() {
 865   assert(MetaspaceShared::is_heap_object_archiving_allowed(), "must be");
 866 
 867   _shared_table.reset();
 868   int num_buckets = the_table()->_items_count / SharedSymbolTableBucketSize;
 869   // calculation of num_buckets can result in zero buckets, we need at least one
 870   CompactStringTableWriter writer(num_buckets > 1 ? num_buckets : 1,
 871                                   &MetaspaceShared::stats()->string);
 872 
 873   // Copy the interned strings into the "string space" within the java heap
 874   copy_shared_string_table(&writer);
 875   writer.dump(&_shared_table, "string");
 876 }
 877 
 878 void StringTable::serialize(SerializeClosure* soc) {
 879   _shared_table.serialize(soc);
 880 
 881   if (soc->writing()) {
 882     // Sanity. Make sure we don't use the shared table at dump time
 883     _shared_table.reset();
 884   } else if (!_shared_string_mapped) {
 885     _shared_table.reset();
 886   }
 887 }
 888 
 889 class SharedStringIterator {
 890   OopClosure* _oop_closure;


 802     return s;
 803   }
 804 
 805   oop new_s = NULL;
 806   typeArrayOop v = java_lang_String::value_no_keepalive(s);
 807   typeArrayOop new_v =
 808     (typeArrayOop)MetaspaceShared::archive_heap_object(v, THREAD);
 809   if (new_v == NULL) {
 810     return NULL;
 811   }
 812   new_s = MetaspaceShared::archive_heap_object(s, THREAD);
 813   if (new_s == NULL) {
 814     return NULL;
 815   }
 816 
 817   // adjust the pointer to the 'value' field in the new String oop
 818   java_lang_String::set_value_raw(new_s, new_v);
 819   return new_s;
 820 }
 821 









 822 struct CopyToArchive : StackObj {
 823   CompactHashtableWriter* _writer;
 824   CopyToArchive(CompactHashtableWriter* writer) : _writer(writer) {}
 825   bool operator()(WeakHandle<vm_string_table_data>* val) {
 826     oop s = val->peek();
 827     if (s == NULL) {
 828       return true;
 829     }
 830     unsigned int hash = java_lang_String::hash_code(s);
 831     if (hash == 0) {
 832       // We do not archive Strings with a 0 hashcode because ......
 833       return true;
 834     }
 835 
 836     java_lang_String::set_hash(s, hash);
 837     oop new_s = StringTable::create_archived_string(s, Thread::current());
 838     if (new_s == NULL) {
 839       return true;
 840     }
 841 
 842     val->replace(new_s);
 843     // add to the compact table
 844     _writer->add(hash, CompressedOops::encode(new_s));
 845     return true;
 846   }
 847 };
 848 
 849 void StringTable::copy_shared_string_table(CompactHashtableWriter* writer) {
 850   assert(MetaspaceShared::is_heap_object_archiving_allowed(), "must be");
 851 
 852   CopyToArchive copy(writer);
 853   StringTable::the_table()->_local_table->do_scan(Thread::current(), copy);
 854 }
 855 
 856 void StringTable::write_to_archive() {
 857   assert(MetaspaceShared::is_heap_object_archiving_allowed(), "must be");
 858 
 859   _shared_table.reset();
 860   int num_buckets = CompactHashtableWriter::default_num_buckets(
 861       StringTable::the_table()->_items_count);
 862   CompactHashtableWriter writer(num_buckets,
 863                                 &MetaspaceShared::stats()->string);
 864 
 865   // Copy the interned strings into the "string space" within the java heap
 866   copy_shared_string_table(&writer);
 867   writer.dump(&_shared_table, "string");
 868 }
 869 
 870 void StringTable::serialize(SerializeClosure* soc) {
 871   _shared_table.serialize(soc);
 872 
 873   if (soc->writing()) {
 874     // Sanity. Make sure we don't use the shared table at dump time
 875     _shared_table.reset();
 876   } else if (!_shared_string_mapped) {
 877     _shared_table.reset();
 878   }
 879 }
 880 
 881 class SharedStringIterator {
 882   OopClosure* _oop_closure;
< prev index next >