Currently Parse::Parse() has the following code to initialize its trap counts:
// Accumulate deoptimization counts.
// (The range_check and store_check counts are checked elsewhere.)
ciMethodData* md = method()->method_data();
for (uint reason = 0; reason < md->trap_reason_limit(); reason++) {
uint md_count = md->trap_count(reason);
if (md_count != 0) {
if (md_count == md->trap_count_limit())
md_count += md->overflow_trap_count();
The intention of this code is to also take into account the `overflow_trap_count()` for trap reasons which have overflowed.
But the code is wrong, because `md->trap_count(reason)` will return `(uint)-1` if an overflow happened and `md->trap_count_limit()` will return `(jubyte)-1` (i.e. 0xff) so the condition `md_count == md->trap_count_limit()` will never be true if an overflow happened.
Instead the code should be something like:
if (md_count == (uint)-1) {
md_count = md->trap_count_limit() + md->overflow_trap_count();
// Accumulate deoptimization counts.
// (The range_check and store_check counts are checked elsewhere.)
ciMethodData* md = method()->method_data();
for (uint reason = 0; reason < md->trap_reason_limit(); reason++) {
uint md_count = md->trap_count(reason);
if (md_count != 0) {
if (md_count == md->trap_count_limit())
md_count += md->overflow_trap_count();
The intention of this code is to also take into account the `overflow_trap_count()` for trap reasons which have overflowed.
But the code is wrong, because `md->trap_count(reason)` will return `(uint)-1` if an overflow happened and `md->trap_count_limit()` will return `(jubyte)-1` (i.e. 0xff) so the condition `md_count == md->trap_count_limit()` will never be true if an overflow happened.
Instead the code should be something like:
if (md_count == (uint)-1) {
md_count = md->trap_count_limit() + md->overflow_trap_count();