如何测量类文件中字节码指令的数量? [英] How can I measure number of bytecode instructions in class file?

查看:95
本文介绍了如何测量类文件中字节码指令的数量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经为我的每个班级文件计算了平均圈复杂度。
我想知道如何使用Eclipse来测量每个类文件中字节码指令的数量?

I have calculated the average cyclomatic complexity for each of my class files. I was wondering how I could measure the number of bytecode instructions in each of my class files using Eclipse perhaps?

推荐答案

我不知道您是否可以从Eclipse轻松地做到这一点,但是您可以使用 javap -c 可以反汇编您的类文件。如果只关心每种方法的指令数,应该不太难将其包装在脚本中。

I don't know if you can do that easily from Eclipse, but you can use javap -c to get a disassembly of your class files. Shouldn't be too hard to wrap that in a script if you only care about the number of instructions per method.

示例:

 $ javap -c Test
Compiled from "Test.java"
public class Test extends java.lang.Object{
public Test();
  Code:
   0:   aload_0
   1:   invokespecial   #1; //Method java/lang/Object."<init>":()V
   4:   return

public static void main(java.lang.String[]);
  Code:
   0:   getstatic   #2; //Field java/lang/System.out:Ljava/io/PrintStream;
   3:   ldc #3; //String Hello
   5:   invokevirtual   #4; //Method java/io/PrintStream.println:(Ljava/lang/String;)V
   8:   return

}

这篇关于如何测量类文件中字节码指令的数量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆