@@ -3063,15 +3063,15 @@ u2 ClassFileParser::parse_classfile_inner_classes_attribute(const ClassFileStrea
3063
3063
" Class is both outer and inner class in class file %s" , CHECK_0);
3064
3064
}
3065
3065
3066
- u2 recognized_modifiers = RECOGNIZED_INNER_CLASS_MODIFIERS;
3066
+ // Access flags
3067
+ u2 flags;
3067
3068
// JVM_ACC_MODULE is defined in JDK-9 and later.
3068
3069
if (_major_version >= JAVA_9_VERSION) {
3069
- recognized_modifiers |= JVM_ACC_MODULE;
3070
+ flags = cfs->get_u2_fast () & (RECOGNIZED_INNER_CLASS_MODIFIERS | JVM_ACC_MODULE);
3071
+ } else {
3072
+ flags = cfs->get_u2_fast () & RECOGNIZED_INNER_CLASS_MODIFIERS;
3070
3073
}
3071
3074
3072
- // Access flags
3073
- u2 flags = cfs->get_u2_fast () & recognized_modifiers;
3074
-
3075
3075
if ((flags & JVM_ACC_INTERFACE) && _major_version < JAVA_6_VERSION) {
3076
3076
// Set abstract bit for old class files for backward compatibility
3077
3077
flags |= JVM_ACC_ABSTRACT;
@@ -3085,8 +3085,7 @@ u2 ClassFileParser::parse_classfile_inner_classes_attribute(const ClassFileStrea
3085
3085
}
3086
3086
}
3087
3087
3088
- const char * name = inner_name_index == 0 ? " unnamed" : cp->symbol_at (inner_name_index)->as_utf8 ();
3089
- verify_legal_class_modifiers (flags, name, false , CHECK_0);
3088
+ verify_legal_class_modifiers (flags, CHECK_0);
3090
3089
AccessFlags inner_access_flags (flags);
3091
3090
3092
3091
inner_classes->at_put (index++, inner_class_info_index);
@@ -4427,9 +4426,8 @@ static void check_illegal_static_method(const InstanceKlass* this_klass, TRAPS)
4427
4426
4428
4427
// utility methods for format checking
4429
4428
4430
- void ClassFileParser::verify_legal_class_modifiers (jint flags, const char * name, bool is_Object, TRAPS) const {
4429
+ void ClassFileParser::verify_legal_class_modifiers (jint flags, TRAPS) const {
4431
4430
const bool is_module = (flags & JVM_ACC_MODULE) != 0 ;
4432
- const bool is_inner_class = name != nullptr ;
4433
4431
assert (_major_version >= JAVA_9_VERSION || !is_module, " JVM_ACC_MODULE should not be set" );
4434
4432
if (is_module) {
4435
4433
ResourceMark rm (THREAD);
@@ -4464,24 +4462,13 @@ void ClassFileParser::verify_legal_class_modifiers(jint flags, const char* name,
4464
4462
if (!valid_value_class) {
4465
4463
class_note = " (a value class must be final or else abstract)" ;
4466
4464
}
4467
- if (name == nullptr ) { // Not an inner class
4468
- Exceptions::fthrow (
4469
- THREAD_AND_LOCATION,
4470
- vmSymbols::java_lang_ClassFormatError (),
4471
- " Illegal class modifiers in class %s%s: 0x%X" ,
4472
- _class_name->as_C_string (), class_note, flags
4473
- );
4474
- return ;
4475
- } else {
4476
- // Names are all known to be < 64k so we know this formatted message is not excessively large.
4477
- Exceptions::fthrow (
4478
- THREAD_AND_LOCATION,
4479
- vmSymbols::java_lang_ClassFormatError (),
4480
- " Illegal class modifiers in declaration of inner class %s%s of class %s: 0x%X" ,
4481
- name, class_note, _class_name->as_C_string (), flags
4482
- );
4483
- return ;
4484
- }
4465
+ Exceptions::fthrow (
4466
+ THREAD_AND_LOCATION,
4467
+ vmSymbols::java_lang_ClassFormatError (),
4468
+ " Illegal class modifiers in class %s%s: 0x%X" ,
4469
+ _class_name->as_C_string (), class_note, flags
4470
+ );
4471
+ return ;
4485
4472
}
4486
4473
}
4487
4474
@@ -5793,15 +5780,15 @@ void ClassFileParser::parse_stream(const ClassFileStream* const stream,
5793
5780
// ACCESS FLAGS
5794
5781
stream->guarantee_more (8 , CHECK); // flags, this_class, super_class, infs_len
5795
5782
5796
- u2 recognized_modifiers = JVM_RECOGNIZED_CLASS_MODIFIERS;
5783
+ // Access flags
5784
+ u2 flags;
5797
5785
// JVM_ACC_MODULE is defined in JDK-9 and later.
5798
5786
if (_major_version >= JAVA_9_VERSION) {
5799
- recognized_modifiers |= JVM_ACC_MODULE;
5787
+ flags = stream->get_u2_fast () & (JVM_RECOGNIZED_CLASS_MODIFIERS | JVM_ACC_MODULE);
5788
+ } else {
5789
+ flags = stream->get_u2_fast () & JVM_RECOGNIZED_CLASS_MODIFIERS;
5800
5790
}
5801
5791
5802
- // Access flags
5803
- u2 flags = stream->get_u2_fast () & recognized_modifiers;
5804
-
5805
5792
if ((flags & JVM_ACC_INTERFACE) && _major_version < JAVA_6_VERSION) {
5806
5793
// Set abstract bit for old class files for backward compatibility
5807
5794
flags |= JVM_ACC_ABSTRACT;
@@ -5816,6 +5803,17 @@ void ClassFileParser::parse_stream(const ClassFileStream* const stream,
5816
5803
}
5817
5804
}
5818
5805
5806
+ verify_legal_class_modifiers (flags, CHECK);
5807
+
5808
+ short bad_constant = class_bad_constant_seen ();
5809
+ if (bad_constant != 0 ) {
5810
+ // Do not throw CFE until after the access_flags are checked because if
5811
+ // ACC_MODULE is set in the access flags, then NCDFE must be thrown, not CFE.
5812
+ classfile_parse_error (" Unknown constant tag %u in class file %s" , bad_constant, THREAD);
5813
+ return ;
5814
+ }
5815
+
5816
+ _access_flags.set_flags (flags);
5819
5817
5820
5818
// This class and superclass
5821
5819
_this_class_index = stream->get_u2_fast ();
@@ -5828,20 +5826,6 @@ void ClassFileParser::parse_stream(const ClassFileStream* const stream,
5828
5826
Symbol* const class_name_in_cp = cp->klass_name_at (_this_class_index);
5829
5827
assert (class_name_in_cp != nullptr , " class_name can't be null" );
5830
5828
5831
- bool is_java_lang_Object = class_name_in_cp == vmSymbols::java_lang_Object ();
5832
-
5833
- verify_legal_class_modifiers (flags, nullptr , is_java_lang_Object, CHECK);
5834
-
5835
- _access_flags.set_flags (flags);
5836
-
5837
- short bad_constant = class_bad_constant_seen ();
5838
- if (bad_constant != 0 ) {
5839
- // Do not throw CFE until after the access_flags are checked because if
5840
- // ACC_MODULE is set in the access flags, then NCDFE must be thrown, not CFE.
5841
- classfile_parse_error (" Unknown constant tag %u in class file %s" , bad_constant, THREAD);
5842
- return ;
5843
- }
5844
-
5845
5829
// Don't need to check whether this class name is legal or not.
5846
5830
// It has been checked when constant pool is parsed.
5847
5831
// However, make sure it is not an array type.
0 commit comments