From 6c15200735846b0366ff6a5c15456f1781efba73 Mon Sep 17 00:00:00 2001 From: Denghui Dong Date: Thu, 10 Sep 2020 15:57:56 +0800 Subject: [PATCH] [Backport] 8237499: JFR: Include stack trace in the ThreadStart event Summary: Test Plan: test/jdk/jfr/event/runtime/TestThreadStartEndEvents.java Reviewed-by: zhengxiaolinX, yuleil Issue: https://github.com/alibaba/dragonwell8/issues/127 --- src/share/classes/jdk/jfr/conf/default.jfc | 1 + src/share/classes/jdk/jfr/conf/profile.jfc | 1 + .../runtime/TestThreadStartEndEvents.java | 21 +++++++++++++++---- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/share/classes/jdk/jfr/conf/default.jfc b/src/share/classes/jdk/jfr/conf/default.jfc index c35e71ec0..f1b0b3e63 100644 --- a/src/share/classes/jdk/jfr/conf/default.jfc +++ b/src/share/classes/jdk/jfr/conf/default.jfc @@ -29,6 +29,7 @@ true + true diff --git a/src/share/classes/jdk/jfr/conf/profile.jfc b/src/share/classes/jdk/jfr/conf/profile.jfc index 814c09ef8..10bc1dbc7 100644 --- a/src/share/classes/jdk/jfr/conf/profile.jfc +++ b/src/share/classes/jdk/jfr/conf/profile.jfc @@ -29,6 +29,7 @@ true + true diff --git a/test/jdk/jfr/event/runtime/TestThreadStartEndEvents.java b/test/jdk/jfr/event/runtime/TestThreadStartEndEvents.java index ea0de076e..660c4a24a 100644 --- a/test/jdk/jfr/event/runtime/TestThreadStartEndEvents.java +++ b/test/jdk/jfr/event/runtime/TestThreadStartEndEvents.java @@ -25,12 +25,17 @@ package jdk.jfr.event.runtime; +import static jdk.test.lib.Asserts.assertEquals; +import static jdk.test.lib.Asserts.assertNotNull; + import java.time.Duration; import java.util.List; import java.util.concurrent.CountDownLatch; import jdk.jfr.Recording; import jdk.jfr.consumer.RecordedEvent; +import jdk.jfr.consumer.RecordedMethod; +import jdk.jfr.consumer.RecordedStackTrace; import jdk.test.lib.jfr.EventNames; import jdk.test.lib.jfr.Events; @@ -62,19 +67,27 @@ public class TestThreadStartEndEvents { recording.stop(); int currThreadIndex = 0; - long currentThreadId = Thread.currentThread().getId(); List events = Events.fromRecording(recording); + events.sort((e1, e2) -> e1.getStartTime().compareTo(e2.getStartTime())); Events.hasEvents(events); for (RecordedEvent event : events) { - System.out.println("Event:" + event); - if (event.getThread().getJavaThreadId() != currentThreadId) { + if (!event.getThread().getJavaName().startsWith(THREAD_NAME_PREFIX)) { continue; } + System.out.println("Event:" + event); // Threads should be started and stopped in the correct order. Events.assertEventThread(event, threads[currThreadIndex % threads.length]); String eventName = currThreadIndex < threads.length ? EVENT_NAME_THREAD_START : EVENT_NAME_THREAD_END; if (!eventName.equals(event.getEventType().getName())) { - throw new Exception("Expected event of tyoe " + eventName + " but got " + event.getEventType().getName()); + throw new Exception("Expected event of type " + eventName + " but got " + event.getEventType().getName()); + } + + if (eventName == EVENT_NAME_THREAD_START) { + Events.assertEventThread(event, "parentThread", Thread.currentThread()); + RecordedStackTrace stackTrace = event.getValue("stackTrace"); + assertNotNull(stackTrace); + RecordedMethod topMethod = stackTrace.getFrames().get(0).getMethod(); + assertEquals(topMethod.getName(), "startThread"); } currThreadIndex++; } -- GitLab