< prev index next >

src/hotspot/share/classfile/classFileParser.cpp

Print this page
rev 59083 : DRAFT 8236522: NonTearable marker interface for inline classes to enforce atomicity


  66 #include "runtime/fieldDescriptor.inline.hpp"
  67 #include "runtime/handles.inline.hpp"
  68 #include "runtime/javaCalls.hpp"
  69 #include "runtime/os.hpp"
  70 #include "runtime/perfData.hpp"
  71 #include "runtime/reflection.hpp"
  72 #include "runtime/safepointVerifiers.hpp"
  73 #include "runtime/signature.hpp"
  74 #include "runtime/timer.hpp"
  75 #include "services/classLoadingService.hpp"
  76 #include "services/threadService.hpp"
  77 #include "utilities/align.hpp"
  78 #include "utilities/bitMap.inline.hpp"
  79 #include "utilities/copy.hpp"
  80 #include "utilities/exceptions.hpp"
  81 #include "utilities/globalDefinitions.hpp"
  82 #include "utilities/growableArray.hpp"
  83 #include "utilities/macros.hpp"
  84 #include "utilities/ostream.hpp"
  85 #include "utilities/resourceHash.hpp"

  86 #include "utilities/utf8.hpp"
  87 
  88 #if INCLUDE_CDS
  89 #include "classfile/systemDictionaryShared.hpp"
  90 #endif
  91 #if INCLUDE_JFR
  92 #include "jfr/support/jfrTraceIdExtension.hpp"
  93 #endif
  94 
  95 // We generally try to create the oops directly when parsing, rather than
  96 // allocating temporary data structures and copying the bytes twice. A
  97 // temporary area is only needed when parsing utf8 entries in the constant
  98 // pool and when parsing line number tables.
  99 
 100 // We add assert in debug mode when class format is not checked.
 101 
 102 #define JAVA_CLASSFILE_MAGIC              0xCAFEBABE
 103 #define JAVA_MIN_SUPPORTED_VERSION        45
 104 #define JAVA_PREVIEW_MINOR_VERSION        65535
 105 


 926   while (entry != NULL) {
 927     if (entry->_name == name && entry->_sig == sig) {
 928       return false;
 929     }
 930     entry = entry->_next;
 931   }
 932 
 933   // No duplicate is found, allocate a new entry and fill it.
 934   entry = new NameSigHash();
 935   entry->_name = name;
 936   entry->_sig = sig;
 937 
 938   // Insert into hash table
 939   entry->_next = table[index];
 940   table[index] = entry;
 941 
 942   return true;
 943 }
 944 
 945 // Side-effects: populates the _local_interfaces field
 946 void ClassFileParser::parse_interfaces(const ClassFileStream* const stream,
 947                                        const int itfs_len,
 948                                        ConstantPool* const cp,
 949                                        bool* const has_nonstatic_concrete_methods,







 950                                        TRAPS) {
 951   assert(stream != NULL, "invariant");
 952   assert(cp != NULL, "invariant");
 953   assert(has_nonstatic_concrete_methods != NULL, "invariant");
 954 
 955   if (itfs_len == 0) {
 956     _local_interfaces = Universe::the_empty_instance_klass_array();
 957   } else {
 958     assert(itfs_len > 0, "only called for len>0");
 959     _local_interfaces = MetadataFactory::new_array<InstanceKlass*>(_loader_data, itfs_len, NULL, CHECK);
 960 
 961     int index;
 962     for (index = 0; index < itfs_len; index++) {
 963       const u2 interface_index = stream->get_u2(CHECK);
 964       Klass* interf;
 965       check_property(
 966         valid_klass_reference_at(interface_index),
 967         "Interface name has bad constant pool index %u in class file %s",
 968         interface_index, CHECK);
 969       if (cp->tag_at(interface_index).is_klass()) {


 977                            "Bad interface name in class file %s", CHECK);
 978 
 979         // Call resolve_super so classcircularity is checked
 980         interf = SystemDictionary::resolve_super_or_fail(
 981                                                   _class_name,
 982                                                   unresolved_klass,
 983                                                   Handle(THREAD, _loader_data->class_loader()),
 984                                                   _protection_domain,
 985                                                   false,
 986                                                   CHECK);
 987       }
 988 
 989       if (!interf->is_interface()) {
 990         THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(),
 991                   err_msg("class %s can not implement %s, because it is not an interface (%s)",
 992                           _class_name->as_klass_external_name(),
 993                           interf->external_name(),
 994                           interf->class_in_module_of_loader()));
 995       }
 996 
 997       if (InstanceKlass::cast(interf)->has_nonstatic_concrete_methods()) {

 998         *has_nonstatic_concrete_methods = true;
 999       }
1000       _local_interfaces->at_put(index, InstanceKlass::cast(interf));



1001     }
1002 
1003     if (!_need_verify || itfs_len <= 1) {
1004       return;
1005     }
1006 
1007     // Check if there's any duplicates in interfaces
1008     ResourceMark rm(THREAD);
1009     NameSigHash** interface_names = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD,
1010                                                                  NameSigHash*,
1011                                                                  HASH_ROW_SIZE);
1012     initialize_hashtable(interface_names);
1013     bool dup = false;
1014     const Symbol* name = NULL;
1015     {
1016       debug_only(NoSafepointVerifier nsv;)
1017       for (index = 0; index < itfs_len; index++) {
1018         const InstanceKlass* const k = _local_interfaces->at(index);
1019         name = k->name();
1020         // If no duplicates, add (name, NULL) in hashtable interface_names.


4329       return;
4330     }
4331   }
4332 
4333   // Compute the non-contended fields count.
4334   // The packing code below relies on these counts to determine if some field
4335   // can be squeezed into the alignment gap. Contended fields are obviously
4336   // exempt from that.
4337   unsigned int nonstatic_double_count = fac->count[NONSTATIC_DOUBLE] - fac_contended.count[NONSTATIC_DOUBLE];
4338   unsigned int nonstatic_word_count   = fac->count[NONSTATIC_WORD]   - fac_contended.count[NONSTATIC_WORD];
4339   unsigned int nonstatic_short_count  = fac->count[NONSTATIC_SHORT]  - fac_contended.count[NONSTATIC_SHORT];
4340   unsigned int nonstatic_byte_count   = fac->count[NONSTATIC_BYTE]   - fac_contended.count[NONSTATIC_BYTE];
4341   unsigned int nonstatic_oop_count    = fac->count[NONSTATIC_OOP]    - fac_contended.count[NONSTATIC_OOP];
4342 
4343   int static_value_type_count = 0;
4344   int nonstatic_value_type_count = 0;
4345   int* nonstatic_value_type_indexes = NULL;
4346   Klass** nonstatic_value_type_klasses = NULL;
4347   unsigned int value_type_oop_map_count = 0;
4348   int not_flattened_value_types = 0;

4349 
4350   int max_nonstatic_value_type = fac->count[NONSTATIC_FLATTENABLE] + 1;
4351 
4352   nonstatic_value_type_indexes = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, int,
4353                                                               max_nonstatic_value_type);
4354   for (int i = 0; i < max_nonstatic_value_type; i++) {
4355     nonstatic_value_type_indexes[i] = -1;
4356   }
4357   nonstatic_value_type_klasses = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, Klass*,
4358                                                               max_nonstatic_value_type);
4359 
4360   for (AllFieldStream fs(_fields, _cp); !fs.done(); fs.next()) {
4361     if (fs.allocation_type() == STATIC_FLATTENABLE) {
4362       ResourceMark rm;
4363       if (!fs.signature()->is_Q_signature()) {
4364         THROW(vmSymbols::java_lang_ClassFormatError());
4365       }
4366       static_value_type_count++;
4367     } else if (fs.allocation_type() == NONSTATIC_FLATTENABLE) {
4368       // Pre-resolve the flattenable field and check for value type circularity issues.
4369       ResourceMark rm;
4370       if (!fs.signature()->is_Q_signature()) {
4371         THROW(vmSymbols::java_lang_ClassFormatError());
4372       }
4373       Klass* klass =
4374         SystemDictionary::resolve_flattenable_field_or_fail(&fs,
4375                                                             Handle(THREAD, _loader_data->class_loader()),
4376                                                             _protection_domain, true, CHECK);
4377       assert(klass != NULL, "Sanity check");
4378       if (!klass->access_flags().is_value_type()) {
4379         THROW(vmSymbols::java_lang_IncompatibleClassChangeError());
4380       }
4381       ValueKlass* vk = ValueKlass::cast(klass);
4382       // Conditions to apply flattening or not should be defined in a single place
4383       if ((ValueFieldMaxFlatSize < 0) || (vk->size_helper() * HeapWordSize) <= ValueFieldMaxFlatSize) {









4384         nonstatic_value_type_indexes[nonstatic_value_type_count] = fs.index();
4385         nonstatic_value_type_klasses[nonstatic_value_type_count] = klass;
4386         nonstatic_value_type_count++;
4387 
4388         ValueKlass* vklass = ValueKlass::cast(klass);
4389         if (vklass->contains_oops()) {
4390           value_type_oop_map_count += vklass->nonstatic_oop_map_count();
4391         }
4392         fs.set_flattened(true);



4393       } else {
4394         not_flattened_value_types++;
4395         fs.set_flattened(false);
4396       }
4397     }
4398   }
4399 
4400   // Adjusting non_static_oop_count to take into account not flattened value types;
4401   nonstatic_oop_count += not_flattened_value_types;
4402 
4403   // Total non-static fields count, including every contended field
4404   unsigned int nonstatic_fields_count = fac->count[NONSTATIC_DOUBLE] + fac->count[NONSTATIC_WORD] +
4405                                         fac->count[NONSTATIC_SHORT] + fac->count[NONSTATIC_BYTE] +
4406                                         fac->count[NONSTATIC_OOP] + fac->count[NONSTATIC_FLATTENABLE];
4407 
4408   const bool super_has_nonstatic_fields =
4409           (_super_klass != NULL && _super_klass->has_nonstatic_fields());
4410   const bool has_nonstatic_fields =
4411     super_has_nonstatic_fields || (nonstatic_fields_count != 0);
4412   const bool has_nonstatic_value_fields = nonstatic_value_type_count > 0;


4831           instance_size,
4832           nonstatic_fields_start,
4833           nonstatic_fields_end,
4834           static_fields_end);
4835     nonstatic_oop_maps->print_on(tty);
4836     tty->print("\n");
4837     tty->print_cr("Instance size = %d", instance_size);
4838     tty->print_cr("Nonstatic_field_size = %d", nonstatic_field_size);
4839     tty->print_cr("Static_field_size = %d", static_field_size);
4840     tty->print_cr("Has nonstatic fields = %d", has_nonstatic_fields);
4841     tty->print_cr("---");
4842   }
4843 
4844 #endif
4845   // Pass back information needed for InstanceKlass creation
4846   info->oop_map_blocks = nonstatic_oop_maps;
4847   info->_instance_size = instance_size;
4848   info->_static_field_size = static_field_size;
4849   info->_nonstatic_field_size = nonstatic_field_size;
4850   info->_has_nonstatic_fields = has_nonstatic_fields;













4851 }
4852 
4853 void ClassFileParser::set_precomputed_flags(InstanceKlass* ik) {
4854   assert(ik != NULL, "invariant");
4855 
4856   const Klass* const super = ik->super();
4857 
4858   // Check if this klass has an empty finalize method (i.e. one with return bytecode only),
4859   // in which case we don't have to register objects as finalizable
4860   if (!_has_empty_finalizer) {
4861     if (_has_finalizer ||
4862         (super != NULL && super->has_finalizer())) {
4863       ik->set_has_finalizer();
4864     }
4865   }
4866 
4867 #ifdef ASSERT
4868   bool f = false;
4869   const Method* const m = ik->lookup_method(vmSymbols::finalize_method_name(),
4870                                            vmSymbols::void_method_signature());


5966 
5967           if (!match) {
5968             char buf[1000];
5969             tty->print("Compiler intrinsic is defined for method [%s], "
5970                        "but the method is not available in class [%s].%s",
5971                         vmIntrinsics::short_name_as_C_string(vmIntrinsics::ID_from(id),
5972                                                              buf, sizeof(buf)),
5973                         ik->name()->as_C_string(),
5974                         NOT_DEBUG("") DEBUG_ONLY(" Exiting.")
5975             );
5976             tty->cr();
5977             DEBUG_ONLY(vm_exit(1));
5978           }
5979         }
5980       } // end for
5981     } // CheckIntrinsics
5982 #endif // ASSERT
5983   }
5984 }
5985 

5986 InstanceKlass* ClassFileParser::create_instance_klass(bool changed_by_loadhook, TRAPS) {
5987   if (_klass != NULL) {
5988     return _klass;
5989   }
5990 
5991   InstanceKlass* const ik =
5992     InstanceKlass::allocate_instance_klass(*this, CHECK_NULL);
5993 
5994   fill_instance_klass(ik, changed_by_loadhook, CHECK_NULL);
5995 
5996   assert(_klass == ik, "invariant");
5997 
5998 
5999   if (ik->should_store_fingerprint()) {
6000     ik->store_fingerprint(_stream->compute_fingerprint());
6001   }
6002 
6003   ik->set_has_passed_fingerprint_check(false);
6004   if (UseAOT && ik->supers_have_passed_fingerprint_checks()) {
6005     uint64_t aot_fp = AOTLoader::get_saved_fingerprint(ik);


6035   const bool publicize = !is_internal();
6036 
6037   _loader_data->add_class(ik, publicize);
6038 
6039   set_klass_to_deallocate(ik);
6040 
6041   assert(_field_info != NULL, "invariant");
6042   assert(ik->static_field_size() == _field_info->_static_field_size, "sanity");
6043   assert(ik->nonstatic_oop_map_count() == _field_info->oop_map_blocks->_nonstatic_oop_map_count,
6044          "sanity");
6045 
6046   assert(ik->is_instance_klass(), "sanity");
6047   assert(ik->size_helper() == _field_info->_instance_size, "sanity");
6048 
6049   // Fill in information already parsed
6050   ik->set_should_verify_class(_need_verify);
6051 
6052   // Not yet: supers are done below to support the new subtype-checking fields
6053   ik->set_nonstatic_field_size(_field_info->_nonstatic_field_size);
6054   ik->set_has_nonstatic_fields(_field_info->_has_nonstatic_fields);



6055   if (_is_empty_value) {
6056     ik->set_is_empty_value();
6057   }
6058   assert(_fac != NULL, "invariant");
6059   ik->set_static_oop_field_count(_fac->count[STATIC_OOP] + _fac->count[STATIC_FLATTENABLE]);
6060 
6061   // this transfers ownership of a lot of arrays from
6062   // the parser onto the InstanceKlass*
6063   apply_parsed_class_metadata(ik, _java_fields_count, CHECK);
6064 
6065   // note that is not safe to use the fields in the parser from this point on
6066   assert(NULL == _cp, "invariant");
6067   assert(NULL == _fields, "invariant");
6068   assert(NULL == _methods, "invariant");
6069   assert(NULL == _inner_classes, "invariant");
6070   assert(NULL == _nest_members, "invariant");
6071   assert(NULL == _local_interfaces, "invariant");
6072   assert(NULL == _combined_annotations, "invariant");
6073   assert(NULL == _record_components, "invariant");
6074 


6084   // has to be changed accordingly.
6085   ik->set_initial_method_idnum(ik->methods()->length());
6086 
6087   ik->set_this_class_index(_this_class_index);
6088 
6089   if (is_unsafe_anonymous()) {
6090     // _this_class_index is a CONSTANT_Class entry that refers to this
6091     // anonymous class itself. If this class needs to refer to its own methods or
6092     // fields, it would use a CONSTANT_MethodRef, etc, which would reference
6093     // _this_class_index. However, because this class is anonymous (it's
6094     // not stored in SystemDictionary), _this_class_index cannot be resolved
6095     // with ConstantPool::klass_at_impl, which does a SystemDictionary lookup.
6096     // Therefore, we must eagerly resolve _this_class_index now.
6097     ik->constants()->klass_at_put(_this_class_index, ik);
6098   }
6099 
6100   ik->set_minor_version(_minor_version);
6101   ik->set_major_version(_major_version);
6102   ik->set_has_nonstatic_concrete_methods(_has_nonstatic_concrete_methods);
6103   ik->set_declares_nonstatic_concrete_methods(_declares_nonstatic_concrete_methods);



6104 
6105   if (_unsafe_anonymous_host != NULL) {
6106     assert (ik->is_unsafe_anonymous(), "should be the same");
6107     ik->set_unsafe_anonymous_host(_unsafe_anonymous_host);
6108   }
6109 
6110   // Set PackageEntry for this_klass
6111   oop cl = ik->class_loader();
6112   Handle clh = Handle(THREAD, java_lang_ClassLoader::non_reflection_class_loader(cl));
6113   ClassLoaderData* cld = ClassLoaderData::class_loader_data_or_null(clh());
6114   ik->set_package(cld, CHECK);
6115 
6116   const Array<Method*>* const methods = ik->methods();
6117   assert(methods != NULL, "invariant");
6118   const int methods_len = methods->length();
6119 
6120   check_methods_for_intrinsics(ik, methods);
6121 
6122   // Fill in field values obtained by parse_classfile_attributes
6123   if (_parsed_annotations->has_any_annotations()) {


6416   _bad_constant_seen(0),
6417   _synthetic_flag(false),
6418   _sde_length(false),
6419   _sde_buffer(NULL),
6420   _sourcefile_index(0),
6421   _generic_signature_index(0),
6422   _major_version(0),
6423   _minor_version(0),
6424   _this_class_index(0),
6425   _super_class_index(0),
6426   _itfs_len(0),
6427   _java_fields_count(0),
6428   _need_verify(false),
6429   _relax_verify(false),
6430   _has_nonstatic_concrete_methods(false),
6431   _declares_nonstatic_concrete_methods(false),
6432   _has_final_method(false),
6433   _has_contended_fields(false),
6434   _has_flattenable_fields(false),
6435   _is_empty_value(false),


6436   _has_finalizer(false),
6437   _has_empty_finalizer(false),
6438   _has_vanilla_constructor(false),
6439   _max_bootstrap_specifier_index(-1) {
6440 
6441   _class_name = name != NULL ? name : vmSymbols::unknown_class_name();
6442   _class_name->increment_refcount();
6443 
6444   assert(THREAD->is_Java_thread(), "invariant");
6445   assert(_loader_data != NULL, "invariant");
6446   assert(stream != NULL, "invariant");
6447   assert(_stream != NULL, "invariant");
6448   assert(_stream->buffer() == _stream->current(), "invariant");
6449   assert(_class_name != NULL, "invariant");
6450   assert(0 == _access_flags.as_int(), "invariant");
6451 
6452   // Figure out whether we can skip format checking (matching classic VM behavior)
6453   if (DumpSharedSpaces) {
6454     // verify == true means it's a 'remote' class (i.e., non-boot class)
6455     // Verification decision is based on BytecodeVerificationRemote flag


6755           classlist_file->flush();
6756         }
6757       }
6758     }
6759 #endif
6760   }
6761 
6762   // SUPERKLASS
6763   _super_class_index = stream->get_u2_fast();
6764   _super_klass = parse_super_class(cp,
6765                                    _super_class_index,
6766                                    _need_verify,
6767                                    CHECK);
6768 
6769   // Interfaces
6770   _itfs_len = stream->get_u2_fast();
6771   parse_interfaces(stream,
6772                    _itfs_len,
6773                    cp,
6774                    &_has_nonstatic_concrete_methods,

6775                    CHECK);
6776 
6777   assert(_local_interfaces != NULL, "invariant");
6778 
6779   // Fields (offsets are filled in later)
6780   _fac = new FieldAllocationCount();
6781   parse_fields(stream,
6782                _access_flags.is_interface(),
6783                _access_flags.is_value_type(),
6784                _fac,
6785                cp,
6786                cp_size,
6787                &_java_fields_count,
6788                CHECK);
6789 
6790   assert(_fields != NULL, "invariant");
6791 
6792   // Methods
6793   AccessFlags promoted_flags;
6794   parse_methods(stream,
6795                 _access_flags.is_interface(),
6796                 _access_flags.is_value_type(),
6797                 &promoted_flags,
6798                 &_has_final_method,
6799                 &_declares_nonstatic_concrete_methods,
6800                 CHECK);
6801 
6802   assert(_methods != NULL, "invariant");
6803 
6804   // promote flags from parse_methods() to the klass' flags
6805   _access_flags.add_promoted_flags(promoted_flags.as_int());
6806 
6807   if (_declares_nonstatic_concrete_methods) {
6808     _has_nonstatic_concrete_methods = true;
6809   }
6810 
6811   // Additional attributes/annotations
6812   _parsed_annotations = new ClassAnnotationCollector();
6813   parse_classfile_attributes(stream, cp, _parsed_annotations, CHECK);
6814 
6815   assert(_inner_classes != NULL, "invariant");
6816 


6825 
6826   // all bytes in stream read and parsed
6827 }
6828 
6829 void ClassFileParser::post_process_parsed_stream(const ClassFileStream* const stream,
6830                                                  ConstantPool* cp,
6831                                                  TRAPS) {
6832   assert(stream != NULL, "invariant");
6833   assert(stream->at_eos(), "invariant");
6834   assert(cp != NULL, "invariant");
6835   assert(_loader_data != NULL, "invariant");
6836 
6837   if (_class_name == vmSymbols::java_lang_Object()) {
6838     check_property(_local_interfaces == Universe::the_empty_instance_klass_array(),
6839                    "java.lang.Object cannot implement an interface in class file %s",
6840                    CHECK);
6841   }
6842   // We check super class after class file is parsed and format is checked
6843   if (_super_class_index > 0 && NULL ==_super_klass) {
6844     Symbol* const super_class_name = cp->klass_name_at(_super_class_index);
6845     if (_access_flags.is_interface()) {
6846       // Before attempting to resolve the superclass, check for class format
6847       // errors not checked yet.
6848       guarantee_property(super_class_name == vmSymbols::java_lang_Object(),
6849         "Interfaces must have java.lang.Object as superclass in class file %s",
6850         CHECK);
6851     }
6852     Handle loader(THREAD, _loader_data->class_loader());
6853     _super_klass = (const InstanceKlass*)
6854                        SystemDictionary::resolve_super_or_fail(_class_name,
6855                                                                super_class_name,
6856                                                                loader,
6857                                                                _protection_domain,
6858                                                                true,
6859                                                                CHECK);
6860   }
6861 
6862   if (_super_klass != NULL) {
6863     if (_super_klass->has_nonstatic_concrete_methods()) {
6864       _has_nonstatic_concrete_methods = true;
6865     }



6866 
6867     if (_super_klass->is_interface()) {
6868       ResourceMark rm(THREAD);
6869       Exceptions::fthrow(
6870         THREAD_AND_LOCATION,
6871         vmSymbols::java_lang_IncompatibleClassChangeError(),
6872         "class %s has interface %s as super class",
6873         _class_name->as_klass_external_name(),
6874         _super_klass->external_name()
6875       );
6876       return;
6877     }
6878 
6879     // For a value class, only java/lang/Object is an acceptable super class
6880     if (_access_flags.get_flags() & JVM_ACC_VALUE) {
6881       guarantee_property(_super_klass->name() == vmSymbols::java_lang_Object(),
6882         "Value type must have java.lang.Object as superclass in class file %s",
6883         CHECK);
6884     }
6885 
6886     // Make sure super class is not final
6887     if (_super_klass->is_final()) {
6888       THROW_MSG(vmSymbols::java_lang_VerifyError(), "Cannot inherit from final class");
6889     }
6890   }
6891 












6892   // Compute the transitive list of all unique interfaces implemented by this class
6893   _transitive_interfaces =
6894     compute_transitive_interfaces(_super_klass,
6895                                   _local_interfaces,
6896                                   _loader_data,
6897                                   CHECK);
6898 
6899   assert(_transitive_interfaces != NULL, "invariant");
6900 
6901   // sort methods
6902   _method_ordering = sort_methods(_methods);
6903 
6904   _all_mirandas = new GrowableArray<Method*>(20);
6905 
6906   Handle loader(THREAD, _loader_data->class_loader());
6907   klassVtable::compute_vtable_size_and_num_mirandas(&_vtable_size,
6908                                                     &_num_miranda_methods,
6909                                                     _all_mirandas,
6910                                                     _super_klass,
6911                                                     _methods,
6912                                                     _access_flags,
6913                                                     _major_version,
6914                                                     loader,
6915                                                     _class_name,
6916                                                     _local_interfaces,
6917                                                     CHECK);
6918 
6919   // Size of Java itable (in words)
6920   _itable_size = _access_flags.is_interface() ? 0 :
6921     klassItable::compute_itable_size(_transitive_interfaces);
6922 
6923   assert(_fac != NULL, "invariant");
6924   assert(_parsed_annotations != NULL, "invariant");
6925 
6926 
6927   for (AllFieldStream fs(_fields, cp); !fs.done(); fs.next()) {
6928     if (fs.is_flattenable() && !fs.access_flags().is_static()) {
6929       // Pre-load value class
6930       Klass* klass = SystemDictionary::resolve_flattenable_field_or_fail(&fs,
6931           Handle(THREAD, _loader_data->class_loader()),
6932           _protection_domain, true, CHECK);
6933       assert(klass != NULL, "Sanity check");
6934       assert(klass->access_flags().is_value_type(), "Value type expected");
6935       _has_flattenable_fields = true;
6936     }
6937   }
6938 
6939   _field_info = new FieldLayoutInfo();
6940   if (UseNewLayout) {




  66 #include "runtime/fieldDescriptor.inline.hpp"
  67 #include "runtime/handles.inline.hpp"
  68 #include "runtime/javaCalls.hpp"
  69 #include "runtime/os.hpp"
  70 #include "runtime/perfData.hpp"
  71 #include "runtime/reflection.hpp"
  72 #include "runtime/safepointVerifiers.hpp"
  73 #include "runtime/signature.hpp"
  74 #include "runtime/timer.hpp"
  75 #include "services/classLoadingService.hpp"
  76 #include "services/threadService.hpp"
  77 #include "utilities/align.hpp"
  78 #include "utilities/bitMap.inline.hpp"
  79 #include "utilities/copy.hpp"
  80 #include "utilities/exceptions.hpp"
  81 #include "utilities/globalDefinitions.hpp"
  82 #include "utilities/growableArray.hpp"
  83 #include "utilities/macros.hpp"
  84 #include "utilities/ostream.hpp"
  85 #include "utilities/resourceHash.hpp"
  86 #include "utilities/stringUtils.hpp"
  87 #include "utilities/utf8.hpp"
  88 
  89 #if INCLUDE_CDS
  90 #include "classfile/systemDictionaryShared.hpp"
  91 #endif
  92 #if INCLUDE_JFR
  93 #include "jfr/support/jfrTraceIdExtension.hpp"
  94 #endif
  95 
  96 // We generally try to create the oops directly when parsing, rather than
  97 // allocating temporary data structures and copying the bytes twice. A
  98 // temporary area is only needed when parsing utf8 entries in the constant
  99 // pool and when parsing line number tables.
 100 
 101 // We add assert in debug mode when class format is not checked.
 102 
 103 #define JAVA_CLASSFILE_MAGIC              0xCAFEBABE
 104 #define JAVA_MIN_SUPPORTED_VERSION        45
 105 #define JAVA_PREVIEW_MINOR_VERSION        65535
 106 


 927   while (entry != NULL) {
 928     if (entry->_name == name && entry->_sig == sig) {
 929       return false;
 930     }
 931     entry = entry->_next;
 932   }
 933 
 934   // No duplicate is found, allocate a new entry and fill it.
 935   entry = new NameSigHash();
 936   entry->_name = name;
 937   entry->_sig = sig;
 938 
 939   // Insert into hash table
 940   entry->_next = table[index];
 941   table[index] = entry;
 942 
 943   return true;
 944 }
 945 
 946 // Side-effects: populates the _local_interfaces field
 947 void ClassFileParser::parse_interfaces(const ClassFileStream* stream,
 948                                        int itfs_len,
 949                                        ConstantPool* cp,
 950                                        bool* const has_nonstatic_concrete_methods,
 951                                        // FIXME: lots of these functions
 952                                        // declare their parameters as const,
 953                                        // which adds only noise to the code.
 954                                        // Remove the spurious const modifiers.
 955                                        // Many are of the form "const int x"
 956                                        // or "T* const x".
 957                                        bool* const is_declared_atomic,
 958                                        TRAPS) {
 959   assert(stream != NULL, "invariant");
 960   assert(cp != NULL, "invariant");
 961   assert(has_nonstatic_concrete_methods != NULL, "invariant");
 962 
 963   if (itfs_len == 0) {
 964     _local_interfaces = Universe::the_empty_instance_klass_array();
 965   } else {
 966     assert(itfs_len > 0, "only called for len>0");
 967     _local_interfaces = MetadataFactory::new_array<InstanceKlass*>(_loader_data, itfs_len, NULL, CHECK);
 968 
 969     int index;
 970     for (index = 0; index < itfs_len; index++) {
 971       const u2 interface_index = stream->get_u2(CHECK);
 972       Klass* interf;
 973       check_property(
 974         valid_klass_reference_at(interface_index),
 975         "Interface name has bad constant pool index %u in class file %s",
 976         interface_index, CHECK);
 977       if (cp->tag_at(interface_index).is_klass()) {


 985                            "Bad interface name in class file %s", CHECK);
 986 
 987         // Call resolve_super so classcircularity is checked
 988         interf = SystemDictionary::resolve_super_or_fail(
 989                                                   _class_name,
 990                                                   unresolved_klass,
 991                                                   Handle(THREAD, _loader_data->class_loader()),
 992                                                   _protection_domain,
 993                                                   false,
 994                                                   CHECK);
 995       }
 996 
 997       if (!interf->is_interface()) {
 998         THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(),
 999                   err_msg("class %s can not implement %s, because it is not an interface (%s)",
1000                           _class_name->as_klass_external_name(),
1001                           interf->external_name(),
1002                           interf->class_in_module_of_loader()));
1003       }
1004 
1005       InstanceKlass* ik = InstanceKlass::cast(interf);
1006       if (ik->has_nonstatic_concrete_methods()) {
1007         *has_nonstatic_concrete_methods = true;
1008       }
1009       if (ik->is_declared_atomic()) {
1010         *is_declared_atomic = true;
1011       }
1012       _local_interfaces->at_put(index, ik);
1013     }
1014 
1015     if (!_need_verify || itfs_len <= 1) {
1016       return;
1017     }
1018 
1019     // Check if there's any duplicates in interfaces
1020     ResourceMark rm(THREAD);
1021     NameSigHash** interface_names = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD,
1022                                                                  NameSigHash*,
1023                                                                  HASH_ROW_SIZE);
1024     initialize_hashtable(interface_names);
1025     bool dup = false;
1026     const Symbol* name = NULL;
1027     {
1028       debug_only(NoSafepointVerifier nsv;)
1029       for (index = 0; index < itfs_len; index++) {
1030         const InstanceKlass* const k = _local_interfaces->at(index);
1031         name = k->name();
1032         // If no duplicates, add (name, NULL) in hashtable interface_names.


4341       return;
4342     }
4343   }
4344 
4345   // Compute the non-contended fields count.
4346   // The packing code below relies on these counts to determine if some field
4347   // can be squeezed into the alignment gap. Contended fields are obviously
4348   // exempt from that.
4349   unsigned int nonstatic_double_count = fac->count[NONSTATIC_DOUBLE] - fac_contended.count[NONSTATIC_DOUBLE];
4350   unsigned int nonstatic_word_count   = fac->count[NONSTATIC_WORD]   - fac_contended.count[NONSTATIC_WORD];
4351   unsigned int nonstatic_short_count  = fac->count[NONSTATIC_SHORT]  - fac_contended.count[NONSTATIC_SHORT];
4352   unsigned int nonstatic_byte_count   = fac->count[NONSTATIC_BYTE]   - fac_contended.count[NONSTATIC_BYTE];
4353   unsigned int nonstatic_oop_count    = fac->count[NONSTATIC_OOP]    - fac_contended.count[NONSTATIC_OOP];
4354 
4355   int static_value_type_count = 0;
4356   int nonstatic_value_type_count = 0;
4357   int* nonstatic_value_type_indexes = NULL;
4358   Klass** nonstatic_value_type_klasses = NULL;
4359   unsigned int value_type_oop_map_count = 0;
4360   int not_flattened_value_types = 0;
4361   int not_atomic_value_types = 0;
4362 
4363   int max_nonstatic_value_type = fac->count[NONSTATIC_FLATTENABLE] + 1;
4364 
4365   nonstatic_value_type_indexes = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, int,
4366                                                               max_nonstatic_value_type);
4367   for (int i = 0; i < max_nonstatic_value_type; i++) {
4368     nonstatic_value_type_indexes[i] = -1;
4369   }
4370   nonstatic_value_type_klasses = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, Klass*,
4371                                                               max_nonstatic_value_type);
4372 
4373   for (AllFieldStream fs(_fields, _cp); !fs.done(); fs.next()) {
4374     if (fs.allocation_type() == STATIC_FLATTENABLE) {
4375       ResourceMark rm;
4376       if (!fs.signature()->is_Q_signature()) {
4377         THROW(vmSymbols::java_lang_ClassFormatError());
4378       }
4379       static_value_type_count++;
4380     } else if (fs.allocation_type() == NONSTATIC_FLATTENABLE) {
4381       // Pre-resolve the flattenable field and check for value type circularity issues.
4382       ResourceMark rm;
4383       if (!fs.signature()->is_Q_signature()) {
4384         THROW(vmSymbols::java_lang_ClassFormatError());
4385       }
4386       Klass* klass =
4387         SystemDictionary::resolve_flattenable_field_or_fail(&fs,
4388                                                             Handle(THREAD, _loader_data->class_loader()),
4389                                                             _protection_domain, true, CHECK);
4390       assert(klass != NULL, "Sanity check");
4391       if (!klass->access_flags().is_value_type()) {
4392         THROW(vmSymbols::java_lang_IncompatibleClassChangeError());
4393       }
4394       ValueKlass* vk = ValueKlass::cast(klass);
4395       // Conditions to apply flattening or not should be defined in a single place
4396       bool too_big_to_flatten = (ValueFieldMaxFlatSize >= 0 &&
4397                                  (vk->size_helper() * HeapWordSize) > ValueFieldMaxFlatSize);
4398       bool too_atomic_to_flatten = vk->is_declared_atomic();
4399       bool too_volatile_to_flatten = fs.access_flags().is_volatile();
4400       if (vk->is_naturally_atomic()) {
4401         too_atomic_to_flatten = false;
4402         //too_volatile_to_flatten = false; //FIXME
4403         // volatile fields are currently never flattened, this could change in the future
4404       }
4405       if (!(too_big_to_flatten | too_atomic_to_flatten | too_volatile_to_flatten)) {
4406         nonstatic_value_type_indexes[nonstatic_value_type_count] = fs.index();
4407         nonstatic_value_type_klasses[nonstatic_value_type_count] = klass;
4408         nonstatic_value_type_count++;
4409 
4410         ValueKlass* vklass = ValueKlass::cast(klass);
4411         if (vklass->contains_oops()) {
4412           value_type_oop_map_count += vklass->nonstatic_oop_map_count();
4413         }
4414         fs.set_flattened(true);
4415         if (!vk->is_atomic()) {  // flat and non-atomic: take note
4416           not_atomic_value_types++;
4417         }
4418       } else {
4419         not_flattened_value_types++;
4420         fs.set_flattened(false);
4421       }
4422     }
4423   }
4424 
4425   // Adjusting non_static_oop_count to take into account not flattened value types;
4426   nonstatic_oop_count += not_flattened_value_types;
4427 
4428   // Total non-static fields count, including every contended field
4429   unsigned int nonstatic_fields_count = fac->count[NONSTATIC_DOUBLE] + fac->count[NONSTATIC_WORD] +
4430                                         fac->count[NONSTATIC_SHORT] + fac->count[NONSTATIC_BYTE] +
4431                                         fac->count[NONSTATIC_OOP] + fac->count[NONSTATIC_FLATTENABLE];
4432 
4433   const bool super_has_nonstatic_fields =
4434           (_super_klass != NULL && _super_klass->has_nonstatic_fields());
4435   const bool has_nonstatic_fields =
4436     super_has_nonstatic_fields || (nonstatic_fields_count != 0);
4437   const bool has_nonstatic_value_fields = nonstatic_value_type_count > 0;


4856           instance_size,
4857           nonstatic_fields_start,
4858           nonstatic_fields_end,
4859           static_fields_end);
4860     nonstatic_oop_maps->print_on(tty);
4861     tty->print("\n");
4862     tty->print_cr("Instance size = %d", instance_size);
4863     tty->print_cr("Nonstatic_field_size = %d", nonstatic_field_size);
4864     tty->print_cr("Static_field_size = %d", static_field_size);
4865     tty->print_cr("Has nonstatic fields = %d", has_nonstatic_fields);
4866     tty->print_cr("---");
4867   }
4868 
4869 #endif
4870   // Pass back information needed for InstanceKlass creation
4871   info->oop_map_blocks = nonstatic_oop_maps;
4872   info->_instance_size = instance_size;
4873   info->_static_field_size = static_field_size;
4874   info->_nonstatic_field_size = nonstatic_field_size;
4875   info->_has_nonstatic_fields = has_nonstatic_fields;
4876 
4877   // A value type is naturally atomic if it has just one field, and
4878   // that field is simple enough.
4879   info->_is_naturally_atomic = (is_value_type() &&
4880                                 !super_has_nonstatic_fields &&
4881                                 (nonstatic_fields_count <= 1) &&
4882                                 (not_atomic_value_types == 0) &&
4883                                 (nonstatic_contended_count == 0));
4884   // This may be too restrictive, since if all the fields fit in 64
4885   // bits we could make the decision to align instances of this class
4886   // to 64-bit boundaries, and load and store them as single words.
4887   // And on machines which supported larger atomics we could similarly
4888   // allow larger values to be atomic, if properly aligned.
4889 }
4890 
4891 void ClassFileParser::set_precomputed_flags(InstanceKlass* ik) {
4892   assert(ik != NULL, "invariant");
4893 
4894   const Klass* const super = ik->super();
4895 
4896   // Check if this klass has an empty finalize method (i.e. one with return bytecode only),
4897   // in which case we don't have to register objects as finalizable
4898   if (!_has_empty_finalizer) {
4899     if (_has_finalizer ||
4900         (super != NULL && super->has_finalizer())) {
4901       ik->set_has_finalizer();
4902     }
4903   }
4904 
4905 #ifdef ASSERT
4906   bool f = false;
4907   const Method* const m = ik->lookup_method(vmSymbols::finalize_method_name(),
4908                                            vmSymbols::void_method_signature());


6004 
6005           if (!match) {
6006             char buf[1000];
6007             tty->print("Compiler intrinsic is defined for method [%s], "
6008                        "but the method is not available in class [%s].%s",
6009                         vmIntrinsics::short_name_as_C_string(vmIntrinsics::ID_from(id),
6010                                                              buf, sizeof(buf)),
6011                         ik->name()->as_C_string(),
6012                         NOT_DEBUG("") DEBUG_ONLY(" Exiting.")
6013             );
6014             tty->cr();
6015             DEBUG_ONLY(vm_exit(1));
6016           }
6017         }
6018       } // end for
6019     } // CheckIntrinsics
6020 #endif // ASSERT
6021   }
6022 }
6023 
6024 // Called from a factory method in KlassFactory, not from this file.
6025 InstanceKlass* ClassFileParser::create_instance_klass(bool changed_by_loadhook, TRAPS) {
6026   if (_klass != NULL) {
6027     return _klass;
6028   }
6029 
6030   InstanceKlass* const ik =
6031     InstanceKlass::allocate_instance_klass(*this, CHECK_NULL);
6032 
6033   fill_instance_klass(ik, changed_by_loadhook, CHECK_NULL);
6034 
6035   assert(_klass == ik, "invariant");
6036 
6037 
6038   if (ik->should_store_fingerprint()) {
6039     ik->store_fingerprint(_stream->compute_fingerprint());
6040   }
6041 
6042   ik->set_has_passed_fingerprint_check(false);
6043   if (UseAOT && ik->supers_have_passed_fingerprint_checks()) {
6044     uint64_t aot_fp = AOTLoader::get_saved_fingerprint(ik);


6074   const bool publicize = !is_internal();
6075 
6076   _loader_data->add_class(ik, publicize);
6077 
6078   set_klass_to_deallocate(ik);
6079 
6080   assert(_field_info != NULL, "invariant");
6081   assert(ik->static_field_size() == _field_info->_static_field_size, "sanity");
6082   assert(ik->nonstatic_oop_map_count() == _field_info->oop_map_blocks->_nonstatic_oop_map_count,
6083          "sanity");
6084 
6085   assert(ik->is_instance_klass(), "sanity");
6086   assert(ik->size_helper() == _field_info->_instance_size, "sanity");
6087 
6088   // Fill in information already parsed
6089   ik->set_should_verify_class(_need_verify);
6090 
6091   // Not yet: supers are done below to support the new subtype-checking fields
6092   ik->set_nonstatic_field_size(_field_info->_nonstatic_field_size);
6093   ik->set_has_nonstatic_fields(_field_info->_has_nonstatic_fields);
6094   if (_field_info->_is_naturally_atomic && ik->is_value()) {
6095     ik->set_is_naturally_atomic();
6096   }
6097   if (_is_empty_value) {
6098     ik->set_is_empty_value();
6099   }
6100   assert(_fac != NULL, "invariant");
6101   ik->set_static_oop_field_count(_fac->count[STATIC_OOP] + _fac->count[STATIC_FLATTENABLE]);
6102 
6103   // this transfers ownership of a lot of arrays from
6104   // the parser onto the InstanceKlass*
6105   apply_parsed_class_metadata(ik, _java_fields_count, CHECK);
6106 
6107   // note that is not safe to use the fields in the parser from this point on
6108   assert(NULL == _cp, "invariant");
6109   assert(NULL == _fields, "invariant");
6110   assert(NULL == _methods, "invariant");
6111   assert(NULL == _inner_classes, "invariant");
6112   assert(NULL == _nest_members, "invariant");
6113   assert(NULL == _local_interfaces, "invariant");
6114   assert(NULL == _combined_annotations, "invariant");
6115   assert(NULL == _record_components, "invariant");
6116 


6126   // has to be changed accordingly.
6127   ik->set_initial_method_idnum(ik->methods()->length());
6128 
6129   ik->set_this_class_index(_this_class_index);
6130 
6131   if (is_unsafe_anonymous()) {
6132     // _this_class_index is a CONSTANT_Class entry that refers to this
6133     // anonymous class itself. If this class needs to refer to its own methods or
6134     // fields, it would use a CONSTANT_MethodRef, etc, which would reference
6135     // _this_class_index. However, because this class is anonymous (it's
6136     // not stored in SystemDictionary), _this_class_index cannot be resolved
6137     // with ConstantPool::klass_at_impl, which does a SystemDictionary lookup.
6138     // Therefore, we must eagerly resolve _this_class_index now.
6139     ik->constants()->klass_at_put(_this_class_index, ik);
6140   }
6141 
6142   ik->set_minor_version(_minor_version);
6143   ik->set_major_version(_major_version);
6144   ik->set_has_nonstatic_concrete_methods(_has_nonstatic_concrete_methods);
6145   ik->set_declares_nonstatic_concrete_methods(_declares_nonstatic_concrete_methods);
6146   if (_is_declared_atomic) {
6147     ik->set_is_declared_atomic();
6148   }
6149 
6150   if (_unsafe_anonymous_host != NULL) {
6151     assert (ik->is_unsafe_anonymous(), "should be the same");
6152     ik->set_unsafe_anonymous_host(_unsafe_anonymous_host);
6153   }
6154 
6155   // Set PackageEntry for this_klass
6156   oop cl = ik->class_loader();
6157   Handle clh = Handle(THREAD, java_lang_ClassLoader::non_reflection_class_loader(cl));
6158   ClassLoaderData* cld = ClassLoaderData::class_loader_data_or_null(clh());
6159   ik->set_package(cld, CHECK);
6160 
6161   const Array<Method*>* const methods = ik->methods();
6162   assert(methods != NULL, "invariant");
6163   const int methods_len = methods->length();
6164 
6165   check_methods_for_intrinsics(ik, methods);
6166 
6167   // Fill in field values obtained by parse_classfile_attributes
6168   if (_parsed_annotations->has_any_annotations()) {


6461   _bad_constant_seen(0),
6462   _synthetic_flag(false),
6463   _sde_length(false),
6464   _sde_buffer(NULL),
6465   _sourcefile_index(0),
6466   _generic_signature_index(0),
6467   _major_version(0),
6468   _minor_version(0),
6469   _this_class_index(0),
6470   _super_class_index(0),
6471   _itfs_len(0),
6472   _java_fields_count(0),
6473   _need_verify(false),
6474   _relax_verify(false),
6475   _has_nonstatic_concrete_methods(false),
6476   _declares_nonstatic_concrete_methods(false),
6477   _has_final_method(false),
6478   _has_contended_fields(false),
6479   _has_flattenable_fields(false),
6480   _is_empty_value(false),
6481   _is_naturally_atomic(false),
6482   _is_declared_atomic(false),
6483   _has_finalizer(false),
6484   _has_empty_finalizer(false),
6485   _has_vanilla_constructor(false),
6486   _max_bootstrap_specifier_index(-1) {
6487 
6488   _class_name = name != NULL ? name : vmSymbols::unknown_class_name();
6489   _class_name->increment_refcount();
6490 
6491   assert(THREAD->is_Java_thread(), "invariant");
6492   assert(_loader_data != NULL, "invariant");
6493   assert(stream != NULL, "invariant");
6494   assert(_stream != NULL, "invariant");
6495   assert(_stream->buffer() == _stream->current(), "invariant");
6496   assert(_class_name != NULL, "invariant");
6497   assert(0 == _access_flags.as_int(), "invariant");
6498 
6499   // Figure out whether we can skip format checking (matching classic VM behavior)
6500   if (DumpSharedSpaces) {
6501     // verify == true means it's a 'remote' class (i.e., non-boot class)
6502     // Verification decision is based on BytecodeVerificationRemote flag


6802           classlist_file->flush();
6803         }
6804       }
6805     }
6806 #endif
6807   }
6808 
6809   // SUPERKLASS
6810   _super_class_index = stream->get_u2_fast();
6811   _super_klass = parse_super_class(cp,
6812                                    _super_class_index,
6813                                    _need_verify,
6814                                    CHECK);
6815 
6816   // Interfaces
6817   _itfs_len = stream->get_u2_fast();
6818   parse_interfaces(stream,
6819                    _itfs_len,
6820                    cp,
6821                    &_has_nonstatic_concrete_methods,
6822                    &_is_declared_atomic,
6823                    CHECK);
6824 
6825   assert(_local_interfaces != NULL, "invariant");
6826 
6827   // Fields (offsets are filled in later)
6828   _fac = new FieldAllocationCount();
6829   parse_fields(stream,
6830                is_interface(),
6831                is_value_type(),
6832                _fac,
6833                cp,
6834                cp_size,
6835                &_java_fields_count,
6836                CHECK);
6837 
6838   assert(_fields != NULL, "invariant");
6839 
6840   // Methods
6841   AccessFlags promoted_flags;
6842   parse_methods(stream,
6843                 is_interface(),
6844                 is_value_type(),
6845                 &promoted_flags,
6846                 &_has_final_method,
6847                 &_declares_nonstatic_concrete_methods,
6848                 CHECK);
6849 
6850   assert(_methods != NULL, "invariant");
6851 
6852   // promote flags from parse_methods() to the klass' flags
6853   _access_flags.add_promoted_flags(promoted_flags.as_int());
6854 
6855   if (_declares_nonstatic_concrete_methods) {
6856     _has_nonstatic_concrete_methods = true;
6857   }
6858 
6859   // Additional attributes/annotations
6860   _parsed_annotations = new ClassAnnotationCollector();
6861   parse_classfile_attributes(stream, cp, _parsed_annotations, CHECK);
6862 
6863   assert(_inner_classes != NULL, "invariant");
6864 


6873 
6874   // all bytes in stream read and parsed
6875 }
6876 
6877 void ClassFileParser::post_process_parsed_stream(const ClassFileStream* const stream,
6878                                                  ConstantPool* cp,
6879                                                  TRAPS) {
6880   assert(stream != NULL, "invariant");
6881   assert(stream->at_eos(), "invariant");
6882   assert(cp != NULL, "invariant");
6883   assert(_loader_data != NULL, "invariant");
6884 
6885   if (_class_name == vmSymbols::java_lang_Object()) {
6886     check_property(_local_interfaces == Universe::the_empty_instance_klass_array(),
6887                    "java.lang.Object cannot implement an interface in class file %s",
6888                    CHECK);
6889   }
6890   // We check super class after class file is parsed and format is checked
6891   if (_super_class_index > 0 && NULL ==_super_klass) {
6892     Symbol* const super_class_name = cp->klass_name_at(_super_class_index);
6893     if (is_interface()) {
6894       // Before attempting to resolve the superclass, check for class format
6895       // errors not checked yet.
6896       guarantee_property(super_class_name == vmSymbols::java_lang_Object(),
6897         "Interfaces must have java.lang.Object as superclass in class file %s",
6898         CHECK);
6899     }
6900     Handle loader(THREAD, _loader_data->class_loader());
6901     _super_klass = (const InstanceKlass*)
6902                        SystemDictionary::resolve_super_or_fail(_class_name,
6903                                                                super_class_name,
6904                                                                loader,
6905                                                                _protection_domain,
6906                                                                true,
6907                                                                CHECK);
6908   }
6909 
6910   if (_super_klass != NULL) {
6911     if (_super_klass->has_nonstatic_concrete_methods()) {
6912       _has_nonstatic_concrete_methods = true;
6913     }
6914     if (_super_klass->is_declared_atomic()) {
6915       _is_declared_atomic = true;
6916     }
6917 
6918     if (_super_klass->is_interface()) {
6919       ResourceMark rm(THREAD);
6920       Exceptions::fthrow(
6921         THREAD_AND_LOCATION,
6922         vmSymbols::java_lang_IncompatibleClassChangeError(),
6923         "class %s has interface %s as super class",
6924         _class_name->as_klass_external_name(),
6925         _super_klass->external_name()
6926       );
6927       return;
6928     }
6929 
6930     // For a value class, only java/lang/Object is an acceptable super class
6931     if (_access_flags.get_flags() & JVM_ACC_VALUE) {
6932       guarantee_property(_super_klass->name() == vmSymbols::java_lang_Object(),
6933         "Value type must have java.lang.Object as superclass in class file %s",
6934         CHECK);
6935     }
6936 
6937     // Make sure super class is not final
6938     if (_super_klass->is_final()) {
6939       THROW_MSG(vmSymbols::java_lang_VerifyError(), "Cannot inherit from final class");
6940     }
6941   }
6942 
6943   if (_class_name == vmSymbols::java_lang_NonTearable() && _loader_data->class_loader() == NULL) {
6944     // This is the original source of this condition.
6945     // It propagates by inheritance, as if testing "instanceof NonTearable".
6946     _is_declared_atomic = true;
6947   } else if (*ForceNonTearable != '\0') {
6948     // Allow a command line switch to force the same atomicity property:
6949     const char* class_name_str = _class_name->as_C_string();
6950     if (StringUtils::class_list_match(ForceNonTearable, class_name_str)) {
6951       _is_declared_atomic = true;
6952     }
6953   }
6954 
6955   // Compute the transitive list of all unique interfaces implemented by this class
6956   _transitive_interfaces =
6957     compute_transitive_interfaces(_super_klass,
6958                                   _local_interfaces,
6959                                   _loader_data,
6960                                   CHECK);
6961 
6962   assert(_transitive_interfaces != NULL, "invariant");
6963 
6964   // sort methods
6965   _method_ordering = sort_methods(_methods);
6966 
6967   _all_mirandas = new GrowableArray<Method*>(20);
6968 
6969   Handle loader(THREAD, _loader_data->class_loader());
6970   klassVtable::compute_vtable_size_and_num_mirandas(&_vtable_size,
6971                                                     &_num_miranda_methods,
6972                                                     _all_mirandas,
6973                                                     _super_klass,
6974                                                     _methods,
6975                                                     _access_flags,
6976                                                     _major_version,
6977                                                     loader,
6978                                                     _class_name,
6979                                                     _local_interfaces,
6980                                                     CHECK);
6981 
6982   // Size of Java itable (in words)
6983   _itable_size = is_interface() ? 0 :
6984     klassItable::compute_itable_size(_transitive_interfaces);
6985 
6986   assert(_fac != NULL, "invariant");
6987   assert(_parsed_annotations != NULL, "invariant");
6988 
6989 
6990   for (AllFieldStream fs(_fields, cp); !fs.done(); fs.next()) {
6991     if (fs.is_flattenable() && !fs.access_flags().is_static()) {
6992       // Pre-load value class
6993       Klass* klass = SystemDictionary::resolve_flattenable_field_or_fail(&fs,
6994           Handle(THREAD, _loader_data->class_loader()),
6995           _protection_domain, true, CHECK);
6996       assert(klass != NULL, "Sanity check");
6997       assert(klass->access_flags().is_value_type(), "Value type expected");
6998       _has_flattenable_fields = true;
6999     }
7000   }
7001 
7002   _field_info = new FieldLayoutInfo();
7003   if (UseNewLayout) {


< prev index next >