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