8239265: JFR: Test cleanup of jdk.jfr.api.consumer package
Reviewed-by: mgronlun
This commit is contained in:
parent
6f6b4c0ef9
commit
f75f78ae3a
test/jdk/jdk/jfr/api/consumer
TestFieldAccess.javaTestGetStackTrace.javaTestHiddenMethod.javaTestMethodGetModifiers.javaTestReadTwice.javaTestRecordedClassLoader.javaTestRecordedEvent.javaTestRecordedEventGetThread.javaTestRecordedEventGetThreadOther.javaTestRecordedFrame.javaTestRecordedFullStackTrace.javaTestRecordedInstantEventTimestamp.javaTestRecordedMethodDescriptor.javaTestRecordedObject.javaTestRecordingFile.javaTestRecordingFileReadEventEof.javaTestSingleRecordedEvent.javaTestValueDescriptorRecorded.java
@ -45,6 +45,8 @@ import jdk.test.lib.jfr.Events;
|
|||||||
public class TestFieldAccess {
|
public class TestFieldAccess {
|
||||||
|
|
||||||
private static class MyEvent extends Event {
|
private static class MyEvent extends Event {
|
||||||
|
byte byteField = 42;
|
||||||
|
char charField = 'X';
|
||||||
String stringField = "Hello";
|
String stringField = "Hello";
|
||||||
int intField = 4711;
|
int intField = 4711;
|
||||||
long longField = 4712L;
|
long longField = 4712L;
|
||||||
@ -72,6 +74,12 @@ public class TestFieldAccess {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void testGetField(RecordedEvent event, MyEvent myEvent) {
|
private static void testGetField(RecordedEvent event, MyEvent myEvent) {
|
||||||
|
char charField = event.getValue("charField");
|
||||||
|
Asserts.assertEquals(charField, myEvent.charField);
|
||||||
|
|
||||||
|
byte byteField = event.getValue("byteField");
|
||||||
|
Asserts.assertEquals(byteField, myEvent.byteField);
|
||||||
|
|
||||||
String stringField = event.getValue("stringField");
|
String stringField = event.getValue("stringField");
|
||||||
Asserts.assertEquals(stringField, myEvent.stringField);
|
Asserts.assertEquals(stringField, myEvent.stringField);
|
||||||
|
|
||||||
@ -103,7 +111,6 @@ public class TestFieldAccess {
|
|||||||
String className = event.getValue("classField.name");
|
String className = event.getValue("classField.name");
|
||||||
Asserts.assertEquals(classField.getName(), className.replace("/", "."));
|
Asserts.assertEquals(classField.getName(), className.replace("/", "."));
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
event.getValue("doesnotexist");
|
event.getValue("doesnotexist");
|
||||||
} catch (IllegalArgumentException iae) {
|
} catch (IllegalArgumentException iae) {
|
||||||
@ -125,6 +132,8 @@ public class TestFieldAccess {
|
|||||||
|
|
||||||
private static void testHasField(RecordedEvent event) {
|
private static void testHasField(RecordedEvent event) {
|
||||||
System.out.println(event);
|
System.out.println(event);
|
||||||
|
Asserts.assertTrue(event.hasField("charField"));
|
||||||
|
Asserts.assertTrue(event.hasField("byteField"));
|
||||||
Asserts.assertTrue(event.hasField("stringField"));
|
Asserts.assertTrue(event.hasField("stringField"));
|
||||||
Asserts.assertTrue(event.hasField("intField"));
|
Asserts.assertTrue(event.hasField("intField"));
|
||||||
Asserts.assertTrue(event.hasField("longField"));
|
Asserts.assertTrue(event.hasField("longField"));
|
||||||
|
@ -31,7 +31,6 @@ import static jdk.test.lib.Asserts.assertNull;
|
|||||||
import static jdk.test.lib.Asserts.assertTrue;
|
import static jdk.test.lib.Asserts.assertTrue;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Consumer;
|
|
||||||
|
|
||||||
import jdk.jfr.Recording;
|
import jdk.jfr.Recording;
|
||||||
import jdk.jfr.consumer.RecordedEvent;
|
import jdk.jfr.consumer.RecordedEvent;
|
||||||
@ -53,27 +52,26 @@ import jdk.test.lib.jfr.SimpleEvent;
|
|||||||
public class TestGetStackTrace {
|
public class TestGetStackTrace {
|
||||||
|
|
||||||
public static void main(String[] args) throws Throwable {
|
public static void main(String[] args) throws Throwable {
|
||||||
testStackTrace(r -> r.enable(SimpleEvent.class), TestGetStackTrace::assertNoStackTrace);
|
testWithoutStackTrace(recordEvent("stackTrace", "false"));
|
||||||
testStackTrace(r -> r.enable(SimpleEvent.class).withoutStackTrace(), TestGetStackTrace::assertStackTrace);
|
testWithStackTrace(recordEvent("stackTrace", "true"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void testStackTrace(Consumer<Recording> recordingConfigurer, Consumer<RecordedEvent> asserter) throws Throwable {
|
private static RecordedEvent recordEvent(String key, String value) throws Throwable {
|
||||||
Recording r = new Recording();
|
try (Recording r = new Recording()) {
|
||||||
recordingConfigurer.accept(r);
|
r.enable(SimpleEvent.class).with(key, value);
|
||||||
r.start();
|
r.start();
|
||||||
SimpleEvent event = new SimpleEvent();
|
SimpleEvent event = new SimpleEvent();
|
||||||
event.commit();
|
event.commit();
|
||||||
r.stop();
|
r.stop();
|
||||||
List<RecordedEvent> events = Events.fromRecording(r);
|
return Events.fromRecording(r).get(0);
|
||||||
r.close();
|
}
|
||||||
Events.hasEvents(events);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void assertNoStackTrace(RecordedEvent re) {
|
private static void testWithoutStackTrace(RecordedEvent re) {
|
||||||
assertNull(re.getStackTrace());
|
assertNull(re.getStackTrace());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void assertStackTrace(RecordedEvent re) {
|
private static void testWithStackTrace(RecordedEvent re) {
|
||||||
assertNotNull(re.getStackTrace());
|
assertNotNull(re.getStackTrace());
|
||||||
RecordedStackTrace strace = re.getStackTrace();
|
RecordedStackTrace strace = re.getStackTrace();
|
||||||
assertEquals(strace.isTruncated(), false);
|
assertEquals(strace.isTruncated(), false);
|
||||||
|
@ -56,7 +56,7 @@ import jdk.test.lib.jfr.Events;
|
|||||||
public final class TestHiddenMethod {
|
public final class TestHiddenMethod {
|
||||||
|
|
||||||
public static void main(String[] args) throws Throwable {
|
public static void main(String[] args) throws Throwable {
|
||||||
Recording recording = new Recording();
|
try (Recording recording = new Recording()) {
|
||||||
recording.enable(MyEvent.class).withThreshold(Duration.ofMillis(0));
|
recording.enable(MyEvent.class).withThreshold(Duration.ofMillis(0));
|
||||||
recording.start();
|
recording.start();
|
||||||
|
|
||||||
@ -93,6 +93,7 @@ public final class TestHiddenMethod {
|
|||||||
assertTrue(hasHiddenStackFrame(hiddenEvent), "No hidden frame in hidden event: " + hiddenEvent);
|
assertTrue(hasHiddenStackFrame(hiddenEvent), "No hidden frame in hidden event: " + hiddenEvent);
|
||||||
assertFalse(hasHiddenStackFrame(visibleEvent), "Hidden frame in visible event: " + visibleEvent);
|
assertFalse(hasHiddenStackFrame(visibleEvent), "Hidden frame in visible event: " + visibleEvent);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static boolean hasHiddenStackFrame(RecordedEvent event) throws Throwable {
|
private static boolean hasHiddenStackFrame(RecordedEvent event) throws Throwable {
|
||||||
RecordedStackTrace stacktrace = event.getStackTrace();
|
RecordedStackTrace stacktrace = event.getStackTrace();
|
||||||
@ -108,5 +109,4 @@ public final class TestHiddenMethod {
|
|||||||
|
|
||||||
public static class MyEvent extends Event {
|
public static class MyEvent extends Event {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -41,6 +41,7 @@ import jdk.test.lib.jfr.SimpleEvent;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
|
* @summary Verifies that a recorded method has the correct modifier
|
||||||
* @key jfr
|
* @key jfr
|
||||||
* @requires vm.hasJFR
|
* @requires vm.hasJFR
|
||||||
* @library /test/lib
|
* @library /test/lib
|
||||||
@ -49,7 +50,7 @@ import jdk.test.lib.jfr.SimpleEvent;
|
|||||||
public final class TestMethodGetModifiers {
|
public final class TestMethodGetModifiers {
|
||||||
|
|
||||||
public static void main(String[] args) throws Throwable {
|
public static void main(String[] args) throws Throwable {
|
||||||
Recording recording = new Recording();
|
try (Recording recording = new Recording()) {
|
||||||
recording.start();
|
recording.start();
|
||||||
|
|
||||||
SimpleEvent ev = new SimpleEvent();
|
SimpleEvent ev = new SimpleEvent();
|
||||||
@ -60,7 +61,7 @@ public final class TestMethodGetModifiers {
|
|||||||
Events.hasEvents(recordedEvents);
|
Events.hasEvents(recordedEvents);
|
||||||
RecordedEvent recordedEvent = recordedEvents.get(0);
|
RecordedEvent recordedEvent = recordedEvents.get(0);
|
||||||
|
|
||||||
System.out.println("recorded event:" + recordedEvent);
|
System.out.println(recordedEvent);
|
||||||
|
|
||||||
RecordedStackTrace stacktrace = recordedEvent.getStackTrace();
|
RecordedStackTrace stacktrace = recordedEvent.getStackTrace();
|
||||||
List<RecordedFrame> frames = stacktrace.getFrames();
|
List<RecordedFrame> frames = stacktrace.getFrames();
|
||||||
@ -74,8 +75,7 @@ public final class TestMethodGetModifiers {
|
|||||||
RecordedClass type = method.getType();
|
RecordedClass type = method.getType();
|
||||||
assertNotNull(type, "Recorded class can not be null");
|
assertNotNull(type, "Recorded class can not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,6 @@ import jdk.jfr.consumer.RecordingFile;
|
|||||||
import jdk.test.lib.Asserts;
|
import jdk.test.lib.Asserts;
|
||||||
import jdk.test.lib.Utils;
|
import jdk.test.lib.Utils;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @summary Reads the recorded file two times and verifies that both reads are the same
|
* @summary Reads the recorded file two times and verifies that both reads are the same
|
||||||
@ -51,7 +50,7 @@ public class TestReadTwice {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws Throwable {
|
public static void main(String[] args) throws Throwable {
|
||||||
Recording r = new Recording();
|
try (Recording r = new Recording()) {
|
||||||
r.enable(MyEvent.class).withoutStackTrace();
|
r.enable(MyEvent.class).withoutStackTrace();
|
||||||
r.start();
|
r.start();
|
||||||
|
|
||||||
@ -65,13 +64,12 @@ public class TestReadTwice {
|
|||||||
Path path = Utils.createTempFile("read-twice", ".jfr");
|
Path path = Utils.createTempFile("read-twice", ".jfr");
|
||||||
System.out.println("Dumping to " + path);
|
System.out.println("Dumping to " + path);
|
||||||
r.dump(path);
|
r.dump(path);
|
||||||
r.close();
|
|
||||||
|
|
||||||
// Read all events from the file in one go
|
// Read all events from the file in one go
|
||||||
List<RecordedEvent> events = RecordingFile.readAllEvents(path);
|
List<RecordedEvent> events = RecordingFile.readAllEvents(path);
|
||||||
|
|
||||||
// Read again the same events one by one
|
// Read again the same events one by one
|
||||||
RecordingFile rfile = new RecordingFile(path);
|
try (RecordingFile rfile = new RecordingFile(path)) {
|
||||||
List<RecordedEvent> events2 = new LinkedList<>();
|
List<RecordedEvent> events2 = new LinkedList<>();
|
||||||
while (rfile.hasMoreEvents()) {
|
while (rfile.hasMoreEvents()) {
|
||||||
events2.add(rfile.readEvent());
|
events2.add(rfile.readEvent());
|
||||||
@ -79,6 +77,7 @@ public class TestReadTwice {
|
|||||||
|
|
||||||
// Compare sizes
|
// Compare sizes
|
||||||
Asserts.assertEquals(events.size(), events2.size());
|
Asserts.assertEquals(events.size(), events2.size());
|
||||||
rfile.close();
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,6 +45,7 @@ import jdk.test.lib.jfr.TestClassLoader;
|
|||||||
* @run main/othervm jdk.jfr.api.consumer.TestRecordedClassLoader
|
* @run main/othervm jdk.jfr.api.consumer.TestRecordedClassLoader
|
||||||
*/
|
*/
|
||||||
public class TestRecordedClassLoader {
|
public class TestRecordedClassLoader {
|
||||||
|
|
||||||
private final static String TEST_CLASS_NAME = "jdk.jfr.api.consumer.TestRecordedClassLoader$MyTestClass";
|
private final static String TEST_CLASS_NAME = "jdk.jfr.api.consumer.TestRecordedClassLoader$MyTestClass";
|
||||||
private final static String EVENT_NAME = EventNames.ClassDefine;
|
private final static String EVENT_NAME = EventNames.ClassDefine;
|
||||||
|
|
||||||
@ -52,7 +53,7 @@ public class TestRecordedClassLoader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
Recording recording = new Recording();
|
try (Recording recording = new Recording()) {
|
||||||
recording.enable(EVENT_NAME).withoutStackTrace();
|
recording.enable(EVENT_NAME).withoutStackTrace();
|
||||||
TestClassLoader cl = new TestClassLoader();
|
TestClassLoader cl = new TestClassLoader();
|
||||||
recording.start();
|
recording.start();
|
||||||
@ -117,4 +118,5 @@ public class TestRecordedClassLoader {
|
|||||||
}
|
}
|
||||||
Asserts.assertTrue(isDefined, "No class define event found to verify RecordedClassLoader");
|
Asserts.assertTrue(isDefined, "No class define event found to verify RecordedClassLoader");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,6 @@ public class TestRecordedEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static class TestEvent extends Event {
|
static class TestEvent extends Event {
|
||||||
|
|
||||||
@Description("MyField")
|
@Description("MyField")
|
||||||
Class<?> clzField = String.class;
|
Class<?> clzField = String.class;
|
||||||
int intField;
|
int intField;
|
||||||
@ -60,16 +59,15 @@ public class TestRecordedEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws Throwable {
|
public static void main(String[] args) throws Throwable {
|
||||||
Recording r = new Recording();
|
try (Recording r = new Recording()) {
|
||||||
r.start();
|
r.start();
|
||||||
TestEvent t = new TestEvent();
|
TestEvent t = new TestEvent();
|
||||||
t.commit();
|
t.commit();
|
||||||
r.stop();
|
r.stop();
|
||||||
|
|
||||||
List<RecordedEvent> events = Events.fromRecording(r);
|
List<RecordedEvent> events = Events.fromRecording(r);
|
||||||
Events.hasEvents(events);
|
Events.hasEvents(events);
|
||||||
|
|
||||||
Asserts.assertEquals(events.size(), 1);
|
Asserts.assertEquals(events.size(), 1);
|
||||||
|
|
||||||
RecordedEvent event = events.get(0);
|
RecordedEvent event = events.get(0);
|
||||||
|
|
||||||
List<ValueDescriptor> descriptors = event.getFields();
|
List<ValueDescriptor> descriptors = event.getFields();
|
||||||
@ -100,11 +98,11 @@ public class TestRecordedEvent {
|
|||||||
Object recordedClassLoader = myRecClass.getValue("classLoader");
|
Object recordedClassLoader = myRecClass.getValue("classLoader");
|
||||||
Asserts.assertTrue(recordedClassLoader instanceof RecordedClassLoader, "Expected Recorded ClassLoader got " + recordedClassLoader);
|
Asserts.assertTrue(recordedClassLoader instanceof RecordedClassLoader, "Expected Recorded ClassLoader got " + recordedClassLoader);
|
||||||
|
|
||||||
RecordedClassLoader myRecClassLoader = (RecordedClassLoader)recordedClassLoader;
|
RecordedClassLoader myRecClassLoader = (RecordedClassLoader) recordedClassLoader;
|
||||||
ClassLoader cl = MyClass.class.getClassLoader();
|
ClassLoader cl = MyClass.class.getClassLoader();
|
||||||
Asserts.assertEquals(cl.getClass().getName(), myRecClassLoader.getType().getName(), "Expected Recorded ClassLoader type to equal loader type");
|
Asserts.assertEquals(cl.getClass().getName(), myRecClassLoader.getType().getName(), "Expected Recorded ClassLoader type to equal loader type");
|
||||||
|
|
||||||
Asserts.assertNotNull(myRecClass.getModifiers());
|
Asserts.assertNotNull(myRecClass.getModifiers());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,24 +49,24 @@ public class TestRecordedEventGetThread {
|
|||||||
public static void main(String[] args) throws Throwable {
|
public static void main(String[] args) throws Throwable {
|
||||||
Thread currentThread = Thread.currentThread();
|
Thread currentThread = Thread.currentThread();
|
||||||
currentThread.setName(MY_THREAD_NAME);
|
currentThread.setName(MY_THREAD_NAME);
|
||||||
long expectedThreadId = currentThread.getId();
|
|
||||||
|
|
||||||
Recording r = new Recording();
|
try (Recording r = new Recording()) {
|
||||||
r.start();
|
r.start();
|
||||||
SimpleEvent t = new SimpleEvent();
|
SimpleEvent t = new SimpleEvent();
|
||||||
t.commit();
|
t.commit();
|
||||||
r.stop();
|
r.stop();
|
||||||
|
|
||||||
List<RecordedEvent> events = Events.fromRecording(r);
|
List<RecordedEvent> events = Events.fromRecording(r);
|
||||||
r.close();
|
|
||||||
Events.hasEvents(events);
|
Events.hasEvents(events);
|
||||||
RecordedEvent event = events.get(0);
|
RecordedEvent event = events.get(0);
|
||||||
RecordedThread recordedThread = event.getThread();
|
RecordedThread recordedThread = event.getThread();
|
||||||
|
|
||||||
Asserts.assertNotNull(recordedThread);
|
Asserts.assertNotNull(recordedThread);
|
||||||
|
|
||||||
Asserts.assertEquals(recordedThread.getJavaName(), MY_THREAD_NAME);
|
Asserts.assertEquals(recordedThread.getJavaName(), MY_THREAD_NAME);
|
||||||
Asserts.assertEquals(recordedThread.getJavaThreadId(), expectedThreadId);
|
Asserts.assertEquals(recordedThread.getJavaThreadId(), currentThread.getId());
|
||||||
Asserts.assertNotNull(recordedThread.getOSThreadId());
|
Asserts.assertNotNull(recordedThread.getOSThreadId());
|
||||||
Asserts.assertNotNull(recordedThread.getId());
|
Asserts.assertNotNull(recordedThread.getId());
|
||||||
Asserts.assertEquals(recordedThread.getOSName(), MY_THREAD_NAME);
|
Asserts.assertEquals(recordedThread.getOSName(), MY_THREAD_NAME);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -47,25 +47,28 @@ import jdk.test.lib.Utils;
|
|||||||
public class TestRecordedEventGetThreadOther {
|
public class TestRecordedEventGetThreadOther {
|
||||||
|
|
||||||
private static final String MY_THREAD_NAME = "MY_THREAD_NAME";
|
private static final String MY_THREAD_NAME = "MY_THREAD_NAME";
|
||||||
private static long expectedThreadId;
|
|
||||||
private static Path dumpFilePath;
|
|
||||||
|
|
||||||
static class TestEvent extends Event {
|
static class TestEvent extends Event {
|
||||||
}
|
}
|
||||||
|
|
||||||
static class PostingThread extends Thread {
|
static class PostingThread extends Thread {
|
||||||
|
private final Path dumpFilePath;
|
||||||
PostingThread() {
|
PostingThread(Path dumpFilePath) {
|
||||||
setName(MY_THREAD_NAME);
|
this.dumpFilePath = dumpFilePath;
|
||||||
expectedThreadId = getId();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
System.out.println("Starting thread...");
|
System.out.println("Starting thread...");
|
||||||
dumpFilePath = postEventAndDumpToFile();
|
try (Recording r = new Recording()) {
|
||||||
|
r.start();
|
||||||
|
TestEvent t = new TestEvent();
|
||||||
|
t.commit();
|
||||||
|
r.stop();
|
||||||
|
r.dump(dumpFilePath);
|
||||||
System.out.println("events dumped to the file " + dumpFilePath);
|
System.out.println("events dumped to the file " + dumpFilePath);
|
||||||
|
}
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
t.printStackTrace();
|
t.printStackTrace();
|
||||||
Asserts.fail();
|
Asserts.fail();
|
||||||
@ -73,13 +76,13 @@ public class TestRecordedEventGetThreadOther {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws Throwable {
|
public static void main(String[] args) throws Exception {
|
||||||
Thread.currentThread().setName("MyMainThread");
|
Path dumpFilePath = Utils.createTempFile("event-thread", ".jfr");
|
||||||
|
|
||||||
PostingThread thread = new PostingThread();
|
PostingThread thread = new PostingThread(dumpFilePath);
|
||||||
|
thread.setName(MY_THREAD_NAME);
|
||||||
thread.start();
|
thread.start();
|
||||||
thread.join();
|
thread.join();
|
||||||
System.out.println("testing dump in file " + dumpFilePath);
|
|
||||||
|
|
||||||
List<RecordedEvent> events = RecordingFile.readAllEvents(dumpFilePath);
|
List<RecordedEvent> events = RecordingFile.readAllEvents(dumpFilePath);
|
||||||
Asserts.assertEquals(events.size(), 1);
|
Asserts.assertEquals(events.size(), 1);
|
||||||
@ -89,21 +92,8 @@ public class TestRecordedEventGetThreadOther {
|
|||||||
|
|
||||||
Asserts.assertNotNull(recordedThread);
|
Asserts.assertNotNull(recordedThread);
|
||||||
Asserts.assertEquals(recordedThread.getJavaName(), MY_THREAD_NAME);
|
Asserts.assertEquals(recordedThread.getJavaName(), MY_THREAD_NAME);
|
||||||
Asserts.assertEquals(recordedThread.getJavaThreadId(), expectedThreadId);
|
Asserts.assertEquals(recordedThread.getJavaThreadId(), thread.getId());
|
||||||
Asserts.assertNotNull(recordedThread.getId());
|
Asserts.assertNotNull(recordedThread.getId());
|
||||||
Asserts.assertEquals(recordedThread.getOSName(), MY_THREAD_NAME);
|
Asserts.assertEquals(recordedThread.getOSName(), MY_THREAD_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Path postEventAndDumpToFile() throws Throwable {
|
|
||||||
Recording r = new Recording();
|
|
||||||
r.start();
|
|
||||||
TestEvent t = new TestEvent();
|
|
||||||
t.commit();
|
|
||||||
r.stop();
|
|
||||||
Path path = Utils.createTempFile("event-thread", ".jfr");
|
|
||||||
System.out.println("Created path: " + path);
|
|
||||||
r.dump(path);
|
|
||||||
r.close();
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,7 @@ package jdk.jfr.api.consumer;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import jdk.jfr.Recording;
|
import jdk.jfr.Recording;
|
||||||
import jdk.jfr.consumer.RecordedEvent;
|
import jdk.jfr.consumer.RecordedEvent;
|
||||||
@ -49,31 +50,16 @@ import jdk.test.lib.jfr.SimpleEvent;
|
|||||||
public final class TestRecordedFrame {
|
public final class TestRecordedFrame {
|
||||||
|
|
||||||
public static void main(String[] args) throws IOException {
|
public static void main(String[] args) throws IOException {
|
||||||
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
|
System.out.println(); // Makes BCI for method larger than 0
|
||||||
doTest(getLineNumber("main", stackTrace) + 1);
|
test(); // Records the line number and BCI for the main method/frame
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
static void test() throws IOException {
|
||||||
* Returns line number of the passed method for the passed stacktrace
|
try (Recording recording = new Recording()) {
|
||||||
*/
|
|
||||||
private static int getLineNumber(String methodName, StackTraceElement[] stackTrace) {
|
|
||||||
for (StackTraceElement ste : stackTrace) {
|
|
||||||
if (methodName.equals(ste.getMethodName())) {
|
|
||||||
return ste.getLineNumber();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw new RuntimeException("Unexpected error: could not analyze stacktrace");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void doTest(int lineNumber) throws IOException {
|
|
||||||
|
|
||||||
System.out.println("Enetring method");
|
|
||||||
|
|
||||||
Recording recording = new Recording();
|
|
||||||
recording.start();
|
recording.start();
|
||||||
|
|
||||||
SimpleEvent ev = new SimpleEvent();
|
SimpleEvent ev = new SimpleEvent();
|
||||||
commitEvent(ev);
|
ev.commit();
|
||||||
recording.stop();
|
recording.stop();
|
||||||
|
|
||||||
List<RecordedEvent> recordedEvents = Events.fromRecording(recording);
|
List<RecordedEvent> recordedEvents = Events.fromRecording(recording);
|
||||||
@ -83,40 +69,40 @@ public final class TestRecordedFrame {
|
|||||||
RecordedStackTrace stacktrace = recordedEvent.getStackTrace();
|
RecordedStackTrace stacktrace = recordedEvent.getStackTrace();
|
||||||
List<RecordedFrame> frames = stacktrace.getFrames();
|
List<RecordedFrame> frames = stacktrace.getFrames();
|
||||||
for (RecordedFrame frame : frames) {
|
for (RecordedFrame frame : frames) {
|
||||||
|
|
||||||
// All frames are java frames
|
// All frames are java frames
|
||||||
Asserts.assertTrue(frame.isJavaFrame());
|
Asserts.assertTrue(frame.isJavaFrame());
|
||||||
// Verify the main() method frame
|
// Verify the main() method frame
|
||||||
RecordedMethod method = frame.getMethod();
|
RecordedMethod method = frame.getMethod();
|
||||||
if (method.getName().equals("main")) {
|
if (method.getName().equals("main")) {
|
||||||
|
|
||||||
// Frame type
|
// Frame type
|
||||||
String type = frame.getType();
|
String type = frame.getType();
|
||||||
System.out.println("type: " + type);
|
System.out.println("type: " + type);
|
||||||
Asserts.assertTrue(
|
Set<String> types = Set.of("Interpreted", "JIT compiled", "Inlined");
|
||||||
type.equals("Interpreted")
|
Asserts.assertTrue(types.contains(type));
|
||||||
|| type.equals("JIT compiled")
|
// Line number
|
||||||
|| type.equals("Inlined"));
|
Asserts.assertEquals(getLineNumber("main"), frame.getLineNumber());
|
||||||
|
// Interpreted
|
||||||
Asserts.assertEquals(lineNumber, frame.getLineNumber());
|
|
||||||
|
|
||||||
boolean isInterpreted = "Interpreted".equals(type);
|
boolean isInterpreted = "Interpreted".equals(type);
|
||||||
boolean expectedInterpreted = "true".equals(System.getProperty("interpreted"));
|
boolean expectedInterpreted = "true".equals(System.getProperty("interpreted"));
|
||||||
Asserts.assertEquals(isInterpreted, expectedInterpreted);
|
Asserts.assertEquals(isInterpreted, expectedInterpreted);
|
||||||
|
// BCI
|
||||||
int bci = frame.getBytecodeIndex();
|
int bci = frame.getBytecodeIndex();
|
||||||
|
|
||||||
System.out.println("bci: " + bci);
|
System.out.println("bci: " + bci);
|
||||||
Asserts.assertTrue(bci > 0);
|
Asserts.assertGreaterThan(bci, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns line number of a method on the stack
|
||||||
|
*/
|
||||||
|
private static int getLineNumber(String methodName) {
|
||||||
|
for (StackTraceElement ste : Thread.currentThread().getStackTrace()) {
|
||||||
|
if (methodName.equals(ste.getMethodName())) {
|
||||||
|
return ste.getLineNumber();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
throw new RuntimeException("Unexpected error: could not analyze stacktrace");
|
||||||
private static void commitEvent(SimpleEvent ev) {
|
|
||||||
System.out.println("commit");
|
|
||||||
ev.commit();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -79,16 +79,16 @@ public class TestRecordedFullStackTrace {
|
|||||||
private static void assertStackTraces(RecurseThread[] threads) throws Throwable {
|
private static void assertStackTraces(RecurseThread[] threads) throws Throwable {
|
||||||
Path path = null;
|
Path path = null;
|
||||||
do {
|
do {
|
||||||
Recording recording = new Recording();
|
try (Recording recording = new Recording()) {
|
||||||
recording.enable(EVENT_NAME).withPeriod(Duration.ofMillis(50));
|
recording.enable(EVENT_NAME).withPeriod(Duration.ofMillis(1));
|
||||||
recording.start();
|
recording.start();
|
||||||
Thread.sleep(500);
|
Thread.sleep(50);
|
||||||
recording.stop();
|
recording.stop();
|
||||||
// Dump the recording to a file
|
// Dump the recording to a file
|
||||||
path = Utils.createTempFile("execution-stack-trace", ".jfr");
|
path = Utils.createTempFile("execution-stack-trace", ".jfr");
|
||||||
System.out.println("Dumping to " + path);
|
System.out.println("Dumping to " + path);
|
||||||
recording.dump(path);
|
recording.dump(path);
|
||||||
recording.close();
|
}
|
||||||
} while (!hasValidStackTraces(path, threads));
|
} while (!hasValidStackTraces(path, threads));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,8 +103,7 @@ public class TestRecordedFullStackTrace {
|
|||||||
for (int threadIndex = 0; threadIndex < threads.length; ++threadIndex) {
|
for (int threadIndex = 0; threadIndex < threads.length; ++threadIndex) {
|
||||||
RecurseThread currThread = threads[threadIndex];
|
RecurseThread currThread = threads[threadIndex];
|
||||||
if (threadId == currThread.getId()) {
|
if (threadId == currThread.getId()) {
|
||||||
System.out.println("ThreadName=" + currThread.getName() + ", depth=" + currThread.totalDepth);
|
Asserts.assertEquals(threadName, currThread.getName(), "Wrong thread name, deptth=" + currThread.totalDepth);
|
||||||
Asserts.assertEquals(threadName, currThread.getName(), "Wrong thread name");
|
|
||||||
if ("recurseEnd".equals(getTopMethodName(event))) {
|
if ("recurseEnd".equals(getTopMethodName(event))) {
|
||||||
isEventFound[threadIndex] = true;
|
isEventFound[threadIndex] = true;
|
||||||
checkEvent(event, currThread.totalDepth);
|
checkEvent(event, currThread.totalDepth);
|
||||||
@ -147,8 +146,7 @@ public class TestRecordedFullStackTrace {
|
|||||||
for (int i = 0; i < frames.size(); ++i) {
|
for (int i = 0; i < frames.size(); ++i) {
|
||||||
String name = frames.get(i).getMethod().getName();
|
String name = frames.get(i).getMethod().getName();
|
||||||
String expectedName = expectedMethods.get(i);
|
String expectedName = expectedMethods.get(i);
|
||||||
System.out.printf("method[%d]=%s, expected=%s%n", i, name, expectedName);
|
Asserts.assertEquals(name, expectedName, "Wrong method name at index " + i);
|
||||||
Asserts.assertEquals(name, expectedName, "Wrong method name");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isTruncated = stacktrace.isTruncated();
|
boolean isTruncated = stacktrace.isTruncated();
|
||||||
|
@ -44,7 +44,7 @@ import jdk.test.lib.jfr.SimpleEvent;
|
|||||||
public class TestRecordedInstantEventTimestamp {
|
public class TestRecordedInstantEventTimestamp {
|
||||||
|
|
||||||
public static void main(String[] args) throws Throwable {
|
public static void main(String[] args) throws Throwable {
|
||||||
Recording r = new Recording();
|
try (Recording r = new Recording()) {
|
||||||
r.start();
|
r.start();
|
||||||
SimpleEvent s = new SimpleEvent();
|
SimpleEvent s = new SimpleEvent();
|
||||||
s.commit();
|
s.commit();
|
||||||
@ -54,7 +54,6 @@ public class TestRecordedInstantEventTimestamp {
|
|||||||
Events.hasEvents(events);
|
Events.hasEvents(events);
|
||||||
RecordedEvent event = events.get(0);
|
RecordedEvent event = events.get(0);
|
||||||
Asserts.assertEquals(event.getStartTime(), event.getEndTime());
|
Asserts.assertEquals(event.getStartTime(), event.getEndTime());
|
||||||
|
}
|
||||||
r.close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,14 +34,15 @@ import java.util.List;
|
|||||||
import jdk.jfr.Event;
|
import jdk.jfr.Event;
|
||||||
import jdk.jfr.Recording;
|
import jdk.jfr.Recording;
|
||||||
import jdk.jfr.consumer.RecordedEvent;
|
import jdk.jfr.consumer.RecordedEvent;
|
||||||
import jdk.jfr.consumer.RecordedMethod;
|
|
||||||
import jdk.jfr.consumer.RecordedFrame;
|
import jdk.jfr.consumer.RecordedFrame;
|
||||||
|
import jdk.jfr.consumer.RecordedMethod;
|
||||||
import jdk.jfr.consumer.RecordedStackTrace;
|
import jdk.jfr.consumer.RecordedStackTrace;
|
||||||
import jdk.test.lib.jfr.Events;
|
import jdk.test.lib.jfr.Events;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
|
* @summary Verifies that the method descriptor is correct
|
||||||
* @key jfr
|
* @key jfr
|
||||||
* @requires vm.hasJFR
|
* @requires vm.hasJFR
|
||||||
* @library /test/lib
|
* @library /test/lib
|
||||||
@ -49,18 +50,18 @@ import jdk.test.lib.jfr.Events;
|
|||||||
*/
|
*/
|
||||||
public final class TestRecordedMethodDescriptor {
|
public final class TestRecordedMethodDescriptor {
|
||||||
|
|
||||||
private static boolean isMainMethodDescriptorRecorded;
|
public static class MyEvent extends Event {
|
||||||
|
}
|
||||||
|
|
||||||
private static final String MAIN_METHOD_DESCRIPTOR = "([Ljava/lang/String;)V";
|
private static final String MAIN_METHOD_DESCRIPTOR = "([Ljava/lang/String;)V";
|
||||||
private static final String MAIN_METHOD_NAME = "main";
|
private static final String MAIN_METHOD_NAME = "main";
|
||||||
|
|
||||||
public static void main(String[] args) throws Throwable {
|
public static void main(String[] args) throws Exception {
|
||||||
Recording recording = new Recording();
|
try (Recording recording = new Recording()) {
|
||||||
recording.enable(MyEvent.class).withStackTrace();
|
recording.enable(MyEvent.class);
|
||||||
recording.start();
|
recording.start();
|
||||||
|
|
||||||
MyEvent event = new MyEvent();
|
MyEvent event = new MyEvent();
|
||||||
event.begin();
|
|
||||||
event.end();
|
|
||||||
event.commit();
|
event.commit();
|
||||||
recording.stop();
|
recording.stop();
|
||||||
|
|
||||||
@ -71,27 +72,20 @@ public final class TestRecordedMethodDescriptor {
|
|||||||
RecordedStackTrace stacktrace = recordedEvent.getStackTrace();
|
RecordedStackTrace stacktrace = recordedEvent.getStackTrace();
|
||||||
List<RecordedFrame> frames = stacktrace.getFrames();
|
List<RecordedFrame> frames = stacktrace.getFrames();
|
||||||
assertFalse(frames.isEmpty(), "Stacktrace frames was empty");
|
assertFalse(frames.isEmpty(), "Stacktrace frames was empty");
|
||||||
|
|
||||||
|
boolean foundMainMethod = false;
|
||||||
for (RecordedFrame frame : frames) {
|
for (RecordedFrame frame : frames) {
|
||||||
analyzeRecordedMethodDescriptor(frame.getMethod());
|
RecordedMethod method = frame.getMethod();
|
||||||
}
|
|
||||||
|
|
||||||
assertTrue(isMainMethodDescriptorRecorded, "main() method descriptor has never been recorded");
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void analyzeRecordedMethodDescriptor(RecordedMethod method) {
|
|
||||||
|
|
||||||
String descr = method.getDescriptor();
|
String descr = method.getDescriptor();
|
||||||
assertNotNull(descr, "Method descriptor is null");
|
assertNotNull(descr, "Method descriptor is null");
|
||||||
String name = method.getName();
|
String name = method.getName();
|
||||||
assertNotNull(name, "Method name is null");
|
assertNotNull(name, "Method name is null");
|
||||||
|
|
||||||
if (name.equals(MAIN_METHOD_NAME) && descr.equals(MAIN_METHOD_DESCRIPTOR)) {
|
if (name.equals(MAIN_METHOD_NAME) && descr.equals(MAIN_METHOD_DESCRIPTOR)) {
|
||||||
assertFalse(isMainMethodDescriptorRecorded, "main() method descriptor already recorded");
|
assertFalse(foundMainMethod, "main() method descriptor already recorded");
|
||||||
isMainMethodDescriptorRecorded = true;
|
foundMainMethod = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
assertTrue(foundMainMethod, "main() method descriptor has never been recorded");
|
||||||
public static class MyEvent extends Event {
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -377,7 +377,7 @@ public class TestRecordedObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static RecordedObject makeRecordedObject() throws IOException {
|
private static RecordedObject makeRecordedObject() throws IOException {
|
||||||
Recording r = new Recording();
|
try (Recording r = new Recording()) {
|
||||||
r.start();
|
r.start();
|
||||||
EventWithValues t = new EventWithValues();
|
EventWithValues t = new EventWithValues();
|
||||||
t.commit();
|
t.commit();
|
||||||
@ -386,6 +386,7 @@ public class TestRecordedObject {
|
|||||||
Events.hasEvents(events);
|
Events.hasEvents(events);
|
||||||
return events.get(0);
|
return events.get(0);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static Set<String> createAll() {
|
private static Set<String> createAll() {
|
||||||
Set<String> set = new HashSet<>();
|
Set<String> set = new HashSet<>();
|
||||||
|
@ -74,9 +74,10 @@ public class TestRecordingFile {
|
|||||||
private final static long METADATA_OFFSET = 24;
|
private final static long METADATA_OFFSET = 24;
|
||||||
|
|
||||||
public static void main(String[] args) throws Throwable {
|
public static void main(String[] args) throws Throwable {
|
||||||
|
Path valid = Utils.createTempFile("three-event-recording", ".jfr");
|
||||||
|
|
||||||
// create some recording data
|
// create some recording data
|
||||||
Recording r = new Recording();
|
try (Recording r = new Recording()) {
|
||||||
r.enable(TestEvent1.class).withoutStackTrace();
|
r.enable(TestEvent1.class).withoutStackTrace();
|
||||||
r.enable(TestEvent2.class).withoutStackTrace();
|
r.enable(TestEvent2.class).withoutStackTrace();
|
||||||
r.enable(TestEvent3.class).withoutStackTrace();
|
r.enable(TestEvent3.class).withoutStackTrace();
|
||||||
@ -88,10 +89,8 @@ public class TestRecordingFile {
|
|||||||
TestEvent3 t3 = new TestEvent3();
|
TestEvent3 t3 = new TestEvent3();
|
||||||
t3.commit();
|
t3.commit();
|
||||||
r.stop();
|
r.stop();
|
||||||
Path valid = Utils.createTempFile("three-event-recording", ".jfr");
|
|
||||||
r.dump(valid);
|
r.dump(valid);
|
||||||
r.close();
|
}
|
||||||
|
|
||||||
Path brokenWithZeros = createBrokenWIthZeros(valid);
|
Path brokenWithZeros = createBrokenWIthZeros(valid);
|
||||||
Path brokenMetadata = createBrokenMetadata(valid);
|
Path brokenMetadata = createBrokenMetadata(valid);
|
||||||
// prepare event sets
|
// prepare event sets
|
||||||
|
@ -44,13 +44,12 @@ import jdk.test.lib.jfr.SimpleEvent;
|
|||||||
public class TestRecordingFileReadEventEof {
|
public class TestRecordingFileReadEventEof {
|
||||||
|
|
||||||
public static void main(String[] args) throws Throwable {
|
public static void main(String[] args) throws Throwable {
|
||||||
Recording r = new Recording();
|
try (Recording r = new Recording()) {
|
||||||
r.start();
|
r.start();
|
||||||
SimpleEvent t = new SimpleEvent();
|
SimpleEvent t = new SimpleEvent();
|
||||||
t.commit();
|
t.commit();
|
||||||
r.stop();
|
r.stop();
|
||||||
RecordingFile file = Events.copyTo(r);
|
RecordingFile file = Events.copyTo(r);
|
||||||
r.close();
|
|
||||||
file.readEvent();
|
file.readEvent();
|
||||||
try {
|
try {
|
||||||
file.readEvent();
|
file.readEvent();
|
||||||
@ -59,4 +58,5 @@ public class TestRecordingFileReadEventEof {
|
|||||||
// OK, as expected
|
// OK, as expected
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,7 @@ public class TestSingleRecordedEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws Throwable {
|
public static void main(String[] args) throws Throwable {
|
||||||
Recording r = new Recording();
|
try (Recording r = new Recording()) {
|
||||||
r.start();
|
r.start();
|
||||||
// Commit a single event to the recording
|
// Commit a single event to the recording
|
||||||
MyEvent event = new MyEvent();
|
MyEvent event = new MyEvent();
|
||||||
@ -60,10 +60,8 @@ public class TestSingleRecordedEvent {
|
|||||||
|
|
||||||
// Should be 1 event only
|
// Should be 1 event only
|
||||||
Asserts.assertEquals(events.size(), 1);
|
Asserts.assertEquals(events.size(), 1);
|
||||||
|
|
||||||
RecordedEvent recordedEvent = events.get(0);
|
RecordedEvent recordedEvent = events.get(0);
|
||||||
|
|
||||||
// Event description should be the same
|
|
||||||
Asserts.assertEquals(recordedEvent.getEventType().getDescription(), "MyDescription");
|
Asserts.assertEquals(recordedEvent.getEventType().getDescription(), "MyDescription");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,14 +48,13 @@ import jdk.test.lib.jfr.Events;
|
|||||||
public class TestValueDescriptorRecorded {
|
public class TestValueDescriptorRecorded {
|
||||||
|
|
||||||
private static class MyEvent extends Event {
|
private static class MyEvent extends Event {
|
||||||
|
|
||||||
@Label("myLabel")
|
@Label("myLabel")
|
||||||
@Description("myDescription")
|
@Description("myDescription")
|
||||||
int myValue;
|
int myValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws Throwable {
|
public static void main(String[] args) throws Throwable {
|
||||||
Recording r = new Recording();
|
try (Recording r = new Recording()) {
|
||||||
r.enable(MyEvent.class).withoutStackTrace();
|
r.enable(MyEvent.class).withoutStackTrace();
|
||||||
r.start();
|
r.start();
|
||||||
MyEvent event = new MyEvent();
|
MyEvent event = new MyEvent();
|
||||||
@ -65,7 +64,6 @@ public class TestValueDescriptorRecorded {
|
|||||||
List<RecordedEvent> events = Events.fromRecording(r);
|
List<RecordedEvent> events = Events.fromRecording(r);
|
||||||
Events.hasEvents(events);
|
Events.hasEvents(events);
|
||||||
RecordedEvent recordedEvent = events.get(0);
|
RecordedEvent recordedEvent = events.get(0);
|
||||||
|
|
||||||
for (ValueDescriptor desc : recordedEvent.getFields()) {
|
for (ValueDescriptor desc : recordedEvent.getFields()) {
|
||||||
if ("myValue".equals(desc.getName())) {
|
if ("myValue".equals(desc.getName())) {
|
||||||
Asserts.assertEquals(desc.getLabel(), "myLabel");
|
Asserts.assertEquals(desc.getLabel(), "myLabel");
|
||||||
@ -76,4 +74,5 @@ public class TestValueDescriptorRecorded {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user