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