Mercurial > hg > truffle
annotate src/share/vm/runtime/signature.cpp @ 20417:d35872270666
8057658: Enable G1 FullGC extensions
Summary: Refactored the G1 FullGC code to enable it to be extended.
Reviewed-by: mgerdin, brutisso
author | sjohanss |
---|---|
date | Tue, 09 Sep 2014 00:05:25 +0200 |
parents | 78bbf4d43a14 |
children | 52b4284cb496 |
rev | line source |
---|---|
0 | 1 /* |
17937
78bbf4d43a14
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
17467
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:
17467
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; |
0 | 228 while (sig->byte_at(_index) != ')') _index++; |
229 expect(')'); | |
230 // Parse return type | |
231 _parameter_index = -1; | |
232 parse_type(); | |
233 check_signature_end(); | |
234 _parameter_index = 0; | |
235 } | |
236 | |
237 | |
238 void SignatureIterator::iterate() { | |
239 // Parse parameters | |
240 _parameter_index = 0; | |
241 _index = 0; | |
242 expect('('); | |
243 while (_signature->byte_at(_index) != ')') _parameter_index += parse_type(); | |
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 // Implementation of SignatureStream | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
254 SignatureStream::SignatureStream(Symbol* signature, bool is_method) : |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
255 _signature(signature), _at_return_type(false) { |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
256 _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
|
257 _names = new GrowableArray<Symbol*>(10); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
258 next(); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
259 } |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
260 |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
261 SignatureStream::~SignatureStream() { |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
262 // decrement refcount for names created during signature parsing |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
263 for (int i = 0; i < _names->length(); i++) { |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
264 _names->at(i)->decrement_refcount(); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
265 } |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
266 } |
0 | 267 |
268 bool SignatureStream::is_done() const { | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
269 return _end > _signature->utf8_length(); |
0 | 270 } |
271 | |
272 | |
273 void SignatureStream::next_non_primitive(int t) { | |
274 switch (t) { | |
275 case 'L': { | |
276 _type = T_OBJECT; | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
277 Symbol* sig = _signature; |
0 | 278 while (sig->byte_at(_end++) != ';'); |
279 break; | |
280 } | |
281 case '[': { | |
282 _type = T_ARRAY; | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
283 Symbol* sig = _signature; |
0 | 284 char c = sig->byte_at(_end); |
285 while ('0' <= c && c <= '9') c = sig->byte_at(_end++); | |
286 while (sig->byte_at(_end) == '[') { | |
287 _end++; | |
288 c = sig->byte_at(_end); | |
289 while ('0' <= c && c <= '9') c = sig->byte_at(_end++); | |
290 } | |
291 switch(sig->byte_at(_end)) { | |
292 case 'B': | |
293 case 'C': | |
294 case 'D': | |
295 case 'F': | |
296 case 'I': | |
297 case 'J': | |
298 case 'S': | |
299 case 'Z':_end++; break; | |
300 default: { | |
301 while (sig->byte_at(_end++) != ';'); | |
302 break; | |
303 } | |
304 } | |
305 break; | |
306 } | |
307 case ')': _end++; next(); _at_return_type = true; break; | |
308 default : ShouldNotReachHere(); | |
309 } | |
310 } | |
311 | |
312 | |
313 bool SignatureStream::is_object() const { | |
314 return _type == T_OBJECT | |
315 || _type == T_ARRAY; | |
316 } | |
317 | |
318 bool SignatureStream::is_array() const { | |
319 return _type == T_ARRAY; | |
320 } | |
321 | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
322 Symbol* SignatureStream::as_symbol(TRAPS) { |
0 | 323 // Create a symbol from for string _begin _end |
324 int begin = _begin; | |
325 int end = _end; | |
326 | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
327 if ( _signature->byte_at(_begin) == 'L' |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
328 && _signature->byte_at(_end-1) == ';') { |
0 | 329 begin++; |
330 end--; | |
331 } | |
332 | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
333 // 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
|
334 // SignatureStream scope. |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
335 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
|
336 _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
|
337 return name; |
0 | 338 } |
339 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
340 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
|
341 FailureMode failure_mode, TRAPS) { |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
0
diff
changeset
|
342 if (!is_object()) return NULL; |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
343 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
|
344 if (failure_mode == ReturnNull) { |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
0
diff
changeset
|
345 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
|
346 } else { |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
0
diff
changeset
|
347 bool throw_error = (failure_mode == NCDFError); |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
0
diff
changeset
|
348 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
|
349 } |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
0
diff
changeset
|
350 } |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
0
diff
changeset
|
351 |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
0
diff
changeset
|
352 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
|
353 FailureMode failure_mode, TRAPS) { |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
0
diff
changeset
|
354 if (!is_object()) |
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
0
diff
changeset
|
355 return Universe::java_mirror(type()); |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
356 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
|
357 if (klass == NULL) return NULL; |
6983 | 358 return klass->java_mirror(); |
1508
2ffde6cfe049
6939196: method handle signatures off the boot class path get linkage errors
jrose
parents:
0
diff
changeset
|
359 } |
0 | 360 |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
361 Symbol* SignatureStream::as_symbol_or_null() { |
0 | 362 // Create a symbol from for string _begin _end |
363 ResourceMark rm; | |
364 | |
365 int begin = _begin; | |
366 int end = _end; | |
367 | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
368 if ( _signature->byte_at(_begin) == 'L' |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
369 && _signature->byte_at(_end-1) == ';') { |
0 | 370 begin++; |
371 end--; | |
372 } | |
373 | |
374 char* buffer = NEW_RESOURCE_ARRAY(char, end - begin); | |
375 for (int index = begin; index < end; index++) { | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
376 buffer[index - begin] = _signature->byte_at(index); |
0 | 377 } |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
378 Symbol* result = SymbolTable::probe(buffer, end - begin); |
0 | 379 return result; |
380 } | |
381 | |
12875
d13d7aba8c12
8023657: New type profiling points: arguments to call
roland
parents:
6983
diff
changeset
|
382 int SignatureStream::reference_parameter_count() { |
d13d7aba8c12
8023657: New type profiling points: arguments to call
roland
parents:
6983
diff
changeset
|
383 int args_count = 0; |
d13d7aba8c12
8023657: New type profiling points: arguments to call
roland
parents:
6983
diff
changeset
|
384 for ( ; !at_return_type(); next()) { |
d13d7aba8c12
8023657: New type profiling points: arguments to call
roland
parents:
6983
diff
changeset
|
385 if (is_object()) { |
d13d7aba8c12
8023657: New type profiling points: arguments to call
roland
parents:
6983
diff
changeset
|
386 args_count++; |
d13d7aba8c12
8023657: New type profiling points: arguments to call
roland
parents:
6983
diff
changeset
|
387 } |
d13d7aba8c12
8023657: New type profiling points: arguments to call
roland
parents:
6983
diff
changeset
|
388 } |
d13d7aba8c12
8023657: New type profiling points: arguments to call
roland
parents:
6983
diff
changeset
|
389 return args_count; |
d13d7aba8c12
8023657: New type profiling points: arguments to call
roland
parents:
6983
diff
changeset
|
390 } |
d13d7aba8c12
8023657: New type profiling points: arguments to call
roland
parents:
6983
diff
changeset
|
391 |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
392 bool SignatureVerifier::is_valid_signature(Symbol* sig) { |
0 | 393 const char* signature = (const char*)sig->bytes(); |
394 ssize_t len = sig->utf8_length(); | |
395 if (signature == NULL || signature[0] == '\0' || len < 1) { | |
396 return false; | |
397 } else if (signature[0] == '(') { | |
398 return is_valid_method_signature(sig); | |
399 } else { | |
400 return is_valid_type_signature(sig); | |
401 } | |
402 } | |
403 | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
404 bool SignatureVerifier::is_valid_method_signature(Symbol* sig) { |
0 | 405 const char* method_sig = (const char*)sig->bytes(); |
406 ssize_t len = sig->utf8_length(); | |
407 ssize_t index = 0; | |
408 if (method_sig != NULL && len > 1 && method_sig[index] == '(') { | |
409 ++index; | |
410 while (index < len && method_sig[index] != ')') { | |
411 ssize_t res = is_valid_type(&method_sig[index], len - index); | |
412 if (res == -1) { | |
413 return false; | |
414 } else { | |
415 index += res; | |
416 } | |
417 } | |
418 if (index < len && method_sig[index] == ')') { | |
419 // check the return type | |
420 ++index; | |
421 return (is_valid_type(&method_sig[index], len - index) == (len - index)); | |
422 } | |
423 } | |
424 return false; | |
425 } | |
426 | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
427 bool SignatureVerifier::is_valid_type_signature(Symbol* sig) { |
0 | 428 const char* type_sig = (const char*)sig->bytes(); |
429 ssize_t len = sig->utf8_length(); | |
430 return (type_sig != NULL && len >= 1 && | |
431 (is_valid_type(type_sig, len) == len)); | |
432 } | |
433 | |
434 // Checks to see if the type (not to go beyond 'limit') refers to a valid type. | |
435 // Returns -1 if it is not, or the index of the next character that is not part | |
436 // of the type. The type encoding may end before 'limit' and that's ok. | |
437 ssize_t SignatureVerifier::is_valid_type(const char* type, ssize_t limit) { | |
438 ssize_t index = 0; | |
439 | |
440 // Iterate over any number of array dimensions | |
441 while (index < limit && type[index] == '[') ++index; | |
442 if (index >= limit) { | |
443 return -1; | |
444 } | |
445 switch (type[index]) { | |
446 case 'B': case 'C': case 'D': case 'F': case 'I': | |
447 case 'J': case 'S': case 'Z': case 'V': | |
448 return index + 1; | |
449 case 'L': | |
450 for (index = index + 1; index < limit; ++index) { | |
451 char c = type[index]; | |
452 if (c == ';') { | |
453 return index + 1; | |
454 } | |
455 if (invalid_name_char(c)) { | |
456 return -1; | |
457 } | |
458 } | |
459 // fall through | |
460 default: ; // fall through | |
461 } | |
462 return -1; | |
463 } | |
464 | |
465 bool SignatureVerifier::invalid_name_char(char c) { | |
466 switch (c) { | |
467 case '\0': case '.': case ';': case '[': | |
468 return true; | |
469 default: | |
470 return false; | |
471 } | |
472 } |