RFR: 8310606: Fix signed integer overflow, part 3 [v2]

Dean Long dlong at openjdk.org
Fri Jun 23 22:00:10 UTC 2023


On Fri, 23 Jun 2023 17:45:56 GMT, Andrew Haley <aph at openjdk.org> wrote:

>> src/hotspot/share/jfr/leakprofiler/utilities/granularTimer.cpp line 41:
>> 
>>> 39:   const julong end_time_ticks = (julong)_start_time_ticks.value() + (julong)duration_ticks;
>>> 40:   _finish_time_ticks = end_time_ticks > (julong)max_jlong ? JfrTicks(max_jlong) : JfrTicks(end_time_ticks);
>>> 41:   _finished = _finish_time_ticks == _start_time_ticks;
>> 
>> Isn't there a much better way to fix this?
>
> If you change 
> 
> `if (JfrTicks::now() > _finish_time_ticks) {`
> 
> to
> 
> `if (JfrTicks::now() - _finish_time_ticks > 0) {`
> 
> you get natural wrap-around semantics. As long as the total interval is less than half the total julong range. And you don't need to worry about `max_jlong`, etc.

The problem here is Java code is passing a value of max_jlong for duration_ticks.  I don't see how changing the logic (in is_finished()?) helps with that.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/14619#discussion_r1240441233


More information about the hotspot-dev mailing list