From 2872b8f979c9de43c0aa1706ce1a3d425427c79e Mon Sep 17 00:00:00 2001 From: Denghui Dong Date: Fri, 31 Jul 2020 13:21:59 +0800 Subject: [PATCH] [JFR] Added SafepointStatistics and HugeObjectAllocationSample Events Summary: SafepointStatistics is a periodic event, both events are experimental now and disbaled by default Test Plan: jdk/jfr/event/runtime/TestSafepointEvents.java jdk/jfr/event/compiler/TestHugeObjectAllocationSample.java jdk/jfr/event/metadata/TestLookForUntestedEvents.java Reviewed-by: kuaiwei Issue: https://github.com/alibaba/dragonwell8/issues/116 --- src/share/classes/jdk/jfr/conf/default.jfc | 10 +++ src/share/classes/jdk/jfr/conf/profile.jfc | 10 +++ .../TestHugeObjectAllocationSample.java | 72 +++++++++++++++++++ .../metadata/TestLookForUntestedEvents.java | 3 +- .../event/runtime/TestSafepointEvents.java | 18 +++++ test/lib/jdk/test/lib/jfr/EventNames.java | 3 + 6 files changed, 115 insertions(+), 1 deletion(-) create mode 100644 test/jdk/jfr/event/compiler/TestHugeObjectAllocationSample.java diff --git a/src/share/classes/jdk/jfr/conf/default.jfc b/src/share/classes/jdk/jfr/conf/default.jfc index 871949601..c35e71ec0 100644 --- a/src/share/classes/jdk/jfr/conf/default.jfc +++ b/src/share/classes/jdk/jfr/conf/default.jfc @@ -644,6 +644,16 @@ true + + false + 5 s + + + + false + true + + diff --git a/src/share/classes/jdk/jfr/conf/profile.jfc b/src/share/classes/jdk/jfr/conf/profile.jfc index 03e7e4b1e..814c09ef8 100644 --- a/src/share/classes/jdk/jfr/conf/profile.jfc +++ b/src/share/classes/jdk/jfr/conf/profile.jfc @@ -644,6 +644,16 @@ true + + false + 5 s + + + + false + true + + diff --git a/test/jdk/jfr/event/compiler/TestHugeObjectAllocationSample.java b/test/jdk/jfr/event/compiler/TestHugeObjectAllocationSample.java new file mode 100644 index 000000000..b2e16bb31 --- /dev/null +++ b/test/jdk/jfr/event/compiler/TestHugeObjectAllocationSample.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2020 Alibaba Group Holding Limited. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Alibaba designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package jdk.jfr.event.compiler; + +import static java.lang.Math.floor; +import static jdk.test.lib.Asserts.assertGreaterThanOrEqual; + +import java.time.Duration; + +import jdk.jfr.Recording; +import jdk.jfr.consumer.RecordedEvent; +import jdk.test.lib.jfr.EventNames; +import jdk.test.lib.jfr.Events; + +/** + * @test + * @summary Test that when a huge object is allocated an event will be triggered. + * @key jfr + * + * @library /lib / + * @run main/othervm -XX:+UseTLAB -XX:-FastTLABRefill -XX:TLABSize=90k -XX:-ResizeTLAB -XX:TLABRefillWasteFraction=256 -XX:HugeObjectAllocationThreshold=64m jdk.jfr.event.compiler.TestHugeObjectAllocationSample + * @run main/othervm -XX:+UseTLAB -XX:-FastTLABRefill -XX:TLABSize=90k -XX:-ResizeTLAB -XX:TLABRefillWasteFraction=256 -Xint -XX:HugeObjectAllocationThreshold=64m jdk.jfr.event.compiler.TestHugeObjectAllocationSample + */ +public class TestHugeObjectAllocationSample { + private static final String EVENT_NAME = EventNames.HugeObjectAllocationSample; + private static final int OBJECT_SIZE = 64 * 1024 * 1024; + private static final int OBJECTS_TO_ALLOCATE = 100; + + public static void main(String[] args) throws Exception { + Recording recording = new Recording(); + recording.enable(EVENT_NAME).withThreshold(Duration.ofMillis(0)); + recording.start(); + for (int i = 0; i < OBJECTS_TO_ALLOCATE ; i++) { + System.out.println("new huge byte array " + i +": " + new byte[OBJECT_SIZE]); + } + recording.stop(); + int count = 0; + for (RecordedEvent event : Events.fromRecording(recording)) { + if (!EVENT_NAME.equals(event.getEventType().getName())) { + continue; + } + System.out.println("Event:" + event); + long allocationSize = Events.assertField(event, "allocationSize").atLeast((long)OBJECT_SIZE).getValue(); + String className = Events.assertField(event, "objectClass.name").notEmpty().getValue(); + if (Thread.currentThread().getId() == event.getThread().getJavaThreadId() + && className.equals(byte[].class.getName())) { + count++; + } + } + int minCount = (int) floor(OBJECTS_TO_ALLOCATE * 0.80); + assertGreaterThanOrEqual(count, minCount, "Too few events"); + } +} diff --git a/test/jdk/jfr/event/metadata/TestLookForUntestedEvents.java b/test/jdk/jfr/event/metadata/TestLookForUntestedEvents.java index 96dbda7f0..e5b973e7c 100644 --- a/test/jdk/jfr/event/metadata/TestLookForUntestedEvents.java +++ b/test/jdk/jfr/event/metadata/TestLookForUntestedEvents.java @@ -91,7 +91,8 @@ public class TestLookForUntestedEvents { private static final Set experimentalEvents = new HashSet<>( Arrays.asList( "Flush", "FlushStorage", "FlushStacktrace", - "FlushStringPool", "FlushMetadata", "FlushTypeSet") + "FlushStringPool", "FlushMetadata", "FlushTypeSet", + "SafepointStatistics", "HugeObjectAllocationSample") ); public static void main(String[] args) throws Exception { diff --git a/test/jdk/jfr/event/runtime/TestSafepointEvents.java b/test/jdk/jfr/event/runtime/TestSafepointEvents.java index 8aad064c0..ad14f59c1 100644 --- a/test/jdk/jfr/event/runtime/TestSafepointEvents.java +++ b/test/jdk/jfr/event/runtime/TestSafepointEvents.java @@ -30,6 +30,7 @@ import java.nio.file.Paths; import java.time.Duration; import java.util.*; +import jdk.jfr.Period; import jdk.jfr.Recording; import jdk.jfr.consumer.RecordedEvent; @@ -63,6 +64,7 @@ public class TestSafepointEvents { public static void main(String[] args) throws Exception { Recording recording = new Recording(); + recording.enable(EventNames.SafepointStatistics).with(Period.NAME, "endChunk"); for (String name : EVENT_NAMES) { recording.enable(name).withThreshold(Duration.ofMillis(0)); } @@ -85,7 +87,15 @@ public class TestSafepointEvents { // Collect all events grouped by safepoint id SortedMap> safepointIds = new TreeMap<>(); + RecordedEvent lastStatEvent = null; for (RecordedEvent event : Events.fromRecording(recording)) { + System.out.println(event); + if (event.getEventType().getName().equals(EventNames.SafepointStatistics)) { + if (lastStatEvent == null || event.getStartTime().compareTo(lastStatEvent.getStartTime()) > 0) { + lastStatEvent = event; + } + continue; + } Integer safepointId = event.getValue("safepointId"); if (!safepointIds.containsKey(safepointId)) { safepointIds.put(safepointId, new HashSet<>()); @@ -107,6 +117,14 @@ public class TestSafepointEvents { assertTrue(safepointEvents.contains(name), "Expected event '" + name + "' to be present"); } } + + // check statistics fields + Events.assertField(lastStatEvent, "totalCount").atLeast(1L); + Events.assertField(lastStatEvent, "syncTime").atLeast(0L); + Events.assertField(lastStatEvent, "safepointTime").atLeast(0L); + Events.assertField(lastStatEvent, "applicationTime").atLeast(0L); + Events.assertField(lastStatEvent, "maxSyncTime").atLeast(0L); + Events.assertField(lastStatEvent, "maxVMOperatoinTime").atLeast(0L); } catch (Throwable e) { recording.dump(Paths.get("failed.jfr")); throw e; diff --git a/test/lib/jdk/test/lib/jfr/EventNames.java b/test/lib/jdk/test/lib/jfr/EventNames.java index 1a1a5fc3a..d3658e7cd 100644 --- a/test/lib/jdk/test/lib/jfr/EventNames.java +++ b/test/lib/jdk/test/lib/jfr/EventNames.java @@ -185,6 +185,9 @@ public class EventNames { public final static String OptoInstanceObjectAllocation = PREFIX + "OptoInstanceObjectAllocation"; public final static String OptoArrayObjectAllocation = PREFIX + "OptoArrayObjectAllocation"; + public final static String SafepointStatistics = PREFIX + "SafepointStatistics"; + public final static String HugeObjectAllocationSample = PREFIX + "HugeObjectAllocationSample"; + public static boolean isGcEvent(EventType et) { return et.getCategoryNames().contains(GC_CATEGORY); } -- GitLab