|
1 /* |
|
2 * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved. |
|
3 * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. |
|
4 */ |
|
5 |
|
6 import java.util.List; |
|
7 import java.util.concurrent.CountDownLatch; |
|
8 |
|
9 import jrockit.Asserts; |
|
10 import jrockit.TestThread; |
|
11 import jrockit.XRun; |
|
12 import jrockit.jfr.TestRecording; |
|
13 import jrockit.jfr.ValueFilter; |
|
14 import oracle.jrockit.jfr.parser.FLREvent; |
|
15 import oracle.jrockit.jfr.parser.FLRStruct; |
|
16 |
|
17 /* |
|
18 * @test TestJavaMonitorInflateEvent |
|
19 * @key jfr |
|
20 * @library ../common |
|
21 * @modules jdk.jfr/oracle.jrockit.jfr |
|
22 * jdk.jfr/oracle.jrockit.jfr.parser |
|
23 * @build jrockit.* jrockit.jfr.* |
|
24 * @run main/othervm -XX:+UnlockCommercialFeatures -XX:+FlightRecorder TestJavaMonitorInflateEvent |
|
25 */ |
|
26 public class TestJavaMonitorInflateEvent { |
|
27 |
|
28 private static final String FIELD_CLASS_NAME = "name"; |
|
29 private static final String FIELD_KLASS = "klass"; |
|
30 private static final String FIELD_ADDRESS = "address"; |
|
31 private static final String FIELD_CAUSE = "cause"; |
|
32 |
|
33 private final static String EVENT_PATH = "java/monitor_inflate"; |
|
34 |
|
35 static class Lock { |
|
36 } |
|
37 |
|
38 public static void main(String[] args) throws Exception { |
|
39 TestRecording r = new TestRecording(); |
|
40 try { |
|
41 r.createJVMSetting(EVENT_PATH, true, true, 0, 0); |
|
42 |
|
43 final Lock lock = new Lock(); |
|
44 final CountDownLatch latch = new CountDownLatch(1); |
|
45 |
|
46 // create a thread that waits |
|
47 TestThread waitThread = new TestThread(new XRun() { |
|
48 @Override |
|
49 public void xrun() throws Throwable { |
|
50 synchronized (lock) { |
|
51 latch.countDown(); |
|
52 lock.wait(123456); |
|
53 } |
|
54 } |
|
55 }); |
|
56 try { |
|
57 r.start(); |
|
58 waitThread.start(); |
|
59 latch.await(); |
|
60 synchronized (lock) { |
|
61 lock.notifyAll(); |
|
62 } |
|
63 } finally { |
|
64 waitThread.join(); |
|
65 r.stop(); |
|
66 } |
|
67 |
|
68 List<FLREvent> events = r.parser().findJVMEvents(EVENT_PATH); |
|
69 System.out.println(events); |
|
70 if (events.isEmpty()) { |
|
71 throw new Exception("Expected event"); |
|
72 } |
|
73 |
|
74 String thisThreadName = Thread.currentThread().getName(); |
|
75 String waitThreadName = waitThread.getName(); |
|
76 |
|
77 // Find at least one event with the correct monitor class and check the other fields |
|
78 boolean foundEvent = false; |
|
79 for (FLREvent event : events) { |
|
80 if (!String.valueOf(event.getThread().getResolvedValue("name")).equals(waitThreadName)) { |
|
81 continue; |
|
82 } |
|
83 // Check lock class |
|
84 FLRStruct klassStruct = (FLRStruct) event.getResolvedValue(FIELD_KLASS); |
|
85 String recordedLockClass = String.valueOf(klassStruct.getResolvedValue(FIELD_CLASS_NAME)); |
|
86 String lockClass = lock.getClass().getName(); |
|
87 if (!recordedLockClass.equals(lockClass)) { |
|
88 continue; |
|
89 } |
|
90 |
|
91 foundEvent = true; |
|
92 // Check address |
|
93 Asserts.assertNotEquals(0L, event.getResolvedValue(FIELD_ADDRESS), FIELD_ADDRESS + " should not be 0"); |
|
94 // Check cause |
|
95 Asserts.assertNotNull(event.getValue(FIELD_CAUSE), FIELD_CAUSE + " should not be null"); |
|
96 } |
|
97 Asserts.assertTrue(foundEvent, "Excepted event from test thread"); |
|
98 } catch (Throwable e) { |
|
99 r.copyTo("failed.jfr"); |
|
100 throw e; |
|
101 } finally { |
|
102 r.close(); |
|
103 } |
|
104 } |
|
105 } |