< prev index next >

src/hotspot/share/runtime/signature.cpp

Print this page




  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "classfile/symbolTable.hpp"
  27 #include "classfile/systemDictionary.hpp"
  28 #include "memory/oopFactory.hpp"
  29 #include "memory/resourceArea.hpp"
  30 #include "oops/instanceKlass.hpp"
  31 #include "oops/oop.inline.hpp"
  32 #include "oops/symbol.hpp"
  33 #include "oops/typeArrayKlass.hpp"
  34 #include "runtime/signature.hpp"
  35 
  36 // Implementation of SignatureIterator
  37 
  38 // Signature syntax:
  39 //
  40 // Signature  = "(" {Parameter} ")" ReturnType.
  41 // Parameter  = FieldType.
  42 // ReturnType = FieldType | "V".
  43 // FieldType  = "B" | "C" | "D" | "F" | "I" | "J" | "S" | "Z" | "L" ClassName ";" | "Q" ValueTypeName ";" | "[" FieldType.
  44 // ClassName  = string.
  45 
  46 
  47 SignatureIterator::SignatureIterator(Symbol* signature) {
  48   _signature       = signature;
  49   _parameter_index = 0;
  50 }
  51 
  52 void SignatureIterator::expect(char c) {
  53   if (_signature->byte_at(_index) != c) fatal("expecting %c", c);
  54   _index++;
  55 }
  56 
  57 
  58 void SignatureIterator::skip_optional_size() {
  59   Symbol* sig = _signature;
  60   char c = sig->byte_at(_index);
  61   while ('0' <= c && c <= '9') c = sig->byte_at(++_index);
  62 }
  63 


  80               _index++; size = T_FLOAT_size  ; break;
  81     case 'I': do_int   (); if (_parameter_index < 0 ) _return_type = T_INT;
  82               _index++; size = T_INT_size    ; break;
  83     case 'J': do_long  (); if (_parameter_index < 0 ) _return_type = T_LONG;
  84               _index++; size = T_LONG_size   ; break;
  85     case 'S': do_short (); if (_parameter_index < 0 ) _return_type = T_SHORT;
  86               _index++; size = T_SHORT_size  ; break;
  87     case 'Z': do_bool  (); if (_parameter_index < 0 ) _return_type = T_BOOLEAN;
  88               _index++; size = T_BOOLEAN_size; break;
  89     case 'V': do_void  (); if (_parameter_index < 0 ) _return_type = T_VOID;
  90               _index++; size = T_VOID_size;  ; break;
  91     case 'L':
  92       { int begin = ++_index;
  93         Symbol* sig = _signature;
  94         while (sig->byte_at(_index++) != ';') ;
  95         do_object(begin, _index);
  96       }
  97       if (_parameter_index < 0 ) _return_type = T_OBJECT;
  98       size = T_OBJECT_size;
  99       break;
 100     case 'Q':
 101       { int begin = ++_index;
 102         Symbol* sig = _signature;
 103         while (sig->byte_at(_index++) != ';') ;
 104         do_valuetype(begin, _index);
 105       }
 106       if (_parameter_index < 0 ) _return_type = T_VALUETYPE;
 107       size = T_VALUETYPE_size;
 108       break;
 109     case '[':
 110       { int begin = ++_index;
 111         skip_optional_size();
 112         Symbol* sig = _signature;
 113         while (sig->byte_at(_index) == '[') {
 114           _index++;
 115           skip_optional_size();
 116         }
 117         if (sig->byte_at(_index) == 'L' || sig->byte_at(_index) == 'Q') {
 118           while (sig->byte_at(_index++) != ';') ;
 119         } else {
 120           _index++;
 121         }
 122         do_array(begin, _index);
 123        if (_parameter_index < 0 ) _return_type = T_ARRAY;
 124       }
 125       size = T_ARRAY_size;
 126       break;
 127     default:
 128       ShouldNotReachHere();
 129       break;
 130   }
 131   assert(size >= 0, "size must be set");
 132   return size;
 133 }
 134 
 135 
 136 void SignatureIterator::check_signature_end() {
 137   if (_index < _signature->utf8_length()) {


 184       case byte_parm:
 185         do_byte();
 186         _parameter_index += T_BYTE_size;
 187         break;
 188       case char_parm:
 189         do_char();
 190         _parameter_index += T_CHAR_size;
 191         break;
 192       case short_parm:
 193         do_short();
 194         _parameter_index += T_SHORT_size;
 195         break;
 196       case int_parm:
 197         do_int();
 198         _parameter_index += T_INT_size;
 199         break;
 200       case obj_parm:
 201         do_object(0, 0);
 202         _parameter_index += T_OBJECT_size;
 203         break;
 204       case valuetype_parm:
 205         do_valuetype(0,0);
 206         _parameter_index += T_VALUETYPE_size;
 207         break;
 208       case long_parm:
 209         do_long();
 210         _parameter_index += T_LONG_size;
 211         break;
 212       case float_parm:
 213         do_float();
 214         _parameter_index += T_FLOAT_size;
 215         break;
 216       case double_parm:
 217         do_double();
 218         _parameter_index += T_DOUBLE_size;
 219         break;
 220       case done_parm:
 221         return;
 222         break;
 223       default:
 224         tty->print_cr("*** parameter is " UINT64_FORMAT, fingerprint & parameter_feature_mask);
 225         tty->print_cr("*** fingerprint is " PTR64_FORMAT, saved_fingerprint);
 226         ShouldNotReachHere();
 227         break;


 238   expect('(');
 239   Symbol* sig = _signature;
 240   // Need to skip over each type in the signature's argument list until a
 241   // closing ')' is found., then get the return type.  We cannot just scan
 242   // for the first ')' because ')' is a legal character in a type name.
 243   while (sig->byte_at(_index) != ')') {
 244     switch(sig->byte_at(_index)) {
 245       case 'B':
 246       case 'C':
 247       case 'D':
 248       case 'F':
 249       case 'I':
 250       case 'J':
 251       case 'S':
 252       case 'Z':
 253       case 'V':
 254         {
 255           _index++;
 256         }
 257         break;
 258       case 'Q':
 259       case 'L':
 260         {
 261           while (sig->byte_at(_index++) != ';') ;
 262         }
 263         break;
 264       case '[':
 265         {
 266           int begin = ++_index;
 267           skip_optional_size();
 268           while (sig->byte_at(_index) == '[') {
 269             _index++;
 270             skip_optional_size();
 271           }
 272           if (sig->byte_at(_index) == 'L' || sig->byte_at(_index) == 'Q') {
 273             while (sig->byte_at(_index++) != ';') ;
 274           } else {
 275             _index++;
 276           }
 277         }
 278         break;
 279       default:
 280         ShouldNotReachHere();
 281         break;
 282     }
 283   }
 284   expect(')');
 285   // Parse return type
 286   _parameter_index = -1;
 287   parse_type();
 288   check_signature_end();
 289   _parameter_index = 0;
 290 }
 291 
 292 


 316 SignatureStream::~SignatureStream() {
 317   // decrement refcount for names created during signature parsing
 318   for (int i = 0; i < _names->length(); i++) {
 319     _names->at(i)->decrement_refcount();
 320   }
 321 }
 322 
 323 bool SignatureStream::is_done() const {
 324   return _end > _signature->utf8_length();
 325 }
 326 
 327 
 328 void SignatureStream::next_non_primitive(int t) {
 329   switch (t) {
 330     case 'L': {
 331       _type = T_OBJECT;
 332       Symbol* sig = _signature;
 333       while (sig->byte_at(_end++) != ';');
 334       break;
 335     }
 336     case 'Q': {
 337       _type = T_VALUETYPE;
 338       Symbol* sig = _signature;
 339       while (sig->byte_at(_end++) != ';');
 340       break;
 341     }
 342     case '[': {
 343       _type = T_ARRAY;
 344       Symbol* sig = _signature;
 345       char c = sig->byte_at(_end);
 346       while ('0' <= c && c <= '9') c = sig->byte_at(_end++);
 347       while (sig->byte_at(_end) == '[') {
 348         _end++;
 349         c = sig->byte_at(_end);
 350         while ('0' <= c && c <= '9') c = sig->byte_at(_end++);
 351       }
 352       switch(sig->byte_at(_end)) {
 353         case 'B':
 354         case 'C':
 355         case 'D':
 356         case 'F':
 357         case 'I':
 358         case 'J':
 359         case 'S':
 360         case 'Z':_end++; break;
 361         default: {


 373 
 374 bool SignatureStream::is_object() const {
 375   return _type == T_OBJECT
 376       || _type == T_ARRAY
 377       || _type == T_VALUETYPE;
 378 }
 379 
 380 bool SignatureStream::is_array() const {
 381   return _type == T_ARRAY;
 382 }
 383 
 384 Symbol* SignatureStream::as_symbol(TRAPS) {
 385   // Create a symbol from for string _begin _end
 386   int begin = _begin;
 387   int end   = _end;
 388 
 389   if (_type == T_OBJECT || _type == T_VALUETYPE) {
 390     begin++;
 391     end--;
 392     if (begin == end) {
 393       return (_type == T_OBJECT) ? vmSymbols::java_lang_Object() : vmSymbols::java_lang____Value();
 394     }
 395   }
 396 
 397   // Save names for cleaning up reference count at the end of
 398   // SignatureStream scope.
 399   Symbol* name = SymbolTable::new_symbol(_signature, begin, end, CHECK_NULL);
 400   _names->push(name);  // save new symbol for decrementing later
 401   return name;
 402 }
 403 
 404 Klass* SignatureStream::as_klass(Handle class_loader, Handle protection_domain,
 405                                    FailureMode failure_mode, TRAPS) {
 406   if (!is_object())  return NULL;
 407   Symbol* name = as_symbol(CHECK_NULL);
 408   if (failure_mode == ReturnNull) {
 409     return SystemDictionary::resolve_or_null(name, class_loader, protection_domain, THREAD);
 410   } else {
 411     bool throw_error = (failure_mode == NCDFError);
 412     return SystemDictionary::resolve_or_fail(name, class_loader, protection_domain, throw_error, THREAD);
 413   }


 416 oop SignatureStream::as_java_mirror(Handle class_loader, Handle protection_domain,
 417                                     FailureMode failure_mode, TRAPS) {
 418   if (!is_object())
 419     return Universe::java_mirror(type());
 420   Klass* klass = as_klass(class_loader, protection_domain, failure_mode, CHECK_NULL);
 421   if (klass == NULL)  return NULL;
 422   return klass->java_mirror();
 423 }
 424 
 425 Symbol* SignatureStream::as_symbol_or_null() {
 426   // Create a symbol from for string _begin _end
 427   ResourceMark rm;
 428 
 429   int begin = _begin;
 430   int end   = _end;
 431 
 432   if (_type == T_OBJECT || _type == T_VALUETYPE) {
 433     begin++;
 434     end--;
 435     if (begin == end) {
 436       return (_type == T_OBJECT) ? vmSymbols::java_lang_Object() : vmSymbols::java_lang____Value();
 437     }
 438   }
 439 
 440   char* buffer = NEW_RESOURCE_ARRAY(char, end - begin);
 441   for (int index = begin; index < end; index++) {
 442     buffer[index - begin] = _signature->byte_at(index);
 443   }
 444   Symbol* result = SymbolTable::probe(buffer, end - begin);
 445   return result;
 446 }
 447 
 448 int SignatureStream::reference_parameter_count() {
 449   int args_count = 0;
 450   for ( ; !at_return_type(); next()) {
 451     if (is_object()) {
 452       args_count++;
 453     }
 454   }
 455   return args_count;
 456 }


 495   ssize_t len = sig->utf8_length();
 496   return (type_sig != NULL && len >= 1 &&
 497           (is_valid_type(type_sig, len) == len));
 498 }
 499 
 500 // Checks to see if the type (not to go beyond 'limit') refers to a valid type.
 501 // Returns -1 if it is not, or the index of the next character that is not part
 502 // of the type.  The type encoding may end before 'limit' and that's ok.
 503 ssize_t SignatureVerifier::is_valid_type(const char* type, ssize_t limit) {
 504   ssize_t index = 0;
 505 
 506   // Iterate over any number of array dimensions
 507   while (index < limit && type[index] == '[') ++index;
 508   if (index >= limit) {
 509     return -1;
 510   }
 511   switch (type[index]) {
 512     case 'B': case 'C': case 'D': case 'F': case 'I':
 513     case 'J': case 'S': case 'Z': case 'V':
 514       return index + 1;
 515     case 'Q':
 516     case 'L':
 517       for (index = index + 1; index < limit; ++index) {
 518         char c = type[index];
 519         if (c == ';') {
 520           return index + 1;
 521         }
 522         if (invalid_name_char(c)) {
 523           return -1;
 524         }
 525       }
 526       // fall through
 527     default: ; // fall through
 528   }
 529   return -1;
 530 }
 531 
 532 bool SignatureVerifier::invalid_name_char(char c) {
 533   switch (c) {
 534     case '\0': case '.': case ';': case '[':
 535       return true;




  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "classfile/symbolTable.hpp"
  27 #include "classfile/systemDictionary.hpp"
  28 #include "memory/oopFactory.hpp"
  29 #include "memory/resourceArea.hpp"
  30 #include "oops/instanceKlass.hpp"
  31 #include "oops/oop.inline.hpp"
  32 #include "oops/symbol.hpp"
  33 #include "oops/typeArrayKlass.hpp"
  34 #include "runtime/signature.hpp"
  35 
  36 // Implementation of SignatureIterator
  37 
  38 // Signature syntax:
  39 //
  40 // Signature  = "(" {Parameter} ")" ReturnType.
  41 // Parameter  = FieldType.
  42 // ReturnType = FieldType | "V".
  43 // FieldType  = "B" | "C" | "D" | "F" | "I" | "J" | "S" | "Z" | "L" ClassName ";" | "[" FieldType.
  44 // ClassName  = string.
  45 
  46 
  47 SignatureIterator::SignatureIterator(Symbol* signature) {
  48   _signature       = signature;
  49   _parameter_index = 0;
  50 }
  51 
  52 void SignatureIterator::expect(char c) {
  53   if (_signature->byte_at(_index) != c) fatal("expecting %c", c);
  54   _index++;
  55 }
  56 
  57 
  58 void SignatureIterator::skip_optional_size() {
  59   Symbol* sig = _signature;
  60   char c = sig->byte_at(_index);
  61   while ('0' <= c && c <= '9') c = sig->byte_at(++_index);
  62 }
  63 


  80               _index++; size = T_FLOAT_size  ; break;
  81     case 'I': do_int   (); if (_parameter_index < 0 ) _return_type = T_INT;
  82               _index++; size = T_INT_size    ; break;
  83     case 'J': do_long  (); if (_parameter_index < 0 ) _return_type = T_LONG;
  84               _index++; size = T_LONG_size   ; break;
  85     case 'S': do_short (); if (_parameter_index < 0 ) _return_type = T_SHORT;
  86               _index++; size = T_SHORT_size  ; break;
  87     case 'Z': do_bool  (); if (_parameter_index < 0 ) _return_type = T_BOOLEAN;
  88               _index++; size = T_BOOLEAN_size; break;
  89     case 'V': do_void  (); if (_parameter_index < 0 ) _return_type = T_VOID;
  90               _index++; size = T_VOID_size;  ; break;
  91     case 'L':
  92       { int begin = ++_index;
  93         Symbol* sig = _signature;
  94         while (sig->byte_at(_index++) != ';') ;
  95         do_object(begin, _index);
  96       }
  97       if (_parameter_index < 0 ) _return_type = T_OBJECT;
  98       size = T_OBJECT_size;
  99       break;









 100     case '[':
 101       { int begin = ++_index;
 102         skip_optional_size();
 103         Symbol* sig = _signature;
 104         while (sig->byte_at(_index) == '[') {
 105           _index++;
 106           skip_optional_size();
 107         }
 108         if (sig->byte_at(_index) == 'L') {
 109           while (sig->byte_at(_index++) != ';') ;
 110         } else {
 111           _index++;
 112         }
 113         do_array(begin, _index);
 114        if (_parameter_index < 0 ) _return_type = T_ARRAY;
 115       }
 116       size = T_ARRAY_size;
 117       break;
 118     default:
 119       ShouldNotReachHere();
 120       break;
 121   }
 122   assert(size >= 0, "size must be set");
 123   return size;
 124 }
 125 
 126 
 127 void SignatureIterator::check_signature_end() {
 128   if (_index < _signature->utf8_length()) {


 175       case byte_parm:
 176         do_byte();
 177         _parameter_index += T_BYTE_size;
 178         break;
 179       case char_parm:
 180         do_char();
 181         _parameter_index += T_CHAR_size;
 182         break;
 183       case short_parm:
 184         do_short();
 185         _parameter_index += T_SHORT_size;
 186         break;
 187       case int_parm:
 188         do_int();
 189         _parameter_index += T_INT_size;
 190         break;
 191       case obj_parm:
 192         do_object(0, 0);
 193         _parameter_index += T_OBJECT_size;
 194         break;




 195       case long_parm:
 196         do_long();
 197         _parameter_index += T_LONG_size;
 198         break;
 199       case float_parm:
 200         do_float();
 201         _parameter_index += T_FLOAT_size;
 202         break;
 203       case double_parm:
 204         do_double();
 205         _parameter_index += T_DOUBLE_size;
 206         break;
 207       case done_parm:
 208         return;
 209         break;
 210       default:
 211         tty->print_cr("*** parameter is " UINT64_FORMAT, fingerprint & parameter_feature_mask);
 212         tty->print_cr("*** fingerprint is " PTR64_FORMAT, saved_fingerprint);
 213         ShouldNotReachHere();
 214         break;


 225   expect('(');
 226   Symbol* sig = _signature;
 227   // Need to skip over each type in the signature's argument list until a
 228   // closing ')' is found., then get the return type.  We cannot just scan
 229   // for the first ')' because ')' is a legal character in a type name.
 230   while (sig->byte_at(_index) != ')') {
 231     switch(sig->byte_at(_index)) {
 232       case 'B':
 233       case 'C':
 234       case 'D':
 235       case 'F':
 236       case 'I':
 237       case 'J':
 238       case 'S':
 239       case 'Z':
 240       case 'V':
 241         {
 242           _index++;
 243         }
 244         break;

 245       case 'L':
 246         {
 247           while (sig->byte_at(_index++) != ';') ;
 248         }
 249         break;
 250       case '[':
 251         {
 252           int begin = ++_index;
 253           skip_optional_size();
 254           while (sig->byte_at(_index) == '[') {
 255             _index++;
 256             skip_optional_size();
 257           }
 258           if (sig->byte_at(_index) == 'L') {
 259             while (sig->byte_at(_index++) != ';') ;
 260           } else {
 261             _index++;
 262           }
 263         }
 264         break;
 265       default:
 266         ShouldNotReachHere();
 267         break;
 268     }
 269   }
 270   expect(')');
 271   // Parse return type
 272   _parameter_index = -1;
 273   parse_type();
 274   check_signature_end();
 275   _parameter_index = 0;
 276 }
 277 
 278 


 302 SignatureStream::~SignatureStream() {
 303   // decrement refcount for names created during signature parsing
 304   for (int i = 0; i < _names->length(); i++) {
 305     _names->at(i)->decrement_refcount();
 306   }
 307 }
 308 
 309 bool SignatureStream::is_done() const {
 310   return _end > _signature->utf8_length();
 311 }
 312 
 313 
 314 void SignatureStream::next_non_primitive(int t) {
 315   switch (t) {
 316     case 'L': {
 317       _type = T_OBJECT;
 318       Symbol* sig = _signature;
 319       while (sig->byte_at(_end++) != ';');
 320       break;
 321     }






 322     case '[': {
 323       _type = T_ARRAY;
 324       Symbol* sig = _signature;
 325       char c = sig->byte_at(_end);
 326       while ('0' <= c && c <= '9') c = sig->byte_at(_end++);
 327       while (sig->byte_at(_end) == '[') {
 328         _end++;
 329         c = sig->byte_at(_end);
 330         while ('0' <= c && c <= '9') c = sig->byte_at(_end++);
 331       }
 332       switch(sig->byte_at(_end)) {
 333         case 'B':
 334         case 'C':
 335         case 'D':
 336         case 'F':
 337         case 'I':
 338         case 'J':
 339         case 'S':
 340         case 'Z':_end++; break;
 341         default: {


 353 
 354 bool SignatureStream::is_object() const {
 355   return _type == T_OBJECT
 356       || _type == T_ARRAY
 357       || _type == T_VALUETYPE;
 358 }
 359 
 360 bool SignatureStream::is_array() const {
 361   return _type == T_ARRAY;
 362 }
 363 
 364 Symbol* SignatureStream::as_symbol(TRAPS) {
 365   // Create a symbol from for string _begin _end
 366   int begin = _begin;
 367   int end   = _end;
 368 
 369   if (_type == T_OBJECT || _type == T_VALUETYPE) {
 370     begin++;
 371     end--;
 372     if (begin == end) {
 373       return vmSymbols::java_lang_Object();
 374     }
 375   }
 376 
 377   // Save names for cleaning up reference count at the end of
 378   // SignatureStream scope.
 379   Symbol* name = SymbolTable::new_symbol(_signature, begin, end, CHECK_NULL);
 380   _names->push(name);  // save new symbol for decrementing later
 381   return name;
 382 }
 383 
 384 Klass* SignatureStream::as_klass(Handle class_loader, Handle protection_domain,
 385                                    FailureMode failure_mode, TRAPS) {
 386   if (!is_object())  return NULL;
 387   Symbol* name = as_symbol(CHECK_NULL);
 388   if (failure_mode == ReturnNull) {
 389     return SystemDictionary::resolve_or_null(name, class_loader, protection_domain, THREAD);
 390   } else {
 391     bool throw_error = (failure_mode == NCDFError);
 392     return SystemDictionary::resolve_or_fail(name, class_loader, protection_domain, throw_error, THREAD);
 393   }


 396 oop SignatureStream::as_java_mirror(Handle class_loader, Handle protection_domain,
 397                                     FailureMode failure_mode, TRAPS) {
 398   if (!is_object())
 399     return Universe::java_mirror(type());
 400   Klass* klass = as_klass(class_loader, protection_domain, failure_mode, CHECK_NULL);
 401   if (klass == NULL)  return NULL;
 402   return klass->java_mirror();
 403 }
 404 
 405 Symbol* SignatureStream::as_symbol_or_null() {
 406   // Create a symbol from for string _begin _end
 407   ResourceMark rm;
 408 
 409   int begin = _begin;
 410   int end   = _end;
 411 
 412   if (_type == T_OBJECT || _type == T_VALUETYPE) {
 413     begin++;
 414     end--;
 415     if (begin == end) {
 416       return vmSymbols::java_lang_Object();
 417     }
 418   }
 419 
 420   char* buffer = NEW_RESOURCE_ARRAY(char, end - begin);
 421   for (int index = begin; index < end; index++) {
 422     buffer[index - begin] = _signature->byte_at(index);
 423   }
 424   Symbol* result = SymbolTable::probe(buffer, end - begin);
 425   return result;
 426 }
 427 
 428 int SignatureStream::reference_parameter_count() {
 429   int args_count = 0;
 430   for ( ; !at_return_type(); next()) {
 431     if (is_object()) {
 432       args_count++;
 433     }
 434   }
 435   return args_count;
 436 }


 475   ssize_t len = sig->utf8_length();
 476   return (type_sig != NULL && len >= 1 &&
 477           (is_valid_type(type_sig, len) == len));
 478 }
 479 
 480 // Checks to see if the type (not to go beyond 'limit') refers to a valid type.
 481 // Returns -1 if it is not, or the index of the next character that is not part
 482 // of the type.  The type encoding may end before 'limit' and that's ok.
 483 ssize_t SignatureVerifier::is_valid_type(const char* type, ssize_t limit) {
 484   ssize_t index = 0;
 485 
 486   // Iterate over any number of array dimensions
 487   while (index < limit && type[index] == '[') ++index;
 488   if (index >= limit) {
 489     return -1;
 490   }
 491   switch (type[index]) {
 492     case 'B': case 'C': case 'D': case 'F': case 'I':
 493     case 'J': case 'S': case 'Z': case 'V':
 494       return index + 1;

 495     case 'L':
 496       for (index = index + 1; index < limit; ++index) {
 497         char c = type[index];
 498         if (c == ';') {
 499           return index + 1;
 500         }
 501         if (invalid_name_char(c)) {
 502           return -1;
 503         }
 504       }
 505       // fall through
 506     default: ; // fall through
 507   }
 508   return -1;
 509 }
 510 
 511 bool SignatureVerifier::invalid_name_char(char c) {
 512   switch (c) {
 513     case '\0': case '.': case ';': case '[':
 514       return true;


< prev index next >