< prev index next >

src/hotspot/share/classfile/classFileParser.cpp

Print this page
rev 58565 : 8238358: Implementation of JEP 371: Hidden Classes
Reviewed-by: duke
Contributed-by: mandy.chung@oracle.com, lois.foltan@oracle.com, david.holmes@oracle.com, harold.seigel@oracle.com, serguei.spitsyn@oracle.com, alex.buckley@oracle.com, jamsheed.c.m@oracle.com


1075     _method_DontInline,
1076     _method_InjectedProfile,
1077     _method_LambdaForm_Compiled,
1078     _method_Hidden,
1079     _method_HotSpotIntrinsicCandidate,
1080     _jdk_internal_vm_annotation_Contended,
1081     _field_Stable,
1082     _jdk_internal_vm_annotation_ReservedStackAccess,
1083     _annotation_LIMIT
1084   };
1085   const Location _location;
1086   int _annotations_present;
1087   u2 _contended_group;
1088 
1089   AnnotationCollector(Location location)
1090     : _location(location), _annotations_present(0)
1091   {
1092     assert((int)_annotation_LIMIT <= (int)sizeof(_annotations_present) * BitsPerByte, "");
1093   }
1094   // If this annotation name has an ID, report it (or _none).
1095   ID annotation_index(const ClassLoaderData* loader_data, const Symbol* name);
1096   // Set the annotation name:
1097   void set_annotation(ID id) {
1098     assert((int)id >= 0 && (int)id < (int)_annotation_LIMIT, "oob");
1099     _annotations_present |= nth_bit((int)id);
1100   }
1101 
1102   void remove_annotation(ID id) {
1103     assert((int)id >= 0 && (int)id < (int)_annotation_LIMIT, "oob");
1104     _annotations_present &= ~nth_bit((int)id);
1105   }
1106 
1107   // Report if the annotation is present.
1108   bool has_any_annotations() const { return _annotations_present != 0; }
1109   bool has_annotation(ID id) const { return (nth_bit((int)id) & _annotations_present) != 0; }
1110 
1111   void set_contended_group(u2 group) { _contended_group = group; }
1112   u2 contended_group() const { return _contended_group; }
1113 
1114   bool is_contended() const { return has_annotation(_jdk_internal_vm_annotation_Contended); }
1115 


1208       int nval = Bytes::get_Java_u2((address)buffer + index - 2);
1209       while (--nval >= 0 && index < limit) {
1210         index = skip_annotation_value(buffer, limit, index);
1211       }
1212     }
1213     break;
1214     case '@':
1215       index = skip_annotation(buffer, limit, index);
1216       break;
1217     default:
1218       return limit;  //  bad tag byte
1219   }
1220   return index;
1221 }
1222 
1223 // Sift through annotations, looking for those significant to the VM:
1224 static void parse_annotations(const ConstantPool* const cp,
1225                               const u1* buffer, int limit,
1226                               AnnotationCollector* coll,
1227                               ClassLoaderData* loader_data,

1228                               TRAPS) {
1229 
1230   assert(cp != NULL, "invariant");
1231   assert(buffer != NULL, "invariant");
1232   assert(coll != NULL, "invariant");
1233   assert(loader_data != NULL, "invariant");
1234 
1235   // annotations := do(nann:u2) {annotation}
1236   int index = 2; // read nann
1237   if (index >= limit)  return;
1238   int nann = Bytes::get_Java_u2((address)buffer + index - 2);
1239   enum {  // initial annotation layout
1240     atype_off = 0,      // utf8 such as 'Ljava/lang/annotation/Retention;'
1241     count_off = 2,      // u2   such as 1 (one value)
1242     member_off = 4,     // utf8 such as 'value'
1243     tag_off = 6,        // u1   such as 'c' (type) or 'e' (enum)
1244     e_tag_val = 'e',
1245     e_type_off = 7,   // utf8 such as 'Ljava/lang/annotation/RetentionPolicy;'
1246     e_con_off = 9,    // utf8 payload, such as 'SOURCE', 'CLASS', 'RUNTIME'
1247     e_size = 11,     // end of 'e' annotation


1253     s_size = 9,
1254     min_size = 6        // smallest possible size (zero members)
1255   };
1256   // Cannot add min_size to index in case of overflow MAX_INT
1257   while ((--nann) >= 0 && (index - 2 <= limit - min_size)) {
1258     int index0 = index;
1259     index = skip_annotation(buffer, limit, index);
1260     const u1* const abase = buffer + index0;
1261     const int atype = Bytes::get_Java_u2((address)abase + atype_off);
1262     const int count = Bytes::get_Java_u2((address)abase + count_off);
1263     const Symbol* const aname = check_symbol_at(cp, atype);
1264     if (aname == NULL)  break;  // invalid annotation name
1265     const Symbol* member = NULL;
1266     if (count >= 1) {
1267       const int member_index = Bytes::get_Java_u2((address)abase + member_off);
1268       member = check_symbol_at(cp, member_index);
1269       if (member == NULL)  break;  // invalid member name
1270     }
1271 
1272     // Here is where parsing particular annotations will take place.
1273     AnnotationCollector::ID id = coll->annotation_index(loader_data, aname);
1274     if (AnnotationCollector::_unknown == id)  continue;
1275     coll->set_annotation(id);
1276 
1277     if (AnnotationCollector::_jdk_internal_vm_annotation_Contended == id) {
1278       // @Contended can optionally specify the contention group.
1279       //
1280       // Contended group defines the equivalence class over the fields:
1281       // the fields within the same contended group are not treated distinct.
1282       // The only exception is default group, which does not incur the
1283       // equivalence. Naturally, contention group for classes is meaningless.
1284       //
1285       // While the contention group is specified as String, annotation
1286       // values are already interned, and we might as well use the constant
1287       // pool index as the group tag.
1288       //
1289       u2 group_index = 0; // default contended group
1290       if (count == 1
1291         && s_size == (index - index0)  // match size
1292         && s_tag_val == *(abase + tag_off)
1293         && member == vmSymbols::value_name()) {


1379         if (attribute_length != 2) {
1380           classfile_parse_error(
1381             "Wrong size %u for field's Signature attribute in class file %s",
1382             attribute_length, CHECK);
1383         }
1384         generic_signature_index = parse_generic_signature_attribute(cfs, CHECK);
1385       } else if (attribute_name == vmSymbols::tag_runtime_visible_annotations()) {
1386         if (runtime_visible_annotations != NULL) {
1387           classfile_parse_error(
1388             "Multiple RuntimeVisibleAnnotations attributes for field in class file %s", CHECK);
1389         }
1390         runtime_visible_annotations_length = attribute_length;
1391         runtime_visible_annotations = cfs->current();
1392         assert(runtime_visible_annotations != NULL, "null visible annotations");
1393         cfs->guarantee_more(runtime_visible_annotations_length, CHECK);
1394         parse_annotations(cp,
1395                           runtime_visible_annotations,
1396                           runtime_visible_annotations_length,
1397                           parsed_annotations,
1398                           _loader_data,

1399                           CHECK);
1400         cfs->skip_u1_fast(runtime_visible_annotations_length);
1401       } else if (attribute_name == vmSymbols::tag_runtime_invisible_annotations()) {
1402         if (runtime_invisible_annotations_exists) {
1403           classfile_parse_error(
1404             "Multiple RuntimeInvisibleAnnotations attributes for field in class file %s", CHECK);
1405         }
1406         runtime_invisible_annotations_exists = true;
1407         if (PreserveAllAnnotations) {
1408           runtime_invisible_annotations_length = attribute_length;
1409           runtime_invisible_annotations = cfs->current();
1410           assert(runtime_invisible_annotations != NULL, "null invisible annotations");
1411         }
1412         cfs->skip_u1(attribute_length, CHECK);
1413       } else if (attribute_name == vmSymbols::tag_runtime_visible_type_annotations()) {
1414         if (runtime_visible_type_annotations != NULL) {
1415           classfile_parse_error(
1416             "Multiple RuntimeVisibleTypeAnnotations attributes for field in class file %s", CHECK);
1417         }
1418         runtime_visible_type_annotations_length = attribute_length;


2042   }
2043   return checked_exceptions_start;
2044 }
2045 
2046 void ClassFileParser::throwIllegalSignature(const char* type,
2047                                             const Symbol* name,
2048                                             const Symbol* sig,
2049                                             TRAPS) const {
2050   assert(name != NULL, "invariant");
2051   assert(sig != NULL, "invariant");
2052 
2053   ResourceMark rm(THREAD);
2054   Exceptions::fthrow(THREAD_AND_LOCATION,
2055       vmSymbols::java_lang_ClassFormatError(),
2056       "%s \"%s\" in class %s has illegal signature \"%s\"", type,
2057       name->as_C_string(), _class_name->as_C_string(), sig->as_C_string());
2058 }
2059 
2060 AnnotationCollector::ID
2061 AnnotationCollector::annotation_index(const ClassLoaderData* loader_data,
2062                                       const Symbol* name) {

2063   const vmSymbols::SID sid = vmSymbols::find_sid(name);
2064   // Privileged code can use all annotations.  Other code silently drops some.
2065   const bool privileged = loader_data->is_the_null_class_loader_data() ||
2066                           loader_data->is_platform_class_loader_data() ||
2067                           loader_data->is_unsafe_anonymous();
2068   switch (sid) {
2069     case vmSymbols::VM_SYMBOL_ENUM_NAME(reflect_CallerSensitive_signature): {
2070       if (_location != _in_method)  break;  // only allow for methods
2071       if (!privileged)              break;  // only allow in privileged code
2072       return _method_CallerSensitive;
2073     }
2074     case vmSymbols::VM_SYMBOL_ENUM_NAME(jdk_internal_vm_annotation_ForceInline_signature): {
2075       if (_location != _in_method)  break;  // only allow for methods
2076       if (!privileged)              break;  // only allow in privileged code
2077       return _method_ForceInline;
2078     }
2079     case vmSymbols::VM_SYMBOL_ENUM_NAME(jdk_internal_vm_annotation_DontInline_signature): {
2080       if (_location != _in_method)  break;  // only allow for methods
2081       if (!privileged)              break;  // only allow in privileged code
2082       return _method_DontInline;
2083     }
2084     case vmSymbols::VM_SYMBOL_ENUM_NAME(java_lang_invoke_InjectedProfile_signature): {
2085       if (_location != _in_method)  break;  // only allow for methods
2086       if (!privileged)              break;  // only allow in privileged code
2087       return _method_InjectedProfile;


2654           classfile_parse_error(
2655             "Invalid Signature attribute length %u in class file %s",
2656             method_attribute_length, CHECK_NULL);
2657         }
2658         generic_signature_index = parse_generic_signature_attribute(cfs, CHECK_NULL);
2659       } else if (method_attribute_name == vmSymbols::tag_runtime_visible_annotations()) {
2660         if (runtime_visible_annotations != NULL) {
2661           classfile_parse_error(
2662             "Multiple RuntimeVisibleAnnotations attributes for method in class file %s",
2663             CHECK_NULL);
2664         }
2665         runtime_visible_annotations_length = method_attribute_length;
2666         runtime_visible_annotations = cfs->current();
2667         assert(runtime_visible_annotations != NULL, "null visible annotations");
2668         cfs->guarantee_more(runtime_visible_annotations_length, CHECK_NULL);
2669         parse_annotations(cp,
2670                           runtime_visible_annotations,
2671                           runtime_visible_annotations_length,
2672                           &parsed_annotations,
2673                           _loader_data,

2674                           CHECK_NULL);
2675         cfs->skip_u1_fast(runtime_visible_annotations_length);
2676       } else if (method_attribute_name == vmSymbols::tag_runtime_invisible_annotations()) {
2677         if (runtime_invisible_annotations_exists) {
2678           classfile_parse_error(
2679             "Multiple RuntimeInvisibleAnnotations attributes for method in class file %s",
2680             CHECK_NULL);
2681         }
2682         runtime_invisible_annotations_exists = true;
2683         if (PreserveAllAnnotations) {
2684           runtime_invisible_annotations_length = method_attribute_length;
2685           runtime_invisible_annotations = cfs->current();
2686           assert(runtime_invisible_annotations != NULL, "null invisible annotations");
2687         }
2688         cfs->skip_u1(method_attribute_length, CHECK_NULL);
2689       } else if (method_attribute_name == vmSymbols::tag_runtime_visible_parameter_annotations()) {
2690         if (runtime_visible_parameter_annotations != NULL) {
2691           classfile_parse_error(
2692             "Multiple RuntimeVisibleParameterAnnotations attributes for method in class file %s",
2693             CHECK_NULL);


2848                                                 checked_exceptions_length * sizeof(CheckedExceptionElement),
2849                                                 sizeof(u2));
2850   }
2851 
2852   // Copy class file LVT's/LVTT's into the HotSpot internal LVT.
2853   if (total_lvt_length > 0) {
2854     promoted_flags->set_has_localvariable_table();
2855     copy_localvariable_table(m->constMethod(),
2856                              lvt_cnt,
2857                              localvariable_table_length,
2858                              localvariable_table_start,
2859                              lvtt_cnt,
2860                              localvariable_type_table_length,
2861                              localvariable_type_table_start,
2862                              CHECK_NULL);
2863   }
2864 
2865   if (parsed_annotations.has_any_annotations())
2866     parsed_annotations.apply_to(methodHandle(THREAD, m));
2867 




2868   // Copy annotations
2869   copy_method_annotations(m->constMethod(),
2870                           runtime_visible_annotations,
2871                           runtime_visible_annotations_length,
2872                           runtime_invisible_annotations,
2873                           runtime_invisible_annotations_length,
2874                           runtime_visible_parameter_annotations,
2875                           runtime_visible_parameter_annotations_length,
2876                           runtime_invisible_parameter_annotations,
2877                           runtime_invisible_parameter_annotations_length,
2878                           runtime_visible_type_annotations,
2879                           runtime_visible_type_annotations_length,
2880                           runtime_invisible_type_annotations,
2881                           runtime_invisible_type_annotations_length,
2882                           annotation_default,
2883                           annotation_default_length,
2884                           CHECK_NULL);
2885 
2886   if (name == vmSymbols::finalize_method_name() &&
2887       signature == vmSymbols::void_method_signature()) {


3579         if (attribute_length != 2) {
3580           classfile_parse_error(
3581             "Wrong Signature attribute length %u in class file %s",
3582             attribute_length, CHECK);
3583         }
3584         parse_classfile_signature_attribute(cfs, CHECK);
3585       } else if (tag == vmSymbols::tag_runtime_visible_annotations()) {
3586         if (runtime_visible_annotations != NULL) {
3587           classfile_parse_error(
3588             "Multiple RuntimeVisibleAnnotations attributes in class file %s", CHECK);
3589         }
3590         runtime_visible_annotations_length = attribute_length;
3591         runtime_visible_annotations = cfs->current();
3592         assert(runtime_visible_annotations != NULL, "null visible annotations");
3593         cfs->guarantee_more(runtime_visible_annotations_length, CHECK);
3594         parse_annotations(cp,
3595                           runtime_visible_annotations,
3596                           runtime_visible_annotations_length,
3597                           parsed_annotations,
3598                           _loader_data,

3599                           CHECK);
3600         cfs->skip_u1_fast(runtime_visible_annotations_length);
3601       } else if (tag == vmSymbols::tag_runtime_invisible_annotations()) {
3602         if (runtime_invisible_annotations_exists) {
3603           classfile_parse_error(
3604             "Multiple RuntimeInvisibleAnnotations attributes in class file %s", CHECK);
3605         }
3606         runtime_invisible_annotations_exists = true;
3607         if (PreserveAllAnnotations) {
3608           runtime_invisible_annotations_length = attribute_length;
3609           runtime_invisible_annotations = cfs->current();
3610           assert(runtime_invisible_annotations != NULL, "null invisible annotations");
3611         }
3612         cfs->skip_u1(attribute_length, CHECK);
3613       } else if (tag == vmSymbols::tag_enclosing_method()) {
3614         if (parsed_enclosingmethod_attribute) {
3615           classfile_parse_error("Multiple EnclosingMethod attributes in class file %s", CHECK);
3616         } else {
3617           parsed_enclosingmethod_attribute = true;
3618         }


5575 
5576           if (!match) {
5577             char buf[1000];
5578             tty->print("Compiler intrinsic is defined for method [%s], "
5579                        "but the method is not available in class [%s].%s",
5580                         vmIntrinsics::short_name_as_C_string(vmIntrinsics::ID_from(id),
5581                                                              buf, sizeof(buf)),
5582                         ik->name()->as_C_string(),
5583                         NOT_DEBUG("") DEBUG_ONLY(" Exiting.")
5584             );
5585             tty->cr();
5586             DEBUG_ONLY(vm_exit(1));
5587           }
5588         }
5589       } // end for
5590     } // CheckIntrinsics
5591 #endif // ASSERT
5592   }
5593 }
5594 
5595 InstanceKlass* ClassFileParser::create_instance_klass(bool changed_by_loadhook, TRAPS) {


5596   if (_klass != NULL) {
5597     return _klass;
5598   }
5599 
5600   InstanceKlass* const ik =
5601     InstanceKlass::allocate_instance_klass(*this, CHECK_NULL);
5602 
5603   fill_instance_klass(ik, changed_by_loadhook, CHECK_NULL);




5604 
5605   assert(_klass == ik, "invariant");
5606 
5607 
5608   if (ik->should_store_fingerprint()) {
5609     ik->store_fingerprint(_stream->compute_fingerprint());
5610   }
5611 
5612   ik->set_has_passed_fingerprint_check(false);
5613   if (UseAOT && ik->supers_have_passed_fingerprint_checks()) {
5614     uint64_t aot_fp = AOTLoader::get_saved_fingerprint(ik);
5615     uint64_t fp = ik->has_stored_fingerprint() ? ik->get_stored_fingerprint() : _stream->compute_fingerprint();
5616     if (aot_fp != 0 && aot_fp == fp) {
5617       // This class matches with a class saved in an AOT library
5618       ik->set_has_passed_fingerprint_check(true);
5619     } else {
5620       ResourceMark rm;
5621       log_info(class, fingerprint)("%s :  expected = " PTR64_FORMAT " actual = " PTR64_FORMAT,
5622                                  ik->external_name(), aot_fp, _stream->compute_fingerprint());
5623     }
5624   }
5625 
5626   return ik;
5627 }
5628 
5629 void ClassFileParser::fill_instance_klass(InstanceKlass* ik, bool changed_by_loadhook, TRAPS) {



5630   assert(ik != NULL, "invariant");
5631 
5632   // Set name and CLD before adding to CLD
5633   ik->set_class_loader_data(_loader_data);
5634   ik->set_name(_class_name);
5635 
5636   // Add all classes to our internal class loader list here,
5637   // including classes in the bootstrap (NULL) class loader.
5638   const bool publicize = !is_internal();
5639 
5640   _loader_data->add_class(ik, publicize);
5641 
5642   set_klass_to_deallocate(ik);
5643 
5644   assert(_field_info != NULL, "invariant");
5645   assert(ik->static_field_size() == _field_info->_static_field_size, "sanity");
5646   assert(ik->nonstatic_oop_map_count() == _field_info->oop_map_blocks->_nonstatic_oop_map_count,
5647          "sanity");
5648 
5649   assert(ik->is_instance_klass(), "sanity");
5650   assert(ik->size_helper() == _field_info->_instance_size, "sanity");
5651 
5652   // Fill in information already parsed
5653   ik->set_should_verify_class(_need_verify);
5654 
5655   // Not yet: supers are done below to support the new subtype-checking fields
5656   ik->set_nonstatic_field_size(_field_info->_nonstatic_field_size);
5657   ik->set_has_nonstatic_fields(_field_info->_has_nonstatic_fields);
5658   assert(_fac != NULL, "invariant");
5659   ik->set_static_oop_field_count(_fac->count[STATIC_OOP]);
5660 
5661   // this transfers ownership of a lot of arrays from
5662   // the parser onto the InstanceKlass*
5663   apply_parsed_class_metadata(ik, _java_fields_count, CHECK);
5664 





5665   // note that is not safe to use the fields in the parser from this point on
5666   assert(NULL == _cp, "invariant");
5667   assert(NULL == _fields, "invariant");
5668   assert(NULL == _methods, "invariant");
5669   assert(NULL == _inner_classes, "invariant");
5670   assert(NULL == _nest_members, "invariant");
5671   assert(NULL == _local_interfaces, "invariant");
5672   assert(NULL == _combined_annotations, "invariant");
5673   assert(NULL == _record_components, "invariant");
5674 
5675   if (_has_final_method) {
5676     ik->set_has_final_method();
5677   }
5678 
5679   ik->copy_method_ordering(_method_ordering, CHECK);
5680   // The InstanceKlass::_methods_jmethod_ids cache
5681   // is managed on the assumption that the initial cache
5682   // size is equal to the number of methods in the class. If
5683   // that changes, then InstanceKlass::idnum_can_increment()
5684   // has to be changed accordingly.
5685   ik->set_initial_method_idnum(ik->methods()->length());
5686 
5687   ik->set_this_class_index(_this_class_index);
5688 
5689   if (is_unsafe_anonymous()) {
5690     // _this_class_index is a CONSTANT_Class entry that refers to this
5691     // anonymous class itself. If this class needs to refer to its own methods or
5692     // fields, it would use a CONSTANT_MethodRef, etc, which would reference
5693     // _this_class_index. However, because this class is anonymous (it's
5694     // not stored in SystemDictionary), _this_class_index cannot be resolved
5695     // with ConstantPool::klass_at_impl, which does a SystemDictionary lookup.
5696     // Therefore, we must eagerly resolve _this_class_index now.
5697     ik->constants()->klass_at_put(_this_class_index, ik);
5698   }
5699 
5700   ik->set_minor_version(_minor_version);
5701   ik->set_major_version(_major_version);
5702   ik->set_has_nonstatic_concrete_methods(_has_nonstatic_concrete_methods);
5703   ik->set_declares_nonstatic_concrete_methods(_declares_nonstatic_concrete_methods);
5704 
5705   if (_unsafe_anonymous_host != NULL) {
5706     assert (ik->is_unsafe_anonymous(), "should be the same");
5707     ik->set_unsafe_anonymous_host(_unsafe_anonymous_host);
5708   }



5709 
5710   // Set PackageEntry for this_klass
5711   oop cl = ik->class_loader();
5712   Handle clh = Handle(THREAD, java_lang_ClassLoader::non_reflection_class_loader(cl));
5713   ClassLoaderData* cld = ClassLoaderData::class_loader_data_or_null(clh());
5714   ik->set_package(cld, CHECK);
5715 
5716   const Array<Method*>* const methods = ik->methods();
5717   assert(methods != NULL, "invariant");
5718   const int methods_len = methods->length();
5719 
5720   check_methods_for_intrinsics(ik, methods);
5721 
5722   // Fill in field values obtained by parse_classfile_attributes
5723   if (_parsed_annotations->has_any_annotations()) {
5724     _parsed_annotations->apply_to(ik);
5725   }
5726 
5727   apply_parsed_class_attributes(ik);
5728 


5768   check_final_method_override(ik, CHECK);
5769 
5770   // reject static interface methods prior to Java 8
5771   if (ik->is_interface() && _major_version < JAVA_8_VERSION) {
5772     check_illegal_static_method(ik, CHECK);
5773   }
5774 
5775   // Obtain this_klass' module entry
5776   ModuleEntry* module_entry = ik->module();
5777   assert(module_entry != NULL, "module_entry should always be set");
5778 
5779   // Obtain java.lang.Module
5780   Handle module_handle(THREAD, module_entry->module());
5781 
5782   // Allocate mirror and initialize static fields
5783   // The create_mirror() call will also call compute_modifiers()
5784   java_lang_Class::create_mirror(ik,
5785                                  Handle(THREAD, _loader_data->class_loader()),
5786                                  module_handle,
5787                                  _protection_domain,

5788                                  CHECK);
5789 
5790   assert(_all_mirandas != NULL, "invariant");
5791 
5792   // Generate any default methods - default methods are public interface methods
5793   // that have a default implementation.  This is new with Java 8.
5794   if (_has_nonstatic_concrete_methods) {
5795     DefaultMethods::generate_default_methods(ik,
5796                                              _all_mirandas,
5797                                              CHECK);
5798   }
5799 
5800   // Add read edges to the unnamed modules of the bootstrap and app class loaders.
5801   if (changed_by_loadhook && !module_handle.is_null() && module_entry->is_named() &&
5802       !module_entry->has_default_read_edges()) {
5803     if (!module_entry->set_has_default_read_edges()) {
5804       // We won a potential race
5805       JvmtiExport::add_default_read_edges(module_handle, THREAD);
5806     }
5807   }


5852   // in order for it to not be destroyed in the ClassFileParser destructor.
5853   set_klass_to_deallocate(NULL);
5854 
5855   // it's official
5856   set_klass(ik);
5857 
5858   debug_only(ik->verify();)
5859 }
5860 
5861 void ClassFileParser::update_class_name(Symbol* new_class_name) {
5862   // Decrement the refcount in the old name, since we're clobbering it.
5863   _class_name->decrement_refcount();
5864 
5865   _class_name = new_class_name;
5866   // Increment the refcount of the new name.
5867   // Now the ClassFileParser owns this name and will decrement in
5868   // the destructor.
5869   _class_name->increment_refcount();
5870 }
5871 
5872 
5873 // For an unsafe anonymous class that is in the unnamed package, move it to its host class's
5874 // package by prepending its host class's package name to its class name and setting
5875 // its _class_name field.
5876 void ClassFileParser::prepend_host_package_name(const InstanceKlass* unsafe_anonymous_host, TRAPS) {
5877   ResourceMark rm(THREAD);
5878   assert(strrchr(_class_name->as_C_string(), JVM_SIGNATURE_SLASH) == NULL,
5879          "Unsafe anonymous class should not be in a package");
5880   TempNewSymbol host_pkg_name =
5881     ClassLoader::package_from_class_name(unsafe_anonymous_host->name());
5882 
5883   if (host_pkg_name != NULL) {
5884     int host_pkg_len = host_pkg_name->utf8_length();
5885     int class_name_len = _class_name->utf8_length();
5886     int symbol_len = host_pkg_len + 1 + class_name_len;
5887     char* new_anon_name = NEW_RESOURCE_ARRAY(char, symbol_len + 1);
5888     int n = os::snprintf(new_anon_name, symbol_len + 1, "%.*s/%.*s",
5889                          host_pkg_len, host_pkg_name->base(), class_name_len, _class_name->base());
5890     assert(n == symbol_len, "Unexpected number of characters in string");
5891 
5892     // Decrement old _class_name to avoid leaking.


5905 // host's package.  If the classes are in different packages then throw an IAE
5906 // exception.
5907 void ClassFileParser::fix_unsafe_anonymous_class_name(TRAPS) {
5908   assert(_unsafe_anonymous_host != NULL, "Expected an unsafe anonymous class");
5909 
5910   const jbyte* anon_last_slash = UTF8::strrchr((const jbyte*)_class_name->base(),
5911                                                _class_name->utf8_length(), JVM_SIGNATURE_SLASH);
5912   if (anon_last_slash == NULL) {  // Unnamed package
5913     prepend_host_package_name(_unsafe_anonymous_host, CHECK);
5914   } else {
5915     if (!_unsafe_anonymous_host->is_same_class_package(_unsafe_anonymous_host->class_loader(), _class_name)) {
5916       ResourceMark rm(THREAD);
5917       THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
5918         err_msg("Host class %s and anonymous class %s are in different packages",
5919         _unsafe_anonymous_host->name()->as_C_string(), _class_name->as_C_string()));
5920     }
5921   }
5922 }
5923 
5924 static bool relax_format_check_for(ClassLoaderData* loader_data) {
5925   bool trusted = (loader_data->is_the_null_class_loader_data() ||
5926                   SystemDictionary::is_platform_class_loader(loader_data->class_loader()));
5927   bool need_verify =
5928     // verifyAll
5929     (BytecodeVerificationLocal && BytecodeVerificationRemote) ||
5930     // verifyRemote
5931     (!BytecodeVerificationLocal && BytecodeVerificationRemote && !trusted);
5932   return !need_verify;
5933 }
5934 
5935 ClassFileParser::ClassFileParser(ClassFileStream* stream,
5936                                  Symbol* name,
5937                                  ClassLoaderData* loader_data,
5938                                  Handle protection_domain,
5939                                  const InstanceKlass* unsafe_anonymous_host,
5940                                  GrowableArray<Handle>* cp_patches,
5941                                  Publicity pub_level,
5942                                  TRAPS) :
5943   _stream(stream),
5944   _requested_name(name),
5945   _class_name(NULL),
5946   _loader_data(loader_data),
5947   _unsafe_anonymous_host(unsafe_anonymous_host),
5948   _cp_patches(cp_patches),


5949   _num_patched_klasses(0),
5950   _max_num_patched_klasses(0),
5951   _orig_cp_size(0),
5952   _first_patched_klass_resolved_index(0),
5953   _super_klass(),
5954   _cp(NULL),
5955   _fields(NULL),
5956   _methods(NULL),
5957   _inner_classes(NULL),
5958   _nest_members(NULL),
5959   _nest_host(0),
5960   _record_components(NULL),
5961   _local_interfaces(NULL),
5962   _transitive_interfaces(NULL),
5963   _combined_annotations(NULL),
5964   _class_annotations(NULL),
5965   _class_type_annotations(NULL),
5966   _fields_annotations(NULL),
5967   _fields_type_annotations(NULL),
5968   _klass(NULL),
5969   _klass_to_deallocate(NULL),
5970   _parsed_annotations(NULL),
5971   _fac(NULL),
5972   _field_info(NULL),
5973   _method_ordering(NULL),
5974   _all_mirandas(NULL),
5975   _vtable_size(0),
5976   _itable_size(0),
5977   _num_miranda_methods(0),
5978   _rt(REF_NONE),
5979   _protection_domain(protection_domain),
5980   _access_flags(),
5981   _pub_level(pub_level),
5982   _bad_constant_seen(0),
5983   _synthetic_flag(false),
5984   _sde_length(false),
5985   _sde_buffer(NULL),
5986   _sourcefile_index(0),
5987   _generic_signature_index(0),
5988   _major_version(0),
5989   _minor_version(0),
5990   _this_class_index(0),
5991   _super_class_index(0),
5992   _itfs_len(0),
5993   _java_fields_count(0),
5994   _need_verify(false),
5995   _relax_verify(false),
5996   _has_nonstatic_concrete_methods(false),
5997   _declares_nonstatic_concrete_methods(false),
5998   _has_final_method(false),
5999   _has_contended_fields(false),


6162             _major_version,  _minor_version, _class_name->as_C_string());
6163     Exceptions::fthrow(
6164       THREAD_AND_LOCATION,
6165       vmSymbols::java_lang_UnsupportedClassVersionError(),
6166       "Unsupported major.minor version for dump time %u.%u",
6167       _major_version,
6168       _minor_version);
6169   }
6170 
6171   // Check version numbers - we check this even with verifier off
6172   verify_class_version(_major_version, _minor_version, _class_name, CHECK);
6173 
6174   stream->guarantee_more(3, CHECK); // length, first cp tag
6175   u2 cp_size = stream->get_u2_fast();
6176 
6177   guarantee_property(
6178     cp_size >= 1, "Illegal constant pool size %u in class file %s",
6179     cp_size, CHECK);
6180 
6181   _orig_cp_size = cp_size;




6182   if (int(cp_size) + _max_num_patched_klasses > 0xffff) {
6183     THROW_MSG(vmSymbols::java_lang_InternalError(), "not enough space for patched classes");
6184   }
6185   cp_size += _max_num_patched_klasses;

6186 
6187   _cp = ConstantPool::allocate(_loader_data,
6188                                cp_size,
6189                                CHECK);
6190 
6191   ConstantPool* const cp = _cp;
6192 
6193   parse_constant_pool(stream, cp, _orig_cp_size, CHECK);
6194 
6195   assert(cp_size == (const u2)cp->length(), "invariant");
6196 
6197   // ACCESS FLAGS
6198   stream->guarantee_more(8, CHECK);  // flags, this_class, super_class, infs_len
6199 
6200   // Access flags
6201   jint flags;
6202   // JVM_ACC_MODULE is defined in JDK-9 and later.
6203   if (_major_version >= JAVA_9_VERSION) {
6204     flags = stream->get_u2_fast() & (JVM_RECOGNIZED_CLASS_MODIFIERS | JVM_ACC_MODULE);
6205   } else {


6216   short bad_constant = class_bad_constant_seen();
6217   if (bad_constant != 0) {
6218     // Do not throw CFE until after the access_flags are checked because if
6219     // ACC_MODULE is set in the access flags, then NCDFE must be thrown, not CFE.
6220     classfile_parse_error("Unknown constant tag %u in class file %s", bad_constant, CHECK);
6221   }
6222 
6223   _access_flags.set_flags(flags);
6224 
6225   // This class and superclass
6226   _this_class_index = stream->get_u2_fast();
6227   check_property(
6228     valid_cp_range(_this_class_index, cp_size) &&
6229       cp->tag_at(_this_class_index).is_unresolved_klass(),
6230     "Invalid this class index %u in constant pool in class file %s",
6231     _this_class_index, CHECK);
6232 
6233   Symbol* const class_name_in_cp = cp->klass_name_at(_this_class_index);
6234   assert(class_name_in_cp != NULL, "class_name can't be null");
6235 
6236   // Update _class_name to reflect the name in the constant pool
6237   update_class_name(class_name_in_cp);
6238 
6239   // Don't need to check whether this class name is legal or not.
6240   // It has been checked when constant pool is parsed.
6241   // However, make sure it is not an array type.
6242   if (_need_verify) {
6243     guarantee_property(_class_name->char_at(0) != JVM_SIGNATURE_ARRAY,
6244                        "Bad class name in class file %s",
6245                        CHECK);
6246   }
6247 
6248   // Checks if name in class file matches requested name
6249   if (_requested_name != NULL && _requested_name != _class_name) {



































6250     ResourceMark rm(THREAD);
6251     Exceptions::fthrow(
6252       THREAD_AND_LOCATION,
6253       vmSymbols::java_lang_NoClassDefFoundError(),
6254       "%s (wrong name: %s)",
6255       _class_name->as_C_string(),
6256       _requested_name != NULL ? _requested_name->as_C_string() : "NoName"
6257     );
6258     return;






6259   }
6260 
6261   // if this is an anonymous class fix up its name if it's in the unnamed
6262   // package.  Otherwise, throw IAE if it is in a different package than
6263   // its host class.
6264   if (_unsafe_anonymous_host != NULL) {
6265     fix_unsafe_anonymous_class_name(CHECK);
6266   }
6267 
6268   // Verification prevents us from creating names with dots in them, this
6269   // asserts that that's the case.
6270   assert(is_internal_format(_class_name), "external class name format used internally");
6271 
6272   if (!is_internal()) {
6273     LogTarget(Debug, class, preorder) lt;
6274     if (lt.is_enabled()){
6275       ResourceMark rm(THREAD);
6276       LogStream ls(lt);
6277       ls.print("%s", _class_name->as_klass_external_name());
6278       if (stream->source() != NULL) {
6279         ls.print(" source: %s", stream->source());
6280       }
6281       ls.cr();
6282     }
6283 
6284 #if INCLUDE_CDS
6285     if (DumpLoadedClassList != NULL && stream->source() != NULL && classlist_file->is_open()) {
6286       if (!ClassLoader::has_jrt_entry()) {
6287         warning("DumpLoadedClassList and CDS are not supported in exploded build");
6288         DumpLoadedClassList = NULL;
6289       } else if (SystemDictionaryShared::is_sharing_possible(_loader_data) &&

6290                  _unsafe_anonymous_host == NULL) {
6291         // Only dump the classes that can be stored into CDS archive.
6292         // Unsafe anonymous classes such as generated LambdaForm classes are also not included.
6293         oop class_loader = _loader_data->class_loader();
6294         ResourceMark rm(THREAD);
6295         bool skip = false;
6296         if (class_loader == NULL || SystemDictionary::is_platform_class_loader(class_loader)) {
6297           // For the boot and platform class loaders, skip classes that are not found in the
6298           // java runtime image, such as those found in the --patch-module entries.
6299           // These classes can't be loaded from the archive during runtime.
6300           if (!stream->from_boot_loader_modules_image() && strncmp(stream->source(), "jrt:", 4) != 0) {
6301             skip = true;
6302           }
6303 
6304           if (class_loader == NULL && ClassLoader::contains_append_entry(stream->source())) {
6305             // .. but don't skip the boot classes that are loaded from -Xbootclasspath/a
6306             // as they can be loaded from the archive during runtime.
6307             skip = false;
6308           }
6309         }
6310         if (skip) {
6311           tty->print_cr("skip writing class %s from source %s to classlist file",
6312             _class_name->as_C_string(), stream->source());


6367   }
6368 
6369   // Additional attributes/annotations
6370   _parsed_annotations = new ClassAnnotationCollector();
6371   parse_classfile_attributes(stream, cp, _parsed_annotations, CHECK);
6372 
6373   assert(_inner_classes != NULL, "invariant");
6374 
6375   // Finalize the Annotations metadata object,
6376   // now that all annotation arrays have been created.
6377   create_combined_annotations(CHECK);
6378 
6379   // Make sure this is the end of class file stream
6380   guarantee_property(stream->at_eos(),
6381                      "Extra bytes at the end of class file %s",
6382                      CHECK);
6383 
6384   // all bytes in stream read and parsed
6385 }
6386 





























6387 void ClassFileParser::post_process_parsed_stream(const ClassFileStream* const stream,
6388                                                  ConstantPool* cp,
6389                                                  TRAPS) {
6390   assert(stream != NULL, "invariant");
6391   assert(stream->at_eos(), "invariant");
6392   assert(cp != NULL, "invariant");
6393   assert(_loader_data != NULL, "invariant");
6394 
6395   if (_class_name == vmSymbols::java_lang_Object()) {
6396     check_property(_local_interfaces == Universe::the_empty_instance_klass_array(),
6397                    "java.lang.Object cannot implement an interface in class file %s",
6398                    CHECK);
6399   }
6400   // We check super class after class file is parsed and format is checked
6401   if (_super_class_index > 0 && NULL ==_super_klass) {
6402     Symbol* const super_class_name = cp->klass_name_at(_super_class_index);
6403     if (_access_flags.is_interface()) {
6404       // Before attempting to resolve the superclass, check for class format
6405       // errors not checked yet.
6406       guarantee_property(super_class_name == vmSymbols::java_lang_Object(),




1075     _method_DontInline,
1076     _method_InjectedProfile,
1077     _method_LambdaForm_Compiled,
1078     _method_Hidden,
1079     _method_HotSpotIntrinsicCandidate,
1080     _jdk_internal_vm_annotation_Contended,
1081     _field_Stable,
1082     _jdk_internal_vm_annotation_ReservedStackAccess,
1083     _annotation_LIMIT
1084   };
1085   const Location _location;
1086   int _annotations_present;
1087   u2 _contended_group;
1088 
1089   AnnotationCollector(Location location)
1090     : _location(location), _annotations_present(0)
1091   {
1092     assert((int)_annotation_LIMIT <= (int)sizeof(_annotations_present) * BitsPerByte, "");
1093   }
1094   // If this annotation name has an ID, report it (or _none).
1095   ID annotation_index(const ClassLoaderData* loader_data, const Symbol* name, const bool can_access_vm_annotations);
1096   // Set the annotation name:
1097   void set_annotation(ID id) {
1098     assert((int)id >= 0 && (int)id < (int)_annotation_LIMIT, "oob");
1099     _annotations_present |= nth_bit((int)id);
1100   }
1101 
1102   void remove_annotation(ID id) {
1103     assert((int)id >= 0 && (int)id < (int)_annotation_LIMIT, "oob");
1104     _annotations_present &= ~nth_bit((int)id);
1105   }
1106 
1107   // Report if the annotation is present.
1108   bool has_any_annotations() const { return _annotations_present != 0; }
1109   bool has_annotation(ID id) const { return (nth_bit((int)id) & _annotations_present) != 0; }
1110 
1111   void set_contended_group(u2 group) { _contended_group = group; }
1112   u2 contended_group() const { return _contended_group; }
1113 
1114   bool is_contended() const { return has_annotation(_jdk_internal_vm_annotation_Contended); }
1115 


1208       int nval = Bytes::get_Java_u2((address)buffer + index - 2);
1209       while (--nval >= 0 && index < limit) {
1210         index = skip_annotation_value(buffer, limit, index);
1211       }
1212     }
1213     break;
1214     case '@':
1215       index = skip_annotation(buffer, limit, index);
1216       break;
1217     default:
1218       return limit;  //  bad tag byte
1219   }
1220   return index;
1221 }
1222 
1223 // Sift through annotations, looking for those significant to the VM:
1224 static void parse_annotations(const ConstantPool* const cp,
1225                               const u1* buffer, int limit,
1226                               AnnotationCollector* coll,
1227                               ClassLoaderData* loader_data,
1228                               const bool can_access_vm_annotations,
1229                               TRAPS) {
1230 
1231   assert(cp != NULL, "invariant");
1232   assert(buffer != NULL, "invariant");
1233   assert(coll != NULL, "invariant");
1234   assert(loader_data != NULL, "invariant");
1235 
1236   // annotations := do(nann:u2) {annotation}
1237   int index = 2; // read nann
1238   if (index >= limit)  return;
1239   int nann = Bytes::get_Java_u2((address)buffer + index - 2);
1240   enum {  // initial annotation layout
1241     atype_off = 0,      // utf8 such as 'Ljava/lang/annotation/Retention;'
1242     count_off = 2,      // u2   such as 1 (one value)
1243     member_off = 4,     // utf8 such as 'value'
1244     tag_off = 6,        // u1   such as 'c' (type) or 'e' (enum)
1245     e_tag_val = 'e',
1246     e_type_off = 7,   // utf8 such as 'Ljava/lang/annotation/RetentionPolicy;'
1247     e_con_off = 9,    // utf8 payload, such as 'SOURCE', 'CLASS', 'RUNTIME'
1248     e_size = 11,     // end of 'e' annotation


1254     s_size = 9,
1255     min_size = 6        // smallest possible size (zero members)
1256   };
1257   // Cannot add min_size to index in case of overflow MAX_INT
1258   while ((--nann) >= 0 && (index - 2 <= limit - min_size)) {
1259     int index0 = index;
1260     index = skip_annotation(buffer, limit, index);
1261     const u1* const abase = buffer + index0;
1262     const int atype = Bytes::get_Java_u2((address)abase + atype_off);
1263     const int count = Bytes::get_Java_u2((address)abase + count_off);
1264     const Symbol* const aname = check_symbol_at(cp, atype);
1265     if (aname == NULL)  break;  // invalid annotation name
1266     const Symbol* member = NULL;
1267     if (count >= 1) {
1268       const int member_index = Bytes::get_Java_u2((address)abase + member_off);
1269       member = check_symbol_at(cp, member_index);
1270       if (member == NULL)  break;  // invalid member name
1271     }
1272 
1273     // Here is where parsing particular annotations will take place.
1274     AnnotationCollector::ID id = coll->annotation_index(loader_data, aname, can_access_vm_annotations);
1275     if (AnnotationCollector::_unknown == id)  continue;
1276     coll->set_annotation(id);
1277 
1278     if (AnnotationCollector::_jdk_internal_vm_annotation_Contended == id) {
1279       // @Contended can optionally specify the contention group.
1280       //
1281       // Contended group defines the equivalence class over the fields:
1282       // the fields within the same contended group are not treated distinct.
1283       // The only exception is default group, which does not incur the
1284       // equivalence. Naturally, contention group for classes is meaningless.
1285       //
1286       // While the contention group is specified as String, annotation
1287       // values are already interned, and we might as well use the constant
1288       // pool index as the group tag.
1289       //
1290       u2 group_index = 0; // default contended group
1291       if (count == 1
1292         && s_size == (index - index0)  // match size
1293         && s_tag_val == *(abase + tag_off)
1294         && member == vmSymbols::value_name()) {


1380         if (attribute_length != 2) {
1381           classfile_parse_error(
1382             "Wrong size %u for field's Signature attribute in class file %s",
1383             attribute_length, CHECK);
1384         }
1385         generic_signature_index = parse_generic_signature_attribute(cfs, CHECK);
1386       } else if (attribute_name == vmSymbols::tag_runtime_visible_annotations()) {
1387         if (runtime_visible_annotations != NULL) {
1388           classfile_parse_error(
1389             "Multiple RuntimeVisibleAnnotations attributes for field in class file %s", CHECK);
1390         }
1391         runtime_visible_annotations_length = attribute_length;
1392         runtime_visible_annotations = cfs->current();
1393         assert(runtime_visible_annotations != NULL, "null visible annotations");
1394         cfs->guarantee_more(runtime_visible_annotations_length, CHECK);
1395         parse_annotations(cp,
1396                           runtime_visible_annotations,
1397                           runtime_visible_annotations_length,
1398                           parsed_annotations,
1399                           _loader_data,
1400                           _can_access_vm_annotations,
1401                           CHECK);
1402         cfs->skip_u1_fast(runtime_visible_annotations_length);
1403       } else if (attribute_name == vmSymbols::tag_runtime_invisible_annotations()) {
1404         if (runtime_invisible_annotations_exists) {
1405           classfile_parse_error(
1406             "Multiple RuntimeInvisibleAnnotations attributes for field in class file %s", CHECK);
1407         }
1408         runtime_invisible_annotations_exists = true;
1409         if (PreserveAllAnnotations) {
1410           runtime_invisible_annotations_length = attribute_length;
1411           runtime_invisible_annotations = cfs->current();
1412           assert(runtime_invisible_annotations != NULL, "null invisible annotations");
1413         }
1414         cfs->skip_u1(attribute_length, CHECK);
1415       } else if (attribute_name == vmSymbols::tag_runtime_visible_type_annotations()) {
1416         if (runtime_visible_type_annotations != NULL) {
1417           classfile_parse_error(
1418             "Multiple RuntimeVisibleTypeAnnotations attributes for field in class file %s", CHECK);
1419         }
1420         runtime_visible_type_annotations_length = attribute_length;


2044   }
2045   return checked_exceptions_start;
2046 }
2047 
2048 void ClassFileParser::throwIllegalSignature(const char* type,
2049                                             const Symbol* name,
2050                                             const Symbol* sig,
2051                                             TRAPS) const {
2052   assert(name != NULL, "invariant");
2053   assert(sig != NULL, "invariant");
2054 
2055   ResourceMark rm(THREAD);
2056   Exceptions::fthrow(THREAD_AND_LOCATION,
2057       vmSymbols::java_lang_ClassFormatError(),
2058       "%s \"%s\" in class %s has illegal signature \"%s\"", type,
2059       name->as_C_string(), _class_name->as_C_string(), sig->as_C_string());
2060 }
2061 
2062 AnnotationCollector::ID
2063 AnnotationCollector::annotation_index(const ClassLoaderData* loader_data,
2064                                       const Symbol* name,
2065                                       const bool can_access_vm_annotations) {
2066   const vmSymbols::SID sid = vmSymbols::find_sid(name);
2067   // Privileged code can use all annotations.  Other code silently drops some.
2068   const bool privileged = loader_data->is_boot_class_loader_data() ||
2069                           loader_data->is_platform_class_loader_data() ||
2070                           can_access_vm_annotations;
2071   switch (sid) {
2072     case vmSymbols::VM_SYMBOL_ENUM_NAME(reflect_CallerSensitive_signature): {
2073       if (_location != _in_method)  break;  // only allow for methods
2074       if (!privileged)              break;  // only allow in privileged code
2075       return _method_CallerSensitive;
2076     }
2077     case vmSymbols::VM_SYMBOL_ENUM_NAME(jdk_internal_vm_annotation_ForceInline_signature): {
2078       if (_location != _in_method)  break;  // only allow for methods
2079       if (!privileged)              break;  // only allow in privileged code
2080       return _method_ForceInline;
2081     }
2082     case vmSymbols::VM_SYMBOL_ENUM_NAME(jdk_internal_vm_annotation_DontInline_signature): {
2083       if (_location != _in_method)  break;  // only allow for methods
2084       if (!privileged)              break;  // only allow in privileged code
2085       return _method_DontInline;
2086     }
2087     case vmSymbols::VM_SYMBOL_ENUM_NAME(java_lang_invoke_InjectedProfile_signature): {
2088       if (_location != _in_method)  break;  // only allow for methods
2089       if (!privileged)              break;  // only allow in privileged code
2090       return _method_InjectedProfile;


2657           classfile_parse_error(
2658             "Invalid Signature attribute length %u in class file %s",
2659             method_attribute_length, CHECK_NULL);
2660         }
2661         generic_signature_index = parse_generic_signature_attribute(cfs, CHECK_NULL);
2662       } else if (method_attribute_name == vmSymbols::tag_runtime_visible_annotations()) {
2663         if (runtime_visible_annotations != NULL) {
2664           classfile_parse_error(
2665             "Multiple RuntimeVisibleAnnotations attributes for method in class file %s",
2666             CHECK_NULL);
2667         }
2668         runtime_visible_annotations_length = method_attribute_length;
2669         runtime_visible_annotations = cfs->current();
2670         assert(runtime_visible_annotations != NULL, "null visible annotations");
2671         cfs->guarantee_more(runtime_visible_annotations_length, CHECK_NULL);
2672         parse_annotations(cp,
2673                           runtime_visible_annotations,
2674                           runtime_visible_annotations_length,
2675                           &parsed_annotations,
2676                           _loader_data,
2677                           _can_access_vm_annotations,
2678                           CHECK_NULL);
2679         cfs->skip_u1_fast(runtime_visible_annotations_length);
2680       } else if (method_attribute_name == vmSymbols::tag_runtime_invisible_annotations()) {
2681         if (runtime_invisible_annotations_exists) {
2682           classfile_parse_error(
2683             "Multiple RuntimeInvisibleAnnotations attributes for method in class file %s",
2684             CHECK_NULL);
2685         }
2686         runtime_invisible_annotations_exists = true;
2687         if (PreserveAllAnnotations) {
2688           runtime_invisible_annotations_length = method_attribute_length;
2689           runtime_invisible_annotations = cfs->current();
2690           assert(runtime_invisible_annotations != NULL, "null invisible annotations");
2691         }
2692         cfs->skip_u1(method_attribute_length, CHECK_NULL);
2693       } else if (method_attribute_name == vmSymbols::tag_runtime_visible_parameter_annotations()) {
2694         if (runtime_visible_parameter_annotations != NULL) {
2695           classfile_parse_error(
2696             "Multiple RuntimeVisibleParameterAnnotations attributes for method in class file %s",
2697             CHECK_NULL);


2852                                                 checked_exceptions_length * sizeof(CheckedExceptionElement),
2853                                                 sizeof(u2));
2854   }
2855 
2856   // Copy class file LVT's/LVTT's into the HotSpot internal LVT.
2857   if (total_lvt_length > 0) {
2858     promoted_flags->set_has_localvariable_table();
2859     copy_localvariable_table(m->constMethod(),
2860                              lvt_cnt,
2861                              localvariable_table_length,
2862                              localvariable_table_start,
2863                              lvtt_cnt,
2864                              localvariable_type_table_length,
2865                              localvariable_type_table_start,
2866                              CHECK_NULL);
2867   }
2868 
2869   if (parsed_annotations.has_any_annotations())
2870     parsed_annotations.apply_to(methodHandle(THREAD, m));
2871 
2872   if (is_hidden()) { // Mark methods in hidden classes as 'hidden'.
2873     m->set_hidden(true);
2874   }
2875 
2876   // Copy annotations
2877   copy_method_annotations(m->constMethod(),
2878                           runtime_visible_annotations,
2879                           runtime_visible_annotations_length,
2880                           runtime_invisible_annotations,
2881                           runtime_invisible_annotations_length,
2882                           runtime_visible_parameter_annotations,
2883                           runtime_visible_parameter_annotations_length,
2884                           runtime_invisible_parameter_annotations,
2885                           runtime_invisible_parameter_annotations_length,
2886                           runtime_visible_type_annotations,
2887                           runtime_visible_type_annotations_length,
2888                           runtime_invisible_type_annotations,
2889                           runtime_invisible_type_annotations_length,
2890                           annotation_default,
2891                           annotation_default_length,
2892                           CHECK_NULL);
2893 
2894   if (name == vmSymbols::finalize_method_name() &&
2895       signature == vmSymbols::void_method_signature()) {


3587         if (attribute_length != 2) {
3588           classfile_parse_error(
3589             "Wrong Signature attribute length %u in class file %s",
3590             attribute_length, CHECK);
3591         }
3592         parse_classfile_signature_attribute(cfs, CHECK);
3593       } else if (tag == vmSymbols::tag_runtime_visible_annotations()) {
3594         if (runtime_visible_annotations != NULL) {
3595           classfile_parse_error(
3596             "Multiple RuntimeVisibleAnnotations attributes in class file %s", CHECK);
3597         }
3598         runtime_visible_annotations_length = attribute_length;
3599         runtime_visible_annotations = cfs->current();
3600         assert(runtime_visible_annotations != NULL, "null visible annotations");
3601         cfs->guarantee_more(runtime_visible_annotations_length, CHECK);
3602         parse_annotations(cp,
3603                           runtime_visible_annotations,
3604                           runtime_visible_annotations_length,
3605                           parsed_annotations,
3606                           _loader_data,
3607                           _can_access_vm_annotations,
3608                           CHECK);
3609         cfs->skip_u1_fast(runtime_visible_annotations_length);
3610       } else if (tag == vmSymbols::tag_runtime_invisible_annotations()) {
3611         if (runtime_invisible_annotations_exists) {
3612           classfile_parse_error(
3613             "Multiple RuntimeInvisibleAnnotations attributes in class file %s", CHECK);
3614         }
3615         runtime_invisible_annotations_exists = true;
3616         if (PreserveAllAnnotations) {
3617           runtime_invisible_annotations_length = attribute_length;
3618           runtime_invisible_annotations = cfs->current();
3619           assert(runtime_invisible_annotations != NULL, "null invisible annotations");
3620         }
3621         cfs->skip_u1(attribute_length, CHECK);
3622       } else if (tag == vmSymbols::tag_enclosing_method()) {
3623         if (parsed_enclosingmethod_attribute) {
3624           classfile_parse_error("Multiple EnclosingMethod attributes in class file %s", CHECK);
3625         } else {
3626           parsed_enclosingmethod_attribute = true;
3627         }


5584 
5585           if (!match) {
5586             char buf[1000];
5587             tty->print("Compiler intrinsic is defined for method [%s], "
5588                        "but the method is not available in class [%s].%s",
5589                         vmIntrinsics::short_name_as_C_string(vmIntrinsics::ID_from(id),
5590                                                              buf, sizeof(buf)),
5591                         ik->name()->as_C_string(),
5592                         NOT_DEBUG("") DEBUG_ONLY(" Exiting.")
5593             );
5594             tty->cr();
5595             DEBUG_ONLY(vm_exit(1));
5596           }
5597         }
5598       } // end for
5599     } // CheckIntrinsics
5600 #endif // ASSERT
5601   }
5602 }
5603 
5604 InstanceKlass* ClassFileParser::create_instance_klass(bool changed_by_loadhook,
5605                                                       const ClassInstanceInfo& cl_inst_info,
5606                                                       TRAPS) {
5607   if (_klass != NULL) {
5608     return _klass;
5609   }
5610 
5611   InstanceKlass* const ik =
5612     InstanceKlass::allocate_instance_klass(*this, CHECK_NULL);
5613 
5614   if (is_hidden()) {
5615     mangle_hidden_class_name(ik);
5616   }
5617 
5618   fill_instance_klass(ik, changed_by_loadhook, cl_inst_info, CHECK_NULL);
5619 
5620   assert(_klass == ik, "invariant");
5621 
5622 
5623   if (ik->should_store_fingerprint()) {
5624     ik->store_fingerprint(_stream->compute_fingerprint());
5625   }
5626 
5627   ik->set_has_passed_fingerprint_check(false);
5628   if (UseAOT && ik->supers_have_passed_fingerprint_checks()) {
5629     uint64_t aot_fp = AOTLoader::get_saved_fingerprint(ik);
5630     uint64_t fp = ik->has_stored_fingerprint() ? ik->get_stored_fingerprint() : _stream->compute_fingerprint();
5631     if (aot_fp != 0 && aot_fp == fp) {
5632       // This class matches with a class saved in an AOT library
5633       ik->set_has_passed_fingerprint_check(true);
5634     } else {
5635       ResourceMark rm;
5636       log_info(class, fingerprint)("%s :  expected = " PTR64_FORMAT " actual = " PTR64_FORMAT,
5637                                  ik->external_name(), aot_fp, _stream->compute_fingerprint());
5638     }
5639   }
5640 
5641   return ik;
5642 }
5643 
5644 void ClassFileParser::fill_instance_klass(InstanceKlass* ik,
5645                                           bool changed_by_loadhook,
5646                                           const ClassInstanceInfo& cl_inst_info,
5647                                           TRAPS) {
5648   assert(ik != NULL, "invariant");
5649 
5650   // Set name and CLD before adding to CLD
5651   ik->set_class_loader_data(_loader_data);
5652   ik->set_name(_class_name);
5653 
5654   // Add all classes to our internal class loader list here,
5655   // including classes in the bootstrap (NULL) class loader.
5656   const bool publicize = !is_internal();
5657 
5658   _loader_data->add_class(ik, publicize);
5659 
5660   set_klass_to_deallocate(ik);
5661 
5662   assert(_field_info != NULL, "invariant");
5663   assert(ik->static_field_size() == _field_info->_static_field_size, "sanity");
5664   assert(ik->nonstatic_oop_map_count() == _field_info->oop_map_blocks->_nonstatic_oop_map_count,
5665          "sanity");
5666 
5667   assert(ik->is_instance_klass(), "sanity");
5668   assert(ik->size_helper() == _field_info->_instance_size, "sanity");
5669 
5670   // Fill in information already parsed
5671   ik->set_should_verify_class(_need_verify);
5672 
5673   // Not yet: supers are done below to support the new subtype-checking fields
5674   ik->set_nonstatic_field_size(_field_info->_nonstatic_field_size);
5675   ik->set_has_nonstatic_fields(_field_info->_has_nonstatic_fields);
5676   assert(_fac != NULL, "invariant");
5677   ik->set_static_oop_field_count(_fac->count[STATIC_OOP]);
5678 
5679   // this transfers ownership of a lot of arrays from
5680   // the parser onto the InstanceKlass*
5681   apply_parsed_class_metadata(ik, _java_fields_count, CHECK);
5682 
5683   // can only set dynamic nest-host after static nest information is set
5684   if (cl_inst_info.dynamic_nest_host() != NULL) {
5685     ik->set_nest_host(cl_inst_info.dynamic_nest_host(), THREAD);
5686   }
5687 
5688   // note that is not safe to use the fields in the parser from this point on
5689   assert(NULL == _cp, "invariant");
5690   assert(NULL == _fields, "invariant");
5691   assert(NULL == _methods, "invariant");
5692   assert(NULL == _inner_classes, "invariant");
5693   assert(NULL == _nest_members, "invariant");
5694   assert(NULL == _local_interfaces, "invariant");
5695   assert(NULL == _combined_annotations, "invariant");
5696   assert(NULL == _record_components, "invariant");
5697 
5698   if (_has_final_method) {
5699     ik->set_has_final_method();
5700   }
5701 
5702   ik->copy_method_ordering(_method_ordering, CHECK);
5703   // The InstanceKlass::_methods_jmethod_ids cache
5704   // is managed on the assumption that the initial cache
5705   // size is equal to the number of methods in the class. If
5706   // that changes, then InstanceKlass::idnum_can_increment()
5707   // has to be changed accordingly.
5708   ik->set_initial_method_idnum(ik->methods()->length());
5709 
5710   ik->set_this_class_index(_this_class_index);
5711 
5712   if (_is_hidden || is_unsafe_anonymous()) {
5713     // _this_class_index is a CONSTANT_Class entry that refers to this
5714     // hidden or anonymous class itself. If this class needs to refer to its own
5715     // methods or fields, it would use a CONSTANT_MethodRef, etc, which would reference
5716     // _this_class_index. However, because this class is hidden or anonymous (it's
5717     // not stored in SystemDictionary), _this_class_index cannot be resolved
5718     // with ConstantPool::klass_at_impl, which does a SystemDictionary lookup.
5719     // Therefore, we must eagerly resolve _this_class_index now.
5720     ik->constants()->klass_at_put(_this_class_index, ik);
5721   }
5722 
5723   ik->set_minor_version(_minor_version);
5724   ik->set_major_version(_major_version);
5725   ik->set_has_nonstatic_concrete_methods(_has_nonstatic_concrete_methods);
5726   ik->set_declares_nonstatic_concrete_methods(_declares_nonstatic_concrete_methods);
5727 
5728   if (_unsafe_anonymous_host != NULL) {
5729     assert (ik->is_unsafe_anonymous(), "should be the same");
5730     ik->set_unsafe_anonymous_host(_unsafe_anonymous_host);
5731   }
5732   if (_is_hidden) {
5733     ik->set_is_hidden();
5734   }
5735 
5736   // Set PackageEntry for this_klass
5737   oop cl = ik->class_loader();
5738   Handle clh = Handle(THREAD, java_lang_ClassLoader::non_reflection_class_loader(cl));
5739   ClassLoaderData* cld = ClassLoaderData::class_loader_data_or_null(clh());
5740   ik->set_package(cld, CHECK);
5741 
5742   const Array<Method*>* const methods = ik->methods();
5743   assert(methods != NULL, "invariant");
5744   const int methods_len = methods->length();
5745 
5746   check_methods_for_intrinsics(ik, methods);
5747 
5748   // Fill in field values obtained by parse_classfile_attributes
5749   if (_parsed_annotations->has_any_annotations()) {
5750     _parsed_annotations->apply_to(ik);
5751   }
5752 
5753   apply_parsed_class_attributes(ik);
5754 


5794   check_final_method_override(ik, CHECK);
5795 
5796   // reject static interface methods prior to Java 8
5797   if (ik->is_interface() && _major_version < JAVA_8_VERSION) {
5798     check_illegal_static_method(ik, CHECK);
5799   }
5800 
5801   // Obtain this_klass' module entry
5802   ModuleEntry* module_entry = ik->module();
5803   assert(module_entry != NULL, "module_entry should always be set");
5804 
5805   // Obtain java.lang.Module
5806   Handle module_handle(THREAD, module_entry->module());
5807 
5808   // Allocate mirror and initialize static fields
5809   // The create_mirror() call will also call compute_modifiers()
5810   java_lang_Class::create_mirror(ik,
5811                                  Handle(THREAD, _loader_data->class_loader()),
5812                                  module_handle,
5813                                  _protection_domain,
5814                                  cl_inst_info.class_data(),
5815                                  CHECK);
5816 
5817   assert(_all_mirandas != NULL, "invariant");
5818 
5819   // Generate any default methods - default methods are public interface methods
5820   // that have a default implementation.  This is new with Java 8.
5821   if (_has_nonstatic_concrete_methods) {
5822     DefaultMethods::generate_default_methods(ik,
5823                                              _all_mirandas,
5824                                              CHECK);
5825   }
5826 
5827   // Add read edges to the unnamed modules of the bootstrap and app class loaders.
5828   if (changed_by_loadhook && !module_handle.is_null() && module_entry->is_named() &&
5829       !module_entry->has_default_read_edges()) {
5830     if (!module_entry->set_has_default_read_edges()) {
5831       // We won a potential race
5832       JvmtiExport::add_default_read_edges(module_handle, THREAD);
5833     }
5834   }


5879   // in order for it to not be destroyed in the ClassFileParser destructor.
5880   set_klass_to_deallocate(NULL);
5881 
5882   // it's official
5883   set_klass(ik);
5884 
5885   debug_only(ik->verify();)
5886 }
5887 
5888 void ClassFileParser::update_class_name(Symbol* new_class_name) {
5889   // Decrement the refcount in the old name, since we're clobbering it.
5890   _class_name->decrement_refcount();
5891 
5892   _class_name = new_class_name;
5893   // Increment the refcount of the new name.
5894   // Now the ClassFileParser owns this name and will decrement in
5895   // the destructor.
5896   _class_name->increment_refcount();
5897 }
5898 

5899 // For an unsafe anonymous class that is in the unnamed package, move it to its host class's
5900 // package by prepending its host class's package name to its class name and setting
5901 // its _class_name field.
5902 void ClassFileParser::prepend_host_package_name(const InstanceKlass* unsafe_anonymous_host, TRAPS) {
5903   ResourceMark rm(THREAD);
5904   assert(strrchr(_class_name->as_C_string(), JVM_SIGNATURE_SLASH) == NULL,
5905          "Unsafe anonymous class should not be in a package");
5906   TempNewSymbol host_pkg_name =
5907     ClassLoader::package_from_class_name(unsafe_anonymous_host->name());
5908 
5909   if (host_pkg_name != NULL) {
5910     int host_pkg_len = host_pkg_name->utf8_length();
5911     int class_name_len = _class_name->utf8_length();
5912     int symbol_len = host_pkg_len + 1 + class_name_len;
5913     char* new_anon_name = NEW_RESOURCE_ARRAY(char, symbol_len + 1);
5914     int n = os::snprintf(new_anon_name, symbol_len + 1, "%.*s/%.*s",
5915                          host_pkg_len, host_pkg_name->base(), class_name_len, _class_name->base());
5916     assert(n == symbol_len, "Unexpected number of characters in string");
5917 
5918     // Decrement old _class_name to avoid leaking.


5931 // host's package.  If the classes are in different packages then throw an IAE
5932 // exception.
5933 void ClassFileParser::fix_unsafe_anonymous_class_name(TRAPS) {
5934   assert(_unsafe_anonymous_host != NULL, "Expected an unsafe anonymous class");
5935 
5936   const jbyte* anon_last_slash = UTF8::strrchr((const jbyte*)_class_name->base(),
5937                                                _class_name->utf8_length(), JVM_SIGNATURE_SLASH);
5938   if (anon_last_slash == NULL) {  // Unnamed package
5939     prepend_host_package_name(_unsafe_anonymous_host, CHECK);
5940   } else {
5941     if (!_unsafe_anonymous_host->is_same_class_package(_unsafe_anonymous_host->class_loader(), _class_name)) {
5942       ResourceMark rm(THREAD);
5943       THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
5944         err_msg("Host class %s and anonymous class %s are in different packages",
5945         _unsafe_anonymous_host->name()->as_C_string(), _class_name->as_C_string()));
5946     }
5947   }
5948 }
5949 
5950 static bool relax_format_check_for(ClassLoaderData* loader_data) {
5951   bool trusted = loader_data->is_boot_class_loader_data() ||
5952                  loader_data->is_platform_class_loader_data();
5953   bool need_verify =
5954     // verifyAll
5955     (BytecodeVerificationLocal && BytecodeVerificationRemote) ||
5956     // verifyRemote
5957     (!BytecodeVerificationLocal && BytecodeVerificationRemote && !trusted);
5958   return !need_verify;
5959 }
5960 
5961 ClassFileParser::ClassFileParser(ClassFileStream* stream,
5962                                  Symbol* name,
5963                                  ClassLoaderData* loader_data,
5964                                  const ClassLoadInfo* cl_info,


5965                                  Publicity pub_level,
5966                                  TRAPS) :
5967   _stream(stream),

5968   _class_name(NULL),
5969   _loader_data(loader_data),
5970   _unsafe_anonymous_host(cl_info->unsafe_anonymous_host()),
5971   _cp_patches(cl_info->cp_patches()),
5972   _is_hidden(cl_info->is_hidden()),
5973   _can_access_vm_annotations(cl_info->can_access_vm_annotations()),
5974   _num_patched_klasses(0),
5975   _max_num_patched_klasses(0),
5976   _orig_cp_size(0),
5977   _first_patched_klass_resolved_index(0),
5978   _super_klass(),
5979   _cp(NULL),
5980   _fields(NULL),
5981   _methods(NULL),
5982   _inner_classes(NULL),
5983   _nest_members(NULL),
5984   _nest_host(0),
5985   _record_components(NULL),
5986   _local_interfaces(NULL),
5987   _transitive_interfaces(NULL),
5988   _combined_annotations(NULL),
5989   _class_annotations(NULL),
5990   _class_type_annotations(NULL),
5991   _fields_annotations(NULL),
5992   _fields_type_annotations(NULL),
5993   _klass(NULL),
5994   _klass_to_deallocate(NULL),
5995   _parsed_annotations(NULL),
5996   _fac(NULL),
5997   _field_info(NULL),
5998   _method_ordering(NULL),
5999   _all_mirandas(NULL),
6000   _vtable_size(0),
6001   _itable_size(0),
6002   _num_miranda_methods(0),
6003   _rt(REF_NONE),
6004   _protection_domain(cl_info->protection_domain()),
6005   _access_flags(),
6006   _pub_level(pub_level),
6007   _bad_constant_seen(0),
6008   _synthetic_flag(false),
6009   _sde_length(false),
6010   _sde_buffer(NULL),
6011   _sourcefile_index(0),
6012   _generic_signature_index(0),
6013   _major_version(0),
6014   _minor_version(0),
6015   _this_class_index(0),
6016   _super_class_index(0),
6017   _itfs_len(0),
6018   _java_fields_count(0),
6019   _need_verify(false),
6020   _relax_verify(false),
6021   _has_nonstatic_concrete_methods(false),
6022   _declares_nonstatic_concrete_methods(false),
6023   _has_final_method(false),
6024   _has_contended_fields(false),


6187             _major_version,  _minor_version, _class_name->as_C_string());
6188     Exceptions::fthrow(
6189       THREAD_AND_LOCATION,
6190       vmSymbols::java_lang_UnsupportedClassVersionError(),
6191       "Unsupported major.minor version for dump time %u.%u",
6192       _major_version,
6193       _minor_version);
6194   }
6195 
6196   // Check version numbers - we check this even with verifier off
6197   verify_class_version(_major_version, _minor_version, _class_name, CHECK);
6198 
6199   stream->guarantee_more(3, CHECK); // length, first cp tag
6200   u2 cp_size = stream->get_u2_fast();
6201 
6202   guarantee_property(
6203     cp_size >= 1, "Illegal constant pool size %u in class file %s",
6204     cp_size, CHECK);
6205 
6206   _orig_cp_size = cp_size;
6207   if (is_hidden()) { // Add a slot for hidden class name.
6208     assert(_max_num_patched_klasses == 0, "Sanity check");
6209     cp_size++;
6210   } else {
6211     if (int(cp_size) + _max_num_patched_klasses > 0xffff) {
6212       THROW_MSG(vmSymbols::java_lang_InternalError(), "not enough space for patched classes");
6213     }
6214     cp_size += _max_num_patched_klasses;
6215   }
6216 
6217   _cp = ConstantPool::allocate(_loader_data,
6218                                cp_size,
6219                                CHECK);
6220 
6221   ConstantPool* const cp = _cp;
6222 
6223   parse_constant_pool(stream, cp, _orig_cp_size, CHECK);
6224 
6225   assert(cp_size == (const u2)cp->length(), "invariant");
6226 
6227   // ACCESS FLAGS
6228   stream->guarantee_more(8, CHECK);  // flags, this_class, super_class, infs_len
6229 
6230   // Access flags
6231   jint flags;
6232   // JVM_ACC_MODULE is defined in JDK-9 and later.
6233   if (_major_version >= JAVA_9_VERSION) {
6234     flags = stream->get_u2_fast() & (JVM_RECOGNIZED_CLASS_MODIFIERS | JVM_ACC_MODULE);
6235   } else {


6246   short bad_constant = class_bad_constant_seen();
6247   if (bad_constant != 0) {
6248     // Do not throw CFE until after the access_flags are checked because if
6249     // ACC_MODULE is set in the access flags, then NCDFE must be thrown, not CFE.
6250     classfile_parse_error("Unknown constant tag %u in class file %s", bad_constant, CHECK);
6251   }
6252 
6253   _access_flags.set_flags(flags);
6254 
6255   // This class and superclass
6256   _this_class_index = stream->get_u2_fast();
6257   check_property(
6258     valid_cp_range(_this_class_index, cp_size) &&
6259       cp->tag_at(_this_class_index).is_unresolved_klass(),
6260     "Invalid this class index %u in constant pool in class file %s",
6261     _this_class_index, CHECK);
6262 
6263   Symbol* const class_name_in_cp = cp->klass_name_at(_this_class_index);
6264   assert(class_name_in_cp != NULL, "class_name can't be null");
6265 



6266   // Don't need to check whether this class name is legal or not.
6267   // It has been checked when constant pool is parsed.
6268   // However, make sure it is not an array type.
6269   if (_need_verify) {
6270     guarantee_property(class_name_in_cp->char_at(0) != JVM_SIGNATURE_ARRAY,
6271                        "Bad class name in class file %s",
6272                        CHECK);
6273   }
6274 
6275 #ifdef ASSERT
6276   // Basic sanity checks
6277   assert(!(_is_hidden && (_unsafe_anonymous_host != NULL)), "mutually exclusive variants");
6278 
6279   if (_unsafe_anonymous_host != NULL) {
6280     assert(_class_name == vmSymbols::unknown_class_name(), "A named anonymous class???");
6281   }
6282   if (_is_hidden) {
6283     assert(_class_name != vmSymbols::unknown_class_name(), "hidden classes should have a special name");
6284   }
6285 #endif
6286 
6287   // Update the _class_name as needed depending on whether this is a named,
6288   // un-named, hidden or unsafe-anonymous class.
6289 
6290   if (_is_hidden) {
6291     assert(_class_name != NULL, "Unexpected null _class_name");
6292 #ifdef ASSERT
6293     if (_need_verify) {
6294       verify_legal_class_name(_class_name, CHECK);
6295     }
6296 #endif
6297 
6298   // NOTE: !_is_hidden does not imply "findable" as it could be an old-style
6299   //       "hidden" unsafe-anonymous class
6300 
6301   // If this is an anonymous class fix up its name if it is in the unnamed
6302   // package.  Otherwise, throw IAE if it is in a different package than
6303   // its host class.
6304   } else if (_unsafe_anonymous_host != NULL) {
6305     update_class_name(class_name_in_cp);
6306     fix_unsafe_anonymous_class_name(CHECK);
6307 
6308   } else {
6309     // Check if name in class file matches given name
6310     if (_class_name != class_name_in_cp) {
6311       if (_class_name != vmSymbols::unknown_class_name()) {
6312         ResourceMark rm(THREAD);
6313         Exceptions::fthrow(THREAD_AND_LOCATION,

6314                            vmSymbols::java_lang_NoClassDefFoundError(),
6315                            "%s (wrong name: %s)",
6316                            class_name_in_cp->as_C_string(),
6317                            _class_name->as_C_string()
6318                            );
6319         return;
6320       } else {
6321         // The class name was not known by the caller so we set it from
6322         // the value in the CP.
6323         update_class_name(class_name_in_cp);
6324       }
6325       // else nothing to do: the expected class name matches what is in the CP
6326     }






6327   }
6328 
6329   // Verification prevents us from creating names with dots in them, this
6330   // asserts that that's the case.
6331   assert(is_internal_format(_class_name), "external class name format used internally");
6332 
6333   if (!is_internal()) {
6334     LogTarget(Debug, class, preorder) lt;
6335     if (lt.is_enabled()){
6336       ResourceMark rm(THREAD);
6337       LogStream ls(lt);
6338       ls.print("%s", _class_name->as_klass_external_name());
6339       if (stream->source() != NULL) {
6340         ls.print(" source: %s", stream->source());
6341       }
6342       ls.cr();
6343     }
6344 
6345 #if INCLUDE_CDS
6346     if (DumpLoadedClassList != NULL && stream->source() != NULL && classlist_file->is_open()) {
6347       if (!ClassLoader::has_jrt_entry()) {
6348         warning("DumpLoadedClassList and CDS are not supported in exploded build");
6349         DumpLoadedClassList = NULL;
6350       } else if (SystemDictionaryShared::is_sharing_possible(_loader_data) &&
6351                  !_is_hidden &&
6352                  _unsafe_anonymous_host == NULL) {
6353         // Only dump the classes that can be stored into CDS archive.
6354         // Hidden and unsafe anonymous classes such as generated LambdaForm classes are also not included.
6355         oop class_loader = _loader_data->class_loader();
6356         ResourceMark rm(THREAD);
6357         bool skip = false;
6358         if (class_loader == NULL || SystemDictionary::is_platform_class_loader(class_loader)) {
6359           // For the boot and platform class loaders, skip classes that are not found in the
6360           // java runtime image, such as those found in the --patch-module entries.
6361           // These classes can't be loaded from the archive during runtime.
6362           if (!stream->from_boot_loader_modules_image() && strncmp(stream->source(), "jrt:", 4) != 0) {
6363             skip = true;
6364           }
6365 
6366           if (class_loader == NULL && ClassLoader::contains_append_entry(stream->source())) {
6367             // .. but don't skip the boot classes that are loaded from -Xbootclasspath/a
6368             // as they can be loaded from the archive during runtime.
6369             skip = false;
6370           }
6371         }
6372         if (skip) {
6373           tty->print_cr("skip writing class %s from source %s to classlist file",
6374             _class_name->as_C_string(), stream->source());


6429   }
6430 
6431   // Additional attributes/annotations
6432   _parsed_annotations = new ClassAnnotationCollector();
6433   parse_classfile_attributes(stream, cp, _parsed_annotations, CHECK);
6434 
6435   assert(_inner_classes != NULL, "invariant");
6436 
6437   // Finalize the Annotations metadata object,
6438   // now that all annotation arrays have been created.
6439   create_combined_annotations(CHECK);
6440 
6441   // Make sure this is the end of class file stream
6442   guarantee_property(stream->at_eos(),
6443                      "Extra bytes at the end of class file %s",
6444                      CHECK);
6445 
6446   // all bytes in stream read and parsed
6447 }
6448 
6449 void ClassFileParser::mangle_hidden_class_name(InstanceKlass* const ik) {
6450   ResourceMark rm;
6451   // Construct hidden name from _class_name, "+", and &ik. Note that we can't
6452   // use a '/' because that confuses finding the class's package.  Also, can't
6453   // use an illegal char such as ';' because that causes serialization issues
6454   // and issues with hidden classes that create their own hidden classes.
6455   char addr_buf[20];
6456   jio_snprintf(addr_buf, 20, INTPTR_FORMAT, p2i(ik));
6457   size_t new_name_len = _class_name->utf8_length() + 2 + strlen(addr_buf);
6458   char* new_name = NEW_RESOURCE_ARRAY(char, new_name_len);
6459   jio_snprintf(new_name, new_name_len, "%s+%s",
6460                _class_name->as_C_string(), addr_buf);
6461   update_class_name(SymbolTable::new_symbol(new_name));
6462 
6463   // Add a Utf8 entry containing the hidden name.
6464   assert(_class_name != NULL, "Unexpected null _class_name");
6465   int hidden_index = _orig_cp_size; // this is an extra slot we added
6466   _cp->symbol_at_put(hidden_index, _class_name);
6467 
6468   // Update this_class_index's slot in the constant pool with the new Utf8 entry.
6469   // We have to update the resolved_klass_index and the name_index together
6470   // so extract the existing resolved_klass_index first.
6471   CPKlassSlot cp_klass_slot = _cp->klass_slot_at(_this_class_index);
6472   int resolved_klass_index = cp_klass_slot.resolved_klass_index();
6473   _cp->unresolved_klass_at_put(_this_class_index, hidden_index, resolved_klass_index);
6474   assert(_cp->klass_slot_at(_this_class_index).name_index() == _orig_cp_size,
6475          "Bad name_index");
6476 }
6477 
6478 void ClassFileParser::post_process_parsed_stream(const ClassFileStream* const stream,
6479                                                  ConstantPool* cp,
6480                                                  TRAPS) {
6481   assert(stream != NULL, "invariant");
6482   assert(stream->at_eos(), "invariant");
6483   assert(cp != NULL, "invariant");
6484   assert(_loader_data != NULL, "invariant");
6485 
6486   if (_class_name == vmSymbols::java_lang_Object()) {
6487     check_property(_local_interfaces == Universe::the_empty_instance_klass_array(),
6488                    "java.lang.Object cannot implement an interface in class file %s",
6489                    CHECK);
6490   }
6491   // We check super class after class file is parsed and format is checked
6492   if (_super_class_index > 0 && NULL ==_super_klass) {
6493     Symbol* const super_class_name = cp->klass_name_at(_super_class_index);
6494     if (_access_flags.is_interface()) {
6495       // Before attempting to resolve the superclass, check for class format
6496       // errors not checked yet.
6497       guarantee_property(super_class_name == vmSymbols::java_lang_Object(),


< prev index next >