1 /*
2 * Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
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 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef SHARE_RUNTIME_SIGNATURE_HPP
26 #define SHARE_RUNTIME_SIGNATURE_HPP
27
28 #include "memory/allocation.hpp"
29 #include "oops/method.hpp"
30
31
32 // Static routines and parsing loops for processing field and method
33 // descriptors. In the HotSpot sources we call them "signatures".
34 //
35 // A SignatureStream iterates over a Java descriptor (or parts of it).
36 // The syntax is documented in the Java Virtual Machine Specification,
37 // section 4.3.
38 //
39 // The syntax may be summarized as follows:
40 //
41 // MethodType: '(' {FieldType}* ')' (FieldType | 'V')
42 // FieldType: PrimitiveType | ObjectType | ArrayType
43 // PrimitiveType: 'B' | 'C' | 'D' | 'F' | 'I' | 'J' | 'S' | 'Z'
44 // ObjectType: 'L' ClassName ';' | ArrayType
45 // ArrayType: '[' FieldType
46 // ClassName: {UnqualifiedName '/'}* UnqualifiedName
47 // UnqualifiedName: NameChar {NameChar}*
48 // NameChar: ANY_CHAR_EXCEPT('/' | '.' | ';' | '[')
49 //
50 // All of the concrete characters in the above grammar are given
51 // standard manifest constant names of the form JVM_SIGNATURE_x.
52 // Executable code uses these constant names in preference to raw
53 // character constants. Comments and assertion code sometimes use
54 // the raw character constants for brevity.
55 //
56 // The primitive field types (like 'I') correspond 1-1 with type codes
57 // (like T_INT) which form part of the specification of the 'newarray'
58 // instruction (JVMS 6.5, section on newarray). These type codes are
59 // widely used in the HotSpot code. They are joined by ad hoc codes
60 // like T_OBJECT and T_ARRAY (defined in HotSpot but not in the JVMS)
61 // so that each "basic type" of field descriptor (or void return type)
62 // has a corresponding T_x code. Thus, while T_x codes play a very
63 // minor role in the JVMS, they play a major role in the HotSpot
64 // sources. There are fewer than 16 such "basic types", so they fit
65 // nicely into bitfields.
66 //
67 // The syntax of ClassName overlaps slightly with the descriptor
68 // syntaxes. The strings "I" and "(I)V" are both class names
69 // *and* descriptors. If a class name contains any character other
70 // than "BCDFIJSZ()V" it cannot be confused with a descriptor.
71 // Class names inside of descriptors are always contained in an
72 // "envelope" syntax which starts with 'L' and ends with ';'.
73 //
74 // As a confounding factor, array types report their type name strings
75 // in descriptor format. These name strings are easy to recognize,
76 // since they begin with '['. For this reason some API points on
77 // HotSpot look for array descriptors as well as proper class names.
78 //
79 // For historical reasons some API points that accept class names and
80 // array names also look for class names wrapped inside an envelope
81 // (like "LFoo;") and unwrap them on the fly (to a name like "Foo").
82
83 class Signature : AllStatic {
84 private:
85 static bool is_valid_array_signature(const Symbol* sig);
86
87 public:
88
89 // Returns the basic type of a field signature (or T_VOID for "V").
90 // Assumes the signature is a valid field descriptor.
91 // Do not apply this function to class names or method signatures.
basic_type(const Symbol * signature)92 static BasicType basic_type(const Symbol* signature) {
93 return basic_type(signature->char_at(0));
94 }
95
96 // Returns T_ILLEGAL for an illegal signature char.
97 static BasicType basic_type(int ch);
98
99 // Assuming it is either a class name or signature,
100 // determine if it in fact cannot be a class name.
101 // This means it either starts with '[' or ends with ';'
not_class_name(const Symbol * signature)102 static bool not_class_name(const Symbol* signature) {
103 return (signature->starts_with(JVM_SIGNATURE_ARRAY) ||
104 signature->ends_with(JVM_SIGNATURE_ENDCLASS));
105 }
106
107 // Assuming it is either a class name or signature,
108 // determine if it in fact is an array descriptor.
is_array(const Symbol * signature)109 static bool is_array(const Symbol* signature) {
110 return (signature->utf8_length() > 1 &&
111 signature->char_at(0) == JVM_SIGNATURE_ARRAY &&
112 is_valid_array_signature(signature));
113 }
114
115 // Assuming it is either a class name or signature,
116 // determine if it contains a class name plus ';'.
has_envelope(const Symbol * signature)117 static bool has_envelope(const Symbol* signature) {
118 return ((signature->utf8_length() > 0) &&
119 signature->ends_with(JVM_SIGNATURE_ENDCLASS) &&
120 has_envelope(signature->char_at(0)));
121 }
122
123 // Determine if this signature char introduces an
124 // envelope, which is a class name plus ';'.
has_envelope(char signature_char)125 static bool has_envelope(char signature_char) {
126 return (signature_char == JVM_SIGNATURE_CLASS);
127 }
128
129 // Assuming has_envelope is true, return the symbol
130 // inside the envelope, by stripping 'L' and ';'.
131 // Caller is responsible for decrementing the newly created
132 // Symbol's refcount, use TempNewSymbol.
133 static Symbol* strip_envelope(const Symbol* signature);
134
135 // Assuming it's either a field or method descriptor, determine
136 // whether it is in fact a method descriptor:
is_method(const Symbol * signature)137 static bool is_method(const Symbol* signature) {
138 return signature->starts_with(JVM_SIGNATURE_FUNC);
139 }
140
141 // Assuming it's a method signature, determine if it must
142 // return void.
is_void_method(const Symbol * signature)143 static bool is_void_method(const Symbol* signature) {
144 assert(is_method(signature), "signature is not for a method");
145 return signature->ends_with(JVM_SIGNATURE_VOID);
146 }
147 };
148
149 // A SignatureIterator uses a SignatureStream to produce BasicType
150 // results, discarding class names. This means it can be accelerated
151 // using a fingerprint mechanism, in many cases, without loss of type
152 // information. The FingerPrinter class computes and caches this
153 // reduced information for faster iteration.
154
155 class SignatureIterator: public ResourceObj {
156 public:
157 typedef uint64_t fingerprint_t;
158
159 protected:
160 Symbol* _signature; // the signature to iterate over
161 BasicType _return_type;
162 fingerprint_t _fingerprint;
163
164 public:
165 // Definitions used in generating and iterating the
166 // bit field form of the signature generated by the
167 // Fingerprinter.
168 enum {
169 fp_static_feature_size = 1,
170 fp_is_static_bit = 1,
171
172 fp_result_feature_size = 4,
173 fp_result_feature_mask = right_n_bits(fp_result_feature_size),
174 fp_parameter_feature_size = 4,
175 fp_parameter_feature_mask = right_n_bits(fp_parameter_feature_size),
176
177 fp_parameters_done = 0, // marker for end of parameters (must be zero)
178
179 // Parameters take up full wordsize, minus the result and static bit fields.
180 // Since fp_parameters_done is zero, termination field arises from shifting
181 // in zero bits, and therefore occupies no extra space.
182 // The sentinel value is all-zero-bits, which is impossible for a true
183 // fingerprint, since at least the result field will be non-zero.
184 fp_max_size_of_parameters = ((BitsPerLong
185 - (fp_result_feature_size + fp_static_feature_size))
186 / fp_parameter_feature_size)
187 };
188
189 static bool fp_is_valid_type(BasicType type, bool for_return_type = false);
190
191 // Sentinel values are zero and not-zero (-1).
192 // No need to protect the sign bit, since every valid return type is non-zero
193 // (even T_VOID), and there are no valid parameter fields which are 0xF (T_VOID).
zero_fingerprint()194 static fingerprint_t zero_fingerprint() { return (fingerprint_t)0; }
overflow_fingerprint()195 static fingerprint_t overflow_fingerprint() { return ~(fingerprint_t)0; }
fp_is_valid(fingerprint_t fingerprint)196 static bool fp_is_valid(fingerprint_t fingerprint) {
197 return (fingerprint != zero_fingerprint()) && (fingerprint != overflow_fingerprint());
198 }
199
200 // Constructors
SignatureIterator(Symbol * signature,fingerprint_t fingerprint=zero_fingerprint ())201 SignatureIterator(Symbol* signature, fingerprint_t fingerprint = zero_fingerprint()) {
202 _signature = signature;
203 _return_type = T_ILLEGAL; // sentinel value for uninitialized
204 _fingerprint = zero_fingerprint();
205 if (fingerprint != _fingerprint) {
206 set_fingerprint(fingerprint);
207 }
208 }
209
210 // If the fingerprint is present, we can use an accelerated loop.
211 void set_fingerprint(fingerprint_t fingerprint);
212
213 // Returns the set fingerprint, or zero_fingerprint()
214 // if none has been set already.
fingerprint() const215 fingerprint_t fingerprint() const { return _fingerprint; }
216
217 // Iteration
218 // Hey look: There are no virtual methods in this class.
219 // So how is it customized? By calling do_parameters_on
220 // an object which answers to "do_type(BasicType)".
221 // By convention, this object is in the subclass
222 // itself, so the call is "do_parameters_on(this)".
223 // The effect of this is to inline the parsing loop
224 // everywhere "do_parameters_on" is called.
225 // If there is a valid fingerprint in the object,
226 // an improved loop is called which just unpacks the
227 // bitfields from the fingerprint. Otherwise, the
228 // symbol is parsed.
229 template<typename T> inline void do_parameters_on(T* callback); // iterates over parameters only
230 BasicType return_type(); // computes the value on the fly if necessary
231
fp_is_static(fingerprint_t fingerprint)232 static bool fp_is_static(fingerprint_t fingerprint) {
233 assert(fp_is_valid(fingerprint), "invalid fingerprint");
234 return fingerprint & fp_is_static_bit;
235 }
fp_return_type(fingerprint_t fingerprint)236 static BasicType fp_return_type(fingerprint_t fingerprint) {
237 assert(fp_is_valid(fingerprint), "invalid fingerprint");
238 return (BasicType) ((fingerprint >> fp_static_feature_size) & fp_result_feature_mask);
239 }
fp_start_parameters(fingerprint_t fingerprint)240 static fingerprint_t fp_start_parameters(fingerprint_t fingerprint) {
241 assert(fp_is_valid(fingerprint), "invalid fingerprint");
242 return fingerprint >> (fp_static_feature_size + fp_result_feature_size);
243 }
fp_next_parameter(fingerprint_t & mask)244 static BasicType fp_next_parameter(fingerprint_t& mask) {
245 int result = (mask & fp_parameter_feature_mask);
246 mask >>= fp_parameter_feature_size;
247 return (BasicType) result;
248 }
249 };
250
251
252 // Specialized SignatureIterators: Used to compute signature specific values.
253
254 class SignatureTypeNames : public SignatureIterator {
255 protected:
256 virtual void type_name(const char* name) = 0;
257
258 friend class SignatureIterator; // so do_parameters_on can call do_type
do_type(BasicType type)259 void do_type(BasicType type) {
260 switch (type) {
261 case T_BOOLEAN: type_name("jboolean"); break;
262 case T_CHAR: type_name("jchar" ); break;
263 case T_FLOAT: type_name("jfloat" ); break;
264 case T_DOUBLE: type_name("jdouble" ); break;
265 case T_BYTE: type_name("jbyte" ); break;
266 case T_SHORT: type_name("jshort" ); break;
267 case T_INT: type_name("jint" ); break;
268 case T_LONG: type_name("jlong" ); break;
269 case T_VOID: type_name("void" ); break;
270 case T_ARRAY:
271 case T_OBJECT: type_name("jobject" ); break;
272 default: ShouldNotReachHere();
273 }
274 }
275
276 public:
SignatureTypeNames(Symbol * signature)277 SignatureTypeNames(Symbol* signature) : SignatureIterator(signature) {}
278 };
279
280
281 // Specialized SignatureIterator: Used to compute the argument size.
282
283 class ArgumentSizeComputer: public SignatureIterator {
284 private:
285 int _size;
286 friend class SignatureIterator; // so do_parameters_on can call do_type
do_type(BasicType type)287 void do_type(BasicType type) { _size += parameter_type_word_count(type); }
288 public:
289 ArgumentSizeComputer(Symbol* signature);
size()290 int size() { return _size; }
291 };
292
293
294 class ArgumentCount: public SignatureIterator {
295 private:
296 int _size;
297 friend class SignatureIterator; // so do_parameters_on can call do_type
do_type(BasicType type)298 void do_type(BasicType type) { _size++; }
299 public:
300 ArgumentCount(Symbol* signature);
size()301 int size() { return _size; }
302 };
303
304
305 class ReferenceArgumentCount: public SignatureIterator {
306 private:
307 int _refs;
308 friend class SignatureIterator; // so do_parameters_on can call do_type
do_type(BasicType type)309 void do_type(BasicType type) { if (is_reference_type(type)) _refs++; }
310 public:
311 ReferenceArgumentCount(Symbol* signature);
count()312 int count() { return _refs; }
313 };
314
315
316 // Specialized SignatureIterator: Used to compute the result type.
317
318 class ResultTypeFinder: public SignatureIterator {
319 public:
type()320 BasicType type() { return return_type(); }
ResultTypeFinder(Symbol * signature)321 ResultTypeFinder(Symbol* signature) : SignatureIterator(signature) { }
322 };
323
324
325 // Fingerprinter computes a unique ID for a given method. The ID
326 // is a bitvector characterizing the methods signature (incl. the receiver).
327 class Fingerprinter: public SignatureIterator {
328 private:
329 fingerprint_t _accumulator;
330 int _param_size;
331 int _shift_count;
332 const Method* _method;
333
initialize_accumulator()334 void initialize_accumulator() {
335 _accumulator = 0;
336 _shift_count = fp_result_feature_size + fp_static_feature_size;
337 _param_size = 0;
338 }
339
340 // Out-of-line method does it all in constructor:
341 void compute_fingerprint_and_return_type(bool static_flag = false);
342
343 friend class SignatureIterator; // so do_parameters_on can call do_type
do_type(BasicType type)344 void do_type(BasicType type) {
345 assert(fp_is_valid_type(type), "bad parameter type");
346 _accumulator |= ((fingerprint_t)type << _shift_count);
347 _shift_count += fp_parameter_feature_size;
348 _param_size += (is_double_word_type(type) ? 2 : 1);
349 }
350
351 public:
size_of_parameters() const352 int size_of_parameters() const { return _param_size; }
353 // fingerprint() and return_type() are in super class
354
Fingerprinter(const methodHandle & method)355 Fingerprinter(const methodHandle& method)
356 : SignatureIterator(method->signature()),
357 _method(method()) {
358 compute_fingerprint_and_return_type();
359 }
Fingerprinter(Symbol * signature,bool is_static)360 Fingerprinter(Symbol* signature, bool is_static)
361 : SignatureIterator(signature),
362 _method(NULL) {
363 compute_fingerprint_and_return_type(is_static);
364 }
365 };
366
367
368 // Specialized SignatureIterator: Used for native call purposes
369
370 class NativeSignatureIterator: public SignatureIterator {
371 private:
372 methodHandle _method;
373 // We need separate JNI and Java offset values because in 64 bit mode,
374 // the argument offsets are not in sync with the Java stack.
375 // For example a long takes up 1 "C" stack entry but 2 Java stack entries.
376 int _offset; // The java stack offset
377 int _prepended; // number of prepended JNI parameters (1 JNIEnv, plus 1 mirror if static)
378 int _jni_offset; // the current parameter offset, starting with 0
379
380 friend class SignatureIterator; // so do_parameters_on can call do_type
do_type(BasicType type)381 void do_type(BasicType type) {
382 switch (type) {
383 case T_BYTE:
384 case T_SHORT:
385 case T_INT:
386 case T_BOOLEAN:
387 case T_CHAR:
388 pass_int(); _jni_offset++; _offset++;
389 break;
390 case T_FLOAT:
391 pass_float(); _jni_offset++; _offset++;
392 break;
393 case T_DOUBLE: {
394 int jni_offset = LP64_ONLY(1) NOT_LP64(2);
395 pass_double(); _jni_offset += jni_offset; _offset += 2;
396 break;
397 }
398 case T_LONG: {
399 int jni_offset = LP64_ONLY(1) NOT_LP64(2);
400 pass_long(); _jni_offset += jni_offset; _offset += 2;
401 break;
402 }
403 case T_ARRAY:
404 case T_OBJECT:
405 pass_object(); _jni_offset++; _offset++;
406 break;
407 default:
408 ShouldNotReachHere();
409 }
410 }
411
412 public:
method() const413 methodHandle method() const { return _method; }
offset() const414 int offset() const { return _offset; }
jni_offset() const415 int jni_offset() const { return _jni_offset + _prepended; }
is_static() const416 bool is_static() const { return method()->is_static(); }
417 virtual void pass_int() = 0;
418 virtual void pass_long() = 0;
419 virtual void pass_object() = 0; // objects, arrays, inlines
420 virtual void pass_float() = 0;
421 #ifdef _LP64
422 virtual void pass_double() = 0;
423 #else
pass_double()424 virtual void pass_double() { pass_long(); } // may be same as long
425 #endif
426
NativeSignatureIterator(const methodHandle & method)427 NativeSignatureIterator(const methodHandle& method) : SignatureIterator(method->signature()) {
428 _method = method;
429 _offset = 0;
430 _jni_offset = 0;
431
432 const int JNIEnv_words = 1;
433 const int mirror_words = 1;
434 _prepended = !is_static() ? JNIEnv_words : JNIEnv_words + mirror_words;
435 }
436
iterate()437 void iterate() { iterate(Fingerprinter(method()).fingerprint()); }
438
439 // iterate() calls the 3 virtual methods according to the following invocation syntax:
440 //
441 // {pass_int | pass_long | pass_object}
442 //
443 // Arguments are handled from left to right (receiver first, if any).
444 // The offset() values refer to the Java stack offsets but are 0 based and increasing.
445 // The java_offset() values count down to 0, and refer to the Java TOS.
446 // The jni_offset() values increase from 1 or 2, and refer to C arguments.
447 // The method's return type is ignored.
448
iterate(fingerprint_t fingerprint)449 void iterate(fingerprint_t fingerprint) {
450 set_fingerprint(fingerprint);
451 if (!is_static()) {
452 // handle receiver (not handled by iterate because not in signature)
453 pass_object(); _jni_offset++; _offset++;
454 }
455 do_parameters_on(this);
456 }
457 };
458
459
460 // This is the core parsing logic for iterating over signatures.
461 // All of the previous classes use this for doing their work.
462
463 class SignatureStream : public StackObj {
464 private:
465 const Symbol* _signature;
466 int _begin;
467 int _end;
468 int _limit;
469 int _array_prefix; // count of '[' before the array element descr
470 BasicType _type;
471 int _state;
472 Symbol* _previous_name; // cache the previously looked up symbol to avoid lookups
473 GrowableArray<Symbol*>* _names; // symbols created while parsing that need to be dereferenced
474
475 Symbol* find_symbol();
476
477 enum { _s_field = 0, _s_method = 1, _s_method_return = 3 };
set_done()478 void set_done() {
479 _state |= -2; // preserve s_method bit
480 assert(is_done(), "Unable to set state to done");
481 }
482 int scan_type(BasicType bt);
483
484 public:
at_return_type() const485 bool at_return_type() const { return _state == (int)_s_method_return; }
is_done() const486 bool is_done() const { return _state < 0; }
487 void next();
488
489 SignatureStream(const Symbol* signature, bool is_method = true);
490 ~SignatureStream();
491
is_reference() const492 bool is_reference() const { return is_reference_type(_type); }
is_array() const493 bool is_array() const { return _type == T_ARRAY; }
is_primitive() const494 bool is_primitive() const { return is_java_primitive(_type); }
type() const495 BasicType type() const { return _type; }
496
raw_bytes() const497 const u1* raw_bytes() const { return _signature->bytes() + _begin; }
raw_length() const498 int raw_length() const { return _end - _begin; }
raw_symbol_begin() const499 int raw_symbol_begin() const { return _begin + (has_envelope() ? 1 : 0); }
raw_symbol_end() const500 int raw_symbol_end() const { return _end - (has_envelope() ? 1 : 0); }
raw_char_at(int i) const501 char raw_char_at(int i) const {
502 assert(i < _limit, "index for raw_char_at is over the limit");
503 return _signature->char_at(i);
504 }
505
506 // True if there is an embedded class name in this type,
507 // followed by ';'.
has_envelope() const508 bool has_envelope() const {
509 if (!Signature::has_envelope(_signature->char_at(_begin)))
510 return false;
511 // this should always be true, but let's test it:
512 assert(_signature->char_at(_end-1) == JVM_SIGNATURE_ENDCLASS, "signature envelope has no semi-colon at end");
513 return true;
514 }
515
516 // return the symbol for chars in symbol_begin()..symbol_end()
as_symbol()517 Symbol* as_symbol() {
518 return find_symbol();
519 }
520
521 // in case you want only the return type:
522 void skip_to_return_type();
523
524 // number of '[' in array prefix
array_prefix_length()525 int array_prefix_length() {
526 return _type == T_ARRAY ? _array_prefix : 0;
527 }
528
529 // In case you want only the array base type,
530 // reset the stream after skipping some brackets '['.
531 // (The argument is clipped to array_prefix_length(),
532 // and if it ends up as zero this call is a nop.
533 // The default is value skips all brackets '['.)
534 private:
535 int skip_whole_array_prefix();
536 public:
skip_array_prefix(int max_skip_length)537 int skip_array_prefix(int max_skip_length) {
538 if (_type != T_ARRAY) {
539 return 0;
540 }
541 if (_array_prefix > max_skip_length) {
542 // strip some but not all levels of T_ARRAY
543 _array_prefix -= max_skip_length;
544 _begin += max_skip_length;
545 return max_skip_length;
546 }
547 return skip_whole_array_prefix();
548 }
skip_array_prefix()549 int skip_array_prefix() {
550 if (_type != T_ARRAY) {
551 return 0;
552 }
553 return skip_whole_array_prefix();
554 }
555
556 // free-standing lookups (bring your own CL/PD pair)
557 enum FailureMode { ReturnNull, NCDFError, CachedOrNull };
558 Klass* as_klass(Handle class_loader, Handle protection_domain, FailureMode failure_mode, TRAPS);
559 oop as_java_mirror(Handle class_loader, Handle protection_domain, FailureMode failure_mode, TRAPS);
560 };
561
562 // Specialized SignatureStream: used for invoking SystemDictionary to either find
563 // or resolve the underlying type when iterating over a
564 // Java descriptor (or parts of it).
565 class ResolvingSignatureStream : public SignatureStream {
566 Klass* _load_origin;
567 bool _handles_cached;
568 Handle _class_loader; // cached when needed
569 Handle _protection_domain; // cached when needed
570
initialize_load_origin(Klass * load_origin)571 void initialize_load_origin(Klass* load_origin) {
572 _load_origin = load_origin;
573 _handles_cached = (load_origin == NULL);
574 }
need_handles(TRAPS)575 void need_handles(TRAPS) {
576 if (!_handles_cached) {
577 cache_handles(THREAD);
578 _handles_cached = true;
579 }
580 }
581 void cache_handles(TRAPS);
582
583 public:
584 ResolvingSignatureStream(Symbol* signature, Klass* load_origin, bool is_method = true);
585 ResolvingSignatureStream(Symbol* signature, Handle class_loader, Handle protection_domain, bool is_method = true);
586 ResolvingSignatureStream(const Method* method);
587 ResolvingSignatureStream(fieldDescriptor& field);
588
load_origin()589 Klass* load_origin() { return _load_origin; }
class_loader(TRAPS)590 Handle class_loader(TRAPS) { need_handles(THREAD); return _class_loader; }
protection_domain(TRAPS)591 Handle protection_domain(TRAPS) { need_handles(THREAD); return _protection_domain; }
592
593 Klass* as_klass_if_loaded(TRAPS);
as_klass(FailureMode failure_mode,TRAPS)594 Klass* as_klass(FailureMode failure_mode, TRAPS) {
595 need_handles(THREAD);
596 return SignatureStream::as_klass(_class_loader, _protection_domain,
597 failure_mode, THREAD);
598 }
as_java_mirror(FailureMode failure_mode,TRAPS)599 oop as_java_mirror(FailureMode failure_mode, TRAPS) {
600 if (is_reference()) {
601 need_handles(THREAD);
602 }
603 return SignatureStream::as_java_mirror(_class_loader, _protection_domain,
604 failure_mode, THREAD);
605 }
606 };
607
608 // Here is how all the SignatureIterator classes invoke the
609 // SignatureStream engine to do their parsing.
610 template<typename T> inline
do_parameters_on(T * callback)611 void SignatureIterator::do_parameters_on(T* callback) {
612 fingerprint_t unaccumulator = _fingerprint;
613
614 // Check for too many arguments, or missing fingerprint:
615 if (!fp_is_valid(unaccumulator)) {
616 SignatureStream ss(_signature);
617 for (; !ss.at_return_type(); ss.next()) {
618 callback->do_type(ss.type());
619 }
620 // while we are here, capture the return type
621 _return_type = ss.type();
622 } else {
623 // Optimized version of do_parameters when fingerprint is known
624 assert(_return_type != T_ILLEGAL, "return type already captured from fp");
625 unaccumulator = fp_start_parameters(unaccumulator);
626 for (BasicType type; (type = fp_next_parameter(unaccumulator)) != (BasicType)fp_parameters_done; ) {
627 assert(fp_is_valid_type(type), "garbled fingerprint");
628 callback->do_type(type);
629 }
630 }
631 }
632
633 #ifdef ASSERT
634 class SignatureVerifier : public StackObj {
635 public:
636 static bool is_valid_method_signature(Symbol* sig);
637 static bool is_valid_type_signature(Symbol* sig);
638 private:
639 static ssize_t is_valid_type(const char*, ssize_t);
640 };
641 #endif
642 #endif // SHARE_RUNTIME_SIGNATURE_HPP
643