Mercurial > hg > graal-jvmci-8
comparison src/share/vm/graal/graalVMEntries.cpp @ 3662:e0bbc6b1c4a1
Fixed wrong type transition.
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Thu, 17 Nov 2011 18:02:12 +0100 |
parents | 56c8f567dfb6 |
children | 8c46cdb684d4 |
comparison
equal
deleted
inserted
replaced
3661:d24f157f2ba8 | 3662:e0bbc6b1c4a1 |
---|---|
226 } | 226 } |
227 | 227 |
228 // public native RiTypeProfile RiMethod_typeProfile(long vmId, int bci); | 228 // public native RiTypeProfile RiMethod_typeProfile(long vmId, int bci); |
229 JNIEXPORT jobject JNICALL Java_com_oracle_graal_hotspot_VMEntries_RiMethod_2typeProfile(JNIEnv *, jobject, jobject hotspot_method, jint bci) { | 229 JNIEXPORT jobject JNICALL Java_com_oracle_graal_hotspot_VMEntries_RiMethod_2typeProfile(JNIEnv *, jobject, jobject hotspot_method, jint bci) { |
230 TRACE_graal_3("VMEntries::RiMethod_typeProfile"); | 230 TRACE_graal_3("VMEntries::RiMethod_typeProfile"); |
231 VM_ENTRY_MARK; | |
231 Handle obj; | 232 Handle obj; |
232 { | 233 |
233 VM_ENTRY_MARK; | 234 methodHandle method = getMethodFromHotSpotMethod(hotspot_method); |
234 ResourceMark rm; | 235 methodDataHandle method_data = method->method_data(); |
235 methodHandle method = getMethodFromHotSpotMethod(hotspot_method); | 236 if (method_data == NULL || !method_data->is_mature()) { |
236 methodDataHandle method_data = method->method_data(); | 237 return NULL; |
237 if (method_data == NULL || !method_data->is_mature()) { | 238 } |
238 return NULL; | 239 ProfileData* data = method_data->bci_to_data(bci); |
239 } | 240 if (data != NULL && data->is_ReceiverTypeData()) { |
240 ProfileData* data = method_data->bci_to_data(bci); | 241 ReceiverTypeData* recv = data->as_ReceiverTypeData(); |
241 if (data != NULL && data->is_ReceiverTypeData()) { | 242 GrowableArray<KlassHandle> receivers; |
242 ReceiverTypeData* recv = data->as_ReceiverTypeData(); | 243 GrowableArray<int> counts; |
243 GrowableArray<KlassHandle> receivers; | 244 // determine morphism |
244 GrowableArray<int> counts; | 245 uint total_count = 0; |
245 // determine morphism | 246 for (uint i = 0; i < recv->row_limit(); i++) { |
246 uint total_count = 0; | 247 klassOop receiver = recv->receiver(i); |
247 for (uint i = 0; i < recv->row_limit(); i++) { | 248 if (receiver == NULL) continue; |
248 klassOop receiver = recv->receiver(i); | 249 uint count = recv->receiver_count(i); |
249 if (receiver == NULL) continue; | 250 total_count += count; |
250 uint count = recv->receiver_count(i); | 251 receivers.append(receiver); |
251 total_count += count; | 252 counts.append(count); |
252 receivers.append(receiver); | 253 } |
253 counts.append(count); | 254 |
255 instanceKlass::cast(RiTypeProfile::klass())->initialize(CHECK_NULL); | |
256 obj = instanceKlass::cast(RiTypeProfile::klass())->allocate_instance(CHECK_NULL); | |
257 assert(obj() != NULL, "must succeed in allocating instance"); | |
258 | |
259 int count = MAX2(total_count, recv->count()); | |
260 RiTypeProfile::set_count(obj, scale_count(method_data(), count)); | |
261 RiTypeProfile::set_morphism(obj, receivers.length()); | |
262 | |
263 if (receivers.length() > 0) { | |
264 typeArrayHandle probabilities = oopFactory::new_typeArray(T_FLOAT, receivers.length(), CHECK_NULL); | |
265 objArrayHandle types = oopFactory::new_objArray(SystemDictionary::RiType_klass(), receivers.length(), CHECK_NULL); | |
266 for (int i = 0; i < receivers.length(); i++) { | |
267 KlassHandle receiver = receivers.at(i); | |
268 | |
269 float prob = counts.at(i) / (float) total_count; | |
270 Handle type = GraalCompiler::get_RiType(receiver, CHECK_NULL); | |
271 | |
272 probabilities->float_at_put(i, prob); | |
273 types->obj_at_put(i, type()); | |
274 | |
254 } | 275 } |
255 | 276 |
256 instanceKlass::cast(RiTypeProfile::klass())->initialize(CHECK_NULL); | 277 RiTypeProfile::set_probabilities(obj, probabilities()); |
257 obj = instanceKlass::cast(RiTypeProfile::klass())->allocate_instance(CHECK_NULL); | 278 RiTypeProfile::set_types(obj, types()); |
258 assert(obj() != NULL, "must succeed in allocating instance"); | 279 } else { |
259 | 280 RiTypeProfile::set_probabilities(obj, NULL); |
260 int count = MAX2(total_count, recv->count()); | 281 RiTypeProfile::set_types(obj, NULL); |
261 RiTypeProfile::set_count(obj, scale_count(method_data(), count)); | 282 } |
262 RiTypeProfile::set_morphism(obj, receivers.length()); | 283 } |
263 | |
264 if (receivers.length() > 0) { | |
265 typeArrayHandle probabilities = oopFactory::new_typeArray(T_FLOAT, receivers.length(), CHECK_NULL); | |
266 objArrayHandle types = oopFactory::new_objArray(SystemDictionary::RiType_klass(), receivers.length(), CHECK_NULL); | |
267 for (int i = 0; i < receivers.length(); i++) { | |
268 KlassHandle receiver = receivers.at(i); | |
269 | |
270 float prob = counts.at(i) / (float) total_count; | |
271 Handle type = GraalCompiler::get_RiType(receiver, CHECK_NULL); | |
272 | |
273 probabilities->float_at_put(i, prob); | |
274 types->obj_at_put(i, type()); | |
275 | |
276 } | |
277 | |
278 RiTypeProfile::set_probabilities(obj, probabilities()); | |
279 RiTypeProfile::set_types(obj, types()); | |
280 } else { | |
281 RiTypeProfile::set_probabilities(obj, NULL); | |
282 RiTypeProfile::set_types(obj, NULL); | |
283 } | |
284 } | |
285 } | |
286 | |
287 return JNIHandles::make_local(obj()); | 284 return JNIHandles::make_local(obj()); |
288 } | 285 } |
289 | 286 |
290 JNIEXPORT jdouble JNICALL Java_com_oracle_graal_hotspot_VMEntries_RiMethod_2branchProbability(JNIEnv *, jobject, jobject hotspot_method, jint bci) { | 287 JNIEXPORT jdouble JNICALL Java_com_oracle_graal_hotspot_VMEntries_RiMethod_2branchProbability(JNIEnv *, jobject, jobject hotspot_method, jint bci) { |
291 TRACE_graal_3("VMEntries::RiMethod_typeProfile"); | 288 TRACE_graal_3("VMEntries::RiMethod_typeProfile"); |