Created
January 18, 2011 18:39
-
-
Save keithrbennett/784911 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Demonstrates javap -c retaining identifier names. | |
| // | |
| // Do: | |
| // javac MyClass.java | |
| // javap -c MyClass | |
| public class MyClass { | |
| // Use a value that the compiler cannot predict, | |
| // to eliminate the possibility of the variable | |
| // being optimized away. | |
| public long aNumber = System.currentTimeMillis(); | |
| void myFunc() { | |
| System.out.println(aNumber * 2 + 1); | |
| } | |
| public static void main(String [] args) { | |
| new MyClass().myFunc(); | |
| } | |
| } | |
| /* | |
| Here is the output of javap -c MyClass: | |
| >javap -c MyClass | |
| Compiled from "MyClass.java" | |
| public class MyClass extends java.lang.Object{ | |
| public long aNumber; | |
| public MyClass(); | |
| Code: | |
| 0: aload_0 | |
| 1: invokespecial #1; //Method java/lang/Object."<init>":()V | |
| 4: aload_0 | |
| 5: invokestatic #2; //Method java/lang/System.currentTimeMillis:()J | |
| 8: putfield #3; //Field aNumber:J | |
| 11: return | |
| void myFunc(); | |
| Code: | |
| 0: getstatic #4; //Field java/lang/System.out:Ljava/io/PrintStream; | |
| 3: aload_0 | |
| 4: getfield #3; //Field aNumber:J | |
| 7: ldc2_w #5; //long 2l | |
| 10: lmul | |
| 11: lconst_1 | |
| 12: ladd | |
| 13: invokevirtual #7; //Method java/io/PrintStream.println:(J)V | |
| 16: return | |
| public static void main(java.lang.String[]); | |
| Code: | |
| 0: new #8; //class MyClass | |
| 3: dup | |
| 4: invokespecial #9; //Method "<init>":()V | |
| 7: invokevirtual #10; //Method myFunc:()V | |
| 10: return | |
| } | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment