How to use javap to see what lines of bytecode correspond to lines in the Java code? -


i tasked make method calculates magnitude of given vector , used javap -c break down.

now must show each local variable in magnitude frame corresponds in java, , lines of bytecode correspond what.

here method made:

public class vector {     /** magnitude of vector      * calculates magnitude of vector corresponding      *   array a.      *      * @return magnitude      */     public double magnitude(double[] a){         int n = a.length;         double sum = 1;         (int i=0; i<n; i++){             sum = sum*a[i];         }         double magnitude = math.sqrt(sum);         return magnitude;     } } 

here result of using javap -c:

public class vector {    public vector();      code:         0: aload_0         1: invokespecial #1                  // method java/lang/object."<init>":()v         4: return     public double magnitude(double[]);      code:         0: aload_1         1: arraylength         2: istore_2         3: dconst_1         4: dstore_3         5: iconst_0         6: istore        5         8: iload         5        10: iload_2        11: if_icmpge     27        14: dload_3        15: aload_1        16: iload         5        18: daload        19: dmul        20: dstore_3        21: iinc          5, 1        24: goto          8        27: dload_3        28: invokestatic  #2                  // method java/lang/math.sqrt:(d)d        31: dstore        5        33: dload         5        35: dreturn  } 

run javap -l flag:

$ javap -c -l vector  compiled "vector.java" public class vector {   public vector();     code:        0: aload_0               1: invokespecial #1                  // method java/lang/object."<init>":()v        4: return             linenumbertable:       line 1: 0    public double magnitude(double[]);     code:        0: aload_1               1: arraylength           2: istore_2              3: dconst_1              4: dstore_3              ...       35: dreturn            linenumbertable:       line 12: 0       line 14: 3       line 16: 5       line 18: 14       line 16: 21       line 22: 27       line 24: 33 } 

for example, can see instructions 3 & 4 correspond line 14, 1 loaded double @ index 2.


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -