< prev index next >

src/hotspot/share/classfile/stringTable.cpp

Print this page

@@ -22,21 +22,22 @@
  *
  */
 
 #include "precompiled.hpp"
 #include "classfile/altHashing.hpp"
-#include "classfile/compactHashtable.inline.hpp"
+#include "classfile/compactHashtable.hpp"
 #include "classfile/javaClasses.inline.hpp"
 #include "classfile/stringTable.hpp"
 #include "classfile/systemDictionary.hpp"
 #include "gc/shared/collectedHeap.hpp"
 #include "gc/shared/oopStorage.inline.hpp"
 #include "gc/shared/oopStorageParState.inline.hpp"
 #include "logging/log.hpp"
 #include "logging/logStream.hpp"
 #include "memory/allocation.inline.hpp"
 #include "memory/filemap.hpp"
+#include "memory/heapShared.inline.hpp"
 #include "memory/metaspaceShared.inline.hpp"
 #include "memory/resourceArea.hpp"
 #include "memory/universe.hpp"
 #include "oops/access.inline.hpp"
 #include "oops/oop.inline.hpp"

@@ -61,12 +62,28 @@
 #define REHASH_LEN         32
 // If we have as many dead items as 50% of the number of bucket
 #define CLEAN_DEAD_HIGH_WATER_MARK 0.5
 
 // --------------------------------------------------------------------------
+inline oop read_string_from_compact_hashtable(address base_address, u4 offset) {
+  assert(sizeof(narrowOop) == sizeof(offset), "must be");
+  narrowOop v = (narrowOop)offset;
+  return HeapShared::decode_from_archive(v);
+}
+
+inline bool string_equals_compact_hashtable_entry(oop value, const jchar* key, int len) {
+  return java_lang_String::equals(value, (jchar*)key, len);
+}
+
+static CompactHashtable<
+  const jchar*, oop,
+  read_string_from_compact_hashtable,
+  string_equals_compact_hashtable_entry
+> _shared_table;
+
+// --------------------------------------------------------------------------
 StringTable* StringTable::_the_table = NULL;
-CompactHashtable<oop, char> StringTable::_shared_table;
 volatile bool StringTable::_shared_string_mapped = false;
 volatile bool StringTable::_alt_hash = false;
 
 static juint murmur_seed = 0;
 

@@ -776,11 +793,11 @@
 // Sharing
 #if INCLUDE_CDS_JAVA_HEAP
 oop StringTable::lookup_shared(jchar* name, int len, unsigned int hash) {
   assert(hash == java_lang_String::hash_code(name, len),
          "hash must be computed using java_lang_String::hash_code");
-  return _shared_table.lookup((const char*)name, hash, len);
+  return _shared_table.lookup(name, hash, len);
 }
 
 oop StringTable::create_archived_string(oop s, Thread* THREAD) {
   assert(DumpSharedSpaces, "this function is only used with -Xshare:dump");
 

@@ -803,10 +820,19 @@
   // adjust the pointer to the 'value' field in the new String oop
   java_lang_String::set_value_raw(new_s, new_v);
   return new_s;
 }
 
+class CompactStringTableWriter: public CompactHashtableWriter {
+public:
+  CompactStringTableWriter(int num_entries, CompactHashtableStats* stats) :
+    CompactHashtableWriter(num_entries, stats) {}
+  void add(unsigned int hash, oop string) {
+    CompactHashtableWriter::add(hash, CompressedOops::encode(string));
+  }
+};
+
 struct CopyToArchive : StackObj {
   CompactStringTableWriter* _writer;
   CopyToArchive(CompactStringTableWriter* writer) : _writer(writer) {}
   bool operator()(WeakHandle<vm_string_table_data>* val) {
     oop s = val->peek();

@@ -847,24 +873,33 @@
   CompactStringTableWriter writer(num_buckets > 1 ? num_buckets : 1,
                                   &MetaspaceShared::stats()->string);
 
   // Copy the interned strings into the "string space" within the java heap
   copy_shared_string_table(&writer);
-  writer.dump(&_shared_table);
+  writer.dump(&_shared_table, "string");
 }
 
 void StringTable::serialize(SerializeClosure* soc) {
-  _shared_table.set_type(CompactHashtable<oop, char>::_string_table);
   _shared_table.serialize(soc);
 
   if (soc->writing()) {
     // Sanity. Make sure we don't use the shared table at dump time
     _shared_table.reset();
   } else if (!_shared_string_mapped) {
     _shared_table.reset();
   }
 }
 
+class SharedStringIterator {
+  OopClosure* _oop_closure;
+public:
+  SharedStringIterator(OopClosure* f) : _oop_closure(f) {}
+  void do_value(oop string) {
+    _oop_closure->do_oop(&string);
+  }
+};
+
 void StringTable::shared_oops_do(OopClosure* f) {
-  _shared_table.oops_do(f);
+  SharedStringIterator iter(f);
+  _shared_table.iterate(&iter);
 }
 #endif //INCLUDE_CDS_JAVA_HEAP
< prev index next >