author | lfoltan |
Wed, 13 Feb 2019 15:50:08 -0500 | |
changeset 53746 | bdccafc038a2 |
parent 53731 | ee45b48c9e4a |
child 54133 | 829bf950287e |
permissions | -rw-r--r-- |
1 | 1 |
/* |
53156 | 2 |
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved. |
1 | 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 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4567
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4567
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4567
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
25 |
|
7397 | 26 |
#include "precompiled.hpp" |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
27 |
#include "classfile/altHashing.hpp" |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
28 |
#include "classfile/classLoaderData.hpp" |
52014
1aa9beac610e
8210754: print_location is not reliable enough (printing register info)
mdoerr
parents:
51997
diff
changeset
|
29 |
#include "gc/shared/collectedHeap.hpp" |
46746
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46492
diff
changeset
|
30 |
#include "logging/log.hpp" |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46492
diff
changeset
|
31 |
#include "logging/logStream.hpp" |
25351
7c198a690050
8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents:
22757
diff
changeset
|
32 |
#include "memory/allocation.inline.hpp" |
7c198a690050
8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents:
22757
diff
changeset
|
33 |
#include "memory/resourceArea.hpp" |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
34 |
#include "oops/symbol.hpp" |
40655
9f644073d3a0
8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents:
36570
diff
changeset
|
35 |
#include "runtime/atomic.hpp" |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
36 |
#include "runtime/os.hpp" |
1 | 37 |
|
51179
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
47216
diff
changeset
|
38 |
uint32_t Symbol::pack_length_and_refcount(int length, int refcount) { |
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
47216
diff
changeset
|
39 |
STATIC_ASSERT(max_symbol_length == ((1 << 16) - 1)); |
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
47216
diff
changeset
|
40 |
STATIC_ASSERT(PERM_REFCOUNT == ((1 << 16) - 1)); |
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
47216
diff
changeset
|
41 |
assert(length >= 0, "negative length"); |
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
47216
diff
changeset
|
42 |
assert(length <= max_symbol_length, "too long symbol"); |
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
47216
diff
changeset
|
43 |
assert(refcount >= 0, "negative refcount"); |
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
47216
diff
changeset
|
44 |
assert(refcount <= PERM_REFCOUNT, "invalid refcount"); |
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
47216
diff
changeset
|
45 |
uint32_t hi = length; |
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
47216
diff
changeset
|
46 |
uint32_t lo = refcount; |
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
47216
diff
changeset
|
47 |
return (hi << 16) | lo; |
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
47216
diff
changeset
|
48 |
} |
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
47216
diff
changeset
|
49 |
|
18438
9ea6bbfe0b83
8009575: Reduce Symbol::_refcount from 4 bytes to 2 bytes
iklam
parents:
17858
diff
changeset
|
50 |
Symbol::Symbol(const u1* name, int length, int refcount) { |
51179
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
47216
diff
changeset
|
51 |
_length_and_refcount = pack_length_and_refcount(length, refcount); |
32357
43087bc6dd04
8130115: REDO - Reduce Symbol::_identity_hash to 2 bytes
minqi
parents:
31616
diff
changeset
|
52 |
_identity_hash = (short)os::random(); |
51179
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
47216
diff
changeset
|
53 |
for (int i = 0; i < length; i++) { |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
54 |
byte_at_put(i, name[i]); |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
55 |
} |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
56 |
} |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
57 |
|
19696
bd5a0131bde1
8021954: VM SIGSEGV during classloading on MacOS; hs_err_pid file produced
coleenp
parents:
18438
diff
changeset
|
58 |
void* Symbol::operator new(size_t sz, int len, TRAPS) throw() { |
35898
ddc274f0052f
8145628: hotspot metadata classes shouldn't use HeapWordSize or heap related macros like align_object_size
coleenp
parents:
33468
diff
changeset
|
59 |
int alloc_size = size(len)*wordSize; |
13195 | 60 |
address res = (address) AllocateHeap(alloc_size, mtSymbol); |
12263
d20640f4f8fe
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
8921
diff
changeset
|
61 |
return res; |
d20640f4f8fe
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
8921
diff
changeset
|
62 |
} |
d20640f4f8fe
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
8921
diff
changeset
|
63 |
|
19696
bd5a0131bde1
8021954: VM SIGSEGV during classloading on MacOS; hs_err_pid file produced
coleenp
parents:
18438
diff
changeset
|
64 |
void* Symbol::operator new(size_t sz, int len, Arena* arena, TRAPS) throw() { |
35898
ddc274f0052f
8145628: hotspot metadata classes shouldn't use HeapWordSize or heap related macros like align_object_size
coleenp
parents:
33468
diff
changeset
|
65 |
int alloc_size = size(len)*wordSize; |
ddc274f0052f
8145628: hotspot metadata classes shouldn't use HeapWordSize or heap related macros like align_object_size
coleenp
parents:
33468
diff
changeset
|
66 |
address res = (address)arena->Amalloc_4(alloc_size); |
12263
d20640f4f8fe
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
8921
diff
changeset
|
67 |
return res; |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
68 |
} |
4567
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
768
diff
changeset
|
69 |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
70 |
void Symbol::operator delete(void *p) { |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
71 |
assert(((Symbol*)p)->refcount() == 0, "should not call this"); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
72 |
FreeHeap(p); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
73 |
} |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
74 |
|
4567
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
768
diff
changeset
|
75 |
// ------------------------------------------------------------------ |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
76 |
// Symbol::starts_with |
4567
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
768
diff
changeset
|
77 |
// |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
768
diff
changeset
|
78 |
// Tests if the symbol starts with the specified prefix of the given |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
768
diff
changeset
|
79 |
// length. |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
80 |
bool Symbol::starts_with(const char* prefix, int len) const { |
4567
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
768
diff
changeset
|
81 |
if (len > utf8_length()) return false; |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
768
diff
changeset
|
82 |
while (len-- > 0) { |
51997
9ce37fa2e179
8209138: Symbol constructor uses u1 as the element type of its name argument
hseigel
parents:
51405
diff
changeset
|
83 |
if (prefix[len] != char_at(len)) |
4567
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
768
diff
changeset
|
84 |
return false; |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
768
diff
changeset
|
85 |
} |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
768
diff
changeset
|
86 |
assert(len == -1, "we should be at the beginning"); |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
768
diff
changeset
|
87 |
return true; |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
768
diff
changeset
|
88 |
} |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
768
diff
changeset
|
89 |
|
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
768
diff
changeset
|
90 |
|
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
768
diff
changeset
|
91 |
// ------------------------------------------------------------------ |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
92 |
// Symbol::index_of |
4567
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
768
diff
changeset
|
93 |
// |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
768
diff
changeset
|
94 |
// Finds if the given string is a substring of this symbol's utf8 bytes. |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
768
diff
changeset
|
95 |
// Return -1 on failure. Otherwise return the first index where str occurs. |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
96 |
int Symbol::index_of_at(int i, const char* str, int len) const { |
4567
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
768
diff
changeset
|
97 |
assert(i >= 0 && i <= utf8_length(), "oob"); |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
768
diff
changeset
|
98 |
if (len <= 0) return 0; |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
768
diff
changeset
|
99 |
char first_char = str[0]; |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
100 |
address bytes = (address) ((Symbol*)this)->base(); |
4567
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
768
diff
changeset
|
101 |
address limit = bytes + utf8_length() - len; // inclusive limit |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
768
diff
changeset
|
102 |
address scan = bytes + i; |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
768
diff
changeset
|
103 |
if (scan > limit) |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
768
diff
changeset
|
104 |
return -1; |
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13195
diff
changeset
|
105 |
for (; scan <= limit; scan++) { |
4567
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
768
diff
changeset
|
106 |
scan = (address) memchr(scan, first_char, (limit + 1 - scan)); |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
768
diff
changeset
|
107 |
if (scan == NULL) |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
768
diff
changeset
|
108 |
return -1; // not found |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
768
diff
changeset
|
109 |
assert(scan >= bytes+i && scan <= limit, "scan oob"); |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
768
diff
changeset
|
110 |
if (memcmp(scan, str, len) == 0) |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
768
diff
changeset
|
111 |
return (int)(scan - bytes); |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
768
diff
changeset
|
112 |
} |
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13195
diff
changeset
|
113 |
return -1; |
4567
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
768
diff
changeset
|
114 |
} |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
768
diff
changeset
|
115 |
|
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
768
diff
changeset
|
116 |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
117 |
char* Symbol::as_C_string(char* buf, int size) const { |
1 | 118 |
if (size > 0) { |
119 |
int len = MIN2(size - 1, utf8_length()); |
|
120 |
for (int i = 0; i < len; i++) { |
|
51997
9ce37fa2e179
8209138: Symbol constructor uses u1 as the element type of its name argument
hseigel
parents:
51405
diff
changeset
|
121 |
buf[i] = char_at(i); |
1 | 122 |
} |
123 |
buf[len] = '\0'; |
|
124 |
} |
|
125 |
return buf; |
|
126 |
} |
|
127 |
||
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
128 |
char* Symbol::as_C_string() const { |
1 | 129 |
int len = utf8_length(); |
130 |
char* str = NEW_RESOURCE_ARRAY(char, len + 1); |
|
131 |
return as_C_string(str, len + 1); |
|
132 |
} |
|
133 |
||
33468
b82c87453d2d
8139996: CompileCommand prints quoted ascii strings
neliasso
parents:
32357
diff
changeset
|
134 |
void Symbol::print_utf8_on(outputStream* st) const { |
b82c87453d2d
8139996: CompileCommand prints quoted ascii strings
neliasso
parents:
32357
diff
changeset
|
135 |
st->print("%s", as_C_string()); |
b82c87453d2d
8139996: CompileCommand prints quoted ascii strings
neliasso
parents:
32357
diff
changeset
|
136 |
} |
b82c87453d2d
8139996: CompileCommand prints quoted ascii strings
neliasso
parents:
32357
diff
changeset
|
137 |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
138 |
void Symbol::print_symbol_on(outputStream* st) const { |
36570
9608a7830fe9
8149557: Resource mark breaks printing to string stream
goetz
parents:
35898
diff
changeset
|
139 |
char *s; |
1 | 140 |
st = st ? st : tty; |
36570
9608a7830fe9
8149557: Resource mark breaks printing to string stream
goetz
parents:
35898
diff
changeset
|
141 |
{ |
9608a7830fe9
8149557: Resource mark breaks printing to string stream
goetz
parents:
35898
diff
changeset
|
142 |
// ResourceMark may not affect st->print(). If st is a string |
9608a7830fe9
8149557: Resource mark breaks printing to string stream
goetz
parents:
35898
diff
changeset
|
143 |
// stream it could resize, using the same resource arena. |
9608a7830fe9
8149557: Resource mark breaks printing to string stream
goetz
parents:
35898
diff
changeset
|
144 |
ResourceMark rm; |
9608a7830fe9
8149557: Resource mark breaks printing to string stream
goetz
parents:
35898
diff
changeset
|
145 |
s = as_quoted_ascii(); |
9608a7830fe9
8149557: Resource mark breaks printing to string stream
goetz
parents:
35898
diff
changeset
|
146 |
s = os::strdup(s); |
9608a7830fe9
8149557: Resource mark breaks printing to string stream
goetz
parents:
35898
diff
changeset
|
147 |
} |
9608a7830fe9
8149557: Resource mark breaks printing to string stream
goetz
parents:
35898
diff
changeset
|
148 |
if (s == NULL) { |
9608a7830fe9
8149557: Resource mark breaks printing to string stream
goetz
parents:
35898
diff
changeset
|
149 |
st->print("(null)"); |
9608a7830fe9
8149557: Resource mark breaks printing to string stream
goetz
parents:
35898
diff
changeset
|
150 |
} else { |
9608a7830fe9
8149557: Resource mark breaks printing to string stream
goetz
parents:
35898
diff
changeset
|
151 |
st->print("%s", s); |
9608a7830fe9
8149557: Resource mark breaks printing to string stream
goetz
parents:
35898
diff
changeset
|
152 |
os::free(s); |
9608a7830fe9
8149557: Resource mark breaks printing to string stream
goetz
parents:
35898
diff
changeset
|
153 |
} |
14477
95e66ea71f71
6830717: replay of compilations would help with debugging
minqi
parents:
13728
diff
changeset
|
154 |
} |
95e66ea71f71
6830717: replay of compilations would help with debugging
minqi
parents:
13728
diff
changeset
|
155 |
|
95e66ea71f71
6830717: replay of compilations would help with debugging
minqi
parents:
13728
diff
changeset
|
156 |
char* Symbol::as_quoted_ascii() const { |
95e66ea71f71
6830717: replay of compilations would help with debugging
minqi
parents:
13728
diff
changeset
|
157 |
const char *ptr = (const char *)&_body[0]; |
95e66ea71f71
6830717: replay of compilations would help with debugging
minqi
parents:
13728
diff
changeset
|
158 |
int quoted_length = UTF8::quoted_ascii_length(ptr, utf8_length()); |
95e66ea71f71
6830717: replay of compilations would help with debugging
minqi
parents:
13728
diff
changeset
|
159 |
char* result = NEW_RESOURCE_ARRAY(char, quoted_length + 1); |
16602
5df51d3bc550
8011048: Possible reading from unmapped memory in UTF8::as_quoted_ascii()
iklam
parents:
15855
diff
changeset
|
160 |
UTF8::as_quoted_ascii(ptr, utf8_length(), result, quoted_length + 1); |
14477
95e66ea71f71
6830717: replay of compilations would help with debugging
minqi
parents:
13728
diff
changeset
|
161 |
return result; |
1 | 162 |
} |
163 |
||
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
164 |
jchar* Symbol::as_unicode(int& length) const { |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
165 |
Symbol* this_ptr = (Symbol*)this; |
1 | 166 |
length = UTF8::unicode_length((char*)this_ptr->bytes(), utf8_length()); |
167 |
jchar* result = NEW_RESOURCE_ARRAY(jchar, length); |
|
168 |
if (length > 0) { |
|
169 |
UTF8::convert_to_unicode((char*)this_ptr->bytes(), result, length); |
|
170 |
} |
|
171 |
return result; |
|
172 |
} |
|
173 |
||
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
174 |
const char* Symbol::as_klass_external_name(char* buf, int size) const { |
1 | 175 |
if (size > 0) { |
176 |
char* str = as_C_string(buf, size); |
|
177 |
int length = (int)strlen(str); |
|
178 |
// Turn all '/'s into '.'s (also for array klasses) |
|
179 |
for (int index = 0; index < length; index++) { |
|
180 |
if (str[index] == '/') { |
|
181 |
str[index] = '.'; |
|
182 |
} |
|
183 |
} |
|
184 |
return str; |
|
185 |
} else { |
|
186 |
return buf; |
|
187 |
} |
|
188 |
} |
|
189 |
||
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
190 |
const char* Symbol::as_klass_external_name() const { |
1 | 191 |
char* str = as_C_string(); |
192 |
int length = (int)strlen(str); |
|
193 |
// Turn all '/'s into '.'s (also for array klasses) |
|
194 |
for (int index = 0; index < length; index++) { |
|
195 |
if (str[index] == '/') { |
|
196 |
str[index] = '.'; |
|
197 |
} |
|
198 |
} |
|
199 |
return str; |
|
200 |
} |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
201 |
|
51179
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
47216
diff
changeset
|
202 |
// Increment refcount while checking for zero. If the Symbol's refcount becomes zero |
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
47216
diff
changeset
|
203 |
// a thread could be concurrently removing the Symbol. This is used during SymbolTable |
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
47216
diff
changeset
|
204 |
// lookup to avoid reviving a dead Symbol. |
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
47216
diff
changeset
|
205 |
bool Symbol::try_increment_refcount() { |
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
47216
diff
changeset
|
206 |
uint32_t found = _length_and_refcount; |
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
47216
diff
changeset
|
207 |
while (true) { |
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
47216
diff
changeset
|
208 |
uint32_t old_value = found; |
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
47216
diff
changeset
|
209 |
int refc = extract_refcount(old_value); |
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
47216
diff
changeset
|
210 |
if (refc == PERM_REFCOUNT) { |
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
47216
diff
changeset
|
211 |
return true; // sticky max or created permanent |
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
47216
diff
changeset
|
212 |
} else if (refc == 0) { |
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
47216
diff
changeset
|
213 |
return false; // dead, can't revive. |
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
47216
diff
changeset
|
214 |
} else { |
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
47216
diff
changeset
|
215 |
found = Atomic::cmpxchg(old_value + 1, &_length_and_refcount, old_value); |
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
47216
diff
changeset
|
216 |
if (found == old_value) { |
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
47216
diff
changeset
|
217 |
return true; // successfully updated. |
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
47216
diff
changeset
|
218 |
} |
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
47216
diff
changeset
|
219 |
// refcount changed, try again. |
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
47216
diff
changeset
|
220 |
} |
15855
2ac9ebea17f3
8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents:
15471
diff
changeset
|
221 |
} |
2ac9ebea17f3
8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents:
15471
diff
changeset
|
222 |
} |
2ac9ebea17f3
8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents:
15471
diff
changeset
|
223 |
|
51179
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
47216
diff
changeset
|
224 |
// The increment_refcount() is called when not doing lookup. It is assumed that you |
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
47216
diff
changeset
|
225 |
// have a symbol with a non-zero refcount and it can't become zero while referenced by |
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
47216
diff
changeset
|
226 |
// this caller. |
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
47216
diff
changeset
|
227 |
void Symbol::increment_refcount() { |
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
47216
diff
changeset
|
228 |
if (!try_increment_refcount()) { |
15855
2ac9ebea17f3
8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents:
15471
diff
changeset
|
229 |
#ifdef ASSERT |
51179
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
47216
diff
changeset
|
230 |
print(); |
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
47216
diff
changeset
|
231 |
fatal("refcount has gone to zero"); |
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
47216
diff
changeset
|
232 |
#endif |
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
47216
diff
changeset
|
233 |
} |
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
47216
diff
changeset
|
234 |
#ifndef PRODUCT |
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
47216
diff
changeset
|
235 |
if (refcount() != PERM_REFCOUNT) { // not a permanent symbol |
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
47216
diff
changeset
|
236 |
NOT_PRODUCT(Atomic::inc(&_total_count);) |
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
47216
diff
changeset
|
237 |
} |
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
47216
diff
changeset
|
238 |
#endif |
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
47216
diff
changeset
|
239 |
} |
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
47216
diff
changeset
|
240 |
|
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
47216
diff
changeset
|
241 |
// Decrement refcount potentially while racing increment, so we need |
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
47216
diff
changeset
|
242 |
// to check the value after attempting to decrement so that if another |
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
47216
diff
changeset
|
243 |
// thread increments to PERM_REFCOUNT the value is not decremented. |
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
47216
diff
changeset
|
244 |
void Symbol::decrement_refcount() { |
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
47216
diff
changeset
|
245 |
uint32_t found = _length_and_refcount; |
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
47216
diff
changeset
|
246 |
while (true) { |
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
47216
diff
changeset
|
247 |
uint32_t old_value = found; |
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
47216
diff
changeset
|
248 |
int refc = extract_refcount(old_value); |
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
47216
diff
changeset
|
249 |
if (refc == PERM_REFCOUNT) { |
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
47216
diff
changeset
|
250 |
return; // refcount is permanent, permanent is sticky |
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
47216
diff
changeset
|
251 |
} else if (refc == 0) { |
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
47216
diff
changeset
|
252 |
#ifdef ASSERT |
15855
2ac9ebea17f3
8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents:
15471
diff
changeset
|
253 |
print(); |
51179
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
47216
diff
changeset
|
254 |
fatal("refcount underflow"); |
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
47216
diff
changeset
|
255 |
#endif |
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
47216
diff
changeset
|
256 |
return; |
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
47216
diff
changeset
|
257 |
} else { |
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
47216
diff
changeset
|
258 |
found = Atomic::cmpxchg(old_value - 1, &_length_and_refcount, old_value); |
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
47216
diff
changeset
|
259 |
if (found == old_value) { |
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
47216
diff
changeset
|
260 |
return; // successfully updated. |
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
47216
diff
changeset
|
261 |
} |
516acf6956a2
8207359: Make SymbolTable increment_refcount disallow zero
coleenp
parents:
47216
diff
changeset
|
262 |
// refcount changed, try again. |
15855
2ac9ebea17f3
8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents:
15471
diff
changeset
|
263 |
} |
2ac9ebea17f3
8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents:
15471
diff
changeset
|
264 |
} |
2ac9ebea17f3
8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents:
15471
diff
changeset
|
265 |
} |
2ac9ebea17f3
8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents:
15471
diff
changeset
|
266 |
|
46746
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46492
diff
changeset
|
267 |
void Symbol::metaspace_pointers_do(MetaspaceClosure* it) { |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46492
diff
changeset
|
268 |
if (log_is_enabled(Trace, cds)) { |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46492
diff
changeset
|
269 |
LogStream trace_stream(Log(cds)::trace()); |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46492
diff
changeset
|
270 |
trace_stream.print("Iter(Symbol): %p ", this); |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46492
diff
changeset
|
271 |
print_value_on(&trace_stream); |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46492
diff
changeset
|
272 |
trace_stream.cr(); |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46492
diff
changeset
|
273 |
} |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46492
diff
changeset
|
274 |
} |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46492
diff
changeset
|
275 |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
276 |
void Symbol::print_on(outputStream* st) const { |
52190
4e04b7ab20a3
8209087: Clean up runtime code that compares 'this' to NULL
hseigel
parents:
52014
diff
changeset
|
277 |
st->print("Symbol: '"); |
4e04b7ab20a3
8209087: Clean up runtime code that compares 'this' to NULL
hseigel
parents:
52014
diff
changeset
|
278 |
print_symbol_on(st); |
4e04b7ab20a3
8209087: Clean up runtime code that compares 'this' to NULL
hseigel
parents:
52014
diff
changeset
|
279 |
st->print("'"); |
4e04b7ab20a3
8209087: Clean up runtime code that compares 'this' to NULL
hseigel
parents:
52014
diff
changeset
|
280 |
st->print(" count %d", refcount()); |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
281 |
} |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
282 |
|
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
283 |
// The print_value functions are present in all builds, to support the |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
284 |
// disassembler and error reporting. |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
285 |
void Symbol::print_value_on(outputStream* st) const { |
52190
4e04b7ab20a3
8209087: Clean up runtime code that compares 'this' to NULL
hseigel
parents:
52014
diff
changeset
|
286 |
st->print("'"); |
4e04b7ab20a3
8209087: Clean up runtime code that compares 'this' to NULL
hseigel
parents:
52014
diff
changeset
|
287 |
for (int i = 0; i < utf8_length(); i++) { |
4e04b7ab20a3
8209087: Clean up runtime code that compares 'this' to NULL
hseigel
parents:
52014
diff
changeset
|
288 |
st->print("%c", char_at(i)); |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
289 |
} |
52190
4e04b7ab20a3
8209087: Clean up runtime code that compares 'this' to NULL
hseigel
parents:
52014
diff
changeset
|
290 |
st->print("'"); |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
291 |
} |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
292 |
|
52014
1aa9beac610e
8210754: print_location is not reliable enough (printing register info)
mdoerr
parents:
51997
diff
changeset
|
293 |
bool Symbol::is_valid(Symbol* s) { |
1aa9beac610e
8210754: print_location is not reliable enough (printing register info)
mdoerr
parents:
51997
diff
changeset
|
294 |
if (!is_aligned(s, sizeof(MetaWord))) return false; |
1aa9beac610e
8210754: print_location is not reliable enough (printing register info)
mdoerr
parents:
51997
diff
changeset
|
295 |
if ((size_t)s < os::min_page_size()) return false; |
1aa9beac610e
8210754: print_location is not reliable enough (printing register info)
mdoerr
parents:
51997
diff
changeset
|
296 |
|
1aa9beac610e
8210754: print_location is not reliable enough (printing register info)
mdoerr
parents:
51997
diff
changeset
|
297 |
if (!os::is_readable_range(s, s + 1)) return false; |
1aa9beac610e
8210754: print_location is not reliable enough (printing register info)
mdoerr
parents:
51997
diff
changeset
|
298 |
|
1aa9beac610e
8210754: print_location is not reliable enough (printing register info)
mdoerr
parents:
51997
diff
changeset
|
299 |
// Symbols are not allocated in Java heap. |
1aa9beac610e
8210754: print_location is not reliable enough (printing register info)
mdoerr
parents:
51997
diff
changeset
|
300 |
if (Universe::heap()->is_in_reserved(s)) return false; |
1aa9beac610e
8210754: print_location is not reliable enough (printing register info)
mdoerr
parents:
51997
diff
changeset
|
301 |
|
1aa9beac610e
8210754: print_location is not reliable enough (printing register info)
mdoerr
parents:
51997
diff
changeset
|
302 |
int len = s->utf8_length(); |
1aa9beac610e
8210754: print_location is not reliable enough (printing register info)
mdoerr
parents:
51997
diff
changeset
|
303 |
if (len < 0) return false; |
1aa9beac610e
8210754: print_location is not reliable enough (printing register info)
mdoerr
parents:
51997
diff
changeset
|
304 |
|
1aa9beac610e
8210754: print_location is not reliable enough (printing register info)
mdoerr
parents:
51997
diff
changeset
|
305 |
jbyte* bytes = (jbyte*) s->bytes(); |
1aa9beac610e
8210754: print_location is not reliable enough (printing register info)
mdoerr
parents:
51997
diff
changeset
|
306 |
return os::is_readable_range(bytes, bytes + len); |
1aa9beac610e
8210754: print_location is not reliable enough (printing register info)
mdoerr
parents:
51997
diff
changeset
|
307 |
} |
1aa9beac610e
8210754: print_location is not reliable enough (printing register info)
mdoerr
parents:
51997
diff
changeset
|
308 |
|
12263
d20640f4f8fe
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
8921
diff
changeset
|
309 |
// SymbolTable prints this in its statistics |
51405
8b23aa7cef47
8195100: Use a low latency hashtable for SymbolTable
gziemski
parents:
51179
diff
changeset
|
310 |
NOT_PRODUCT(size_t Symbol::_total_count = 0;) |