src/share/vm/classfile/classFileParser.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File bug_8040292_9 Sdiff src/share/vm/classfile

src/share/vm/classfile/classFileParser.cpp

Print this page




 871 void ClassFileParser::parse_field_attributes(u2 attributes_count,
 872                                              bool is_static, u2 signature_index,
 873                                              u2* constantvalue_index_addr,
 874                                              bool* is_synthetic_addr,
 875                                              u2* generic_signature_index_addr,
 876                                              ClassFileParser::FieldAnnotationCollector* parsed_annotations,
 877                                              TRAPS) {
 878   ClassFileStream* cfs = stream();
 879   assert(attributes_count > 0, "length should be greater than 0");
 880   u2 constantvalue_index = 0;
 881   u2 generic_signature_index = 0;
 882   bool is_synthetic = false;
 883   u1* runtime_visible_annotations = NULL;
 884   int runtime_visible_annotations_length = 0;
 885   u1* runtime_invisible_annotations = NULL;
 886   int runtime_invisible_annotations_length = 0;
 887   u1* runtime_visible_type_annotations = NULL;
 888   int runtime_visible_type_annotations_length = 0;
 889   u1* runtime_invisible_type_annotations = NULL;
 890   int runtime_invisible_type_annotations_length = 0;

 891   bool runtime_invisible_type_annotations_exists = false;
 892   while (attributes_count--) {
 893     cfs->guarantee_more(6, CHECK);  // attribute_name_index, attribute_length
 894     u2 attribute_name_index = cfs->get_u2_fast();
 895     u4 attribute_length = cfs->get_u4_fast();
 896     check_property(valid_symbol_at(attribute_name_index),
 897                    "Invalid field attribute index %u in class file %s",
 898                    attribute_name_index,
 899                    CHECK);
 900     Symbol* attribute_name = _cp->symbol_at(attribute_name_index);
 901     if (is_static && attribute_name == vmSymbols::tag_constant_value()) {
 902       // ignore if non-static
 903       if (constantvalue_index != 0) {
 904         classfile_parse_error("Duplicate ConstantValue attribute in class file %s", CHECK);
 905       }
 906       check_property(
 907         attribute_length == 2,
 908         "Invalid ConstantValue field attribute length %u in class file %s",
 909         attribute_length, CHECK);
 910       constantvalue_index = cfs->get_u2(CHECK);


 916         classfile_parse_error(
 917           "Invalid Synthetic field attribute length %u in class file %s",
 918           attribute_length, CHECK);
 919       }
 920       is_synthetic = true;
 921     } else if (attribute_name == vmSymbols::tag_deprecated()) { // 4276120
 922       if (attribute_length != 0) {
 923         classfile_parse_error(
 924           "Invalid Deprecated field attribute length %u in class file %s",
 925           attribute_length, CHECK);
 926       }
 927     } else if (_major_version >= JAVA_1_5_VERSION) {
 928       if (attribute_name == vmSymbols::tag_signature()) {
 929         if (attribute_length != 2) {
 930           classfile_parse_error(
 931             "Wrong size %u for field's Signature attribute in class file %s",
 932             attribute_length, CHECK);
 933         }
 934         generic_signature_index = cfs->get_u2(CHECK);
 935       } else if (attribute_name == vmSymbols::tag_runtime_visible_annotations()) {




 936         runtime_visible_annotations_length = attribute_length;
 937         runtime_visible_annotations = cfs->get_u1_buffer();
 938         assert(runtime_visible_annotations != NULL, "null visible annotations");
 939         parse_annotations(runtime_visible_annotations,
 940                           runtime_visible_annotations_length,
 941                           parsed_annotations,
 942                           CHECK);
 943         cfs->skip_u1(runtime_visible_annotations_length, CHECK);
 944       } else if (PreserveAllAnnotations && attribute_name == vmSymbols::tag_runtime_invisible_annotations()) {






 945         runtime_invisible_annotations_length = attribute_length;
 946         runtime_invisible_annotations = cfs->get_u1_buffer();
 947         assert(runtime_invisible_annotations != NULL, "null invisible annotations");
 948         cfs->skip_u1(runtime_invisible_annotations_length, CHECK);

 949       } else if (attribute_name == vmSymbols::tag_runtime_visible_type_annotations()) {
 950         if (runtime_visible_type_annotations != NULL) {
 951           classfile_parse_error(
 952             "Multiple RuntimeVisibleTypeAnnotations attributes for field in class file %s", CHECK);
 953         }
 954         runtime_visible_type_annotations_length = attribute_length;
 955         runtime_visible_type_annotations = cfs->get_u1_buffer();
 956         assert(runtime_visible_type_annotations != NULL, "null visible type annotations");
 957         cfs->skip_u1(runtime_visible_type_annotations_length, CHECK);
 958       } else if (attribute_name == vmSymbols::tag_runtime_invisible_type_annotations()) {
 959         if (runtime_invisible_type_annotations_exists) {
 960           classfile_parse_error(
 961             "Multiple RuntimeInvisibleTypeAnnotations attributes for field in class file %s", CHECK);
 962         } else {
 963           runtime_invisible_type_annotations_exists = true;
 964         }
 965         if (PreserveAllAnnotations) {
 966           runtime_invisible_type_annotations_length = attribute_length;
 967           runtime_invisible_type_annotations = cfs->get_u1_buffer();
 968           assert(runtime_invisible_type_annotations != NULL, "null invisible type annotations");


2062   bool parsed_code_attribute = false;
2063   bool parsed_checked_exceptions_attribute = false;
2064   bool parsed_stackmap_attribute = false;
2065   // stackmap attribute - JDK1.5
2066   u1* stackmap_data = NULL;
2067   int stackmap_data_length = 0;
2068   u2 generic_signature_index = 0;
2069   MethodAnnotationCollector parsed_annotations;
2070   u1* runtime_visible_annotations = NULL;
2071   int runtime_visible_annotations_length = 0;
2072   u1* runtime_invisible_annotations = NULL;
2073   int runtime_invisible_annotations_length = 0;
2074   u1* runtime_visible_parameter_annotations = NULL;
2075   int runtime_visible_parameter_annotations_length = 0;
2076   u1* runtime_invisible_parameter_annotations = NULL;
2077   int runtime_invisible_parameter_annotations_length = 0;
2078   u1* runtime_visible_type_annotations = NULL;
2079   int runtime_visible_type_annotations_length = 0;
2080   u1* runtime_invisible_type_annotations = NULL;
2081   int runtime_invisible_type_annotations_length = 0;

2082   bool runtime_invisible_type_annotations_exists = false;

2083   u1* annotation_default = NULL;
2084   int annotation_default_length = 0;
2085 
2086   // Parse code and exceptions attribute
2087   u2 method_attributes_count = cfs->get_u2_fast();
2088   while (method_attributes_count--) {
2089     cfs->guarantee_more(6, CHECK_(nullHandle));  // method_attribute_name_index, method_attribute_length
2090     u2 method_attribute_name_index = cfs->get_u2_fast();
2091     u4 method_attribute_length = cfs->get_u4_fast();
2092     check_property(
2093       valid_symbol_at(method_attribute_name_index),
2094       "Invalid method attribute name index %u in class file %s",
2095       method_attribute_name_index, CHECK_(nullHandle));
2096 
2097     Symbol* method_attribute_name = _cp->symbol_at(method_attribute_name_index);
2098     if (method_attribute_name == vmSymbols::tag_code()) {
2099       // Parse Code attribute
2100       if (_need_verify) {
2101         guarantee_property(
2102             !access_flags.is_native() && !access_flags.is_abstract(),


2291           method_attribute_length, CHECK_(nullHandle));
2292       }
2293       // Should we check that there hasn't already been a synthetic attribute?
2294       access_flags.set_is_synthetic();
2295     } else if (method_attribute_name == vmSymbols::tag_deprecated()) { // 4276120
2296       if (method_attribute_length != 0) {
2297         classfile_parse_error(
2298           "Invalid Deprecated method attribute length %u in class file %s",
2299           method_attribute_length, CHECK_(nullHandle));
2300       }
2301     } else if (_major_version >= JAVA_1_5_VERSION) {
2302       if (method_attribute_name == vmSymbols::tag_signature()) {
2303         if (method_attribute_length != 2) {
2304           classfile_parse_error(
2305             "Invalid Signature attribute length %u in class file %s",
2306             method_attribute_length, CHECK_(nullHandle));
2307         }
2308         cfs->guarantee_more(2, CHECK_(nullHandle));  // generic_signature_index
2309         generic_signature_index = cfs->get_u2_fast();
2310       } else if (method_attribute_name == vmSymbols::tag_runtime_visible_annotations()) {




2311         runtime_visible_annotations_length = method_attribute_length;
2312         runtime_visible_annotations = cfs->get_u1_buffer();
2313         assert(runtime_visible_annotations != NULL, "null visible annotations");
2314         parse_annotations(runtime_visible_annotations,
2315             runtime_visible_annotations_length, &parsed_annotations,
2316             CHECK_(nullHandle));
2317         cfs->skip_u1(runtime_visible_annotations_length, CHECK_(nullHandle));
2318       } else if (PreserveAllAnnotations && method_attribute_name == vmSymbols::tag_runtime_invisible_annotations()) {






2319         runtime_invisible_annotations_length = method_attribute_length;
2320         runtime_invisible_annotations = cfs->get_u1_buffer();
2321         assert(runtime_invisible_annotations != NULL, "null invisible annotations");
2322         cfs->skip_u1(runtime_invisible_annotations_length, CHECK_(nullHandle));

2323       } else if (method_attribute_name == vmSymbols::tag_runtime_visible_parameter_annotations()) {




2324         runtime_visible_parameter_annotations_length = method_attribute_length;
2325         runtime_visible_parameter_annotations = cfs->get_u1_buffer();
2326         assert(runtime_visible_parameter_annotations != NULL, "null visible parameter annotations");
2327         cfs->skip_u1(runtime_visible_parameter_annotations_length, CHECK_(nullHandle));
2328       } else if (PreserveAllAnnotations && method_attribute_name == vmSymbols::tag_runtime_invisible_parameter_annotations()) {






2329         runtime_invisible_parameter_annotations_length = method_attribute_length;
2330         runtime_invisible_parameter_annotations = cfs->get_u1_buffer();
2331         assert(runtime_invisible_parameter_annotations != NULL, "null invisible parameter annotations");
2332         cfs->skip_u1(runtime_invisible_parameter_annotations_length, CHECK_(nullHandle));

2333       } else if (method_attribute_name == vmSymbols::tag_annotation_default()) {





2334         annotation_default_length = method_attribute_length;
2335         annotation_default = cfs->get_u1_buffer();
2336         assert(annotation_default != NULL, "null annotation default");
2337         cfs->skip_u1(annotation_default_length, CHECK_(nullHandle));
2338       } else if (method_attribute_name == vmSymbols::tag_runtime_visible_type_annotations()) {
2339         if (runtime_visible_type_annotations != NULL) {
2340           classfile_parse_error(
2341             "Multiple RuntimeVisibleTypeAnnotations attributes for method in class file %s",
2342             CHECK_(nullHandle));
2343         }
2344         runtime_visible_type_annotations_length = method_attribute_length;
2345         runtime_visible_type_annotations = cfs->get_u1_buffer();
2346         assert(runtime_visible_type_annotations != NULL, "null visible type annotations");
2347         // No need for the VM to parse Type annotations
2348         cfs->skip_u1(runtime_visible_type_annotations_length, CHECK_(nullHandle));
2349       } else if (method_attribute_name == vmSymbols::tag_runtime_invisible_type_annotations()) {
2350         if (runtime_invisible_type_annotations_exists) {
2351           classfile_parse_error(
2352             "Multiple RuntimeInvisibleTypeAnnotations attributes for method in class file %s",
2353             CHECK_(nullHandle));


2842 void ClassFileParser::parse_classfile_attributes(ClassFileParser::ClassAnnotationCollector* parsed_annotations,
2843                                                  TRAPS) {
2844   ClassFileStream* cfs = stream();
2845   // Set inner classes attribute to default sentinel
2846   _inner_classes = Universe::the_empty_short_array();
2847   cfs->guarantee_more(2, CHECK);  // attributes_count
2848   u2 attributes_count = cfs->get_u2_fast();
2849   bool parsed_sourcefile_attribute = false;
2850   bool parsed_innerclasses_attribute = false;
2851   bool parsed_enclosingmethod_attribute = false;
2852   bool parsed_bootstrap_methods_attribute = false;
2853   u1* runtime_visible_annotations = NULL;
2854   int runtime_visible_annotations_length = 0;
2855   u1* runtime_invisible_annotations = NULL;
2856   int runtime_invisible_annotations_length = 0;
2857   u1* runtime_visible_type_annotations = NULL;
2858   int runtime_visible_type_annotations_length = 0;
2859   u1* runtime_invisible_type_annotations = NULL;
2860   int runtime_invisible_type_annotations_length = 0;
2861   bool runtime_invisible_type_annotations_exists = false;


2862   u1* inner_classes_attribute_start = NULL;
2863   u4  inner_classes_attribute_length = 0;
2864   u2  enclosing_method_class_index = 0;
2865   u2  enclosing_method_method_index = 0;
2866   // Iterate over attributes
2867   while (attributes_count--) {
2868     cfs->guarantee_more(6, CHECK);  // attribute_name_index, attribute_length
2869     u2 attribute_name_index = cfs->get_u2_fast();
2870     u4 attribute_length = cfs->get_u4_fast();
2871     check_property(
2872       valid_symbol_at(attribute_name_index),
2873       "Attribute name has bad constant pool index %u in class file %s",
2874       attribute_name_index, CHECK);
2875     Symbol* tag = _cp->symbol_at(attribute_name_index);
2876     if (tag == vmSymbols::tag_source_file()) {
2877       // Check for SourceFile tag
2878       if (_need_verify) {
2879         guarantee_property(attribute_length == 2, "Wrong SourceFile attribute length in class file %s", CHECK);
2880       }
2881       if (parsed_sourcefile_attribute) {
2882         classfile_parse_error("Multiple SourceFile attributes in class file %s", CHECK);
2883       } else {
2884         parsed_sourcefile_attribute = true;
2885       }
2886       parse_classfile_sourcefile_attribute(CHECK);
2887     } else if (tag == vmSymbols::tag_source_debug_extension()) {
2888       // Check for SourceDebugExtension tag





2889       parse_classfile_source_debug_extension_attribute((int)attribute_length, CHECK);
2890     } else if (tag == vmSymbols::tag_inner_classes()) {
2891       // Check for InnerClasses tag
2892       if (parsed_innerclasses_attribute) {
2893         classfile_parse_error("Multiple InnerClasses attributes in class file %s", CHECK);
2894       } else {
2895         parsed_innerclasses_attribute = true;
2896       }
2897       inner_classes_attribute_start = cfs->get_u1_buffer();
2898       inner_classes_attribute_length = attribute_length;
2899       cfs->skip_u1(inner_classes_attribute_length, CHECK);
2900     } else if (tag == vmSymbols::tag_synthetic()) {
2901       // Check for Synthetic tag
2902       // Shouldn't we check that the synthetic flags wasn't already set? - not required in spec
2903       if (attribute_length != 0) {
2904         classfile_parse_error(
2905           "Invalid Synthetic classfile attribute length %u in class file %s",
2906           attribute_length, CHECK);
2907       }
2908       parse_classfile_synthetic_attribute(CHECK);
2909     } else if (tag == vmSymbols::tag_deprecated()) {
2910       // Check for Deprecatd tag - 4276120
2911       if (attribute_length != 0) {
2912         classfile_parse_error(
2913           "Invalid Deprecated classfile attribute length %u in class file %s",
2914           attribute_length, CHECK);
2915       }
2916     } else if (_major_version >= JAVA_1_5_VERSION) {
2917       if (tag == vmSymbols::tag_signature()) {
2918         if (attribute_length != 2) {
2919           classfile_parse_error(
2920             "Wrong Signature attribute length %u in class file %s",
2921             attribute_length, CHECK);
2922         }
2923         parse_classfile_signature_attribute(CHECK);
2924       } else if (tag == vmSymbols::tag_runtime_visible_annotations()) {




2925         runtime_visible_annotations_length = attribute_length;
2926         runtime_visible_annotations = cfs->get_u1_buffer();
2927         assert(runtime_visible_annotations != NULL, "null visible annotations");
2928         parse_annotations(runtime_visible_annotations,
2929                           runtime_visible_annotations_length,
2930                           parsed_annotations,
2931                           CHECK);
2932         cfs->skip_u1(runtime_visible_annotations_length, CHECK);
2933       } else if (PreserveAllAnnotations && tag == vmSymbols::tag_runtime_invisible_annotations()) {






2934         runtime_invisible_annotations_length = attribute_length;
2935         runtime_invisible_annotations = cfs->get_u1_buffer();
2936         assert(runtime_invisible_annotations != NULL, "null invisible annotations");
2937         cfs->skip_u1(runtime_invisible_annotations_length, CHECK);

2938       } else if (tag == vmSymbols::tag_enclosing_method()) {
2939         if (parsed_enclosingmethod_attribute) {
2940           classfile_parse_error("Multiple EnclosingMethod attributes in class file %s", CHECK);
2941         }   else {
2942           parsed_enclosingmethod_attribute = true;
2943         }
2944         cfs->guarantee_more(4, CHECK);  // class_index, method_index
2945         enclosing_method_class_index  = cfs->get_u2_fast();
2946         enclosing_method_method_index = cfs->get_u2_fast();
2947         if (enclosing_method_class_index == 0) {
2948           classfile_parse_error("Invalid class index in EnclosingMethod attribute in class file %s", CHECK);
2949         }
2950         // Validate the constant pool indices and types
2951         check_property(valid_klass_reference_at(enclosing_method_class_index),
2952           "Invalid or out-of-bounds class index in EnclosingMethod attribute in class file %s", CHECK);
2953         if (enclosing_method_method_index != 0 &&
2954             (!_cp->is_within_bounds(enclosing_method_method_index) ||
2955              !_cp->tag_at(enclosing_method_method_index).is_name_and_type())) {
2956           classfile_parse_error("Invalid or out-of-bounds method index in EnclosingMethod attribute in class file %s", CHECK);
2957         }




 871 void ClassFileParser::parse_field_attributes(u2 attributes_count,
 872                                              bool is_static, u2 signature_index,
 873                                              u2* constantvalue_index_addr,
 874                                              bool* is_synthetic_addr,
 875                                              u2* generic_signature_index_addr,
 876                                              ClassFileParser::FieldAnnotationCollector* parsed_annotations,
 877                                              TRAPS) {
 878   ClassFileStream* cfs = stream();
 879   assert(attributes_count > 0, "length should be greater than 0");
 880   u2 constantvalue_index = 0;
 881   u2 generic_signature_index = 0;
 882   bool is_synthetic = false;
 883   u1* runtime_visible_annotations = NULL;
 884   int runtime_visible_annotations_length = 0;
 885   u1* runtime_invisible_annotations = NULL;
 886   int runtime_invisible_annotations_length = 0;
 887   u1* runtime_visible_type_annotations = NULL;
 888   int runtime_visible_type_annotations_length = 0;
 889   u1* runtime_invisible_type_annotations = NULL;
 890   int runtime_invisible_type_annotations_length = 0;
 891   bool runtime_invisible_annotations_exists = false;
 892   bool runtime_invisible_type_annotations_exists = false;
 893   while (attributes_count--) {
 894     cfs->guarantee_more(6, CHECK);  // attribute_name_index, attribute_length
 895     u2 attribute_name_index = cfs->get_u2_fast();
 896     u4 attribute_length = cfs->get_u4_fast();
 897     check_property(valid_symbol_at(attribute_name_index),
 898                    "Invalid field attribute index %u in class file %s",
 899                    attribute_name_index,
 900                    CHECK);
 901     Symbol* attribute_name = _cp->symbol_at(attribute_name_index);
 902     if (is_static && attribute_name == vmSymbols::tag_constant_value()) {
 903       // ignore if non-static
 904       if (constantvalue_index != 0) {
 905         classfile_parse_error("Duplicate ConstantValue attribute in class file %s", CHECK);
 906       }
 907       check_property(
 908         attribute_length == 2,
 909         "Invalid ConstantValue field attribute length %u in class file %s",
 910         attribute_length, CHECK);
 911       constantvalue_index = cfs->get_u2(CHECK);


 917         classfile_parse_error(
 918           "Invalid Synthetic field attribute length %u in class file %s",
 919           attribute_length, CHECK);
 920       }
 921       is_synthetic = true;
 922     } else if (attribute_name == vmSymbols::tag_deprecated()) { // 4276120
 923       if (attribute_length != 0) {
 924         classfile_parse_error(
 925           "Invalid Deprecated field attribute length %u in class file %s",
 926           attribute_length, CHECK);
 927       }
 928     } else if (_major_version >= JAVA_1_5_VERSION) {
 929       if (attribute_name == vmSymbols::tag_signature()) {
 930         if (attribute_length != 2) {
 931           classfile_parse_error(
 932             "Wrong size %u for field's Signature attribute in class file %s",
 933             attribute_length, CHECK);
 934         }
 935         generic_signature_index = cfs->get_u2(CHECK);
 936       } else if (attribute_name == vmSymbols::tag_runtime_visible_annotations()) {
 937         if (runtime_visible_annotations != NULL) {
 938           classfile_parse_error(
 939             "Multiple RuntimeVisibleAnnotations attributes for field in class file %s", CHECK);
 940         }
 941         runtime_visible_annotations_length = attribute_length;
 942         runtime_visible_annotations = cfs->get_u1_buffer();
 943         assert(runtime_visible_annotations != NULL, "null visible annotations");
 944         parse_annotations(runtime_visible_annotations,
 945                           runtime_visible_annotations_length,
 946                           parsed_annotations,
 947                           CHECK);
 948         cfs->skip_u1(runtime_visible_annotations_length, CHECK);
 949       } else if (attribute_name == vmSymbols::tag_runtime_invisible_annotations()) {
 950         if (runtime_invisible_annotations_exists) {
 951           classfile_parse_error(
 952             "Multiple RuntimeInvisibleAnnotations attributes for field in class file %s", CHECK);
 953         }
 954         runtime_invisible_annotations_exists = true;
 955         if (PreserveAllAnnotations) {
 956           runtime_invisible_annotations_length = attribute_length;
 957           runtime_invisible_annotations = cfs->get_u1_buffer();
 958           assert(runtime_invisible_annotations != NULL, "null invisible annotations");
 959         }
 960         cfs->skip_u1(attribute_length, CHECK);
 961       } else if (attribute_name == vmSymbols::tag_runtime_visible_type_annotations()) {
 962         if (runtime_visible_type_annotations != NULL) {
 963           classfile_parse_error(
 964             "Multiple RuntimeVisibleTypeAnnotations attributes for field in class file %s", CHECK);
 965         }
 966         runtime_visible_type_annotations_length = attribute_length;
 967         runtime_visible_type_annotations = cfs->get_u1_buffer();
 968         assert(runtime_visible_type_annotations != NULL, "null visible type annotations");
 969         cfs->skip_u1(runtime_visible_type_annotations_length, CHECK);
 970       } else if (attribute_name == vmSymbols::tag_runtime_invisible_type_annotations()) {
 971         if (runtime_invisible_type_annotations_exists) {
 972           classfile_parse_error(
 973             "Multiple RuntimeInvisibleTypeAnnotations attributes for field in class file %s", CHECK);
 974         } else {
 975           runtime_invisible_type_annotations_exists = true;
 976         }
 977         if (PreserveAllAnnotations) {
 978           runtime_invisible_type_annotations_length = attribute_length;
 979           runtime_invisible_type_annotations = cfs->get_u1_buffer();
 980           assert(runtime_invisible_type_annotations != NULL, "null invisible type annotations");


2074   bool parsed_code_attribute = false;
2075   bool parsed_checked_exceptions_attribute = false;
2076   bool parsed_stackmap_attribute = false;
2077   // stackmap attribute - JDK1.5
2078   u1* stackmap_data = NULL;
2079   int stackmap_data_length = 0;
2080   u2 generic_signature_index = 0;
2081   MethodAnnotationCollector parsed_annotations;
2082   u1* runtime_visible_annotations = NULL;
2083   int runtime_visible_annotations_length = 0;
2084   u1* runtime_invisible_annotations = NULL;
2085   int runtime_invisible_annotations_length = 0;
2086   u1* runtime_visible_parameter_annotations = NULL;
2087   int runtime_visible_parameter_annotations_length = 0;
2088   u1* runtime_invisible_parameter_annotations = NULL;
2089   int runtime_invisible_parameter_annotations_length = 0;
2090   u1* runtime_visible_type_annotations = NULL;
2091   int runtime_visible_type_annotations_length = 0;
2092   u1* runtime_invisible_type_annotations = NULL;
2093   int runtime_invisible_type_annotations_length = 0;
2094   bool runtime_invisible_annotations_exists = false;
2095   bool runtime_invisible_type_annotations_exists = false;
2096   bool runtime_invisible_parameter_annotations_exists = false;
2097   u1* annotation_default = NULL;
2098   int annotation_default_length = 0;
2099 
2100   // Parse code and exceptions attribute
2101   u2 method_attributes_count = cfs->get_u2_fast();
2102   while (method_attributes_count--) {
2103     cfs->guarantee_more(6, CHECK_(nullHandle));  // method_attribute_name_index, method_attribute_length
2104     u2 method_attribute_name_index = cfs->get_u2_fast();
2105     u4 method_attribute_length = cfs->get_u4_fast();
2106     check_property(
2107       valid_symbol_at(method_attribute_name_index),
2108       "Invalid method attribute name index %u in class file %s",
2109       method_attribute_name_index, CHECK_(nullHandle));
2110 
2111     Symbol* method_attribute_name = _cp->symbol_at(method_attribute_name_index);
2112     if (method_attribute_name == vmSymbols::tag_code()) {
2113       // Parse Code attribute
2114       if (_need_verify) {
2115         guarantee_property(
2116             !access_flags.is_native() && !access_flags.is_abstract(),


2305           method_attribute_length, CHECK_(nullHandle));
2306       }
2307       // Should we check that there hasn't already been a synthetic attribute?
2308       access_flags.set_is_synthetic();
2309     } else if (method_attribute_name == vmSymbols::tag_deprecated()) { // 4276120
2310       if (method_attribute_length != 0) {
2311         classfile_parse_error(
2312           "Invalid Deprecated method attribute length %u in class file %s",
2313           method_attribute_length, CHECK_(nullHandle));
2314       }
2315     } else if (_major_version >= JAVA_1_5_VERSION) {
2316       if (method_attribute_name == vmSymbols::tag_signature()) {
2317         if (method_attribute_length != 2) {
2318           classfile_parse_error(
2319             "Invalid Signature attribute length %u in class file %s",
2320             method_attribute_length, CHECK_(nullHandle));
2321         }
2322         cfs->guarantee_more(2, CHECK_(nullHandle));  // generic_signature_index
2323         generic_signature_index = cfs->get_u2_fast();
2324       } else if (method_attribute_name == vmSymbols::tag_runtime_visible_annotations()) {
2325         if (runtime_visible_annotations != NULL) {
2326           classfile_parse_error(
2327             "Multiple RuntimeVisibleAnnotations attributes for method in class file %s", CHECK_(nullHandle));
2328         }
2329         runtime_visible_annotations_length = method_attribute_length;
2330         runtime_visible_annotations = cfs->get_u1_buffer();
2331         assert(runtime_visible_annotations != NULL, "null visible annotations");
2332         parse_annotations(runtime_visible_annotations,
2333             runtime_visible_annotations_length, &parsed_annotations,
2334             CHECK_(nullHandle));
2335         cfs->skip_u1(runtime_visible_annotations_length, CHECK_(nullHandle));
2336       } else if (method_attribute_name == vmSymbols::tag_runtime_invisible_annotations()) {
2337         if (runtime_invisible_annotations_exists) {
2338           classfile_parse_error(
2339             "Multiple RuntimeInvisibleAnnotations attributes for method in class file %s", CHECK_(nullHandle));
2340         }
2341         runtime_invisible_annotations_exists = true;
2342         if (PreserveAllAnnotations) {
2343           runtime_invisible_annotations_length = method_attribute_length;
2344           runtime_invisible_annotations = cfs->get_u1_buffer();
2345           assert(runtime_invisible_annotations != NULL, "null invisible annotations");
2346         }
2347         cfs->skip_u1(method_attribute_length, CHECK_(nullHandle));
2348       } else if (method_attribute_name == vmSymbols::tag_runtime_visible_parameter_annotations()) {
2349         if (runtime_visible_parameter_annotations != NULL) {
2350           classfile_parse_error(
2351             "Multiple RuntimeVisibleParameterAnnotations attributes for method in class file %s", CHECK_(nullHandle));
2352         }
2353         runtime_visible_parameter_annotations_length = method_attribute_length;
2354         runtime_visible_parameter_annotations = cfs->get_u1_buffer();
2355         assert(runtime_visible_parameter_annotations != NULL, "null visible parameter annotations");
2356         cfs->skip_u1(runtime_visible_parameter_annotations_length, CHECK_(nullHandle));
2357       } else if (method_attribute_name == vmSymbols::tag_runtime_invisible_parameter_annotations()) {
2358         if (runtime_invisible_parameter_annotations_exists) {
2359           classfile_parse_error(
2360             "Multiple RuntimeInvisibleParameterAnnotations attributes for method in class file %s", CHECK_(nullHandle));
2361         }
2362         runtime_invisible_parameter_annotations_exists = true;
2363         if (PreserveAllAnnotations) {
2364           runtime_invisible_parameter_annotations_length = method_attribute_length;
2365           runtime_invisible_parameter_annotations = cfs->get_u1_buffer();
2366           assert(runtime_invisible_parameter_annotations != NULL, "null invisible parameter annotations");
2367         }
2368         cfs->skip_u1(method_attribute_length, CHECK_(nullHandle));
2369       } else if (method_attribute_name == vmSymbols::tag_annotation_default()) {
2370         if (annotation_default != NULL) {
2371           classfile_parse_error(
2372             "Multiple AnnotationDefault attributes for method in class file %s",
2373             CHECK_(nullHandle));
2374         }
2375         annotation_default_length = method_attribute_length;
2376         annotation_default = cfs->get_u1_buffer();
2377         assert(annotation_default != NULL, "null annotation default");
2378         cfs->skip_u1(annotation_default_length, CHECK_(nullHandle));
2379       } else if (method_attribute_name == vmSymbols::tag_runtime_visible_type_annotations()) {
2380         if (runtime_visible_type_annotations != NULL) {
2381           classfile_parse_error(
2382             "Multiple RuntimeVisibleTypeAnnotations attributes for method in class file %s",
2383             CHECK_(nullHandle));
2384         }
2385         runtime_visible_type_annotations_length = method_attribute_length;
2386         runtime_visible_type_annotations = cfs->get_u1_buffer();
2387         assert(runtime_visible_type_annotations != NULL, "null visible type annotations");
2388         // No need for the VM to parse Type annotations
2389         cfs->skip_u1(runtime_visible_type_annotations_length, CHECK_(nullHandle));
2390       } else if (method_attribute_name == vmSymbols::tag_runtime_invisible_type_annotations()) {
2391         if (runtime_invisible_type_annotations_exists) {
2392           classfile_parse_error(
2393             "Multiple RuntimeInvisibleTypeAnnotations attributes for method in class file %s",
2394             CHECK_(nullHandle));


2883 void ClassFileParser::parse_classfile_attributes(ClassFileParser::ClassAnnotationCollector* parsed_annotations,
2884                                                  TRAPS) {
2885   ClassFileStream* cfs = stream();
2886   // Set inner classes attribute to default sentinel
2887   _inner_classes = Universe::the_empty_short_array();
2888   cfs->guarantee_more(2, CHECK);  // attributes_count
2889   u2 attributes_count = cfs->get_u2_fast();
2890   bool parsed_sourcefile_attribute = false;
2891   bool parsed_innerclasses_attribute = false;
2892   bool parsed_enclosingmethod_attribute = false;
2893   bool parsed_bootstrap_methods_attribute = false;
2894   u1* runtime_visible_annotations = NULL;
2895   int runtime_visible_annotations_length = 0;
2896   u1* runtime_invisible_annotations = NULL;
2897   int runtime_invisible_annotations_length = 0;
2898   u1* runtime_visible_type_annotations = NULL;
2899   int runtime_visible_type_annotations_length = 0;
2900   u1* runtime_invisible_type_annotations = NULL;
2901   int runtime_invisible_type_annotations_length = 0;
2902   bool runtime_invisible_type_annotations_exists = false;
2903   bool runtime_invisible_annotations_exists = false;
2904   bool parsed_source_debug_ext_annotations_exist = false;
2905   u1* inner_classes_attribute_start = NULL;
2906   u4  inner_classes_attribute_length = 0;
2907   u2  enclosing_method_class_index = 0;
2908   u2  enclosing_method_method_index = 0;
2909   // Iterate over attributes
2910   while (attributes_count--) {
2911     cfs->guarantee_more(6, CHECK);  // attribute_name_index, attribute_length
2912     u2 attribute_name_index = cfs->get_u2_fast();
2913     u4 attribute_length = cfs->get_u4_fast();
2914     check_property(
2915       valid_symbol_at(attribute_name_index),
2916       "Attribute name has bad constant pool index %u in class file %s",
2917       attribute_name_index, CHECK);
2918     Symbol* tag = _cp->symbol_at(attribute_name_index);
2919     if (tag == vmSymbols::tag_source_file()) {
2920       // Check for SourceFile tag
2921       if (_need_verify) {
2922         guarantee_property(attribute_length == 2, "Wrong SourceFile attribute length in class file %s", CHECK);
2923       }
2924       if (parsed_sourcefile_attribute) {
2925         classfile_parse_error("Multiple SourceFile attributes in class file %s", CHECK);
2926       } else {
2927         parsed_sourcefile_attribute = true;
2928       }
2929       parse_classfile_sourcefile_attribute(CHECK);
2930     } else if (tag == vmSymbols::tag_source_debug_extension()) {
2931       // Check for SourceDebugExtension tag
2932       if (parsed_source_debug_ext_annotations_exist) {
2933           classfile_parse_error(
2934             "Multiple SourceDebugExtension attributes in class file %s", CHECK);
2935       }
2936       parsed_source_debug_ext_annotations_exist = true;
2937       parse_classfile_source_debug_extension_attribute((int)attribute_length, CHECK);
2938     } else if (tag == vmSymbols::tag_inner_classes()) {
2939       // Check for InnerClasses tag
2940       if (parsed_innerclasses_attribute) {
2941         classfile_parse_error("Multiple InnerClasses attributes in class file %s", CHECK);
2942       } else {
2943         parsed_innerclasses_attribute = true;
2944       }
2945       inner_classes_attribute_start = cfs->get_u1_buffer();
2946       inner_classes_attribute_length = attribute_length;
2947       cfs->skip_u1(inner_classes_attribute_length, CHECK);
2948     } else if (tag == vmSymbols::tag_synthetic()) {
2949       // Check for Synthetic tag
2950       // Shouldn't we check that the synthetic flags wasn't already set? - not required in spec
2951       if (attribute_length != 0) {
2952         classfile_parse_error(
2953           "Invalid Synthetic classfile attribute length %u in class file %s",
2954           attribute_length, CHECK);
2955       }
2956       parse_classfile_synthetic_attribute(CHECK);
2957     } else if (tag == vmSymbols::tag_deprecated()) {
2958       // Check for Deprecatd tag - 4276120
2959       if (attribute_length != 0) {
2960         classfile_parse_error(
2961           "Invalid Deprecated classfile attribute length %u in class file %s",
2962           attribute_length, CHECK);
2963       }
2964     } else if (_major_version >= JAVA_1_5_VERSION) {
2965       if (tag == vmSymbols::tag_signature()) {
2966         if (attribute_length != 2) {
2967           classfile_parse_error(
2968             "Wrong Signature attribute length %u in class file %s",
2969             attribute_length, CHECK);
2970         }
2971         parse_classfile_signature_attribute(CHECK);
2972       } else if (tag == vmSymbols::tag_runtime_visible_annotations()) {
2973         if (runtime_visible_annotations != NULL) {
2974           classfile_parse_error(
2975             "Multiple RuntimeVisibleAnnotations attributes in class file %s", CHECK);
2976         }
2977         runtime_visible_annotations_length = attribute_length;
2978         runtime_visible_annotations = cfs->get_u1_buffer();
2979         assert(runtime_visible_annotations != NULL, "null visible annotations");
2980         parse_annotations(runtime_visible_annotations,
2981                           runtime_visible_annotations_length,
2982                           parsed_annotations,
2983                           CHECK);
2984         cfs->skip_u1(runtime_visible_annotations_length, CHECK);
2985       } else if (tag == vmSymbols::tag_runtime_invisible_annotations()) {
2986         if (runtime_invisible_annotations_exists) {
2987           classfile_parse_error(
2988             "Multiple RuntimeInvisibleAnnotations attributes in class file %s", CHECK);
2989         }
2990         runtime_invisible_annotations_exists = true;
2991         if (PreserveAllAnnotations) {
2992           runtime_invisible_annotations_length = attribute_length;
2993           runtime_invisible_annotations = cfs->get_u1_buffer();
2994           assert(runtime_invisible_annotations != NULL, "null invisible annotations");
2995         }
2996         cfs->skip_u1(attribute_length, CHECK);
2997       } else if (tag == vmSymbols::tag_enclosing_method()) {
2998         if (parsed_enclosingmethod_attribute) {
2999           classfile_parse_error("Multiple EnclosingMethod attributes in class file %s", CHECK);
3000         }   else {
3001           parsed_enclosingmethod_attribute = true;
3002         }
3003         cfs->guarantee_more(4, CHECK);  // class_index, method_index
3004         enclosing_method_class_index  = cfs->get_u2_fast();
3005         enclosing_method_method_index = cfs->get_u2_fast();
3006         if (enclosing_method_class_index == 0) {
3007           classfile_parse_error("Invalid class index in EnclosingMethod attribute in class file %s", CHECK);
3008         }
3009         // Validate the constant pool indices and types
3010         check_property(valid_klass_reference_at(enclosing_method_class_index),
3011           "Invalid or out-of-bounds class index in EnclosingMethod attribute in class file %s", CHECK);
3012         if (enclosing_method_method_index != 0 &&
3013             (!_cp->is_within_bounds(enclosing_method_method_index) ||
3014              !_cp->tag_at(enclosing_method_method_index).is_name_and_type())) {
3015           classfile_parse_error("Invalid or out-of-bounds method index in EnclosingMethod attribute in class file %s", CHECK);
3016         }


src/share/vm/classfile/classFileParser.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File