1.1 --- a/src/share/vm/classfile/classFileParser.cpp Fri Sep 04 12:53:02 2009 -0400 1.2 +++ b/src/share/vm/classfile/classFileParser.cpp Wed Sep 16 09:10:57 2009 -0400 1.3 @@ -766,16 +766,16 @@ 1.4 1.5 1.6 struct FieldAllocationCount { 1.7 - int static_oop_count; 1.8 - int static_byte_count; 1.9 - int static_short_count; 1.10 - int static_word_count; 1.11 - int static_double_count; 1.12 - int nonstatic_oop_count; 1.13 - int nonstatic_byte_count; 1.14 - int nonstatic_short_count; 1.15 - int nonstatic_word_count; 1.16 - int nonstatic_double_count; 1.17 + unsigned int static_oop_count; 1.18 + unsigned int static_byte_count; 1.19 + unsigned int static_short_count; 1.20 + unsigned int static_word_count; 1.21 + unsigned int static_double_count; 1.22 + unsigned int nonstatic_oop_count; 1.23 + unsigned int nonstatic_byte_count; 1.24 + unsigned int nonstatic_short_count; 1.25 + unsigned int nonstatic_word_count; 1.26 + unsigned int nonstatic_double_count; 1.27 }; 1.28 1.29 typeArrayHandle ClassFileParser::parse_fields(constantPoolHandle cp, bool is_interface, 1.30 @@ -2909,11 +2909,11 @@ 1.31 } 1.32 // end of "discovered" field compactibility fix 1.33 1.34 - int nonstatic_double_count = fac.nonstatic_double_count; 1.35 - int nonstatic_word_count = fac.nonstatic_word_count; 1.36 - int nonstatic_short_count = fac.nonstatic_short_count; 1.37 - int nonstatic_byte_count = fac.nonstatic_byte_count; 1.38 - int nonstatic_oop_count = fac.nonstatic_oop_count; 1.39 + unsigned int nonstatic_double_count = fac.nonstatic_double_count; 1.40 + unsigned int nonstatic_word_count = fac.nonstatic_word_count; 1.41 + unsigned int nonstatic_short_count = fac.nonstatic_short_count; 1.42 + unsigned int nonstatic_byte_count = fac.nonstatic_byte_count; 1.43 + unsigned int nonstatic_oop_count = fac.nonstatic_oop_count; 1.44 1.45 bool super_has_nonstatic_fields = 1.46 (super_klass() != NULL && super_klass->has_nonstatic_fields()); 1.47 @@ -2923,26 +2923,26 @@ 1.48 nonstatic_oop_count) != 0); 1.49 1.50 1.51 - // Prepare list of oops for oop maps generation. 1.52 - u2* nonstatic_oop_offsets; 1.53 - u2* nonstatic_oop_length; 1.54 - int nonstatic_oop_map_count = 0; 1.55 + // Prepare list of oops for oop map generation. 1.56 + int* nonstatic_oop_offsets; 1.57 + unsigned int* nonstatic_oop_counts; 1.58 + unsigned int nonstatic_oop_map_count = 0; 1.59 1.60 nonstatic_oop_offsets = NEW_RESOURCE_ARRAY_IN_THREAD( 1.61 - THREAD, u2, nonstatic_oop_count+1); 1.62 - nonstatic_oop_length = NEW_RESOURCE_ARRAY_IN_THREAD( 1.63 - THREAD, u2, nonstatic_oop_count+1); 1.64 + THREAD, int, nonstatic_oop_count + 1); 1.65 + nonstatic_oop_counts = NEW_RESOURCE_ARRAY_IN_THREAD( 1.66 + THREAD, unsigned int, nonstatic_oop_count + 1); 1.67 1.68 // Add fake fields for java.lang.Class instances (also see above). 1.69 // FieldsAllocationStyle and CompactFields values will be reset to default. 1.70 if(class_name() == vmSymbols::java_lang_Class() && class_loader.is_null()) { 1.71 java_lang_Class_fix_post(&next_nonstatic_field_offset); 1.72 - nonstatic_oop_offsets[0] = (u2)first_nonstatic_field_offset; 1.73 - int fake_oop_count = (( next_nonstatic_field_offset - 1.74 - first_nonstatic_field_offset ) / heapOopSize); 1.75 - nonstatic_oop_length [0] = (u2)fake_oop_count; 1.76 - nonstatic_oop_map_count = 1; 1.77 - nonstatic_oop_count -= fake_oop_count; 1.78 + nonstatic_oop_offsets[0] = first_nonstatic_field_offset; 1.79 + const uint fake_oop_count = (next_nonstatic_field_offset - 1.80 + first_nonstatic_field_offset) / heapOopSize; 1.81 + nonstatic_oop_counts[0] = fake_oop_count; 1.82 + nonstatic_oop_map_count = 1; 1.83 + nonstatic_oop_count -= fake_oop_count; 1.84 first_nonstatic_oop_offset = first_nonstatic_field_offset; 1.85 } else { 1.86 first_nonstatic_oop_offset = 0; // will be set for first oop field 1.87 @@ -3120,13 +3120,15 @@ 1.88 // Update oop maps 1.89 if( nonstatic_oop_map_count > 0 && 1.90 nonstatic_oop_offsets[nonstatic_oop_map_count - 1] == 1.91 - (u2)(real_offset - nonstatic_oop_length[nonstatic_oop_map_count - 1] * heapOopSize) ) { 1.92 + real_offset - 1.93 + int(nonstatic_oop_counts[nonstatic_oop_map_count - 1]) * 1.94 + heapOopSize ) { 1.95 // Extend current oop map 1.96 - nonstatic_oop_length[nonstatic_oop_map_count - 1] += 1; 1.97 + nonstatic_oop_counts[nonstatic_oop_map_count - 1] += 1; 1.98 } else { 1.99 // Create new oop map 1.100 - nonstatic_oop_offsets[nonstatic_oop_map_count] = (u2)real_offset; 1.101 - nonstatic_oop_length [nonstatic_oop_map_count] = 1; 1.102 + nonstatic_oop_offsets[nonstatic_oop_map_count] = real_offset; 1.103 + nonstatic_oop_counts [nonstatic_oop_map_count] = 1; 1.104 nonstatic_oop_map_count += 1; 1.105 if( first_nonstatic_oop_offset == 0 ) { // Undefined 1.106 first_nonstatic_oop_offset = real_offset; 1.107 @@ -3183,8 +3185,10 @@ 1.108 1.109 assert(instance_size == align_object_size(align_size_up((instanceOopDesc::base_offset_in_bytes() + nonstatic_field_size*heapOopSize), wordSize) / wordSize), "consistent layout helper value"); 1.110 1.111 - // Size of non-static oop map blocks (in words) allocated at end of klass 1.112 - int nonstatic_oop_map_size = compute_oop_map_size(super_klass, nonstatic_oop_map_count, first_nonstatic_oop_offset); 1.113 + // Number of non-static oop map blocks allocated at end of klass. 1.114 + const unsigned int total_oop_map_count = 1.115 + compute_oop_map_count(super_klass, nonstatic_oop_map_count, 1.116 + first_nonstatic_oop_offset); 1.117 1.118 // Compute reference type 1.119 ReferenceType rt; 1.120 @@ -3195,14 +3199,15 @@ 1.121 } 1.122 1.123 // We can now create the basic klassOop for this klass 1.124 - klassOop ik = oopFactory::new_instanceKlass( 1.125 - vtable_size, itable_size, 1.126 - static_field_size, nonstatic_oop_map_size, 1.127 - rt, CHECK_(nullHandle)); 1.128 + klassOop ik = oopFactory::new_instanceKlass(vtable_size, itable_size, 1.129 + static_field_size, 1.130 + total_oop_map_count, 1.131 + rt, CHECK_(nullHandle)); 1.132 instanceKlassHandle this_klass (THREAD, ik); 1.133 1.134 - assert(this_klass->static_field_size() == static_field_size && 1.135 - this_klass->nonstatic_oop_map_size() == nonstatic_oop_map_size, "sanity check"); 1.136 + assert(this_klass->static_field_size() == static_field_size, "sanity"); 1.137 + assert(this_klass->nonstatic_oop_map_count() == total_oop_map_count, 1.138 + "sanity"); 1.139 1.140 // Fill in information already parsed 1.141 this_klass->set_access_flags(access_flags); 1.142 @@ -3288,7 +3293,7 @@ 1.143 klassItable::setup_itable_offset_table(this_klass); 1.144 1.145 // Do final class setup 1.146 - fill_oop_maps(this_klass, nonstatic_oop_map_count, nonstatic_oop_offsets, nonstatic_oop_length); 1.147 + fill_oop_maps(this_klass, nonstatic_oop_map_count, nonstatic_oop_offsets, nonstatic_oop_counts); 1.148 1.149 set_precomputed_flags(this_klass); 1.150 1.151 @@ -3381,66 +3386,73 @@ 1.152 } 1.153 1.154 1.155 -int ClassFileParser::compute_oop_map_size(instanceKlassHandle super, int nonstatic_oop_map_count, int first_nonstatic_oop_offset) { 1.156 - int map_size = super.is_null() ? 0 : super->nonstatic_oop_map_size(); 1.157 +unsigned int 1.158 +ClassFileParser::compute_oop_map_count(instanceKlassHandle super, 1.159 + unsigned int nonstatic_oop_map_count, 1.160 + int first_nonstatic_oop_offset) { 1.161 + unsigned int map_count = 1.162 + super.is_null() ? 0 : super->nonstatic_oop_map_count(); 1.163 if (nonstatic_oop_map_count > 0) { 1.164 // We have oops to add to map 1.165 - if (map_size == 0) { 1.166 - map_size = nonstatic_oop_map_count; 1.167 + if (map_count == 0) { 1.168 + map_count = nonstatic_oop_map_count; 1.169 } else { 1.170 - // Check whether we should add a new map block or whether the last one can be extended 1.171 - OopMapBlock* first_map = super->start_of_nonstatic_oop_maps(); 1.172 - OopMapBlock* last_map = first_map + map_size - 1; 1.173 - 1.174 - int next_offset = last_map->offset() + (last_map->length() * heapOopSize); 1.175 + // Check whether we should add a new map block or whether the last one can 1.176 + // be extended 1.177 + OopMapBlock* const first_map = super->start_of_nonstatic_oop_maps(); 1.178 + OopMapBlock* const last_map = first_map + map_count - 1; 1.179 + 1.180 + int next_offset = last_map->offset() + last_map->count() * heapOopSize; 1.181 if (next_offset == first_nonstatic_oop_offset) { 1.182 // There is no gap bettwen superklass's last oop field and first 1.183 // local oop field, merge maps. 1.184 nonstatic_oop_map_count -= 1; 1.185 } else { 1.186 // Superklass didn't end with a oop field, add extra maps 1.187 - assert(next_offset<first_nonstatic_oop_offset, "just checking"); 1.188 + assert(next_offset < first_nonstatic_oop_offset, "just checking"); 1.189 } 1.190 - map_size += nonstatic_oop_map_count; 1.191 + map_count += nonstatic_oop_map_count; 1.192 } 1.193 } 1.194 - return map_size; 1.195 + return map_count; 1.196 } 1.197 1.198 1.199 void ClassFileParser::fill_oop_maps(instanceKlassHandle k, 1.200 - int nonstatic_oop_map_count, 1.201 - u2* nonstatic_oop_offsets, u2* nonstatic_oop_length) { 1.202 + unsigned int nonstatic_oop_map_count, 1.203 + int* nonstatic_oop_offsets, 1.204 + unsigned int* nonstatic_oop_counts) { 1.205 OopMapBlock* this_oop_map = k->start_of_nonstatic_oop_maps(); 1.206 - OopMapBlock* last_oop_map = this_oop_map + k->nonstatic_oop_map_size(); 1.207 - instanceKlass* super = k->superklass(); 1.208 - if (super != NULL) { 1.209 - int super_oop_map_size = super->nonstatic_oop_map_size(); 1.210 + const instanceKlass* const super = k->superklass(); 1.211 + const unsigned int super_count = super ? super->nonstatic_oop_map_count() : 0; 1.212 + if (super_count > 0) { 1.213 + // Copy maps from superklass 1.214 OopMapBlock* super_oop_map = super->start_of_nonstatic_oop_maps(); 1.215 - // Copy maps from superklass 1.216 - while (super_oop_map_size-- > 0) { 1.217 + for (unsigned int i = 0; i < super_count; ++i) { 1.218 *this_oop_map++ = *super_oop_map++; 1.219 } 1.220 } 1.221 + 1.222 if (nonstatic_oop_map_count > 0) { 1.223 - if (this_oop_map + nonstatic_oop_map_count > last_oop_map) { 1.224 - // Calculated in compute_oop_map_size() number of oop maps is less then 1.225 - // collected oop maps since there is no gap between superklass's last oop 1.226 - // field and first local oop field. Extend the last oop map copied 1.227 + if (super_count + nonstatic_oop_map_count > k->nonstatic_oop_map_count()) { 1.228 + // The counts differ because there is no gap between superklass's last oop 1.229 + // field and the first local oop field. Extend the last oop map copied 1.230 // from the superklass instead of creating new one. 1.231 nonstatic_oop_map_count--; 1.232 nonstatic_oop_offsets++; 1.233 this_oop_map--; 1.234 - this_oop_map->set_length(this_oop_map->length() + *nonstatic_oop_length++); 1.235 + this_oop_map->set_count(this_oop_map->count() + *nonstatic_oop_counts++); 1.236 this_oop_map++; 1.237 } 1.238 - assert((this_oop_map + nonstatic_oop_map_count) == last_oop_map, "just checking"); 1.239 + 1.240 // Add new map blocks, fill them 1.241 while (nonstatic_oop_map_count-- > 0) { 1.242 this_oop_map->set_offset(*nonstatic_oop_offsets++); 1.243 - this_oop_map->set_length(*nonstatic_oop_length++); 1.244 + this_oop_map->set_count(*nonstatic_oop_counts++); 1.245 this_oop_map++; 1.246 } 1.247 + assert(k->start_of_nonstatic_oop_maps() + k->nonstatic_oop_map_count() == 1.248 + this_oop_map, "sanity"); 1.249 } 1.250 } 1.251