Skip to content

Commit f72435a

Browse files
WanKundongjoon-hyun
authored andcommitted
[SPARK-53966][CORE] Add utility functions to detect JVM GCs
### What changes were proposed in this pull request? This PR aims to add utility functions to detect JVM GCs. ### Why are the changes needed? To provide a general capability to optimize based on the GC types. ### Does this PR introduce _any_ user-facing change? No ### How was this patch tested? Manual review. ### Was this patch authored or co-authored using generative AI tooling? No Closes #52678 from wankunde/zgc. Authored-by: WanKun <[email protected]> Signed-off-by: Dongjoon Hyun <[email protected]>
1 parent fcbafc3 commit f72435a

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

core/src/main/scala/org/apache/spark/util/Utils.scala

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3138,7 +3138,19 @@ private[spark] object Utils
31383138
/**
31393139
* Return whether we are using G1GC or not
31403140
*/
3141-
lazy val isG1GC: Boolean = {
3141+
lazy val isG1GC: Boolean = checkUseGC("UseG1GC")
3142+
3143+
/**
3144+
* Return whether we are using ZGC or not
3145+
*/
3146+
lazy val isZGC: Boolean = checkUseGC("UseZGC")
3147+
3148+
/**
3149+
* Return whether we are using ShenandoahGC or not
3150+
*/
3151+
lazy val isShenandoahGC: Boolean = checkUseGC("UseShenandoahGC")
3152+
3153+
def checkUseGC(useGCObjectStr: String): Boolean = {
31423154
Try {
31433155
val clazz = Utils.classForName("com.sun.management.HotSpotDiagnosticMXBean")
31443156
.asInstanceOf[Class[_ <: PlatformManagedObject]]
@@ -3147,9 +3159,9 @@ private[spark] object Utils
31473159
val vmOptionMethod = clazz.getMethod("getVMOption", classOf[String])
31483160
val valueMethod = vmOptionClazz.getMethod("getValue")
31493161

3150-
val useG1GCObject = vmOptionMethod.invoke(hotSpotDiagnosticMXBean, "UseG1GC")
3151-
val useG1GC = valueMethod.invoke(useG1GCObject).asInstanceOf[String]
3152-
"true".equals(useG1GC)
3162+
val useGCObject = vmOptionMethod.invoke(hotSpotDiagnosticMXBean, useGCObjectStr)
3163+
val useGC = valueMethod.invoke(useGCObject).asInstanceOf[String]
3164+
"true".equals(useGC)
31533165
}.getOrElse(false)
31543166
}
31553167

0 commit comments

Comments
 (0)