3968 int max_nonstatic_value_type = fac->count[NONSTATIC_VALUETYPE] + 1; 3969 3970 nonstatic_value_type_indexes = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, int, 3971 max_nonstatic_value_type); 3972 for (int i = 0; i < max_nonstatic_value_type; i++) { 3973 nonstatic_value_type_indexes[i] = -1; 3974 } 3975 nonstatic_value_type_klasses = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, Klass*, 3976 max_nonstatic_value_type); 3977 3978 for (AllFieldStream fs(_fields, _cp); !fs.done(); fs.next()) { 3979 if (fs.allocation_type() == STATIC_VALUETYPE) { 3980 static_value_type_count++; 3981 } else if (fs.allocation_type() == NONSTATIC_VALUETYPE) { 3982 Symbol* signature = fs.signature(); 3983 Klass* klass = SystemDictionary::resolve_or_fail(signature, 3984 Handle(THREAD, _loader_data->class_loader()), 3985 _protection_domain, true, CHECK); 3986 assert(klass != NULL, "Sanity check"); 3987 assert(klass->access_flags().is_value_type(), "Value type expected"); 3988 nonstatic_value_type_indexes[nonstatic_value_type_count] = fs.index(); 3989 nonstatic_value_type_klasses[nonstatic_value_type_count] = klass; 3990 nonstatic_value_type_count++; 3991 3992 ValueKlass* vklass = ValueKlass::cast(klass); 3993 if (vklass->contains_oops()) { 3994 value_type_oop_map_count += vklass->nonstatic_oop_map_count(); 3995 } 3996 } 3997 } 3998 3999 // Total non-static fields count, including every contended field 4000 unsigned int nonstatic_fields_count = fac->count[NONSTATIC_DOUBLE] + fac->count[NONSTATIC_WORD] + 4001 fac->count[NONSTATIC_SHORT] + fac->count[NONSTATIC_BYTE] + 4002 fac->count[NONSTATIC_OOP] + fac->count[NONSTATIC_VALUETYPE]; 4003 4004 const bool super_has_nonstatic_fields = 4005 (_super_klass != NULL && _super_klass->has_nonstatic_fields()); 4006 const bool has_nonstatic_fields = 4007 super_has_nonstatic_fields || (nonstatic_fields_count != 0); 4008 const bool has_nonstatic_value_fields = nonstatic_value_type_count > 0; 4009 4010 if (is_value_type() && (!has_nonstatic_fields)) { 4011 // There are a number of fixes required throughout the type system and JIT 4012 if (class_name() != vmSymbols::java_lang____Value()) { 4013 throwValueTypeLimitation(THREAD_AND_LOCATION, "Value Types do not support zero instance size yet"); 4014 } 4015 } 4197 real_offset = next_static_oop_offset; 4198 next_static_oop_offset += heapOopSize; 4199 break; 4200 case STATIC_BYTE: 4201 real_offset = next_static_byte_offset; 4202 next_static_byte_offset += 1; 4203 break; 4204 case STATIC_SHORT: 4205 real_offset = next_static_short_offset; 4206 next_static_short_offset += BytesPerShort; 4207 break; 4208 case STATIC_WORD: 4209 real_offset = next_static_word_offset; 4210 next_static_word_offset += BytesPerInt; 4211 break; 4212 case STATIC_DOUBLE: 4213 real_offset = next_static_double_offset; 4214 next_static_double_offset += BytesPerLong; 4215 break; 4216 case NONSTATIC_VALUETYPE: 4217 { 4218 Klass* klass = nonstatic_value_type_klasses[next_value_type_index]; 4219 assert(klass != NULL, "Klass should have been loaded and resolved earlier"); 4220 assert(klass->access_flags().is_value_type(),"Must be a value type"); 4221 ValueKlass* vklass = ValueKlass::cast(klass); 4222 real_offset = next_nonstatic_valuetype_offset; 4223 next_nonstatic_valuetype_offset += (vklass->size_helper()) * wordSize - vklass->first_field_offset(); 4224 // aligning next value type on a 64 bits boundary 4225 next_nonstatic_valuetype_offset = align_up(next_nonstatic_valuetype_offset, BytesPerLong); 4226 next_value_type_index += 1; 4227 4228 if (vklass->contains_oops()) { // add flatten oop maps 4229 int diff = real_offset - vklass->first_field_offset(); 4230 const OopMapBlock* map = vklass->start_of_nonstatic_oop_maps(); 4231 const OopMapBlock* const last_map = map + vklass->nonstatic_oop_map_count(); 4232 while (map < last_map) { 4233 nonstatic_oop_maps->add(map->offset() + diff, map->count()); 4234 map++; 4235 } 4236 } 4237 } 4238 break; 4239 case NONSTATIC_OOP: 4240 if( nonstatic_oop_space_count > 0 ) { 4241 real_offset = nonstatic_oop_space_offset; 4242 nonstatic_oop_space_offset += heapOopSize; 4243 nonstatic_oop_space_count -= 1; 4244 } else { 4245 real_offset = next_nonstatic_oop_offset; 4246 next_nonstatic_oop_offset += heapOopSize; 4247 } 4248 nonstatic_oop_maps->add(real_offset, 1); 4249 break; 4250 case NONSTATIC_BYTE: 4251 if( nonstatic_byte_space_count > 0 ) { 4252 real_offset = nonstatic_byte_space_offset; 4253 nonstatic_byte_space_offset += 1; 4254 nonstatic_byte_space_count -= 1; 4255 } else { 4256 real_offset = next_nonstatic_byte_offset; 4257 next_nonstatic_byte_offset += 1; 4258 } | 3968 int max_nonstatic_value_type = fac->count[NONSTATIC_VALUETYPE] + 1; 3969 3970 nonstatic_value_type_indexes = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, int, 3971 max_nonstatic_value_type); 3972 for (int i = 0; i < max_nonstatic_value_type; i++) { 3973 nonstatic_value_type_indexes[i] = -1; 3974 } 3975 nonstatic_value_type_klasses = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, Klass*, 3976 max_nonstatic_value_type); 3977 3978 for (AllFieldStream fs(_fields, _cp); !fs.done(); fs.next()) { 3979 if (fs.allocation_type() == STATIC_VALUETYPE) { 3980 static_value_type_count++; 3981 } else if (fs.allocation_type() == NONSTATIC_VALUETYPE) { 3982 Symbol* signature = fs.signature(); 3983 Klass* klass = SystemDictionary::resolve_or_fail(signature, 3984 Handle(THREAD, _loader_data->class_loader()), 3985 _protection_domain, true, CHECK); 3986 assert(klass != NULL, "Sanity check"); 3987 assert(klass->access_flags().is_value_type(), "Value type expected"); 3988 ValueKlass* vk = ValueKlass::cast(klass); 3989 // Conditions to apply flattening or not should be defined 3990 //in a single place 3991 if (vk->size_helper() <= ValueArrayElemMaxFlatSize) { 3992 nonstatic_value_type_indexes[nonstatic_value_type_count] = fs.index(); 3993 nonstatic_value_type_klasses[nonstatic_value_type_count] = klass; 3994 nonstatic_value_type_count++; 3995 3996 ValueKlass* vklass = ValueKlass::cast(klass); 3997 if (vklass->contains_oops()) { 3998 value_type_oop_map_count += vklass->nonstatic_oop_map_count(); 3999 } 4000 fs.set_flattening(true); 4001 } else { 4002 value_type_oop_map_count++; 4003 fs.set_flattening(false); 4004 } 4005 } 4006 } 4007 4008 // Total non-static fields count, including every contended field 4009 unsigned int nonstatic_fields_count = fac->count[NONSTATIC_DOUBLE] + fac->count[NONSTATIC_WORD] + 4010 fac->count[NONSTATIC_SHORT] + fac->count[NONSTATIC_BYTE] + 4011 fac->count[NONSTATIC_OOP] + fac->count[NONSTATIC_VALUETYPE]; 4012 4013 const bool super_has_nonstatic_fields = 4014 (_super_klass != NULL && _super_klass->has_nonstatic_fields()); 4015 const bool has_nonstatic_fields = 4016 super_has_nonstatic_fields || (nonstatic_fields_count != 0); 4017 const bool has_nonstatic_value_fields = nonstatic_value_type_count > 0; 4018 4019 if (is_value_type() && (!has_nonstatic_fields)) { 4020 // There are a number of fixes required throughout the type system and JIT 4021 if (class_name() != vmSymbols::java_lang____Value()) { 4022 throwValueTypeLimitation(THREAD_AND_LOCATION, "Value Types do not support zero instance size yet"); 4023 } 4024 } 4206 real_offset = next_static_oop_offset; 4207 next_static_oop_offset += heapOopSize; 4208 break; 4209 case STATIC_BYTE: 4210 real_offset = next_static_byte_offset; 4211 next_static_byte_offset += 1; 4212 break; 4213 case STATIC_SHORT: 4214 real_offset = next_static_short_offset; 4215 next_static_short_offset += BytesPerShort; 4216 break; 4217 case STATIC_WORD: 4218 real_offset = next_static_word_offset; 4219 next_static_word_offset += BytesPerInt; 4220 break; 4221 case STATIC_DOUBLE: 4222 real_offset = next_static_double_offset; 4223 next_static_double_offset += BytesPerLong; 4224 break; 4225 case NONSTATIC_VALUETYPE: 4226 if (fs.is_flatten()) { 4227 Klass* klass = nonstatic_value_type_klasses[next_value_type_index]; 4228 assert(klass != NULL, "Klass should have been loaded and resolved earlier"); 4229 assert(klass->access_flags().is_value_type(),"Must be a value type"); 4230 ValueKlass* vklass = ValueKlass::cast(klass); 4231 real_offset = next_nonstatic_valuetype_offset; 4232 next_nonstatic_valuetype_offset += (vklass->size_helper()) * wordSize - vklass->first_field_offset(); 4233 // aligning next value type on a 64 bits boundary 4234 next_nonstatic_valuetype_offset = align_up(next_nonstatic_valuetype_offset, BytesPerLong); 4235 next_value_type_index += 1; 4236 4237 if (vklass->contains_oops()) { // add flatten oop maps 4238 int diff = real_offset - vklass->first_field_offset(); 4239 const OopMapBlock* map = vklass->start_of_nonstatic_oop_maps(); 4240 const OopMapBlock* const last_map = map + vklass->nonstatic_oop_map_count(); 4241 while (map < last_map) { 4242 nonstatic_oop_maps->add(map->offset() + diff, map->count()); 4243 map++; 4244 } 4245 } 4246 break; 4247 } else { 4248 // Fall through 4249 } 4250 case NONSTATIC_OOP: 4251 if( nonstatic_oop_space_count > 0 ) { 4252 real_offset = nonstatic_oop_space_offset; 4253 nonstatic_oop_space_offset += heapOopSize; 4254 nonstatic_oop_space_count -= 1; 4255 } else { 4256 real_offset = next_nonstatic_oop_offset; 4257 next_nonstatic_oop_offset += heapOopSize; 4258 } 4259 nonstatic_oop_maps->add(real_offset, 1); 4260 break; 4261 case NONSTATIC_BYTE: 4262 if( nonstatic_byte_space_count > 0 ) { 4263 real_offset = nonstatic_byte_space_offset; 4264 nonstatic_byte_space_offset += 1; 4265 nonstatic_byte_space_count -= 1; 4266 } else { 4267 real_offset = next_nonstatic_byte_offset; 4268 next_nonstatic_byte_offset += 1; 4269 } |