Compiled Expression Examples
Twice
Java:
class Expr1 { public static int twice(int x) { return x*2; } }
Bytecode:
javac -g Expr1.java javap -c -l Expr1
public static int twice(int); Code: 0: iload_0 // load int from var 0 to top of stack 1: iconst_2 // push 2 on top of stack 2: imul // replace two topmost elements with their product 3: ireturn // return top of stack }
Area
class Expr2 { public static int cubeArea(int a, int b, int c) { return (a*b + b*c + a*c) * 2; } }
Bytecode:
javac -g Expr2.java javap -c -l Expr2
public static int cubeArea(int, int, int); Code: 0: iload_0 1: iload_1 2: imul 3: iload_1 4: iload_2 5: imul 6: iadd 7: iload_0 8: iload_2 9: imul 10: iadd 11: iconst_2 12: imul 13: ireturn } LocalVariableTable: Start Length Slot Name Signature 0 14 0 a I 0 14 1 b I 0 14 2 c I