author | rfield |
Tue, 14 Nov 2017 19:33:37 -0800 (2017-11-15) | |
changeset 47840 | e0f08a49f3e3 |
parent 47216 | 71c04702a3d5 |
child 48157 | 7c4d43c26352 |
permissions | -rw-r--r-- |
24426 | 1 |
/* |
44323
1566bea4793a
8176593: Throwable::getStackTrace performance regression
redestad
parents:
37995
diff
changeset
|
2 |
* Copyright (c) 1997, 2017, 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 |
||
28 |
#include "memory/allocation.inline.hpp" |
|
29 |
#include "utilities/hashtable.hpp" |
|
30 |
||
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28363
diff
changeset
|
31 |
template <class T, class N> class CompactHashtable; |
37995 | 32 |
class CompactStringTableWriter; |
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28363
diff
changeset
|
33 |
class FileMapInfo; |
37995 | 34 |
class SerializeClosure; |
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28363
diff
changeset
|
35 |
|
26421
37d88e604ad0
8056084: Refactor Hashtable to allow implementations without rehashing support
mgerdin
parents:
24426
diff
changeset
|
36 |
class StringTable : public RehashableHashtable<oop, mtSymbol> { |
24426 | 37 |
friend class VMStructs; |
38 |
friend class Symbol; |
|
39 |
||
40 |
private: |
|
41 |
// The string table |
|
42 |
static StringTable* _the_table; |
|
43 |
||
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28363
diff
changeset
|
44 |
// Shared string table |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28363
diff
changeset
|
45 |
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
|
46 |
static bool _shared_string_mapped; |
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28363
diff
changeset
|
47 |
|
24426 | 48 |
// Set if one bucket is out of balance due to hash algorithm deficiency |
49 |
static bool _needs_rehashing; |
|
50 |
||
51 |
// Claimed high water mark for parallel chunked scanning |
|
52 |
static volatile int _parallel_claimed_idx; |
|
53 |
||
54 |
static oop intern(Handle string_or_null, jchar* chars, int length, TRAPS); |
|
55 |
oop basic_add(int index, Handle string_or_null, jchar* name, int len, |
|
56 |
unsigned int hashValue, TRAPS); |
|
57 |
||
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28363
diff
changeset
|
58 |
oop lookup_in_main_table(int index, jchar* chars, int length, unsigned int hashValue); |
44323
1566bea4793a
8176593: Throwable::getStackTrace performance regression
redestad
parents:
37995
diff
changeset
|
59 |
static oop lookup_shared(jchar* name, int len, unsigned int hash); |
24426 | 60 |
|
61 |
// Apply the give oop closure to the entries to the buckets |
|
62 |
// in the range [start_idx, end_idx). |
|
63 |
static void buckets_oops_do(OopClosure* f, int start_idx, int end_idx); |
|
45114
45644c5f6b8e
8180048: Interned string and symbol table leak memory during parallel unlinking
tschatzl
parents:
44323
diff
changeset
|
64 |
|
45644c5f6b8e
8180048: Interned string and symbol table leak memory during parallel unlinking
tschatzl
parents:
44323
diff
changeset
|
65 |
typedef StringTable::BucketUnlinkContext BucketUnlinkContext; |
24426 | 66 |
// Unlink or apply the give oop closure to the entries to the buckets |
45114
45644c5f6b8e
8180048: Interned string and symbol table leak memory during parallel unlinking
tschatzl
parents:
44323
diff
changeset
|
67 |
// in the range [start_idx, end_idx). Unlinked bucket entries are collected in the given |
45644c5f6b8e
8180048: Interned string and symbol table leak memory during parallel unlinking
tschatzl
parents:
44323
diff
changeset
|
68 |
// context to be freed later. |
45644c5f6b8e
8180048: Interned string and symbol table leak memory during parallel unlinking
tschatzl
parents:
44323
diff
changeset
|
69 |
// This allows multiple threads to work on the table at once. |
45644c5f6b8e
8180048: Interned string and symbol table leak memory during parallel unlinking
tschatzl
parents:
44323
diff
changeset
|
70 |
static void buckets_unlink_or_oops_do(BoolObjectClosure* is_alive, OopClosure* f, int start_idx, int end_idx, BucketUnlinkContext* context); |
24426 | 71 |
|
44323
1566bea4793a
8176593: Throwable::getStackTrace performance regression
redestad
parents:
37995
diff
changeset
|
72 |
// Hashing algorithm, used as the hash value used by the |
1566bea4793a
8176593: Throwable::getStackTrace performance regression
redestad
parents:
37995
diff
changeset
|
73 |
// StringTable for bucket selection and comparison (stored in the |
1566bea4793a
8176593: Throwable::getStackTrace performance regression
redestad
parents:
37995
diff
changeset
|
74 |
// HashtableEntry structures). This is used in the String.intern() method. |
1566bea4793a
8176593: Throwable::getStackTrace performance regression
redestad
parents:
37995
diff
changeset
|
75 |
static unsigned int hash_string(const jchar* s, int len); |
1566bea4793a
8176593: Throwable::getStackTrace performance regression
redestad
parents:
37995
diff
changeset
|
76 |
static unsigned int hash_string(oop string); |
1566bea4793a
8176593: Throwable::getStackTrace performance regression
redestad
parents:
37995
diff
changeset
|
77 |
static unsigned int alt_hash_string(const jchar* s, int len); |
1566bea4793a
8176593: Throwable::getStackTrace performance regression
redestad
parents:
37995
diff
changeset
|
78 |
|
26421
37d88e604ad0
8056084: Refactor Hashtable to allow implementations without rehashing support
mgerdin
parents:
24426
diff
changeset
|
79 |
StringTable() : RehashableHashtable<oop, mtSymbol>((int)StringTableSize, |
24426 | 80 |
sizeof (HashtableEntry<oop, mtSymbol>)) {} |
81 |
||
82 |
StringTable(HashtableBucket<mtSymbol>* t, int number_of_entries) |
|
26421
37d88e604ad0
8056084: Refactor Hashtable to allow implementations without rehashing support
mgerdin
parents:
24426
diff
changeset
|
83 |
: RehashableHashtable<oop, mtSymbol>((int)StringTableSize, sizeof (HashtableEntry<oop, mtSymbol>), t, |
24426 | 84 |
number_of_entries) {} |
85 |
public: |
|
86 |
// The string table |
|
87 |
static StringTable* the_table() { return _the_table; } |
|
88 |
||
89 |
// Size of one bucket in the string table. Used when checking for rollover. |
|
90 |
static uint bucket_size() { return sizeof(HashtableBucket<mtSymbol>); } |
|
91 |
||
92 |
static void create_table() { |
|
93 |
assert(_the_table == NULL, "One string table allowed."); |
|
94 |
_the_table = new StringTable(); |
|
95 |
} |
|
96 |
||
97 |
// GC support |
|
98 |
// Delete pointers to otherwise-unreachable objects. |
|
99 |
static void unlink_or_oops_do(BoolObjectClosure* cl, OopClosure* f) { |
|
100 |
int processed = 0; |
|
101 |
int removed = 0; |
|
102 |
unlink_or_oops_do(cl, f, &processed, &removed); |
|
103 |
} |
|
104 |
static void unlink(BoolObjectClosure* cl) { |
|
105 |
int processed = 0; |
|
106 |
int removed = 0; |
|
107 |
unlink_or_oops_do(cl, NULL, &processed, &removed); |
|
108 |
} |
|
109 |
static void unlink_or_oops_do(BoolObjectClosure* cl, OopClosure* f, int* processed, int* removed); |
|
110 |
static void unlink(BoolObjectClosure* cl, int* processed, int* removed) { |
|
111 |
unlink_or_oops_do(cl, NULL, processed, removed); |
|
112 |
} |
|
113 |
// Serially invoke "f->do_oop" on the locations of all oops in the table. |
|
114 |
static void oops_do(OopClosure* f); |
|
115 |
||
116 |
// Possibly parallel versions of the above |
|
117 |
static void possibly_parallel_unlink_or_oops_do(BoolObjectClosure* cl, OopClosure* f, int* processed, int* removed); |
|
118 |
static void possibly_parallel_unlink(BoolObjectClosure* cl, int* processed, int* removed) { |
|
119 |
possibly_parallel_unlink_or_oops_do(cl, NULL, processed, removed); |
|
120 |
} |
|
121 |
static void possibly_parallel_oops_do(OopClosure* f); |
|
122 |
||
123 |
// Internal test. |
|
124 |
static void test_alt_hash() PRODUCT_RETURN; |
|
125 |
||
126 |
// Probing |
|
127 |
static oop lookup(Symbol* symbol); |
|
128 |
static oop lookup(jchar* chars, int length); |
|
129 |
||
130 |
// Interning |
|
131 |
static oop intern(Symbol* symbol, TRAPS); |
|
132 |
static oop intern(oop string, TRAPS); |
|
133 |
static oop intern(const char *utf8_string, TRAPS); |
|
134 |
||
135 |
// Debugging |
|
136 |
static void verify(); |
|
28363
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
26421
diff
changeset
|
137 |
static void dump(outputStream* st, bool verbose=false); |
24426 | 138 |
|
139 |
enum VerifyMesgModes { |
|
140 |
_verify_quietly = 0, |
|
141 |
_verify_with_mesgs = 1 |
|
142 |
}; |
|
143 |
||
144 |
enum VerifyRetTypes { |
|
145 |
_verify_pass = 0, |
|
146 |
_verify_fail_continue = 1, |
|
147 |
_verify_fail_done = 2 |
|
148 |
}; |
|
149 |
||
150 |
static VerifyRetTypes compare_entries(int bkt1, int e_cnt1, |
|
151 |
HashtableEntry<oop, mtSymbol>* e_ptr1, |
|
152 |
int bkt2, int e_cnt2, |
|
153 |
HashtableEntry<oop, mtSymbol>* e_ptr2); |
|
154 |
static VerifyRetTypes verify_entry(int bkt, int e_cnt, |
|
155 |
HashtableEntry<oop, mtSymbol>* e_ptr, |
|
156 |
VerifyMesgModes mesg_mode); |
|
157 |
static int verify_and_compare_entries(); |
|
158 |
||
159 |
// Sharing |
|
46810
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
160 |
static void set_shared_string_mapped() { _shared_string_mapped = true; } |
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
161 |
static bool shared_string_mapped() { return _shared_string_mapped; } |
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
162 |
static void shared_oops_do(OopClosure* f) NOT_CDS_JAVA_HEAP_RETURN; |
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28363
diff
changeset
|
163 |
static bool copy_shared_string(GrowableArray<MemRegion> *string_space, |
46810
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
164 |
CompactStringTableWriter* ch_table) NOT_CDS_JAVA_HEAP_RETURN_(false); |
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
165 |
static oop create_archived_string(oop s, Thread* THREAD) NOT_CDS_JAVA_HEAP_RETURN_(NULL); |
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
166 |
static void write_to_archive(GrowableArray<MemRegion> *string_space) NOT_CDS_JAVA_HEAP_RETURN; |
7dad333205cd
8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents:
46746
diff
changeset
|
167 |
static void serialize(SerializeClosure* soc) NOT_CDS_JAVA_HEAP_RETURN; |
24426 | 168 |
|
169 |
// Rehash the symbol table if it gets out of balance |
|
170 |
static void rehash_table(); |
|
171 |
static bool needs_rehashing() { return _needs_rehashing; } |
|
172 |
||
173 |
// Parallel chunked scanning |
|
174 |
static void clear_parallel_claimed_index() { _parallel_claimed_idx = 0; } |
|
175 |
static int parallel_claimed_index() { return _parallel_claimed_idx; } |
|
176 |
}; |
|
177 |
#endif // SHARE_VM_CLASSFILE_STRINGTABLE_HPP |