author | prr |
Thu, 16 Mar 2017 09:50:59 -0700 | |
changeset 44307 | 8f905d7d01d8 |
parent 40860 | 34163901ad5f |
child 46492 | 5848b57c9dc5 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
35898
ddc274f0052f
8145628: hotspot metadata classes shouldn't use HeapWordSize or heap related macros like align_object_size
coleenp
parents:
33468
diff
changeset
|
2 |
* Copyright (c) 1997, 2016, 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" |
25351
7c198a690050
8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents:
22757
diff
changeset
|
29 |
#include "memory/allocation.inline.hpp" |
7c198a690050
8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents:
22757
diff
changeset
|
30 |
#include "memory/resourceArea.hpp" |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
31 |
#include "oops/symbol.hpp" |
40655
9f644073d3a0
8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents:
36570
diff
changeset
|
32 |
#include "runtime/atomic.hpp" |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
33 |
#include "runtime/os.hpp" |
1 | 34 |
|
18438
9ea6bbfe0b83
8009575: Reduce Symbol::_refcount from 4 bytes to 2 bytes
iklam
parents:
17858
diff
changeset
|
35 |
Symbol::Symbol(const u1* name, int length, int refcount) { |
9ea6bbfe0b83
8009575: Reduce Symbol::_refcount from 4 bytes to 2 bytes
iklam
parents:
17858
diff
changeset
|
36 |
_refcount = refcount; |
9ea6bbfe0b83
8009575: Reduce Symbol::_refcount from 4 bytes to 2 bytes
iklam
parents:
17858
diff
changeset
|
37 |
_length = length; |
32357
43087bc6dd04
8130115: REDO - Reduce Symbol::_identity_hash to 2 bytes
minqi
parents:
31616
diff
changeset
|
38 |
_identity_hash = (short)os::random(); |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
39 |
for (int i = 0; i < _length; i++) { |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
40 |
byte_at_put(i, name[i]); |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
41 |
} |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
42 |
} |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
43 |
|
19696
bd5a0131bde1
8021954: VM SIGSEGV during classloading on MacOS; hs_err_pid file produced
coleenp
parents:
18438
diff
changeset
|
44 |
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
|
45 |
int alloc_size = size(len)*wordSize; |
13195 | 46 |
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
|
47 |
return res; |
d20640f4f8fe
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
8921
diff
changeset
|
48 |
} |
d20640f4f8fe
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
8921
diff
changeset
|
49 |
|
19696
bd5a0131bde1
8021954: VM SIGSEGV during classloading on MacOS; hs_err_pid file produced
coleenp
parents:
18438
diff
changeset
|
50 |
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
|
51 |
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
|
52 |
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
|
53 |
return res; |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
54 |
} |
4567
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
768
diff
changeset
|
55 |
|
19696
bd5a0131bde1
8021954: VM SIGSEGV during classloading on MacOS; hs_err_pid file produced
coleenp
parents:
18438
diff
changeset
|
56 |
void* Symbol::operator new(size_t sz, int len, ClassLoaderData* loader_data, TRAPS) throw() { |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
57 |
address res; |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
58 |
res = (address) Metaspace::allocate(loader_data, size(len), true, |
17858
c292f8791cca
8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents:
16602
diff
changeset
|
59 |
MetaspaceObj::SymbolType, CHECK_NULL); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
60 |
return res; |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
61 |
} |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
62 |
|
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
63 |
void Symbol::operator delete(void *p) { |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
64 |
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
|
65 |
FreeHeap(p); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
66 |
} |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
67 |
|
4567
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
768
diff
changeset
|
68 |
// ------------------------------------------------------------------ |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
69 |
// Symbol::equals |
4567
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
768
diff
changeset
|
70 |
// |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
768
diff
changeset
|
71 |
// Compares the symbol with a string of the given length. |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
72 |
bool Symbol::equals(const char* str, int len) const { |
1 | 73 |
int l = utf8_length(); |
74 |
if (l != len) return false; |
|
75 |
while (l-- > 0) { |
|
76 |
if (str[l] != (char) byte_at(l)) |
|
77 |
return false; |
|
78 |
} |
|
79 |
assert(l == -1, "we should be at the beginning"); |
|
80 |
return true; |
|
81 |
} |
|
82 |
||
4567
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
768
diff
changeset
|
83 |
|
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
768
diff
changeset
|
84 |
// ------------------------------------------------------------------ |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
85 |
// Symbol::starts_with |
4567
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
768
diff
changeset
|
86 |
// |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
768
diff
changeset
|
87 |
// 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
|
88 |
// length. |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
89 |
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
|
90 |
if (len > utf8_length()) return false; |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
768
diff
changeset
|
91 |
while (len-- > 0) { |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
768
diff
changeset
|
92 |
if (prefix[len] != (char) byte_at(len)) |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
768
diff
changeset
|
93 |
return false; |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
768
diff
changeset
|
94 |
} |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
768
diff
changeset
|
95 |
assert(len == -1, "we should be at the beginning"); |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
768
diff
changeset
|
96 |
return true; |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
768
diff
changeset
|
97 |
} |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
768
diff
changeset
|
98 |
|
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
768
diff
changeset
|
99 |
|
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
768
diff
changeset
|
100 |
// ------------------------------------------------------------------ |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
101 |
// Symbol::index_of |
4567
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
768
diff
changeset
|
102 |
// |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
768
diff
changeset
|
103 |
// 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
|
104 |
// 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
|
105 |
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
|
106 |
assert(i >= 0 && i <= utf8_length(), "oob"); |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
768
diff
changeset
|
107 |
if (len <= 0) return 0; |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
768
diff
changeset
|
108 |
char first_char = str[0]; |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
109 |
address bytes = (address) ((Symbol*)this)->base(); |
4567
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
768
diff
changeset
|
110 |
address limit = bytes + utf8_length() - len; // inclusive limit |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
768
diff
changeset
|
111 |
address scan = bytes + i; |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
768
diff
changeset
|
112 |
if (scan > limit) |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
768
diff
changeset
|
113 |
return -1; |
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13195
diff
changeset
|
114 |
for (; scan <= limit; scan++) { |
4567
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
768
diff
changeset
|
115 |
scan = (address) memchr(scan, first_char, (limit + 1 - scan)); |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
768
diff
changeset
|
116 |
if (scan == NULL) |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
768
diff
changeset
|
117 |
return -1; // not found |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
768
diff
changeset
|
118 |
assert(scan >= bytes+i && scan <= limit, "scan oob"); |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
768
diff
changeset
|
119 |
if (memcmp(scan, str, len) == 0) |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
768
diff
changeset
|
120 |
return (int)(scan - bytes); |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
768
diff
changeset
|
121 |
} |
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13195
diff
changeset
|
122 |
return -1; |
4567
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
768
diff
changeset
|
123 |
} |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
768
diff
changeset
|
124 |
|
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
768
diff
changeset
|
125 |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
126 |
char* Symbol::as_C_string(char* buf, int size) const { |
1 | 127 |
if (size > 0) { |
128 |
int len = MIN2(size - 1, utf8_length()); |
|
129 |
for (int i = 0; i < len; i++) { |
|
130 |
buf[i] = byte_at(i); |
|
131 |
} |
|
132 |
buf[len] = '\0'; |
|
133 |
} |
|
134 |
return buf; |
|
135 |
} |
|
136 |
||
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
137 |
char* Symbol::as_C_string() const { |
1 | 138 |
int len = utf8_length(); |
139 |
char* str = NEW_RESOURCE_ARRAY(char, len + 1); |
|
140 |
return as_C_string(str, len + 1); |
|
141 |
} |
|
142 |
||
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
143 |
char* Symbol::as_C_string_flexible_buffer(Thread* t, |
1 | 144 |
char* buf, int size) const { |
145 |
char* str; |
|
146 |
int len = utf8_length(); |
|
147 |
int buf_len = len + 1; |
|
148 |
if (size < buf_len) { |
|
149 |
str = NEW_RESOURCE_ARRAY(char, buf_len); |
|
150 |
} else { |
|
151 |
str = buf; |
|
152 |
} |
|
153 |
return as_C_string(str, buf_len); |
|
154 |
} |
|
155 |
||
33468
b82c87453d2d
8139996: CompileCommand prints quoted ascii strings
neliasso
parents:
32357
diff
changeset
|
156 |
void Symbol::print_utf8_on(outputStream* st) const { |
b82c87453d2d
8139996: CompileCommand prints quoted ascii strings
neliasso
parents:
32357
diff
changeset
|
157 |
st->print("%s", as_C_string()); |
b82c87453d2d
8139996: CompileCommand prints quoted ascii strings
neliasso
parents:
32357
diff
changeset
|
158 |
} |
b82c87453d2d
8139996: CompileCommand prints quoted ascii strings
neliasso
parents:
32357
diff
changeset
|
159 |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
160 |
void Symbol::print_symbol_on(outputStream* st) const { |
36570
9608a7830fe9
8149557: Resource mark breaks printing to string stream
goetz
parents:
35898
diff
changeset
|
161 |
char *s; |
1 | 162 |
st = st ? st : tty; |
36570
9608a7830fe9
8149557: Resource mark breaks printing to string stream
goetz
parents:
35898
diff
changeset
|
163 |
{ |
9608a7830fe9
8149557: Resource mark breaks printing to string stream
goetz
parents:
35898
diff
changeset
|
164 |
// 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
|
165 |
// stream it could resize, using the same resource arena. |
9608a7830fe9
8149557: Resource mark breaks printing to string stream
goetz
parents:
35898
diff
changeset
|
166 |
ResourceMark rm; |
9608a7830fe9
8149557: Resource mark breaks printing to string stream
goetz
parents:
35898
diff
changeset
|
167 |
s = as_quoted_ascii(); |
9608a7830fe9
8149557: Resource mark breaks printing to string stream
goetz
parents:
35898
diff
changeset
|
168 |
s = os::strdup(s); |
9608a7830fe9
8149557: Resource mark breaks printing to string stream
goetz
parents:
35898
diff
changeset
|
169 |
} |
9608a7830fe9
8149557: Resource mark breaks printing to string stream
goetz
parents:
35898
diff
changeset
|
170 |
if (s == NULL) { |
9608a7830fe9
8149557: Resource mark breaks printing to string stream
goetz
parents:
35898
diff
changeset
|
171 |
st->print("(null)"); |
9608a7830fe9
8149557: Resource mark breaks printing to string stream
goetz
parents:
35898
diff
changeset
|
172 |
} else { |
9608a7830fe9
8149557: Resource mark breaks printing to string stream
goetz
parents:
35898
diff
changeset
|
173 |
st->print("%s", s); |
9608a7830fe9
8149557: Resource mark breaks printing to string stream
goetz
parents:
35898
diff
changeset
|
174 |
os::free(s); |
9608a7830fe9
8149557: Resource mark breaks printing to string stream
goetz
parents:
35898
diff
changeset
|
175 |
} |
14477
95e66ea71f71
6830717: replay of compilations would help with debugging
minqi
parents:
13728
diff
changeset
|
176 |
} |
95e66ea71f71
6830717: replay of compilations would help with debugging
minqi
parents:
13728
diff
changeset
|
177 |
|
95e66ea71f71
6830717: replay of compilations would help with debugging
minqi
parents:
13728
diff
changeset
|
178 |
char* Symbol::as_quoted_ascii() const { |
95e66ea71f71
6830717: replay of compilations would help with debugging
minqi
parents:
13728
diff
changeset
|
179 |
const char *ptr = (const char *)&_body[0]; |
95e66ea71f71
6830717: replay of compilations would help with debugging
minqi
parents:
13728
diff
changeset
|
180 |
int quoted_length = UTF8::quoted_ascii_length(ptr, utf8_length()); |
95e66ea71f71
6830717: replay of compilations would help with debugging
minqi
parents:
13728
diff
changeset
|
181 |
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
|
182 |
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
|
183 |
return result; |
1 | 184 |
} |
185 |
||
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
186 |
jchar* Symbol::as_unicode(int& length) const { |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
187 |
Symbol* this_ptr = (Symbol*)this; |
1 | 188 |
length = UTF8::unicode_length((char*)this_ptr->bytes(), utf8_length()); |
189 |
jchar* result = NEW_RESOURCE_ARRAY(jchar, length); |
|
190 |
if (length > 0) { |
|
191 |
UTF8::convert_to_unicode((char*)this_ptr->bytes(), result, length); |
|
192 |
} |
|
193 |
return result; |
|
194 |
} |
|
195 |
||
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
196 |
const char* Symbol::as_klass_external_name(char* buf, int size) const { |
1 | 197 |
if (size > 0) { |
198 |
char* str = as_C_string(buf, size); |
|
199 |
int length = (int)strlen(str); |
|
200 |
// Turn all '/'s into '.'s (also for array klasses) |
|
201 |
for (int index = 0; index < length; index++) { |
|
202 |
if (str[index] == '/') { |
|
203 |
str[index] = '.'; |
|
204 |
} |
|
205 |
} |
|
206 |
return str; |
|
207 |
} else { |
|
208 |
return buf; |
|
209 |
} |
|
210 |
} |
|
211 |
||
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
212 |
const char* Symbol::as_klass_external_name() const { |
1 | 213 |
char* str = as_C_string(); |
214 |
int length = (int)strlen(str); |
|
215 |
// Turn all '/'s into '.'s (also for array klasses) |
|
216 |
for (int index = 0; index < length; index++) { |
|
217 |
if (str[index] == '/') { |
|
218 |
str[index] = '.'; |
|
219 |
} |
|
220 |
} |
|
221 |
return str; |
|
222 |
} |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
223 |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
224 |
// Alternate hashing for unbalanced symbol tables. |
22757
b2cbb3680b4f
8033792: AltHashing used jint for imprecise bit shifting
minqi
parents:
19696
diff
changeset
|
225 |
unsigned int Symbol::new_hash(juint seed) { |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
226 |
ResourceMark rm; |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
227 |
// Use alternate hashing algorithm on this symbol. |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
228 |
return AltHashing::murmur3_32(seed, (const jbyte*)as_C_string(), utf8_length()); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
229 |
} |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
230 |
|
15855
2ac9ebea17f3
8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents:
15471
diff
changeset
|
231 |
void Symbol::increment_refcount() { |
40860
34163901ad5f
8161280: assert failed: reference count underflow for symbol
iklam
parents:
40655
diff
changeset
|
232 |
// Only increment the refcount if non-negative. If negative either |
15855
2ac9ebea17f3
8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents:
15471
diff
changeset
|
233 |
// overflow has occurred or it is a permanent symbol in a read only |
2ac9ebea17f3
8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents:
15471
diff
changeset
|
234 |
// shared archive. |
40860
34163901ad5f
8161280: assert failed: reference count underflow for symbol
iklam
parents:
40655
diff
changeset
|
235 |
if (_refcount >= 0) { // not a permanent symbol |
15855
2ac9ebea17f3
8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents:
15471
diff
changeset
|
236 |
Atomic::inc(&_refcount); |
2ac9ebea17f3
8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents:
15471
diff
changeset
|
237 |
NOT_PRODUCT(Atomic::inc(&_total_count);) |
2ac9ebea17f3
8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents:
15471
diff
changeset
|
238 |
} |
2ac9ebea17f3
8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents:
15471
diff
changeset
|
239 |
} |
2ac9ebea17f3
8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents:
15471
diff
changeset
|
240 |
|
2ac9ebea17f3
8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents:
15471
diff
changeset
|
241 |
void Symbol::decrement_refcount() { |
40860
34163901ad5f
8161280: assert failed: reference count underflow for symbol
iklam
parents:
40655
diff
changeset
|
242 |
if (_refcount >= 0) { // not a permanent symbol |
34163901ad5f
8161280: assert failed: reference count underflow for symbol
iklam
parents:
40655
diff
changeset
|
243 |
jshort new_value = Atomic::add(-1, &_refcount); |
15855
2ac9ebea17f3
8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents:
15471
diff
changeset
|
244 |
#ifdef ASSERT |
40860
34163901ad5f
8161280: assert failed: reference count underflow for symbol
iklam
parents:
40655
diff
changeset
|
245 |
if (new_value == -1) { // we have transitioned from 0 -> -1 |
15855
2ac9ebea17f3
8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents:
15471
diff
changeset
|
246 |
print(); |
2ac9ebea17f3
8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents:
15471
diff
changeset
|
247 |
assert(false, "reference count underflow for symbol"); |
2ac9ebea17f3
8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents:
15471
diff
changeset
|
248 |
} |
2ac9ebea17f3
8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents:
15471
diff
changeset
|
249 |
#endif |
40860
34163901ad5f
8161280: assert failed: reference count underflow for symbol
iklam
parents:
40655
diff
changeset
|
250 |
(void)new_value; |
15855
2ac9ebea17f3
8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents:
15471
diff
changeset
|
251 |
} |
2ac9ebea17f3
8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents:
15471
diff
changeset
|
252 |
} |
2ac9ebea17f3
8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents:
15471
diff
changeset
|
253 |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
254 |
void Symbol::print_on(outputStream* st) const { |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
255 |
if (this == NULL) { |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
256 |
st->print_cr("NULL"); |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
257 |
} else { |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
258 |
st->print("Symbol: '"); |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
259 |
print_symbol_on(st); |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
260 |
st->print("'"); |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
261 |
st->print(" count %d", refcount()); |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
262 |
} |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
263 |
} |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
264 |
|
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
265 |
// 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
|
266 |
// disassembler and error reporting. |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
267 |
void Symbol::print_value_on(outputStream* st) const { |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
268 |
if (this == NULL) { |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
269 |
st->print("NULL"); |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
270 |
} else { |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
271 |
st->print("'"); |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
272 |
for (int i = 0; i < utf8_length(); i++) { |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
273 |
st->print("%c", byte_at(i)); |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
274 |
} |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
275 |
st->print("'"); |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
276 |
} |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
277 |
} |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
278 |
|
12263
d20640f4f8fe
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
8921
diff
changeset
|
279 |
// SymbolTable prints this in its statistics |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
280 |
NOT_PRODUCT(int Symbol::_total_count = 0;) |