Menu

how with only Jar files its calculating?

2006-10-17
2013-04-02
  • Nobody/Anonymous

    Can any body tell me how with only jar file calculation of cyclometric metric is done?
    I am qurious about this method. Please respond me with good feed back.

     
    • Pradeep

      Pradeep - 2006-10-17

      The class files store information in a particular format know as the 'Virtual Machine Specification'. For more infomation on the virtual machine spec see here - http://java.sun.com/docs/books/vmspec/

      For CyVis though we did not do the work of reading the class files ourself, instead we used ASM (ASM is a Java bytecode manipulation framework). ASM has a good API that lets us get the required information (to calculate cyclomatic complexity) from the class files.

      Regards

      Pradeep 

       
    • Nobody/Anonymous

      I thought that cyclomatic complexity makes sense in terms of source code. I think that it uses the number of entry and exit points for each method. How good are your results when you apply to byte code? Consider a switch statement - compiler optimization could change the code completely. Can you explain or justify your rationale for the metrics in the byte code context.

       
    • Pradeep

      Pradeep - 2007-02-06

      I believe that byte code has all the information needed to obtain the cyclomatic complexity. Even if the compiler does optimise an if condition for instance will be represented by two Instruction - one being a jump statement (eg. goto, goto_w, jsr, jsr_w, ret.) and other being an conditional statement (eg.  ifeq, iflt, ifle, ifne, ifgt, ifge, ifnull, ifnonnull etc). In Byte code all branch statement (while, if, do while, for etc) are represented with a jump and the a conditional statement.

      Just knowing the number of jump statements alone would give a rough idea of cyclomatic complexity. For example

      public void testE(int a)
      {
              if(a>b)
              {
                 //code
              }
              while(a>c)
              {
                 //code
              }   
      }

      Both the if & while statement would have one jump statement and a conditional statement associated with them  in the byte code.  During optimization the type of conditional statement maybe changed by the compiler(not sure, should check it out), but still a conditional statement is needed. And the Jump statement is also a must.

      So if we know there are two jump statements we could makeout that there are two branches in the method. And depending on the position of the conditional statements and jump statements we could determine the exact cyclomatic complexity. For method testE the cyclomatic Complexity would be 2+1 =3

      Hope that explains

      Pradeep

       

Log in to post a comment.