2014-05-07 14:16:45 -05:00
|
|
|
/*
|
2018-03-27 11:53:23 -04:00
|
|
|
* Copyright (c) 1997, 2018, 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SHARE_VM_CLASSFILE_STRINGTABLE_HPP
|
|
|
|
#define SHARE_VM_CLASSFILE_STRINGTABLE_HPP
|
|
|
|
|
2018-06-07 14:11:56 +02:00
|
|
|
#include "gc/shared/oopStorage.hpp"
|
|
|
|
#include "gc/shared/oopStorageParState.hpp"
|
|
|
|
#include "memory/allocation.hpp"
|
|
|
|
#include "memory/padded.hpp"
|
|
|
|
#include "oops/oop.hpp"
|
|
|
|
#include "oops/weakHandle.hpp"
|
|
|
|
#include "utilities/concurrentHashTable.hpp"
|
2014-05-07 14:16:45 -05:00
|
|
|
|
2016-04-17 19:15:52 -07:00
|
|
|
class CompactStringTableWriter;
|
|
|
|
class SerializeClosure;
|
2015-06-12 17:29:14 -04:00
|
|
|
|
2018-06-07 14:11:56 +02:00
|
|
|
class StringTable;
|
|
|
|
class StringTableConfig;
|
|
|
|
typedef ConcurrentHashTable<WeakHandle<vm_string_table_data>,
|
|
|
|
StringTableConfig, mtSymbol> StringTableHash;
|
|
|
|
|
|
|
|
class StringTableCreateEntry;
|
|
|
|
|
|
|
|
class StringTable : public CHeapObj<mtSymbol>{
|
2014-05-07 14:16:45 -05:00
|
|
|
friend class VMStructs;
|
|
|
|
friend class Symbol;
|
2018-06-07 14:11:56 +02:00
|
|
|
friend class StringTableConfig;
|
|
|
|
friend class StringTableCreateEntry;
|
2014-05-07 14:16:45 -05:00
|
|
|
|
|
|
|
private:
|
2018-06-07 14:11:56 +02:00
|
|
|
void grow(JavaThread* jt);
|
|
|
|
void clean_dead_entries(JavaThread* jt);
|
|
|
|
|
2014-05-07 14:16:45 -05:00
|
|
|
// The string table
|
|
|
|
static StringTable* _the_table;
|
2018-08-14 18:42:14 -05:00
|
|
|
static volatile bool _shared_string_mapped;
|
|
|
|
static volatile bool _alt_hash;
|
|
|
|
|
2018-06-07 14:11:56 +02:00
|
|
|
private:
|
|
|
|
|
|
|
|
StringTableHash* _local_table;
|
|
|
|
size_t _current_size;
|
|
|
|
volatile bool _has_work;
|
2018-08-14 18:42:14 -05:00
|
|
|
// Set if one bucket is out of balance due to hash algorithm deficiency
|
2018-06-07 14:11:56 +02:00
|
|
|
volatile bool _needs_rehashing;
|
|
|
|
|
|
|
|
OopStorage* _weak_handles;
|
|
|
|
|
2018-08-14 18:42:14 -05:00
|
|
|
volatile size_t _items_count;
|
2018-06-07 14:11:56 +02:00
|
|
|
DEFINE_PAD_MINUS_SIZE(1, DEFAULT_CACHE_LINE_SIZE, sizeof(volatile size_t));
|
2018-08-14 18:42:14 -05:00
|
|
|
volatile size_t _uncleaned_items_count;
|
2018-06-07 14:11:56 +02:00
|
|
|
DEFINE_PAD_MINUS_SIZE(2, DEFAULT_CACHE_LINE_SIZE, sizeof(volatile size_t));
|
2015-06-12 17:29:14 -04:00
|
|
|
|
2018-06-07 14:11:56 +02:00
|
|
|
double get_load_factor();
|
|
|
|
double get_dead_factor();
|
|
|
|
|
|
|
|
void check_concurrent_work();
|
|
|
|
void trigger_concurrent_work();
|
|
|
|
|
2018-06-19 10:00:39 -04:00
|
|
|
static size_t item_added();
|
2018-06-07 14:11:56 +02:00
|
|
|
static void item_removed();
|
2018-08-14 18:42:14 -05:00
|
|
|
size_t add_items_count_to_clean(size_t ndead);
|
2018-06-07 14:11:56 +02:00
|
|
|
|
|
|
|
StringTable();
|
|
|
|
|
2018-09-18 21:47:14 -07:00
|
|
|
static oop intern(Handle string_or_null_h, const jchar* name, int len, TRAPS);
|
|
|
|
oop do_intern(Handle string_or_null, const jchar* name, int len, uintx hash, TRAPS);
|
|
|
|
oop do_lookup(const jchar* name, int len, uintx hash);
|
2018-06-07 14:11:56 +02:00
|
|
|
|
|
|
|
void concurrent_work(JavaThread* jt);
|
|
|
|
void print_table_statistics(outputStream* st, const char* table_name);
|
|
|
|
|
|
|
|
void try_rehash_table();
|
|
|
|
bool do_rehash();
|
|
|
|
|
|
|
|
public:
|
2014-05-07 14:16:45 -05:00
|
|
|
// The string table
|
|
|
|
static StringTable* the_table() { return _the_table; }
|
2018-08-14 18:42:14 -05:00
|
|
|
size_t table_size();
|
2014-05-07 14:16:45 -05:00
|
|
|
|
2018-06-07 14:11:56 +02:00
|
|
|
static OopStorage* weak_storage() { return the_table()->_weak_handles; }
|
2014-05-07 14:16:45 -05:00
|
|
|
|
|
|
|
static void create_table() {
|
|
|
|
assert(_the_table == NULL, "One string table allowed.");
|
|
|
|
_the_table = new StringTable();
|
|
|
|
}
|
|
|
|
|
2018-06-07 14:11:56 +02:00
|
|
|
static void do_concurrent_work(JavaThread* jt);
|
|
|
|
static bool has_work() { return the_table()->_has_work; }
|
|
|
|
|
2014-05-07 14:16:45 -05:00
|
|
|
// GC support
|
2018-06-14 07:26:27 +02:00
|
|
|
|
|
|
|
// Must be called before a parallel walk where strings might die.
|
|
|
|
static void reset_dead_counter() {
|
2018-08-14 18:42:14 -05:00
|
|
|
the_table()->_uncleaned_items_count = 0;
|
2018-06-14 07:26:27 +02:00
|
|
|
}
|
|
|
|
// After the parallel walk this method must be called to trigger
|
|
|
|
// cleaning. Note it might trigger a resize instead.
|
|
|
|
static void finish_dead_counter() {
|
|
|
|
the_table()->check_concurrent_work();
|
|
|
|
}
|
|
|
|
|
|
|
|
// If GC uses ParState directly it should add the number of cleared
|
|
|
|
// strings to this method.
|
|
|
|
static void inc_dead_counter(size_t ndead) {
|
2018-08-14 18:42:14 -05:00
|
|
|
the_table()->add_items_count_to_clean(ndead);
|
2018-06-14 07:26:27 +02:00
|
|
|
}
|
|
|
|
|
2014-05-07 14:16:45 -05:00
|
|
|
// Delete pointers to otherwise-unreachable objects.
|
|
|
|
static void unlink(BoolObjectClosure* cl) {
|
2018-06-07 14:11:56 +02:00
|
|
|
unlink_or_oops_do(cl);
|
2014-05-07 14:16:45 -05:00
|
|
|
}
|
2018-06-07 14:11:56 +02:00
|
|
|
static void unlink_or_oops_do(BoolObjectClosure* is_alive, OopClosure* f = NULL,
|
2018-08-27 17:20:29 -04:00
|
|
|
size_t* processed = NULL, size_t* removed = NULL);
|
2018-06-07 14:11:56 +02:00
|
|
|
|
2014-05-07 14:16:45 -05:00
|
|
|
// Serially invoke "f->do_oop" on the locations of all oops in the table.
|
|
|
|
static void oops_do(OopClosure* f);
|
|
|
|
|
|
|
|
// Possibly parallel versions of the above
|
2018-06-07 14:11:56 +02:00
|
|
|
static void possibly_parallel_unlink(
|
|
|
|
OopStorage::ParState<false /* concurrent */, false /* const*/>* par_state_string,
|
2018-08-27 17:20:29 -04:00
|
|
|
BoolObjectClosure* cl, size_t* processed, size_t* removed);
|
2018-06-07 14:11:56 +02:00
|
|
|
static void possibly_parallel_oops_do(
|
|
|
|
OopStorage::ParState<false /* concurrent */, false /* const*/>* par_state_string,
|
|
|
|
OopClosure* f);
|
2014-05-07 14:16:45 -05:00
|
|
|
|
|
|
|
// Probing
|
|
|
|
static oop lookup(Symbol* symbol);
|
2018-09-18 21:47:14 -07:00
|
|
|
static oop lookup(const jchar* chars, int length);
|
2014-05-07 14:16:45 -05:00
|
|
|
|
|
|
|
// Interning
|
|
|
|
static oop intern(Symbol* symbol, TRAPS);
|
|
|
|
static oop intern(oop string, TRAPS);
|
|
|
|
static oop intern(const char *utf8_string, TRAPS);
|
|
|
|
|
2018-06-07 14:11:56 +02:00
|
|
|
// Rehash the string table if it gets out of balance
|
|
|
|
static void rehash_table();
|
|
|
|
static bool needs_rehashing()
|
|
|
|
{ return StringTable::the_table()->_needs_rehashing; }
|
2014-05-07 14:16:45 -05:00
|
|
|
|
|
|
|
// Sharing
|
2018-06-07 14:11:56 +02:00
|
|
|
private:
|
2018-09-18 21:47:14 -07:00
|
|
|
oop lookup_shared(const jchar* name, int len, unsigned int hash) NOT_CDS_JAVA_HEAP_RETURN_(NULL);
|
2018-06-07 14:11:56 +02:00
|
|
|
static void copy_shared_string_table(CompactStringTableWriter* ch_table) NOT_CDS_JAVA_HEAP_RETURN;
|
|
|
|
public:
|
2018-06-14 07:26:27 +02:00
|
|
|
static oop create_archived_string(oop s, Thread* THREAD) NOT_CDS_JAVA_HEAP_RETURN_(NULL);
|
2017-08-14 14:32:17 -04:00
|
|
|
static void set_shared_string_mapped() { _shared_string_mapped = true; }
|
2018-06-14 07:26:27 +02:00
|
|
|
static bool shared_string_mapped() { return _shared_string_mapped; }
|
2017-08-14 14:32:17 -04:00
|
|
|
static void shared_oops_do(OopClosure* f) NOT_CDS_JAVA_HEAP_RETURN;
|
2018-06-07 14:11:56 +02:00
|
|
|
static void write_to_archive() NOT_CDS_JAVA_HEAP_RETURN;
|
2017-08-14 14:32:17 -04:00
|
|
|
static void serialize(SerializeClosure* soc) NOT_CDS_JAVA_HEAP_RETURN;
|
2014-05-07 14:16:45 -05:00
|
|
|
|
2018-06-07 14:11:56 +02:00
|
|
|
// Jcmd
|
|
|
|
static void dump(outputStream* st, bool verbose=false);
|
|
|
|
// Debugging
|
|
|
|
static size_t verify_and_compare_entries();
|
|
|
|
static void verify();
|
2014-05-07 14:16:45 -05:00
|
|
|
};
|
2018-06-07 14:11:56 +02:00
|
|
|
|
2014-05-07 14:16:45 -05:00
|
|
|
#endif // SHARE_VM_CLASSFILE_STRINGTABLE_HPP
|