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?
Asked
Active
Viewed 818 times
2 Answers
3
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.
Example:
$ 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
}

Mat
- 202,337
- 40
- 393
- 406
-
Thanks for this. How can I do this from Eclipse? – Joeblackdev Aug 20 '11 at 13:57
-
You can configure javap as an external tool – Sean Patrick Floyd Aug 20 '11 at 13:59
-
1@Joeblackdev: http://stackoverflow.com/questions/7056987/how-to-use-javap-with-eclipse. – Mat Aug 20 '11 at 14:02
3
Use javap as mentioned by Mat, ore use Commons BCEL to access the byte code programmatically.

Sean Patrick Floyd
- 292,901
- 67
- 465
- 588