< prev index next >
src/hotspot/share/ci/ciMethod.cpp
Print this page
*** 460,469 ****
--- 460,489 ----
}
#endif // COMPILER1
// ------------------------------------------------------------------
+ // ciMethod::saturated_add
+ //
+ // Update profile counters with saturating addition
+ // Wil check and handle the overflow condition
+ template <typename L, typename R>
+ int ciMethod::saturated_add(L a, R b) {
+ jlong src1 = a;
+ jlong src2 = b;
+ jlong sum = src1 + src2;
+ if (sum > max_jint) {
+ sum = max_jint;
+ } else if (sum < min_jint) {
+ sum = min_jint;
+ }
+
+ return (int)sum;
+ }
+
+
+ // ------------------------------------------------------------------
// ciMethod::call_profile_at_bci
//
// Get the ciCallProfile for the invocation of this method.
// Also reports receiver types for non-call type checks (if TypeProfileCasts).
ciCallProfile ciMethod::call_profile_at_bci(int bci) {
*** 500,512 ****
}
}
for (uint i = 0; i < call->row_limit(); i++) {
ciKlass* receiver = call->receiver(i);
if (receiver == NULL) continue;
! int rcount = call->receiver_count(i) + epsilon;
if (rcount == 0) rcount = 1; // Should be valid value
! receivers_count_total += rcount;
// Add the receiver to result data.
result.add_receiver(receiver, rcount);
// If we extend profiling to record methods,
// we will set result._method also.
}
--- 520,532 ----
}
}
for (uint i = 0; i < call->row_limit(); i++) {
ciKlass* receiver = call->receiver(i);
if (receiver == NULL) continue;
! int rcount = saturated_add(call->receiver_count(i), epsilon);
if (rcount == 0) rcount = 1; // Should be valid value
! receivers_count_total = saturated_add(receivers_count_total, rcount);
// Add the receiver to result data.
result.add_receiver(receiver, rcount);
// If we extend profiling to record methods,
// we will set result._method also.
}
*** 532,542 ****
// Make the count consistent if this is a call profile. If count is
// zero or less, presume that this is a typecheck profile and
// do nothing. Otherwise, increase count to be the sum of all
// receiver's counts.
if (count >= 0) {
! count += receivers_count_total;
}
}
result._count = count;
}
}
--- 552,562 ----
// Make the count consistent if this is a call profile. If count is
// zero or less, presume that this is a typecheck profile and
// do nothing. Otherwise, increase count to be the sum of all
// receiver's counts.
if (count >= 0) {
! count = saturated_add(count, receivers_count_total);
}
}
result._count = count;
}
}
< prev index next >