hotspot/src/share/vm/classfile/classFileParser.cpp
changeset 40923 10fe1c28b9f6
parent 40921 cc129ac8e609
child 41669 2091069b6851
child 41544 d77997d3a28b
equal deleted inserted replaced
40922:d9f1eaf18f9a 40923:10fe1c28b9f6
  5405   set_klass(ik);
  5405   set_klass(ik);
  5406 
  5406 
  5407   debug_only(ik->verify();)
  5407   debug_only(ik->verify();)
  5408 }
  5408 }
  5409 
  5409 
       
  5410 // For an anonymous class that is in the unnamed package, move it to its host class's
       
  5411 // package by prepending its host class's package name to its class name and setting
       
  5412 // its _class_name field.
       
  5413 void ClassFileParser::prepend_host_package_name(const InstanceKlass* host_klass, TRAPS) {
       
  5414   ResourceMark rm(THREAD);
       
  5415   assert(strrchr(_class_name->as_C_string(), '/') == NULL,
       
  5416          "Anonymous class should not be in a package");
       
  5417   const char* host_pkg_name =
       
  5418     ClassLoader::package_from_name(host_klass->name()->as_C_string(), NULL);
       
  5419 
       
  5420   if (host_pkg_name != NULL) {
       
  5421     size_t host_pkg_len = strlen(host_pkg_name);
       
  5422     int class_name_len = _class_name->utf8_length();
       
  5423     char* new_anon_name =
       
  5424       NEW_RESOURCE_ARRAY(char, host_pkg_len + 1 + class_name_len);
       
  5425     // Copy host package name and trailing /.
       
  5426     strncpy(new_anon_name, host_pkg_name, host_pkg_len);
       
  5427     new_anon_name[host_pkg_len] = '/';
       
  5428     // Append anonymous class name. The anonymous class name can contain odd
       
  5429     // characters.  So, do a strncpy instead of using sprintf("%s...").
       
  5430     strncpy(new_anon_name + host_pkg_len + 1, (char *)_class_name->base(), class_name_len);
       
  5431 
       
  5432     // Create a symbol and update the anonymous class name.
       
  5433     _class_name = SymbolTable::new_symbol(new_anon_name,
       
  5434                                           (int)host_pkg_len + 1 + class_name_len,
       
  5435                                           CHECK);
       
  5436   }
       
  5437 }
       
  5438 
       
  5439 // If the host class and the anonymous class are in the same package then do
       
  5440 // nothing.  If the anonymous class is in the unnamed package then move it to its
       
  5441 // host's package.  If the classes are in different packages then throw an IAE
       
  5442 // exception.
       
  5443 void ClassFileParser::fix_anonymous_class_name(TRAPS) {
       
  5444   assert(_host_klass != NULL, "Expected an anonymous class");
       
  5445 
       
  5446   const jbyte* anon_last_slash = UTF8::strrchr(_class_name->base(),
       
  5447                                                _class_name->utf8_length(), '/');
       
  5448   if (anon_last_slash == NULL) {  // Unnamed package
       
  5449     prepend_host_package_name(_host_klass, CHECK);
       
  5450   } else {
       
  5451     if (!InstanceKlass::is_same_class_package(_host_klass->class_loader(),
       
  5452                                               _host_klass->name(),
       
  5453                                               _host_klass->class_loader(),
       
  5454                                               _class_name)) {
       
  5455       ResourceMark rm(THREAD);
       
  5456       THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
       
  5457         err_msg("Host class %s and anonymous class %s are in different packages",
       
  5458         _host_klass->name()->as_C_string(), _class_name->as_C_string()));
       
  5459     }
       
  5460   }
       
  5461 }
       
  5462 
  5410 static bool relax_format_check_for(ClassLoaderData* loader_data) {
  5463 static bool relax_format_check_for(ClassLoaderData* loader_data) {
  5411   bool trusted = (loader_data->is_the_null_class_loader_data() ||
  5464   bool trusted = (loader_data->is_the_null_class_loader_data() ||
  5412                   SystemDictionary::is_platform_class_loader(loader_data->class_loader()));
  5465                   SystemDictionary::is_platform_class_loader(loader_data->class_loader()));
  5413   bool need_verify =
  5466   bool need_verify =
  5414     // verifyAll
  5467     // verifyAll
  5420 
  5473 
  5421 ClassFileParser::ClassFileParser(ClassFileStream* stream,
  5474 ClassFileParser::ClassFileParser(ClassFileStream* stream,
  5422                                  Symbol* name,
  5475                                  Symbol* name,
  5423                                  ClassLoaderData* loader_data,
  5476                                  ClassLoaderData* loader_data,
  5424                                  Handle protection_domain,
  5477                                  Handle protection_domain,
  5425                                  const Klass* host_klass,
  5478                                  const InstanceKlass* host_klass,
  5426                                  GrowableArray<Handle>* cp_patches,
  5479                                  GrowableArray<Handle>* cp_patches,
  5427                                  Publicity pub_level,
  5480                                  Publicity pub_level,
  5428                                  TRAPS) :
  5481                                  TRAPS) :
  5429   _stream(stream),
  5482   _stream(stream),
  5430   _requested_name(name),
  5483   _requested_name(name),
  5695       _requested_name != NULL ? _requested_name->as_C_string() : "NoName"
  5748       _requested_name != NULL ? _requested_name->as_C_string() : "NoName"
  5696     );
  5749     );
  5697     return;
  5750     return;
  5698   }
  5751   }
  5699 
  5752 
       
  5753   // if this is an anonymous class fix up its name if it's in the unnamed
       
  5754   // package.  Otherwise, throw IAE if it is in a different package than
       
  5755   // its host class.
       
  5756   if (_host_klass != NULL) {
       
  5757     fix_anonymous_class_name(CHECK);
       
  5758   }
       
  5759 
  5700   // Verification prevents us from creating names with dots in them, this
  5760   // Verification prevents us from creating names with dots in them, this
  5701   // asserts that that's the case.
  5761   // asserts that that's the case.
  5702   assert(is_internal_format(_class_name), "external class name format used internally");
  5762   assert(is_internal_format(_class_name), "external class name format used internally");
  5703 
  5763 
  5704   if (!is_internal()) {
  5764   if (!is_internal()) {