Skip to content

Commit 45dec48

Browse files
committed
8292592: JFR test TestNative is not reliable due to low rate of sampling.
Reviewed-by: egahlin, shade
1 parent 58aae34 commit 45dec48

File tree

2 files changed

+62
-10
lines changed

2 files changed

+62
-10
lines changed

test/jdk/jdk/jfr/event/sampling/TestNative.java renamed to test/jdk/jdk/jfr/event/profiling/TestNative.java

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,11 @@
2121
* questions.
2222
*/
2323

24-
package jdk.jfr.event.sampling;
24+
package jdk.jfr.event.profiling;
2525

2626
import java.time.Duration;
27-
import java.util.List;
28-
import java.util.concurrent.Semaphore;
29-
import java.util.concurrent.atomic.AtomicInteger;
3027

3128
import jdk.jfr.Recording;
32-
import jdk.jfr.consumer.RecordedFrame;
3329
import jdk.jfr.consumer.RecordingStream;
3430
import jdk.jfr.internal.JVM;
3531
import jdk.test.lib.jfr.EventNames;
@@ -40,20 +36,17 @@
4036
* @requires vm.hasJFR
4137
* @library /test/lib
4238
* @modules jdk.jfr/jdk.jfr.internal
43-
* @run main jdk.jfr.event.sampling.TestNative
39+
* @run main jdk.jfr.event.profiling.TestNative
4440
*/
4541
public class TestNative {
4642

4743
final static String NATIVE_EVENT = EventNames.NativeMethodSample;
4844

4945
static volatile boolean alive = true;
5046

51-
// Please resist the temptation to speed up the test by decreasing
52-
// the period. It is explicity set to 1100 ms to provoke the 1000 ms
53-
// threshold in the JVM for os::naked_short_sleep().
5447
public static void main(String[] args) throws Exception {
5548
try (RecordingStream rs = new RecordingStream()) {
56-
rs.enable(NATIVE_EVENT).withPeriod(Duration.ofMillis(1100));
49+
rs.enable(NATIVE_EVENT).withPeriod(Duration.ofMillis(1));
5750
rs.onEvent(NATIVE_EVENT, e -> {
5851
alive = false;
5952
rs.close();
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright (c) 2017, 2022, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
package jdk.jfr.event.profiling;
25+
26+
import java.time.Duration;
27+
28+
import jdk.jfr.consumer.RecordingStream;
29+
import jdk.test.lib.jfr.EventNames;
30+
import jdk.test.lib.jfr.RecurseThread;
31+
32+
/*
33+
* @test
34+
* @key jfr
35+
* @requires vm.hasJFR
36+
* @library /test/lib
37+
* @modules jdk.jfr/jdk.jfr.internal
38+
* @run main jdk.jfr.event.profiling.TestSamplingLongPeriod
39+
*/
40+
public class TestSamplingLongPeriod {
41+
42+
final static String SAMPLE_EVENT = EventNames.ExecutionSample;
43+
44+
// The period is set to 1100 ms to provoke the 1000 ms
45+
// threshold in the JVM for os::naked_short_sleep().
46+
public static void main(String[] args) throws Exception {
47+
RecurseThread t = new RecurseThread(50);
48+
t.setDaemon(true);
49+
try (RecordingStream rs = new RecordingStream()) {
50+
rs.enable(SAMPLE_EVENT).withPeriod(Duration.ofMillis(1100));
51+
rs.onEvent(SAMPLE_EVENT, e -> {
52+
t.quit();
53+
rs.close();
54+
});
55+
t.start();
56+
rs.start();
57+
}
58+
}
59+
}

0 commit comments

Comments
 (0)