src/hotspot/share/runtime/signature.cpp
changeset 58722 cba8afa5cfed
parent 54847 59ea39bb2809
equal deleted inserted replaced
58720:ae0af9fb3dbb 58722:cba8afa5cfed
    61   //       seems that the product build for win32_i486 with MS VC++ 6.0 doesn't
    61   //       seems that the product build for win32_i486 with MS VC++ 6.0 doesn't
    62   //       work (stack underflow for some tests) - this seems to be a VC++ 6.0
    62   //       work (stack underflow for some tests) - this seems to be a VC++ 6.0
    63   //       compiler bug (was problem - gri 4/27/2000).
    63   //       compiler bug (was problem - gri 4/27/2000).
    64   int size = -1;
    64   int size = -1;
    65   switch(_signature->char_at(_index)) {
    65   switch(_signature->char_at(_index)) {
    66     case 'B': do_byte  (); if (_parameter_index < 0 ) _return_type = T_BYTE;
    66     case JVM_SIGNATURE_BYTE:    do_byte(); if (_parameter_index < 0 ) _return_type = T_BYTE;
    67               _index++; size = T_BYTE_size   ; break;
    67                                   _index++; size = T_BYTE_size; break;
    68     case 'C': do_char  (); if (_parameter_index < 0 ) _return_type = T_CHAR;
    68     case JVM_SIGNATURE_CHAR:    do_char(); if (_parameter_index < 0 ) _return_type = T_CHAR;
    69               _index++; size = T_CHAR_size   ; break;
    69                                   _index++; size = T_CHAR_size; break;
    70     case 'D': do_double(); if (_parameter_index < 0 ) _return_type = T_DOUBLE;
    70     case JVM_SIGNATURE_DOUBLE:  do_double(); if (_parameter_index < 0 ) _return_type = T_DOUBLE;
    71               _index++; size = T_DOUBLE_size ; break;
    71                                   _index++; size = T_DOUBLE_size; break;
    72     case 'F': do_float (); if (_parameter_index < 0 ) _return_type = T_FLOAT;
    72     case JVM_SIGNATURE_FLOAT:   do_float(); if (_parameter_index < 0 ) _return_type = T_FLOAT;
    73               _index++; size = T_FLOAT_size  ; break;
    73                                   _index++; size = T_FLOAT_size; break;
    74     case 'I': do_int   (); if (_parameter_index < 0 ) _return_type = T_INT;
    74     case JVM_SIGNATURE_INT:     do_int(); if (_parameter_index < 0 ) _return_type = T_INT;
    75               _index++; size = T_INT_size    ; break;
    75                                   _index++; size = T_INT_size; break;
    76     case 'J': do_long  (); if (_parameter_index < 0 ) _return_type = T_LONG;
    76     case JVM_SIGNATURE_LONG:    do_long(); if (_parameter_index < 0 ) _return_type = T_LONG;
    77               _index++; size = T_LONG_size   ; break;
    77                                   _index++; size = T_LONG_size; break;
    78     case 'S': do_short (); if (_parameter_index < 0 ) _return_type = T_SHORT;
    78     case JVM_SIGNATURE_SHORT:   do_short(); if (_parameter_index < 0 ) _return_type = T_SHORT;
    79               _index++; size = T_SHORT_size  ; break;
    79                                   _index++; size = T_SHORT_size; break;
    80     case 'Z': do_bool  (); if (_parameter_index < 0 ) _return_type = T_BOOLEAN;
    80     case JVM_SIGNATURE_BOOLEAN: do_bool(); if (_parameter_index < 0 ) _return_type = T_BOOLEAN;
    81               _index++; size = T_BOOLEAN_size; break;
    81                                   _index++; size = T_BOOLEAN_size; break;
    82     case 'V': do_void  (); if (_parameter_index < 0 ) _return_type = T_VOID;
    82     case JVM_SIGNATURE_VOID:    do_void(); if (_parameter_index < 0 ) _return_type = T_VOID;
    83               _index++; size = T_VOID_size;  ; break;
    83                                   _index++; size = T_VOID_size; break;
    84     case 'L':
    84     case JVM_SIGNATURE_CLASS:
    85       { int begin = ++_index;
    85       { int begin = ++_index;
    86         Symbol* sig = _signature;
    86         Symbol* sig = _signature;
    87         while (sig->char_at(_index++) != ';') ;
    87         while (sig->char_at(_index++) != JVM_SIGNATURE_ENDCLASS) ;
    88         do_object(begin, _index);
    88         do_object(begin, _index);
    89       }
    89       }
    90       if (_parameter_index < 0 ) _return_type = T_OBJECT;
    90       if (_parameter_index < 0 ) _return_type = T_OBJECT;
    91       size = T_OBJECT_size;
    91       size = T_OBJECT_size;
    92       break;
    92       break;
    93     case '[':
    93     case JVM_SIGNATURE_ARRAY:
    94       { int begin = ++_index;
    94       { int begin = ++_index;
    95         Symbol* sig = _signature;
    95         Symbol* sig = _signature;
    96         while (sig->char_at(_index) == '[') {
    96         while (sig->char_at(_index) == JVM_SIGNATURE_ARRAY) {
    97           _index++;
    97           _index++;
    98         }
    98         }
    99         if (sig->char_at(_index) == 'L') {
    99         if (sig->char_at(_index) == JVM_SIGNATURE_CLASS) {
   100           while (sig->char_at(_index++) != ';') ;
   100           while (sig->char_at(_index++) != JVM_SIGNATURE_ENDCLASS) ;
   101         } else {
   101         } else {
   102           _index++;
   102           _index++;
   103         }
   103         }
   104         do_array(begin, _index);
   104         do_array(begin, _index);
   105        if (_parameter_index < 0 ) _return_type = T_ARRAY;
   105        if (_parameter_index < 0 ) _return_type = T_ARRAY;
   126 
   126 
   127 void SignatureIterator::iterate_parameters() {
   127 void SignatureIterator::iterate_parameters() {
   128   // Parse parameters
   128   // Parse parameters
   129   _index = 0;
   129   _index = 0;
   130   _parameter_index = 0;
   130   _parameter_index = 0;
   131   expect('(');
   131   expect(JVM_SIGNATURE_FUNC);
   132   while (_signature->char_at(_index) != ')') _parameter_index += parse_type();
   132   while (_signature->char_at(_index) != JVM_SIGNATURE_ENDFUNC) _parameter_index += parse_type();
   133   expect(')');
   133   expect(JVM_SIGNATURE_ENDFUNC);
   134   _parameter_index = 0;
   134   _parameter_index = 0;
   135 }
   135 }
   136 
   136 
   137 // Optimized version of iterate_parameters when fingerprint is known
   137 // Optimized version of iterate_parameters when fingerprint is known
   138 void SignatureIterator::iterate_parameters( uint64_t fingerprint ) {
   138 void SignatureIterator::iterate_parameters( uint64_t fingerprint ) {
   200 
   200 
   201 
   201 
   202 void SignatureIterator::iterate_returntype() {
   202 void SignatureIterator::iterate_returntype() {
   203   // Ignore parameters
   203   // Ignore parameters
   204   _index = 0;
   204   _index = 0;
   205   expect('(');
   205   expect(JVM_SIGNATURE_FUNC);
   206   Symbol* sig = _signature;
   206   Symbol* sig = _signature;
   207   // Need to skip over each type in the signature's argument list until a
   207   // Need to skip over each type in the signature's argument list until a
   208   // closing ')' is found., then get the return type.  We cannot just scan
   208   // closing ')' is found., then get the return type.  We cannot just scan
   209   // for the first ')' because ')' is a legal character in a type name.
   209   // for the first ')' because ')' is a legal character in a type name.
   210   while (sig->char_at(_index) != ')') {
   210   while (sig->char_at(_index) != JVM_SIGNATURE_ENDFUNC) {
   211     switch(sig->char_at(_index)) {
   211     switch(sig->char_at(_index)) {
   212       case 'B':
   212       case JVM_SIGNATURE_BYTE:
   213       case 'C':
   213       case JVM_SIGNATURE_CHAR:
   214       case 'D':
   214       case JVM_SIGNATURE_DOUBLE:
   215       case 'F':
   215       case JVM_SIGNATURE_FLOAT:
   216       case 'I':
   216       case JVM_SIGNATURE_INT:
   217       case 'J':
   217       case JVM_SIGNATURE_LONG:
   218       case 'S':
   218       case JVM_SIGNATURE_SHORT:
   219       case 'Z':
   219       case JVM_SIGNATURE_BOOLEAN:
   220       case 'V':
   220       case JVM_SIGNATURE_VOID:
   221         {
   221         {
   222           _index++;
   222           _index++;
   223         }
   223         }
   224         break;
   224         break;
   225       case 'L':
   225       case JVM_SIGNATURE_CLASS:
   226         {
   226         {
   227           while (sig->char_at(_index++) != ';') ;
   227           while (sig->char_at(_index++) != JVM_SIGNATURE_ENDCLASS) ;
   228         }
   228         }
   229         break;
   229         break;
   230       case '[':
   230       case JVM_SIGNATURE_ARRAY:
   231         {
   231         {
   232           while (sig->char_at(++_index) == '[') ;
   232           while (sig->char_at(++_index) == JVM_SIGNATURE_ARRAY) ;
   233           if (sig->char_at(_index) == 'L') {
   233           if (sig->char_at(_index) == JVM_SIGNATURE_CLASS) {
   234             while (sig->char_at(_index++) != ';') ;
   234             while (sig->char_at(_index++) != JVM_SIGNATURE_ENDCLASS) ;
   235           } else {
   235           } else {
   236             _index++;
   236             _index++;
   237           }
   237           }
   238         }
   238         }
   239         break;
   239         break;
   240       default:
   240       default:
   241         ShouldNotReachHere();
   241         ShouldNotReachHere();
   242         break;
   242         break;
   243     }
   243     }
   244   }
   244   }
   245   expect(')');
   245   expect(JVM_SIGNATURE_ENDFUNC);
   246   // Parse return type
   246   // Parse return type
   247   _parameter_index = -1;
   247   _parameter_index = -1;
   248   parse_type();
   248   parse_type();
   249   check_signature_end();
   249   check_signature_end();
   250   _parameter_index = 0;
   250   _parameter_index = 0;
   253 
   253 
   254 void SignatureIterator::iterate() {
   254 void SignatureIterator::iterate() {
   255   // Parse parameters
   255   // Parse parameters
   256   _parameter_index = 0;
   256   _parameter_index = 0;
   257   _index = 0;
   257   _index = 0;
   258   expect('(');
   258   expect(JVM_SIGNATURE_FUNC);
   259   while (_signature->char_at(_index) != ')') _parameter_index += parse_type();
   259   while (_signature->char_at(_index) != JVM_SIGNATURE_ENDFUNC) _parameter_index += parse_type();
   260   expect(')');
   260   expect(JVM_SIGNATURE_ENDFUNC);
   261   // Parse return type
   261   // Parse return type
   262   _parameter_index = -1;
   262   _parameter_index = -1;
   263   parse_type();
   263   parse_type();
   264   check_signature_end();
   264   check_signature_end();
   265   _parameter_index = 0;
   265   _parameter_index = 0;
   287 }
   287 }
   288 
   288 
   289 
   289 
   290 void SignatureStream::next_non_primitive(int t) {
   290 void SignatureStream::next_non_primitive(int t) {
   291   switch (t) {
   291   switch (t) {
   292     case 'L': {
   292     case JVM_SIGNATURE_CLASS: {
   293       _type = T_OBJECT;
   293       _type = T_OBJECT;
   294       Symbol* sig = _signature;
   294       Symbol* sig = _signature;
   295       while (sig->char_at(_end++) != ';');
   295       while (sig->char_at(_end++) != JVM_SIGNATURE_ENDCLASS);
   296       break;
   296       break;
   297     }
   297     }
   298     case '[': {
   298     case JVM_SIGNATURE_ARRAY: {
   299       _type = T_ARRAY;
   299       _type = T_ARRAY;
   300       Symbol* sig = _signature;
   300       Symbol* sig = _signature;
   301       char c = sig->char_at(_end);
   301       char c = sig->char_at(_end);
   302       while ('0' <= c && c <= '9') c = sig->char_at(_end++);
   302       while ('0' <= c && c <= '9') c = sig->char_at(_end++);
   303       while (sig->char_at(_end) == '[') {
   303       while (sig->char_at(_end) == JVM_SIGNATURE_ARRAY) {
   304         _end++;
   304         _end++;
   305         c = sig->char_at(_end);
   305         c = sig->char_at(_end);
   306         while ('0' <= c && c <= '9') c = sig->char_at(_end++);
   306         while ('0' <= c && c <= '9') c = sig->char_at(_end++);
   307       }
   307       }
   308       switch(sig->char_at(_end)) {
   308       switch(sig->char_at(_end)) {
   309         case 'B':
   309         case JVM_SIGNATURE_BYTE:
   310         case 'C':
   310         case JVM_SIGNATURE_CHAR:
   311         case 'D':
   311         case JVM_SIGNATURE_DOUBLE:
   312         case 'F':
   312         case JVM_SIGNATURE_FLOAT:
   313         case 'I':
   313         case JVM_SIGNATURE_INT:
   314         case 'J':
   314         case JVM_SIGNATURE_LONG:
   315         case 'S':
   315         case JVM_SIGNATURE_SHORT:
   316         case 'Z':_end++; break;
   316         case JVM_SIGNATURE_BOOLEAN:_end++; break;
   317         default: {
   317         default: {
   318           while (sig->char_at(_end++) != ';');
   318           while (sig->char_at(_end++) != JVM_SIGNATURE_ENDCLASS);
   319           break;
   319           break;
   320         }
   320         }
   321       }
   321       }
   322       break;
   322       break;
   323     }
   323     }
   324     case ')': _end++; next(); _at_return_type = true; break;
   324     case JVM_SIGNATURE_ENDFUNC: _end++; next(); _at_return_type = true; break;
   325     default : ShouldNotReachHere();
   325     default : ShouldNotReachHere();
   326   }
   326   }
   327 }
   327 }
   328 
   328 
   329 
   329 
   339 Symbol* SignatureStream::as_symbol() {
   339 Symbol* SignatureStream::as_symbol() {
   340   // Create a symbol from for string _begin _end
   340   // Create a symbol from for string _begin _end
   341   int begin = _begin;
   341   int begin = _begin;
   342   int end   = _end;
   342   int end   = _end;
   343 
   343 
   344   if (   _signature->char_at(_begin) == 'L'
   344   if (   _signature->char_at(_begin) == JVM_SIGNATURE_CLASS
   345       && _signature->char_at(_end-1) == ';') {
   345       && _signature->char_at(_end-1) == JVM_SIGNATURE_ENDCLASS) {
   346     begin++;
   346     begin++;
   347     end--;
   347     end--;
   348   }
   348   }
   349 
   349 
   350   const char* symbol_chars = (const char*)_signature->base() + begin;
   350   const char* symbol_chars = (const char*)_signature->base() + begin;
   405   ResourceMark rm;
   405   ResourceMark rm;
   406 
   406 
   407   int begin = _begin;
   407   int begin = _begin;
   408   int end   = _end;
   408   int end   = _end;
   409 
   409 
   410   if (   _signature->char_at(_begin) == 'L'
   410   if (   _signature->char_at(_begin) == JVM_SIGNATURE_CLASS
   411       && _signature->char_at(_end-1) == ';') {
   411       && _signature->char_at(_end-1) == JVM_SIGNATURE_ENDCLASS) {
   412     begin++;
   412     begin++;
   413     end--;
   413     end--;
   414   }
   414   }
   415 
   415 
   416   char* buffer = NEW_RESOURCE_ARRAY(char, end - begin);
   416   char* buffer = NEW_RESOURCE_ARRAY(char, end - begin);
   434 #ifdef ASSERT
   434 #ifdef ASSERT
   435 bool SignatureVerifier::is_valid_method_signature(Symbol* sig) {
   435 bool SignatureVerifier::is_valid_method_signature(Symbol* sig) {
   436   const char* method_sig = (const char*)sig->bytes();
   436   const char* method_sig = (const char*)sig->bytes();
   437   ssize_t len = sig->utf8_length();
   437   ssize_t len = sig->utf8_length();
   438   ssize_t index = 0;
   438   ssize_t index = 0;
   439   if (method_sig != NULL && len > 1 && method_sig[index] == '(') {
   439   if (method_sig != NULL && len > 1 && method_sig[index] == JVM_SIGNATURE_FUNC) {
   440     ++index;
   440     ++index;
   441     while (index < len && method_sig[index] != ')') {
   441     while (index < len && method_sig[index] != JVM_SIGNATURE_ENDFUNC) {
   442       ssize_t res = is_valid_type(&method_sig[index], len - index);
   442       ssize_t res = is_valid_type(&method_sig[index], len - index);
   443       if (res == -1) {
   443       if (res == -1) {
   444         return false;
   444         return false;
   445       } else {
   445       } else {
   446         index += res;
   446         index += res;
   447       }
   447       }
   448     }
   448     }
   449     if (index < len && method_sig[index] == ')') {
   449     if (index < len && method_sig[index] == JVM_SIGNATURE_ENDFUNC) {
   450       // check the return type
   450       // check the return type
   451       ++index;
   451       ++index;
   452       return (is_valid_type(&method_sig[index], len - index) == (len - index));
   452       return (is_valid_type(&method_sig[index], len - index) == (len - index));
   453     }
   453     }
   454   }
   454   }
   467 // of the type.  The type encoding may end before 'limit' and that's ok.
   467 // of the type.  The type encoding may end before 'limit' and that's ok.
   468 ssize_t SignatureVerifier::is_valid_type(const char* type, ssize_t limit) {
   468 ssize_t SignatureVerifier::is_valid_type(const char* type, ssize_t limit) {
   469   ssize_t index = 0;
   469   ssize_t index = 0;
   470 
   470 
   471   // Iterate over any number of array dimensions
   471   // Iterate over any number of array dimensions
   472   while (index < limit && type[index] == '[') ++index;
   472   while (index < limit && type[index] == JVM_SIGNATURE_ARRAY) ++index;
   473   if (index >= limit) {
   473   if (index >= limit) {
   474     return -1;
   474     return -1;
   475   }
   475   }
   476   switch (type[index]) {
   476   switch (type[index]) {
   477     case 'B': case 'C': case 'D': case 'F': case 'I':
   477     case JVM_SIGNATURE_BYTE:
   478     case 'J': case 'S': case 'Z': case 'V':
   478     case JVM_SIGNATURE_CHAR:
       
   479     case JVM_SIGNATURE_DOUBLE:
       
   480     case JVM_SIGNATURE_FLOAT:
       
   481     case JVM_SIGNATURE_INT:
       
   482     case JVM_SIGNATURE_LONG:
       
   483     case JVM_SIGNATURE_SHORT:
       
   484     case JVM_SIGNATURE_BOOLEAN:
       
   485     case JVM_SIGNATURE_VOID:
   479       return index + 1;
   486       return index + 1;
   480     case 'L':
   487     case JVM_SIGNATURE_CLASS:
   481       for (index = index + 1; index < limit; ++index) {
   488       for (index = index + 1; index < limit; ++index) {
   482         char c = type[index];
   489         char c = type[index];
   483         switch (c) {
   490         switch (c) {
   484           case ';':
   491           case JVM_SIGNATURE_ENDCLASS:
   485             return index + 1;
   492             return index + 1;
   486           case '\0': case '.': case '[':
   493           case '\0': case JVM_SIGNATURE_DOT: case JVM_SIGNATURE_ARRAY:
   487             return -1;
   494             return -1;
   488           default: ; // fall through
   495           default: ; // fall through
   489         }
   496         }
   490       }
   497       }
   491       // fall through
   498       // fall through