RFR: 8273239: Standardize Ticks APIs return type

Albert Mingkun Yang ayang at openjdk.java.net
Thu Sep 2 12:28:28 UTC 2021


On Thu, 2 Sep 2021 10:44:21 GMT, David Holmes <dholmes at openjdk.org> wrote:

> Any changes to these API's should be approved by that team IMO.

I checked with Markus before sending out this PR.

> I'm more inclined to expect an API that produces integral values than fractions

Only `nanoseconds()` can return an integral value without discarding any info. Converting to other units requires some floating calculation; the fractional part is either dropped behind the API (in `master`) or controlled by the caller (in this patch). 

> Converting nanosecond time values to double can be information losing.

True. Such loss comes from the following conversion (from `ticks.hpp`). (Note: this kind of loss is different from the one discarding the fractional part on API boundary.)


template <typename TimeSource, const int unit>
inline double conversion(typename TimeSource::Type& value) {
  return (double)value * ((double)unit / (double)TimeSource::frequency());
}


I am not sure how significant this loss is in practice; all callers of `seconds()` (the most used API among the four) suffer from this loss.

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

PR: https://git.openjdk.java.net/jdk/pull/5332


More information about the hotspot-dev mailing list