Last active
August 29, 2015 14:08
-
-
Save arturmkrtchyan/d5f8b1a8dd8b5d6ed013 to your computer and use it in GitHub Desktop.
JIT: Run Java With PrintAssembly
This file contains 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
......................................................... | |
Decoding compiled method 0xb36e2848: | |
Code: | |
[Entry Point] | |
[Verified Entry Point] | |
[Constants] | |
# {method} 'multiply' '(I)J' in 'AssemblyMain' | |
# parm0: ecx = int | |
# [sp+0x10] (sp of caller) | |
0xb36e2920: sub $0xc,%esp | |
0xb36e2926: mov %ebp,0x8(%esp) ;*synchronization entry | |
; - AssemblyMain::multiply@-1 (line 21) | |
0xb36e292a: imul %ecx,%ecx ; multiply number*number | |
0xb36e292d: mov %ecx,%eax | |
0xb36e292f: mov %ecx,%edx | |
0xb36e2931: sar $0x1f,%edx ;*i2l ; - AssemblyMain::multiply@3 (line 21) | |
0xb36e2934: add $0x8,%esp | |
0xb36e2937: pop %ebp | |
0xb36e2938: test %eax,0xb779c000 ; {poll_return} | |
0xb36e293e: ret | |
......................................................... |
This file contains 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
public class AssemblyMain { | |
public static void main(String[] args) { | |
int number = 100000; | |
System.out.println("Calculating SUM of the squares of 1 to " + number); | |
long sum = sum(number); | |
System.out.println("SUM: " + sum); | |
} | |
private static long sum(int number) { | |
long sum = 0; | |
for(int i = 1; i < number; i++) { | |
sum += multiply(i); | |
} | |
return sum; | |
} | |
private static long multiply(int number) { | |
return number * number; | |
} | |
} |
This file contains 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
Java Hotspot(TM) Server VM warning: PrintAssembly is enabled; | |
turning on DebugNonSafepoints to gain additional output | |
Could not load hsdis-i386.so; library not loadable; | |
PrintAssembly is disabled |
This file contains 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
javac AssemblyMain.java && \ | |
java -server -XX:+UnlockDiagnosticVMOptions -XX:+PrintAssembly AssemblyMain |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment