Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions core/src/main/scala/org/apache/spark/util/Utils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3138,7 +3138,19 @@ private[spark] object Utils
/**
* Return whether we are using G1GC or not
*/
lazy val isG1GC: Boolean = {
lazy val isG1GC: Boolean = checkUseGC("UseG1GC")

/**
* Return whether we are using ZGC or not
*/
lazy val isZGC: Boolean = checkUseGC("UseZGC")

/**
* Return whether we are using ShenandoahGC or not
*/
lazy val isShenandoahGC: Boolean = checkUseGC("UseShenandoahGC")

def checkUseGC(useGCObjectStr: String): Boolean = {
Copy link
Member

Choose a reason for hiding this comment

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

Hi, @wankunde . Thank you for making a PR. Could you spin off this contribution? This sounds like a good idea to add a general utility function to detect GCs. We can proceed this one first.

As @pan3793 mentioned, if you can generalize more to detect other GCs, it would be a perfect contribution.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for your review. For this PR, I will only add a function to detect GCs for G1, ZGC and ShenandoahGC

Try {
val clazz = Utils.classForName("com.sun.management.HotSpotDiagnosticMXBean")
.asInstanceOf[Class[_ <: PlatformManagedObject]]
Expand All @@ -3147,9 +3159,9 @@ private[spark] object Utils
val vmOptionMethod = clazz.getMethod("getVMOption", classOf[String])
val valueMethod = vmOptionClazz.getMethod("getValue")

val useG1GCObject = vmOptionMethod.invoke(hotSpotDiagnosticMXBean, "UseG1GC")
val useG1GC = valueMethod.invoke(useG1GCObject).asInstanceOf[String]
"true".equals(useG1GC)
val useGCObject = vmOptionMethod.invoke(hotSpotDiagnosticMXBean, useGCObjectStr)
val useGC = valueMethod.invoke(useGCObject).asInstanceOf[String]
"true".equals(useGC)
}.getOrElse(false)
}

Expand Down