-
Notifications
You must be signed in to change notification settings - Fork 565
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fail HelidonTests by default when pinning jfr event is detected #8857
Comments
I think JFR requires Oracle JDK. I guess the way to approach this is to include one script, with Oracle JDK, that executes the tests with the JVM args: And then find events on the generated JRF file: If found, then error. |
It seems from JDK 9 it is part of JDK, so we can use it in My idea is to create a new maven module: |
I am trying to make a simple reproducer, but for some reason I don't catch the import static org.junit.Assert.assertTrue;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import jdk.jfr.Event;
import jdk.jfr.Name;
import jdk.jfr.consumer.RecordingStream;
import org.junit.Test;
public class JFRTest {
@Test
public void pinnedVirtualThreads() throws InterruptedException {
CountDownLatch stopListening = new CountDownLatch(1);
CountDownLatch startListening = new CountDownLatch(1);
try (RecordingStream recordingStream = new RecordingStream()) {
// Create and start the recording stream
startRecordingStream(recordingStream, startListening, stopListening);
// Make sure JFR listener is running before continue
while (true) {
new StartEvent().commit();
if (startListening.await(1, TimeUnit.SECONDS)) {
break;
}
}
// Simulate blocking operation
Thread vt = Thread.ofVirtual().start(() -> {
synchronized (this) {
System.out.println("Virtual Thread is pinned");
}
});
vt.join();
}
// Wait till the jdk.VirtualThreadPinned triggers
assertTrue("jdk.VirtualThreadPinned was not sent", stopListening.await(5, TimeUnit.SECONDS));
}
private void startRecordingStream(RecordingStream recordingStream, CountDownLatch startListening, CountDownLatch stopListening) {
// Enable the jdk.VirtualThreadPinned event
recordingStream.enable("jdk.VirtualThreadPinned").withStackTrace();
// Notify listener is running after receiving the StartEvent
recordingStream.onEvent("StartEvent", event -> {
System.out.println("Received " + event);
startListening.countDown();
});
// Set an event handler
recordingStream.onEvent("jdk.VirtualThreadPinned", event -> {
System.out.println("VirtualThreadPinned event detected!");
System.out.println("Timestamp: " + event);
stopListening.countDown();
});
// Start the recording stream
recordingStream.startAsync();
}
@Name("StartEvent")
private static class StartEvent extends Event {
}
} It fails with:
|
You have to block the carrier thread for more than 20 millis(that is the default) Thread vt = Thread.ofVirtual().start(() -> {
synchronized (this) {
Thread.sleep(50);
}
}); |
I read that too, but I thought it means that be default Anyway, I added 2 seconds of sleep and still nothing. |
The issue was the event was triggered but not flushed immediately. Closing the RecordingStream doesn't flush. So I had to add before closing: |
…elidon-io#8857 Signed-off-by: Jorge Bescos Gascon <[email protected]>
…elidon-io#8857 Signed-off-by: Jorge Bescos Gascon <[email protected]>
…elidon-io#8857 Signed-off-by: Jorge Bescos Gascon <[email protected]>
…elidon-io#8857 Signed-off-by: Jorge Bescos Gascon <[email protected]>
…elidon-io#8857 Signed-off-by: Jorge Bescos Gascon <[email protected]>
…elidon-io#8857 Signed-off-by: Jorge Bescos Gascon <[email protected]>
…elidon-io#8857 Signed-off-by: Jorge Bescos Gascon <[email protected]>
…elidon-io#8857 Signed-off-by: Jorge Bescos Gascon <[email protected]>
We should monitor JFR event
jdk.VirtualThreadPinned
in@HelidonTest
tests and fail the test causing the pinningThe text was updated successfully, but these errors were encountered: