Skip to content

Commit 2880106

Browse files
committed
8237574: Make TestNative work without -nativepath
Reviewed-by: mgronlun, mseledtsov
1 parent 8aff9fc commit 2880106

File tree

2 files changed

+25
-87
lines changed

2 files changed

+25
-87
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -25,70 +25,49 @@
2525

2626
package jdk.jfr.event.sampling;
2727

28-
import java.io.File;
29-
import java.nio.file.Paths;
3028
import java.time.Duration;
29+
import java.util.List;
30+
import java.util.concurrent.Semaphore;
31+
import java.util.concurrent.atomic.AtomicInteger;
3132

32-
import jdk.jfr.FlightRecorder;
3333
import jdk.jfr.Recording;
34-
import jdk.jfr.consumer.RecordedEvent;
35-
import jdk.jfr.consumer.RecordingFile;
34+
import jdk.jfr.consumer.RecordedFrame;
35+
import jdk.jfr.consumer.RecordingStream;
36+
import jdk.jfr.internal.JVM;
3637
import jdk.test.lib.jfr.EventNames;
37-
import jdk.test.lib.process.OutputAnalyzer;
38-
import jdk.test.lib.process.ProcessTools;
3938

4039
/*
4140
* @test
4241
* @key jfr
4342
* @requires vm.hasJFR
4443
* @library /test/lib
45-
* @modules java.base/jdk.internal.misc
46-
* @run main/native jdk.jfr.event.sampling.TestNative
44+
* @modules jdk.jfr/jdk.jfr.internal
45+
* @run main jdk.jfr.event.sampling.TestNative
4746
*/
4847
public class TestNative {
4948

50-
public final static String EVENT_SETTINGS_FILE = System.getProperty("test.src", ".") + File.separator + "sampling.jfc";
51-
public final static String JFR_DUMP = "samples.jfr";
52-
public final static String EXCEPTION = "No native samples found";
53-
public final static String NATIVE_EVENT = EventNames.NativeMethodSample;
54-
public static Recording recording;
49+
final static String NATIVE_EVENT = EventNames.NativeMethodSample;
5550

56-
public static native void longTime();
51+
static volatile boolean alive = true;
5752

5853
public static void main(String[] args) throws Exception {
59-
String lib = System.getProperty("test.nativepath");
60-
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true, "-Djava.library.path=" + lib, "jdk.jfr.event.sampling.TestNative$Test");
54+
try (RecordingStream rs = new RecordingStream()) {
55+
rs.enable(NATIVE_EVENT).withPeriod(Duration.ofMillis(1));
56+
rs.onEvent(NATIVE_EVENT, e -> {
57+
alive = false;
58+
rs.close();
59+
});
60+
Thread t = new Thread(TestNative::nativeMethod);
61+
t.setDaemon(true);
62+
t.start();
63+
rs.start();
64+
}
6165

62-
OutputAnalyzer output = ProcessTools.executeProcess(pb);
63-
output.shouldHaveExitValue(0);
64-
output.stdoutShouldNotContain("No native samples found");
6566
}
6667

67-
static class Test {
68-
public static void main(String[] args) throws Exception {
69-
System.loadLibrary("TestNative");
70-
FlightRecorder.getFlightRecorder();
71-
recording = new Recording();
72-
recording.setToDisk(true);
73-
recording.setDestination(Paths.get(JFR_DUMP));
74-
recording.enable(NATIVE_EVENT).withPeriod(Duration.ofMillis(10));
75-
recording.start();
76-
77-
longTime();
78-
79-
recording.stop();
80-
recording.close();
81-
82-
try (RecordingFile rf = new RecordingFile(Paths.get(JFR_DUMP))) {
83-
while (rf.hasMoreEvents()) {
84-
RecordedEvent re = rf.readEvent();
85-
if (re.getEventType().getName().equals(NATIVE_EVENT)) {
86-
return;
87-
}
88-
}
89-
}
90-
91-
throw new Exception("No native samples found");
68+
public static void nativeMethod() {
69+
while (alive) {
70+
JVM.getJVM().getPid();
9271
}
9372
}
9473
}

test/jdk/jdk/jfr/event/sampling/libTestNative.c

-41
This file was deleted.

0 commit comments

Comments
 (0)