< prev index next >

src/hotspot/share/classfile/classFileParser.cpp

Print this page

   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */


  24 #include "precompiled.hpp"
  25 #include "cds/cdsConfig.hpp"
  26 #include "classfile/classFileParser.hpp"
  27 #include "classfile/classFileStream.hpp"
  28 #include "classfile/classLoader.hpp"
  29 #include "classfile/classLoaderData.inline.hpp"
  30 #include "classfile/classLoadInfo.hpp"
  31 #include "classfile/defaultMethods.hpp"
  32 #include "classfile/fieldLayoutBuilder.hpp"
  33 #include "classfile/javaClasses.inline.hpp"
  34 #include "classfile/moduleEntry.hpp"
  35 #include "classfile/packageEntry.hpp"
  36 #include "classfile/symbolTable.hpp"
  37 #include "classfile/systemDictionary.hpp"
  38 #include "classfile/verificationType.hpp"
  39 #include "classfile/verifier.hpp"
  40 #include "classfile/vmClasses.hpp"
  41 #include "classfile/vmSymbols.hpp"
  42 #include "jvm.h"
  43 #include "logging/log.hpp"
  44 #include "logging/logStream.hpp"
  45 #include "memory/allocation.hpp"
  46 #include "memory/metadataFactory.hpp"
  47 #include "memory/oopFactory.hpp"
  48 #include "memory/resourceArea.hpp"
  49 #include "memory/universe.hpp"
  50 #include "oops/annotations.hpp"
  51 #include "oops/constantPool.inline.hpp"
  52 #include "oops/fieldInfo.hpp"
  53 #include "oops/fieldStreams.inline.hpp"

  54 #include "oops/instanceKlass.inline.hpp"
  55 #include "oops/instanceMirrorKlass.hpp"
  56 #include "oops/klass.inline.hpp"
  57 #include "oops/klassVtable.hpp"
  58 #include "oops/metadata.hpp"
  59 #include "oops/method.inline.hpp"
  60 #include "oops/oop.inline.hpp"
  61 #include "oops/recordComponent.hpp"
  62 #include "oops/symbol.hpp"
  63 #include "prims/jvmtiExport.hpp"
  64 #include "prims/jvmtiThreadState.hpp"
  65 #include "runtime/arguments.hpp"
  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/checkedCast.hpp"
  80 #include "utilities/copy.hpp"
  81 #include "utilities/formatBuffer.hpp"
  82 #include "utilities/exceptions.hpp"
  83 #include "utilities/globalDefinitions.hpp"
  84 #include "utilities/growableArray.hpp"
  85 #include "utilities/macros.hpp"
  86 #include "utilities/ostream.hpp"
  87 #include "utilities/resourceHash.hpp"

  88 #include "utilities/utf8.hpp"
  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 
 107 // Used for two backward compatibility reasons:

 132 #define JAVA_13_VERSION                   57
 133 
 134 #define JAVA_14_VERSION                   58
 135 
 136 #define JAVA_15_VERSION                   59
 137 
 138 #define JAVA_16_VERSION                   60
 139 
 140 #define JAVA_17_VERSION                   61
 141 
 142 #define JAVA_18_VERSION                   62
 143 
 144 #define JAVA_19_VERSION                   63
 145 
 146 #define JAVA_20_VERSION                   64
 147 
 148 #define JAVA_21_VERSION                   65
 149 
 150 #define JAVA_22_VERSION                   66
 151 


 152 void ClassFileParser::set_class_bad_constant_seen(short bad_constant) {
 153   assert((bad_constant == JVM_CONSTANT_Module ||
 154           bad_constant == JVM_CONSTANT_Package) && _major_version >= JAVA_9_VERSION,
 155          "Unexpected bad constant pool entry");
 156   if (_bad_constant_seen == 0) _bad_constant_seen = bad_constant;
 157 }
 158 
 159 void ClassFileParser::parse_constant_pool_entries(const ClassFileStream* const stream,
 160                                                   ConstantPool* cp,
 161                                                   const int length,
 162                                                   TRAPS) {
 163   assert(stream != nullptr, "invariant");
 164   assert(cp != nullptr, "invariant");
 165 
 166   // Use a local copy of ClassFileStream. It helps the C++ compiler to optimize
 167   // this function (_current can be allocated in a register, with scalar
 168   // replacement of aggregates). The _current pointer is copied back to
 169   // stream() when this function returns. DON'T call another method within
 170   // this method that uses stream().
 171   const ClassFileStream cfs1 = *stream;
 172   const ClassFileStream* const cfs = &cfs1;
 173 
 174   debug_only(const u1* const old_current = stream->current();)
 175 
 176   // Used for batching symbol allocations.
 177   const char* names[SymbolTable::symbol_alloc_batch_size];
 178   int lengths[SymbolTable::symbol_alloc_batch_size];
 179   int indices[SymbolTable::symbol_alloc_batch_size];
 180   unsigned int hashValues[SymbolTable::symbol_alloc_batch_size];
 181   int names_count = 0;
 182 
 183   // parsing  Index 0 is unused
 184   for (int index = 1; index < length; index++) {
 185     // Each of the following case guarantees one more byte in the stream
 186     // for the following tag or the access_flags following constant pool,
 187     // so we don't need bounds-check for reading tag.
 188     const u1 tag = cfs->get_u1_fast();
 189     switch (tag) {
 190       case JVM_CONSTANT_Class : {
 191         cfs->guarantee_more(3, CHECK);  // name_index, tag/access_flags
 192         const u2 name_index = cfs->get_u2_fast();
 193         cp->klass_index_at_put(index, name_index);
 194         break;
 195       }
 196       case JVM_CONSTANT_Fieldref: {
 197         cfs->guarantee_more(5, CHECK);  // class_index, name_and_type_index, tag/access_flags
 198         const u2 class_index = cfs->get_u2_fast();
 199         const u2 name_and_type_index = cfs->get_u2_fast();
 200         cp->field_at_put(index, class_index, name_and_type_index);
 201         break;
 202       }
 203       case JVM_CONSTANT_Methodref: {
 204         cfs->guarantee_more(5, CHECK);  // class_index, name_and_type_index, tag/access_flags
 205         const u2 class_index = cfs->get_u2_fast();
 206         const u2 name_and_type_index = cfs->get_u2_fast();
 207         cp->method_at_put(index, class_index, name_and_type_index);
 208         break;
 209       }
 210       case JVM_CONSTANT_InterfaceMethodref: {

 491         check_property(valid_symbol_at(name_ref_index),
 492           "Invalid constant pool index %u in class file %s",
 493           name_ref_index, CHECK);
 494         check_property(valid_symbol_at(signature_ref_index),
 495           "Invalid constant pool index %u in class file %s",
 496           signature_ref_index, CHECK);
 497         break;
 498       }
 499       case JVM_CONSTANT_Utf8:
 500         break;
 501       case JVM_CONSTANT_UnresolvedClass:         // fall-through
 502       case JVM_CONSTANT_UnresolvedClassInError: {
 503         ShouldNotReachHere();     // Only JVM_CONSTANT_ClassIndex should be present
 504         break;
 505       }
 506       case JVM_CONSTANT_ClassIndex: {
 507         const int class_index = cp->klass_index_at(index);
 508         check_property(valid_symbol_at(class_index),
 509           "Invalid constant pool index %u in class file %s",
 510           class_index, CHECK);



 511         cp->unresolved_klass_at_put(index, class_index, num_klasses++);
 512         break;
 513       }
 514       case JVM_CONSTANT_StringIndex: {
 515         const int string_index = cp->string_index_at(index);
 516         check_property(valid_symbol_at(string_index),
 517           "Invalid constant pool index %u in class file %s",
 518           string_index, CHECK);
 519         Symbol* const sym = cp->symbol_at(string_index);
 520         cp->unresolved_string_at_put(index, sym);
 521         break;
 522       }
 523       case JVM_CONSTANT_MethodHandle: {
 524         const int ref_index = cp->method_handle_index_at(index);
 525         check_property(valid_cp_range(ref_index, length),
 526           "Invalid constant pool index %u in class file %s",
 527           ref_index, CHECK);
 528         const constantTag tag = cp->tag_at(ref_index);
 529         const int ref_kind = cp->method_handle_ref_kind_at(index);
 530 

 700             }
 701           }
 702         } else {
 703           if (_need_verify) {
 704             // Method name and signature are individually verified above, when iterating
 705             // NameAndType_info.  Need to check here that signature is non-zero length and
 706             // the right type.
 707             if (!Signature::is_method(signature)) {
 708               throwIllegalSignature("Method", name, signature, CHECK);
 709             }
 710           }
 711           // If a class method name begins with '<', it must be "<init>" and have void signature.
 712           const unsigned int name_len = name->utf8_length();
 713           if (tag == JVM_CONSTANT_Methodref && name_len != 0 &&
 714               name->char_at(0) == JVM_SIGNATURE_SPECIAL) {
 715             if (name != vmSymbols::object_initializer_name()) {
 716               classfile_parse_error(
 717                 "Bad method name at constant pool index %u in class file %s",
 718                 name_ref_index, THREAD);
 719               return;
 720             } else if (!Signature::is_void_method(signature)) { // must have void signature.
 721               throwIllegalSignature("Method", name, signature, CHECK);
 722             }
 723           }
 724         }
 725         break;
 726       }
 727       case JVM_CONSTANT_MethodHandle: {
 728         const int ref_index = cp->method_handle_index_at(index);
 729         const int ref_kind = cp->method_handle_ref_kind_at(index);
 730         switch (ref_kind) {
 731           case JVM_REF_invokeVirtual:
 732           case JVM_REF_invokeStatic:
 733           case JVM_REF_invokeSpecial:
 734           case JVM_REF_newInvokeSpecial: {
 735             const int name_and_type_ref_index =
 736               cp->uncached_name_and_type_ref_index_at(ref_index);
 737             const int name_ref_index =
 738               cp->name_ref_index_at(name_and_type_ref_index);
 739             const Symbol* const name = cp->symbol_at(name_ref_index);
 740             if (ref_kind == JVM_REF_newInvokeSpecial) {
 741               if (name != vmSymbols::object_initializer_name()) {

 742                 classfile_parse_error(
 743                   "Bad constructor name at constant pool index %u in class file %s",
 744                     name_ref_index, THREAD);
 745                 return;
 746               }
 747             } else {
 748               if (name == vmSymbols::object_initializer_name()) {








 749                 classfile_parse_error(
 750                   "Bad method name at constant pool index %u in class file %s",
 751                   name_ref_index, THREAD);
 752                 return;
 753               }
 754             }
 755             break;
 756           }
 757           // Other ref_kinds are already fully checked in previous pass.
 758         } // switch(ref_kind)
 759         break;
 760       }
 761       case JVM_CONSTANT_MethodType: {
 762         const Symbol* const no_name = vmSymbols::type_name(); // place holder
 763         const Symbol* const signature = cp->method_type_signature_at(index);
 764         verify_legal_method_signature(no_name, signature, CHECK);
 765         break;
 766       }
 767       case JVM_CONSTANT_Utf8: {
 768         assert(cp->symbol_at(index)->refcount() != 0, "count corrupted");

 780 
 781   NameSigHash(Symbol* name, Symbol* sig) :
 782     _name(name),
 783     _sig(sig) {}
 784 
 785   static unsigned int hash(NameSigHash const& namesig) {
 786     return namesig._name->identity_hash() ^ namesig._sig->identity_hash();
 787   }
 788 
 789   static bool equals(NameSigHash const& e0, NameSigHash const& e1) {
 790     return (e0._name == e1._name) &&
 791           (e0._sig  == e1._sig);
 792   }
 793 };
 794 
 795 using NameSigHashtable = ResourceHashtable<NameSigHash, int,
 796                                            NameSigHash::HASH_ROW_SIZE,
 797                                            AnyObj::RESOURCE_AREA, mtInternal,
 798                                            &NameSigHash::hash, &NameSigHash::equals>;
 799 
 800 // Side-effects: populates the _local_interfaces field
 801 void ClassFileParser::parse_interfaces(const ClassFileStream* const stream,
 802                                        const int itfs_len,
 803                                        ConstantPool* const cp,









 804                                        bool* const has_nonstatic_concrete_methods,






 805                                        TRAPS) {
 806   assert(stream != nullptr, "invariant");
 807   assert(cp != nullptr, "invariant");
 808   assert(has_nonstatic_concrete_methods != nullptr, "invariant");
 809 
 810   if (itfs_len == 0) {
 811     _local_interfaces = Universe::the_empty_instance_klass_array();

 812   } else {
 813     assert(itfs_len > 0, "only called for len>0");
 814     _local_interfaces = MetadataFactory::new_array<InstanceKlass*>(_loader_data, itfs_len, nullptr, CHECK);
 815 
 816     int index;
 817     for (index = 0; index < itfs_len; index++) {
 818       const u2 interface_index = stream->get_u2(CHECK);
 819       Klass* interf;
 820       check_property(
 821         valid_klass_reference_at(interface_index),
 822         "Interface name has bad constant pool index %u in class file %s",
 823         interface_index, CHECK);
 824       if (cp->tag_at(interface_index).is_klass()) {
 825         interf = cp->resolved_klass_at(interface_index);
 826       } else {
 827         Symbol* const unresolved_klass  = cp->klass_name_at(interface_index);
 828 
 829         // Don't need to check legal name because it's checked when parsing constant pool.
 830         // But need to make sure it's not an array type.
 831         guarantee_property(unresolved_klass->char_at(0) != JVM_SIGNATURE_ARRAY,
 832                            "Bad interface name in class file %s", CHECK);
 833 
 834         // Call resolve_super so class circularity is checked
 835         interf = SystemDictionary::resolve_super_or_fail(
 836                                                   _class_name,
 837                                                   unresolved_klass,
 838                                                   Handle(THREAD, _loader_data->class_loader()),
 839                                                   _protection_domain,
 840                                                   false,
 841                                                   CHECK);
 842       }
 843 
 844       if (!interf->is_interface()) {
 845         THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(),
 846                   err_msg("class %s can not implement %s, because it is not an interface (%s)",
 847                           _class_name->as_klass_external_name(),
 848                           interf->external_name(),
 849                           interf->class_in_module_of_loader()));
 850       }
 851 
 852       if (InstanceKlass::cast(interf)->has_nonstatic_concrete_methods()) {
 853         *has_nonstatic_concrete_methods = true;
 854       }
 855       _local_interfaces->at_put(index, InstanceKlass::cast(interf));
 856     }
 857 
 858     if (!_need_verify || itfs_len <= 1) {
 859       return;
 860     }
 861 
 862     // Check if there's any duplicates in interfaces
 863     ResourceMark rm(THREAD);
 864     // Set containing interface names
 865     ResourceHashtable<Symbol*, int>* interface_names = new ResourceHashtable<Symbol*, int>();
 866     for (index = 0; index < itfs_len; index++) {
 867       const InstanceKlass* const k = _local_interfaces->at(index);
 868       Symbol* interface_name = k->name();
 869       // If no duplicates, add (name, nullptr) in hashtable interface_names.
 870       if (!interface_names->put(interface_name, 0)) {
 871         classfile_parse_error("Duplicate interface name \"%s\" in class file %s",
 872                                interface_name->as_C_string(), THREAD);
 873         return;
 874       }
 875     }
 876   }
 877 }
 878 
 879 void ClassFileParser::verify_constantvalue(const ConstantPool* const cp,
 880                                            int constantvalue_index,
 881                                            int signature_index,
 882                                            TRAPS) const {
 883   // Make sure the constant pool entry is of a type appropriate to this field
 884   guarantee_property(
 885     (constantvalue_index > 0 &&
 886       constantvalue_index < cp->length()),
 887     "Bad initial value index %u in ConstantValue attribute in class file %s",
 888     constantvalue_index, CHECK);

 934 
 935 class AnnotationCollector : public ResourceObj{
 936 public:
 937   enum Location { _in_field, _in_method, _in_class };
 938   enum ID {
 939     _unknown = 0,
 940     _method_CallerSensitive,
 941     _method_ForceInline,
 942     _method_DontInline,
 943     _method_ChangesCurrentThread,
 944     _method_JvmtiMountTransition,
 945     _method_InjectedProfile,
 946     _method_LambdaForm_Compiled,
 947     _method_Hidden,
 948     _method_Scoped,
 949     _method_IntrinsicCandidate,
 950     _jdk_internal_vm_annotation_Contended,
 951     _field_Stable,
 952     _jdk_internal_vm_annotation_ReservedStackAccess,
 953     _jdk_internal_ValueBased,



 954     _annotation_LIMIT
 955   };
 956   const Location _location;
 957   int _annotations_present;
 958   u2 _contended_group;
 959 
 960   AnnotationCollector(Location location)
 961     : _location(location), _annotations_present(0), _contended_group(0)
 962   {
 963     assert((int)_annotation_LIMIT <= (int)sizeof(_annotations_present) * BitsPerByte, "");
 964   }
 965   // If this annotation name has an ID, report it (or _none).
 966   ID annotation_index(const ClassLoaderData* loader_data, const Symbol* name, bool can_access_vm_annotations);
 967   // Set the annotation name:
 968   void set_annotation(ID id) {
 969     assert((int)id >= 0 && (int)id < (int)_annotation_LIMIT, "oob");
 970     _annotations_present |= (int)nth_bit((int)id);
 971   }
 972 
 973   void remove_annotation(ID id) {

1330                                             CHECK);
1331   parsed_annotations->set_field_annotations(a);
1332   a = assemble_annotations(runtime_visible_type_annotations,
1333                            runtime_visible_type_annotations_length,
1334                            runtime_invisible_type_annotations,
1335                            runtime_invisible_type_annotations_length,
1336                            CHECK);
1337   parsed_annotations->set_field_type_annotations(a);
1338   return;
1339 }
1340 
1341 
1342 // Field allocation types. Used for computing field offsets.
1343 
1344 enum FieldAllocationType {
1345   STATIC_OOP,           // Oops
1346   STATIC_BYTE,          // Boolean, Byte, char
1347   STATIC_SHORT,         // shorts
1348   STATIC_WORD,          // ints
1349   STATIC_DOUBLE,        // aligned long or double

1350   NONSTATIC_OOP,
1351   NONSTATIC_BYTE,
1352   NONSTATIC_SHORT,
1353   NONSTATIC_WORD,
1354   NONSTATIC_DOUBLE,

1355   MAX_FIELD_ALLOCATION_TYPE,
1356   BAD_ALLOCATION_TYPE = -1
1357 };
1358 
1359 static FieldAllocationType _basic_type_to_atype[2 * (T_CONFLICT + 1)] = {
1360   BAD_ALLOCATION_TYPE, // 0
1361   BAD_ALLOCATION_TYPE, // 1
1362   BAD_ALLOCATION_TYPE, // 2
1363   BAD_ALLOCATION_TYPE, // 3
1364   NONSTATIC_BYTE ,     // T_BOOLEAN     =  4,
1365   NONSTATIC_SHORT,     // T_CHAR        =  5,
1366   NONSTATIC_WORD,      // T_FLOAT       =  6,
1367   NONSTATIC_DOUBLE,    // T_DOUBLE      =  7,
1368   NONSTATIC_BYTE,      // T_BYTE        =  8,
1369   NONSTATIC_SHORT,     // T_SHORT       =  9,
1370   NONSTATIC_WORD,      // T_INT         = 10,
1371   NONSTATIC_DOUBLE,    // T_LONG        = 11,
1372   NONSTATIC_OOP,       // T_OBJECT      = 12,
1373   NONSTATIC_OOP,       // T_ARRAY       = 13,
1374   BAD_ALLOCATION_TYPE, // T_VOID        = 14,
1375   BAD_ALLOCATION_TYPE, // T_ADDRESS     = 15,
1376   BAD_ALLOCATION_TYPE, // T_NARROWOOP   = 16,
1377   BAD_ALLOCATION_TYPE, // T_METADATA    = 17,
1378   BAD_ALLOCATION_TYPE, // T_NARROWKLASS = 18,
1379   BAD_ALLOCATION_TYPE, // T_CONFLICT    = 19,

1380   BAD_ALLOCATION_TYPE, // 0
1381   BAD_ALLOCATION_TYPE, // 1
1382   BAD_ALLOCATION_TYPE, // 2
1383   BAD_ALLOCATION_TYPE, // 3
1384   STATIC_BYTE ,        // T_BOOLEAN     =  4,
1385   STATIC_SHORT,        // T_CHAR        =  5,
1386   STATIC_WORD,         // T_FLOAT       =  6,
1387   STATIC_DOUBLE,       // T_DOUBLE      =  7,
1388   STATIC_BYTE,         // T_BYTE        =  8,
1389   STATIC_SHORT,        // T_SHORT       =  9,
1390   STATIC_WORD,         // T_INT         = 10,
1391   STATIC_DOUBLE,       // T_LONG        = 11,
1392   STATIC_OOP,          // T_OBJECT      = 12,
1393   STATIC_OOP,          // T_ARRAY       = 13,
1394   BAD_ALLOCATION_TYPE, // T_VOID        = 14,
1395   BAD_ALLOCATION_TYPE, // T_ADDRESS     = 15,
1396   BAD_ALLOCATION_TYPE, // T_NARROWOOP   = 16,
1397   BAD_ALLOCATION_TYPE, // T_METADATA    = 17,
1398   BAD_ALLOCATION_TYPE, // T_NARROWKLASS = 18,
1399   BAD_ALLOCATION_TYPE, // T_CONFLICT    = 19,

1400 };
1401 
1402 static FieldAllocationType basic_type_to_atype(bool is_static, BasicType type) {
1403   assert(type >= T_BOOLEAN && type < T_VOID, "only allowable values");
1404   FieldAllocationType result = _basic_type_to_atype[type + (is_static ? (T_CONFLICT + 1) : 0)];
1405   assert(result != BAD_ALLOCATION_TYPE, "bad type");



1406   return result;
1407 }
1408 
1409 class ClassFileParser::FieldAllocationCount : public ResourceObj {
1410  public:
1411   u2 count[MAX_FIELD_ALLOCATION_TYPE];
1412 
1413   FieldAllocationCount() {
1414     for (int i = 0; i < MAX_FIELD_ALLOCATION_TYPE; i++) {
1415       count[i] = 0;
1416     }
1417   }
1418 
1419   void update(bool is_static, BasicType type) {
1420     FieldAllocationType atype = basic_type_to_atype(is_static, type);
1421     if (atype != BAD_ALLOCATION_TYPE) {
1422       // Make sure there is no overflow with injected fields.
1423       assert(count[atype] < 0xFFFF, "More than 65535 fields");
1424       count[atype]++;
1425     }
1426   }
1427 };
1428 
1429 // Side-effects: populates the _fields, _fields_annotations,
1430 // _fields_type_annotations fields
1431 void ClassFileParser::parse_fields(const ClassFileStream* const cfs,
1432                                    bool is_interface,
1433                                    FieldAllocationCount* const fac,
1434                                    ConstantPool* cp,
1435                                    const int cp_size,
1436                                    u2* const java_fields_count_ptr,
1437                                    TRAPS) {
1438 
1439   assert(cfs != nullptr, "invariant");
1440   assert(fac != nullptr, "invariant");
1441   assert(cp != nullptr, "invariant");
1442   assert(java_fields_count_ptr != nullptr, "invariant");
1443 
1444   assert(nullptr == _fields_annotations, "invariant");
1445   assert(nullptr == _fields_type_annotations, "invariant");
1446 

1447   cfs->guarantee_more(2, CHECK);  // length
1448   const u2 length = cfs->get_u2_fast();
1449   *java_fields_count_ptr = length;
1450 
1451   int num_injected = 0;
1452   const InjectedField* const injected = JavaClasses::get_injected(_class_name,
1453                                                                   &num_injected);
1454   const int total_fields = length + num_injected;




1455 
1456   // Allocate a temporary resource array to collect field data.
1457   // After parsing all fields, data are stored in a UNSIGNED5 compressed stream.
1458   _temp_field_info = new GrowableArray<FieldInfo>(total_fields);
1459 

1460   ResourceMark rm(THREAD);
1461   for (int n = 0; n < length; n++) {
1462     // access_flags, name_index, descriptor_index, attributes_count
1463     cfs->guarantee_more(8, CHECK);
1464 




1465     AccessFlags access_flags;
1466     const jint flags = cfs->get_u2_fast() & JVM_RECOGNIZED_FIELD_MODIFIERS;
1467     verify_legal_field_modifiers(flags, is_interface, CHECK);
1468     access_flags.set_flags(flags);
1469     FieldInfo::FieldFlags fieldFlags(0);
1470 
1471     const u2 name_index = cfs->get_u2_fast();
1472     check_property(valid_symbol_at(name_index),
1473       "Invalid constant pool index %u for field name in class file %s",
1474       name_index, CHECK);
1475     const Symbol* const name = cp->symbol_at(name_index);
1476     verify_legal_field_name(name, CHECK);
1477 
1478     const u2 signature_index = cfs->get_u2_fast();
1479     check_property(valid_symbol_at(signature_index),
1480       "Invalid constant pool index %u for field signature in class file %s",
1481       signature_index, CHECK);
1482     const Symbol* const sig = cp->symbol_at(signature_index);
1483     verify_legal_field_signature(name, sig, CHECK);

1484 
1485     u2 constantvalue_index = 0;
1486     bool is_synthetic = false;
1487     u2 generic_signature_index = 0;
1488     const bool is_static = access_flags.is_static();
1489     FieldAnnotationCollector parsed_annotations(_loader_data);
1490 


1491     const u2 attributes_count = cfs->get_u2_fast();
1492     if (attributes_count > 0) {
1493       parse_field_attributes(cfs,
1494                              attributes_count,
1495                              is_static,
1496                              signature_index,
1497                              &constantvalue_index,
1498                              &is_synthetic,
1499                              &generic_signature_index,
1500                              &parsed_annotations,
1501                              CHECK);
1502 
1503       if (parsed_annotations.field_annotations() != nullptr) {
1504         if (_fields_annotations == nullptr) {
1505           _fields_annotations = MetadataFactory::new_array<AnnotationArray*>(
1506                                              _loader_data, length, nullptr,
1507                                              CHECK);
1508         }
1509         _fields_annotations->at_put(n, parsed_annotations.field_annotations());










1510         parsed_annotations.set_field_annotations(nullptr);
1511       }
1512       if (parsed_annotations.field_type_annotations() != nullptr) {
1513         if (_fields_type_annotations == nullptr) {
1514           _fields_type_annotations =
1515             MetadataFactory::new_array<AnnotationArray*>(_loader_data,
1516                                                          length,
1517                                                          nullptr,
1518                                                          CHECK);
1519         }
1520         _fields_type_annotations->at_put(n, parsed_annotations.field_type_annotations());
1521         parsed_annotations.set_field_type_annotations(nullptr);
1522       }
1523 
1524       if (is_synthetic) {
1525         access_flags.set_is_synthetic();
1526       }
1527       if (generic_signature_index != 0) {
1528         fieldFlags.update_generic(true);
1529       }
1530     }
1531 
1532     const BasicType type = cp->basic_type_for_signature_at(signature_index);
1533 
1534     // Update FieldAllocationCount for this kind of field
1535     fac->update(is_static, type);



1536 
1537     FieldInfo fi(access_flags, name_index, signature_index, constantvalue_index, fieldFlags);
1538     fi.set_index(n);
1539     if (fieldFlags.is_generic()) {
1540       fi.set_generic_signature_index(generic_signature_index);
1541     }
1542     parsed_annotations.apply_to(&fi);
1543     if (fi.field_flags().is_contended()) {
1544       _has_contended_fields = true;
1545     }
1546     _temp_field_info->append(fi);
1547   }
1548   assert(_temp_field_info->length() == length, "Must be");
1549 
1550   int index = length;
1551   if (num_injected != 0) {
1552     for (int n = 0; n < num_injected; n++) {
1553       // Check for duplicates
1554       if (injected[n].may_be_java) {
1555         const Symbol* const name      = injected[n].name();

1563             duplicate = true;
1564             break;
1565           }
1566         }
1567         if (duplicate) {
1568           // These will be removed from the field array at the end
1569           continue;
1570         }
1571       }
1572 
1573       // Injected field
1574       FieldInfo::FieldFlags fflags(0);
1575       fflags.update_injected(true);
1576       AccessFlags aflags;
1577       FieldInfo fi(aflags, (u2)(injected[n].name_index), (u2)(injected[n].signature_index), 0, fflags);
1578       fi.set_index(index);
1579       _temp_field_info->append(fi);
1580 
1581       // Update FieldAllocationCount for this kind of field
1582       const BasicType type = Signature::basic_type(injected[n].signature());
1583       fac->update(false, type);
1584       index++;
1585     }
1586   }
1587 










































1588   assert(_temp_field_info->length() == index, "Must be");
1589 
1590   if (_need_verify && length > 1) {
1591     // Check duplicated fields
1592     ResourceMark rm(THREAD);
1593     // Set containing name-signature pairs
1594     NameSigHashtable* names_and_sigs = new NameSigHashtable();
1595     for (int i = 0; i < _temp_field_info->length(); i++) {
1596       NameSigHash name_and_sig(_temp_field_info->adr_at(i)->name(_cp),
1597                                _temp_field_info->adr_at(i)->signature(_cp));
1598       // If no duplicates, add name/signature in hashtable names_and_sigs.
1599       if(!names_and_sigs->put(name_and_sig, 0)) {
1600         classfile_parse_error("Duplicate field name \"%s\" with signature \"%s\" in class file %s",
1601                                name_and_sig._name->as_C_string(), name_and_sig._sig->as_klass_external_name(), THREAD);
1602         return;
1603       }
1604     }
1605   }
1606 }
1607 

1851         "Exception name has bad type at constant pool %u in class file %s",
1852         checked_exception, CHECK_NULL);
1853     }
1854   }
1855   // check exceptions attribute length
1856   if (_need_verify) {
1857     guarantee_property(method_attribute_length == (sizeof(*checked_exceptions_length) +
1858                                                    sizeof(u2) * size),
1859                       "Exceptions attribute has wrong length in class file %s", CHECK_NULL);
1860   }
1861   return checked_exceptions_start;
1862 }
1863 
1864 void ClassFileParser::throwIllegalSignature(const char* type,
1865                                             const Symbol* name,
1866                                             const Symbol* sig,
1867                                             TRAPS) const {
1868   assert(name != nullptr, "invariant");
1869   assert(sig != nullptr, "invariant");
1870 





1871   ResourceMark rm(THREAD);
1872   Exceptions::fthrow(THREAD_AND_LOCATION,
1873       vmSymbols::java_lang_ClassFormatError(),
1874       "%s \"%s\" in class %s has illegal signature \"%s\"", type,
1875       name->as_C_string(), _class_name->as_C_string(), sig->as_C_string());
1876 }
1877 
1878 AnnotationCollector::ID
1879 AnnotationCollector::annotation_index(const ClassLoaderData* loader_data,
1880                                       const Symbol* name,
1881                                       const bool can_access_vm_annotations) {
1882   const vmSymbolID sid = vmSymbols::find_sid(name);
1883   // Privileged code can use all annotations.  Other code silently drops some.
1884   const bool privileged = loader_data->is_boot_class_loader_data() ||
1885                           loader_data->is_platform_class_loader_data() ||
1886                           can_access_vm_annotations;
1887   switch (sid) {
1888     case VM_SYMBOL_ENUM_NAME(reflect_CallerSensitive_signature): {
1889       if (_location != _in_method)  break;  // only allow for methods
1890       if (!privileged)              break;  // only allow in privileged code
1891       return _method_CallerSensitive;
1892     }
1893     case VM_SYMBOL_ENUM_NAME(jdk_internal_vm_annotation_ForceInline_signature): {
1894       if (_location != _in_method)  break;  // only allow for methods
1895       if (!privileged)              break;  // only allow in privileged code

1942     }
1943     case VM_SYMBOL_ENUM_NAME(jdk_internal_vm_annotation_Contended_signature): {
1944       if (_location != _in_field && _location != _in_class) {
1945         break;  // only allow for fields and classes
1946       }
1947       if (!EnableContended || (RestrictContended && !privileged)) {
1948         break;  // honor privileges
1949       }
1950       return _jdk_internal_vm_annotation_Contended;
1951     }
1952     case VM_SYMBOL_ENUM_NAME(jdk_internal_vm_annotation_ReservedStackAccess_signature): {
1953       if (_location != _in_method)  break;  // only allow for methods
1954       if (RestrictReservedStack && !privileged) break; // honor privileges
1955       return _jdk_internal_vm_annotation_ReservedStackAccess;
1956     }
1957     case VM_SYMBOL_ENUM_NAME(jdk_internal_ValueBased_signature): {
1958       if (_location != _in_class)   break;  // only allow for classes
1959       if (!privileged)              break;  // only allow in privileged code
1960       return _jdk_internal_ValueBased;
1961     }












1962     default: {
1963       break;
1964     }
1965   }
1966   return AnnotationCollector::_unknown;
1967 }
1968 
1969 void ClassFileParser::FieldAnnotationCollector::apply_to(FieldInfo* f) {
1970   if (is_contended())
1971     // Setting the contended group also sets the contended bit in field flags
1972     f->set_contended_group(contended_group());
1973   if (is_stable())
1974     (f->field_flags_addr())->update_stable(true);
1975 }
1976 
1977 ClassFileParser::FieldAnnotationCollector::~FieldAnnotationCollector() {
1978   // If there's an error deallocate metadata for field annotations
1979   MetadataFactory::free_array<u1>(_loader_data, _field_annotations);
1980   MetadataFactory::free_array<u1>(_loader_data, _field_type_annotations);
1981 }

2157       runtime_invisible_type_annotations_length > 0) {
2158     a = assemble_annotations(runtime_visible_type_annotations,
2159                              runtime_visible_type_annotations_length,
2160                              runtime_invisible_type_annotations,
2161                              runtime_invisible_type_annotations_length,
2162                              CHECK);
2163     cm->set_type_annotations(a);
2164   }
2165 }
2166 
2167 
2168 // Note: the parse_method below is big and clunky because all parsing of the code and exceptions
2169 // attribute is inlined. This is cumbersome to avoid since we inline most of the parts in the
2170 // Method* to save footprint, so we only know the size of the resulting Method* when the
2171 // entire method attribute is parsed.
2172 //
2173 // The has_localvariable_table parameter is used to pass up the value to InstanceKlass.
2174 
2175 Method* ClassFileParser::parse_method(const ClassFileStream* const cfs,
2176                                       bool is_interface,


2177                                       const ConstantPool* cp,
2178                                       bool* const has_localvariable_table,
2179                                       TRAPS) {
2180   assert(cfs != nullptr, "invariant");
2181   assert(cp != nullptr, "invariant");
2182   assert(has_localvariable_table != nullptr, "invariant");
2183 
2184   ResourceMark rm(THREAD);
2185   // Parse fixed parts:
2186   // access_flags, name_index, descriptor_index, attributes_count
2187   cfs->guarantee_more(8, CHECK_NULL);
2188 
2189   int flags = cfs->get_u2_fast();
2190   const u2 name_index = cfs->get_u2_fast();
2191   const int cp_size = cp->length();
2192   check_property(
2193     valid_symbol_at(name_index),
2194     "Illegal constant pool index %u for method name in class file %s",
2195     name_index, CHECK_NULL);
2196   const Symbol* const name = cp->symbol_at(name_index);

2198 
2199   const u2 signature_index = cfs->get_u2_fast();
2200   guarantee_property(
2201     valid_symbol_at(signature_index),
2202     "Illegal constant pool index %u for method signature in class file %s",
2203     signature_index, CHECK_NULL);
2204   const Symbol* const signature = cp->symbol_at(signature_index);
2205 
2206   if (name == vmSymbols::class_initializer_name()) {
2207     // We ignore the other access flags for a valid class initializer.
2208     // (JVM Spec 2nd ed., chapter 4.6)
2209     if (_major_version < 51) { // backward compatibility
2210       flags = JVM_ACC_STATIC;
2211     } else if ((flags & JVM_ACC_STATIC) == JVM_ACC_STATIC) {
2212       flags &= JVM_ACC_STATIC | (_major_version <= JAVA_16_VERSION ? JVM_ACC_STRICT : 0);
2213     } else {
2214       classfile_parse_error("Method <clinit> is not static in class file %s", THREAD);
2215       return nullptr;
2216     }
2217   } else {
2218     verify_legal_method_modifiers(flags, is_interface, name, CHECK_NULL);
2219   }
2220 
2221   if (name == vmSymbols::object_initializer_name() && is_interface) {
2222     classfile_parse_error("Interface cannot have a method named <init>, class file %s", THREAD);
2223     return nullptr;
2224   }
2225 









2226   int args_size = -1;  // only used when _need_verify is true
2227   if (_need_verify) {
2228     verify_legal_name_with_signature(name, signature, CHECK_NULL);
2229     args_size = ((flags & JVM_ACC_STATIC) ? 0 : 1) +
2230                  verify_legal_method_signature(name, signature, CHECK_NULL);
2231     if (args_size > MAX_ARGS_SIZE) {
2232       classfile_parse_error("Too many arguments in method signature in class file %s", THREAD);
2233       return nullptr;
2234     }
2235   }
2236 
2237   AccessFlags access_flags(flags & JVM_RECOGNIZED_METHOD_MODIFIERS);
2238 
2239   // Default values for code and exceptions attribute elements
2240   u2 max_stack = 0;
2241   u2 max_locals = 0;
2242   u4 code_length = 0;
2243   const u1* code_start = 0;
2244   u2 exception_table_length = 0;
2245   const unsafe_u2* exception_table_start = nullptr; // (potentially unaligned) pointer to array of u2 elements

2770     if (m->is_empty_method()) {
2771       _has_empty_finalizer = true;
2772     } else {
2773       _has_finalizer = true;
2774     }
2775   }
2776   if (name == vmSymbols::object_initializer_name() &&
2777       signature == vmSymbols::void_method_signature() &&
2778       m->is_vanilla_constructor()) {
2779     _has_vanilla_constructor = true;
2780   }
2781 
2782   NOT_PRODUCT(m->verify());
2783   return m;
2784 }
2785 
2786 
2787 // Side-effects: populates the _methods field in the parser
2788 void ClassFileParser::parse_methods(const ClassFileStream* const cfs,
2789                                     bool is_interface,


2790                                     bool* const has_localvariable_table,
2791                                     bool* has_final_method,
2792                                     bool* declares_nonstatic_concrete_methods,
2793                                     TRAPS) {
2794   assert(cfs != nullptr, "invariant");
2795   assert(has_localvariable_table != nullptr, "invariant");
2796   assert(has_final_method != nullptr, "invariant");
2797   assert(declares_nonstatic_concrete_methods != nullptr, "invariant");
2798 
2799   assert(nullptr == _methods, "invariant");
2800 
2801   cfs->guarantee_more(2, CHECK);  // length
2802   const u2 length = cfs->get_u2_fast();
2803   if (length == 0) {
2804     _methods = Universe::the_empty_method_array();
2805   } else {
2806     _methods = MetadataFactory::new_array<Method*>(_loader_data,
2807                                                    length,
2808                                                    nullptr,
2809                                                    CHECK);
2810 
2811     for (int index = 0; index < length; index++) {
2812       Method* method = parse_method(cfs,
2813                                     is_interface,


2814                                     _cp,
2815                                     has_localvariable_table,
2816                                     CHECK);
2817 
2818       if (method->is_final()) {
2819         *has_final_method = true;
2820       }
2821       // declares_nonstatic_concrete_methods: declares concrete instance methods, any access flags
2822       // used for interface initialization, and default method inheritance analysis
2823       if (is_interface && !(*declares_nonstatic_concrete_methods)
2824         && !method->is_abstract() && !method->is_static()) {
2825         *declares_nonstatic_concrete_methods = true;
2826       }
2827       _methods->at_put(index, method);
2828     }
2829 
2830     if (_need_verify && length > 1) {
2831       // Check duplicated methods
2832       ResourceMark rm(THREAD);
2833       // Set containing name-signature pairs

3059         valid_klass_reference_at(outer_class_info_index),
3060       "outer_class_info_index %u has bad constant type in class file %s",
3061       outer_class_info_index, CHECK_0);
3062 
3063     if (outer_class_info_index != 0) {
3064       const Symbol* const outer_class_name = cp->klass_name_at(outer_class_info_index);
3065       char* bytes = (char*)outer_class_name->bytes();
3066       guarantee_property(bytes[0] != JVM_SIGNATURE_ARRAY,
3067                          "Outer class is an array class in class file %s", CHECK_0);
3068     }
3069     // Inner class name
3070     const u2 inner_name_index = cfs->get_u2_fast();
3071     check_property(
3072       inner_name_index == 0 || valid_symbol_at(inner_name_index),
3073       "inner_name_index %u has bad constant type in class file %s",
3074       inner_name_index, CHECK_0);
3075     if (_need_verify) {
3076       guarantee_property(inner_class_info_index != outer_class_info_index,
3077                          "Class is both outer and inner class in class file %s", CHECK_0);
3078     }
3079     // Access flags
3080     jint flags;
3081     // JVM_ACC_MODULE is defined in JDK-9 and later.
3082     if (_major_version >= JAVA_9_VERSION) {
3083       flags = cfs->get_u2_fast() & (RECOGNIZED_INNER_CLASS_MODIFIERS | JVM_ACC_MODULE);
3084     } else {
3085       flags = cfs->get_u2_fast() & RECOGNIZED_INNER_CLASS_MODIFIERS;
3086     }




3087     if ((flags & JVM_ACC_INTERFACE) && _major_version < JAVA_6_VERSION) {
3088       // Set abstract bit for old class files for backward compatibility
3089       flags |= JVM_ACC_ABSTRACT;
3090     }
3091     verify_legal_class_modifiers(flags, CHECK_0);












3092     AccessFlags inner_access_flags(flags);
3093 
3094     inner_classes->at_put(index++, inner_class_info_index);
3095     inner_classes->at_put(index++, outer_class_info_index);
3096     inner_classes->at_put(index++, inner_name_index);
3097     inner_classes->at_put(index++, inner_access_flags.as_short());
3098   }
3099 
3100   // Check for circular and duplicate entries.
3101   bool has_circularity = false;
3102   if (_need_verify) {
3103     has_circularity = check_inner_classes_circularity(cp, length * 4, CHECK_0);
3104     if (has_circularity) {
3105       // If circularity check failed then ignore InnerClasses attribute.
3106       MetadataFactory::free_array<u2>(_loader_data, _inner_classes);
3107       index = 0;
3108       if (parsed_enclosingmethod_attribute) {
3109         inner_classes = MetadataFactory::new_array<u2>(_loader_data, 2, CHECK_0);
3110         _inner_classes = inner_classes;
3111       } else {

3175   if (length > 0) {
3176     int index = 0;
3177     cfs->guarantee_more(2 * length, CHECK_0);
3178     for (int n = 0; n < length; n++) {
3179       const u2 class_info_index = cfs->get_u2_fast();
3180       check_property(
3181         valid_klass_reference_at(class_info_index),
3182         "Permitted subclass class_info_index %u has bad constant type in class file %s",
3183         class_info_index, CHECK_0);
3184       permitted_subclasses->at_put(index++, class_info_index);
3185     }
3186     assert(index == size, "wrong size");
3187   }
3188 
3189   // Restore buffer's current position.
3190   cfs->set_current(current_mark);
3191 
3192   return length;
3193 }
3194 

































3195 //  Record {
3196 //    u2 attribute_name_index;
3197 //    u4 attribute_length;
3198 //    u2 components_count;
3199 //    component_info components[components_count];
3200 //  }
3201 //  component_info {
3202 //    u2 name_index;
3203 //    u2 descriptor_index
3204 //    u2 attributes_count;
3205 //    attribute_info_attributes[attributes_count];
3206 //  }
3207 u4 ClassFileParser::parse_classfile_record_attribute(const ClassFileStream* const cfs,
3208                                                      const ConstantPool* cp,
3209                                                      const u1* const record_attribute_start,
3210                                                      TRAPS) {
3211   const u1* const current_mark = cfs->current();
3212   int components_count = 0;
3213   unsigned int calculate_attr_size = 0;
3214   if (record_attribute_start != nullptr) {

3459   }
3460   guarantee_property(current_start + attribute_byte_length == cfs->current(),
3461                      "Bad length on BootstrapMethods in class file %s",
3462                      CHECK);
3463 }
3464 
3465 void ClassFileParser::parse_classfile_attributes(const ClassFileStream* const cfs,
3466                                                  ConstantPool* cp,
3467                  ClassFileParser::ClassAnnotationCollector* parsed_annotations,
3468                                                  TRAPS) {
3469   assert(cfs != nullptr, "invariant");
3470   assert(cp != nullptr, "invariant");
3471   assert(parsed_annotations != nullptr, "invariant");
3472 
3473   // Set inner classes attribute to default sentinel
3474   _inner_classes = Universe::the_empty_short_array();
3475   // Set nest members attribute to default sentinel
3476   _nest_members = Universe::the_empty_short_array();
3477   // Set _permitted_subclasses attribute to default sentinel
3478   _permitted_subclasses = Universe::the_empty_short_array();


3479   cfs->guarantee_more(2, CHECK);  // attributes_count
3480   u2 attributes_count = cfs->get_u2_fast();
3481   bool parsed_sourcefile_attribute = false;
3482   bool parsed_innerclasses_attribute = false;
3483   bool parsed_nest_members_attribute = false;
3484   bool parsed_permitted_subclasses_attribute = false;

3485   bool parsed_nest_host_attribute = false;
3486   bool parsed_record_attribute = false;
3487   bool parsed_enclosingmethod_attribute = false;
3488   bool parsed_bootstrap_methods_attribute = false;
3489   const u1* runtime_visible_annotations = nullptr;
3490   int runtime_visible_annotations_length = 0;
3491   const u1* runtime_invisible_annotations = nullptr;
3492   int runtime_invisible_annotations_length = 0;
3493   const u1* runtime_visible_type_annotations = nullptr;
3494   int runtime_visible_type_annotations_length = 0;
3495   const u1* runtime_invisible_type_annotations = nullptr;
3496   int runtime_invisible_type_annotations_length = 0;
3497   bool runtime_invisible_type_annotations_exists = false;
3498   bool runtime_invisible_annotations_exists = false;
3499   bool parsed_source_debug_ext_annotations_exist = false;
3500   const u1* inner_classes_attribute_start = nullptr;
3501   u4  inner_classes_attribute_length = 0;
3502   u2  enclosing_method_class_index = 0;
3503   u2  enclosing_method_method_index = 0;
3504   const u1* nest_members_attribute_start = nullptr;
3505   u4  nest_members_attribute_length = 0;
3506   const u1* record_attribute_start = nullptr;
3507   u4  record_attribute_length = 0;
3508   const u1* permitted_subclasses_attribute_start = nullptr;
3509   u4  permitted_subclasses_attribute_length = 0;


3510 
3511   // Iterate over attributes
3512   while (attributes_count--) {
3513     cfs->guarantee_more(6, CHECK);  // attribute_name_index, attribute_length
3514     const u2 attribute_name_index = cfs->get_u2_fast();
3515     const u4 attribute_length = cfs->get_u4_fast();
3516     check_property(
3517       valid_symbol_at(attribute_name_index),
3518       "Attribute name has bad constant pool index %u in class file %s",
3519       attribute_name_index, CHECK);
3520     const Symbol* const tag = cp->symbol_at(attribute_name_index);
3521     if (tag == vmSymbols::tag_source_file()) {
3522       // Check for SourceFile tag
3523       if (_need_verify) {
3524         guarantee_property(attribute_length == 2, "Wrong SourceFile attribute length in class file %s", CHECK);
3525       }
3526       if (parsed_sourcefile_attribute) {
3527         classfile_parse_error("Multiple SourceFile attributes in class file %s", THREAD);
3528         return;
3529       } else {

3716               return;
3717             }
3718             parsed_record_attribute = true;
3719             record_attribute_start = cfs->current();
3720             record_attribute_length = attribute_length;
3721           } else if (_major_version >= JAVA_17_VERSION) {
3722             if (tag == vmSymbols::tag_permitted_subclasses()) {
3723               if (parsed_permitted_subclasses_attribute) {
3724                 classfile_parse_error("Multiple PermittedSubclasses attributes in class file %s", CHECK);
3725                 return;
3726               }
3727               // Classes marked ACC_FINAL cannot have a PermittedSubclasses attribute.
3728               if (_access_flags.is_final()) {
3729                 classfile_parse_error("PermittedSubclasses attribute in final class file %s", CHECK);
3730                 return;
3731               }
3732               parsed_permitted_subclasses_attribute = true;
3733               permitted_subclasses_attribute_start = cfs->current();
3734               permitted_subclasses_attribute_length = attribute_length;
3735             }









3736           }
3737           // Skip attribute_length for any attribute where major_verson >= JAVA_17_VERSION
3738           cfs->skip_u1(attribute_length, CHECK);
3739         } else {
3740           // Unknown attribute
3741           cfs->skip_u1(attribute_length, CHECK);
3742         }
3743       } else {
3744         // Unknown attribute
3745         cfs->skip_u1(attribute_length, CHECK);
3746       }
3747     } else {
3748       // Unknown attribute
3749       cfs->skip_u1(attribute_length, CHECK);
3750     }
3751   }
3752   _class_annotations = assemble_annotations(runtime_visible_annotations,
3753                                             runtime_visible_annotations_length,
3754                                             runtime_invisible_annotations,
3755                                             runtime_invisible_annotations_length,

3796                             CHECK);
3797     if (_need_verify) {
3798       guarantee_property(record_attribute_length == calculated_attr_length,
3799                          "Record attribute has wrong length in class file %s",
3800                          CHECK);
3801     }
3802   }
3803 
3804   if (parsed_permitted_subclasses_attribute) {
3805     const u2 num_subclasses = parse_classfile_permitted_subclasses_attribute(
3806                             cfs,
3807                             permitted_subclasses_attribute_start,
3808                             CHECK);
3809     if (_need_verify) {
3810       guarantee_property(
3811         permitted_subclasses_attribute_length == sizeof(num_subclasses) + sizeof(u2) * num_subclasses,
3812         "Wrong PermittedSubclasses attribute length in class file %s", CHECK);
3813     }
3814   }
3815 












3816   if (_max_bootstrap_specifier_index >= 0) {
3817     guarantee_property(parsed_bootstrap_methods_attribute,
3818                        "Missing BootstrapMethods attribute in class file %s", CHECK);
3819   }
3820 }
3821 
3822 void ClassFileParser::apply_parsed_class_attributes(InstanceKlass* k) {
3823   assert(k != nullptr, "invariant");
3824 
3825   if (_synthetic_flag)
3826     k->set_is_synthetic();
3827   if (_sourcefile_index != 0) {
3828     k->set_source_file_name_index(_sourcefile_index);
3829   }
3830   if (_generic_signature_index != 0) {
3831     k->set_generic_signature_index(_generic_signature_index);
3832   }
3833   if (_sde_buffer != nullptr) {
3834     k->set_source_debug_extension(_sde_buffer, _sde_length);
3835   }

3861     _class_annotations       = nullptr;
3862     _class_type_annotations  = nullptr;
3863     _fields_annotations      = nullptr;
3864     _fields_type_annotations = nullptr;
3865 }
3866 
3867 // Transfer ownership of metadata allocated to the InstanceKlass.
3868 void ClassFileParser::apply_parsed_class_metadata(
3869                                             InstanceKlass* this_klass,
3870                                             int java_fields_count) {
3871   assert(this_klass != nullptr, "invariant");
3872 
3873   _cp->set_pool_holder(this_klass);
3874   this_klass->set_constants(_cp);
3875   this_klass->set_fieldinfo_stream(_fieldinfo_stream);
3876   this_klass->set_fields_status(_fields_status);
3877   this_klass->set_methods(_methods);
3878   this_klass->set_inner_classes(_inner_classes);
3879   this_klass->set_nest_members(_nest_members);
3880   this_klass->set_nest_host_index(_nest_host);

3881   this_klass->set_annotations(_combined_annotations);
3882   this_klass->set_permitted_subclasses(_permitted_subclasses);
3883   this_klass->set_record_components(_record_components);
3884   // Delay the setting of _local_interfaces and _transitive_interfaces until after
3885   // initialize_supers() in fill_instance_klass(). It is because the _local_interfaces could
3886   // be shared with _transitive_interfaces and _transitive_interfaces may be shared with
3887   // its _super. If an OOM occurs while loading the current klass, its _super field
3888   // may not have been set. When GC tries to free the klass, the _transitive_interfaces
3889   // may be deallocated mistakenly in InstanceKlass::deallocate_interfaces(). Subsequent
3890   // dereferences to the deallocated _transitive_interfaces will result in a crash.
3891 
3892   // Clear out these fields so they don't get deallocated by the destructor
3893   clear_class_metadata();
3894 }
3895 
3896 AnnotationArray* ClassFileParser::assemble_annotations(const u1* const runtime_visible_annotations,
3897                                                        int runtime_visible_annotations_length,
3898                                                        const u1* const runtime_invisible_annotations,
3899                                                        int runtime_invisible_annotations_length,
3900                                                        TRAPS) {

3912     }
3913     if (runtime_invisible_annotations != nullptr) {
3914       for (int i = 0; i < runtime_invisible_annotations_length; i++) {
3915         int append = runtime_visible_annotations_length+i;
3916         annotations->at_put(append, runtime_invisible_annotations[i]);
3917       }
3918     }
3919   }
3920   return annotations;
3921 }
3922 
3923 const InstanceKlass* ClassFileParser::parse_super_class(ConstantPool* const cp,
3924                                                         const int super_class_index,
3925                                                         const bool need_verify,
3926                                                         TRAPS) {
3927   assert(cp != nullptr, "invariant");
3928   const InstanceKlass* super_klass = nullptr;
3929 
3930   if (super_class_index == 0) {
3931     check_property(_class_name == vmSymbols::java_lang_Object(),
3932                    "Invalid superclass index %u in class file %s",
3933                    super_class_index,
3934                    CHECK_NULL);
3935   } else {
3936     check_property(valid_klass_reference_at(super_class_index),
3937                    "Invalid superclass index %u in class file %s",
3938                    super_class_index,
3939                    CHECK_NULL);
3940     // The class name should be legal because it is checked when parsing constant pool.
3941     // However, make sure it is not an array type.
3942     bool is_array = false;
3943     if (cp->tag_at(super_class_index).is_klass()) {
3944       super_klass = InstanceKlass::cast(cp->resolved_klass_at(super_class_index));
3945       if (need_verify)
3946         is_array = super_klass->is_array_klass();
3947     } else if (need_verify) {
3948       is_array = (cp->klass_name_at(super_class_index)->char_at(0) == JVM_SIGNATURE_ARRAY);
3949     }
3950     if (need_verify) {

3951       guarantee_property(!is_array,
3952                         "Bad superclass name in class file %s", CHECK_NULL);
3953     }
3954   }
3955   return super_klass;
3956 }
3957 
3958 OopMapBlocksBuilder::OopMapBlocksBuilder(unsigned int max_blocks) {
3959   _max_nonstatic_oop_maps = max_blocks;
3960   _nonstatic_oop_map_count = 0;
3961   if (max_blocks == 0) {
3962     _nonstatic_oop_maps = nullptr;
3963   } else {
3964     _nonstatic_oop_maps =
3965         NEW_RESOURCE_ARRAY(OopMapBlock, _max_nonstatic_oop_maps);
3966     memset(_nonstatic_oop_maps, 0, sizeof(OopMapBlock) * max_blocks);
3967   }
3968 }
3969 
3970 OopMapBlock* OopMapBlocksBuilder::last_oop_map() const {

4054 }
4055 
4056 void OopMapBlocksBuilder::print_on(outputStream* st) const {
4057   st->print_cr("  OopMapBlocks: %3d  /%3d", _nonstatic_oop_map_count, _max_nonstatic_oop_maps);
4058   if (_nonstatic_oop_map_count > 0) {
4059     OopMapBlock* map = _nonstatic_oop_maps;
4060     OopMapBlock* last_map = last_oop_map();
4061     assert(map <= last_map, "Last less than first");
4062     while (map <= last_map) {
4063       st->print_cr("    Offset: %3d  -%3d Count: %3d", map->offset(),
4064                    map->offset() + map->offset_span() - heapOopSize, map->count());
4065       map++;
4066     }
4067   }
4068 }
4069 
4070 void OopMapBlocksBuilder::print_value_on(outputStream* st) const {
4071   print_on(st);
4072 }
4073 



















4074 void ClassFileParser::set_precomputed_flags(InstanceKlass* ik) {
4075   assert(ik != nullptr, "invariant");
4076 
4077   const InstanceKlass* const super = ik->java_super();
4078 
4079   // Check if this klass has an empty finalize method (i.e. one with return bytecode only),
4080   // in which case we don't have to register objects as finalizable
4081   if (!_has_empty_finalizer) {
4082     if (_has_finalizer ||
4083         (super != nullptr && super->has_finalizer())) {
4084       ik->set_has_finalizer();
4085     }
4086   }
4087 
4088 #ifdef ASSERT
4089   bool f = false;
4090   const Method* const m = ik->lookup_method(vmSymbols::finalize_method_name(),
4091                                            vmSymbols::void_method_signature());
4092   if (InstanceKlass::is_finalization_enabled() &&
4093       (m != nullptr) && !m->is_empty_method()) {
4094       f = true;
4095   }
4096 
4097   // Spec doesn't prevent agent from redefinition of empty finalizer.
4098   // Despite the fact that it's generally bad idea and redefined finalizer
4099   // will not work as expected we shouldn't abort vm in this case
4100   if (!ik->has_redefined_this_or_super()) {
4101     assert(ik->has_finalizer() == f, "inconsistent has_finalizer");
4102   }
4103 #endif
4104 
4105   // Check if this klass supports the java.lang.Cloneable interface
4106   if (vmClasses::Cloneable_klass_loaded()) {
4107     if (ik->is_subtype_of(vmClasses::Cloneable_klass())) {





4108       ik->set_is_cloneable();
4109     }
4110   }
4111 
4112   // Check if this klass has a vanilla default constructor
4113   if (super == nullptr) {
4114     // java.lang.Object has empty default constructor
4115     ik->set_has_vanilla_constructor();
4116   } else {
4117     if (super->has_vanilla_constructor() &&
4118         _has_vanilla_constructor) {
4119       ik->set_has_vanilla_constructor();
4120     }
4121 #ifdef ASSERT
4122     bool v = false;
4123     if (super->has_vanilla_constructor()) {
4124       const Method* const constructor =
4125         ik->find_method(vmSymbols::object_initializer_name(),
4126                        vmSymbols::void_method_signature());
4127       if (constructor != nullptr && constructor->is_vanilla_constructor()) {
4128         v = true;
4129       }
4130     }
4131     assert(v == ik->has_vanilla_constructor(), "inconsistent has_vanilla_constructor");
4132 #endif
4133   }
4134 
4135   // If it cannot be fast-path allocated, set a bit in the layout helper.
4136   // See documentation of InstanceKlass::can_be_fastpath_allocated().
4137   assert(ik->size_helper() > 0, "layout_helper is initialized");
4138   if ((!RegisterFinalizersAtInit && ik->has_finalizer())
4139       || ik->is_abstract() || ik->is_interface()
4140       || (ik->name() == vmSymbols::java_lang_Class() && ik->class_loader() == nullptr)
4141       || ik->size_helper() >= FastAllocateSizeLimit) {
4142     // Forbid fast-path allocation.
4143     const jint lh = Klass::instance_layout_helper(ik->size_helper(), true);
4144     ik->set_layout_helper(lh);
4145   }
4146 }
4147 






4148 // utility methods for appending an array with check for duplicates
4149 
4150 static void append_interfaces(GrowableArray<InstanceKlass*>* result,
4151                               const Array<InstanceKlass*>* const ifs) {
4152   // iterate over new interfaces
4153   for (int i = 0; i < ifs->length(); i++) {
4154     InstanceKlass* const e = ifs->at(i);
4155     assert(e->is_klass() && e->is_interface(), "just checking");
4156     // add new interface
4157     result->append_if_missing(e);
4158   }
4159 }
4160 
4161 static Array<InstanceKlass*>* compute_transitive_interfaces(const InstanceKlass* super,
4162                                                             Array<InstanceKlass*>* local_ifs,
4163                                                             ClassLoaderData* loader_data,
4164                                                             TRAPS) {
4165   assert(local_ifs != nullptr, "invariant");
4166   assert(loader_data != nullptr, "invariant");
4167 

4171   // Add superclass transitive interfaces size
4172   if (super != nullptr) {
4173     super_size = super->transitive_interfaces()->length();
4174     max_transitive_size += super_size;
4175   }
4176   // Add local interfaces' super interfaces
4177   const int local_size = local_ifs->length();
4178   for (int i = 0; i < local_size; i++) {
4179     InstanceKlass* const l = local_ifs->at(i);
4180     max_transitive_size += l->transitive_interfaces()->length();
4181   }
4182   // Finally add local interfaces
4183   max_transitive_size += local_size;
4184   // Construct array
4185   if (max_transitive_size == 0) {
4186     // no interfaces, use canonicalized array
4187     return Universe::the_empty_instance_klass_array();
4188   } else if (max_transitive_size == super_size) {
4189     // no new local interfaces added, share superklass' transitive interface array
4190     return super->transitive_interfaces();
4191   } else if (max_transitive_size == local_size) {
4192     // only local interfaces added, share local interface array
4193     return local_ifs;

4194   } else {
4195     ResourceMark rm;
4196     GrowableArray<InstanceKlass*>* const result = new GrowableArray<InstanceKlass*>(max_transitive_size);
4197 
4198     // Copy down from superclass
4199     if (super != nullptr) {
4200       append_interfaces(result, super->transitive_interfaces());
4201     }
4202 
4203     // Copy down from local interfaces' superinterfaces
4204     for (int i = 0; i < local_size; i++) {
4205       InstanceKlass* const l = local_ifs->at(i);
4206       append_interfaces(result, l->transitive_interfaces());
4207     }
4208     // Finally add local interfaces
4209     append_interfaces(result, local_ifs);
4210 
4211     // length will be less than the max_transitive_size if duplicates were removed
4212     const int length = result->length();
4213     assert(length <= max_transitive_size, "just checking");

4214     Array<InstanceKlass*>* const new_result =
4215       MetadataFactory::new_array<InstanceKlass*>(loader_data, length, CHECK_NULL);
4216     for (int i = 0; i < length; i++) {
4217       InstanceKlass* const e = result->at(i);
4218       assert(e != nullptr, "just checking");
4219       new_result->at_put(i, e);
4220     }
4221     return new_result;
4222   }
4223 }
4224 
4225 void ClassFileParser::check_super_class_access(const InstanceKlass* this_klass, TRAPS) {
4226   assert(this_klass != nullptr, "invariant");
4227   const Klass* const super = this_klass->super();
4228 
4229   if (super != nullptr) {
4230     const InstanceKlass* super_ik = InstanceKlass::cast(super);
4231 
4232     if (super->is_final()) {
4233       classfile_icce_error("class %s cannot inherit from final class %s", super_ik, THREAD);
4234       return;
4235     }
4236 
4237     if (super_ik->is_sealed() && !super_ik->has_as_permitted_subclass(this_klass)) {
4238       classfile_icce_error("class %s cannot inherit from sealed class %s", super_ik, THREAD);
4239       return;
4240     }
4241 










4242     // If the loader is not the boot loader then throw an exception if its
4243     // superclass is in package jdk.internal.reflect and its loader is not a
4244     // special reflection class loader
4245     if (!this_klass->class_loader_data()->is_the_null_class_loader_data()) {
4246       PackageEntry* super_package = super->package();
4247       if (super_package != nullptr &&
4248           super_package->name()->fast_compare(vmSymbols::jdk_internal_reflect()) == 0 &&
4249           !java_lang_ClassLoader::is_reflection_class_loader(this_klass->class_loader())) {
4250         ResourceMark rm(THREAD);
4251         Exceptions::fthrow(
4252           THREAD_AND_LOCATION,
4253           vmSymbols::java_lang_IllegalAccessError(),
4254           "class %s loaded by %s cannot access jdk/internal/reflect superclass %s",
4255           this_klass->external_name(),
4256           this_klass->class_loader_data()->loader_name_and_id(),
4257           super->external_name());
4258         return;
4259       }
4260     }
4261 

4407 
4408   for (int index = 0; index < num_methods; index++) {
4409     const Method* const m = methods->at(index);
4410     // if m is static and not the init method, throw a verify error
4411     if ((m->is_static()) && (m->name() != vmSymbols::class_initializer_name())) {
4412       ResourceMark rm(THREAD);
4413       Exceptions::fthrow(
4414         THREAD_AND_LOCATION,
4415         vmSymbols::java_lang_VerifyError(),
4416         "Illegal static method %s in interface %s",
4417         m->name()->as_C_string(),
4418         this_klass->external_name()
4419       );
4420       return;
4421     }
4422   }
4423 }
4424 
4425 // utility methods for format checking
4426 
4427 void ClassFileParser::verify_legal_class_modifiers(jint flags, TRAPS) const {
4428   const bool is_module = (flags & JVM_ACC_MODULE) != 0;


4429   assert(_major_version >= JAVA_9_VERSION || !is_module, "JVM_ACC_MODULE should not be set");
4430   if (is_module) {
4431     ResourceMark rm(THREAD);
4432     Exceptions::fthrow(
4433       THREAD_AND_LOCATION,
4434       vmSymbols::java_lang_NoClassDefFoundError(),
4435       "%s is not a class because access_flag ACC_MODULE is set",
4436       _class_name->as_C_string());
4437     return;
4438   }
4439 
4440   if (!_need_verify) { return; }
4441 
4442   const bool is_interface  = (flags & JVM_ACC_INTERFACE)  != 0;
4443   const bool is_abstract   = (flags & JVM_ACC_ABSTRACT)   != 0;
4444   const bool is_final      = (flags & JVM_ACC_FINAL)      != 0;
4445   const bool is_super      = (flags & JVM_ACC_SUPER)      != 0;
4446   const bool is_enum       = (flags & JVM_ACC_ENUM)       != 0;
4447   const bool is_annotation = (flags & JVM_ACC_ANNOTATION) != 0;
4448   const bool major_gte_1_5 = _major_version >= JAVA_1_5_VERSION;
4449 
4450   if ((is_abstract && is_final) ||
4451       (is_interface && !is_abstract) ||
4452       (is_interface && major_gte_1_5 && (is_super || is_enum)) ||
4453       (!is_interface && major_gte_1_5 && is_annotation)) {

4454     ResourceMark rm(THREAD);
4455     Exceptions::fthrow(
4456       THREAD_AND_LOCATION,
4457       vmSymbols::java_lang_ClassFormatError(),
4458       "Illegal class modifiers in class %s: 0x%X",
4459       _class_name->as_C_string(), flags
4460     );
4461     return;












4462   }
4463 }
4464 
4465 static bool has_illegal_visibility(jint flags) {
4466   const bool is_public    = (flags & JVM_ACC_PUBLIC)    != 0;
4467   const bool is_protected = (flags & JVM_ACC_PROTECTED) != 0;
4468   const bool is_private   = (flags & JVM_ACC_PRIVATE)   != 0;
4469 
4470   return ((is_public && is_protected) ||
4471           (is_public && is_private) ||
4472           (is_protected && is_private));
4473 }
4474 
4475 // A legal major_version.minor_version must be one of the following:
4476 //
4477 //  Major_version >= 45 and major_version < 56, any minor_version.
4478 //  Major_version >= 56 and major_version <= JVM_CLASSFILE_MAJOR_VERSION and minor_version = 0.
4479 //  Major_version = JVM_CLASSFILE_MAJOR_VERSION and minor_version = 65535 and --enable-preview is present.
4480 //
4481 void ClassFileParser::verify_class_version(u2 major, u2 minor, Symbol* class_name, TRAPS){

4507         THREAD_AND_LOCATION,
4508         vmSymbols::java_lang_UnsupportedClassVersionError(),
4509         "%s (class file version %u.%u) was compiled with preview features that are unsupported. "
4510         "This version of the Java Runtime only recognizes preview features for class file version %u.%u",
4511         class_name->as_C_string(), major, minor, JVM_CLASSFILE_MAJOR_VERSION, JAVA_PREVIEW_MINOR_VERSION);
4512       return;
4513     }
4514 
4515     if (!Arguments::enable_preview()) {
4516       classfile_ucve_error("Preview features are not enabled for %s (class file version %u.%u). Try running with '--enable-preview'",
4517                            class_name, major, minor, THREAD);
4518       return;
4519     }
4520 
4521   } else { // minor != JAVA_PREVIEW_MINOR_VERSION
4522     classfile_ucve_error("%s (class file version %u.%u) was compiled with an invalid non-zero minor version",
4523                          class_name, major, minor, THREAD);
4524   }
4525 }
4526 
4527 void ClassFileParser::verify_legal_field_modifiers(jint flags,
4528                                                    bool is_interface,
4529                                                    TRAPS) const {
4530   if (!_need_verify) { return; }
4531 
4532   const bool is_public    = (flags & JVM_ACC_PUBLIC)    != 0;
4533   const bool is_protected = (flags & JVM_ACC_PROTECTED) != 0;
4534   const bool is_private   = (flags & JVM_ACC_PRIVATE)   != 0;
4535   const bool is_static    = (flags & JVM_ACC_STATIC)    != 0;
4536   const bool is_final     = (flags & JVM_ACC_FINAL)     != 0;
4537   const bool is_volatile  = (flags & JVM_ACC_VOLATILE)  != 0;
4538   const bool is_transient = (flags & JVM_ACC_TRANSIENT) != 0;
4539   const bool is_enum      = (flags & JVM_ACC_ENUM)      != 0;
4540   const bool major_gte_1_5 = _major_version >= JAVA_1_5_VERSION;
4541 




4542   bool is_illegal = false;
4543 
4544   if (is_interface) {
4545     if (!is_public || !is_static || !is_final || is_private ||
4546         is_protected || is_volatile || is_transient ||
4547         (major_gte_1_5 && is_enum)) {
4548       is_illegal = true;
4549     }
4550   } else { // not interface
4551     if (has_illegal_visibility(flags) || (is_final && is_volatile)) {
4552       is_illegal = true;






4553     }
4554   }
4555 
4556   if (is_illegal) {
4557     ResourceMark rm(THREAD);
4558     Exceptions::fthrow(
4559       THREAD_AND_LOCATION,
4560       vmSymbols::java_lang_ClassFormatError(),
4561       "Illegal field modifiers in class %s: 0x%X",
4562       _class_name->as_C_string(), flags);
4563     return;
4564   }
4565 }
4566 
4567 void ClassFileParser::verify_legal_method_modifiers(jint flags,
4568                                                     bool is_interface,
4569                                                     const Symbol* name,
4570                                                     TRAPS) const {
4571   if (!_need_verify) { return; }
4572 
4573   const bool is_public       = (flags & JVM_ACC_PUBLIC)       != 0;
4574   const bool is_private      = (flags & JVM_ACC_PRIVATE)      != 0;
4575   const bool is_static       = (flags & JVM_ACC_STATIC)       != 0;
4576   const bool is_final        = (flags & JVM_ACC_FINAL)        != 0;
4577   const bool is_native       = (flags & JVM_ACC_NATIVE)       != 0;
4578   const bool is_abstract     = (flags & JVM_ACC_ABSTRACT)     != 0;
4579   const bool is_bridge       = (flags & JVM_ACC_BRIDGE)       != 0;
4580   const bool is_strict       = (flags & JVM_ACC_STRICT)       != 0;
4581   const bool is_synchronized = (flags & JVM_ACC_SYNCHRONIZED) != 0;
4582   const bool is_protected    = (flags & JVM_ACC_PROTECTED)    != 0;
4583   const bool major_gte_1_5   = _major_version >= JAVA_1_5_VERSION;
4584   const bool major_gte_8     = _major_version >= JAVA_8_VERSION;
4585   const bool major_gte_17    = _major_version >= JAVA_17_VERSION;
4586   const bool is_initializer  = (name == vmSymbols::object_initializer_name());





4587 
4588   bool is_illegal = false;
4589 

4590   if (is_interface) {
4591     if (major_gte_8) {
4592       // Class file version is JAVA_8_VERSION or later Methods of
4593       // interfaces may set any of the flags except ACC_PROTECTED,
4594       // ACC_FINAL, ACC_NATIVE, and ACC_SYNCHRONIZED; they must
4595       // have exactly one of the ACC_PUBLIC or ACC_PRIVATE flags set.
4596       if ((is_public == is_private) || /* Only one of private and public should be true - XNOR */
4597           (is_native || is_protected || is_final || is_synchronized) ||
4598           // If a specific method of a class or interface has its
4599           // ACC_ABSTRACT flag set, it must not have any of its
4600           // ACC_FINAL, ACC_NATIVE, ACC_PRIVATE, ACC_STATIC,
4601           // ACC_STRICT, or ACC_SYNCHRONIZED flags set.  No need to
4602           // check for ACC_FINAL, ACC_NATIVE or ACC_SYNCHRONIZED as
4603           // those flags are illegal irrespective of ACC_ABSTRACT being set or not.
4604           (is_abstract && (is_private || is_static || (!major_gte_17 && is_strict)))) {
4605         is_illegal = true;
4606       }
4607     } else if (major_gte_1_5) {
4608       // Class file version in the interval [JAVA_1_5_VERSION, JAVA_8_VERSION)
4609       if (!is_public || is_private || is_protected || is_static || is_final ||
4610           is_synchronized || is_native || !is_abstract || is_strict) {
4611         is_illegal = true;
4612       }
4613     } else {
4614       // Class file version is pre-JAVA_1_5_VERSION
4615       if (!is_public || is_static || is_final || is_native || !is_abstract) {
4616         is_illegal = true;
4617       }
4618     }
4619   } else { // not interface
4620     if (has_illegal_visibility(flags)) {
4621       is_illegal = true;
4622     } else {
4623       if (is_initializer) {
4624         if (is_static || is_final || is_synchronized || is_native ||
4625             is_abstract || (major_gte_1_5 && is_bridge)) {
4626           is_illegal = true;
4627         }
4628       } else { // not initializer
4629         if (is_abstract) {
4630           if ((is_final || is_native || is_private || is_static ||
4631               (major_gte_1_5 && (is_synchronized || (!major_gte_17 && is_strict))))) {
4632             is_illegal = true;





4633           }
4634         }
4635       }
4636     }
4637   }
4638 
4639   if (is_illegal) {
4640     ResourceMark rm(THREAD);
4641     Exceptions::fthrow(
4642       THREAD_AND_LOCATION,
4643       vmSymbols::java_lang_ClassFormatError(),
4644       "Method %s in class %s has illegal modifiers: 0x%X",
4645       name->as_C_string(), _class_name->as_C_string(), flags);









4646     return;
4647   }
4648 }
4649 
4650 void ClassFileParser::verify_legal_utf8(const unsigned char* buffer,
4651                                         int length,
4652                                         TRAPS) const {
4653   assert(_need_verify, "only called when _need_verify is true");
4654   if (!UTF8::is_legal_utf8(buffer, length, _major_version <= 47)) {
4655     classfile_parse_error("Illegal UTF8 string in constant pool in class file %s", THREAD);
4656   }
4657 }
4658 
4659 // Unqualified names may not contain the characters '.', ';', '[', or '/'.
4660 // In class names, '/' separates unqualified names.  This is verified in this function also.
4661 // Method names also may not contain the characters '<' or '>', unless <init>
4662 // or <clinit>.  Note that method names may not be <init> or <clinit> in this
4663 // method.  Because these names have been checked as special cases before
4664 // calling this method in verify_legal_method_name.
4665 //

4682         if (type == ClassFileParser::LegalClass) {
4683           if (p == name || p+1 >= name+length ||
4684               *(p+1) == JVM_SIGNATURE_SLASH) {
4685             return false;
4686           }
4687         } else {
4688           return false;   // do not permit '/' unless it's class name
4689         }
4690         break;
4691       case JVM_SIGNATURE_SPECIAL:
4692       case JVM_SIGNATURE_ENDSPECIAL:
4693         // do not permit '<' or '>' in method names
4694         if (type == ClassFileParser::LegalMethod) {
4695           return false;
4696         }
4697     }
4698   }
4699   return true;
4700 }
4701 










4702 // Take pointer to a UTF8 byte string (not NUL-terminated).
4703 // Skip over the longest part of the string that could
4704 // be taken as a fieldname. Allow non-trailing '/'s if slash_ok is true.
4705 // Return a pointer to just past the fieldname.
4706 // Return null if no fieldname at all was found, or in the case of slash_ok
4707 // being true, we saw consecutive slashes (meaning we were looking for a
4708 // qualified path but found something that was badly-formed).
4709 static const char* skip_over_field_name(const char* const name,
4710                                         bool slash_ok,
4711                                         unsigned int length) {
4712   const char* p;
4713   jboolean last_is_slash = false;
4714   jboolean not_first_ch = false;
4715 
4716   for (p = name; p != name + length; not_first_ch = true) {
4717     const char* old_p = p;
4718     jchar ch = *p;
4719     if (ch < 128) {
4720       p++;
4721       // quick check for ascii

4783 // be taken as a field signature. Allow "void" if void_ok.
4784 // Return a pointer to just past the signature.
4785 // Return null if no legal signature is found.
4786 const char* ClassFileParser::skip_over_field_signature(const char* signature,
4787                                                        bool void_ok,
4788                                                        unsigned int length,
4789                                                        TRAPS) const {
4790   unsigned int array_dim = 0;
4791   while (length > 0) {
4792     switch (signature[0]) {
4793     case JVM_SIGNATURE_VOID: if (!void_ok) { return nullptr; }
4794     case JVM_SIGNATURE_BOOLEAN:
4795     case JVM_SIGNATURE_BYTE:
4796     case JVM_SIGNATURE_CHAR:
4797     case JVM_SIGNATURE_SHORT:
4798     case JVM_SIGNATURE_INT:
4799     case JVM_SIGNATURE_FLOAT:
4800     case JVM_SIGNATURE_LONG:
4801     case JVM_SIGNATURE_DOUBLE:
4802       return signature + 1;
4803     case JVM_SIGNATURE_CLASS: {

4804       if (_major_version < JAVA_1_5_VERSION) {
4805         // Skip over the class name if one is there
4806         const char* const p = skip_over_field_name(signature + 1, true, --length);
4807 
4808         // The next character better be a semicolon
4809         if (p && (p - signature) > 1 && p[0] == JVM_SIGNATURE_ENDCLASS) {
4810           return p + 1;
4811         }
4812       }
4813       else {
4814         // Skip leading 'L' and ignore first appearance of ';'
4815         signature++;
4816         const char* c = (const char*) memchr(signature, JVM_SIGNATURE_ENDCLASS, length - 1);
4817         // Format check signature
4818         if (c != nullptr) {
4819           int newlen = pointer_delta_as_int(c, (char*) signature);
4820           bool legal = verify_unqualified_name(signature, newlen, LegalClass);
4821           if (!legal) {
4822             classfile_parse_error("Class name is empty or contains illegal character "
4823                                   "in descriptor in class file %s",
4824                                   THREAD);
4825             return nullptr;
4826           }
4827           return signature + newlen + 1;
4828         }
4829       }
4830       return nullptr;
4831     }
4832     case JVM_SIGNATURE_ARRAY:
4833       array_dim++;
4834       if (array_dim > 255) {

4850 
4851 // Checks if name is a legal class name.
4852 void ClassFileParser::verify_legal_class_name(const Symbol* name, TRAPS) const {
4853   if (!_need_verify || _relax_verify) { return; }
4854 
4855   assert(name->refcount() > 0, "symbol must be kept alive");
4856   char* bytes = (char*)name->bytes();
4857   unsigned int length = name->utf8_length();
4858   bool legal = false;
4859 
4860   if (length > 0) {
4861     const char* p;
4862     if (bytes[0] == JVM_SIGNATURE_ARRAY) {
4863       p = skip_over_field_signature(bytes, false, length, CHECK);
4864       legal = (p != nullptr) && ((p - bytes) == (int)length);
4865     } else if (_major_version < JAVA_1_5_VERSION) {
4866       if (bytes[0] != JVM_SIGNATURE_SPECIAL) {
4867         p = skip_over_field_name(bytes, true, length);
4868         legal = (p != nullptr) && ((p - bytes) == (int)length);
4869       }




4870     } else {
4871       // 4900761: relax the constraints based on JSR202 spec
4872       // Class names may be drawn from the entire Unicode character set.
4873       // Identifiers between '/' must be unqualified names.
4874       // The utf8 string has been verified when parsing cpool entries.
4875       legal = verify_unqualified_name(bytes, length, LegalClass);
4876     }
4877   }
4878   if (!legal) {
4879     ResourceMark rm(THREAD);
4880     assert(_class_name != nullptr, "invariant");
4881     Exceptions::fthrow(
4882       THREAD_AND_LOCATION,
4883       vmSymbols::java_lang_ClassFormatError(),
4884       "Illegal class name \"%.*s\" in class file %s", length, bytes,
4885       _class_name->as_C_string()
4886     );
4887     return;
4888   }
4889 }

4915       THREAD_AND_LOCATION,
4916       vmSymbols::java_lang_ClassFormatError(),
4917       "Illegal field name \"%.*s\" in class %s", length, bytes,
4918       _class_name->as_C_string()
4919     );
4920     return;
4921   }
4922 }
4923 
4924 // Checks if name is a legal method name.
4925 void ClassFileParser::verify_legal_method_name(const Symbol* name, TRAPS) const {
4926   if (!_need_verify || _relax_verify) { return; }
4927 
4928   assert(name != nullptr, "method name is null");
4929   char* bytes = (char*)name->bytes();
4930   unsigned int length = name->utf8_length();
4931   bool legal = false;
4932 
4933   if (length > 0) {
4934     if (bytes[0] == JVM_SIGNATURE_SPECIAL) {
4935       if (name == vmSymbols::object_initializer_name() || name == vmSymbols::class_initializer_name()) {

4936         legal = true;
4937       }
4938     } else if (_major_version < JAVA_1_5_VERSION) {
4939       const char* p;
4940       p = skip_over_field_name(bytes, false, length);
4941       legal = (p != nullptr) && ((p - bytes) == (int)length);
4942     } else {
4943       // 4881221: relax the constraints based on JSR202 spec
4944       legal = verify_unqualified_name(bytes, length, LegalMethod);
4945     }
4946   }
4947 
4948   if (!legal) {
4949     ResourceMark rm(THREAD);
4950     assert(_class_name != nullptr, "invariant");
4951     Exceptions::fthrow(
4952       THREAD_AND_LOCATION,
4953       vmSymbols::java_lang_ClassFormatError(),
4954       "Illegal method name \"%.*s\" in class %s", length, bytes,
4955       _class_name->as_C_string()

4976 
4977 // Check that the signature is compatible with the method name.  For example,
4978 // check that <init> has a void signature.
4979 void ClassFileParser::verify_legal_name_with_signature(const Symbol* name,
4980                                                        const Symbol* signature,
4981                                                        TRAPS) const {
4982   if (!_need_verify) {
4983     return;
4984   }
4985 
4986   // Class initializers cannot have args for class format version >= 51.
4987   if (name == vmSymbols::class_initializer_name() &&
4988       signature != vmSymbols::void_method_signature() &&
4989       _major_version >= JAVA_7_VERSION) {
4990     throwIllegalSignature("Method", name, signature, THREAD);
4991     return;
4992   }
4993 
4994   int sig_length = signature->utf8_length();
4995   if (name->utf8_length() > 0 &&
4996       name->char_at(0) == JVM_SIGNATURE_SPECIAL &&
4997       sig_length > 0 &&
4998       signature->char_at(sig_length - 1) != JVM_SIGNATURE_VOID) {
4999     throwIllegalSignature("Method", name, signature, THREAD);
5000   }
5001 }
5002 
5003 // Checks if signature is a legal method signature.
5004 // Returns number of parameters
5005 int ClassFileParser::verify_legal_method_signature(const Symbol* name,
5006                                                    const Symbol* signature,
5007                                                    TRAPS) const {
5008   if (!_need_verify) {
5009     // make sure caller's args_size will be less than 0 even for non-static
5010     // method so it will be recomputed in compute_size_of_parameters().
5011     return -2;
5012   }
5013 
5014   unsigned int args_size = 0;
5015   const char* p = (const char*)signature->bytes();
5016   unsigned int length = signature->utf8_length();
5017   const char* nextp;
5018 

5155   }
5156 }
5157 
5158 InstanceKlass* ClassFileParser::create_instance_klass(bool changed_by_loadhook,
5159                                                       const ClassInstanceInfo& cl_inst_info,
5160                                                       TRAPS) {
5161   if (_klass != nullptr) {
5162     return _klass;
5163   }
5164 
5165   InstanceKlass* const ik =
5166     InstanceKlass::allocate_instance_klass(*this, CHECK_NULL);
5167 
5168   if (is_hidden()) {
5169     mangle_hidden_class_name(ik);
5170   }
5171 
5172   fill_instance_klass(ik, changed_by_loadhook, cl_inst_info, CHECK_NULL);
5173 
5174   assert(_klass == ik, "invariant");
5175 
5176   return ik;
5177 }
5178 
5179 void ClassFileParser::fill_instance_klass(InstanceKlass* ik,
5180                                           bool changed_by_loadhook,
5181                                           const ClassInstanceInfo& cl_inst_info,
5182                                           TRAPS) {
5183   assert(ik != nullptr, "invariant");
5184 
5185   // Set name and CLD before adding to CLD
5186   ik->set_class_loader_data(_loader_data);
5187   ik->set_name(_class_name);
5188 
5189   // Add all classes to our internal class loader list here,
5190   // including classes in the bootstrap (null) class loader.
5191   const bool publicize = !is_internal();
5192 
5193   _loader_data->add_class(ik, publicize);
5194 
5195   set_klass_to_deallocate(ik);
5196 
5197   assert(_field_info != nullptr, "invariant");
5198   assert(ik->static_field_size() == _field_info->_static_field_size, "sanity");
5199   assert(ik->nonstatic_oop_map_count() == _field_info->oop_map_blocks->_nonstatic_oop_map_count,
5200          "sanity");
5201 
5202   assert(ik->is_instance_klass(), "sanity");
5203   assert(ik->size_helper() == _field_info->_instance_size, "sanity");
5204 
5205   // Fill in information already parsed
5206   ik->set_should_verify_class(_need_verify);
5207 
5208   // Not yet: supers are done below to support the new subtype-checking fields
5209   ik->set_nonstatic_field_size(_field_info->_nonstatic_field_size);
5210   ik->set_has_nonstatic_fields(_field_info->_has_nonstatic_fields);




5211   assert(_fac != nullptr, "invariant");
5212   ik->set_static_oop_field_count(_fac->count[STATIC_OOP]);
5213 
5214   // this transfers ownership of a lot of arrays from
5215   // the parser onto the InstanceKlass*
5216   apply_parsed_class_metadata(ik, _java_fields_count);



5217 
5218   // can only set dynamic nest-host after static nest information is set
5219   if (cl_inst_info.dynamic_nest_host() != nullptr) {
5220     ik->set_nest_host(cl_inst_info.dynamic_nest_host());
5221   }
5222 
5223   // note that is not safe to use the fields in the parser from this point on
5224   assert(nullptr == _cp, "invariant");
5225   assert(nullptr == _fieldinfo_stream, "invariant");
5226   assert(nullptr == _fields_status, "invariant");
5227   assert(nullptr == _methods, "invariant");
5228   assert(nullptr == _inner_classes, "invariant");
5229   assert(nullptr == _nest_members, "invariant");

5230   assert(nullptr == _combined_annotations, "invariant");
5231   assert(nullptr == _record_components, "invariant");
5232   assert(nullptr == _permitted_subclasses, "invariant");
5233 
5234   if (_has_localvariable_table) {
5235     ik->set_has_localvariable_table(true);
5236   }
5237 
5238   if (_has_final_method) {
5239     ik->set_has_final_method();
5240   }
5241 
5242   ik->copy_method_ordering(_method_ordering, CHECK);
5243   // The InstanceKlass::_methods_jmethod_ids cache
5244   // is managed on the assumption that the initial cache
5245   // size is equal to the number of methods in the class. If
5246   // that changes, then InstanceKlass::idnum_can_increment()
5247   // has to be changed accordingly.
5248   ik->set_initial_method_idnum(checked_cast<u2>(ik->methods()->length()));
5249 
5250   ik->set_this_class_index(_this_class_index);
5251 
5252   if (_is_hidden) {
5253     // _this_class_index is a CONSTANT_Class entry that refers to this
5254     // hidden class itself. If this class needs to refer to its own methods
5255     // or fields, it would use a CONSTANT_MethodRef, etc, which would reference
5256     // _this_class_index. However, because this class is hidden (it's
5257     // not stored in SystemDictionary), _this_class_index cannot be resolved
5258     // with ConstantPool::klass_at_impl, which does a SystemDictionary lookup.
5259     // Therefore, we must eagerly resolve _this_class_index now.
5260     ik->constants()->klass_at_put(_this_class_index, ik);
5261   }
5262 
5263   ik->set_minor_version(_minor_version);
5264   ik->set_major_version(_major_version);
5265   ik->set_has_nonstatic_concrete_methods(_has_nonstatic_concrete_methods);
5266   ik->set_declares_nonstatic_concrete_methods(_declares_nonstatic_concrete_methods);
5267 






5268   if (_is_hidden) {
5269     ik->set_is_hidden();
5270   }
5271 
5272   // Set PackageEntry for this_klass
5273   oop cl = ik->class_loader();
5274   Handle clh = Handle(THREAD, java_lang_ClassLoader::non_reflection_class_loader(cl));
5275   ClassLoaderData* cld = ClassLoaderData::class_loader_data_or_null(clh());
5276   ik->set_package(cld, nullptr, CHECK);
5277 
5278   const Array<Method*>* const methods = ik->methods();
5279   assert(methods != nullptr, "invariant");
5280   const int methods_len = methods->length();
5281 
5282   check_methods_for_intrinsics(ik, methods);
5283 
5284   // Fill in field values obtained by parse_classfile_attributes
5285   if (_parsed_annotations->has_any_annotations()) {
5286     _parsed_annotations->apply_to(ik);
5287   }

5354 
5355   assert(_all_mirandas != nullptr, "invariant");
5356 
5357   // Generate any default methods - default methods are public interface methods
5358   // that have a default implementation.  This is new with Java 8.
5359   if (_has_nonstatic_concrete_methods) {
5360     DefaultMethods::generate_default_methods(ik,
5361                                              _all_mirandas,
5362                                              CHECK);
5363   }
5364 
5365   // Add read edges to the unnamed modules of the bootstrap and app class loaders.
5366   if (changed_by_loadhook && !module_handle.is_null() && module_entry->is_named() &&
5367       !module_entry->has_default_read_edges()) {
5368     if (!module_entry->set_has_default_read_edges()) {
5369       // We won a potential race
5370       JvmtiExport::add_default_read_edges(module_handle, THREAD);
5371     }
5372   }
5373 



























5374   ClassLoadingService::notify_class_loaded(ik, false /* not shared class */);
5375 
5376   if (!is_internal()) {
5377     ik->print_class_load_logging(_loader_data, module_entry, _stream);
5378 
5379     if (ik->minor_version() == JAVA_PREVIEW_MINOR_VERSION &&
5380         ik->major_version() == JVM_CLASSFILE_MAJOR_VERSION &&
5381         log_is_enabled(Info, class, preview)) {
5382       ResourceMark rm;
5383       log_info(class, preview)("Loading class %s that depends on preview features (class file version %d.65535)",
5384                                ik->external_name(), JVM_CLASSFILE_MAJOR_VERSION);
5385     }
5386 
5387     if (log_is_enabled(Debug, class, resolve))  {
5388       ResourceMark rm;
5389       // print out the superclass.
5390       const char * from = ik->external_name();
5391       if (ik->java_super() != nullptr) {
5392         log_debug(class, resolve)("%s %s (super)",
5393                    from,

5445                                  Symbol* name,
5446                                  ClassLoaderData* loader_data,
5447                                  const ClassLoadInfo* cl_info,
5448                                  Publicity pub_level,
5449                                  TRAPS) :
5450   _stream(stream),
5451   _class_name(nullptr),
5452   _loader_data(loader_data),
5453   _is_hidden(cl_info->is_hidden()),
5454   _can_access_vm_annotations(cl_info->can_access_vm_annotations()),
5455   _orig_cp_size(0),
5456   _super_klass(),
5457   _cp(nullptr),
5458   _fieldinfo_stream(nullptr),
5459   _fields_status(nullptr),
5460   _methods(nullptr),
5461   _inner_classes(nullptr),
5462   _nest_members(nullptr),
5463   _nest_host(0),
5464   _permitted_subclasses(nullptr),

5465   _record_components(nullptr),
5466   _local_interfaces(nullptr),

5467   _transitive_interfaces(nullptr),
5468   _combined_annotations(nullptr),
5469   _class_annotations(nullptr),
5470   _class_type_annotations(nullptr),
5471   _fields_annotations(nullptr),
5472   _fields_type_annotations(nullptr),
5473   _klass(nullptr),
5474   _klass_to_deallocate(nullptr),
5475   _parsed_annotations(nullptr),
5476   _fac(nullptr),
5477   _field_info(nullptr),

5478   _temp_field_info(nullptr),
5479   _method_ordering(nullptr),
5480   _all_mirandas(nullptr),
5481   _vtable_size(0),
5482   _itable_size(0),
5483   _num_miranda_methods(0),
5484   _protection_domain(cl_info->protection_domain()),
5485   _access_flags(),
5486   _pub_level(pub_level),
5487   _bad_constant_seen(0),
5488   _synthetic_flag(false),
5489   _sde_length(false),
5490   _sde_buffer(nullptr),
5491   _sourcefile_index(0),
5492   _generic_signature_index(0),
5493   _major_version(0),
5494   _minor_version(0),
5495   _this_class_index(0),
5496   _super_class_index(0),
5497   _itfs_len(0),
5498   _java_fields_count(0),
5499   _need_verify(false),
5500   _relax_verify(false),
5501   _has_nonstatic_concrete_methods(false),
5502   _declares_nonstatic_concrete_methods(false),
5503   _has_localvariable_table(false),
5504   _has_final_method(false),
5505   _has_contended_fields(false),








5506   _has_finalizer(false),
5507   _has_empty_finalizer(false),
5508   _has_vanilla_constructor(false),
5509   _max_bootstrap_specifier_index(-1) {
5510 
5511   _class_name = name != nullptr ? name : vmSymbols::unknown_class_name();
5512   _class_name->increment_refcount();
5513 
5514   assert(_loader_data != nullptr, "invariant");
5515   assert(stream != nullptr, "invariant");
5516   assert(_stream != nullptr, "invariant");
5517   assert(_stream->buffer() == _stream->current(), "invariant");
5518   assert(_class_name != nullptr, "invariant");
5519   assert(0 == _access_flags.as_int(), "invariant");
5520 
5521   // Figure out whether we can skip format checking (matching classic VM behavior)
5522   if (CDSConfig::is_dumping_static_archive()) {
5523     // verify == true means it's a 'remote' class (i.e., non-boot class)
5524     // Verification decision is based on BytecodeVerificationRemote flag
5525     // for those classes.

5536 
5537   // Check if verification needs to be relaxed for this class file
5538   // Do not restrict it to jdk1.0 or jdk1.1 to maintain backward compatibility (4982376)
5539   _relax_verify = relax_format_check_for(_loader_data);
5540 
5541   parse_stream(stream, CHECK);
5542 
5543   post_process_parsed_stream(stream, _cp, CHECK);
5544 }
5545 
5546 void ClassFileParser::clear_class_metadata() {
5547   // metadata created before the instance klass is created.  Must be
5548   // deallocated if classfile parsing returns an error.
5549   _cp = nullptr;
5550   _fieldinfo_stream = nullptr;
5551   _fields_status = nullptr;
5552   _methods = nullptr;
5553   _inner_classes = nullptr;
5554   _nest_members = nullptr;
5555   _permitted_subclasses = nullptr;

5556   _combined_annotations = nullptr;
5557   _class_annotations = _class_type_annotations = nullptr;
5558   _fields_annotations = _fields_type_annotations = nullptr;
5559   _record_components = nullptr;
5560 }
5561 
5562 // Destructor to clean up
5563 ClassFileParser::~ClassFileParser() {
5564   _class_name->decrement_refcount();
5565 
5566   if (_cp != nullptr) {
5567     MetadataFactory::free_metadata(_loader_data, _cp);
5568   }
5569 
5570   if (_fieldinfo_stream != nullptr) {
5571     MetadataFactory::free_array<u1>(_loader_data, _fieldinfo_stream);
5572   }
5573 
5574   if (_fields_status != nullptr) {
5575     MetadataFactory::free_array<FieldStatus>(_loader_data, _fields_status);
5576   }
5577 




5578   if (_methods != nullptr) {
5579     // Free methods
5580     InstanceKlass::deallocate_methods(_loader_data, _methods);
5581   }
5582 
5583   // beware of the Universe::empty_blah_array!!
5584   if (_inner_classes != nullptr && _inner_classes != Universe::the_empty_short_array()) {
5585     MetadataFactory::free_array<u2>(_loader_data, _inner_classes);
5586   }
5587 
5588   if (_nest_members != nullptr && _nest_members != Universe::the_empty_short_array()) {
5589     MetadataFactory::free_array<u2>(_loader_data, _nest_members);
5590   }
5591 
5592   if (_record_components != nullptr) {
5593     InstanceKlass::deallocate_record_components(_loader_data, _record_components);
5594   }
5595 
5596   if (_permitted_subclasses != nullptr && _permitted_subclasses != Universe::the_empty_short_array()) {
5597     MetadataFactory::free_array<u2>(_loader_data, _permitted_subclasses);
5598   }
5599 




5600   // Free interfaces
5601   InstanceKlass::deallocate_interfaces(_loader_data, _super_klass,
5602                                        _local_interfaces, _transitive_interfaces);
5603 
5604   if (_combined_annotations != nullptr) {
5605     // After all annotations arrays have been created, they are installed into the
5606     // Annotations object that will be assigned to the InstanceKlass being created.
5607 
5608     // Deallocate the Annotations object and the installed annotations arrays.
5609     _combined_annotations->deallocate_contents(_loader_data);
5610 
5611     // If the _combined_annotations pointer is non-null,
5612     // then the other annotations fields should have been cleared.
5613     assert(_class_annotations       == nullptr, "Should have been cleared");
5614     assert(_class_type_annotations  == nullptr, "Should have been cleared");
5615     assert(_fields_annotations      == nullptr, "Should have been cleared");
5616     assert(_fields_type_annotations == nullptr, "Should have been cleared");
5617   } else {
5618     // If the annotations arrays were not installed into the Annotations object,
5619     // then they have to be deallocated explicitly.

5664     cp_size, CHECK);
5665 
5666   _orig_cp_size = cp_size;
5667   if (is_hidden()) { // Add a slot for hidden class name.
5668     cp_size++;
5669   }
5670 
5671   _cp = ConstantPool::allocate(_loader_data,
5672                                cp_size,
5673                                CHECK);
5674 
5675   ConstantPool* const cp = _cp;
5676 
5677   parse_constant_pool(stream, cp, _orig_cp_size, CHECK);
5678 
5679   assert(cp_size == (u2)cp->length(), "invariant");
5680 
5681   // ACCESS FLAGS
5682   stream->guarantee_more(8, CHECK);  // flags, this_class, super_class, infs_len
5683 
5684   // Access flags
5685   jint flags;
5686   // JVM_ACC_MODULE is defined in JDK-9 and later.
5687   if (_major_version >= JAVA_9_VERSION) {
5688     flags = stream->get_u2_fast() & (JVM_RECOGNIZED_CLASS_MODIFIERS | JVM_ACC_MODULE);
5689   } else {
5690     flags = stream->get_u2_fast() & JVM_RECOGNIZED_CLASS_MODIFIERS;
5691   }
5692 



5693   if ((flags & JVM_ACC_INTERFACE) && _major_version < JAVA_6_VERSION) {
5694     // Set abstract bit for old class files for backward compatibility
5695     flags |= JVM_ACC_ABSTRACT;
5696   }
5697 
5698   verify_legal_class_modifiers(flags, CHECK);
5699 
5700   short bad_constant = class_bad_constant_seen();
5701   if (bad_constant != 0) {
5702     // Do not throw CFE until after the access_flags are checked because if
5703     // ACC_MODULE is set in the access flags, then NCDFE must be thrown, not CFE.
5704     classfile_parse_error("Unknown constant tag %u in class file %s", bad_constant, THREAD);
5705     return;
5706   }
5707 
5708   _access_flags.set_flags(flags);
5709 
5710   // This class and superclass
5711   _this_class_index = stream->get_u2_fast();
5712   check_property(
5713     valid_cp_range(_this_class_index, cp_size) &&
5714       cp->tag_at(_this_class_index).is_unresolved_klass(),
5715     "Invalid this class index %u in constant pool in class file %s",
5716     _this_class_index, CHECK);
5717 
5718   Symbol* const class_name_in_cp = cp->klass_name_at(_this_class_index);
5719   assert(class_name_in_cp != nullptr, "class_name can't be null");
5720 
























5721   // Don't need to check whether this class name is legal or not.
5722   // It has been checked when constant pool is parsed.
5723   // However, make sure it is not an array type.
5724   if (_need_verify) {
5725     guarantee_property(class_name_in_cp->char_at(0) != JVM_SIGNATURE_ARRAY,
5726                        "Bad class name in class file %s",
5727                        CHECK);
5728   }
5729 
5730 #ifdef ASSERT
5731   // Basic sanity checks
5732   if (_is_hidden) {
5733     assert(_class_name != vmSymbols::unknown_class_name(), "hidden classes should have a special name");
5734   }
5735 #endif
5736 
5737   // Update the _class_name as needed depending on whether this is a named, un-named, or hidden class.
5738 
5739   if (_is_hidden) {
5740     assert(_class_name != nullptr, "Unexpected null _class_name");

5780       }
5781       ls.cr();
5782     }
5783   }
5784 
5785   // SUPERKLASS
5786   _super_class_index = stream->get_u2_fast();
5787   _super_klass = parse_super_class(cp,
5788                                    _super_class_index,
5789                                    _need_verify,
5790                                    CHECK);
5791 
5792   // Interfaces
5793   _itfs_len = stream->get_u2_fast();
5794   parse_interfaces(stream,
5795                    _itfs_len,
5796                    cp,
5797                    &_has_nonstatic_concrete_methods,
5798                    CHECK);
5799 
5800   assert(_local_interfaces != nullptr, "invariant");
5801 
5802   // Fields (offsets are filled in later)
5803   _fac = new FieldAllocationCount();
5804   parse_fields(stream,
5805                _access_flags.is_interface(),
5806                _fac,
5807                cp,
5808                cp_size,
5809                &_java_fields_count,
5810                CHECK);
5811 
5812   assert(_temp_field_info != nullptr, "invariant");
5813 
5814   // Methods
5815   parse_methods(stream,
5816                 _access_flags.is_interface(),


5817                 &_has_localvariable_table,
5818                 &_has_final_method,
5819                 &_declares_nonstatic_concrete_methods,
5820                 CHECK);
5821 
5822   assert(_methods != nullptr, "invariant");
5823 
5824   if (_declares_nonstatic_concrete_methods) {
5825     _has_nonstatic_concrete_methods = true;
5826   }
5827 
5828   // Additional attributes/annotations
5829   _parsed_annotations = new ClassAnnotationCollector();
5830   parse_classfile_attributes(stream, cp, _parsed_annotations, CHECK);
5831 
5832   assert(_inner_classes != nullptr, "invariant");
5833 
5834   // Finalize the Annotations metadata object,
5835   // now that all annotation arrays have been created.
5836   create_combined_annotations(CHECK);

5876   // Update this_class_index's slot in the constant pool with the new Utf8 entry.
5877   // We have to update the resolved_klass_index and the name_index together
5878   // so extract the existing resolved_klass_index first.
5879   CPKlassSlot cp_klass_slot = _cp->klass_slot_at(_this_class_index);
5880   int resolved_klass_index = cp_klass_slot.resolved_klass_index();
5881   _cp->unresolved_klass_at_put(_this_class_index, hidden_index, resolved_klass_index);
5882   assert(_cp->klass_slot_at(_this_class_index).name_index() == _orig_cp_size,
5883          "Bad name_index");
5884 }
5885 
5886 void ClassFileParser::post_process_parsed_stream(const ClassFileStream* const stream,
5887                                                  ConstantPool* cp,
5888                                                  TRAPS) {
5889   assert(stream != nullptr, "invariant");
5890   assert(stream->at_eos(), "invariant");
5891   assert(cp != nullptr, "invariant");
5892   assert(_loader_data != nullptr, "invariant");
5893 
5894   if (_class_name == vmSymbols::java_lang_Object()) {
5895     check_property(_local_interfaces == Universe::the_empty_instance_klass_array(),
5896                    "java.lang.Object cannot implement an interface in class file %s",
5897                    CHECK);
5898   }
5899   // We check super class after class file is parsed and format is checked
5900   if (_super_class_index > 0 && nullptr == _super_klass) {
5901     Symbol* const super_class_name = cp->klass_name_at(_super_class_index);
5902     if (_access_flags.is_interface()) {
5903       // Before attempting to resolve the superclass, check for class format
5904       // errors not checked yet.
5905       guarantee_property(super_class_name == vmSymbols::java_lang_Object(),
5906         "Interfaces must have java.lang.Object as superclass in class file %s",
5907         CHECK);
5908     }
5909     Handle loader(THREAD, _loader_data->class_loader());
5910     if (loader.is_null() && super_class_name == vmSymbols::java_lang_Object()) {
5911       _super_klass = vmClasses::Object_klass();
5912     } else {
5913       _super_klass = (const InstanceKlass*)
5914                        SystemDictionary::resolve_super_or_fail(_class_name,
5915                                                                super_class_name,
5916                                                                loader,
5917                                                                _protection_domain,
5918                                                                true,
5919                                                                CHECK);
5920     }
5921   }
5922 
5923   if (_super_klass != nullptr) {









5924     if (_super_klass->has_nonstatic_concrete_methods()) {
5925       _has_nonstatic_concrete_methods = true;
5926     }
5927 
5928     if (_super_klass->is_interface()) {
5929       classfile_icce_error("class %s has interface %s as super class", _super_klass, THREAD);
5930       return;









































5931     }
5932   }
5933 















































5934   // Compute the transitive list of all unique interfaces implemented by this class
5935   _transitive_interfaces =
5936     compute_transitive_interfaces(_super_klass,
5937                                   _local_interfaces,
5938                                   _loader_data,
5939                                   CHECK);
5940 
5941   assert(_transitive_interfaces != nullptr, "invariant");
5942 
5943   // sort methods
5944   _method_ordering = sort_methods(_methods);
5945 
5946   _all_mirandas = new GrowableArray<Method*>(20);
5947 
5948   Handle loader(THREAD, _loader_data->class_loader());
5949   klassVtable::compute_vtable_size_and_num_mirandas(&_vtable_size,
5950                                                     &_num_miranda_methods,
5951                                                     _all_mirandas,
5952                                                     _super_klass,
5953                                                     _methods,
5954                                                     _access_flags,
5955                                                     _major_version,
5956                                                     loader,
5957                                                     _class_name,
5958                                                     _local_interfaces);
5959 
5960   // Size of Java itable (in words)
5961   _itable_size = _access_flags.is_interface() ? 0 :
5962     klassItable::compute_itable_size(_transitive_interfaces);
5963 
5964   assert(_fac != nullptr, "invariant");
5965   assert(_parsed_annotations != nullptr, "invariant");
5966 






























































5967   _field_info = new FieldLayoutInfo();
5968   FieldLayoutBuilder lb(class_name(), super_klass(), _cp, /*_fields*/ _temp_field_info,
5969                         _parsed_annotations->is_contended(), _field_info);
5970   lb.build_layout();







5971 
5972   int injected_fields_count = _temp_field_info->length() - _java_fields_count;
5973   _fieldinfo_stream =
5974     FieldInfoStream::create_FieldInfoStream(_temp_field_info, _java_fields_count,
5975                                             injected_fields_count, loader_data(), CHECK);
5976   _fields_status =
5977     MetadataFactory::new_array<FieldStatus>(_loader_data, _temp_field_info->length(),
5978                                             FieldStatus(0), CHECK);
5979 }
5980 
5981 void ClassFileParser::set_klass(InstanceKlass* klass) {
5982 
5983 #ifdef ASSERT
5984   if (klass != nullptr) {
5985     assert(nullptr == _klass, "leaking?");
5986   }
5987 #endif
5988 
5989   _klass = klass;
5990 }

   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "oops/inlineKlass.hpp"
  26 #include "precompiled.hpp"
  27 #include "cds/cdsConfig.hpp"
  28 #include "classfile/classFileParser.hpp"
  29 #include "classfile/classFileStream.hpp"
  30 #include "classfile/classLoader.hpp"
  31 #include "classfile/classLoaderData.inline.hpp"
  32 #include "classfile/classLoadInfo.hpp"
  33 #include "classfile/defaultMethods.hpp"
  34 #include "classfile/fieldLayoutBuilder.hpp"
  35 #include "classfile/javaClasses.inline.hpp"
  36 #include "classfile/moduleEntry.hpp"
  37 #include "classfile/packageEntry.hpp"
  38 #include "classfile/symbolTable.hpp"
  39 #include "classfile/systemDictionary.hpp"
  40 #include "classfile/verificationType.hpp"
  41 #include "classfile/verifier.hpp"
  42 #include "classfile/vmClasses.hpp"
  43 #include "classfile/vmSymbols.hpp"
  44 #include "jvm.h"
  45 #include "logging/log.hpp"
  46 #include "logging/logStream.hpp"
  47 #include "memory/allocation.hpp"
  48 #include "memory/metadataFactory.hpp"
  49 #include "memory/oopFactory.hpp"
  50 #include "memory/resourceArea.hpp"
  51 #include "memory/universe.hpp"
  52 #include "oops/annotations.hpp"
  53 #include "oops/constantPool.inline.hpp"
  54 #include "oops/fieldInfo.hpp"
  55 #include "oops/fieldStreams.inline.hpp"
  56 #include "oops/inlineKlass.inline.hpp"
  57 #include "oops/instanceKlass.inline.hpp"
  58 #include "oops/instanceMirrorKlass.hpp"
  59 #include "oops/klass.inline.hpp"
  60 #include "oops/klassVtable.hpp"
  61 #include "oops/metadata.hpp"
  62 #include "oops/method.inline.hpp"
  63 #include "oops/oop.inline.hpp"
  64 #include "oops/recordComponent.hpp"
  65 #include "oops/symbol.hpp"
  66 #include "prims/jvmtiExport.hpp"
  67 #include "prims/jvmtiThreadState.hpp"
  68 #include "runtime/arguments.hpp"
  69 #include "runtime/fieldDescriptor.inline.hpp"
  70 #include "runtime/handles.inline.hpp"
  71 #include "runtime/javaCalls.hpp"
  72 #include "runtime/os.hpp"
  73 #include "runtime/perfData.hpp"
  74 #include "runtime/reflection.hpp"
  75 #include "runtime/safepointVerifiers.hpp"
  76 #include "runtime/signature.hpp"
  77 #include "runtime/timer.hpp"
  78 #include "services/classLoadingService.hpp"
  79 #include "services/threadService.hpp"
  80 #include "utilities/align.hpp"
  81 #include "utilities/bitMap.inline.hpp"
  82 #include "utilities/checkedCast.hpp"
  83 #include "utilities/copy.hpp"
  84 #include "utilities/formatBuffer.hpp"
  85 #include "utilities/exceptions.hpp"
  86 #include "utilities/globalDefinitions.hpp"
  87 #include "utilities/growableArray.hpp"
  88 #include "utilities/macros.hpp"
  89 #include "utilities/ostream.hpp"
  90 #include "utilities/resourceHash.hpp"
  91 #include "utilities/stringUtils.hpp"
  92 #include "utilities/utf8.hpp"
  93 #if INCLUDE_CDS
  94 #include "classfile/systemDictionaryShared.hpp"
  95 #endif
  96 #if INCLUDE_JFR
  97 #include "jfr/support/jfrTraceIdExtension.hpp"
  98 #endif
  99 
 100 // We generally try to create the oops directly when parsing, rather than
 101 // allocating temporary data structures and copying the bytes twice. A
 102 // temporary area is only needed when parsing utf8 entries in the constant
 103 // pool and when parsing line number tables.
 104 
 105 // We add assert in debug mode when class format is not checked.
 106 
 107 #define JAVA_CLASSFILE_MAGIC              0xCAFEBABE
 108 #define JAVA_MIN_SUPPORTED_VERSION        45
 109 #define JAVA_PREVIEW_MINOR_VERSION        65535
 110 
 111 // Used for two backward compatibility reasons:

 136 #define JAVA_13_VERSION                   57
 137 
 138 #define JAVA_14_VERSION                   58
 139 
 140 #define JAVA_15_VERSION                   59
 141 
 142 #define JAVA_16_VERSION                   60
 143 
 144 #define JAVA_17_VERSION                   61
 145 
 146 #define JAVA_18_VERSION                   62
 147 
 148 #define JAVA_19_VERSION                   63
 149 
 150 #define JAVA_20_VERSION                   64
 151 
 152 #define JAVA_21_VERSION                   65
 153 
 154 #define JAVA_22_VERSION                   66
 155 
 156 #define CONSTANT_CLASS_DESCRIPTORS        66
 157 
 158 void ClassFileParser::set_class_bad_constant_seen(short bad_constant) {
 159   assert((bad_constant == JVM_CONSTANT_Module ||
 160           bad_constant == JVM_CONSTANT_Package) && _major_version >= JAVA_9_VERSION,
 161          "Unexpected bad constant pool entry");
 162   if (_bad_constant_seen == 0) _bad_constant_seen = bad_constant;
 163 }
 164 
 165 void ClassFileParser::parse_constant_pool_entries(const ClassFileStream* const stream,
 166                                                   ConstantPool* cp,
 167                                                   const int length,
 168                                                   TRAPS) {
 169   assert(stream != nullptr, "invariant");
 170   assert(cp != nullptr, "invariant");
 171 
 172   // Use a local copy of ClassFileStream. It helps the C++ compiler to optimize
 173   // this function (_current can be allocated in a register, with scalar
 174   // replacement of aggregates). The _current pointer is copied back to
 175   // stream() when this function returns. DON'T call another method within
 176   // this method that uses stream().
 177   const ClassFileStream cfs1 = *stream;
 178   const ClassFileStream* const cfs = &cfs1;
 179 
 180   debug_only(const u1* const old_current = stream->current();)
 181 
 182   // Used for batching symbol allocations.
 183   const char* names[SymbolTable::symbol_alloc_batch_size];
 184   int lengths[SymbolTable::symbol_alloc_batch_size];
 185   int indices[SymbolTable::symbol_alloc_batch_size];
 186   unsigned int hashValues[SymbolTable::symbol_alloc_batch_size];
 187   int names_count = 0;
 188 
 189   // parsing  Index 0 is unused
 190   for (int index = 1; index < length; index++) {
 191     // Each of the following case guarantees one more byte in the stream
 192     // for the following tag or the access_flags following constant pool,
 193     // so we don't need bounds-check for reading tag.
 194     const u1 tag = cfs->get_u1_fast();
 195     switch (tag) {
 196       case JVM_CONSTANT_Class: {
 197         cfs->guarantee_more(3, CHECK);  // name_index, tag/access_flags
 198         const u2 name_index = cfs->get_u2_fast();
 199         cp->klass_index_at_put(index, name_index);
 200         break;
 201       }
 202       case JVM_CONSTANT_Fieldref: {
 203         cfs->guarantee_more(5, CHECK);  // class_index, name_and_type_index, tag/access_flags
 204         const u2 class_index = cfs->get_u2_fast();
 205         const u2 name_and_type_index = cfs->get_u2_fast();
 206         cp->field_at_put(index, class_index, name_and_type_index);
 207         break;
 208       }
 209       case JVM_CONSTANT_Methodref: {
 210         cfs->guarantee_more(5, CHECK);  // class_index, name_and_type_index, tag/access_flags
 211         const u2 class_index = cfs->get_u2_fast();
 212         const u2 name_and_type_index = cfs->get_u2_fast();
 213         cp->method_at_put(index, class_index, name_and_type_index);
 214         break;
 215       }
 216       case JVM_CONSTANT_InterfaceMethodref: {

 497         check_property(valid_symbol_at(name_ref_index),
 498           "Invalid constant pool index %u in class file %s",
 499           name_ref_index, CHECK);
 500         check_property(valid_symbol_at(signature_ref_index),
 501           "Invalid constant pool index %u in class file %s",
 502           signature_ref_index, CHECK);
 503         break;
 504       }
 505       case JVM_CONSTANT_Utf8:
 506         break;
 507       case JVM_CONSTANT_UnresolvedClass:         // fall-through
 508       case JVM_CONSTANT_UnresolvedClassInError: {
 509         ShouldNotReachHere();     // Only JVM_CONSTANT_ClassIndex should be present
 510         break;
 511       }
 512       case JVM_CONSTANT_ClassIndex: {
 513         const int class_index = cp->klass_index_at(index);
 514         check_property(valid_symbol_at(class_index),
 515           "Invalid constant pool index %u in class file %s",
 516           class_index, CHECK);
 517 
 518         Symbol* const name = cp->symbol_at(class_index);
 519         const unsigned int name_len = name->utf8_length();
 520         cp->unresolved_klass_at_put(index, class_index, num_klasses++);
 521         break;
 522       }
 523       case JVM_CONSTANT_StringIndex: {
 524         const int string_index = cp->string_index_at(index);
 525         check_property(valid_symbol_at(string_index),
 526           "Invalid constant pool index %u in class file %s",
 527           string_index, CHECK);
 528         Symbol* const sym = cp->symbol_at(string_index);
 529         cp->unresolved_string_at_put(index, sym);
 530         break;
 531       }
 532       case JVM_CONSTANT_MethodHandle: {
 533         const int ref_index = cp->method_handle_index_at(index);
 534         check_property(valid_cp_range(ref_index, length),
 535           "Invalid constant pool index %u in class file %s",
 536           ref_index, CHECK);
 537         const constantTag tag = cp->tag_at(ref_index);
 538         const int ref_kind = cp->method_handle_ref_kind_at(index);
 539 

 709             }
 710           }
 711         } else {
 712           if (_need_verify) {
 713             // Method name and signature are individually verified above, when iterating
 714             // NameAndType_info.  Need to check here that signature is non-zero length and
 715             // the right type.
 716             if (!Signature::is_method(signature)) {
 717               throwIllegalSignature("Method", name, signature, CHECK);
 718             }
 719           }
 720           // If a class method name begins with '<', it must be "<init>" and have void signature.
 721           const unsigned int name_len = name->utf8_length();
 722           if (tag == JVM_CONSTANT_Methodref && name_len != 0 &&
 723               name->char_at(0) == JVM_SIGNATURE_SPECIAL) {
 724             if (name != vmSymbols::object_initializer_name()) {
 725               classfile_parse_error(
 726                 "Bad method name at constant pool index %u in class file %s",
 727                 name_ref_index, THREAD);
 728               return;
 729             } else if (!Signature::is_void_method(signature)) {  // must have void signature.
 730               throwIllegalSignature("Method", name, signature, CHECK);
 731             }
 732           }
 733         }
 734         break;
 735       }
 736       case JVM_CONSTANT_MethodHandle: {
 737         const int ref_index = cp->method_handle_index_at(index);
 738         const int ref_kind = cp->method_handle_ref_kind_at(index);
 739         switch (ref_kind) {
 740           case JVM_REF_invokeVirtual:
 741           case JVM_REF_invokeStatic:
 742           case JVM_REF_invokeSpecial:
 743           case JVM_REF_newInvokeSpecial: {
 744             const int name_and_type_ref_index =
 745               cp->uncached_name_and_type_ref_index_at(ref_index);
 746             const int name_ref_index =
 747               cp->name_ref_index_at(name_and_type_ref_index);
 748             const Symbol* const name = cp->symbol_at(name_ref_index);
 749 
 750             if (name != vmSymbols::object_initializer_name()) { // !<init>
 751               if (ref_kind == JVM_REF_newInvokeSpecial) {
 752                 classfile_parse_error(
 753                   "Bad constructor name at constant pool index %u in class file %s",
 754                     name_ref_index, THREAD);
 755                 return;
 756               }
 757             } else { // <init>
 758               // The allowed invocation mode of <init> depends on its signature.
 759               // This test corresponds to verify_invoke_instructions in the verifier.
 760               const int signature_ref_index =
 761                 cp->signature_ref_index_at(name_and_type_ref_index);
 762               const Symbol* const signature = cp->symbol_at(signature_ref_index);
 763               if (signature->is_void_method_signature()
 764                   && ref_kind == JVM_REF_newInvokeSpecial) {
 765                 // OK, could be a constructor call
 766               } else {
 767                 classfile_parse_error(
 768                   "Bad method name at constant pool index %u in class file %s",
 769                   name_ref_index, THREAD);
 770                 return;
 771               }
 772             }
 773             break;
 774           }
 775           // Other ref_kinds are already fully checked in previous pass.
 776         } // switch(ref_kind)
 777         break;
 778       }
 779       case JVM_CONSTANT_MethodType: {
 780         const Symbol* const no_name = vmSymbols::type_name(); // place holder
 781         const Symbol* const signature = cp->method_type_signature_at(index);
 782         verify_legal_method_signature(no_name, signature, CHECK);
 783         break;
 784       }
 785       case JVM_CONSTANT_Utf8: {
 786         assert(cp->symbol_at(index)->refcount() != 0, "count corrupted");

 798 
 799   NameSigHash(Symbol* name, Symbol* sig) :
 800     _name(name),
 801     _sig(sig) {}
 802 
 803   static unsigned int hash(NameSigHash const& namesig) {
 804     return namesig._name->identity_hash() ^ namesig._sig->identity_hash();
 805   }
 806 
 807   static bool equals(NameSigHash const& e0, NameSigHash const& e1) {
 808     return (e0._name == e1._name) &&
 809           (e0._sig  == e1._sig);
 810   }
 811 };
 812 
 813 using NameSigHashtable = ResourceHashtable<NameSigHash, int,
 814                                            NameSigHash::HASH_ROW_SIZE,
 815                                            AnyObj::RESOURCE_AREA, mtInternal,
 816                                            &NameSigHash::hash, &NameSigHash::equals>;
 817 
 818 static void check_identity_and_value_modifiers(ClassFileParser* current, const InstanceKlass* super_type, TRAPS) {
 819   assert(super_type != nullptr,"Method doesn't support null super type");
 820   if (super_type->access_flags().is_identity_class() && !current->access_flags().is_identity_class()
 821       && super_type->super() != nullptr /* Super is not j.l.Object */) {
 822       THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(),
 823                 err_msg("Value type %s has an identity type as supertype",
 824                 current->class_name()->as_klass_external_name()));
 825   }
 826 }
 827 
 828 void ClassFileParser::parse_interfaces(const ClassFileStream* stream,
 829                                        int itfs_len,
 830                                        ConstantPool* cp,
 831                                        bool* const has_nonstatic_concrete_methods,
 832                                        // FIXME: lots of these functions
 833                                        // declare their parameters as const,
 834                                        // which adds only noise to the code.
 835                                        // Remove the spurious const modifiers.
 836                                        // Many are of the form "const int x"
 837                                        // or "T* const x".
 838                                        TRAPS) {
 839   assert(stream != nullptr, "invariant");
 840   assert(cp != nullptr, "invariant");
 841   assert(has_nonstatic_concrete_methods != nullptr, "invariant");
 842 
 843   if (itfs_len == 0) {
 844     _local_interfaces = Universe::the_empty_instance_klass_array();
 845 
 846   } else {
 847     assert(itfs_len > 0, "only called for len>0");
 848     _local_interface_indexes = new GrowableArray<u2>(itfs_len);
 849     int index = 0;

 850     for (index = 0; index < itfs_len; index++) {
 851       const u2 interface_index = stream->get_u2(CHECK);

 852       check_property(
 853         valid_klass_reference_at(interface_index),
 854         "Interface name has bad constant pool index %u in class file %s",
 855         interface_index, CHECK);
 856       _local_interface_indexes->at_put_grow(index, interface_index);































 857     }
 858 
 859     if (!_need_verify || itfs_len <= 1) {
 860       return;
 861     }
 862 
 863     // Check if there's any duplicates in interfaces
 864     ResourceMark rm(THREAD);
 865     // Set containing interface names
 866     ResourceHashtable<Symbol*, int>* interface_names = new ResourceHashtable<Symbol*, int>();
 867     for (index = 0; index < itfs_len; index++) {
 868       Symbol* interface_name = cp->klass_name_at(_local_interface_indexes->at(index));

 869       // If no duplicates, add (name, nullptr) in hashtable interface_names.
 870       if (!interface_names->put(interface_name, 0)) {
 871         classfile_parse_error("Duplicate interface name \"%s\" in class file %s",
 872                                interface_name->as_C_string(), THREAD);
 873         return;
 874       }
 875     }
 876   }
 877 }
 878 
 879 void ClassFileParser::verify_constantvalue(const ConstantPool* const cp,
 880                                            int constantvalue_index,
 881                                            int signature_index,
 882                                            TRAPS) const {
 883   // Make sure the constant pool entry is of a type appropriate to this field
 884   guarantee_property(
 885     (constantvalue_index > 0 &&
 886       constantvalue_index < cp->length()),
 887     "Bad initial value index %u in ConstantValue attribute in class file %s",
 888     constantvalue_index, CHECK);

 934 
 935 class AnnotationCollector : public ResourceObj{
 936 public:
 937   enum Location { _in_field, _in_method, _in_class };
 938   enum ID {
 939     _unknown = 0,
 940     _method_CallerSensitive,
 941     _method_ForceInline,
 942     _method_DontInline,
 943     _method_ChangesCurrentThread,
 944     _method_JvmtiMountTransition,
 945     _method_InjectedProfile,
 946     _method_LambdaForm_Compiled,
 947     _method_Hidden,
 948     _method_Scoped,
 949     _method_IntrinsicCandidate,
 950     _jdk_internal_vm_annotation_Contended,
 951     _field_Stable,
 952     _jdk_internal_vm_annotation_ReservedStackAccess,
 953     _jdk_internal_ValueBased,
 954     _jdk_internal_ImplicitlyConstructible,
 955     _jdk_internal_LooselyConsistentValue,
 956     _jdk_internal_NullRestricted,
 957     _annotation_LIMIT
 958   };
 959   const Location _location;
 960   int _annotations_present;
 961   u2 _contended_group;
 962 
 963   AnnotationCollector(Location location)
 964     : _location(location), _annotations_present(0), _contended_group(0)
 965   {
 966     assert((int)_annotation_LIMIT <= (int)sizeof(_annotations_present) * BitsPerByte, "");
 967   }
 968   // If this annotation name has an ID, report it (or _none).
 969   ID annotation_index(const ClassLoaderData* loader_data, const Symbol* name, bool can_access_vm_annotations);
 970   // Set the annotation name:
 971   void set_annotation(ID id) {
 972     assert((int)id >= 0 && (int)id < (int)_annotation_LIMIT, "oob");
 973     _annotations_present |= (int)nth_bit((int)id);
 974   }
 975 
 976   void remove_annotation(ID id) {

1333                                             CHECK);
1334   parsed_annotations->set_field_annotations(a);
1335   a = assemble_annotations(runtime_visible_type_annotations,
1336                            runtime_visible_type_annotations_length,
1337                            runtime_invisible_type_annotations,
1338                            runtime_invisible_type_annotations_length,
1339                            CHECK);
1340   parsed_annotations->set_field_type_annotations(a);
1341   return;
1342 }
1343 
1344 
1345 // Field allocation types. Used for computing field offsets.
1346 
1347 enum FieldAllocationType {
1348   STATIC_OOP,           // Oops
1349   STATIC_BYTE,          // Boolean, Byte, char
1350   STATIC_SHORT,         // shorts
1351   STATIC_WORD,          // ints
1352   STATIC_DOUBLE,        // aligned long or double
1353   STATIC_INLINE,        // inline type field
1354   NONSTATIC_OOP,
1355   NONSTATIC_BYTE,
1356   NONSTATIC_SHORT,
1357   NONSTATIC_WORD,
1358   NONSTATIC_DOUBLE,
1359   NONSTATIC_INLINE,
1360   MAX_FIELD_ALLOCATION_TYPE,
1361   BAD_ALLOCATION_TYPE = -1
1362 };
1363 
1364 static FieldAllocationType _basic_type_to_atype[2 * (T_CONFLICT + 1)] = {
1365   BAD_ALLOCATION_TYPE, // 0
1366   BAD_ALLOCATION_TYPE, // 1
1367   BAD_ALLOCATION_TYPE, // 2
1368   BAD_ALLOCATION_TYPE, // 3
1369   NONSTATIC_BYTE ,     // T_BOOLEAN     =  4,
1370   NONSTATIC_SHORT,     // T_CHAR        =  5,
1371   NONSTATIC_WORD,      // T_FLOAT       =  6,
1372   NONSTATIC_DOUBLE,    // T_DOUBLE      =  7,
1373   NONSTATIC_BYTE,      // T_BYTE        =  8,
1374   NONSTATIC_SHORT,     // T_SHORT       =  9,
1375   NONSTATIC_WORD,      // T_INT         = 10,
1376   NONSTATIC_DOUBLE,    // T_LONG        = 11,
1377   NONSTATIC_OOP,       // T_OBJECT      = 12,
1378   NONSTATIC_OOP,       // T_ARRAY       = 13,
1379   NONSTATIC_OOP,       // T_PRIMITIVE_OBJECT = 14,
1380   BAD_ALLOCATION_TYPE, // T_VOID        = 15,
1381   BAD_ALLOCATION_TYPE, // T_ADDRESS     = 16,
1382   BAD_ALLOCATION_TYPE, // T_NARROWOOP   = 17,
1383   BAD_ALLOCATION_TYPE, // T_METADATA    = 18,
1384   BAD_ALLOCATION_TYPE, // T_NARROWKLASS = 19,
1385   BAD_ALLOCATION_TYPE, // T_CONFLICT    = 20,
1386   BAD_ALLOCATION_TYPE, // 0
1387   BAD_ALLOCATION_TYPE, // 1
1388   BAD_ALLOCATION_TYPE, // 2
1389   BAD_ALLOCATION_TYPE, // 3
1390   STATIC_BYTE ,        // T_BOOLEAN     =  4,
1391   STATIC_SHORT,        // T_CHAR        =  5,
1392   STATIC_WORD,         // T_FLOAT       =  6,
1393   STATIC_DOUBLE,       // T_DOUBLE      =  7,
1394   STATIC_BYTE,         // T_BYTE        =  8,
1395   STATIC_SHORT,        // T_SHORT       =  9,
1396   STATIC_WORD,         // T_INT         = 10,
1397   STATIC_DOUBLE,       // T_LONG        = 11,
1398   STATIC_OOP,          // T_OBJECT      = 12,
1399   STATIC_OOP,          // T_ARRAY       = 13,
1400   STATIC_OOP,          // T_PRIMITIVE_OBJECT = 14,
1401   BAD_ALLOCATION_TYPE, // T_VOID        = 15,
1402   BAD_ALLOCATION_TYPE, // T_ADDRESS     = 16,
1403   BAD_ALLOCATION_TYPE, // T_NARROWOOP   = 17,
1404   BAD_ALLOCATION_TYPE, // T_METADATA    = 18,
1405   BAD_ALLOCATION_TYPE, // T_NARROWKLASS = 19,
1406   BAD_ALLOCATION_TYPE, // T_CONFLICT    = 20
1407 };
1408 
1409 static FieldAllocationType basic_type_to_atype(bool is_static, BasicType type, bool is_inline_type) {
1410   assert(type >= T_BOOLEAN && type < T_VOID, "only allowable values");
1411   FieldAllocationType result = _basic_type_to_atype[type + (is_static ? (T_CONFLICT + 1) : 0)];
1412   assert(result != BAD_ALLOCATION_TYPE, "bad type");
1413   if (is_inline_type) {
1414     result = is_static ? STATIC_INLINE : NONSTATIC_INLINE;
1415   }
1416   return result;
1417 }
1418 
1419 class ClassFileParser::FieldAllocationCount : public ResourceObj {
1420  public:
1421   u2 count[MAX_FIELD_ALLOCATION_TYPE];
1422 
1423   FieldAllocationCount() {
1424     for (int i = 0; i < MAX_FIELD_ALLOCATION_TYPE; i++) {
1425       count[i] = 0;
1426     }
1427   }
1428 
1429   void update(bool is_static, BasicType type, bool is_inline_type) {
1430     FieldAllocationType atype = basic_type_to_atype(is_static, type, is_inline_type);
1431     if (atype != BAD_ALLOCATION_TYPE) {
1432       // Make sure there is no overflow with injected fields.
1433       assert(count[atype] < 0xFFFF, "More than 65535 fields");
1434       count[atype]++;
1435     }
1436   }
1437 };
1438 
1439 // Side-effects: populates the _fields, _fields_annotations,
1440 // _fields_type_annotations fields
1441 void ClassFileParser::parse_fields(const ClassFileStream* const cfs,
1442                                    AccessFlags class_access_flags,
1443                                    FieldAllocationCount* const fac,
1444                                    ConstantPool* cp,
1445                                    const int cp_size,
1446                                    u2* const java_fields_count_ptr,
1447                                    TRAPS) {
1448 
1449   assert(cfs != nullptr, "invariant");
1450   assert(fac != nullptr, "invariant");
1451   assert(cp != nullptr, "invariant");
1452   assert(java_fields_count_ptr != nullptr, "invariant");
1453 
1454   assert(nullptr == _fields_annotations, "invariant");
1455   assert(nullptr == _fields_type_annotations, "invariant");
1456 
1457   bool is_inline_type = !class_access_flags.is_identity_class() && !class_access_flags.is_abstract();
1458   cfs->guarantee_more(2, CHECK);  // length
1459   const u2 length = cfs->get_u2_fast();
1460   *java_fields_count_ptr = length;
1461 
1462   int num_injected = 0;
1463   const InjectedField* const injected = JavaClasses::get_injected(_class_name,
1464                                                                   &num_injected);
1465 
1466   // two more slots are required for inline classes:
1467   // one for the static field with a reference to the pre-allocated default value
1468   // one for the field the JVM injects when detecting an empty inline class
1469   const int total_fields = length + num_injected + (is_inline_type ? 2 : 0);
1470 
1471   // Allocate a temporary resource array to collect field data.
1472   // After parsing all fields, data are stored in a UNSIGNED5 compressed stream.
1473   _temp_field_info = new GrowableArray<FieldInfo>(total_fields);
1474 
1475   int instance_fields_count = 0;
1476   ResourceMark rm(THREAD);
1477   for (int n = 0; n < length; n++) {
1478     // access_flags, name_index, descriptor_index, attributes_count
1479     cfs->guarantee_more(8, CHECK);
1480 
1481     jint recognized_modifiers = JVM_RECOGNIZED_FIELD_MODIFIERS;
1482 
1483     const jint flags = cfs->get_u2_fast() & recognized_modifiers;
1484     verify_legal_field_modifiers(flags, class_access_flags, CHECK);
1485     AccessFlags access_flags;


1486     access_flags.set_flags(flags);
1487     FieldInfo::FieldFlags fieldFlags(0);
1488 
1489     const u2 name_index = cfs->get_u2_fast();
1490     check_property(valid_symbol_at(name_index),
1491       "Invalid constant pool index %u for field name in class file %s",
1492       name_index, CHECK);
1493     const Symbol* const name = cp->symbol_at(name_index);
1494     verify_legal_field_name(name, CHECK);
1495 
1496     const u2 signature_index = cfs->get_u2_fast();
1497     check_property(valid_symbol_at(signature_index),
1498       "Invalid constant pool index %u for field signature in class file %s",
1499       signature_index, CHECK);
1500     const Symbol* const sig = cp->symbol_at(signature_index);
1501     verify_legal_field_signature(name, sig, CHECK);
1502     if (!access_flags.is_static()) instance_fields_count++;
1503 
1504     u2 constantvalue_index = 0;
1505     bool is_synthetic = false;
1506     u2 generic_signature_index = 0;
1507     const bool is_static = access_flags.is_static();
1508     FieldAnnotationCollector parsed_annotations(_loader_data);
1509 
1510     bool is_null_restricted = false;
1511 
1512     const u2 attributes_count = cfs->get_u2_fast();
1513     if (attributes_count > 0) {
1514       parse_field_attributes(cfs,
1515                              attributes_count,
1516                              is_static,
1517                              signature_index,
1518                              &constantvalue_index,
1519                              &is_synthetic,
1520                              &generic_signature_index,
1521                              &parsed_annotations,
1522                              CHECK);
1523 
1524       if (parsed_annotations.field_annotations() != nullptr) {
1525         if (_fields_annotations == nullptr) {
1526           _fields_annotations = MetadataFactory::new_array<AnnotationArray*>(
1527                                              _loader_data, length, nullptr,
1528                                              CHECK);
1529         }
1530         _fields_annotations->at_put(n, parsed_annotations.field_annotations());
1531         if (parsed_annotations.has_annotation(AnnotationCollector::_jdk_internal_NullRestricted)) {
1532           if (!Signature::has_envelope(sig)) {
1533             Exceptions::fthrow(
1534               THREAD_AND_LOCATION,
1535               vmSymbols::java_lang_ClassFormatError(),
1536               "Illegal use of @jdk.internal.vm.annotation.NullRestricted annotation on field %s with signature %s (primitive types can never be null)",
1537               name->as_C_string(), sig->as_C_string());
1538           }
1539           is_null_restricted = true;
1540         }
1541         parsed_annotations.set_field_annotations(nullptr);
1542       }
1543       if (parsed_annotations.field_type_annotations() != nullptr) {
1544         if (_fields_type_annotations == nullptr) {
1545           _fields_type_annotations =
1546             MetadataFactory::new_array<AnnotationArray*>(_loader_data,
1547                                                          length,
1548                                                          nullptr,
1549                                                          CHECK);
1550         }
1551         _fields_type_annotations->at_put(n, parsed_annotations.field_type_annotations());
1552         parsed_annotations.set_field_type_annotations(nullptr);
1553       }
1554 
1555       if (is_synthetic) {
1556         access_flags.set_is_synthetic();
1557       }
1558       if (generic_signature_index != 0) {
1559         fieldFlags.update_generic(true);
1560       }
1561     }
1562 
1563     const BasicType type = cp->basic_type_for_signature_at(signature_index);
1564 
1565     // Update FieldAllocationCount for this kind of field
1566     // This use of T_PRIMITIVE_OBJECT is not valid anymore => FIXME (relate to cleanup (removal?) of FiedAllocationCount
1567     fac->update(is_static, type, type == T_PRIMITIVE_OBJECT);
1568 
1569     if (is_null_restricted) fieldFlags.update_null_free_inline_type(true);
1570 
1571     FieldInfo fi(access_flags, name_index, signature_index, constantvalue_index, fieldFlags);
1572     fi.set_index(n);
1573     if (fieldFlags.is_generic()) {
1574       fi.set_generic_signature_index(generic_signature_index);
1575     }
1576     parsed_annotations.apply_to(&fi);
1577     if (fi.field_flags().is_contended()) {
1578       _has_contended_fields = true;
1579     }
1580     _temp_field_info->append(fi);
1581   }
1582   assert(_temp_field_info->length() == length, "Must be");
1583 
1584   int index = length;
1585   if (num_injected != 0) {
1586     for (int n = 0; n < num_injected; n++) {
1587       // Check for duplicates
1588       if (injected[n].may_be_java) {
1589         const Symbol* const name      = injected[n].name();

1597             duplicate = true;
1598             break;
1599           }
1600         }
1601         if (duplicate) {
1602           // These will be removed from the field array at the end
1603           continue;
1604         }
1605       }
1606 
1607       // Injected field
1608       FieldInfo::FieldFlags fflags(0);
1609       fflags.update_injected(true);
1610       AccessFlags aflags;
1611       FieldInfo fi(aflags, (u2)(injected[n].name_index), (u2)(injected[n].signature_index), 0, fflags);
1612       fi.set_index(index);
1613       _temp_field_info->append(fi);
1614 
1615       // Update FieldAllocationCount for this kind of field
1616       const BasicType type = Signature::basic_type(injected[n].signature());
1617       fac->update(false, type, false);
1618       index++;
1619     }
1620   }
1621 
1622   if (is_inline_type) {
1623     // Inject static ".default" field
1624     FieldInfo::FieldFlags fflags(0);
1625     fflags.update_injected(true);
1626     AccessFlags aflags(JVM_ACC_STATIC);
1627     FieldInfo fi(aflags,
1628                  (u2)vmSymbols::as_int(VM_SYMBOL_ENUM_NAME(default_value_name)),
1629                  (u2)vmSymbols::as_int(VM_SYMBOL_ENUM_NAME(object_signature)),
1630                  0,
1631                  fflags);
1632       fi.set_index(index);
1633       _temp_field_info->append(fi);
1634 
1635     const BasicType type = Signature::basic_type(vmSymbols::object_signature());
1636     fac->update(true, type, false);
1637     index++;
1638   }
1639 
1640   if (is_inline_type && instance_fields_count == 0) {
1641     // Inject ".empty" dummy field
1642     _is_empty_inline_type = true;
1643 
1644     FieldInfo::FieldFlags fflags(0);
1645     fflags.update_injected(true);
1646     AccessFlags aflags;
1647     FieldInfo fi(aflags,
1648                  (u2)vmSymbols::as_int(VM_SYMBOL_ENUM_NAME(empty_marker_name)),
1649                  (u2)vmSymbols::as_int(VM_SYMBOL_ENUM_NAME(byte_signature)),
1650                  0,
1651                  fflags);
1652     fi.set_index(index);
1653     _temp_field_info->append(fi);
1654 
1655     const BasicType type = Signature::basic_type(vmSymbols::byte_signature());
1656     fac->update(false, type, false);
1657     index++;
1658   }
1659 
1660   if (instance_fields_count > 0) {
1661     _has_nonstatic_fields = true;
1662   }
1663 
1664   assert(_temp_field_info->length() == index, "Must be");
1665 
1666   if (_need_verify && length > 1) {
1667     // Check duplicated fields
1668     ResourceMark rm(THREAD);
1669     // Set containing name-signature pairs
1670     NameSigHashtable* names_and_sigs = new NameSigHashtable();
1671     for (int i = 0; i < _temp_field_info->length(); i++) {
1672       NameSigHash name_and_sig(_temp_field_info->adr_at(i)->name(_cp),
1673                                _temp_field_info->adr_at(i)->signature(_cp));
1674       // If no duplicates, add name/signature in hashtable names_and_sigs.
1675       if(!names_and_sigs->put(name_and_sig, 0)) {
1676         classfile_parse_error("Duplicate field name \"%s\" with signature \"%s\" in class file %s",
1677                                name_and_sig._name->as_C_string(), name_and_sig._sig->as_klass_external_name(), THREAD);
1678         return;
1679       }
1680     }
1681   }
1682 }
1683 

1927         "Exception name has bad type at constant pool %u in class file %s",
1928         checked_exception, CHECK_NULL);
1929     }
1930   }
1931   // check exceptions attribute length
1932   if (_need_verify) {
1933     guarantee_property(method_attribute_length == (sizeof(*checked_exceptions_length) +
1934                                                    sizeof(u2) * size),
1935                       "Exceptions attribute has wrong length in class file %s", CHECK_NULL);
1936   }
1937   return checked_exceptions_start;
1938 }
1939 
1940 void ClassFileParser::throwIllegalSignature(const char* type,
1941                                             const Symbol* name,
1942                                             const Symbol* sig,
1943                                             TRAPS) const {
1944   assert(name != nullptr, "invariant");
1945   assert(sig != nullptr, "invariant");
1946 
1947   const char* class_note = "";
1948   if (is_inline_type() && name == vmSymbols::object_initializer_name()) {
1949     class_note = " (an inline class)";
1950   }
1951 
1952   ResourceMark rm(THREAD);
1953   Exceptions::fthrow(THREAD_AND_LOCATION,
1954       vmSymbols::java_lang_ClassFormatError(),
1955       "%s \"%s\" in class %s%s has illegal signature \"%s\"", type,
1956       name->as_C_string(), _class_name->as_C_string(), class_note, sig->as_C_string());
1957 }
1958 
1959 AnnotationCollector::ID
1960 AnnotationCollector::annotation_index(const ClassLoaderData* loader_data,
1961                                       const Symbol* name,
1962                                       const bool can_access_vm_annotations) {
1963   const vmSymbolID sid = vmSymbols::find_sid(name);
1964   // Privileged code can use all annotations.  Other code silently drops some.
1965   const bool privileged = loader_data->is_boot_class_loader_data() ||
1966                           loader_data->is_platform_class_loader_data() ||
1967                           can_access_vm_annotations;
1968   switch (sid) {
1969     case VM_SYMBOL_ENUM_NAME(reflect_CallerSensitive_signature): {
1970       if (_location != _in_method)  break;  // only allow for methods
1971       if (!privileged)              break;  // only allow in privileged code
1972       return _method_CallerSensitive;
1973     }
1974     case VM_SYMBOL_ENUM_NAME(jdk_internal_vm_annotation_ForceInline_signature): {
1975       if (_location != _in_method)  break;  // only allow for methods
1976       if (!privileged)              break;  // only allow in privileged code

2023     }
2024     case VM_SYMBOL_ENUM_NAME(jdk_internal_vm_annotation_Contended_signature): {
2025       if (_location != _in_field && _location != _in_class) {
2026         break;  // only allow for fields and classes
2027       }
2028       if (!EnableContended || (RestrictContended && !privileged)) {
2029         break;  // honor privileges
2030       }
2031       return _jdk_internal_vm_annotation_Contended;
2032     }
2033     case VM_SYMBOL_ENUM_NAME(jdk_internal_vm_annotation_ReservedStackAccess_signature): {
2034       if (_location != _in_method)  break;  // only allow for methods
2035       if (RestrictReservedStack && !privileged) break; // honor privileges
2036       return _jdk_internal_vm_annotation_ReservedStackAccess;
2037     }
2038     case VM_SYMBOL_ENUM_NAME(jdk_internal_ValueBased_signature): {
2039       if (_location != _in_class)   break;  // only allow for classes
2040       if (!privileged)              break;  // only allow in privileged code
2041       return _jdk_internal_ValueBased;
2042     }
2043     case VM_SYMBOL_ENUM_NAME(jdk_internal_vm_annotation_ImplicitlyConstructible_signature): {
2044       if (_location != _in_class)   break; // only allow for classes
2045       return _jdk_internal_ImplicitlyConstructible;
2046     }
2047     case VM_SYMBOL_ENUM_NAME(jdk_internal_vm_annotation_LooselyConsistentValue_signature): {
2048       if (_location != _in_class)   break; // only allow for classes
2049       return _jdk_internal_LooselyConsistentValue;
2050     }
2051     case VM_SYMBOL_ENUM_NAME(jdk_internal_vm_annotation_NullRestricted_signature): {
2052       if (_location != _in_field)   break; // only allow for fields
2053       return _jdk_internal_NullRestricted;
2054     }
2055     default: {
2056       break;
2057     }
2058   }
2059   return AnnotationCollector::_unknown;
2060 }
2061 
2062 void ClassFileParser::FieldAnnotationCollector::apply_to(FieldInfo* f) {
2063   if (is_contended())
2064     // Setting the contended group also sets the contended bit in field flags
2065     f->set_contended_group(contended_group());
2066   if (is_stable())
2067     (f->field_flags_addr())->update_stable(true);
2068 }
2069 
2070 ClassFileParser::FieldAnnotationCollector::~FieldAnnotationCollector() {
2071   // If there's an error deallocate metadata for field annotations
2072   MetadataFactory::free_array<u1>(_loader_data, _field_annotations);
2073   MetadataFactory::free_array<u1>(_loader_data, _field_type_annotations);
2074 }

2250       runtime_invisible_type_annotations_length > 0) {
2251     a = assemble_annotations(runtime_visible_type_annotations,
2252                              runtime_visible_type_annotations_length,
2253                              runtime_invisible_type_annotations,
2254                              runtime_invisible_type_annotations_length,
2255                              CHECK);
2256     cm->set_type_annotations(a);
2257   }
2258 }
2259 
2260 
2261 // Note: the parse_method below is big and clunky because all parsing of the code and exceptions
2262 // attribute is inlined. This is cumbersome to avoid since we inline most of the parts in the
2263 // Method* to save footprint, so we only know the size of the resulting Method* when the
2264 // entire method attribute is parsed.
2265 //
2266 // The has_localvariable_table parameter is used to pass up the value to InstanceKlass.
2267 
2268 Method* ClassFileParser::parse_method(const ClassFileStream* const cfs,
2269                                       bool is_interface,
2270                                       bool is_value_class,
2271                                       bool is_abstract_class,
2272                                       const ConstantPool* cp,
2273                                       bool* const has_localvariable_table,
2274                                       TRAPS) {
2275   assert(cfs != nullptr, "invariant");
2276   assert(cp != nullptr, "invariant");
2277   assert(has_localvariable_table != nullptr, "invariant");
2278 
2279   ResourceMark rm(THREAD);
2280   // Parse fixed parts:
2281   // access_flags, name_index, descriptor_index, attributes_count
2282   cfs->guarantee_more(8, CHECK_NULL);
2283 
2284   int flags = cfs->get_u2_fast();
2285   const u2 name_index = cfs->get_u2_fast();
2286   const int cp_size = cp->length();
2287   check_property(
2288     valid_symbol_at(name_index),
2289     "Illegal constant pool index %u for method name in class file %s",
2290     name_index, CHECK_NULL);
2291   const Symbol* const name = cp->symbol_at(name_index);

2293 
2294   const u2 signature_index = cfs->get_u2_fast();
2295   guarantee_property(
2296     valid_symbol_at(signature_index),
2297     "Illegal constant pool index %u for method signature in class file %s",
2298     signature_index, CHECK_NULL);
2299   const Symbol* const signature = cp->symbol_at(signature_index);
2300 
2301   if (name == vmSymbols::class_initializer_name()) {
2302     // We ignore the other access flags for a valid class initializer.
2303     // (JVM Spec 2nd ed., chapter 4.6)
2304     if (_major_version < 51) { // backward compatibility
2305       flags = JVM_ACC_STATIC;
2306     } else if ((flags & JVM_ACC_STATIC) == JVM_ACC_STATIC) {
2307       flags &= JVM_ACC_STATIC | (_major_version <= JAVA_16_VERSION ? JVM_ACC_STRICT : 0);
2308     } else {
2309       classfile_parse_error("Method <clinit> is not static in class file %s", THREAD);
2310       return nullptr;
2311     }
2312   } else {
2313     verify_legal_method_modifiers(flags, access_flags() , name, CHECK_NULL);
2314   }
2315 
2316   if (name == vmSymbols::object_initializer_name() && is_interface) {
2317     classfile_parse_error("Interface cannot have a method named <init>, class file %s", THREAD);
2318     return nullptr;
2319   }
2320 
2321   if (EnableValhalla) {
2322     if (((flags & JVM_ACC_SYNCHRONIZED) == JVM_ACC_SYNCHRONIZED)
2323         && ((flags & JVM_ACC_STATIC) == 0 )
2324         && !_access_flags.is_identity_class()) {
2325       classfile_parse_error("Invalid synchronized method in non-identity class %s", THREAD);
2326         return nullptr;
2327     }
2328   }
2329 
2330   int args_size = -1;  // only used when _need_verify is true
2331   if (_need_verify) {
2332     verify_legal_name_with_signature(name, signature, CHECK_NULL);
2333     args_size = ((flags & JVM_ACC_STATIC) ? 0 : 1) +
2334                  verify_legal_method_signature(name, signature, CHECK_NULL);
2335     if (args_size > MAX_ARGS_SIZE) {
2336       classfile_parse_error("Too many arguments in method signature in class file %s", THREAD);
2337       return nullptr;
2338     }
2339   }
2340 
2341   AccessFlags access_flags(flags & JVM_RECOGNIZED_METHOD_MODIFIERS);
2342 
2343   // Default values for code and exceptions attribute elements
2344   u2 max_stack = 0;
2345   u2 max_locals = 0;
2346   u4 code_length = 0;
2347   const u1* code_start = 0;
2348   u2 exception_table_length = 0;
2349   const unsafe_u2* exception_table_start = nullptr; // (potentially unaligned) pointer to array of u2 elements

2874     if (m->is_empty_method()) {
2875       _has_empty_finalizer = true;
2876     } else {
2877       _has_finalizer = true;
2878     }
2879   }
2880   if (name == vmSymbols::object_initializer_name() &&
2881       signature == vmSymbols::void_method_signature() &&
2882       m->is_vanilla_constructor()) {
2883     _has_vanilla_constructor = true;
2884   }
2885 
2886   NOT_PRODUCT(m->verify());
2887   return m;
2888 }
2889 
2890 
2891 // Side-effects: populates the _methods field in the parser
2892 void ClassFileParser::parse_methods(const ClassFileStream* const cfs,
2893                                     bool is_interface,
2894                                     bool is_value_class,
2895                                     bool is_abstract_type,
2896                                     bool* const has_localvariable_table,
2897                                     bool* has_final_method,
2898                                     bool* declares_nonstatic_concrete_methods,
2899                                     TRAPS) {
2900   assert(cfs != nullptr, "invariant");
2901   assert(has_localvariable_table != nullptr, "invariant");
2902   assert(has_final_method != nullptr, "invariant");
2903   assert(declares_nonstatic_concrete_methods != nullptr, "invariant");
2904 
2905   assert(nullptr == _methods, "invariant");
2906 
2907   cfs->guarantee_more(2, CHECK);  // length
2908   const u2 length = cfs->get_u2_fast();
2909   if (length == 0) {
2910     _methods = Universe::the_empty_method_array();
2911   } else {
2912     _methods = MetadataFactory::new_array<Method*>(_loader_data,
2913                                                    length,
2914                                                    nullptr,
2915                                                    CHECK);
2916 
2917     for (int index = 0; index < length; index++) {
2918       Method* method = parse_method(cfs,
2919                                     is_interface,
2920                                     is_value_class,
2921                                     is_abstract_type,
2922                                     _cp,
2923                                     has_localvariable_table,
2924                                     CHECK);
2925 
2926       if (method->is_final()) {
2927         *has_final_method = true;
2928       }
2929       // declares_nonstatic_concrete_methods: declares concrete instance methods, any access flags
2930       // used for interface initialization, and default method inheritance analysis
2931       if (is_interface && !(*declares_nonstatic_concrete_methods)
2932         && !method->is_abstract() && !method->is_static()) {
2933         *declares_nonstatic_concrete_methods = true;
2934       }
2935       _methods->at_put(index, method);
2936     }
2937 
2938     if (_need_verify && length > 1) {
2939       // Check duplicated methods
2940       ResourceMark rm(THREAD);
2941       // Set containing name-signature pairs

3167         valid_klass_reference_at(outer_class_info_index),
3168       "outer_class_info_index %u has bad constant type in class file %s",
3169       outer_class_info_index, CHECK_0);
3170 
3171     if (outer_class_info_index != 0) {
3172       const Symbol* const outer_class_name = cp->klass_name_at(outer_class_info_index);
3173       char* bytes = (char*)outer_class_name->bytes();
3174       guarantee_property(bytes[0] != JVM_SIGNATURE_ARRAY,
3175                          "Outer class is an array class in class file %s", CHECK_0);
3176     }
3177     // Inner class name
3178     const u2 inner_name_index = cfs->get_u2_fast();
3179     check_property(
3180       inner_name_index == 0 || valid_symbol_at(inner_name_index),
3181       "inner_name_index %u has bad constant type in class file %s",
3182       inner_name_index, CHECK_0);
3183     if (_need_verify) {
3184       guarantee_property(inner_class_info_index != outer_class_info_index,
3185                          "Class is both outer and inner class in class file %s", CHECK_0);
3186     }
3187 
3188     jint recognized_modifiers = RECOGNIZED_INNER_CLASS_MODIFIERS;
3189     // JVM_ACC_MODULE is defined in JDK-9 and later.
3190     if (_major_version >= JAVA_9_VERSION) {
3191       recognized_modifiers |= JVM_ACC_MODULE;


3192     }
3193 
3194     // Access flags
3195     jint flags = cfs->get_u2_fast() & recognized_modifiers;
3196 
3197     if ((flags & JVM_ACC_INTERFACE) && _major_version < JAVA_6_VERSION) {
3198       // Set abstract bit for old class files for backward compatibility
3199       flags |= JVM_ACC_ABSTRACT;
3200     }
3201 
3202     if (EnableValhalla) {
3203       if (!supports_inline_types()) {
3204         const bool is_module = (flags & JVM_ACC_MODULE) != 0;
3205         const bool is_interface = (flags & JVM_ACC_INTERFACE) != 0;
3206         if (!is_module && !is_interface) {
3207           flags |= JVM_ACC_IDENTITY;
3208         }
3209       }
3210     }
3211 
3212     const char* name = inner_name_index == 0 ? "unnamed" : cp->symbol_at(inner_name_index)->as_utf8();
3213     verify_legal_class_modifiers(flags, name, false, CHECK_0);
3214     AccessFlags inner_access_flags(flags);
3215 
3216     inner_classes->at_put(index++, inner_class_info_index);
3217     inner_classes->at_put(index++, outer_class_info_index);
3218     inner_classes->at_put(index++, inner_name_index);
3219     inner_classes->at_put(index++, inner_access_flags.as_short());
3220   }
3221 
3222   // Check for circular and duplicate entries.
3223   bool has_circularity = false;
3224   if (_need_verify) {
3225     has_circularity = check_inner_classes_circularity(cp, length * 4, CHECK_0);
3226     if (has_circularity) {
3227       // If circularity check failed then ignore InnerClasses attribute.
3228       MetadataFactory::free_array<u2>(_loader_data, _inner_classes);
3229       index = 0;
3230       if (parsed_enclosingmethod_attribute) {
3231         inner_classes = MetadataFactory::new_array<u2>(_loader_data, 2, CHECK_0);
3232         _inner_classes = inner_classes;
3233       } else {

3297   if (length > 0) {
3298     int index = 0;
3299     cfs->guarantee_more(2 * length, CHECK_0);
3300     for (int n = 0; n < length; n++) {
3301       const u2 class_info_index = cfs->get_u2_fast();
3302       check_property(
3303         valid_klass_reference_at(class_info_index),
3304         "Permitted subclass class_info_index %u has bad constant type in class file %s",
3305         class_info_index, CHECK_0);
3306       permitted_subclasses->at_put(index++, class_info_index);
3307     }
3308     assert(index == size, "wrong size");
3309   }
3310 
3311   // Restore buffer's current position.
3312   cfs->set_current(current_mark);
3313 
3314   return length;
3315 }
3316 
3317 u2 ClassFileParser::parse_classfile_preload_attribute(const ClassFileStream* const cfs,
3318                                                                    const u1* const preload_attribute_start,
3319                                                                    TRAPS) {
3320   const u1* const current_mark = cfs->current();
3321   u2 length = 0;
3322   if (preload_attribute_start != nullptr) {
3323     cfs->set_current(preload_attribute_start);
3324     cfs->guarantee_more(2, CHECK_0);  // length
3325     length = cfs->get_u2_fast();
3326   }
3327   const int size = length;
3328   Array<u2>* const preload_classes = MetadataFactory::new_array<u2>(_loader_data, size, CHECK_0);
3329   _preload_classes = preload_classes;
3330   if (length > 0) {
3331     int index = 0;
3332     cfs->guarantee_more(2 * length, CHECK_0);
3333     for (int n = 0; n < length; n++) {
3334       const u2 class_info_index = cfs->get_u2_fast();
3335       check_property(
3336         valid_klass_reference_at(class_info_index),
3337         "Preload class_info_index %u has bad constant type in class file %s",
3338         class_info_index, CHECK_0);
3339       preload_classes->at_put(index++, class_info_index);
3340     }
3341     assert(index == size, "wrong size");
3342   }
3343 
3344   // Restore buffer's current position.
3345   cfs->set_current(current_mark);
3346 
3347   return length;
3348 }
3349 
3350 //  Record {
3351 //    u2 attribute_name_index;
3352 //    u4 attribute_length;
3353 //    u2 components_count;
3354 //    component_info components[components_count];
3355 //  }
3356 //  component_info {
3357 //    u2 name_index;
3358 //    u2 descriptor_index
3359 //    u2 attributes_count;
3360 //    attribute_info_attributes[attributes_count];
3361 //  }
3362 u4 ClassFileParser::parse_classfile_record_attribute(const ClassFileStream* const cfs,
3363                                                      const ConstantPool* cp,
3364                                                      const u1* const record_attribute_start,
3365                                                      TRAPS) {
3366   const u1* const current_mark = cfs->current();
3367   int components_count = 0;
3368   unsigned int calculate_attr_size = 0;
3369   if (record_attribute_start != nullptr) {

3614   }
3615   guarantee_property(current_start + attribute_byte_length == cfs->current(),
3616                      "Bad length on BootstrapMethods in class file %s",
3617                      CHECK);
3618 }
3619 
3620 void ClassFileParser::parse_classfile_attributes(const ClassFileStream* const cfs,
3621                                                  ConstantPool* cp,
3622                  ClassFileParser::ClassAnnotationCollector* parsed_annotations,
3623                                                  TRAPS) {
3624   assert(cfs != nullptr, "invariant");
3625   assert(cp != nullptr, "invariant");
3626   assert(parsed_annotations != nullptr, "invariant");
3627 
3628   // Set inner classes attribute to default sentinel
3629   _inner_classes = Universe::the_empty_short_array();
3630   // Set nest members attribute to default sentinel
3631   _nest_members = Universe::the_empty_short_array();
3632   // Set _permitted_subclasses attribute to default sentinel
3633   _permitted_subclasses = Universe::the_empty_short_array();
3634   // Set _preload_classes attribute to default sentinel
3635   _preload_classes = Universe::the_empty_short_array();
3636   cfs->guarantee_more(2, CHECK);  // attributes_count
3637   u2 attributes_count = cfs->get_u2_fast();
3638   bool parsed_sourcefile_attribute = false;
3639   bool parsed_innerclasses_attribute = false;
3640   bool parsed_nest_members_attribute = false;
3641   bool parsed_permitted_subclasses_attribute = false;
3642   bool parsed_preload_attribute = false;
3643   bool parsed_nest_host_attribute = false;
3644   bool parsed_record_attribute = false;
3645   bool parsed_enclosingmethod_attribute = false;
3646   bool parsed_bootstrap_methods_attribute = false;
3647   const u1* runtime_visible_annotations = nullptr;
3648   int runtime_visible_annotations_length = 0;
3649   const u1* runtime_invisible_annotations = nullptr;
3650   int runtime_invisible_annotations_length = 0;
3651   const u1* runtime_visible_type_annotations = nullptr;
3652   int runtime_visible_type_annotations_length = 0;
3653   const u1* runtime_invisible_type_annotations = nullptr;
3654   int runtime_invisible_type_annotations_length = 0;
3655   bool runtime_invisible_type_annotations_exists = false;
3656   bool runtime_invisible_annotations_exists = false;
3657   bool parsed_source_debug_ext_annotations_exist = false;
3658   const u1* inner_classes_attribute_start = nullptr;
3659   u4  inner_classes_attribute_length = 0;
3660   u2  enclosing_method_class_index = 0;
3661   u2  enclosing_method_method_index = 0;
3662   const u1* nest_members_attribute_start = nullptr;
3663   u4  nest_members_attribute_length = 0;
3664   const u1* record_attribute_start = nullptr;
3665   u4  record_attribute_length = 0;
3666   const u1* permitted_subclasses_attribute_start = nullptr;
3667   u4  permitted_subclasses_attribute_length = 0;
3668   const u1* preload_attribute_start = nullptr;
3669   u4  preload_attribute_length = 0;
3670 
3671   // Iterate over attributes
3672   while (attributes_count--) {
3673     cfs->guarantee_more(6, CHECK);  // attribute_name_index, attribute_length
3674     const u2 attribute_name_index = cfs->get_u2_fast();
3675     const u4 attribute_length = cfs->get_u4_fast();
3676     check_property(
3677       valid_symbol_at(attribute_name_index),
3678       "Attribute name has bad constant pool index %u in class file %s",
3679       attribute_name_index, CHECK);
3680     const Symbol* const tag = cp->symbol_at(attribute_name_index);
3681     if (tag == vmSymbols::tag_source_file()) {
3682       // Check for SourceFile tag
3683       if (_need_verify) {
3684         guarantee_property(attribute_length == 2, "Wrong SourceFile attribute length in class file %s", CHECK);
3685       }
3686       if (parsed_sourcefile_attribute) {
3687         classfile_parse_error("Multiple SourceFile attributes in class file %s", THREAD);
3688         return;
3689       } else {

3876               return;
3877             }
3878             parsed_record_attribute = true;
3879             record_attribute_start = cfs->current();
3880             record_attribute_length = attribute_length;
3881           } else if (_major_version >= JAVA_17_VERSION) {
3882             if (tag == vmSymbols::tag_permitted_subclasses()) {
3883               if (parsed_permitted_subclasses_attribute) {
3884                 classfile_parse_error("Multiple PermittedSubclasses attributes in class file %s", CHECK);
3885                 return;
3886               }
3887               // Classes marked ACC_FINAL cannot have a PermittedSubclasses attribute.
3888               if (_access_flags.is_final()) {
3889                 classfile_parse_error("PermittedSubclasses attribute in final class file %s", CHECK);
3890                 return;
3891               }
3892               parsed_permitted_subclasses_attribute = true;
3893               permitted_subclasses_attribute_start = cfs->current();
3894               permitted_subclasses_attribute_length = attribute_length;
3895             }
3896             if (EnableValhalla && tag == vmSymbols::tag_preload()) {
3897               if (parsed_preload_attribute) {
3898                 classfile_parse_error("Multiple Preload attributes in class file %s", CHECK);
3899                 return;
3900               }
3901               parsed_preload_attribute = true;
3902               preload_attribute_start = cfs->current();
3903               preload_attribute_length = attribute_length;
3904             }
3905           }
3906           // Skip attribute_length for any attribute where major_verson >= JAVA_17_VERSION
3907           cfs->skip_u1(attribute_length, CHECK);
3908         } else {
3909           // Unknown attribute
3910           cfs->skip_u1(attribute_length, CHECK);
3911         }
3912       } else {
3913         // Unknown attribute
3914         cfs->skip_u1(attribute_length, CHECK);
3915       }
3916     } else {
3917       // Unknown attribute
3918       cfs->skip_u1(attribute_length, CHECK);
3919     }
3920   }
3921   _class_annotations = assemble_annotations(runtime_visible_annotations,
3922                                             runtime_visible_annotations_length,
3923                                             runtime_invisible_annotations,
3924                                             runtime_invisible_annotations_length,

3965                             CHECK);
3966     if (_need_verify) {
3967       guarantee_property(record_attribute_length == calculated_attr_length,
3968                          "Record attribute has wrong length in class file %s",
3969                          CHECK);
3970     }
3971   }
3972 
3973   if (parsed_permitted_subclasses_attribute) {
3974     const u2 num_subclasses = parse_classfile_permitted_subclasses_attribute(
3975                             cfs,
3976                             permitted_subclasses_attribute_start,
3977                             CHECK);
3978     if (_need_verify) {
3979       guarantee_property(
3980         permitted_subclasses_attribute_length == sizeof(num_subclasses) + sizeof(u2) * num_subclasses,
3981         "Wrong PermittedSubclasses attribute length in class file %s", CHECK);
3982     }
3983   }
3984 
3985   if (parsed_preload_attribute) {
3986     const u2 num_classes = parse_classfile_preload_attribute(
3987                             cfs,
3988                             preload_attribute_start,
3989                             CHECK);
3990     if (_need_verify) {
3991       guarantee_property(
3992         preload_attribute_length == sizeof(num_classes) + sizeof(u2) * num_classes,
3993         "Wrong Preload attribute length in class file %s", CHECK);
3994     }
3995   }
3996 
3997   if (_max_bootstrap_specifier_index >= 0) {
3998     guarantee_property(parsed_bootstrap_methods_attribute,
3999                        "Missing BootstrapMethods attribute in class file %s", CHECK);
4000   }
4001 }
4002 
4003 void ClassFileParser::apply_parsed_class_attributes(InstanceKlass* k) {
4004   assert(k != nullptr, "invariant");
4005 
4006   if (_synthetic_flag)
4007     k->set_is_synthetic();
4008   if (_sourcefile_index != 0) {
4009     k->set_source_file_name_index(_sourcefile_index);
4010   }
4011   if (_generic_signature_index != 0) {
4012     k->set_generic_signature_index(_generic_signature_index);
4013   }
4014   if (_sde_buffer != nullptr) {
4015     k->set_source_debug_extension(_sde_buffer, _sde_length);
4016   }

4042     _class_annotations       = nullptr;
4043     _class_type_annotations  = nullptr;
4044     _fields_annotations      = nullptr;
4045     _fields_type_annotations = nullptr;
4046 }
4047 
4048 // Transfer ownership of metadata allocated to the InstanceKlass.
4049 void ClassFileParser::apply_parsed_class_metadata(
4050                                             InstanceKlass* this_klass,
4051                                             int java_fields_count) {
4052   assert(this_klass != nullptr, "invariant");
4053 
4054   _cp->set_pool_holder(this_klass);
4055   this_klass->set_constants(_cp);
4056   this_klass->set_fieldinfo_stream(_fieldinfo_stream);
4057   this_klass->set_fields_status(_fields_status);
4058   this_klass->set_methods(_methods);
4059   this_klass->set_inner_classes(_inner_classes);
4060   this_klass->set_nest_members(_nest_members);
4061   this_klass->set_nest_host_index(_nest_host);
4062   this_klass->set_preload_classes(_preload_classes);
4063   this_klass->set_annotations(_combined_annotations);
4064   this_klass->set_permitted_subclasses(_permitted_subclasses);
4065   this_klass->set_record_components(_record_components);
4066   // Delay the setting of _local_interfaces and _transitive_interfaces until after
4067   // initialize_supers() in fill_instance_klass(). It is because the _local_interfaces could
4068   // be shared with _transitive_interfaces and _transitive_interfaces may be shared with
4069   // its _super. If an OOM occurs while loading the current klass, its _super field
4070   // may not have been set. When GC tries to free the klass, the _transitive_interfaces
4071   // may be deallocated mistakenly in InstanceKlass::deallocate_interfaces(). Subsequent
4072   // dereferences to the deallocated _transitive_interfaces will result in a crash.
4073 
4074   // Clear out these fields so they don't get deallocated by the destructor
4075   clear_class_metadata();
4076 }
4077 
4078 AnnotationArray* ClassFileParser::assemble_annotations(const u1* const runtime_visible_annotations,
4079                                                        int runtime_visible_annotations_length,
4080                                                        const u1* const runtime_invisible_annotations,
4081                                                        int runtime_invisible_annotations_length,
4082                                                        TRAPS) {

4094     }
4095     if (runtime_invisible_annotations != nullptr) {
4096       for (int i = 0; i < runtime_invisible_annotations_length; i++) {
4097         int append = runtime_visible_annotations_length+i;
4098         annotations->at_put(append, runtime_invisible_annotations[i]);
4099       }
4100     }
4101   }
4102   return annotations;
4103 }
4104 
4105 const InstanceKlass* ClassFileParser::parse_super_class(ConstantPool* const cp,
4106                                                         const int super_class_index,
4107                                                         const bool need_verify,
4108                                                         TRAPS) {
4109   assert(cp != nullptr, "invariant");
4110   const InstanceKlass* super_klass = nullptr;
4111 
4112   if (super_class_index == 0) {
4113     check_property(_class_name == vmSymbols::java_lang_Object(),
4114                    "Invalid superclass index 0 in class file %s",

4115                    CHECK_NULL);
4116   } else {
4117     check_property(valid_klass_reference_at(super_class_index),
4118                    "Invalid superclass index %u in class file %s",
4119                    super_class_index,
4120                    CHECK_NULL);
4121     // The class name should be legal because it is checked when parsing constant pool.
4122     // However, make sure it is not an array type.

4123     if (cp->tag_at(super_class_index).is_klass()) {
4124       super_klass = InstanceKlass::cast(cp->resolved_klass_at(super_class_index));




4125     }
4126     if (need_verify) {
4127       bool is_array = (cp->klass_name_at(super_class_index)->char_at(0) == JVM_SIGNATURE_ARRAY);
4128       guarantee_property(!is_array,
4129                         "Bad superclass name in class file %s", CHECK_NULL);
4130     }
4131   }
4132   return super_klass;
4133 }
4134 
4135 OopMapBlocksBuilder::OopMapBlocksBuilder(unsigned int max_blocks) {
4136   _max_nonstatic_oop_maps = max_blocks;
4137   _nonstatic_oop_map_count = 0;
4138   if (max_blocks == 0) {
4139     _nonstatic_oop_maps = nullptr;
4140   } else {
4141     _nonstatic_oop_maps =
4142         NEW_RESOURCE_ARRAY(OopMapBlock, _max_nonstatic_oop_maps);
4143     memset(_nonstatic_oop_maps, 0, sizeof(OopMapBlock) * max_blocks);
4144   }
4145 }
4146 
4147 OopMapBlock* OopMapBlocksBuilder::last_oop_map() const {

4231 }
4232 
4233 void OopMapBlocksBuilder::print_on(outputStream* st) const {
4234   st->print_cr("  OopMapBlocks: %3d  /%3d", _nonstatic_oop_map_count, _max_nonstatic_oop_maps);
4235   if (_nonstatic_oop_map_count > 0) {
4236     OopMapBlock* map = _nonstatic_oop_maps;
4237     OopMapBlock* last_map = last_oop_map();
4238     assert(map <= last_map, "Last less than first");
4239     while (map <= last_map) {
4240       st->print_cr("    Offset: %3d  -%3d Count: %3d", map->offset(),
4241                    map->offset() + map->offset_span() - heapOopSize, map->count());
4242       map++;
4243     }
4244   }
4245 }
4246 
4247 void OopMapBlocksBuilder::print_value_on(outputStream* st) const {
4248   print_on(st);
4249 }
4250 
4251 void ClassFileParser::throwInlineTypeLimitation(THREAD_AND_LOCATION_DECL,
4252                                                 const char* msg,
4253                                                 const Symbol* name,
4254                                                 const Symbol* sig) const {
4255 
4256   ResourceMark rm(THREAD);
4257   if (name == nullptr || sig == nullptr) {
4258     Exceptions::fthrow(THREAD_AND_LOCATION_ARGS,
4259         vmSymbols::java_lang_ClassFormatError(),
4260         "class: %s - %s", _class_name->as_C_string(), msg);
4261   }
4262   else {
4263     Exceptions::fthrow(THREAD_AND_LOCATION_ARGS,
4264         vmSymbols::java_lang_ClassFormatError(),
4265         "\"%s\" sig: \"%s\" class: %s - %s", name->as_C_string(), sig->as_C_string(),
4266         _class_name->as_C_string(), msg);
4267   }
4268 }
4269 
4270 void ClassFileParser::set_precomputed_flags(InstanceKlass* ik) {
4271   assert(ik != nullptr, "invariant");
4272 
4273   const InstanceKlass* const super = ik->java_super();
4274 
4275   // Check if this klass has an empty finalize method (i.e. one with return bytecode only),
4276   // in which case we don't have to register objects as finalizable
4277   if (!_has_empty_finalizer) {
4278     if (_has_finalizer ||
4279         (super != nullptr && super->has_finalizer())) {
4280       ik->set_has_finalizer();
4281     }
4282   }
4283 
4284 #ifdef ASSERT
4285   bool f = false;
4286   const Method* const m = ik->lookup_method(vmSymbols::finalize_method_name(),
4287                                            vmSymbols::void_method_signature());
4288   if (InstanceKlass::is_finalization_enabled() &&
4289       (m != nullptr) && !m->is_empty_method()) {
4290       f = true;
4291   }
4292 
4293   // Spec doesn't prevent agent from redefinition of empty finalizer.
4294   // Despite the fact that it's generally bad idea and redefined finalizer
4295   // will not work as expected we shouldn't abort vm in this case
4296   if (!ik->has_redefined_this_or_super()) {
4297     assert(ik->has_finalizer() == f, "inconsistent has_finalizer");
4298   }
4299 #endif
4300 
4301   // Check if this klass supports the java.lang.Cloneable interface
4302   if (vmClasses::Cloneable_klass_loaded()) {
4303     if (ik->is_subtype_of(vmClasses::Cloneable_klass())) {
4304       if (ik->is_inline_klass()) {
4305         JavaThread *THREAD = JavaThread::current();
4306         throwInlineTypeLimitation(THREAD_AND_LOCATION, "Inline Types do not support Cloneable");
4307         return;
4308       }
4309       ik->set_is_cloneable();
4310     }
4311   }
4312 
4313   // Check if this klass has a vanilla default constructor
4314   if (super == nullptr) {
4315     // java.lang.Object has empty default constructor
4316     ik->set_has_vanilla_constructor();
4317   } else {
4318     if (super->has_vanilla_constructor() &&
4319         _has_vanilla_constructor) {
4320       ik->set_has_vanilla_constructor();
4321     }
4322 #ifdef ASSERT
4323     bool v = false;
4324     if (super->has_vanilla_constructor()) {
4325       const Method* const constructor =
4326         ik->find_method(vmSymbols::object_initializer_name(),
4327                        vmSymbols::void_method_signature());
4328       if (constructor != nullptr && constructor->is_vanilla_constructor()) {
4329         v = true;
4330       }
4331     }
4332     assert(v == ik->has_vanilla_constructor(), "inconsistent has_vanilla_constructor");
4333 #endif
4334   }
4335 
4336   // If it cannot be fast-path allocated, set a bit in the layout helper.
4337   // See documentation of InstanceKlass::can_be_fastpath_allocated().
4338   assert(ik->size_helper() > 0, "layout_helper is initialized");
4339   if ((!RegisterFinalizersAtInit && ik->has_finalizer())
4340       || ik->is_abstract() || ik->is_interface()
4341       || (ik->name() == vmSymbols::java_lang_Class() && ik->class_loader() == nullptr)
4342       || ik->size_helper() >= FastAllocateSizeLimit) {
4343     // Forbid fast-path allocation.
4344     const jint lh = Klass::instance_layout_helper(ik->size_helper(), true);
4345     ik->set_layout_helper(lh);
4346   }
4347 }
4348 
4349 bool ClassFileParser::supports_inline_types() const {
4350   // Inline types are only supported by class file version 61.65535 and later
4351   return _major_version > JAVA_22_VERSION ||
4352          (_major_version == JAVA_22_VERSION /*&& _minor_version == JAVA_PREVIEW_MINOR_VERSION*/); // JAVA_PREVIEW_MINOR_VERSION not yet implemented by javac, check JVMS draft
4353 }
4354 
4355 // utility methods for appending an array with check for duplicates
4356 
4357 static void append_interfaces(GrowableArray<InstanceKlass*>* result,
4358                               const Array<InstanceKlass*>* const ifs) {
4359   // iterate over new interfaces
4360   for (int i = 0; i < ifs->length(); i++) {
4361     InstanceKlass* const e = ifs->at(i);
4362     assert(e->is_klass() && e->is_interface(), "just checking");
4363     // add new interface
4364     result->append_if_missing(e);
4365   }
4366 }
4367 
4368 static Array<InstanceKlass*>* compute_transitive_interfaces(const InstanceKlass* super,
4369                                                             Array<InstanceKlass*>* local_ifs,
4370                                                             ClassLoaderData* loader_data,
4371                                                             TRAPS) {
4372   assert(local_ifs != nullptr, "invariant");
4373   assert(loader_data != nullptr, "invariant");
4374 

4378   // Add superclass transitive interfaces size
4379   if (super != nullptr) {
4380     super_size = super->transitive_interfaces()->length();
4381     max_transitive_size += super_size;
4382   }
4383   // Add local interfaces' super interfaces
4384   const int local_size = local_ifs->length();
4385   for (int i = 0; i < local_size; i++) {
4386     InstanceKlass* const l = local_ifs->at(i);
4387     max_transitive_size += l->transitive_interfaces()->length();
4388   }
4389   // Finally add local interfaces
4390   max_transitive_size += local_size;
4391   // Construct array
4392   if (max_transitive_size == 0) {
4393     // no interfaces, use canonicalized array
4394     return Universe::the_empty_instance_klass_array();
4395   } else if (max_transitive_size == super_size) {
4396     // no new local interfaces added, share superklass' transitive interface array
4397     return super->transitive_interfaces();
4398     // The three lines below are commented to work around bug JDK-8245487
4399 //  } else if (max_transitive_size == local_size) {
4400 //    // only local interfaces added, share local interface array
4401 //    return local_ifs;
4402   } else {
4403     ResourceMark rm;
4404     GrowableArray<InstanceKlass*>* const result = new GrowableArray<InstanceKlass*>(max_transitive_size);
4405 
4406     // Copy down from superclass
4407     if (super != nullptr) {
4408       append_interfaces(result, super->transitive_interfaces());
4409     }
4410 
4411     // Copy down from local interfaces' superinterfaces
4412     for (int i = 0; i < local_size; i++) {
4413       InstanceKlass* const l = local_ifs->at(i);
4414       append_interfaces(result, l->transitive_interfaces());
4415     }
4416     // Finally add local interfaces
4417     append_interfaces(result, local_ifs);
4418 
4419     // length will be less than the max_transitive_size if duplicates were removed
4420     const int length = result->length();
4421     assert(length <= max_transitive_size, "just checking");
4422 
4423     Array<InstanceKlass*>* const new_result =
4424       MetadataFactory::new_array<InstanceKlass*>(loader_data, length, CHECK_NULL);
4425     for (int i = 0; i < length; i++) {
4426       InstanceKlass* const e = result->at(i);
4427       assert(e != nullptr, "just checking");
4428       new_result->at_put(i, e);
4429     }
4430     return new_result;
4431   }
4432 }
4433 
4434 void ClassFileParser::check_super_class_access(const InstanceKlass* this_klass, TRAPS) {
4435   assert(this_klass != nullptr, "invariant");
4436   const Klass* const super = this_klass->super();
4437 
4438   if (super != nullptr) {
4439     const InstanceKlass* super_ik = InstanceKlass::cast(super);
4440 
4441     if (super->is_final()) {
4442       classfile_icce_error("class %s cannot inherit from final class %s", super_ik, THREAD);
4443       return;
4444     }
4445 
4446     if (super_ik->is_sealed() && !super_ik->has_as_permitted_subclass(this_klass)) {
4447       classfile_icce_error("class %s cannot inherit from sealed class %s", super_ik, THREAD);
4448       return;
4449     }
4450 
4451     // The JVMS says that super classes for value types must not have the ACC_IDENTITY
4452     // flag set. But, java.lang.Object must still be allowed to be a direct super class
4453     // for a value classes.  So, it is treated as a special case for now.
4454     if (!this_klass->access_flags().is_identity_class() &&
4455         super_ik->name() != vmSymbols::java_lang_Object() &&
4456         super_ik->is_identity_class()) {
4457       classfile_icce_error("value class %s cannot inherit from class %s", super_ik, THREAD);
4458       return;
4459     }
4460 
4461     // If the loader is not the boot loader then throw an exception if its
4462     // superclass is in package jdk.internal.reflect and its loader is not a
4463     // special reflection class loader
4464     if (!this_klass->class_loader_data()->is_the_null_class_loader_data()) {
4465       PackageEntry* super_package = super->package();
4466       if (super_package != nullptr &&
4467           super_package->name()->fast_compare(vmSymbols::jdk_internal_reflect()) == 0 &&
4468           !java_lang_ClassLoader::is_reflection_class_loader(this_klass->class_loader())) {
4469         ResourceMark rm(THREAD);
4470         Exceptions::fthrow(
4471           THREAD_AND_LOCATION,
4472           vmSymbols::java_lang_IllegalAccessError(),
4473           "class %s loaded by %s cannot access jdk/internal/reflect superclass %s",
4474           this_klass->external_name(),
4475           this_klass->class_loader_data()->loader_name_and_id(),
4476           super->external_name());
4477         return;
4478       }
4479     }
4480 

4626 
4627   for (int index = 0; index < num_methods; index++) {
4628     const Method* const m = methods->at(index);
4629     // if m is static and not the init method, throw a verify error
4630     if ((m->is_static()) && (m->name() != vmSymbols::class_initializer_name())) {
4631       ResourceMark rm(THREAD);
4632       Exceptions::fthrow(
4633         THREAD_AND_LOCATION,
4634         vmSymbols::java_lang_VerifyError(),
4635         "Illegal static method %s in interface %s",
4636         m->name()->as_C_string(),
4637         this_klass->external_name()
4638       );
4639       return;
4640     }
4641   }
4642 }
4643 
4644 // utility methods for format checking
4645 
4646 void ClassFileParser::verify_legal_class_modifiers(jint flags, const char* name, bool is_Object, TRAPS) const {
4647   const bool is_module = (flags & JVM_ACC_MODULE) != 0;
4648   const bool is_identity_class = (flags & JVM_ACC_IDENTITY) != 0;
4649   const bool is_inner_class = name != nullptr;
4650   assert(_major_version >= JAVA_9_VERSION || !is_module, "JVM_ACC_MODULE should not be set");
4651   if (is_module) {
4652     ResourceMark rm(THREAD);
4653     Exceptions::fthrow(
4654       THREAD_AND_LOCATION,
4655       vmSymbols::java_lang_NoClassDefFoundError(),
4656       "%s is not a class because access_flag ACC_MODULE is set",
4657       _class_name->as_C_string());
4658     return;
4659   }
4660 
4661   // if (!_need_verify) { return; }
4662 
4663   const bool is_interface  = (flags & JVM_ACC_INTERFACE)  != 0;
4664   const bool is_abstract   = (flags & JVM_ACC_ABSTRACT)   != 0;
4665   const bool is_final      = (flags & JVM_ACC_FINAL)      != 0;
4666   const bool is_identity   = (flags & JVM_ACC_IDENTITY)   != 0;
4667   const bool is_enum       = (flags & JVM_ACC_ENUM)       != 0;
4668   const bool is_annotation = (flags & JVM_ACC_ANNOTATION) != 0;
4669   const bool major_gte_1_5 = _major_version >= JAVA_1_5_VERSION;
4670 
4671   if ((is_abstract && is_final) ||
4672       (is_interface && !is_abstract) ||
4673       (is_interface && major_gte_1_5 && (is_identity || is_enum)) ||   //  ACC_SUPER (now ACC_IDENTITY) was illegal for interfaces
4674       (!is_interface && major_gte_1_5 && is_annotation) ||
4675       (!is_identity_class && is_enum)) {
4676     ResourceMark rm(THREAD);
4677     const char* class_note = "";
4678     if (!is_identity_class)  class_note = " (a value class)";
4679     if (name == nullptr) { // Not an inner class
4680       Exceptions::fthrow(
4681         THREAD_AND_LOCATION,
4682         vmSymbols::java_lang_ClassFormatError(),
4683         "Illegal class modifiers in class %s%s: 0x%X",
4684         _class_name->as_C_string(), class_note, flags
4685       );
4686       return;
4687     } else {
4688       Exceptions::fthrow(
4689         THREAD_AND_LOCATION,
4690         vmSymbols::java_lang_ClassFormatError(),
4691         "Illegal class modifiers in declaration of inner class %s%s of class %s: 0x%X",
4692         name, class_note, _class_name->as_C_string(), flags
4693       );
4694       return;
4695     }
4696   }
4697 }
4698 
4699 static bool has_illegal_visibility(jint flags) {
4700   const bool is_public    = (flags & JVM_ACC_PUBLIC)    != 0;
4701   const bool is_protected = (flags & JVM_ACC_PROTECTED) != 0;
4702   const bool is_private   = (flags & JVM_ACC_PRIVATE)   != 0;
4703 
4704   return ((is_public && is_protected) ||
4705           (is_public && is_private) ||
4706           (is_protected && is_private));
4707 }
4708 
4709 // A legal major_version.minor_version must be one of the following:
4710 //
4711 //  Major_version >= 45 and major_version < 56, any minor_version.
4712 //  Major_version >= 56 and major_version <= JVM_CLASSFILE_MAJOR_VERSION and minor_version = 0.
4713 //  Major_version = JVM_CLASSFILE_MAJOR_VERSION and minor_version = 65535 and --enable-preview is present.
4714 //
4715 void ClassFileParser::verify_class_version(u2 major, u2 minor, Symbol* class_name, TRAPS){

4741         THREAD_AND_LOCATION,
4742         vmSymbols::java_lang_UnsupportedClassVersionError(),
4743         "%s (class file version %u.%u) was compiled with preview features that are unsupported. "
4744         "This version of the Java Runtime only recognizes preview features for class file version %u.%u",
4745         class_name->as_C_string(), major, minor, JVM_CLASSFILE_MAJOR_VERSION, JAVA_PREVIEW_MINOR_VERSION);
4746       return;
4747     }
4748 
4749     if (!Arguments::enable_preview()) {
4750       classfile_ucve_error("Preview features are not enabled for %s (class file version %u.%u). Try running with '--enable-preview'",
4751                            class_name, major, minor, THREAD);
4752       return;
4753     }
4754 
4755   } else { // minor != JAVA_PREVIEW_MINOR_VERSION
4756     classfile_ucve_error("%s (class file version %u.%u) was compiled with an invalid non-zero minor version",
4757                          class_name, major, minor, THREAD);
4758   }
4759 }
4760 
4761 void ClassFileParser:: verify_legal_field_modifiers(jint flags,
4762                                                    AccessFlags class_access_flags,
4763                                                    TRAPS) const {
4764   if (!_need_verify) { return; }
4765 
4766   const bool is_public    = (flags & JVM_ACC_PUBLIC)    != 0;
4767   const bool is_protected = (flags & JVM_ACC_PROTECTED) != 0;
4768   const bool is_private   = (flags & JVM_ACC_PRIVATE)   != 0;
4769   const bool is_static    = (flags & JVM_ACC_STATIC)    != 0;
4770   const bool is_final     = (flags & JVM_ACC_FINAL)     != 0;
4771   const bool is_volatile  = (flags & JVM_ACC_VOLATILE)  != 0;
4772   const bool is_transient = (flags & JVM_ACC_TRANSIENT) != 0;
4773   const bool is_enum      = (flags & JVM_ACC_ENUM)      != 0;
4774   const bool major_gte_1_5 = _major_version >= JAVA_1_5_VERSION;
4775 
4776   const bool is_interface = class_access_flags.is_interface();
4777   const bool is_abstract = class_access_flags.is_abstract();
4778   const bool is_identity_class = class_access_flags.is_identity_class();
4779 
4780   bool is_illegal = false;
4781 
4782   if (is_interface) {
4783     if (!is_public || !is_static || !is_final || is_private ||
4784         is_protected || is_volatile || is_transient ||
4785         (major_gte_1_5 && is_enum)) {
4786       is_illegal = true;
4787     }
4788   } else { // not interface
4789     if (has_illegal_visibility(flags) || (is_final && is_volatile)) {
4790       is_illegal = true;
4791     } else {
4792       if (!is_identity_class && !is_abstract && !is_static && !is_final) {
4793         is_illegal = true;
4794       } else if (is_abstract && !is_identity_class && !is_static) {
4795         is_illegal = true;
4796       }
4797     }
4798   }
4799 
4800   if (is_illegal) {
4801     ResourceMark rm(THREAD);
4802     Exceptions::fthrow(
4803       THREAD_AND_LOCATION,
4804       vmSymbols::java_lang_ClassFormatError(),
4805       "Illegal field modifiers in class %s: 0x%X",
4806       _class_name->as_C_string(), flags);
4807     return;
4808   }
4809 }
4810 
4811 void ClassFileParser::verify_legal_method_modifiers(jint flags,
4812                                                     AccessFlags class_access_flags,
4813                                                     const Symbol* name,
4814                                                     TRAPS) const {
4815   if (!_need_verify) { return; }
4816 
4817   const bool is_public       = (flags & JVM_ACC_PUBLIC)       != 0;
4818   const bool is_private      = (flags & JVM_ACC_PRIVATE)      != 0;
4819   const bool is_static       = (flags & JVM_ACC_STATIC)       != 0;
4820   const bool is_final        = (flags & JVM_ACC_FINAL)        != 0;
4821   const bool is_native       = (flags & JVM_ACC_NATIVE)       != 0;
4822   const bool is_abstract     = (flags & JVM_ACC_ABSTRACT)     != 0;
4823   const bool is_bridge       = (flags & JVM_ACC_BRIDGE)       != 0;
4824   const bool is_strict       = (flags & JVM_ACC_STRICT)       != 0;
4825   const bool is_synchronized = (flags & JVM_ACC_SYNCHRONIZED) != 0;
4826   const bool is_protected    = (flags & JVM_ACC_PROTECTED)    != 0;
4827   const bool major_gte_1_5   = _major_version >= JAVA_1_5_VERSION;
4828   const bool major_gte_8     = _major_version >= JAVA_8_VERSION;
4829   const bool major_gte_17    = _major_version >= JAVA_17_VERSION;
4830   const bool is_initializer  = (name == vmSymbols::object_initializer_name());
4831   // LW401 CR required: removal of value factories support
4832   const bool is_interface    = class_access_flags.is_interface();
4833   const bool is_value_class  = !class_access_flags.is_identity_class();
4834   const bool is_identity_class = class_access_flags.is_identity_class();
4835   const bool is_abstract_class = class_access_flags.is_abstract();
4836 
4837   bool is_illegal = false;
4838 
4839   const char* class_note = "";
4840   if (is_interface) {
4841     if (major_gte_8) {
4842       // Class file version is JAVA_8_VERSION or later Methods of
4843       // interfaces may set any of the flags except ACC_PROTECTED,
4844       // ACC_FINAL, ACC_NATIVE, and ACC_SYNCHRONIZED; they must
4845       // have exactly one of the ACC_PUBLIC or ACC_PRIVATE flags set.
4846       if ((is_public == is_private) || /* Only one of private and public should be true - XNOR */
4847           (is_native || is_protected || is_final || is_synchronized) ||
4848           // If a specific method of a class or interface has its
4849           // ACC_ABSTRACT flag set, it must not have any of its
4850           // ACC_FINAL, ACC_NATIVE, ACC_PRIVATE, ACC_STATIC,
4851           // ACC_STRICT, or ACC_SYNCHRONIZED flags set.  No need to
4852           // check for ACC_FINAL, ACC_NATIVE or ACC_SYNCHRONIZED as
4853           // those flags are illegal irrespective of ACC_ABSTRACT being set or not.
4854           (is_abstract && (is_private || is_static || (!major_gte_17 && is_strict)))) {
4855         is_illegal = true;
4856       }
4857     } else if (major_gte_1_5) {
4858       // Class file version in the interval [JAVA_1_5_VERSION, JAVA_8_VERSION)
4859       if (!is_public || is_private || is_protected || is_static || is_final ||
4860           is_synchronized || is_native || !is_abstract || is_strict) {
4861         is_illegal = true;
4862       }
4863     } else {
4864       // Class file version is pre-JAVA_1_5_VERSION
4865       if (!is_public || is_static || is_final || is_native || !is_abstract) {
4866         is_illegal = true;
4867       }
4868     }
4869   } else { // not interface
4870     if (has_illegal_visibility(flags)) {
4871       is_illegal = true;
4872     } else {
4873       if (is_initializer) {
4874         if (is_static || is_final || is_synchronized || is_native ||
4875             is_abstract || (major_gte_1_5 && is_bridge)) {
4876           is_illegal = true;
4877         }
4878       } else { // not initializer
4879         if (!is_identity_class && is_synchronized && !is_static) {
4880           is_illegal = true;
4881           class_note = " (not an identity class)";
4882         } else {
4883           if (is_abstract) {
4884             if ((is_final || is_native || is_private || is_static ||
4885                 (major_gte_1_5 && (is_synchronized || (!major_gte_17 && is_strict))))) {
4886               is_illegal = true;
4887             }
4888           }
4889         }
4890       }
4891     }
4892   }
4893 
4894   if (is_illegal) {
4895     ResourceMark rm(THREAD);
4896     if (is_value_class && is_initializer) {
4897       Exceptions::fthrow(
4898         THREAD_AND_LOCATION,
4899         vmSymbols::java_lang_ClassFormatError(),
4900         "Method <init> is not allowed in value class %s",
4901         _class_name->as_C_string());
4902     } else {
4903       Exceptions::fthrow(
4904         THREAD_AND_LOCATION,
4905         vmSymbols::java_lang_ClassFormatError(),
4906         "Method %s in class %s%s has illegal modifiers: 0x%X",
4907         name->as_C_string(), _class_name->as_C_string(),
4908         class_note, flags);
4909     }
4910     return;
4911   }
4912 }
4913 
4914 void ClassFileParser::verify_legal_utf8(const unsigned char* buffer,
4915                                         int length,
4916                                         TRAPS) const {
4917   assert(_need_verify, "only called when _need_verify is true");
4918   if (!UTF8::is_legal_utf8(buffer, length, _major_version <= 47)) {
4919     classfile_parse_error("Illegal UTF8 string in constant pool in class file %s", THREAD);
4920   }
4921 }
4922 
4923 // Unqualified names may not contain the characters '.', ';', '[', or '/'.
4924 // In class names, '/' separates unqualified names.  This is verified in this function also.
4925 // Method names also may not contain the characters '<' or '>', unless <init>
4926 // or <clinit>.  Note that method names may not be <init> or <clinit> in this
4927 // method.  Because these names have been checked as special cases before
4928 // calling this method in verify_legal_method_name.
4929 //

4946         if (type == ClassFileParser::LegalClass) {
4947           if (p == name || p+1 >= name+length ||
4948               *(p+1) == JVM_SIGNATURE_SLASH) {
4949             return false;
4950           }
4951         } else {
4952           return false;   // do not permit '/' unless it's class name
4953         }
4954         break;
4955       case JVM_SIGNATURE_SPECIAL:
4956       case JVM_SIGNATURE_ENDSPECIAL:
4957         // do not permit '<' or '>' in method names
4958         if (type == ClassFileParser::LegalMethod) {
4959           return false;
4960         }
4961     }
4962   }
4963   return true;
4964 }
4965 
4966 bool ClassFileParser::is_class_in_preload_attribute(Symbol *klass) {
4967   if (_preload_classes == nullptr) return false;
4968   for (int i = 0; i < _preload_classes->length(); i++) {
4969         // if (_cp->tag_at(_preload_classes->at(i)).is_klass()) continue;
4970         Symbol* class_name = _cp->klass_at_noresolve(_preload_classes->at(i));
4971         if (class_name == klass) return true;
4972   }
4973   return false;
4974 }
4975 
4976 // Take pointer to a UTF8 byte string (not NUL-terminated).
4977 // Skip over the longest part of the string that could
4978 // be taken as a fieldname. Allow non-trailing '/'s if slash_ok is true.
4979 // Return a pointer to just past the fieldname.
4980 // Return null if no fieldname at all was found, or in the case of slash_ok
4981 // being true, we saw consecutive slashes (meaning we were looking for a
4982 // qualified path but found something that was badly-formed).
4983 static const char* skip_over_field_name(const char* const name,
4984                                         bool slash_ok,
4985                                         unsigned int length) {
4986   const char* p;
4987   jboolean last_is_slash = false;
4988   jboolean not_first_ch = false;
4989 
4990   for (p = name; p != name + length; not_first_ch = true) {
4991     const char* old_p = p;
4992     jchar ch = *p;
4993     if (ch < 128) {
4994       p++;
4995       // quick check for ascii

5057 // be taken as a field signature. Allow "void" if void_ok.
5058 // Return a pointer to just past the signature.
5059 // Return null if no legal signature is found.
5060 const char* ClassFileParser::skip_over_field_signature(const char* signature,
5061                                                        bool void_ok,
5062                                                        unsigned int length,
5063                                                        TRAPS) const {
5064   unsigned int array_dim = 0;
5065   while (length > 0) {
5066     switch (signature[0]) {
5067     case JVM_SIGNATURE_VOID: if (!void_ok) { return nullptr; }
5068     case JVM_SIGNATURE_BOOLEAN:
5069     case JVM_SIGNATURE_BYTE:
5070     case JVM_SIGNATURE_CHAR:
5071     case JVM_SIGNATURE_SHORT:
5072     case JVM_SIGNATURE_INT:
5073     case JVM_SIGNATURE_FLOAT:
5074     case JVM_SIGNATURE_LONG:
5075     case JVM_SIGNATURE_DOUBLE:
5076       return signature + 1;
5077     case JVM_SIGNATURE_CLASS:
5078     {
5079       if (_major_version < JAVA_1_5_VERSION) {
5080         // Skip over the class name if one is there
5081         const char* const p = skip_over_field_name(signature + 1, true, --length);
5082 
5083         // The next character better be a semicolon
5084         if (p && (p - signature) > 1 && p[0] == JVM_SIGNATURE_ENDCLASS) {
5085           return p + 1;
5086         }
5087       }
5088       else {
5089         // Skip leading 'L' or 'Q' and ignore first appearance of ';'
5090         signature++;
5091         const char* c = (const char*) memchr(signature, JVM_SIGNATURE_ENDCLASS, length - 1);
5092         // Format check signature
5093         if (c != nullptr) {
5094           int newlen = pointer_delta_as_int(c, (char*) signature);
5095           bool legal = verify_unqualified_name(signature, newlen, LegalClass);
5096           if (!legal) {
5097             classfile_parse_error("Class name is empty or contains illegal character "
5098                                   "in descriptor in class file %s",
5099                                   THREAD);
5100             return nullptr;
5101           }
5102           return signature + newlen + 1;
5103         }
5104       }
5105       return nullptr;
5106     }
5107     case JVM_SIGNATURE_ARRAY:
5108       array_dim++;
5109       if (array_dim > 255) {

5125 
5126 // Checks if name is a legal class name.
5127 void ClassFileParser::verify_legal_class_name(const Symbol* name, TRAPS) const {
5128   if (!_need_verify || _relax_verify) { return; }
5129 
5130   assert(name->refcount() > 0, "symbol must be kept alive");
5131   char* bytes = (char*)name->bytes();
5132   unsigned int length = name->utf8_length();
5133   bool legal = false;
5134 
5135   if (length > 0) {
5136     const char* p;
5137     if (bytes[0] == JVM_SIGNATURE_ARRAY) {
5138       p = skip_over_field_signature(bytes, false, length, CHECK);
5139       legal = (p != nullptr) && ((p - bytes) == (int)length);
5140     } else if (_major_version < JAVA_1_5_VERSION) {
5141       if (bytes[0] != JVM_SIGNATURE_SPECIAL) {
5142         p = skip_over_field_name(bytes, true, length);
5143         legal = (p != nullptr) && ((p - bytes) == (int)length);
5144       }
5145     } else if ((_major_version >= CONSTANT_CLASS_DESCRIPTORS || _class_name->starts_with("jdk/internal/reflect/"))
5146                    && bytes[length - 1] == ';' ) {
5147       // Support for L...; and Q...; descriptors
5148       legal = verify_unqualified_name(bytes + 1, length - 2, LegalClass);
5149     } else {
5150       // 4900761: relax the constraints based on JSR202 spec
5151       // Class names may be drawn from the entire Unicode character set.
5152       // Identifiers between '/' must be unqualified names.
5153       // The utf8 string has been verified when parsing cpool entries.
5154       legal = verify_unqualified_name(bytes, length, LegalClass);
5155     }
5156   }
5157   if (!legal) {
5158     ResourceMark rm(THREAD);
5159     assert(_class_name != nullptr, "invariant");
5160     Exceptions::fthrow(
5161       THREAD_AND_LOCATION,
5162       vmSymbols::java_lang_ClassFormatError(),
5163       "Illegal class name \"%.*s\" in class file %s", length, bytes,
5164       _class_name->as_C_string()
5165     );
5166     return;
5167   }
5168 }

5194       THREAD_AND_LOCATION,
5195       vmSymbols::java_lang_ClassFormatError(),
5196       "Illegal field name \"%.*s\" in class %s", length, bytes,
5197       _class_name->as_C_string()
5198     );
5199     return;
5200   }
5201 }
5202 
5203 // Checks if name is a legal method name.
5204 void ClassFileParser::verify_legal_method_name(const Symbol* name, TRAPS) const {
5205   if (!_need_verify || _relax_verify) { return; }
5206 
5207   assert(name != nullptr, "method name is null");
5208   char* bytes = (char*)name->bytes();
5209   unsigned int length = name->utf8_length();
5210   bool legal = false;
5211 
5212   if (length > 0) {
5213     if (bytes[0] == JVM_SIGNATURE_SPECIAL) {
5214       if (name == vmSymbols::object_initializer_name() ||
5215           name == vmSymbols::class_initializer_name()) {
5216         legal = true;
5217       }
5218     } else if (_major_version < JAVA_1_5_VERSION) {
5219       const char* p;
5220       p = skip_over_field_name(bytes, false, length);
5221       legal = (p != nullptr) && ((p - bytes) == (int)length);
5222     } else {
5223       // 4881221: relax the constraints based on JSR202 spec
5224       legal = verify_unqualified_name(bytes, length, LegalMethod);
5225     }
5226   }
5227 
5228   if (!legal) {
5229     ResourceMark rm(THREAD);
5230     assert(_class_name != nullptr, "invariant");
5231     Exceptions::fthrow(
5232       THREAD_AND_LOCATION,
5233       vmSymbols::java_lang_ClassFormatError(),
5234       "Illegal method name \"%.*s\" in class %s", length, bytes,
5235       _class_name->as_C_string()

5256 
5257 // Check that the signature is compatible with the method name.  For example,
5258 // check that <init> has a void signature.
5259 void ClassFileParser::verify_legal_name_with_signature(const Symbol* name,
5260                                                        const Symbol* signature,
5261                                                        TRAPS) const {
5262   if (!_need_verify) {
5263     return;
5264   }
5265 
5266   // Class initializers cannot have args for class format version >= 51.
5267   if (name == vmSymbols::class_initializer_name() &&
5268       signature != vmSymbols::void_method_signature() &&
5269       _major_version >= JAVA_7_VERSION) {
5270     throwIllegalSignature("Method", name, signature, THREAD);
5271     return;
5272   }
5273 
5274   int sig_length = signature->utf8_length();
5275   if (name->utf8_length() > 0 &&
5276     name->char_at(0) == JVM_SIGNATURE_SPECIAL &&
5277     sig_length > 0 &&
5278     signature->char_at(sig_length - 1) != JVM_SIGNATURE_VOID) {
5279     throwIllegalSignature("Method", name, signature, THREAD);
5280   }
5281 }
5282 
5283 // Checks if signature is a legal method signature.
5284 // Returns number of parameters
5285 int ClassFileParser::verify_legal_method_signature(const Symbol* name,
5286                                                    const Symbol* signature,
5287                                                    TRAPS) const {
5288   if (!_need_verify) {
5289     // make sure caller's args_size will be less than 0 even for non-static
5290     // method so it will be recomputed in compute_size_of_parameters().
5291     return -2;
5292   }
5293 
5294   unsigned int args_size = 0;
5295   const char* p = (const char*)signature->bytes();
5296   unsigned int length = signature->utf8_length();
5297   const char* nextp;
5298 

5435   }
5436 }
5437 
5438 InstanceKlass* ClassFileParser::create_instance_klass(bool changed_by_loadhook,
5439                                                       const ClassInstanceInfo& cl_inst_info,
5440                                                       TRAPS) {
5441   if (_klass != nullptr) {
5442     return _klass;
5443   }
5444 
5445   InstanceKlass* const ik =
5446     InstanceKlass::allocate_instance_klass(*this, CHECK_NULL);
5447 
5448   if (is_hidden()) {
5449     mangle_hidden_class_name(ik);
5450   }
5451 
5452   fill_instance_klass(ik, changed_by_loadhook, cl_inst_info, CHECK_NULL);
5453 
5454   assert(_klass == ik, "invariant");

5455   return ik;
5456 }
5457 
5458 void ClassFileParser::fill_instance_klass(InstanceKlass* ik,
5459                                           bool changed_by_loadhook,
5460                                           const ClassInstanceInfo& cl_inst_info,
5461                                           TRAPS) {
5462   assert(ik != nullptr, "invariant");
5463 
5464   // Set name and CLD before adding to CLD
5465   ik->set_class_loader_data(_loader_data);
5466   ik->set_name(_class_name);
5467 
5468   // Add all classes to our internal class loader list here,
5469   // including classes in the bootstrap (null) class loader.
5470   const bool publicize = !is_internal();
5471 
5472   _loader_data->add_class(ik, publicize);
5473 
5474   set_klass_to_deallocate(ik);
5475 
5476   assert(_field_info != nullptr, "invariant");
5477   assert(ik->static_field_size() == _field_info->_static_field_size, "sanity");
5478   assert(ik->nonstatic_oop_map_count() == _field_info->oop_map_blocks->_nonstatic_oop_map_count,
5479          "sanity");
5480 
5481   assert(ik->is_instance_klass(), "sanity");
5482   assert(ik->size_helper() == _field_info->_instance_size, "sanity");
5483 
5484   // Fill in information already parsed
5485   ik->set_should_verify_class(_need_verify);
5486 
5487   // Not yet: supers are done below to support the new subtype-checking fields
5488   ik->set_nonstatic_field_size(_field_info->_nonstatic_field_size);
5489   ik->set_has_nonstatic_fields(_field_info->_has_nonstatic_fields);
5490   if (_field_info->_is_naturally_atomic && ik->is_inline_klass()) {
5491     ik->set_is_naturally_atomic();
5492   }
5493 
5494   assert(_fac != nullptr, "invariant");
5495   ik->set_static_oop_field_count(_fac->count[STATIC_OOP] + _fac->count[STATIC_INLINE]);
5496 
5497   // this transfers ownership of a lot of arrays from
5498   // the parser onto the InstanceKlass*
5499   apply_parsed_class_metadata(ik, _java_fields_count);
5500   if (ik->is_inline_klass()) {
5501     InlineKlass::cast(ik)->init_fixed_block();
5502   }
5503 
5504   // can only set dynamic nest-host after static nest information is set
5505   if (cl_inst_info.dynamic_nest_host() != nullptr) {
5506     ik->set_nest_host(cl_inst_info.dynamic_nest_host());
5507   }
5508 
5509   // note that is not safe to use the fields in the parser from this point on
5510   assert(nullptr == _cp, "invariant");
5511   assert(nullptr == _fieldinfo_stream, "invariant");
5512   assert(nullptr == _fields_status, "invariant");
5513   assert(nullptr == _methods, "invariant");
5514   assert(nullptr == _inner_classes, "invariant");
5515   assert(nullptr == _nest_members, "invariant");
5516   assert(nullptr == _preload_classes, "invariant");
5517   assert(nullptr == _combined_annotations, "invariant");
5518   assert(nullptr == _record_components, "invariant");
5519   assert(nullptr == _permitted_subclasses, "invariant");
5520 
5521   if (_has_localvariable_table) {
5522     ik->set_has_localvariable_table(true);
5523   }
5524 
5525   if (_has_final_method) {
5526     ik->set_has_final_method();
5527   }
5528 
5529   ik->copy_method_ordering(_method_ordering, CHECK);
5530   // The InstanceKlass::_methods_jmethod_ids cache
5531   // is managed on the assumption that the initial cache
5532   // size is equal to the number of methods in the class. If
5533   // that changes, then InstanceKlass::idnum_can_increment()
5534   // has to be changed accordingly.
5535   ik->set_initial_method_idnum(checked_cast<u2>(ik->methods()->length()));
5536 
5537   ik->set_this_class_index(_this_class_index);
5538 
5539   if (_is_hidden) {
5540     // _this_class_index is a CONSTANT_Class entry that refers to this
5541     // hidden class itself. If this class needs to refer to its own methods
5542     // or fields, it would use a CONSTANT_MethodRef, etc, which would reference
5543     // _this_class_index. However, because this class is hidden (it's
5544     // not stored in SystemDictionary), _this_class_index cannot be resolved
5545     // with ConstantPool::klass_at_impl, which does a SystemDictionary lookup.
5546     // Therefore, we must eagerly resolve _this_class_index now.
5547     ik->constants()->klass_at_put(_this_class_index, ik);
5548   }
5549 
5550   ik->set_minor_version(_minor_version);
5551   ik->set_major_version(_major_version);
5552   ik->set_has_nonstatic_concrete_methods(_has_nonstatic_concrete_methods);
5553   ik->set_declares_nonstatic_concrete_methods(_declares_nonstatic_concrete_methods);
5554 
5555   if (_must_be_atomic) {
5556     ik->set_must_be_atomic();
5557   }
5558   if (_is_implicitly_constructible) {
5559     ik->set_is_implicitly_constructible();
5560   }
5561   if (_is_hidden) {
5562     ik->set_is_hidden();
5563   }
5564 
5565   // Set PackageEntry for this_klass
5566   oop cl = ik->class_loader();
5567   Handle clh = Handle(THREAD, java_lang_ClassLoader::non_reflection_class_loader(cl));
5568   ClassLoaderData* cld = ClassLoaderData::class_loader_data_or_null(clh());
5569   ik->set_package(cld, nullptr, CHECK);
5570 
5571   const Array<Method*>* const methods = ik->methods();
5572   assert(methods != nullptr, "invariant");
5573   const int methods_len = methods->length();
5574 
5575   check_methods_for_intrinsics(ik, methods);
5576 
5577   // Fill in field values obtained by parse_classfile_attributes
5578   if (_parsed_annotations->has_any_annotations()) {
5579     _parsed_annotations->apply_to(ik);
5580   }

5647 
5648   assert(_all_mirandas != nullptr, "invariant");
5649 
5650   // Generate any default methods - default methods are public interface methods
5651   // that have a default implementation.  This is new with Java 8.
5652   if (_has_nonstatic_concrete_methods) {
5653     DefaultMethods::generate_default_methods(ik,
5654                                              _all_mirandas,
5655                                              CHECK);
5656   }
5657 
5658   // Add read edges to the unnamed modules of the bootstrap and app class loaders.
5659   if (changed_by_loadhook && !module_handle.is_null() && module_entry->is_named() &&
5660       !module_entry->has_default_read_edges()) {
5661     if (!module_entry->set_has_default_read_edges()) {
5662       // We won a potential race
5663       JvmtiExport::add_default_read_edges(module_handle, THREAD);
5664     }
5665   }
5666 
5667   bool all_fields_empty = true;
5668   for (AllFieldStream fs(ik); !fs.done(); fs.next()) {
5669     if (!fs.access_flags().is_static()) {
5670       if (fs.field_descriptor().is_null_free_inline_type()) {
5671         Klass* k = _inline_type_field_klasses->at(fs.index());
5672         ik->set_inline_type_field_klass(fs.index(), k);
5673         if (!InlineKlass::cast(k)->is_empty_inline_type()) { all_fields_empty = false; }
5674       } else {
5675         all_fields_empty = false;
5676       }
5677     } else if (is_inline_type() && (fs.name() == vmSymbols::default_value_name())) {
5678       InlineKlass::cast(ik)->set_default_value_offset(ik->field_offset(fs.index()));
5679     }
5680   }
5681 
5682   if (_is_empty_inline_type || (is_inline_type() && all_fields_empty)) {
5683     ik->set_is_empty_inline_type();
5684   }
5685 
5686   if (is_inline_type()) {
5687     InlineKlass* vk = InlineKlass::cast(ik);
5688     vk->set_alignment(_alignment);
5689     vk->set_first_field_offset(_first_field_offset);
5690     vk->set_exact_size_in_bytes(_exact_size_in_bytes);
5691     InlineKlass::cast(ik)->initialize_calling_convention(CHECK);
5692   }
5693 
5694   ClassLoadingService::notify_class_loaded(ik, false /* not shared class */);
5695 
5696   if (!is_internal()) {
5697     ik->print_class_load_logging(_loader_data, module_entry, _stream);
5698 
5699     if (ik->minor_version() == JAVA_PREVIEW_MINOR_VERSION &&
5700         ik->major_version() == JVM_CLASSFILE_MAJOR_VERSION &&
5701         log_is_enabled(Info, class, preview)) {
5702       ResourceMark rm;
5703       log_info(class, preview)("Loading class %s that depends on preview features (class file version %d.65535)",
5704                                ik->external_name(), JVM_CLASSFILE_MAJOR_VERSION);
5705     }
5706 
5707     if (log_is_enabled(Debug, class, resolve))  {
5708       ResourceMark rm;
5709       // print out the superclass.
5710       const char * from = ik->external_name();
5711       if (ik->java_super() != nullptr) {
5712         log_debug(class, resolve)("%s %s (super)",
5713                    from,

5765                                  Symbol* name,
5766                                  ClassLoaderData* loader_data,
5767                                  const ClassLoadInfo* cl_info,
5768                                  Publicity pub_level,
5769                                  TRAPS) :
5770   _stream(stream),
5771   _class_name(nullptr),
5772   _loader_data(loader_data),
5773   _is_hidden(cl_info->is_hidden()),
5774   _can_access_vm_annotations(cl_info->can_access_vm_annotations()),
5775   _orig_cp_size(0),
5776   _super_klass(),
5777   _cp(nullptr),
5778   _fieldinfo_stream(nullptr),
5779   _fields_status(nullptr),
5780   _methods(nullptr),
5781   _inner_classes(nullptr),
5782   _nest_members(nullptr),
5783   _nest_host(0),
5784   _permitted_subclasses(nullptr),
5785   _preload_classes(nullptr),
5786   _record_components(nullptr),
5787   _local_interfaces(nullptr),
5788   _local_interface_indexes(nullptr),
5789   _transitive_interfaces(nullptr),
5790   _combined_annotations(nullptr),
5791   _class_annotations(nullptr),
5792   _class_type_annotations(nullptr),
5793   _fields_annotations(nullptr),
5794   _fields_type_annotations(nullptr),
5795   _klass(nullptr),
5796   _klass_to_deallocate(nullptr),
5797   _parsed_annotations(nullptr),
5798   _fac(nullptr),
5799   _field_info(nullptr),
5800   _inline_type_field_klasses(nullptr),
5801   _temp_field_info(nullptr),
5802   _method_ordering(nullptr),
5803   _all_mirandas(nullptr),
5804   _vtable_size(0),
5805   _itable_size(0),
5806   _num_miranda_methods(0),
5807   _protection_domain(cl_info->protection_domain()),
5808   _access_flags(),
5809   _pub_level(pub_level),
5810   _bad_constant_seen(0),
5811   _synthetic_flag(false),
5812   _sde_length(false),
5813   _sde_buffer(nullptr),
5814   _sourcefile_index(0),
5815   _generic_signature_index(0),
5816   _major_version(0),
5817   _minor_version(0),
5818   _this_class_index(0),
5819   _super_class_index(0),
5820   _itfs_len(0),
5821   _java_fields_count(0),
5822   _need_verify(false),
5823   _relax_verify(false),
5824   _has_nonstatic_concrete_methods(false),
5825   _declares_nonstatic_concrete_methods(false),
5826   _has_localvariable_table(false),
5827   _has_final_method(false),
5828   _has_contended_fields(false),
5829   _has_inline_type_fields(false),
5830   _has_nonstatic_fields(false),
5831   _is_empty_inline_type(false),
5832   _is_naturally_atomic(false),
5833   _must_be_atomic(true),
5834   _is_implicitly_constructible(false),
5835   _has_loosely_consistent_annotation(false),
5836   _has_implicitly_constructible_annotation(false),
5837   _has_finalizer(false),
5838   _has_empty_finalizer(false),
5839   _has_vanilla_constructor(false),
5840   _max_bootstrap_specifier_index(-1) {
5841 
5842   _class_name = name != nullptr ? name : vmSymbols::unknown_class_name();
5843   _class_name->increment_refcount();
5844 
5845   assert(_loader_data != nullptr, "invariant");
5846   assert(stream != nullptr, "invariant");
5847   assert(_stream != nullptr, "invariant");
5848   assert(_stream->buffer() == _stream->current(), "invariant");
5849   assert(_class_name != nullptr, "invariant");
5850   assert(0 == _access_flags.as_int(), "invariant");
5851 
5852   // Figure out whether we can skip format checking (matching classic VM behavior)
5853   if (CDSConfig::is_dumping_static_archive()) {
5854     // verify == true means it's a 'remote' class (i.e., non-boot class)
5855     // Verification decision is based on BytecodeVerificationRemote flag
5856     // for those classes.

5867 
5868   // Check if verification needs to be relaxed for this class file
5869   // Do not restrict it to jdk1.0 or jdk1.1 to maintain backward compatibility (4982376)
5870   _relax_verify = relax_format_check_for(_loader_data);
5871 
5872   parse_stream(stream, CHECK);
5873 
5874   post_process_parsed_stream(stream, _cp, CHECK);
5875 }
5876 
5877 void ClassFileParser::clear_class_metadata() {
5878   // metadata created before the instance klass is created.  Must be
5879   // deallocated if classfile parsing returns an error.
5880   _cp = nullptr;
5881   _fieldinfo_stream = nullptr;
5882   _fields_status = nullptr;
5883   _methods = nullptr;
5884   _inner_classes = nullptr;
5885   _nest_members = nullptr;
5886   _permitted_subclasses = nullptr;
5887   _preload_classes = nullptr;
5888   _combined_annotations = nullptr;
5889   _class_annotations = _class_type_annotations = nullptr;
5890   _fields_annotations = _fields_type_annotations = nullptr;
5891   _record_components = nullptr;
5892 }
5893 
5894 // Destructor to clean up
5895 ClassFileParser::~ClassFileParser() {
5896   _class_name->decrement_refcount();
5897 
5898   if (_cp != nullptr) {
5899     MetadataFactory::free_metadata(_loader_data, _cp);
5900   }
5901 
5902   if (_fieldinfo_stream != nullptr) {
5903     MetadataFactory::free_array<u1>(_loader_data, _fieldinfo_stream);
5904   }
5905 
5906   if (_fields_status != nullptr) {
5907     MetadataFactory::free_array<FieldStatus>(_loader_data, _fields_status);
5908   }
5909 
5910   if (_inline_type_field_klasses != nullptr) {
5911      MetadataFactory::free_array<InlineKlass*>(_loader_data, _inline_type_field_klasses);
5912   }
5913 
5914   if (_methods != nullptr) {
5915     // Free methods
5916     InstanceKlass::deallocate_methods(_loader_data, _methods);
5917   }
5918 
5919   // beware of the Universe::empty_blah_array!!
5920   if (_inner_classes != nullptr && _inner_classes != Universe::the_empty_short_array()) {
5921     MetadataFactory::free_array<u2>(_loader_data, _inner_classes);
5922   }
5923 
5924   if (_nest_members != nullptr && _nest_members != Universe::the_empty_short_array()) {
5925     MetadataFactory::free_array<u2>(_loader_data, _nest_members);
5926   }
5927 
5928   if (_record_components != nullptr) {
5929     InstanceKlass::deallocate_record_components(_loader_data, _record_components);
5930   }
5931 
5932   if (_permitted_subclasses != nullptr && _permitted_subclasses != Universe::the_empty_short_array()) {
5933     MetadataFactory::free_array<u2>(_loader_data, _permitted_subclasses);
5934   }
5935 
5936   if (_preload_classes != nullptr && _preload_classes != Universe::the_empty_short_array()) {
5937     MetadataFactory::free_array<u2>(_loader_data, _preload_classes);
5938   }
5939 
5940   // Free interfaces
5941   InstanceKlass::deallocate_interfaces(_loader_data, _super_klass,
5942                                        _local_interfaces, _transitive_interfaces);
5943 
5944   if (_combined_annotations != nullptr) {
5945     // After all annotations arrays have been created, they are installed into the
5946     // Annotations object that will be assigned to the InstanceKlass being created.
5947 
5948     // Deallocate the Annotations object and the installed annotations arrays.
5949     _combined_annotations->deallocate_contents(_loader_data);
5950 
5951     // If the _combined_annotations pointer is non-null,
5952     // then the other annotations fields should have been cleared.
5953     assert(_class_annotations       == nullptr, "Should have been cleared");
5954     assert(_class_type_annotations  == nullptr, "Should have been cleared");
5955     assert(_fields_annotations      == nullptr, "Should have been cleared");
5956     assert(_fields_type_annotations == nullptr, "Should have been cleared");
5957   } else {
5958     // If the annotations arrays were not installed into the Annotations object,
5959     // then they have to be deallocated explicitly.

6004     cp_size, CHECK);
6005 
6006   _orig_cp_size = cp_size;
6007   if (is_hidden()) { // Add a slot for hidden class name.
6008     cp_size++;
6009   }
6010 
6011   _cp = ConstantPool::allocate(_loader_data,
6012                                cp_size,
6013                                CHECK);
6014 
6015   ConstantPool* const cp = _cp;
6016 
6017   parse_constant_pool(stream, cp, _orig_cp_size, CHECK);
6018 
6019   assert(cp_size == (u2)cp->length(), "invariant");
6020 
6021   // ACCESS FLAGS
6022   stream->guarantee_more(8, CHECK);  // flags, this_class, super_class, infs_len
6023 
6024   jint recognized_modifiers = JVM_RECOGNIZED_CLASS_MODIFIERS;

6025   // JVM_ACC_MODULE is defined in JDK-9 and later.
6026   if (_major_version >= JAVA_9_VERSION) {
6027     recognized_modifiers |= JVM_ACC_MODULE;


6028   }
6029 
6030   // Access flags
6031   jint flags = stream->get_u2_fast() & recognized_modifiers;
6032 
6033   if ((flags & JVM_ACC_INTERFACE) && _major_version < JAVA_6_VERSION) {
6034     // Set abstract bit for old class files for backward compatibility
6035     flags |= JVM_ACC_ABSTRACT;
6036   }
6037 












6038   // This class and superclass
6039   _this_class_index = stream->get_u2_fast();
6040   check_property(
6041     valid_cp_range(_this_class_index, cp_size) &&
6042       cp->tag_at(_this_class_index).is_unresolved_klass(),
6043     "Invalid this class index %u in constant pool in class file %s",
6044     _this_class_index, CHECK);
6045 
6046   Symbol* const class_name_in_cp = cp->klass_name_at(_this_class_index);
6047   assert(class_name_in_cp != nullptr, "class_name can't be null");
6048 
6049   bool is_java_lang_Object = class_name_in_cp == vmSymbols::java_lang_Object();
6050 
6051   verify_legal_class_modifiers(flags, nullptr, is_java_lang_Object, CHECK);
6052 
6053   if (EnableValhalla) {
6054     if(!supports_inline_types()) {
6055       const bool is_module = (flags & JVM_ACC_MODULE) != 0;
6056       const bool is_interface = (flags & JVM_ACC_INTERFACE) != 0;
6057       if (!is_module && !is_interface && !is_java_lang_Object) {
6058         flags |= JVM_ACC_IDENTITY;
6059       }
6060     }
6061   }
6062 
6063   _access_flags.set_flags(flags);
6064 
6065   short bad_constant = class_bad_constant_seen();
6066   if (bad_constant != 0) {
6067     // Do not throw CFE until after the access_flags are checked because if
6068     // ACC_MODULE is set in the access flags, then NCDFE must be thrown, not CFE.
6069     classfile_parse_error("Unknown constant tag %u in class file %s", bad_constant, THREAD);
6070     return;
6071   }
6072 
6073   // Don't need to check whether this class name is legal or not.
6074   // It has been checked when constant pool is parsed.
6075   // However, make sure it is not an array type.
6076   if (_need_verify) {
6077     guarantee_property(class_name_in_cp->char_at(0) != JVM_SIGNATURE_ARRAY,
6078                        "Bad class name in class file %s",
6079                        CHECK);
6080   }
6081 
6082 #ifdef ASSERT
6083   // Basic sanity checks
6084   if (_is_hidden) {
6085     assert(_class_name != vmSymbols::unknown_class_name(), "hidden classes should have a special name");
6086   }
6087 #endif
6088 
6089   // Update the _class_name as needed depending on whether this is a named, un-named, or hidden class.
6090 
6091   if (_is_hidden) {
6092     assert(_class_name != nullptr, "Unexpected null _class_name");

6132       }
6133       ls.cr();
6134     }
6135   }
6136 
6137   // SUPERKLASS
6138   _super_class_index = stream->get_u2_fast();
6139   _super_klass = parse_super_class(cp,
6140                                    _super_class_index,
6141                                    _need_verify,
6142                                    CHECK);
6143 
6144   // Interfaces
6145   _itfs_len = stream->get_u2_fast();
6146   parse_interfaces(stream,
6147                    _itfs_len,
6148                    cp,
6149                    &_has_nonstatic_concrete_methods,
6150                    CHECK);
6151 


6152   // Fields (offsets are filled in later)
6153   _fac = new FieldAllocationCount();
6154   parse_fields(stream,
6155                _access_flags,
6156                _fac,
6157                cp,
6158                cp_size,
6159                &_java_fields_count,
6160                CHECK);
6161 
6162   assert(_temp_field_info != nullptr, "invariant");
6163 
6164   // Methods
6165   parse_methods(stream,
6166                 is_interface(),
6167                 !is_identity_class(),
6168                 is_abstract_class(),
6169                 &_has_localvariable_table,
6170                 &_has_final_method,
6171                 &_declares_nonstatic_concrete_methods,
6172                 CHECK);
6173 
6174   assert(_methods != nullptr, "invariant");
6175 
6176   if (_declares_nonstatic_concrete_methods) {
6177     _has_nonstatic_concrete_methods = true;
6178   }
6179 
6180   // Additional attributes/annotations
6181   _parsed_annotations = new ClassAnnotationCollector();
6182   parse_classfile_attributes(stream, cp, _parsed_annotations, CHECK);
6183 
6184   assert(_inner_classes != nullptr, "invariant");
6185 
6186   // Finalize the Annotations metadata object,
6187   // now that all annotation arrays have been created.
6188   create_combined_annotations(CHECK);

6228   // Update this_class_index's slot in the constant pool with the new Utf8 entry.
6229   // We have to update the resolved_klass_index and the name_index together
6230   // so extract the existing resolved_klass_index first.
6231   CPKlassSlot cp_klass_slot = _cp->klass_slot_at(_this_class_index);
6232   int resolved_klass_index = cp_klass_slot.resolved_klass_index();
6233   _cp->unresolved_klass_at_put(_this_class_index, hidden_index, resolved_klass_index);
6234   assert(_cp->klass_slot_at(_this_class_index).name_index() == _orig_cp_size,
6235          "Bad name_index");
6236 }
6237 
6238 void ClassFileParser::post_process_parsed_stream(const ClassFileStream* const stream,
6239                                                  ConstantPool* cp,
6240                                                  TRAPS) {
6241   assert(stream != nullptr, "invariant");
6242   assert(stream->at_eos(), "invariant");
6243   assert(cp != nullptr, "invariant");
6244   assert(_loader_data != nullptr, "invariant");
6245 
6246   if (_class_name == vmSymbols::java_lang_Object()) {
6247     check_property(_local_interfaces == Universe::the_empty_instance_klass_array(),
6248         "java.lang.Object cannot implement an interface in class file %s",
6249         CHECK);
6250   }
6251   // We check super class after class file is parsed and format is checked
6252   if (_super_class_index > 0 && nullptr == _super_klass) {
6253     Symbol* const super_class_name = cp->klass_name_at(_super_class_index);
6254     if (is_interface()) {
6255       // Before attempting to resolve the superclass, check for class format
6256       // errors not checked yet.
6257       guarantee_property(super_class_name == vmSymbols::java_lang_Object(),
6258         "Interfaces must have java.lang.Object as superclass in class file %s",
6259         CHECK);
6260     }
6261     Handle loader(THREAD, _loader_data->class_loader());
6262     if (loader.is_null() && super_class_name == vmSymbols::java_lang_Object()) {
6263       _super_klass = vmClasses::Object_klass();
6264     } else {
6265       _super_klass = (const InstanceKlass*)
6266                        SystemDictionary::resolve_super_or_fail(_class_name,
6267                                                                super_class_name,
6268                                                                loader,
6269                                                                _protection_domain,
6270                                                                true,
6271                                                                CHECK);
6272     }
6273   }
6274 
6275   if (_super_klass != nullptr) {
6276     if (_super_klass->is_interface()) {
6277       classfile_icce_error("class %s has interface %s as super class", _super_klass, THREAD);
6278       return;
6279     }
6280 
6281     if (EnableValhalla) {
6282       check_identity_and_value_modifiers(this, _super_klass, CHECK);
6283     }
6284 
6285     if (_super_klass->has_nonstatic_concrete_methods()) {
6286       _has_nonstatic_concrete_methods = true;
6287     }
6288 
6289     if (EnableValhalla && !_access_flags.is_identity_class()) {
6290       const InstanceKlass* k = _super_klass;
6291       int inherited_instance_fields = 0;
6292       while (k != nullptr) {
6293         for (AllFieldStream fs(k); !fs.done(); fs.next()) {
6294           if (!fs.access_flags().is_static()) inherited_instance_fields++;
6295         }
6296         k = k->super() == nullptr ? nullptr :  InstanceKlass::cast(k->super());
6297       }
6298       if (inherited_instance_fields > 0) {
6299         THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), "Value classes don't support inherited non-static fields yet");
6300       }
6301     }
6302   }
6303 
6304   if (_parsed_annotations->has_annotation(AnnotationCollector::_jdk_internal_LooselyConsistentValue) && _access_flags.is_identity_class()) {
6305     THROW_MSG(vmSymbols::java_lang_ClassFormatError(),
6306           err_msg("class %s cannot have annotation jdk.internal.vm.annotation.LooselyConsistentValue, because it is not a value class",
6307                   _class_name->as_klass_external_name()));
6308   }
6309   if (_parsed_annotations->has_annotation(AnnotationCollector::_jdk_internal_ImplicitlyConstructible) && _access_flags.is_identity_class()) {
6310     THROW_MSG(vmSymbols::java_lang_ClassFormatError(),
6311           err_msg("class %s cannot have annotation jdk.internal.vm.annotation.ImplicitlyConstructible, because it is not a value class",
6312                   _class_name->as_klass_external_name()));
6313   }
6314 
6315   // Determining is the class allows tearing or not (default is not)
6316   // Test might need extensions when field inheritance is added for value classes
6317   if (EnableValhalla && !_access_flags.is_identity_class()) {
6318     if (_super_klass != nullptr  // not j.l.Object
6319               && _parsed_annotations->has_annotation(ClassAnnotationCollector::_jdk_internal_LooselyConsistentValue)
6320               && (_super_klass == vmClasses::Object_klass() || !_super_klass->must_be_atomic())) {
6321       _must_be_atomic = false;
6322     }
6323     if (_parsed_annotations->has_annotation(ClassAnnotationCollector::_jdk_internal_ImplicitlyConstructible)) {
6324       _is_implicitly_constructible = true;
6325     }
6326     // Apply VM options override
6327     if (*ForceNonTearable != '\0') {
6328       // Allow a command line switch to force the same atomicity property:
6329       const char* class_name_str = _class_name->as_C_string();
6330       if (StringUtils::class_list_match(ForceNonTearable, class_name_str)) {
6331         _must_be_atomic = true;
6332       }
6333     }
6334   }
6335 
6336   int itfs_len = _local_interface_indexes == nullptr ? 0 : _local_interface_indexes->length();
6337   _local_interfaces = MetadataFactory::new_array<InstanceKlass*>(_loader_data, itfs_len, nullptr, CHECK);
6338   if (_local_interface_indexes != nullptr) {
6339     for (int i = 0; i < _local_interface_indexes->length(); i++) {
6340       u2 interface_index = _local_interface_indexes->at(i);
6341       Klass* interf;
6342       if (cp->tag_at(interface_index).is_klass()) {
6343         interf = cp->resolved_klass_at(interface_index);
6344       } else {
6345         Symbol* const unresolved_klass  = cp->klass_name_at(interface_index);
6346 
6347         // Don't need to check legal name because it's checked when parsing constant pool.
6348         // But need to make sure it's not an array type.
6349         guarantee_property(unresolved_klass->char_at(0) != JVM_SIGNATURE_ARRAY,
6350                             "Bad interface name in class file %s", CHECK);
6351 
6352         // Call resolve_super so class circularity is checked
6353         interf = SystemDictionary::resolve_super_or_fail(
6354                                                   _class_name,
6355                                                   unresolved_klass,
6356                                                   Handle(THREAD, _loader_data->class_loader()),
6357                                                   _protection_domain,
6358                                                   false,
6359                                                   CHECK);
6360       }
6361 
6362       if (!interf->is_interface()) {
6363         THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(),
6364                   err_msg("class %s can not implement %s, because it is not an interface (%s)",
6365                           _class_name->as_klass_external_name(),
6366                           interf->external_name(),
6367                           interf->class_in_module_of_loader()));
6368       }
6369 
6370       if (EnableValhalla) {
6371         // Check modifiers and set carries_identity_modifier/carries_value_modifier flags
6372         check_identity_and_value_modifiers(this, InstanceKlass::cast(interf), CHECK);
6373       }
6374 
6375       if (InstanceKlass::cast(interf)->has_nonstatic_concrete_methods()) {
6376         _has_nonstatic_concrete_methods = true;
6377       }
6378       _local_interfaces->at_put(i, InstanceKlass::cast(interf));
6379     }
6380   }
6381   assert(_local_interfaces != nullptr, "invariant");
6382 
6383   // Compute the transitive list of all unique interfaces implemented by this class
6384   _transitive_interfaces =
6385     compute_transitive_interfaces(_super_klass,
6386                                   _local_interfaces,
6387                                   _loader_data,
6388                                   CHECK);
6389 
6390   assert(_transitive_interfaces != nullptr, "invariant");
6391 
6392   // sort methods
6393   _method_ordering = sort_methods(_methods);
6394 
6395   _all_mirandas = new GrowableArray<Method*>(20);
6396 
6397   Handle loader(THREAD, _loader_data->class_loader());
6398   klassVtable::compute_vtable_size_and_num_mirandas(&_vtable_size,
6399                                                     &_num_miranda_methods,
6400                                                     _all_mirandas,
6401                                                     _super_klass,
6402                                                     _methods,
6403                                                     _access_flags,
6404                                                     _major_version,
6405                                                     loader,
6406                                                     _class_name,
6407                                                     _local_interfaces);
6408 
6409   // Size of Java itable (in words)
6410   _itable_size = is_interface() ? 0 :
6411     klassItable::compute_itable_size(_transitive_interfaces);
6412 
6413   assert(_fac != nullptr, "invariant");
6414   assert(_parsed_annotations != nullptr, "invariant");
6415 
6416   if (EnableValhalla) {
6417     _inline_type_field_klasses = MetadataFactory::new_array<InlineKlass*>(_loader_data,
6418                                                    java_fields_count(),
6419                                                    nullptr,
6420                                                    CHECK);
6421     for (GrowableArrayIterator<FieldInfo> it = _temp_field_info->begin(); it != _temp_field_info->end(); ++it) {
6422       FieldInfo fieldinfo = *it;
6423       Symbol* sig = fieldinfo.signature(cp);
6424       if (fieldinfo.field_flags().is_null_free_inline_type() && !fieldinfo.access_flags().is_static()) {
6425         // Pre-load classes of fields that are candidate for flattening
6426         Klass* klass = SystemDictionary::resolve_inline_type_field_or_fail(sig,
6427             Handle(THREAD, _loader_data->class_loader()),
6428             _protection_domain, true, CHECK);
6429         assert(klass != nullptr, "Sanity check");
6430         if (klass->access_flags().is_identity_class()) {
6431           assert(klass->is_instance_klass(), "Sanity check");
6432           ResourceMark rm(THREAD);
6433           THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(),
6434                     err_msg("Class %s expects class %s to be concrete value type, but it is an identity class",
6435                     _class_name->as_C_string(),
6436                     InstanceKlass::cast(klass)->external_name()));
6437         }
6438         if (klass->is_abstract()) {
6439           assert(klass->is_instance_klass(), "Sanity check");
6440           ResourceMark rm(THREAD);
6441           THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(),
6442                     err_msg("Class %s expects class %s to be concrete value type, but it is an abstract class",
6443                     _class_name->as_C_string(),
6444                     InstanceKlass::cast(klass)->external_name()));
6445         }
6446         InlineKlass* vk = InlineKlass::cast(klass);
6447         if (!vk->is_implicitly_constructible()) {
6448           ResourceMark rm(THREAD);
6449           THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(),
6450                     err_msg("Class %s expects class %s to be implicitly constructible, but it is not",
6451                     _class_name->as_C_string(),
6452                     InstanceKlass::cast(klass)->external_name()));
6453         }
6454         _inline_type_field_klasses->at_put(fieldinfo.index(), InlineKlass::cast(klass));
6455       } else {
6456         if (sig != _class_name && is_class_in_preload_attribute(sig)) {
6457           oop loader = loader_data()->class_loader();
6458           Klass* klass = SystemDictionary::resolve_or_null(sig, Handle(THREAD, loader), _protection_domain, THREAD);
6459           if (HAS_PENDING_EXCEPTION) {
6460             CLEAR_PENDING_EXCEPTION;
6461           }
6462           // Should we verify that klass is a value class? What the PreLoad attribute spec says about that?
6463           if (klass != nullptr) {
6464             if (klass->is_inline_klass()) {
6465               _inline_type_field_klasses->at_put(fieldinfo.index(), InlineKlass::cast(klass));
6466               log_info(class, preload)("Preloading class %s during linking of class %s because of its Preload attribute", sig->as_C_string(), _class_name->as_C_string());
6467             } else {
6468               log_info(class, preload)("Preloading class %s during linking of class %s because of its Preload attribute but loaded class is not a value class", sig->as_C_string(), _class_name->as_C_string());
6469             }
6470           } else {
6471             log_warning(class, preload)("Preloading of class %s during linking of class %s (Preload attribute) failed", sig->as_C_string(), _class_name->as_C_string());
6472           }
6473         }
6474       }
6475     }
6476   }
6477 
6478   _field_info = new FieldLayoutInfo();
6479   FieldLayoutBuilder lb(class_name(), super_klass(), _cp, /*_fields*/ _temp_field_info,
6480       _parsed_annotations->is_contended(), is_inline_type(),
6481       _field_info, _inline_type_field_klasses);
6482   lb.build_layout(CHECK);
6483   if (is_inline_type()) {
6484     _alignment = lb.get_alignment();
6485     _first_field_offset = lb.get_first_field_offset();
6486     _exact_size_in_bytes = lb.get_exact_size_in_byte();
6487   }
6488   _has_inline_type_fields = _field_info->_has_inline_fields;
6489 
6490   int injected_fields_count = _temp_field_info->length() - _java_fields_count;
6491   _fieldinfo_stream =
6492     FieldInfoStream::create_FieldInfoStream(_temp_field_info, _java_fields_count,
6493                                             injected_fields_count, loader_data(), CHECK);
6494   _fields_status =
6495     MetadataFactory::new_array<FieldStatus>(_loader_data, _temp_field_info->length(),
6496                                             FieldStatus(0), CHECK);
6497 }
6498 
6499 void ClassFileParser::set_klass(InstanceKlass* klass) {
6500 
6501 #ifdef ASSERT
6502   if (klass != nullptr) {
6503     assert(nullptr == _klass, "leaking?");
6504   }
6505 #endif
6506 
6507   _klass = klass;
6508 }
< prev index next >