10000 Upgrade asm to 5.1 · scala/scala@79abfc7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 79abfc7

Browse files
committed
Upgrade asm to 5.1
The constructor of scala.tools.asm.Handle now takes an additional boolean parameter to denote whether the owner is an interface.
1 parent 5ddb0bb commit 79abfc7

File tree

8 files changed

+23
-13
lines changed

8 files changed

+23
-13
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1334,11 +1334,13 @@ abstract class BCodeBodyBuilder extends BCodeSkelBuilder {
13341334
val isStaticMethod = lambdaTarget.hasFlag(Flags.STATIC)
13351335
def asmType(sym: Symbol) = classBTypeFromSymbol(sym).toASMType
13361336

1337+
val isInterface = lambdaTarget.owner.isTrait
13371338
val implMethodHandle =
1338-
new asm.Handle(if (lambdaTarget.hasFlag(Flags.STATIC)) asm.Opcodes.H_INVOKESTATIC else if (lambdaTarget.owner.isTrait) asm.Opcodes.H_INVOKEINTERFACE else asm.Opcodes.H_INVOKEVIRTUAL,
1339+
new asm.Handle(if (lambdaTarget.hasFlag(Flags.STATIC)) asm.Opcodes.H_INVOKESTATIC else if (isInterface) asm.Opcodes.H_INVOKEINTERFACE else asm.Opcodes.H_INVOKEVIRTUAL,
13391340
classBTypeFromSymbol(lambdaTarget.owner).internalName,
13401341
lambdaTarget.name.toString,
1341-
methodBTypeFromSymbol(lambdaTarget).descriptor)
1342+
methodBTypeFromSymbol(lambdaTarget).descriptor,
1343+
/* itf = */ isInterface)
13421344
val receiver = if (isStaticMethod) Nil else lambdaTarget.owner :: Nil
13431345
val (capturedParams, lambdaParams) = lambdaTarget.paramss.head.splitAt(lambdaTarget.paramss.head.length - arity)
13441346
// Requires https://github.com/scala/scala-java8-compat on the runtime classpath

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@ class BTypesFromSymbols[G <: Global](val global: G) extends BTypes {
157157
def staticHandleFromSymbol(sym: Symbol): asm.Handle = {
158158
val owner = if (sym.owner.isModuleClass) sym.owner.linkedClassOfClass else sym.owner
159159
val descriptor = methodBTypeFromMethodType(sym.info, isConstructor = false).descriptor
160-
new asm.Handle(asm.Opcodes.H_INVOKESTATIC, classBTypeFromSymbol(owner).internalName, sym.name.encoded, descriptor)
160+
val ownerBType = classBTypeFromSymbol(owner)
161+
new asm.Handle(asm.Opcodes.H_INVOKESTATIC, ownerBType.internalName, sym.name.encoded, descriptor, /* itf = */ ownerBType.isInterface.get)
161162
}
162163

163164
/**

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,8 @@ class CoreBTypes[BTFS <: BTypesFromSymbols[_ <: Global]](val bTypes: BTFS) {
258258
coreBTypes.jliMethodTypeRef,
259259
ArrayBType(ObjectRef)),
260260
coreBTypes.jliCallSiteRef
261-
).descriptor)
261+
).descriptor,
262+
/* itf = */ false)
262263

263264
lazy val lambdaDeserializeBootstrapHandle =
264265
new scala.tools.asm.Handle(scala.tools.asm.Opcodes.H_INVOKESTATIC,
@@ -270,7 +271,8 @@ class CoreBTypes[BTFS <: BTypesFromSymbols[_ <: Global]](val bTypes: BTFS) {
270271
coreBTypes.jliMethodTypeRef
271272
),
272273
coreBTypes.jliCallSiteRef
273-
).descriptor)
274+
).descriptor,
275+
/* itf = */ false)
274276
}
275277

276278
/**

src/compiler/scala/tools/nsc/backend/jvm/opt/CallGraph.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,13 +418,13 @@ class CallGraph[BT <: BTypes](val btypes: BT) {
418418
private val metafactoryHandle = {
419419
val metafactoryMethodName: String = "metafactory"
420420
val metafactoryDesc: String = "(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;"
421-
new Handle(Opcodes.H_INVOKESTATIC, lambdaMetaFactoryInternalName, metafactoryMethodName, metafactoryDesc)
421+
new Handle(Opcodes.H_INVOKESTATIC, lambdaMetaFactoryInternalName, metafactoryMethodName, metafactoryDesc, /* itf = */ false)
422422
}
423423

424424
private val altMetafactoryHandle = {
425425
val altMetafactoryMethodName: String = "altMetafactory"
426426
val altMetafactoryDesc: String = "(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;[Ljava/lang/Object;)Ljava/lang/invoke/CallSite;"
427-
new Handle(Opcodes.H_INVOKESTATIC, lambdaMetaFactoryInternalName, altMetafactoryMethodName, altMetafactoryDesc)
427+
new Handle(Opcodes.H_INVOKESTATIC, lambdaMetaFactoryInternalName, altMetafactoryMethodName, altMetafactoryDesc, /* itf = */ false)
428428
}
429429

430430
def unapply(insn: AbstractInsnNode): Option[(InvokeDynamicInsnNode, Type, Handle, Type)] = insn match {

src/partest-extras/scala/tools/partest/ASMConverters.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ object ASMConverters {
9494
case class FrameEntry (`type`: Int, local: List[Any], stack: List[Any]) extends Instruction { def opcode: Int = -1 }
9595
case class LineNumber (line: Int, start: Label) extends Instruction { def opcode: Int = -1 }
9696

97-
case class MethodHandle(tag: Int, owner: String, name: String, desc: String)
97+
case class MethodHandle(tag: Int, owner: String, name: String, desc: String, itf: Boolean)
9898

9999
case class ExceptionHandler(start: Label, end: Label, handler: Label, desc: Option[String])
100100
case class LocalVariable(name: String, desc: String, signature: Option[String], start: Label, end: Label, index: Int)
@@ -147,7 +147,7 @@ object ASMConverters {
147147
case _ => a // can be: Class, method Type, primitive constant
148148
})(collection.breakOut)
149149

150-
private def convertMethodHandle(h: asm.Handle): MethodHandle = MethodHandle(h.getTag, h.getOwner, h.getName, h.getDesc)
150+
private def convertMethodHandle(h: asm.Handle): MethodHandle = MethodHandle(h.getTag, h.getOwner, h.getName, h.getDesc, h.isInterface)
151151

152152
private def convertHandlers(method: t.MethodNode): List[ExceptionHandler] = {
153153
method.tryCatchBlocks.asScala.map(h => ExceptionHandler(applyLabel(h.start), applyLabel(h.end), applyLabel(h.handler), Option(h.`type`)))(collection.breakOut)
@@ -227,7 +227,7 @@ object ASMConverters {
227227
case x => x.asInstanceOf[Object]
228228
}
229229

230-
def unconvertMethodHandle(h: MethodHandle): asm.Hand 57AE le = new asm.Handle(h.tag, h.owner, h.name, h.desc)
230+
def unconvertMethodHandle(h: MethodHandle): asm.Handle = new asm.Handle(h.tag, h.owner, h.name, h.desc, h.itf)
231231
def unconvertBsmArgs(a: List[Object]): Array[Object] = a.map({
232232
case h: MethodHandle => unconvertMethodHandle(h)
233233
case o => o

test/files/run/classfile-format-51.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ object Test extends DirectTest {
8080

8181
val test = cw.visitMethod(ACC_PUBLIC + ACC_FINAL, "test", s"()Ljava/lang/String;", null, null)
8282
test.visitCode()
83-
val bootstrapHandle = new Handle(H_INVOKESTATIC, invokerClassName, bootstrapMethodName, bootStrapMethodType)
83+
val bootstrapHandle = new Handle(H_INVOKESTATIC, invokerClassName, bootstrapMethodName, bootStrapMethodType, /* itf = */ false)
8484
test.visitInvokeDynamicInsn("invoke", targetMethodType, bootstrapHandle)
8585
test.visitInsn(ARETURN)
8686
test.visitMaxs(1, 1)

test/files/run/noInlineUnknownIndy/Test.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@ object Test extends DirectTest {
1515
}
1616

1717
def show(): Unit = {
18-
val unknownBootstrapMethod = new Handle(Opcodes.H_INVOKESTATIC, "not/java/lang/SomeLambdaMetafactory", "notAMetaFactoryMethod", "(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;[Ljava/lang/Object;)Ljava/lang/invoke/CallSite;")
18+
val unknownBootstrapMethod = new Handle(
19+
Opcodes.H_INVOKESTATIC,
20+
"not/java/lang/SomeLambdaMetafactory",
21+
"notAMetaFactoryMethod",
22+
"(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;[Ljava/lang/Object;)Ljava/lang/invoke/CallSite;",
23+
/* itf = */ false)
1924
modifyClassFile(new File(testOutput.toFile, "A_1.class"))((cn: ClassNode) => {
2025
val testMethod = cn.methods.iterator.asScala.find(_.name == "test").head
2126
val indy = testMethod.instructions.iterator.asScala.collect({ case i: InvokeDynamicInsnNode => i }).next()

versions.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ scala-parser-combinators.version.number=1.0.4
2727
scala-swing.version.number=2.0.0-M2
2828
scala-swing.version.osgi=2.0.0.M2
2929
jline.version=2.14.1
30-
scala-asm.version=5.0.4-scala-3
30+
scala-asm.version=5.1.0-scala-1
3131

3232
# external modules, used internally (not shipped)
3333
partest.version.number=1.0.17

0 commit comments

Comments
 (0)
0