< prev index next >

src/hotspot/share/classfile/classFileParser.cpp

Print this page


   1 /*
   2  * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   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  *


 139   // Used for batching symbol allocations.
 140   const char* names[SymbolTable::symbol_alloc_batch_size];
 141   int lengths[SymbolTable::symbol_alloc_batch_size];
 142   int indices[SymbolTable::symbol_alloc_batch_size];
 143   unsigned int hashValues[SymbolTable::symbol_alloc_batch_size];
 144   int names_count = 0;
 145 
 146   // parsing  Index 0 is unused
 147   for (int index = 1; index < length; index++) {
 148     // Each of the following case guarantees one more byte in the stream
 149     // for the following tag or the access_flags following constant pool,
 150     // so we don't need bounds-check for reading tag.
 151     const u1 tag = cfs->get_u1_fast();
 152     switch (tag) {
 153       case JVM_CONSTANT_Class: {
 154         cfs->guarantee_more(3, CHECK);  // name_index, tag/access_flags
 155         const u2 name_index = cfs->get_u2_fast();
 156         cp->klass_index_at_put(index, name_index);
 157         break;
 158       }
 159       case JVM_CONSTANT_Value: {  // may be present in a retransform situation
 160         cfs->guarantee_more(3, CHECK);  // name_index, tag/access_flags
 161         const u2 name_index = cfs->get_u2_fast();
 162         cp->value_type_index_at_put(index, name_index);
 163         break;
 164       }
 165       case JVM_CONSTANT_Fieldref: {
 166         cfs->guarantee_more(5, CHECK);  // class_index, name_and_type_index, tag/access_flags
 167         const u2 class_index = cfs->get_u2_fast();
 168         const u2 name_and_type_index = cfs->get_u2_fast();
 169         cp->field_at_put(index, class_index, name_and_type_index);
 170         break;
 171       }
 172       case JVM_CONSTANT_Methodref: {
 173         cfs->guarantee_more(5, CHECK);  // class_index, name_and_type_index, tag/access_flags
 174         const u2 class_index = cfs->get_u2_fast();
 175         const u2 name_and_type_index = cfs->get_u2_fast();
 176         cp->method_at_put(index, class_index, name_and_type_index);
 177         break;
 178       }
 179       case JVM_CONSTANT_InterfaceMethodref: {
 180         cfs->guarantee_more(5, CHECK);  // class_index, name_and_type_index, tag/access_flags
 181         const u2 class_index = cfs->get_u2_fast();
 182         const u2 name_and_type_index = cfs->get_u2_fast();
 183         cp->interface_method_at_put(index, class_index, name_and_type_index);
 184         break;


 409                                          const int length,
 410                                          TRAPS) {
 411   assert(cp != NULL, "invariant");
 412   assert(stream != NULL, "invariant");
 413 
 414   // parsing constant pool entries
 415   parse_constant_pool_entries(stream, cp, length, CHECK);
 416   if (class_bad_constant_seen() != 0) {
 417     // a bad CP entry has been detected previously so stop parsing and just return.
 418     return;
 419   }
 420 
 421   int index = 1;  // declared outside of loops for portability
 422   int num_klasses = 0;
 423 
 424   // first verification pass - validate cross references
 425   // and fixup class and string constants
 426   for (index = 1; index < length; index++) {          // Index 0 is unused
 427     const jbyte tag = cp->tag_at(index).value();
 428     switch (tag) {
 429       case JVM_CONSTANT_Class:
 430       case JVM_CONSTANT_Value: {
 431         ShouldNotReachHere();     // Only JVM_CONSTANT_[Class|Value]Index should be present
 432         break;
 433       }
 434       case JVM_CONSTANT_Fieldref:
 435         // fall through
 436       case JVM_CONSTANT_Methodref:
 437         // fall through
 438       case JVM_CONSTANT_InterfaceMethodref: {
 439         if (!_need_verify) break;
 440         const int klass_ref_index = cp->klass_ref_index_at(index);
 441         const int name_and_type_ref_index = cp->name_and_type_ref_index_at(index);
 442         check_property(valid_klass_reference_at(klass_ref_index) ||
 443                        (valid_value_type_reference_at(klass_ref_index) &&
 444                         ((EnableMVT && (tag == JVM_CONSTANT_Fieldref)) ||
 445                          EnableValhalla)),
 446                        "Invalid constant pool index %u in class file %s",
 447                        klass_ref_index, CHECK);
 448         check_property(valid_cp_range(name_and_type_ref_index, length) &&
 449           cp->tag_at(name_and_type_ref_index).is_name_and_type(),
 450           "Invalid constant pool index %u in class file %s",
 451           name_and_type_ref_index, CHECK);
 452         break;
 453       }
 454       case JVM_CONSTANT_String: {
 455         ShouldNotReachHere();     // Only JVM_CONSTANT_StringIndex should be present
 456         break;
 457       }
 458       case JVM_CONSTANT_Integer:
 459         break;
 460       case JVM_CONSTANT_Float:
 461         break;
 462       case JVM_CONSTANT_Long:
 463       case JVM_CONSTANT_Double: {
 464         index++;
 465         check_property(


 482       }
 483       case JVM_CONSTANT_Utf8:
 484         break;
 485       case JVM_CONSTANT_UnresolvedClass:         // fall-through
 486       case JVM_CONSTANT_UnresolvedClassInError: {
 487         ShouldNotReachHere();     // Only JVM_CONSTANT_ClassIndex should be present
 488         break;
 489       }
 490       case JVM_CONSTANT_ClassIndex: {
 491         const int class_index = cp->klass_index_at(index);
 492         check_property(valid_symbol_at(class_index),
 493           "Invalid constant pool index %u in class file %s",
 494           class_index, CHECK);
 495 
 496         Symbol* const name = cp->symbol_at(class_index);
 497         const unsigned int name_len = name->utf8_length();
 498 
 499         cp->unresolved_klass_at_put(index, class_index, num_klasses++);
 500         break;
 501       }
 502       case JVM_CONSTANT_ValueIndex: {
 503         const int class_index = cp->value_type_index_at(index);
 504         check_property(valid_symbol_at(class_index),
 505           "Invalid constant pool index %u in class file %s",
 506           class_index, CHECK);
 507         cp->unresolved_value_type_at_put(index, class_index, num_klasses++);
 508         break;
 509       }
 510       case JVM_CONSTANT_StringIndex: {
 511         const int string_index = cp->string_index_at(index);
 512         check_property(valid_symbol_at(string_index),
 513           "Invalid constant pool index %u in class file %s",
 514           string_index, CHECK);
 515         Symbol* const sym = cp->symbol_at(string_index);
 516         cp->unresolved_string_at_put(index, sym);
 517         break;
 518       }
 519       case JVM_CONSTANT_MethodHandle: {
 520         const int ref_index = cp->method_handle_index_at(index);
 521         check_property(valid_cp_range(ref_index, length),
 522           "Invalid constant pool index %u in class file %s",
 523           ref_index, CHECK);
 524         const constantTag tag = cp->tag_at(ref_index);
 525         const int ref_kind = cp->method_handle_ref_kind_at(index);
 526 
 527         switch (ref_kind) {
 528           case JVM_REF_getField:
 529           case JVM_REF_getStatic:


 634 
 635     for (index = 1; index < length; index++) {          // Index 0 is unused
 636       if (has_cp_patch_at(index)) {
 637         guarantee_property(index != this_class_index,
 638           "Illegal constant pool patch to self at %d in class file %s",
 639           index, CHECK);
 640         patch_constant_pool(cp, index, cp_patch_at(index), CHECK);
 641       }
 642     }
 643   }
 644 
 645   if (!_need_verify) {
 646     return;
 647   }
 648 
 649   // second verification pass - checks the strings are of the right format.
 650   // but not yet to the other entries
 651   for (index = 1; index < length; index++) {
 652     const jbyte tag = cp->tag_at(index).value();
 653     switch (tag) {
 654       case JVM_CONSTANT_UnresolvedClass:
 655       case JVM_CONSTANT_UnresolvedValue: {
 656         const Symbol* const class_name = cp->klass_name_at(index);
 657         // check the name, even if _cp_patches will overwrite it
 658         verify_legal_class_name(class_name, CHECK);
 659         break;
 660       }
 661       case JVM_CONSTANT_NameAndType: {
 662         if (_need_verify) {
 663           const int sig_index = cp->signature_ref_index_at(index);
 664           const int name_index = cp->name_ref_index_at(index);
 665           const Symbol* const name = cp->symbol_at(name_index);
 666           const Symbol* const sig = cp->symbol_at(sig_index);
 667           guarantee_property(sig->utf8_length() != 0,
 668             "Illegal zero length constant pool entry at %d in class %s",
 669             sig_index, CHECK);
 670           guarantee_property(name->utf8_length() != 0,
 671             "Illegal zero length constant pool entry at %d in class %s",
 672             name_index, CHECK);
 673 
 674           if (sig->byte_at(0) == JVM_SIGNATURE_FUNC) {
 675             // Format check method name and signature


3171   // 4-tuples of shorts of inner classes data and 2 shorts of enclosing
3172   // method data:
3173   //   [inner_class_info_index,
3174   //    outer_class_info_index,
3175   //    inner_name_index,
3176   //    inner_class_access_flags,
3177   //    ...
3178   //    enclosing_method_class_index,
3179   //    enclosing_method_method_index]
3180   const int size = length * 4 + (parsed_enclosingmethod_attribute ? 2 : 0);
3181   Array<u2>* const inner_classes = MetadataFactory::new_array<u2>(_loader_data, size, CHECK_0);
3182   _inner_classes = inner_classes;
3183 
3184   int index = 0;
3185   const int cp_size = _cp->length();
3186   cfs->guarantee_more(8 * length, CHECK_0);  // 4-tuples of u2
3187   for (int n = 0; n < length; n++) {
3188     // Inner class index
3189     const u2 inner_class_info_index = cfs->get_u2_fast();
3190     check_property(
3191       (valid_klass_reference_at(inner_class_info_index) ||
3192        (EnableValhalla && valid_value_type_reference_at(inner_class_info_index))),
3193       "inner_class_info_index %u has bad constant type in class file %s",
3194       inner_class_info_index, CHECK_0);
3195     // Outer class index
3196     const u2 outer_class_info_index = cfs->get_u2_fast();
3197     check_property(
3198       outer_class_info_index == 0 ||
3199         (valid_klass_reference_at(outer_class_info_index) ||
3200          (EnableValhalla && valid_value_type_reference_at(outer_class_info_index))),
3201       "outer_class_info_index %u has bad constant type in class file %s",
3202       outer_class_info_index, CHECK_0);
3203     // Inner class name
3204     const u2 inner_name_index = cfs->get_u2_fast();
3205     check_property(
3206       inner_name_index == 0 || valid_symbol_at(inner_name_index),
3207       "inner_name_index %u has bad constant type in class file %s",
3208       inner_name_index, CHECK_0);
3209     if (_need_verify) {
3210       guarantee_property(inner_class_info_index != outer_class_info_index,
3211                          "Class is both outer and inner class in class file %s", CHECK_0);
3212     }
3213 
3214     jint recognized_modifiers = RECOGNIZED_INNER_CLASS_MODIFIERS;
3215     // JVM_ACC_MODULE is defined in JDK-9 and later.
3216     if (_major_version >= JAVA_9_VERSION) {
3217       recognized_modifiers |= JVM_ACC_MODULE;
3218     }
3219     // JVM_ACC_VALUE is defined for class file version 53.1 and later
3220     if (supports_value_types()) {


3669       }
3670     }
3671   }
3672   return annotations;
3673 }
3674 
3675 const InstanceKlass* ClassFileParser::parse_super_class(ConstantPool* const cp,
3676                                                         const int super_class_index,
3677                                                         const bool need_verify,
3678                                                         TRAPS) {
3679   assert(cp != NULL, "invariant");
3680   const InstanceKlass* super_klass = NULL;
3681 
3682   if (super_class_index == 0) {
3683     check_property(_class_name == vmSymbols::java_lang_Object()
3684                    || (_access_flags.get_flags() & JVM_ACC_VALUE),
3685                    "Invalid superclass index %u in class file %s",
3686                    super_class_index,
3687                    CHECK_NULL);
3688   } else {
3689     check_property((valid_klass_reference_at(super_class_index) ||
3690                     ((EnableValhalla || EnableMVT) && valid_value_type_reference_at(super_class_index))),
3691                    "Invalid superclass index %u in class file %s",
3692                    super_class_index,
3693                    CHECK_NULL);
3694     // The class name should be legal because it is checked when parsing constant pool.
3695     // However, make sure it is not an array type.
3696     bool is_array = false;
3697     if (cp->tag_at(super_class_index).is_klass() || cp->tag_at(super_class_index).is_value_type()) {
3698       super_klass = InstanceKlass::cast(cp->resolved_klass_at(super_class_index));
3699       if (need_verify)
3700         is_array = super_klass->is_array_klass();
3701     } else if (need_verify) {
3702       is_array = (cp->klass_name_at(super_class_index)->byte_at(0) == JVM_SIGNATURE_ARRAY);
3703     }
3704     if (need_verify) {
3705       guarantee_property(!is_array,
3706                         "Bad superclass name in class file %s", CHECK_NULL);
3707     }
3708   }
3709   return super_klass;
3710 }
3711 
3712 #ifndef PRODUCT
3713 static void print_field_layout(const Symbol* name,
3714                                Array<u2>* fields,
3715                                const constantPoolHandle& cp,
3716                                int instance_size,
3717                                int instance_fields_start,


6169 
6170   if ((flags & JVM_ACC_INTERFACE) && _major_version < JAVA_6_VERSION) {
6171     // Set abstract bit for old class files for backward compatibility
6172     flags |= JVM_ACC_ABSTRACT;
6173   }
6174 
6175   verify_legal_class_modifiers(flags, CHECK);
6176 
6177   short bad_constant = class_bad_constant_seen();
6178   if (bad_constant != 0) {
6179     // Do not throw CFE until after the access_flags are checked because if
6180     // ACC_MODULE is set in the access flags, then NCDFE must be thrown, not CFE.
6181     classfile_parse_error("Unknown constant tag %u in class file %s", bad_constant, CHECK);
6182   }
6183 
6184   _access_flags.set_flags(flags);
6185 
6186   // This class and superclass
6187   _this_class_index = stream->get_u2_fast();
6188   check_property(
6189     (valid_cp_range(_this_class_index, cp_size) &&
6190      (cp->tag_at(_this_class_index).is_unresolved_klass() ||
6191       cp->tag_at(_this_class_index).is_unresolved_value_type())),
6192     "Invalid this class index %u in constant pool in class file %s",
6193     _this_class_index, CHECK);
6194 
6195   Symbol* const class_name_in_cp = cp->klass_name_at(_this_class_index);
6196   assert(class_name_in_cp != NULL, "class_name can't be null");
6197 
6198   // Update _class_name which could be null previously
6199   // to reflect the name in the constant pool
6200   _class_name = class_name_in_cp;
6201 
6202   // Don't need to check whether this class name is legal or not.
6203   // It has been checked when constant pool is parsed.
6204   // However, make sure it is not an array type.
6205   if (_need_verify) {
6206     guarantee_property(_class_name->byte_at(0) != JVM_SIGNATURE_ARRAY,
6207                        "Bad class name in class file %s",
6208                        CHECK);
6209   }
6210 
6211   // Checks if name in class file matches requested name


6382   }
6383 
6384   if (_super_klass != NULL) {
6385     if (_super_klass->has_nonstatic_concrete_methods()) {
6386       _has_nonstatic_concrete_methods = true;
6387     }
6388 
6389     if (_super_klass->is_interface()) {
6390       ResourceMark rm(THREAD);
6391       Exceptions::fthrow(
6392         THREAD_AND_LOCATION,
6393         vmSymbols::java_lang_IncompatibleClassChangeError(),
6394         "class %s has interface %s as super class",
6395         _class_name->as_klass_external_name(),
6396         _super_klass->external_name()
6397       );
6398       return;
6399     }
6400 
6401     // For a value class, only java/lang/Object is an acceptable super class
6402     if ((EnableValhalla || EnableMVT) &&
6403         _access_flags.get_flags() & JVM_ACC_VALUE) {
6404       guarantee_property(_super_klass->name() == vmSymbols::java_lang_Object(),
6405                          "Value class can only inherit java/lang/Object",
6406                          CHECK);
6407     }
6408 
6409     // Make sure super class is not final
6410     if (_super_klass->is_final()) {
6411       THROW_MSG(vmSymbols::java_lang_VerifyError(), "Cannot inherit from final class");
6412     }
6413   }
6414 
6415   // Compute the transitive list of all unique interfaces implemented by this class
6416   _transitive_interfaces =
6417     compute_transitive_interfaces(_super_klass,
6418                                   _local_interfaces,
6419                                   _loader_data,
6420                                   CHECK);
6421 
6422   assert(_transitive_interfaces != NULL, "invariant");


   1 /*
   2  * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   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  *


 139   // Used for batching symbol allocations.
 140   const char* names[SymbolTable::symbol_alloc_batch_size];
 141   int lengths[SymbolTable::symbol_alloc_batch_size];
 142   int indices[SymbolTable::symbol_alloc_batch_size];
 143   unsigned int hashValues[SymbolTable::symbol_alloc_batch_size];
 144   int names_count = 0;
 145 
 146   // parsing  Index 0 is unused
 147   for (int index = 1; index < length; index++) {
 148     // Each of the following case guarantees one more byte in the stream
 149     // for the following tag or the access_flags following constant pool,
 150     // so we don't need bounds-check for reading tag.
 151     const u1 tag = cfs->get_u1_fast();
 152     switch (tag) {
 153       case JVM_CONSTANT_Class: {
 154         cfs->guarantee_more(3, CHECK);  // name_index, tag/access_flags
 155         const u2 name_index = cfs->get_u2_fast();
 156         cp->klass_index_at_put(index, name_index);
 157         break;
 158       }






 159       case JVM_CONSTANT_Fieldref: {
 160         cfs->guarantee_more(5, CHECK);  // class_index, name_and_type_index, tag/access_flags
 161         const u2 class_index = cfs->get_u2_fast();
 162         const u2 name_and_type_index = cfs->get_u2_fast();
 163         cp->field_at_put(index, class_index, name_and_type_index);
 164         break;
 165       }
 166       case JVM_CONSTANT_Methodref: {
 167         cfs->guarantee_more(5, CHECK);  // class_index, name_and_type_index, tag/access_flags
 168         const u2 class_index = cfs->get_u2_fast();
 169         const u2 name_and_type_index = cfs->get_u2_fast();
 170         cp->method_at_put(index, class_index, name_and_type_index);
 171         break;
 172       }
 173       case JVM_CONSTANT_InterfaceMethodref: {
 174         cfs->guarantee_more(5, CHECK);  // class_index, name_and_type_index, tag/access_flags
 175         const u2 class_index = cfs->get_u2_fast();
 176         const u2 name_and_type_index = cfs->get_u2_fast();
 177         cp->interface_method_at_put(index, class_index, name_and_type_index);
 178         break;


 403                                          const int length,
 404                                          TRAPS) {
 405   assert(cp != NULL, "invariant");
 406   assert(stream != NULL, "invariant");
 407 
 408   // parsing constant pool entries
 409   parse_constant_pool_entries(stream, cp, length, CHECK);
 410   if (class_bad_constant_seen() != 0) {
 411     // a bad CP entry has been detected previously so stop parsing and just return.
 412     return;
 413   }
 414 
 415   int index = 1;  // declared outside of loops for portability
 416   int num_klasses = 0;
 417 
 418   // first verification pass - validate cross references
 419   // and fixup class and string constants
 420   for (index = 1; index < length; index++) {          // Index 0 is unused
 421     const jbyte tag = cp->tag_at(index).value();
 422     switch (tag) {
 423       case JVM_CONSTANT_Class: {
 424         ShouldNotReachHere();     // Only JVM_CONSTANT_ClassIndex should be present

 425         break;
 426       }
 427       case JVM_CONSTANT_Fieldref:
 428         // fall through
 429       case JVM_CONSTANT_Methodref:
 430         // fall through
 431       case JVM_CONSTANT_InterfaceMethodref: {
 432         if (!_need_verify) break;
 433         const int klass_ref_index = cp->klass_ref_index_at(index);
 434         const int name_and_type_ref_index = cp->name_and_type_ref_index_at(index);
 435         check_property(valid_klass_reference_at(klass_ref_index),



 436                        "Invalid constant pool index %u in class file %s",
 437                        klass_ref_index, CHECK);
 438         check_property(valid_cp_range(name_and_type_ref_index, length) &&
 439           cp->tag_at(name_and_type_ref_index).is_name_and_type(),
 440           "Invalid constant pool index %u in class file %s",
 441           name_and_type_ref_index, CHECK);
 442         break;
 443       }
 444       case JVM_CONSTANT_String: {
 445         ShouldNotReachHere();     // Only JVM_CONSTANT_StringIndex should be present
 446         break;
 447       }
 448       case JVM_CONSTANT_Integer:
 449         break;
 450       case JVM_CONSTANT_Float:
 451         break;
 452       case JVM_CONSTANT_Long:
 453       case JVM_CONSTANT_Double: {
 454         index++;
 455         check_property(


 472       }
 473       case JVM_CONSTANT_Utf8:
 474         break;
 475       case JVM_CONSTANT_UnresolvedClass:         // fall-through
 476       case JVM_CONSTANT_UnresolvedClassInError: {
 477         ShouldNotReachHere();     // Only JVM_CONSTANT_ClassIndex should be present
 478         break;
 479       }
 480       case JVM_CONSTANT_ClassIndex: {
 481         const int class_index = cp->klass_index_at(index);
 482         check_property(valid_symbol_at(class_index),
 483           "Invalid constant pool index %u in class file %s",
 484           class_index, CHECK);
 485 
 486         Symbol* const name = cp->symbol_at(class_index);
 487         const unsigned int name_len = name->utf8_length();
 488 
 489         cp->unresolved_klass_at_put(index, class_index, num_klasses++);
 490         break;
 491       }








 492       case JVM_CONSTANT_StringIndex: {
 493         const int string_index = cp->string_index_at(index);
 494         check_property(valid_symbol_at(string_index),
 495           "Invalid constant pool index %u in class file %s",
 496           string_index, CHECK);
 497         Symbol* const sym = cp->symbol_at(string_index);
 498         cp->unresolved_string_at_put(index, sym);
 499         break;
 500       }
 501       case JVM_CONSTANT_MethodHandle: {
 502         const int ref_index = cp->method_handle_index_at(index);
 503         check_property(valid_cp_range(ref_index, length),
 504           "Invalid constant pool index %u in class file %s",
 505           ref_index, CHECK);
 506         const constantTag tag = cp->tag_at(ref_index);
 507         const int ref_kind = cp->method_handle_ref_kind_at(index);
 508 
 509         switch (ref_kind) {
 510           case JVM_REF_getField:
 511           case JVM_REF_getStatic:


 616 
 617     for (index = 1; index < length; index++) {          // Index 0 is unused
 618       if (has_cp_patch_at(index)) {
 619         guarantee_property(index != this_class_index,
 620           "Illegal constant pool patch to self at %d in class file %s",
 621           index, CHECK);
 622         patch_constant_pool(cp, index, cp_patch_at(index), CHECK);
 623       }
 624     }
 625   }
 626 
 627   if (!_need_verify) {
 628     return;
 629   }
 630 
 631   // second verification pass - checks the strings are of the right format.
 632   // but not yet to the other entries
 633   for (index = 1; index < length; index++) {
 634     const jbyte tag = cp->tag_at(index).value();
 635     switch (tag) {
 636       case JVM_CONSTANT_UnresolvedClass: {

 637         const Symbol* const class_name = cp->klass_name_at(index);
 638         // check the name, even if _cp_patches will overwrite it
 639         verify_legal_class_name(class_name, CHECK);
 640         break;
 641       }
 642       case JVM_CONSTANT_NameAndType: {
 643         if (_need_verify) {
 644           const int sig_index = cp->signature_ref_index_at(index);
 645           const int name_index = cp->name_ref_index_at(index);
 646           const Symbol* const name = cp->symbol_at(name_index);
 647           const Symbol* const sig = cp->symbol_at(sig_index);
 648           guarantee_property(sig->utf8_length() != 0,
 649             "Illegal zero length constant pool entry at %d in class %s",
 650             sig_index, CHECK);
 651           guarantee_property(name->utf8_length() != 0,
 652             "Illegal zero length constant pool entry at %d in class %s",
 653             name_index, CHECK);
 654 
 655           if (sig->byte_at(0) == JVM_SIGNATURE_FUNC) {
 656             // Format check method name and signature


3152   // 4-tuples of shorts of inner classes data and 2 shorts of enclosing
3153   // method data:
3154   //   [inner_class_info_index,
3155   //    outer_class_info_index,
3156   //    inner_name_index,
3157   //    inner_class_access_flags,
3158   //    ...
3159   //    enclosing_method_class_index,
3160   //    enclosing_method_method_index]
3161   const int size = length * 4 + (parsed_enclosingmethod_attribute ? 2 : 0);
3162   Array<u2>* const inner_classes = MetadataFactory::new_array<u2>(_loader_data, size, CHECK_0);
3163   _inner_classes = inner_classes;
3164 
3165   int index = 0;
3166   const int cp_size = _cp->length();
3167   cfs->guarantee_more(8 * length, CHECK_0);  // 4-tuples of u2
3168   for (int n = 0; n < length; n++) {
3169     // Inner class index
3170     const u2 inner_class_info_index = cfs->get_u2_fast();
3171     check_property(
3172       valid_klass_reference_at(inner_class_info_index),

3173       "inner_class_info_index %u has bad constant type in class file %s",
3174       inner_class_info_index, CHECK_0);
3175     // Outer class index
3176     const u2 outer_class_info_index = cfs->get_u2_fast();
3177     check_property(
3178       outer_class_info_index == 0 ||
3179         valid_klass_reference_at(outer_class_info_index),

3180       "outer_class_info_index %u has bad constant type in class file %s",
3181       outer_class_info_index, CHECK_0);
3182     // Inner class name
3183     const u2 inner_name_index = cfs->get_u2_fast();
3184     check_property(
3185       inner_name_index == 0 || valid_symbol_at(inner_name_index),
3186       "inner_name_index %u has bad constant type in class file %s",
3187       inner_name_index, CHECK_0);
3188     if (_need_verify) {
3189       guarantee_property(inner_class_info_index != outer_class_info_index,
3190                          "Class is both outer and inner class in class file %s", CHECK_0);
3191     }
3192 
3193     jint recognized_modifiers = RECOGNIZED_INNER_CLASS_MODIFIERS;
3194     // JVM_ACC_MODULE is defined in JDK-9 and later.
3195     if (_major_version >= JAVA_9_VERSION) {
3196       recognized_modifiers |= JVM_ACC_MODULE;
3197     }
3198     // JVM_ACC_VALUE is defined for class file version 53.1 and later
3199     if (supports_value_types()) {


3648       }
3649     }
3650   }
3651   return annotations;
3652 }
3653 
3654 const InstanceKlass* ClassFileParser::parse_super_class(ConstantPool* const cp,
3655                                                         const int super_class_index,
3656                                                         const bool need_verify,
3657                                                         TRAPS) {
3658   assert(cp != NULL, "invariant");
3659   const InstanceKlass* super_klass = NULL;
3660 
3661   if (super_class_index == 0) {
3662     check_property(_class_name == vmSymbols::java_lang_Object()
3663                    || (_access_flags.get_flags() & JVM_ACC_VALUE),
3664                    "Invalid superclass index %u in class file %s",
3665                    super_class_index,
3666                    CHECK_NULL);
3667   } else {
3668     check_property(valid_klass_reference_at(super_class_index),

3669                    "Invalid superclass index %u in class file %s",
3670                    super_class_index,
3671                    CHECK_NULL);
3672     // The class name should be legal because it is checked when parsing constant pool.
3673     // However, make sure it is not an array type.
3674     bool is_array = false;
3675     if (cp->tag_at(super_class_index).is_klass()) {
3676       super_klass = InstanceKlass::cast(cp->resolved_klass_at(super_class_index));
3677       if (need_verify)
3678         is_array = super_klass->is_array_klass();
3679     } else if (need_verify) {
3680       is_array = (cp->klass_name_at(super_class_index)->byte_at(0) == JVM_SIGNATURE_ARRAY);
3681     }
3682     if (need_verify) {
3683       guarantee_property(!is_array,
3684                         "Bad superclass name in class file %s", CHECK_NULL);
3685     }
3686   }
3687   return super_klass;
3688 }
3689 
3690 #ifndef PRODUCT
3691 static void print_field_layout(const Symbol* name,
3692                                Array<u2>* fields,
3693                                const constantPoolHandle& cp,
3694                                int instance_size,
3695                                int instance_fields_start,


6147 
6148   if ((flags & JVM_ACC_INTERFACE) && _major_version < JAVA_6_VERSION) {
6149     // Set abstract bit for old class files for backward compatibility
6150     flags |= JVM_ACC_ABSTRACT;
6151   }
6152 
6153   verify_legal_class_modifiers(flags, CHECK);
6154 
6155   short bad_constant = class_bad_constant_seen();
6156   if (bad_constant != 0) {
6157     // Do not throw CFE until after the access_flags are checked because if
6158     // ACC_MODULE is set in the access flags, then NCDFE must be thrown, not CFE.
6159     classfile_parse_error("Unknown constant tag %u in class file %s", bad_constant, CHECK);
6160   }
6161 
6162   _access_flags.set_flags(flags);
6163 
6164   // This class and superclass
6165   _this_class_index = stream->get_u2_fast();
6166   check_property(
6167     valid_cp_range(_this_class_index, cp_size) &&
6168       cp->tag_at(_this_class_index).is_unresolved_klass(),

6169     "Invalid this class index %u in constant pool in class file %s",
6170     _this_class_index, CHECK);
6171 
6172   Symbol* const class_name_in_cp = cp->klass_name_at(_this_class_index);
6173   assert(class_name_in_cp != NULL, "class_name can't be null");
6174 
6175   // Update _class_name which could be null previously
6176   // to reflect the name in the constant pool
6177   _class_name = class_name_in_cp;
6178 
6179   // Don't need to check whether this class name is legal or not.
6180   // It has been checked when constant pool is parsed.
6181   // However, make sure it is not an array type.
6182   if (_need_verify) {
6183     guarantee_property(_class_name->byte_at(0) != JVM_SIGNATURE_ARRAY,
6184                        "Bad class name in class file %s",
6185                        CHECK);
6186   }
6187 
6188   // Checks if name in class file matches requested name


6359   }
6360 
6361   if (_super_klass != NULL) {
6362     if (_super_klass->has_nonstatic_concrete_methods()) {
6363       _has_nonstatic_concrete_methods = true;
6364     }
6365 
6366     if (_super_klass->is_interface()) {
6367       ResourceMark rm(THREAD);
6368       Exceptions::fthrow(
6369         THREAD_AND_LOCATION,
6370         vmSymbols::java_lang_IncompatibleClassChangeError(),
6371         "class %s has interface %s as super class",
6372         _class_name->as_klass_external_name(),
6373         _super_klass->external_name()
6374       );
6375       return;
6376     }
6377 
6378     // For a value class, only java/lang/Object is an acceptable super class
6379     if (EnableValhalla &&
6380         _access_flags.get_flags() & JVM_ACC_VALUE) {
6381       guarantee_property(_super_klass->name() == vmSymbols::java_lang_Object(),
6382                          "Value class can only inherit java/lang/Object",
6383                          CHECK);
6384     }
6385 
6386     // Make sure super class is not final
6387     if (_super_klass->is_final()) {
6388       THROW_MSG(vmSymbols::java_lang_VerifyError(), "Cannot inherit from final class");
6389     }
6390   }
6391 
6392   // Compute the transitive list of all unique interfaces implemented by this class
6393   _transitive_interfaces =
6394     compute_transitive_interfaces(_super_klass,
6395                                   _local_interfaces,
6396                                   _loader_data,
6397                                   CHECK);
6398 
6399   assert(_transitive_interfaces != NULL, "invariant");


< prev index next >