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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
25 #include "precompiled.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
26 #include "classfile/symbolTable.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
27 #include "classfile/systemDictionary.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
28 #include "memory/oopFactory.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
29 #include "oops/instanceKlass.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
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
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
32 #include "oops/typeArrayKlass.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
33 #include "runtime/signature.hpp"
0
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
36
a61af66fc99e Initial load
duke
parents:
diff changeset
37 // Implementation of SignatureIterator
a61af66fc99e Initial load
duke
parents:
diff changeset
38
a61af66fc99e Initial load
duke
parents:
diff changeset
39 // Signature syntax:
a61af66fc99e Initial load
duke
parents:
diff changeset
40 //
a61af66fc99e Initial load
duke
parents:
diff changeset
41 // Signature = "(" {Parameter} ")" ReturnType.
a61af66fc99e Initial load
duke
parents:
diff changeset
42 // Parameter = FieldType.
a61af66fc99e Initial load
duke
parents:
diff changeset
43 // ReturnType = FieldType | "V".
a61af66fc99e Initial load
duke
parents:
diff changeset
44 // FieldType = "B" | "C" | "D" | "F" | "I" | "J" | "S" | "Z" | "L" ClassName ";" | "[" FieldType.
a61af66fc99e Initial load
duke
parents:
diff changeset
45 // ClassName = string.
a61af66fc99e Initial load
duke
parents:
diff changeset
46
a61af66fc99e Initial load
duke
parents:
diff changeset
47
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
48 SignatureIterator::SignatureIterator(Symbol* signature) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
49 _signature = signature;
a61af66fc99e Initial load
duke
parents:
diff changeset
50 _parameter_index = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
51 }
a61af66fc99e Initial load
duke
parents:
diff changeset
52
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
55 _index++;
a61af66fc99e Initial load
duke
parents:
diff changeset
56 }
a61af66fc99e Initial load
duke
parents:
diff changeset
57
a61af66fc99e Initial load
duke
parents:
diff changeset
58
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
61 char c = sig->byte_at(_index);
a61af66fc99e Initial load
duke
parents:
diff changeset
62 while ('0' <= c && c <= '9') c = sig->byte_at(++_index);
a61af66fc99e Initial load
duke
parents:
diff changeset
63 }
a61af66fc99e Initial load
duke
parents:
diff changeset
64
a61af66fc99e Initial load
duke
parents:
diff changeset
65
a61af66fc99e Initial load
duke
parents:
diff changeset
66 int SignatureIterator::parse_type() {
a61af66fc99e Initial load
duke
parents:
diff changeset
67 // Note: This function could be simplified by using "return T_XXX_size;"
a61af66fc99e Initial load
duke
parents:
diff changeset
68 // instead of the assignment and the break statements. However, it
a61af66fc99e Initial load
duke
parents:
diff changeset
69 // seems that the product build for win32_i486 with MS VC++ 6.0 doesn't
a61af66fc99e Initial load
duke
parents:
diff changeset
70 // work (stack underflow for some tests) - this seems to be a VC++ 6.0
a61af66fc99e Initial load
duke
parents:
diff changeset
71 // compiler bug (was problem - gri 4/27/2000).
a61af66fc99e Initial load
duke
parents:
diff changeset
72 int size = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
73 switch(_signature->byte_at(_index)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
74 case 'B': do_byte (); if (_parameter_index < 0 ) _return_type = T_BYTE;
a61af66fc99e Initial load
duke
parents:
diff changeset
75 _index++; size = T_BYTE_size ; break;
a61af66fc99e Initial load
duke
parents:
diff changeset
76 case 'C': do_char (); if (_parameter_index < 0 ) _return_type = T_CHAR;
a61af66fc99e Initial load
duke
parents:
diff changeset
77 _index++; size = T_CHAR_size ; break;
a61af66fc99e Initial load
duke
parents:
diff changeset
78 case 'D': do_double(); if (_parameter_index < 0 ) _return_type = T_DOUBLE;
a61af66fc99e Initial load
duke
parents:
diff changeset
79 _index++; size = T_DOUBLE_size ; break;
a61af66fc99e Initial load
duke
parents:
diff changeset
80 case 'F': do_float (); if (_parameter_index < 0 ) _return_type = T_FLOAT;
a61af66fc99e Initial load
duke
parents:
diff changeset
81 _index++; size = T_FLOAT_size ; break;
a61af66fc99e Initial load
duke
parents:
diff changeset
82 case 'I': do_int (); if (_parameter_index < 0 ) _return_type = T_INT;
a61af66fc99e Initial load
duke
parents:
diff changeset
83 _index++; size = T_INT_size ; break;
a61af66fc99e Initial load
duke
parents:
diff changeset
84 case 'J': do_long (); if (_parameter_index < 0 ) _return_type = T_LONG;
a61af66fc99e Initial load
duke
parents:
diff changeset
85 _index++; size = T_LONG_size ; break;
a61af66fc99e Initial load
duke
parents:
diff changeset
86 case 'S': do_short (); if (_parameter_index < 0 ) _return_type = T_SHORT;
a61af66fc99e Initial load
duke
parents:
diff changeset
87 _index++; size = T_SHORT_size ; break;
a61af66fc99e Initial load
duke
parents:
diff changeset
88 case 'Z': do_bool (); if (_parameter_index < 0 ) _return_type = T_BOOLEAN;
a61af66fc99e Initial load
duke
parents:
diff changeset
89 _index++; size = T_BOOLEAN_size; break;
a61af66fc99e Initial load
duke
parents:
diff changeset
90 case 'V': do_void (); if (_parameter_index < 0 ) _return_type = T_VOID;
a61af66fc99e Initial load
duke
parents:
diff changeset
91 _index++; size = T_VOID_size; ; break;
a61af66fc99e Initial load
duke
parents:
diff changeset
92 case 'L':
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
95 while (sig->byte_at(_index++) != ';') ;
a61af66fc99e Initial load
duke
parents:
diff changeset
96 do_object(begin, _index);
a61af66fc99e Initial load
duke
parents:
diff changeset
97 }
a61af66fc99e Initial load
duke
parents:
diff changeset
98 if (_parameter_index < 0 ) _return_type = T_OBJECT;
a61af66fc99e Initial load
duke
parents:
diff changeset
99 size = T_OBJECT_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
100 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
101 case '[':
a61af66fc99e Initial load
duke
parents:
diff changeset
102 { int begin = ++_index;
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
105 while (sig->byte_at(_index) == '[') {
a61af66fc99e Initial load
duke
parents:
diff changeset
106 _index++;
a61af66fc99e Initial load
duke
parents:
diff changeset
107 skip_optional_size();
a61af66fc99e Initial load
duke
parents:
diff changeset
108 }
a61af66fc99e Initial load
duke
parents:
diff changeset
109 if (sig->byte_at(_index) == 'L') {
a61af66fc99e Initial load
duke
parents:
diff changeset
110 while (sig->byte_at(_index++) != ';') ;
a61af66fc99e Initial load
duke
parents:
diff changeset
111 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
112 _index++;
a61af66fc99e Initial load
duke
parents:
diff changeset
113 }
a61af66fc99e Initial load
duke
parents:
diff changeset
114 do_array(begin, _index);
a61af66fc99e Initial load
duke
parents:
diff changeset
115 if (_parameter_index < 0 ) _return_type = T_ARRAY;
a61af66fc99e Initial load
duke
parents:
diff changeset
116 }
a61af66fc99e Initial load
duke
parents:
diff changeset
117 size = T_ARRAY_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
118 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
119 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
120 ShouldNotReachHere();
a61af66fc99e Initial load
duke
parents:
diff changeset
121 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
122 }
a61af66fc99e Initial load
duke
parents:
diff changeset
123 assert(size >= 0, "size must be set");
a61af66fc99e Initial load
duke
parents:
diff changeset
124 return size;
a61af66fc99e Initial load
duke
parents:
diff changeset
125 }
a61af66fc99e Initial load
duke
parents:
diff changeset
126
a61af66fc99e Initial load
duke
parents:
diff changeset
127
a61af66fc99e Initial load
duke
parents:
diff changeset
128 void SignatureIterator::check_signature_end() {
a61af66fc99e Initial load
duke
parents:
diff changeset
129 if (_index < _signature->utf8_length()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
130 tty->print_cr("too many chars in signature");
a61af66fc99e Initial load
duke
parents:
diff changeset
131 _signature->print_value_on(tty);
a61af66fc99e Initial load
duke
parents:
diff changeset
132 tty->print_cr(" @ %d", _index);
a61af66fc99e Initial load
duke
parents:
diff changeset
133 }
a61af66fc99e Initial load
duke
parents:
diff changeset
134 }
a61af66fc99e Initial load
duke
parents:
diff changeset
135
a61af66fc99e Initial load
duke
parents:
diff changeset
136
a61af66fc99e Initial load
duke
parents:
diff changeset
137 void SignatureIterator::dispatch_field() {
a61af66fc99e Initial load
duke
parents:
diff changeset
138 // no '(', just one (field) type
a61af66fc99e Initial load
duke
parents:
diff changeset
139 _index = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
140 _parameter_index = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
141 parse_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
142 check_signature_end();
a61af66fc99e Initial load
duke
parents:
diff changeset
143 }
a61af66fc99e Initial load
duke
parents:
diff changeset
144
a61af66fc99e Initial load
duke
parents:
diff changeset
145
a61af66fc99e Initial load
duke
parents:
diff changeset
146 void SignatureIterator::iterate_parameters() {
a61af66fc99e Initial load
duke
parents:
diff changeset
147 // Parse parameters
a61af66fc99e Initial load
duke
parents:
diff changeset
148 _index = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
149 _parameter_index = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
150 expect('(');
a61af66fc99e Initial load
duke
parents:
diff changeset
151 while (_signature->byte_at(_index) != ')') _parameter_index += parse_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
152 expect(')');
a61af66fc99e Initial load
duke
parents:
diff changeset
153 _parameter_index = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
154 }
a61af66fc99e Initial load
duke
parents:
diff changeset
155
a61af66fc99e Initial load
duke
parents:
diff changeset
156 // Optimized version of iterat_parameters when fingerprint is known
a61af66fc99e Initial load
duke
parents:
diff changeset
157 void SignatureIterator::iterate_parameters( uint64_t fingerprint ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
158 uint64_t saved_fingerprint = fingerprint;
a61af66fc99e Initial load
duke
parents:
diff changeset
159
a61af66fc99e Initial load
duke
parents:
diff changeset
160 // Check for too many arguments
a61af66fc99e Initial load
duke
parents:
diff changeset
161 if ( fingerprint == UCONST64(-1) ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
162 SignatureIterator::iterate_parameters();
a61af66fc99e Initial load
duke
parents:
diff changeset
163 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
164 }
a61af66fc99e Initial load
duke
parents:
diff changeset
165
a61af66fc99e Initial load
duke
parents:
diff changeset
166 assert(fingerprint, "Fingerprint should not be 0");
a61af66fc99e Initial load
duke
parents:
diff changeset
167
a61af66fc99e Initial load
duke
parents:
diff changeset
168 _parameter_index = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
169 fingerprint = fingerprint >> (static_feature_size + result_feature_size);
a61af66fc99e Initial load
duke
parents:
diff changeset
170 while ( 1 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
171 switch ( fingerprint & parameter_feature_mask ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
172 case bool_parm:
a61af66fc99e Initial load
duke
parents:
diff changeset
173 do_bool();
a61af66fc99e Initial load
duke
parents:
diff changeset
174 _parameter_index += T_BOOLEAN_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
175 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
176 case byte_parm:
a61af66fc99e Initial load
duke
parents:
diff changeset
177 do_byte();
a61af66fc99e Initial load
duke
parents:
diff changeset
178 _parameter_index += T_BYTE_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
179 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
180 case char_parm:
a61af66fc99e Initial load
duke
parents:
diff changeset
181 do_char();
a61af66fc99e Initial load
duke
parents:
diff changeset
182 _parameter_index += T_CHAR_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
183 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
184 case short_parm:
a61af66fc99e Initial load
duke
parents:
diff changeset
185 do_short();
a61af66fc99e Initial load
duke
parents:
diff changeset
186 _parameter_index += T_SHORT_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
187 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
188 case int_parm:
a61af66fc99e Initial load
duke
parents:
diff changeset
189 do_int();
a61af66fc99e Initial load
duke
parents:
diff changeset
190 _parameter_index += T_INT_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
191 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
192 case obj_parm:
a61af66fc99e Initial load
duke
parents:
diff changeset
193 do_object(0, 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
194 _parameter_index += T_OBJECT_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
195 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
196 case long_parm:
a61af66fc99e Initial load
duke
parents:
diff changeset
197 do_long();
a61af66fc99e Initial load
duke
parents:
diff changeset
198 _parameter_index += T_LONG_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
199 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
200 case float_parm:
a61af66fc99e Initial load
duke
parents:
diff changeset
201 do_float();
a61af66fc99e Initial load
duke
parents:
diff changeset
202 _parameter_index += T_FLOAT_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
203 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
204 case double_parm:
a61af66fc99e Initial load
duke
parents:
diff changeset
205 do_double();
a61af66fc99e Initial load
duke
parents:
diff changeset
206 _parameter_index += T_DOUBLE_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
207 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
208 case done_parm:
a61af66fc99e Initial load
duke
parents:
diff changeset
209 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
210 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
211 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
212 tty->print_cr("*** parameter is %d", fingerprint & parameter_feature_mask);
a61af66fc99e Initial load
duke
parents:
diff changeset
213 tty->print_cr("*** fingerprint is " PTR64_FORMAT, saved_fingerprint);
a61af66fc99e Initial load
duke
parents:
diff changeset
214 ShouldNotReachHere();
a61af66fc99e Initial load
duke
parents:
diff changeset
215 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
216 }
a61af66fc99e Initial load
duke
parents:
diff changeset
217 fingerprint >>= parameter_feature_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
218 }
a61af66fc99e Initial load
duke
parents:
diff changeset
219 _parameter_index = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
220 }
a61af66fc99e Initial load
duke
parents:
diff changeset
221
a61af66fc99e Initial load
duke
parents:
diff changeset
222
a61af66fc99e Initial load
duke
parents:
diff changeset
223 void SignatureIterator::iterate_returntype() {
a61af66fc99e Initial load
duke
parents:
diff changeset
224 // Ignore parameters
a61af66fc99e Initial load
duke
parents:
diff changeset
225 _index = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
226 expect('(');
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1972
diff changeset
227 Symbol* sig = _signature;
23954
56e96eb12a4b 8157176: Improved classfile parsing
vkempik
parents: 17937
diff changeset
228 // Need to skip over each type in the signature's argument list until a
56e96eb12a4b 8157176: Improved classfile parsing
vkempik
parents: 17937
diff changeset
229 // closing ')' is found., then get the return type. We cannot just scan
56e96eb12a4b 8157176: Improved classfile parsing
vkempik
parents: 17937
diff changeset
230 // for the first ')' because ')' is a legal character in a type name.
56e96eb12a4b 8157176: Improved classfile parsing
vkempik
parents: 17937
diff changeset
231 while (sig->byte_at(_index) != ')') {
56e96eb12a4b 8157176: Improved classfile parsing
vkempik
parents: 17937
diff changeset
232 switch(sig->byte_at(_index)) {
56e96eb12a4b 8157176: Improved classfile parsing
vkempik
parents: 17937
diff changeset
233 case 'B':
56e96eb12a4b 8157176: Improved classfile parsing
vkempik
parents: 17937
diff changeset
234 case 'C':
56e96eb12a4b 8157176: Improved classfile parsing
vkempik
parents: 17937
diff changeset
235 case 'D':
56e96eb12a4b 8157176: Improved classfile parsing
vkempik
parents: 17937
diff changeset
236 case 'F':
56e96eb12a4b 8157176: Improved classfile parsing
vkempik
parents: 17937
diff changeset
237 case 'I':
56e96eb12a4b 8157176: Improved classfile parsing
vkempik
parents: 17937
diff changeset
238 case 'J':
56e96eb12a4b 8157176: Improved classfile parsing
vkempik
parents: 17937
diff changeset
239 case 'S':
56e96eb12a4b 8157176: Improved classfile parsing
vkempik
parents: 17937
diff changeset
240 case 'Z':
56e96eb12a4b 8157176: Improved classfile parsing
vkempik
parents: 17937
diff changeset
241 case 'V':
56e96eb12a4b 8157176: Improved classfile parsing
vkempik
parents: 17937
diff changeset
242 {
56e96eb12a4b 8157176: Improved classfile parsing
vkempik
parents: 17937
diff changeset
243 _index++;
56e96eb12a4b 8157176: Improved classfile parsing
vkempik
parents: 17937
diff changeset
244 }
56e96eb12a4b 8157176: Improved classfile parsing
vkempik
parents: 17937
diff changeset
245 break;
56e96eb12a4b 8157176: Improved classfile parsing
vkempik
parents: 17937
diff changeset
246 case 'L':
56e96eb12a4b 8157176: Improved classfile parsing
vkempik
parents: 17937
diff changeset
247 {
56e96eb12a4b 8157176: Improved classfile parsing
vkempik
parents: 17937
diff changeset
248 while (sig->byte_at(_index++) != ';') ;
56e96eb12a4b 8157176: Improved classfile parsing
vkempik
parents: 17937
diff changeset
249 }
56e96eb12a4b 8157176: Improved classfile parsing
vkempik
parents: 17937
diff changeset
250 break;
56e96eb12a4b 8157176: Improved classfile parsing
vkempik
parents: 17937
diff changeset
251 case '[':
56e96eb12a4b 8157176: Improved classfile parsing
vkempik
parents: 17937
diff changeset
252 {
56e96eb12a4b 8157176: Improved classfile parsing
vkempik
parents: 17937
diff changeset
253 int begin = ++_index;
56e96eb12a4b 8157176: Improved classfile parsing
vkempik
parents: 17937
diff changeset
254 skip_optional_size();
56e96eb12a4b 8157176: Improved classfile parsing
vkempik
parents: 17937
diff changeset
255 while (sig->byte_at(_index) == '[') {
56e96eb12a4b 8157176: Improved classfile parsing
vkempik
parents: 17937
diff changeset
256 _index++;
56e96eb12a4b 8157176: Improved classfile parsing
vkempik
parents: 17937
diff changeset
257 skip_optional_size();
56e96eb12a4b 8157176: Improved classfile parsing
vkempik
parents: 17937
diff changeset
258 }
56e96eb12a4b 8157176: Improved classfile parsing
vkempik
parents: 17937
diff changeset
259 if (sig->byte_at(_index) == 'L') {
56e96eb12a4b 8157176: Improved classfile parsing
vkempik
parents: 17937
diff changeset
260 while (sig->byte_at(_index++) != ';') ;
56e96eb12a4b 8157176: Improved classfile parsing
vkempik
parents: 17937
diff changeset
261 } else {
56e96eb12a4b 8157176: Improved classfile parsing
vkempik
parents: 17937
diff changeset
262 _index++;
56e96eb12a4b 8157176: Improved classfile parsing
vkempik
parents: 17937
diff changeset
263 }
56e96eb12a4b 8157176: Improved classfile parsing
vkempik
parents: 17937
diff changeset
264 }
56e96eb12a4b 8157176: Improved classfile parsing
vkempik
parents: 17937
diff changeset
265 break;
56e96eb12a4b 8157176: Improved classfile parsing
vkempik
parents: 17937
diff changeset
266 default:
56e96eb12a4b 8157176: Improved classfile parsing
vkempik
parents: 17937
diff changeset
267 ShouldNotReachHere();
56e96eb12a4b 8157176: Improved classfile parsing
vkempik
parents: 17937
diff changeset
268 break;
56e96eb12a4b 8157176: Improved classfile parsing
vkempik
parents: 17937
diff changeset
269 }
56e96eb12a4b 8157176: Improved classfile parsing
vkempik
parents: 17937
diff changeset
270 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
271 expect(')');
a61af66fc99e Initial load
duke
parents:
diff changeset
272 // Parse return type
a61af66fc99e Initial load
duke
parents:
diff changeset
273 _parameter_index = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
274 parse_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
275 check_signature_end();
a61af66fc99e Initial load
duke
parents:
diff changeset
276 _parameter_index = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
277 }
a61af66fc99e Initial load
duke
parents:
diff changeset
278
a61af66fc99e Initial load
duke
parents:
diff changeset
279
a61af66fc99e Initial load
duke
parents:
diff changeset
280 void SignatureIterator::iterate() {
a61af66fc99e Initial load
duke
parents:
diff changeset
281 // Parse parameters
a61af66fc99e Initial load
duke
parents:
diff changeset
282 _parameter_index = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
283 _index = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
284 expect('(');
a61af66fc99e Initial load
duke
parents:
diff changeset
285 while (_signature->byte_at(_index) != ')') _parameter_index += parse_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
286 expect(')');
a61af66fc99e Initial load
duke
parents:
diff changeset
287 // Parse return type
a61af66fc99e Initial load
duke
parents:
diff changeset
288 _parameter_index = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
289 parse_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
290 check_signature_end();
a61af66fc99e Initial load
duke
parents:
diff changeset
291 _parameter_index = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
292 }
a61af66fc99e Initial load
duke
parents:
diff changeset
293
a61af66fc99e Initial load
duke
parents:
diff changeset
294
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
309
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
312 }
a61af66fc99e Initial load
duke
parents:
diff changeset
313
a61af66fc99e Initial load
duke
parents:
diff changeset
314
a61af66fc99e Initial load
duke
parents:
diff changeset
315 void SignatureStream::next_non_primitive(int t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
316 switch (t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
317 case 'L': {
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
320 while (sig->byte_at(_end++) != ';');
a61af66fc99e Initial load
duke
parents:
diff changeset
321 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
322 }
a61af66fc99e Initial load
duke
parents:
diff changeset
323 case '[': {
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
326 char c = sig->byte_at(_end);
a61af66fc99e Initial load
duke
parents:
diff changeset
327 while ('0' <= c && c <= '9') c = sig->byte_at(_end++);
a61af66fc99e Initial load
duke
parents:
diff changeset
328 while (sig->byte_at(_end) == '[') {
a61af66fc99e Initial load
duke
parents:
diff changeset
329 _end++;
a61af66fc99e Initial load
duke
parents:
diff changeset
330 c = sig->byte_at(_end);
a61af66fc99e Initial load
duke
parents:
diff changeset
331 while ('0' <= c && c <= '9') c = sig->byte_at(_end++);
a61af66fc99e Initial load
duke
parents:
diff changeset
332 }
a61af66fc99e Initial load
duke
parents:
diff changeset
333 switch(sig->byte_at(_end)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
334 case 'B':
a61af66fc99e Initial load
duke
parents:
diff changeset
335 case 'C':
a61af66fc99e Initial load
duke
parents:
diff changeset
336 case 'D':
a61af66fc99e Initial load
duke
parents:
diff changeset
337 case 'F':
a61af66fc99e Initial load
duke
parents:
diff changeset
338 case 'I':
a61af66fc99e Initial load
duke
parents:
diff changeset
339 case 'J':
a61af66fc99e Initial load
duke
parents:
diff changeset
340 case 'S':
a61af66fc99e Initial load
duke
parents:
diff changeset
341 case 'Z':_end++; break;
a61af66fc99e Initial load
duke
parents:
diff changeset
342 default: {
a61af66fc99e Initial load
duke
parents:
diff changeset
343 while (sig->byte_at(_end++) != ';');
a61af66fc99e Initial load
duke
parents:
diff changeset
344 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
345 }
a61af66fc99e Initial load
duke
parents:
diff changeset
346 }
a61af66fc99e Initial load
duke
parents:
diff changeset
347 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
348 }
a61af66fc99e Initial load
duke
parents:
diff changeset
349 case ')': _end++; next(); _at_return_type = true; break;
a61af66fc99e Initial load
duke
parents:
diff changeset
350 default : ShouldNotReachHere();
a61af66fc99e Initial load
duke
parents:
diff changeset
351 }
a61af66fc99e Initial load
duke
parents:
diff changeset
352 }
a61af66fc99e Initial load
duke
parents:
diff changeset
353
a61af66fc99e Initial load
duke
parents:
diff changeset
354
a61af66fc99e Initial load
duke
parents:
diff changeset
355 bool SignatureStream::is_object() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
356 return _type == T_OBJECT
a61af66fc99e Initial load
duke
parents:
diff changeset
357 || _type == T_ARRAY;
a61af66fc99e Initial load
duke
parents:
diff changeset
358 }
a61af66fc99e Initial load
duke
parents:
diff changeset
359
a61af66fc99e Initial load
duke
parents:
diff changeset
360 bool SignatureStream::is_array() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
361 return _type == T_ARRAY;
a61af66fc99e Initial load
duke
parents:
diff changeset
362 }
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
365 // Create a symbol from for string _begin _end
a61af66fc99e Initial load
duke
parents:
diff changeset
366 int begin = _begin;
a61af66fc99e Initial load
duke
parents:
diff changeset
367 int end = _end;
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
371 begin++;
a61af66fc99e Initial load
duke
parents:
diff changeset
372 end--;
a61af66fc99e Initial load
duke
parents:
diff changeset
373 }
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
380 }
a61af66fc99e Initial load
duke
parents:
diff changeset
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
070d523b96a7 8001471: Klass::cast() does nothing
hseigel
parents: 6725
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
404 // Create a symbol from for string _begin _end
a61af66fc99e Initial load
duke
parents:
diff changeset
405 ResourceMark rm;
a61af66fc99e Initial load
duke
parents:
diff changeset
406
a61af66fc99e Initial load
duke
parents:
diff changeset
407 int begin = _begin;
a61af66fc99e Initial load
duke
parents:
diff changeset
408 int end = _end;
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
412 begin++;
a61af66fc99e Initial load
duke
parents:
diff changeset
413 end--;
a61af66fc99e Initial load
duke
parents:
diff changeset
414 }
a61af66fc99e Initial load
duke
parents:
diff changeset
415
a61af66fc99e Initial load
duke
parents:
diff changeset
416 char* buffer = NEW_RESOURCE_ARRAY(char, end - begin);
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
421 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
422 }
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
435 const char* signature = (const char*)sig->bytes();
a61af66fc99e Initial load
duke
parents:
diff changeset
436 ssize_t len = sig->utf8_length();
a61af66fc99e Initial load
duke
parents:
diff changeset
437 if (signature == NULL || signature[0] == '\0' || len < 1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
438 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
439 } else if (signature[0] == '(') {
a61af66fc99e Initial load
duke
parents:
diff changeset
440 return is_valid_method_signature(sig);
a61af66fc99e Initial load
duke
parents:
diff changeset
441 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
442 return is_valid_type_signature(sig);
a61af66fc99e Initial load
duke
parents:
diff changeset
443 }
a61af66fc99e Initial load
duke
parents:
diff changeset
444 }
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
447 const char* method_sig = (const char*)sig->bytes();
a61af66fc99e Initial load
duke
parents:
diff changeset
448 ssize_t len = sig->utf8_length();
a61af66fc99e Initial load
duke
parents:
diff changeset
449 ssize_t index = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
450 if (method_sig != NULL && len > 1 && method_sig[index] == '(') {
a61af66fc99e Initial load
duke
parents:
diff changeset
451 ++index;
a61af66fc99e Initial load
duke
parents:
diff changeset
452 while (index < len && method_sig[index] != ')') {
a61af66fc99e Initial load
duke
parents:
diff changeset
453 ssize_t res = is_valid_type(&method_sig[index], len - index);
a61af66fc99e Initial load
duke
parents:
diff changeset
454 if (res == -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
455 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
456 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
457 index += res;
a61af66fc99e Initial load
duke
parents:
diff changeset
458 }
a61af66fc99e Initial load
duke
parents:
diff changeset
459 }
a61af66fc99e Initial load
duke
parents:
diff changeset
460 if (index < len && method_sig[index] == ')') {
a61af66fc99e Initial load
duke
parents:
diff changeset
461 // check the return type
a61af66fc99e Initial load
duke
parents:
diff changeset
462 ++index;
a61af66fc99e Initial load
duke
parents:
diff changeset
463 return (is_valid_type(&method_sig[index], len - index) == (len - index));
a61af66fc99e Initial load
duke
parents:
diff changeset
464 }
a61af66fc99e Initial load
duke
parents:
diff changeset
465 }
a61af66fc99e Initial load
duke
parents:
diff changeset
466 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
467 }
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
470 const char* type_sig = (const char*)sig->bytes();
a61af66fc99e Initial load
duke
parents:
diff changeset
471 ssize_t len = sig->utf8_length();
a61af66fc99e Initial load
duke
parents:
diff changeset
472 return (type_sig != NULL && len >= 1 &&
a61af66fc99e Initial load
duke
parents:
diff changeset
473 (is_valid_type(type_sig, len) == len));
a61af66fc99e Initial load
duke
parents:
diff changeset
474 }
a61af66fc99e Initial load
duke
parents:
diff changeset
475
a61af66fc99e Initial load
duke
parents:
diff changeset
476 // Checks to see if the type (not to go beyond 'limit') refers to a valid type.
a61af66fc99e Initial load
duke
parents:
diff changeset
477 // Returns -1 if it is not, or the index of the next character that is not part
a61af66fc99e Initial load
duke
parents:
diff changeset
478 // of the type. The type encoding may end before 'limit' and that's ok.
a61af66fc99e Initial load
duke
parents:
diff changeset
479 ssize_t SignatureVerifier::is_valid_type(const char* type, ssize_t limit) {
a61af66fc99e Initial load
duke
parents:
diff changeset
480 ssize_t index = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
481
a61af66fc99e Initial load
duke
parents:
diff changeset
482 // Iterate over any number of array dimensions
a61af66fc99e Initial load
duke
parents:
diff changeset
483 while (index < limit && type[index] == '[') ++index;
a61af66fc99e Initial load
duke
parents:
diff changeset
484 if (index >= limit) {
a61af66fc99e Initial load
duke
parents:
diff changeset
485 return -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
486 }
a61af66fc99e Initial load
duke
parents:
diff changeset
487 switch (type[index]) {
a61af66fc99e Initial load
duke
parents:
diff changeset
488 case 'B': case 'C': case 'D': case 'F': case 'I':
a61af66fc99e Initial load
duke
parents:
diff changeset
489 case 'J': case 'S': case 'Z': case 'V':
a61af66fc99e Initial load
duke
parents:
diff changeset
490 return index + 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
491 case 'L':
a61af66fc99e Initial load
duke
parents:
diff changeset
492 for (index = index + 1; index < limit; ++index) {
a61af66fc99e Initial load
duke
parents:
diff changeset
493 char c = type[index];
a61af66fc99e Initial load
duke
parents:
diff changeset
494 if (c == ';') {
a61af66fc99e Initial load
duke
parents:
diff changeset
495 return index + 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
496 }
a61af66fc99e Initial load
duke
parents:
diff changeset
497 if (invalid_name_char(c)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
498 return -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
499 }
a61af66fc99e Initial load
duke
parents:
diff changeset
500 }
a61af66fc99e Initial load
duke
parents:
diff changeset
501 // fall through
a61af66fc99e Initial load
duke
parents:
diff changeset
502 default: ; // fall through
a61af66fc99e Initial load
duke
parents:
diff changeset
503 }
a61af66fc99e Initial load
duke
parents:
diff changeset
504 return -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
505 }
a61af66fc99e Initial load
duke
parents:
diff changeset
506
a61af66fc99e Initial load
duke
parents:
diff changeset
507 bool SignatureVerifier::invalid_name_char(char c) {
a61af66fc99e Initial load
duke
parents:
diff changeset
508 switch (c) {
a61af66fc99e Initial load
duke
parents:
diff changeset
509 case '\0': case '.': case ';': case '[':
a61af66fc99e Initial load
duke
parents:
diff changeset
510 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
511 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
512 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
513 }
a61af66fc99e Initial load
duke
parents:
diff changeset
514 }