1.1 --- a/src/share/vm/classfile/classFileParser.cpp Mon May 20 15:43:50 2013 +0400 1.2 +++ b/src/share/vm/classfile/classFileParser.cpp Mon May 20 23:41:27 2013 +0400 1.3 @@ -3121,10 +3121,6 @@ 1.4 FieldLayoutInfo* info, 1.5 TRAPS) { 1.6 1.7 - // get the padding width from the option 1.8 - // TODO: Ask VM about specific CPU we are running on 1.9 - int pad_size = ContendedPaddingWidth; 1.10 - 1.11 // Field size and offset computation 1.12 int nonstatic_field_size = _super_klass() == NULL ? 0 : _super_klass()->nonstatic_field_size(); 1.13 int next_static_oop_offset; 1.14 @@ -3137,13 +3133,14 @@ 1.15 int next_nonstatic_word_offset; 1.16 int next_nonstatic_short_offset; 1.17 int next_nonstatic_byte_offset; 1.18 - int next_nonstatic_type_offset; 1.19 int first_nonstatic_oop_offset; 1.20 - int first_nonstatic_field_offset; 1.21 int next_nonstatic_field_offset; 1.22 int next_nonstatic_padded_offset; 1.23 1.24 // Count the contended fields by type. 1.25 + // 1.26 + // We ignore static fields, because @Contended is not supported for them. 1.27 + // The layout code below will also ignore the static fields. 1.28 int nonstatic_contended_count = 0; 1.29 FieldAllocationCount fac_contended; 1.30 for (AllFieldStream fs(_fields, _cp); !fs.done(); fs.next()) { 1.31 @@ -3175,16 +3172,17 @@ 1.32 next_static_byte_offset = next_static_short_offset + 1.33 ((fac->count[STATIC_SHORT]) * BytesPerShort); 1.34 1.35 - first_nonstatic_field_offset = instanceOopDesc::base_offset_in_bytes() + 1.36 - nonstatic_field_size * heapOopSize; 1.37 - 1.38 - next_nonstatic_field_offset = first_nonstatic_field_offset; 1.39 - 1.40 - // class is contended, pad before all the fields 1.41 + int nonstatic_fields_start = instanceOopDesc::base_offset_in_bytes() + 1.42 + nonstatic_field_size * heapOopSize; 1.43 + 1.44 + next_nonstatic_field_offset = nonstatic_fields_start; 1.45 + 1.46 + // Class is contended, pad before all the fields 1.47 if (parsed_annotations->is_contended()) { 1.48 - next_nonstatic_field_offset += pad_size; 1.49 + next_nonstatic_field_offset += ContendedPaddingWidth; 1.50 } 1.51 1.52 + // Compute the non-contended fields count 1.53 unsigned int nonstatic_double_count = fac->count[NONSTATIC_DOUBLE] - fac_contended.count[NONSTATIC_DOUBLE]; 1.54 unsigned int nonstatic_word_count = fac->count[NONSTATIC_WORD] - fac_contended.count[NONSTATIC_WORD]; 1.55 unsigned int nonstatic_short_count = fac->count[NONSTATIC_SHORT] - fac_contended.count[NONSTATIC_SHORT]; 1.56 @@ -3242,6 +3240,7 @@ 1.57 compact_fields = false; // Don't compact fields 1.58 } 1.59 1.60 + // Rearrange fields for a given allocation style 1.61 if( allocation_style == 0 ) { 1.62 // Fields order: oops, longs/doubles, ints, shorts/chars, bytes, padded fields 1.63 next_nonstatic_oop_offset = next_nonstatic_field_offset; 1.64 @@ -3282,6 +3281,8 @@ 1.65 int nonstatic_short_space_offset; 1.66 int nonstatic_byte_space_offset; 1.67 1.68 + // Try to squeeze some of the fields into the gaps due to 1.69 + // long/double alignment. 1.70 if( nonstatic_double_count > 0 ) { 1.71 int offset = next_nonstatic_double_offset; 1.72 next_nonstatic_double_offset = align_size_up(offset, BytesPerLong); 1.73 @@ -3455,7 +3456,7 @@ 1.74 1.75 // if there is at least one contended field, we need to have pre-padding for them 1.76 if (nonstatic_contended_count > 0) { 1.77 - next_nonstatic_padded_offset += pad_size; 1.78 + next_nonstatic_padded_offset += ContendedPaddingWidth; 1.79 } 1.80 1.81 // collect all contended groups 1.82 @@ -3534,7 +3535,7 @@ 1.83 // the fields within the same contended group are not inter-padded. 1.84 // The only exception is default group, which does not incur the 1.85 // equivalence, and so requires intra-padding. 1.86 - next_nonstatic_padded_offset += pad_size; 1.87 + next_nonstatic_padded_offset += ContendedPaddingWidth; 1.88 } 1.89 1.90 fs.set_offset(real_offset); 1.91 @@ -3546,7 +3547,7 @@ 1.92 // subclass fields and/or adjacent object. 1.93 // If this was the default group, the padding is already in place. 1.94 if (current_group != 0) { 1.95 - next_nonstatic_padded_offset += pad_size; 1.96 + next_nonstatic_padded_offset += ContendedPaddingWidth; 1.97 } 1.98 } 1.99 1.100 @@ -3560,19 +3561,19 @@ 1.101 // This helps to alleviate memory contention effects for subclass fields 1.102 // and/or adjacent object. 1.103 if (parsed_annotations->is_contended()) { 1.104 - notaligned_offset += pad_size; 1.105 + notaligned_offset += ContendedPaddingWidth; 1.106 } 1.107 1.108 - int next_static_type_offset = align_size_up(next_static_byte_offset, wordSize); 1.109 - int static_field_size = (next_static_type_offset - 1.110 - InstanceMirrorKlass::offset_of_static_fields()) / wordSize; 1.111 - 1.112 - next_nonstatic_type_offset = align_size_up(notaligned_offset, heapOopSize ); 1.113 - nonstatic_field_size = nonstatic_field_size + ((next_nonstatic_type_offset 1.114 - - first_nonstatic_field_offset)/heapOopSize); 1.115 - 1.116 - next_nonstatic_type_offset = align_size_up(notaligned_offset, wordSize ); 1.117 - int instance_size = align_object_size(next_nonstatic_type_offset / wordSize); 1.118 + int nonstatic_fields_end = align_size_up(notaligned_offset, heapOopSize); 1.119 + int instance_end = align_size_up(notaligned_offset, wordSize); 1.120 + int static_fields_end = align_size_up(next_static_byte_offset, wordSize); 1.121 + 1.122 + int static_field_size = (static_fields_end - 1.123 + InstanceMirrorKlass::offset_of_static_fields()) / wordSize; 1.124 + nonstatic_field_size = nonstatic_field_size + 1.125 + (nonstatic_fields_end - nonstatic_fields_start) / heapOopSize; 1.126 + 1.127 + int instance_size = align_object_size(instance_end / wordSize); 1.128 1.129 assert(instance_size == align_object_size(align_size_up( 1.130 (instanceOopDesc::base_offset_in_bytes() + nonstatic_field_size*heapOopSize), 1.131 @@ -3589,9 +3590,9 @@ 1.132 _fields, 1.133 _cp, 1.134 instance_size, 1.135 - first_nonstatic_field_offset, 1.136 - next_nonstatic_field_offset, 1.137 - next_static_type_offset); 1.138 + nonstatic_fields_start, 1.139 + nonstatic_fields_end, 1.140 + static_fields_end); 1.141 } 1.142 1.143 #endif