summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorLukas Rytz <lukas.rytz@gmail.com>2015-02-23 20:43:21 +0100
committerLukas Rytz <lukas.rytz@gmail.com>2015-03-11 12:53:28 -0700
commit42054a1bebcc2155f773787ffda781b497d4178b (patch)
treec5cf4f830c1d27cba397e5060a9bd29cc08ad9b4 /test
parent3a32ae3651f69237bde32598674bc135ad9e4064 (diff)
downloadscala-42054a1bebcc2155f773787ffda781b497d4178b.tar.gz
scala-42054a1bebcc2155f773787ffda781b497d4178b.tar.bz2
scala-42054a1bebcc2155f773787ffda781b497d4178b.zip
Emit the ScalaInlineInfo attribute under GenASM
The goal of this commit is to allow the new inliner (in GenBCode, coming soon) to inline methods generated by the GenASM backend of 2.11.6. The ScalaInlineInfo attribute is added to every classfile generated by GenASM. It contains metadata about the class and its methods that will be used by the new inliner. Storing this metadata to the classfile prevents the need to look up a class symbol for a certain class file name, a process that is known to be brittle due to name mangling. Also, some symbols are not exactly the same when originating in a class being compiled or an unpickled one. For example, method symbols for mixed-in members are only added to classes being compiled. The classfile attribute is relatively small, because all strings it references (class internal names, method names, method descriptors) would exist anyway in the constant pool. It just adds a few references and bits for each method in the classfile. Jar sizes before: 480142 scala-actors.jar 15531408 scala-compiler.jar 5543249 scala-library.jar 4663078 scala-reflect.jar 785953 scalap.jar After: 490491 scala-actors.jar (102.1%) 15865500 scala-compiler.jar (102.1%) 5722504 scala-library.jar (103.2%) 4788370 scala-reflect.jar (102.7%) 805890 scalap.jar (102.5%)
Diffstat (limited to 'test')
-rw-r--r--test/files/run/t7974.check23
-rw-r--r--test/files/run/t7974/Test.scala14
-rw-r--r--test/junit/scala/tools/nsc/backend/jvm/opt/ScalaInlineInfoTest.scala85
3 files changed, 95 insertions, 27 deletions
diff --git a/test/files/run/t7974.check b/test/files/run/t7974.check
index d8152d3286..4eae5eb152 100644
--- a/test/files/run/t7974.check
+++ b/test/files/run/t7974.check
@@ -1,19 +1,3 @@
-public class Symbols {
-
-
-
-
- // access flags 0x12
- private final Lscala/Symbol; someSymbol3
-
- // access flags 0xA
- private static Lscala/Symbol; symbol$1
-
- // access flags 0xA
- private static Lscala/Symbol; symbol$2
-
- // access flags 0xA
- private static Lscala/Symbol; symbol$3
// access flags 0x9
public static <clinit>()V
@@ -33,6 +17,7 @@ public class Symbols {
MAXSTACK = 2
MAXLOCALS = 0
+
// access flags 0x1
public someSymbol1()Lscala/Symbol;
GETSTATIC Symbols.symbol$1 : Lscala/Symbol;
@@ -40,6 +25,7 @@ public class Symbols {
MAXSTACK = 1
MAXLOCALS = 1
+
// access flags 0x1
public someSymbol2()Lscala/Symbol;
GETSTATIC Symbols.symbol$2 : Lscala/Symbol;
@@ -47,6 +33,7 @@ public class Symbols {
MAXSTACK = 1
MAXLOCALS = 1
+
// access flags 0x1
public sameSymbol1()Lscala/Symbol;
GETSTATIC Symbols.symbol$1 : Lscala/Symbol;
@@ -54,6 +41,7 @@ public class Symbols {
MAXSTACK = 1
MAXLOCALS = 1
+
// access flags 0x1
public someSymbol3()Lscala/Symbol;
ALOAD 0
@@ -62,6 +50,7 @@ public class Symbols {
MAXSTACK = 1
MAXLOCALS = 1
+
// access flags 0x1
public <init>()V
ALOAD 0
@@ -72,4 +61,4 @@ public class Symbols {
RETURN
MAXSTACK = 2
MAXLOCALS = 1
-}
+
diff --git a/test/files/run/t7974/Test.scala b/test/files/run/t7974/Test.scala
index 29d2b9cb64..296ec32ee2 100644
--- a/test/files/run/t7974/Test.scala
+++ b/test/files/run/t7974/Test.scala
@@ -1,20 +1,14 @@
-import java.io.PrintWriter;
+import java.io.PrintWriter
import scala.tools.partest.BytecodeTest
+import scala.tools.nsc.backend.jvm.AsmUtils
import scala.tools.asm.util._
import scala.tools.nsc.util.stringFromWriter
+import scala.collection.convert.decorateAsScala._
object Test extends BytecodeTest {
def show {
val classNode = loadClassNode("Symbols", skipDebugInfo = true)
- val textifier = new Textifier
- classNode.accept(new TraceClassVisitor(null, textifier, null))
-
- val classString = stringFromWriter(w => textifier.print(w))
- val result =
- classString.split('\n')
- .dropWhile(elem => elem != "public class Symbols {")
- .filterNot(elem => elem.startsWith(" @Lscala/reflect/ScalaSignature") || elem.startsWith(" ATTRIBUTE ScalaSig"))
- result foreach println
+ classNode.methods.asScala.foreach(m => println(AsmUtils.textify(m)))
}
}
diff --git a/test/junit/scala/tools/nsc/backend/jvm/opt/ScalaInlineInfoTest.scala b/test/junit/scala/tools/nsc/backend/jvm/opt/ScalaInlineInfoTest.scala
new file mode 100644
index 0000000000..f8e887426b
--- /dev/null
+++ b/test/junit/scala/tools/nsc/backend/jvm/opt/ScalaInlineInfoTest.scala
@@ -0,0 +1,85 @@
+package scala.tools.nsc
+package backend.jvm
+package opt
+
+import org.junit.runner.RunWith
+import org.junit.runners.JUnit4
+import org.junit.Test
+import scala.tools.asm.Opcodes._
+import org.junit.Assert._
+
+import CodeGenTools._
+import scala.tools.nsc.backend.jvm.BTypes.{MethodInlineInfo, InlineInfo}
+import scala.tools.partest.ASMConverters
+import ASMConverters._
+import scala.collection.convert.decorateAsScala._
+
+object ScalaInlineInfoTest {
+ var compiler = newCompiler(extraArgs = "-Ybackend:GenBCode -Yopt:l:none")
+ def clear(): Unit = { compiler = null }
+}
+
+@RunWith(classOf[JUnit4])
+class ScalaInlineInfoTest {
+ val compiler = newCompiler()
+
+ @Test
+ def traitMembersInlineInfo(): Unit = {
+ val code =
+ """trait T {
+ | def f1 = 1 // concrete method
+ | private def f2 = 1 // implOnly method (does not end up in the interface)
+ | def f3 = {
+ | def nest = 0 // nested method (does not end up in the interface)
+ | nest
+ | }
+ |
+ | @inline
+ | def f4 = super.toString // super accessor
+ |
+ | object O // module accessor (method is generated)
+ | def f5 = {
+ | object L { val x = 0 } // nested module (just flattened out)
+ | L.x
+ | }
+ |
+ | @noinline
+ | def f6: Int // abstract method (not in impl class)
+ |
+ | // fields
+ |
+ | val x1 = 0
+ | var y2 = 0
+ | var x3: Int
+ | lazy val x4 = 0
+ |
+ | final val x5 = 0
+ |}
+ """.stripMargin
+
+ val cs @ List(t, tl, to, tCls) = compileClasses(compiler)(code)
+ val List(info) = t.attrs.asScala.collect({ case a: InlineInfoAttribute => a.inlineInfo }).toList
+ val expect = InlineInfo(
+ None, // self type
+ false, // final class
+ Map(
+ ("O()LT$O$;", MethodInlineInfo(true, false,false,false)),
+ ("T$$super$toString()Ljava/lang/String;",MethodInlineInfo(false,false,false,false)),
+ ("T$_setter_$x1_$eq(I)V", MethodInlineInfo(false,false,false,false)),
+ ("f1()I", MethodInlineInfo(false,true, false,false)),
+ ("f3()I", MethodInlineInfo(false,true, false,false)),
+ ("f4()Ljava/lang/String;", MethodInlineInfo(false,true, true, false)),
+ ("f5()I", MethodInlineInfo(false,true, false,false)),
+ ("f6()I", MethodInlineInfo(false,false,false,true )),
+ ("x1()I", MethodInlineInfo(false,false,false,false)),
+ ("x3()I", MethodInlineInfo(false,false,false,false)),
+ ("x3_$eq(I)V", MethodInlineInfo(false,false,false,false)),
+ ("x4()I", MethodInlineInfo(false,false,false,false)),
+ ("x5()I", MethodInlineInfo(true, false,false,false)),
+ ("y2()I", MethodInlineInfo(false,false,false,false)),
+ ("y2_$eq(I)V", MethodInlineInfo(false,false,false,false))),
+ None // warning
+ )
+ assert(info == expect, info)
+ }
+}