45 // NOTE: The new optimizer has an alternate, for-loop based signature |
45 // NOTE: The new optimizer has an alternate, for-loop based signature |
46 // iterator implemented in opto/type.cpp, TypeTuple::make(). |
46 // iterator implemented in opto/type.cpp, TypeTuple::make(). |
47 |
47 |
48 class SignatureIterator: public ResourceObj { |
48 class SignatureIterator: public ResourceObj { |
49 protected: |
49 protected: |
50 symbolHandle _signature; // the signature to iterate over |
50 Symbol* _signature; // the signature to iterate over |
51 int _index; // the current character index (only valid during iteration) |
51 int _index; // the current character index (only valid during iteration) |
52 int _parameter_index; // the current parameter index (0 outside iteration phase) |
52 int _parameter_index; // the current parameter index (0 outside iteration phase) |
53 BasicType _return_type; |
53 BasicType _return_type; |
54 |
54 |
55 void expect(char c); |
55 void expect(char c); |
85 result_feature_size - parameter_feature_size - |
85 result_feature_size - parameter_feature_size - |
86 static_feature_size) / parameter_feature_size |
86 static_feature_size) / parameter_feature_size |
87 }; |
87 }; |
88 |
88 |
89 // Constructors |
89 // Constructors |
90 SignatureIterator(symbolOop signature); |
90 SignatureIterator(Symbol* signature); |
91 SignatureIterator(Thread *thread, symbolOop signature); |
|
92 SignatureIterator(symbolHandle signature); |
|
93 |
91 |
94 // Iteration |
92 // Iteration |
95 void dispatch_field(); // dispatches once for field signatures |
93 void dispatch_field(); // dispatches once for field signatures |
96 void iterate_parameters(); // iterates over parameters only |
94 void iterate_parameters(); // iterates over parameters only |
97 void iterate_parameters( uint64_t fingerprint ); |
95 void iterate_parameters( uint64_t fingerprint ); |
136 void do_void() { type_name("void" ); } |
134 void do_void() { type_name("void" ); } |
137 void do_object(int begin, int end) { type_name("jobject" ); } |
135 void do_object(int begin, int end) { type_name("jobject" ); } |
138 void do_array (int begin, int end) { type_name("jobject" ); } |
136 void do_array (int begin, int end) { type_name("jobject" ); } |
139 |
137 |
140 public: |
138 public: |
141 SignatureTypeNames(symbolHandle signature) : SignatureIterator(signature) {} |
139 SignatureTypeNames(Symbol* signature) : SignatureIterator(signature) {} |
142 }; |
140 }; |
143 |
141 |
144 |
142 |
145 class SignatureInfo: public SignatureIterator { |
143 class SignatureInfo: public SignatureIterator { |
146 protected: |
144 protected: |
164 void do_void () { set(T_VOID_size , T_VOID ); } |
162 void do_void () { set(T_VOID_size , T_VOID ); } |
165 void do_object(int begin, int end) { set(T_OBJECT_size , T_OBJECT ); } |
163 void do_object(int begin, int end) { set(T_OBJECT_size , T_OBJECT ); } |
166 void do_array (int begin, int end) { set(T_ARRAY_size , T_ARRAY ); } |
164 void do_array (int begin, int end) { set(T_ARRAY_size , T_ARRAY ); } |
167 |
165 |
168 public: |
166 public: |
169 SignatureInfo(symbolHandle signature) : SignatureIterator(signature) { |
167 SignatureInfo(Symbol* signature) : SignatureIterator(signature) { |
170 _has_iterated = _has_iterated_return = false; |
168 _has_iterated = _has_iterated_return = false; |
171 _size = 0; |
169 _size = 0; |
172 _return_type = T_ILLEGAL; |
170 _return_type = T_ILLEGAL; |
173 } |
171 } |
174 |
172 |
179 |
177 |
180 class ArgumentSizeComputer: public SignatureInfo { |
178 class ArgumentSizeComputer: public SignatureInfo { |
181 private: |
179 private: |
182 void set(int size, BasicType type) { _size += size; } |
180 void set(int size, BasicType type) { _size += size; } |
183 public: |
181 public: |
184 ArgumentSizeComputer(symbolHandle signature) : SignatureInfo(signature) {} |
182 ArgumentSizeComputer(Symbol* signature) : SignatureInfo(signature) {} |
185 |
183 |
186 int size() { lazy_iterate_parameters(); return _size; } |
184 int size() { lazy_iterate_parameters(); return _size; } |
187 }; |
185 }; |
188 |
186 |
189 |
187 |
190 class ArgumentCount: public SignatureInfo { |
188 class ArgumentCount: public SignatureInfo { |
191 private: |
189 private: |
192 void set(int size, BasicType type) { _size ++; } |
190 void set(int size, BasicType type) { _size ++; } |
193 public: |
191 public: |
194 ArgumentCount(symbolHandle signature) : SignatureInfo(signature) {} |
192 ArgumentCount(Symbol* signature) : SignatureInfo(signature) {} |
195 |
193 |
196 int size() { lazy_iterate_parameters(); return _size; } |
194 int size() { lazy_iterate_parameters(); return _size; } |
197 }; |
195 }; |
198 |
196 |
199 |
197 |
203 private: |
201 private: |
204 void set(int size, BasicType type) { _return_type = type; } |
202 void set(int size, BasicType type) { _return_type = type; } |
205 public: |
203 public: |
206 BasicType type() { lazy_iterate_return(); return _return_type; } |
204 BasicType type() { lazy_iterate_return(); return _return_type; } |
207 |
205 |
208 ResultTypeFinder(symbolHandle signature) : SignatureInfo(signature) {} |
206 ResultTypeFinder(Symbol* signature) : SignatureInfo(signature) {} |
209 }; |
207 }; |
210 |
208 |
211 |
209 |
212 // Fingerprinter computes a unique ID for a given method. The ID |
210 // Fingerprinter computes a unique ID for a given method. The ID |
213 // is a bitvector characterizing the methods signature (incl. the receiver). |
211 // is a bitvector characterizing the methods signature (incl. the receiver). |
232 void do_array (int begin, int end) { _fingerprint |= (((uint64_t)obj_parm) << _shift_count); _shift_count += parameter_feature_size; } |
230 void do_array (int begin, int end) { _fingerprint |= (((uint64_t)obj_parm) << _shift_count); _shift_count += parameter_feature_size; } |
233 |
231 |
234 void do_void() { ShouldNotReachHere(); } |
232 void do_void() { ShouldNotReachHere(); } |
235 |
233 |
236 Fingerprinter(methodHandle method) : SignatureIterator(method->signature()) { |
234 Fingerprinter(methodHandle method) : SignatureIterator(method->signature()) { |
237 mh = method; |
|
238 _fingerprint = 0; |
|
239 } |
|
240 |
|
241 Fingerprinter(Thread *thread, methodHandle method) : SignatureIterator(thread, method->signature()) { |
|
242 mh = method; |
235 mh = method; |
243 _fingerprint = 0; |
236 _fingerprint = 0; |
244 } |
237 } |
245 |
238 |
246 uint64_t fingerprint() { |
239 uint64_t fingerprint() { |
354 |
347 |
355 // Handy stream for iterating over signature |
348 // Handy stream for iterating over signature |
356 |
349 |
357 class SignatureStream : public StackObj { |
350 class SignatureStream : public StackObj { |
358 private: |
351 private: |
359 symbolHandle _signature; |
352 Symbol* _signature; |
360 int _begin; |
353 int _begin; |
361 int _end; |
354 int _end; |
362 BasicType _type; |
355 BasicType _type; |
363 bool _at_return_type; |
356 bool _at_return_type; |
|
357 GrowableArray<Symbol*>* _names; // symbols created while parsing signature |
364 |
358 |
365 public: |
359 public: |
366 bool at_return_type() const { return _at_return_type; } |
360 bool at_return_type() const { return _at_return_type; } |
367 bool is_done() const; |
361 bool is_done() const; |
368 void next_non_primitive(int t); |
362 void next_non_primitive(int t); |
369 void next() { |
363 void next() { |
370 symbolOop sig = _signature(); |
364 Symbol* sig = _signature; |
371 int len = sig->utf8_length(); |
365 int len = sig->utf8_length(); |
372 if (_end >= len) { |
366 if (_end >= len) { |
373 _end = len + 1; |
367 _end = len + 1; |
374 return; |
368 return; |
375 } |
369 } |
390 return; |
384 return; |
391 } |
385 } |
392 _end++; |
386 _end++; |
393 } |
387 } |
394 |
388 |
395 SignatureStream(symbolHandle signature, |
389 SignatureStream(Symbol* signature, bool is_method = true); |
396 bool is_method = true) : |
390 ~SignatureStream(); |
397 _signature(signature), _at_return_type(false) { |
|
398 _begin = _end = (is_method ? 1 : 0); // skip first '(' in method signatures |
|
399 next(); |
|
400 } |
|
401 |
391 |
402 bool is_object() const; // True if this argument is an object |
392 bool is_object() const; // True if this argument is an object |
403 bool is_array() const; // True if this argument is an array |
393 bool is_array() const; // True if this argument is an array |
404 BasicType type() const { return _type; } |
394 BasicType type() const { return _type; } |
405 symbolOop as_symbol(TRAPS); |
395 Symbol* as_symbol(TRAPS); |
406 enum FailureMode { ReturnNull, CNFException, NCDFError }; |
396 enum FailureMode { ReturnNull, CNFException, NCDFError }; |
407 klassOop as_klass(Handle class_loader, Handle protection_domain, FailureMode failure_mode, TRAPS); |
397 klassOop as_klass(Handle class_loader, Handle protection_domain, FailureMode failure_mode, TRAPS); |
408 oop as_java_mirror(Handle class_loader, Handle protection_domain, FailureMode failure_mode, TRAPS); |
398 oop as_java_mirror(Handle class_loader, Handle protection_domain, FailureMode failure_mode, TRAPS); |
409 |
399 |
410 // return same as_symbol except allocation of new symbols is avoided. |
400 // return same as_symbol except allocation of new symbols is avoided. |
411 symbolOop as_symbol_or_null(); |
401 Symbol* as_symbol_or_null(); |
412 }; |
402 }; |
413 |
403 |
414 class SignatureVerifier : public StackObj { |
404 class SignatureVerifier : public StackObj { |
415 public: |
405 public: |
416 // Returns true if the symbol is valid method or type signature |
406 // Returns true if the symbol is valid method or type signature |
417 static bool is_valid_signature(symbolHandle sig); |
407 static bool is_valid_signature(Symbol* sig); |
418 |
408 |
419 static bool is_valid_method_signature(symbolHandle sig); |
409 static bool is_valid_method_signature(Symbol* sig); |
420 static bool is_valid_type_signature(symbolHandle sig); |
410 static bool is_valid_type_signature(Symbol* sig); |
421 private: |
411 private: |
422 |
412 |
423 static ssize_t is_valid_type(const char*, ssize_t); |
413 static ssize_t is_valid_type(const char*, ssize_t); |
424 static bool invalid_name_char(char); |
414 static bool invalid_name_char(char); |
425 }; |
415 }; |