LuciferYang commented on code in PR #46873:
URL: https://github.com/apache/spark/pull/46873#discussion_r1626886340


##########
core/src/main/scala/org/apache/spark/util/Utils.scala:
##########
@@ -3058,8 +3059,13 @@ private[spark] object Utils
    */
   lazy val isG1GC: Boolean = {
     Try {
-      ManagementFactory.getGarbageCollectorMXBeans.asScala
-        .exists(_.getName.contains("G1"))
+      // SPARK-48505: If the initialization probe of `HotSpotDiagnosticMXBean` 
is successful,
+      // the reflection API can be avoided in subsequent operations.
+      val clazz = 
Utils.classForName("com.sun.management.HotSpotDiagnosticMXBean")
+      val hotSpotDiagnosticMXBean = ManagementFactory.getPlatformMXBean(clazz)
+        .asInstanceOf[HotSpotDiagnosticMXBean]
+      val useG1GC = hotSpotDiagnosticMXBean.getVMOption("UseG1GC").getValue
+      "true".equals(useG1GC)

Review Comment:
   Have I understood your suggestion correctly? 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to