diff options
author | Paul Phillips <paulp@improving.org> | 2013-02-01 17:38:56 -0800 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2013-02-01 17:38:56 -0800 |
commit | a45a78a1d4111709acdc0bca9a1ac869a8e53ea5 (patch) | |
tree | 5c909c41db2470c460cbb3c33672294c9342b914 /test/files/jvm/bytecode-test-example/Test.scala | |
parent | 26de4394b19d6614b7d414b33f66ebf7adcb8833 (diff) | |
parent | 644eb7078a11613a06dcaaefb807cbcc44f65ea7 (diff) | |
download | scala-a45a78a1d4111709acdc0bca9a1ac869a8e53ea5.tar.gz scala-a45a78a1d4111709acdc0bca9a1ac869a8e53ea5.tar.bz2 scala-a45a78a1d4111709acdc0bca9a1ac869a8e53ea5.zip |
Merge commit '644eb7078a' into wip/fresh-merge2
Conflicts:
build.xml
src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala
Diffstat (limited to 'test/files/jvm/bytecode-test-example/Test.scala')
-rw-r--r-- | test/files/jvm/bytecode-test-example/Test.scala | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/test/files/jvm/bytecode-test-example/Test.scala b/test/files/jvm/bytecode-test-example/Test.scala new file mode 100644 index 0000000000..d668059cb7 --- /dev/null +++ b/test/files/jvm/bytecode-test-example/Test.scala @@ -0,0 +1,32 @@ +import scala.tools.partest.BytecodeTest + +import scala.tools.nsc.util.JavaClassPath +import java.io.InputStream +import scala.tools.asm +import asm.ClassReader +import asm.tree.{ClassNode, InsnList} +import scala.collection.JavaConverters._ + +object Test extends BytecodeTest { + def show: Unit = { + val classNode = loadClassNode("Foo_1") + val methodNode = getMethod(classNode, "foo") + println(countNullChecks(methodNode.instructions)) + } + + def countNullChecks(insnList: InsnList): Int = { + /** Is given instruction a null check? + * NOTE + * This will detect direct null compparsion as in + * if (x == null) ... + * and not indirect as in + * val foo = null + * if (x == foo) ... + */ + def isNullCheck(node: asm.tree.AbstractInsnNode): Boolean = { + val opcode = node.getOpcode + (opcode == asm.Opcodes.IFNULL) || (opcode == asm.Opcodes.IFNONNULL) + } + insnList.iterator.asScala.count(isNullCheck) + } +} |