< prev index next >

src/share/vm/classfile/classFileParser.cpp

Print this page
rev 11179 : 8140594: Various minor code improvements (compiler)
Reviewed-by: thartmann


1384 
1385 static FieldAllocationType basic_type_to_atype(bool is_static, BasicType type) {
1386   assert(type >= T_BOOLEAN && type < T_VOID, "only allowable values");
1387   FieldAllocationType result = _basic_type_to_atype[type + (is_static ? (T_CONFLICT + 1) : 0)];
1388   assert(result != BAD_ALLOCATION_TYPE, "bad type");
1389   return result;
1390 }
1391 
1392 class ClassFileParser::FieldAllocationCount : public ResourceObj {
1393  public:
1394   u2 count[MAX_FIELD_ALLOCATION_TYPE];
1395 
1396   FieldAllocationCount() {
1397     for (int i = 0; i < MAX_FIELD_ALLOCATION_TYPE; i++) {
1398       count[i] = 0;
1399     }
1400   }
1401 
1402   FieldAllocationType update(bool is_static, BasicType type) {
1403     FieldAllocationType atype = basic_type_to_atype(is_static, type);

1404     // Make sure there is no overflow with injected fields.
1405     assert(count[atype] < 0xFFFF, "More than 65535 fields");
1406     count[atype]++;

1407     return atype;
1408   }
1409 };
1410 
1411 // Side-effects: populates the _fields, _fields_annotations,
1412 // _fields_type_annotations fields
1413 void ClassFileParser::parse_fields(const ClassFileStream* const cfs,
1414                                    bool is_interface,
1415                                    FieldAllocationCount* const fac,
1416                                    ConstantPool* cp,
1417                                    const int cp_size,
1418                                    u2* const java_fields_count_ptr,
1419                                    TRAPS) {
1420 
1421   assert(cfs != NULL, "invariant");
1422   assert(fac != NULL, "invariant");
1423   assert(cp != NULL, "invariant");
1424   assert(java_fields_count_ptr != NULL, "invariant");
1425 
1426   assert(NULL == _fields, "invariant");


3318         }
3319         guarantee_property(attribute_length == 4,
3320           "Wrong EnclosingMethod attribute length %u in class file %s",
3321           attribute_length, CHECK);
3322         cfs->guarantee_more(4, CHECK);  // class_index, method_index
3323         enclosing_method_class_index  = cfs->get_u2_fast();
3324         enclosing_method_method_index = cfs->get_u2_fast();
3325         if (enclosing_method_class_index == 0) {
3326           classfile_parse_error("Invalid class index in EnclosingMethod attribute in class file %s", CHECK);
3327         }
3328         // Validate the constant pool indices and types
3329         check_property(valid_klass_reference_at(enclosing_method_class_index),
3330           "Invalid or out-of-bounds class index in EnclosingMethod attribute in class file %s", CHECK);
3331         if (enclosing_method_method_index != 0 &&
3332             (!cp->is_within_bounds(enclosing_method_method_index) ||
3333              !cp->tag_at(enclosing_method_method_index).is_name_and_type())) {
3334           classfile_parse_error("Invalid or out-of-bounds method index in EnclosingMethod attribute in class file %s", CHECK);
3335         }
3336       } else if (tag == vmSymbols::tag_bootstrap_methods() &&
3337                  _major_version >= Verifier::INVOKEDYNAMIC_MAJOR_VERSION) {
3338         if (parsed_bootstrap_methods_attribute)
3339           classfile_parse_error("Multiple BootstrapMethods attributes in class file %s", CHECK);

3340         parsed_bootstrap_methods_attribute = true;
3341         parse_classfile_bootstrap_methods_attribute(cfs, cp, attribute_length, CHECK);
3342       } else if (tag == vmSymbols::tag_runtime_visible_type_annotations()) {
3343         if (runtime_visible_type_annotations != NULL) {
3344           classfile_parse_error(
3345             "Multiple RuntimeVisibleTypeAnnotations attributes in class file %s", CHECK);
3346         }
3347         runtime_visible_type_annotations_length = attribute_length;
3348         runtime_visible_type_annotations = cfs->get_u1_buffer();
3349         assert(runtime_visible_type_annotations != NULL, "null visible type annotations");
3350         // No need for the VM to parse Type annotations
3351         cfs->skip_u1(runtime_visible_type_annotations_length, CHECK);
3352       } else if (tag == vmSymbols::tag_runtime_invisible_type_annotations()) {
3353         if (runtime_invisible_type_annotations_exists) {
3354           classfile_parse_error(
3355             "Multiple RuntimeInvisibleTypeAnnotations attributes in class file %s", CHECK);
3356         } else {
3357           runtime_invisible_type_annotations_exists = true;
3358         }
3359         if (PreserveAllAnnotations) {




1384 
1385 static FieldAllocationType basic_type_to_atype(bool is_static, BasicType type) {
1386   assert(type >= T_BOOLEAN && type < T_VOID, "only allowable values");
1387   FieldAllocationType result = _basic_type_to_atype[type + (is_static ? (T_CONFLICT + 1) : 0)];
1388   assert(result != BAD_ALLOCATION_TYPE, "bad type");
1389   return result;
1390 }
1391 
1392 class ClassFileParser::FieldAllocationCount : public ResourceObj {
1393  public:
1394   u2 count[MAX_FIELD_ALLOCATION_TYPE];
1395 
1396   FieldAllocationCount() {
1397     for (int i = 0; i < MAX_FIELD_ALLOCATION_TYPE; i++) {
1398       count[i] = 0;
1399     }
1400   }
1401 
1402   FieldAllocationType update(bool is_static, BasicType type) {
1403     FieldAllocationType atype = basic_type_to_atype(is_static, type);
1404     if (atype != BAD_ALLOCATION_TYPE) {
1405       // Make sure there is no overflow with injected fields.
1406       assert(count[atype] < 0xFFFF, "More than 65535 fields");
1407       count[atype]++;
1408     }
1409     return atype;
1410   }
1411 };
1412 
1413 // Side-effects: populates the _fields, _fields_annotations,
1414 // _fields_type_annotations fields
1415 void ClassFileParser::parse_fields(const ClassFileStream* const cfs,
1416                                    bool is_interface,
1417                                    FieldAllocationCount* const fac,
1418                                    ConstantPool* cp,
1419                                    const int cp_size,
1420                                    u2* const java_fields_count_ptr,
1421                                    TRAPS) {
1422 
1423   assert(cfs != NULL, "invariant");
1424   assert(fac != NULL, "invariant");
1425   assert(cp != NULL, "invariant");
1426   assert(java_fields_count_ptr != NULL, "invariant");
1427 
1428   assert(NULL == _fields, "invariant");


3320         }
3321         guarantee_property(attribute_length == 4,
3322           "Wrong EnclosingMethod attribute length %u in class file %s",
3323           attribute_length, CHECK);
3324         cfs->guarantee_more(4, CHECK);  // class_index, method_index
3325         enclosing_method_class_index  = cfs->get_u2_fast();
3326         enclosing_method_method_index = cfs->get_u2_fast();
3327         if (enclosing_method_class_index == 0) {
3328           classfile_parse_error("Invalid class index in EnclosingMethod attribute in class file %s", CHECK);
3329         }
3330         // Validate the constant pool indices and types
3331         check_property(valid_klass_reference_at(enclosing_method_class_index),
3332           "Invalid or out-of-bounds class index in EnclosingMethod attribute in class file %s", CHECK);
3333         if (enclosing_method_method_index != 0 &&
3334             (!cp->is_within_bounds(enclosing_method_method_index) ||
3335              !cp->tag_at(enclosing_method_method_index).is_name_and_type())) {
3336           classfile_parse_error("Invalid or out-of-bounds method index in EnclosingMethod attribute in class file %s", CHECK);
3337         }
3338       } else if (tag == vmSymbols::tag_bootstrap_methods() &&
3339                  _major_version >= Verifier::INVOKEDYNAMIC_MAJOR_VERSION) {
3340         if (parsed_bootstrap_methods_attribute) {
3341           classfile_parse_error("Multiple BootstrapMethods attributes in class file %s", CHECK);
3342         }
3343         parsed_bootstrap_methods_attribute = true;
3344         parse_classfile_bootstrap_methods_attribute(cfs, cp, attribute_length, CHECK);
3345       } else if (tag == vmSymbols::tag_runtime_visible_type_annotations()) {
3346         if (runtime_visible_type_annotations != NULL) {
3347           classfile_parse_error(
3348             "Multiple RuntimeVisibleTypeAnnotations attributes in class file %s", CHECK);
3349         }
3350         runtime_visible_type_annotations_length = attribute_length;
3351         runtime_visible_type_annotations = cfs->get_u1_buffer();
3352         assert(runtime_visible_type_annotations != NULL, "null visible type annotations");
3353         // No need for the VM to parse Type annotations
3354         cfs->skip_u1(runtime_visible_type_annotations_length, CHECK);
3355       } else if (tag == vmSymbols::tag_runtime_invisible_type_annotations()) {
3356         if (runtime_invisible_type_annotations_exists) {
3357           classfile_parse_error(
3358             "Multiple RuntimeInvisibleTypeAnnotations attributes in class file %s", CHECK);
3359         } else {
3360           runtime_invisible_type_annotations_exists = true;
3361         }
3362         if (PreserveAllAnnotations) {


< prev index next >