src/share/vm/classfile/classFileParser.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File bug_8058575.hs.3 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 static bool relax_format_check_for(ClassLoaderData* loader_data) {
5406   bool trusted = (loader_data->is_the_null_class_loader_data() ||
5407                   SystemDictionary::is_platform_class_loader(loader_data->class_loader()));
5408   bool need_verify =
5409     // verifyAll
5410     (BytecodeVerificationLocal && BytecodeVerificationRemote) ||
5411     // verifyRemote
5412     (!BytecodeVerificationLocal && BytecodeVerificationRemote && !trusted);
5413   return !need_verify;
5414 }
5415 
5416 ClassFileParser::ClassFileParser(ClassFileStream* stream,
5417                                  Symbol* name,
5418                                  ClassLoaderData* loader_data,
5419                                  Handle protection_domain,
5420                                  const Klass* host_klass,
5421                                  GrowableArray<Handle>* cp_patches,
5422                                  Publicity pub_level,
5423                                  TRAPS) :
5424   _stream(stream),
5425   _requested_name(name),
5426   _loader_data(loader_data),
5427   _host_klass(host_klass),
5428   _cp_patches(cp_patches),
5429   _super_klass(),
5430   _cp(NULL),
5431   _fields(NULL),
5432   _methods(NULL),
5433   _inner_classes(NULL),
5434   _local_interfaces(NULL),
5435   _transitive_interfaces(NULL),
5436   _combined_annotations(NULL),
5437   _annotations(NULL),
5438   _type_annotations(NULL),
5439   _fields_annotations(NULL),
5440   _fields_type_annotations(NULL),


5673   // Don't need to check whether this class name is legal or not.
5674   // It has been checked when constant pool is parsed.
5675   // However, make sure it is not an array type.
5676   if (_need_verify) {
5677     guarantee_property(_class_name->byte_at(0) != JVM_SIGNATURE_ARRAY,
5678                        "Bad class name in class file %s",
5679                        CHECK);
5680   }
5681 
5682   // Checks if name in class file matches requested name
5683   if (_requested_name != NULL && _requested_name != _class_name) {
5684     ResourceMark rm(THREAD);
5685     Exceptions::fthrow(
5686       THREAD_AND_LOCATION,
5687       vmSymbols::java_lang_NoClassDefFoundError(),
5688       "%s (wrong name: %s)",
5689       _class_name->as_C_string(),
5690       _requested_name != NULL ? _requested_name->as_C_string() : "NoName"
5691     );
5692     return;







5693   }
5694 
5695   // Verification prevents us from creating names with dots in them, this
5696   // asserts that that's the case.
5697   assert(is_internal_format(_class_name), "external class name format used internally");
5698 
5699   if (!is_internal()) {
5700     if (log_is_enabled(Debug, class, preorder)){
5701       ResourceMark rm(THREAD);
5702       outputStream* log = Log(class, preorder)::debug_stream();
5703       log->print("%s", _class_name->as_klass_external_name());
5704       if (stream->source() != NULL) {
5705         log->print(" source: %s", stream->source());
5706       }
5707       log->cr();
5708     }
5709 
5710 #if INCLUDE_CDS
5711     if (DumpLoadedClassList != NULL && stream->source() != NULL && classlist_file->is_open()) {
5712       // 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 unnamed 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 InstanceKlass* 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   const char* host_pkg_name =
5413     ClassLoader::package_from_name(host_klass->name()->as_C_string(), NULL);
5414 
5415   if (host_pkg_name != NULL) {
5416     size_t host_pkg_len = strlen(host_pkg_name);
5417     int class_name_len = _class_name->utf8_length();
5418     char* new_anon_name =
5419       NEW_RESOURCE_ARRAY(char, host_pkg_len + 1 + class_name_len);
5420     // Copy host package name and trailing /.
5421     strncpy(new_anon_name, host_pkg_name, host_pkg_len);
5422     new_anon_name[host_pkg_len] = '/';
5423     // Append anonymous class name. The anonymous class name can contain odd
5424     // characters.  So, do a strncpy instead of using sprintf("%s...").
5425     strncpy(new_anon_name + host_pkg_len + 1, (char *)_class_name->base(), class_name_len);
5426 
5427     // Create a symbol and update the anonymous class name.
5428     _class_name = SymbolTable::lookup(new_anon_name,
5429                                       (int)host_pkg_len + 1 + class_name_len,
5430                                       CHECK);
5431   }
5432 }
5433 
5434 // If the host class and the anonymous class are in the same package then do
5435 // nothing.  If the anonymous class is in the unnamed package then move it to its
5436 // host's package.  If the classes are in different packages then throw an IAE
5437 // exception.
5438 void ClassFileParser::fix_anonymous_class_name(TRAPS) {
5439   assert(_host_klass != NULL, "Expected an anonymous class");
5440 
5441   const jbyte* anon_last_slash = UTF8::strrchr(_class_name->base(),
5442                                                _class_name->utf8_length(), '/');
5443   if (anon_last_slash == NULL) {  // Unnamed package
5444     prepend_host_package_name(_host_klass, CHECK);
5445   } else {
5446     if (!InstanceKlass::is_same_class_package(_host_klass->class_loader(),
5447                                               _host_klass->name(),
5448                                               _host_klass->class_loader(),
5449                                               _class_name)) {
5450       ResourceMark rm(THREAD);
5451       THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
5452         err_msg("Host class %s and anonymous class %s are in different packages",
5453         _host_klass->name()->as_C_string(), _class_name->as_C_string()));
5454     }
5455   }
5456 }
5457 
5458 static bool relax_format_check_for(ClassLoaderData* loader_data) {
5459   bool trusted = (loader_data->is_the_null_class_loader_data() ||
5460                   SystemDictionary::is_platform_class_loader(loader_data->class_loader()));
5461   bool need_verify =
5462     // verifyAll
5463     (BytecodeVerificationLocal && BytecodeVerificationRemote) ||
5464     // verifyRemote
5465     (!BytecodeVerificationLocal && BytecodeVerificationRemote && !trusted);
5466   return !need_verify;
5467 }
5468 
5469 ClassFileParser::ClassFileParser(ClassFileStream* stream,
5470                                  Symbol* name,
5471                                  ClassLoaderData* loader_data,
5472                                  Handle protection_domain,
5473                                  const InstanceKlass* host_klass,
5474                                  GrowableArray<Handle>* cp_patches,
5475                                  Publicity pub_level,
5476                                  TRAPS) :
5477   _stream(stream),
5478   _requested_name(name),
5479   _loader_data(loader_data),
5480   _host_klass(host_klass),
5481   _cp_patches(cp_patches),
5482   _super_klass(),
5483   _cp(NULL),
5484   _fields(NULL),
5485   _methods(NULL),
5486   _inner_classes(NULL),
5487   _local_interfaces(NULL),
5488   _transitive_interfaces(NULL),
5489   _combined_annotations(NULL),
5490   _annotations(NULL),
5491   _type_annotations(NULL),
5492   _fields_annotations(NULL),
5493   _fields_type_annotations(NULL),


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