< prev index next >

src/hotspot/share/classfile/classFileParser.cpp

Print this page




3161   u2 length = 0;
3162   if (nest_members_attribute_start != NULL) {
3163     cfs->set_current(nest_members_attribute_start);
3164     cfs->guarantee_more(2, CHECK_0);  // length
3165     length = cfs->get_u2_fast();
3166   }
3167   const int size = length;
3168   Array<u2>* const nest_members = MetadataFactory::new_array<u2>(_loader_data, size, CHECK_0);
3169   _nest_members = nest_members;
3170 
3171   int index = 0;
3172   cfs->guarantee_more(2 * length, CHECK_0);
3173   for (int n = 0; n < length; n++) {
3174     const u2 class_info_index = cfs->get_u2_fast();
3175     check_property(
3176       valid_klass_reference_at(class_info_index),
3177       "Nest member class_info_index %u has bad constant type in class file %s",
3178       class_info_index, CHECK_0);
3179     nest_members->at_put(index++, class_info_index);
3180   }
3181   if (_need_verify) {
3182     for (int i = 0; i < length; i++) {
3183       for (int j = i + 1; j < length; j++) {
3184         guarantee_property((nest_members->at(i) != nest_members->at(j)),
3185                            "Duplicate entry in NestMembers in class file %s",
3186                            CHECK_0);
3187       }
3188     }
3189   }
3190   assert(index == size, "wrong size");
3191 
3192   // Restore buffer's current position.
3193   cfs->set_current(current_mark);
3194 
3195   return length;
3196 }
3197 
3198 void ClassFileParser::parse_classfile_synthetic_attribute(TRAPS) {
3199   set_class_synthetic_flag(true);
3200 }
3201 
3202 void ClassFileParser::parse_classfile_signature_attribute(const ClassFileStream* const cfs, TRAPS) {
3203   assert(cfs != NULL, "invariant");
3204 
3205   const u2 signature_index = cfs->get_u2(CHECK);
3206   check_property(
3207     valid_symbol_at(signature_index),
3208     "Invalid constant pool index %u in Signature attribute in class file %s",
3209     signature_index, CHECK);


3352       }
3353       parse_classfile_sourcefile_attribute(cfs, CHECK);
3354     } else if (tag == vmSymbols::tag_source_debug_extension()) {
3355       // Check for SourceDebugExtension tag
3356       if (parsed_source_debug_ext_annotations_exist) {
3357           classfile_parse_error(
3358             "Multiple SourceDebugExtension attributes in class file %s", CHECK);
3359       }
3360       parsed_source_debug_ext_annotations_exist = true;
3361       parse_classfile_source_debug_extension_attribute(cfs, (int)attribute_length, CHECK);
3362     } else if (tag == vmSymbols::tag_inner_classes()) {
3363       // Check for InnerClasses tag
3364       if (parsed_innerclasses_attribute) {
3365         classfile_parse_error("Multiple InnerClasses attributes in class file %s", CHECK);
3366       } else {
3367         parsed_innerclasses_attribute = true;
3368       }
3369       inner_classes_attribute_start = cfs->current();
3370       inner_classes_attribute_length = attribute_length;
3371       cfs->skip_u1(inner_classes_attribute_length, CHECK);
3372     } else if (tag == vmSymbols::tag_nest_members()) {
3373       // Check for NestMembers tag
3374       if (parsed_nest_members_attribute) {
3375         classfile_parse_error("Multiple NestMembers attributes in class file %s", CHECK);
3376       } else {
3377         parsed_nest_members_attribute = true;
3378       }
3379       if (parsed_nest_host_attribute) {
3380         classfile_parse_error("Conflicting NestHost and NestMembers attributes in class file %s", CHECK);
3381       }
3382       nest_members_attribute_start = cfs->current();
3383       nest_members_attribute_length = attribute_length;
3384       cfs->skip_u1(nest_members_attribute_length, CHECK);
3385     } else if (tag == vmSymbols::tag_nest_host()) {
3386       if (parsed_nest_host_attribute) {
3387         classfile_parse_error("Multiple NestHost attributes in class file %s", CHECK);
3388       } else {
3389         parsed_nest_host_attribute = true;
3390       }
3391       if (parsed_nest_members_attribute) {
3392         classfile_parse_error("Conflicting NestMembers and NestHost attributes in class file %s", CHECK);
3393       }
3394       cfs->guarantee_more(2, CHECK);
3395       u2 class_info_index = cfs->get_u2_fast();
3396       check_property(
3397         valid_klass_reference_at(class_info_index),
3398         "Nest-host class_info_index %u has bad constant type in class file %s",
3399         class_info_index, CHECK);
3400       _nest_host = class_info_index;
3401     } else if (tag == vmSymbols::tag_synthetic()) {
3402       // Check for Synthetic tag
3403       // Shouldn't we check that the synthetic flags wasn't already set? - not required in spec
3404       if (attribute_length != 0) {
3405         classfile_parse_error(
3406           "Invalid Synthetic classfile attribute length %u in class file %s",
3407           attribute_length, CHECK);
3408       }
3409       parse_classfile_synthetic_attribute(CHECK);
3410     } else if (tag == vmSymbols::tag_deprecated()) {
3411       // Check for Deprecatd tag - 4276120
3412       if (attribute_length != 0) {
3413         classfile_parse_error(
3414           "Invalid Deprecated classfile attribute length %u in class file %s",
3415           attribute_length, CHECK);
3416       }
3417     } else if (_major_version >= JAVA_1_5_VERSION) {
3418       if (tag == vmSymbols::tag_signature()) {
3419         if (_generic_signature_index != 0) {
3420           classfile_parse_error(


3490             "Multiple RuntimeVisibleTypeAnnotations attributes in class file %s", CHECK);
3491         }
3492         runtime_visible_type_annotations_length = attribute_length;
3493         runtime_visible_type_annotations = cfs->current();
3494         assert(runtime_visible_type_annotations != NULL, "null visible type annotations");
3495         // No need for the VM to parse Type annotations
3496         cfs->skip_u1(runtime_visible_type_annotations_length, CHECK);
3497       } else if (tag == vmSymbols::tag_runtime_invisible_type_annotations()) {
3498         if (runtime_invisible_type_annotations_exists) {
3499           classfile_parse_error(
3500             "Multiple RuntimeInvisibleTypeAnnotations attributes in class file %s", CHECK);
3501         } else {
3502           runtime_invisible_type_annotations_exists = true;
3503         }
3504         if (PreserveAllAnnotations) {
3505           runtime_invisible_type_annotations_length = attribute_length;
3506           runtime_invisible_type_annotations = cfs->current();
3507           assert(runtime_invisible_type_annotations != NULL, "null invisible type annotations");
3508         }
3509         cfs->skip_u1(attribute_length, CHECK);































3510       } else {
3511         // Unknown attribute
3512         cfs->skip_u1(attribute_length, CHECK);
3513       }
3514     } else {
3515       // Unknown attribute
3516       cfs->skip_u1(attribute_length, CHECK);
3517     }
3518   }
3519   _annotations = assemble_annotations(runtime_visible_annotations,
3520                                       runtime_visible_annotations_length,
3521                                       runtime_invisible_annotations,
3522                                       runtime_invisible_annotations_length,
3523                                       CHECK);
3524   _type_annotations = assemble_annotations(runtime_visible_type_annotations,
3525                                            runtime_visible_type_annotations_length,
3526                                            runtime_invisible_type_annotations,
3527                                            runtime_invisible_type_annotations_length,
3528                                            CHECK);
3529 
3530   if (parsed_innerclasses_attribute || parsed_enclosingmethod_attribute) {
3531     const u2 num_of_classes = parse_classfile_inner_classes_attribute(
3532                             cfs,
3533                             inner_classes_attribute_start,
3534                             parsed_innerclasses_attribute,
3535                             enclosing_method_class_index,
3536                             enclosing_method_method_index,
3537                             CHECK);
3538     if (parsed_innerclasses_attribute && _need_verify && _major_version >= JAVA_1_5_VERSION) {
3539       guarantee_property(
3540         inner_classes_attribute_length == sizeof(num_of_classes) + 4 * sizeof(u2) * num_of_classes,
3541         "Wrong InnerClasses attribute length in class file %s", CHECK);
3542     }
3543   }
3544 
3545   if (parsed_nest_members_attribute) {
3546     const u2 num_of_classes = parse_classfile_nest_members_attribute(
3547                             cfs,
3548                             nest_members_attribute_start,
3549                             CHECK);
3550     if (_need_verify && _major_version >= JAVA_10_VERSION) {
3551       guarantee_property(
3552         nest_members_attribute_length == sizeof(num_of_classes) + sizeof(u2) * num_of_classes,
3553         "Wrong NestMembers attribute length in class file %s", CHECK);
3554     }
3555   }
3556 
3557   if (_max_bootstrap_specifier_index >= 0) {
3558     guarantee_property(parsed_bootstrap_methods_attribute,
3559                        "Missing BootstrapMethods attribute in class file %s", CHECK);
3560   }
3561 }
3562 
3563 void ClassFileParser::apply_parsed_class_attributes(InstanceKlass* k) {
3564   assert(k != NULL, "invariant");
3565 
3566   if (_synthetic_flag)
3567     k->set_is_synthetic();
3568   if (_sourcefile_index != 0) {
3569     k->set_source_file_name_index(_sourcefile_index);
3570   }




3161   u2 length = 0;
3162   if (nest_members_attribute_start != NULL) {
3163     cfs->set_current(nest_members_attribute_start);
3164     cfs->guarantee_more(2, CHECK_0);  // length
3165     length = cfs->get_u2_fast();
3166   }
3167   const int size = length;
3168   Array<u2>* const nest_members = MetadataFactory::new_array<u2>(_loader_data, size, CHECK_0);
3169   _nest_members = nest_members;
3170 
3171   int index = 0;
3172   cfs->guarantee_more(2 * length, CHECK_0);
3173   for (int n = 0; n < length; n++) {
3174     const u2 class_info_index = cfs->get_u2_fast();
3175     check_property(
3176       valid_klass_reference_at(class_info_index),
3177       "Nest member class_info_index %u has bad constant type in class file %s",
3178       class_info_index, CHECK_0);
3179     nest_members->at_put(index++, class_info_index);
3180   }









3181   assert(index == size, "wrong size");
3182 
3183   // Restore buffer's current position.
3184   cfs->set_current(current_mark);
3185 
3186   return length;
3187 }
3188 
3189 void ClassFileParser::parse_classfile_synthetic_attribute(TRAPS) {
3190   set_class_synthetic_flag(true);
3191 }
3192 
3193 void ClassFileParser::parse_classfile_signature_attribute(const ClassFileStream* const cfs, TRAPS) {
3194   assert(cfs != NULL, "invariant");
3195 
3196   const u2 signature_index = cfs->get_u2(CHECK);
3197   check_property(
3198     valid_symbol_at(signature_index),
3199     "Invalid constant pool index %u in Signature attribute in class file %s",
3200     signature_index, CHECK);


3343       }
3344       parse_classfile_sourcefile_attribute(cfs, CHECK);
3345     } else if (tag == vmSymbols::tag_source_debug_extension()) {
3346       // Check for SourceDebugExtension tag
3347       if (parsed_source_debug_ext_annotations_exist) {
3348           classfile_parse_error(
3349             "Multiple SourceDebugExtension attributes in class file %s", CHECK);
3350       }
3351       parsed_source_debug_ext_annotations_exist = true;
3352       parse_classfile_source_debug_extension_attribute(cfs, (int)attribute_length, CHECK);
3353     } else if (tag == vmSymbols::tag_inner_classes()) {
3354       // Check for InnerClasses tag
3355       if (parsed_innerclasses_attribute) {
3356         classfile_parse_error("Multiple InnerClasses attributes in class file %s", CHECK);
3357       } else {
3358         parsed_innerclasses_attribute = true;
3359       }
3360       inner_classes_attribute_start = cfs->current();
3361       inner_classes_attribute_length = attribute_length;
3362       cfs->skip_u1(inner_classes_attribute_length, CHECK);





























3363     } else if (tag == vmSymbols::tag_synthetic()) {
3364       // Check for Synthetic tag
3365       // Shouldn't we check that the synthetic flags wasn't already set? - not required in spec
3366       if (attribute_length != 0) {
3367         classfile_parse_error(
3368           "Invalid Synthetic classfile attribute length %u in class file %s",
3369           attribute_length, CHECK);
3370       }
3371       parse_classfile_synthetic_attribute(CHECK);
3372     } else if (tag == vmSymbols::tag_deprecated()) {
3373       // Check for Deprecatd tag - 4276120
3374       if (attribute_length != 0) {
3375         classfile_parse_error(
3376           "Invalid Deprecated classfile attribute length %u in class file %s",
3377           attribute_length, CHECK);
3378       }
3379     } else if (_major_version >= JAVA_1_5_VERSION) {
3380       if (tag == vmSymbols::tag_signature()) {
3381         if (_generic_signature_index != 0) {
3382           classfile_parse_error(


3452             "Multiple RuntimeVisibleTypeAnnotations attributes in class file %s", CHECK);
3453         }
3454         runtime_visible_type_annotations_length = attribute_length;
3455         runtime_visible_type_annotations = cfs->current();
3456         assert(runtime_visible_type_annotations != NULL, "null visible type annotations");
3457         // No need for the VM to parse Type annotations
3458         cfs->skip_u1(runtime_visible_type_annotations_length, CHECK);
3459       } else if (tag == vmSymbols::tag_runtime_invisible_type_annotations()) {
3460         if (runtime_invisible_type_annotations_exists) {
3461           classfile_parse_error(
3462             "Multiple RuntimeInvisibleTypeAnnotations attributes in class file %s", CHECK);
3463         } else {
3464           runtime_invisible_type_annotations_exists = true;
3465         }
3466         if (PreserveAllAnnotations) {
3467           runtime_invisible_type_annotations_length = attribute_length;
3468           runtime_invisible_type_annotations = cfs->current();
3469           assert(runtime_invisible_type_annotations != NULL, "null invisible type annotations");
3470         }
3471         cfs->skip_u1(attribute_length, CHECK);
3472       } else if (_major_version >= JAVA_10_VERSION) {
3473         if (tag == vmSymbols::tag_nest_members()) {
3474           // Check for NestMembers tag
3475           if (parsed_nest_members_attribute) {
3476             classfile_parse_error("Multiple NestMembers attributes in class file %s", CHECK);
3477           } else {
3478             parsed_nest_members_attribute = true;
3479           }
3480           if (parsed_nest_host_attribute) {
3481             classfile_parse_error("Conflicting NestHost and NestMembers attributes in class file %s", CHECK);
3482           }
3483           nest_members_attribute_start = cfs->current();
3484           nest_members_attribute_length = attribute_length;
3485           cfs->skip_u1(nest_members_attribute_length, CHECK);
3486         } else if (tag == vmSymbols::tag_nest_host()) {
3487           if (parsed_nest_host_attribute) {
3488             classfile_parse_error("Multiple NestHost attributes in class file %s", CHECK);
3489           } else {
3490             parsed_nest_host_attribute = true;
3491           }
3492           if (parsed_nest_members_attribute) {
3493             classfile_parse_error("Conflicting NestMembers and NestHost attributes in class file %s", CHECK);
3494           }
3495           cfs->guarantee_more(2, CHECK);
3496           u2 class_info_index = cfs->get_u2_fast();
3497           check_property(
3498                          valid_klass_reference_at(class_info_index),
3499                          "Nest-host class_info_index %u has bad constant type in class file %s",
3500                          class_info_index, CHECK);
3501           _nest_host = class_info_index;
3502         }
3503       } else {
3504         // Unknown attribute
3505         cfs->skip_u1(attribute_length, CHECK);
3506       }
3507     } else {
3508       // Unknown attribute
3509       cfs->skip_u1(attribute_length, CHECK);
3510     }
3511   }
3512   _annotations = assemble_annotations(runtime_visible_annotations,
3513                                       runtime_visible_annotations_length,
3514                                       runtime_invisible_annotations,
3515                                       runtime_invisible_annotations_length,
3516                                       CHECK);
3517   _type_annotations = assemble_annotations(runtime_visible_type_annotations,
3518                                            runtime_visible_type_annotations_length,
3519                                            runtime_invisible_type_annotations,
3520                                            runtime_invisible_type_annotations_length,
3521                                            CHECK);
3522 
3523   if (parsed_innerclasses_attribute || parsed_enclosingmethod_attribute) {
3524     const u2 num_of_classes = parse_classfile_inner_classes_attribute(
3525                             cfs,
3526                             inner_classes_attribute_start,
3527                             parsed_innerclasses_attribute,
3528                             enclosing_method_class_index,
3529                             enclosing_method_method_index,
3530                             CHECK);
3531     if (parsed_innerclasses_attribute && _need_verify && _major_version >= JAVA_1_5_VERSION) {
3532       guarantee_property(
3533         inner_classes_attribute_length == sizeof(num_of_classes) + 4 * sizeof(u2) * num_of_classes,
3534         "Wrong InnerClasses attribute length in class file %s", CHECK);
3535     }
3536   }
3537 
3538   if (parsed_nest_members_attribute) {
3539     const u2 num_of_classes = parse_classfile_nest_members_attribute(
3540                             cfs,
3541                             nest_members_attribute_start,
3542                             CHECK);
3543     if (_need_verify) {
3544       guarantee_property(
3545         nest_members_attribute_length == sizeof(num_of_classes) + sizeof(u2) * num_of_classes,
3546         "Wrong NestMembers attribute length in class file %s", CHECK);
3547     }
3548   }
3549 
3550   if (_max_bootstrap_specifier_index >= 0) {
3551     guarantee_property(parsed_bootstrap_methods_attribute,
3552                        "Missing BootstrapMethods attribute in class file %s", CHECK);
3553   }
3554 }
3555 
3556 void ClassFileParser::apply_parsed_class_attributes(InstanceKlass* k) {
3557   assert(k != NULL, "invariant");
3558 
3559   if (_synthetic_flag)
3560     k->set_is_synthetic();
3561   if (_sourcefile_index != 0) {
3562     k->set_source_file_name_index(_sourcefile_index);
3563   }


< prev index next >