Mercurial > hg > truffle
comparison src/share/vm/graal/graalVMEntries.cpp @ 3211:76507b87dd25
global absolute probability analysis:
* added switch probability, changed branch probability from int to double
* absolute probability on each FixedNode computed by new ComputeProbabilityPhase
* loopFrequency estimation on LoopBegin nodes
* added GraalOptions.ProbabilityAnalysis flag: builds probability information and let inlining and escape analysis use it
author | Lukas Stadler <lukas.stadler@jku.at> |
---|---|
date | Tue, 12 Jul 2011 17:00:25 +0200 |
parents | 2fb14099d069 |
children | 8cd198d7cbc1 |
comparison
equal
deleted
inserted
replaced
3210:27ae76ed33ca | 3211:76507b87dd25 |
---|---|
249 } | 249 } |
250 | 250 |
251 return JNIHandles::make_local(obj()); | 251 return JNIHandles::make_local(obj()); |
252 } | 252 } |
253 | 253 |
254 // public native RiTypeProfile RiMethod_branchProfile(long vmId, int bci); | 254 JNIEXPORT jdouble JNICALL Java_com_oracle_graal_runtime_VMEntries_RiMethod_2branchProbability(JNIEnv *, jobject, jobject hotspot_method, jint bci) { |
255 JNIEXPORT jint JNICALL Java_com_oracle_graal_runtime_VMEntries_RiMethod_2branchProbability(JNIEnv *, jobject, jobject hotspot_method, jint bci) { | |
256 TRACE_graal_3("VMEntries::RiMethod_typeProfile"); | 255 TRACE_graal_3("VMEntries::RiMethod_typeProfile"); |
257 ciMethodData* method_data; | 256 ciMethodData* method_data; |
258 ciMethod* cimethod; | 257 ciMethod* cimethod; |
259 { | 258 { |
260 VM_ENTRY_MARK; | 259 VM_ENTRY_MARK; |
275 int not_taken = 0; | 274 int not_taken = 0; |
276 if (data->is_BranchData()) { | 275 if (data->is_BranchData()) { |
277 not_taken = data->as_BranchData()->not_taken(); | 276 not_taken = data->as_BranchData()->not_taken(); |
278 } | 277 } |
279 | 278 |
280 // scale the counts to be commensurate with invocation counts: | |
281 taken = cimethod->scale_count(taken); | |
282 not_taken = cimethod->scale_count(not_taken); | |
283 | |
284 // Give up if too few (or too many, in which case the sum will overflow) counts to be meaningful. | 279 // Give up if too few (or too many, in which case the sum will overflow) counts to be meaningful. |
285 // We also check that individual counters are positive first, otherwise the sum can become positive. | 280 // We also check that individual counters are positive first, otherwise the sum can become positive. |
286 if (taken < 0 || not_taken < 0 || taken + not_taken < 40) return -1; | 281 if (taken < 0 || not_taken < 0 || taken + not_taken < 40) return -1; |
287 | 282 |
288 // Pin probability to sane limits | 283 // Pin probability to sane limits |
289 if (taken == 0) | 284 if (taken == 0) |
290 return 0; | 285 return 0; |
291 else if (not_taken == 0) | 286 else if (not_taken == 0) |
292 return 100; | 287 return 1; |
293 else { // Compute probability of true path | 288 else { // Compute probability of true path |
294 int probability = (int)(taken * 100.0 / (taken + not_taken)); | 289 return (jdouble)(taken) / (taken + not_taken); |
295 return MIN2(99, MAX2(1, probability)); | 290 } |
291 } | |
292 | |
293 JNIEXPORT jobject JNICALL Java_com_oracle_graal_runtime_VMEntries_RiMethod_2switchProbability(JNIEnv *, jobject, jobject hotspot_method, jint bci) { | |
294 TRACE_graal_3("VMEntries::RiMethod_typeProfile"); | |
295 ciMethodData* method_data; | |
296 ciMethod* cimethod; | |
297 { | |
298 VM_ENTRY_MARK; | |
299 methodOop method = getMethodFromHotSpotMethod(hotspot_method); | |
300 cimethod = (ciMethod*)CURRENT_ENV->get_object(method); | |
301 } | |
302 method_data = cimethod->method_data(); | |
303 | |
304 jfloat probability = -1; | |
305 | |
306 if (method_data == NULL || !method_data->is_mature()) return NULL; | |
307 | |
308 ciProfileData* data = method_data->bci_to_data(bci); | |
309 if (data == NULL || !data->is_MultiBranchData()) return NULL; | |
310 | |
311 MultiBranchData* branch_data = data->as_MultiBranchData(); | |
312 | |
313 long sum = 0; | |
314 int cases = branch_data->number_of_cases(); | |
315 GrowableArray<uint>* counts = new GrowableArray<uint>(cases + 1); | |
316 | |
317 for (int i = 0; i < cases; i++) { | |
318 uint value = branch_data->count_at(i); | |
319 sum += value; | |
320 counts->append(value); | |
321 } | |
322 uint value = branch_data->default_count(); | |
323 sum += value; | |
324 counts->append(value); | |
325 | |
326 // Give up if too few (or too many, in which case the sum will overflow) counts to be meaningful. | |
327 // We also check that individual counters are positive first, otherwise the sum can become positive. | |
328 if (sum < 10 * (cases + 3)) return NULL; | |
329 | |
330 { | |
331 VM_ENTRY_MARK; | |
332 typeArrayOop probability = oopFactory::new_typeArray(T_DOUBLE, cases + 1, CHECK_NULL); | |
333 for (int i = 0; i < cases + 1; i++) { | |
334 probability->double_at_put(i, counts->at(i) / (double) sum); | |
335 } | |
336 return JNIHandles::make_local(probability); | |
296 } | 337 } |
297 } | 338 } |
298 | 339 |
299 // public RiType RiSignature_lookupType(String returnType, HotSpotTypeResolved accessingClass); | 340 // public RiType RiSignature_lookupType(String returnType, HotSpotTypeResolved accessingClass); |
300 JNIEXPORT jobject JNICALL Java_com_oracle_graal_runtime_VMEntries_RiSignature_1lookupType(JNIEnv *env, jobject, jstring jname, jobject accessingClass) { | 341 JNIEXPORT jobject JNICALL Java_com_oracle_graal_runtime_VMEntries_RiSignature_1lookupType(JNIEnv *env, jobject, jstring jname, jobject accessingClass) { |
854 {CC"RiMethod_signature", CC"("RESOLVED_METHOD")"STRING, FN_PTR(Java_com_oracle_graal_runtime_VMEntries_RiMethod_1signature)}, | 895 {CC"RiMethod_signature", CC"("RESOLVED_METHOD")"STRING, FN_PTR(Java_com_oracle_graal_runtime_VMEntries_RiMethod_1signature)}, |
855 {CC"RiMethod_exceptionHandlers", CC"("RESOLVED_METHOD")"EXCEPTION_HANDLERS, FN_PTR(Java_com_oracle_graal_runtime_VMEntries_RiMethod_1exceptionHandlers)}, | 896 {CC"RiMethod_exceptionHandlers", CC"("RESOLVED_METHOD")"EXCEPTION_HANDLERS, FN_PTR(Java_com_oracle_graal_runtime_VMEntries_RiMethod_1exceptionHandlers)}, |
856 {CC"RiMethod_hasBalancedMonitors", CC"("RESOLVED_METHOD")Z", FN_PTR(Java_com_oracle_graal_runtime_VMEntries_RiMethod_1hasBalancedMonitors)}, | 897 {CC"RiMethod_hasBalancedMonitors", CC"("RESOLVED_METHOD")Z", FN_PTR(Java_com_oracle_graal_runtime_VMEntries_RiMethod_1hasBalancedMonitors)}, |
857 {CC"RiMethod_uniqueConcreteMethod", CC"("RESOLVED_METHOD")"METHOD, FN_PTR(Java_com_oracle_graal_runtime_VMEntries_RiMethod_1uniqueConcreteMethod)}, | 898 {CC"RiMethod_uniqueConcreteMethod", CC"("RESOLVED_METHOD")"METHOD, FN_PTR(Java_com_oracle_graal_runtime_VMEntries_RiMethod_1uniqueConcreteMethod)}, |
858 {CC"RiMethod_typeProfile", CC"("RESOLVED_METHOD"I)"TYPE_PROFILE, FN_PTR(Java_com_oracle_graal_runtime_VMEntries_RiMethod_2typeProfile)}, | 899 {CC"RiMethod_typeProfile", CC"("RESOLVED_METHOD"I)"TYPE_PROFILE, FN_PTR(Java_com_oracle_graal_runtime_VMEntries_RiMethod_2typeProfile)}, |
859 {CC"RiMethod_branchProbability", CC"("RESOLVED_METHOD"I)I", FN_PTR(Java_com_oracle_graal_runtime_VMEntries_RiMethod_2branchProbability)}, | 900 {CC"RiMethod_branchProbability", CC"("RESOLVED_METHOD"I)D", FN_PTR(Java_com_oracle_graal_runtime_VMEntries_RiMethod_2branchProbability)}, |
901 {CC"RiMethod_switchProbability", CC"("RESOLVED_METHOD"I)[D", FN_PTR(Java_com_oracle_graal_runtime_VMEntries_RiMethod_2switchProbability)}, | |
860 {CC"RiMethod_invocationCount", CC"("RESOLVED_METHOD")I", FN_PTR(Java_com_oracle_graal_runtime_VMEntries_RiMethod_1invocationCount)}, | 902 {CC"RiMethod_invocationCount", CC"("RESOLVED_METHOD")I", FN_PTR(Java_com_oracle_graal_runtime_VMEntries_RiMethod_1invocationCount)}, |
861 {CC"RiMethod_exceptionProbability", CC"("RESOLVED_METHOD"I)I", FN_PTR(Java_com_oracle_graal_runtime_VMEntries_RiMethod_2exceptionProbability)}, | 903 {CC"RiMethod_exceptionProbability", CC"("RESOLVED_METHOD"I)I", FN_PTR(Java_com_oracle_graal_runtime_VMEntries_RiMethod_2exceptionProbability)}, |
862 {CC"RiSignature_lookupType", CC"("STRING RESOLVED_TYPE")"TYPE, FN_PTR(Java_com_oracle_graal_runtime_VMEntries_RiSignature_1lookupType)}, | 904 {CC"RiSignature_lookupType", CC"("STRING RESOLVED_TYPE")"TYPE, FN_PTR(Java_com_oracle_graal_runtime_VMEntries_RiSignature_1lookupType)}, |
863 {CC"RiConstantPool_lookupConstant", CC"("PROXY"I)"OBJECT, FN_PTR(Java_com_oracle_graal_runtime_VMEntries_RiConstantPool_1lookupConstant)}, | 905 {CC"RiConstantPool_lookupConstant", CC"("PROXY"I)"OBJECT, FN_PTR(Java_com_oracle_graal_runtime_VMEntries_RiConstantPool_1lookupConstant)}, |
864 {CC"RiConstantPool_lookupMethod", CC"("PROXY"IB)"METHOD, FN_PTR(Java_com_oracle_graal_runtime_VMEntries_RiConstantPool_1lookupMethod)}, | 906 {CC"RiConstantPool_lookupMethod", CC"("PROXY"IB)"METHOD, FN_PTR(Java_com_oracle_graal_runtime_VMEntries_RiConstantPool_1lookupMethod)}, |