Skip to content

Commit 60bcaf1

Browse files
committed
Clean up some bytecode tests
1 parent 97d8e5a commit 60bcaf1

File tree

6 files changed

+111
-168
lines changed

6 files changed

+111
-168
lines changed

test/junit/scala/issues/BytecodeTest.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -150,21 +150,21 @@ class BytecodeTest extends ClearAfterClass {
150150
val List(c) = compileClasses(compiler)(code)
151151

152152
// t1: no unnecessary GOTOs
153-
assertSameCode(getSingleMethod(c, "t1").instructions.dropNonOp, List(
153+
assertSameCode(getSingleMethod(c, "t1"), List(
154154
VarOp(ILOAD, 1), Jump(IFEQ, Label(6)),
155155
Op(ICONST_1), Jump(GOTO, Label(9)),
156156
Label(6), Op(ICONST_2),
157157
Label(9), Op(IRETURN)))
158158

159159
// t2: no unnecessary GOTOs
160-
assertSameCode(getSingleMethod(c, "t2").instructions.dropNonOp, List(
160+
assertSameCode(getSingleMethod(c, "t2"), List(
161161
VarOp(ILOAD, 1), IntOp(SIPUSH, 393), Jump(IF_ICMPNE, Label(7)),
162162
Op(ICONST_1), Jump(GOTO, Label(10)),
163163
Label(7), Op(ICONST_2),
164164
Label(10), Op(IRETURN)))
165165

166166
// t3: Array == is translated to reference equality, AnyRef == to null checks and equals
167-
assertSameCode(getSingleMethod(c, "t3").instructions.dropNonOp, List(
167+
assertSameCode(getSingleMethod(c, "t3"), List(
168168
// Array ==
169169
VarOp(ALOAD, 1), VarOp(ALOAD, 2), Jump(IF_ACMPEQ, Label(23)),
170170
// AnyRef ==
@@ -183,13 +183,13 @@ class BytecodeTest extends ClearAfterClass {
183183
Label(13), Op(IRETURN))
184184

185185
// t4: one side is known null, so just a null check on the other
186-
assertSameCode(getSingleMethod(c, "t4").instructions.dropNonOp, t4t5)
186+
assertSameCode(getSingleMethod(c, "t4"), t4t5)
187187

188188
// t5: one side known null, so just a null check on the other
189-
assertSameCode(getSingleMethod(c, "t5").instructions.dropNonOp, t4t5)
189+
assertSameCode(getSingleMethod(c, "t5"), t4t5)
190190

191191
// t6: no unnecessary GOTOs
192-
assertSameCode(getSingleMethod(c, "t6").instructions.dropNonOp, List(
192+
assertSameCode(getSingleMethod(c, "t6"), List(
193193
VarOp(ILOAD, 1), IntOp(BIPUSH, 10), Jump(IF_ICMPNE, Label(7)),
194194
VarOp(ILOAD, 2), Jump(IFNE, Label(12)),
195195
Label(7), VarOp(ILOAD, 1), Op(ICONST_1), Jump(IF_ICMPEQ, Label(16)),
@@ -201,7 +201,7 @@ class BytecodeTest extends ClearAfterClass {
201201
assertInvoke(getSingleMethod(c, "t7"), "scala/runtime/BoxesRunTime", "equals")
202202

203203
// t8: no null checks invoking equals on modules and constants
204-
assertSameCode(getSingleMethod(c, "t8").instructions.dropNonOp, List(
204+
assertSameCode(getSingleMethod(c, "t8"), List(
205205
Field(GETSTATIC, "scala/collection/immutable/Nil$", "MODULE$", "Lscala/collection/immutable/Nil$;"), VarOp(ALOAD, 1), Invoke(INVOKEVIRTUAL, "java/lang/Object", "equals", "(Ljava/lang/Object;)Z", false), Jump(IFNE, Label(10)),
206206
Ldc(LDC, ""), VarOp(ALOAD, 1), Invoke(INVOKEVIRTUAL, "java/lang/Object", "equals", "(Ljava/lang/Object;)Z", false), Jump(IFNE, Label(14)),
207207
Label(10), Op(ICONST_1), Jump(GOTO, Label(17)),

test/junit/scala/issues/OptimizedBytecodeTest.scala

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class OptimizedBytecodeTest extends ClearAfterClass {
3636
|}
3737
""".stripMargin
3838
val List(c) = compileClasses(compiler)(code)
39-
assertSameCode(getSingleMethod(c, "t").instructions.dropNonOp, List(Label(0), Jump(GOTO, Label(0))))
39+
assertSameCode(getSingleMethod(c, "t"), List(Label(0), Jump(GOTO, Label(0))))
4040
}
4141

4242
@Test
@@ -55,17 +55,10 @@ class OptimizedBytecodeTest extends ClearAfterClass {
5555
""".stripMargin
5656
val List(c) = compileClasses(compiler)(code)
5757

58-
assertEquals(
59-
getSingleMethod(c, "t").instructions.summary,
60-
List(LDC, ASTORE, ALOAD /*0*/, ALOAD /*1*/, "C$$$anonfun$1", IRETURN))
61-
62-
assertEquals(
63-
getSingleMethod(c, "C$$$anonfun$1").instructions.summary,
64-
List(LDC, "C$$$anonfun$2", IRETURN))
65-
66-
assertEquals(
67-
getSingleMethod(c, "C$$$anonfun$2").instructions.summary,
68-
List(-1 /*A*/, GOTO /*A*/))
58+
assertSameSummary(getSingleMethod(c, "t"), List(
59+
LDC, ASTORE, ALOAD /*0*/, ALOAD /*1*/, "C$$$anonfun$1", IRETURN))
60+
assertSameSummary(getSingleMethod(c, "C$$$anonfun$1"), List(LDC, "C$$$anonfun$2", IRETURN))
61+
assertSameSummary(getSingleMethod(c, "C$$$anonfun$2"), List(-1 /*A*/, GOTO /*A*/))
6962
}
7063

7164
@Test
@@ -87,9 +80,7 @@ class OptimizedBytecodeTest extends ClearAfterClass {
8780
|}
8881
""".stripMargin
8982
val List(c, t, tMod) = compileClasses(compiler)(code, allowMessage = _.msg.contains("not be exhaustive"))
90-
assertEquals(
91-
getSingleMethod(c, "t").instructions.summary,
92-
List(GETSTATIC, "$qmark$qmark$qmark", ATHROW))
83+
assertSameSummary(getSingleMethod(c, "t"), List(GETSTATIC, "$qmark$qmark$qmark", ATHROW))
9384
}
9485

9586
@Test
@@ -235,9 +226,7 @@ class OptimizedBytecodeTest extends ClearAfterClass {
235226
|}
236227
""".stripMargin
237228
val List(c) = compileClasses(compiler)(code)
238-
assertEquals(
239-
getSingleMethod(c, "t").instructions.summary,
240-
List(
229+
assertSameSummary(getSingleMethod(c, "t"), List(
241230
ALOAD /*1*/, INSTANCEOF /*Some*/, IFNE /*A*/,
242231
ALOAD /*0*/, "getInt", POP,
243232
-1 /*A*/, BIPUSH, IRETURN))
@@ -256,13 +245,11 @@ class OptimizedBytecodeTest extends ClearAfterClass {
256245
|}
257246
""".stripMargin
258247
val List(c) = compileClasses(compiler)(code)
259-
assertEquals(
260-
getSingleMethod(c, "t").instructions.summary,
261-
List(
262-
-1 /*A*/, ILOAD /*1*/, TABLESWITCH,
263-
-1, ALOAD, "pr", RETURN,
264-
-1, ALOAD, "pr", RETURN,
265-
-1, ILOAD, ICONST_2, ISUB, ISTORE, GOTO /*A*/))
248+
assertSameSummary(getSingleMethod(c, "t"), List(
249+
-1 /*A*/, ILOAD /*1*/, TABLESWITCH,
250+
-1, ALOAD, "pr", RETURN,
251+
-1, ALOAD, "pr", RETURN,
252+
-1, ILOAD, ICONST_2, ISUB, ISTORE, GOTO /*A*/))
266253
}
267254

268255
@Test
@@ -283,12 +270,10 @@ class OptimizedBytecodeTest extends ClearAfterClass {
283270

284271
val cls = compileClassesSeparately(List(c1, c2), extraArgs = OptimizedBytecodeTest.args)
285272
val c = cls.find(_.name == "C").get
286-
assertEquals(
287-
getSingleMethod(c, "t").instructions.summary,
288-
List(
289-
GETSTATIC, IFNONNULL, ACONST_NULL, ATHROW, // module load and null checks not yet eliminated
290-
-1, ICONST_1, GETSTATIC, IFNONNULL, ACONST_NULL, ATHROW,
291-
-1, ICONST_2, IADD, IRETURN))
273+
assertSameSummary(getSingleMethod(c, "t"), List(
274+
GETSTATIC, IFNONNULL, ACONST_NULL, ATHROW, // module load and null checks not yet eliminated
275+
-1, ICONST_1, GETSTATIC, IFNONNULL, ACONST_NULL, ATHROW,
276+
-1, ICONST_2, IADD, IRETURN))
292277
}
293278

294279
@Test

test/junit/scala/tools/nsc/backend/jvm/opt/ClosureOptimizerTest.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class ClosureOptimizerTest extends ClearAfterClass {
8282
|}
8383
""".stripMargin
8484
val List(c) = compileClasses(compiler)(code)
85-
assertSameCode(getSingleMethod(c, "t").instructions.dropNonOp,
85+
assertSameCode(getSingleMethod(c, "t"),
8686
List(VarOp(ALOAD, 1), Invoke(INVOKEVIRTUAL, "scala/collection/immutable/List", "head", "()Ljava/lang/Object;", false),
8787
TypeOp(CHECKCAST, "java/lang/String"), Invoke(INVOKESTATIC, "C", "C$$$anonfun$1", "(Ljava/lang/String;)Ljava/lang/String;", false),
8888
Op(ARETURN)))
@@ -103,7 +103,6 @@ class ClosureOptimizerTest extends ClearAfterClass {
103103
|}
104104
""".stripMargin
105105
val List(c) = compileClasses(compiler)(code)
106-
assertEquals(getSingleMethod(c, "t").instructions.summary,
107-
List(NEW, DUP, LDC, "<init>", ATHROW))
106+
assertSameSummary(getSingleMethod(c, "t"), List(NEW, DUP, LDC, "<init>", ATHROW))
108107
}
109108
}

test/junit/scala/tools/nsc/backend/jvm/opt/InlinerTest.scala

Lines changed: 34 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class InlinerTest extends ClearAfterClass {
100100
val g = inlineTest(code)
101101

102102
val gConv = convertMethod(g)
103-
assertSameCode(gConv.instructions.dropNonOp,
103+
assertSameCode(gConv,
104104
List(
105105
VarOp(ALOAD, 0), VarOp(ASTORE, 1), // store this
106106
Op(ICONST_1), VarOp(ISTORE, 2), Jump(GOTO, Label(10)), // store return value
@@ -144,10 +144,10 @@ class InlinerTest extends ClearAfterClass {
144144
VarOp(ALOAD, 2),
145145
Op(ATHROW))
146146

147-
assertSameCode(convertMethod(g).instructions.dropNonOp, gBeforeLocalOpt)
147+
assertSameCode(convertMethod(g), gBeforeLocalOpt)
148148

149149
compiler.genBCode.bTypes.localOpt.methodOptimizations(g, "C")
150-
assertSameCode(convertMethod(g).instructions.dropNonOp, invokeQQQ :+ Op(ATHROW))
150+
assertSameCode(convertMethod(g), invokeQQQ :+ Op(ATHROW))
151151
}
152152

153153
@Test
@@ -1313,60 +1313,40 @@ class InlinerTest extends ClearAfterClass {
13131313
""".stripMargin
13141314
val List(c, _, _) = compile(code)
13151315

1316-
assertEquals(getSingleMethod(c, "t1").instructions.summary,
1317-
List(BIPUSH, "C$$$anonfun$1", IRETURN))
1318-
1319-
assertEquals(getSingleMethod(c, "t1a").instructions.summary,
1320-
List(LCONST_1, "C$$$anonfun$2", IRETURN))
1321-
1322-
assertEquals(getSingleMethod(c, "t2").instructions.summary, List(
1323-
ICONST_1, ICONST_2, "C$$$anonfun$3",IRETURN))
1316+
assertSameSummary(getSingleMethod(c, "t1"), List(BIPUSH, "C$$$anonfun$1", IRETURN))
1317+
assertSameSummary(getSingleMethod(c, "t1a"), List(LCONST_1, "C$$$anonfun$2", IRETURN))
1318+
assertSameSummary(getSingleMethod(c, "t2"), List(ICONST_1, ICONST_2, "C$$$anonfun$3",IRETURN))
13241319

13251320
// val a = new ValKl(n); new ValKl(anonfun(a.x)).x
13261321
// value class instantiation-extraction should be optimized by boxing elim
1327-
assertEquals(getSingleMethod(c, "t3").instructions.summary, List(
1322+
assertSameSummary(getSingleMethod(c, "t3"), List(
13281323
NEW, DUP, ICONST_1, "<init>", ASTORE,
13291324
NEW, DUP, ALOAD, "x",
13301325
"C$$$anonfun$4",
13311326
"<init>",
13321327
"x", IRETURN))
13331328

1334-
assertEquals(getSingleMethod(c, "t4").instructions.summary, List(
1335-
BIPUSH, "C$$$anonfun$5", "boxToInteger", ARETURN))
1336-
1337-
assertEquals(getSingleMethod(c, "t4a").instructions.summary, List(
1338-
ICONST_1, LDC, "C$$$anonfun$6", LRETURN))
1339-
1340-
assertEquals(getSingleMethod(c, "t5").instructions.summary, List(
1341-
BIPUSH, ICONST_3, "C$$$anonfun$7", "boxToInteger", ARETURN))
1342-
1343-
assertEquals(getSingleMethod(c, "t5a").instructions.summary, List(
1344-
BIPUSH, BIPUSH, I2B, "C$$$anonfun$8", IRETURN))
1345-
1346-
assertEquals(getSingleMethod(c, "t6").instructions.summary, List(
1347-
BIPUSH, "C$$$anonfun$9", RETURN))
1348-
1349-
assertEquals(getSingleMethod(c, "t7").instructions.summary, List(
1350-
ICONST_1, "C$$$anonfun$10", RETURN))
1351-
1352-
assertEquals(getSingleMethod(c, "t8").instructions.summary, List(
1353-
ICONST_1, LDC, "C$$$anonfun$11", LRETURN))
1354-
1355-
assertEquals(getSingleMethod(c, "t9").instructions.summary, List(
1356-
ICONST_1, "boxToInteger", "C$$$anonfun$12", RETURN))
1329+
assertSameSummary(getSingleMethod(c, "t4"), List(BIPUSH, "C$$$anonfun$5", "boxToInteger", ARETURN))
1330+
assertSameSummary(getSingleMethod(c, "t4a"), List(ICONST_1, LDC, "C$$$anonfun$6", LRETURN))
1331+
assertSameSummary(getSingleMethod(c, "t5"), List(BIPUSH, ICONST_3, "C$$$anonfun$7", "boxToInteger", ARETURN))
1332+
assertSameSummary(getSingleMethod(c, "t5a"), List(BIPUSH, BIPUSH, I2B, "C$$$anonfun$8", IRETURN))
1333+
assertSameSummary(getSingleMethod(c, "t6"), List(BIPUSH, "C$$$anonfun$9", RETURN))
1334+
assertSameSummary(getSingleMethod(c, "t7"), List(ICONST_1, "C$$$anonfun$10", RETURN))
1335+
assertSameSummary(getSingleMethod(c, "t8"), List(ICONST_1, LDC, "C$$$anonfun$11", LRETURN))
1336+
assertSameSummary(getSingleMethod(c, "t9"), List(ICONST_1, "boxToInteger", "C$$$anonfun$12", RETURN))
13571337

13581338
// t9a inlines Range.foreach, which is quite a bit of code, so just testing the core
13591339
assertInvoke(getSingleMethod(c, "t9a"), "C", "C$$$anonfun$13")
1360-
assert(getSingleMethod(c, "t9a").instructions.summary.contains("boxToInteger"))
1340+
assertInvoke(getSingleMethod(c, "t9a"), "scala/runtime/BoxesRunTime", "boxToInteger")
13611341

1362-
assertEquals(getSingleMethod(c, "t10").instructions.summary, List(
1342+
assertSameSummary(getSingleMethod(c, "t10"), List(
13631343
ICONST_1, ISTORE,
13641344
ALOAD, ILOAD,
13651345
"C$$$anonfun$14", RETURN))
13661346

13671347
// t10a inlines Range.foreach
13681348
assertInvoke(getSingleMethod(c, "t10a"), "C", "C$$$anonfun$15")
1369-
assert(!getSingleMethod(c, "t10a").instructions.summary.contains("boxToInteger"))
1349+
assertDoesNotInvoke(getSingleMethod(c, "t10a"), "boxToInteger")
13701350
}
13711351

13721352
@Test
@@ -1389,7 +1369,7 @@ class InlinerTest extends ClearAfterClass {
13891369
|}
13901370
""".stripMargin
13911371
val List(c) = compile(code)
1392-
assertSameCode(getSingleMethod(c, "t1").instructions.dropNonOp, List(Op(ICONST_0), Op(ICONST_1), Op(IADD), Op(IRETURN)))
1372+
assertSameCode(getSingleMethod(c, "t1"), List(Op(ICONST_0), Op(ICONST_1), Op(IADD), Op(IRETURN)))
13931373
assertEquals(getSingleMethod(c, "t2").instructions collect { case i: Invoke => i.owner +"."+ i.name }, List(
13941374
"scala/runtime/IntRef.create", "C.C$$$anonfun$1"))
13951375
}
@@ -1430,9 +1410,9 @@ class InlinerTest extends ClearAfterClass {
14301410
|}
14311411
""".stripMargin
14321412
val List(c) = compile(code)
1433-
assertSameCode(getSingleMethod(c, "t1").instructions.dropNonOp, List(Op(ICONST_3), Op(ICONST_4), Op(IADD), Op(IRETURN)))
1434-
assertSameCode(getSingleMethod(c, "t2").instructions.dropNonOp, List(Op(ICONST_1), Op(ICONST_2), Op(IADD), Op(IRETURN)))
1435-
assertSameCode(getSingleMethod(c, "t3").instructions.dropNonOp, List(Op(ICONST_1), Op(ICONST_3), Op(ISUB), Op(IRETURN)))
1413+
assertSameCode(getSingleMethod(c, "t1"), List(Op(ICONST_3), Op(ICONST_4), Op(IADD), Op(IRETURN)))
1414+
assertSameCode(getSingleMethod(c, "t2"), List(Op(ICONST_1), Op(ICONST_2), Op(IADD), Op(IRETURN)))
1415+
assertSameCode(getSingleMethod(c, "t3"), List(Op(ICONST_1), Op(ICONST_3), Op(ISUB), Op(IRETURN)))
14361416
assertNoInvoke(getSingleMethod(c, "t4"))
14371417
assertNoInvoke(getSingleMethod(c, "t5"))
14381418
}
@@ -1461,9 +1441,9 @@ class InlinerTest extends ClearAfterClass {
14611441
""".stripMargin
14621442
val List(c, _) = compile(code)
14631443
def casts(m: String) = getSingleMethod(c, m).instructions collect { case TypeOp(CHECKCAST, tp) => tp }
1464-
assertSameCode(getSingleMethod(c, "t1").instructions.dropNonOp, List(VarOp(ALOAD, 1), Op(ARETURN)))
1465-
assertSameCode(getSingleMethod(c, "t2").instructions.dropNonOp, List(VarOp(ALOAD, 1), Op(ARETURN)))
1466-
assertSameCode(getSingleMethod(c, "t3").instructions.dropNonOp, List(VarOp(ALOAD, 1), TypeOp(CHECKCAST, "C"), Op(ARETURN)))
1444+
assertSameCode(getSingleMethod(c, "t1"), List(VarOp(ALOAD, 1), Op(ARETURN)))
1445+
assertSameCode(getSingleMethod(c, "t2"), List(VarOp(ALOAD, 1), Op(ARETURN)))
1446+
assertSameCode(getSingleMethod(c, "t3"), List(VarOp(ALOAD, 1), TypeOp(CHECKCAST, "C"), Op(ARETURN)))
14671447
assertEquals(casts("t4"), List("C"))
14681448
assertEquals(casts("t5"), Nil)
14691449
assertEquals(casts("t6"), Nil)
@@ -1489,12 +1469,11 @@ class InlinerTest extends ClearAfterClass {
14891469

14901470
val cls = compile(code)
14911471
val test = cls.find(_.name == "Test$").get
1492-
assertEquals(
1493-
getSingleMethod(test, "f").instructions.summary,
1494-
List(GETSTATIC, "mkFoo",
1495-
BIPUSH, ISTORE,
1496-
IFNONNULL, ACONST_NULL, ATHROW, -1 /*label*/,
1497-
ILOAD, ICONST_1, IADD, IRETURN))
1472+
assertSameSummary(getSingleMethod(test, "f"), List(
1473+
GETSTATIC, "mkFoo",
1474+
BIPUSH, ISTORE,
1475+
IFNONNULL, ACONST_NULL, ATHROW, -1 /*label*/,
1476+
ILOAD, ICONST_1, IADD, IRETURN))
14981477
}
14991478

15001479
@Test // a test taken from the test suite for the 2.11 inliner
@@ -1509,11 +1488,10 @@ class InlinerTest extends ClearAfterClass {
15091488
val List(c) = compile(code)
15101489

15111490
// box-unbox will clean it up
1512-
assertEquals(getSingleMethod(c, "t").instructions.summary,
1513-
List(
1514-
ALOAD, "C$$$anonfun$1", IFEQ /*A*/,
1515-
"C$$$anonfun$2", IRETURN,
1516-
-1 /*A*/, "C$$$anonfun$3", IRETURN))
1491+
assertSameSummary(getSingleMethod(c, "t"), List(
1492+
ALOAD, "C$$$anonfun$1", IFEQ /*A*/,
1493+
"C$$$anonfun$2", IRETURN,
1494+
-1 /*A*/, "C$$$anonfun$3", IRETURN))
15171495
}
15181496

15191497
@Test

0 commit comments

Comments
 (0)