< prev index next >

src/share/vm/classfile/classFileParser.cpp

Print this page
rev 10979 : 8140594: Various minor code improvements (compiler)


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");


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


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


< prev index next >