comparison src/share/vm/graal/graalVMEntries.cpp @ 3656:56c8f567dfb6

Fix typeProfile : collect all receivers and counts before making java calls
author Gilles Duboscq <gilles.m.duboscq@gmail.com>
date Thu, 17 Nov 2011 16:08:14 +0100
parents 2a0cb564e470
children e0bbc6b1c4a1
comparison
equal deleted inserted replaced
3655:2a0cb564e470 3656:56c8f567dfb6
238 return NULL; 238 return NULL;
239 } 239 }
240 ProfileData* data = method_data->bci_to_data(bci); 240 ProfileData* data = method_data->bci_to_data(bci);
241 if (data != NULL && data->is_ReceiverTypeData()) { 241 if (data != NULL && data->is_ReceiverTypeData()) {
242 ReceiverTypeData* recv = data->as_ReceiverTypeData(); 242 ReceiverTypeData* recv = data->as_ReceiverTypeData();
243 GrowableArray<KlassHandle> receivers;
244 GrowableArray<int> counts;
243 // determine morphism 245 // determine morphism
244 int morphism = 0;
245 uint total_count = 0; 246 uint total_count = 0;
246 for (uint i = 0; i < recv->row_limit(); i++) { 247 for (uint i = 0; i < recv->row_limit(); i++) {
247 klassOop receiver = recv->receiver(i); 248 klassOop receiver = recv->receiver(i);
248 if (receiver == NULL) continue; 249 if (receiver == NULL) continue;
249 morphism++; 250 uint count = recv->receiver_count(i);
250 total_count += recv->receiver_count(i); 251 total_count += count;
252 receivers.append(receiver);
253 counts.append(count);
251 } 254 }
252 255
253 instanceKlass::cast(RiTypeProfile::klass())->initialize(CHECK_NULL); 256 instanceKlass::cast(RiTypeProfile::klass())->initialize(CHECK_NULL);
254 obj = instanceKlass::cast(RiTypeProfile::klass())->allocate_instance(CHECK_NULL); 257 obj = instanceKlass::cast(RiTypeProfile::klass())->allocate_instance(CHECK_NULL);
255 assert(obj() != NULL, "must succeed in allocating instance"); 258 assert(obj() != NULL, "must succeed in allocating instance");
256 259
257 int count = MAX2(total_count, recv->count()); 260 int count = MAX2(total_count, recv->count());
258 RiTypeProfile::set_count(obj, scale_count(method_data(), count)); 261 RiTypeProfile::set_count(obj, scale_count(method_data(), count));
259 RiTypeProfile::set_morphism(obj, morphism); 262 RiTypeProfile::set_morphism(obj, receivers.length());
260 263
261 if (morphism > 0) { 264 if (receivers.length() > 0) {
262 typeArrayHandle probabilities = oopFactory::new_typeArray(T_FLOAT, morphism, CHECK_NULL); 265 typeArrayHandle probabilities = oopFactory::new_typeArray(T_FLOAT, receivers.length(), CHECK_NULL);
263 objArrayHandle types = oopFactory::new_objArray(SystemDictionary::RiType_klass(), morphism, CHECK_NULL); 266 objArrayHandle types = oopFactory::new_objArray(SystemDictionary::RiType_klass(), receivers.length(), CHECK_NULL);
264 int pos = 0; 267 for (int i = 0; i < receivers.length(); i++) {
265 for (uint i = 0; i < recv->row_limit(); i++) { 268 KlassHandle receiver = receivers.at(i);
266 KlassHandle receiver = recv->receiver(i); 269
267 if (receiver.is_null()) continue; 270 float prob = counts.at(i) / (float) total_count;
268
269 float prob = recv->receiver_count(i) / (float) total_count;
270 Handle type = GraalCompiler::get_RiType(receiver, CHECK_NULL); 271 Handle type = GraalCompiler::get_RiType(receiver, CHECK_NULL);
271 272
272 probabilities->float_at_put(pos, prob); 273 probabilities->float_at_put(i, prob);
273 types->obj_at_put(pos, type()); 274 types->obj_at_put(i, type());
274 275
275 pos++;
276 } 276 }
277 277
278 RiTypeProfile::set_probabilities(obj, probabilities()); 278 RiTypeProfile::set_probabilities(obj, probabilities());
279 RiTypeProfile::set_types(obj, types()); 279 RiTypeProfile::set_types(obj, types());
280 } else { 280 } else {