hotspot/src/share/vm/classfile/classFileParser.cpp
changeset 41744 851a954c677d
parent 41544 d77997d3a28b
parent 41741 2f5b8bbcb18c
child 42630 ae91fbc4b59f
child 42574 25ff9171b28b
equal deleted inserted replaced
41643:df0e03e3ca0e 41744:851a954c677d
   796 
   796 
   797 // Side-effects: populates the _local_interfaces field
   797 // Side-effects: populates the _local_interfaces field
   798 void ClassFileParser::parse_interfaces(const ClassFileStream* const stream,
   798 void ClassFileParser::parse_interfaces(const ClassFileStream* const stream,
   799                                        const int itfs_len,
   799                                        const int itfs_len,
   800                                        ConstantPool* const cp,
   800                                        ConstantPool* const cp,
   801                                        bool* const has_default_methods,
   801                                        bool* const has_nonstatic_concrete_methods,
   802                                        TRAPS) {
   802                                        TRAPS) {
   803   assert(stream != NULL, "invariant");
   803   assert(stream != NULL, "invariant");
   804   assert(cp != NULL, "invariant");
   804   assert(cp != NULL, "invariant");
   805   assert(has_default_methods != NULL, "invariant");
   805   assert(has_nonstatic_concrete_methods != NULL, "invariant");
   806 
   806 
   807   if (itfs_len == 0) {
   807   if (itfs_len == 0) {
   808     _local_interfaces = Universe::the_empty_klass_array();
   808     _local_interfaces = Universe::the_empty_klass_array();
   809   } else {
   809   } else {
   810     assert(itfs_len > 0, "only called for len>0");
   810     assert(itfs_len > 0, "only called for len>0");
   842       if (!interf()->is_interface()) {
   842       if (!interf()->is_interface()) {
   843         THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(),
   843         THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(),
   844                    "Implementing class");
   844                    "Implementing class");
   845       }
   845       }
   846 
   846 
   847       if (InstanceKlass::cast(interf())->has_default_methods()) {
   847       if (InstanceKlass::cast(interf())->has_nonstatic_concrete_methods()) {
   848         *has_default_methods = true;
   848         *has_nonstatic_concrete_methods = true;
   849       }
   849       }
   850       _local_interfaces->at_put(index, interf());
   850       _local_interfaces->at_put(index, interf());
   851     }
   851     }
   852 
   852 
   853     if (!_need_verify || itfs_len <= 1) {
   853     if (!_need_verify || itfs_len <= 1) {
  2828 // Side-effects: populates the _methods field in the parser
  2828 // Side-effects: populates the _methods field in the parser
  2829 void ClassFileParser::parse_methods(const ClassFileStream* const cfs,
  2829 void ClassFileParser::parse_methods(const ClassFileStream* const cfs,
  2830                                     bool is_interface,
  2830                                     bool is_interface,
  2831                                     AccessFlags* promoted_flags,
  2831                                     AccessFlags* promoted_flags,
  2832                                     bool* has_final_method,
  2832                                     bool* has_final_method,
  2833                                     bool* declares_default_methods,
  2833                                     bool* declares_nonstatic_concrete_methods,
  2834                                     TRAPS) {
  2834                                     TRAPS) {
  2835   assert(cfs != NULL, "invariant");
  2835   assert(cfs != NULL, "invariant");
  2836   assert(promoted_flags != NULL, "invariant");
  2836   assert(promoted_flags != NULL, "invariant");
  2837   assert(has_final_method != NULL, "invariant");
  2837   assert(has_final_method != NULL, "invariant");
  2838   assert(declares_default_methods != NULL, "invariant");
  2838   assert(declares_nonstatic_concrete_methods != NULL, "invariant");
  2839 
  2839 
  2840   assert(NULL == _methods, "invariant");
  2840   assert(NULL == _methods, "invariant");
  2841 
  2841 
  2842   cfs->guarantee_more(2, CHECK);  // length
  2842   cfs->guarantee_more(2, CHECK);  // length
  2843   const u2 length = cfs->get_u2_fast();
  2843   const u2 length = cfs->get_u2_fast();
  2858                                     CHECK);
  2858                                     CHECK);
  2859 
  2859 
  2860       if (method->is_final()) {
  2860       if (method->is_final()) {
  2861         *has_final_method = true;
  2861         *has_final_method = true;
  2862       }
  2862       }
  2863       // declares_default_methods: declares concrete instance methods, any access flags
  2863       // declares_nonstatic_concrete_methods: declares concrete instance methods, any access flags
  2864       // used for interface initialization, and default method inheritance analysis
  2864       // used for interface initialization, and default method inheritance analysis
  2865       if (is_interface && !(*declares_default_methods)
  2865       if (is_interface && !(*declares_nonstatic_concrete_methods)
  2866         && !method->is_abstract() && !method->is_static()) {
  2866         && !method->is_abstract() && !method->is_static()) {
  2867         *declares_default_methods = true;
  2867         *declares_nonstatic_concrete_methods = true;
  2868       }
  2868       }
  2869       _methods->at_put(index, method);
  2869       _methods->at_put(index, method);
  2870     }
  2870     }
  2871 
  2871 
  2872     if (_need_verify && length > 1) {
  2872     if (_need_verify && length > 1) {
  5248     ik->constants()->klass_at_put(_this_class_index, ik); // eagerly resolve
  5248     ik->constants()->klass_at_put(_this_class_index, ik); // eagerly resolve
  5249   }
  5249   }
  5250 
  5250 
  5251   ik->set_minor_version(_minor_version);
  5251   ik->set_minor_version(_minor_version);
  5252   ik->set_major_version(_major_version);
  5252   ik->set_major_version(_major_version);
  5253   ik->set_has_default_methods(_has_default_methods);
  5253   ik->set_has_nonstatic_concrete_methods(_has_nonstatic_concrete_methods);
  5254   ik->set_declares_default_methods(_declares_default_methods);
  5254   ik->set_declares_nonstatic_concrete_methods(_declares_nonstatic_concrete_methods);
  5255 
  5255 
  5256   if (_host_klass != NULL) {
  5256   if (_host_klass != NULL) {
  5257     assert (ik->is_anonymous(), "should be the same");
  5257     assert (ik->is_anonymous(), "should be the same");
  5258     ik->set_host_klass(_host_klass);
  5258     ik->set_host_klass(_host_klass);
  5259   }
  5259   }
  5309   check_super_interface_access(ik, CHECK);
  5309   check_super_interface_access(ik, CHECK);
  5310 
  5310 
  5311   // check if this class overrides any final method
  5311   // check if this class overrides any final method
  5312   check_final_method_override(ik, CHECK);
  5312   check_final_method_override(ik, CHECK);
  5313 
  5313 
  5314   // check that if this class is an interface then it doesn't have static methods
  5314   // reject static interface methods prior to Java 8
  5315   if (ik->is_interface()) {
  5315   if (ik->is_interface() && _major_version < JAVA_8_VERSION) {
  5316     /* An interface in a JAVA 8 classfile can be static */
  5316     check_illegal_static_method(ik, CHECK);
  5317     if (_major_version < JAVA_8_VERSION) {
       
  5318       check_illegal_static_method(ik, CHECK);
       
  5319     }
       
  5320   }
  5317   }
  5321 
  5318 
  5322   // Obtain this_klass' module entry
  5319   // Obtain this_klass' module entry
  5323   ModuleEntry* module_entry = ik->module();
  5320   ModuleEntry* module_entry = ik->module();
  5324   assert(module_entry != NULL, "module_entry should always be set");
  5321   assert(module_entry != NULL, "module_entry should always be set");
  5334                                  _protection_domain,
  5331                                  _protection_domain,
  5335                                  CHECK);
  5332                                  CHECK);
  5336 
  5333 
  5337   assert(_all_mirandas != NULL, "invariant");
  5334   assert(_all_mirandas != NULL, "invariant");
  5338 
  5335 
  5339   // Generate any default methods - default methods are interface methods
  5336   // Generate any default methods - default methods are public interface methods
  5340   // that have a default implementation.  This is new with Lambda project.
  5337   // that have a default implementation.  This is new with Java 8.
  5341   if (_has_default_methods ) {
  5338   if (_has_nonstatic_concrete_methods) {
  5342     DefaultMethods::generate_default_methods(ik,
  5339     DefaultMethods::generate_default_methods(ik,
  5343                                              _all_mirandas,
  5340                                              _all_mirandas,
  5344                                              CHECK);
  5341                                              CHECK);
  5345   }
  5342   }
  5346 
  5343 
  5521   _super_class_index(0),
  5518   _super_class_index(0),
  5522   _itfs_len(0),
  5519   _itfs_len(0),
  5523   _java_fields_count(0),
  5520   _java_fields_count(0),
  5524   _need_verify(false),
  5521   _need_verify(false),
  5525   _relax_verify(false),
  5522   _relax_verify(false),
  5526   _has_default_methods(false),
  5523   _has_nonstatic_concrete_methods(false),
  5527   _declares_default_methods(false),
  5524   _declares_nonstatic_concrete_methods(false),
  5528   _has_final_method(false),
  5525   _has_final_method(false),
  5529   _has_finalizer(false),
  5526   _has_finalizer(false),
  5530   _has_empty_finalizer(false),
  5527   _has_empty_finalizer(false),
  5531   _has_vanilla_constructor(false),
  5528   _has_vanilla_constructor(false),
  5532   _max_bootstrap_specifier_index(-1) {
  5529   _max_bootstrap_specifier_index(-1) {
  5776     if (DumpLoadedClassList != NULL && stream->source() != NULL && classlist_file->is_open()) {
  5773     if (DumpLoadedClassList != NULL && stream->source() != NULL && classlist_file->is_open()) {
  5777       // Only dump the classes that can be stored into CDS archive.
  5774       // Only dump the classes that can be stored into CDS archive.
  5778       // Anonymous classes such as generated LambdaForm classes are also not included.
  5775       // Anonymous classes such as generated LambdaForm classes are also not included.
  5779       if (SystemDictionaryShared::is_sharing_possible(_loader_data) &&
  5776       if (SystemDictionaryShared::is_sharing_possible(_loader_data) &&
  5780           _host_klass == NULL) {
  5777           _host_klass == NULL) {
       
  5778         oop class_loader = _loader_data->class_loader();
  5781         ResourceMark rm(THREAD);
  5779         ResourceMark rm(THREAD);
  5782         classlist_file->print_cr("%s", _class_name->as_C_string());
  5780         // For the boot and platform class loaders, check if the class is not found in the
  5783         classlist_file->flush();
  5781         // java runtime image. Additional check for the boot class loader is if the class
       
  5782         // is not found in the boot loader's appended entries. This indicates that the class
       
  5783         // is not useable during run time, such as the ones found in the --patch-module entries,
       
  5784         // so it should not be included in the classlist file.
       
  5785         if (((class_loader == NULL && !ClassLoader::contains_append_entry(stream->source())) ||
       
  5786              SystemDictionary::is_platform_class_loader(class_loader)) &&
       
  5787             !ClassLoader::is_jrt(stream->source())) {
       
  5788           tty->print_cr("skip writing class %s from source %s to classlist file",
       
  5789             _class_name->as_C_string(), stream->source());
       
  5790         } else {
       
  5791           classlist_file->print_cr("%s", _class_name->as_C_string());
       
  5792           classlist_file->flush();
       
  5793         }
  5784       }
  5794       }
  5785     }
  5795     }
  5786 #endif
  5796 #endif
  5787   }
  5797   }
  5788 
  5798 
  5796   // Interfaces
  5806   // Interfaces
  5797   _itfs_len = stream->get_u2_fast();
  5807   _itfs_len = stream->get_u2_fast();
  5798   parse_interfaces(stream,
  5808   parse_interfaces(stream,
  5799                    _itfs_len,
  5809                    _itfs_len,
  5800                    cp,
  5810                    cp,
  5801                    &_has_default_methods,
  5811                    &_has_nonstatic_concrete_methods,
  5802                    CHECK);
  5812                    CHECK);
  5803 
  5813 
  5804   assert(_local_interfaces != NULL, "invariant");
  5814   assert(_local_interfaces != NULL, "invariant");
  5805 
  5815 
  5806   // Fields (offsets are filled in later)
  5816   // Fields (offsets are filled in later)
  5819   AccessFlags promoted_flags;
  5829   AccessFlags promoted_flags;
  5820   parse_methods(stream,
  5830   parse_methods(stream,
  5821                 _access_flags.is_interface(),
  5831                 _access_flags.is_interface(),
  5822                 &promoted_flags,
  5832                 &promoted_flags,
  5823                 &_has_final_method,
  5833                 &_has_final_method,
  5824                 &_declares_default_methods,
  5834                 &_declares_nonstatic_concrete_methods,
  5825                 CHECK);
  5835                 CHECK);
  5826 
  5836 
  5827   assert(_methods != NULL, "invariant");
  5837   assert(_methods != NULL, "invariant");
  5828 
  5838 
  5829   // promote flags from parse_methods() to the klass' flags
  5839   // promote flags from parse_methods() to the klass' flags
  5830   _access_flags.add_promoted_flags(promoted_flags.as_int());
  5840   _access_flags.add_promoted_flags(promoted_flags.as_int());
  5831 
  5841 
  5832   if (_declares_default_methods) {
  5842   if (_declares_nonstatic_concrete_methods) {
  5833     _has_default_methods = true;
  5843     _has_nonstatic_concrete_methods = true;
  5834   }
  5844   }
  5835 
  5845 
  5836   // Additional attributes/annotations
  5846   // Additional attributes/annotations
  5837   _parsed_annotations = new ClassAnnotationCollector();
  5847   _parsed_annotations = new ClassAnnotationCollector();
  5838   parse_classfile_attributes(stream, cp, _parsed_annotations, CHECK);
  5848   parse_classfile_attributes(stream, cp, _parsed_annotations, CHECK);
  5882                                                                true,
  5892                                                                true,
  5883                                                                CHECK);
  5893                                                                CHECK);
  5884   }
  5894   }
  5885 
  5895 
  5886   if (_super_klass != NULL) {
  5896   if (_super_klass != NULL) {
  5887     if (_super_klass->has_default_methods()) {
  5897     if (_super_klass->has_nonstatic_concrete_methods()) {
  5888       _has_default_methods = true;
  5898       _has_nonstatic_concrete_methods = true;
  5889     }
  5899     }
  5890 
  5900 
  5891     if (_super_klass->is_interface()) {
  5901     if (_super_klass->is_interface()) {
  5892       ResourceMark rm(THREAD);
  5902       ResourceMark rm(THREAD);
  5893       Exceptions::fthrow(
  5903       Exceptions::fthrow(