22 */
23
24 package jdk.jfr.event.runtime;
25
26 import java.time.Duration;
27 import java.util.*;
28
29 import jdk.jfr.Recording;
30 import jdk.jfr.consumer.RecordedEvent;
31 import jdk.jfr.consumer.RecordedThread;
32 import jdk.test.lib.jfr.EventNames;
33 import jdk.test.lib.jfr.Events;
34
35 /**
36 * @test
37 * @bug 8242263
38 * @requires vm.hasJFR
39 * @key jfr
40 * @library /test/lib
41 * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:DiagnoseSyncOnValueBasedClasses=2 jdk.jfr.event.runtime.TestSyncOnValueBasedClassEvent
42 */
43 public class TestSyncOnValueBasedClassEvent {
44 static final String EVENT_NAME = EventNames.SyncOnValueBasedClass;
45 static String[] classesWanted = {"java/lang/Character", "java/lang/Boolean", "java/lang/Byte", "java/lang/Short",
46 "java/lang/Integer", "java/lang/Long", "java/lang/Float", "java/lang/Double",
47 "java/time/Duration", "java/util/OptionalInt", "java/lang/Runtime$Version"};
48 static List<Object> testObjects = new ArrayList<Object>();
49 static Integer counter = 0;
50
51 private static void initTestObjects() {
52 testObjects.add(Character.valueOf('H'));
53 testObjects.add(Boolean.valueOf(true));
54 testObjects.add(Byte.valueOf((byte)0x40));
55 testObjects.add(Short.valueOf((short)0x4000));
56 testObjects.add(Integer.valueOf(0x40000000));
57 testObjects.add(Long.valueOf(0x4000000000000000L));
58 testObjects.add(Float.valueOf(1.20f));
59 testObjects.add(Double.valueOf(1.2345));
60 testObjects.add(Duration.ofMillis(5));
61 testObjects.add(OptionalInt.of(10));
62 testObjects.add(Runtime.version());
63 }
64
65 public static void main(String[] args) throws Throwable {
66 initTestObjects();
67 Recording recording = new Recording();
68 recording.enable(EVENT_NAME).withThreshold(Duration.ofMillis(0));
69 recording.start();
70 for (Object obj : testObjects) {
71 synchronized (obj) {
72 counter++;
73 }
74 }
75 recording.stop();
76
77 List<String> classesFound = new ArrayList<String>();
78 List<RecordedEvent> events = Events.fromRecording(recording);
79 Events.hasEvents(events);
80 for (RecordedEvent event : Events.fromRecording(recording)) {
81 String className = Events.assertField(event, "valueBasedClass.name").notEmpty().getValue();
|
22 */
23
24 package jdk.jfr.event.runtime;
25
26 import java.time.Duration;
27 import java.util.*;
28
29 import jdk.jfr.Recording;
30 import jdk.jfr.consumer.RecordedEvent;
31 import jdk.jfr.consumer.RecordedThread;
32 import jdk.test.lib.jfr.EventNames;
33 import jdk.test.lib.jfr.Events;
34
35 /**
36 * @test
37 * @bug 8242263
38 * @requires vm.hasJFR
39 * @key jfr
40 * @library /test/lib
41 * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:DiagnoseSyncOnValueBasedClasses=2 jdk.jfr.event.runtime.TestSyncOnValueBasedClassEvent
42 * @run main/othervm --enable-preview -XX:+UnlockDiagnosticVMOptions -XX:DiagnoseSyncOnValueBasedClasses=2 jdk.jfr.event.runtime.TestSyncOnValueBasedClassEvent
43 */
44 public class TestSyncOnValueBasedClassEvent {
45 static final String EVENT_NAME = EventNames.SyncOnValueBasedClass;
46 static String[] classesWanted = {"java/lang/Character", "java/lang/Boolean", "java/lang/Byte", "java/lang/Short",
47 "java/lang/Integer", "java/lang/Long", "java/lang/Float", "java/lang/Double",
48 "java/lang/Runtime$Version"};
49 static List<Object> testObjects = new ArrayList<Object>();
50 static Integer counter = 0;
51
52 private static void initTestObjects() {
53 testObjects.add(Character.valueOf('H'));
54 testObjects.add(Boolean.valueOf(true));
55 testObjects.add(Byte.valueOf((byte)0x40));
56 testObjects.add(Short.valueOf((short)0x4000));
57 testObjects.add(Integer.valueOf(0x40000000));
58 testObjects.add(Long.valueOf(0x4000000000000000L));
59 testObjects.add(Float.valueOf(1.20f));
60 testObjects.add(Double.valueOf(1.2345));
61 testObjects.add(Runtime.version());
62 }
63
64 public static void main(String[] args) throws Throwable {
65 initTestObjects();
66 Recording recording = new Recording();
67 recording.enable(EVENT_NAME).withThreshold(Duration.ofMillis(0));
68 recording.start();
69 for (Object obj : testObjects) {
70 synchronized (obj) {
71 counter++;
72 }
73 }
74 recording.stop();
75
76 List<String> classesFound = new ArrayList<String>();
77 List<RecordedEvent> events = Events.fromRecording(recording);
78 Events.hasEvents(events);
79 for (RecordedEvent event : Events.fromRecording(recording)) {
80 String className = Events.assertField(event, "valueBasedClass.name").notEmpty().getValue();
|