< 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"
@@ -60,13 +61,26 @@
// If a chain gets to 32 something might be wrong
#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
+#if INCLUDE_CDS_JAVA_HEAP
+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);
+}
+
+static CompactHashtable<
+ const jchar*, oop,
+ read_string_from_compact_hashtable,
+ java_lang_String::equals
+> _shared_table;
+#endif
+
// --------------------------------------------------------------------------
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;
@@ -132,11 +146,11 @@
if (val_oop == NULL) {
// dead oop, mark this hash dead for cleaning
*is_dead = true;
return false;
}
- bool equals = java_lang_String::equals(val_oop, (jchar*)_str, _len);
+ bool equals = java_lang_String::equals(val_oop, _str, _len);
if (!equals) {
return false;
}
// Need to resolve weak handle and Handleize through possible safepoint.
_found = Handle(_thread, value->resolve());
@@ -234,11 +248,11 @@
int length;
jchar* chars = symbol->as_unicode(length);
return lookup(chars, length);
}
-oop StringTable::lookup(jchar* name, int len) {
+oop StringTable::lookup(const jchar* name, int len) {
unsigned int hash = java_lang_String::hash_code(name, len);
oop string = StringTable::the_table()->lookup_shared(name, len, hash);
if (string != NULL) {
return string;
}
@@ -261,11 +275,11 @@
oop get_res_oop() {
return _return();
}
};
-oop StringTable::do_lookup(jchar* name, int len, uintx hash) {
+oop StringTable::do_lookup(const jchar* name, int len, uintx hash) {
Thread* thread = Thread::current();
StringTableLookupJchar lookup(thread, hash, name, len);
StringTableGet stg(thread);
bool rehash_warning;
_local_table->get(thread, lookup, stg, &rehash_warning);
@@ -306,11 +320,11 @@
Handle string;
oop result = intern(string, chars, length, CHECK_NULL);
return result;
}
-oop StringTable::intern(Handle string_or_null_h, jchar* name, int len, TRAPS) {
+oop StringTable::intern(Handle string_or_null_h, const jchar* name, int len, TRAPS) {
// shared table always uses java_lang_String::hash_code
unsigned int hash = java_lang_String::hash_code(name, len);
oop found_string = StringTable::the_table()->lookup_shared(name, len, hash);
if (found_string != NULL) {
return found_string;
@@ -344,11 +358,11 @@
oop get_return() const {
return _return();
}
};
-oop StringTable::do_intern(Handle string_or_null_h, jchar* name,
+oop StringTable::do_intern(Handle string_or_null_h, const jchar* name,
int len, uintx hash, TRAPS) {
HandleMark hm(THREAD); // cleanup strings created
Handle string_h;
if (!string_or_null_h.is_null()) {
@@ -773,14 +787,14 @@
}
}
// Sharing
#if INCLUDE_CDS_JAVA_HEAP
-oop StringTable::lookup_shared(jchar* name, int len, unsigned int hash) {
+oop StringTable::lookup_shared(const 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 +817,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 +870,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 >