Skip to content

Commit ad110da

Browse files
authored
Merge pull request scala#7384 from lrytz/asm7
Upgrade to ASM 7
2 parents 257c1f0 + da0fc87 commit ad110da

File tree

7 files changed

+27
-66
lines changed

7 files changed

+27
-66
lines changed

src/compiler/scala/tools/nsc/backend/jvm/PostProcessor.scala

+1-5
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,11 @@ abstract class PostProcessor extends PerRunInit {
7272
setInnerClasses(classNode)
7373
serializeClass(classNode)
7474
} catch {
75-
case e: java.lang.RuntimeException if e.getMessage != null && (e.getMessage contains "too large!") =>
76-
backendReporting.error(NoPosition,
77-
s"Could not write class ${internalName} because it exceeds JVM code size limits. ${e.getMessage}")
78-
null
7975
case ex: InterruptedException => throw ex
8076
case ex: Throwable =>
8177
// TODO fail fast rather than continuing to write the rest of the class files?
8278
if (frontendAccess.compilerSettings.debug) ex.printStackTrace()
83-
backendReporting.error(NoPosition, s"Error while emitting ${internalName}\n${ex.getMessage}")
79+
backendReporting.error(NoPosition, s"Error while emitting $internalName\n${ex.getMessage}")
8480
null
8581
}
8682

src/compiler/scala/tools/nsc/backend/jvm/analysis/NullnessAnalyzer.scala

+17-54
Original file line numberDiff line numberDiff line change
@@ -149,54 +149,33 @@ final class NullnessInterpreter(knownNonNullInvocation: MethodInsnNode => Boolea
149149
}
150150

151151
class NullnessFrame(nLocals: Int, nStack: Int) extends AliasingFrame[NullnessValue](nLocals, nStack) {
152-
/**
153-
* Hack to support branch-dependent values after a null check (if (x == null) ... else ...).
154-
* Short pseudo-code of the analyzer:
155-
*
156-
* analyze()
157-
* while (numInstructionsToProcess > 0) {
158-
* currentFrame = oldFrame.clone().execute(insnNode, interpreter)
159-
* if (insnNode instanceof JumpInsnNode) {
160-
* merge(insnIndex + 1, currentFrame, subroutine)
161-
* merge(jumpInsnIndex, currentFrame, subroutine)
162-
*
163-
* merge(int insnIndex, Frame frame)
164-
* oldFrame = frames[insnIndex]
165-
* if (oldFrame == null) frames[insnIndex] = newFrame(frame)
166-
* else oldFrame.merge(frame, interpreter)
167-
*
168-
* The `currentFrame` is a temporary frame with the status after executing the instruction.
169-
* It is then either passed to `frame.merge` or to `new Frame` as parameter.
170-
*
171-
* Both of these methods are overwritten in NullnessFrame to invoke `postBranch()`. On the first
172-
* invocation it sets the state of `currentFrame` for the first branch, then for the second branch.
173-
* So `currentFrame` can have a different state for each branch.
174-
*/
175-
private var postBranch: () => Unit = null
176-
177-
override def init(src: Frame[_ <: NullnessValue]): Frame[NullnessValue] = {
178-
postBranch = null
179-
super.init(src)
180-
}
152+
private[this] var ifNullAliases: AliasSet = null
181153

182154
// Auxiliary constructor required for implementing `NullnessAnalyzer.newFrame`
183155
def this(src: Frame[_ <: NullnessValue]) {
184156
this(src.getLocals, src.getMaxStackSize)
185-
val s = src.asInstanceOf[NullnessFrame]
186-
if (s.postBranch != null) s.postBranch()
187157
init(src)
188158
}
189159

190-
override def merge(other: Frame[_ <: NullnessValue], interpreter: Interpreter[NullnessValue]): Boolean = {
191-
val o = other.asInstanceOf[NullnessFrame]
192-
if (o.postBranch != null) o.postBranch()
193-
super.merge(other, interpreter)
160+
private def setNullness(s: AliasSet, v: NullnessValue) = {
161+
val it = s.iterator
162+
while (it.hasNext)
163+
this.setValue(it.next(), v)
164+
}
165+
166+
override def initJumpTarget(opcode: Int, target: LabelNode): Unit = {
167+
// when `target` is defined, we're in the case where the branch condition is true
168+
val conditionTrue = target != null
169+
if (opcode == Opcodes.IFNULL)
170+
setNullness(ifNullAliases, if (conditionTrue) NullValue else NotNullValue)
171+
else if (opcode == Opcodes.IFNONNULL)
172+
setNullness(ifNullAliases, if (conditionTrue) NotNullValue else NullValue)
194173
}
195174

196175
override def execute(insn: AbstractInsnNode, interpreter: Interpreter[NullnessValue]): Unit = {
197176
import Opcodes._
198177

199-
val ifNullAliases: AliasSet = insn.getOpcode match {
178+
ifNullAliases = insn.getOpcode match {
200179
case IFNULL | IFNONNULL => aliasesOf(this.stackTop)
201180
case _ => null
202181
}
@@ -264,24 +243,8 @@ class NullnessFrame(nLocals: Int, nStack: Int) extends AliasingFrame[NullnessVal
264243

265244
super.execute(insn, interpreter)
266245

267-
def setNullness(s: AliasSet, v: NullnessValue) = {
268-
val it = s.iterator
269-
while (it.hasNext)
270-
this.setValue(it.next(), v)
271-
}
272-
273-
if (ifNullAliases != null) {
274-
val v = if (insn.getOpcode == IFNULL) NotNullValue else NullValue
275-
postBranch = () => {
276-
setNullness(ifNullAliases, v)
277-
postBranch = () => {
278-
setNullness(ifNullAliases, v.invert)
279-
postBranch = null
280-
}
281-
}
282-
}
283-
284-
if (nullCheckedAliases != null) setNullness(nullCheckedAliases, NotNullValue)
246+
if (nullCheckedAliases != null)
247+
setNullness(nullCheckedAliases, NotNullValue)
285248
}
286249
}
287250

src/compiler/scala/tools/nsc/backend/jvm/analysis/ProdConsAnalyzer.scala

+3-3
Original file line numberDiff line numberDiff line change
@@ -459,16 +459,16 @@ case class ParameterProducer(local: Int)
459459
case class UninitializedLocalProducer(local: Int) extends InitialProducer
460460
case class ExceptionProducer[V <: Value](handlerLabel: LabelNode, handlerStackTop: Int) extends InitialProducer
461461

462-
class InitialProducerSourceInterpreter extends SourceInterpreter(scala.tools.asm.Opcodes.ASM7_EXPERIMENTAL) {
462+
class InitialProducerSourceInterpreter extends SourceInterpreter(scala.tools.asm.Opcodes.ASM7) {
463463
override def newParameterValue(isInstanceMethod: Boolean, local: Int, tp: Type): SourceValue = {
464464
new SourceValue(tp.getSize, ParameterProducer(local))
465465
}
466466

467-
override def newEmptyNonParameterLocalValue(local: Int): SourceValue = {
467+
override def newEmptyValue(local: Int): SourceValue = {
468468
new SourceValue(1, UninitializedLocalProducer(local))
469469
}
470470

471-
override def newExceptionValue(tryCatchBlockNode: TryCatchBlockNode, handlerFrame: Frame[_ <: Value], exceptionType: Type): SourceValue = {
471+
override def newExceptionValue(tryCatchBlockNode: TryCatchBlockNode, handlerFrame: Frame[SourceValue], exceptionType: Type): SourceValue = {
472472
val handlerStackTop = handlerFrame.stackTop + 1 // +1 because this value is about to be pushed onto `handlerFrame`.
473473
new SourceValue(1, ExceptionProducer(tryCatchBlockNode.handler, handlerStackTop))
474474
}

src/compiler/scala/tools/nsc/backend/jvm/analysis/TypeFlowAnalyzer.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import scala.tools.nsc.backend.jvm.analysis.TypeFlowInterpreter._
2222
import scala.tools.nsc.backend.jvm.analysis.BackendUtils.LambdaMetaFactoryCall
2323
import scala.tools.nsc.backend.jvm.opt.BytecodeUtils._
2424

25-
abstract class TypeFlowInterpreter extends BasicInterpreter(scala.tools.asm.Opcodes.ASM7_EXPERIMENTAL) {
25+
abstract class TypeFlowInterpreter extends BasicInterpreter(scala.tools.asm.Opcodes.ASM7) {
2626
override def newParameterValue(isInstanceMethod: Boolean, local: Int, tpe: Type): BasicValue =
2727
new ParamValue(local, tpe)
2828

test/files/run/large_class.check

+2-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
error: Could not write class BigEnoughToFail because it exceeds JVM code size limits. Class file too large!
1+
error: Error while emitting BigEnoughToFail
2+
Class too large: BigEnoughToFail

test/files/run/large_code.check

+2-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
error: Could not write class BigEnoughToFail because it exceeds JVM code size limits. Method tooLong's code too large!
1+
error: Error while emitting BigEnoughToFail
2+
Method too large: BigEnoughToFail.tooLong ()V

versions.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ starr.version=2.13.0-M5-6e0cba7
77
# Other usages:
88
# - scala-asm: jar content included in scala-compiler
99
# - jline: shaded with JarJar and included in scala-compiler
10-
scala-asm.version=6.2.0-scala-2
10+
scala-asm.version=7.0.0-scala-1
1111
jline.version=2.14.6

0 commit comments

Comments
 (0)