Mercurial > hg > graal-compiler
annotate src/share/vm/oops/symbol.cpp @ 6231:7e5976e66c62
7182543: NMT ON: Aggregate a few NMT related bugs
Summary: 1) Fixed MemTrackWorker::generations_in_used() calculation 2) Ensured NMT not to leak memory recorders after shutdown 3) Used ThreadCritical to block safepoint safe threads
Reviewed-by: acorn, coleenp, dholmes, kvn
author | zgu |
---|---|
date | Thu, 19 Jul 2012 09:05:42 -0400 |
parents | d2a62e0f25eb |
children | 1d7922586cf6 |
rev | line source |
---|---|
0 | 1 /* |
5979
fc9d8850ab8b
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
2426
diff
changeset
|
2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. |
0 | 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 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1138
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1138
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1138
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
25 |
1972 | 26 #include "precompiled.hpp" |
27 #include "oops/oop.inline.hpp" | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
28 #include "oops/symbol.hpp" |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
29 #include "runtime/os.hpp" |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
30 #include "memory/allocation.inline.hpp" |
0 | 31 |
5979
fc9d8850ab8b
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
2426
diff
changeset
|
32 Symbol::Symbol(const u1* name, int length, int refcount) : _refcount(refcount), _length(length) { |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
33 _identity_hash = os::random(); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
34 for (int i = 0; i < _length; i++) { |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
35 byte_at_put(i, name[i]); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
36 } |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
37 } |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
38 |
5979
fc9d8850ab8b
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
2426
diff
changeset
|
39 void* Symbol::operator new(size_t sz, int len, TRAPS) { |
fc9d8850ab8b
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
2426
diff
changeset
|
40 int alloc_size = object_size(len)*HeapWordSize; |
6197 | 41 address res = (address) AllocateHeap(alloc_size, mtSymbol); |
5979
fc9d8850ab8b
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
2426
diff
changeset
|
42 DEBUG_ONLY(set_allocation_type(res, ResourceObj::C_HEAP);) |
fc9d8850ab8b
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
2426
diff
changeset
|
43 return res; |
fc9d8850ab8b
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
2426
diff
changeset
|
44 } |
fc9d8850ab8b
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
2426
diff
changeset
|
45 |
fc9d8850ab8b
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
2426
diff
changeset
|
46 void* Symbol::operator new(size_t sz, int len, Arena* arena, TRAPS) { |
fc9d8850ab8b
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
2426
diff
changeset
|
47 int alloc_size = object_size(len)*HeapWordSize; |
fc9d8850ab8b
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
2426
diff
changeset
|
48 address res = (address)arena->Amalloc(alloc_size); |
fc9d8850ab8b
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
2426
diff
changeset
|
49 DEBUG_ONLY(set_allocation_type(res, ResourceObj::ARENA);) |
fc9d8850ab8b
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
2426
diff
changeset
|
50 return res; |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
51 } |
1138
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
52 |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
53 // ------------------------------------------------------------------ |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
54 // Symbol::equals |
1138
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
55 // |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
56 // Compares the symbol with a string of the given length. |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
57 bool Symbol::equals(const char* str, int len) const { |
0 | 58 int l = utf8_length(); |
59 if (l != len) return false; | |
60 while (l-- > 0) { | |
61 if (str[l] != (char) byte_at(l)) | |
62 return false; | |
63 } | |
64 assert(l == -1, "we should be at the beginning"); | |
65 return true; | |
66 } | |
67 | |
1138
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
68 |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
69 // ------------------------------------------------------------------ |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
70 // Symbol::starts_with |
1138
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
71 // |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
72 // Tests if the symbol starts with the specified prefix of the given |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
73 // length. |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
74 bool Symbol::starts_with(const char* prefix, int len) const { |
1138
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
75 if (len > utf8_length()) return false; |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
76 while (len-- > 0) { |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
77 if (prefix[len] != (char) byte_at(len)) |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
78 return false; |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
79 } |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
80 assert(len == -1, "we should be at the beginning"); |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
81 return true; |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
82 } |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
83 |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
84 |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
85 // ------------------------------------------------------------------ |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
86 // Symbol::index_of |
1138
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
87 // |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
88 // Finds if the given string is a substring of this symbol's utf8 bytes. |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
89 // Return -1 on failure. Otherwise return the first index where str occurs. |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
90 int Symbol::index_of_at(int i, const char* str, int len) const { |
1138
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
91 assert(i >= 0 && i <= utf8_length(), "oob"); |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
92 if (len <= 0) return 0; |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
93 char first_char = str[0]; |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
94 address bytes = (address) ((Symbol*)this)->base(); |
1138
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
95 address limit = bytes + utf8_length() - len; // inclusive limit |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
96 address scan = bytes + i; |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
97 if (scan > limit) |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
98 return -1; |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
99 for (;;) { |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
100 scan = (address) memchr(scan, first_char, (limit + 1 - scan)); |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
101 if (scan == NULL) |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
102 return -1; // not found |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
103 assert(scan >= bytes+i && scan <= limit, "scan oob"); |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
104 if (memcmp(scan, str, len) == 0) |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
105 return (int)(scan - bytes); |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
106 } |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
107 } |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
108 |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
222
diff
changeset
|
109 |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
110 char* Symbol::as_C_string(char* buf, int size) const { |
0 | 111 if (size > 0) { |
112 int len = MIN2(size - 1, utf8_length()); | |
113 for (int i = 0; i < len; i++) { | |
114 buf[i] = byte_at(i); | |
115 } | |
116 buf[len] = '\0'; | |
117 } | |
118 return buf; | |
119 } | |
120 | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
121 char* Symbol::as_C_string() const { |
0 | 122 int len = utf8_length(); |
123 char* str = NEW_RESOURCE_ARRAY(char, len + 1); | |
124 return as_C_string(str, len + 1); | |
125 } | |
126 | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
127 char* Symbol::as_C_string_flexible_buffer(Thread* t, |
0 | 128 char* buf, int size) const { |
129 char* str; | |
130 int len = utf8_length(); | |
131 int buf_len = len + 1; | |
132 if (size < buf_len) { | |
133 str = NEW_RESOURCE_ARRAY(char, buf_len); | |
134 } else { | |
135 str = buf; | |
136 } | |
137 return as_C_string(str, buf_len); | |
138 } | |
139 | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
140 void Symbol::print_symbol_on(outputStream* st) const { |
0 | 141 st = st ? st : tty; |
222 | 142 int length = UTF8::unicode_length((const char*)bytes(), utf8_length()); |
143 const char *ptr = (const char *)bytes(); | |
144 jchar value; | |
145 for (int index = 0; index < length; index++) { | |
146 ptr = UTF8::next(ptr, &value); | |
147 if (value >= 32 && value < 127 || value == '\'' || value == '\\') { | |
148 st->put(value); | |
149 } else { | |
150 st->print("\\u%04x", value); | |
151 } | |
152 } | |
0 | 153 } |
154 | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
155 jchar* Symbol::as_unicode(int& length) const { |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
156 Symbol* this_ptr = (Symbol*)this; |
0 | 157 length = UTF8::unicode_length((char*)this_ptr->bytes(), utf8_length()); |
158 jchar* result = NEW_RESOURCE_ARRAY(jchar, length); | |
159 if (length > 0) { | |
160 UTF8::convert_to_unicode((char*)this_ptr->bytes(), result, length); | |
161 } | |
162 return result; | |
163 } | |
164 | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
165 const char* Symbol::as_klass_external_name(char* buf, int size) const { |
0 | 166 if (size > 0) { |
167 char* str = as_C_string(buf, size); | |
168 int length = (int)strlen(str); | |
169 // Turn all '/'s into '.'s (also for array klasses) | |
170 for (int index = 0; index < length; index++) { | |
171 if (str[index] == '/') { | |
172 str[index] = '.'; | |
173 } | |
174 } | |
175 return str; | |
176 } else { | |
177 return buf; | |
178 } | |
179 } | |
180 | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
181 const char* Symbol::as_klass_external_name() const { |
0 | 182 char* str = as_C_string(); |
183 int length = (int)strlen(str); | |
184 // Turn all '/'s into '.'s (also for array klasses) | |
185 for (int index = 0; index < length; index++) { | |
186 if (str[index] == '/') { | |
187 str[index] = '.'; | |
188 } | |
189 } | |
190 return str; | |
191 } | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
192 |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
193 |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
194 void Symbol::print_on(outputStream* st) const { |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
195 if (this == NULL) { |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
196 st->print_cr("NULL"); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
197 } else { |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
198 st->print("Symbol: '"); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
199 print_symbol_on(st); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
200 st->print("'"); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
201 st->print(" count %d", refcount()); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
202 } |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
203 } |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
204 |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
205 // The print_value functions are present in all builds, to support the |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
206 // disassembler and error reporting. |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
207 void Symbol::print_value_on(outputStream* st) const { |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
208 if (this == NULL) { |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
209 st->print("NULL"); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
210 } else { |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
211 st->print("'"); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
212 for (int i = 0; i < utf8_length(); i++) { |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
213 st->print("%c", byte_at(i)); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
214 } |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
215 st->print("'"); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
216 } |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
217 } |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
218 |
5979
fc9d8850ab8b
7150058: Allocate symbols from null boot loader to an arena for NMT
coleenp
parents:
2426
diff
changeset
|
219 // SymbolTable prints this in its statistics |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
220 NOT_PRODUCT(int Symbol::_total_count = 0;) |