diff --git a/src/share/classes/jdk/jfr/Recording.java b/src/share/classes/jdk/jfr/Recording.java index bf9e4352bb4572bc2df49e7afa002e3e7d3f8821..9b0a1ef4942859b35eadc572853793896791c1ce 100644 --- a/src/share/classes/jdk/jfr/Recording.java +++ b/src/share/classes/jdk/jfr/Recording.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2020, 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 @@ -424,7 +424,7 @@ public final class Recording implements Closeable { * * @since 14 */ - public void setFlushInterval(Duration interval) { + /*package private*/ void setFlushInterval(Duration interval) { Objects.nonNull(interval); if (interval.isNegative()) { throw new IllegalArgumentException("Stream interval can't be negative"); @@ -439,7 +439,7 @@ public final class Recording implements Closeable { * * @since 14 */ - public Duration getFlushInterval() { + /*package private*/ Duration getFlushInterval() { return internal.getFlushInterval(); } diff --git a/src/share/classes/jdk/jfr/consumer/RecordingStream.java b/src/share/classes/jdk/jfr/consumer/RecordingStream.java index 70d13baf98c2d0a34e498a15e0fb72e61faa437c..054770a8dcbba053669bf6fd3b3540af85f7afd8 100644 --- a/src/share/classes/jdk/jfr/consumer/RecordingStream.java +++ b/src/share/classes/jdk/jfr/consumer/RecordingStream.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 2020, 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 @@ -86,7 +86,6 @@ public final class RecordingStream implements AutoCloseable, EventStream { Utils.checkAccessFlightRecorder(); AccessControlContext acc = AccessController.getContext(); this.recording = new Recording(); - this.recording.setFlushInterval(Duration.ofMillis(1000)); try { PlatformRecording pr = PrivateAccess.getInstance().getPlatformRecording(recording); this.directoryStream = new EventDirectoryStream(acc, null, SecuritySupport.PRIVILIGED, pr); @@ -267,20 +266,6 @@ public final class RecordingStream implements AutoCloseable, EventStream { recording.setMaxSize(maxSize); } - /** - * Determines how often events are made available for streaming. - * - * @param interval the interval at which events are made available to the - * stream, no {@code null} - * - * @throws IllegalArgumentException if {@code interval} is negative - * - * @throws IllegalStateException if the stream is closed - */ - public void setFlushInterval(Duration interval) { - recording.setFlushInterval(interval); - } - @Override public void setReuse(boolean reuse) { directoryStream.setReuse(reuse); diff --git a/src/share/classes/jdk/jfr/internal/dcmd/DCmdStart.java b/src/share/classes/jdk/jfr/internal/dcmd/DCmdStart.java index adc73fddf71197f732bf4681c8540f650e726fff..db0534d7d4c42cf8599b7445a7494aab84f05e0b 100644 --- a/src/share/classes/jdk/jfr/internal/dcmd/DCmdStart.java +++ b/src/share/classes/jdk/jfr/internal/dcmd/DCmdStart.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2020, 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 @@ -45,6 +45,7 @@ import jdk.jfr.internal.LogTag; import jdk.jfr.internal.Logger; import jdk.jfr.internal.Options; import jdk.jfr.internal.OldObjectSample; +import jdk.jfr.internal.PlatformRecording; import jdk.jfr.internal.PrivateAccess; import jdk.jfr.internal.SecuritySupport.SafePath; import jdk.jfr.internal.Type; @@ -196,7 +197,8 @@ final class DCmdStart extends AbstractDCmd { } if (flush != null) { - recording.setFlushInterval(Duration.ofNanos(flush)); + PlatformRecording p = PrivateAccess.getInstance().getPlatformRecording(recording); + p.setFlushInterval(Duration.ofNanos(flush)); } if (maxSize != null) { diff --git a/test/jdk/jfr/api/consumer/recordingstream/TestSetEndTime.java b/test/jdk/jfr/api/consumer/recordingstream/TestSetEndTime.java index 8a8c0da3132f9eb66c12b9433c1d5beda65fe001..4c76faa10d7969449a25628b915b19222ea9d5e0 100644 --- a/test/jdk/jfr/api/consumer/recordingstream/TestSetEndTime.java +++ b/test/jdk/jfr/api/consumer/recordingstream/TestSetEndTime.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 2020, 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 @@ -77,7 +77,6 @@ public final class TestSetEndTime { CountDownLatch closed = new CountDownLatch(1); AtomicInteger count = new AtomicInteger(); try (RecordingStream rs = new RecordingStream()) { - rs.setFlushInterval(Duration.ofSeconds(1)); rs.onEvent(e -> { count.incrementAndGet(); }); diff --git a/test/jdk/jfr/api/consumer/recordingstream/TestSetFlushInterval.java b/test/jdk/jfr/api/consumer/recordingstream/TestSetFlushInterval.java deleted file mode 100644 index 657139354929435ae70e457951ec66c9cd2ede6b..0000000000000000000000000000000000000000 --- a/test/jdk/jfr/api/consumer/recordingstream/TestSetFlushInterval.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2019, 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 - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package jdk.jfr.api.consumer.recordingstream; - -import java.time.Duration; - -import jdk.jfr.consumer.RecordingStream; -import jdk.test.lib.jfr.EventNames; - -/** - * @test - * @summary Tests RecordingStream::setFlushInterval - * @key jfr - * @library /lib / - * @run main/othervm jdk.jfr.api.consumer.recordingstream.TestSetFlushInterval - */ -public class TestSetFlushInterval { - - public static void main(String... args) throws Exception { - Duration expectedDuration = Duration.ofMillis(1001); - try (RecordingStream r = new RecordingStream()) { - r.setFlushInterval(expectedDuration); - r.enable(EventNames.ActiveRecording); - r.onEvent(e -> { - System.out.println(e); - Duration duration = e.getDuration("flushInterval"); - if (expectedDuration.equals(duration)) { - System.out.println("Closing recording"); - r.close(); - return; - } - System.out.println("Flush interval not set, was " + duration + - ", but expected " + expectedDuration); - }); - r.start(); - } - } -} diff --git a/test/jdk/jfr/api/consumer/security/TestStreamingRemote.java b/test/jdk/jfr/api/consumer/security/TestStreamingRemote.java index 12f3c3e1d53d0fcd542bc381b3c91789dbe07fe8..04e1e20b9c12cd19e64a01a2511332ec05918152 100644 --- a/test/jdk/jfr/api/consumer/security/TestStreamingRemote.java +++ b/test/jdk/jfr/api/consumer/security/TestStreamingRemote.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 2020, 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 @@ -73,7 +73,6 @@ public class TestStreamingRemote { public static void main(String... args) throws Exception { try (Recording r = new Recording()) { - r.setFlushInterval(Duration.ofSeconds(1)); r.start(); String repository = System.getProperty("jdk.jfr.repository"); Path policy = createPolicyFile(repository); diff --git a/test/jdk/jfr/api/consumer/streaming/TestInProcessMigration.java b/test/jdk/jfr/api/consumer/streaming/TestInProcessMigration.java index 11a4fe9b60a268a02bc92c320650de87a04bc3bc..e78c443b05791a6b06edf3ecf9f2e4cf26bc62ba 100644 --- a/test/jdk/jfr/api/consumer/streaming/TestInProcessMigration.java +++ b/test/jdk/jfr/api/consumer/streaming/TestInProcessMigration.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 2020, 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 @@ -70,7 +70,6 @@ public class TestInProcessMigration { System.out.println("Started es.startAsync()"); try (Recording r = new Recording()) { - r.setFlushInterval(Duration.ofSeconds(1)); r.start(); // Chunk in default repository MigrationEvent e1 = new MigrationEvent(); diff --git a/test/jdk/jfr/api/recording/time/TestSetFlushInterval.java b/test/jdk/jfr/api/recording/time/TestSetFlushInterval.java deleted file mode 100644 index 179363861cdfcc8dfd1cdbd6c70b82e75ae03de7..0000000000000000000000000000000000000000 --- a/test/jdk/jfr/api/recording/time/TestSetFlushInterval.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (c) 2019, 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 - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package jdk.jfr.api.recording.time; - -import java.time.Duration; -import java.util.concurrent.CountDownLatch; - -import jdk.jfr.Recording; -import jdk.jfr.consumer.EventStream; -import jdk.test.lib.Asserts; - -/** - * @test - * @key jfr - * @summary Test Recording::SetFlushInterval(...) and - * Recording::getFlushInterval() - * @library /lib / - * @run main/othervm jdk.jfr.api.recording.time.TestSetFlushInterval - */ - -public class TestSetFlushInterval { - - public static void main(String[] args) throws Throwable { - testSetGet(); - testSetNull(); - testFlush(); - } - - static void testFlush() throws Exception { - CountDownLatch flush = new CountDownLatch(1); - try (EventStream es = EventStream.openRepository()) { - es.onFlush(() -> { - flush.countDown(); - }); - es.startAsync(); - try (Recording r = new Recording()) { - r.setFlushInterval(Duration.ofSeconds(1)); - r.start(); - flush.await(); - } - } - } - - static void testSetNull() { - try (Recording r = new Recording()) { - r.setFlushInterval(null); - Asserts.fail("Expected NullPointerException"); - } catch (NullPointerException npe) { - // as expected - } - } - - static void testSetGet() { - try (Recording r = new Recording()) { - Duration a = Duration.ofNanos(21378461289374646L); - r.setFlushInterval(a); - Duration b = r.getFlushInterval(); - Asserts.assertEQ(a, b); - } - } - -} diff --git a/test/jdk/jfr/startupargs/TestFlushInterval.java b/test/jdk/jfr/startupargs/TestFlushInterval.java index 310a75bb7f356dabfffd06cf88ea6cc45aab5380..283eef3a53d2742ea66aed389f1d1c16793c1e2d 100644 --- a/test/jdk/jfr/startupargs/TestFlushInterval.java +++ b/test/jdk/jfr/startupargs/TestFlushInterval.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 2020, 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 @@ -29,20 +29,25 @@ import java.time.Duration; import jdk.jfr.FlightRecorder; import jdk.jfr.Recording; +import jdk.jfr.internal.PlatformRecording; +import jdk.jfr.internal.PrivateAccess; /** * @test * @summary Start a recording with a flush interval * @key jfr * @library /lib / - * @run main/othervm -XX:StartFlightRecording=flush-interval=1s jdk.jfr.startupargs.TestFlushInterval + * @modules jdk.jfr/jdk.jfr.internal + * @run main/othervm -XX:StartFlightRecording=flush-interval=2s jdk.jfr.startupargs.TestFlushInterval */ public class TestFlushInterval { public static void main(String[] args) throws Exception { for (Recording r : FlightRecorder.getFlightRecorder().getRecordings()) { - Duration d = r.getFlushInterval(); - if (d.equals(Duration.ofSeconds(1))) { + PrivateAccess p = PrivateAccess.getInstance(); + PlatformRecording pr = p.getPlatformRecording(r); + Duration d = pr.getFlushInterval(); + if (d.equals(Duration.ofSeconds(2))) { return; //OK } else { throw new Exception("Unexpected flush-interval " + d);