src/hotspot/share/classfile/classFileParser.cpp
changeset 51997 9ce37fa2e179
parent 51444 3e5d28e6de32
child 52431 b0af758a092c
equal deleted inserted replaced
51996:84743156e780 51997:9ce37fa2e179
   653             sig_index, CHECK);
   653             sig_index, CHECK);
   654           guarantee_property(name->utf8_length() != 0,
   654           guarantee_property(name->utf8_length() != 0,
   655             "Illegal zero length constant pool entry at %d in class %s",
   655             "Illegal zero length constant pool entry at %d in class %s",
   656             name_index, CHECK);
   656             name_index, CHECK);
   657 
   657 
   658           if (sig->byte_at(0) == JVM_SIGNATURE_FUNC) {
   658           if (sig->char_at(0) == JVM_SIGNATURE_FUNC) {
   659             // Format check method name and signature
   659             // Format check method name and signature
   660             verify_legal_method_name(name, CHECK);
   660             verify_legal_method_name(name, CHECK);
   661             verify_legal_method_signature(name, sig, CHECK);
   661             verify_legal_method_signature(name, sig, CHECK);
   662           } else {
   662           } else {
   663             // Format check field name and signature
   663             // Format check field name and signature
   680         const Symbol* const signature = cp->symbol_at(signature_ref_index);
   680         const Symbol* const signature = cp->symbol_at(signature_ref_index);
   681         if (_need_verify) {
   681         if (_need_verify) {
   682           // CONSTANT_Dynamic's name and signature are verified above, when iterating NameAndType_info.
   682           // CONSTANT_Dynamic's name and signature are verified above, when iterating NameAndType_info.
   683           // Need only to be sure signature is non-zero length and the right type.
   683           // Need only to be sure signature is non-zero length and the right type.
   684           if (signature->utf8_length() == 0 ||
   684           if (signature->utf8_length() == 0 ||
   685               signature->byte_at(0) == JVM_SIGNATURE_FUNC) {
   685               signature->char_at(0) == JVM_SIGNATURE_FUNC) {
   686             throwIllegalSignature("CONSTANT_Dynamic", name, signature, CHECK);
   686             throwIllegalSignature("CONSTANT_Dynamic", name, signature, CHECK);
   687           }
   687           }
   688         }
   688         }
   689         break;
   689         break;
   690       }
   690       }
   705         if (tag == JVM_CONSTANT_Fieldref) {
   705         if (tag == JVM_CONSTANT_Fieldref) {
   706           if (_need_verify) {
   706           if (_need_verify) {
   707             // Field name and signature are verified above, when iterating NameAndType_info.
   707             // Field name and signature are verified above, when iterating NameAndType_info.
   708             // Need only to be sure signature is non-zero length and the right type.
   708             // Need only to be sure signature is non-zero length and the right type.
   709             if (signature->utf8_length() == 0 ||
   709             if (signature->utf8_length() == 0 ||
   710                 signature->byte_at(0) == JVM_SIGNATURE_FUNC) {
   710                 signature->char_at(0) == JVM_SIGNATURE_FUNC) {
   711               throwIllegalSignature("Field", name, signature, CHECK);
   711               throwIllegalSignature("Field", name, signature, CHECK);
   712             }
   712             }
   713           }
   713           }
   714         } else {
   714         } else {
   715           if (_need_verify) {
   715           if (_need_verify) {
   716             // Method name and signature are verified above, when iterating NameAndType_info.
   716             // Method name and signature are verified above, when iterating NameAndType_info.
   717             // Need only to be sure signature is non-zero length and the right type.
   717             // Need only to be sure signature is non-zero length and the right type.
   718             if (signature->utf8_length() == 0 ||
   718             if (signature->utf8_length() == 0 ||
   719                 signature->byte_at(0) != JVM_SIGNATURE_FUNC) {
   719                 signature->char_at(0) != JVM_SIGNATURE_FUNC) {
   720               throwIllegalSignature("Method", name, signature, CHECK);
   720               throwIllegalSignature("Method", name, signature, CHECK);
   721             }
   721             }
   722           }
   722           }
   723           // 4509014: If a class method name begins with '<', it must be "<init>"
   723           // 4509014: If a class method name begins with '<', it must be "<init>"
   724           const unsigned int name_len = name->utf8_length();
   724           const unsigned int name_len = name->utf8_length();
   725           if (tag == JVM_CONSTANT_Methodref &&
   725           if (tag == JVM_CONSTANT_Methodref &&
   726               name_len != 0 &&
   726               name_len != 0 &&
   727               name->byte_at(0) == '<' &&
   727               name->char_at(0) == '<' &&
   728               name != vmSymbols::object_initializer_name()) {
   728               name != vmSymbols::object_initializer_name()) {
   729             classfile_parse_error(
   729             classfile_parse_error(
   730               "Bad method name at constant pool index %u in class file %s",
   730               "Bad method name at constant pool index %u in class file %s",
   731               name_ref_index, CHECK);
   731               name_ref_index, CHECK);
   732           }
   732           }
   940       } else {
   940       } else {
   941         Symbol* const unresolved_klass  = cp->klass_name_at(interface_index);
   941         Symbol* const unresolved_klass  = cp->klass_name_at(interface_index);
   942 
   942 
   943         // Don't need to check legal name because it's checked when parsing constant pool.
   943         // Don't need to check legal name because it's checked when parsing constant pool.
   944         // But need to make sure it's not an array type.
   944         // But need to make sure it's not an array type.
   945         guarantee_property(unresolved_klass->byte_at(0) != JVM_SIGNATURE_ARRAY,
   945         guarantee_property(unresolved_klass->char_at(0) != JVM_SIGNATURE_ARRAY,
   946                            "Bad interface name in class file %s", CHECK);
   946                            "Bad interface name in class file %s", CHECK);
   947 
   947 
   948         // Call resolve_super so classcircularity is checked
   948         // Call resolve_super so classcircularity is checked
   949         interf = SystemDictionary::resolve_super_or_fail(
   949         interf = SystemDictionary::resolve_super_or_fail(
   950                                                   _class_name,
   950                                                   _class_name,
  3750     if (cp->tag_at(super_class_index).is_klass()) {
  3750     if (cp->tag_at(super_class_index).is_klass()) {
  3751       super_klass = InstanceKlass::cast(cp->resolved_klass_at(super_class_index));
  3751       super_klass = InstanceKlass::cast(cp->resolved_klass_at(super_class_index));
  3752       if (need_verify)
  3752       if (need_verify)
  3753         is_array = super_klass->is_array_klass();
  3753         is_array = super_klass->is_array_klass();
  3754     } else if (need_verify) {
  3754     } else if (need_verify) {
  3755       is_array = (cp->klass_name_at(super_class_index)->byte_at(0) == JVM_SIGNATURE_ARRAY);
  3755       is_array = (cp->klass_name_at(super_class_index)->char_at(0) == JVM_SIGNATURE_ARRAY);
  3756     }
  3756     }
  3757     if (need_verify) {
  3757     if (need_verify) {
  3758       guarantee_property(!is_array,
  3758       guarantee_property(!is_array,
  3759                         "Bad superclass name in class file %s", CHECK_NULL);
  3759                         "Bad superclass name in class file %s", CHECK_NULL);
  3760     }
  3760     }
  5377       nextp = skip_over_field_signature(p, false, length, CHECK_0);
  5377       nextp = skip_over_field_signature(p, false, length, CHECK_0);
  5378     }
  5378     }
  5379     // The first non-signature thing better be a ')'
  5379     // The first non-signature thing better be a ')'
  5380     if ((length > 0) && (*p++ == JVM_SIGNATURE_ENDFUNC)) {
  5380     if ((length > 0) && (*p++ == JVM_SIGNATURE_ENDFUNC)) {
  5381       length--;
  5381       length--;
  5382       if (name->utf8_length() > 0 && name->byte_at(0) == '<') {
  5382       if (name->utf8_length() > 0 && name->char_at(0) == '<') {
  5383         // All internal methods must return void
  5383         // All internal methods must return void
  5384         if ((length == 1) && (p[0] == JVM_SIGNATURE_VOID)) {
  5384         if ((length == 1) && (p[0] == JVM_SIGNATURE_VOID)) {
  5385           return args_size;
  5385           return args_size;
  5386         }
  5386         }
  5387       } else {
  5387       } else {
  5794 // host's package.  If the classes are in different packages then throw an IAE
  5794 // host's package.  If the classes are in different packages then throw an IAE
  5795 // exception.
  5795 // exception.
  5796 void ClassFileParser::fix_unsafe_anonymous_class_name(TRAPS) {
  5796 void ClassFileParser::fix_unsafe_anonymous_class_name(TRAPS) {
  5797   assert(_unsafe_anonymous_host != NULL, "Expected an unsafe anonymous class");
  5797   assert(_unsafe_anonymous_host != NULL, "Expected an unsafe anonymous class");
  5798 
  5798 
  5799   const jbyte* anon_last_slash = UTF8::strrchr(_class_name->base(),
  5799   const jbyte* anon_last_slash = UTF8::strrchr((const jbyte*)_class_name->base(),
  5800                                                _class_name->utf8_length(), '/');
  5800                                                _class_name->utf8_length(), '/');
  5801   if (anon_last_slash == NULL) {  // Unnamed package
  5801   if (anon_last_slash == NULL) {  // Unnamed package
  5802     prepend_host_package_name(_unsafe_anonymous_host, CHECK);
  5802     prepend_host_package_name(_unsafe_anonymous_host, CHECK);
  5803   } else {
  5803   } else {
  5804     if (!_unsafe_anonymous_host->is_same_class_package(_unsafe_anonymous_host->class_loader(), _class_name)) {
  5804     if (!_unsafe_anonymous_host->is_same_class_package(_unsafe_anonymous_host->class_loader(), _class_name)) {
  6117 
  6117 
  6118   // Don't need to check whether this class name is legal or not.
  6118   // Don't need to check whether this class name is legal or not.
  6119   // It has been checked when constant pool is parsed.
  6119   // It has been checked when constant pool is parsed.
  6120   // However, make sure it is not an array type.
  6120   // However, make sure it is not an array type.
  6121   if (_need_verify) {
  6121   if (_need_verify) {
  6122     guarantee_property(_class_name->byte_at(0) != JVM_SIGNATURE_ARRAY,
  6122     guarantee_property(_class_name->char_at(0) != JVM_SIGNATURE_ARRAY,
  6123                        "Bad class name in class file %s",
  6123                        "Bad class name in class file %s",
  6124                        CHECK);
  6124                        CHECK);
  6125   }
  6125   }
  6126 
  6126 
  6127   // Checks if name in class file matches requested name
  6127   // Checks if name in class file matches requested name