src/hotspot/share/prims/methodHandles.cpp
changeset 58722 cba8afa5cfed
parent 58545 725244418646
child 59056 15936b142f86
equal deleted inserted replaced
58720:ae0af9fb3dbb 58722:cba8afa5cfed
   540   assert(vmSymbols::object_signature()->utf8_length() == (int)OBJ_SIG_LEN, "");
   540   assert(vmSymbols::object_signature()->utf8_length() == (int)OBJ_SIG_LEN, "");
   541   assert(vmSymbols::object_signature()->equals(OBJ_SIG), "");
   541   assert(vmSymbols::object_signature()->equals(OBJ_SIG), "");
   542   const int len = sig->utf8_length();
   542   const int len = sig->utf8_length();
   543   for (int i = 0; i < len; i++) {
   543   for (int i = 0; i < len; i++) {
   544     switch (sig->char_at(i)) {
   544     switch (sig->char_at(i)) {
   545     case 'L':
   545     case JVM_SIGNATURE_CLASS:
   546       // only java/lang/Object is valid here
   546       // only java/lang/Object is valid here
   547       if (sig->index_of_at(i, OBJ_SIG, OBJ_SIG_LEN) != i)
   547       if (sig->index_of_at(i, OBJ_SIG, OBJ_SIG_LEN) != i)
   548         return false;
   548         return false;
   549       i += OBJ_SIG_LEN-1;  //-1 because of i++ in loop
   549       i += OBJ_SIG_LEN-1;  //-1 because of i++ in loop
   550       continue;
   550       continue;
   551     case '(': case ')': case 'V':
   551     case JVM_SIGNATURE_FUNC:
   552     case 'I': case 'J': case 'F': case 'D':
   552     case JVM_SIGNATURE_ENDFUNC:
       
   553     case JVM_SIGNATURE_VOID:
       
   554     case JVM_SIGNATURE_INT:
       
   555     case JVM_SIGNATURE_LONG:
       
   556     case JVM_SIGNATURE_FLOAT:
       
   557     case JVM_SIGNATURE_DOUBLE:
   553       continue;
   558       continue;
   554     //case '[':
       
   555     //case 'Z': case 'B': case 'C': case 'S':
       
   556     default:
   559     default:
       
   560       // subword types (T_BYTE etc.), arrays
   557       return false;
   561       return false;
   558     }
   562     }
   559   }
   563   }
   560   return true;
   564   return true;
   561 }
   565 }
   565   if (sig == NULL) {
   569   if (sig == NULL) {
   566     return sig;
   570     return sig;
   567   } else if (is_basic_type_signature(sig)) {
   571   } else if (is_basic_type_signature(sig)) {
   568     sig->increment_refcount();
   572     sig->increment_refcount();
   569     return sig;  // that was easy
   573     return sig;  // that was easy
   570   } else if (sig->char_at(0) != '(') {
   574   } else if (sig->char_at(0) != JVM_SIGNATURE_FUNC) {
   571     BasicType bt = char2type(sig->char_at(0));
   575     BasicType bt = char2type(sig->char_at(0));
   572     if (is_subword_type(bt)) {
   576     if (is_subword_type(bt)) {
   573       bsig = vmSymbols::int_signature();
   577       bsig = vmSymbols::int_signature();
   574     } else {
   578     } else {
   575       assert(is_reference_type(bt), "is_basic_type_signature was false");
   579       assert(is_reference_type(bt), "is_basic_type_signature was false");
   576       bsig = vmSymbols::object_signature();
   580       bsig = vmSymbols::object_signature();
   577     }
   581     }
   578   } else {
   582   } else {
   579     ResourceMark rm;
   583     ResourceMark rm;
   580     stringStream buffer(128);
   584     stringStream buffer(128);
   581     buffer.put('(');
   585     buffer.put(JVM_SIGNATURE_FUNC);
   582     int arg_pos = 0, keep_arg_pos = -1;
   586     int arg_pos = 0, keep_arg_pos = -1;
   583     if (keep_last_arg)
   587     if (keep_last_arg)
   584       keep_arg_pos = ArgumentCount(sig).size() - 1;
   588       keep_arg_pos = ArgumentCount(sig).size() - 1;
   585     for (SignatureStream ss(sig); !ss.is_done(); ss.next()) {
   589     for (SignatureStream ss(sig); !ss.is_done(); ss.next()) {
   586       BasicType bt = ss.type();
   590       BasicType bt = ss.type();
   587       size_t this_arg_pos = buffer.size();
   591       size_t this_arg_pos = buffer.size();
   588       if (ss.at_return_type()) {
   592       if (ss.at_return_type()) {
   589         buffer.put(')');
   593         buffer.put(JVM_SIGNATURE_ENDFUNC);
   590       }
   594       }
   591       if (arg_pos == keep_arg_pos) {
   595       if (arg_pos == keep_arg_pos) {
   592         buffer.write((char*) ss.raw_bytes(),
   596         buffer.write((char*) ss.raw_bytes(),
   593                      (int)   ss.raw_length());
   597                      (int)   ss.raw_length());
   594       } else if (is_reference_type(bt)) {
   598       } else if (is_reference_type(bt)) {
   619   int array = 0;
   623   int array = 0;
   620   bool prev_type = false;
   624   bool prev_type = false;
   621   for (int i = 0; i < len; i++) {
   625   for (int i = 0; i < len; i++) {
   622     char ch = sig->char_at(i);
   626     char ch = sig->char_at(i);
   623     switch (ch) {
   627     switch (ch) {
   624     case '(': case ')':
   628     case JVM_SIGNATURE_FUNC:
       
   629     case JVM_SIGNATURE_ENDFUNC:
   625       prev_type = false;
   630       prev_type = false;
   626       st->put(ch);
   631       st->put(ch);
   627       continue;
   632       continue;
   628     case '[':
   633     case JVM_SIGNATURE_ARRAY:
   629       if (!keep_basic_names && keep_arrays)
   634       if (!keep_basic_names && keep_arrays)
   630         st->put(ch);
   635         st->put(ch);
   631       array++;
   636       array++;
   632       continue;
   637       continue;
   633     case 'L':
   638     case JVM_SIGNATURE_CLASS:
   634       {
   639       {
   635         if (prev_type)  st->put(',');
   640         if (prev_type)  st->put(',');
   636         int start = i+1, slash = start;
   641         int start = i+1, slash = start;
   637         while (++i < len && (ch = sig->char_at(i)) != ';') {
   642         while (++i < len && (ch = sig->char_at(i)) != JVM_SIGNATURE_ENDCLASS) {
   638           if (ch == '/' || ch == '.' || ch == '$')  slash = i+1;
   643           if (ch == JVM_SIGNATURE_SLASH || ch == JVM_SIGNATURE_DOT || ch == '$')  slash = i+1;
   639         }
   644         }
   640         if (slash < i)  start = slash;
   645         if (slash < i)  start = slash;
   641         if (!keep_basic_names) {
   646         if (!keep_basic_names) {
   642           st->put('L');
   647           st->put(JVM_SIGNATURE_CLASS);
   643         } else {
   648         } else {
   644           for (int j = start; j < i; j++)
   649           for (int j = start; j < i; j++)
   645             st->put(sig->char_at(j));
   650             st->put(sig->char_at(j));
   646           prev_type = true;
   651           prev_type = true;
   647         }
   652         }
   648         break;
   653         break;
   649       }
   654       }
   650     default:
   655     default:
   651       {
   656       {
   652         if (array && char2type(ch) != T_ILLEGAL && !keep_arrays) {
   657         if (array && char2type(ch) != T_ILLEGAL && !keep_arrays) {
   653           ch = '[';
   658           ch = JVM_SIGNATURE_ARRAY;
   654           array = 0;
   659           array = 0;
   655         }
   660         }
   656         if (prev_type)  st->put(',');
   661         if (prev_type)  st->put(',');
   657         const char* n = NULL;
   662         const char* n = NULL;
   658         if (keep_basic_names)
   663         if (keep_basic_names)
   976   if (name != NULL) {
   981   if (name != NULL) {
   977     if (name->utf8_length() == 0)  return 0; // a match is not possible
   982     if (name->utf8_length() == 0)  return 0; // a match is not possible
   978   }
   983   }
   979   if (sig != NULL) {
   984   if (sig != NULL) {
   980     if (sig->utf8_length() == 0)  return 0; // a match is not possible
   985     if (sig->utf8_length() == 0)  return 0; // a match is not possible
   981     if (sig->char_at(0) == '(')
   986     if (sig->char_at(0) == JVM_SIGNATURE_FUNC)
   982       match_flags &= ~(IS_FIELD | IS_TYPE);
   987       match_flags &= ~(IS_FIELD | IS_TYPE);
   983     else
   988     else
   984       match_flags &= ~(IS_CONSTRUCTOR | IS_METHOD);
   989       match_flags &= ~(IS_CONSTRUCTOR | IS_METHOD);
   985   }
   990   }
   986 
   991 
  1454           }
  1459           }
  1455         case -2:  // type
  1460         case -2:  // type
  1456           {
  1461           {
  1457             Symbol* type = caller->constants()->signature_ref_at(bss_index_in_pool);
  1462             Symbol* type = caller->constants()->signature_ref_at(bss_index_in_pool);
  1458             Handle th;
  1463             Handle th;
  1459             if (type->char_at(0) == '(') {
  1464             if (type->char_at(0) == JVM_SIGNATURE_FUNC) {
  1460               th = SystemDictionary::find_method_handle_type(type, caller, CHECK);
  1465               th = SystemDictionary::find_method_handle_type(type, caller, CHECK);
  1461             } else {
  1466             } else {
  1462               th = SystemDictionary::find_java_mirror_for_type(type, caller, SignatureStream::NCDFError, CHECK);
  1467               th = SystemDictionary::find_java_mirror_for_type(type, caller, SignatureStream::NCDFError, CHECK);
  1463             }
  1468             }
  1464             pseudo_arg = th();
  1469             pseudo_arg = th();