Mercurial > hg > graal-compiler
comparison src/share/vm/classfile/classFileParser.cpp @ 10408:836a62f43af9
Merge with http://hg.openjdk.java.net/hsx/hsx25/hotspot/
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Wed, 19 Jun 2013 10:45:56 +0200 |
parents | f2aebc22372a f2110083203d |
children | 6b0fd0964b87 |
comparison
equal
deleted
inserted
replaced
10086:e0fb8a213650 | 10408:836a62f43af9 |
---|---|
37 #include "classfile/vmSymbols.hpp" | 37 #include "classfile/vmSymbols.hpp" |
38 #include "memory/allocation.hpp" | 38 #include "memory/allocation.hpp" |
39 #include "memory/gcLocker.hpp" | 39 #include "memory/gcLocker.hpp" |
40 #include "memory/metadataFactory.hpp" | 40 #include "memory/metadataFactory.hpp" |
41 #include "memory/oopFactory.hpp" | 41 #include "memory/oopFactory.hpp" |
42 #include "memory/referenceType.hpp" | |
42 #include "memory/universe.inline.hpp" | 43 #include "memory/universe.inline.hpp" |
43 #include "oops/constantPool.hpp" | 44 #include "oops/constantPool.hpp" |
44 #include "oops/fieldStreams.hpp" | 45 #include "oops/fieldStreams.hpp" |
45 #include "oops/instanceKlass.hpp" | 46 #include "oops/instanceKlass.hpp" |
46 #include "oops/instanceMirrorKlass.hpp" | 47 #include "oops/instanceMirrorKlass.hpp" |
434 tag.is_field(), | 435 tag.is_field(), |
435 "Invalid constant pool index %u in class file %s (not a field)", | 436 "Invalid constant pool index %u in class file %s (not a field)", |
436 ref_index, CHECK_(nullHandle)); | 437 ref_index, CHECK_(nullHandle)); |
437 break; | 438 break; |
438 case JVM_REF_invokeVirtual: | 439 case JVM_REF_invokeVirtual: |
439 case JVM_REF_invokeStatic: | |
440 case JVM_REF_invokeSpecial: | |
441 case JVM_REF_newInvokeSpecial: | 440 case JVM_REF_newInvokeSpecial: |
442 check_property( | 441 check_property( |
443 tag.is_method(), | 442 tag.is_method(), |
444 "Invalid constant pool index %u in class file %s (not a method)", | 443 "Invalid constant pool index %u in class file %s (not a method)", |
445 ref_index, CHECK_(nullHandle)); | 444 ref_index, CHECK_(nullHandle)); |
446 break; | 445 break; |
446 case JVM_REF_invokeStatic: | |
447 case JVM_REF_invokeSpecial: | |
448 check_property(tag.is_method() || | |
449 ((_major_version >= JAVA_8_VERSION) && tag.is_interface_method()), | |
450 "Invalid constant pool index %u in class file %s (not a method)", | |
451 ref_index, CHECK_(nullHandle)); | |
452 break; | |
447 case JVM_REF_invokeInterface: | 453 case JVM_REF_invokeInterface: |
448 check_property( | 454 check_property( |
449 tag.is_interface_method(), | 455 tag.is_interface_method(), |
450 "Invalid constant pool index %u in class file %s (not an interface method)", | 456 "Invalid constant pool index %u in class file %s (not an interface method)", |
451 ref_index, CHECK_(nullHandle)); | 457 ref_index, CHECK_(nullHandle)); |
1712 AnnotationCollector::ID id = coll->annotation_index(_loader_data, aname); | 1718 AnnotationCollector::ID id = coll->annotation_index(_loader_data, aname); |
1713 if (id == AnnotationCollector::_unknown) continue; | 1719 if (id == AnnotationCollector::_unknown) continue; |
1714 coll->set_annotation(id); | 1720 coll->set_annotation(id); |
1715 | 1721 |
1716 if (id == AnnotationCollector::_sun_misc_Contended) { | 1722 if (id == AnnotationCollector::_sun_misc_Contended) { |
1723 // @Contended can optionally specify the contention group. | |
1724 // | |
1725 // Contended group defines the equivalence class over the fields: | |
1726 // the fields within the same contended group are not treated distinct. | |
1727 // The only exception is default group, which does not incur the | |
1728 // equivalence. Naturally, contention group for classes is meaningless. | |
1729 // | |
1730 // While the contention group is specified as String, annotation | |
1731 // values are already interned, and we might as well use the constant | |
1732 // pool index as the group tag. | |
1733 // | |
1734 u2 group_index = 0; // default contended group | |
1717 if (count == 1 | 1735 if (count == 1 |
1718 && s_size == (index - index0) // match size | 1736 && s_size == (index - index0) // match size |
1719 && s_tag_val == *(abase + tag_off) | 1737 && s_tag_val == *(abase + tag_off) |
1720 && member == vmSymbols::value_name()) { | 1738 && member == vmSymbols::value_name()) { |
1721 u2 group_index = Bytes::get_Java_u2(abase + s_con_off); | 1739 group_index = Bytes::get_Java_u2(abase + s_con_off); |
1722 coll->set_contended_group(group_index); | 1740 if (_cp->symbol_at(group_index)->utf8_length() == 0) { |
1723 } else { | 1741 group_index = 0; // default contended group |
1724 coll->set_contended_group(0); // default contended group | 1742 } |
1725 } | 1743 } |
1744 coll->set_contended_group(group_index); | |
1726 } | 1745 } |
1727 } | 1746 } |
1728 } | 1747 } |
1729 | 1748 |
1730 ClassFileParser::AnnotationCollector::ID | 1749 ClassFileParser::AnnotationCollector::ID |
2020 u2* localvariable_type_table_length; | 2039 u2* localvariable_type_table_length; |
2021 u2** localvariable_type_table_start; | 2040 u2** localvariable_type_table_start; |
2022 u2 method_parameters_length = 0; | 2041 u2 method_parameters_length = 0; |
2023 u1* method_parameters_data = NULL; | 2042 u1* method_parameters_data = NULL; |
2024 bool method_parameters_seen = false; | 2043 bool method_parameters_seen = false; |
2025 bool method_parameters_four_byte_flags; | |
2026 bool parsed_code_attribute = false; | 2044 bool parsed_code_attribute = false; |
2027 bool parsed_checked_exceptions_attribute = false; | 2045 bool parsed_checked_exceptions_attribute = false; |
2028 bool parsed_stackmap_attribute = false; | 2046 bool parsed_stackmap_attribute = false; |
2029 // stackmap attribute - JDK1.5 | 2047 // stackmap attribute - JDK1.5 |
2030 u1* stackmap_data = NULL; | 2048 u1* stackmap_data = NULL; |
2234 if (method_parameters_seen) { | 2252 if (method_parameters_seen) { |
2235 classfile_parse_error("Multiple MethodParameters attributes in class file %s", CHECK_(nullHandle)); | 2253 classfile_parse_error("Multiple MethodParameters attributes in class file %s", CHECK_(nullHandle)); |
2236 } | 2254 } |
2237 method_parameters_seen = true; | 2255 method_parameters_seen = true; |
2238 method_parameters_length = cfs->get_u1_fast(); | 2256 method_parameters_length = cfs->get_u1_fast(); |
2239 // Track the actual size (note: this is written for clarity; a | 2257 if (method_attribute_length != (method_parameters_length * 4u) + 1u) { |
2240 // decent compiler will CSE and constant-fold this into a single | |
2241 // expression) | |
2242 // Use the attribute length to figure out the size of flags | |
2243 if (method_attribute_length == (method_parameters_length * 6u) + 1u) { | |
2244 method_parameters_four_byte_flags = true; | |
2245 } else if (method_attribute_length == (method_parameters_length * 4u) + 1u) { | |
2246 method_parameters_four_byte_flags = false; | |
2247 } else { | |
2248 classfile_parse_error( | 2258 classfile_parse_error( |
2249 "Invalid MethodParameters method attribute length %u in class file", | 2259 "Invalid MethodParameters method attribute length %u in class file", |
2250 method_attribute_length, CHECK_(nullHandle)); | 2260 method_attribute_length, CHECK_(nullHandle)); |
2251 } | 2261 } |
2252 method_parameters_data = cfs->get_u1_buffer(); | 2262 method_parameters_data = cfs->get_u1_buffer(); |
2253 cfs->skip_u2_fast(method_parameters_length); | 2263 cfs->skip_u2_fast(method_parameters_length); |
2254 if (method_parameters_four_byte_flags) { | 2264 cfs->skip_u2_fast(method_parameters_length); |
2255 cfs->skip_u4_fast(method_parameters_length); | |
2256 } else { | |
2257 cfs->skip_u2_fast(method_parameters_length); | |
2258 } | |
2259 // ignore this attribute if it cannot be reflected | 2265 // ignore this attribute if it cannot be reflected |
2260 if (!SystemDictionary::Parameter_klass_loaded()) | 2266 if (!SystemDictionary::Parameter_klass_loaded()) |
2261 method_parameters_length = 0; | 2267 method_parameters_length = 0; |
2262 } else if (method_attribute_name == vmSymbols::tag_synthetic()) { | 2268 } else if (method_attribute_name == vmSymbols::tag_synthetic()) { |
2263 if (method_attribute_length != 0) { | 2269 if (method_attribute_length != 0) { |
2416 if (method_parameters_length > 0) { | 2422 if (method_parameters_length > 0) { |
2417 MethodParametersElement* elem = m->constMethod()->method_parameters_start(); | 2423 MethodParametersElement* elem = m->constMethod()->method_parameters_start(); |
2418 for (int i = 0; i < method_parameters_length; i++) { | 2424 for (int i = 0; i < method_parameters_length; i++) { |
2419 elem[i].name_cp_index = Bytes::get_Java_u2(method_parameters_data); | 2425 elem[i].name_cp_index = Bytes::get_Java_u2(method_parameters_data); |
2420 method_parameters_data += 2; | 2426 method_parameters_data += 2; |
2421 if (method_parameters_four_byte_flags) { | 2427 elem[i].flags = Bytes::get_Java_u2(method_parameters_data); |
2422 elem[i].flags = Bytes::get_Java_u4(method_parameters_data); | 2428 method_parameters_data += 2; |
2423 method_parameters_data += 4; | |
2424 } else { | |
2425 elem[i].flags = Bytes::get_Java_u2(method_parameters_data); | |
2426 method_parameters_data += 2; | |
2427 } | |
2428 } | 2429 } |
2429 } | 2430 } |
2430 | 2431 |
2431 // Copy checked exceptions | 2432 // Copy checked exceptions |
2432 if (checked_exceptions_length > 0) { | 2433 if (checked_exceptions_length > 0) { |
3064 tty->print_cr("Parsing %s", sig->as_C_string()); | 3065 tty->print_cr("Parsing %s", sig->as_C_string()); |
3065 method_spec->print_on(tty); | 3066 method_spec->print_on(tty); |
3066 } | 3067 } |
3067 } | 3068 } |
3068 } | 3069 } |
3069 #endif // ASSERT | 3070 #endif // def ASSERT |
3070 | 3071 |
3071 | 3072 |
3072 instanceKlassHandle ClassFileParser::parse_super_class(int super_class_index, | 3073 instanceKlassHandle ClassFileParser::parse_super_class(int super_class_index, |
3073 TRAPS) { | 3074 TRAPS) { |
3074 instanceKlassHandle super_klass; | 3075 instanceKlassHandle super_klass; |
3119 FieldAllocationCount* fac, | 3120 FieldAllocationCount* fac, |
3120 ClassAnnotationCollector* parsed_annotations, | 3121 ClassAnnotationCollector* parsed_annotations, |
3121 FieldLayoutInfo* info, | 3122 FieldLayoutInfo* info, |
3122 TRAPS) { | 3123 TRAPS) { |
3123 | 3124 |
3124 // get the padding width from the option | |
3125 // TODO: Ask VM about specific CPU we are running on | |
3126 int pad_size = ContendedPaddingWidth; | |
3127 | |
3128 // Field size and offset computation | 3125 // Field size and offset computation |
3129 int nonstatic_field_size = _super_klass() == NULL ? 0 : _super_klass()->nonstatic_field_size(); | 3126 int nonstatic_field_size = _super_klass() == NULL ? 0 : _super_klass()->nonstatic_field_size(); |
3130 #ifndef PRODUCT | |
3131 int orig_nonstatic_field_size = 0; | |
3132 #endif | |
3133 int next_static_oop_offset; | 3127 int next_static_oop_offset; |
3134 int next_static_double_offset; | 3128 int next_static_double_offset; |
3135 int next_static_word_offset; | 3129 int next_static_word_offset; |
3136 int next_static_short_offset; | 3130 int next_static_short_offset; |
3137 int next_static_byte_offset; | 3131 int next_static_byte_offset; |
3138 int next_nonstatic_oop_offset; | 3132 int next_nonstatic_oop_offset; |
3139 int next_nonstatic_double_offset; | 3133 int next_nonstatic_double_offset; |
3140 int next_nonstatic_word_offset; | 3134 int next_nonstatic_word_offset; |
3141 int next_nonstatic_short_offset; | 3135 int next_nonstatic_short_offset; |
3142 int next_nonstatic_byte_offset; | 3136 int next_nonstatic_byte_offset; |
3143 int next_nonstatic_type_offset; | |
3144 int first_nonstatic_oop_offset; | 3137 int first_nonstatic_oop_offset; |
3145 int first_nonstatic_field_offset; | |
3146 int next_nonstatic_field_offset; | 3138 int next_nonstatic_field_offset; |
3147 int next_nonstatic_padded_offset; | 3139 int next_nonstatic_padded_offset; |
3148 | 3140 |
3149 // Count the contended fields by type. | 3141 // Count the contended fields by type. |
3142 // | |
3143 // We ignore static fields, because @Contended is not supported for them. | |
3144 // The layout code below will also ignore the static fields. | |
3150 int nonstatic_contended_count = 0; | 3145 int nonstatic_contended_count = 0; |
3151 FieldAllocationCount fac_contended; | 3146 FieldAllocationCount fac_contended; |
3152 for (AllFieldStream fs(_fields, _cp); !fs.done(); fs.next()) { | 3147 for (AllFieldStream fs(_fields, _cp); !fs.done(); fs.next()) { |
3153 FieldAllocationType atype = (FieldAllocationType) fs.allocation_type(); | 3148 FieldAllocationType atype = (FieldAllocationType) fs.allocation_type(); |
3154 if (fs.is_contended()) { | 3149 if (fs.is_contended()) { |
3156 if (!fs.access_flags().is_static()) { | 3151 if (!fs.access_flags().is_static()) { |
3157 nonstatic_contended_count++; | 3152 nonstatic_contended_count++; |
3158 } | 3153 } |
3159 } | 3154 } |
3160 } | 3155 } |
3161 int contended_count = nonstatic_contended_count; | |
3162 | 3156 |
3163 | 3157 |
3164 // Calculate the starting byte offsets | 3158 // Calculate the starting byte offsets |
3165 next_static_oop_offset = InstanceMirrorKlass::offset_of_static_fields(); | 3159 next_static_oop_offset = InstanceMirrorKlass::offset_of_static_fields(); |
3166 next_static_double_offset = next_static_oop_offset + | 3160 next_static_double_offset = next_static_oop_offset + |
3176 next_static_short_offset = next_static_word_offset + | 3170 next_static_short_offset = next_static_word_offset + |
3177 ((fac->count[STATIC_WORD]) * BytesPerInt); | 3171 ((fac->count[STATIC_WORD]) * BytesPerInt); |
3178 next_static_byte_offset = next_static_short_offset + | 3172 next_static_byte_offset = next_static_short_offset + |
3179 ((fac->count[STATIC_SHORT]) * BytesPerShort); | 3173 ((fac->count[STATIC_SHORT]) * BytesPerShort); |
3180 | 3174 |
3181 first_nonstatic_field_offset = instanceOopDesc::base_offset_in_bytes() + | 3175 int nonstatic_fields_start = instanceOopDesc::base_offset_in_bytes() + |
3182 nonstatic_field_size * heapOopSize; | 3176 nonstatic_field_size * heapOopSize; |
3183 | 3177 |
3184 // class is contended, pad before all the fields | 3178 next_nonstatic_field_offset = nonstatic_fields_start; |
3185 if (parsed_annotations->is_contended()) { | 3179 |
3186 first_nonstatic_field_offset += pad_size; | 3180 bool is_contended_class = parsed_annotations->is_contended(); |
3187 } | 3181 |
3188 | 3182 // Class is contended, pad before all the fields |
3189 next_nonstatic_field_offset = first_nonstatic_field_offset; | 3183 if (is_contended_class) { |
3190 | 3184 next_nonstatic_field_offset += ContendedPaddingWidth; |
3185 } | |
3186 | |
3187 // Compute the non-contended fields count. | |
3188 // The packing code below relies on these counts to determine if some field | |
3189 // can be squeezed into the alignment gap. Contended fields are obviously | |
3190 // exempt from that. | |
3191 unsigned int nonstatic_double_count = fac->count[NONSTATIC_DOUBLE] - fac_contended.count[NONSTATIC_DOUBLE]; | 3191 unsigned int nonstatic_double_count = fac->count[NONSTATIC_DOUBLE] - fac_contended.count[NONSTATIC_DOUBLE]; |
3192 unsigned int nonstatic_word_count = fac->count[NONSTATIC_WORD] - fac_contended.count[NONSTATIC_WORD]; | 3192 unsigned int nonstatic_word_count = fac->count[NONSTATIC_WORD] - fac_contended.count[NONSTATIC_WORD]; |
3193 unsigned int nonstatic_short_count = fac->count[NONSTATIC_SHORT] - fac_contended.count[NONSTATIC_SHORT]; | 3193 unsigned int nonstatic_short_count = fac->count[NONSTATIC_SHORT] - fac_contended.count[NONSTATIC_SHORT]; |
3194 unsigned int nonstatic_byte_count = fac->count[NONSTATIC_BYTE] - fac_contended.count[NONSTATIC_BYTE]; | 3194 unsigned int nonstatic_byte_count = fac->count[NONSTATIC_BYTE] - fac_contended.count[NONSTATIC_BYTE]; |
3195 unsigned int nonstatic_oop_count = fac->count[NONSTATIC_OOP] - fac_contended.count[NONSTATIC_OOP]; | 3195 unsigned int nonstatic_oop_count = fac->count[NONSTATIC_OOP] - fac_contended.count[NONSTATIC_OOP]; |
3196 | 3196 |
3197 // Total non-static fields count, including every contended field | |
3198 unsigned int nonstatic_fields_count = fac->count[NONSTATIC_DOUBLE] + fac->count[NONSTATIC_WORD] + | |
3199 fac->count[NONSTATIC_SHORT] + fac->count[NONSTATIC_BYTE] + | |
3200 fac->count[NONSTATIC_OOP]; | |
3201 | |
3197 bool super_has_nonstatic_fields = | 3202 bool super_has_nonstatic_fields = |
3198 (_super_klass() != NULL && _super_klass->has_nonstatic_fields()); | 3203 (_super_klass() != NULL && _super_klass->has_nonstatic_fields()); |
3199 bool has_nonstatic_fields = super_has_nonstatic_fields || | 3204 bool has_nonstatic_fields = super_has_nonstatic_fields || (nonstatic_fields_count != 0); |
3200 ((nonstatic_double_count + nonstatic_word_count + | |
3201 nonstatic_short_count + nonstatic_byte_count + | |
3202 nonstatic_oop_count) != 0); | |
3203 | 3205 |
3204 | 3206 |
3205 // Prepare list of oops for oop map generation. | 3207 // Prepare list of oops for oop map generation. |
3208 // | |
3209 // "offset" and "count" lists are describing the set of contiguous oop | |
3210 // regions. offset[i] is the start of the i-th region, which then has | |
3211 // count[i] oops following. Before we know how many regions are required, | |
3212 // we pessimistically allocate the maps to fit all the oops into the | |
3213 // distinct regions. | |
3214 // | |
3215 // TODO: We add +1 to always allocate non-zero resource arrays; we need | |
3216 // to figure out if we still need to do this. | |
3206 int* nonstatic_oop_offsets; | 3217 int* nonstatic_oop_offsets; |
3207 unsigned int* nonstatic_oop_counts; | 3218 unsigned int* nonstatic_oop_counts; |
3208 unsigned int nonstatic_oop_map_count = 0; | 3219 unsigned int nonstatic_oop_map_count = 0; |
3220 unsigned int max_nonstatic_oop_maps = fac->count[NONSTATIC_OOP] + 1; | |
3209 | 3221 |
3210 nonstatic_oop_offsets = NEW_RESOURCE_ARRAY_IN_THREAD( | 3222 nonstatic_oop_offsets = NEW_RESOURCE_ARRAY_IN_THREAD( |
3211 THREAD, int, nonstatic_oop_count + 1); | 3223 THREAD, int, max_nonstatic_oop_maps); |
3212 nonstatic_oop_counts = NEW_RESOURCE_ARRAY_IN_THREAD( | 3224 nonstatic_oop_counts = NEW_RESOURCE_ARRAY_IN_THREAD( |
3213 THREAD, unsigned int, nonstatic_oop_count + 1); | 3225 THREAD, unsigned int, max_nonstatic_oop_maps); |
3214 | 3226 |
3215 first_nonstatic_oop_offset = 0; // will be set for first oop field | 3227 first_nonstatic_oop_offset = 0; // will be set for first oop field |
3216 | 3228 |
3217 #ifndef PRODUCT | |
3218 if( PrintCompactFieldsSavings ) { | |
3219 next_nonstatic_double_offset = next_nonstatic_field_offset + | |
3220 (nonstatic_oop_count * heapOopSize); | |
3221 if ( nonstatic_double_count > 0 ) { | |
3222 next_nonstatic_double_offset = align_size_up(next_nonstatic_double_offset, BytesPerLong); | |
3223 } | |
3224 next_nonstatic_word_offset = next_nonstatic_double_offset + | |
3225 (nonstatic_double_count * BytesPerLong); | |
3226 next_nonstatic_short_offset = next_nonstatic_word_offset + | |
3227 (nonstatic_word_count * BytesPerInt); | |
3228 next_nonstatic_byte_offset = next_nonstatic_short_offset + | |
3229 (nonstatic_short_count * BytesPerShort); | |
3230 next_nonstatic_type_offset = align_size_up((next_nonstatic_byte_offset + | |
3231 nonstatic_byte_count ), heapOopSize ); | |
3232 orig_nonstatic_field_size = nonstatic_field_size + | |
3233 ((next_nonstatic_type_offset - first_nonstatic_field_offset)/heapOopSize); | |
3234 } | |
3235 #endif | |
3236 bool compact_fields = CompactFields; | 3229 bool compact_fields = CompactFields; |
3237 int allocation_style = FieldsAllocationStyle; | 3230 int allocation_style = FieldsAllocationStyle; |
3238 if( allocation_style < 0 || allocation_style > 2 ) { // Out of range? | 3231 if( allocation_style < 0 || allocation_style > 2 ) { // Out of range? |
3239 assert(false, "0 <= FieldsAllocationStyle <= 2"); | 3232 assert(false, "0 <= FieldsAllocationStyle <= 2"); |
3240 allocation_style = 1; // Optimistic | 3233 allocation_style = 1; // Optimistic |
3262 _class_name == vmSymbols::java_lang_Long())) { | 3255 _class_name == vmSymbols::java_lang_Long())) { |
3263 allocation_style = 0; // Allocate oops first | 3256 allocation_style = 0; // Allocate oops first |
3264 compact_fields = false; // Don't compact fields | 3257 compact_fields = false; // Don't compact fields |
3265 } | 3258 } |
3266 | 3259 |
3260 // Rearrange fields for a given allocation style | |
3267 if( allocation_style == 0 ) { | 3261 if( allocation_style == 0 ) { |
3268 // Fields order: oops, longs/doubles, ints, shorts/chars, bytes, padded fields | 3262 // Fields order: oops, longs/doubles, ints, shorts/chars, bytes, padded fields |
3269 next_nonstatic_oop_offset = next_nonstatic_field_offset; | 3263 next_nonstatic_oop_offset = next_nonstatic_field_offset; |
3270 next_nonstatic_double_offset = next_nonstatic_oop_offset + | 3264 next_nonstatic_double_offset = next_nonstatic_oop_offset + |
3271 (nonstatic_oop_count * heapOopSize); | 3265 (nonstatic_oop_count * heapOopSize); |
3302 int nonstatic_oop_space_offset; | 3296 int nonstatic_oop_space_offset; |
3303 int nonstatic_word_space_offset; | 3297 int nonstatic_word_space_offset; |
3304 int nonstatic_short_space_offset; | 3298 int nonstatic_short_space_offset; |
3305 int nonstatic_byte_space_offset; | 3299 int nonstatic_byte_space_offset; |
3306 | 3300 |
3301 // Try to squeeze some of the fields into the gaps due to | |
3302 // long/double alignment. | |
3307 if( nonstatic_double_count > 0 ) { | 3303 if( nonstatic_double_count > 0 ) { |
3308 int offset = next_nonstatic_double_offset; | 3304 int offset = next_nonstatic_double_offset; |
3309 next_nonstatic_double_offset = align_size_up(offset, BytesPerLong); | 3305 next_nonstatic_double_offset = align_size_up(offset, BytesPerLong); |
3310 if( compact_fields && offset != next_nonstatic_double_offset ) { | 3306 if( compact_fields && offset != next_nonstatic_double_offset ) { |
3311 // Allocate available fields into the gap before double field. | 3307 // Allocate available fields into the gap before double field. |
3411 nonstatic_oop_offsets[nonstatic_oop_map_count - 1] == | 3407 nonstatic_oop_offsets[nonstatic_oop_map_count - 1] == |
3412 real_offset - | 3408 real_offset - |
3413 int(nonstatic_oop_counts[nonstatic_oop_map_count - 1]) * | 3409 int(nonstatic_oop_counts[nonstatic_oop_map_count - 1]) * |
3414 heapOopSize ) { | 3410 heapOopSize ) { |
3415 // Extend current oop map | 3411 // Extend current oop map |
3412 assert(nonstatic_oop_map_count - 1 < max_nonstatic_oop_maps, "range check"); | |
3416 nonstatic_oop_counts[nonstatic_oop_map_count - 1] += 1; | 3413 nonstatic_oop_counts[nonstatic_oop_map_count - 1] += 1; |
3417 } else { | 3414 } else { |
3418 // Create new oop map | 3415 // Create new oop map |
3416 assert(nonstatic_oop_map_count < max_nonstatic_oop_maps, "range check"); | |
3419 nonstatic_oop_offsets[nonstatic_oop_map_count] = real_offset; | 3417 nonstatic_oop_offsets[nonstatic_oop_map_count] = real_offset; |
3420 nonstatic_oop_counts [nonstatic_oop_map_count] = 1; | 3418 nonstatic_oop_counts [nonstatic_oop_map_count] = 1; |
3421 nonstatic_oop_map_count += 1; | 3419 nonstatic_oop_map_count += 1; |
3422 if( first_nonstatic_oop_offset == 0 ) { // Undefined | 3420 if( first_nonstatic_oop_offset == 0 ) { // Undefined |
3423 first_nonstatic_oop_offset = real_offset; | 3421 first_nonstatic_oop_offset = real_offset; |
3471 // In the absence of alignment information, we end up with pessimistically separating | 3469 // In the absence of alignment information, we end up with pessimistically separating |
3472 // the fields with full-width padding. | 3470 // the fields with full-width padding. |
3473 // | 3471 // |
3474 // Additionally, this should not break alignment for the fields, so we round the alignment up | 3472 // Additionally, this should not break alignment for the fields, so we round the alignment up |
3475 // for each field. | 3473 // for each field. |
3476 if (contended_count > 0) { | 3474 if (nonstatic_contended_count > 0) { |
3477 | 3475 |
3478 // if there is at least one contended field, we need to have pre-padding for them | 3476 // if there is at least one contended field, we need to have pre-padding for them |
3479 if (nonstatic_contended_count > 0) { | 3477 next_nonstatic_padded_offset += ContendedPaddingWidth; |
3480 next_nonstatic_padded_offset += pad_size; | |
3481 } | |
3482 | 3478 |
3483 // collect all contended groups | 3479 // collect all contended groups |
3484 BitMap bm(_cp->size()); | 3480 BitMap bm(_cp->size()); |
3485 for (AllFieldStream fs(_fields, _cp); !fs.done(); fs.next()) { | 3481 for (AllFieldStream fs(_fields, _cp); !fs.done(); fs.next()) { |
3486 // skip already laid out fields | 3482 // skip already laid out fields |
3537 next_nonstatic_padded_offset = align_size_up(next_nonstatic_padded_offset, heapOopSize); | 3533 next_nonstatic_padded_offset = align_size_up(next_nonstatic_padded_offset, heapOopSize); |
3538 real_offset = next_nonstatic_padded_offset; | 3534 real_offset = next_nonstatic_padded_offset; |
3539 next_nonstatic_padded_offset += heapOopSize; | 3535 next_nonstatic_padded_offset += heapOopSize; |
3540 | 3536 |
3541 // Create new oop map | 3537 // Create new oop map |
3538 assert(nonstatic_oop_map_count < max_nonstatic_oop_maps, "range check"); | |
3542 nonstatic_oop_offsets[nonstatic_oop_map_count] = real_offset; | 3539 nonstatic_oop_offsets[nonstatic_oop_map_count] = real_offset; |
3543 nonstatic_oop_counts [nonstatic_oop_map_count] = 1; | 3540 nonstatic_oop_counts [nonstatic_oop_map_count] = 1; |
3544 nonstatic_oop_map_count += 1; | 3541 nonstatic_oop_map_count += 1; |
3545 if( first_nonstatic_oop_offset == 0 ) { // Undefined | 3542 if( first_nonstatic_oop_offset == 0 ) { // Undefined |
3546 first_nonstatic_oop_offset = real_offset; | 3543 first_nonstatic_oop_offset = real_offset; |
3554 if (fs.contended_group() == 0) { | 3551 if (fs.contended_group() == 0) { |
3555 // Contended group defines the equivalence class over the fields: | 3552 // Contended group defines the equivalence class over the fields: |
3556 // the fields within the same contended group are not inter-padded. | 3553 // the fields within the same contended group are not inter-padded. |
3557 // The only exception is default group, which does not incur the | 3554 // The only exception is default group, which does not incur the |
3558 // equivalence, and so requires intra-padding. | 3555 // equivalence, and so requires intra-padding. |
3559 next_nonstatic_padded_offset += pad_size; | 3556 next_nonstatic_padded_offset += ContendedPaddingWidth; |
3560 } | 3557 } |
3561 | 3558 |
3562 fs.set_offset(real_offset); | 3559 fs.set_offset(real_offset); |
3563 } // for | 3560 } // for |
3564 | 3561 |
3566 // Note that this will effectively pad the last group in the back; | 3563 // Note that this will effectively pad the last group in the back; |
3567 // this is expected to alleviate memory contention effects for | 3564 // this is expected to alleviate memory contention effects for |
3568 // subclass fields and/or adjacent object. | 3565 // subclass fields and/or adjacent object. |
3569 // If this was the default group, the padding is already in place. | 3566 // If this was the default group, the padding is already in place. |
3570 if (current_group != 0) { | 3567 if (current_group != 0) { |
3571 next_nonstatic_padded_offset += pad_size; | 3568 next_nonstatic_padded_offset += ContendedPaddingWidth; |
3572 } | 3569 } |
3573 } | 3570 } |
3574 | 3571 |
3575 // handle static fields | 3572 // handle static fields |
3576 } | 3573 } |
3577 | |
3578 // Size of instances | |
3579 int notaligned_offset = next_nonstatic_padded_offset; | |
3580 | 3574 |
3581 // Entire class is contended, pad in the back. | 3575 // Entire class is contended, pad in the back. |
3582 // This helps to alleviate memory contention effects for subclass fields | 3576 // This helps to alleviate memory contention effects for subclass fields |
3583 // and/or adjacent object. | 3577 // and/or adjacent object. |
3584 if (parsed_annotations->is_contended()) { | 3578 if (is_contended_class) { |
3585 notaligned_offset += pad_size; | 3579 next_nonstatic_padded_offset += ContendedPaddingWidth; |
3586 } | 3580 } |
3587 | 3581 |
3588 int next_static_type_offset = align_size_up(next_static_byte_offset, wordSize); | 3582 int notaligned_nonstatic_fields_end = next_nonstatic_padded_offset; |
3589 int static_field_size = (next_static_type_offset - | 3583 |
3590 InstanceMirrorKlass::offset_of_static_fields()) / wordSize; | 3584 int nonstatic_fields_end = align_size_up(notaligned_nonstatic_fields_end, heapOopSize); |
3591 | 3585 int instance_end = align_size_up(notaligned_nonstatic_fields_end, wordSize); |
3592 next_nonstatic_type_offset = align_size_up(notaligned_offset, heapOopSize ); | 3586 int static_fields_end = align_size_up(next_static_byte_offset, wordSize); |
3593 nonstatic_field_size = nonstatic_field_size + ((next_nonstatic_type_offset | 3587 |
3594 - first_nonstatic_field_offset)/heapOopSize); | 3588 int static_field_size = (static_fields_end - |
3595 | 3589 InstanceMirrorKlass::offset_of_static_fields()) / wordSize; |
3596 next_nonstatic_type_offset = align_size_up(notaligned_offset, wordSize ); | 3590 nonstatic_field_size = nonstatic_field_size + |
3597 int instance_size = align_object_size(next_nonstatic_type_offset / wordSize); | 3591 (nonstatic_fields_end - nonstatic_fields_start) / heapOopSize; |
3592 | |
3593 int instance_size = align_object_size(instance_end / wordSize); | |
3598 | 3594 |
3599 assert(instance_size == align_object_size(align_size_up( | 3595 assert(instance_size == align_object_size(align_size_up( |
3600 (instanceOopDesc::base_offset_in_bytes() + nonstatic_field_size*heapOopSize + ((parsed_annotations->is_contended()) ? pad_size : 0)), | 3596 (instanceOopDesc::base_offset_in_bytes() + nonstatic_field_size*heapOopSize), |
3601 wordSize) / wordSize), "consistent layout helper value"); | 3597 wordSize) / wordSize), "consistent layout helper value"); |
3598 | |
3599 // Invariant: nonstatic_field end/start should only change if there are | |
3600 // nonstatic fields in the class, or if the class is contended. We compare | |
3601 // against the non-aligned value, so that end alignment will not fail the | |
3602 // assert without actually having the fields. | |
3603 assert((notaligned_nonstatic_fields_end == nonstatic_fields_start) || | |
3604 is_contended_class || | |
3605 (nonstatic_fields_count > 0), "double-check nonstatic start/end"); | |
3602 | 3606 |
3603 // Number of non-static oop map blocks allocated at end of klass. | 3607 // Number of non-static oop map blocks allocated at end of klass. |
3604 const unsigned int total_oop_map_count = | 3608 const unsigned int total_oop_map_count = |
3605 compute_oop_map_count(_super_klass, nonstatic_oop_map_count, | 3609 compute_oop_map_count(_super_klass, nonstatic_oop_map_count, |
3606 first_nonstatic_oop_offset); | 3610 first_nonstatic_oop_offset); |
3607 | 3611 |
3608 #ifndef PRODUCT | 3612 #ifndef PRODUCT |
3609 if( PrintCompactFieldsSavings ) { | |
3610 ResourceMark rm; | |
3611 if( nonstatic_field_size < orig_nonstatic_field_size ) { | |
3612 tty->print("[Saved %d of %d bytes in %s]\n", | |
3613 (orig_nonstatic_field_size - nonstatic_field_size)*heapOopSize, | |
3614 orig_nonstatic_field_size*heapOopSize, | |
3615 _class_name); | |
3616 } else if( nonstatic_field_size > orig_nonstatic_field_size ) { | |
3617 tty->print("[Wasted %d over %d bytes in %s]\n", | |
3618 (nonstatic_field_size - orig_nonstatic_field_size)*heapOopSize, | |
3619 orig_nonstatic_field_size*heapOopSize, | |
3620 _class_name); | |
3621 } | |
3622 } | |
3623 | |
3624 if (PrintFieldLayout) { | 3613 if (PrintFieldLayout) { |
3625 print_field_layout(_class_name, | 3614 print_field_layout(_class_name, |
3626 _fields, | 3615 _fields, |
3627 _cp, | 3616 _cp, |
3628 instance_size, | 3617 instance_size, |
3629 first_nonstatic_field_offset, | 3618 nonstatic_fields_start, |
3630 next_nonstatic_field_offset, | 3619 nonstatic_fields_end, |
3631 next_static_type_offset); | 3620 static_fields_end); |
3632 } | 3621 } |
3633 | 3622 |
3634 #endif | 3623 #endif |
3635 // Pass back information needed for InstanceKlass creation | 3624 // Pass back information needed for InstanceKlass creation |
3636 info->nonstatic_oop_offsets = nonstatic_oop_offsets; | 3625 info->nonstatic_oop_offsets = nonstatic_oop_offsets; |
3835 ); | 3824 ); |
3836 return nullHandle; | 3825 return nullHandle; |
3837 } | 3826 } |
3838 | 3827 |
3839 if (TraceClassLoadingPreorder) { | 3828 if (TraceClassLoadingPreorder) { |
3840 tty->print("[Loading %s", name->as_klass_external_name()); | 3829 tty->print("[Loading %s", (name != NULL) ? name->as_klass_external_name() : "NoName"); |
3841 if (cfs->source() != NULL) tty->print(" from %s", cfs->source()); | 3830 if (cfs->source() != NULL) tty->print(" from %s", cfs->source()); |
3842 tty->print_cr("]"); | 3831 tty->print_cr("]"); |
3843 } | 3832 } |
3844 | 3833 |
3845 u2 super_class_index = cfs->get_u2_fast(); | 3834 u2 super_class_index = cfs->get_u2_fast(); |
4074 if (_major_version < JAVA_8_VERSION) { | 4063 if (_major_version < JAVA_8_VERSION) { |
4075 check_illegal_static_method(this_klass, CHECK_(nullHandle)); | 4064 check_illegal_static_method(this_klass, CHECK_(nullHandle)); |
4076 } | 4065 } |
4077 } | 4066 } |
4078 | 4067 |
4068 // Allocate mirror and initialize static fields | |
4069 java_lang_Class::create_mirror(this_klass, protection_domain, CHECK_(nullHandle)); | |
4070 | |
4079 | 4071 |
4080 #ifdef ASSERT | 4072 #ifdef ASSERT |
4081 if (ParseAllGenericSignatures) { | 4073 if (ParseAllGenericSignatures) { |
4082 parseAndPrintGenericSignatures(this_klass, CHECK_(nullHandle)); | 4074 parseAndPrintGenericSignatures(this_klass, CHECK_(nullHandle)); |
4083 } | 4075 } |
4088 if (has_default_methods && !access_flags.is_interface() && | 4080 if (has_default_methods && !access_flags.is_interface() && |
4089 local_interfaces->length() > 0) { | 4081 local_interfaces->length() > 0) { |
4090 DefaultMethods::generate_default_methods( | 4082 DefaultMethods::generate_default_methods( |
4091 this_klass(), &all_mirandas, CHECK_(nullHandle)); | 4083 this_klass(), &all_mirandas, CHECK_(nullHandle)); |
4092 } | 4084 } |
4093 | |
4094 // Allocate mirror and initialize static fields | |
4095 java_lang_Class::create_mirror(this_klass, CHECK_(nullHandle)); | |
4096 | |
4097 // Allocate a simple java object for locking during class initialization. | |
4098 // This needs to be a java object because it can be held across a java call. | |
4099 typeArrayOop r = oopFactory::new_typeArray(T_INT, 0, CHECK_NULL); | |
4100 this_klass->set_init_lock(r); | |
4101 | |
4102 // TODO: Move these oops to the mirror | |
4103 this_klass->set_protection_domain(protection_domain()); | |
4104 | 4085 |
4105 // Update the loader_data graph. | 4086 // Update the loader_data graph. |
4106 record_defined_class_dependencies(this_klass, CHECK_NULL); | 4087 record_defined_class_dependencies(this_klass, CHECK_NULL); |
4107 | 4088 |
4108 ClassLoadingService::notify_class_loaded(InstanceKlass::cast(this_klass()), | 4089 ClassLoadingService::notify_class_loaded(InstanceKlass::cast(this_klass()), |