8000 Merge pull request #6733 from retronym/bump/asm-6.2 · scala/scala@78c0fc9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 78c0fc9

Browse files
authored
Merge pull request #6733 from retronym/bump/asm-6.2
Upgrade to scala-asm 6.2
2 parents 53710db + dc27de7 commit 78c0fc9

File tree

18 files changed

+187
-45
lines changed

18 files changed

+187
-45
lines changed

src/compiler/scala/tools/asm/LabelAccess.java

Lines changed: 0 additions & 18 deletions
This file was deleted.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ object AsmUtils {
6666
}
6767

6868
def classFromBytes(bytes: Array[Byte]): ClassNode = {
69-
val node = new ClassNode()
69+
val node = new ClassNode1()
7070
new ClassReader(bytes).accept(node, ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES)
7171

7272
node

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ package backend.jvm
99

1010
import scala.tools.asm
1111
import BackendReporting._
12+
import scala.reflect.internal.Flags
13+
import scala.tools.asm.{ByteVector, ClassWriter}
1214
import scala.tools.nsc.backend.jvm.BCodeHelpers.ScalaSigBytes
1315
import scala.tools.nsc.reporters.NoReporter
1416

@@ -354,9 +356,14 @@ abstract class BCodeHelpers extends BCodeIdiomatic {
354356
* can-multi-thread
355357
*/
356358
def createJAttribute(name: String, b: Array[Byte], offset: Int, len: Int): asm.Attribute = {
357-
val dest = new Array[Byte](len)
358-
System.arraycopy(b, offset, dest, 0, len)
359-
new asm.CustomAttr(name, dest)
359+
new asm.Attribute(name) {
360+
override def write(classWriter: ClassWriter, code: Array[Byte],
361+
codeLength: Int, maxStack: Int, maxLocals: Int): asm.ByteVector = {
362+
val byteVector = new asm.ByteVector(len)
363+
byteVector.putByteArray(b, offset, len)
364+
byteVector
365+
}
366+ F438
}
360367
}
361368

362369
/*
@@ -871,7 +878,7 @@ abstract class BCodeHelpers extends BCodeIdiomatic {
871878
assert(moduleClass.companionClass == NoSymbol, moduleClass)
872879

873880
val bType = mirrorClassClassBType(moduleClass)
874-
val mirrorClass = new asm.tree.ClassNode
881+
val mirrorClass = new ClassNode1
875882
mirrorClass.visit(
876883
backendUtils.classfileVersion.get,
877884
bType.info.get.flags,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ abstract class BCodeSkelBuilder extends BCodeHelpers {
105105
thisBType = classBTypeFromSymbol(claszSymbol)
106106
initModuleInClinit = isCZStaticModule && canAssignModuleInClinit(cd, claszSymbol)
107107

108-
cnode = new asm.tree.ClassNode()
108+
cnode = new ClassNode1()
109109

110110
initJClass(cnode)
111111

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,8 @@ abstract class BTypes {
765765
// finds the first common one.
766766
// MOST LIKELY the answer can be found here, see the comments and links by Miguel:
767767
// - https://github.com/scala/bug/issues/3872
768+
// @jz Wouldn't it be better to walk the superclass chain of both types in reverse (starting from Object), and
769+
// finding the last common link? That would be O(N), whereas this looks O(N^2)
768770
firstCommonSuffix(this :: this.superClassesTransitive.orThrow, other :: other.superClassesTransitive.orThrow)
769771
}
770772

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/* NSC -- new Scala compiler
2+
* Copyright 2018 LAMP/EPFL
3+
* @author Martin Odersky
4+
*/
5+
package scala.tools.nsc.backend.jvm;
6+
7+
import scala.tools.asm.MethodVisitor;
8+
import scala.tools.asm.Opcodes;
9+
import scala.tools.asm.tree.ClassNode;
10+
import scala.tools.asm.tree.MethodNode;
11+
12+
/**
13+
* A subclass of {@link ClassNode} to customize the representation of
14+
* label nodes with {@link LabelNode1}.
15+
*/
16+
public class ClassNode1 extends ClassNode {
17+
public ClassNode1() {
18+
this(Opcodes.ASM6);
19+
}
20+
21+
public ClassNode1(int api) {
22+
super(api);
23+
}
24+
25+
@Override
26+
public MethodVisitor visitMethod(int access, String name, String descriptor, String signature, String[] exceptions) {
27+
MethodNode method = new MethodNode1(access, name, descriptor, signature, exceptions);
28+
methods.add(method);
29+
return method;
30+
}
31+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/* NSC -- new Scala compiler
2+
* Copyright 2018 LAMP/EPFL
3+
* @author Martin Odersky
4+
*/
5+
package scala.tools.nsc.backend.jvm;
6+
7+
import scala.tools.asm.Label;
8+
import scala.tools.asm. F987 tree.ClassNode;
9+
import scala.tools.asm.tree.LabelNode;
10+
11+
/**
12+
* A subclass of {@link LabelNode} to add user-definable flags.
13+
*/
14+
public class LabelNode1 extends LabelNode {
15+
public LabelNode1() {
16+
}
17+
18+
public LabelNode1(Label label) {
19+
super(label);
20+
}
21+
22+
public int flags;
23+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/* NSC -- new Scala compiler
2+
* Copyright 2018 LAMP/EPFL
3+
* @author Martin Odersky
4+
*/
5+
package scala.tools.nsc.backend.jvm;
6+
7+
import scala.tools.asm.Label;
8+
import scala.tools.asm.Opcodes;
9+
import scala.tools.asm.tree.LabelNode;
10+
import scala.tools.asm.tree.MethodNode;
11+
/**
12+
* A subclass of {@link MethodNode} to customize the representation of
13+
* label nodes with {@link LabelNode1}.
14+
*/
15+
public class MethodNode1 extends MethodNode {
16+
public MethodNode1(int api, int access, String name, String descriptor, String signature, String[] exceptions) {
17+
super(api, access, name, descriptor, signature, exceptions);
18+
}
19+
20+
public MethodNode1(int access, String name, String descriptor, String signature, String[] exceptions) {
21+
this(Opcodes.ASM6, access, name, descriptor, signature, exceptions);
22+
}
23+
24+
public MethodNode1(int api) {
25+
super(api);
26+
}
27+
28+
public MethodNode1() {
29+
this(Opcodes.ASM6);
30+
}
31+
32+
@Override
33+
protected LabelNode getLabelNode(Label label) {
34+
if (!(label.info instanceof LabelNode)) {
35+
label.info = new LabelNode1(label);
36+
}
37+
return (LabelNode) label.info;
38+
}
39+
}

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import scala.tools.asm
1313
import scala.tools.asm.Opcodes._
1414
import scala.tools.asm.tree._
1515
import scala.tools.asm.tree.analysis._
16-
import scala.tools.asm.{Handle, LabelAccess, Type}
16+
import scala.tools.asm.{Handle, Label, Type}
1717
import scala.tools.nsc.backend.jvm.BTypes._
1818
import scala.tools.nsc.backend.jvm.GenBCode._
1919
import scala.tools.nsc.backend.jvm.analysis.BackendUtils._
@@ -587,9 +587,18 @@ object BackendUtils {
587587
def clearDceDone(method: MethodNode) = method.access &= ~ACC_DCE_DONE
588588

589589
private val LABEL_REACHABLE_STATUS = 0x1000000
590-
def isLabelReachable(label: LabelNode) = LabelAccess.isLabelFlagSet(label.getLabel, LABEL_REACHABLE_STATUS)
591-
def setLabelReachable(label: LabelNode) = LabelAccess.setLabelFlag(label.getLabel, LABEL_REACHABLE_STATUS)
592-
def clearLabelReachable(label: LabelNode) = LabelAccess.clearLabelFlag(label.getLabel, LABEL_REACHABLE_STATUS)
590+
private def isLabelFlagSet(l: LabelNode1, f: Int): Boolean = (l.flags & f) != 0
591+
592+
private def setLabelFlag(l: LabelNode1, f: Int): Unit = {
593+
l.flags |= f
594+
}
595+
596+
private def clearLabelFlag(l: LabelNode1, f: Int): Unit = {
597+
l.flags &= ~f
598+
}
599+
def isLabelReachable(label: LabelNode) = isLabelFlagSet(label.asInstanceOf[LabelNode1], LABEL_REACHABLE_STATUS)
600+
def setLabelReachable(label: LabelNode) = setLabelFlag(label.asInstanceOf[LabelNode1], LABEL_REACHABLE_STATUS)
601+
def clearLabelReachable(label: LabelNode) = clearLabelFlag(label.asInstanceOf[LabelNode1], LABEL_REACHABLE_STATUS)
593602

594603
abstract class NestedClassesCollector[T] extends GenericSignatureVisitor {
595604
val innerClasses = mutable.Set.empty[T]

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ trait ProdConsAnalyzerImpl {
9494
}
9595

9696
def consumersOfOutputsFrom(insn: AbstractInsnNode): Set[AbstractInsnNode] = insn match {
97-
case _: UninitializedLocalProducer => Set.empty
98-
case ParameterProducer(local) => consumersOfValueAt(methodNode.instructions.getFirst, local)
99-
case ExceptionProducer(handlerLabel, handlerFrame) => consumersOfValueAt(handlerLabel, handlerFrame.stackTop)
97+
case _: UninitializedLocalProducer => Set.empty
98+
case ParameterProducer(local) => consumersOfValueAt(methodNode.instructions.getFirst, local)
99+
case ExceptionProducer(handlerLabel, handlerStackTop) => consumersOfValueAt(handlerLabel, handlerStackTop)
100100
case _ =>
101101
_consumersOfOutputsFrom.get(insn).map(v => Set.from[AbstractInsnNode](v.indices.iterator.flatMap(v.apply))).getOrElse(Set.empty)
102102
}
@@ -388,7 +388,7 @@ trait ProdConsAnalyzerImpl {
388388
private def outputValueSlots(insn: AbstractInsnNode): Seq[Int] = insn match {
389389
case ParameterProducer(local) => Seq(local)
390390
case UninitializedLocalProducer(local) => Seq(local)
391-
case ExceptionProducer(_, frame) => Seq(frame.stackTop)
391+
case ExceptionProducer(_, stackTop) => Seq(stackTop)
392392
case _ =>
393393
if (insn.getOpcode == -1) return Seq.empty
394394
if (isStore(insn)) {
@@ -453,11 +453,11 @@ abstract class InitialProducer extends AbstractInsnNode(-1) {
453453
override def accept(cv: MethodVisitor): Unit = throw new UnsupportedOperationException
454454
}
455455

456-
case class ParameterProducer(local: Int) extends InitialProducer
457-
case class UninitializedLocalProducer(local: Int) extends InitialProducer
458-
case class ExceptionProducer[V <: Value](handlerLabel: LabelNode, handlerFrame: Frame[V]) extends InitialProducer
456+
case class ParameterProducer(local: Int) extends InitialProducer
457+
case class UninitializedLocalProducer(local: Int) extends InitialProducer
458+
case class ExceptionProducer[V <: Value](handlerLabel: LabelNode, handlerStackTop: Int) extends InitialProducer
459459

460-
class InitialProducerSourceInterpreter extends SourceInterpreter {
460+
class InitialProducerSourceInterpreter extends SourceInterpreter(scala.tools.asm.Opcodes.ASM7_EXPERIMENTAL) {
461461
override def newParameterValue(isInstanceMethod: Boolean, local: Int, tp: Type): SourceValue = {
462462
new SourceValue(tp.getSize, ParameterProducer(local))
463463
}
@@ -467,6 +467,7 @@ class InitialProducerSourceInterpreter extends SourceInterpreter {
467467
}
468468

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

0 commit comments

Comments
 (0)
0