This is an automated email from the ASF dual-hosted git repository.
yangjie01 pushed a commit to branch branch-3.5
in repository https://gitbox.apache.org/repos/asf/spark.git
The following commit(s) were added to refs/heads/branch-3.5 by this push:
new b0e30ea8c3df [SPARK-53955][CORE][3.5] Prefer to detect Java Home from
env JAVA_HOME on finding jmap for JDK 8
b0e30ea8c3df is described below
commit b0e30ea8c3df69253ca8b86b81b830efc818189f
Author: Cheng Pan <[email protected]>
AuthorDate: Wed Oct 29 21:46:51 2025 +0800
[SPARK-53955][CORE][3.5] Prefer to detect Java Home from env JAVA_HOME on
finding jmap for JDK 8
### What changes were proposed in this pull request?
Prefer to detect Java Home from env `JAVA_HOME` on finding `jmap`, then
System Properties `java.home`
### Why are the changes needed?
https://stackoverflow.com/questions/45441516/difference-between-java-home-and-java-home
> `JAVA_HOME` points to the JDK installation path given by the Environment
Variable.
>
> But `java.home` points to the JRE installation path.
Somehow, it returns the same value in JDK 11+ (according to the following
article, users are still able to create a JRE by themselves?), but it returns a
different value in JDK 8 or prior
https://adoptium.net/news/2021/12/eclipse-temurin-jres-are-back
```
➜ spark-3.5.7-bin-hadoop3 bin/spark-shell
Setting default log level to "WARN".
To adjust logging level use sc.setLogLevel(newLevel). For SparkR, use
setLogLevel(newLevel).
25/10/20 17:59:07 WARN NativeCodeLoader: Unable to load native-hadoop
library for your platform... using builtin-java classes where applicable
Spark context Web UI available at http://HIH-D-25944Z:4040
Spark context available as 'sc' (master = local[*], app id =
local-1760954347801).
Spark session available as 'spark'.
Welcome to
____ __
/ __/__ ___ _____/ /__
_\ \/ _ \/ _ `/ __/ '_/
/___/ .__/\_,_/_/ /_/\_\ version 3.5.7
/_/
Using Scala version 2.12.18 (OpenJDK 64-Bit Server VM, Java 17.0.15)
Type in expressions to have them evaluated.
Type :help for more information.
scala> System.getProperty("java.home")
res0: String = /home/chengpan/.sdkman/candidates/java/17.0.15-zulu
scala> System.getenv("JAVA_HOME")
res1: String = /home/chengpan/.sdkman/candidates/java/17.0.15-zulu
```
```
➜ spark-3.5.7-bin-hadoop3 bin/spark-shell
Setting default log level to "WARN".
To adjust logging level use sc.setLogLevel(newLevel). For SparkR, use
setLogLevel(newLevel).
25/10/20 17:59:25 WARN NativeCodeLoader: Unable to load native-hadoop
library for your platform... using builtin-java classes where applicable
Spark context Web UI available at http://HIH-D-25944Z:4040
Spark context available as 'sc' (master = local[*], app id =
local-1760954366052).
Spark session available as 'spark'.
Welcome to
____ __
/ __/__ ___ _____/ /__
_\ \/ _ \/ _ `/ __/ '_/
/___/ .__/\_,_/_/ /_/\_\ version 3.5.7
/_/
Using Scala version 2.12.18 (OpenJDK 64-Bit Server VM, Java 1.8.0_432)
Type in expressions to have them evaluated.
Type :help for more information.
scala> System.getProperty("java.home")
res0: String = /home/chengpan/.sdkman/candidates/java/8.0.432.fx-zulu/jre
scala> System.getenv("JAVA_HOME")
res1: String = /home/chengpan/.sdkman/candidates/java/8.0.432.fx-zulu
```
In JDK8, `jmap` exists under `JAVA_HOME/bin`, but not under
`JAVA_HOME/jre/bin`.
### Does this PR introduce _any_ user-facing change?
No.
### How was this patch tested?
Manually verified.
### Was this patch authored or co-authored using generative AI tooling?
No.
Closes #52665 from pan3793/SPARK-53955.
Authored-by: Cheng Pan <[email protected]>
Signed-off-by: yangjie01 <[email protected]>
---
core/src/main/scala/org/apache/spark/util/Utils.scala | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
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 4e498e57d920..653e869088f0 100644
--- a/core/src/main/scala/org/apache/spark/util/Utils.scala
+++ b/core/src/main/scala/org/apache/spark/util/Utils.scala
@@ -2142,7 +2142,8 @@ private[spark] object Utils
def getHeapHistogram(): Array[String] = {
// From Java 9+, we can use 'ProcessHandle.current().pid()'
val pid = getProcessName().split("@").head
- val jmap = System.getProperty("java.home") + "/bin/jmap"
+ val jmap = Option(System.getenv("JAVA_HOME"))
+ .getOrElse(System.getProperty("java.home")) + "/bin/jmap"
val builder = new ProcessBuilder(jmap, "-histo:live", pid)
val p = builder.start()
val rows = ArrayBuffer.empty[String]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]