SlideShare a Scribd company logo
1 of 159
Mastering Java Bytecode
Anton Arhipov | ZeroTurnaround
whoami
• Anton Arhipov
• Java Dev / Product Lead
• ZeroTurnaround, JRebel

• @antonarhipov @javarebel
Today – Java Core
• Mastering Java Bytecode

• The Future of Java on Multi-
  Core, Lambdas, Spliterators and
  Methods

• OpenJDK JVM Internals

• Invokedynamic Deep Dive
Why Bytecode?
•   Know your platform!
•   Create your own compiler?
•   Programming model (AOP, ORM)
•   Awesome tools (JRebel )

• … just bored?
THE INTRO
1+2
1+2

12+
1+2

12+
1+2

12+   PUSH 1
               1
1+2

12+   PUSH 1
      PUSH 2
               2
               1
1+2

12+   PUSH 1
      PUSH 2
               3
      ADD
1+2

12+   ICONST_1
      ICONST_2
                 3
      IADD
?=1+2
TAXONOMY
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
• constant values (ldc, iconst_1)
TYPE OPERATION

• <TYPE> ::= b, s, c, i, l, f, d, a
• 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
Bytecode Taxonomy

  Stack
Manipulation
Bytecode Taxonomy

  Stack         Flow
Manipulation   Control
Bytecode Taxonomy

  Stack         Flow
Manipulation   Control




               Object
               Model
Bytecode Taxonomy

  Stack         Flow
Manipulation   Control




               Object
 Arithmetics
               Model
Bytecode Taxonomy

  Stack                   Flow
Manipulation             Control

          monitorenter
          monitorexit



                         Object
 Arithmetics
                         Model
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:workgeeconclasses>javap   Hello -c
C:workgeeconclasses>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:workgeeconclasses>javap Hello -c
Compiled from "Hello.java"
public class Hello extends java.lang.Object{
public Hello();
  Code:                                      the default constructor
   0: aload_0
   1: invokespecial #1; //Method java/lang/Object."<init>":()V
   4: return
C:workgeeconclasses>javap Hello -c
Compiled from "Hello.java"
public class Hello extends java.lang.Object{
public Hello();
  Code:                                      push this to stack
   0: aload_0
   1: invokespecial #1; //Method java/lang/Object."<init>":()V
   4: return
C:workgeeconclasses>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:workgeeconclasses>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:workgeeconclasses>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:workgeeconclasses>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
                          get static field
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:workgeeconclasses>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:workgeeconclasses>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:workgeeconclasses>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:workgeeconclasses>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:workgeeconclasses>javap   Hello -c -verbose
C:workgeeconclasses>javap   Hello -c -verbose
C:workgeeconclasses>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:workgeeconclasses>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:workgeeconclasses>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:workgeeconclasses>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:workgeeconclasses>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:workgeeconclasses>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;
MODEL OF
COMPUTATION
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
0 1 2      … N
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

    aload_0      getfield    00      02     areturn


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

       2A          B4        00      02        B0


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
dup       A
pop       B
swap
dup_x1
dup2_x1
dup       A
pop       A
swap      B
dup_x1
dup2_x1
dup       A
pop       B
swap
dup_x1
dup2_x1
dup       B
pop       A
swap
dup_x1
dup2_x1
dup       B
pop       A
swap      B
dup_x1
dup2_x1
dup       B
pop       A
swap      B
dup_x1    B
dup2_x1   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             1.0
swap
                     0.0
dup2_x2
dconst_0
dconst_1                  1.0
swap       not allowed!

                          0.0
dup2_x2
dconst_0
dconst_1             1.0
swap2
                     0.0
dup2_x2
dconst_0
dconst_1              1.0
            doesn’t
swap2        exist
                      0.0
dup2_x2
dconst_0
dconst_1             1.0
dup2_x2
                     0.0

                     1.0
dup2_x2
dconst_0
dconst_1             0.0
dup2_x2
pop2                 1.0
dup2_x2
dconst_0
dconst_1             0.0
dup2_x2
pop2                 1.0

profit! 
LOCAL VARIABLES
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
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


                                         The table
public int calculate(int);
 Code:                                    maps
 Stack=2, Locals=2, Args_size=2         numbers to
  …
                                          names
 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              Sized explicitly
  …

 LocalVariableTable:
 Start Length Slot Name Signature
    0        5    0 this  LLocalVariables;
    0        5    1 value I
Local Variables                         Stack

var        value                      depth     value
                        ldc "Hello"
0                                      0
                        astore_0
1                       iconst_1       1
                        astore_1
2                       aload_0        2

3                                      3

4                                      4
Local Variables                         Stack

var        value                      depth     value
                        ldc "Hello"
0                                      0       "Hello"
                        astore_0
1                       iconst_1       1
                        astore_1
2                       aload_0        2

3                                      3

4                                      4
Local Variables                         Stack

var        value                      depth     value
                        ldc "Hello"
0         "Hello"                      0
                        astore_0
1                       iconst_1       1
                        astore_1
2                       aload_0        2

3                                      3

4                                      4
Local Variables                         Stack

var        value                      depth     value
                        ldc "Hello"
0         "Hello"                      0              1
                        astore_0
1                       iconst_1       1
                        astore_1
2                       aload_0        2

3                                      3

4                                      4
Local Variables                         Stack

var        value                      depth     value
                        ldc "Hello"
0         "Hello"                      0
                        astore_0
1             1         iconst_1       1
                        astore_1
2                       aload_0        2

3                                      3

4                                      4
Local Variables                         Stack

var        value                      depth     value
                        ldc "Hello"
0         "Hello"                      0       "Hello"
                        astore_0
1             1         iconst_1       1
                        astore_1
2                       aload_0        2

3                                      3

4                                      4
load
  Local
Variables           Stack
  Table

            store
OBJECTS
Object Initialization
new
 0xBB

         <init>
  Instance initialization method

                         <clinit>
                         Class and interface
                        initialization method
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
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
invokeXXX
•   invokestatic
•   invokespecial
•   invokevirtual
•   invokeinterface
•   invokedynamic
invokestatic
•   invokestatic
•   invokespecial
•   invokevirtual     Integer.valueOf(“42”)
•   invokeinterface
•   invokedynamic
invokespecial
•   invokestatic            <init>
•   invokespecial
•   invokevirtual     private void foo();
•   invokeinterface
•   invokedynamic     super.method();
invokevirtual
                        class A
•   invokestatic         A/method1
                         A/method2
•   invokespecial
•   invokevirtual
•   invokeinterface
•   invokedynamic
invokevirtual
                           class A
•   invokestatic            A/method1
                            A/method2
•   invokespecial
                      class B
•   invokevirtual
•   invokeinterface
•   invokedynamic
invokevirtual
                             class A
•   invokestatic               A/method1
                               A/method2
•   invokespecial
                      class B
•   invokevirtual      A/method1
                       B/method2
•   invokeinterface    B/method3

•   invokedynamic
invokeinterface
                             class A
•   invokestatic               A/method1
                               A/method2
•   invokespecial
                      class B impl X
•   invokevirtual      A/method1
                       B/method2
•   invokeinterface    B/method3
                       X/methodX
•   invokedynamic
invokeinterface
                             class A
•   invokestatic               A/method1
                               A/method2
•   invokespecial
                      class B impl X
•   invokevirtual      A/method1

•   invokeinterface
                       B/method2
                       B/method3
                                    D impl X
                       X/methodX      D/method1
•   invokedynamic                     X/methodX
invokeinterface
                             class A
•   invokestatic               A/method1
                               A/method2
•   invokespecial
                      class B impl X
•   invokevirtual      A/method1

•   invokeinterface
                       B/method2
                       B/method3
                                    D impl X
                       X/methodX      D/method1
•   invokedynamic                     X/methodX
invokeinterface
                                             class A
   •   invokestatic                             A/method1
                                                A/method2
   •   invokespecial
                                   class B impl X
   •   invokevirtual                 A/method1

   •   invokeinterface
                                     B/method2
                                     B/method3
                                                      D impl X
                                     X/methodX          D/method1
   •   invokedynamic                                    X/methodX



Efficient Implementation of Java Interfaces: Invokeinterface Considered
Harmless, Bowen Alpern, Anthony Cocchi, Stephen Fink, David Grove, and
Derek Lieber, OOPSLA’01
Method Invocation
Method Invocation
obj.method(param1, param2);
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
                               obj
      push param1
      push param2
      call method
Method Invocation
obj.method(param1, param2);
                              param2
      push obj                param1
      push param1
      push param2              obj
      call method
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();
class Car$Engine extends j.l.Object{
final Car this$0;                       static void access$000(Car);
                                          Code:
Car$Engine(Car);                          0: aload_0
                                          1: invokespecial #1; // move: ()V;
public void start();                      4: return
  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();
class Car$Engine extends j.l.Object{
final Car this$0;                       static void access$000(Car);
                                          Code:
Car$Engine(Car);                          0: aload_0
                                          1: invokespecial #1; // move: ()V;
public void start();                      4: return
  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={}
      }

 $> scalac Singleton.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={}
}
public class Singleton {
                       public void test(){
                         Singleton$.MODULE$.test();
                       }
                     }


object Singleton {
  def test={}
}
public class Singleton {
                       public void test(){
                         Singleton$.MODULE$.test();
                       }
                     }

                     public final class Singleton$
object Singleton {     implements scala.ScalaObject {
  def test={}          public static final Singleton$ MODULE$;
}                        static { new Singleton$(); }

                         private Singleton$(){
                           MODULE$ = this;
                         }

                         public void test() {
                         }
                     }
class Groovy { }
class Groovy { }
$> groovyc Groovy.groovy
$> javap –c –p Groovy
class Groovy { }
$> groovyc Groovy.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);
OBJECTWEB ASM
SLIDES
GOTO IDE
SLIDES
IDE: DEMO
https://github.com/antonarhipov
@antonarhipov

anton@zeroturnaround.com

More Related Content

What's hot

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
 
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
 
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
 
Beyond JVM - YOW! Sydney 2013
Beyond JVM - YOW! Sydney 2013Beyond JVM - YOW! Sydney 2013
Beyond JVM - YOW! Sydney 2013Charles Nutter
 
Oredev 2015 - Taming Java Agents
Oredev 2015 - Taming Java AgentsOredev 2015 - Taming Java Agents
Oredev 2015 - Taming Java AgentsAnton Arhipov
 
Productive Programming in Java 8 - with Lambdas and Streams
Productive Programming in Java 8 - with Lambdas and Streams Productive Programming in Java 8 - with Lambdas and Streams
Productive Programming in Java 8 - with Lambdas and Streams Ganesh Samarthyam
 
What to expect from Java 9
What to expect from Java 9What to expect from Java 9
What to expect from Java 9Ivan Krylov
 
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
 
JRuby and Invokedynamic - Japan JUG 2015
JRuby and Invokedynamic - Japan JUG 2015JRuby and Invokedynamic - Japan JUG 2015
JRuby and Invokedynamic - Japan JUG 2015Charles Nutter
 
Modern Programming in Java 8 - Lambdas, Streams and Date Time API
Modern Programming in Java 8 - Lambdas, Streams and Date Time APIModern Programming in Java 8 - Lambdas, Streams and Date Time API
Modern Programming in Java 8 - Lambdas, Streams and Date Time APIGanesh Samarthyam
 
Code lifecycle in the jvm - TopConf Linz
Code lifecycle in the jvm - TopConf LinzCode lifecycle in the jvm - TopConf Linz
Code lifecycle in the jvm - TopConf LinzIvan Krylov
 
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
 
JavaScript Library Overview
JavaScript Library OverviewJavaScript Library Overview
JavaScript Library Overviewjeresig
 
Monitoring distributed (micro-)services
Monitoring distributed (micro-)servicesMonitoring distributed (micro-)services
Monitoring distributed (micro-)servicesRafael Winterhalter
 
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
 
Spring into rails
Spring into railsSpring into rails
Spring into railsHiro Asari
 

What's hot (20)

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
 
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
 
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!
 
55 New Features in Java 7
55 New Features in Java 755 New Features in Java 7
55 New Features in Java 7
 
Beyond JVM - YOW! Sydney 2013
Beyond JVM - YOW! Sydney 2013Beyond JVM - YOW! Sydney 2013
Beyond JVM - YOW! Sydney 2013
 
JRuby and You
JRuby and YouJRuby and You
JRuby and You
 
Oredev 2015 - Taming Java Agents
Oredev 2015 - Taming Java AgentsOredev 2015 - Taming Java Agents
Oredev 2015 - Taming Java Agents
 
JVM
JVMJVM
JVM
 
Productive Programming in Java 8 - with Lambdas and Streams
Productive Programming in Java 8 - with Lambdas and Streams Productive Programming in Java 8 - with Lambdas and Streams
Productive Programming in Java 8 - with Lambdas and Streams
 
What to expect from Java 9
What to expect from Java 9What to expect from Java 9
What to expect from Java 9
 
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
 
JRuby and Invokedynamic - Japan JUG 2015
JRuby and Invokedynamic - Japan JUG 2015JRuby and Invokedynamic - Japan JUG 2015
JRuby and Invokedynamic - Japan JUG 2015
 
Modern Programming in Java 8 - Lambdas, Streams and Date Time API
Modern Programming in Java 8 - Lambdas, Streams and Date Time APIModern Programming in Java 8 - Lambdas, Streams and Date Time API
Modern Programming in Java 8 - Lambdas, Streams and Date Time API
 
Code lifecycle in the jvm - TopConf Linz
Code lifecycle in the jvm - TopConf LinzCode lifecycle in the jvm - TopConf Linz
Code lifecycle in the jvm - TopConf Linz
 
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
 
JavaScript Library Overview
JavaScript Library OverviewJavaScript Library Overview
JavaScript Library Overview
 
Monitoring distributed (micro-)services
Monitoring distributed (micro-)servicesMonitoring distributed (micro-)services
Monitoring distributed (micro-)services
 
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
 
Spring into rails
Spring into railsSpring into rails
Spring into rails
 

Viewers also liked

Bytecode manipulation with Javassist and ASM
Bytecode manipulation with Javassist and ASMBytecode manipulation with Javassist and ASM
Bytecode manipulation with Javassist and ASMashleypuls
 
LatJUG. Java Bytecode Fundamentals
LatJUG. Java Bytecode FundamentalsLatJUG. Java Bytecode Fundamentals
LatJUG. Java Bytecode Fundamentalsdenis Udod
 
GC @ jmaghreb2014
GC @ jmaghreb2014GC @ jmaghreb2014
GC @ jmaghreb2014Ivan Krylov
 
Programming JVM Bytecode
Programming JVM BytecodeProgramming JVM Bytecode
Programming JVM BytecodeJoe Kutner
 
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
 
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
 
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
 

Viewers also liked (12)

Bytecode manipulation with Javassist and ASM
Bytecode manipulation with Javassist and ASMBytecode manipulation with Javassist and ASM
Bytecode manipulation with Javassist and ASM
 
LatJUG. Java Bytecode Fundamentals
LatJUG. Java Bytecode FundamentalsLatJUG. Java Bytecode Fundamentals
LatJUG. Java Bytecode Fundamentals
 
GC @ jmaghreb2014
GC @ jmaghreb2014GC @ jmaghreb2014
GC @ jmaghreb2014
 
Programming JVM Bytecode
Programming JVM BytecodeProgramming JVM Bytecode
Programming JVM Bytecode
 
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
 
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
 
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
 
Java Annotation
Java AnnotationJava Annotation
Java Annotation
 
[Jbcn 2016] Garbage Collectors WTF!?
[Jbcn 2016] Garbage Collectors WTF!?[Jbcn 2016] Garbage Collectors WTF!?
[Jbcn 2016] Garbage Collectors WTF!?
 

Similar to Mastering Java Bytecode - JAX.de 2012

Java Bytecode for Discriminating Developers - JavaZone 2011
Java Bytecode for Discriminating Developers - JavaZone 2011Java Bytecode for Discriminating Developers - JavaZone 2011
Java Bytecode for Discriminating Developers - JavaZone 2011Anton Arhipov
 
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
 
How to implement a simple dalvik virtual machine
How to implement a simple dalvik virtual machineHow to implement a simple dalvik virtual machine
How to implement a simple dalvik virtual machineChun-Yu Wang
 
Down the Rabbit Hole: An Adventure in JVM Wonderland
Down the Rabbit Hole: An Adventure in JVM WonderlandDown the Rabbit Hole: An Adventure in JVM Wonderland
Down the Rabbit Hole: An Adventure in JVM WonderlandCharles Nutter
 
Develop realtime web with Scala and Xitrum
Develop realtime web with Scala and XitrumDevelop realtime web with Scala and Xitrum
Develop realtime web with Scala and XitrumNgoc Dao
 
Java review00
Java review00Java review00
Java review00saryu2011
 
Core java over view basics introduction by quontra solutions
Core java over view basics introduction by quontra solutionsCore java over view basics introduction by quontra solutions
Core java over view basics introduction by quontra solutionsQUONTRASOLUTIONS
 
Introduction to Software Development
Introduction to Software DevelopmentIntroduction to Software Development
Introduction to Software DevelopmentZeeshan MIrza
 
Advanced debugging  techniques in different environments
Advanced debugging  techniques in different environmentsAdvanced debugging  techniques in different environments
Advanced debugging  techniques in different environmentsAndrii Soldatenko
 
Building High Performance Android Applications in Java and C++
Building High Performance Android Applications in Java and C++Building High Performance Android Applications in Java and C++
Building High Performance Android Applications in Java and C++Kenneth Geisshirt
 
Java Bytecode Fundamentals - JUG.lv
Java Bytecode Fundamentals - JUG.lvJava Bytecode Fundamentals - JUG.lv
Java Bytecode Fundamentals - JUG.lvAnton Arhipov
 
basic core java up to operator
basic core java up to operatorbasic core java up to operator
basic core java up to operatorkamal kotecha
 

Similar to Mastering Java Bytecode - JAX.de 2012 (20)

Java Bytecode for Discriminating Developers - JavaZone 2011
Java Bytecode for Discriminating Developers - JavaZone 2011Java Bytecode for Discriminating Developers - JavaZone 2011
Java Bytecode for Discriminating Developers - JavaZone 2011
 
Mastering Java ByteCode
Mastering Java ByteCodeMastering Java ByteCode
Mastering Java ByteCode
 
In Vogue Dynamic
In Vogue DynamicIn Vogue Dynamic
In Vogue Dynamic
 
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
 
How to implement a simple dalvik virtual machine
How to implement a simple dalvik virtual machineHow to implement a simple dalvik virtual machine
How to implement a simple dalvik virtual machine
 
Down the Rabbit Hole: An Adventure in JVM Wonderland
Down the Rabbit Hole: An Adventure in JVM WonderlandDown the Rabbit Hole: An Adventure in JVM Wonderland
Down the Rabbit Hole: An Adventure in JVM Wonderland
 
Java introduction
Java introductionJava introduction
Java introduction
 
Java Basic PART I
Java Basic PART IJava Basic PART I
Java Basic PART I
 
Javalecture 1
Javalecture 1Javalecture 1
Javalecture 1
 
Java goes wild, lesson 1
Java goes wild, lesson 1Java goes wild, lesson 1
Java goes wild, lesson 1
 
Develop realtime web with Scala and Xitrum
Develop realtime web with Scala and XitrumDevelop realtime web with Scala and Xitrum
Develop realtime web with Scala and Xitrum
 
Java review00
Java review00Java review00
Java review00
 
Core java over view basics introduction by quontra solutions
Core java over view basics introduction by quontra solutionsCore java over view basics introduction by quontra solutions
Core java over view basics introduction by quontra solutions
 
Introduction to Software Development
Introduction to Software DevelopmentIntroduction to Software Development
Introduction to Software Development
 
Advanced debugging  techniques in different environments
Advanced debugging  techniques in different environmentsAdvanced debugging  techniques in different environments
Advanced debugging  techniques in different environments
 
Introduction to java programming part 1
Introduction to java programming   part 1Introduction to java programming   part 1
Introduction to java programming part 1
 
Building High Performance Android Applications in Java and C++
Building High Performance Android Applications in Java and C++Building High Performance Android Applications in Java and C++
Building High Performance Android Applications in Java and C++
 
Java Bytecode Fundamentals - JUG.lv
Java Bytecode Fundamentals - JUG.lvJava Bytecode Fundamentals - JUG.lv
Java Bytecode Fundamentals - JUG.lv
 
basic core java up to operator
basic core java up to operatorbasic core java up to operator
basic core java up to operator
 
java swing
java swingjava swing
java swing
 

More from 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
 

More from 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
 

Recently uploaded

"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 

Recently uploaded (20)

"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 

Mastering Java Bytecode - JAX.de 2012

  • 1. Mastering Java Bytecode Anton Arhipov | ZeroTurnaround
  • 2. whoami • Anton Arhipov • Java Dev / Product Lead • ZeroTurnaround, JRebel • @antonarhipov @javarebel
  • 3. Today – Java Core • Mastering Java Bytecode • The Future of Java on Multi- Core, Lambdas, Spliterators and Methods • OpenJDK JVM Internals • Invokedynamic Deep Dive
  • 4.
  • 5. Why Bytecode? • Know your platform! • Create your own compiler? • Programming model (AOP, ORM) • Awesome tools (JRebel ) • … just bored?
  • 7. 1+2
  • 10. 1+2 12+ PUSH 1 1
  • 11. 1+2 12+ PUSH 1 PUSH 2 2 1
  • 12. 1+2 12+ PUSH 1 PUSH 2 3 ADD
  • 13. 1+2 12+ ICONST_1 ICONST_2 3 IADD
  • 14. ?=1+2
  • 16. Bytecode • One-byte instructions • 256 possible opcodes • 200+ in use
  • 18. TYPE OPERATION • <TYPE> ::= b, s, c, i, l, f, d, a
  • 19. TYPE OPERATION • <TYPE> ::= b, s, c, i, l, f, d, a • constant values (ldc, iconst_1)
  • 20. TYPE OPERATION • <TYPE> ::= b, s, c, i, l, f, d, a • 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 Flow Manipulation Control
  • 24. Bytecode Taxonomy Stack Flow Manipulation Control Object Model
  • 25. Bytecode Taxonomy Stack Flow Manipulation Control Object Arithmetics Model
  • 26. Bytecode Taxonomy Stack Flow Manipulation Control monitorenter monitorexit Object Arithmetics Model
  • 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:workgeeconclasses>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:workgeeconclasses>javap Hello -c Compiled from "Hello.java" public class Hello extends java.lang.Object{ public Hello(); Code: the default constructor 0: aload_0 1: invokespecial #1; //Method java/lang/Object."<init>":()V 4: return
  • 34. C:workgeeconclasses>javap Hello -c Compiled from "Hello.java" public class Hello extends java.lang.Object{ public Hello(); Code: push this to stack 0: aload_0 1: invokespecial #1; //Method java/lang/Object."<init>":()V 4: return
  • 35. C:workgeeconclasses>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:workgeeconclasses>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:workgeeconclasses>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:workgeeconclasses>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 get static field 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
  • 39. C:workgeeconclasses>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:workgeeconclasses>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:workgeeconclasses>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:workgeeconclasses>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
  • 43. C:workgeeconclasses>javap Hello -c -verbose
  • 44. C:workgeeconclasses>javap Hello -c -verbose
  • 45. C:workgeeconclasses>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:workgeeconclasses>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:workgeeconclasses>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:workgeeconclasses>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:workgeeconclasses>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:workgeeconclasses>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 0 1 2 … N 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 aload_0 getfield 00 02 areturn 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 2A B4 00 02 B0 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. dup A pop B swap dup_x1 dup2_x1
  • 65. dup A pop A swap B dup_x1 dup2_x1
  • 66. dup A pop B swap dup_x1 dup2_x1
  • 67. dup B pop A swap dup_x1 dup2_x1
  • 68. dup B pop A swap B dup_x1 dup2_x1
  • 69. dup B pop A swap B dup_x1 B dup2_x1 A
  • 70. dup2_x2 How do you swap doubles?
  • 75. dup2_x2 dconst_0 dconst_1 1.0 swap not allowed! 0.0
  • 76. dup2_x2 dconst_0 dconst_1 1.0 swap2 0.0
  • 77. dup2_x2 dconst_0 dconst_1 1.0 doesn’t swap2 exist 0.0
  • 78. dup2_x2 dconst_0 dconst_1 1.0 dup2_x2 0.0 1.0
  • 79. dup2_x2 dconst_0 dconst_1 0.0 dup2_x2 pop2 1.0
  • 80. dup2_x2 dconst_0 dconst_1 0.0 dup2_x2 pop2 1.0 profit! 
  • 83. 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
  • 84. 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
  • 85. 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
  • 86. Local Variables The table public int calculate(int); Code: maps Stack=2, Locals=2, Args_size=2 numbers to … names LocalVariableTable: Start Length Slot Name Signature 0 5 0 this LLocalVariables; 0 5 1 value I
  • 87. Local Variables public int calculate(int); Code: Stack=2, Locals=2, Args_size=2 Sized explicitly … LocalVariableTable: Start Length Slot Name Signature 0 5 0 this LLocalVariables; 0 5 1 value I
  • 88. Local Variables Stack var value depth value ldc "Hello" 0 0 astore_0 1 iconst_1 1 astore_1 2 aload_0 2 3 3 4 4
  • 89. Local Variables Stack var value depth value ldc "Hello" 0 0 "Hello" astore_0 1 iconst_1 1 astore_1 2 aload_0 2 3 3 4 4
  • 90. Local Variables Stack var value depth value ldc "Hello" 0 "Hello" 0 astore_0 1 iconst_1 1 astore_1 2 aload_0 2 3 3 4 4
  • 91. Local Variables Stack var value depth value ldc "Hello" 0 "Hello" 0 1 astore_0 1 iconst_1 1 astore_1 2 aload_0 2 3 3 4 4
  • 92. Local Variables Stack var value depth value ldc "Hello" 0 "Hello" 0 astore_0 1 1 iconst_1 1 astore_1 2 aload_0 2 3 3 4 4
  • 93. Local Variables Stack var value depth value ldc "Hello" 0 "Hello" 0 "Hello" astore_0 1 1 iconst_1 1 astore_1 2 aload_0 2 3 3 4 4
  • 94. load Local Variables Stack Table store
  • 96. Object Initialization new 0xBB <init> Instance initialization method <clinit> Class and interface initialization method
  • 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
  • 101. Object Initialization: new public Initializer(); Code:
  • 102. Object Initialization: new public Initializer(); Code: 0: aload_0
  • 103. Object Initialization: new public Initializer(); Code: 0: aload_0 1: invokespecial #1; //Method java/lang/Object."<init>":()V
  • 104. Object Initialization: new public Initializer(); Code: 0: aload_0 1: invokespecial #1; //Method java/lang/Object."<init>":()V 4: aload_0
  • 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
  • 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;
  • 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
  • 108. 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
  • 111. 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
  • 112.
  • 115. invokeXXX • invokestatic • invokespecial • invokevirtual • invokeinterface • invokedynamic
  • 116. invokestatic • invokestatic • invokespecial • invokevirtual Integer.valueOf(“42”) • invokeinterface • invokedynamic
  • 117. invokespecial • invokestatic <init> • invokespecial • invokevirtual private void foo(); • invokeinterface • invokedynamic super.method();
  • 118. invokevirtual class A • invokestatic A/method1 A/method2 • invokespecial • invokevirtual • invokeinterface • invokedynamic
  • 119. invokevirtual class A • invokestatic A/method1 A/method2 • invokespecial class B • invokevirtual • invokeinterface • invokedynamic
  • 120. invokevirtual class A • invokestatic A/method1 A/method2 • invokespecial class B • invokevirtual A/method1 B/method2 • invokeinterface B/method3 • invokedynamic
  • 121. invokeinterface class A • invokestatic A/method1 A/method2 • invokespecial class B impl X • invokevirtual A/method1 B/method2 • invokeinterface B/method3 X/methodX • invokedynamic
  • 122. invokeinterface class A • invokestatic A/method1 A/method2 • invokespecial class B impl X • invokevirtual A/method1 • invokeinterface B/method2 B/method3 D impl X X/methodX D/method1 • invokedynamic X/methodX
  • 123. invokeinterface class A • invokestatic A/method1 A/method2 • invokespecial class B impl X • invokevirtual A/method1 • invokeinterface B/method2 B/method3 D impl X X/methodX D/method1 • invokedynamic X/methodX
  • 124. invokeinterface class A • invokestatic A/method1 A/method2 • invokespecial class B impl X • invokevirtual A/method1 • invokeinterface B/method2 B/method3 D impl X X/methodX D/method1 • invokedynamic X/methodX Efficient Implementation of Java Interfaces: Invokeinterface Considered Harmless, Bowen Alpern, Anthony Cocchi, Stephen Fink, David Grove, and Derek Lieber, OOPSLA’01
  • 128. Method Invocation obj.method(param1, param2); push obj push param1 push param2 call method
  • 129. Method Invocation obj.method(param1, param2); obj push obj push param1 push param2 call method
  • 130. Method Invocation obj.method(param1, param2); param1 push obj obj push param1 push param2 call method
  • 131. Method Invocation obj.method(param1, param2); param2 push obj param1 push param1 push param2 obj call method
  • 132. Method Invocation obj.method(param1, param2); obj? push obj push param1 push param2 call method
  • 133. Method Invocation this.add(1, 2); 0: aload_0 1: iconst_1 2: iconst_2 3: invokevirtual #2; //Method add:(II)I
  • 137. 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 }
  • 138. Inner Classes public class Car extends j.l.Object{ public Car(); private void move(); class Car$Engine extends j.l.Object{ final Car this$0; static void access$000(Car); Code: Car$Engine(Car); 0: aload_0 1: invokespecial #1; // move: ()V; public void start(); 4: return Code: } 0: aload_0 1: getfield #1; //Field this$0:LCar; 4: invokestatic #3; // Car.access$000:(LCar;)V 7: return }
  • 139. Inner Classes public class Car extends j.l.Object{ public Car(); private void move(); class Car$Engine extends j.l.Object{ final Car this$0; static void access$000(Car); Code: Car$Engine(Car); 0: aload_0 1: invokespecial #1; // move: ()V; public void start(); 4: return Code: } 0: aload_0 1: getfield #1; //Field this$0:LCar; 4: invokestatic #3; // Car.access$000:(LCar;)V 7: return }
  • 140. “HOW DO THEY DO THAT?”
  • 141. object Singleton { def test={} }
  • 142. object Singleton { def test={} } $> scalac Singleton.scala Singleton.class Singleton$.class
  • 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 }
  • 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 }
  • 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 }
  • 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 {}; Code: 0: new #9; //class Singleton$ 3: invokespecial #12; //Method "<init>":()V 6: return public void test(); private Singleton$(); }
  • 147. 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$(); }
  • 148. 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$(); }
  • 149. 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
  • 150. object Singleton { def test={} }
  • 151. public class Singleton { public void test(){ Singleton$.MODULE$.test(); } } object Singleton { def test={} }
  • 152. public class Singleton { public void test(){ Singleton$.MODULE$.test(); } } public final class Singleton$ object Singleton { implements scala.ScalaObject { def test={} public static final Singleton$ MODULE$; } static { new Singleton$(); } private Singleton$(){ MODULE$ = this; } public void test() { } }
  • 154. class Groovy { } $> groovyc Groovy.groovy $> javap –c –p Groovy
  • 155. class Groovy { } $> groovyc Groovy.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);