Skip to content

Commit

Permalink
8003216: Add JFR event indicating explicit System.gc() call
Browse files Browse the repository at this point in the history
Reviewed-by: jbachorik, mgronlun, tschatzl
  • Loading branch information
egahlin committed Jun 10, 2021
1 parent 2b41459 commit e11f70a
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/hotspot/share/jfr/metadata/metadata.xml
Expand Up @@ -278,6 +278,10 @@
<Field type="Tickspan" name="longestPause" label="Longest Pause" description="Longest individual pause during the garbage collection" />
</Event>

<Event name="SystemGC" category="Java Virtual Machine, GC, Collector" label="System GC" stackTrace="true" startTime="true" thread="true">
<Field type="boolean" name="invokedConcurrent" label="Invoked Concurrent" />
</Event>

<Event name="ParallelOldGarbageCollection" category="Java Virtual Machine, GC, Collector" label="Parallel Old Garbage Collection"
description="Extra information specific to Parallel Old Garbage Collections">
<Field type="uint" name="gcId" label="GC Identifier" relation="GcId" />
Expand Down
3 changes: 3 additions & 0 deletions src/hotspot/share/prims/jvm.cpp
Expand Up @@ -443,7 +443,10 @@ JVM_END

JVM_ENTRY_NO_ENV(void, JVM_GC(void))
if (!DisableExplicitGC) {
EventSystemGC event;
event.set_invokedConcurrent(ExplicitGCInvokesConcurrent);
Universe::heap()->collect(GCCause::_java_lang_system_gc);
event.commit();
}
JVM_END

Expand Down
6 changes: 6 additions & 0 deletions src/jdk.jfr/share/conf/jfr/default.jfc
Expand Up @@ -346,6 +346,12 @@
<setting name="threshold">0 ms</setting>
</event>

<event name="jdk.SystemGC">
<setting name="enabled">true</setting>
<setting name="threshold">0 ms</setting>
<setting name="stackTrace">true</setting>
</event>

<event name="jdk.ParallelOldGarbageCollection">
<setting name="enabled" control="gc-enabled-normal">true</setting>
<setting name="threshold">0 ms</setting>
Expand Down
6 changes: 6 additions & 0 deletions src/jdk.jfr/share/conf/jfr/profile.jfc
Expand Up @@ -346,6 +346,12 @@
<setting name="threshold">0 ms</setting>
</event>

<event name="jdk.SystemGC">
<setting name="enabled">true</setting>
<setting name="threshold">0 ms</setting>
<setting name="stackTrace">true</setting>
</event>

<event name="jdk.ParallelOldGarbageCollection">
<setting name="enabled" control="gc-enabled-normal">true</setting>
<setting name="threshold">0 ms</setting>
Expand Down
79 changes: 79 additions & 0 deletions test/jdk/jdk/jfr/event/gc/collection/TestSystemGc.java
@@ -0,0 +1,79 @@
/*
* Copyright (c) 2020, Oracle and/or its affiliates. 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. Oracle 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.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

package jdk.jfr.event.gc.collection;

import java.lang.management.ManagementFactory;
import java.util.List;

import jdk.jfr.Recording;
import jdk.jfr.consumer.RecordedEvent;
import jdk.test.lib.Asserts;
import jdk.test.lib.jfr.EventNames;
import jdk.test.lib.jfr.Events;

/**
* @test
* @key jfr
* @requires vm.hasJFR
* @library /test/lib /test/jdk
* @run main/othervm -XX:+ExplicitGCInvokesConcurrent jdk.jfr.event.gc.collection.TestSystemGC true
* @run main/othervm -XX:-ExplicitGCInvokesConcurrent jdk.jfr.event.gc.collection.TestSystemGC false
*/
public class TestSystemGC {
public static void main(String[] args) throws Exception {
boolean concurrent = Boolean.valueOf(args[0]);
try (Recording recording = new Recording()) {
recording.enable(EventNames.SystemGC);
recording.start();

// Trigger 3 System GC
System.gc();
ManagementFactory.getMemoryMXBean().gc();
Runtime.getRuntime().gc();

recording.stop();
List<RecordedEvent> events = Events.fromRecording(recording);
System.out.println(events);

Asserts.assertEquals(3, events.size(), "Expected 3 SystemGC events");

RecordedEvent event1 = events.get(0);
Events.assertFrame(event1, System.class, "gc");
Events.assertEventThread(event1, Thread.currentThread());
Events.assertField(event1, "invokedConcurrent").isEqual(concurrent);

RecordedEvent event2 = events.get(1);
Events.assertFrame(event2, Runtime.class, "gc");
Events.assertEventThread(event2, Thread.currentThread());
Events.assertField(event1, "invokedConcurrent").isEqual(concurrent);

RecordedEvent event3 = events.get(2);
// MemoryMXBean.class is an interface so can't assertFrame on it
Events.assertEventThread(event3, Thread.currentThread());
Events.assertField(event1, "invokedConcurrent").isEqual(concurrent);
}
}
}
1 change: 1 addition & 0 deletions test/lib/jdk/test/lib/jfr/EventNames.java
Expand Up @@ -150,6 +150,7 @@ public class EventNames {
public final static String ZUncommit = PREFIX + "ZUncommit";
public final static String ZUnmap = PREFIX + "ZUnmap";
public final static String GCLocker = PREFIX + "GCLocker";
public static final String SystemGC = PREFIX + "SystemGC";

// Compiler
public final static String Compilation = PREFIX + "Compilation";
Expand Down

1 comment on commit e11f70a

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.