This is an automated email from the ASF dual-hosted git repository. yao pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/spark.git
The following commit(s) were added to refs/heads/master by this push: new abbe301d7645 [SPARK-48505][CORE] Simplify the implementation of `Utils#isG1GC` abbe301d7645 is described below commit abbe301d7645217f22641cf3a5c41502680e65be Author: yangjie01 <yangji...@baidu.com> AuthorDate: Tue Jun 4 15:41:41 2024 +0800 [SPARK-48505][CORE] Simplify the implementation of `Utils#isG1GC` ### What changes were proposed in this pull request? This PR changes to use the result of `ManagementFactory.getGarbageCollectorMXBeans` to determine whether G1GC is used. When G1GC is used, `ManagementFactory.getGarbageCollectorMXBeans` will return two instances of `GarbageCollectorExtImpl`, their names are `G1 Young Generation` and `G1 Old Generation` respectively. ### Why are the changes needed? Simplify the implementation. ### Does this PR introduce _any_ user-facing change? No ### How was this patch tested? Pass GitHub Actions ### Was this patch authored or co-authored using generative AI tooling? No Closes #46783 from LuciferYang/refactor-isG1GC. Lead-authored-by: yangjie01 <yangji...@baidu.com> Co-authored-by: YangJie <yangji...@baidu.com> Signed-off-by: Kent Yao <y...@apache.org> --- core/src/main/scala/org/apache/spark/util/Utils.scala | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/core/src/main/scala/org/apache/spark/util/Utils.scala b/core/src/main/scala/org/apache/spark/util/Utils.scala index 0ac1405abe6c..991fb074d246 100644 --- a/core/src/main/scala/org/apache/spark/util/Utils.scala +++ b/core/src/main/scala/org/apache/spark/util/Utils.scala @@ -19,7 +19,7 @@ package org.apache.spark.util import java.io._ import java.lang.{Byte => JByte} -import java.lang.management.{LockInfo, ManagementFactory, MonitorInfo, PlatformManagedObject, ThreadInfo} +import java.lang.management.{LockInfo, ManagementFactory, MonitorInfo, ThreadInfo} import java.lang.reflect.InvocationTargetException import java.math.{MathContext, RoundingMode} import java.net._ @@ -3058,16 +3058,8 @@ private[spark] object Utils */ lazy val isG1GC: Boolean = { Try { - val clazz = Utils.classForName("com.sun.management.HotSpotDiagnosticMXBean") - .asInstanceOf[Class[_ <: PlatformManagedObject]] - val vmOptionClazz = Utils.classForName("com.sun.management.VMOption") - val hotSpotDiagnosticMXBean = ManagementFactory.getPlatformMXBean(clazz) - 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) + ManagementFactory.getGarbageCollectorMXBeans.asScala + .exists(_.getName.contains("G1")) }.getOrElse(false) } } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@spark.apache.org For additional commands, e-mail: commits-h...@spark.apache.org