< prev index next >

src/share/vm/classfile/classFileParser.cpp

Print this page




 781     }
 782     entry = entry->_next;
 783   }
 784 
 785   // No duplicate is found, allocate a new entry and fill it.
 786   entry = new NameSigHash();
 787   entry->_name = name;
 788   entry->_sig = sig;
 789 
 790   // Insert into hash table
 791   entry->_next = table[index];
 792   table[index] = entry;
 793 
 794   return true;
 795 }
 796 
 797 // Side-effects: populates the _local_interfaces field
 798 void ClassFileParser::parse_interfaces(const ClassFileStream* const stream,
 799                                        const int itfs_len,
 800                                        ConstantPool* const cp,
 801                                        bool* const has_default_methods,
 802                                        TRAPS) {
 803   assert(stream != NULL, "invariant");
 804   assert(cp != NULL, "invariant");
 805   assert(has_default_methods != NULL, "invariant");
 806 
 807   if (itfs_len == 0) {
 808     _local_interfaces = Universe::the_empty_klass_array();
 809   } else {
 810     assert(itfs_len > 0, "only called for len>0");
 811     _local_interfaces = MetadataFactory::new_array<Klass*>(_loader_data, itfs_len, NULL, CHECK);
 812 
 813     int index;
 814     for (index = 0; index < itfs_len; index++) {
 815       const u2 interface_index = stream->get_u2(CHECK);
 816       KlassHandle interf;
 817       check_property(
 818         valid_klass_reference_at(interface_index),
 819         "Interface name has bad constant pool index %u in class file %s",
 820         interface_index, CHECK);
 821       if (cp->tag_at(interface_index).is_klass()) {
 822         interf = KlassHandle(THREAD, cp->resolved_klass_at(interface_index));
 823       } else {
 824         Symbol* const unresolved_klass  = cp->klass_name_at(interface_index);
 825 


 827         // But need to make sure it's not an array type.
 828         guarantee_property(unresolved_klass->byte_at(0) != JVM_SIGNATURE_ARRAY,
 829                            "Bad interface name in class file %s", CHECK);
 830 
 831         // Call resolve_super so classcircularity is checked
 832         const Klass* const k =
 833           SystemDictionary::resolve_super_or_fail(_class_name,
 834                                                   unresolved_klass,
 835                                                   _loader_data->class_loader(),
 836                                                   _protection_domain,
 837                                                   false,
 838                                                   CHECK);
 839         interf = KlassHandle(THREAD, k);
 840       }
 841 
 842       if (!interf()->is_interface()) {
 843         THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(),
 844                    "Implementing class");
 845       }
 846 
 847       if (InstanceKlass::cast(interf())->has_default_methods()) {
 848         *has_default_methods = true;
 849       }
 850       _local_interfaces->at_put(index, interf());
 851     }
 852 
 853     if (!_need_verify || itfs_len <= 1) {
 854       return;
 855     }
 856 
 857     // Check if there's any duplicates in interfaces
 858     ResourceMark rm(THREAD);
 859     NameSigHash** interface_names = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD,
 860                                                                  NameSigHash*,
 861                                                                  HASH_ROW_SIZE);
 862     initialize_hashtable(interface_names);
 863     bool dup = false;
 864     {
 865       debug_only(NoSafepointVerifier nsv;)
 866       for (index = 0; index < itfs_len; index++) {
 867         const Klass* const k = _local_interfaces->at(index);
 868         const Symbol* const name = InstanceKlass::cast(k)->name();


2813   }
2814   if (name == vmSymbols::object_initializer_name() &&
2815       signature == vmSymbols::void_method_signature() &&
2816       m->is_vanilla_constructor()) {
2817     _has_vanilla_constructor = true;
2818   }
2819 
2820   NOT_PRODUCT(m->verify());
2821   return m;
2822 }
2823 
2824 
2825 // The promoted_flags parameter is used to pass relevant access_flags
2826 // from the methods back up to the containing klass. These flag values
2827 // are added to klass's access_flags.
2828 // Side-effects: populates the _methods field in the parser
2829 void ClassFileParser::parse_methods(const ClassFileStream* const cfs,
2830                                     bool is_interface,
2831                                     AccessFlags* promoted_flags,
2832                                     bool* has_final_method,
2833                                     bool* declares_default_methods,
2834                                     TRAPS) {
2835   assert(cfs != NULL, "invariant");
2836   assert(promoted_flags != NULL, "invariant");
2837   assert(has_final_method != NULL, "invariant");
2838   assert(declares_default_methods != NULL, "invariant");
2839 
2840   assert(NULL == _methods, "invariant");
2841 
2842   cfs->guarantee_more(2, CHECK);  // length
2843   const u2 length = cfs->get_u2_fast();
2844   if (length == 0) {
2845     _methods = Universe::the_empty_method_array();
2846   } else {
2847     _methods = MetadataFactory::new_array<Method*>(_loader_data,
2848                                                    length,
2849                                                    NULL,
2850                                                    CHECK);
2851 
2852     HandleMark hm(THREAD);
2853     for (int index = 0; index < length; index++) {
2854       Method* method = parse_method(cfs,
2855                                     is_interface,
2856                                     _cp,
2857                                     promoted_flags,
2858                                     CHECK);
2859 
2860       if (method->is_final()) {
2861         *has_final_method = true;
2862       }
2863       // declares_default_methods: declares concrete instance methods, any access flags
2864       // used for interface initialization, and default method inheritance analysis
2865       if (is_interface && !(*declares_default_methods)
2866         && !method->is_abstract() && !method->is_static()) {
2867         *declares_default_methods = true;
2868       }
2869       _methods->at_put(index, method);
2870     }
2871 
2872     if (_need_verify && length > 1) {
2873       // Check duplicated methods
2874       ResourceMark rm(THREAD);
2875       NameSigHash** names_and_sigs = NEW_RESOURCE_ARRAY_IN_THREAD(
2876         THREAD, NameSigHash*, HASH_ROW_SIZE);
2877       initialize_hashtable(names_and_sigs);
2878       bool dup = false;
2879       {
2880         debug_only(NoSafepointVerifier nsv;)
2881         for (int i = 0; i < length; i++) {
2882           const Method* const m = _methods->at(i);
2883           // If no duplicates, add name/signature in hashtable names_and_sigs.
2884           if (!put_after_lookup(m->name(), m->signature(), names_and_sigs)) {
2885             dup = true;
2886             break;
2887           }


5233     ik->set_has_final_method();
5234   }
5235 
5236   ik->copy_method_ordering(_method_ordering, CHECK);
5237   // The InstanceKlass::_methods_jmethod_ids cache
5238   // is managed on the assumption that the initial cache
5239   // size is equal to the number of methods in the class. If
5240   // that changes, then InstanceKlass::idnum_can_increment()
5241   // has to be changed accordingly.
5242   ik->set_initial_method_idnum(ik->methods()->length());
5243 
5244   ik->set_name(_class_name);
5245 
5246   if (is_anonymous()) {
5247     // I am well known to myself
5248     ik->constants()->klass_at_put(_this_class_index, ik); // eagerly resolve
5249   }
5250 
5251   ik->set_minor_version(_minor_version);
5252   ik->set_major_version(_major_version);
5253   ik->set_has_default_methods(_has_default_methods);
5254   ik->set_declares_default_methods(_declares_default_methods);
5255 
5256   if (_host_klass != NULL) {
5257     assert (ik->is_anonymous(), "should be the same");
5258     ik->set_host_klass(_host_klass);
5259   }
5260 
5261   // Set PackageEntry for this_klass
5262   oop cl = ik->class_loader();
5263   Handle clh = Handle(THREAD, java_lang_ClassLoader::non_reflection_class_loader(cl));
5264   ClassLoaderData* cld = ClassLoaderData::class_loader_data_or_null(clh());
5265   ik->set_package(cld, CHECK);
5266 
5267   const Array<Method*>* const methods = ik->methods();
5268   assert(methods != NULL, "invariant");
5269   const int methods_len = methods->length();
5270 
5271   check_methods_for_intrinsics(ik, methods);
5272 
5273   // Fill in field values obtained by parse_classfile_attributes
5274   if (_parsed_annotations->has_any_annotations()) {


5294 
5295   // Compute transitive closure of interfaces this class implements
5296   // Do final class setup
5297   fill_oop_maps(ik,
5298                 _field_info->nonstatic_oop_map_count,
5299                 _field_info->nonstatic_oop_offsets,
5300                 _field_info->nonstatic_oop_counts);
5301 
5302   // Fill in has_finalizer, has_vanilla_constructor, and layout_helper
5303   set_precomputed_flags(ik);
5304 
5305   // check if this class can access its super class
5306   check_super_class_access(ik, CHECK);
5307 
5308   // check if this class can access its superinterfaces
5309   check_super_interface_access(ik, CHECK);
5310 
5311   // check if this class overrides any final method
5312   check_final_method_override(ik, CHECK);
5313 
5314   // check that if this class is an interface then it doesn't have static methods
5315   if (ik->is_interface()) {
5316     /* An interface in a JAVA 8 classfile can be static */
5317     if (_major_version < JAVA_8_VERSION) {
5318       check_illegal_static_method(ik, CHECK);
5319     }
5320   }
5321 
5322   // Obtain this_klass' module entry
5323   ModuleEntry* module_entry = ik->module();
5324   assert(module_entry != NULL, "module_entry should always be set");
5325 
5326   // Obtain java.lang.reflect.Module
5327   Handle module_handle(THREAD, JNIHandles::resolve(module_entry->module()));
5328 
5329   // Allocate mirror and initialize static fields
5330   // The create_mirror() call will also call compute_modifiers()
5331   java_lang_Class::create_mirror(ik,
5332                                  _loader_data->class_loader(),
5333                                  module_handle,
5334                                  _protection_domain,
5335                                  CHECK);
5336 
5337   assert(_all_mirandas != NULL, "invariant");
5338 
5339   // Generate any default methods - default methods are interface methods
5340   // that have a default implementation.  This is new with Lambda project.
5341   if (_has_default_methods ) {
5342     DefaultMethods::generate_default_methods(ik,
5343                                              _all_mirandas,
5344                                              CHECK);
5345   }
5346 
5347   // Add read edges to the unnamed modules of the bootstrap and app class loaders.
5348   if (changed_by_loadhook && !module_handle.is_null() && module_entry->is_named() &&
5349       !module_entry->has_default_read_edges()) {
5350     if (!module_entry->set_has_default_read_edges()) {
5351       // We won a potential race
5352       JvmtiExport::add_default_read_edges(module_handle, THREAD);
5353     }
5354   }
5355 
5356   // Update the loader_data graph.
5357   record_defined_class_dependencies(ik, CHECK);
5358 
5359   ClassLoadingService::notify_class_loaded(ik, false /* not shared class */);
5360 
5361   if (!is_internal()) {


5506   _vtable_size(0),
5507   _itable_size(0),
5508   _num_miranda_methods(0),
5509   _rt(REF_NONE),
5510   _protection_domain(protection_domain),
5511   _access_flags(),
5512   _pub_level(pub_level),
5513   _synthetic_flag(false),
5514   _sde_length(false),
5515   _sde_buffer(NULL),
5516   _sourcefile_index(0),
5517   _generic_signature_index(0),
5518   _major_version(0),
5519   _minor_version(0),
5520   _this_class_index(0),
5521   _super_class_index(0),
5522   _itfs_len(0),
5523   _java_fields_count(0),
5524   _need_verify(false),
5525   _relax_verify(false),
5526   _has_default_methods(false),
5527   _declares_default_methods(false),
5528   _has_final_method(false),
5529   _has_finalizer(false),
5530   _has_empty_finalizer(false),
5531   _has_vanilla_constructor(false),
5532   _max_bootstrap_specifier_index(-1) {
5533 
5534   _class_name = name != NULL ? name : vmSymbols::unknown_class_name();
5535 
5536   assert(THREAD->is_Java_thread(), "invariant");
5537   assert(_loader_data != NULL, "invariant");
5538   assert(stream != NULL, "invariant");
5539   assert(_stream != NULL, "invariant");
5540   assert(_stream->buffer() == _stream->current(), "invariant");
5541   assert(_class_name != NULL, "invariant");
5542   assert(0 == _access_flags.as_int(), "invariant");
5543 
5544   // Figure out whether we can skip format checking (matching classic VM behavior)
5545   if (DumpSharedSpaces) {
5546     // verify == true means it's a 'remote' class (i.e., non-boot class)
5547     // Verification decision is based on BytecodeVerificationRemote flag


5781         ResourceMark rm(THREAD);
5782         classlist_file->print_cr("%s", _class_name->as_C_string());
5783         classlist_file->flush();
5784       }
5785     }
5786 #endif
5787   }
5788 
5789   // SUPERKLASS
5790   _super_class_index = stream->get_u2_fast();
5791   _super_klass = parse_super_class(cp,
5792                                    _super_class_index,
5793                                    _need_verify,
5794                                    CHECK);
5795 
5796   // Interfaces
5797   _itfs_len = stream->get_u2_fast();
5798   parse_interfaces(stream,
5799                    _itfs_len,
5800                    cp,
5801                    &_has_default_methods,
5802                    CHECK);
5803 
5804   assert(_local_interfaces != NULL, "invariant");
5805 
5806   // Fields (offsets are filled in later)
5807   _fac = new FieldAllocationCount();
5808   parse_fields(stream,
5809                _access_flags.is_interface(),
5810                _fac,
5811                cp,
5812                cp_size,
5813                &_java_fields_count,
5814                CHECK);
5815 
5816   assert(_fields != NULL, "invariant");
5817 
5818   // Methods
5819   AccessFlags promoted_flags;
5820   parse_methods(stream,
5821                 _access_flags.is_interface(),
5822                 &promoted_flags,
5823                 &_has_final_method,
5824                 &_declares_default_methods,
5825                 CHECK);
5826 
5827   assert(_methods != NULL, "invariant");
5828 
5829   // promote flags from parse_methods() to the klass' flags
5830   _access_flags.add_promoted_flags(promoted_flags.as_int());
5831 
5832   if (_declares_default_methods) {
5833     _has_default_methods = true;
5834   }
5835 
5836   // Additional attributes/annotations
5837   _parsed_annotations = new ClassAnnotationCollector();
5838   parse_classfile_attributes(stream, cp, _parsed_annotations, CHECK);
5839 
5840   assert(_inner_classes != NULL, "invariant");
5841 
5842   // Finalize the Annotations metadata object,
5843   // now that all annotation arrays have been created.
5844   create_combined_annotations(CHECK);
5845 
5846   // Make sure this is the end of class file stream
5847   guarantee_property(stream->at_eos(),
5848                      "Extra bytes at the end of class file %s",
5849                      CHECK);
5850 
5851   // all bytes in stream read and parsed
5852 }
5853 


5862   // We check super class after class file is parsed and format is checked
5863   if (_super_class_index > 0 && NULL ==_super_klass) {
5864     Symbol* const super_class_name = cp->klass_name_at(_super_class_index);
5865     if (_access_flags.is_interface()) {
5866       // Before attempting to resolve the superclass, check for class format
5867       // errors not checked yet.
5868       guarantee_property(super_class_name == vmSymbols::java_lang_Object(),
5869         "Interfaces must have java.lang.Object as superclass in class file %s",
5870         CHECK);
5871     }
5872     _super_klass = (const InstanceKlass*)
5873                        SystemDictionary::resolve_super_or_fail(_class_name,
5874                                                                super_class_name,
5875                                                                _loader_data->class_loader(),
5876                                                                _protection_domain,
5877                                                                true,
5878                                                                CHECK);
5879   }
5880 
5881   if (_super_klass != NULL) {
5882     if (_super_klass->has_default_methods()) {
5883       _has_default_methods = true;
5884     }
5885 
5886     if (_super_klass->is_interface()) {
5887       ResourceMark rm(THREAD);
5888       Exceptions::fthrow(
5889         THREAD_AND_LOCATION,
5890         vmSymbols::java_lang_IncompatibleClassChangeError(),
5891         "class %s has interface %s as super class",
5892         _class_name->as_klass_external_name(),
5893         _super_klass->external_name()
5894       );
5895       return;
5896     }
5897     // Make sure super class is not final
5898     if (_super_klass->is_final()) {
5899       THROW_MSG(vmSymbols::java_lang_VerifyError(), "Cannot inherit from final class");
5900     }
5901   }
5902 
5903   // Compute the transitive list of all unique interfaces implemented by this class




 781     }
 782     entry = entry->_next;
 783   }
 784 
 785   // No duplicate is found, allocate a new entry and fill it.
 786   entry = new NameSigHash();
 787   entry->_name = name;
 788   entry->_sig = sig;
 789 
 790   // Insert into hash table
 791   entry->_next = table[index];
 792   table[index] = entry;
 793 
 794   return true;
 795 }
 796 
 797 // Side-effects: populates the _local_interfaces field
 798 void ClassFileParser::parse_interfaces(const ClassFileStream* const stream,
 799                                        const int itfs_len,
 800                                        ConstantPool* const cp,
 801                                        bool* const has_nonstatic_concrete_methods,
 802                                        TRAPS) {
 803   assert(stream != NULL, "invariant");
 804   assert(cp != NULL, "invariant");
 805   assert(has_nonstatic_concrete_methods != NULL, "invariant");
 806 
 807   if (itfs_len == 0) {
 808     _local_interfaces = Universe::the_empty_klass_array();
 809   } else {
 810     assert(itfs_len > 0, "only called for len>0");
 811     _local_interfaces = MetadataFactory::new_array<Klass*>(_loader_data, itfs_len, NULL, CHECK);
 812 
 813     int index;
 814     for (index = 0; index < itfs_len; index++) {
 815       const u2 interface_index = stream->get_u2(CHECK);
 816       KlassHandle interf;
 817       check_property(
 818         valid_klass_reference_at(interface_index),
 819         "Interface name has bad constant pool index %u in class file %s",
 820         interface_index, CHECK);
 821       if (cp->tag_at(interface_index).is_klass()) {
 822         interf = KlassHandle(THREAD, cp->resolved_klass_at(interface_index));
 823       } else {
 824         Symbol* const unresolved_klass  = cp->klass_name_at(interface_index);
 825 


 827         // But need to make sure it's not an array type.
 828         guarantee_property(unresolved_klass->byte_at(0) != JVM_SIGNATURE_ARRAY,
 829                            "Bad interface name in class file %s", CHECK);
 830 
 831         // Call resolve_super so classcircularity is checked
 832         const Klass* const k =
 833           SystemDictionary::resolve_super_or_fail(_class_name,
 834                                                   unresolved_klass,
 835                                                   _loader_data->class_loader(),
 836                                                   _protection_domain,
 837                                                   false,
 838                                                   CHECK);
 839         interf = KlassHandle(THREAD, k);
 840       }
 841 
 842       if (!interf()->is_interface()) {
 843         THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(),
 844                    "Implementing class");
 845       }
 846 
 847       if (InstanceKlass::cast(interf())->has_nonstatic_concrete_methods()) {
 848         *has_nonstatic_concrete_methods = true;
 849       }
 850       _local_interfaces->at_put(index, interf());
 851     }
 852 
 853     if (!_need_verify || itfs_len <= 1) {
 854       return;
 855     }
 856 
 857     // Check if there's any duplicates in interfaces
 858     ResourceMark rm(THREAD);
 859     NameSigHash** interface_names = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD,
 860                                                                  NameSigHash*,
 861                                                                  HASH_ROW_SIZE);
 862     initialize_hashtable(interface_names);
 863     bool dup = false;
 864     {
 865       debug_only(NoSafepointVerifier nsv;)
 866       for (index = 0; index < itfs_len; index++) {
 867         const Klass* const k = _local_interfaces->at(index);
 868         const Symbol* const name = InstanceKlass::cast(k)->name();


2813   }
2814   if (name == vmSymbols::object_initializer_name() &&
2815       signature == vmSymbols::void_method_signature() &&
2816       m->is_vanilla_constructor()) {
2817     _has_vanilla_constructor = true;
2818   }
2819 
2820   NOT_PRODUCT(m->verify());
2821   return m;
2822 }
2823 
2824 
2825 // The promoted_flags parameter is used to pass relevant access_flags
2826 // from the methods back up to the containing klass. These flag values
2827 // are added to klass's access_flags.
2828 // Side-effects: populates the _methods field in the parser
2829 void ClassFileParser::parse_methods(const ClassFileStream* const cfs,
2830                                     bool is_interface,
2831                                     AccessFlags* promoted_flags,
2832                                     bool* has_final_method,
2833                                     bool* declares_nonstatic_concrete_methods,
2834                                     TRAPS) {
2835   assert(cfs != NULL, "invariant");
2836   assert(promoted_flags != NULL, "invariant");
2837   assert(has_final_method != NULL, "invariant");
2838   assert(declares_nonstatic_concrete_methods != NULL, "invariant");
2839 
2840   assert(NULL == _methods, "invariant");
2841 
2842   cfs->guarantee_more(2, CHECK);  // length
2843   const u2 length = cfs->get_u2_fast();
2844   if (length == 0) {
2845     _methods = Universe::the_empty_method_array();
2846   } else {
2847     _methods = MetadataFactory::new_array<Method*>(_loader_data,
2848                                                    length,
2849                                                    NULL,
2850                                                    CHECK);
2851 
2852     HandleMark hm(THREAD);
2853     for (int index = 0; index < length; index++) {
2854       Method* method = parse_method(cfs,
2855                                     is_interface,
2856                                     _cp,
2857                                     promoted_flags,
2858                                     CHECK);
2859 
2860       if (method->is_final()) {
2861         *has_final_method = true;
2862       }
2863       // declares_nonstatic_concrete_methods: declares concrete instance methods, any access flags
2864       // used for interface initialization, and default method inheritance analysis
2865       if (is_interface && !(*declares_nonstatic_concrete_methods)
2866         && !method->is_abstract() && !method->is_static()) {
2867         *declares_nonstatic_concrete_methods = true;
2868       }
2869       _methods->at_put(index, method);
2870     }
2871 
2872     if (_need_verify && length > 1) {
2873       // Check duplicated methods
2874       ResourceMark rm(THREAD);
2875       NameSigHash** names_and_sigs = NEW_RESOURCE_ARRAY_IN_THREAD(
2876         THREAD, NameSigHash*, HASH_ROW_SIZE);
2877       initialize_hashtable(names_and_sigs);
2878       bool dup = false;
2879       {
2880         debug_only(NoSafepointVerifier nsv;)
2881         for (int i = 0; i < length; i++) {
2882           const Method* const m = _methods->at(i);
2883           // If no duplicates, add name/signature in hashtable names_and_sigs.
2884           if (!put_after_lookup(m->name(), m->signature(), names_and_sigs)) {
2885             dup = true;
2886             break;
2887           }


5233     ik->set_has_final_method();
5234   }
5235 
5236   ik->copy_method_ordering(_method_ordering, CHECK);
5237   // The InstanceKlass::_methods_jmethod_ids cache
5238   // is managed on the assumption that the initial cache
5239   // size is equal to the number of methods in the class. If
5240   // that changes, then InstanceKlass::idnum_can_increment()
5241   // has to be changed accordingly.
5242   ik->set_initial_method_idnum(ik->methods()->length());
5243 
5244   ik->set_name(_class_name);
5245 
5246   if (is_anonymous()) {
5247     // I am well known to myself
5248     ik->constants()->klass_at_put(_this_class_index, ik); // eagerly resolve
5249   }
5250 
5251   ik->set_minor_version(_minor_version);
5252   ik->set_major_version(_major_version);
5253   ik->set_has_nonstatic_concrete_methods(_has_nonstatic_concrete_methods);
5254   ik->set_declares_nonstatic_concrete_methods(_declares_nonstatic_concrete_methods);
5255 
5256   if (_host_klass != NULL) {
5257     assert (ik->is_anonymous(), "should be the same");
5258     ik->set_host_klass(_host_klass);
5259   }
5260 
5261   // Set PackageEntry for this_klass
5262   oop cl = ik->class_loader();
5263   Handle clh = Handle(THREAD, java_lang_ClassLoader::non_reflection_class_loader(cl));
5264   ClassLoaderData* cld = ClassLoaderData::class_loader_data_or_null(clh());
5265   ik->set_package(cld, CHECK);
5266 
5267   const Array<Method*>* const methods = ik->methods();
5268   assert(methods != NULL, "invariant");
5269   const int methods_len = methods->length();
5270 
5271   check_methods_for_intrinsics(ik, methods);
5272 
5273   // Fill in field values obtained by parse_classfile_attributes
5274   if (_parsed_annotations->has_any_annotations()) {


5294 
5295   // Compute transitive closure of interfaces this class implements
5296   // Do final class setup
5297   fill_oop_maps(ik,
5298                 _field_info->nonstatic_oop_map_count,
5299                 _field_info->nonstatic_oop_offsets,
5300                 _field_info->nonstatic_oop_counts);
5301 
5302   // Fill in has_finalizer, has_vanilla_constructor, and layout_helper
5303   set_precomputed_flags(ik);
5304 
5305   // check if this class can access its super class
5306   check_super_class_access(ik, CHECK);
5307 
5308   // check if this class can access its superinterfaces
5309   check_super_interface_access(ik, CHECK);
5310 
5311   // check if this class overrides any final method
5312   check_final_method_override(ik, CHECK);
5313 
5314   // reject static interface methods prior to Java 8
5315   if (ik->is_interface() && _major_version < JAVA_8_VERSION) {


5316     check_illegal_static_method(ik, CHECK);
5317   }

5318 
5319   // Obtain this_klass' module entry
5320   ModuleEntry* module_entry = ik->module();
5321   assert(module_entry != NULL, "module_entry should always be set");
5322 
5323   // Obtain java.lang.reflect.Module
5324   Handle module_handle(THREAD, JNIHandles::resolve(module_entry->module()));
5325 
5326   // Allocate mirror and initialize static fields
5327   // The create_mirror() call will also call compute_modifiers()
5328   java_lang_Class::create_mirror(ik,
5329                                  _loader_data->class_loader(),
5330                                  module_handle,
5331                                  _protection_domain,
5332                                  CHECK);
5333 
5334   assert(_all_mirandas != NULL, "invariant");
5335 
5336   // Generate any default methods - default methods are public interface methods
5337   // that have a default implementation.  This is new with Java 8.
5338   if (_has_nonstatic_concrete_methods ) {
5339     DefaultMethods::generate_default_methods(ik,
5340                                              _all_mirandas,
5341                                              CHECK);
5342   }
5343 
5344   // Add read edges to the unnamed modules of the bootstrap and app class loaders.
5345   if (changed_by_loadhook && !module_handle.is_null() && module_entry->is_named() &&
5346       !module_entry->has_default_read_edges()) {
5347     if (!module_entry->set_has_default_read_edges()) {
5348       // We won a potential race
5349       JvmtiExport::add_default_read_edges(module_handle, THREAD);
5350     }
5351   }
5352 
5353   // Update the loader_data graph.
5354   record_defined_class_dependencies(ik, CHECK);
5355 
5356   ClassLoadingService::notify_class_loaded(ik, false /* not shared class */);
5357 
5358   if (!is_internal()) {


5503   _vtable_size(0),
5504   _itable_size(0),
5505   _num_miranda_methods(0),
5506   _rt(REF_NONE),
5507   _protection_domain(protection_domain),
5508   _access_flags(),
5509   _pub_level(pub_level),
5510   _synthetic_flag(false),
5511   _sde_length(false),
5512   _sde_buffer(NULL),
5513   _sourcefile_index(0),
5514   _generic_signature_index(0),
5515   _major_version(0),
5516   _minor_version(0),
5517   _this_class_index(0),
5518   _super_class_index(0),
5519   _itfs_len(0),
5520   _java_fields_count(0),
5521   _need_verify(false),
5522   _relax_verify(false),
5523   _has_nonstatic_concrete_methods(false),
5524   _declares_nonstatic_concrete_methods(false),
5525   _has_final_method(false),
5526   _has_finalizer(false),
5527   _has_empty_finalizer(false),
5528   _has_vanilla_constructor(false),
5529   _max_bootstrap_specifier_index(-1) {
5530 
5531   _class_name = name != NULL ? name : vmSymbols::unknown_class_name();
5532 
5533   assert(THREAD->is_Java_thread(), "invariant");
5534   assert(_loader_data != NULL, "invariant");
5535   assert(stream != NULL, "invariant");
5536   assert(_stream != NULL, "invariant");
5537   assert(_stream->buffer() == _stream->current(), "invariant");
5538   assert(_class_name != NULL, "invariant");
5539   assert(0 == _access_flags.as_int(), "invariant");
5540 
5541   // Figure out whether we can skip format checking (matching classic VM behavior)
5542   if (DumpSharedSpaces) {
5543     // verify == true means it's a 'remote' class (i.e., non-boot class)
5544     // Verification decision is based on BytecodeVerificationRemote flag


5778         ResourceMark rm(THREAD);
5779         classlist_file->print_cr("%s", _class_name->as_C_string());
5780         classlist_file->flush();
5781       }
5782     }
5783 #endif
5784   }
5785 
5786   // SUPERKLASS
5787   _super_class_index = stream->get_u2_fast();
5788   _super_klass = parse_super_class(cp,
5789                                    _super_class_index,
5790                                    _need_verify,
5791                                    CHECK);
5792 
5793   // Interfaces
5794   _itfs_len = stream->get_u2_fast();
5795   parse_interfaces(stream,
5796                    _itfs_len,
5797                    cp,
5798                    &_has_nonstatic_concrete_methods,
5799                    CHECK);
5800 
5801   assert(_local_interfaces != NULL, "invariant");
5802 
5803   // Fields (offsets are filled in later)
5804   _fac = new FieldAllocationCount();
5805   parse_fields(stream,
5806                _access_flags.is_interface(),
5807                _fac,
5808                cp,
5809                cp_size,
5810                &_java_fields_count,
5811                CHECK);
5812 
5813   assert(_fields != NULL, "invariant");
5814 
5815   // Methods
5816   AccessFlags promoted_flags;
5817   parse_methods(stream,
5818                 _access_flags.is_interface(),
5819                 &promoted_flags,
5820                 &_has_final_method,
5821                 &_declares_nonstatic_concrete_methods,
5822                 CHECK);
5823 
5824   assert(_methods != NULL, "invariant");
5825 
5826   // promote flags from parse_methods() to the klass' flags
5827   _access_flags.add_promoted_flags(promoted_flags.as_int());
5828 
5829   if (_declares_nonstatic_concrete_methods) {
5830     _has_nonstatic_concrete_methods = true;
5831   }
5832 
5833   // Additional attributes/annotations
5834   _parsed_annotations = new ClassAnnotationCollector();
5835   parse_classfile_attributes(stream, cp, _parsed_annotations, CHECK);
5836 
5837   assert(_inner_classes != NULL, "invariant");
5838 
5839   // Finalize the Annotations metadata object,
5840   // now that all annotation arrays have been created.
5841   create_combined_annotations(CHECK);
5842 
5843   // Make sure this is the end of class file stream
5844   guarantee_property(stream->at_eos(),
5845                      "Extra bytes at the end of class file %s",
5846                      CHECK);
5847 
5848   // all bytes in stream read and parsed
5849 }
5850 


5859   // We check super class after class file is parsed and format is checked
5860   if (_super_class_index > 0 && NULL ==_super_klass) {
5861     Symbol* const super_class_name = cp->klass_name_at(_super_class_index);
5862     if (_access_flags.is_interface()) {
5863       // Before attempting to resolve the superclass, check for class format
5864       // errors not checked yet.
5865       guarantee_property(super_class_name == vmSymbols::java_lang_Object(),
5866         "Interfaces must have java.lang.Object as superclass in class file %s",
5867         CHECK);
5868     }
5869     _super_klass = (const InstanceKlass*)
5870                        SystemDictionary::resolve_super_or_fail(_class_name,
5871                                                                super_class_name,
5872                                                                _loader_data->class_loader(),
5873                                                                _protection_domain,
5874                                                                true,
5875                                                                CHECK);
5876   }
5877 
5878   if (_super_klass != NULL) {
5879     if (_super_klass->has_nonstatic_concrete_methods()) {
5880       _has_nonstatic_concrete_methods = true;
5881     }
5882 
5883     if (_super_klass->is_interface()) {
5884       ResourceMark rm(THREAD);
5885       Exceptions::fthrow(
5886         THREAD_AND_LOCATION,
5887         vmSymbols::java_lang_IncompatibleClassChangeError(),
5888         "class %s has interface %s as super class",
5889         _class_name->as_klass_external_name(),
5890         _super_klass->external_name()
5891       );
5892       return;
5893     }
5894     // Make sure super class is not final
5895     if (_super_klass->is_final()) {
5896       THROW_MSG(vmSymbols::java_lang_VerifyError(), "Cannot inherit from final class");
5897     }
5898   }
5899 
5900   // Compute the transitive list of all unique interfaces implemented by this class


< prev index next >