Skip to content

Instantly share code, notes, and snippets.

@arturmkrtchyan
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arturmkrtchyan/d5f8b1a8dd8b5d6ed013 to your computer and use it in GitHub Desktop.
Save arturmkrtchyan/d5f8b1a8dd8b5d6ed013 to your computer and use it in GitHub Desktop.
JIT: Run Java With PrintAssembly
.........................................................
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
.........................................................
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;
}
}
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
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