From e25a9e7fd86e4eaf020e54021efaa7059dc654c9 Mon Sep 17 00:00:00 2001 From: Erik Gahlin Date: Wed, 4 Sep 2024 12:08:16 +0000 Subject: [PATCH] 8339486: JFR: Modernize Reviewed-by: mgronlun --- .../share/classes/jdk/jfr/internal/PlatformRecorder.java | 2 +- .../share/classes/jdk/jfr/internal/query/Function.java | 2 +- .../share/classes/jdk/jfr/internal/util/StopWatch.java | 4 ++-- test/jdk/jdk/jfr/api/event/TestGetDuration.java | 6 +++--- test/jdk/jdk/jfr/api/recording/misc/TestGetStream.java | 4 ++-- test/jdk/jdk/jfr/api/recording/options/TestDuration.java | 4 ++-- test/jdk/jdk/jfr/api/recording/state/TestStateDuration.java | 4 ++-- .../jdk/jfr/api/recording/state/TestStateScheduleStart.java | 4 ++-- test/jdk/jdk/jfr/event/runtime/TestThreadCpuTimeEvent.java | 4 ++-- 9 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/jdk.jfr/share/classes/jdk/jfr/internal/PlatformRecorder.java b/src/jdk.jfr/share/classes/jdk/jfr/internal/PlatformRecorder.java index 24b98bb629f..b33a8943042 100644 --- a/src/jdk.jfr/share/classes/jdk/jfr/internal/PlatformRecorder.java +++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/PlatformRecorder.java @@ -657,7 +657,7 @@ public final class PlatformRecorder { } target.setStartTime(startTime); target.setStopTime(endTime); - target.setInternalDuration(Duration.between(startTime, endTime)); + target.setInternalDuration(startTime.until(endTime)); } public synchronized void migrate(SafePath repo) throws IOException { diff --git a/src/jdk.jfr/share/classes/jdk/jfr/internal/query/Function.java b/src/jdk.jfr/share/classes/jdk/jfr/internal/query/Function.java index 9540834b87a..29d55e95673 100644 --- a/src/jdk.jfr/share/classes/jdk/jfr/internal/query/Function.java +++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/query/Function.java @@ -472,7 +472,7 @@ abstract class Function { if (last == null) { return ChronoUnit.FOREVER.getDuration(); } - return Duration.between(first, last); + return first.until(last); } } diff --git a/src/jdk.jfr/share/classes/jdk/jfr/internal/util/StopWatch.java b/src/jdk.jfr/share/classes/jdk/jfr/internal/util/StopWatch.java index 24bf3d16b01..cf775f7d995 100644 --- a/src/jdk.jfr/share/classes/jdk/jfr/internal/util/StopWatch.java +++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/util/StopWatch.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -62,7 +62,7 @@ public final class StopWatch { for (int i = 0; i < timings.size() - 1; i++) { Timing current = timings.get(i); Timing next = timings.get(i + 1); - Duration d = Duration.between(current.start(), next.start()); + Duration d = current.start().until(next.start()); sb.add(current.name() + "=" + ValueFormatter.formatDuration(d)); } return sb.toString(); diff --git a/test/jdk/jdk/jfr/api/event/TestGetDuration.java b/test/jdk/jdk/jfr/api/event/TestGetDuration.java index c3242ea90c7..b25969198ed 100644 --- a/test/jdk/jdk/jfr/api/event/TestGetDuration.java +++ b/test/jdk/jdk/jfr/api/event/TestGetDuration.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2024, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -87,7 +87,7 @@ public class TestGetDuration { Events.hasEvents(testEvents); for (RecordedEvent re : testEvents) { int id = re.getValue("id"); - Asserts.assertEquals(re.getDuration(), Duration.between(re.getStartTime(), re.getEndTime())); + Asserts.assertEquals(re.getDuration(), re.getStartTime().until(re.getEndTime())); switch (id) { case DURATIONAL_EVENT_ID: Asserts.assertTrue(!re.getDuration().isNegative() && !re.getDuration().isZero()); @@ -111,7 +111,7 @@ public class TestGetDuration { List recordedEvents = Events.fromRecording(r); Events.hasEvents(recordedEvents); for (RecordedEvent re : recordedEvents) { - Asserts.assertEquals(re.getDuration(), Duration.between(re.getStartTime(), re.getEndTime())); + Asserts.assertEquals(re.getDuration(), re.getStartTime().until(re.getEndTime())); switch (re.getEventType().getName()) { case EventNames.JVMInformation: Asserts.assertTrue(re.getDuration().isZero()); diff --git a/test/jdk/jdk/jfr/api/recording/misc/TestGetStream.java b/test/jdk/jdk/jfr/api/recording/misc/TestGetStream.java index dd936101caa..3b353d0968b 100644 --- a/test/jdk/jdk/jfr/api/recording/misc/TestGetStream.java +++ b/test/jdk/jdk/jfr/api/recording/misc/TestGetStream.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2024, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -88,7 +88,7 @@ public class TestGetStream { } private static void printTimeStamp(String name, Instant t) { - Duration s = Duration.between(offset, t); + Duration s = offset.until(t); System.out.println(name + ": " + (s.getSeconds() * 1_000_000_000L + s.getNano())); } diff --git a/test/jdk/jdk/jfr/api/recording/options/TestDuration.java b/test/jdk/jdk/jfr/api/recording/options/TestDuration.java index 6a2ef2c30cd..8f231ab77a0 100644 --- a/test/jdk/jdk/jfr/api/recording/options/TestDuration.java +++ b/test/jdk/jdk/jfr/api/recording/options/TestDuration.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -53,7 +53,7 @@ public class TestDuration { Instant afterStop = Instant.now(); Asserts.assertLessThanOrEqual(r.getStopTime(), afterStop, "getStopTime() > afterStop"); - long durationMillis = Duration.between(afterStart, r.getStopTime()).toMillis(); + long durationMillis = afterStart.until(r.getStopTime()).toMillis(); // Performance of test servers varies too much to make a strict check of actual duration. // We only check that recording stops before timeout of 20 seconds. diff --git a/test/jdk/jdk/jfr/api/recording/state/TestStateDuration.java b/test/jdk/jdk/jfr/api/recording/state/TestStateDuration.java index bdf620fa1b3..5e8ef60b367 100644 --- a/test/jdk/jdk/jfr/api/recording/state/TestStateDuration.java +++ b/test/jdk/jdk/jfr/api/recording/state/TestStateDuration.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -55,7 +55,7 @@ public class TestStateDuration { System.out.println("Waiting for recording to reach STOPPED state"); CommonHelper.waitForRecordingState(r, RecordingState.STOPPED); Instant stop = Instant.now(); - Duration measuredDuration = Duration.between(start, stop); + Duration measuredDuration = start.until(stop); System.out.println("Recording stopped at " + stop + ". Measured duration " + measuredDuration); // Timer task uses System.currentMillis, and java.time uses other source. Duration deltaDueToClockNotInSync = Duration.ofMillis(100); diff --git a/test/jdk/jdk/jfr/api/recording/state/TestStateScheduleStart.java b/test/jdk/jdk/jfr/api/recording/state/TestStateScheduleStart.java index ddeee64a7b4..3708ded56f1 100644 --- a/test/jdk/jdk/jfr/api/recording/state/TestStateScheduleStart.java +++ b/test/jdk/jdk/jfr/api/recording/state/TestStateScheduleStart.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -55,7 +55,7 @@ public class TestStateScheduleStart { // Test servers vary too much in performance to make an accurate check. // We only check that we don't time out after 20 seconds. Instant started = Instant.now(); - long millis = Duration.between(start, started).toMillis(); + long millis = start.until(started).toMillis(); System.out.println("Recording started at " + started + ". Delta millis=" + millis + ", expected about 2000"); verifyIllegalState(() -> r.start(), "double start()"); diff --git a/test/jdk/jdk/jfr/event/runtime/TestThreadCpuTimeEvent.java b/test/jdk/jdk/jfr/event/runtime/TestThreadCpuTimeEvent.java index a3ebb1550db..a6520614eab 100644 --- a/test/jdk/jdk/jfr/event/runtime/TestThreadCpuTimeEvent.java +++ b/test/jdk/jdk/jfr/event/runtime/TestThreadCpuTimeEvent.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -93,7 +93,7 @@ public class TestThreadCpuTimeEvent { barrier.await(); Instant start = Instant.now(); counter = 0; - while ((Duration.between(start, Instant.now()).compareTo(runTime) < 0) || + while ((start.until(Instant.now()).compareTo(runTime) < 0) || (counter < cpuConsumerMinCount)) { counter++; }