8378806: Genshen: Add scope of collection to end of cycle message in JMX notification

Reviewed-by: kdnilsen, xpeng
This commit is contained in:
William Kemper 2026-03-20 16:20:40 +00:00
parent 396cc0ab6a
commit b32e9b0f9b
4 changed files with 104 additions and 2 deletions

View File

@ -40,6 +40,22 @@
ShenandoahPhaseTimings::Phase ShenandoahTimingsTracker::_current_phase = ShenandoahPhaseTimings::_invalid_phase;
const char* ShenandoahGCSession::cycle_end_message(ShenandoahGenerationType type) {
switch (type) {
case NON_GEN:
return "end of GC cycle";
case GLOBAL:
return "end of Global GC cycle";
case YOUNG:
return "end of Young GC cycle";
case OLD:
return "end of Old GC cycle";
default:
ShouldNotReachHere();
return "end of GC cycle";
}
}
ShenandoahGCSession::ShenandoahGCSession(GCCause::Cause cause, ShenandoahGeneration* generation) :
_heap(ShenandoahHeap::heap()),
_generation(generation),
@ -54,7 +70,7 @@ ShenandoahGCSession::ShenandoahGCSession(GCCause::Cause cause, ShenandoahGenerat
_heap->trace_heap_before_gc(_tracer);
_trace_cycle.initialize(_heap->cycle_memory_manager(), cause,
"end of GC cycle",
cycle_end_message(_generation->type()),
/* allMemoryPoolsAffected */ true,
/* recordGCBeginTime = */ true,
/* recordPreGCUsage = */ true,

View File

@ -67,6 +67,8 @@ private:
GCTracer* const _tracer;
TraceMemoryManagerStats _trace_cycle;
static const char* cycle_end_message(ShenandoahGenerationType type);
public:
ShenandoahGCSession(GCCause::Cause cause, ShenandoahGeneration* generation);
~ShenandoahGCSession();

View File

@ -0,0 +1,83 @@
/*
* Copyright Amazon.com Inc. 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.
*
* 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.
*
*/
/*
* @test
* @summary Check that GC cycle end message contains generation name
* @library /test/lib /
* @requires vm.gc.Shenandoah
*
* @run main/othervm -Xmx128m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
* -XX:+UseShenandoahGC -XX:ShenandoahGCMode=generational
* TestCycleEndMessage
*/
import java.lang.management.GarbageCollectorMXBean;
import java.lang.management.ManagementFactory;
import java.util.concurrent.atomic.AtomicBoolean;
import javax.management.Notification;
import javax.management.NotificationEmitter;
import javax.management.NotificationListener;
import javax.management.openmbean.CompositeData;
import com.sun.management.GarbageCollectionNotificationInfo;
public class TestCycleEndMessage {
public static void main(String[] args) throws Exception {
final AtomicBoolean foundGenerationInCycle = new AtomicBoolean(false);
NotificationListener listener = new NotificationListener() {
@Override
public void handleNotification(Notification n, Object o) {
if (n.getType().equals(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION)) {
GarbageCollectionNotificationInfo info = GarbageCollectionNotificationInfo.from((CompositeData) n.getUserData());
String name = info.getGcName();
String action = info.getGcAction();
System.out.println("Received: " + name + " / " + action);
if (name.equals("Shenandoah Cycles") &&
(action.contains("Global") || action.contains("Young") || action.contains("Old"))) {
foundGenerationInCycle.set(true);
}
}
}
};
for (GarbageCollectorMXBean bean : ManagementFactory.getGarbageCollectorMXBeans()) {
((NotificationEmitter) bean).addNotificationListener(listener, null, null);
}
System.gc();
Thread.sleep(2000);
if (!foundGenerationInCycle.get()) {
throw new IllegalStateException("Expected to find generation name (Global/Young/Old) in Shenandoah Cycles action message");
}
System.out.println("Test passed: Found generation name in cycle end message");
}
}

View File

@ -129,7 +129,8 @@ class TestStringDeduplicationTools {
GarbageCollectionNotificationInfo info = GarbageCollectionNotificationInfo.from((CompositeData) n.getUserData());
// Shenandoah and Z GC also report GC pauses, skip them
if (info.getGcName().startsWith("Shenandoah")) {
if ("end of GC cycle".equals(info.getGcAction())) {
String action = info.getGcAction();
if (action != null && action.contains("GC cycle")) {
gcCount++;
}
} else if (info.getGcName().startsWith("ZGC")) {