annotate src/share/vm/runtime/signature.cpp @ 2129:8f8dfba37802

6994753: Implement optional hook to a Java method at VM startup. Reviewed-by: mchung, acorn
author kevinw
date Wed, 12 Jan 2011 15:44:16 +0000
parents f95d63e2154a
children 3582bf76420e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
2 * Copyright (c) 1997, 2010, 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"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
31 #include "oops/symbolOop.hpp"
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
a61af66fc99e Initial load
duke
parents:
diff changeset
35
a61af66fc99e Initial load
duke
parents:
diff changeset
36 // Implementation of SignatureIterator
a61af66fc99e Initial load
duke
parents:
diff changeset
37
a61af66fc99e Initial load
duke
parents:
diff changeset
38 // Signature syntax:
a61af66fc99e Initial load
duke
parents:
diff changeset
39 //
a61af66fc99e Initial load
duke
parents:
diff changeset
40 // Signature = "(" {Parameter} ")" ReturnType.
a61af66fc99e Initial load
duke
parents:
diff changeset
41 // Parameter = FieldType.
a61af66fc99e Initial load
duke
parents:
diff changeset
42 // ReturnType = FieldType | "V".
a61af66fc99e Initial load
duke
parents:
diff changeset
43 // FieldType = "B" | "C" | "D" | "F" | "I" | "J" | "S" | "Z" | "L" ClassName ";" | "[" FieldType.
a61af66fc99e Initial load
duke
parents:
diff changeset
44 // ClassName = string.
a61af66fc99e Initial load
duke
parents:
diff changeset
45
a61af66fc99e Initial load
duke
parents:
diff changeset
46
a61af66fc99e Initial load
duke
parents:
diff changeset
47 SignatureIterator::SignatureIterator(symbolHandle signature) {
a61af66fc99e Initial load
duke
parents:
diff changeset
48 assert(signature->is_symbol(), "not a symbol");
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 // Overloaded version called without handle
a61af66fc99e Initial load
duke
parents:
diff changeset
54 SignatureIterator::SignatureIterator(symbolOop signature) {
a61af66fc99e Initial load
duke
parents:
diff changeset
55 symbolHandle sh(Thread::current(), signature);
a61af66fc99e Initial load
duke
parents:
diff changeset
56 _signature = sh;
a61af66fc99e Initial load
duke
parents:
diff changeset
57 _parameter_index = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
58 }
a61af66fc99e Initial load
duke
parents:
diff changeset
59
a61af66fc99e Initial load
duke
parents:
diff changeset
60 SignatureIterator::SignatureIterator(Thread *thread, symbolOop signature) {
a61af66fc99e Initial load
duke
parents:
diff changeset
61 symbolHandle sh(thread, signature);
a61af66fc99e Initial load
duke
parents:
diff changeset
62 _signature = sh;
a61af66fc99e Initial load
duke
parents:
diff changeset
63 _parameter_index = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
64 }
a61af66fc99e Initial load
duke
parents:
diff changeset
65
a61af66fc99e Initial load
duke
parents:
diff changeset
66 void SignatureIterator::expect(char c) {
1490
f03d0a26bf83 6888954: argument formatting for assert() and friends
jcoomes
parents: 0
diff changeset
67 if (_signature->byte_at(_index) != c) fatal(err_msg("expecting %c", c));
0
a61af66fc99e Initial load
duke
parents:
diff changeset
68 _index++;
a61af66fc99e Initial load
duke
parents:
diff changeset
69 }
a61af66fc99e Initial load
duke
parents:
diff changeset
70
a61af66fc99e Initial load
duke
parents:
diff changeset
71
a61af66fc99e Initial load
duke
parents:
diff changeset
72 void SignatureIterator::skip_optional_size() {
a61af66fc99e Initial load
duke
parents:
diff changeset
73 symbolOop sig = _signature();
a61af66fc99e Initial load
duke
parents:
diff changeset
74 char c = sig->byte_at(_index);
a61af66fc99e Initial load
duke
parents:
diff changeset
75 while ('0' <= c && c <= '9') c = sig->byte_at(++_index);
a61af66fc99e Initial load
duke
parents:
diff changeset
76 }
a61af66fc99e Initial load
duke
parents:
diff changeset
77
a61af66fc99e Initial load
duke
parents:
diff changeset
78
a61af66fc99e Initial load
duke
parents:
diff changeset
79 int SignatureIterator::parse_type() {
a61af66fc99e Initial load
duke
parents:
diff changeset
80 // Note: This function could be simplified by using "return T_XXX_size;"
a61af66fc99e Initial load
duke
parents:
diff changeset
81 // instead of the assignment and the break statements. However, it
a61af66fc99e Initial load
duke
parents:
diff changeset
82 // seems that the product build for win32_i486 with MS VC++ 6.0 doesn't
a61af66fc99e Initial load
duke
parents:
diff changeset
83 // work (stack underflow for some tests) - this seems to be a VC++ 6.0
a61af66fc99e Initial load
duke
parents:
diff changeset
84 // compiler bug (was problem - gri 4/27/2000).
a61af66fc99e Initial load
duke
parents:
diff changeset
85 int size = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
86 switch(_signature->byte_at(_index)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
87 case 'B': do_byte (); if (_parameter_index < 0 ) _return_type = T_BYTE;
a61af66fc99e Initial load
duke
parents:
diff changeset
88 _index++; size = T_BYTE_size ; break;
a61af66fc99e Initial load
duke
parents:
diff changeset
89 case 'C': do_char (); if (_parameter_index < 0 ) _return_type = T_CHAR;
a61af66fc99e Initial load
duke
parents:
diff changeset
90 _index++; size = T_CHAR_size ; break;
a61af66fc99e Initial load
duke
parents:
diff changeset
91 case 'D': do_double(); if (_parameter_index < 0 ) _return_type = T_DOUBLE;
a61af66fc99e Initial load
duke
parents:
diff changeset
92 _index++; size = T_DOUBLE_size ; break;
a61af66fc99e Initial load
duke
parents:
diff changeset
93 case 'F': do_float (); if (_parameter_index < 0 ) _return_type = T_FLOAT;
a61af66fc99e Initial load
duke
parents:
diff changeset
94 _index++; size = T_FLOAT_size ; break;
a61af66fc99e Initial load
duke
parents:
diff changeset
95 case 'I': do_int (); if (_parameter_index < 0 ) _return_type = T_INT;
a61af66fc99e Initial load
duke
parents:
diff changeset
96 _index++; size = T_INT_size ; break;
a61af66fc99e Initial load
duke
parents:
diff changeset
97 case 'J': do_long (); if (_parameter_index < 0 ) _return_type = T_LONG;
a61af66fc99e Initial load
duke
parents:
diff changeset
98 _index++; size = T_LONG_size ; break;
a61af66fc99e Initial load
duke
parents:
diff changeset
99 case 'S': do_short (); if (_parameter_index < 0 ) _return_type = T_SHORT;
a61af66fc99e Initial load
duke
parents:
diff changeset
100 _index++; size = T_SHORT_size ; break;
a61af66fc99e Initial load
duke
parents:
diff changeset
101 case 'Z': do_bool (); if (_parameter_index < 0 ) _return_type = T_BOOLEAN;
a61af66fc99e Initial load
duke
parents:
diff changeset
102 _index++; size = T_BOOLEAN_size; break;
a61af66fc99e Initial load
duke
parents:
diff changeset
103 case 'V': do_void (); if (_parameter_index < 0 ) _return_type = T_VOID;
a61af66fc99e Initial load
duke
parents:
diff changeset
104 _index++; size = T_VOID_size; ; break;
a61af66fc99e Initial load
duke
parents:
diff changeset
105 case 'L':
a61af66fc99e Initial load
duke
parents:
diff changeset
106 { int begin = ++_index;
a61af66fc99e Initial load
duke
parents:
diff changeset
107 symbolOop sig = _signature();
a61af66fc99e Initial load
duke
parents:
diff changeset
108 while (sig->byte_at(_index++) != ';') ;
a61af66fc99e Initial load
duke
parents:
diff changeset
109 do_object(begin, _index);
a61af66fc99e Initial load
duke
parents:
diff changeset
110 }
a61af66fc99e Initial load
duke
parents:
diff changeset
111 if (_parameter_index < 0 ) _return_type = T_OBJECT;
a61af66fc99e Initial load
duke
parents:
diff changeset
112 size = T_OBJECT_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
113 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
114 case '[':
a61af66fc99e Initial load
duke
parents:
diff changeset
115 { int begin = ++_index;
a61af66fc99e Initial load
duke
parents:
diff changeset
116 skip_optional_size();
a61af66fc99e Initial load
duke
parents:
diff changeset
117 symbolOop sig = _signature();
a61af66fc99e Initial load
duke
parents:
diff changeset
118 while (sig->byte_at(_index) == '[') {
a61af66fc99e Initial load
duke
parents:
diff changeset
119 _index++;
a61af66fc99e Initial load
duke
parents:
diff changeset
120 skip_optional_size();
a61af66fc99e Initial load
duke
parents:
diff changeset
121 }
a61af66fc99e Initial load
duke
parents:
diff changeset
122 if (sig->byte_at(_index) == 'L') {
a61af66fc99e Initial load
duke
parents:
diff changeset
123 while (sig->byte_at(_index++) != ';') ;
a61af66fc99e Initial load
duke
parents:
diff changeset
124 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
125 _index++;
a61af66fc99e Initial load
duke
parents:
diff changeset
126 }
a61af66fc99e Initial load
duke
parents:
diff changeset
127 do_array(begin, _index);
a61af66fc99e Initial load
duke
parents:
diff changeset
128 if (_parameter_index < 0 ) _return_type = T_ARRAY;
a61af66fc99e Initial load
duke
parents:
diff changeset
129 }
a61af66fc99e Initial load
duke
parents:
diff changeset
130 size = T_ARRAY_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
131 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
132 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
133 ShouldNotReachHere();
a61af66fc99e Initial load
duke
parents:
diff changeset
134 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
135 }
a61af66fc99e Initial load
duke
parents:
diff changeset
136 assert(size >= 0, "size must be set");
a61af66fc99e Initial load
duke
parents:
diff changeset
137 return size;
a61af66fc99e Initial load
duke
parents:
diff changeset
138 }
a61af66fc99e Initial load
duke
parents:
diff changeset
139
a61af66fc99e Initial load
duke
parents:
diff changeset
140
a61af66fc99e Initial load
duke
parents:
diff changeset
141 void SignatureIterator::check_signature_end() {
a61af66fc99e Initial load
duke
parents:
diff changeset
142 if (_index < _signature->utf8_length()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
143 tty->print_cr("too many chars in signature");
a61af66fc99e Initial load
duke
parents:
diff changeset
144 _signature->print_value_on(tty);
a61af66fc99e Initial load
duke
parents:
diff changeset
145 tty->print_cr(" @ %d", _index);
a61af66fc99e Initial load
duke
parents:
diff changeset
146 }
a61af66fc99e Initial load
duke
parents:
diff changeset
147 }
a61af66fc99e Initial load
duke
parents:
diff changeset
148
a61af66fc99e Initial load
duke
parents:
diff changeset
149
a61af66fc99e Initial load
duke
parents:
diff changeset
150 void SignatureIterator::dispatch_field() {
a61af66fc99e Initial load
duke
parents:
diff changeset
151 // no '(', just one (field) type
a61af66fc99e Initial load
duke
parents:
diff changeset
152 _index = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
153 _parameter_index = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
154 parse_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
155 check_signature_end();
a61af66fc99e Initial load
duke
parents:
diff changeset
156 }
a61af66fc99e Initial load
duke
parents:
diff changeset
157
a61af66fc99e Initial load
duke
parents:
diff changeset
158
a61af66fc99e Initial load
duke
parents:
diff changeset
159 void SignatureIterator::iterate_parameters() {
a61af66fc99e Initial load
duke
parents:
diff changeset
160 // Parse parameters
a61af66fc99e Initial load
duke
parents:
diff changeset
161 _index = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
162 _parameter_index = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
163 expect('(');
a61af66fc99e Initial load
duke
parents:
diff changeset
164 while (_signature->byte_at(_index) != ')') _parameter_index += parse_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
165 expect(')');
a61af66fc99e Initial load
duke
parents:
diff changeset
166 _parameter_index = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
167 }
a61af66fc99e Initial load
duke
parents:
diff changeset
168
a61af66fc99e Initial load
duke
parents:
diff changeset
169 // Optimized version of iterat_parameters when fingerprint is known
a61af66fc99e Initial load
duke
parents:
diff changeset
170 void SignatureIterator::iterate_parameters( uint64_t fingerprint ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
171 uint64_t saved_fingerprint = fingerprint;
a61af66fc99e Initial load
duke
parents:
diff changeset
172
a61af66fc99e Initial load
duke
parents:
diff changeset
173 // Check for too many arguments
a61af66fc99e Initial load
duke
parents:
diff changeset
174 if ( fingerprint == UCONST64(-1) ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
175 SignatureIterator::iterate_parameters();
a61af66fc99e Initial load
duke
parents:
diff changeset
176 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
177 }
a61af66fc99e Initial load
duke
parents:
diff changeset
178
a61af66fc99e Initial load
duke
parents:
diff changeset
179 assert(fingerprint, "Fingerprint should not be 0");
a61af66fc99e Initial load
duke
parents:
diff changeset
180
a61af66fc99e Initial load
duke
parents:
diff changeset
181 _parameter_index = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
182 fingerprint = fingerprint >> (static_feature_size + result_feature_size);
a61af66fc99e Initial load
duke
parents:
diff changeset
183 while ( 1 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
184 switch ( fingerprint & parameter_feature_mask ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
185 case bool_parm:
a61af66fc99e Initial load
duke
parents:
diff changeset
186 do_bool();
a61af66fc99e Initial load
duke
parents:
diff changeset
187 _parameter_index += T_BOOLEAN_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
188 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
189 case byte_parm:
a61af66fc99e Initial load
duke
parents:
diff changeset
190 do_byte();
a61af66fc99e Initial load
duke
parents:
diff changeset
191 _parameter_index += T_BYTE_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
192 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
193 case char_parm:
a61af66fc99e Initial load
duke
parents:
diff changeset
194 do_char();
a61af66fc99e Initial load
duke
parents:
diff changeset
195 _parameter_index += T_CHAR_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
196 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
197 case short_parm:
a61af66fc99e Initial load
duke
parents:
diff changeset
198 do_short();
a61af66fc99e Initial load
duke
parents:
diff changeset
199 _parameter_index += T_SHORT_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
200 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
201 case int_parm:
a61af66fc99e Initial load
duke
parents:
diff changeset
202 do_int();
a61af66fc99e Initial load
duke
parents:
diff changeset
203 _parameter_index += T_INT_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
204 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
205 case obj_parm:
a61af66fc99e Initial load
duke
parents:
diff changeset
206 do_object(0, 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
207 _parameter_index += T_OBJECT_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
208 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
209 case long_parm:
a61af66fc99e Initial load
duke
parents:
diff changeset
210 do_long();
a61af66fc99e Initial load
duke
parents:
diff changeset
211 _parameter_index += T_LONG_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
212 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
213 case float_parm:
a61af66fc99e Initial load
duke
parents:
diff changeset
214 do_float();
a61af66fc99e Initial load
duke
parents:
diff changeset
215 _parameter_index += T_FLOAT_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
216 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
217 case double_parm:
a61af66fc99e Initial load
duke
parents:
diff changeset
218 do_double();
a61af66fc99e Initial load
duke
parents:
diff changeset
219 _parameter_index += T_DOUBLE_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
220 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
221 case done_parm:
a61af66fc99e Initial load
duke
parents:
diff changeset
222 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
223 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
224 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
225 tty->print_cr("*** parameter is %d", fingerprint & parameter_feature_mask);
a61af66fc99e Initial load
duke
parents:
diff changeset
226 tty->print_cr("*** fingerprint is " PTR64_FORMAT, saved_fingerprint);
a61af66fc99e Initial load
duke
parents:
diff changeset
227 ShouldNotReachHere();
a61af66fc99e Initial load
duke
parents:
diff changeset
228 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
229 }
a61af66fc99e Initial load
duke
parents:
diff changeset
230 fingerprint >>= parameter_feature_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
231 }
a61af66fc99e Initial load
duke
parents:
diff changeset
232 _parameter_index = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
233 }
a61af66fc99e Initial load
duke
parents:
diff changeset
234
a61af66fc99e Initial load
duke
parents:
diff changeset
235
a61af66fc99e Initial load
duke
parents:
diff changeset
236 void SignatureIterator::iterate_returntype() {
a61af66fc99e Initial load
duke
parents:
diff changeset
237 // Ignore parameters
a61af66fc99e Initial load
duke
parents:
diff changeset
238 _index = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
239 expect('(');
a61af66fc99e Initial load
duke
parents:
diff changeset
240 symbolOop sig = _signature();
a61af66fc99e Initial load
duke
parents:
diff changeset
241 while (sig->byte_at(_index) != ')') _index++;
a61af66fc99e Initial load
duke
parents:
diff changeset
242 expect(')');
a61af66fc99e Initial load
duke
parents:
diff changeset
243 // Parse return type
a61af66fc99e Initial load
duke
parents:
diff changeset
244 _parameter_index = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
245 parse_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
246 check_signature_end();
a61af66fc99e Initial load
duke
parents:
diff changeset
247 _parameter_index = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
248 }
a61af66fc99e Initial load
duke
parents:
diff changeset
249
a61af66fc99e Initial load
duke
parents:
diff changeset
250
a61af66fc99e Initial load
duke
parents:
diff changeset
251 void SignatureIterator::iterate() {
a61af66fc99e Initial load
duke
parents:
diff changeset
252 // Parse parameters
a61af66fc99e Initial load
duke
parents:
diff changeset
253 _parameter_index = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
254 _index = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
255 expect('(');
a61af66fc99e Initial load
duke
parents:
diff changeset
256 while (_signature->byte_at(_index) != ')') _parameter_index += parse_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
257 expect(')');
a61af66fc99e Initial load
duke
parents:
diff changeset
258 // Parse return type
a61af66fc99e Initial load
duke
parents:
diff changeset
259 _parameter_index = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
260 parse_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
261 check_signature_end();
a61af66fc99e Initial load
duke
parents:
diff changeset
262 _parameter_index = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
263 }
a61af66fc99e Initial load
duke
parents:
diff changeset
264
a61af66fc99e Initial load
duke
parents:
diff changeset
265
a61af66fc99e Initial load
duke
parents:
diff changeset
266 // Implementation of SignatureStream
a61af66fc99e Initial load
duke
parents:
diff changeset
267
a61af66fc99e Initial load
duke
parents:
diff changeset
268 bool SignatureStream::is_done() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
269 return _end > _signature()->utf8_length();
a61af66fc99e Initial load
duke
parents:
diff changeset
270 }
a61af66fc99e Initial load
duke
parents:
diff changeset
271
a61af66fc99e Initial load
duke
parents:
diff changeset
272
a61af66fc99e Initial load
duke
parents:
diff changeset
273 void SignatureStream::next_non_primitive(int t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
274 switch (t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
275 case 'L': {
a61af66fc99e Initial load
duke
parents:
diff changeset
276 _type = T_OBJECT;
a61af66fc99e Initial load
duke
parents:
diff changeset
277 symbolOop sig = _signature();
a61af66fc99e Initial load
duke
parents:
diff changeset
278 while (sig->byte_at(_end++) != ';');
a61af66fc99e Initial load
duke
parents:
diff changeset
279 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
280 }
a61af66fc99e Initial load
duke
parents:
diff changeset
281 case '[': {
a61af66fc99e Initial load
duke
parents:
diff changeset
282 _type = T_ARRAY;
a61af66fc99e Initial load
duke
parents:
diff changeset
283 symbolOop sig = _signature();
a61af66fc99e Initial load
duke
parents:
diff changeset
284 char c = sig->byte_at(_end);
a61af66fc99e Initial load
duke
parents:
diff changeset
285 while ('0' <= c && c <= '9') c = sig->byte_at(_end++);
a61af66fc99e Initial load
duke
parents:
diff changeset
286 while (sig->byte_at(_end) == '[') {
a61af66fc99e Initial load
duke
parents:
diff changeset
287 _end++;
a61af66fc99e Initial load
duke
parents:
diff changeset
288 c = sig->byte_at(_end);
a61af66fc99e Initial load
duke
parents:
diff changeset
289 while ('0' <= c && c <= '9') c = sig->byte_at(_end++);
a61af66fc99e Initial load
duke
parents:
diff changeset
290 }
a61af66fc99e Initial load
duke
parents:
diff changeset
291 switch(sig->byte_at(_end)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
292 case 'B':
a61af66fc99e Initial load
duke
parents:
diff changeset
293 case 'C':
a61af66fc99e Initial load
duke
parents:
diff changeset
294 case 'D':
a61af66fc99e Initial load
duke
parents:
diff changeset
295 case 'F':
a61af66fc99e Initial load
duke
parents:
diff changeset
296 case 'I':
a61af66fc99e Initial load
duke
parents:
diff changeset
297 case 'J':
a61af66fc99e Initial load
duke
parents:
diff changeset
298 case 'S':
a61af66fc99e Initial load
duke
parents:
diff changeset
299 case 'Z':_end++; break;
a61af66fc99e Initial load
duke
parents:
diff changeset
300 default: {
a61af66fc99e Initial load
duke
parents:
diff changeset
301 while (sig->byte_at(_end++) != ';');
a61af66fc99e Initial load
duke
parents:
diff changeset
302 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
303 }
a61af66fc99e Initial load
duke
parents:
diff changeset
304 }
a61af66fc99e Initial load
duke
parents:
diff changeset
305 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
306 }
a61af66fc99e Initial load
duke
parents:
diff changeset
307 case ')': _end++; next(); _at_return_type = true; break;
a61af66fc99e Initial load
duke
parents:
diff changeset
308 default : ShouldNotReachHere();
a61af66fc99e Initial load
duke
parents:
diff changeset
309 }
a61af66fc99e Initial load
duke
parents:
diff changeset
310 }
a61af66fc99e Initial load
duke
parents:
diff changeset
311
a61af66fc99e Initial load
duke
parents:
diff changeset
312
a61af66fc99e Initial load
duke
parents:
diff changeset
313 bool SignatureStream::is_object() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
314 return _type == T_OBJECT
a61af66fc99e Initial load
duke
parents:
diff changeset
315 || _type == T_ARRAY;
a61af66fc99e Initial load
duke
parents:
diff changeset
316 }
a61af66fc99e Initial load
duke
parents:
diff changeset
317
a61af66fc99e Initial load
duke
parents:
diff changeset
318 bool SignatureStream::is_array() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
319 return _type == T_ARRAY;
a61af66fc99e Initial load
duke
parents:
diff changeset
320 }
a61af66fc99e Initial load
duke
parents:
diff changeset
321
a61af66fc99e Initial load
duke
parents:
diff changeset
322 symbolOop SignatureStream::as_symbol(TRAPS) {
a61af66fc99e Initial load
duke
parents:
diff changeset
323 // Create a symbol from for string _begin _end
a61af66fc99e Initial load
duke
parents:
diff changeset
324 int begin = _begin;
a61af66fc99e Initial load
duke
parents:
diff changeset
325 int end = _end;
a61af66fc99e Initial load
duke
parents:
diff changeset
326
a61af66fc99e Initial load
duke
parents:
diff changeset
327 if ( _signature()->byte_at(_begin) == 'L'
a61af66fc99e Initial load
duke
parents:
diff changeset
328 && _signature()->byte_at(_end-1) == ';') {
a61af66fc99e Initial load
duke
parents:
diff changeset
329 begin++;
a61af66fc99e Initial load
duke
parents:
diff changeset
330 end--;
a61af66fc99e Initial load
duke
parents:
diff changeset
331 }
a61af66fc99e Initial load
duke
parents:
diff changeset
332
a61af66fc99e Initial load
duke
parents:
diff changeset
333 symbolOop result = oopFactory::new_symbol(_signature, begin, end, CHECK_NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
334 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
335 }
a61af66fc99e Initial load
duke
parents:
diff changeset
336
1508
2ffde6cfe049 6939196: method handle signatures off the boot class path get linkage errors
jrose
parents: 0
diff changeset
337 klassOop SignatureStream::as_klass(Handle class_loader, Handle protection_domain,
2ffde6cfe049 6939196: method handle signatures off the boot class path get linkage errors
jrose
parents: 0
diff changeset
338 FailureMode failure_mode, TRAPS) {
2ffde6cfe049 6939196: method handle signatures off the boot class path get linkage errors
jrose
parents: 0
diff changeset
339 if (!is_object()) return NULL;
2ffde6cfe049 6939196: method handle signatures off the boot class path get linkage errors
jrose
parents: 0
diff changeset
340 symbolOop name = as_symbol(CHECK_NULL);
2ffde6cfe049 6939196: method handle signatures off the boot class path get linkage errors
jrose
parents: 0
diff changeset
341 if (failure_mode == ReturnNull) {
2ffde6cfe049 6939196: method handle signatures off the boot class path get linkage errors
jrose
parents: 0
diff changeset
342 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
343 } else {
2ffde6cfe049 6939196: method handle signatures off the boot class path get linkage errors
jrose
parents: 0
diff changeset
344 bool throw_error = (failure_mode == NCDFError);
2ffde6cfe049 6939196: method handle signatures off the boot class path get linkage errors
jrose
parents: 0
diff changeset
345 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
346 }
2ffde6cfe049 6939196: method handle signatures off the boot class path get linkage errors
jrose
parents: 0
diff changeset
347 }
2ffde6cfe049 6939196: method handle signatures off the boot class path get linkage errors
jrose
parents: 0
diff changeset
348
2ffde6cfe049 6939196: method handle signatures off the boot class path get linkage errors
jrose
parents: 0
diff changeset
349 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
350 FailureMode failure_mode, TRAPS) {
2ffde6cfe049 6939196: method handle signatures off the boot class path get linkage errors
jrose
parents: 0
diff changeset
351 if (!is_object())
2ffde6cfe049 6939196: method handle signatures off the boot class path get linkage errors
jrose
parents: 0
diff changeset
352 return Universe::java_mirror(type());
2ffde6cfe049 6939196: method handle signatures off the boot class path get linkage errors
jrose
parents: 0
diff changeset
353 klassOop klass = as_klass(class_loader, protection_domain, failure_mode, CHECK_NULL);
2ffde6cfe049 6939196: method handle signatures off the boot class path get linkage errors
jrose
parents: 0
diff changeset
354 if (klass == NULL) return NULL;
2ffde6cfe049 6939196: method handle signatures off the boot class path get linkage errors
jrose
parents: 0
diff changeset
355 return Klass::cast(klass)->java_mirror();
2ffde6cfe049 6939196: method handle signatures off the boot class path get linkage errors
jrose
parents: 0
diff changeset
356 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
357
a61af66fc99e Initial load
duke
parents:
diff changeset
358 symbolOop SignatureStream::as_symbol_or_null() {
a61af66fc99e Initial load
duke
parents:
diff changeset
359 // Create a symbol from for string _begin _end
a61af66fc99e Initial load
duke
parents:
diff changeset
360 ResourceMark rm;
a61af66fc99e Initial load
duke
parents:
diff changeset
361
a61af66fc99e Initial load
duke
parents:
diff changeset
362 int begin = _begin;
a61af66fc99e Initial load
duke
parents:
diff changeset
363 int end = _end;
a61af66fc99e Initial load
duke
parents:
diff changeset
364
a61af66fc99e Initial load
duke
parents:
diff changeset
365 if ( _signature()->byte_at(_begin) == 'L'
a61af66fc99e Initial load
duke
parents:
diff changeset
366 && _signature()->byte_at(_end-1) == ';') {
a61af66fc99e Initial load
duke
parents:
diff changeset
367 begin++;
a61af66fc99e Initial load
duke
parents:
diff changeset
368 end--;
a61af66fc99e Initial load
duke
parents:
diff changeset
369 }
a61af66fc99e Initial load
duke
parents:
diff changeset
370
a61af66fc99e Initial load
duke
parents:
diff changeset
371 char* buffer = NEW_RESOURCE_ARRAY(char, end - begin);
a61af66fc99e Initial load
duke
parents:
diff changeset
372 for (int index = begin; index < end; index++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
373 buffer[index - begin] = _signature()->byte_at(index);
a61af66fc99e Initial load
duke
parents:
diff changeset
374 }
a61af66fc99e Initial load
duke
parents:
diff changeset
375 symbolOop result = SymbolTable::probe(buffer, end - begin);
a61af66fc99e Initial load
duke
parents:
diff changeset
376 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
377 }
a61af66fc99e Initial load
duke
parents:
diff changeset
378
a61af66fc99e Initial load
duke
parents:
diff changeset
379 bool SignatureVerifier::is_valid_signature(symbolHandle sig) {
a61af66fc99e Initial load
duke
parents:
diff changeset
380 const char* signature = (const char*)sig->bytes();
a61af66fc99e Initial load
duke
parents:
diff changeset
381 ssize_t len = sig->utf8_length();
a61af66fc99e Initial load
duke
parents:
diff changeset
382 if (signature == NULL || signature[0] == '\0' || len < 1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
383 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
384 } else if (signature[0] == '(') {
a61af66fc99e Initial load
duke
parents:
diff changeset
385 return is_valid_method_signature(sig);
a61af66fc99e Initial load
duke
parents:
diff changeset
386 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
387 return is_valid_type_signature(sig);
a61af66fc99e Initial load
duke
parents:
diff changeset
388 }
a61af66fc99e Initial load
duke
parents:
diff changeset
389 }
a61af66fc99e Initial load
duke
parents:
diff changeset
390
a61af66fc99e Initial load
duke
parents:
diff changeset
391 bool SignatureVerifier::is_valid_method_signature(symbolHandle sig) {
a61af66fc99e Initial load
duke
parents:
diff changeset
392 const char* method_sig = (const char*)sig->bytes();
a61af66fc99e Initial load
duke
parents:
diff changeset
393 ssize_t len = sig->utf8_length();
a61af66fc99e Initial load
duke
parents:
diff changeset
394 ssize_t index = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
395 if (method_sig != NULL && len > 1 && method_sig[index] == '(') {
a61af66fc99e Initial load
duke
parents:
diff changeset
396 ++index;
a61af66fc99e Initial load
duke
parents:
diff changeset
397 while (index < len && method_sig[index] != ')') {
a61af66fc99e Initial load
duke
parents:
diff changeset
398 ssize_t res = is_valid_type(&method_sig[index], len - index);
a61af66fc99e Initial load
duke
parents:
diff changeset
399 if (res == -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
400 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
401 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
402 index += res;
a61af66fc99e Initial load
duke
parents:
diff changeset
403 }
a61af66fc99e Initial load
duke
parents:
diff changeset
404 }
a61af66fc99e Initial load
duke
parents:
diff changeset
405 if (index < len && method_sig[index] == ')') {
a61af66fc99e Initial load
duke
parents:
diff changeset
406 // check the return type
a61af66fc99e Initial load
duke
parents:
diff changeset
407 ++index;
a61af66fc99e Initial load
duke
parents:
diff changeset
408 return (is_valid_type(&method_sig[index], len - index) == (len - index));
a61af66fc99e Initial load
duke
parents:
diff changeset
409 }
a61af66fc99e Initial load
duke
parents:
diff changeset
410 }
a61af66fc99e Initial load
duke
parents:
diff changeset
411 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
412 }
a61af66fc99e Initial load
duke
parents:
diff changeset
413
a61af66fc99e Initial load
duke
parents:
diff changeset
414 bool SignatureVerifier::is_valid_type_signature(symbolHandle sig) {
a61af66fc99e Initial load
duke
parents:
diff changeset
415 const char* type_sig = (const char*)sig->bytes();
a61af66fc99e Initial load
duke
parents:
diff changeset
416 ssize_t len = sig->utf8_length();
a61af66fc99e Initial load
duke
parents:
diff changeset
417 return (type_sig != NULL && len >= 1 &&
a61af66fc99e Initial load
duke
parents:
diff changeset
418 (is_valid_type(type_sig, len) == len));
a61af66fc99e Initial load
duke
parents:
diff changeset
419 }
a61af66fc99e Initial load
duke
parents:
diff changeset
420
a61af66fc99e Initial load
duke
parents:
diff changeset
421 // Checks to see if the type (not to go beyond 'limit') refers to a valid type.
a61af66fc99e Initial load
duke
parents:
diff changeset
422 // Returns -1 if it is not, or the index of the next character that is not part
a61af66fc99e Initial load
duke
parents:
diff changeset
423 // of the type. The type encoding may end before 'limit' and that's ok.
a61af66fc99e Initial load
duke
parents:
diff changeset
424 ssize_t SignatureVerifier::is_valid_type(const char* type, ssize_t limit) {
a61af66fc99e Initial load
duke
parents:
diff changeset
425 ssize_t index = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
426
a61af66fc99e Initial load
duke
parents:
diff changeset
427 // Iterate over any number of array dimensions
a61af66fc99e Initial load
duke
parents:
diff changeset
428 while (index < limit && type[index] == '[') ++index;
a61af66fc99e Initial load
duke
parents:
diff changeset
429 if (index >= limit) {
a61af66fc99e Initial load
duke
parents:
diff changeset
430 return -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
431 }
a61af66fc99e Initial load
duke
parents:
diff changeset
432 switch (type[index]) {
a61af66fc99e Initial load
duke
parents:
diff changeset
433 case 'B': case 'C': case 'D': case 'F': case 'I':
a61af66fc99e Initial load
duke
parents:
diff changeset
434 case 'J': case 'S': case 'Z': case 'V':
a61af66fc99e Initial load
duke
parents:
diff changeset
435 return index + 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
436 case 'L':
a61af66fc99e Initial load
duke
parents:
diff changeset
437 for (index = index + 1; index < limit; ++index) {
a61af66fc99e Initial load
duke
parents:
diff changeset
438 char c = type[index];
a61af66fc99e Initial load
duke
parents:
diff changeset
439 if (c == ';') {
a61af66fc99e Initial load
duke
parents:
diff changeset
440 return index + 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
441 }
a61af66fc99e Initial load
duke
parents:
diff changeset
442 if (invalid_name_char(c)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
443 return -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
444 }
a61af66fc99e Initial load
duke
parents:
diff changeset
445 }
a61af66fc99e Initial load
duke
parents:
diff changeset
446 // fall through
a61af66fc99e Initial load
duke
parents:
diff changeset
447 default: ; // fall through
a61af66fc99e Initial load
duke
parents:
diff changeset
448 }
a61af66fc99e Initial load
duke
parents:
diff changeset
449 return -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
450 }
a61af66fc99e Initial load
duke
parents:
diff changeset
451
a61af66fc99e Initial load
duke
parents:
diff changeset
452 bool SignatureVerifier::invalid_name_char(char c) {
a61af66fc99e Initial load
duke
parents:
diff changeset
453 switch (c) {
a61af66fc99e Initial load
duke
parents:
diff changeset
454 case '\0': case '.': case ';': case '[':
a61af66fc99e Initial load
duke
parents:
diff changeset
455 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
456 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
457 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
458 }
a61af66fc99e Initial load
duke
parents:
diff changeset
459 }