-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-40729][CORE] Make Spark use UnsafeFieldAccessor as default for Java 18+
#38190
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
-Djdk.reflect.useDirectMethodHandle=false to spark-shell and maven/sbt test options-Djdk.reflect.useDirectMethodHandle=false to make Java18/19 use UnsafeFieldAccessor instead of MethodHandleAccessor
-Djdk.reflect.useDirectMethodHandle=false to make Java18/19 use UnsafeFieldAccessor instead of MethodHandleAccessor -Djdk.reflect.useDirectMethodHandle=false to make Java18/19 use UnsafeFieldAccessor instead of MethodHandleAccessor
|
spark/core/src/main/scala/org/apache/spark/util/ClosureCleaner.scala Lines 397 to 408 in 8e85393
Any suggestions for code level fix? |
-Djdk.reflect.useDirectMethodHandle=false to make Java18/19 use UnsafeFieldAccessor instead of MethodHandleAccessor -Djdk.reflect.useDirectMethodHandle=false to make Java18/19 use UnsafeFieldAccessor instead of MethodHandleAccessor when use Spark-Shell
-Djdk.reflect.useDirectMethodHandle=false to make Java18/19 use UnsafeFieldAccessor instead of MethodHandleAccessor when use Spark-Shell-Djdk.reflect.useDirectMethodHandle=false to make Java18/19 use UnsafeFieldAccessor in Spark-Shell
|
cc @rednaxelafx |
pom.xml
Outdated
| <filereports>SparkTestSuite.txt</filereports> | ||
| <argLine>-ea -Xmx4g -Xss4m -XX:MaxMetaspaceSize=2g -XX:ReservedCodeCacheSize=${CodeCacheSize} ${extraJavaTestArgs} -Dio.netty.tryReflectionSetAccessible=true</argLine> | ||
| <argLine>-ea -Xmx4g -Xss4m -XX:MaxMetaspaceSize=2g -XX:ReservedCodeCacheSize=${CodeCacheSize} ${extraJavaTestArgs} -Dio.netty.tryReflectionSetAccessible=true | ||
| -Djdk.reflect.useDirectMethodHandle=false</argLine> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about the vanilla Scala REPL? Is this only Apache Spark REPL issue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue seem to be that the ClosureCleaner is trying to set a final field which shouldn't be allowed. This is Spark-specific (and affects all other projects that copied Spark's ClosureCleaner), and doesn't exist in the vanilla Scala REPL.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, only Apache Spark REPL issue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it. Thank you, @rednaxelafx and @LuciferYang .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is required, why don't we put this into JavaModuleOptions like the other Java options?
Yes, this is a feasible way, let me try it. |
-Djdk.reflect.useDirectMethodHandle=false to make Java18/19 use UnsafeFieldAccessor in Spark-ShellUnsafeFieldAccessor as default with Java18/19
| "--add-opens=java.base/sun.util.calendar=ALL-UNNAMED", | ||
| "--add-opens=java.security.jgss/sun.security.krb5=ALL-UNNAMED"}; | ||
| "--add-opens=java.security.jgss/sun.security.krb5=ALL-UNNAMED", | ||
| "-Djdk.reflect.useDirectMethodHandle=false"}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is better to rename JavaModuleOptions as JavaExtraOptions. Do you suggest completing the corresponding refactor work in this pr? @dongjoon-hyun
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My idea is that this pr solves the issue first if need, and then do the rename work by a separate pr
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ya, I agree with you. Let's postpone the renaming.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @dongjoon-hyun
UnsafeFieldAccessor as default with Java18/19UnsafeFieldAccessor as default with Java18/19
dongjoon-hyun
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1, LGTM. Thank you, @LuciferYang and @rednaxelafx .
Merged to master for Apache Spark 3.4.0.
UnsafeFieldAccessor as default with Java18/19UnsafeFieldAccessor as default for Java 18+
|
thanks @dongjoon-hyun @rednaxelafx |
What changes were proposed in this pull request?
This pr add
-Djdk.reflect.useDirectMethodHandle=falsetoJavaModuleOptionsandmaven/sbtextraJavaTestArgsto make Spark useUnsafeFieldAccessoras default with Java 18/19 to avoid the bad case described in SPARK-40729 .Why are the changes needed?
After JEP 416: Reimplement Core Reflection with Method Handles,
MethodHandleAccessor 'is the default reflection implementation of Java, but in Spark it will cause the bad case mentioned in SPARK-40729, so add-Djdk.reflect.useDirectMethodHandle=false` as a workaround for Java 18/19.Does this PR introduce any user-facing change?
No, The new option will not affect Java versions below 18
How was this patch tested?
replmodule test with Java 18/19Before
After
Before
After