forked from oracle/graal
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a8efbf7
commit 1b5236a
Showing
21 changed files
with
1,005 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
133 changes: 133 additions & 0 deletions
133
....core.genscavenge/src/com/oracle/svm/core/genscavenge/AbstractGarbageCollectorMXBean.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
/* | ||
* Copyright (c) 2024, 2024, Oracle and/or its affiliates. All rights reserved. | ||
* Copyright (c) 2024, 2024, Red Hat Inc. 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 com.oracle.svm.core.genscavenge; | ||
|
||
import com.oracle.svm.core.util.BasedOnJDKFile; | ||
|
||
import com.oracle.svm.core.SubstrateUtil; | ||
import com.oracle.svm.core.genscavenge.service.GcNotificationRequest; | ||
import com.oracle.svm.core.genscavenge.service.PoolMemoryUsage; | ||
import com.oracle.svm.core.genscavenge.service.Target_com_sun_management_GcInfo; | ||
import com.oracle.svm.core.genscavenge.service.Target_java_lang_management_internal_GcInfoBuilder; | ||
|
||
import com.sun.management.GarbageCollectionNotificationInfo; | ||
import com.sun.management.GcInfo; | ||
import com.sun.management.internal.GarbageCollectionNotifInfoCompositeData; | ||
import com.sun.management.internal.GcInfoBuilder; | ||
import sun.management.NotificationEmitterSupport; | ||
|
||
import javax.management.MBeanNotificationInfo; | ||
import javax.management.Notification; | ||
import javax.management.NotificationEmitter; | ||
import javax.management.openmbean.CompositeData; | ||
import java.lang.management.MemoryUsage; | ||
|
||
public abstract class AbstractGarbageCollectorMXBean extends NotificationEmitterSupport | ||
implements com.sun.management.GarbageCollectorMXBean, NotificationEmitter { | ||
@BasedOnJDKFile("https://github.com/openjdk/jdk/blob/jdk-24+14/src/hotspot/share/gc/serial/serialHeap.cpp#L451") // | ||
|
||
private static final String ACTION_MINOR = "end of minor GC"; | ||
@BasedOnJDKFile("https://github.com/openjdk/jdk/blob/jdk-24+14/src/hotspot/share/gc/serial/serialHeap.cpp#L718") // | ||
private static final String ACTION_MAJOR = "end of major GC"; | ||
private GcInfoBuilder gcInfoBuilder; | ||
private volatile GcInfo gcInfo; | ||
private long seqNumber = 0; | ||
|
||
private synchronized GcInfoBuilder getGcInfoBuilder() { | ||
if (gcInfoBuilder == null) { | ||
Target_java_lang_management_internal_GcInfoBuilder gib = new Target_java_lang_management_internal_GcInfoBuilder(this, getMemoryPoolNames()); | ||
gcInfoBuilder = SubstrateUtil.cast(gib, GcInfoBuilder.class); | ||
} | ||
return gcInfoBuilder; | ||
} | ||
|
||
/** | ||
* Use the data taken from the request queue to populate MemoryUsage. The service thread calls | ||
* this method. | ||
*/ | ||
public void createNotification(GcNotificationRequest request) { | ||
AbstractMemoryPoolMXBean[] beans = GenScavengeMemoryPoolMXBeans.singleton().getMXBeans(); | ||
|
||
String[] poolNames = getMemoryPoolNames(); | ||
MemoryUsage[] before = new MemoryUsage[poolNames.length]; | ||
MemoryUsage[] after = new MemoryUsage[poolNames.length]; | ||
|
||
// Pools must be in the order of getMemoryPoolNames() to match GcInfoBuilder | ||
for (int i = 0; i < poolNames.length; i++) { | ||
for (int j = 0; j < beans.length; j++) { | ||
PoolMemoryUsage pmu = request.getPoolBefore(j); | ||
if (pmu.name != null && pmu.name.equals(poolNames[i])) { | ||
before[i] = beans[j].memoryUsage(pmu.used, pmu.committed); | ||
pmu = request.getPoolAfter(j); | ||
after[i] = beans[j].memoryUsage(pmu.used, pmu.committed); | ||
} | ||
} | ||
} | ||
|
||
// Number of GC threads. | ||
Object[] extAttribute = new Object[]{Integer.valueOf(1)}; | ||
|
||
Target_com_sun_management_GcInfo targetGcInfo = new Target_com_sun_management_GcInfo(getGcInfoBuilder(), request.epoch, request.startTime, request.endTime, before, after, extAttribute); | ||
gcInfo = SubstrateUtil.cast(targetGcInfo, GcInfo.class); | ||
|
||
GarbageCollectionNotificationInfo info = new GarbageCollectionNotificationInfo( | ||
getName(), | ||
request.isIncremental ? ACTION_MINOR : ACTION_MAJOR, | ||
request.cause.getName(), | ||
gcInfo); | ||
|
||
CompositeData cd = GarbageCollectionNotifInfoCompositeData.toCompositeData(info); | ||
|
||
Notification notif = new Notification(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION, | ||
getObjectName(), | ||
getNextSeqNumber(), | ||
request.timestamp, | ||
getName()); | ||
notif.setUserData(cd); | ||
|
||
sendNotification(notif); | ||
} | ||
|
||
private long getNextSeqNumber() { | ||
return ++seqNumber; | ||
} | ||
|
||
@Override | ||
public MBeanNotificationInfo[] getNotificationInfo() { | ||
return new MBeanNotificationInfo[]{ | ||
new MBeanNotificationInfo( | ||
new String[]{GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION}, | ||
"javax.management.Notification", | ||
"GC Notification") | ||
}; | ||
} | ||
|
||
/** OpenJDK calls to native code to obtain this. */ | ||
@Override | ||
public GcInfo getLastGcInfo() { | ||
return gcInfo; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.