2014-05-07 14:16:45 -05:00
|
|
|
/*
|
2020-08-27 22:24:28 -07:00
|
|
|
* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
|
2014-05-07 14:16:45 -05:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
|
|
*
|
|
|
|
* This code is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License version 2 only, as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* version 2 for more details (a copy is included in the LICENSE file that
|
|
|
|
* accompanied this code).
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License version
|
|
|
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
|
|
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
|
|
* or visit www.oracle.com if you need additional information or have any
|
|
|
|
* questions.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "precompiled.hpp"
|
|
|
|
#include "classfile/altHashing.hpp"
|
2018-09-18 21:47:14 -07:00
|
|
|
#include "classfile/compactHashtable.hpp"
|
2016-01-04 15:41:05 +01:00
|
|
|
#include "classfile/javaClasses.inline.hpp"
|
2014-05-07 14:16:45 -05:00
|
|
|
#include "classfile/stringTable.hpp"
|
|
|
|
#include "classfile/systemDictionary.hpp"
|
2018-05-07 14:57:25 +02:00
|
|
|
#include "gc/shared/collectedHeap.hpp"
|
2018-06-07 14:11:56 +02:00
|
|
|
#include "gc/shared/oopStorage.inline.hpp"
|
2019-08-21 18:42:30 -04:00
|
|
|
#include "gc/shared/oopStorageSet.hpp"
|
2017-06-05 13:13:38 -04:00
|
|
|
#include "logging/log.hpp"
|
2018-06-07 14:11:56 +02:00
|
|
|
#include "logging/logStream.hpp"
|
2014-05-07 14:16:45 -05:00
|
|
|
#include "memory/allocation.inline.hpp"
|
|
|
|
#include "memory/filemap.hpp"
|
2018-09-18 21:47:14 -07:00
|
|
|
#include "memory/heapShared.inline.hpp"
|
2016-04-04 12:57:48 -04:00
|
|
|
#include "memory/resourceArea.hpp"
|
2018-05-07 14:57:25 +02:00
|
|
|
#include "memory/universe.hpp"
|
2018-01-08 16:21:23 +01:00
|
|
|
#include "oops/access.inline.hpp"
|
2019-05-09 14:26:03 +02:00
|
|
|
#include "oops/compressedOops.hpp"
|
2014-05-07 14:16:45 -05:00
|
|
|
#include "oops/oop.inline.hpp"
|
2018-02-22 10:39:42 +01:00
|
|
|
#include "oops/typeArrayOop.inline.hpp"
|
2018-06-07 14:11:56 +02:00
|
|
|
#include "oops/weakHandle.inline.hpp"
|
2016-08-21 20:56:37 -04:00
|
|
|
#include "runtime/atomic.hpp"
|
2018-03-14 12:12:00 +01:00
|
|
|
#include "runtime/handles.inline.hpp"
|
2014-05-07 14:16:45 -05:00
|
|
|
#include "runtime/mutexLocker.hpp"
|
2018-03-23 18:54:12 +01:00
|
|
|
#include "runtime/safepointVerifiers.hpp"
|
2018-06-07 14:11:56 +02:00
|
|
|
#include "runtime/timerTrace.hpp"
|
|
|
|
#include "runtime/interfaceSupport.inline.hpp"
|
2017-08-02 10:52:50 -04:00
|
|
|
#include "services/diagnosticCommand.hpp"
|
2018-06-07 14:11:56 +02:00
|
|
|
#include "utilities/concurrentHashTable.inline.hpp"
|
|
|
|
#include "utilities/concurrentHashTableTasks.inline.hpp"
|
2014-11-12 12:41:59 +01:00
|
|
|
#include "utilities/macros.hpp"
|
2019-03-30 08:26:20 -07:00
|
|
|
#include "utilities/utf8.hpp"
|
2014-05-07 14:16:45 -05:00
|
|
|
|
2018-06-07 14:11:56 +02:00
|
|
|
// We prefer short chains of avg 2
|
2018-12-10 11:59:55 -06:00
|
|
|
const double PREF_AVG_LIST_LEN = 2.0;
|
2018-06-07 14:11:56 +02:00
|
|
|
// 2^24 is max size
|
2018-12-10 11:59:55 -06:00
|
|
|
const size_t END_SIZE = 24;
|
2019-06-11 07:31:47 -04:00
|
|
|
// If a chain gets to 100 something might be wrong
|
|
|
|
const size_t REHASH_LEN = 100;
|
2018-06-07 14:11:56 +02:00
|
|
|
// If we have as many dead items as 50% of the number of bucket
|
2018-12-10 11:59:55 -06:00
|
|
|
const double CLEAN_DEAD_HIGH_WATER_MARK = 0.5;
|
2014-05-07 14:16:45 -05:00
|
|
|
|
2018-09-18 21:47:14 -07:00
|
|
|
#if INCLUDE_CDS_JAVA_HEAP
|
|
|
|
inline oop read_string_from_compact_hashtable(address base_address, u4 offset) {
|
|
|
|
assert(sizeof(narrowOop) == sizeof(offset), "must be");
|
2020-10-01 10:45:22 +00:00
|
|
|
narrowOop v = CompressedOops::narrow_oop_cast(offset);
|
2018-09-18 21:47:14 -07:00
|
|
|
return HeapShared::decode_from_archive(v);
|
|
|
|
}
|
|
|
|
|
|
|
|
static CompactHashtable<
|
|
|
|
const jchar*, oop,
|
|
|
|
read_string_from_compact_hashtable,
|
|
|
|
java_lang_String::equals
|
|
|
|
> _shared_table;
|
|
|
|
#endif
|
|
|
|
|
2018-06-07 14:11:56 +02:00
|
|
|
// --------------------------------------------------------------------------
|
2014-05-07 14:16:45 -05:00
|
|
|
|
2019-06-24 16:51:23 -04:00
|
|
|
typedef ConcurrentHashTable<StringTableConfig, mtSymbol> StringTableHash;
|
2019-05-16 07:09:17 -04:00
|
|
|
static StringTableHash* _local_table = NULL;
|
|
|
|
|
|
|
|
volatile bool StringTable::_has_work = false;
|
|
|
|
volatile bool StringTable::_needs_rehashing = false;
|
2020-07-16 17:41:14 -04:00
|
|
|
OopStorage* StringTable::_oop_storage;
|
2019-05-16 07:09:17 -04:00
|
|
|
|
|
|
|
static size_t _current_size = 0;
|
|
|
|
static volatile size_t _items_count = 0;
|
|
|
|
|
|
|
|
volatile bool _alt_hash = false;
|
2018-06-07 14:11:56 +02:00
|
|
|
static juint murmur_seed = 0;
|
2014-05-07 14:16:45 -05:00
|
|
|
|
2018-06-07 14:11:56 +02:00
|
|
|
uintx hash_string(const jchar* s, int len, bool useAlt) {
|
|
|
|
return useAlt ?
|
|
|
|
AltHashing::murmur3_32(murmur_seed, s, len) :
|
|
|
|
java_lang_String::hash_code(s, len);
|
|
|
|
}
|
2014-05-07 14:16:45 -05:00
|
|
|
|
2019-06-24 16:51:23 -04:00
|
|
|
class StringTableConfig : public StackObj {
|
2018-06-07 14:11:56 +02:00
|
|
|
private:
|
2014-05-07 14:16:45 -05:00
|
|
|
public:
|
2020-06-23 09:38:21 +02:00
|
|
|
typedef WeakHandle Value;
|
2019-06-24 16:51:23 -04:00
|
|
|
|
|
|
|
static uintx get_hash(Value const& value, bool* is_dead) {
|
2018-06-07 14:11:56 +02:00
|
|
|
EXCEPTION_MARK;
|
|
|
|
oop val_oop = value.peek();
|
|
|
|
if (val_oop == NULL) {
|
|
|
|
*is_dead = true;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
*is_dead = false;
|
|
|
|
ResourceMark rm(THREAD);
|
|
|
|
// All String oops are hashed as unicode
|
|
|
|
int length;
|
|
|
|
jchar* chars = java_lang_String::as_unicode_string(val_oop, length, THREAD);
|
|
|
|
if (chars != NULL) {
|
2019-05-16 07:09:17 -04:00
|
|
|
return hash_string(chars, length, _alt_hash);
|
2018-06-07 14:11:56 +02:00
|
|
|
}
|
|
|
|
vm_exit_out_of_memory(length, OOM_MALLOC_ERROR, "get hash from oop");
|
|
|
|
return 0;
|
2014-05-07 14:16:45 -05:00
|
|
|
}
|
2018-06-07 14:11:56 +02:00
|
|
|
// We use default allocation/deallocation but counted
|
2019-06-24 16:51:23 -04:00
|
|
|
static void* allocate_node(size_t size, Value const& value) {
|
2018-06-07 14:11:56 +02:00
|
|
|
StringTable::item_added();
|
2019-06-24 16:51:23 -04:00
|
|
|
return AllocateHeap(size, mtSymbol);
|
2018-06-07 14:11:56 +02:00
|
|
|
}
|
2019-06-24 16:51:23 -04:00
|
|
|
static void free_node(void* memory, Value const& value) {
|
2020-07-16 17:41:14 -04:00
|
|
|
value.release(StringTable::_oop_storage);
|
2019-06-24 16:51:23 -04:00
|
|
|
FreeHeap(memory);
|
2018-06-07 14:11:56 +02:00
|
|
|
StringTable::item_removed();
|
2014-05-07 14:16:45 -05:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-06-07 14:11:56 +02:00
|
|
|
class StringTableLookupJchar : StackObj {
|
|
|
|
private:
|
|
|
|
Thread* _thread;
|
|
|
|
uintx _hash;
|
|
|
|
int _len;
|
|
|
|
const jchar* _str;
|
|
|
|
Handle _found;
|
2014-05-07 14:16:45 -05:00
|
|
|
|
2018-06-07 14:11:56 +02:00
|
|
|
public:
|
|
|
|
StringTableLookupJchar(Thread* thread, uintx hash, const jchar* key, int len)
|
2018-08-08 15:31:07 +02:00
|
|
|
: _thread(thread), _hash(hash), _len(len), _str(key) {
|
2018-06-07 14:11:56 +02:00
|
|
|
}
|
|
|
|
uintx get_hash() const {
|
|
|
|
return _hash;
|
|
|
|
}
|
2020-06-23 09:38:21 +02:00
|
|
|
bool equals(WeakHandle* value, bool* is_dead) {
|
2018-06-07 14:11:56 +02:00
|
|
|
oop val_oop = value->peek();
|
|
|
|
if (val_oop == NULL) {
|
|
|
|
// dead oop, mark this hash dead for cleaning
|
|
|
|
*is_dead = true;
|
|
|
|
return false;
|
|
|
|
}
|
2018-09-18 21:47:14 -07:00
|
|
|
bool equals = java_lang_String::equals(val_oop, _str, _len);
|
2018-06-07 14:11:56 +02:00
|
|
|
if (!equals) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// Need to resolve weak handle and Handleize through possible safepoint.
|
|
|
|
_found = Handle(_thread, value->resolve());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
2014-05-07 14:16:45 -05:00
|
|
|
|
2018-06-07 14:11:56 +02:00
|
|
|
class StringTableLookupOop : public StackObj {
|
|
|
|
private:
|
|
|
|
Thread* _thread;
|
|
|
|
uintx _hash;
|
|
|
|
Handle _find;
|
|
|
|
Handle _found; // Might be a different oop with the same value that's already
|
|
|
|
// in the table, which is the point.
|
|
|
|
public:
|
|
|
|
StringTableLookupOop(Thread* thread, uintx hash, Handle handle)
|
|
|
|
: _thread(thread), _hash(hash), _find(handle) { }
|
2014-05-07 14:16:45 -05:00
|
|
|
|
2018-06-07 14:11:56 +02:00
|
|
|
uintx get_hash() const {
|
|
|
|
return _hash;
|
|
|
|
}
|
2015-06-12 17:29:14 -04:00
|
|
|
|
2020-06-23 09:38:21 +02:00
|
|
|
bool equals(WeakHandle* value, bool* is_dead) {
|
2018-06-07 14:11:56 +02:00
|
|
|
oop val_oop = value->peek();
|
|
|
|
if (val_oop == NULL) {
|
|
|
|
// dead oop, mark this hash dead for cleaning
|
|
|
|
*is_dead = true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
bool equals = java_lang_String::equals(_find(), val_oop);
|
|
|
|
if (!equals) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// Need to resolve weak handle and Handleize through possible safepoint.
|
|
|
|
_found = Handle(_thread, value->resolve());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
2014-05-07 14:16:45 -05:00
|
|
|
|
2018-08-14 18:42:14 -05:00
|
|
|
static size_t ceil_log2(size_t val) {
|
2018-06-07 14:11:56 +02:00
|
|
|
size_t ret;
|
|
|
|
for (ret = 1; ((size_t)1 << ret) < val; ++ret);
|
|
|
|
return ret;
|
2017-03-15 13:03:13 +01:00
|
|
|
}
|
|
|
|
|
2019-05-16 07:09:17 -04:00
|
|
|
void StringTable::create_table() {
|
2018-08-14 18:42:14 -05:00
|
|
|
size_t start_size_log_2 = ceil_log2(StringTableSize);
|
2018-06-07 14:11:56 +02:00
|
|
|
_current_size = ((size_t)1) << start_size_log_2;
|
|
|
|
log_trace(stringtable)("Start size: " SIZE_FORMAT " (" SIZE_FORMAT ")",
|
|
|
|
_current_size, start_size_log_2);
|
|
|
|
_local_table = new StringTableHash(start_size_log_2, END_SIZE, REHASH_LEN);
|
2020-07-16 17:41:14 -04:00
|
|
|
_oop_storage = OopStorageSet::create_weak("StringTable Weak");
|
|
|
|
_oop_storage->register_num_dead_callback(&gc_notification);
|
2016-03-22 13:32:18 -04:00
|
|
|
}
|
8141132: JEP 254: Compact Strings
Adopt a more space-efficient internal representation for strings.
Co-authored-by: Brent Christian <brent.christian@oracle.com>
Co-authored-by: Vivek Deshpande <vivek.r.deshpande@intel.com>
Co-authored-by: Charlie Hunt <charlie.hunt@oracle.com>
Co-authored-by: Vladimir Kozlov <vladimir.kozlov@oracle.com>
Co-authored-by: Roger Riggs <roger.riggs@oracle.com>
Co-authored-by: Xueming Shen <xueming.shen@oracle.com>
Co-authored-by: Aleksey Shipilev <aleksey.shipilev@oracle.com>
Co-authored-by: Sandhya Viswanathan <sandhya.viswanathan@intel.com>
Reviewed-by: alanb, bdelsart, coleenp, iklam, jiangli, jrose, kevinw, naoto, pliden, roland, smarks, twisti
2015-11-03 09:41:03 +01:00
|
|
|
|
2018-06-07 14:11:56 +02:00
|
|
|
size_t StringTable::item_added() {
|
2019-11-25 12:31:39 +01:00
|
|
|
return Atomic::add(&_items_count, (size_t)1);
|
2018-01-08 16:21:23 +01:00
|
|
|
}
|
|
|
|
|
2018-06-07 14:11:56 +02:00
|
|
|
void StringTable::item_removed() {
|
2019-11-25 12:31:39 +01:00
|
|
|
Atomic::add(&_items_count, (size_t)-1);
|
2018-01-08 16:21:23 +01:00
|
|
|
}
|
|
|
|
|
2019-05-16 07:09:17 -04:00
|
|
|
double StringTable::get_load_factor() {
|
2020-07-16 17:41:14 -04:00
|
|
|
return double(_items_count)/double(_current_size);
|
2015-06-12 17:29:14 -04:00
|
|
|
}
|
|
|
|
|
2020-07-16 17:41:14 -04:00
|
|
|
double StringTable::get_dead_factor(size_t num_dead) {
|
|
|
|
return double(num_dead)/double(_current_size);
|
2014-05-07 14:16:45 -05:00
|
|
|
}
|
|
|
|
|
2018-08-14 18:42:14 -05:00
|
|
|
size_t StringTable::table_size() {
|
|
|
|
return ((size_t)1) << _local_table->get_size_log2(Thread::current());
|
2014-05-07 14:16:45 -05:00
|
|
|
}
|
|
|
|
|
2018-06-07 14:11:56 +02:00
|
|
|
void StringTable::trigger_concurrent_work() {
|
2019-04-25 10:56:31 -04:00
|
|
|
MutexLocker ml(Service_lock, Mutex::_no_safepoint_check_flag);
|
2020-07-16 17:41:14 -04:00
|
|
|
Atomic::store(&_has_work, true);
|
2018-06-07 14:11:56 +02:00
|
|
|
Service_lock->notify_all();
|
|
|
|
}
|
2014-05-07 14:16:45 -05:00
|
|
|
|
2018-06-07 14:11:56 +02:00
|
|
|
// Probing
|
2014-05-07 14:16:45 -05:00
|
|
|
oop StringTable::lookup(Symbol* symbol) {
|
|
|
|
ResourceMark rm;
|
|
|
|
int length;
|
|
|
|
jchar* chars = symbol->as_unicode(length);
|
|
|
|
return lookup(chars, length);
|
|
|
|
}
|
|
|
|
|
2018-09-18 21:47:14 -07:00
|
|
|
oop StringTable::lookup(const jchar* name, int len) {
|
2017-03-15 13:03:13 +01:00
|
|
|
unsigned int hash = java_lang_String::hash_code(name, len);
|
2019-05-16 07:09:17 -04:00
|
|
|
oop string = lookup_shared(name, len, hash);
|
2015-06-12 17:29:14 -04:00
|
|
|
if (string != NULL) {
|
|
|
|
return string;
|
|
|
|
}
|
2019-05-16 07:09:17 -04:00
|
|
|
if (_alt_hash) {
|
2018-06-07 14:11:56 +02:00
|
|
|
hash = hash_string(name, len, true);
|
2017-03-15 13:03:13 +01:00
|
|
|
}
|
2019-05-16 07:09:17 -04:00
|
|
|
return do_lookup(name, len, hash);
|
2014-05-07 14:16:45 -05:00
|
|
|
}
|
|
|
|
|
2018-06-07 14:11:56 +02:00
|
|
|
class StringTableGet : public StackObj {
|
|
|
|
Thread* _thread;
|
|
|
|
Handle _return;
|
|
|
|
public:
|
|
|
|
StringTableGet(Thread* thread) : _thread(thread) {}
|
2020-06-23 09:38:21 +02:00
|
|
|
void operator()(WeakHandle* val) {
|
2018-06-07 14:11:56 +02:00
|
|
|
oop result = val->resolve();
|
|
|
|
assert(result != NULL, "Result should be reachable");
|
|
|
|
_return = Handle(_thread, result);
|
2014-07-07 10:12:40 +02:00
|
|
|
}
|
2018-06-07 14:11:56 +02:00
|
|
|
oop get_res_oop() {
|
|
|
|
return _return();
|
2014-05-07 14:16:45 -05:00
|
|
|
}
|
2018-06-07 14:11:56 +02:00
|
|
|
};
|
2014-05-07 14:16:45 -05:00
|
|
|
|
2018-09-18 21:47:14 -07:00
|
|
|
oop StringTable::do_lookup(const jchar* name, int len, uintx hash) {
|
2018-06-07 14:11:56 +02:00
|
|
|
Thread* thread = Thread::current();
|
|
|
|
StringTableLookupJchar lookup(thread, hash, name, len);
|
|
|
|
StringTableGet stg(thread);
|
|
|
|
bool rehash_warning;
|
|
|
|
_local_table->get(thread, lookup, stg, &rehash_warning);
|
2018-11-28 11:06:27 +01:00
|
|
|
update_needs_rehash(rehash_warning);
|
2018-06-07 14:11:56 +02:00
|
|
|
return stg.get_res_oop();
|
2014-05-07 14:16:45 -05:00
|
|
|
}
|
|
|
|
|
2018-06-07 14:11:56 +02:00
|
|
|
// Interning
|
2014-05-07 14:16:45 -05:00
|
|
|
oop StringTable::intern(Symbol* symbol, TRAPS) {
|
|
|
|
if (symbol == NULL) return NULL;
|
|
|
|
ResourceMark rm(THREAD);
|
|
|
|
int length;
|
|
|
|
jchar* chars = symbol->as_unicode(length);
|
|
|
|
Handle string;
|
|
|
|
oop result = intern(string, chars, length, CHECK_NULL);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-06-07 14:11:56 +02:00
|
|
|
oop StringTable::intern(oop string, TRAPS) {
|
2014-05-07 14:16:45 -05:00
|
|
|
if (string == NULL) return NULL;
|
|
|
|
ResourceMark rm(THREAD);
|
|
|
|
int length;
|
|
|
|
Handle h_string (THREAD, string);
|
2018-06-07 14:11:56 +02:00
|
|
|
jchar* chars = java_lang_String::as_unicode_string(string, length,
|
|
|
|
CHECK_NULL);
|
2014-05-07 14:16:45 -05:00
|
|
|
oop result = intern(h_string, chars, length, CHECK_NULL);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
oop StringTable::intern(const char* utf8_string, TRAPS) {
|
|
|
|
if (utf8_string == NULL) return NULL;
|
|
|
|
ResourceMark rm(THREAD);
|
|
|
|
int length = UTF8::unicode_length(utf8_string);
|
|
|
|
jchar* chars = NEW_RESOURCE_ARRAY(jchar, length);
|
|
|
|
UTF8::convert_to_unicode(utf8_string, chars, length);
|
|
|
|
Handle string;
|
|
|
|
oop result = intern(string, chars, length, CHECK_NULL);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-09-18 21:47:14 -07:00
|
|
|
oop StringTable::intern(Handle string_or_null_h, const jchar* name, int len, TRAPS) {
|
2018-06-07 14:11:56 +02:00
|
|
|
// shared table always uses java_lang_String::hash_code
|
|
|
|
unsigned int hash = java_lang_String::hash_code(name, len);
|
2019-05-16 07:09:17 -04:00
|
|
|
oop found_string = lookup_shared(name, len, hash);
|
2018-06-07 14:11:56 +02:00
|
|
|
if (found_string != NULL) {
|
|
|
|
return found_string;
|
|
|
|
}
|
2019-05-16 07:09:17 -04:00
|
|
|
if (_alt_hash) {
|
2018-06-07 14:11:56 +02:00
|
|
|
hash = hash_string(name, len, true);
|
|
|
|
}
|
2019-05-16 07:09:17 -04:00
|
|
|
found_string = do_lookup(name, len, hash);
|
2019-02-16 21:15:33 +01:00
|
|
|
if (found_string != NULL) {
|
|
|
|
return found_string;
|
|
|
|
}
|
2019-07-18 07:06:33 -04:00
|
|
|
return do_intern(string_or_null_h, name, len, hash, THREAD);
|
2014-05-07 14:16:45 -05:00
|
|
|
}
|
|
|
|
|
2018-09-18 21:47:14 -07:00
|
|
|
oop StringTable::do_intern(Handle string_or_null_h, const jchar* name,
|
2018-06-07 14:11:56 +02:00
|
|
|
int len, uintx hash, TRAPS) {
|
|
|
|
HandleMark hm(THREAD); // cleanup strings created
|
|
|
|
Handle string_h;
|
2014-05-07 14:16:45 -05:00
|
|
|
|
2018-06-07 14:11:56 +02:00
|
|
|
if (!string_or_null_h.is_null()) {
|
|
|
|
string_h = string_or_null_h;
|
|
|
|
} else {
|
|
|
|
string_h = java_lang_String::create_from_unicode(name, len, CHECK_NULL);
|
|
|
|
}
|
2014-05-07 14:16:45 -05:00
|
|
|
|
2018-06-07 14:11:56 +02:00
|
|
|
// Deduplicate the string before it is interned. Note that we should never
|
|
|
|
// deduplicate a string after it has been interned. Doing so will counteract
|
|
|
|
// compiler optimizations done on e.g. interned string literals.
|
|
|
|
Universe::heap()->deduplicate_string(string_h());
|
2014-05-07 14:16:45 -05:00
|
|
|
|
2018-06-07 14:11:56 +02:00
|
|
|
assert(java_lang_String::equals(string_h(), name, len),
|
|
|
|
"string must be properly initialized");
|
|
|
|
assert(len == java_lang_String::length(string_h()), "Must be same length");
|
2018-11-28 11:06:27 +01:00
|
|
|
|
2018-06-07 14:11:56 +02:00
|
|
|
StringTableLookupOop lookup(THREAD, hash, string_h);
|
2018-11-28 11:06:27 +01:00
|
|
|
StringTableGet stg(THREAD);
|
2014-05-07 14:16:45 -05:00
|
|
|
|
2018-06-07 14:11:56 +02:00
|
|
|
bool rehash_warning;
|
2018-11-28 11:06:27 +01:00
|
|
|
do {
|
2019-05-20 10:06:07 -04:00
|
|
|
// Callers have already looked up the String using the jchar* name, so just go to add.
|
2020-07-16 17:41:14 -04:00
|
|
|
WeakHandle wh(_oop_storage, string_h);
|
2018-11-28 11:06:27 +01:00
|
|
|
// The hash table takes ownership of the WeakHandle, even if it's not inserted.
|
|
|
|
if (_local_table->insert(THREAD, lookup, wh, &rehash_warning)) {
|
|
|
|
update_needs_rehash(rehash_warning);
|
|
|
|
return wh.resolve();
|
|
|
|
}
|
2019-05-20 10:06:07 -04:00
|
|
|
// In case another thread did a concurrent add, return value already in the table.
|
|
|
|
// This could fail if the String got gc'ed concurrently, so loop back until success.
|
|
|
|
if (_local_table->get(THREAD, lookup, stg, &rehash_warning)) {
|
|
|
|
update_needs_rehash(rehash_warning);
|
|
|
|
return stg.get_res_oop();
|
|
|
|
}
|
2018-11-28 11:06:27 +01:00
|
|
|
} while(true);
|
2014-05-07 14:16:45 -05:00
|
|
|
}
|
|
|
|
|
2018-06-07 14:11:56 +02:00
|
|
|
// Concurrent work
|
|
|
|
void StringTable::grow(JavaThread* jt) {
|
|
|
|
StringTableHash::GrowTask gt(_local_table);
|
|
|
|
if (!gt.prepare(jt)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
log_trace(stringtable)("Started to grow");
|
|
|
|
{
|
|
|
|
TraceTime timer("Grow", TRACETIME_LOG(Debug, stringtable, perf));
|
2018-06-18 16:13:21 +02:00
|
|
|
while (gt.do_task(jt)) {
|
2018-06-07 14:11:56 +02:00
|
|
|
gt.pause(jt);
|
|
|
|
{
|
|
|
|
ThreadBlockInVM tbivm(jt);
|
|
|
|
}
|
|
|
|
gt.cont(jt);
|
2014-05-07 14:16:45 -05:00
|
|
|
}
|
|
|
|
}
|
2018-06-07 14:11:56 +02:00
|
|
|
gt.done(jt);
|
2018-08-14 18:42:14 -05:00
|
|
|
_current_size = table_size();
|
2018-06-07 14:11:56 +02:00
|
|
|
log_debug(stringtable)("Grown to size:" SIZE_FORMAT, _current_size);
|
2014-05-07 14:16:45 -05:00
|
|
|
}
|
|
|
|
|
2018-06-07 14:11:56 +02:00
|
|
|
struct StringTableDoDelete : StackObj {
|
2020-06-23 09:38:21 +02:00
|
|
|
void operator()(WeakHandle* val) {
|
2018-06-14 07:26:27 +02:00
|
|
|
/* do nothing */
|
2018-06-07 14:11:56 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct StringTableDeleteCheck : StackObj {
|
|
|
|
long _count;
|
|
|
|
long _item;
|
|
|
|
StringTableDeleteCheck() : _count(0), _item(0) {}
|
2020-06-23 09:38:21 +02:00
|
|
|
bool operator()(WeakHandle* val) {
|
2018-06-07 14:11:56 +02:00
|
|
|
++_item;
|
|
|
|
oop tmp = val->peek();
|
|
|
|
if (tmp == NULL) {
|
|
|
|
++_count;
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
void StringTable::clean_dead_entries(JavaThread* jt) {
|
|
|
|
StringTableHash::BulkDeleteTask bdt(_local_table);
|
|
|
|
if (!bdt.prepare(jt)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
StringTableDeleteCheck stdc;
|
|
|
|
StringTableDoDelete stdd;
|
|
|
|
{
|
|
|
|
TraceTime timer("Clean", TRACETIME_LOG(Debug, stringtable, perf));
|
2018-06-18 16:13:21 +02:00
|
|
|
while(bdt.do_task(jt, stdc, stdd)) {
|
2018-06-07 14:11:56 +02:00
|
|
|
bdt.pause(jt);
|
|
|
|
{
|
|
|
|
ThreadBlockInVM tbivm(jt);
|
|
|
|
}
|
2018-06-27 12:46:15 +02:00
|
|
|
bdt.cont(jt);
|
2014-12-17 23:34:52 -05:00
|
|
|
}
|
2018-06-07 14:11:56 +02:00
|
|
|
bdt.done(jt);
|
|
|
|
}
|
|
|
|
log_debug(stringtable)("Cleaned %ld of %ld", stdc._count, stdc._item);
|
2014-05-07 14:16:45 -05:00
|
|
|
}
|
|
|
|
|
2020-07-16 17:41:14 -04:00
|
|
|
void StringTable::gc_notification(size_t num_dead) {
|
|
|
|
log_trace(stringtable)("Uncleaned items:" SIZE_FORMAT, num_dead);
|
|
|
|
|
|
|
|
if (has_work()) {
|
2018-06-07 14:11:56 +02:00
|
|
|
return;
|
|
|
|
}
|
2018-06-14 07:26:27 +02:00
|
|
|
|
2018-06-07 14:11:56 +02:00
|
|
|
double load_factor = StringTable::get_load_factor();
|
2020-07-16 17:41:14 -04:00
|
|
|
double dead_factor = StringTable::get_dead_factor(num_dead);
|
2018-06-07 14:11:56 +02:00
|
|
|
// We should clean/resize if we have more dead than alive,
|
|
|
|
// more items than preferred load factor or
|
|
|
|
// more dead items than water mark.
|
|
|
|
if ((dead_factor > load_factor) ||
|
|
|
|
(load_factor > PREF_AVG_LIST_LEN) ||
|
|
|
|
(dead_factor > CLEAN_DEAD_HIGH_WATER_MARK)) {
|
2019-01-31 10:29:53 -05:00
|
|
|
log_debug(stringtable)("Concurrent work triggered, live factor: %g dead factor: %g",
|
2018-06-07 14:11:56 +02:00
|
|
|
load_factor, dead_factor);
|
|
|
|
trigger_concurrent_work();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-16 17:41:14 -04:00
|
|
|
bool StringTable::has_work() {
|
|
|
|
return Atomic::load_acquire(&_has_work);
|
|
|
|
}
|
|
|
|
|
2019-05-16 07:09:17 -04:00
|
|
|
void StringTable::do_concurrent_work(JavaThread* jt) {
|
2018-06-07 14:11:56 +02:00
|
|
|
double load_factor = get_load_factor();
|
|
|
|
log_debug(stringtable, perf)("Concurrent work, live factor: %g", load_factor);
|
|
|
|
// We prefer growing, since that also removes dead items
|
|
|
|
if (load_factor > PREF_AVG_LIST_LEN && !_local_table->is_max_size_reached()) {
|
|
|
|
grow(jt);
|
|
|
|
} else {
|
|
|
|
clean_dead_entries(jt);
|
|
|
|
}
|
2020-07-16 17:41:14 -04:00
|
|
|
Atomic::release_store(&_has_work, false);
|
2018-06-07 14:11:56 +02:00
|
|
|
}
|
2014-05-07 14:16:45 -05:00
|
|
|
|
2018-06-07 14:11:56 +02:00
|
|
|
// Rehash
|
|
|
|
bool StringTable::do_rehash() {
|
|
|
|
if (!_local_table->is_safepoint_safe()) {
|
|
|
|
return false;
|
2014-05-07 14:16:45 -05:00
|
|
|
}
|
|
|
|
|
2019-06-11 07:31:47 -04:00
|
|
|
// We use current size, not max size.
|
|
|
|
size_t new_size = _local_table->get_size_log2(Thread::current());
|
|
|
|
StringTableHash* new_table = new StringTableHash(new_size, END_SIZE, REHASH_LEN);
|
2018-06-07 14:11:56 +02:00
|
|
|
// Use alt hash from now on
|
|
|
|
_alt_hash = true;
|
|
|
|
if (!_local_table->try_move_nodes_to(Thread::current(), new_table)) {
|
|
|
|
_alt_hash = false;
|
|
|
|
delete new_table;
|
|
|
|
return false;
|
2014-05-07 14:16:45 -05:00
|
|
|
}
|
|
|
|
|
2018-06-07 14:11:56 +02:00
|
|
|
// free old table
|
|
|
|
delete _local_table;
|
|
|
|
_local_table = new_table;
|
|
|
|
|
|
|
|
return true;
|
2014-05-07 14:16:45 -05:00
|
|
|
}
|
|
|
|
|
2019-05-16 07:09:17 -04:00
|
|
|
void StringTable::rehash_table() {
|
2018-06-07 14:11:56 +02:00
|
|
|
static bool rehashed = false;
|
|
|
|
log_debug(stringtable)("Table imbalanced, rehashing called.");
|
2014-05-07 14:16:45 -05:00
|
|
|
|
2018-06-07 14:11:56 +02:00
|
|
|
// Grow instead of rehash.
|
|
|
|
if (get_load_factor() > PREF_AVG_LIST_LEN &&
|
|
|
|
!_local_table->is_max_size_reached()) {
|
|
|
|
log_debug(stringtable)("Choosing growing over rehashing.");
|
|
|
|
trigger_concurrent_work();
|
|
|
|
_needs_rehashing = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Already rehashed.
|
|
|
|
if (rehashed) {
|
|
|
|
log_warning(stringtable)("Rehashing already done, still long lists.");
|
|
|
|
trigger_concurrent_work();
|
|
|
|
_needs_rehashing = false;
|
|
|
|
return;
|
|
|
|
}
|
2014-05-07 14:16:45 -05:00
|
|
|
|
2018-06-07 14:11:56 +02:00
|
|
|
murmur_seed = AltHashing::compute_seed();
|
|
|
|
{
|
|
|
|
if (do_rehash()) {
|
|
|
|
rehashed = true;
|
|
|
|
} else {
|
|
|
|
log_info(stringtable)("Resizes in progress rehashing skipped.");
|
2014-05-07 14:16:45 -05:00
|
|
|
}
|
|
|
|
}
|
2018-06-07 14:11:56 +02:00
|
|
|
_needs_rehashing = false;
|
|
|
|
}
|
2014-05-07 14:16:45 -05:00
|
|
|
|
2018-06-07 14:11:56 +02:00
|
|
|
// Statistics
|
|
|
|
static int literal_size(oop obj) {
|
|
|
|
// NOTE: this would over-count if (pre-JDK8)
|
|
|
|
// java_lang_Class::has_offset_field() is true and the String.value array is
|
|
|
|
// shared by several Strings. However, starting from JDK8, the String.value
|
|
|
|
// array is not shared anymore.
|
|
|
|
if (obj == NULL) {
|
|
|
|
return 0;
|
|
|
|
} else if (obj->klass() == SystemDictionary::String_klass()) {
|
|
|
|
return (obj->size() + java_lang_String::value(obj)->size()) * HeapWordSize;
|
|
|
|
} else {
|
|
|
|
return obj->size();
|
2014-05-07 14:16:45 -05:00
|
|
|
}
|
2018-06-07 14:11:56 +02:00
|
|
|
}
|
2014-05-07 14:16:45 -05:00
|
|
|
|
2018-06-07 14:11:56 +02:00
|
|
|
struct SizeFunc : StackObj {
|
2020-06-23 09:38:21 +02:00
|
|
|
size_t operator()(WeakHandle* val) {
|
2018-06-07 14:11:56 +02:00
|
|
|
oop s = val->peek();
|
|
|
|
if (s == NULL) {
|
|
|
|
// Dead
|
|
|
|
return 0;
|
2014-05-07 14:16:45 -05:00
|
|
|
}
|
2018-06-07 14:11:56 +02:00
|
|
|
return literal_size(s);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2019-05-08 11:11:50 -05:00
|
|
|
TableStatistics StringTable::get_table_statistics() {
|
|
|
|
static TableStatistics ts;
|
|
|
|
SizeFunc sz;
|
|
|
|
ts = _local_table->statistics_get(Thread::current(), sz, ts);
|
|
|
|
return ts;
|
|
|
|
}
|
|
|
|
|
2018-06-07 14:11:56 +02:00
|
|
|
void StringTable::print_table_statistics(outputStream* st,
|
|
|
|
const char* table_name) {
|
|
|
|
SizeFunc sz;
|
|
|
|
_local_table->statistics_to(Thread::current(), sz, st, table_name);
|
|
|
|
}
|
2014-05-07 14:16:45 -05:00
|
|
|
|
2018-06-07 14:11:56 +02:00
|
|
|
// Verification
|
|
|
|
class VerifyStrings : StackObj {
|
|
|
|
public:
|
2020-06-23 09:38:21 +02:00
|
|
|
bool operator()(WeakHandle* val) {
|
2018-06-07 14:11:56 +02:00
|
|
|
oop s = val->peek();
|
|
|
|
if (s != NULL) {
|
|
|
|
assert(java_lang_String::length(s) >= 0, "Length on string must work.");
|
2014-05-07 14:16:45 -05:00
|
|
|
}
|
2018-06-07 14:11:56 +02:00
|
|
|
return true;
|
|
|
|
};
|
|
|
|
};
|
2014-05-07 14:16:45 -05:00
|
|
|
|
2018-06-07 14:11:56 +02:00
|
|
|
// This verification is part of Universe::verify() and needs to be quick.
|
|
|
|
void StringTable::verify() {
|
|
|
|
Thread* thr = Thread::current();
|
|
|
|
VerifyStrings vs;
|
2019-05-16 07:09:17 -04:00
|
|
|
if (!_local_table->try_scan(thr, vs)) {
|
2018-06-07 14:11:56 +02:00
|
|
|
log_info(stringtable)("verify unavailable at this moment");
|
|
|
|
}
|
2014-05-07 14:16:45 -05:00
|
|
|
}
|
|
|
|
|
2018-06-07 14:11:56 +02:00
|
|
|
// Verification and comp
|
|
|
|
class VerifyCompStrings : StackObj {
|
|
|
|
GrowableArray<oop>* _oops;
|
|
|
|
public:
|
|
|
|
size_t _errors;
|
|
|
|
VerifyCompStrings(GrowableArray<oop>* oops) : _oops(oops), _errors(0) {}
|
2020-06-23 09:38:21 +02:00
|
|
|
bool operator()(WeakHandle* val) {
|
2018-06-07 14:11:56 +02:00
|
|
|
oop s = val->resolve();
|
|
|
|
if (s == NULL) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
int len = _oops->length();
|
|
|
|
for (int i = 0; i < len; i++) {
|
|
|
|
bool eq = java_lang_String::equals(s, _oops->at(i));
|
|
|
|
assert(!eq, "Duplicate strings");
|
|
|
|
if (eq) {
|
|
|
|
_errors++;
|
2014-05-07 14:16:45 -05:00
|
|
|
}
|
|
|
|
}
|
2018-06-07 14:11:56 +02:00
|
|
|
_oops->push(s);
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
size_t StringTable::verify_and_compare_entries() {
|
|
|
|
Thread* thr = Thread::current();
|
|
|
|
GrowableArray<oop>* oops =
|
|
|
|
new (ResourceObj::C_HEAP, mtInternal)
|
2020-06-16 09:37:53 +02:00
|
|
|
GrowableArray<oop>((int)_current_size, mtInternal);
|
2018-06-07 14:11:56 +02:00
|
|
|
|
|
|
|
VerifyCompStrings vcs(oops);
|
2019-05-16 07:09:17 -04:00
|
|
|
if (!_local_table->try_scan(thr, vcs)) {
|
2018-06-07 14:11:56 +02:00
|
|
|
log_info(stringtable)("verify unavailable at this moment");
|
2014-05-07 14:16:45 -05:00
|
|
|
}
|
2018-06-07 14:11:56 +02:00
|
|
|
delete oops;
|
|
|
|
return vcs._errors;
|
|
|
|
}
|
2014-05-07 14:16:45 -05:00
|
|
|
|
2018-06-07 14:11:56 +02:00
|
|
|
// Dumping
|
|
|
|
class PrintString : StackObj {
|
|
|
|
Thread* _thr;
|
|
|
|
outputStream* _st;
|
|
|
|
public:
|
|
|
|
PrintString(Thread* thr, outputStream* st) : _thr(thr), _st(st) {}
|
2020-06-23 09:38:21 +02:00
|
|
|
bool operator()(WeakHandle* val) {
|
2018-06-07 14:11:56 +02:00
|
|
|
oop s = val->peek();
|
|
|
|
if (s == NULL) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
typeArrayOop value = java_lang_String::value_no_keepalive(s);
|
|
|
|
int length = java_lang_String::length(s);
|
|
|
|
bool is_latin1 = java_lang_String::is_latin1(s);
|
2014-05-07 14:16:45 -05:00
|
|
|
|
2018-06-07 14:11:56 +02:00
|
|
|
if (length <= 0) {
|
|
|
|
_st->print("%d: ", length);
|
|
|
|
} else {
|
|
|
|
ResourceMark rm(_thr);
|
|
|
|
int utf8_length = length;
|
|
|
|
char* utf8_string;
|
|
|
|
|
|
|
|
if (!is_latin1) {
|
|
|
|
jchar* chars = value->char_at_addr(0);
|
|
|
|
utf8_string = UNICODE::as_utf8(chars, utf8_length);
|
|
|
|
} else {
|
|
|
|
jbyte* bytes = value->byte_at_addr(0);
|
|
|
|
utf8_string = UNICODE::as_utf8(bytes, utf8_length);
|
2014-05-07 14:16:45 -05:00
|
|
|
}
|
2018-06-07 14:11:56 +02:00
|
|
|
|
|
|
|
_st->print("%d: ", utf8_length);
|
|
|
|
HashtableTextDump::put_utf8(_st, utf8_string, utf8_length);
|
2014-05-07 14:16:45 -05:00
|
|
|
}
|
2018-06-07 14:11:56 +02:00
|
|
|
_st->cr();
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
};
|
2014-05-07 14:16:45 -05:00
|
|
|
|
2018-06-07 14:11:56 +02:00
|
|
|
void StringTable::dump(outputStream* st, bool verbose) {
|
|
|
|
if (!verbose) {
|
2019-05-16 07:09:17 -04:00
|
|
|
print_table_statistics(st, "StringTable");
|
2018-06-07 14:11:56 +02:00
|
|
|
} else {
|
|
|
|
Thread* thr = Thread::current();
|
|
|
|
ResourceMark rm(thr);
|
|
|
|
st->print_cr("VERSION: 1.1");
|
|
|
|
PrintString ps(thr, st);
|
2019-05-16 07:09:17 -04:00
|
|
|
if (!_local_table->try_scan(thr, ps)) {
|
2018-06-07 14:11:56 +02:00
|
|
|
st->print_cr("dump unavailable at this moment");
|
|
|
|
}
|
|
|
|
}
|
2014-05-07 14:16:45 -05:00
|
|
|
}
|
2014-12-17 23:34:52 -05:00
|
|
|
|
|
|
|
// Utility for dumping strings
|
|
|
|
StringtableDCmd::StringtableDCmd(outputStream* output, bool heap) :
|
|
|
|
DCmdWithParser(output, heap),
|
|
|
|
_verbose("-verbose", "Dump the content of each string in the table",
|
|
|
|
"BOOLEAN", false, "false") {
|
|
|
|
_dcmdparser.add_dcmd_option(&_verbose);
|
|
|
|
}
|
|
|
|
|
|
|
|
void StringtableDCmd::execute(DCmdSource source, TRAPS) {
|
|
|
|
VM_DumpHashtable dumper(output(), VM_DumpHashtable::DumpStrings,
|
|
|
|
_verbose.value());
|
|
|
|
VMThread::execute(&dumper);
|
|
|
|
}
|
|
|
|
|
|
|
|
int StringtableDCmd::num_arguments() {
|
|
|
|
ResourceMark rm;
|
|
|
|
StringtableDCmd* dcmd = new StringtableDCmd(NULL, false);
|
|
|
|
if (dcmd != NULL) {
|
|
|
|
DCmdMark mark(dcmd);
|
|
|
|
return dcmd->_dcmdparser.num_arguments();
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2015-06-12 17:29:14 -04:00
|
|
|
|
|
|
|
// Sharing
|
2018-06-07 14:11:56 +02:00
|
|
|
#if INCLUDE_CDS_JAVA_HEAP
|
2018-09-18 21:47:14 -07:00
|
|
|
oop StringTable::lookup_shared(const jchar* name, int len, unsigned int hash) {
|
2018-06-07 14:11:56 +02:00
|
|
|
assert(hash == java_lang_String::hash_code(name, len),
|
|
|
|
"hash must be computed using java_lang_String::hash_code");
|
2018-09-18 21:47:14 -07:00
|
|
|
return _shared_table.lookup(name, hash, len);
|
2018-06-07 14:11:56 +02:00
|
|
|
}
|
|
|
|
|
2017-08-14 14:32:17 -04:00
|
|
|
oop StringTable::create_archived_string(oop s, Thread* THREAD) {
|
|
|
|
assert(DumpSharedSpaces, "this function is only used with -Xshare:dump");
|
2020-08-27 22:24:28 -07:00
|
|
|
assert(!HeapShared::is_archived_object(s), "sanity");
|
2018-07-08 12:43:05 -04:00
|
|
|
|
2017-08-14 14:32:17 -04:00
|
|
|
oop new_s = NULL;
|
2018-01-08 16:21:23 +01:00
|
|
|
typeArrayOop v = java_lang_String::value_no_keepalive(s);
|
2018-10-09 15:58:07 -04:00
|
|
|
typeArrayOop new_v = (typeArrayOop)HeapShared::archive_heap_object(v, THREAD);
|
2017-08-14 14:32:17 -04:00
|
|
|
if (new_v == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2018-10-09 15:58:07 -04:00
|
|
|
new_s = HeapShared::archive_heap_object(s, THREAD);
|
2017-08-14 14:32:17 -04:00
|
|
|
if (new_s == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2020-08-27 22:24:28 -07:00
|
|
|
class CopyToArchive : StackObj {
|
2018-10-08 16:29:10 -07:00
|
|
|
CompactHashtableWriter* _writer;
|
2020-08-27 22:24:28 -07:00
|
|
|
public:
|
2018-10-08 16:29:10 -07:00
|
|
|
CopyToArchive(CompactHashtableWriter* writer) : _writer(writer) {}
|
2020-08-27 22:24:28 -07:00
|
|
|
bool do_entry(oop s, bool value_ignored) {
|
|
|
|
assert(s != NULL, "sanity");
|
2018-06-07 14:11:56 +02:00
|
|
|
unsigned int hash = java_lang_String::hash_code(s);
|
|
|
|
oop new_s = StringTable::create_archived_string(s, Thread::current());
|
|
|
|
if (new_s == NULL) {
|
|
|
|
return true;
|
2015-06-12 17:29:14 -04:00
|
|
|
}
|
2018-06-07 14:11:56 +02:00
|
|
|
|
|
|
|
// add to the compact table
|
2020-10-01 10:45:22 +00:00
|
|
|
_writer->add(hash, CompressedOops::narrow_oop_value(new_s));
|
2018-06-07 14:11:56 +02:00
|
|
|
return true;
|
2015-06-12 17:29:14 -04:00
|
|
|
}
|
2018-06-07 14:11:56 +02:00
|
|
|
};
|
2015-06-12 17:29:14 -04:00
|
|
|
|
2020-08-27 22:24:28 -07:00
|
|
|
void StringTable::write_to_archive(const DumpedInternedStrings* dumped_interned_strings) {
|
2018-10-09 15:58:07 -04:00
|
|
|
assert(HeapShared::is_heap_object_archiving_allowed(), "must be");
|
2017-08-14 14:32:17 -04:00
|
|
|
|
2016-04-17 19:15:52 -07:00
|
|
|
_shared_table.reset();
|
2019-05-17 08:29:55 -07:00
|
|
|
CompactHashtableWriter writer(_items_count, &MetaspaceShared::stats()->string);
|
2017-08-14 14:32:17 -04:00
|
|
|
|
|
|
|
// Copy the interned strings into the "string space" within the java heap
|
2020-08-27 22:24:28 -07:00
|
|
|
CopyToArchive copier(&writer);
|
|
|
|
dumped_interned_strings->iterate(&copier);
|
|
|
|
|
2018-09-18 21:47:14 -07:00
|
|
|
writer.dump(&_shared_table, "string");
|
2017-08-02 18:06:38 -07:00
|
|
|
}
|
2015-06-12 17:29:14 -04:00
|
|
|
|
2018-10-08 16:29:10 -07:00
|
|
|
void StringTable::serialize_shared_table_header(SerializeClosure* soc) {
|
|
|
|
_shared_table.serialize_header(soc);
|
2015-06-12 17:29:14 -04:00
|
|
|
|
2016-04-17 19:15:52 -07:00
|
|
|
if (soc->writing()) {
|
2018-06-07 14:11:56 +02:00
|
|
|
// Sanity. Make sure we don't use the shared table at dump time
|
|
|
|
_shared_table.reset();
|
2018-11-03 15:40:19 -04:00
|
|
|
} else if (!HeapShared::closed_archive_heap_region_mapped()) {
|
2016-04-17 19:15:52 -07:00
|
|
|
_shared_table.reset();
|
2015-06-12 17:29:14 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-18 21:47:14 -07:00
|
|
|
class SharedStringIterator {
|
|
|
|
OopClosure* _oop_closure;
|
|
|
|
public:
|
|
|
|
SharedStringIterator(OopClosure* f) : _oop_closure(f) {}
|
|
|
|
void do_value(oop string) {
|
|
|
|
_oop_closure->do_oop(&string);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-06-12 17:29:14 -04:00
|
|
|
void StringTable::shared_oops_do(OopClosure* f) {
|
2018-09-18 21:47:14 -07:00
|
|
|
SharedStringIterator iter(f);
|
|
|
|
_shared_table.iterate(&iter);
|
2015-06-12 17:29:14 -04:00
|
|
|
}
|
2017-08-14 14:32:17 -04:00
|
|
|
#endif //INCLUDE_CDS_JAVA_HEAP
|