SlideShare ist ein Scribd-Unternehmen logo
1 von 167
Java Bytecode for Discriminating Developers Anton Arhipov
whoami Anton Arhipov Java dev. / Product Lead JRebel http://arhipov.blogspot.com @antonarhipov @javarebel
Who-are-you?
The Master Plan 80%: Bytecode 101 20%: Examples
THE INTRO
1 + 2
+ 1 + 2 1 2
+ 1 + 2 1 2 1 2 +
+ 1 + 2 1 2 1 2 +
+ 1 + 2 1 2 1 2 +  1 PUSH 1
+ 1 + 2 1 2 1 2 +  2 PUSH 1 PUSH 2 1
+ 1 + 2 1 2 1 2 +  3 PUSH 1 PUSH 2 ADD
+ 1 + 2 1 2 1 2 +  3 ICONST_1 ICONST_2 IADD
? = 1 + 2
TAXONOMY
Bytecode One-byte instructions 256 possible opcodes 200+ in use
Bytecode One-byte instructions 256 possible opcodes 200+ in use
TYPE OPERATION
TYPE OPERATION <TYPE> ::= b, s, c, i, l, f, d, a
TYPE OPERATION <TYPE> ::= b, s, c, i, l, f, d, a Operations with constant values (ldc, iconst_1)
TYPE OPERATION <TYPE> ::= b, s, c, i, l, f, d, a Operations with constant values (ldc, iconst_1) Local variables and stack interaction (load/store) Array operations (aload, astore) Math (add, sub, mul, div) Boolean/bitwise operations (iand, ixor) Comparisons (cmpg, cmpl, ifne, ifeq) Conversions (l2d, i2l)
Bytecode Taxonomy Stack  Manipulation
Bytecode Taxonomy Stack  Manipulation Flow Control
Bytecode Taxonomy Stack  Manipulation Flow Control Object  Model
Bytecode Taxonomy Stack  Manipulation Flow Control Object  Model Arithmetics
Bytecode Taxonomy Stack  Manipulation Flow Control Object  Model Arithmetics monitorenter monitorexit
TOOLING
javap Java class file disassembler Used with no options shows class structure only Methods, superclass, interfaces, etc -c shows the bytecode -private shows all methods and members -s prints internal signatures -l prints line numbers and local variable tables
HELLO WORLD!
C:orkeeconlasses>javap Hello -c
C:orkeeconlasses>javap Hello -c Compiled from "Hello.java" public class Hello extends java.lang.Object{ public Hello(); Code: 0:   aload_0 1:   invokespecial   #1; //Method java/lang/Object."<init>":()V 4:   return
C:orkeeconlasses>javap Hello -c Compiled from "Hello.java" public class Hello extends java.lang.Object{ public Hello(); Code: 0:   aload_0 1:   invokespecial   #1; //Method java/lang/Object."<init>":()V 4:   return the default constructor
C:orkeeconlasses>javap Hello -c Compiled from "Hello.java" public class Hello extends java.lang.Object{ public Hello(); Code: 0:   aload_0 1:   invokespecial   #1; //Method java/lang/Object."<init>":()V 4:   return push this to stack
C:orkeeconlasses>javap Hello -c Compiled from "Hello.java" public class Hello extends java.lang.Object{ public Hello(); Code: 0:   aload_0 1:   invokespecial   #1; //Method java/lang/Object."<init>":()V 4:   return invoke <init> on this
C:orkeeconlasses>javap Hello -c Compiled from "Hello.java" public class Hello extends java.lang.Object{ public Hello(); Code: 0:   aload_0 1:   invokespecial   #1; //Method java/lang/Object."<init>":()V 4:   return
C:orkeeconlasses>javap Hello -c Compiled from "Hello.java" public class Hello extends java.lang.Object{ public Hello(); Code: 0:   aload_0 1:   invokespecial   #1; //Method java/lang/Object."<init>":()V 4:   return public static void main(java.lang.String[]); Code: 0:   getstatic       #2; //Field java/lang/System.out:Ljava/io/PrintStream; 3:   ldc     #3; //String Hello, World! 5:   invokevirtual   #4; //Method java/io/PrintStream.println:(Ljava/lang/String;)V
C:orkeeconlasses>javap Hello -c Compiled from "Hello.java" public class Hello extends java.lang.Object{ public Hello(); Code: 0:   aload_0 1:   invokespecial   #1; //Method java/lang/Object."<init>":()V 4:   return public static void main(java.lang.String[]); Code: 0:   getstatic       #2; //Field java/lang/System.out:Ljava/io/PrintStream; 3:   ldc     #3; //String Hello, World! 5:   invokevirtual   #4; //Method java/io/PrintStream.println:(Ljava/lang/String;)V get static field
C:orkeeconlasses>javap Hello -c Compiled from "Hello.java" public class Hello extends java.lang.Object{ public Hello(); Code: 0:   aload_0 1:   invokespecial   #1; //Method java/lang/Object."<init>":()V 4:   return public static void main(java.lang.String[]); Code: 0:   getstatic       #2; //Field java/lang/System.out:Ljava/io/PrintStream; 3:   ldc     #3; //String Hello, World! 5:   invokevirtual   #4; //Method java/io/PrintStream.println:(Ljava/lang/String;)V load string to the stack
C:orkeeconlasses>javap Hello -c Compiled from "Hello.java" public class Hello extends java.lang.Object{ public Hello(); Code: 0:   aload_0 1:   invokespecial   #1; //Method java/lang/Object."<init>":()V 4:   return public static void main(java.lang.String[]); Code: 0:   getstatic       #2; //Field java/lang/System.out:Ljava/io/PrintStream; 3:   ldc     #3; //String Hello, World! 5:   invokevirtual   #4; //Method java/io/PrintStream.println:(Ljava/lang/String;)V invoke method with parameter
C:orkeeconlasses>javap Hello -c Compiled from "Hello.java" public class Hello extends java.lang.Object{ public Hello(); Code: 0:   aload_0 1:   invokespecial   #1; //Method java/lang/Object."<init>":()V 4:   return public static void main(java.lang.String[]); Code: 0:   getstatic       #2; //Field java/lang/System.out:Ljava/io/PrintStream; 3:   ldc     #3; //String Hello, World! 5:   invokevirtual   #4; //Method java/io/PrintStream.println:(Ljava/lang/String;)V
What’s #1,#2, etc ? C:orkeeconlasses>javap Hello -c Compiled from "Hello.java" public class Hello extends java.lang.Object{ public Hello(); Code: 0:   aload_0 1:   invokespecial   #1; //Method java/lang/Object."<init>":()V 4:   return public static void main(java.lang.String[]); Code: 0:   getstatic       #2; //Field java/lang/System.out:Ljava/io/PrintStream; 3:   ldc     #3; //String Hello, World! 5:   invokevirtual   #4; //Method java/io/PrintStream.println:(Ljava/lang/String;)V
C:orkeeconlasses>javap Hello -c -verbose
C:orkeeconlasses>javap Hello -c -verbose
C:orkeeconlasses>javap Hello -c -verbose Compiled from "Hello.java“ public class Hello extends java.lang.Object   SourceFile: "Hello.java"   minor version: 0   major version: 50   Constant pool: const #1 = Method#6.#20; //  java/lang/Object."<init>":()V const #2 = Field#21.#22;        //  java/lang/System.out:Ljava/io/PrintStream; const #3 = String#23;    //  Hello, World! const #4 = Method#24.#25;        //  java/io/PrintStream.println:(Ljava/lang/String;)V const #5 = class#26;    //  Hello const #6 = class#27;    //  java/lang/Object const #7 = Asciz<init>; const #8 = Asciz()V;
C:orkeeconlasses>javap Hello -c -verbose Compiled from "Hello.java“ public class Hello extends java.lang.Object   SourceFile: "Hello.java"   minor version: 0   major version: 50   Constant pool: const #1 = Method#6.#20; //  java/lang/Object."<init>":()V const #2 = Field#21.#22;        //  java/lang/System.out:Ljava/io/PrintStream; const #3 = String#23;    //  Hello, World! const #4 = Method#24.#25;        //  java/io/PrintStream.println:(Ljava/lang/String;)V const #5 = class#26;    //  Hello const #6 = class#27;    //  java/lang/Object const #7 = Asciz<init>; const #8 = Asciz()V;
C:orkeeconlasses>javap Hello -c -verbose … public Hello(); Code:    Stack=1, Locals=1, Args_size=1    0:   aload_0    1:   invokespecial   #1; //Method java/lang/Object."<init>":()V    4:   return LineNumberTable:    line 1: 0  LocalVariableTable:    Start  Length  Slot  Name   Signature    0      5      0    this       LHello;
C:orkeeconlasses>javap Hello -c -verbose … public Hello(); Code:    Stack=1, Locals=1, Args_size=1    0:   aload_0    1:   invokespecial   #1; //Method java/lang/Object."<init>":()V    4:   return LineNumberTable:    line 1: 0  LocalVariableTable:    Start  Length  Slot  Name   Signature    0      5      0    this       LHello;
C:orkeeconlasses>javap Hello -c -verbose … public Hello(); Code:    Stack=1, Locals=1, Args_size=1    0:   aload_0    1:   invokespecial   #1; //Method java/lang/Object."<init>":()V    4:   return LineNumberTable:    line 1: 0  LocalVariableTable:    Start  Length  Slot  Name   Signature    0      5      0    this       LHello;
C:orkeeconlasses>javap Hello -c -verbose … public static void main(java.lang.String[]);   Code:    Stack=2, Locals=1, Args_size=1    0:   getstatic       #2; //Field java/lang/System.out:Ljava/io/PrintStream;    3:   ldc     #3; //String Hello, World!    5:   invokevirtual   #4; //Method java/io/PrintStream.println:(Ljava/lang/String;)V    8:   return   LineNumberTable:    line 4: 0    line 5: 8   LocalVariableTable:    Start  Length  Slot  Name   Signature    0      9      0    args       [Ljava/lang/String;
STACK MACHINE
Stack Machine
Stack Machine JVM is a stack-based machine
Stack Machine JVM is a stack-based machine Each thread has a stack
Stack Machine JVM is a stack-based machine Each thread has a stack Stack stores frames
Stack Machine JVM is a stack-based machine Each thread has a stack Stack stores frames Frame is created on method invocation
Stack Machine JVM is a stack-based machine Each thread has a stack Stack stores frames Frame is created on method invocation Frame consists of: Operand stack Array of local variables
The Frame Local variables N 1 2 3 … Operand stack #1 Constant  Pool
public java.lang.String getName();   Code:    Stack=1, Locals=1, Args_size=1    0:   aload_0    1:   getfield        #2; //Field name:Ljava/lang/String;    4:   areturn LocalVariableTable:    Start  Length  Slot  Name   Signature    0      5      0    this       LGet;
      0                1             2          3             4 areturn aload_0 00 02 getfield public java.lang.String getName();   Code:    Stack=1, Locals=1, Args_size=1    0:   aload_0    1:   getfield        #2; //Field name:Ljava/lang/String;    4:   areturn LocalVariableTable:    Start  Length  Slot  Name   Signature    0      5      0    this       LGet;
      0                1             2          3             4 B0 2A 00 02 B4 public java.lang.String getName();   Code:    Stack=1, Locals=1, Args_size=1    0:   aload_0    1:   getfield        #2; //Field name:Ljava/lang/String;    4:   areturn LocalVariableTable:    Start  Length  Slot  Name   Signature    0      5      0    this       LGet;
public java.lang.String getName();   Code:    Stack=1, Locals=1, Args_size=1    0:   aload_0    1:   getfield        #2; //Field name:Ljava/lang/String;    4:   areturn LocalVariableTable:    Start  Length  Slot  Name   Signature    0      5      0    this       LGet;
STACK CRUNCHING
A dup pop swap dup_x1 dup2_x2 B
A dup pop swap dup_x1 dup2_x2 A B
A dup pop swap dup_x1 dup2_x2 B
B dup pop swap dup_x1 dup2_x2 A
B dup pop swap dup_x1 dup2_x2 A B
B dup pop swap dup_x1 dup2_x2 A B B A
dup2_x2 How do you  swap doubles?
dup2_x2
dup2_x2 dconst_0 0.0
dup2_x2 dconst_0 dconst_1 1.0 0.0
dup2_x2 dconst_0 dconst_1 swap 1.0 0.0
dup2_x2 dconst_0 dconst_1 swap 1.0 not allowed! 0.0
dup2_x2 dconst_0 dconst_1 swap2 1.0 0.0
dup2_x2 dconst_0 dconst_1 swap2 1.0 doesn’t exist 0.0
dup2_x2 dconst_0 dconst_1 dup2_x2 1.0 0.0 1.0
dup2_x2 dconst_0 dconst_1 dup2_x2 pop2 0.0 1.0
dup2_x2 dconst_0 dconst_1 dup2_x2 pop2 0.0 1.0 profit!
LOCAL VARIABLES
Local Variables
public int calculate(int); Code:    Stack=2, Locals=2, Args_size=2     …   LocalVariableTable:    Start  Length  Slot  Name   Signature 0      5      0   this     LLocalVariables; 0      5     1  value   I Local Variables
public int calculate(int); Code:    Stack=2, Locals=2, Args_size=2     …   LocalVariableTable:    Start  Length  Slot  Name   Signature 0      5      0   this     LLocalVariables; 0      5     1  value   I numbered from 0 Local Variables
public int calculate(int); Code:    Stack=2, Locals=2, Args_size=2     …   LocalVariableTable:    Start  Length  Slot  Name   Signature 0      5      0   this     LLocalVariables; 0      5     1  value   I Local Variables instance methods have this at 0
The table maps numbers to names public int calculate(int); Code:    Stack=2, Locals=2, Args_size=2     …   LocalVariableTable:    Start  Length  Slot  Name   Signature 0      5      0   this     LLocalVariables; 0      5     1  value   I Local Variables
Sized explicitly public int calculate(int); Code:    Stack=2, Locals=2, Args_size=2     …   LocalVariableTable:    Start  Length  Slot  Name   Signature 0      5      0   this     LLocalVariables; 0      5     1  value   I Local Variables
Stack Local Variables value var value depth ldc"Hello" astore_0 iconst_1 astore_1 aload_0 0 0 1 1 2 2 3 3 4 4
Stack Local Variables value var value depth ldc"Hello" astore_0 iconst_1 astore_1 aload_0 0 0 "Hello" 1 1 2 2 3 3 4 4
Stack Local Variables value var value depth ldc"Hello" astore_0 iconst_1 astore_1 aload_0 "Hello" 0 0 1 1 2 2 3 3 4 4
Stack Local Variables value var value depth ldc"Hello" astore_0 iconst_1 astore_1 aload_0 "Hello" 0 0 1 1 1 2 2 3 3 4 4
Stack Local Variables value var value depth ldc"Hello" astore_0 iconst_1 astore_1 aload_0 "Hello" 0 0 1 1 1 2 2 3 3 4 4
Stack Local Variables value var value depth ldc"Hello" astore_0 iconst_1 astore_1 aload_0 "Hello" 0 0 "Hello" 1 1 1 2 2 3 3 4 4
load Stack Local Variables Table store
OBJECTS
new <init> <clinit> 0xBB Instance initialization method Class and interface initialization method Object Initialization
Object Initialization: static {} static {};   Code: 0:   iconst_1    1:   putstatic       #2; //Field a:I    4:   iconst_2    5:   putstatic       #3; //Field b:I    8:   return
Object Initialization: static {} <clinit> static {};   Code: 0:   iconst_1    1:   putstatic       #2; //Field a:I    4:   iconst_2    5:   putstatic       #3; //Field b:I    8:   return
Object Initialization: new
Object Initialization: new public Initializer(); Code:
Object Initialization: new public Initializer(); Code:    0:   aload_0
Object Initialization: new public Initializer(); Code:    0:   aload_0    1:   invokespecial   #1; //Method java/lang/Object."<init>":()V
Object Initialization: new public Initializer(); Code:    0:   aload_0    1:   invokespecial   #1; //Method java/lang/Object."<init>":()V    4:   aload_0
Object Initialization: new public Initializer(); Code:    0:   aload_0    1:   invokespecial   #1; //Method java/lang/Object."<init>":()V    4:   aload_0    5:   new#2; //class java/lang/Object    8:   dup
Object Initialization: new public Initializer(); Code:    0:   aload_0    1:   invokespecial   #1; //Method java/lang/Object."<init>":()V    4:   aload_0    5:   new#2; //class java/lang/Object    8:   dup    9:   invokespecial   #1; //Method java/lang/Object."<init>":()V 12: putfield        #3; //Field o:Ljava/lang/Object;
Object Initialization: new public Initializer(); Code:    0:   aload_0    1:   invokespecial   #1; //Method java/lang/Object."<init>":()V    4:   aload_0    5:   new#2; //class java/lang/Object    8:   dup    9:   invokespecial   #1; //Method java/lang/Object."<init>":()V 12: putfield        #3; //Field o:Ljava/lang/Object; 15:  return
Object Initialization: new public Initializer(); Code:    0:   aload_0    1:   invokespecial   #1; //Method java/lang/Object."<init>":()V    4:   aload_0    5:   new#2; //class java/lang/Object    8:   dup    9:   invokespecial   #1; //Method java/lang/Object."<init>":()V 12: putfield        #3; //Field o:Ljava/lang/Object; 15:  return
Object Initialization: {}
Object Initialization: {} ?
Object Initialization: {} public Initializer(int);   Code: 0:aload_0    1:invokespecial   #1; // ..<init> 4:aload_0    5:iconst_1    6:putfield        #2; //Field a:I    9:aload_0 10:iconst_2  11:putfield        #3; //Field c:I  14:aload_0 15:iload_1 16:putfield        #4; //Field b:I 19:return
There’s no initializer
METHOD INVOCATION&PARAMETER PASSING
Methods & Parameters invokestatic invokespecial invokevirtual invokeinterface invokedynamic Efficient Implementation of Java Interfaces: Invokeinterface Considered Harmless,  Bowen Alpern, Anthony Cocchi, Stephen Fink, David Grove, and Derek Lieber, OOPSLA’01
Methods & Parameters invokestatic invokespecial invokevirtual invokeinterface invokedynamic Integer.valueOf(“42”) Efficient Implementation of Java Interfaces: Invokeinterface Considered Harmless,  Bowen Alpern, Anthony Cocchi, Stephen Fink, David Grove, and Derek Lieber, OOPSLA’01
Methods & Parameters invokestatic invokespecial invokevirtual invokeinterface invokedynamic <init> private void foo(); super.method(); Efficient Implementation of Java Interfaces: Invokeinterface Considered Harmless,  Bowen Alpern, Anthony Cocchi, Stephen Fink, David Grove, and Derek Lieber, OOPSLA’01
Methods & Parameters invokestatic invokespecial invokevirtual invokeinterface invokedynamic class A A/method1 A/method2 Efficient Implementation of Java Interfaces: Invokeinterface Considered Harmless,  Bowen Alpern, Anthony Cocchi, Stephen Fink, David Grove, and Derek Lieber, OOPSLA’01
Methods & Parameters invokestatic invokespecial invokevirtual invokeinterface invokedynamic class A A/method1 A/method2 class B Efficient Implementation of Java Interfaces: Invokeinterface Considered Harmless,  Bowen Alpern, Anthony Cocchi, Stephen Fink, David Grove, and Derek Lieber, OOPSLA’01
Methods & Parameters invokestatic invokespecial invokevirtual invokeinterface invokedynamic class A A/method1 A/method2 class B A/method1 B/method2 B/method3 Efficient Implementation of Java Interfaces: Invokeinterface Considered Harmless,  Bowen Alpern, Anthony Cocchi, Stephen Fink, David Grove, and Derek Lieber, OOPSLA’01
Methods & Parameters invokestatic invokespecial invokevirtual invokeinterface invokedynamic class A A/method1 A/method2 class B impl X A/method1 B/method2 B/method3 X/methodX Efficient Implementation of Java Interfaces: Invokeinterface Considered Harmless,  Bowen Alpern, Anthony Cocchi, Stephen Fink, David Grove, and Derek Lieber, OOPSLA’01
Methods & Parameters invokestatic invokespecial invokevirtual invokeinterface invokedynamic class A A/method1 A/method2 class B impl X A/method1 B/method2 B/method3 X/methodX class D impl X D/method1 X/methodX Efficient Implementation of Java Interfaces: Invokeinterface Considered Harmless,  Bowen Alpern, Anthony Cocchi, Stephen Fink, David Grove, and Derek Lieber, OOPSLA’01
Methods & Parameters invokestatic invokespecial invokevirtual invokeinterface invokedynamic class A A/method1 A/method2 class B impl X A/method1 B/method2 B/method3 X/methodX class D impl X D/method1 X/methodX Efficient Implementation of Java Interfaces: Invokeinterface Considered Harmless,  Bowen Alpern, Anthony Cocchi, Stephen Fink, David Grove, and Derek Lieber, OOPSLA’01
Methods & Parameters invokestatic invokespecial invokevirtual invokeinterface invokedynamic Efficient Implementation of Java Interfaces: Invokeinterface Considered Harmless,  Bowen Alpern, Anthony Cocchi, Stephen Fink, David Grove, and Derek Lieber, OOPSLA’01
Method Invocation obj.method(param1, param2);
Method Invocation obj.method(param1, param2); push obj push param1 push param2 call method
Method Invocation obj.method(param1, param2); obj push obj push param1 push param2 call method
Method Invocation obj.method(param1, param2); param1 push obj push param1 push param2 call method obj
Method Invocation obj.method(param1, param2); param2 push obj push param1 push param2 call method param1 obj
Method Invocation obj.method(param1, param2); obj? push obj push param1 push param2 call method
Method Invocation this.add(1, 2); 0:   aload_0 1:   iconst_1 2:   iconst_2 3:   invokevirtual   #2; //Method add:(II)I
INNER CLASSES
Inner Classes
Inner Classes
Inner Classes class Car$Engine extends j.l.Object{ final Car this$0; Car$Engine(Car); public void start(); Code:    0:   aload_0    1:   getfield        #1; //Field this$0:LCar;    4:   invokestatic    #3; //Car.access$000:(LCar;)V    7:   return }
Inner Classes public class Car extends j.l.Object{ public Car(); private void move(); static void access$000(Car); Code:    0:   aload_0    1:   invokespecial   #1; // move: ()V;    4:   return } class Car$Engine extends j.l.Object{ final Car this$0; Car$Engine(Car); public void start(); Code:    0:   aload_0    1:   getfield        #1; //Field this$0:LCar;    4:   invokestatic    #3; //Car.access$000:(LCar;)V    7:   return }
Inner Classes public class Car extends j.l.Object{ public Car(); private void move(); static void access$000(Car); Code:    0:   aload_0    1:   invokespecial   #1; // move: ()V;    4:   return } class Car$Engine extends j.l.Object{ final Car this$0; Car$Engine(Car); public void start(); Code:    0:   aload_0    1:   getfield        #1; //Field this$0:LCar;    4:   invokestatic    #3; //Car.access$000:(LCar;)V    7:   return }
“HOW DO THEY DO THAT?”
object Singleton { def test={} }
object Singleton { def test={} } $> scalacSingleton.scala Singleton.class Singleton$.class
public final class Singleton extends java.lang.Object{ public static final void test(); Code: 0:   getstatic       #11; //Field Singleton$.MODULE$:LSingleton$;    3:   invokevirtual   #13; //Method Singleton$.test:()V    6:   return }
public final class Singleton extends java.lang.Object{ public static final void test(); Code: 0:   getstatic       #11; //Field Singleton$.MODULE$:LSingleton$;    3:   invokevirtual   #13; //Method Singleton$.test:()V    6:   return }
public final class Singleton extends java.lang.Object{ public static final void test(); Code: 0:   getstatic       #11; //Field Singleton$.MODULE$:LSingleton$;    3:   invokevirtual   #13; //Method Singleton$.test:()V    6:   return }
public final class Singleton extends java.lang.Object{ public static final void test(); Code: 0:   getstatic       #11; //Field Singleton$.MODULE$:LSingleton$;    3:   invokevirtual   #13; //Method Singleton$.test:()V    6:   return } public final class Singleton$ extends java.lang.Object implements scala.ScalaObject{ public static final Singleton$ MODULE$; public static {};   Code:    0:   new     #9; //class Singleton$    3:   invokespecial   #12; //Method "<init>":()V    6:   return public void test(); private Singleton$(); }
public final class Singleton extends java.lang.Object{ public static final void test(); Code: 0:   getstatic       #11; //Field Singleton$.MODULE$:LSingleton$;    3:   invokevirtual   #13; //Method Singleton$.test:()V    6:   return } public final class Singleton$ extends java.lang.Object implements scala.ScalaObject{ public static final Singleton$ MODULE$; public static {};   Code:    0:   new     #9; //class Singleton$    3:   invokespecial   #12; //Method "<init>":()V    6:   return public void test(); private Singleton$(); }
public final class Singleton extends java.lang.Object{ public static final void test(); Code: 0:   getstatic       #11; //Field Singleton$.MODULE$:LSingleton$;    3:   invokevirtual   #13; //Method Singleton$.test:()V    6:   return } public final class Singleton$ extends java.lang.Object implements scala.ScalaObject{ public static final Singleton$ MODULE$; public static {};   Code:    0:   new     #9; //class Singleton$    3:   invokespecial   #12; //Method "<init>":()V    6:   return public void test(); private Singleton$(); }
public final class Singleton extends java.lang.Object{ public static final void test(); Code: 0:   getstatic       #11; //Field Singleton$.MODULE$:LSingleton$;    3:   invokevirtual   #13; //Method Singleton$.test:()V    6:   return } public final class Singleton$ extends java.lang.Object implements scala.ScalaObject{ public static final Singleton$ MODULE$; public static {}; public void test(); private Singleton$();  Code:    0:   aload_0    1:   invokespecial#17; //Method java/lang/Object."<init>":()V    4:   aload_0    5:   putstatic#19; //Field MODULE$:LSingleton$;    8:   return
object Singleton { def test={} }
publicclassSingleton { publicvoid test(){ Singleton$.MODULE$.test();   } } object Singleton { def test={} }
publicclassSingleton { publicvoid test(){ Singleton$.MODULE$.test();   } } public final class Singleton$  implements scala.ScalaObject{ public static final Singleton$ MODULE$;     static { newSingleton$(); } private Singleton$(){ MODULE$ = this;     } public void test() {      } } object Singleton { def test={} }
classGroovy {}
classGroovy {} $> groovycGroovy.groovy $> javap –c –p Groovy
classGroovy {} $> groovycGroovy.groovy $> javap –c –p Groovy public class Test extends java.lang.Object implements groovy.lang.GroovyObject{     private static org.codehaus.groovy.reflection.ClassInfo $staticClassInfo;     private transient groovy.lang.MetaClass metaClass;     public static java.lang.Long __timeStamp;     public static java.lang.Long __timeStamp__239_neverHappen1304807931117;     private static java.lang.ref.SoftReference $callSiteArray;     private static java.lang.Class $class$groovy$lang$MetaClass;     private static java.lang.Class $class$Test;     private static java.lang.Class $class$java$lang$String; public java.lang.Object this$dist$invoke$2(java.lang.String, java.lang.Object);     public void this$dist$set$2(java.lang.String, java.lang.Object);     public java.lang.Object this$dist$get$2(java.lang.String);     protected groovy.lang.MetaClass $getStaticMetaClass();     public groovy.lang.MetaClass getMetaClass();     public void setMetaClass(groovy.lang.MetaClass);     public java.lang.Object invokeMethod(java.lang.String, java.lang.Object);     public java.lang.Object getProperty(java.lang.String);     public void setProperty(java.lang.String, java.lang.Object);
CRASH! BOOM! BANG!
Javassist Bytecode manipulation made easy Source-level and bytecode-level API Uses the vocabulary of Java language On-the-fly compilation of the injected code http://www.jboss.org/javassist
for(inti = 0; i < 100; i++){  inta = 0;   try {      while (true) {      a++;      foo(a);       if(a > 1) break;     }    } catch (Exception e) {    } }
for(inti = 0; i < 100; i++){  inta = 0; try {      while (true) {      a++;      foo(a);       if(a > 1) break;     }    } catch (Exception e) {    } }
for(inti = 0; i < 100; i++){  inta = 0; try{  while (true) {      a++;      foo(a);       if(a > 1) break;     }    } catch (Exception e) {    } }
for(inti = 0; i < 100; i++){  inta = 0; try{  while(true) { a++;      foo(a);       if(a > 1) break;     }    } catch (Exception e) {    } }
for(inti = 0; i < 100; i++){  inta = 0; try{  while(true) {      a++; foo(a);       if(a > 1) break;     }    } catch (Exception e) {    } }
Javassist CtMethod method = … method.setBody(“ for(inti = 0; i < 100; i++){  inta = 0;   try {      while (true) {      a++;      foo(a);       if(a > 1) break;     }    } catch (Exception e) {    } }”);
-noverify
# # A fatal error has been detected by the Java Runtime Environment: # #  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at  #  pc=0x01adff06, pid=7732, tid=868 # # JRE version: 6.0_21-b07 # Java VM: Java HotSpot(TM) Client VM (17.0-b17 mixed mode,  #   sharing windows-x86 ) # Problematic frame: # j  zt.javassist.My.test()V+20 # # An error report file with more information is saved as: # C:orkuzzlerss_err_pid7732.log # # If you would like to submit a bug report, please visit: #   http://java.sun.com/webapps/bugreport/crash.jsp # -noverify
Exception in thread "main" java.lang.VerifyError: (class: zt/javassist/My, method: test signature: ()V) Inconsistent stack height 0 != 1 -Xverify:all
public void test();   Code:    Stack=2, Locals=4, Args_size=1    0:   iconst_0    1:   istore_1    2:   iload_1    3:   bipush  100    5:   if_icmpge       42    8:   iconst_0    9:   istore_2    10:  goto    29    13:  iinc    2, 1    16:  aload_0    17:  iload_2    18:  invokevirtual   #23; //Method zt/javassist/My.foo:(I)V    21:  iload_2    22:  iconst_1    23:  if_icmple       29    26:  goto    32    29:  goto    13    32:  astore_3    33:  goto    36    36:  iinc    1, 1    39:  goto    2    42:  return   Exception table:    from   to  target type     10    32    32   Class java/lang/Exception
public void test();   Code:    Stack=2, Locals=4, Args_size=1    0:   iconst_0    1:   istore_1    2:   iload_1    3:   bipush  100    5:   if_icmpge       42    8:   iconst_0    9:   istore_2    10:  goto    29    13:  iinc    2, 1    16:  aload_0    17:  iload_2    18:  invokevirtual   #23; //Method zt/javassist/My.foo:(I)V    21:  iload_2    22:  iconst_1    23:  if_icmple       29    26:  goto    32    29:  goto    13    32:  astore_3    33:  goto    36    36:  iinc    1, 1    39:  goto    2    42:  return   Exception table:    from   to  target type     10    32    32   Class java/lang/Exception No local  variables table
public void test();   Code:    Stack=2, Locals=4, Args_size=1    0:   iconst_0    1:   istore_1    2:   iload_1    3:   bipush  100    5:   if_icmpge       42    8:   iconst_0    9:   istore_2    10:  goto    29    13:  iinc    2, 1    16:  aload_0    17:  iload_2    18:  invokevirtual   #23; //Method zt/javassist/My.foo:(I)V    21:  iload_2    22:  iconst_1    23:  if_icmple       29    26:  goto    32    29:  goto    13    32:  astore_3    33:  goto    36    36:  iinc    1, 1    39:  goto    2    42:  return   Exception table:    from   to  target type     10    32    32   Class java/lang/Exception No local  variables table
Q/A

Weitere ähnliche Inhalte

Was ist angesagt?

Making Java more dynamic: runtime code generation for the JVM
Making Java more dynamic: runtime code generation for the JVMMaking Java more dynamic: runtime code generation for the JVM
Making Java more dynamic: runtime code generation for the JVMRafael Winterhalter
 
Building a java tracer
Building a java tracerBuilding a java tracer
Building a java tracerrahulrevo
 
Con-FESS 2015 - Having Fun With Javassist
Con-FESS 2015 - Having Fun With JavassistCon-FESS 2015 - Having Fun With Javassist
Con-FESS 2015 - Having Fun With JavassistAnton Arhipov
 
Oredev 2015 - Taming Java Agents
Oredev 2015 - Taming Java AgentsOredev 2015 - Taming Java Agents
Oredev 2015 - Taming Java AgentsAnton Arhipov
 
Getting started with Java 9 modules
Getting started with Java 9 modulesGetting started with Java 9 modules
Getting started with Java 9 modulesRafael Winterhalter
 
Mashups with Drupal and QueryPath
Mashups with Drupal and QueryPathMashups with Drupal and QueryPath
Mashups with Drupal and QueryPathMatt Butcher
 
Java and OpenJDK: disecting the ecosystem
Java and OpenJDK: disecting the ecosystemJava and OpenJDK: disecting the ecosystem
Java and OpenJDK: disecting the ecosystemRafael Winterhalter
 
Monitoring distributed (micro-)services
Monitoring distributed (micro-)servicesMonitoring distributed (micro-)services
Monitoring distributed (micro-)servicesRafael Winterhalter
 
Inside the JVM - Follow the white rabbit!
Inside the JVM - Follow the white rabbit!Inside the JVM - Follow the white rabbit!
Inside the JVM - Follow the white rabbit!Sylvain Wallez
 
Using Java from Ruby with JRuby IRB
Using Java from Ruby with JRuby IRBUsing Java from Ruby with JRuby IRB
Using Java from Ruby with JRuby IRBHiro Asari
 
Jdk 7 4-forkjoin
Jdk 7 4-forkjoinJdk 7 4-forkjoin
Jdk 7 4-forkjoinknight1128
 
JRuby in Java Projects
JRuby in Java ProjectsJRuby in Java Projects
JRuby in Java Projectsjazzman1980
 
JVM for Dummies - OSCON 2011
JVM for Dummies - OSCON 2011JVM for Dummies - OSCON 2011
JVM for Dummies - OSCON 2011Charles Nutter
 
The definitive guide to java agents
The definitive guide to java agentsThe definitive guide to java agents
The definitive guide to java agentsRafael Winterhalter
 
Code generation for alternative languages
Code generation for alternative languagesCode generation for alternative languages
Code generation for alternative languagesRafael Winterhalter
 
Lambda Chops - Recipes for Simpler, More Expressive Code
Lambda Chops - Recipes for Simpler, More Expressive CodeLambda Chops - Recipes for Simpler, More Expressive Code
Lambda Chops - Recipes for Simpler, More Expressive CodeIan Robertson
 

Was ist angesagt? (20)

Making Java more dynamic: runtime code generation for the JVM
Making Java more dynamic: runtime code generation for the JVMMaking Java more dynamic: runtime code generation for the JVM
Making Java more dynamic: runtime code generation for the JVM
 
Building a java tracer
Building a java tracerBuilding a java tracer
Building a java tracer
 
Con-FESS 2015 - Having Fun With Javassist
Con-FESS 2015 - Having Fun With JavassistCon-FESS 2015 - Having Fun With Javassist
Con-FESS 2015 - Having Fun With Javassist
 
JVM
JVMJVM
JVM
 
Oredev 2015 - Taming Java Agents
Oredev 2015 - Taming Java AgentsOredev 2015 - Taming Java Agents
Oredev 2015 - Taming Java Agents
 
Getting started with Java 9 modules
Getting started with Java 9 modulesGetting started with Java 9 modules
Getting started with Java 9 modules
 
Mashups with Drupal and QueryPath
Mashups with Drupal and QueryPathMashups with Drupal and QueryPath
Mashups with Drupal and QueryPath
 
Java and OpenJDK: disecting the ecosystem
Java and OpenJDK: disecting the ecosystemJava and OpenJDK: disecting the ecosystem
Java and OpenJDK: disecting the ecosystem
 
Monitoring distributed (micro-)services
Monitoring distributed (micro-)servicesMonitoring distributed (micro-)services
Monitoring distributed (micro-)services
 
Inside the JVM - Follow the white rabbit!
Inside the JVM - Follow the white rabbit!Inside the JVM - Follow the white rabbit!
Inside the JVM - Follow the white rabbit!
 
Using Java from Ruby with JRuby IRB
Using Java from Ruby with JRuby IRBUsing Java from Ruby with JRuby IRB
Using Java from Ruby with JRuby IRB
 
Jdk 7 4-forkjoin
Jdk 7 4-forkjoinJdk 7 4-forkjoin
Jdk 7 4-forkjoin
 
JRuby in Java Projects
JRuby in Java ProjectsJRuby in Java Projects
JRuby in Java Projects
 
JVM for Dummies - OSCON 2011
JVM for Dummies - OSCON 2011JVM for Dummies - OSCON 2011
JVM for Dummies - OSCON 2011
 
Java 10, Java 11 and beyond
Java 10, Java 11 and beyondJava 10, Java 11 and beyond
Java 10, Java 11 and beyond
 
The definitive guide to java agents
The definitive guide to java agentsThe definitive guide to java agents
The definitive guide to java agents
 
Code generation for alternative languages
Code generation for alternative languagesCode generation for alternative languages
Code generation for alternative languages
 
Java concurrency questions and answers
Java concurrency questions and answers Java concurrency questions and answers
Java concurrency questions and answers
 
Lambda Chops - Recipes for Simpler, More Expressive Code
Lambda Chops - Recipes for Simpler, More Expressive CodeLambda Chops - Recipes for Simpler, More Expressive Code
Lambda Chops - Recipes for Simpler, More Expressive Code
 
Project Coin
Project CoinProject Coin
Project Coin
 

Andere mochten auch

JavaOne 2010: Top 10 Causes for Java Issues in Production and What to Do When...
JavaOne 2010: Top 10 Causes for Java Issues in Production and What to Do When...JavaOne 2010: Top 10 Causes for Java Issues in Production and What to Do When...
JavaOne 2010: Top 10 Causes for Java Issues in Production and What to Do When...srisatish ambati
 
JVM, byte codes & jvm languages
JVM, byte codes & jvm languagesJVM, byte codes & jvm languages
JVM, byte codes & jvm languagesEdgar Espina
 
JavaOne 2012 CON 3961 Innovative Testing Techniques Using Bytecode Instrument...
JavaOne 2012 CON 3961 Innovative Testing Techniques Using Bytecode Instrument...JavaOne 2012 CON 3961 Innovative Testing Techniques Using Bytecode Instrument...
JavaOne 2012 CON 3961 Innovative Testing Techniques Using Bytecode Instrument...PaulThwaite
 
Java 5 6 Generics, Concurrency, Garbage Collection, Tuning
Java 5 6 Generics, Concurrency, Garbage Collection, TuningJava 5 6 Generics, Concurrency, Garbage Collection, Tuning
Java 5 6 Generics, Concurrency, Garbage Collection, TuningCarol McDonald
 
Programming JVM Bytecode
Programming JVM BytecodeProgramming JVM Bytecode
Programming JVM BytecodeJoe Kutner
 
GC @ jmaghreb2014
GC @ jmaghreb2014GC @ jmaghreb2014
GC @ jmaghreb2014Ivan Krylov
 
LatJUG. Java Bytecode Fundamentals
LatJUG. Java Bytecode FundamentalsLatJUG. Java Bytecode Fundamentals
LatJUG. Java Bytecode Fundamentalsdenis Udod
 
Introduction to the Java bytecode - So@t - 20130924
Introduction to the Java bytecode - So@t - 20130924Introduction to the Java bytecode - So@t - 20130924
Introduction to the Java bytecode - So@t - 20130924yohanbeschi
 
JVM bytecode - The secret language behind Java and Scala
JVM bytecode - The secret language behind Java and ScalaJVM bytecode - The secret language behind Java and Scala
JVM bytecode - The secret language behind Java and ScalaTakipi
 
Java bytecode and classes
Java bytecode and classesJava bytecode and classes
Java bytecode and classesyoavwix
 
Garbage Collection Pause Times - Angelika Langer
Garbage Collection Pause Times - Angelika LangerGarbage Collection Pause Times - Angelika Langer
Garbage Collection Pause Times - Angelika LangerJAXLondon_Conference
 
Understanding Java Garbage Collection
Understanding Java Garbage CollectionUnderstanding Java Garbage Collection
Understanding Java Garbage CollectionAzul Systems Inc.
 
GC Tuning in the HotSpot Java VM - a FISL 10 Presentation
GC Tuning in the HotSpot Java VM - a FISL 10 PresentationGC Tuning in the HotSpot Java VM - a FISL 10 Presentation
GC Tuning in the HotSpot Java VM - a FISL 10 PresentationLudovic Poitou
 
Understanding Java Garbage Collection - And What You Can Do About It
Understanding Java Garbage Collection - And What You Can Do About ItUnderstanding Java Garbage Collection - And What You Can Do About It
Understanding Java Garbage Collection - And What You Can Do About ItAzul Systems Inc.
 
[Jbcn 2016] Garbage Collectors WTF!?
[Jbcn 2016] Garbage Collectors WTF!?[Jbcn 2016] Garbage Collectors WTF!?
[Jbcn 2016] Garbage Collectors WTF!?Alonso Torres
 
Make Java Profilers Lie Less
Make Java Profilers Lie LessMake Java Profilers Lie Less
Make Java Profilers Lie LessJaroslav Bachorik
 
GeeCon2016- High Performance Instrumentation (handout)
GeeCon2016- High Performance Instrumentation (handout)GeeCon2016- High Performance Instrumentation (handout)
GeeCon2016- High Performance Instrumentation (handout)Jaroslav Bachorik
 

Andere mochten auch (17)

JavaOne 2010: Top 10 Causes for Java Issues in Production and What to Do When...
JavaOne 2010: Top 10 Causes for Java Issues in Production and What to Do When...JavaOne 2010: Top 10 Causes for Java Issues in Production and What to Do When...
JavaOne 2010: Top 10 Causes for Java Issues in Production and What to Do When...
 
JVM, byte codes & jvm languages
JVM, byte codes & jvm languagesJVM, byte codes & jvm languages
JVM, byte codes & jvm languages
 
JavaOne 2012 CON 3961 Innovative Testing Techniques Using Bytecode Instrument...
JavaOne 2012 CON 3961 Innovative Testing Techniques Using Bytecode Instrument...JavaOne 2012 CON 3961 Innovative Testing Techniques Using Bytecode Instrument...
JavaOne 2012 CON 3961 Innovative Testing Techniques Using Bytecode Instrument...
 
Java 5 6 Generics, Concurrency, Garbage Collection, Tuning
Java 5 6 Generics, Concurrency, Garbage Collection, TuningJava 5 6 Generics, Concurrency, Garbage Collection, Tuning
Java 5 6 Generics, Concurrency, Garbage Collection, Tuning
 
Programming JVM Bytecode
Programming JVM BytecodeProgramming JVM Bytecode
Programming JVM Bytecode
 
GC @ jmaghreb2014
GC @ jmaghreb2014GC @ jmaghreb2014
GC @ jmaghreb2014
 
LatJUG. Java Bytecode Fundamentals
LatJUG. Java Bytecode FundamentalsLatJUG. Java Bytecode Fundamentals
LatJUG. Java Bytecode Fundamentals
 
Introduction to the Java bytecode - So@t - 20130924
Introduction to the Java bytecode - So@t - 20130924Introduction to the Java bytecode - So@t - 20130924
Introduction to the Java bytecode - So@t - 20130924
 
JVM bytecode - The secret language behind Java and Scala
JVM bytecode - The secret language behind Java and ScalaJVM bytecode - The secret language behind Java and Scala
JVM bytecode - The secret language behind Java and Scala
 
Java bytecode and classes
Java bytecode and classesJava bytecode and classes
Java bytecode and classes
 
Garbage Collection Pause Times - Angelika Langer
Garbage Collection Pause Times - Angelika LangerGarbage Collection Pause Times - Angelika Langer
Garbage Collection Pause Times - Angelika Langer
 
Understanding Java Garbage Collection
Understanding Java Garbage CollectionUnderstanding Java Garbage Collection
Understanding Java Garbage Collection
 
GC Tuning in the HotSpot Java VM - a FISL 10 Presentation
GC Tuning in the HotSpot Java VM - a FISL 10 PresentationGC Tuning in the HotSpot Java VM - a FISL 10 Presentation
GC Tuning in the HotSpot Java VM - a FISL 10 Presentation
 
Understanding Java Garbage Collection - And What You Can Do About It
Understanding Java Garbage Collection - And What You Can Do About ItUnderstanding Java Garbage Collection - And What You Can Do About It
Understanding Java Garbage Collection - And What You Can Do About It
 
[Jbcn 2016] Garbage Collectors WTF!?
[Jbcn 2016] Garbage Collectors WTF!?[Jbcn 2016] Garbage Collectors WTF!?
[Jbcn 2016] Garbage Collectors WTF!?
 
Make Java Profilers Lie Less
Make Java Profilers Lie LessMake Java Profilers Lie Less
Make Java Profilers Lie Less
 
GeeCon2016- High Performance Instrumentation (handout)
GeeCon2016- High Performance Instrumentation (handout)GeeCon2016- High Performance Instrumentation (handout)
GeeCon2016- High Performance Instrumentation (handout)
 

Ähnlich wie Java Bytecode For Discriminating Developers - GeeCON 2011

Java Bytecode Fundamentals - JUG.lv
Java Bytecode Fundamentals - JUG.lvJava Bytecode Fundamentals - JUG.lv
Java Bytecode Fundamentals - JUG.lvAnton Arhipov
 
Inside the JVM - Follow the white rabbit! / Breizh JUG
Inside the JVM - Follow the white rabbit! / Breizh JUGInside the JVM - Follow the white rabbit! / Breizh JUG
Inside the JVM - Follow the white rabbit! / Breizh JUGSylvain Wallez
 
No dark magic - Byte code engineering in the real world
No dark magic - Byte code engineering in the real worldNo dark magic - Byte code engineering in the real world
No dark magic - Byte code engineering in the real worldtcurdt
 
Advanced debugging  techniques in different environments
Advanced debugging  techniques in different environmentsAdvanced debugging  techniques in different environments
Advanced debugging  techniques in different environmentsAndrii Soldatenko
 
Fast as C: How to Write Really Terrible Java
Fast as C: How to Write Really Terrible JavaFast as C: How to Write Really Terrible Java
Fast as C: How to Write Really Terrible JavaCharles Nutter
 
Building native Android applications with Mirah and Pindah
Building native Android applications with Mirah and PindahBuilding native Android applications with Mirah and Pindah
Building native Android applications with Mirah and PindahNick Plante
 
Introduction to Software Development
Introduction to Software DevelopmentIntroduction to Software Development
Introduction to Software DevelopmentZeeshan MIrza
 
Decompiling Java - SCAM2009 Presentation
Decompiling Java - SCAM2009 PresentationDecompiling Java - SCAM2009 Presentation
Decompiling Java - SCAM2009 PresentationJames Hamilton
 
Advanced Debugging Using Java Bytecodes
Advanced Debugging Using Java BytecodesAdvanced Debugging Using Java Bytecodes
Advanced Debugging Using Java BytecodesGanesh Samarthyam
 
Devoxx France: Développement JAVA avec un IDE dans le Cloud: Yes we can !
Devoxx France: Développement JAVA avec un IDE dans le Cloud: Yes we can !Devoxx France: Développement JAVA avec un IDE dans le Cloud: Yes we can !
Devoxx France: Développement JAVA avec un IDE dans le Cloud: Yes we can !Florent BENOIT
 
Monkeybars in the Manor
Monkeybars in the ManorMonkeybars in the Manor
Monkeybars in the Manormartinbtt
 
Unit of competency
Unit of competencyUnit of competency
Unit of competencyloidasacueza
 
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...Guillaume Laforge
 

Ähnlich wie Java Bytecode For Discriminating Developers - GeeCON 2011 (20)

Java Bytecode Fundamentals - JUG.lv
Java Bytecode Fundamentals - JUG.lvJava Bytecode Fundamentals - JUG.lv
Java Bytecode Fundamentals - JUG.lv
 
In Vogue Dynamic
In Vogue DynamicIn Vogue Dynamic
In Vogue Dynamic
 
Inside the JVM - Follow the white rabbit! / Breizh JUG
Inside the JVM - Follow the white rabbit! / Breizh JUGInside the JVM - Follow the white rabbit! / Breizh JUG
Inside the JVM - Follow the white rabbit! / Breizh JUG
 
Pimp My Java LavaJUG
Pimp My Java LavaJUGPimp My Java LavaJUG
Pimp My Java LavaJUG
 
No dark magic - Byte code engineering in the real world
No dark magic - Byte code engineering in the real worldNo dark magic - Byte code engineering in the real world
No dark magic - Byte code engineering in the real world
 
Advanced debugging  techniques in different environments
Advanced debugging  techniques in different environmentsAdvanced debugging  techniques in different environments
Advanced debugging  techniques in different environments
 
Fast as C: How to Write Really Terrible Java
Fast as C: How to Write Really Terrible JavaFast as C: How to Write Really Terrible Java
Fast as C: How to Write Really Terrible Java
 
Building native Android applications with Mirah and Pindah
Building native Android applications with Mirah and PindahBuilding native Android applications with Mirah and Pindah
Building native Android applications with Mirah and Pindah
 
Introduction to Software Development
Introduction to Software DevelopmentIntroduction to Software Development
Introduction to Software Development
 
Javalecture 1
Javalecture 1Javalecture 1
Javalecture 1
 
Java introduction
Java introductionJava introduction
Java introduction
 
Decompiling Java - SCAM2009 Presentation
Decompiling Java - SCAM2009 PresentationDecompiling Java - SCAM2009 Presentation
Decompiling Java - SCAM2009 Presentation
 
A Life of breakpoint
A Life of breakpointA Life of breakpoint
A Life of breakpoint
 
Demystifying Maven
Demystifying MavenDemystifying Maven
Demystifying Maven
 
Advanced Debugging Using Java Bytecodes
Advanced Debugging Using Java BytecodesAdvanced Debugging Using Java Bytecodes
Advanced Debugging Using Java Bytecodes
 
Jsp
JspJsp
Jsp
 
Devoxx France: Développement JAVA avec un IDE dans le Cloud: Yes we can !
Devoxx France: Développement JAVA avec un IDE dans le Cloud: Yes we can !Devoxx France: Développement JAVA avec un IDE dans le Cloud: Yes we can !
Devoxx France: Développement JAVA avec un IDE dans le Cloud: Yes we can !
 
Monkeybars in the Manor
Monkeybars in the ManorMonkeybars in the Manor
Monkeybars in the Manor
 
Unit of competency
Unit of competencyUnit of competency
Unit of competency
 
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...
 

Mehr von Anton Arhipov

JavaZone 2022 - Building Kotlin DSL.pdf
JavaZone 2022 - Building Kotlin DSL.pdfJavaZone 2022 - Building Kotlin DSL.pdf
JavaZone 2022 - Building Kotlin DSL.pdfAnton Arhipov
 
TechTrain 2019 - (Не)адекватное техническое интервью
TechTrain 2019 - (Не)адекватное техническое интервьюTechTrain 2019 - (Не)адекватное техническое интервью
TechTrain 2019 - (Не)адекватное техническое интервьюAnton Arhipov
 
Build pipelines with TeamCity
Build pipelines with TeamCityBuild pipelines with TeamCity
Build pipelines with TeamCityAnton Arhipov
 
Build pipelines with TeamCity
Build pipelines with TeamCityBuild pipelines with TeamCity
Build pipelines with TeamCityAnton Arhipov
 
Devoxx Ukraine 2018 - Kotlin DSL in under an hour
Devoxx Ukraine 2018 - Kotlin DSL in under an hourDevoxx Ukraine 2018 - Kotlin DSL in under an hour
Devoxx Ukraine 2018 - Kotlin DSL in under an hourAnton Arhipov
 
GeeCON Prague 2018 - Kotlin DSL in under an hour
GeeCON Prague 2018 - Kotlin DSL in under an hourGeeCON Prague 2018 - Kotlin DSL in under an hour
GeeCON Prague 2018 - Kotlin DSL in under an hourAnton Arhipov
 
Build pipelines with TeamCity and Kotlin DSL
Build pipelines with TeamCity and Kotlin DSLBuild pipelines with TeamCity and Kotlin DSL
Build pipelines with TeamCity and Kotlin DSLAnton Arhipov
 
Build pipelines with TeamCity
Build pipelines with TeamCityBuild pipelines with TeamCity
Build pipelines with TeamCityAnton Arhipov
 
JavaDay Kiev 2017 - Integration testing with TestContainers
JavaDay Kiev 2017 - Integration testing with TestContainersJavaDay Kiev 2017 - Integration testing with TestContainers
JavaDay Kiev 2017 - Integration testing with TestContainersAnton Arhipov
 
GeeCON Prague 2017 - TestContainers
GeeCON Prague 2017 - TestContainersGeeCON Prague 2017 - TestContainers
GeeCON Prague 2017 - TestContainersAnton Arhipov
 
JavaOne 2017 - The hitchhiker’s guide to Java class reloading
JavaOne 2017 - The hitchhiker’s guide to Java class reloadingJavaOne 2017 - The hitchhiker’s guide to Java class reloading
JavaOne 2017 - The hitchhiker’s guide to Java class reloadingAnton Arhipov
 
JavaOne 2017 - TestContainers: integration testing without the hassle
JavaOne 2017 - TestContainers: integration testing without the hassleJavaOne 2017 - TestContainers: integration testing without the hassle
JavaOne 2017 - TestContainers: integration testing without the hassleAnton Arhipov
 
JavaOne 2017 - The hitchhiker’s guide to Java class reloading
JavaOne 2017 - The hitchhiker’s guide to Java class reloadingJavaOne 2017 - The hitchhiker’s guide to Java class reloading
JavaOne 2017 - The hitchhiker’s guide to Java class reloadingAnton Arhipov
 
JavaZone 2017 - The Hitchhiker’s guide to Java class reloading
JavaZone 2017 - The Hitchhiker’s guide to Java class reloadingJavaZone 2017 - The Hitchhiker’s guide to Java class reloading
JavaZone 2017 - The Hitchhiker’s guide to Java class reloadingAnton Arhipov
 
JUG.ua 20170225 - Java bytecode instrumentation
JUG.ua 20170225 - Java bytecode instrumentationJUG.ua 20170225 - Java bytecode instrumentation
JUG.ua 20170225 - Java bytecode instrumentationAnton Arhipov
 
Riga DevDays 2017 - The hitchhiker’s guide to Java class reloading
Riga DevDays 2017 - The hitchhiker’s guide to Java class reloadingRiga DevDays 2017 - The hitchhiker’s guide to Java class reloading
Riga DevDays 2017 - The hitchhiker’s guide to Java class reloadingAnton Arhipov
 
GeeCON 2017 - TestContainers. Integration testing without the hassle
GeeCON 2017 - TestContainers. Integration testing without the hassleGeeCON 2017 - TestContainers. Integration testing without the hassle
GeeCON 2017 - TestContainers. Integration testing without the hassleAnton Arhipov
 
JEEConf 2017 - The hitchhiker’s guide to Java class reloading
JEEConf 2017 - The hitchhiker’s guide to Java class reloadingJEEConf 2017 - The hitchhiker’s guide to Java class reloading
JEEConf 2017 - The hitchhiker’s guide to Java class reloadingAnton Arhipov
 
JEEConf 2017 - Having fun with Javassist
JEEConf 2017 - Having fun with JavassistJEEConf 2017 - Having fun with Javassist
JEEConf 2017 - Having fun with JavassistAnton Arhipov
 

Mehr von Anton Arhipov (20)

JavaZone 2022 - Building Kotlin DSL.pdf
JavaZone 2022 - Building Kotlin DSL.pdfJavaZone 2022 - Building Kotlin DSL.pdf
JavaZone 2022 - Building Kotlin DSL.pdf
 
Idiomatic kotlin
Idiomatic kotlinIdiomatic kotlin
Idiomatic kotlin
 
TechTrain 2019 - (Не)адекватное техническое интервью
TechTrain 2019 - (Не)адекватное техническое интервьюTechTrain 2019 - (Не)адекватное техническое интервью
TechTrain 2019 - (Не)адекватное техническое интервью
 
Build pipelines with TeamCity
Build pipelines with TeamCityBuild pipelines with TeamCity
Build pipelines with TeamCity
 
Build pipelines with TeamCity
Build pipelines with TeamCityBuild pipelines with TeamCity
Build pipelines with TeamCity
 
Devoxx Ukraine 2018 - Kotlin DSL in under an hour
Devoxx Ukraine 2018 - Kotlin DSL in under an hourDevoxx Ukraine 2018 - Kotlin DSL in under an hour
Devoxx Ukraine 2018 - Kotlin DSL in under an hour
 
GeeCON Prague 2018 - Kotlin DSL in under an hour
GeeCON Prague 2018 - Kotlin DSL in under an hourGeeCON Prague 2018 - Kotlin DSL in under an hour
GeeCON Prague 2018 - Kotlin DSL in under an hour
 
Build pipelines with TeamCity and Kotlin DSL
Build pipelines with TeamCity and Kotlin DSLBuild pipelines with TeamCity and Kotlin DSL
Build pipelines with TeamCity and Kotlin DSL
 
Build pipelines with TeamCity
Build pipelines with TeamCityBuild pipelines with TeamCity
Build pipelines with TeamCity
 
JavaDay Kiev 2017 - Integration testing with TestContainers
JavaDay Kiev 2017 - Integration testing with TestContainersJavaDay Kiev 2017 - Integration testing with TestContainers
JavaDay Kiev 2017 - Integration testing with TestContainers
 
GeeCON Prague 2017 - TestContainers
GeeCON Prague 2017 - TestContainersGeeCON Prague 2017 - TestContainers
GeeCON Prague 2017 - TestContainers
 
JavaOne 2017 - The hitchhiker’s guide to Java class reloading
JavaOne 2017 - The hitchhiker’s guide to Java class reloadingJavaOne 2017 - The hitchhiker’s guide to Java class reloading
JavaOne 2017 - The hitchhiker’s guide to Java class reloading
 
JavaOne 2017 - TestContainers: integration testing without the hassle
JavaOne 2017 - TestContainers: integration testing without the hassleJavaOne 2017 - TestContainers: integration testing without the hassle
JavaOne 2017 - TestContainers: integration testing without the hassle
 
JavaOne 2017 - The hitchhiker’s guide to Java class reloading
JavaOne 2017 - The hitchhiker’s guide to Java class reloadingJavaOne 2017 - The hitchhiker’s guide to Java class reloading
JavaOne 2017 - The hitchhiker’s guide to Java class reloading
 
JavaZone 2017 - The Hitchhiker’s guide to Java class reloading
JavaZone 2017 - The Hitchhiker’s guide to Java class reloadingJavaZone 2017 - The Hitchhiker’s guide to Java class reloading
JavaZone 2017 - The Hitchhiker’s guide to Java class reloading
 
JUG.ua 20170225 - Java bytecode instrumentation
JUG.ua 20170225 - Java bytecode instrumentationJUG.ua 20170225 - Java bytecode instrumentation
JUG.ua 20170225 - Java bytecode instrumentation
 
Riga DevDays 2017 - The hitchhiker’s guide to Java class reloading
Riga DevDays 2017 - The hitchhiker’s guide to Java class reloadingRiga DevDays 2017 - The hitchhiker’s guide to Java class reloading
Riga DevDays 2017 - The hitchhiker’s guide to Java class reloading
 
GeeCON 2017 - TestContainers. Integration testing without the hassle
GeeCON 2017 - TestContainers. Integration testing without the hassleGeeCON 2017 - TestContainers. Integration testing without the hassle
GeeCON 2017 - TestContainers. Integration testing without the hassle
 
JEEConf 2017 - The hitchhiker’s guide to Java class reloading
JEEConf 2017 - The hitchhiker’s guide to Java class reloadingJEEConf 2017 - The hitchhiker’s guide to Java class reloading
JEEConf 2017 - The hitchhiker’s guide to Java class reloading
 
JEEConf 2017 - Having fun with Javassist
JEEConf 2017 - Having fun with JavassistJEEConf 2017 - Having fun with Javassist
JEEConf 2017 - Having fun with Javassist
 

Kürzlich hochgeladen

Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 

Kürzlich hochgeladen (20)

Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 

Java Bytecode For Discriminating Developers - GeeCON 2011

  • 1. Java Bytecode for Discriminating Developers Anton Arhipov
  • 2. whoami Anton Arhipov Java dev. / Product Lead JRebel http://arhipov.blogspot.com @antonarhipov @javarebel
  • 4. The Master Plan 80%: Bytecode 101 20%: Examples
  • 7. + 1 + 2 1 2
  • 8. + 1 + 2 1 2 1 2 +
  • 9. + 1 + 2 1 2 1 2 +
  • 10. + 1 + 2 1 2 1 2 + 1 PUSH 1
  • 11. + 1 + 2 1 2 1 2 + 2 PUSH 1 PUSH 2 1
  • 12. + 1 + 2 1 2 1 2 + 3 PUSH 1 PUSH 2 ADD
  • 13. + 1 + 2 1 2 1 2 + 3 ICONST_1 ICONST_2 IADD
  • 14. ? = 1 + 2
  • 16. Bytecode One-byte instructions 256 possible opcodes 200+ in use
  • 17. Bytecode One-byte instructions 256 possible opcodes 200+ in use
  • 19. TYPE OPERATION <TYPE> ::= b, s, c, i, l, f, d, a
  • 20. TYPE OPERATION <TYPE> ::= b, s, c, i, l, f, d, a Operations with constant values (ldc, iconst_1)
  • 21. TYPE OPERATION <TYPE> ::= b, s, c, i, l, f, d, a Operations with constant values (ldc, iconst_1) Local variables and stack interaction (load/store) Array operations (aload, astore) Math (add, sub, mul, div) Boolean/bitwise operations (iand, ixor) Comparisons (cmpg, cmpl, ifne, ifeq) Conversions (l2d, i2l)
  • 22. Bytecode Taxonomy Stack Manipulation
  • 23. Bytecode Taxonomy Stack Manipulation Flow Control
  • 24. Bytecode Taxonomy Stack Manipulation Flow Control Object Model
  • 25. Bytecode Taxonomy Stack Manipulation Flow Control Object Model Arithmetics
  • 26. Bytecode Taxonomy Stack Manipulation Flow Control Object Model Arithmetics monitorenter monitorexit
  • 28. javap Java class file disassembler Used with no options shows class structure only Methods, superclass, interfaces, etc -c shows the bytecode -private shows all methods and members -s prints internal signatures -l prints line numbers and local variable tables
  • 30.
  • 32. C:orkeeconlasses>javap Hello -c Compiled from "Hello.java" public class Hello extends java.lang.Object{ public Hello(); Code: 0: aload_0 1: invokespecial #1; //Method java/lang/Object."<init>":()V 4: return
  • 33. C:orkeeconlasses>javap Hello -c Compiled from "Hello.java" public class Hello extends java.lang.Object{ public Hello(); Code: 0: aload_0 1: invokespecial #1; //Method java/lang/Object."<init>":()V 4: return the default constructor
  • 34. C:orkeeconlasses>javap Hello -c Compiled from "Hello.java" public class Hello extends java.lang.Object{ public Hello(); Code: 0: aload_0 1: invokespecial #1; //Method java/lang/Object."<init>":()V 4: return push this to stack
  • 35. C:orkeeconlasses>javap Hello -c Compiled from "Hello.java" public class Hello extends java.lang.Object{ public Hello(); Code: 0: aload_0 1: invokespecial #1; //Method java/lang/Object."<init>":()V 4: return invoke <init> on this
  • 36. C:orkeeconlasses>javap Hello -c Compiled from "Hello.java" public class Hello extends java.lang.Object{ public Hello(); Code: 0: aload_0 1: invokespecial #1; //Method java/lang/Object."<init>":()V 4: return
  • 37. C:orkeeconlasses>javap Hello -c Compiled from "Hello.java" public class Hello extends java.lang.Object{ public Hello(); Code: 0: aload_0 1: invokespecial #1; //Method java/lang/Object."<init>":()V 4: return public static void main(java.lang.String[]); Code: 0: getstatic #2; //Field java/lang/System.out:Ljava/io/PrintStream; 3: ldc #3; //String Hello, World! 5: invokevirtual #4; //Method java/io/PrintStream.println:(Ljava/lang/String;)V
  • 38. C:orkeeconlasses>javap Hello -c Compiled from "Hello.java" public class Hello extends java.lang.Object{ public Hello(); Code: 0: aload_0 1: invokespecial #1; //Method java/lang/Object."<init>":()V 4: return public static void main(java.lang.String[]); Code: 0: getstatic #2; //Field java/lang/System.out:Ljava/io/PrintStream; 3: ldc #3; //String Hello, World! 5: invokevirtual #4; //Method java/io/PrintStream.println:(Ljava/lang/String;)V get static field
  • 39. C:orkeeconlasses>javap Hello -c Compiled from "Hello.java" public class Hello extends java.lang.Object{ public Hello(); Code: 0: aload_0 1: invokespecial #1; //Method java/lang/Object."<init>":()V 4: return public static void main(java.lang.String[]); Code: 0: getstatic #2; //Field java/lang/System.out:Ljava/io/PrintStream; 3: ldc #3; //String Hello, World! 5: invokevirtual #4; //Method java/io/PrintStream.println:(Ljava/lang/String;)V load string to the stack
  • 40. C:orkeeconlasses>javap Hello -c Compiled from "Hello.java" public class Hello extends java.lang.Object{ public Hello(); Code: 0: aload_0 1: invokespecial #1; //Method java/lang/Object."<init>":()V 4: return public static void main(java.lang.String[]); Code: 0: getstatic #2; //Field java/lang/System.out:Ljava/io/PrintStream; 3: ldc #3; //String Hello, World! 5: invokevirtual #4; //Method java/io/PrintStream.println:(Ljava/lang/String;)V invoke method with parameter
  • 41. C:orkeeconlasses>javap Hello -c Compiled from "Hello.java" public class Hello extends java.lang.Object{ public Hello(); Code: 0: aload_0 1: invokespecial #1; //Method java/lang/Object."<init>":()V 4: return public static void main(java.lang.String[]); Code: 0: getstatic #2; //Field java/lang/System.out:Ljava/io/PrintStream; 3: ldc #3; //String Hello, World! 5: invokevirtual #4; //Method java/io/PrintStream.println:(Ljava/lang/String;)V
  • 42. What’s #1,#2, etc ? C:orkeeconlasses>javap Hello -c Compiled from "Hello.java" public class Hello extends java.lang.Object{ public Hello(); Code: 0: aload_0 1: invokespecial #1; //Method java/lang/Object."<init>":()V 4: return public static void main(java.lang.String[]); Code: 0: getstatic #2; //Field java/lang/System.out:Ljava/io/PrintStream; 3: ldc #3; //String Hello, World! 5: invokevirtual #4; //Method java/io/PrintStream.println:(Ljava/lang/String;)V
  • 45. C:orkeeconlasses>javap Hello -c -verbose Compiled from "Hello.java“ public class Hello extends java.lang.Object SourceFile: "Hello.java" minor version: 0 major version: 50 Constant pool: const #1 = Method#6.#20; // java/lang/Object."<init>":()V const #2 = Field#21.#22; // java/lang/System.out:Ljava/io/PrintStream; const #3 = String#23; // Hello, World! const #4 = Method#24.#25; // java/io/PrintStream.println:(Ljava/lang/String;)V const #5 = class#26; // Hello const #6 = class#27; // java/lang/Object const #7 = Asciz<init>; const #8 = Asciz()V;
  • 46. C:orkeeconlasses>javap Hello -c -verbose Compiled from "Hello.java“ public class Hello extends java.lang.Object SourceFile: "Hello.java" minor version: 0 major version: 50 Constant pool: const #1 = Method#6.#20; // java/lang/Object."<init>":()V const #2 = Field#21.#22; // java/lang/System.out:Ljava/io/PrintStream; const #3 = String#23; // Hello, World! const #4 = Method#24.#25; // java/io/PrintStream.println:(Ljava/lang/String;)V const #5 = class#26; // Hello const #6 = class#27; // java/lang/Object const #7 = Asciz<init>; const #8 = Asciz()V;
  • 47. C:orkeeconlasses>javap Hello -c -verbose … public Hello(); Code: Stack=1, Locals=1, Args_size=1 0: aload_0 1: invokespecial #1; //Method java/lang/Object."<init>":()V 4: return LineNumberTable: line 1: 0 LocalVariableTable: Start Length Slot Name Signature 0 5 0 this LHello;
  • 48. C:orkeeconlasses>javap Hello -c -verbose … public Hello(); Code: Stack=1, Locals=1, Args_size=1 0: aload_0 1: invokespecial #1; //Method java/lang/Object."<init>":()V 4: return LineNumberTable: line 1: 0 LocalVariableTable: Start Length Slot Name Signature 0 5 0 this LHello;
  • 49. C:orkeeconlasses>javap Hello -c -verbose … public Hello(); Code: Stack=1, Locals=1, Args_size=1 0: aload_0 1: invokespecial #1; //Method java/lang/Object."<init>":()V 4: return LineNumberTable: line 1: 0 LocalVariableTable: Start Length Slot Name Signature 0 5 0 this LHello;
  • 50. C:orkeeconlasses>javap Hello -c -verbose … public static void main(java.lang.String[]); Code: Stack=2, Locals=1, Args_size=1 0: getstatic #2; //Field java/lang/System.out:Ljava/io/PrintStream; 3: ldc #3; //String Hello, World! 5: invokevirtual #4; //Method java/io/PrintStream.println:(Ljava/lang/String;)V 8: return LineNumberTable: line 4: 0 line 5: 8 LocalVariableTable: Start Length Slot Name Signature 0 9 0 args [Ljava/lang/String;
  • 53. Stack Machine JVM is a stack-based machine
  • 54. Stack Machine JVM is a stack-based machine Each thread has a stack
  • 55. Stack Machine JVM is a stack-based machine Each thread has a stack Stack stores frames
  • 56. Stack Machine JVM is a stack-based machine Each thread has a stack Stack stores frames Frame is created on method invocation
  • 57. Stack Machine JVM is a stack-based machine Each thread has a stack Stack stores frames Frame is created on method invocation Frame consists of: Operand stack Array of local variables
  • 58. The Frame Local variables N 1 2 3 … Operand stack #1 Constant Pool
  • 59. public java.lang.String getName(); Code: Stack=1, Locals=1, Args_size=1 0: aload_0 1: getfield #2; //Field name:Ljava/lang/String; 4: areturn LocalVariableTable: Start Length Slot Name Signature 0 5 0 this LGet;
  • 60. 0 1 2 3 4 areturn aload_0 00 02 getfield public java.lang.String getName(); Code: Stack=1, Locals=1, Args_size=1 0: aload_0 1: getfield #2; //Field name:Ljava/lang/String; 4: areturn LocalVariableTable: Start Length Slot Name Signature 0 5 0 this LGet;
  • 61. 0 1 2 3 4 B0 2A 00 02 B4 public java.lang.String getName(); Code: Stack=1, Locals=1, Args_size=1 0: aload_0 1: getfield #2; //Field name:Ljava/lang/String; 4: areturn LocalVariableTable: Start Length Slot Name Signature 0 5 0 this LGet;
  • 62. public java.lang.String getName(); Code: Stack=1, Locals=1, Args_size=1 0: aload_0 1: getfield #2; //Field name:Ljava/lang/String; 4: areturn LocalVariableTable: Start Length Slot Name Signature 0 5 0 this LGet;
  • 64. A dup pop swap dup_x1 dup2_x2 B
  • 65. A dup pop swap dup_x1 dup2_x2 A B
  • 66. A dup pop swap dup_x1 dup2_x2 B
  • 67. B dup pop swap dup_x1 dup2_x2 A
  • 68. B dup pop swap dup_x1 dup2_x2 A B
  • 69. B dup pop swap dup_x1 dup2_x2 A B B A
  • 70. dup2_x2 How do you swap doubles?
  • 75. dup2_x2 dconst_0 dconst_1 swap 1.0 not allowed! 0.0
  • 76. dup2_x2 dconst_0 dconst_1 swap2 1.0 0.0
  • 77. dup2_x2 dconst_0 dconst_1 swap2 1.0 doesn’t exist 0.0
  • 78. dup2_x2 dconst_0 dconst_1 dup2_x2 1.0 0.0 1.0
  • 79. dup2_x2 dconst_0 dconst_1 dup2_x2 pop2 0.0 1.0
  • 80. dup2_x2 dconst_0 dconst_1 dup2_x2 pop2 0.0 1.0 profit!
  • 83. public int calculate(int); Code: Stack=2, Locals=2, Args_size=2 … LocalVariableTable: Start Length Slot Name Signature 0 5 0 this LLocalVariables; 0 5 1 value I Local Variables
  • 84. public int calculate(int); Code: Stack=2, Locals=2, Args_size=2 … LocalVariableTable: Start Length Slot Name Signature 0 5 0 this LLocalVariables; 0 5 1 value I numbered from 0 Local Variables
  • 85. public int calculate(int); Code: Stack=2, Locals=2, Args_size=2 … LocalVariableTable: Start Length Slot Name Signature 0 5 0 this LLocalVariables; 0 5 1 value I Local Variables instance methods have this at 0
  • 86. The table maps numbers to names public int calculate(int); Code: Stack=2, Locals=2, Args_size=2 … LocalVariableTable: Start Length Slot Name Signature 0 5 0 this LLocalVariables; 0 5 1 value I Local Variables
  • 87. Sized explicitly public int calculate(int); Code: Stack=2, Locals=2, Args_size=2 … LocalVariableTable: Start Length Slot Name Signature 0 5 0 this LLocalVariables; 0 5 1 value I Local Variables
  • 88. Stack Local Variables value var value depth ldc"Hello" astore_0 iconst_1 astore_1 aload_0 0 0 1 1 2 2 3 3 4 4
  • 89. Stack Local Variables value var value depth ldc"Hello" astore_0 iconst_1 astore_1 aload_0 0 0 "Hello" 1 1 2 2 3 3 4 4
  • 90. Stack Local Variables value var value depth ldc"Hello" astore_0 iconst_1 astore_1 aload_0 "Hello" 0 0 1 1 2 2 3 3 4 4
  • 91. Stack Local Variables value var value depth ldc"Hello" astore_0 iconst_1 astore_1 aload_0 "Hello" 0 0 1 1 1 2 2 3 3 4 4
  • 92. Stack Local Variables value var value depth ldc"Hello" astore_0 iconst_1 astore_1 aload_0 "Hello" 0 0 1 1 1 2 2 3 3 4 4
  • 93. Stack Local Variables value var value depth ldc"Hello" astore_0 iconst_1 astore_1 aload_0 "Hello" 0 0 "Hello" 1 1 1 2 2 3 3 4 4
  • 94. load Stack Local Variables Table store
  • 96. new <init> <clinit> 0xBB Instance initialization method Class and interface initialization method Object Initialization
  • 97. Object Initialization: static {} static {}; Code: 0: iconst_1 1: putstatic #2; //Field a:I 4: iconst_2 5: putstatic #3; //Field b:I 8: return
  • 98. Object Initialization: static {} <clinit> static {}; Code: 0: iconst_1 1: putstatic #2; //Field a:I 4: iconst_2 5: putstatic #3; //Field b:I 8: return
  • 100. Object Initialization: new public Initializer(); Code:
  • 101. Object Initialization: new public Initializer(); Code: 0: aload_0
  • 102. Object Initialization: new public Initializer(); Code: 0: aload_0 1: invokespecial #1; //Method java/lang/Object."<init>":()V
  • 103. Object Initialization: new public Initializer(); Code: 0: aload_0 1: invokespecial #1; //Method java/lang/Object."<init>":()V 4: aload_0
  • 104. Object Initialization: new public Initializer(); Code: 0: aload_0 1: invokespecial #1; //Method java/lang/Object."<init>":()V 4: aload_0 5: new#2; //class java/lang/Object 8: dup
  • 105. Object Initialization: new public Initializer(); Code: 0: aload_0 1: invokespecial #1; //Method java/lang/Object."<init>":()V 4: aload_0 5: new#2; //class java/lang/Object 8: dup 9: invokespecial #1; //Method java/lang/Object."<init>":()V 12: putfield #3; //Field o:Ljava/lang/Object;
  • 106. Object Initialization: new public Initializer(); Code: 0: aload_0 1: invokespecial #1; //Method java/lang/Object."<init>":()V 4: aload_0 5: new#2; //class java/lang/Object 8: dup 9: invokespecial #1; //Method java/lang/Object."<init>":()V 12: putfield #3; //Field o:Ljava/lang/Object; 15: return
  • 107. Object Initialization: new public Initializer(); Code: 0: aload_0 1: invokespecial #1; //Method java/lang/Object."<init>":()V 4: aload_0 5: new#2; //class java/lang/Object 8: dup 9: invokespecial #1; //Method java/lang/Object."<init>":()V 12: putfield #3; //Field o:Ljava/lang/Object; 15: return
  • 110. Object Initialization: {} public Initializer(int); Code: 0:aload_0 1:invokespecial #1; // ..<init> 4:aload_0 5:iconst_1 6:putfield #2; //Field a:I 9:aload_0 10:iconst_2 11:putfield #3; //Field c:I 14:aload_0 15:iload_1 16:putfield #4; //Field b:I 19:return
  • 111.
  • 114. Methods & Parameters invokestatic invokespecial invokevirtual invokeinterface invokedynamic Efficient Implementation of Java Interfaces: Invokeinterface Considered Harmless,  Bowen Alpern, Anthony Cocchi, Stephen Fink, David Grove, and Derek Lieber, OOPSLA’01
  • 115. Methods & Parameters invokestatic invokespecial invokevirtual invokeinterface invokedynamic Integer.valueOf(“42”) Efficient Implementation of Java Interfaces: Invokeinterface Considered Harmless,  Bowen Alpern, Anthony Cocchi, Stephen Fink, David Grove, and Derek Lieber, OOPSLA’01
  • 116. Methods & Parameters invokestatic invokespecial invokevirtual invokeinterface invokedynamic <init> private void foo(); super.method(); Efficient Implementation of Java Interfaces: Invokeinterface Considered Harmless,  Bowen Alpern, Anthony Cocchi, Stephen Fink, David Grove, and Derek Lieber, OOPSLA’01
  • 117. Methods & Parameters invokestatic invokespecial invokevirtual invokeinterface invokedynamic class A A/method1 A/method2 Efficient Implementation of Java Interfaces: Invokeinterface Considered Harmless,  Bowen Alpern, Anthony Cocchi, Stephen Fink, David Grove, and Derek Lieber, OOPSLA’01
  • 118. Methods & Parameters invokestatic invokespecial invokevirtual invokeinterface invokedynamic class A A/method1 A/method2 class B Efficient Implementation of Java Interfaces: Invokeinterface Considered Harmless,  Bowen Alpern, Anthony Cocchi, Stephen Fink, David Grove, and Derek Lieber, OOPSLA’01
  • 119. Methods & Parameters invokestatic invokespecial invokevirtual invokeinterface invokedynamic class A A/method1 A/method2 class B A/method1 B/method2 B/method3 Efficient Implementation of Java Interfaces: Invokeinterface Considered Harmless,  Bowen Alpern, Anthony Cocchi, Stephen Fink, David Grove, and Derek Lieber, OOPSLA’01
  • 120. Methods & Parameters invokestatic invokespecial invokevirtual invokeinterface invokedynamic class A A/method1 A/method2 class B impl X A/method1 B/method2 B/method3 X/methodX Efficient Implementation of Java Interfaces: Invokeinterface Considered Harmless,  Bowen Alpern, Anthony Cocchi, Stephen Fink, David Grove, and Derek Lieber, OOPSLA’01
  • 121. Methods & Parameters invokestatic invokespecial invokevirtual invokeinterface invokedynamic class A A/method1 A/method2 class B impl X A/method1 B/method2 B/method3 X/methodX class D impl X D/method1 X/methodX Efficient Implementation of Java Interfaces: Invokeinterface Considered Harmless,  Bowen Alpern, Anthony Cocchi, Stephen Fink, David Grove, and Derek Lieber, OOPSLA’01
  • 122. Methods & Parameters invokestatic invokespecial invokevirtual invokeinterface invokedynamic class A A/method1 A/method2 class B impl X A/method1 B/method2 B/method3 X/methodX class D impl X D/method1 X/methodX Efficient Implementation of Java Interfaces: Invokeinterface Considered Harmless,  Bowen Alpern, Anthony Cocchi, Stephen Fink, David Grove, and Derek Lieber, OOPSLA’01
  • 123. Methods & Parameters invokestatic invokespecial invokevirtual invokeinterface invokedynamic Efficient Implementation of Java Interfaces: Invokeinterface Considered Harmless,  Bowen Alpern, Anthony Cocchi, Stephen Fink, David Grove, and Derek Lieber, OOPSLA’01
  • 125. Method Invocation obj.method(param1, param2); push obj push param1 push param2 call method
  • 126. Method Invocation obj.method(param1, param2); obj push obj push param1 push param2 call method
  • 127. Method Invocation obj.method(param1, param2); param1 push obj push param1 push param2 call method obj
  • 128. Method Invocation obj.method(param1, param2); param2 push obj push param1 push param2 call method param1 obj
  • 129. Method Invocation obj.method(param1, param2); obj? push obj push param1 push param2 call method
  • 130. Method Invocation this.add(1, 2); 0: aload_0 1: iconst_1 2: iconst_2 3: invokevirtual #2; //Method add:(II)I
  • 134. Inner Classes class Car$Engine extends j.l.Object{ final Car this$0; Car$Engine(Car); public void start(); Code: 0: aload_0 1: getfield #1; //Field this$0:LCar; 4: invokestatic #3; //Car.access$000:(LCar;)V 7: return }
  • 135. Inner Classes public class Car extends j.l.Object{ public Car(); private void move(); static void access$000(Car); Code: 0: aload_0 1: invokespecial #1; // move: ()V; 4: return } class Car$Engine extends j.l.Object{ final Car this$0; Car$Engine(Car); public void start(); Code: 0: aload_0 1: getfield #1; //Field this$0:LCar; 4: invokestatic #3; //Car.access$000:(LCar;)V 7: return }
  • 136. Inner Classes public class Car extends j.l.Object{ public Car(); private void move(); static void access$000(Car); Code: 0: aload_0 1: invokespecial #1; // move: ()V; 4: return } class Car$Engine extends j.l.Object{ final Car this$0; Car$Engine(Car); public void start(); Code: 0: aload_0 1: getfield #1; //Field this$0:LCar; 4: invokestatic #3; //Car.access$000:(LCar;)V 7: return }
  • 137. “HOW DO THEY DO THAT?”
  • 138. object Singleton { def test={} }
  • 139. object Singleton { def test={} } $> scalacSingleton.scala Singleton.class Singleton$.class
  • 140. public final class Singleton extends java.lang.Object{ public static final void test(); Code: 0: getstatic #11; //Field Singleton$.MODULE$:LSingleton$; 3: invokevirtual #13; //Method Singleton$.test:()V 6: return }
  • 141. public final class Singleton extends java.lang.Object{ public static final void test(); Code: 0: getstatic #11; //Field Singleton$.MODULE$:LSingleton$; 3: invokevirtual #13; //Method Singleton$.test:()V 6: return }
  • 142. public final class Singleton extends java.lang.Object{ public static final void test(); Code: 0: getstatic #11; //Field Singleton$.MODULE$:LSingleton$; 3: invokevirtual #13; //Method Singleton$.test:()V 6: return }
  • 143. public final class Singleton extends java.lang.Object{ public static final void test(); Code: 0: getstatic #11; //Field Singleton$.MODULE$:LSingleton$; 3: invokevirtual #13; //Method Singleton$.test:()V 6: return } public final class Singleton$ extends java.lang.Object implements scala.ScalaObject{ public static final Singleton$ MODULE$; public static {}; Code: 0: new #9; //class Singleton$ 3: invokespecial #12; //Method "<init>":()V 6: return public void test(); private Singleton$(); }
  • 144. public final class Singleton extends java.lang.Object{ public static final void test(); Code: 0: getstatic #11; //Field Singleton$.MODULE$:LSingleton$; 3: invokevirtual #13; //Method Singleton$.test:()V 6: return } public final class Singleton$ extends java.lang.Object implements scala.ScalaObject{ public static final Singleton$ MODULE$; public static {}; Code: 0: new #9; //class Singleton$ 3: invokespecial #12; //Method "<init>":()V 6: return public void test(); private Singleton$(); }
  • 145. public final class Singleton extends java.lang.Object{ public static final void test(); Code: 0: getstatic #11; //Field Singleton$.MODULE$:LSingleton$; 3: invokevirtual #13; //Method Singleton$.test:()V 6: return } public final class Singleton$ extends java.lang.Object implements scala.ScalaObject{ public static final Singleton$ MODULE$; public static {}; Code: 0: new #9; //class Singleton$ 3: invokespecial #12; //Method "<init>":()V 6: return public void test(); private Singleton$(); }
  • 146. public final class Singleton extends java.lang.Object{ public static final void test(); Code: 0: getstatic #11; //Field Singleton$.MODULE$:LSingleton$; 3: invokevirtual #13; //Method Singleton$.test:()V 6: return } public final class Singleton$ extends java.lang.Object implements scala.ScalaObject{ public static final Singleton$ MODULE$; public static {}; public void test(); private Singleton$(); Code: 0: aload_0 1: invokespecial#17; //Method java/lang/Object."<init>":()V 4: aload_0 5: putstatic#19; //Field MODULE$:LSingleton$; 8: return
  • 147. object Singleton { def test={} }
  • 148. publicclassSingleton { publicvoid test(){ Singleton$.MODULE$.test(); } } object Singleton { def test={} }
  • 149. publicclassSingleton { publicvoid test(){ Singleton$.MODULE$.test(); } } public final class Singleton$ implements scala.ScalaObject{ public static final Singleton$ MODULE$; static { newSingleton$(); } private Singleton$(){ MODULE$ = this; } public void test() { } } object Singleton { def test={} }
  • 151. classGroovy {} $> groovycGroovy.groovy $> javap –c –p Groovy
  • 152. classGroovy {} $> groovycGroovy.groovy $> javap –c –p Groovy public class Test extends java.lang.Object implements groovy.lang.GroovyObject{ private static org.codehaus.groovy.reflection.ClassInfo $staticClassInfo; private transient groovy.lang.MetaClass metaClass; public static java.lang.Long __timeStamp; public static java.lang.Long __timeStamp__239_neverHappen1304807931117; private static java.lang.ref.SoftReference $callSiteArray; private static java.lang.Class $class$groovy$lang$MetaClass; private static java.lang.Class $class$Test; private static java.lang.Class $class$java$lang$String; public java.lang.Object this$dist$invoke$2(java.lang.String, java.lang.Object); public void this$dist$set$2(java.lang.String, java.lang.Object); public java.lang.Object this$dist$get$2(java.lang.String); protected groovy.lang.MetaClass $getStaticMetaClass(); public groovy.lang.MetaClass getMetaClass(); public void setMetaClass(groovy.lang.MetaClass); public java.lang.Object invokeMethod(java.lang.String, java.lang.Object); public java.lang.Object getProperty(java.lang.String); public void setProperty(java.lang.String, java.lang.Object);
  • 154. Javassist Bytecode manipulation made easy Source-level and bytecode-level API Uses the vocabulary of Java language On-the-fly compilation of the injected code http://www.jboss.org/javassist
  • 155. for(inti = 0; i < 100; i++){ inta = 0; try { while (true) { a++; foo(a); if(a > 1) break; } } catch (Exception e) { } }
  • 156. for(inti = 0; i < 100; i++){ inta = 0; try { while (true) { a++; foo(a); if(a > 1) break; } } catch (Exception e) { } }
  • 157. for(inti = 0; i < 100; i++){ inta = 0; try{ while (true) { a++; foo(a); if(a > 1) break; } } catch (Exception e) { } }
  • 158. for(inti = 0; i < 100; i++){ inta = 0; try{ while(true) { a++; foo(a); if(a > 1) break; } } catch (Exception e) { } }
  • 159. for(inti = 0; i < 100; i++){ inta = 0; try{ while(true) { a++; foo(a); if(a > 1) break; } } catch (Exception e) { } }
  • 160. Javassist CtMethod method = … method.setBody(“ for(inti = 0; i < 100; i++){ inta = 0; try { while (true) { a++; foo(a); if(a > 1) break; } } catch (Exception e) { } }”);
  • 162. # # A fatal error has been detected by the Java Runtime Environment: # # EXCEPTION_ACCESS_VIOLATION (0xc0000005) at # pc=0x01adff06, pid=7732, tid=868 # # JRE version: 6.0_21-b07 # Java VM: Java HotSpot(TM) Client VM (17.0-b17 mixed mode, # sharing windows-x86 ) # Problematic frame: # j zt.javassist.My.test()V+20 # # An error report file with more information is saved as: # C:orkuzzlerss_err_pid7732.log # # If you would like to submit a bug report, please visit: # http://java.sun.com/webapps/bugreport/crash.jsp # -noverify
  • 163. Exception in thread "main" java.lang.VerifyError: (class: zt/javassist/My, method: test signature: ()V) Inconsistent stack height 0 != 1 -Xverify:all
  • 164. public void test(); Code: Stack=2, Locals=4, Args_size=1 0: iconst_0 1: istore_1 2: iload_1 3: bipush 100 5: if_icmpge 42 8: iconst_0 9: istore_2 10: goto 29 13: iinc 2, 1 16: aload_0 17: iload_2 18: invokevirtual #23; //Method zt/javassist/My.foo:(I)V 21: iload_2 22: iconst_1 23: if_icmple 29 26: goto 32 29: goto 13 32: astore_3 33: goto 36 36: iinc 1, 1 39: goto 2 42: return Exception table: from to target type 10 32 32 Class java/lang/Exception
  • 165. public void test(); Code: Stack=2, Locals=4, Args_size=1 0: iconst_0 1: istore_1 2: iload_1 3: bipush 100 5: if_icmpge 42 8: iconst_0 9: istore_2 10: goto 29 13: iinc 2, 1 16: aload_0 17: iload_2 18: invokevirtual #23; //Method zt/javassist/My.foo:(I)V 21: iload_2 22: iconst_1 23: if_icmple 29 26: goto 32 29: goto 13 32: astore_3 33: goto 36 36: iinc 1, 1 39: goto 2 42: return Exception table: from to target type 10 32 32 Class java/lang/Exception No local variables table
  • 166. public void test(); Code: Stack=2, Locals=4, Args_size=1 0: iconst_0 1: istore_1 2: iload_1 3: bipush 100 5: if_icmpge 42 8: iconst_0 9: istore_2 10: goto 29 13: iinc 2, 1 16: aload_0 17: iload_2 18: invokevirtual #23; //Method zt/javassist/My.foo:(I)V 21: iload_2 22: iconst_1 23: if_icmple 29 26: goto 32 29: goto 13 32: astore_3 33: goto 36 36: iinc 1, 1 39: goto 2 42: return Exception table: from to target type 10 32 32 Class java/lang/Exception No local variables table
  • 167. Q/A