1 /*
2 * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
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 *
39
40 private:
41 // The string table
42 static StringTable* _the_table;
43
44 // Shared string table
45 static CompactHashtable<oop, char> _shared_table;
46 static bool _ignore_shared_strings;
47
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
58 oop lookup_in_main_table(int index, jchar* chars, int length, unsigned int hashValue);
59 static oop lookup_shared(jchar* name, int len);
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);
64 // Unlink or apply the give oop closure to the entries to the buckets
65 // in the range [start_idx, end_idx).
66 static void buckets_unlink_or_oops_do(BoolObjectClosure* is_alive, OopClosure* f, int start_idx, int end_idx, int* processed, int* removed);
67
68 StringTable() : RehashableHashtable<oop, mtSymbol>((int)StringTableSize,
69 sizeof (HashtableEntry<oop, mtSymbol>)) {}
70
71 StringTable(HashtableBucket<mtSymbol>* t, int number_of_entries)
72 : RehashableHashtable<oop, mtSymbol>((int)StringTableSize, sizeof (HashtableEntry<oop, mtSymbol>), t,
73 number_of_entries) {}
74 public:
75 // The string table
76 static StringTable* the_table() { return _the_table; }
77
78 // Size of one bucket in the string table. Used when checking for rollover.
79 static uint bucket_size() { return sizeof(HashtableBucket<mtSymbol>); }
80
81 static void create_table() {
82 assert(_the_table == NULL, "One string table allowed.");
83 _the_table = new StringTable();
84 }
85
86 // GC support
87 // Delete pointers to otherwise-unreachable objects.
91 unlink_or_oops_do(cl, f, &processed, &removed);
92 }
93 static void unlink(BoolObjectClosure* cl) {
94 int processed = 0;
95 int removed = 0;
96 unlink_or_oops_do(cl, NULL, &processed, &removed);
97 }
98 static void unlink_or_oops_do(BoolObjectClosure* cl, OopClosure* f, int* processed, int* removed);
99 static void unlink(BoolObjectClosure* cl, int* processed, int* removed) {
100 unlink_or_oops_do(cl, NULL, processed, removed);
101 }
102 // Serially invoke "f->do_oop" on the locations of all oops in the table.
103 static void oops_do(OopClosure* f);
104
105 // Possibly parallel versions of the above
106 static void possibly_parallel_unlink_or_oops_do(BoolObjectClosure* cl, OopClosure* f, int* processed, int* removed);
107 static void possibly_parallel_unlink(BoolObjectClosure* cl, int* processed, int* removed) {
108 possibly_parallel_unlink_or_oops_do(cl, NULL, processed, removed);
109 }
110 static void possibly_parallel_oops_do(OopClosure* f);
111
112 // Hashing algorithm, used as the hash value used by the
113 // StringTable for bucket selection and comparison (stored in the
114 // HashtableEntry structures). This is used in the String.intern() method.
115 static unsigned int hash_string(const jchar* s, int len);
116 static unsigned int hash_string(oop string);
117
118 // Internal test.
119 static void test_alt_hash() PRODUCT_RETURN;
120
121 // Probing
122 static oop lookup(Symbol* symbol);
123 static oop lookup(jchar* chars, int length);
124
125 // Interning
126 static oop intern(Symbol* symbol, TRAPS);
127 static oop intern(oop string, TRAPS);
128 static oop intern(const char *utf8_string, TRAPS);
129
130 // Debugging
131 static void verify();
132 static void dump(outputStream* st, bool verbose=false);
133
134 enum VerifyMesgModes {
135 _verify_quietly = 0,
136 _verify_with_mesgs = 1
|
1 /*
2 * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
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 *
39
40 private:
41 // The string table
42 static StringTable* _the_table;
43
44 // Shared string table
45 static CompactHashtable<oop, char> _shared_table;
46 static bool _ignore_shared_strings;
47
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
58 oop lookup_in_main_table(int index, jchar* chars, int length, unsigned int hashValue);
59 static oop lookup_shared(jchar* name, int len, unsigned int hash);
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);
64 // Unlink or apply the give oop closure to the entries to the buckets
65 // in the range [start_idx, end_idx).
66 static void buckets_unlink_or_oops_do(BoolObjectClosure* is_alive, OopClosure* f, int start_idx, int end_idx, int* processed, int* removed);
67
68 // Hashing algorithm, used as the hash value used by the
69 // StringTable for bucket selection and comparison (stored in the
70 // HashtableEntry structures). This is used in the String.intern() method.
71 static unsigned int hash_string(const jchar* s, int len);
72 static unsigned int hash_string(oop string);
73 static unsigned int alt_hash_string(const jchar* s, int len);
74
75 StringTable() : RehashableHashtable<oop, mtSymbol>((int)StringTableSize,
76 sizeof (HashtableEntry<oop, mtSymbol>)) {}
77
78 StringTable(HashtableBucket<mtSymbol>* t, int number_of_entries)
79 : RehashableHashtable<oop, mtSymbol>((int)StringTableSize, sizeof (HashtableEntry<oop, mtSymbol>), t,
80 number_of_entries) {}
81 public:
82 // The string table
83 static StringTable* the_table() { return _the_table; }
84
85 // Size of one bucket in the string table. Used when checking for rollover.
86 static uint bucket_size() { return sizeof(HashtableBucket<mtSymbol>); }
87
88 static void create_table() {
89 assert(_the_table == NULL, "One string table allowed.");
90 _the_table = new StringTable();
91 }
92
93 // GC support
94 // Delete pointers to otherwise-unreachable objects.
98 unlink_or_oops_do(cl, f, &processed, &removed);
99 }
100 static void unlink(BoolObjectClosure* cl) {
101 int processed = 0;
102 int removed = 0;
103 unlink_or_oops_do(cl, NULL, &processed, &removed);
104 }
105 static void unlink_or_oops_do(BoolObjectClosure* cl, OopClosure* f, int* processed, int* removed);
106 static void unlink(BoolObjectClosure* cl, int* processed, int* removed) {
107 unlink_or_oops_do(cl, NULL, processed, removed);
108 }
109 // Serially invoke "f->do_oop" on the locations of all oops in the table.
110 static void oops_do(OopClosure* f);
111
112 // Possibly parallel versions of the above
113 static void possibly_parallel_unlink_or_oops_do(BoolObjectClosure* cl, OopClosure* f, int* processed, int* removed);
114 static void possibly_parallel_unlink(BoolObjectClosure* cl, int* processed, int* removed) {
115 possibly_parallel_unlink_or_oops_do(cl, NULL, processed, removed);
116 }
117 static void possibly_parallel_oops_do(OopClosure* f);
118
119 // Internal test.
120 static void test_alt_hash() PRODUCT_RETURN;
121
122 // Probing
123 static oop lookup(Symbol* symbol);
124 static oop lookup(jchar* chars, int length);
125
126 // Interning
127 static oop intern(Symbol* symbol, TRAPS);
128 static oop intern(oop string, TRAPS);
129 static oop intern(const char *utf8_string, TRAPS);
130
131 // Debugging
132 static void verify();
133 static void dump(outputStream* st, bool verbose=false);
134
135 enum VerifyMesgModes {
136 _verify_quietly = 0,
137 _verify_with_mesgs = 1
|