3142 assert((length+1) > length, "Overflow checking");
3143 u1* const sde = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, u1, length+1);
3144 for (int i = 0; i < length; i++) {
3145 sde[i] = sde_buffer[i];
3146 }
3147 sde[length] = '\0';
3148 set_class_sde_buffer((const char*)sde, length);
3149 }
3150 // Got utf8 string, set stream position forward
3151 cfs->skip_u1(length, CHECK);
3152 }
3153
3154
3155 // Inner classes can be static, private or protected (classic VM does this)
3156 #define RECOGNIZED_INNER_CLASS_MODIFIERS ( JVM_RECOGNIZED_CLASS_MODIFIERS | \
3157 JVM_ACC_PRIVATE | \
3158 JVM_ACC_PROTECTED | \
3159 JVM_ACC_STATIC \
3160 )
3161
3162 // Return number of classes in the inner classes attribute table
3163 u2 ClassFileParser::parse_classfile_inner_classes_attribute(const ClassFileStream* const cfs,
3164 const u1* const inner_classes_attribute_start,
3165 bool parsed_enclosingmethod_attribute,
3166 u2 enclosing_method_class_index,
3167 u2 enclosing_method_method_index,
3168 TRAPS) {
3169 const u1* const current_mark = cfs->current();
3170 u2 length = 0;
3171 if (inner_classes_attribute_start != NULL) {
3172 cfs->set_current(inner_classes_attribute_start);
3173 cfs->guarantee_more(2, CHECK_0); // length
3174 length = cfs->get_u2_fast();
3175 }
3176
3177 // 4-tuples of shorts of inner classes data and 2 shorts of enclosing
3178 // method data:
3179 // [inner_class_info_index,
3180 // outer_class_info_index,
3181 // inner_name_index,
3362 }
3363 guarantee_property(current_start + attribute_byte_length == cfs->current(),
3364 "Bad length on BootstrapMethods in class file %s",
3365 CHECK);
3366 }
3367
3368 void ClassFileParser::parse_classfile_attributes(const ClassFileStream* const cfs,
3369 ConstantPool* cp,
3370 ClassFileParser::ClassAnnotationCollector* parsed_annotations,
3371 TRAPS) {
3372 assert(cfs != NULL, "invariant");
3373 assert(cp != NULL, "invariant");
3374 assert(parsed_annotations != NULL, "invariant");
3375
3376 // Set inner classes attribute to default sentinel
3377 _inner_classes = Universe::the_empty_short_array();
3378 cfs->guarantee_more(2, CHECK); // attributes_count
3379 u2 attributes_count = cfs->get_u2_fast();
3380 bool parsed_sourcefile_attribute = false;
3381 bool parsed_innerclasses_attribute = false;
3382 bool parsed_enclosingmethod_attribute = false;
3383 bool parsed_bootstrap_methods_attribute = false;
3384 const u1* runtime_visible_annotations = NULL;
3385 int runtime_visible_annotations_length = 0;
3386 const u1* runtime_invisible_annotations = NULL;
3387 int runtime_invisible_annotations_length = 0;
3388 const u1* runtime_visible_type_annotations = NULL;
3389 int runtime_visible_type_annotations_length = 0;
3390 const u1* runtime_invisible_type_annotations = NULL;
3391 int runtime_invisible_type_annotations_length = 0;
3392 bool runtime_invisible_type_annotations_exists = false;
3393 bool runtime_invisible_annotations_exists = false;
3394 bool parsed_source_debug_ext_annotations_exist = false;
3395 const u1* inner_classes_attribute_start = NULL;
3396 u4 inner_classes_attribute_length = 0;
3397 u2 enclosing_method_class_index = 0;
3398 u2 enclosing_method_method_index = 0;
3399 // Iterate over attributes
3400 while (attributes_count--) {
3401 cfs->guarantee_more(6, CHECK); // attribute_name_index, attribute_length
3402 const u2 attribute_name_index = cfs->get_u2_fast();
3403 const u4 attribute_length = cfs->get_u4_fast();
3404 check_property(
3405 valid_symbol_at(attribute_name_index),
3406 "Attribute name has bad constant pool index %u in class file %s",
3407 attribute_name_index, CHECK);
3408 const Symbol* const tag = cp->symbol_at(attribute_name_index);
3409 if (tag == vmSymbols::tag_source_file()) {
3410 // Check for SourceFile tag
3411 if (_need_verify) {
3412 guarantee_property(attribute_length == 2, "Wrong SourceFile attribute length in class file %s", CHECK);
3413 }
3414 if (parsed_sourcefile_attribute) {
3415 classfile_parse_error("Multiple SourceFile attributes in class file %s", CHECK);
3416 } else {
3418 }
3419 parse_classfile_sourcefile_attribute(cfs, CHECK);
3420 } else if (tag == vmSymbols::tag_source_debug_extension()) {
3421 // Check for SourceDebugExtension tag
3422 if (parsed_source_debug_ext_annotations_exist) {
3423 classfile_parse_error(
3424 "Multiple SourceDebugExtension attributes in class file %s", CHECK);
3425 }
3426 parsed_source_debug_ext_annotations_exist = true;
3427 parse_classfile_source_debug_extension_attribute(cfs, (int)attribute_length, CHECK);
3428 } else if (tag == vmSymbols::tag_inner_classes()) {
3429 // Check for InnerClasses tag
3430 if (parsed_innerclasses_attribute) {
3431 classfile_parse_error("Multiple InnerClasses attributes in class file %s", CHECK);
3432 } else {
3433 parsed_innerclasses_attribute = true;
3434 }
3435 inner_classes_attribute_start = cfs->current();
3436 inner_classes_attribute_length = attribute_length;
3437 cfs->skip_u1(inner_classes_attribute_length, CHECK);
3438 } else if (tag == vmSymbols::tag_synthetic()) {
3439 // Check for Synthetic tag
3440 // Shouldn't we check that the synthetic flags wasn't already set? - not required in spec
3441 if (attribute_length != 0) {
3442 classfile_parse_error(
3443 "Invalid Synthetic classfile attribute length %u in class file %s",
3444 attribute_length, CHECK);
3445 }
3446 parse_classfile_synthetic_attribute(CHECK);
3447 } else if (tag == vmSymbols::tag_deprecated()) {
3448 // Check for Deprecatd tag - 4276120
3449 if (attribute_length != 0) {
3450 classfile_parse_error(
3451 "Invalid Deprecated classfile attribute length %u in class file %s",
3452 attribute_length, CHECK);
3453 }
3454 } else if (_major_version >= JAVA_1_5_VERSION) {
3455 if (tag == vmSymbols::tag_signature()) {
3456 if (_generic_signature_index != 0) {
3457 classfile_parse_error(
3562 runtime_visible_type_annotations_length,
3563 runtime_invisible_type_annotations,
3564 runtime_invisible_type_annotations_length,
3565 CHECK);
3566
3567 if (parsed_innerclasses_attribute || parsed_enclosingmethod_attribute) {
3568 const u2 num_of_classes = parse_classfile_inner_classes_attribute(
3569 cfs,
3570 inner_classes_attribute_start,
3571 parsed_innerclasses_attribute,
3572 enclosing_method_class_index,
3573 enclosing_method_method_index,
3574 CHECK);
3575 if (parsed_innerclasses_attribute &&_need_verify && _major_version >= JAVA_1_5_VERSION) {
3576 guarantee_property(
3577 inner_classes_attribute_length == sizeof(num_of_classes) + 4 * sizeof(u2) * num_of_classes,
3578 "Wrong InnerClasses attribute length in class file %s", CHECK);
3579 }
3580 }
3581
3582 if (_max_bootstrap_specifier_index >= 0) {
3583 guarantee_property(parsed_bootstrap_methods_attribute,
3584 "Missing BootstrapMethods attribute in class file %s", CHECK);
3585 }
3586 }
3587
3588 void ClassFileParser::apply_parsed_class_attributes(InstanceKlass* k) {
3589 assert(k != NULL, "invariant");
3590
3591 if (_synthetic_flag)
3592 k->set_is_synthetic();
3593 if (_sourcefile_index != 0) {
3594 k->set_source_file_name_index(_sourcefile_index);
3595 }
3596 if (_generic_signature_index != 0) {
3597 k->set_generic_signature_index(_generic_signature_index);
3598 }
3599 if (_sde_buffer != NULL) {
3600 k->set_source_debug_extension(_sde_buffer, _sde_length);
3601 }
3624
3625 // The annotations arrays below has been transfered the
3626 // _combined_annotations so these fields can now be cleared.
3627 _annotations = NULL;
3628 _type_annotations = NULL;
3629 _fields_annotations = NULL;
3630 _fields_type_annotations = NULL;
3631 }
3632
3633 // Transfer ownership of metadata allocated to the InstanceKlass.
3634 void ClassFileParser::apply_parsed_class_metadata(
3635 InstanceKlass* this_klass,
3636 int java_fields_count, TRAPS) {
3637 assert(this_klass != NULL, "invariant");
3638
3639 _cp->set_pool_holder(this_klass);
3640 this_klass->set_constants(_cp);
3641 this_klass->set_fields(_fields, java_fields_count);
3642 this_klass->set_methods(_methods);
3643 this_klass->set_inner_classes(_inner_classes);
3644 this_klass->set_local_interfaces(_local_interfaces);
3645 this_klass->set_transitive_interfaces(_transitive_interfaces);
3646 this_klass->set_annotations(_combined_annotations);
3647
3648 // Clear out these fields so they don't get deallocated by the destructor
3649 clear_class_metadata();
3650 }
3651
3652 AnnotationArray* ClassFileParser::assemble_annotations(const u1* const runtime_visible_annotations,
3653 int runtime_visible_annotations_length,
3654 const u1* const runtime_invisible_annotations,
3655 int runtime_invisible_annotations_length,
3656 TRAPS) {
3657 AnnotationArray* annotations = NULL;
3658 if (runtime_visible_annotations != NULL ||
3659 runtime_invisible_annotations != NULL) {
3660 annotations = MetadataFactory::new_array<u1>(_loader_data,
3661 runtime_visible_annotations_length +
3662 runtime_invisible_annotations_length,
3663 CHECK_(annotations));
4012 for (int i = 0; i < max_nonstatic_value_type; i++) {
4013 nonstatic_value_type_indexes[i] = -1;
4014 }
4015 nonstatic_value_type_klasses = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, Klass*,
4016 max_nonstatic_value_type);
4017
4018 for (AllFieldStream fs(_fields, _cp); !fs.done(); fs.next()) {
4019 if (fs.allocation_type() == STATIC_FLATTENABLE) {
4020 // Pre-resolve the flattenable field and check for value type circularity
4021 // issues. Note that super-class circularity checks are not needed here
4022 // because flattenable fields can only be in value types and value types
4023 // only have java.lang.Object as their super class.
4024 // Also, note that super-interface circularity checks are not needed
4025 // because interfaces cannot be value types.
4026 Klass* klass =
4027 SystemDictionary::resolve_flattenable_field_or_fail(&fs,
4028 Handle(THREAD, _loader_data->class_loader()),
4029 _protection_domain, true, CHECK);
4030 assert(klass != NULL, "Sanity check");
4031 assert(klass->access_flags().is_value_type(), "Value type expected");
4032 static_value_type_count++;
4033 } else if (fs.allocation_type() == NONSTATIC_FLATTENABLE) {
4034 // Pre-resolve the flattenable field and check for value type circularity issues.
4035 Klass* klass =
4036 SystemDictionary::resolve_flattenable_field_or_fail(&fs,
4037 Handle(THREAD, _loader_data->class_loader()),
4038 _protection_domain, true, CHECK);
4039 assert(klass != NULL, "Sanity check");
4040 assert(klass->access_flags().is_value_type(), "Value type expected");
4041 ValueKlass* vk = ValueKlass::cast(klass);
4042 // Conditions to apply flattening or not should be defined in a single place
4043 if ((ValueFieldMaxFlatSize < 0) || (vk->size_helper() * HeapWordSize) <= ValueFieldMaxFlatSize) {
4044 nonstatic_value_type_indexes[nonstatic_value_type_count] = fs.index();
4045 nonstatic_value_type_klasses[nonstatic_value_type_count] = klass;
4046 nonstatic_value_type_count++;
4047
4048 ValueKlass* vklass = ValueKlass::cast(klass);
4049 if (vklass->contains_oops()) {
4050 value_type_oop_map_count += vklass->nonstatic_oop_map_count();
4051 }
4052 fs.set_flattened(true);
4053 } else {
4054 not_flattened_value_types++;
4055 fs.set_flattened(false);
4056 }
4057 }
4058 }
4059
4060 // Adjusting non_static_oop_count to take into account not flattened value types;
5925 ClassLoaderData* loader_data,
5926 Handle protection_domain,
5927 const InstanceKlass* host_klass,
5928 GrowableArray<Handle>* cp_patches,
5929 Publicity pub_level,
5930 TRAPS) :
5931 _stream(stream),
5932 _requested_name(name),
5933 _loader_data(loader_data),
5934 _host_klass(host_klass),
5935 _cp_patches(cp_patches),
5936 _num_patched_klasses(0),
5937 _max_num_patched_klasses(0),
5938 _orig_cp_size(0),
5939 _first_patched_klass_resolved_index(0),
5940 _super_klass(),
5941 _cp(NULL),
5942 _fields(NULL),
5943 _methods(NULL),
5944 _inner_classes(NULL),
5945 _local_interfaces(NULL),
5946 _transitive_interfaces(NULL),
5947 _combined_annotations(NULL),
5948 _annotations(NULL),
5949 _type_annotations(NULL),
5950 _fields_annotations(NULL),
5951 _fields_type_annotations(NULL),
5952 _klass(NULL),
5953 _klass_to_deallocate(NULL),
5954 _parsed_annotations(NULL),
5955 _fac(NULL),
5956 _field_info(NULL),
5957 _method_ordering(NULL),
5958 _all_mirandas(NULL),
5959 _vtable_size(0),
5960 _itable_size(0),
5961 _num_miranda_methods(0),
5962 _rt(REF_NONE),
5963 _protection_domain(protection_domain),
5964 _access_flags(),
|
3142 assert((length+1) > length, "Overflow checking");
3143 u1* const sde = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, u1, length+1);
3144 for (int i = 0; i < length; i++) {
3145 sde[i] = sde_buffer[i];
3146 }
3147 sde[length] = '\0';
3148 set_class_sde_buffer((const char*)sde, length);
3149 }
3150 // Got utf8 string, set stream position forward
3151 cfs->skip_u1(length, CHECK);
3152 }
3153
3154
3155 // Inner classes can be static, private or protected (classic VM does this)
3156 #define RECOGNIZED_INNER_CLASS_MODIFIERS ( JVM_RECOGNIZED_CLASS_MODIFIERS | \
3157 JVM_ACC_PRIVATE | \
3158 JVM_ACC_PROTECTED | \
3159 JVM_ACC_STATIC \
3160 )
3161
3162 u2 ClassFileParser::parse_value_types_attribute(const ClassFileStream* const cfs,
3163 const u1* const value_types_attribute_start,
3164 TRAPS) {
3165 const u1* const current_mark = cfs->current();
3166 u2 length = 0;
3167 if (value_types_attribute_start != NULL) {
3168 cfs->set_current(value_types_attribute_start);
3169 cfs->guarantee_more(2, CHECK_0); // length
3170 length = cfs->get_u2_fast();
3171 }
3172 Array<ValueTypes>* const value_types = MetadataFactory::new_array<ValueTypes>(_loader_data, length, CHECK_0);
3173
3174 int index = 0;
3175 const int cp_size = _cp->length();
3176 cfs->guarantee_more(2 *length, CHECK_0);
3177 for (int n = 0; n < length; n++) {
3178 // Value types class index
3179 const u2 value_types_info_index = cfs->get_u2_fast();
3180 check_property(
3181 valid_klass_reference_at(value_types_info_index),
3182 "value_types_info_index %u has bad constant type in class file %s",
3183 value_types_info_index, CHECK_0);
3184 ValueTypes vt;
3185 vt._class_info_index = value_types_info_index;
3186 vt._class_name = NULL;
3187 value_types->at_put(index++, vt);
3188 }
3189 _value_types = value_types;
3190 // Restore buffer's current position.
3191 cfs->set_current(current_mark);
3192
3193 return length;
3194 }
3195
3196 // Return number of classes in the inner classes attribute table
3197 u2 ClassFileParser::parse_classfile_inner_classes_attribute(const ClassFileStream* const cfs,
3198 const u1* const inner_classes_attribute_start,
3199 bool parsed_enclosingmethod_attribute,
3200 u2 enclosing_method_class_index,
3201 u2 enclosing_method_method_index,
3202 TRAPS) {
3203 const u1* const current_mark = cfs->current();
3204 u2 length = 0;
3205 if (inner_classes_attribute_start != NULL) {
3206 cfs->set_current(inner_classes_attribute_start);
3207 cfs->guarantee_more(2, CHECK_0); // length
3208 length = cfs->get_u2_fast();
3209 }
3210
3211 // 4-tuples of shorts of inner classes data and 2 shorts of enclosing
3212 // method data:
3213 // [inner_class_info_index,
3214 // outer_class_info_index,
3215 // inner_name_index,
3396 }
3397 guarantee_property(current_start + attribute_byte_length == cfs->current(),
3398 "Bad length on BootstrapMethods in class file %s",
3399 CHECK);
3400 }
3401
3402 void ClassFileParser::parse_classfile_attributes(const ClassFileStream* const cfs,
3403 ConstantPool* cp,
3404 ClassFileParser::ClassAnnotationCollector* parsed_annotations,
3405 TRAPS) {
3406 assert(cfs != NULL, "invariant");
3407 assert(cp != NULL, "invariant");
3408 assert(parsed_annotations != NULL, "invariant");
3409
3410 // Set inner classes attribute to default sentinel
3411 _inner_classes = Universe::the_empty_short_array();
3412 cfs->guarantee_more(2, CHECK); // attributes_count
3413 u2 attributes_count = cfs->get_u2_fast();
3414 bool parsed_sourcefile_attribute = false;
3415 bool parsed_innerclasses_attribute = false;
3416 bool parsed_value_types_attribute = false;
3417 bool parsed_enclosingmethod_attribute = false;
3418 bool parsed_bootstrap_methods_attribute = false;
3419 const u1* runtime_visible_annotations = NULL;
3420 int runtime_visible_annotations_length = 0;
3421 const u1* runtime_invisible_annotations = NULL;
3422 int runtime_invisible_annotations_length = 0;
3423 const u1* runtime_visible_type_annotations = NULL;
3424 int runtime_visible_type_annotations_length = 0;
3425 const u1* runtime_invisible_type_annotations = NULL;
3426 int runtime_invisible_type_annotations_length = 0;
3427 bool runtime_invisible_type_annotations_exists = false;
3428 bool runtime_invisible_annotations_exists = false;
3429 bool parsed_source_debug_ext_annotations_exist = false;
3430 const u1* inner_classes_attribute_start = NULL;
3431 u4 inner_classes_attribute_length = 0;
3432 const u1* value_types_attribute_start = NULL;
3433 u4 value_types_attribute_length = 0;
3434 u2 enclosing_method_class_index = 0;
3435 u2 enclosing_method_method_index = 0;
3436 // Iterate over attributes
3437 while (attributes_count--) {
3438 cfs->guarantee_more(6, CHECK); // attribute_name_index, attribute_length
3439 const u2 attribute_name_index = cfs->get_u2_fast();
3440 const u4 attribute_length = cfs->get_u4_fast();
3441 check_property(
3442 valid_symbol_at(attribute_name_index),
3443 "Attribute name has bad constant pool index %u in class file %s",
3444 attribute_name_index, CHECK);
3445 const Symbol* const tag = cp->symbol_at(attribute_name_index);
3446 if (tag == vmSymbols::tag_source_file()) {
3447 // Check for SourceFile tag
3448 if (_need_verify) {
3449 guarantee_property(attribute_length == 2, "Wrong SourceFile attribute length in class file %s", CHECK);
3450 }
3451 if (parsed_sourcefile_attribute) {
3452 classfile_parse_error("Multiple SourceFile attributes in class file %s", CHECK);
3453 } else {
3455 }
3456 parse_classfile_sourcefile_attribute(cfs, CHECK);
3457 } else if (tag == vmSymbols::tag_source_debug_extension()) {
3458 // Check for SourceDebugExtension tag
3459 if (parsed_source_debug_ext_annotations_exist) {
3460 classfile_parse_error(
3461 "Multiple SourceDebugExtension attributes in class file %s", CHECK);
3462 }
3463 parsed_source_debug_ext_annotations_exist = true;
3464 parse_classfile_source_debug_extension_attribute(cfs, (int)attribute_length, CHECK);
3465 } else if (tag == vmSymbols::tag_inner_classes()) {
3466 // Check for InnerClasses tag
3467 if (parsed_innerclasses_attribute) {
3468 classfile_parse_error("Multiple InnerClasses attributes in class file %s", CHECK);
3469 } else {
3470 parsed_innerclasses_attribute = true;
3471 }
3472 inner_classes_attribute_start = cfs->current();
3473 inner_classes_attribute_length = attribute_length;
3474 cfs->skip_u1(inner_classes_attribute_length, CHECK);
3475 } else if (tag == vmSymbols::tag_value_types()) {
3476 // Check for ValueTypes tag
3477 if (parsed_value_types_attribute) {
3478 classfile_parse_error("Multiple ValueTypes attributes in class file %s", CHECK);
3479 } else {
3480 parsed_value_types_attribute = true;
3481 }
3482 value_types_attribute_start = cfs->current();
3483 value_types_attribute_length = attribute_length;
3484 cfs->skip_u1(value_types_attribute_length, CHECK);
3485 } else if (tag == vmSymbols::tag_synthetic()) {
3486 // Check for Synthetic tag
3487 // Shouldn't we check that the synthetic flags wasn't already set? - not required in spec
3488 if (attribute_length != 0) {
3489 classfile_parse_error(
3490 "Invalid Synthetic classfile attribute length %u in class file %s",
3491 attribute_length, CHECK);
3492 }
3493 parse_classfile_synthetic_attribute(CHECK);
3494 } else if (tag == vmSymbols::tag_deprecated()) {
3495 // Check for Deprecatd tag - 4276120
3496 if (attribute_length != 0) {
3497 classfile_parse_error(
3498 "Invalid Deprecated classfile attribute length %u in class file %s",
3499 attribute_length, CHECK);
3500 }
3501 } else if (_major_version >= JAVA_1_5_VERSION) {
3502 if (tag == vmSymbols::tag_signature()) {
3503 if (_generic_signature_index != 0) {
3504 classfile_parse_error(
3609 runtime_visible_type_annotations_length,
3610 runtime_invisible_type_annotations,
3611 runtime_invisible_type_annotations_length,
3612 CHECK);
3613
3614 if (parsed_innerclasses_attribute || parsed_enclosingmethod_attribute) {
3615 const u2 num_of_classes = parse_classfile_inner_classes_attribute(
3616 cfs,
3617 inner_classes_attribute_start,
3618 parsed_innerclasses_attribute,
3619 enclosing_method_class_index,
3620 enclosing_method_method_index,
3621 CHECK);
3622 if (parsed_innerclasses_attribute &&_need_verify && _major_version >= JAVA_1_5_VERSION) {
3623 guarantee_property(
3624 inner_classes_attribute_length == sizeof(num_of_classes) + 4 * sizeof(u2) * num_of_classes,
3625 "Wrong InnerClasses attribute length in class file %s", CHECK);
3626 }
3627 }
3628
3629 if (parsed_value_types_attribute) {
3630 parse_value_types_attribute(cfs, value_types_attribute_start, CHECK);
3631 }
3632
3633 if (_max_bootstrap_specifier_index >= 0) {
3634 guarantee_property(parsed_bootstrap_methods_attribute,
3635 "Missing BootstrapMethods attribute in class file %s", CHECK);
3636 }
3637 }
3638
3639 void ClassFileParser::apply_parsed_class_attributes(InstanceKlass* k) {
3640 assert(k != NULL, "invariant");
3641
3642 if (_synthetic_flag)
3643 k->set_is_synthetic();
3644 if (_sourcefile_index != 0) {
3645 k->set_source_file_name_index(_sourcefile_index);
3646 }
3647 if (_generic_signature_index != 0) {
3648 k->set_generic_signature_index(_generic_signature_index);
3649 }
3650 if (_sde_buffer != NULL) {
3651 k->set_source_debug_extension(_sde_buffer, _sde_length);
3652 }
3675
3676 // The annotations arrays below has been transfered the
3677 // _combined_annotations so these fields can now be cleared.
3678 _annotations = NULL;
3679 _type_annotations = NULL;
3680 _fields_annotations = NULL;
3681 _fields_type_annotations = NULL;
3682 }
3683
3684 // Transfer ownership of metadata allocated to the InstanceKlass.
3685 void ClassFileParser::apply_parsed_class_metadata(
3686 InstanceKlass* this_klass,
3687 int java_fields_count, TRAPS) {
3688 assert(this_klass != NULL, "invariant");
3689
3690 _cp->set_pool_holder(this_klass);
3691 this_klass->set_constants(_cp);
3692 this_klass->set_fields(_fields, java_fields_count);
3693 this_klass->set_methods(_methods);
3694 this_klass->set_inner_classes(_inner_classes);
3695 this_klass->set_value_types(_value_types);
3696 this_klass->set_local_interfaces(_local_interfaces);
3697 this_klass->set_transitive_interfaces(_transitive_interfaces);
3698 this_klass->set_annotations(_combined_annotations);
3699
3700 // Clear out these fields so they don't get deallocated by the destructor
3701 clear_class_metadata();
3702 }
3703
3704 AnnotationArray* ClassFileParser::assemble_annotations(const u1* const runtime_visible_annotations,
3705 int runtime_visible_annotations_length,
3706 const u1* const runtime_invisible_annotations,
3707 int runtime_invisible_annotations_length,
3708 TRAPS) {
3709 AnnotationArray* annotations = NULL;
3710 if (runtime_visible_annotations != NULL ||
3711 runtime_invisible_annotations != NULL) {
3712 annotations = MetadataFactory::new_array<u1>(_loader_data,
3713 runtime_visible_annotations_length +
3714 runtime_invisible_annotations_length,
3715 CHECK_(annotations));
4064 for (int i = 0; i < max_nonstatic_value_type; i++) {
4065 nonstatic_value_type_indexes[i] = -1;
4066 }
4067 nonstatic_value_type_klasses = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, Klass*,
4068 max_nonstatic_value_type);
4069
4070 for (AllFieldStream fs(_fields, _cp); !fs.done(); fs.next()) {
4071 if (fs.allocation_type() == STATIC_FLATTENABLE) {
4072 // Pre-resolve the flattenable field and check for value type circularity
4073 // issues. Note that super-class circularity checks are not needed here
4074 // because flattenable fields can only be in value types and value types
4075 // only have java.lang.Object as their super class.
4076 // Also, note that super-interface circularity checks are not needed
4077 // because interfaces cannot be value types.
4078 Klass* klass =
4079 SystemDictionary::resolve_flattenable_field_or_fail(&fs,
4080 Handle(THREAD, _loader_data->class_loader()),
4081 _protection_domain, true, CHECK);
4082 assert(klass != NULL, "Sanity check");
4083 assert(klass->access_flags().is_value_type(), "Value type expected");
4084 assert(InstanceKlass::is_declared_value_type(_cp, _value_types, klass->name()),
4085 "Flattenable fields' type must be listed in the ValueTypes attribute");
4086 static_value_type_count++;
4087 } else if (fs.allocation_type() == NONSTATIC_FLATTENABLE) {
4088 // Pre-resolve the flattenable field and check for value type circularity issues.
4089 Klass* klass =
4090 SystemDictionary::resolve_flattenable_field_or_fail(&fs,
4091 Handle(THREAD, _loader_data->class_loader()),
4092 _protection_domain, true, CHECK);
4093 assert(klass != NULL, "Sanity check");
4094 assert(klass->access_flags().is_value_type(), "Value type expected");
4095 assert(InstanceKlass::is_declared_value_type(_cp, _value_types, klass->name()),
4096 "Flattenable fields' type must be listed in the ValueTypes attribute");
4097 ValueKlass* vk = ValueKlass::cast(klass);
4098 // Conditions to apply flattening or not should be defined in a single place
4099 if ((ValueFieldMaxFlatSize < 0) || (vk->size_helper() * HeapWordSize) <= ValueFieldMaxFlatSize) {
4100 nonstatic_value_type_indexes[nonstatic_value_type_count] = fs.index();
4101 nonstatic_value_type_klasses[nonstatic_value_type_count] = klass;
4102 nonstatic_value_type_count++;
4103
4104 ValueKlass* vklass = ValueKlass::cast(klass);
4105 if (vklass->contains_oops()) {
4106 value_type_oop_map_count += vklass->nonstatic_oop_map_count();
4107 }
4108 fs.set_flattened(true);
4109 } else {
4110 not_flattened_value_types++;
4111 fs.set_flattened(false);
4112 }
4113 }
4114 }
4115
4116 // Adjusting non_static_oop_count to take into account not flattened value types;
5981 ClassLoaderData* loader_data,
5982 Handle protection_domain,
5983 const InstanceKlass* host_klass,
5984 GrowableArray<Handle>* cp_patches,
5985 Publicity pub_level,
5986 TRAPS) :
5987 _stream(stream),
5988 _requested_name(name),
5989 _loader_data(loader_data),
5990 _host_klass(host_klass),
5991 _cp_patches(cp_patches),
5992 _num_patched_klasses(0),
5993 _max_num_patched_klasses(0),
5994 _orig_cp_size(0),
5995 _first_patched_klass_resolved_index(0),
5996 _super_klass(),
5997 _cp(NULL),
5998 _fields(NULL),
5999 _methods(NULL),
6000 _inner_classes(NULL),
6001 _value_types(NULL),
6002 _local_interfaces(NULL),
6003 _transitive_interfaces(NULL),
6004 _combined_annotations(NULL),
6005 _annotations(NULL),
6006 _type_annotations(NULL),
6007 _fields_annotations(NULL),
6008 _fields_type_annotations(NULL),
6009 _klass(NULL),
6010 _klass_to_deallocate(NULL),
6011 _parsed_annotations(NULL),
6012 _fac(NULL),
6013 _field_info(NULL),
6014 _method_ordering(NULL),
6015 _all_mirandas(NULL),
6016 _vtable_size(0),
6017 _itable_size(0),
6018 _num_miranda_methods(0),
6019 _rt(REF_NONE),
6020 _protection_domain(protection_domain),
6021 _access_flags(),
|