author | pliden |
Fri, 11 Apr 2014 12:29:24 +0200 | |
changeset 24094 | 5dbf1f44de18 |
parent 22551 | 9bf46d16dcc6 |
child 24424 | 2658d7834c6e |
permissions | -rw-r--r-- |
1 | 1 |
/* |
22234
da823d78ad65
8029233: Update copyright year to match last edit in jdk8 hotspot repository for 2013
mikael
parents:
20702
diff
changeset
|
2 |
* Copyright (c) 1997, 2013, 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" |
|
29 |
#include "oops/instanceKlass.hpp" |
|
30 |
#include "oops/oop.inline.hpp" |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
31 |
#include "oops/symbol.hpp" |
7397 | 32 |
#include "oops/typeArrayKlass.hpp" |
33 |
#include "runtime/signature.hpp" |
|
1 | 34 |
|
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) { |
|
5403
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
1
diff
changeset
|
53 |
if (_signature->byte_at(_index) != c) fatal(err_msg("expecting %c", c)); |
1 | 54 |
_index++; |
55 |
} |
|
56 |
||
57 |
||
58 |
void SignatureIterator::skip_optional_size() { |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
59 |
Symbol* sig = _signature; |
1 | 60 |
char c = sig->byte_at(_index); |
61 |
while ('0' <= c && c <= '9') c = sig->byte_at(++_index); |
|
62 |
} |
|
63 |
||
64 |
||
65 |
int SignatureIterator::parse_type() { |
|
66 |
// Note: This function could be simplified by using "return T_XXX_size;" |
|
67 |
// instead of the assignment and the break statements. However, it |
|
68 |
// seems that the product build for win32_i486 with MS VC++ 6.0 doesn't |
|
69 |
// work (stack underflow for some tests) - this seems to be a VC++ 6.0 |
|
70 |
// compiler bug (was problem - gri 4/27/2000). |
|
71 |
int size = -1; |
|
72 |
switch(_signature->byte_at(_index)) { |
|
73 |
case 'B': do_byte (); if (_parameter_index < 0 ) _return_type = T_BYTE; |
|
74 |
_index++; size = T_BYTE_size ; break; |
|
75 |
case 'C': do_char (); if (_parameter_index < 0 ) _return_type = T_CHAR; |
|
76 |
_index++; size = T_CHAR_size ; break; |
|
77 |
case 'D': do_double(); if (_parameter_index < 0 ) _return_type = T_DOUBLE; |
|
78 |
_index++; size = T_DOUBLE_size ; break; |
|
79 |
case 'F': do_float (); if (_parameter_index < 0 ) _return_type = T_FLOAT; |
|
80 |
_index++; size = T_FLOAT_size ; break; |
|
81 |
case 'I': do_int (); if (_parameter_index < 0 ) _return_type = T_INT; |
|
82 |
_index++; size = T_INT_size ; break; |
|
83 |
case 'J': do_long (); if (_parameter_index < 0 ) _return_type = T_LONG; |
|
84 |
_index++; size = T_LONG_size ; break; |
|
85 |
case 'S': do_short (); if (_parameter_index < 0 ) _return_type = T_SHORT; |
|
86 |
_index++; size = T_SHORT_size ; break; |
|
87 |
case 'Z': do_bool (); if (_parameter_index < 0 ) _return_type = T_BOOLEAN; |
|
88 |
_index++; size = T_BOOLEAN_size; break; |
|
89 |
case 'V': do_void (); if (_parameter_index < 0 ) _return_type = T_VOID; |
|
90 |
_index++; size = T_VOID_size; ; break; |
|
91 |
case 'L': |
|
92 |
{ int begin = ++_index; |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
93 |
Symbol* sig = _signature; |
1 | 94 |
while (sig->byte_at(_index++) != ';') ; |
95 |
do_object(begin, _index); |
|
96 |
} |
|
97 |
if (_parameter_index < 0 ) _return_type = T_OBJECT; |
|
98 |
size = T_OBJECT_size; |
|
99 |
break; |
|
100 |
case '[': |
|
101 |
{ int begin = ++_index; |
|
102 |
skip_optional_size(); |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
103 |
Symbol* sig = _signature; |
1 | 104 |
while (sig->byte_at(_index) == '[') { |
105 |
_index++; |
|
106 |
skip_optional_size(); |
|
107 |
} |
|
108 |
if (sig->byte_at(_index) == 'L') { |
|
109 |
while (sig->byte_at(_index++) != ';') ; |
|
110 |
} else { |
|
111 |
_index++; |
|
112 |
} |
|
113 |
do_array(begin, _index); |
|
114 |
if (_parameter_index < 0 ) _return_type = T_ARRAY; |
|
115 |
} |
|
116 |
size = T_ARRAY_size; |
|
117 |
break; |
|
118 |
default: |
|
119 |
ShouldNotReachHere(); |
|
120 |
break; |
|
121 |
} |
|
122 |
assert(size >= 0, "size must be set"); |
|
123 |
return size; |
|
124 |
} |
|
125 |
||
126 |
||
127 |
void SignatureIterator::check_signature_end() { |
|
128 |
if (_index < _signature->utf8_length()) { |
|
129 |
tty->print_cr("too many chars in signature"); |
|
130 |
_signature->print_value_on(tty); |
|
131 |
tty->print_cr(" @ %d", _index); |
|
132 |
} |
|
133 |
} |
|
134 |
||
135 |
||
136 |
void SignatureIterator::dispatch_field() { |
|
137 |
// no '(', just one (field) type |
|
138 |
_index = 0; |
|
139 |
_parameter_index = 0; |
|
140 |
parse_type(); |
|
141 |
check_signature_end(); |
|
142 |
} |
|
143 |
||
144 |
||
145 |
void SignatureIterator::iterate_parameters() { |
|
146 |
// Parse parameters |
|
147 |
_index = 0; |
|
148 |
_parameter_index = 0; |
|
149 |
expect('('); |
|
150 |
while (_signature->byte_at(_index) != ')') _parameter_index += parse_type(); |
|
151 |
expect(')'); |
|
152 |
_parameter_index = 0; |
|
153 |
} |
|
154 |
||
22551 | 155 |
// Optimized version of iterate_parameters when fingerprint is known |
1 | 156 |
void SignatureIterator::iterate_parameters( uint64_t fingerprint ) { |
157 |
uint64_t saved_fingerprint = fingerprint; |
|
158 |
||
159 |
// Check for too many arguments |
|
160 |
if ( fingerprint == UCONST64(-1) ) { |
|
161 |
SignatureIterator::iterate_parameters(); |
|
162 |
return; |
|
163 |
} |
|
164 |
||
165 |
assert(fingerprint, "Fingerprint should not be 0"); |
|
166 |
||
167 |
_parameter_index = 0; |
|
168 |
fingerprint = fingerprint >> (static_feature_size + result_feature_size); |
|
169 |
while ( 1 ) { |
|
170 |
switch ( fingerprint & parameter_feature_mask ) { |
|
171 |
case bool_parm: |
|
172 |
do_bool(); |
|
173 |
_parameter_index += T_BOOLEAN_size; |
|
174 |
break; |
|
175 |
case byte_parm: |
|
176 |
do_byte(); |
|
177 |
_parameter_index += T_BYTE_size; |
|
178 |
break; |
|
179 |
case char_parm: |
|
180 |
do_char(); |
|
181 |
_parameter_index += T_CHAR_size; |
|
182 |
break; |
|
183 |
case short_parm: |
|
184 |
do_short(); |
|
185 |
_parameter_index += T_SHORT_size; |
|
186 |
break; |
|
187 |
case int_parm: |
|
188 |
do_int(); |
|
189 |
_parameter_index += T_INT_size; |
|
190 |
break; |
|
191 |
case obj_parm: |
|
192 |
do_object(0, 0); |
|
193 |
_parameter_index += T_OBJECT_size; |
|
194 |
break; |
|
195 |
case long_parm: |
|
196 |
do_long(); |
|
197 |
_parameter_index += T_LONG_size; |
|
198 |
break; |
|
199 |
case float_parm: |
|
200 |
do_float(); |
|
201 |
_parameter_index += T_FLOAT_size; |
|
202 |
break; |
|
203 |
case double_parm: |
|
204 |
do_double(); |
|
205 |
_parameter_index += T_DOUBLE_size; |
|
206 |
break; |
|
207 |
case done_parm: |
|
208 |
return; |
|
209 |
break; |
|
210 |
default: |
|
211 |
tty->print_cr("*** parameter is %d", fingerprint & parameter_feature_mask); |
|
212 |
tty->print_cr("*** fingerprint is " PTR64_FORMAT, saved_fingerprint); |
|
213 |
ShouldNotReachHere(); |
|
214 |
break; |
|
215 |
} |
|
216 |
fingerprint >>= parameter_feature_size; |
|
217 |
} |
|
218 |
_parameter_index = 0; |
|
219 |
} |
|
220 |
||
221 |
||
222 |
void SignatureIterator::iterate_returntype() { |
|
223 |
// Ignore parameters |
|
224 |
_index = 0; |
|
225 |
expect('('); |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
226 |
Symbol* sig = _signature; |
1 | 227 |
while (sig->byte_at(_index) != ')') _index++; |
228 |
expect(')'); |
|
229 |
// Parse return type |
|
230 |
_parameter_index = -1; |
|
231 |
parse_type(); |
|
232 |
check_signature_end(); |
|
233 |
_parameter_index = 0; |
|
234 |
} |
|
235 |
||
236 |
||
237 |
void SignatureIterator::iterate() { |
|
238 |
// Parse parameters |
|
239 |
_parameter_index = 0; |
|
240 |
_index = 0; |
|
241 |
expect('('); |
|
242 |
while (_signature->byte_at(_index) != ')') _parameter_index += parse_type(); |
|
243 |
expect(')'); |
|
244 |
// Parse return type |
|
245 |
_parameter_index = -1; |
|
246 |
parse_type(); |
|
247 |
check_signature_end(); |
|
248 |
_parameter_index = 0; |
|
249 |
} |
|
250 |
||
251 |
||
252 |
// Implementation of SignatureStream |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
253 |
SignatureStream::SignatureStream(Symbol* signature, bool is_method) : |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
254 |
_signature(signature), _at_return_type(false) { |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
255 |
_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
|
256 |
_names = new GrowableArray<Symbol*>(10); |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
257 |
next(); |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
258 |
} |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
259 |
|
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
260 |
SignatureStream::~SignatureStream() { |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
261 |
// decrement refcount for names created during signature parsing |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
262 |
for (int i = 0; i < _names->length(); i++) { |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
263 |
_names->at(i)->decrement_refcount(); |
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 |
} |
1 | 266 |
|
267 |
bool SignatureStream::is_done() const { |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
268 |
return _end > _signature->utf8_length(); |
1 | 269 |
} |
270 |
||
271 |
||
272 |
void SignatureStream::next_non_primitive(int t) { |
|
273 |
switch (t) { |
|
274 |
case 'L': { |
|
275 |
_type = T_OBJECT; |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
276 |
Symbol* sig = _signature; |
1 | 277 |
while (sig->byte_at(_end++) != ';'); |
278 |
break; |
|
279 |
} |
|
280 |
case '[': { |
|
281 |
_type = T_ARRAY; |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
282 |
Symbol* sig = _signature; |
1 | 283 |
char c = sig->byte_at(_end); |
284 |
while ('0' <= c && c <= '9') c = sig->byte_at(_end++); |
|
285 |
while (sig->byte_at(_end) == '[') { |
|
286 |
_end++; |
|
287 |
c = sig->byte_at(_end); |
|
288 |
while ('0' <= c && c <= '9') c = sig->byte_at(_end++); |
|
289 |
} |
|
290 |
switch(sig->byte_at(_end)) { |
|
291 |
case 'B': |
|
292 |
case 'C': |
|
293 |
case 'D': |
|
294 |
case 'F': |
|
295 |
case 'I': |
|
296 |
case 'J': |
|
297 |
case 'S': |
|
298 |
case 'Z':_end++; break; |
|
299 |
default: { |
|
300 |
while (sig->byte_at(_end++) != ';'); |
|
301 |
break; |
|
302 |
} |
|
303 |
} |
|
304 |
break; |
|
305 |
} |
|
306 |
case ')': _end++; next(); _at_return_type = true; break; |
|
307 |
default : ShouldNotReachHere(); |
|
308 |
} |
|
309 |
} |
|
310 |
||
311 |
||
312 |
bool SignatureStream::is_object() const { |
|
313 |
return _type == T_OBJECT |
|
314 |
|| _type == T_ARRAY; |
|
315 |
} |
|
316 |
||
317 |
bool SignatureStream::is_array() const { |
|
318 |
return _type == T_ARRAY; |
|
319 |
} |
|
320 |
||
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
321 |
Symbol* SignatureStream::as_symbol(TRAPS) { |
1 | 322 |
// Create a symbol from for string _begin _end |
323 |
int begin = _begin; |
|
324 |
int end = _end; |
|
325 |
||
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
326 |
if ( _signature->byte_at(_begin) == 'L' |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
327 |
&& _signature->byte_at(_end-1) == ';') { |
1 | 328 |
begin++; |
329 |
end--; |
|
330 |
} |
|
331 |
||
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
332 |
// 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
|
333 |
// SignatureStream scope. |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
334 |
Symbol* name = SymbolTable::new_symbol(_signature, begin, end, CHECK_NULL); |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
335 |
_names->push(name); // save new symbol for decrementing later |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
336 |
return name; |
1 | 337 |
} |
338 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8921
diff
changeset
|
339 |
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
|
340 |
FailureMode failure_mode, TRAPS) { |
e294db54fc0d
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1
diff
changeset
|
341 |
if (!is_object()) return NULL; |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
342 |
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
|
343 |
if (failure_mode == ReturnNull) { |
e294db54fc0d
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1
diff
changeset
|
344 |
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
|
345 |
} else { |
e294db54fc0d
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1
diff
changeset
|
346 |
bool throw_error = (failure_mode == NCDFError); |
e294db54fc0d
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1
diff
changeset
|
347 |
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
|
348 |
} |
e294db54fc0d
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1
diff
changeset
|
349 |
} |
e294db54fc0d
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1
diff
changeset
|
350 |
|
e294db54fc0d
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1
diff
changeset
|
351 |
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
|
352 |
FailureMode failure_mode, TRAPS) { |
e294db54fc0d
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1
diff
changeset
|
353 |
if (!is_object()) |
e294db54fc0d
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1
diff
changeset
|
354 |
return Universe::java_mirror(type()); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
8921
diff
changeset
|
355 |
Klass* klass = as_klass(class_loader, protection_domain, failure_mode, CHECK_NULL); |
5421
e294db54fc0d
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1
diff
changeset
|
356 |
if (klass == NULL) return NULL; |
14488 | 357 |
return klass->java_mirror(); |
5421
e294db54fc0d
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
1
diff
changeset
|
358 |
} |
1 | 359 |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
360 |
Symbol* SignatureStream::as_symbol_or_null() { |
1 | 361 |
// Create a symbol from for string _begin _end |
362 |
ResourceMark rm; |
|
363 |
||
364 |
int begin = _begin; |
|
365 |
int end = _end; |
|
366 |
||
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
367 |
if ( _signature->byte_at(_begin) == 'L' |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
368 |
&& _signature->byte_at(_end-1) == ';') { |
1 | 369 |
begin++; |
370 |
end--; |
|
371 |
} |
|
372 |
||
373 |
char* buffer = NEW_RESOURCE_ARRAY(char, end - begin); |
|
374 |
for (int index = begin; index < end; index++) { |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
375 |
buffer[index - begin] = _signature->byte_at(index); |
1 | 376 |
} |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
377 |
Symbol* result = SymbolTable::probe(buffer, end - begin); |
1 | 378 |
return result; |
379 |
} |
|
380 |
||
20702
bbe0fcde6e13
8023657: New type profiling points: arguments to call
roland
parents:
14488
diff
changeset
|
381 |
int SignatureStream::reference_parameter_count() { |
bbe0fcde6e13
8023657: New type profiling points: arguments to call
roland
parents:
14488
diff
changeset
|
382 |
int args_count = 0; |
bbe0fcde6e13
8023657: New type profiling points: arguments to call
roland
parents:
14488
diff
changeset
|
383 |
for ( ; !at_return_type(); next()) { |
bbe0fcde6e13
8023657: New type profiling points: arguments to call
roland
parents:
14488
diff
changeset
|
384 |
if (is_object()) { |
bbe0fcde6e13
8023657: New type profiling points: arguments to call
roland
parents:
14488
diff
changeset
|
385 |
args_count++; |
bbe0fcde6e13
8023657: New type profiling points: arguments to call
roland
parents:
14488
diff
changeset
|
386 |
} |
bbe0fcde6e13
8023657: New type profiling points: arguments to call
roland
parents:
14488
diff
changeset
|
387 |
} |
bbe0fcde6e13
8023657: New type profiling points: arguments to call
roland
parents:
14488
diff
changeset
|
388 |
return args_count; |
bbe0fcde6e13
8023657: New type profiling points: arguments to call
roland
parents:
14488
diff
changeset
|
389 |
} |
bbe0fcde6e13
8023657: New type profiling points: arguments to call
roland
parents:
14488
diff
changeset
|
390 |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
391 |
bool SignatureVerifier::is_valid_signature(Symbol* sig) { |
1 | 392 |
const char* signature = (const char*)sig->bytes(); |
393 |
ssize_t len = sig->utf8_length(); |
|
394 |
if (signature == NULL || signature[0] == '\0' || len < 1) { |
|
395 |
return false; |
|
396 |
} else if (signature[0] == '(') { |
|
397 |
return is_valid_method_signature(sig); |
|
398 |
} else { |
|
399 |
return is_valid_type_signature(sig); |
|
400 |
} |
|
401 |
} |
|
402 |
||
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
403 |
bool SignatureVerifier::is_valid_method_signature(Symbol* sig) { |
1 | 404 |
const char* method_sig = (const char*)sig->bytes(); |
405 |
ssize_t len = sig->utf8_length(); |
|
406 |
ssize_t index = 0; |
|
407 |
if (method_sig != NULL && len > 1 && method_sig[index] == '(') { |
|
408 |
++index; |
|
409 |
while (index < len && method_sig[index] != ')') { |
|
410 |
ssize_t res = is_valid_type(&method_sig[index], len - index); |
|
411 |
if (res == -1) { |
|
412 |
return false; |
|
413 |
} else { |
|
414 |
index += res; |
|
415 |
} |
|
416 |
} |
|
417 |
if (index < len && method_sig[index] == ')') { |
|
418 |
// check the return type |
|
419 |
++index; |
|
420 |
return (is_valid_type(&method_sig[index], len - index) == (len - index)); |
|
421 |
} |
|
422 |
} |
|
423 |
return false; |
|
424 |
} |
|
425 |
||
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
426 |
bool SignatureVerifier::is_valid_type_signature(Symbol* sig) { |
1 | 427 |
const char* type_sig = (const char*)sig->bytes(); |
428 |
ssize_t len = sig->utf8_length(); |
|
429 |
return (type_sig != NULL && len >= 1 && |
|
430 |
(is_valid_type(type_sig, len) == len)); |
|
431 |
} |
|
432 |
||
433 |
// Checks to see if the type (not to go beyond 'limit') refers to a valid type. |
|
434 |
// Returns -1 if it is not, or the index of the next character that is not part |
|
435 |
// of the type. The type encoding may end before 'limit' and that's ok. |
|
436 |
ssize_t SignatureVerifier::is_valid_type(const char* type, ssize_t limit) { |
|
437 |
ssize_t index = 0; |
|
438 |
||
439 |
// Iterate over any number of array dimensions |
|
440 |
while (index < limit && type[index] == '[') ++index; |
|
441 |
if (index >= limit) { |
|
442 |
return -1; |
|
443 |
} |
|
444 |
switch (type[index]) { |
|
445 |
case 'B': case 'C': case 'D': case 'F': case 'I': |
|
446 |
case 'J': case 'S': case 'Z': case 'V': |
|
447 |
return index + 1; |
|
448 |
case 'L': |
|
449 |
for (index = index + 1; index < limit; ++index) { |
|
450 |
char c = type[index]; |
|
451 |
if (c == ';') { |
|
452 |
return index + 1; |
|
453 |
} |
|
454 |
if (invalid_name_char(c)) { |
|
455 |
return -1; |
|
456 |
} |
|
457 |
} |
|
458 |
// fall through |
|
459 |
default: ; // fall through |
|
460 |
} |
|
461 |
return -1; |
|
462 |
} |
|
463 |
||
464 |
bool SignatureVerifier::invalid_name_char(char c) { |
|
465 |
switch (c) { |
|
466 |
case '\0': case '.': case ';': case '[': |
|
467 |
return true; |
|
468 |
default: |
|
469 |
return false; |
|
470 |
} |
|
471 |
} |