src/share/vm/classfile/classFileParser.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File bug_8058575.hs Sdiff src/share/vm/classfile

src/share/vm/classfile/classFileParser.cpp

Print this page




5385           const char * to = k->external_name();
5386           log_debug(class, resolve)("%s %s (interface)", from, to);
5387         }
5388       }
5389     }
5390   }
5391 
5392   TRACE_INIT_KLASS_ID(ik);
5393 
5394   // If we reach here, all is well.
5395   // Now remove the InstanceKlass* from the _klass_to_deallocate field
5396   // in order for it to not be destroyed in the ClassFileParser destructor.
5397   set_klass_to_deallocate(NULL);
5398 
5399   // it's official
5400   set_klass(ik);
5401 
5402   debug_only(ik->verify();)
5403 }
5404 





























































5405 ClassFileParser::ClassFileParser(ClassFileStream* stream,
5406                                  Symbol* name,
5407                                  ClassLoaderData* loader_data,
5408                                  Handle protection_domain,
5409                                  const Klass* host_klass,
5410                                  GrowableArray<Handle>* cp_patches,
5411                                  Publicity pub_level,
5412                                  TRAPS) :
5413   _stream(stream),
5414   _requested_name(name),
5415   _loader_data(loader_data),
5416   _host_klass(host_klass),
5417   _cp_patches(cp_patches),
5418   _super_klass(),
5419   _cp(NULL),
5420   _fields(NULL),
5421   _methods(NULL),
5422   _inner_classes(NULL),
5423   _local_interfaces(NULL),
5424   _transitive_interfaces(NULL),


5662   // Don't need to check whether this class name is legal or not.
5663   // It has been checked when constant pool is parsed.
5664   // However, make sure it is not an array type.
5665   if (_need_verify) {
5666     guarantee_property(_class_name->byte_at(0) != JVM_SIGNATURE_ARRAY,
5667                        "Bad class name in class file %s",
5668                        CHECK);
5669   }
5670 
5671   // Checks if name in class file matches requested name
5672   if (_requested_name != NULL && _requested_name != _class_name) {
5673     ResourceMark rm(THREAD);
5674     Exceptions::fthrow(
5675       THREAD_AND_LOCATION,
5676       vmSymbols::java_lang_NoClassDefFoundError(),
5677       "%s (wrong name: %s)",
5678       _class_name->as_C_string(),
5679       _requested_name != NULL ? _requested_name->as_C_string() : "NoName"
5680     );
5681     return;







5682   }
5683 
5684   // Verification prevents us from creating names with dots in them, this
5685   // asserts that that's the case.
5686   assert(is_internal_format(_class_name), "external class name format used internally");
5687 
5688   if (!is_internal()) {
5689     if (log_is_enabled(Debug, class, preorder)){
5690       ResourceMark rm(THREAD);
5691       outputStream* log = Log(class, preorder)::debug_stream();
5692       log->print("%s", _class_name->as_klass_external_name());
5693       if (stream->source() != NULL) {
5694         log->print(" source: %s", stream->source());
5695       }
5696       log->cr();
5697     }
5698 
5699 #if INCLUDE_CDS
5700     if (DumpLoadedClassList != NULL && stream->source() != NULL && classlist_file->is_open()) {
5701       // Only dump the classes that can be stored into CDS archive.




5385           const char * to = k->external_name();
5386           log_debug(class, resolve)("%s %s (interface)", from, to);
5387         }
5388       }
5389     }
5390   }
5391 
5392   TRACE_INIT_KLASS_ID(ik);
5393 
5394   // If we reach here, all is well.
5395   // Now remove the InstanceKlass* from the _klass_to_deallocate field
5396   // in order for it to not be destroyed in the ClassFileParser destructor.
5397   set_klass_to_deallocate(NULL);
5398 
5399   // it's official
5400   set_klass(ik);
5401 
5402   debug_only(ik->verify();)
5403 }
5404 
5405 // For an anonymous class that is in the null package, move it to its host class's
5406 // package by prepending its host class's package name to its class name and setting
5407 // its _class_name field.
5408 void ClassFileParser::prepend_host_package_name(const Klass* host_klass, TRAPS) {
5409   ResourceMark rm(THREAD);
5410   assert(strrchr(_class_name->as_C_string(), '/') == NULL,
5411          "Anonymous class should not be in a package");
5412   int host_pkg_len = 0;
5413   const char* host_pkg_name =
5414     (const char*)InstanceKlass::package_from_name(host_klass->name(), CHECK);
5415   if (host_pkg_name != NULL) {
5416     char* new_anon_name =
5417       NEW_RESOURCE_ARRAY(char, host_pkg_len + 1 + _class_name->utf8_length());
5418     // Copy host package name and trailing /.
5419     strncpy(new_anon_name, host_pkg_name, host_pkg_len);
5420     new_anon_name[host_pkg_len] = '/';
5421     // Append anonymous class name. The anonymous class name can contain odd
5422     // characters.  So, do a strncpy instead of using sprintf("%s...").
5423     strncpy(new_anon_name + host_pkg_len + 1, (char *)_class_name->base(),
5424             _class_name->utf8_length());
5425 
5426     // Create a symbol and update the anonymous class name.
5427     _class_name = SymbolTable::lookup(new_anon_name,
5428                                       host_pkg_len + 1 + _class_name->utf8_length(),
5429                                       CHECK);
5430   }
5431 }
5432 
5433 // If the host class and the anonymous class are in the same package then do
5434 // nothing.  If the anonymous class is in the null package then move it to its
5435 // host's package.  If the classes are in different packages then throw an IAE
5436 // exception.  
5437 void ClassFileParser::fix_anonymous_class_name(TRAPS) {
5438   assert(_host_klass != NULL, "Expected an anonymous class");
5439   const jbyte* anon_last_slash = UTF8::strrchr(_class_name->base(),
5440                                                _class_name->utf8_length(), '/');
5441   const Klass* host_klass;
5442   if (_host_klass->is_objArray_klass()) {
5443     host_klass = ObjArrayKlass::cast(_host_klass)->element_klass();
5444   } else {
5445     host_klass = _host_klass;
5446   }
5447   assert(host_klass->is_instance_klass(), "host klass is not an instance class");
5448 
5449   if (anon_last_slash == NULL) {  // Unnamed package
5450     prepend_host_package_name(host_klass, CHECK);
5451 
5452   } else {
5453     if (!InstanceKlass::is_same_class_package(host_klass->class_loader(),
5454                                               host_klass->name(),
5455                                               host_klass->class_loader(),
5456                                               _class_name)) {
5457       ResourceMark rm(THREAD);
5458       THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
5459         err_msg("Host class %s and anonymous class %s are in different packages",
5460         _host_klass->name()->as_C_string(), _class_name->as_C_string()));
5461     }
5462   }
5463 }
5464 
5465 
5466 ClassFileParser::ClassFileParser(ClassFileStream* stream,
5467                                  Symbol* name,
5468                                  ClassLoaderData* loader_data,
5469                                  Handle protection_domain,
5470                                  const Klass* host_klass,
5471                                  GrowableArray<Handle>* cp_patches,
5472                                  Publicity pub_level,
5473                                  TRAPS) :
5474   _stream(stream),
5475   _requested_name(name),
5476   _loader_data(loader_data),
5477   _host_klass(host_klass),
5478   _cp_patches(cp_patches),
5479   _super_klass(),
5480   _cp(NULL),
5481   _fields(NULL),
5482   _methods(NULL),
5483   _inner_classes(NULL),
5484   _local_interfaces(NULL),
5485   _transitive_interfaces(NULL),


5723   // Don't need to check whether this class name is legal or not.
5724   // It has been checked when constant pool is parsed.
5725   // However, make sure it is not an array type.
5726   if (_need_verify) {
5727     guarantee_property(_class_name->byte_at(0) != JVM_SIGNATURE_ARRAY,
5728                        "Bad class name in class file %s",
5729                        CHECK);
5730   }
5731 
5732   // Checks if name in class file matches requested name
5733   if (_requested_name != NULL && _requested_name != _class_name) {
5734     ResourceMark rm(THREAD);
5735     Exceptions::fthrow(
5736       THREAD_AND_LOCATION,
5737       vmSymbols::java_lang_NoClassDefFoundError(),
5738       "%s (wrong name: %s)",
5739       _class_name->as_C_string(),
5740       _requested_name != NULL ? _requested_name->as_C_string() : "NoName"
5741     );
5742     return;
5743   }
5744 
5745   // if this is an anonymous class fix up its name if it's in the unnamed
5746   // package.  Otherwise, throw IAE if it is in a different package than
5747   // its host class.
5748   if (_host_klass != NULL) {
5749     fix_anonymous_class_name(CHECK);
5750   }
5751 
5752   // Verification prevents us from creating names with dots in them, this
5753   // asserts that that's the case.
5754   assert(is_internal_format(_class_name), "external class name format used internally");
5755 
5756   if (!is_internal()) {
5757     if (log_is_enabled(Debug, class, preorder)){
5758       ResourceMark rm(THREAD);
5759       outputStream* log = Log(class, preorder)::debug_stream();
5760       log->print("%s", _class_name->as_klass_external_name());
5761       if (stream->source() != NULL) {
5762         log->print(" source: %s", stream->source());
5763       }
5764       log->cr();
5765     }
5766 
5767 #if INCLUDE_CDS
5768     if (DumpLoadedClassList != NULL && stream->source() != NULL && classlist_file->is_open()) {
5769       // Only dump the classes that can be stored into CDS archive.


src/share/vm/classfile/classFileParser.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File