Skip to content
Closed
Show file tree
Hide file tree
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
23 changes: 1 addition & 22 deletions core/src/main/scala/org/apache/spark/memory/MemoryManager.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,8 @@

package org.apache.spark.memory

import java.lang.management.{ManagementFactory, PlatformManagedObject}
import javax.annotation.concurrent.GuardedBy

import scala.util.Try

import org.apache.spark.SparkConf
import org.apache.spark.internal.Logging
import org.apache.spark.internal.config._
Expand Down Expand Up @@ -263,7 +260,7 @@ private[spark] abstract class MemoryManager(
}
val size = ByteArrayMethods.nextPowerOf2(maxTungstenMemory / cores / safetyFactor)
val chosenPageSize = math.min(maxPageSize, math.max(minPageSize, size))
if (isG1GC && tungstenMemoryMode == MemoryMode.ON_HEAP) {
if (Utils.isG1GC && tungstenMemoryMode == MemoryMode.ON_HEAP) {
chosenPageSize - Platform.LONG_ARRAY_OFFSET
} else {
chosenPageSize
Expand All @@ -281,22 +278,4 @@ private[spark] abstract class MemoryManager(
case MemoryMode.OFF_HEAP => MemoryAllocator.UNSAFE
}
}

/**
* Return whether we are using G1GC or not
*/
private 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)
}.getOrElse(false)
}
}
20 changes: 19 additions & 1 deletion core/src/main/scala/org/apache/spark/util/Utils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package org.apache.spark.util

import java.io._
import java.lang.{Byte => JByte}
import java.lang.management.{LockInfo, ManagementFactory, MonitorInfo, ThreadInfo}
import java.lang.management.{LockInfo, ManagementFactory, MonitorInfo, PlatformManagedObject, ThreadInfo}
import java.lang.reflect.InvocationTargetException
import java.math.{MathContext, RoundingMode}
import java.net._
Expand Down Expand Up @@ -3278,6 +3278,24 @@ private[spark] object Utils extends Logging {
case _ => math.max(sortedSize(len / 2), 1)
}
}

/**
* Return whether we are using G1GC or not
*/
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)
}.getOrElse(false)
}
}

private[util] object CallerContext extends Logging {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ object DriverSubmissionTest {
println("System properties containing spark.test:")
properties.filter { case (k, _) => k.contains("spark.test") }.foreach(println)

println("JVM G1GC Flag: " + Utils.isG1GC)

for (i <- 1 until numSecondsToSleep) {
println(s"Alive for $i out of $numSecondsToSleep seconds")
Thread.sleep(1000)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,22 @@ private[spark] trait BasicTestsSuite { k8sSuite: KubernetesSuite =>
expectedJVMValue = Seq("(spark.test.foo,spark.test.bar)"))
}

test("SPARK-42474: Run extraJVMOptions JVM GC option check - G1GC", k8sTestTag) {
sparkAppConf
.set("spark.driver.extraJavaOptions", "-XX:+UseG1GC")
.set("spark.executor.extraJavaOptions", "-XX:+UseG1GC")
runSparkJVMCheckAndVerifyCompletion(
expectedJVMValue = Seq("JVM G1GC Flag: true"))
}

test("SPARK-42474: Run extraJVMOptions JVM GC option check - Other GC", k8sTestTag) {
sparkAppConf
.set("spark.driver.extraJavaOptions", "-XX:+UseParallelGC")
.set("spark.executor.extraJavaOptions", "-XX:+UseParallelGC")
runSparkJVMCheckAndVerifyCompletion(
expectedJVMValue = Seq("JVM G1GC Flag: false"))
}

test("Run SparkRemoteFileTest using a remote data file", k8sTestTag, localTestTag) {
assert(sys.props.contains("spark.test.home"), "spark.test.home is not set!")
TestUtils.withHttpServer(sys.props("spark.test.home")) { baseURL =>
Expand Down