author | chrisphi |
Tue, 19 Jun 2018 10:00:39 -0400 | |
changeset 50676 | 8c0a5b51559b |
parent 50556 | e5a40146791b |
child 51405 | 8b23aa7cef47 |
permissions | -rw-r--r-- |
24426 | 1 |
/* |
49621 | 2 |
* Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved. |
24426 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
* |
|
23 |
*/ |
|
24 |
||
25 |
#ifndef SHARE_VM_CLASSFILE_STRINGTABLE_HPP |
|
26 |
#define SHARE_VM_CLASSFILE_STRINGTABLE_HPP |
|
27 |
||
50445
bd6b78feb6a3
8195097: Make it possible to process StringTable outside safepoint
rehn
parents:
49621
diff
changeset
|
28 |
#include "gc/shared/oopStorage.hpp" |
bd6b78feb6a3
8195097: Make it possible to process StringTable outside safepoint
rehn
parents:
49621
diff
changeset
|
29 |
#include "gc/shared/oopStorageParState.hpp" |
bd6b78feb6a3
8195097: Make it possible to process StringTable outside safepoint
rehn
parents:
49621
diff
changeset
|
30 |
#include "memory/allocation.hpp" |
bd6b78feb6a3
8195097: Make it possible to process StringTable outside safepoint
rehn
parents:
49621
diff
changeset
|
31 |
#include "memory/padded.hpp" |
bd6b78feb6a3
8195097: Make it possible to process StringTable outside safepoint
rehn
parents:
49621
diff
changeset
|
32 |
#include "oops/oop.hpp" |
bd6b78feb6a3
8195097: Make it possible to process StringTable outside safepoint
rehn
parents:
49621
diff
changeset
|
33 |
#include "oops/weakHandle.hpp" |
bd6b78feb6a3
8195097: Make it possible to process StringTable outside safepoint
rehn
parents:
49621
diff
changeset
|
34 |
#include "utilities/concurrentHashTable.hpp" |
24426 | 35 |
|
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28363
diff
changeset
|
36 |
template <class T, class N> class CompactHashtable; |
37995 | 37 |
class CompactStringTableWriter; |
38 |
class SerializeClosure; |
|
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28363
diff
changeset
|
39 |
|
50445
bd6b78feb6a3
8195097: Make it possible to process StringTable outside safepoint
rehn
parents:
49621
diff
changeset
|
40 |
class StringTable; |
bd6b78feb6a3
8195097: Make it possible to process StringTable outside safepoint
rehn
parents:
49621
diff
changeset
|
41 |
class StringTableConfig; |
bd6b78feb6a3
8195097: Make it possible to process StringTable outside safepoint
rehn
parents:
49621
diff
changeset
|
42 |
typedef ConcurrentHashTable<WeakHandle<vm_string_table_data>, |
bd6b78feb6a3
8195097: Make it possible to process StringTable outside safepoint
rehn
parents:
49621
diff
changeset
|
43 |
StringTableConfig, mtSymbol> StringTableHash; |
bd6b78feb6a3
8195097: Make it possible to process StringTable outside safepoint
rehn
parents:
49621
diff
changeset
|
44 |
|
bd6b78feb6a3
8195097: Make it possible to process StringTable outside safepoint
rehn
parents:
49621
diff
changeset
|
45 |
class StringTableCreateEntry; |
bd6b78feb6a3
8195097: Make it possible to process StringTable outside safepoint
rehn
parents:
49621
diff
changeset
|
46 |
|
bd6b78feb6a3
8195097: Make it possible to process StringTable outside safepoint
rehn
parents:
49621
diff
changeset
|
47 |
class StringTable : public CHeapObj<mtSymbol>{ |
24426 | 48 |
friend class VMStructs; |
49 |
friend class Symbol; |
|
50445
bd6b78feb6a3
8195097: Make it possible to process StringTable outside safepoint
rehn
parents:
49621
diff
changeset
|
50 |
friend class StringTableConfig; |
bd6b78feb6a3
8195097: Make it possible to process StringTable outside safepoint
rehn
parents:
49621
diff
changeset
|
51 |
friend class StringTableCreateEntry; |
24426 | 52 |
|
53 |
private: |
|
50445
bd6b78feb6a3
8195097: Make it possible to process StringTable outside safepoint
rehn
parents:
49621
diff
changeset
|
54 |
void grow(JavaThread* jt); |
bd6b78feb6a3
8195097: Make it possible to process StringTable outside safepoint
rehn
parents:
49621
diff
changeset
|
55 |
void clean_dead_entries(JavaThread* jt); |
bd6b78feb6a3
8195097: Make it possible to process StringTable outside safepoint
rehn
parents:
49621
diff
changeset
|
56 |
|
24426 | 57 |
// The string table |
58 |
static StringTable* _the_table; |
|
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28363
diff
changeset
|
59 |
// Shared string table |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28363
diff
changeset
|
60 |
static CompactHashtable<oop, char> _shared_table; |
46810
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
61 |
static bool _shared_string_mapped; |
50445
bd6b78feb6a3
8195097: Make it possible to process StringTable outside safepoint
rehn
parents:
49621
diff
changeset
|
62 |
static bool _alt_hash; |
bd6b78feb6a3
8195097: Make it possible to process StringTable outside safepoint
rehn
parents:
49621
diff
changeset
|
63 |
private: |
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28363
diff
changeset
|
64 |
|
50445
bd6b78feb6a3
8195097: Make it possible to process StringTable outside safepoint
rehn
parents:
49621
diff
changeset
|
65 |
// Set if one bucket is out of balance due to hash algorithm deficiency |
bd6b78feb6a3
8195097: Make it possible to process StringTable outside safepoint
rehn
parents:
49621
diff
changeset
|
66 |
StringTableHash* _local_table; |
bd6b78feb6a3
8195097: Make it possible to process StringTable outside safepoint
rehn
parents:
49621
diff
changeset
|
67 |
size_t _current_size; |
bd6b78feb6a3
8195097: Make it possible to process StringTable outside safepoint
rehn
parents:
49621
diff
changeset
|
68 |
volatile bool _has_work; |
bd6b78feb6a3
8195097: Make it possible to process StringTable outside safepoint
rehn
parents:
49621
diff
changeset
|
69 |
volatile bool _needs_rehashing; |
24426 | 70 |
|
50445
bd6b78feb6a3
8195097: Make it possible to process StringTable outside safepoint
rehn
parents:
49621
diff
changeset
|
71 |
OopStorage* _weak_handles; |
24426 | 72 |
|
50445
bd6b78feb6a3
8195097: Make it possible to process StringTable outside safepoint
rehn
parents:
49621
diff
changeset
|
73 |
volatile size_t _items; |
bd6b78feb6a3
8195097: Make it possible to process StringTable outside safepoint
rehn
parents:
49621
diff
changeset
|
74 |
DEFINE_PAD_MINUS_SIZE(1, DEFAULT_CACHE_LINE_SIZE, sizeof(volatile size_t)); |
bd6b78feb6a3
8195097: Make it possible to process StringTable outside safepoint
rehn
parents:
49621
diff
changeset
|
75 |
volatile size_t _uncleaned_items; |
bd6b78feb6a3
8195097: Make it possible to process StringTable outside safepoint
rehn
parents:
49621
diff
changeset
|
76 |
DEFINE_PAD_MINUS_SIZE(2, DEFAULT_CACHE_LINE_SIZE, sizeof(volatile size_t)); |
24426 | 77 |
|
50445
bd6b78feb6a3
8195097: Make it possible to process StringTable outside safepoint
rehn
parents:
49621
diff
changeset
|
78 |
double get_load_factor(); |
bd6b78feb6a3
8195097: Make it possible to process StringTable outside safepoint
rehn
parents:
49621
diff
changeset
|
79 |
double get_dead_factor(); |
45114
45644c5f6b8e
8180048: Interned string and symbol table leak memory during parallel unlinking
tschatzl
parents:
44323
diff
changeset
|
80 |
|
50445
bd6b78feb6a3
8195097: Make it possible to process StringTable outside safepoint
rehn
parents:
49621
diff
changeset
|
81 |
void check_concurrent_work(); |
bd6b78feb6a3
8195097: Make it possible to process StringTable outside safepoint
rehn
parents:
49621
diff
changeset
|
82 |
void trigger_concurrent_work(); |
24426 | 83 |
|
50676
8c0a5b51559b
8203030: Zero s390 31 bit size_t type conflicts in shared code
chrisphi
parents:
50556
diff
changeset
|
84 |
static size_t item_added(); |
50445
bd6b78feb6a3
8195097: Make it possible to process StringTable outside safepoint
rehn
parents:
49621
diff
changeset
|
85 |
static void item_removed(); |
50556
e5a40146791b
8204613: StringTable: Calculates wrong number of uncleaned items.
rehn
parents:
50445
diff
changeset
|
86 |
size_t add_items_to_clean(size_t ndead); |
50445
bd6b78feb6a3
8195097: Make it possible to process StringTable outside safepoint
rehn
parents:
49621
diff
changeset
|
87 |
|
bd6b78feb6a3
8195097: Make it possible to process StringTable outside safepoint
rehn
parents:
49621
diff
changeset
|
88 |
StringTable(); |
44323
1566bea4793a
8176593: Throwable::getStackTrace performance regression
redestad
parents:
37995
diff
changeset
|
89 |
|
50445
bd6b78feb6a3
8195097: Make it possible to process StringTable outside safepoint
rehn
parents:
49621
diff
changeset
|
90 |
static oop intern(Handle string_or_null_h, jchar* name, int len, TRAPS); |
bd6b78feb6a3
8195097: Make it possible to process StringTable outside safepoint
rehn
parents:
49621
diff
changeset
|
91 |
oop do_intern(Handle string_or_null, jchar* name, int len, uintx hash, TRAPS); |
bd6b78feb6a3
8195097: Make it possible to process StringTable outside safepoint
rehn
parents:
49621
diff
changeset
|
92 |
oop do_lookup(jchar* name, int len, uintx hash); |
48618
688e5cbd0b91
8192003: Refactor weak references in StringTable to use the Access API
eosterlund
parents:
48157
diff
changeset
|
93 |
|
50445
bd6b78feb6a3
8195097: Make it possible to process StringTable outside safepoint
rehn
parents:
49621
diff
changeset
|
94 |
void concurrent_work(JavaThread* jt); |
bd6b78feb6a3
8195097: Make it possible to process StringTable outside safepoint
rehn
parents:
49621
diff
changeset
|
95 |
void print_table_statistics(outputStream* st, const char* table_name); |
24426 | 96 |
|
50445
bd6b78feb6a3
8195097: Make it possible to process StringTable outside safepoint
rehn
parents:
49621
diff
changeset
|
97 |
void try_rehash_table(); |
bd6b78feb6a3
8195097: Make it possible to process StringTable outside safepoint
rehn
parents:
49621
diff
changeset
|
98 |
bool do_rehash(); |
bd6b78feb6a3
8195097: Make it possible to process StringTable outside safepoint
rehn
parents:
49621
diff
changeset
|
99 |
|
bd6b78feb6a3
8195097: Make it possible to process StringTable outside safepoint
rehn
parents:
49621
diff
changeset
|
100 |
public: |
24426 | 101 |
// The string table |
102 |
static StringTable* the_table() { return _the_table; } |
|
50445
bd6b78feb6a3
8195097: Make it possible to process StringTable outside safepoint
rehn
parents:
49621
diff
changeset
|
103 |
size_t table_size(Thread* thread = NULL); |
24426 | 104 |
|
50445
bd6b78feb6a3
8195097: Make it possible to process StringTable outside safepoint
rehn
parents:
49621
diff
changeset
|
105 |
static OopStorage* weak_storage() { return the_table()->_weak_handles; } |
24426 | 106 |
|
107 |
static void create_table() { |
|
108 |
assert(_the_table == NULL, "One string table allowed."); |
|
109 |
_the_table = new StringTable(); |
|
110 |
} |
|
111 |
||
50445
bd6b78feb6a3
8195097: Make it possible to process StringTable outside safepoint
rehn
parents:
49621
diff
changeset
|
112 |
static void do_concurrent_work(JavaThread* jt); |
bd6b78feb6a3
8195097: Make it possible to process StringTable outside safepoint
rehn
parents:
49621
diff
changeset
|
113 |
static bool has_work() { return the_table()->_has_work; } |
bd6b78feb6a3
8195097: Make it possible to process StringTable outside safepoint
rehn
parents:
49621
diff
changeset
|
114 |
|
24426 | 115 |
// GC support |
50556
e5a40146791b
8204613: StringTable: Calculates wrong number of uncleaned items.
rehn
parents:
50445
diff
changeset
|
116 |
|
e5a40146791b
8204613: StringTable: Calculates wrong number of uncleaned items.
rehn
parents:
50445
diff
changeset
|
117 |
// Must be called before a parallel walk where strings might die. |
e5a40146791b
8204613: StringTable: Calculates wrong number of uncleaned items.
rehn
parents:
50445
diff
changeset
|
118 |
static void reset_dead_counter() { |
e5a40146791b
8204613: StringTable: Calculates wrong number of uncleaned items.
rehn
parents:
50445
diff
changeset
|
119 |
the_table()->_uncleaned_items = 0; |
e5a40146791b
8204613: StringTable: Calculates wrong number of uncleaned items.
rehn
parents:
50445
diff
changeset
|
120 |
} |
e5a40146791b
8204613: StringTable: Calculates wrong number of uncleaned items.
rehn
parents:
50445
diff
changeset
|
121 |
// After the parallel walk this method must be called to trigger |
e5a40146791b
8204613: StringTable: Calculates wrong number of uncleaned items.
rehn
parents:
50445
diff
changeset
|
122 |
// cleaning. Note it might trigger a resize instead. |
e5a40146791b
8204613: StringTable: Calculates wrong number of uncleaned items.
rehn
parents:
50445
diff
changeset
|
123 |
static void finish_dead_counter() { |
e5a40146791b
8204613: StringTable: Calculates wrong number of uncleaned items.
rehn
parents:
50445
diff
changeset
|
124 |
the_table()->check_concurrent_work(); |
e5a40146791b
8204613: StringTable: Calculates wrong number of uncleaned items.
rehn
parents:
50445
diff
changeset
|
125 |
} |
e5a40146791b
8204613: StringTable: Calculates wrong number of uncleaned items.
rehn
parents:
50445
diff
changeset
|
126 |
|
e5a40146791b
8204613: StringTable: Calculates wrong number of uncleaned items.
rehn
parents:
50445
diff
changeset
|
127 |
// If GC uses ParState directly it should add the number of cleared |
e5a40146791b
8204613: StringTable: Calculates wrong number of uncleaned items.
rehn
parents:
50445
diff
changeset
|
128 |
// strings to this method. |
e5a40146791b
8204613: StringTable: Calculates wrong number of uncleaned items.
rehn
parents:
50445
diff
changeset
|
129 |
static void inc_dead_counter(size_t ndead) { |
e5a40146791b
8204613: StringTable: Calculates wrong number of uncleaned items.
rehn
parents:
50445
diff
changeset
|
130 |
the_table()->add_items_to_clean(ndead); |
e5a40146791b
8204613: StringTable: Calculates wrong number of uncleaned items.
rehn
parents:
50445
diff
changeset
|
131 |
} |
e5a40146791b
8204613: StringTable: Calculates wrong number of uncleaned items.
rehn
parents:
50445
diff
changeset
|
132 |
|
24426 | 133 |
// Delete pointers to otherwise-unreachable objects. |
50445
bd6b78feb6a3
8195097: Make it possible to process StringTable outside safepoint
rehn
parents:
49621
diff
changeset
|
134 |
static void unlink(BoolObjectClosure* cl) { |
bd6b78feb6a3
8195097: Make it possible to process StringTable outside safepoint
rehn
parents:
49621
diff
changeset
|
135 |
unlink_or_oops_do(cl); |
24426 | 136 |
} |
50445
bd6b78feb6a3
8195097: Make it possible to process StringTable outside safepoint
rehn
parents:
49621
diff
changeset
|
137 |
static void unlink_or_oops_do(BoolObjectClosure* is_alive, OopClosure* f = NULL, |
bd6b78feb6a3
8195097: Make it possible to process StringTable outside safepoint
rehn
parents:
49621
diff
changeset
|
138 |
int* processed = NULL, int* removed = NULL); |
bd6b78feb6a3
8195097: Make it possible to process StringTable outside safepoint
rehn
parents:
49621
diff
changeset
|
139 |
|
24426 | 140 |
// Serially invoke "f->do_oop" on the locations of all oops in the table. |
141 |
static void oops_do(OopClosure* f); |
|
142 |
||
143 |
// Possibly parallel versions of the above |
|
50445
bd6b78feb6a3
8195097: Make it possible to process StringTable outside safepoint
rehn
parents:
49621
diff
changeset
|
144 |
static void possibly_parallel_unlink( |
bd6b78feb6a3
8195097: Make it possible to process StringTable outside safepoint
rehn
parents:
49621
diff
changeset
|
145 |
OopStorage::ParState<false /* concurrent */, false /* const*/>* par_state_string, |
bd6b78feb6a3
8195097: Make it possible to process StringTable outside safepoint
rehn
parents:
49621
diff
changeset
|
146 |
BoolObjectClosure* cl, int* processed, int* removed); |
bd6b78feb6a3
8195097: Make it possible to process StringTable outside safepoint
rehn
parents:
49621
diff
changeset
|
147 |
static void possibly_parallel_oops_do( |
bd6b78feb6a3
8195097: Make it possible to process StringTable outside safepoint
rehn
parents:
49621
diff
changeset
|
148 |
OopStorage::ParState<false /* concurrent */, false /* const*/>* par_state_string, |
bd6b78feb6a3
8195097: Make it possible to process StringTable outside safepoint
rehn
parents:
49621
diff
changeset
|
149 |
OopClosure* f); |
24426 | 150 |
|
151 |
// Probing |
|
152 |
static oop lookup(Symbol* symbol); |
|
153 |
static oop lookup(jchar* chars, int length); |
|
154 |
||
155 |
// Interning |
|
156 |
static oop intern(Symbol* symbol, TRAPS); |
|
157 |
static oop intern(oop string, TRAPS); |
|
158 |
static oop intern(const char *utf8_string, TRAPS); |
|
159 |
||
50445
bd6b78feb6a3
8195097: Make it possible to process StringTable outside safepoint
rehn
parents:
49621
diff
changeset
|
160 |
// Rehash the string table if it gets out of balance |
bd6b78feb6a3
8195097: Make it possible to process StringTable outside safepoint
rehn
parents:
49621
diff
changeset
|
161 |
static void rehash_table(); |
bd6b78feb6a3
8195097: Make it possible to process StringTable outside safepoint
rehn
parents:
49621
diff
changeset
|
162 |
static bool needs_rehashing() |
bd6b78feb6a3
8195097: Make it possible to process StringTable outside safepoint
rehn
parents:
49621
diff
changeset
|
163 |
{ return StringTable::the_table()->_needs_rehashing; } |
24426 | 164 |
|
165 |
// Sharing |
|
50445
bd6b78feb6a3
8195097: Make it possible to process StringTable outside safepoint
rehn
parents:
49621
diff
changeset
|
166 |
private: |
bd6b78feb6a3
8195097: Make it possible to process StringTable outside safepoint
rehn
parents:
49621
diff
changeset
|
167 |
oop lookup_shared(jchar* name, int len, unsigned int hash) NOT_CDS_JAVA_HEAP_RETURN_(NULL); |
bd6b78feb6a3
8195097: Make it possible to process StringTable outside safepoint
rehn
parents:
49621
diff
changeset
|
168 |
static void copy_shared_string_table(CompactStringTableWriter* ch_table) NOT_CDS_JAVA_HEAP_RETURN; |
bd6b78feb6a3
8195097: Make it possible to process StringTable outside safepoint
rehn
parents:
49621
diff
changeset
|
169 |
public: |
50556
e5a40146791b
8204613: StringTable: Calculates wrong number of uncleaned items.
rehn
parents:
50445
diff
changeset
|
170 |
static oop create_archived_string(oop s, Thread* THREAD) NOT_CDS_JAVA_HEAP_RETURN_(NULL); |
46810
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
171 |
static void set_shared_string_mapped() { _shared_string_mapped = true; } |
50556
e5a40146791b
8204613: StringTable: Calculates wrong number of uncleaned items.
rehn
parents:
50445
diff
changeset
|
172 |
static bool shared_string_mapped() { return _shared_string_mapped; } |
46810
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
173 |
static void shared_oops_do(OopClosure* f) NOT_CDS_JAVA_HEAP_RETURN; |
50445
bd6b78feb6a3
8195097: Make it possible to process StringTable outside safepoint
rehn
parents:
49621
diff
changeset
|
174 |
static void write_to_archive() NOT_CDS_JAVA_HEAP_RETURN; |
46810
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
175 |
static void serialize(SerializeClosure* soc) NOT_CDS_JAVA_HEAP_RETURN; |
24426 | 176 |
|
50445
bd6b78feb6a3
8195097: Make it possible to process StringTable outside safepoint
rehn
parents:
49621
diff
changeset
|
177 |
// Jcmd |
bd6b78feb6a3
8195097: Make it possible to process StringTable outside safepoint
rehn
parents:
49621
diff
changeset
|
178 |
static void dump(outputStream* st, bool verbose=false); |
bd6b78feb6a3
8195097: Make it possible to process StringTable outside safepoint
rehn
parents:
49621
diff
changeset
|
179 |
// Debugging |
bd6b78feb6a3
8195097: Make it possible to process StringTable outside safepoint
rehn
parents:
49621
diff
changeset
|
180 |
static size_t verify_and_compare_entries(); |
bd6b78feb6a3
8195097: Make it possible to process StringTable outside safepoint
rehn
parents:
49621
diff
changeset
|
181 |
static void verify(); |
bd6b78feb6a3
8195097: Make it possible to process StringTable outside safepoint
rehn
parents:
49621
diff
changeset
|
182 |
}; |
24426 | 183 |
|
184 |
#endif // SHARE_VM_CLASSFILE_STRINGTABLE_HPP |