author | redestad |
Thu, 14 Mar 2019 18:56:25 +0100 | |
changeset 54133 | 829bf950287e |
parent 54124 | 5d48ae032588 |
child 54786 | ebf733a324d4 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
54124
5d48ae032588
8219579: Remove redundant signature parsing from the verifier
hseigel
parents:
51997
diff
changeset
|
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:
5426
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5426
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:
5426
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#include "precompiled.hpp" |
26 |
#include "classfile/symbolTable.hpp" |
|
27 |
#include "classfile/systemDictionary.hpp" |
|
28 |
#include "memory/oopFactory.hpp" |
|
37248 | 29 |
#include "memory/resourceArea.hpp" |
7397 | 30 |
#include "oops/instanceKlass.hpp" |
31 |
#include "oops/oop.inline.hpp" |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
32 |
#include "oops/symbol.hpp" |
7397 | 33 |
#include "oops/typeArrayKlass.hpp" |
34 |
#include "runtime/signature.hpp" |
|
1 | 35 |
|
36 |
// Implementation of SignatureIterator |
|
37 |
||
38 |
// Signature syntax: |
|
39 |
// |
|
40 |
// Signature = "(" {Parameter} ")" ReturnType. |
|
41 |
// Parameter = FieldType. |
|
42 |
// ReturnType = FieldType | "V". |
|
43 |
// FieldType = "B" | "C" | "D" | "F" | "I" | "J" | "S" | "Z" | "L" ClassName ";" | "[" FieldType. |
|
44 |
// ClassName = string. |
|
45 |
||
46 |
||
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
47 |
SignatureIterator::SignatureIterator(Symbol* signature) { |
1 | 48 |
_signature = signature; |
49 |
_parameter_index = 0; |
|
50 |
} |
|
51 |
||
52 |
void SignatureIterator::expect(char c) { |
|
51997
9ce37fa2e179
8209138: Symbol constructor uses u1 as the element type of its name argument
hseigel
parents:
49354
diff
changeset
|
53 |
if (_signature->char_at(_index) != c) fatal("expecting %c", c); |
1 | 54 |
_index++; |
55 |
} |
|
56 |
||
57 |
int SignatureIterator::parse_type() { |
|
58 |
// Note: This function could be simplified by using "return T_XXX_size;" |
|
59 |
// instead of the assignment and the break statements. However, it |
|
60 |
// seems that the product build for win32_i486 with MS VC++ 6.0 doesn't |
|
61 |
// work (stack underflow for some tests) - this seems to be a VC++ 6.0 |
|
62 |
// compiler bug (was problem - gri 4/27/2000). |
|
63 |
int size = -1; |
|
51997
9ce37fa2e179
8209138: Symbol constructor uses u1 as the element type of its name argument
hseigel
parents:
49354
diff
changeset
|
64 |
switch(_signature->char_at(_index)) { |
1 | 65 |
case 'B': do_byte (); if (_parameter_index < 0 ) _return_type = T_BYTE; |
66 |
_index++; size = T_BYTE_size ; break; |
|
67 |
case 'C': do_char (); if (_parameter_index < 0 ) _return_type = T_CHAR; |
|
68 |
_index++; size = T_CHAR_size ; break; |
|
69 |
case 'D': do_double(); if (_parameter_index < 0 ) _return_type = T_DOUBLE; |
|
70 |
_index++; size = T_DOUBLE_size ; break; |
|
71 |
case 'F': do_float (); if (_parameter_index < 0 ) _return_type = T_FLOAT; |
|
72 |
_index++; size = T_FLOAT_size ; break; |
|
73 |
case 'I': do_int (); if (_parameter_index < 0 ) _return_type = T_INT; |
|
74 |
_index++; size = T_INT_size ; break; |
|
75 |
case 'J': do_long (); if (_parameter_index < 0 ) _return_type = T_LONG; |
|
76 |
_index++; size = T_LONG_size ; break; |
|
77 |
case 'S': do_short (); if (_parameter_index < 0 ) _return_type = T_SHORT; |
|
78 |
_index++; size = T_SHORT_size ; break; |
|
79 |
case 'Z': do_bool (); if (_parameter_index < 0 ) _return_type = T_BOOLEAN; |
|
80 |
_index++; size = T_BOOLEAN_size; break; |
|
81 |
case 'V': do_void (); if (_parameter_index < 0 ) _return_type = T_VOID; |
|
82 |
_index++; size = T_VOID_size; ; break; |
|
83 |
case 'L': |
|
84 |
{ int begin = ++_index; |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
85 |
Symbol* sig = _signature; |
51997
9ce37fa2e179
8209138: Symbol constructor uses u1 as the element type of its name argument
hseigel
parents:
49354
diff
changeset
|
86 |
while (sig->char_at(_index++) != ';') ; |
1 | 87 |
do_object(begin, _index); |
88 |
} |
|
89 |
if (_parameter_index < 0 ) _return_type = T_OBJECT; |
|
90 |
size = T_OBJECT_size; |
|
91 |
break; |
|
92 |
case '[': |
|
93 |
{ int begin = ++_index; |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
94 |
Symbol* sig = _signature; |
51997
9ce37fa2e179
8209138: Symbol constructor uses u1 as the element type of its name argument
hseigel
parents:
49354
diff
changeset
|
95 |
while (sig->char_at(_index) == '[') { |
1 | 96 |
_index++; |
97 |
} |
|
51997
9ce37fa2e179
8209138: Symbol constructor uses u1 as the element type of its name argument
hseigel
parents:
49354
diff
changeset
|
98 |
if (sig->char_at(_index) == 'L') { |
9ce37fa2e179
8209138: Symbol constructor uses u1 as the element type of its name argument
hseigel
parents:
49354
diff
changeset
|
99 |
while (sig->char_at(_index++) != ';') ; |
1 | 100 |
} else { |
101 |
_index++; |
|
102 |
} |
|
103 |
do_array(begin, _index); |
|
104 |
if (_parameter_index < 0 ) _return_type = T_ARRAY; |
|
105 |
} |
|
106 |
size = T_ARRAY_size; |
|
107 |
break; |
|
108 |
default: |
|
109 |
ShouldNotReachHere(); |
|
110 |
break; |
|
111 |
} |
|
112 |
assert(size >= 0, "size must be set"); |
|
113 |
return size; |
|
114 |
} |
|
115 |
||
116 |
||
117 |
void SignatureIterator::check_signature_end() { |
|
118 |
if (_index < _signature->utf8_length()) { |
|
119 |
tty->print_cr("too many chars in signature"); |
|
120 |
_signature->print_value_on(tty); |
|
121 |
tty->print_cr(" @ %d", _index); |
|
122 |
} |
|
123 |
} |
|
124 |
||
125 |
||
126 |
void SignatureIterator::iterate_parameters() { |
|
127 |
// Parse parameters |
|
128 |
_index = 0; |
|
129 |
_parameter_index = 0; |
|
130 |
expect('('); |
|
51997
9ce37fa2e179
8209138: Symbol constructor uses u1 as the element type of its name argument
hseigel
parents:
49354
diff
changeset
|
131 |
while (_signature->char_at(_index) != ')') _parameter_index += parse_type(); |
1 | 132 |
expect(')'); |
133 |
_parameter_index = 0; |
|
134 |
} |
|
135 |
||
22551 | 136 |
// Optimized version of iterate_parameters when fingerprint is known |
1 | 137 |
void SignatureIterator::iterate_parameters( uint64_t fingerprint ) { |
138 |
uint64_t saved_fingerprint = fingerprint; |
|
139 |
||
140 |
// Check for too many arguments |
|
27471 | 141 |
if (fingerprint == (uint64_t)CONST64(-1)) { |
1 | 142 |
SignatureIterator::iterate_parameters(); |
143 |
return; |
|
144 |
} |
|
145 |
||
146 |
assert(fingerprint, "Fingerprint should not be 0"); |
|
147 |
||
148 |
_parameter_index = 0; |
|
149 |
fingerprint = fingerprint >> (static_feature_size + result_feature_size); |
|
150 |
while ( 1 ) { |
|
151 |
switch ( fingerprint & parameter_feature_mask ) { |
|
152 |
case bool_parm: |
|
153 |
do_bool(); |
|
154 |
_parameter_index += T_BOOLEAN_size; |
|
155 |
break; |
|
156 |
case byte_parm: |
|
157 |
do_byte(); |
|
158 |
_parameter_index += T_BYTE_size; |
|
159 |
break; |
|
160 |
case char_parm: |
|
161 |
do_char(); |
|
162 |
_parameter_index += T_CHAR_size; |
|
163 |
break; |
|
164 |
case short_parm: |
|
165 |
do_short(); |
|
166 |
_parameter_index += T_SHORT_size; |
|
167 |
break; |
|
168 |
case int_parm: |
|
169 |
do_int(); |
|
170 |
_parameter_index += T_INT_size; |
|
171 |
break; |
|
172 |
case obj_parm: |
|
173 |
do_object(0, 0); |
|
174 |
_parameter_index += T_OBJECT_size; |
|
175 |
break; |
|
176 |
case long_parm: |
|
177 |
do_long(); |
|
178 |
_parameter_index += T_LONG_size; |
|
179 |
break; |
|
180 |
case float_parm: |
|
181 |
do_float(); |
|
182 |
_parameter_index += T_FLOAT_size; |
|
183 |
break; |
|
184 |
case double_parm: |
|
185 |
do_double(); |
|
186 |
_parameter_index += T_DOUBLE_size; |
|
187 |
break; |
|
188 |
case done_parm: |
|
189 |
return; |
|
190 |
default: |
|
33148
68fa8b6c4340
8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents:
33105
diff
changeset
|
191 |
tty->print_cr("*** parameter is " UINT64_FORMAT, fingerprint & parameter_feature_mask); |
1 | 192 |
tty->print_cr("*** fingerprint is " PTR64_FORMAT, saved_fingerprint); |
193 |
ShouldNotReachHere(); |
|
194 |
break; |
|
195 |
} |
|
196 |
fingerprint >>= parameter_feature_size; |
|
197 |
} |
|
198 |
} |
|
199 |
||
200 |
||
201 |
void SignatureIterator::iterate_returntype() { |
|
202 |
// Ignore parameters |
|
203 |
_index = 0; |
|
204 |
expect('('); |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
205 |
Symbol* sig = _signature; |
41545 | 206 |
// Need to skip over each type in the signature's argument list until a |
207 |
// closing ')' is found., then get the return type. We cannot just scan |
|
208 |
// for the first ')' because ')' is a legal character in a type name. |
|
51997
9ce37fa2e179
8209138: Symbol constructor uses u1 as the element type of its name argument
hseigel
parents:
49354
diff
changeset
|
209 |
while (sig->char_at(_index) != ')') { |
9ce37fa2e179
8209138: Symbol constructor uses u1 as the element type of its name argument
hseigel
parents:
49354
diff
changeset
|
210 |
switch(sig->char_at(_index)) { |
41545 | 211 |
case 'B': |
212 |
case 'C': |
|
213 |
case 'D': |
|
214 |
case 'F': |
|
215 |
case 'I': |
|
216 |
case 'J': |
|
217 |
case 'S': |
|
218 |
case 'Z': |
|
219 |
case 'V': |
|
220 |
{ |
|
221 |
_index++; |
|
222 |
} |
|
223 |
break; |
|
224 |
case 'L': |
|
225 |
{ |
|
51997
9ce37fa2e179
8209138: Symbol constructor uses u1 as the element type of its name argument
hseigel
parents:
49354
diff
changeset
|
226 |
while (sig->char_at(_index++) != ';') ; |
41545 | 227 |
} |
228 |
break; |
|
229 |
case '[': |
|
230 |
{ |
|
54133
829bf950287e
8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents:
54124
diff
changeset
|
231 |
while (sig->char_at(++_index) == '[') ; |
51997
9ce37fa2e179
8209138: Symbol constructor uses u1 as the element type of its name argument
hseigel
parents:
49354
diff
changeset
|
232 |
if (sig->char_at(_index) == 'L') { |
9ce37fa2e179
8209138: Symbol constructor uses u1 as the element type of its name argument
hseigel
parents:
49354
diff
changeset
|
233 |
while (sig->char_at(_index++) != ';') ; |
41545 | 234 |
} else { |
235 |
_index++; |
|
236 |
} |
|
237 |
} |
|
238 |
break; |
|
239 |
default: |
|
240 |
ShouldNotReachHere(); |
|
241 |
break; |
|
242 |
} |
|
243 |
} |
|
1 | 244 |
expect(')'); |
245 |
// Parse return type |
|
246 |
_parameter_index = -1; |
|
247 |
parse_type(); |
|
248 |
check_signature_end(); |
|
249 |
_parameter_index = 0; |
|
250 |
} |
|
251 |
||
252 |
||
253 |
void SignatureIterator::iterate() { |
|
254 |
// Parse parameters |
|
255 |
_parameter_index = 0; |
|
256 |
_index = 0; |
|
257 |
expect('('); |
|
51997
9ce37fa2e179
8209138: Symbol constructor uses u1 as the element type of its name argument
hseigel
parents:
49354
diff
changeset
|
258 |
while (_signature->char_at(_index) != ')') _parameter_index += parse_type(); |
1 | 259 |
expect(')'); |
260 |
// Parse return type |
|
261 |
_parameter_index = -1; |
|
262 |
parse_type(); |
|
263 |
check_signature_end(); |
|
264 |
_parameter_index = 0; |
|
265 |
} |
|
266 |
||
267 |
||
268 |
// Implementation of SignatureStream |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
269 |
SignatureStream::SignatureStream(Symbol* signature, bool is_method) : |
54133
829bf950287e
8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents:
54124
diff
changeset
|
270 |
_signature(signature), _at_return_type(false), _previous_name(NULL), _names(NULL) { |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
271 |
_begin = _end = (is_method ? 1 : 0); // skip first '(' in method signatures |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
272 |
next(); |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
273 |
} |
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 |
SignatureStream::~SignatureStream() { |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
276 |
// decrement refcount for names created during signature parsing |
54133
829bf950287e
8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents:
54124
diff
changeset
|
277 |
if (_names != NULL) { |
829bf950287e
8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents:
54124
diff
changeset
|
278 |
for (int i = 0; i < _names->length(); i++) { |
829bf950287e
8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents:
54124
diff
changeset
|
279 |
_names->at(i)->decrement_refcount(); |
829bf950287e
8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents:
54124
diff
changeset
|
280 |
} |
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 |
} |
1 | 283 |
|
284 |
bool SignatureStream::is_done() const { |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
285 |
return _end > _signature->utf8_length(); |
1 | 286 |
} |
287 |
||
288 |
||
289 |
void SignatureStream::next_non_primitive(int t) { |
|
290 |
switch (t) { |
|
291 |
case 'L': { |
|
292 |
_type = T_OBJECT; |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
293 |
Symbol* sig = _signature; |
51997
9ce37fa2e179
8209138: Symbol constructor uses u1 as the element type of its name argument
hseigel
parents:
49354
diff
changeset
|
294 |
while (sig->char_at(_end++) != ';'); |
1 | 295 |
break; |
296 |
} |
|
297 |
case '[': { |
|
298 |
_type = T_ARRAY; |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
299 |
Symbol* sig = _signature; |
51997
9ce37fa2e179
8209138: Symbol constructor uses u1 as the element type of its name argument
hseigel
parents:
49354
diff
changeset
|
300 |
char c = sig->char_at(_end); |
9ce37fa2e179
8209138: Symbol constructor uses u1 as the element type of its name argument
hseigel
parents:
49354
diff
changeset
|
301 |
while ('0' <= c && c <= '9') c = sig->char_at(_end++); |
9ce37fa2e179
8209138: Symbol constructor uses u1 as the element type of its name argument
hseigel
parents:
49354
diff
changeset
|
302 |
while (sig->char_at(_end) == '[') { |
1 | 303 |
_end++; |
51997
9ce37fa2e179
8209138: Symbol constructor uses u1 as the element type of its name argument
hseigel
parents:
49354
diff
changeset
|
304 |
c = sig->char_at(_end); |
9ce37fa2e179
8209138: Symbol constructor uses u1 as the element type of its name argument
hseigel
parents:
49354
diff
changeset
|
305 |
while ('0' <= c && c <= '9') c = sig->char_at(_end++); |
1 | 306 |
} |
51997
9ce37fa2e179
8209138: Symbol constructor uses u1 as the element type of its name argument
hseigel
parents:
49354
diff
changeset
|
307 |
switch(sig->char_at(_end)) { |
1 | 308 |
case 'B': |
309 |
case 'C': |
|
310 |
case 'D': |
|
311 |
case 'F': |
|
312 |
case 'I': |
|
313 |
case 'J': |
|
314 |
case 'S': |
|
315 |
case 'Z':_end++; break; |
|
316 |
default: { |
|
51997
9ce37fa2e179
8209138: Symbol constructor uses u1 as the element type of its name argument
hseigel
parents:
49354
diff
changeset
|
317 |
while (sig->char_at(_end++) != ';'); |
1 | 318 |
break; |
319 |
} |
|
320 |
} |
|
321 |
break; |
|
322 |
} |
|
323 |
case ')': _end++; next(); _at_return_type = true; break; |
|
324 |
default : ShouldNotReachHere(); |
|
325 |
} |
|
326 |
} |
|
327 |
||
328 |
||
329 |
bool SignatureStream::is_object() const { |
|
330 |
return _type == T_OBJECT |
|
331 |
|| _type == T_ARRAY; |
|
332 |
} |
|
333 |
||
334 |
bool SignatureStream::is_array() const { |
|
335 |
return _type == T_ARRAY; |
|
336 |
} |
|
337 |
||
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
338 |
Symbol* SignatureStream::as_symbol(TRAPS) { |
1 | 339 |
// Create a symbol from for string _begin _end |
340 |
int begin = _begin; |
|
341 |
int end = _end; |
|
342 |
||
51997
9ce37fa2e179
8209138: Symbol constructor uses u1 as the element type of its name argument
hseigel
parents:
49354
diff
changeset
|
343 |
if ( _signature->char_at(_begin) == 'L' |
9ce37fa2e179
8209138: Symbol constructor uses u1 as the element type of its name argument
hseigel
parents:
49354
diff
changeset
|
344 |
&& _signature->char_at(_end-1) == ';') { |
1 | 345 |
begin++; |
346 |
end--; |
|
347 |
} |
|
348 |
||
54133
829bf950287e
8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents:
54124
diff
changeset
|
349 |
const char* symbol_chars = (const char*)_signature->base() + begin; |
829bf950287e
8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents:
54124
diff
changeset
|
350 |
int len = end - begin; |
829bf950287e
8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents:
54124
diff
changeset
|
351 |
|
829bf950287e
8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents:
54124
diff
changeset
|
352 |
// Quick check for common symbols in signatures |
829bf950287e
8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents:
54124
diff
changeset
|
353 |
assert((vmSymbols::java_lang_String()->utf8_length() == 16 && vmSymbols::java_lang_Object()->utf8_length() == 16), "sanity"); |
829bf950287e
8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents:
54124
diff
changeset
|
354 |
if (len == 16 && |
829bf950287e
8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents:
54124
diff
changeset
|
355 |
strncmp(symbol_chars, "java/lang/", 10) == 0) { |
829bf950287e
8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents:
54124
diff
changeset
|
356 |
if (strncmp("String", symbol_chars + 10, 6) == 0) { |
829bf950287e
8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents:
54124
diff
changeset
|
357 |
return vmSymbols::java_lang_String(); |
829bf950287e
8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents:
54124
diff
changeset
|
358 |
} else if (strncmp("Object", symbol_chars + 10, 6) == 0) { |
829bf950287e
8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents:
54124
diff
changeset
|
359 |
return vmSymbols::java_lang_Object(); |
829bf950287e
8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents:
54124
diff
changeset
|
360 |
} |
829bf950287e
8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents:
54124
diff
changeset
|
361 |
} |
829bf950287e
8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents:
54124
diff
changeset
|
362 |
|
829bf950287e
8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents:
54124
diff
changeset
|
363 |
Symbol* name = _previous_name; |
829bf950287e
8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents:
54124
diff
changeset
|
364 |
if (name != NULL && name->equals(symbol_chars, len)) { |
829bf950287e
8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents:
54124
diff
changeset
|
365 |
return name; |
829bf950287e
8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents:
54124
diff
changeset
|
366 |
} |
829bf950287e
8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents:
54124
diff
changeset
|
367 |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
368 |
// Save names for cleaning up reference count at the end of |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
369 |
// SignatureStream scope. |
54133
829bf950287e
8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents:
54124
diff
changeset
|
370 |
name = SymbolTable::new_symbol(symbol_chars, len, CHECK_NULL); |
829bf950287e
8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents:
54124
diff
changeset
|
371 |
if (!name->is_permanent()) { |
829bf950287e
8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents:
54124
diff
changeset
|
372 |
if (_names == NULL) { |
829bf950287e
8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents:
54124
diff
changeset
|
373 |
_names = new GrowableArray<Symbol*>(10); |
829bf950287e
8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents:
54124
diff
changeset
|
374 |
} |
829bf950287e
8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents:
54124
diff
changeset
|
375 |
_names->push(name); // save new symbol for decrementing later |
829bf950287e
8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents:
54124
diff
changeset
|
376 |
} |
829bf950287e
8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents:
54124
diff
changeset
|
377 |
_previous_name = name; |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
378 |
return name; |
1 | 379 |
} |
380 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8921
diff
changeset
|
381 |
Klass* SignatureStream::as_klass(Handle class_loader, Handle protection_domain, |
5421
e294db54fc0d
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1
diff
changeset
|
382 |
FailureMode failure_mode, TRAPS) { |
e294db54fc0d
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1
diff
changeset
|
383 |
if (!is_object()) return NULL; |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
384 |
Symbol* name = as_symbol(CHECK_NULL); |
5421
e294db54fc0d
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1
diff
changeset
|
385 |
if (failure_mode == ReturnNull) { |
e294db54fc0d
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1
diff
changeset
|
386 |
return SystemDictionary::resolve_or_null(name, class_loader, protection_domain, THREAD); |
e294db54fc0d
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1
diff
changeset
|
387 |
} else { |
e294db54fc0d
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1
diff
changeset
|
388 |
bool throw_error = (failure_mode == NCDFError); |
e294db54fc0d
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1
diff
changeset
|
389 |
return SystemDictionary::resolve_or_fail(name, class_loader, protection_domain, throw_error, THREAD); |
e294db54fc0d
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1
diff
changeset
|
390 |
} |
e294db54fc0d
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1
diff
changeset
|
391 |
} |
e294db54fc0d
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1
diff
changeset
|
392 |
|
e294db54fc0d
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1
diff
changeset
|
393 |
oop SignatureStream::as_java_mirror(Handle class_loader, Handle protection_domain, |
e294db54fc0d
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1
diff
changeset
|
394 |
FailureMode failure_mode, TRAPS) { |
48836
423bcbb288ff
8196601: IllegalAccessError: cannot access class jdk.jfr.internal.handlers.EventHandler
lfoltan
parents:
48826
diff
changeset
|
395 |
if (!is_object()) |
423bcbb288ff
8196601: IllegalAccessError: cannot access class jdk.jfr.internal.handlers.EventHandler
lfoltan
parents:
48826
diff
changeset
|
396 |
return Universe::java_mirror(type()); |
423bcbb288ff
8196601: IllegalAccessError: cannot access class jdk.jfr.internal.handlers.EventHandler
lfoltan
parents:
48826
diff
changeset
|
397 |
Klass* klass = as_klass(class_loader, protection_domain, failure_mode, CHECK_NULL); |
423bcbb288ff
8196601: IllegalAccessError: cannot access class jdk.jfr.internal.handlers.EventHandler
lfoltan
parents:
48826
diff
changeset
|
398 |
if (klass == NULL) return NULL; |
423bcbb288ff
8196601: IllegalAccessError: cannot access class jdk.jfr.internal.handlers.EventHandler
lfoltan
parents:
48826
diff
changeset
|
399 |
return klass->java_mirror(); |
5421
e294db54fc0d
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1
diff
changeset
|
400 |
} |
1 | 401 |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
402 |
Symbol* SignatureStream::as_symbol_or_null() { |
1 | 403 |
// Create a symbol from for string _begin _end |
404 |
ResourceMark rm; |
|
405 |
||
406 |
int begin = _begin; |
|
407 |
int end = _end; |
|
408 |
||
51997
9ce37fa2e179
8209138: Symbol constructor uses u1 as the element type of its name argument
hseigel
parents:
49354
diff
changeset
|
409 |
if ( _signature->char_at(_begin) == 'L' |
9ce37fa2e179
8209138: Symbol constructor uses u1 as the element type of its name argument
hseigel
parents:
49354
diff
changeset
|
410 |
&& _signature->char_at(_end-1) == ';') { |
1 | 411 |
begin++; |
412 |
end--; |
|
413 |
} |
|
414 |
||
415 |
char* buffer = NEW_RESOURCE_ARRAY(char, end - begin); |
|
416 |
for (int index = begin; index < end; index++) { |
|
51997
9ce37fa2e179
8209138: Symbol constructor uses u1 as the element type of its name argument
hseigel
parents:
49354
diff
changeset
|
417 |
buffer[index - begin] = _signature->char_at(index); |
1 | 418 |
} |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
419 |
Symbol* result = SymbolTable::probe(buffer, end - begin); |
1 | 420 |
return result; |
421 |
} |
|
422 |
||
20702
bbe0fcde6e13
8023657: New type profiling points: arguments to call
roland
parents:
14488
diff
changeset
|
423 |
int SignatureStream::reference_parameter_count() { |
bbe0fcde6e13
8023657: New type profiling points: arguments to call
roland
parents:
14488
diff
changeset
|
424 |
int args_count = 0; |
bbe0fcde6e13
8023657: New type profiling points: arguments to call
roland
parents:
14488
diff
changeset
|
425 |
for ( ; !at_return_type(); next()) { |
bbe0fcde6e13
8023657: New type profiling points: arguments to call
roland
parents:
14488
diff
changeset
|
426 |
if (is_object()) { |
bbe0fcde6e13
8023657: New type profiling points: arguments to call
roland
parents:
14488
diff
changeset
|
427 |
args_count++; |
bbe0fcde6e13
8023657: New type profiling points: arguments to call
roland
parents:
14488
diff
changeset
|
428 |
} |
bbe0fcde6e13
8023657: New type profiling points: arguments to call
roland
parents:
14488
diff
changeset
|
429 |
} |
bbe0fcde6e13
8023657: New type profiling points: arguments to call
roland
parents:
14488
diff
changeset
|
430 |
return args_count; |
bbe0fcde6e13
8023657: New type profiling points: arguments to call
roland
parents:
14488
diff
changeset
|
431 |
} |
bbe0fcde6e13
8023657: New type profiling points: arguments to call
roland
parents:
14488
diff
changeset
|
432 |
|
54124
5d48ae032588
8219579: Remove redundant signature parsing from the verifier
hseigel
parents:
51997
diff
changeset
|
433 |
#ifdef ASSERT |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
434 |
bool SignatureVerifier::is_valid_method_signature(Symbol* sig) { |
1 | 435 |
const char* method_sig = (const char*)sig->bytes(); |
436 |
ssize_t len = sig->utf8_length(); |
|
437 |
ssize_t index = 0; |
|
438 |
if (method_sig != NULL && len > 1 && method_sig[index] == '(') { |
|
439 |
++index; |
|
440 |
while (index < len && method_sig[index] != ')') { |
|
441 |
ssize_t res = is_valid_type(&method_sig[index], len - index); |
|
442 |
if (res == -1) { |
|
443 |
return false; |
|
444 |
} else { |
|
445 |
index += res; |
|
446 |
} |
|
447 |
} |
|
448 |
if (index < len && method_sig[index] == ')') { |
|
449 |
// check the return type |
|
450 |
++index; |
|
451 |
return (is_valid_type(&method_sig[index], len - index) == (len - index)); |
|
452 |
} |
|
453 |
} |
|
454 |
return false; |
|
455 |
} |
|
456 |
||
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
457 |
bool SignatureVerifier::is_valid_type_signature(Symbol* sig) { |
1 | 458 |
const char* type_sig = (const char*)sig->bytes(); |
459 |
ssize_t len = sig->utf8_length(); |
|
460 |
return (type_sig != NULL && len >= 1 && |
|
461 |
(is_valid_type(type_sig, len) == len)); |
|
462 |
} |
|
463 |
||
464 |
// Checks to see if the type (not to go beyond 'limit') refers to a valid type. |
|
465 |
// Returns -1 if it is not, or the index of the next character that is not part |
|
466 |
// of the type. The type encoding may end before 'limit' and that's ok. |
|
467 |
ssize_t SignatureVerifier::is_valid_type(const char* type, ssize_t limit) { |
|
468 |
ssize_t index = 0; |
|
469 |
||
470 |
// Iterate over any number of array dimensions |
|
471 |
while (index < limit && type[index] == '[') ++index; |
|
472 |
if (index >= limit) { |
|
473 |
return -1; |
|
474 |
} |
|
475 |
switch (type[index]) { |
|
476 |
case 'B': case 'C': case 'D': case 'F': case 'I': |
|
477 |
case 'J': case 'S': case 'Z': case 'V': |
|
478 |
return index + 1; |
|
479 |
case 'L': |
|
480 |
for (index = index + 1; index < limit; ++index) { |
|
481 |
char c = type[index]; |
|
54133
829bf950287e
8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents:
54124
diff
changeset
|
482 |
switch (c) { |
829bf950287e
8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents:
54124
diff
changeset
|
483 |
case ';': |
829bf950287e
8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents:
54124
diff
changeset
|
484 |
return index + 1; |
829bf950287e
8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents:
54124
diff
changeset
|
485 |
case '\0': case '.': case '[': |
829bf950287e
8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents:
54124
diff
changeset
|
486 |
return -1; |
829bf950287e
8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents:
54124
diff
changeset
|
487 |
default: ; // fall through |
1 | 488 |
} |
489 |
} |
|
490 |
// fall through |
|
491 |
default: ; // fall through |
|
492 |
} |
|
493 |
return -1; |
|
494 |
} |
|
54124
5d48ae032588
8219579: Remove redundant signature parsing from the verifier
hseigel
parents:
51997
diff
changeset
|
495 |
#endif // ASSERT |