diff --git a/src/share/classes/jdk/jfr/conf/default.jfc b/src/share/classes/jdk/jfr/conf/default.jfc
index 871949601d413a7de28251b6505ce8e3ff084a03..c35e71ec00da65b5399dc5e9f6b07644091496cc 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 03e7e4b1e92a1c1755b7b8bd3c43e783765191bc..814c09ef8ee14464a296baf865078e2ca96fdcc2 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 0000000000000000000000000000000000000000..b2e16bb316984c5880b66f90575360b4b15f0367
--- /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 96dbda7f0da97404a9fbd5a465949a1b752d04a7..e5b973e7c5e1aea96bb1715483e220c1c3f21813 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 8aad064c03249852895bc59dccfb4ba90167920b..ad14f59c1d96305cbb3a1b43a96be9b10d421cf4 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 1a1a5fc3aa71ccb6f7a2bbae153853137c5595cc..d3658e7cda82908d28ff6290985723d0d6f33b7a 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);
}