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

JVM for Dummies - OSCON 2011
JVM for Dummies - OSCON 2011JVM for Dummies - OSCON 2011
JVM for Dummies - OSCON 2011
Charles Nutter
 
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
yohanbeschi
 

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

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
Carol 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 Scala
Takipi
 
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
Ludovic Poitou
 

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 2011
Anton Arhipov
 
Java review00
Java review00Java review00
Java review00
saryu2011
 
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
QUONTRASOLUTIONS
 
Java Bytecode Fundamentals - JUG.lv
Java Bytecode Fundamentals - JUG.lvJava Bytecode Fundamentals - JUG.lv
Java Bytecode Fundamentals - JUG.lv
Anton Arhipov
 

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.pdf
Anton 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 reloading
Anton 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

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Recently uploaded (20)

Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
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...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
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
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
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
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 

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);