-
Notifications
You must be signed in to change notification settings - Fork 29.3k
[SPARK-6152] Use shaded ASM5 to support closure cleaning of Java 8 compiled classes #9512
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
Closed
Closed
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e5e27ce
Use shaded ASM5 for closure cleaning.
JoshRosen c3e7f4a
Do not call deprecated method
JoshRosen 59d649b
Add ability to configure JDK versions in test code compliation.
JoshRosen 38191a1
Add regression test.
JoshRosen fd96788
Use separate settings for scalac and javac JVM versions.
JoshRosen 002d1ea
Add instructions on running Java 8 tests in Scala.
JoshRosen 01f5cca
Merge remote-tracking branch 'origin/master' into SPARK-6152
JoshRosen 9833667
Remove unnecessary Option usage.
JoshRosen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
extras/java8-tests/src/test/scala/org/apache/spark/JDK8ScalaSuite.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.spark | ||
|
|
||
| /** | ||
| * Test cases where JDK8-compiled Scala user code is used with Spark. | ||
| */ | ||
| class JDK8ScalaSuite extends SparkFunSuite with SharedSparkContext { | ||
| test("basic RDD closure test (SPARK-6152)") { | ||
| sc.parallelize(1 to 1000).map(x => x * x).count() | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,8 +21,8 @@ import java.io.{ByteArrayInputStream, ByteArrayOutputStream} | |
|
|
||
| import scala.collection.mutable | ||
|
|
||
| import com.esotericsoftware.reflectasm.shaded.org.objectweb.asm._ | ||
| import com.esotericsoftware.reflectasm.shaded.org.objectweb.asm.Opcodes._ | ||
| import org.apache.xbean.asm5._ | ||
| import org.apache.xbean.asm5.Opcodes._ | ||
|
|
||
| import org.apache.spark.SparkFunSuite | ||
| import org.apache.spark.sql._ | ||
|
|
@@ -516,7 +516,7 @@ private class BoxingFinder( | |
| method: MethodIdentifier[_] = null, | ||
| val boxingInvokes: mutable.Set[String] = mutable.Set.empty, | ||
| visitedMethods: mutable.Set[MethodIdentifier[_]] = mutable.Set.empty) | ||
| extends ClassVisitor(ASM4) { | ||
| extends ClassVisitor(ASM5) { | ||
|
|
||
| private val primitiveBoxingClassName = | ||
| Set("java/lang/Long", | ||
|
|
@@ -533,11 +533,12 @@ private class BoxingFinder( | |
| MethodVisitor = { | ||
| if (method != null && (method.name != name || method.desc != desc)) { | ||
| // If method is specified, skip other methods. | ||
| return new MethodVisitor(ASM4) {} | ||
| return new MethodVisitor(ASM5) {} | ||
| } | ||
|
|
||
| new MethodVisitor(ASM4) { | ||
| override def visitMethodInsn(op: Int, owner: String, name: String, desc: String) { | ||
| new MethodVisitor(ASM5) { | ||
| override def visitMethodInsn( | ||
| op: Int, owner: String, name: String, desc: String, itf: Boolean) { | ||
| if (op == INVOKESPECIAL && name == "<init>" || op == INVOKESTATIC && name == "valueOf") { | ||
| if (primitiveBoxingClassName.contains(owner)) { | ||
| // Find boxing methods, e.g, new java.lang.Long(l) or java.lang.Long.valueOf(l) | ||
|
|
@@ -572,15 +573,7 @@ private object BoxingFinder { | |
| // Copy data over, before delegating to ClassReader - | ||
| // else we can run out of open file handles. | ||
| Utils.copyStream(resourceStream, baos, true) | ||
| // ASM4 doesn't support Java 8 classes, which requires ASM5. | ||
| // So if the class is ASM5 (E.g., java.lang.Long when using JDK8 runtime to run these codes), | ||
| // then ClassReader will throw IllegalArgumentException, | ||
| // However, since this is only for testing, it's safe to skip these classes. | ||
| try { | ||
| Some(new ClassReader(new ByteArrayInputStream(baos.toByteArray))) | ||
| } catch { | ||
| case _: IllegalArgumentException => None | ||
| } | ||
| Some(new ClassReader(new ByteArrayInputStream(baos.toByteArray))) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just realized that this no longer needs to return an |
||
| } | ||
|
|
||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Subtlety: this setting will break the
java8tests when running on Scala 2.10.x, which does not support the emission of Java 8 bytecode. For this reason, we need separate settings for configuring the scalc and javac target JVM versions and need to only set scalac to 1.8 when running Scala 2.11.4 or higher.