I have a java file looking like this:
package answers;
class finalRed{
private long l;
public synchronized void increment(){
l++;
}
public void decrement(){
synchronized(this){
l--;
};
}
}
And I need to view the bytecode of each of the methods, and I know that I should use the javap command. I need a output like this:
public synchronized void increment();
Code:
0: aload_0
1: dup
2: getfield #2 // Field l:J
5: lconst_1
6: ladd
7: putfield #2 // Field l:J
10: return
public void decrement();
Code:
0: aload_0
1: dup
2: astore_1
3: monitorenter
4: aload_0
5: dup
6: getfield #2
9: lconst_1
10: lsub
11: putfield #2
14: aload_1
15: monitorexit
16: goto 24
19: astore_2
20: aload_1
21: monitorexit
22: aload_2
23: athrow
24: return
However, running javap -c C:\Users\Ask\Git\ITUProj\PCPP-private-Garse\week01\code\answers\finalRed.class
(which I can read should work), renders me this output:
Compiled from "finalRed.java"
public class answers.finalRed {
public answers.finalRed();
Code:
0: aload_0
1: invokespecial #1 // Method java/lang/Object."<init>":()V
4: return
}
Which doesn't actually show me any code from the two methods. Running javap with -v or -verbose doesn't help either. How should I run the command to get the actual bytecode of the two methods in the class?
My java version is 12.01