[jdk18] RFR: 8279398: jdk/jfr/api/recording/time/TestTimeMultiple.java failed with "RuntimeException: getStopTime() > afterStop"
Erik Gahlin
egahlin at openjdk.java.net
Thu Jan 6 08:10:36 UTC 2022
Hi,
Could I have review of a fix of a regression introduced with "JDK-8268297: jdk/jfr/api/consumer/streaming/TestLatestEvent.java times out" https://bugs.openjdk.java.net/browse/JDK-8268297
Bumping the timestamp in native, if the timestamp has not changed, ensures that chunks gets a strictly increasing start time, which is needed for event streaming to order chunks chronologically.
Problem is that tests, and probably users as well, expect that the start/stop time of a recording never exceeds what a later invocation to Instant.now() returns, for example:
Recording a = new Recording();
a.start(); // first chunk begins
a.stop(); // first chunk ends
Recording b = new Recording();
b.start(); // second chunk begins, where time stamp is taken and possibly bumped with a nanosecond.
Instant now = Instant.now();
if (now.isBefore(b.getStartTime())) {
System.out.println("WAT");
}
This can happen on Windows where the clock has low resolution, so Recording::start() may finish execution without a clock change. The fix is to let methods that creates a new chunk spin until the clock has catched up.
To verify the fix, I modified the test jdk/jdk/jfr/api/recoding/time/TestTimeMultiple.java so it executes code similar to above 100 times per test and then ran the test 200 times without failures. Without the fix, failures were frequent.
Technically, it's not necessary for all places to use Utils::getChunkStartNanos() instead of JVM::getChunkStartNanos(), but it seemed more prudent to never use the low level function, which can in some circumstances lead to incorrect behavior.
Thanks
Erik
-------------
Commit messages:
- Remove whitespace
- Update comment
- Initial
Changes: https://git.openjdk.java.net/jdk18/pull/84/files
Webrev: https://webrevs.openjdk.java.net/?repo=jdk18&pr=84&range=00
Issue: https://bugs.openjdk.java.net/browse/JDK-8279398
Stats: 61 lines in 3 files changed: 31 ins; 23 del; 7 mod
Patch: https://git.openjdk.java.net/jdk18/pull/84.diff
Fetch: git fetch https://git.openjdk.java.net/jdk18 pull/84/head:pull/84
PR: https://git.openjdk.java.net/jdk18/pull/84
More information about the hotspot-jfr-dev
mailing list