SlideShare une entreprise Scribd logo
1  sur  141
Télécharger pour lire hors ligne
JVM Bytecode for
   Dummies
 (and for the rest of you, as well)
Intro
• Charles Oliver Nutter
 • “JRuby Guy”
 • Sun Microsystems 2006-2009
 • Engine Yard 2009-
• Primarily responsible for compiler, perf
 • Lots of bytecode generation
Two Parts
•   JVM Bytecode
    •   Inspection
    •   Generation
    •   How it works
•   JVM JIT
    •   How it works
    •   Monitoring
    •   Assembly (don’t be scared!)
Two Parts

                                      }
•   JVM Bytecode
    •   Inspection
                                          Today
    •   Generation
    •   How it works




                                      }
•   JVM JIT
    •   How it works                      Session 25141
                                          Hilton Yosemite ABC
    •   Monitoring
                                          Wednesday 10AM
    •   Assembly (don’t be scared!)
Bytecode Definition

• “... instruction sets designed for efficient
  execution by a software interpreter ...”
• “... suitable for further compilation into
  machine code.
Byte Code

• One-byte instructions
• 256 possible “opcodes”
• 200 in use on current JVMs
 • Room for more :-)
• Little variation since Java 1.0
Microsoft’s CLR

• Stack-based, but not interpreted
• Two-byte “Wordcodes”
• Similar operations to JVM
Why Learn It
• Know your platform
 • Full understanding from top to bottom
• Bytecode generation is fun and easy
 • Build your own language?
• May need to read bytecode someday
 • Many libraries generate bytecode
Hello World

public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello, world");
    }
}
javap
• Java class file disassembler
• Basic operation shows class structure
 • Methods, superclasses, interface, etc
• -c flag includes bytecode
• -public, -private, -protected
• -verbose for stack size, locals, args
javap

~/projects/bytecode_for_dummies ➔ javap HelloWorld
Compiled from "HelloWorld.java"
public class HelloWorld extends java.lang.Object{
    public HelloWorld();
    public static void main(java.lang.String[]);
}
javap -c
~/projects/bytecode_for_dummies ➔ javap -c HelloWorld
Compiled from "HelloWorld.java"
public class HelloWorld extends java.lang.Object{
public HelloWorld();
  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
   8:! return

}
javap -verbose
~/projects/bytecode_for_dummies ➔ javap -c -verbose HelloWorld
Compiled from "HelloWorld.java"
public class HelloWorld extends java.lang.Object
  SourceFile: "HelloWorld.java"
  minor version: 0
  major version: 50
  Constant pool:
const #1 = Method! #6.#15;!// java/lang/Object."<init>":()V
const #2 = Field!#16.#17;! / java/lang/System.out:Ljava/io/PrintStream;
                         /
const #3 = String! #18;! / Hello, world
                         /
const #4 = Method! #19.#20;! / java/io/PrintStream.println:(Ljava/lang/String;)V
                             /
const #5 = class!#21;! / HelloWorld
                     /
...

{
javap -verbose

...
public HelloWorld();
  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
javap -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 3: 0
   line 4: 8


}
TraceClassVisitor
$ java -cp <ASM stuff> org.objectweb.asm.util.TraceClassVisitor HelloWorld.class
// class version 50.0 (50)
// access flags 33
public class HelloWorld {


    // access flags 1
    public <init>()V
      ALOAD 0
      INVOKESPECIAL java/lang/Object.<init> ()V
      RETURN
      MAXSTACK = 1
      MAXLOCALS = 1

    // access flags 9
    public static main([Ljava/lang/String;)V
      GETSTATIC java/lang/System.out : Ljava/io/PrintStream;
      LDC "Hello, world"
      INVOKEVIRTUAL java/io/PrintStream.println (Ljava/lang/String;)V
      RETURN
      MAXSTACK = 2
      MAXLOCALS = 1
}
ASMifierClassVisitor
$ java   -cp <ASM stuff> org.objectweb.asm.util.ASMifierClassVisitor HelloWorld.class
import   java.util.*;
import   org.objectweb.asm.*;
import   org.objectweb.asm.attrs.*;
public   class HelloWorldDump implements Opcodes {

public static byte[] dump () throws Exception {

ClassWriter cw = new ClassWriter(0);
FieldVisitor fv;
MethodVisitor mv;
AnnotationVisitor av0;

cw.visit(V1_6, ACC_PUBLIC + ACC_SUPER, "HelloWorld", null, "java/lang/Object", null);
...
...
             ASMifierClassVisitor
{
mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
mv.visitCode();
mv.visitVarInsn(ALOAD, 0);
mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V");
mv.visitInsn(RETURN);
mv.visitMaxs(1, 1);
mv.visitEnd();
}
{
mv = cw.visitMethod(ACC_PUBLIC + ACC_STATIC, "main", "([Ljava/lang/String;)V", null, null);
mv.visitCode();
mv.visitFieldInsn(GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;");
mv.visitLdcInsn("Hello, world");
mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/
String;)V");
mv.visitInsn(RETURN);
mv.visitMaxs(2, 1);
mv.visitEnd();
}
cw.visitEnd();

return cw.toByteArray();
}
}
Thank you!
Thank you!
  (Just Kidding)
Let’s try something a
     little easier...
BiteScript

• (J)Ruby DSL for emitting JVM bytecode
 • Internal DSL
 • Primitive “macro” support
 • Reads like javap -c (but nicer)
• http://github.com/headius/bitescript
Installation
• Download JRuby from http://jruby.org
• Unpack, optionally add bin/ to PATH
 • Ahead of PATH if you have Ruby already
• [bin/]jruby -S gem install bitescript
• `bite myfile.bs` to run myfile.bs file
• `bitec myfile.bs` to compile myfile.bs file
BiteScript Users

• Mirah
 • Ruby-like language for writing Java code
 • BiteScript for JVM bytecode backend
• BrainF*ck implementation
• Other miscellaneous bytecode experiments
JiteScript

• Java API that mimics BiteScript
 • Using a few cute tricks ;-)
• Pretty close to javap output
• Typical Java library installation
• http://github.com/qmx/jitescript
JiteScript Users

• dyn.js
 • invokedynamic-based JavaScript impl
• ???
javap -c
~/projects/bytecode_for_dummies ➔ javap -c HelloWorld
Compiled from "HelloWorld.java"
public class HelloWorld extends java.lang.Object{
public HelloWorld();
  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
   8:! return

}
BiteScript

main do
  getstatic java.lang.System, "out",
             java.io.PrintStream
  ldc "Hello, world!"
  invokevirtual java.io.PrintStream, "println",
      [java.lang.Void::TYPE, java.lang.Object]
  returnvoid
end
BiteScript

import java.lang.System          JRuby’s “import”
import java.io.PrintStream        for Java classes
main do
  getstatic System, "out", PrintStream
  ldc "Hello, world!"
  invokevirtual PrintStream, "println", [void, object]
  returnvoid
end
                                        Shortcuts for
                                       void, int, string,
                                         object, etc
BiteScript

main do
  ldc "Hello, world!"
  aprintln
  returnvoid   A BiteScript “macro”
end
BiteScript

macro :aprintln do
  getstatic System, "out", PrintStream
  swap
  invokevirtual PrintStream, "println",
                [void, object]
end
The Basics

• Stack machine
• Basic operations
• Flow control
• Class structures
• Exception handling
Stack Machine
• The “operand stack” holds operands
• Operations push and/or pop stack values
 • Exceptions: nop, wide, goto, jsr/ret
• Stack must be consistent
 • Largest part of bytecode verifier
• Stack is explicitly sized per method
The JVM Stack
                                          Depth   Value
import java.lang.System
import java.io.PrintStream                 0

main do
                                           1
  getstatic System, "out", PrintStream
  ldc "Hello, world!"
  invokevirtual PrintStream, "println",
                                           2
                         [void, object]
  returnvoid                               3
end
                                           4
The JVM Stack
                                          Depth      Value
import java.lang.System
import java.io.PrintStream                 0      out (a PS)

main do
                                           1
  getstatic System, "out", PrintStream
  ldc "Hello, world!"
  invokevirtual PrintStream, "println",
                                           2
                         [void, object]
  returnvoid                               3
end
                                           4
The JVM Stack
                                          Depth        Value
import java.lang.System
import java.io.PrintStream                 0      “Hello, world!”

main do
                                           1        out (a PS)
  getstatic System, "out", PrintStream
  ldc "Hello, world!"
  invokevirtual PrintStream, "println",
                                           2
                         [void, object]
  returnvoid                               3
end
                                           4
The JVM Stack
                                          Depth   Value
import java.lang.System
import java.io.PrintStream                 0

main do
                                           1
  getstatic System, "out", PrintStream
  ldc "Hello, world!"
  invokevirtual PrintStream, "println",
                                           2
                         [void, object]
  returnvoid                               3
end
                                           4
The JVM Stack
                                          Depth   Value
import java.lang.System
import java.io.PrintStream                 0

main do
                                           1
  getstatic System, "out", PrintStream
  ldc "Hello, world!"
  invokevirtual PrintStream, "println",
                                           2
                         [void, object]
  returnvoid                               3
end
                                           4
Basic Operations

• Stack manipulation
• Local variables
• Math
• Boolean
Stack Operations
0x00    nop                   Do nothing.
0x57    pop           Discard top value from stack
0x58    pop2            Discard top two values
0x59    dup        Duplicate and push top value again
0x5A   dup_x1 Dup and push top value below second value
0x5B   dup_x2   Dup and push top value below third value
0x5C    dup2          Dup top two values and push
0x5D dup2_x1             ...below second value
0x5E dup2_x2              ...below third value
0x5F    swap              Swap top two values
Stack Juggling
             Depth    Value
dup
              0      value_0
pop
swap          1      value_1
dup_x1
              2
dup2_x2
              3

              4
Stack Juggling
             Depth    Value
dup
              0      value_0
pop
swap          1      value_0
dup_x1
              2      value_1
dup2_x2
              3

              4
Stack Juggling
             Depth    Value
dup
              0      value_0
pop
swap          1      value_1
dup_x1
              2
dup2_x2
              3

              4
Stack Juggling
             Depth    Value
dup
              0      value_1
pop
swap          1      value_0
dup_x1
              2
dup2_x2
              3

              4
Stack Juggling
             Depth    Value
dup
              0      value_1
pop
swap          1      value_0
dup_x1
              2      value_1
dup2_x2
              3

              4
Stack Juggling
             Depth    Value
dup
              0      value_1
pop
swap          1      value_0
dup_x1
              2      value_1
dup2_x2
              3      value_1

              4      value_0
Typed Opcodes
     <type><operation>
b     byte             Constant values
s    short          Local vars (load, store)
c     char
                Array operations (aload, astore)
i      int
                 Math ops (add, sub, mul, div)
l     long
                     Boolean and bitwise
f     float
d    double              Comparisons
a   reference            Conversions
Where’s boolean?

• Boolean is generally int 0 or 1
• Boolean operations push int 0 or 1
• Boolean branches expect 0 or nonzero
• To set a boolean...use int 0 or 1
Constant Values
  0x01      aconst_null                  Push null on stack
0x02-0x08 iload_[m1-5]             Push integer [-1 to 5] on stack
0x09-0x0A   lconst_[0,1]             Push long [0 or 1] on stack
0x0B-0x0D fconst_[0,1,2]          Push float [0.0, 1.0, 2.0] on stack
0x0E-0x0F dconst_[0,1]             Push double [0.0, 1.0] on stack
  0x10        bipush             Push byte value to stack as integer
  0x11        sipush            Push short value to stack as integer
  0x12          ldc        Push 32-bit constant to stack (int, float, string)
  0x14        ldc2_w        Push 64-bit constant to stack (long, double)
Why So Many?
• Reducing bytecode size
 • Special iconst_0 and friends take no args
 • bipush, sipush: only 8, 16 bits arguments
• Pre-optimizing JVM
 • Specialized instructions can be optimized
 • Doesn’t matter at all now
Constant Values
                 Depth   Value

 ldc "hello"      0
 dconst_1
                  1
 aconst_null
 bipush 4         2
 ldc_float 2.0
                  3
                  4
                  5
Constant Values
                 Depth    Value

 ldc "hello"      0      “hello”
 dconst_1
                  1
 aconst_null
 bipush 4         2
 ldc_float 2.0
                  3
                  4
                  5
Constant Values
                 Depth    Value

 ldc "hello"      0
 dconst_1
                         1.0d
                  1
 aconst_null
 bipush 4         2      “hello”
 ldc_float 2.0
                  3
                  4
                  5
Woah, Two Slots?

• JVM stack slots (and local vars) are 32-bit
• 64-bit values take up two slots
• “wide” before or “w” suffix
• 64-bit field updates not atomic!
 • Mind those concurrent longs/doubles!
Constant Values
                 Depth    Value

 ldc "hello"      0       null
 dconst_1
                  1
 aconst_null              1.0d
 bipush 4         2
 ldc_float 2.0
                  3      “hello”
                  4
                  5
Constant Values
                 Depth    Value

 ldc "hello"      0        4
 dconst_1
                  1       null
 aconst_null
 bipush 4         2
 ldc_float 2.0            1.0d
                  3
                  4      “hello”
                  5
Constant Values
                 Depth    Value

 ldc "hello"      0       2.0f
 dconst_1
                  1        4
 aconst_null
 bipush 4         2       null
 ldc_float 2.0
                  3
                          1.0
                  4
                  5      “hello”
Local Variable Table

• Local variables numbered from 0
 • Instance methods have “this” at 0
• Separate table maps numbers to names
• Explicitly sized in method definition
Local Variables
  0x15         iload      Load integer from local variable onto stack
   0x16        lload                          ...long...
   0x17        fload                           ...float...
   0x18       dload                         ...double...
   0x19       aload                       ...reference...
0x1A-0x2D Packed loads                iload_0, aload_3, etc
   0x36       istore      Store integer from stack into local variable
   0x37       lstore                          ...long...
   0x38       fstore                          ...float...
   0x39      dstore                         ...double...
   0x3A      astore                       ...reference...
0x3B-0x4E Packed stores             fstore_2, dstore_0, etc
   0x84         iinc        Add given amount to int local variable
Local Variables
Var   Value                     Depth   Value
                  ldc "hello"
0                 bipush 4       0
                  istore 3
1                 dconst_0       1
                  dstore 1
2                 astore 0       2
                  aload 0
3                 iinc 3, 5
                                 3

4                                4
Local Variables
Var   Value                     Depth    Value
                  ldc "hello"
0                 bipush 4       0      “hello”
                  istore 3
1                 dconst_0       1
                  dstore 1
2                 astore 0       2
                  aload 0
3                 iinc 3, 5
                                 3

4                                4
Local Variables
Var   Value                     Depth    Value
                  ldc "hello"
0                 bipush 4       0        4
                  istore 3
1                 dconst_0       1      “hello”
                  dstore 1
2                 astore 0       2
                  aload 0
3                 iinc 3, 5
                                 3

4                                4
Local Variables
Var   Value                     Depth    Value
                  ldc "hello"
0                 bipush 4       0      “hello”
                  istore 3
1                 dconst_0       1
                  dstore 1
2                 astore 0       2
                  aload 0
3      4          iinc 3, 5
                                 3

4                                4
Local Variables
Var   Value                     Depth    Value
                  ldc "hello"
0                 bipush 4       0
                  istore 3               0.0
1                 dconst_0       1
                  dstore 1
2                 astore 0       2      “hello”
                  aload 0
3      4          iinc 3, 5
                                 3

4                                4
Local Variables
Var   Value                     Depth    Value
                  ldc "hello"
0                 bipush 4       0      “hello”
                  istore 3
1                 dconst_0       1
      0.0         dstore 1
2                 astore 0       2
                  aload 0
3      4          iinc 3, 5
                                 3

4                                4
Local Variables
Var    Value                     Depth   Value
                   ldc "hello"
0     “hello”      bipush 4       0
                   istore 3
1                  dconst_0       1
        0.0        dstore 1
2                  astore 0       2
                   aload 0
3        4         iinc 3, 5
                                  3

4                                 4
Local Variables
Var    Value                     Depth    Value
                   ldc "hello"
0     “hello”      bipush 4       0      “hello”
                   istore 3
1                  dconst_0       1
       0.0         dstore 1
2                  astore 0       2
                   aload 0
3       4          iinc 3, 5
                                  3

4                                 4
Local Variables
Var    Value                     Depth    Value
                   ldc "hello"
0     “hello”      bipush 4       0      “hello”
                   istore 3
1                  dconst_0       1
       0.0         dstore 1
2                  astore 0       2
                   aload 0
3       9          iinc 3, 5
                                  3

4                                 4
Arrays
0x2E-0x35   [i,l,f,d,a,b,c,d]aload Load [int, long, ...] from array (on stack) to stack

0x4F-0x56   [i,l,f,d,a,b,c,d]astore Store [int, long, ...] from stack to array (on stack)

  0xBC           newarray                    Construct new primitive array

  0xBD           anewarray                  Construct new reference array

  0xBE          arraylength                          Get array length

  0xC5        multianewarray                Create multi-dimensional array
Arrays
               Depth   Value
iconst_2
newarray int    0
dup
iconst_0        1
iconst_m1
                2
iastore
iconst_0        3
iaload
                4
                5
Arrays
               Depth   Value
iconst_2
newarray int    0       2
dup
iconst_0        1
iconst_m1
                2
iastore
iconst_0        3
iaload
                4
                5
Arrays
               Depth       Value
iconst_2
newarray int    0      int[2] {0,0}
dup
iconst_0        1
iconst_m1
                2
iastore
iconst_0        3
iaload
                4
                5
Arrays
               Depth       Value
iconst_2
newarray int    0      int[2] {0,0}
dup
iconst_0        1      int[2] {0,0}
iconst_m1
                2
iastore
iconst_0        3
iaload
                4
                5
Arrays
               Depth      Value
iconst_2
newarray int    0           0
dup
iconst_0        1      int[2] {0,0}
iconst_m1
                2      int[2] {0,0}
iastore
iconst_0        3
iaload
                4
                5
Arrays
               Depth      Value
iconst_2
newarray int    0          -1
dup
iconst_0        1           0
iconst_m1
                2      int[2] {0,0}
iastore
iconst_0        3      int[2] {0,0}
iaload
                4
                5
Arrays
               Depth       Value
iconst_2
newarray int    0      int[2] {-1, 0}
dup
iconst_0        1
iconst_m1
                2
iastore
iconst_0        3
iaload
                4
                5
Arrays
               Depth       Value
iconst_2
newarray int    0            0
dup
iconst_0        1      int[2] {-1, 0}
iconst_m1
                2
iastore
iconst_0        3
iaload
                4
                5
Arrays
               Depth   Value
iconst_2
newarray int    0      -1
dup
iconst_0        1
iconst_m1
                2
iastore
iconst_0        3
iaload
                4
                5
Math Operations
         add    subtract   multiply   divide   remainder   negate
          +        -          *          /        %          -()

 int     iadd    isub       imul      idiv       irem      ineg

 long    ladd    lsub       lmul      ldiv       lrem      lneg

 float    fadd    fsub       fmul      fdiv       frem      fneg

double   dadd    dsub      dmul       ddiv      drem       dneg
Boolean and Bitwise

                             unsigned
      shift left shift right               and    or    xor
                             shift right

int     ishl        ishr       iushr       iand   ior   ixor
Conversions
                                 To:
                 int    long   float    double   byte   char   short

         int      -     i2l    i2f      i2d     i2b    i2c    i2s
From:




         long    l2i     -     l2f      l2d      -      -       -

         float    f2i    f2l     -       f2d      -      -       -

        double   d2i    d2l    d2f       -       -      -       -
Comparisons
0x94   lcmp           Compare two longs, push int -1, 0, 1


0x95   fcmpl    Compare two floats, push in -1, 0, 1 (-1 for NaN)


0x96   fcmpg    Compare two floats, push in -1, 0, 1 (1 for NaN)


0x97   dcmpl   Compare two doubles, push in -1, 0, 1 (-1 for NaN)


0x98   dcmpg   Compare two doubles, push in -1, 0, 1 (1 for NaN)
Flow Control

• Inspect stack and branch
 • Or just branch, via goto
• Labels mark branch targets
• Wide variety of tests
Flow Control
0x99        ifeq                          If zero on stack, branch
0x9A        ifne                       If nonzero on stack, branch
0x9B          iflt                If stack value is less than zero, branch
0x9C         ifge    If stack value is greater than or equal to zero, branch
0x9D         ifgt             If stack value is greater than zero, branch
0x9E         ifle        If stack value is less than or equal to zero, branch
0x9F   if_icmpeq                If two integers on stack are eq, branch
0xA0   if_icmpne                If two integers on stack are ne, branch
0xA1     if_icmplt               If two integers on stack are lt, branch
0xA2    if_icmpge               If two integers on stack are ge, branch
0xA3    if_icmpgt                                   If tw
                                If two integers on stack are gt, branch
0xA4    if_icmple                If two integers on stack are le, branch
0xA5   if_acmpeq         If two references on stack are the same, branch
0xA6   if_acmpne          If two references on stack are different, branch
0xA7        goto                                  GOTO!
Other Flow Control
  0xA8            jsr                 Jump to subroutine (deprecated)

  0xA9            ret               Return from subroutine (deprecated)

  0xAA       tableswitch        Branch using an indexed table of jump offsets

  0xAB      lookupswitch      Branch using a lookup-based table of jump offsets

0xAC-0xB0 [i,l,f,d,a]return    Return (int, long, float, double, reference) value

  0xB1          return           Void return (exit method, return nothing)

  0xC6           ifnull                  If reference on stack is null

  0xC7         ifnonnull               If reference on stack is not null
Flow Control
aload 0
ldc 0
aaload                            Depth     Value
ldc "branch"                                String[]
invokevirtual string, "equals",    0      {“branch”}
              [boolean, object]
ifne :branch
                                   1
ldc "Not equal!"
                                   2
aprintln
goto :end                          3
label :branch
ldc "Equal!"                       4
aprintln
label :end                         5
returnvoid
Flow Control
aload 0
ldc 0
aaload                            Depth         Value
ldc "branch"
invokevirtual string, "equals",    0              0
              [boolean, object]
ifne :branch
                                   1      String[]{“branch”}

ldc "Not equal!"
                                   2
aprintln
goto :end                          3
label :branch
ldc "Equal!"                       4
aprintln
label :end                         5
returnvoid
Flow Control
aload 0
ldc 0
aaload                            Depth    Value
ldc "branch"
invokevirtual string, "equals",    0      “branch”
              [boolean, object]
ifne :branch
                                   1
ldc "Not equal!"
                                   2
aprintln
goto :end                          3
label :branch
ldc "Equal!"                       4
aprintln
label :end                         5
returnvoid
Flow Control
aload 0
ldc 0
aaload                            Depth    Value
ldc "branch"
invokevirtual string, "equals",    0      “branch”
              [boolean, object]
ifne :branch
                                   1      “branch”

ldc "Not equal!"
                                   2
aprintln
goto :end                          3
label :branch
ldc "Equal!"                       4
aprintln
label :end                         5
returnvoid
Flow Control
aload 0
ldc 0
aaload                            Depth   Value
ldc "branch"
invokevirtual string, "equals",    0       1
              [boolean, object]
ifne :branch
                                   1
ldc "Not equal!"
                                   2
aprintln
goto :end                          3
label :branch
ldc "Equal!"                       4
aprintln
label :end                         5
returnvoid
Flow Control
aload 0
ldc 0
aaload                            Depth   Value
ldc "branch"
invokevirtual string, "equals",    0
              [boolean, object]
ifne :branch
                                   1
ldc "Not equal!"
                                   2
aprintln
goto :end                          3
label :branch
ldc "Equal!"                       4
aprintln
label :end                         5
returnvoid
Flow Control
aload 0
ldc 0
aaload                            Depth   Value
ldc "branch"
invokevirtual string, "equals",    0
              [boolean, object]
ifne :branch
                                   1
ldc "Not equal!"
                                   2
aprintln
goto :end                          3
label :branch
ldc "Equal!"                       4
aprintln
label :end                         5
returnvoid
Flow Control
aload 0
ldc 0
aaload                            Depth    Value
ldc "branch"
invokevirtual string, "equals",    0      “Equal!”
              [boolean, object]
ifne :branch
                                   1
ldc "Not equal!"
                                   2
aprintln
goto :end                          3
label :branch
ldc "Equal!"                       4
aprintln
label :end                         5
returnvoid
Flow Control
aload 0
ldc 0
aaload                            Depth   Value
ldc "branch"
invokevirtual string, "equals",    0
              [boolean, object]
ifne :branch
                                   1
ldc "Not equal!"
                                   2
aprintln
goto :end                          3
label :branch
ldc "Equal!"                       4
aprintln
label :end                         5
returnvoid
Classes and Types

• Signatures!!!
 • Probably the most painful part
 • ...but not a big deal if you understand
Using Classes
0xB2      getstatic                 Fetch static field from class
0xB3      putstatic                   Set static field in class
0xB4      getfield                 Get instance field from object
0xB5      setfield                   Set instance field in object
0xB6    invokevirtual           Invoke instance method on object
0xB7    invokespecial        Invoke constructor or “super” on object
0xB8    invokestatic               Invoke static method on class
0xB9   invokeinterface          Invoke interface method on object
0xBA   invokedynamic       Invoke method dynamically on object (Java 7)
0xBB        new                  Construct new instance of object
0xC0     checkcast                Attempt to cast object to type
0xC1     instanceof      Push nonzero if object is instanceof specified type
Using Classes
new ArrayList
dup
invokespecial ArrayList, '<init>',   Depth        Value
              [void]
                                              an ArrayList
checkcast Collection                  0      (uninitialized)
dup
ldc "first element"                   1
invokeinterface Collection, 'add',
                [boolean, object]     2
pop
checkcast ArrayList                   3
ldc 0
invokevirtual ArrayList, 'get',       4
              [object, int]
aprintln                              5
returnvoid
Using Classes
new ArrayList
dup
invokespecial ArrayList, '<init>',   Depth        Value
              [void]
                                              an ArrayList
checkcast Collection                  0      (uninitialized)
dup
                                                an ArrayList
ldc "first element"                   1        (uninitialized)
invokeinterface Collection, 'add',
                [boolean, object]     2
pop
checkcast ArrayList                   3
ldc 0
invokevirtual ArrayList, 'get',       4
              [object, int]
aprintln                              5
returnvoid
Using Classes
new ArrayList
dup
invokespecial ArrayList, '<init>',   Depth      Value
              [void]
checkcast Collection                  0      an ArrayList
dup
ldc "first element"                   1
invokeinterface Collection, 'add',
                [boolean, object]     2
pop
checkcast ArrayList                   3
ldc 0
invokevirtual ArrayList, 'get',       4
              [object, int]
aprintln                              5
returnvoid
Using Classes
new ArrayList
dup
invokespecial ArrayList, '<init>',   Depth      Value
              [void]
checkcast Collection                  0      a Collection
dup
ldc "first element"                   1
invokeinterface Collection, 'add',
                [boolean, object]     2
pop
checkcast ArrayList                   3
ldc 0
invokevirtual ArrayList, 'get',       4
              [object, int]
aprintln                              5
returnvoid
Using Classes
new ArrayList
dup
invokespecial ArrayList, '<init>',   Depth       Value
              [void]
checkcast Collection                  0      a Collection
dup
ldc "first element"                   1       a Collection
invokeinterface Collection, 'add',
                [boolean, object]     2
pop
checkcast ArrayList                   3
ldc 0
invokevirtual ArrayList, 'get',       4
              [object, int]
aprintln                              5
returnvoid
Using Classes
new ArrayList
dup
invokespecial ArrayList, '<init>',   Depth      Value
              [void]
                                               “first
checkcast Collection                  0      element”
dup
ldc "first element"                   1      a Collection
invokeinterface Collection, 'add',
                [boolean, object]     2      a Collection
pop
checkcast ArrayList                   3
ldc 0
invokevirtual ArrayList, 'get',       4
              [object, int]
aprintln                              5
returnvoid
Using Classes
new ArrayList
dup
invokespecial ArrayList, '<init>',   Depth      Value
              [void]
checkcast Collection                  0       1 (true)
dup
ldc "first element"                   1      a Collection
invokeinterface Collection, 'add',
                [boolean, object]     2
pop
checkcast ArrayList                   3
ldc 0
invokevirtual ArrayList, 'get',       4
              [object, int]
aprintln                              5
returnvoid
Using Classes
new ArrayList
dup
invokespecial ArrayList, '<init>',   Depth      Value
              [void]
checkcast Collection                  0      a Collection
dup
ldc "first element"                   1
invokeinterface Collection, 'add',
                [boolean, object]     2
pop
checkcast ArrayList                   3
ldc 0
invokevirtual ArrayList, 'get',       4
              [object, int]
aprintln                              5
returnvoid
Using Classes
new ArrayList
dup
invokespecial ArrayList, '<init>',   Depth      Value
              [void]
checkcast Collection                  0      an ArrayList
dup
ldc "first element"                   1
invokeinterface Collection, 'add',
                [boolean, object]     2
pop
checkcast ArrayList                   3
ldc 0
invokevirtual ArrayList, 'get',       4
              [object, int]
aprintln                              5
returnvoid
Using Classes
new ArrayList
dup
invokespecial ArrayList, '<init>',   Depth      Value
              [void]
checkcast Collection                  0           0
dup
ldc "first element"                   1      an ArrayList
invokeinterface Collection, 'add',
                [boolean, object]     2
pop
checkcast ArrayList                   3
ldc 0
invokevirtual ArrayList, 'get',       4
              [object, int]
aprintln                              5
returnvoid
Using Classes
new ArrayList
dup
invokespecial ArrayList, '<init>',   Depth     Value
              [void]
                                               “first
checkcast Collection                  0      element”
dup
ldc "first element"                   1
invokeinterface Collection, 'add',
                [boolean, object]     2
pop
checkcast ArrayList                   3
ldc 0
invokevirtual ArrayList, 'get',       4
              [object, int]
aprintln                              5
returnvoid
Using Classes
new ArrayList
dup
invokespecial ArrayList, '<init>',   Depth   Value
              [void]
checkcast Collection                  0
dup
ldc "first element"                   1
invokeinterface Collection, 'add',
                [boolean, object]     2
pop
checkcast ArrayList                   3
ldc 0
invokevirtual ArrayList, 'get',       4
              [object, int]
aprintln                              5
returnvoid
Invokedynamic

• New bytecode in Java 7
• Target method is wired up by user code
• Method handles are the wiring
Emitting Invokedynamic
• Signature is still required
 • But can be almost anything
• Method name is still required
 • But can be almost anything
• MethodHandle for bootstrapping
 • Bytecode-level function pointer, basically
java.lang.invoke
•   MethodHandles
    •   Function points
    •   Adapters (arg juggling, catch, conditionals)
•   CallSites
    •   Place to bind your MH chain
•   SwitchPoint
    •   Zero-cost volatile boolean branch
import   java.lang.invoke.MethodHandle
import   java.lang.invoke.MethodType
import   java.lang.invoke.CallSite
import   java.lang.invoke.ConstantCallSite
import   java.lang.invoke.MethodHandles::Lookup
JClass   = java.lang.Class
Target Method

# The method we want to invoke, prints given string
public_static_method :print, [], void, string do
  aload 0
  aprintln
  returnvoid
end
Invokedynamic
# Our main method, which does one invokedynamic
main do
  # handle for our bootstrap, which binds invokedynamic to a CallSite
  bootstrap = mh_invokestatic this, 'bootstrap',
                              CallSite, Lookup, string, MethodType

  ldc 'Hello, invokedynamic!'
  invokedynamic 'print', [void, string], bootstrap
  returnvoid
end
Invokedynamic
# Our main method, which does one invokedynamic
main do
  # handle for our bootstrap, which binds invokedynamic to a CallSite
  bootstrap = mh_invokestatic this, 'bootstrap',
                              CallSite, Lookup, string, MethodType

  ldc 'Hello, invokedynamic!'
  invokedynamic 'print', [void, string], bootstrap
  returnvoid
end
Invokedynamic
# Our main method, which does one invokedynamic
main do
  # handle for our bootstrap, which binds invokedynamic to a CallSite
  bootstrap = mh_invokestatic this, 'bootstrap',
                              CallSite, Lookup, string, MethodType

  ldc 'Hello, invokedynamic!'
  invokedynamic 'print', [void, string], bootstrap
  returnvoid
end
Invokedynamic
# Our main method, which does one invokedynamic
main do
  # handle for our bootstrap, which binds invokedynamic to a CallSite
  bootstrap = mh_invokestatic this, 'bootstrap',
                              CallSite, Lookup, string, MethodType

  ldc 'Hello, invokedynamic!'
  invokedynamic 'print', [void, string], bootstrap
  returnvoid
end
Bootstrap
# The bootstrap method, which binds our dynamic call
public_static_method :bootstrap, [], CallSite,
                     Lookup, string, MethodType do
  # Constant since we bind just once directly
  new ConstantCallSite
  dup

  # Locate the method indicated by name + type on current class
  aload 0   # Lookup
  ldc this # this class
  aload 1   # String
  aload 2   # MethodType
  invokevirtual Lookup, 'findStatic',
                [MethodHandle, JClass, string, MethodType]

  # finish constructing call site and return
  invokespecial ConstantCallSite, '<init>', [void, MethodHandle]
  areturn
end
Bootstrap
# The bootstrap method, which binds our dynamic call
public_static_method :bootstrap, [], CallSite,
                     Lookup, string, MethodType do
  # Constant since we bind just once directly
  new ConstantCallSite
  dup

  # Locate the method indicated by name + type on current class
  aload 0   # Lookup
  ldc this # this class
  aload 1   # String
  aload 2   # MethodType
  invokevirtual Lookup, 'findStatic',
                [MethodHandle, JClass, string, MethodType]

  # finish constructing call site and return
  invokespecial ConstantCallSite, '<init>', [void, MethodHandle]
  areturn
end
Bootstrap
# The bootstrap method, which binds our dynamic call
public_static_method :bootstrap, [], CallSite,
                     Lookup, string, MethodType do
  # Constant since we bind just once directly
  new ConstantCallSite
  dup

  # Locate the method indicated by name + type on current class
  aload 0   # Lookup
  ldc this # this class
  aload 1   # String
  aload 2   # MethodType
  invokevirtual Lookup, 'findStatic',
                [MethodHandle, JClass, string, MethodType]

  # finish constructing call site and return
  invokespecial ConstantCallSite, '<init>', [void, MethodHandle]
  areturn
end
Bootstrap
# The bootstrap method, which binds our dynamic call
public_static_method :bootstrap, [], CallSite,
                     Lookup, string, MethodType do
  # Constant since we bind just once directly
  new ConstantCallSite
  dup

  # Locate the method indicated by name + type on current class
  aload 0   # Lookup
  ldc this # this class
  aload 1   # String
  aload 2   # MethodType
  invokevirtual Lookup, 'findStatic',
                [MethodHandle, JClass, string, MethodType]

  # finish constructing call site and return
  invokespecial ConstantCallSite, '<init>', [void, MethodHandle]
  areturn
end
Bootstrap
# The bootstrap method, which binds our dynamic call
public_static_method :bootstrap, [], CallSite,
                     Lookup, string, MethodType do
  # Constant since we bind just once directly
  new ConstantCallSite
  dup

  # Locate the method indicated by name + type on current class
  aload 0   # Lookup
  ldc this # this class
  aload 1   # String
  aload 2   # MethodType
  invokevirtual Lookup, 'findStatic',
                [MethodHandle, JClass, string, MethodType]

  # finish constructing call site and return
  invokespecial ConstantCallSite, '<init>', [void, MethodHandle]
  areturn
end
Exceptions and
          Synchronization
                      Table structure for a method indicating start/end of
 -       trycatch
                            try/catch and logic to run on exception


0xC2   monitorenter    Enter synchronized block against object on stack


0xC3   monitorexit       Exit synchronized block (against same object)
More Examples


• A simple loop
• Fibonacci
A Simple Loop
  main do
    aload 0
    push_int 0
    aaload
    label :top
    dup
    aprintln
    goto :top
    returnvoid
  end
Fibonacci
public_static_method "fib", [], int, int do
  iload 0
  ldc 2
  if_icmpge :recurse
  iload 0
  ireturn
  label :recurse
  iload 0
  ldc 1
  isub
  invokestatic this, "fib", [int, int]
  iload 0
  ldc 2
  isub
  invokestatic this, "fib", [int, int]
  iadd
  ireturn
end
main do
  load_times
  istore 1
                   Fibonacci
  ldc "Raw bytecode fib(45) performance:"
  aprintln

  label :top
  iload 1
  ifeq :done
  iinc 1, -1

  start_timing 2
  ldc 45
  invokestatic this, "fib", [int, int]
  pop
  end_timing 2

  ldc "Time: "
  aprintln
  lprintln 2
  goto :top

  label :done
  returnvoid
end
main do
  load_times
  istore 1
                   Fibonacci
  ldc "Raw bytecode fib(45) performance:"
  aprintln

  label :top
  iload 1
  ifeq :done
  iinc 1, -1

  start_timing 2
                                            Macros
  ldc 45
  invokestatic this, "fib", [int, int]
  pop
  end_timing 2

  ldc "Time: "
  aprintln
  lprintln 2
  goto :top

  label :done
  returnvoid
end
Fibonacci

macro :load_times do
  aload 0
  ldc 0
  aaload # number of times
  invokestatic JInteger, 'parseInt',
               [int, string]
end
Fibonacci

macro :start_timing do |i|
  load_time
  lstore i
end
Fibonacci

macro :load_time do
  invokestatic System, "currentTimeMillis", long
end
Fibonacci
macro :end_timing do |i|
  load_time
  lload i
  lsub
  lstore i
end
Fibonacci
macro :lprintln do |i|
  getstatic System, "out", PrintStream
  lload i
  invokevirtual PrintStream, "println",
                [void, long]
end
Real-world Cases
• Reflection-free invocation
 • JRuby, Groovy, other languages
• Bytecoded data objects
 • Hibernate, other data layers
 • java.lang.reflect.Proxy and others
• Language compilers
Tools

• BiteScript
 • So much fun
 • Ruby, so that’s even better
• JiteScript
• ASM - defacto standard library
Part 2 Topics
•   Tracking your bytecode    •   Dumping JVM JIT
    through the JVM               assembly output

•   How the JVM optimizes     •   x86 assembler language
    running code                  for dummies!

•   Monitoring JVM JIT
    compilation

•   Inspecting JVM inlining
Pluggity

• Many thanks to Engine Yard
 • JRuby and Java PaaS
 • JRuby support and services
 • sales@engineyard.com
Pluggity
Pluggity
• Migrating to JRuby on Rails
  5:30 Mon, Parc 55 Market Street
• JVM JIT for Dummies                Part 2
  10:00 Wed, Parc 55 Market street
• JRuby + Java + Cloud
  3:00 Wed, Parc 55 Embarcadero
• Real World JRuby
  4:30 Wed, Parc 55 Market Street
Pluggity

• JRuby meetup/party
  Engine Yard HQ
  500 Third Street, Suite 510
  Tuesday, 6:30PM
• Try JRuby on EY Cloud
  http://engineyard.com/tryjruby
Thank you!

• headius@headius.com, @headius
• http://blog.headius.com
• http://github.com/headius/bitescript
• “java virtual machine specification”
• “jvm opcodes”

Contenu connexe

Tendances

Making Java more dynamic: runtime code generation for the JVM
Making Java more dynamic: runtime code generation for the JVMMaking Java more dynamic: runtime code generation for the JVM
Making Java more dynamic: runtime code generation for the JVMRafael Winterhalter
 
为啥别读HotSpot VM的源码(2012-03-03)
为啥别读HotSpot VM的源码(2012-03-03)为啥别读HotSpot VM的源码(2012-03-03)
为啥别读HotSpot VM的源码(2012-03-03)Kris Mok
 
Bytecode Manipulation with a Java Agent and Byte Buddy
Bytecode Manipulation with a Java Agent and Byte BuddyBytecode Manipulation with a Java Agent and Byte Buddy
Bytecode Manipulation with a Java Agent and Byte BuddyKoichi Sakata
 
JEP280: Java 9 で文字列結合の処理が変わるぞ!準備はいいか!? #jjug_ccc
JEP280: Java 9 で文字列結合の処理が変わるぞ!準備はいいか!? #jjug_cccJEP280: Java 9 で文字列結合の処理が変わるぞ!準備はいいか!? #jjug_ccc
JEP280: Java 9 で文字列結合の処理が変わるぞ!準備はいいか!? #jjug_cccYujiSoftware
 
Java 8-streams-collectors-patterns
Java 8-streams-collectors-patternsJava 8-streams-collectors-patterns
Java 8-streams-collectors-patternsJosé Paumard
 
Java Crash分析(2012-05-10)
Java Crash分析(2012-05-10)Java Crash分析(2012-05-10)
Java Crash分析(2012-05-10)Kris Mok
 
Java I/O and Object Serialization
Java I/O and Object SerializationJava I/O and Object Serialization
Java I/O and Object SerializationNavneet Prakash
 
Java Virtual Machine - Internal Architecture
Java Virtual Machine - Internal ArchitectureJava Virtual Machine - Internal Architecture
Java Virtual Machine - Internal Architecturesubnesh
 
[Effective Kotlin 讀書會] 第八章 Efficient collection processing 導讀
[Effective Kotlin 讀書會] 第八章 Efficient collection processing 導讀[Effective Kotlin 讀書會] 第八章 Efficient collection processing 導讀
[Effective Kotlin 讀書會] 第八章 Efficient collection processing 導讀Shengyou Fan
 
1장 Java란 무엇인가.key
1장 Java란 무엇인가.key1장 Java란 무엇인가.key
1장 Java란 무엇인가.key김 한도
 
Java Virtual Machine (JVM), Difference JDK, JRE & JVM
Java Virtual Machine (JVM), Difference JDK, JRE & JVMJava Virtual Machine (JVM), Difference JDK, JRE & JVM
Java Virtual Machine (JVM), Difference JDK, JRE & JVMshamnasain
 
Play with FILE Structure - Yet Another Binary Exploit Technique
Play with FILE Structure - Yet Another Binary Exploit TechniquePlay with FILE Structure - Yet Another Binary Exploit Technique
Play with FILE Structure - Yet Another Binary Exploit TechniqueAngel Boy
 
Exploiting Deserialization Vulnerabilities in Java
Exploiting Deserialization Vulnerabilities in JavaExploiting Deserialization Vulnerabilities in Java
Exploiting Deserialization Vulnerabilities in JavaCODE WHITE GmbH
 
3장. Garbage Collection
3장. Garbage Collection3장. Garbage Collection
3장. Garbage Collection김 한도
 
Core java concepts
Core java  conceptsCore java  concepts
Core java conceptsRam132
 
Kotlin - scope functions and collections
Kotlin - scope functions and collectionsKotlin - scope functions and collections
Kotlin - scope functions and collectionsWei-Shen Lu
 
JUnit & Mockito, first steps
JUnit & Mockito, first stepsJUnit & Mockito, first steps
JUnit & Mockito, first stepsRenato Primavera
 
A quick and fast intro to Kotlin
A quick and fast intro to Kotlin A quick and fast intro to Kotlin
A quick and fast intro to Kotlin XPeppers
 

Tendances (20)

Java persistence api 2.1
Java persistence api 2.1Java persistence api 2.1
Java persistence api 2.1
 
Making Java more dynamic: runtime code generation for the JVM
Making Java more dynamic: runtime code generation for the JVMMaking Java more dynamic: runtime code generation for the JVM
Making Java more dynamic: runtime code generation for the JVM
 
为啥别读HotSpot VM的源码(2012-03-03)
为啥别读HotSpot VM的源码(2012-03-03)为啥别读HotSpot VM的源码(2012-03-03)
为啥别读HotSpot VM的源码(2012-03-03)
 
Bytecode Manipulation with a Java Agent and Byte Buddy
Bytecode Manipulation with a Java Agent and Byte BuddyBytecode Manipulation with a Java Agent and Byte Buddy
Bytecode Manipulation with a Java Agent and Byte Buddy
 
JEP280: Java 9 で文字列結合の処理が変わるぞ!準備はいいか!? #jjug_ccc
JEP280: Java 9 で文字列結合の処理が変わるぞ!準備はいいか!? #jjug_cccJEP280: Java 9 で文字列結合の処理が変わるぞ!準備はいいか!? #jjug_ccc
JEP280: Java 9 で文字列結合の処理が変わるぞ!準備はいいか!? #jjug_ccc
 
Java 8-streams-collectors-patterns
Java 8-streams-collectors-patternsJava 8-streams-collectors-patterns
Java 8-streams-collectors-patterns
 
Java Crash分析(2012-05-10)
Java Crash分析(2012-05-10)Java Crash分析(2012-05-10)
Java Crash分析(2012-05-10)
 
Java I/O and Object Serialization
Java I/O and Object SerializationJava I/O and Object Serialization
Java I/O and Object Serialization
 
Java Virtual Machine - Internal Architecture
Java Virtual Machine - Internal ArchitectureJava Virtual Machine - Internal Architecture
Java Virtual Machine - Internal Architecture
 
[Effective Kotlin 讀書會] 第八章 Efficient collection processing 導讀
[Effective Kotlin 讀書會] 第八章 Efficient collection processing 導讀[Effective Kotlin 讀書會] 第八章 Efficient collection processing 導讀
[Effective Kotlin 讀書會] 第八章 Efficient collection processing 導讀
 
1장 Java란 무엇인가.key
1장 Java란 무엇인가.key1장 Java란 무엇인가.key
1장 Java란 무엇인가.key
 
Java Virtual Machine (JVM), Difference JDK, JRE & JVM
Java Virtual Machine (JVM), Difference JDK, JRE & JVMJava Virtual Machine (JVM), Difference JDK, JRE & JVM
Java Virtual Machine (JVM), Difference JDK, JRE & JVM
 
Play with FILE Structure - Yet Another Binary Exploit Technique
Play with FILE Structure - Yet Another Binary Exploit TechniquePlay with FILE Structure - Yet Another Binary Exploit Technique
Play with FILE Structure - Yet Another Binary Exploit Technique
 
Exploiting Deserialization Vulnerabilities in Java
Exploiting Deserialization Vulnerabilities in JavaExploiting Deserialization Vulnerabilities in Java
Exploiting Deserialization Vulnerabilities in Java
 
3장. Garbage Collection
3장. Garbage Collection3장. Garbage Collection
3장. Garbage Collection
 
Core java concepts
Core java  conceptsCore java  concepts
Core java concepts
 
Second Level Cache in JPA Explained
Second Level Cache in JPA ExplainedSecond Level Cache in JPA Explained
Second Level Cache in JPA Explained
 
Kotlin - scope functions and collections
Kotlin - scope functions and collectionsKotlin - scope functions and collections
Kotlin - scope functions and collections
 
JUnit & Mockito, first steps
JUnit & Mockito, first stepsJUnit & Mockito, first steps
JUnit & Mockito, first steps
 
A quick and fast intro to Kotlin
A quick and fast intro to Kotlin A quick and fast intro to Kotlin
A quick and fast intro to Kotlin
 

En vedette

JavaOne 2012 - JVM JIT for Dummies
JavaOne 2012 - JVM JIT for DummiesJavaOne 2012 - JVM JIT for Dummies
JavaOne 2012 - JVM JIT for DummiesCharles Nutter
 
Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...
Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...
Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...Charles Nutter
 
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
 
JVM: A Platform for Multiple Languages
JVM: A Platform for Multiple LanguagesJVM: A Platform for Multiple Languages
JVM: A Platform for Multiple LanguagesKris Mok
 
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
 
Nashorn on JDK 8 (ADC2013)
Nashorn on JDK 8 (ADC2013)Nashorn on JDK 8 (ADC2013)
Nashorn on JDK 8 (ADC2013)Kris Mok
 
Win32/Flamer: Reverse Engineering and Framework Reconstruction
Win32/Flamer: Reverse Engineering and Framework ReconstructionWin32/Flamer: Reverse Engineering and Framework Reconstruction
Win32/Flamer: Reverse Engineering and Framework ReconstructionAlex Matrosov
 
Akaun Chapter 5
Akaun Chapter 5Akaun Chapter 5
Akaun Chapter 5WanBK Leo
 
What Makes Great Infographics
What Makes Great InfographicsWhat Makes Great Infographics
What Makes Great InfographicsSlideShare
 
Masters of SlideShare
Masters of SlideShareMasters of SlideShare
Masters of SlideShareKapost
 
STOP! VIEW THIS! 10-Step Checklist When Uploading to Slideshare
STOP! VIEW THIS! 10-Step Checklist When Uploading to SlideshareSTOP! VIEW THIS! 10-Step Checklist When Uploading to Slideshare
STOP! VIEW THIS! 10-Step Checklist When Uploading to SlideshareEmpowered Presentations
 
10 Ways to Win at SlideShare SEO & Presentation Optimization
10 Ways to Win at SlideShare SEO & Presentation Optimization10 Ways to Win at SlideShare SEO & Presentation Optimization
10 Ways to Win at SlideShare SEO & Presentation OptimizationOneupweb
 
How To Get More From SlideShare - Super-Simple Tips For Content Marketing
How To Get More From SlideShare - Super-Simple Tips For Content MarketingHow To Get More From SlideShare - Super-Simple Tips For Content Marketing
How To Get More From SlideShare - Super-Simple Tips For Content MarketingContent Marketing Institute
 
A Guide to SlideShare Analytics - Excerpts from Hubspot's Step by Step Guide ...
A Guide to SlideShare Analytics - Excerpts from Hubspot's Step by Step Guide ...A Guide to SlideShare Analytics - Excerpts from Hubspot's Step by Step Guide ...
A Guide to SlideShare Analytics - Excerpts from Hubspot's Step by Step Guide ...SlideShare
 
2015 Upload Campaigns Calendar - SlideShare
2015 Upload Campaigns Calendar - SlideShare2015 Upload Campaigns Calendar - SlideShare
2015 Upload Campaigns Calendar - SlideShareSlideShare
 
What to Upload to SlideShare
What to Upload to SlideShareWhat to Upload to SlideShare
What to Upload to SlideShareSlideShare
 
How to Make Awesome SlideShares: Tips & Tricks
How to Make Awesome SlideShares: Tips & TricksHow to Make Awesome SlideShares: Tips & Tricks
How to Make Awesome SlideShares: Tips & TricksSlideShare
 
Getting Started With SlideShare
Getting Started With SlideShareGetting Started With SlideShare
Getting Started With SlideShareSlideShare
 

En vedette (20)

JavaOne 2012 - JVM JIT for Dummies
JavaOne 2012 - JVM JIT for DummiesJavaOne 2012 - JVM JIT for Dummies
JavaOne 2012 - JVM JIT for Dummies
 
Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...
Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...
Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...
 
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
 
JVM: A Platform for Multiple Languages
JVM: A Platform for Multiple LanguagesJVM: A Platform for Multiple Languages
JVM: A Platform for Multiple Languages
 
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
 
Nashorn on JDK 8 (ADC2013)
Nashorn on JDK 8 (ADC2013)Nashorn on JDK 8 (ADC2013)
Nashorn on JDK 8 (ADC2013)
 
Win32/Flamer: Reverse Engineering and Framework Reconstruction
Win32/Flamer: Reverse Engineering and Framework ReconstructionWin32/Flamer: Reverse Engineering and Framework Reconstruction
Win32/Flamer: Reverse Engineering and Framework Reconstruction
 
Akaun Chapter 5
Akaun Chapter 5Akaun Chapter 5
Akaun Chapter 5
 
Down the Rabbit Hole
Down the Rabbit HoleDown the Rabbit Hole
Down the Rabbit Hole
 
What Makes Great Infographics
What Makes Great InfographicsWhat Makes Great Infographics
What Makes Great Infographics
 
Masters of SlideShare
Masters of SlideShareMasters of SlideShare
Masters of SlideShare
 
STOP! VIEW THIS! 10-Step Checklist When Uploading to Slideshare
STOP! VIEW THIS! 10-Step Checklist When Uploading to SlideshareSTOP! VIEW THIS! 10-Step Checklist When Uploading to Slideshare
STOP! VIEW THIS! 10-Step Checklist When Uploading to Slideshare
 
You Suck At PowerPoint!
You Suck At PowerPoint!You Suck At PowerPoint!
You Suck At PowerPoint!
 
10 Ways to Win at SlideShare SEO & Presentation Optimization
10 Ways to Win at SlideShare SEO & Presentation Optimization10 Ways to Win at SlideShare SEO & Presentation Optimization
10 Ways to Win at SlideShare SEO & Presentation Optimization
 
How To Get More From SlideShare - Super-Simple Tips For Content Marketing
How To Get More From SlideShare - Super-Simple Tips For Content MarketingHow To Get More From SlideShare - Super-Simple Tips For Content Marketing
How To Get More From SlideShare - Super-Simple Tips For Content Marketing
 
A Guide to SlideShare Analytics - Excerpts from Hubspot's Step by Step Guide ...
A Guide to SlideShare Analytics - Excerpts from Hubspot's Step by Step Guide ...A Guide to SlideShare Analytics - Excerpts from Hubspot's Step by Step Guide ...
A Guide to SlideShare Analytics - Excerpts from Hubspot's Step by Step Guide ...
 
2015 Upload Campaigns Calendar - SlideShare
2015 Upload Campaigns Calendar - SlideShare2015 Upload Campaigns Calendar - SlideShare
2015 Upload Campaigns Calendar - SlideShare
 
What to Upload to SlideShare
What to Upload to SlideShareWhat to Upload to SlideShare
What to Upload to SlideShare
 
How to Make Awesome SlideShares: Tips & Tricks
How to Make Awesome SlideShares: Tips & TricksHow to Make Awesome SlideShares: Tips & Tricks
How to Make Awesome SlideShares: Tips & Tricks
 
Getting Started With SlideShare
Getting Started With SlideShareGetting Started With SlideShare
Getting Started With SlideShare
 

Similaire à JavaOne 2011 - JVM Bytecode for Dummies

Mastering Java Bytecode - JAX.de 2012
Mastering Java Bytecode - JAX.de 2012Mastering Java Bytecode - JAX.de 2012
Mastering Java Bytecode - JAX.de 2012Anton Arhipov
 
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
 
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
 
The State of Managed Runtimes 2013, by Attila Szegedi
The State of Managed Runtimes 2013, by Attila SzegediThe State of Managed Runtimes 2013, by Attila Szegedi
The State of Managed Runtimes 2013, by Attila SzegediZeroTurnaround
 
GOTO Night with Charles Nutter Slides
GOTO Night with Charles Nutter SlidesGOTO Night with Charles Nutter Slides
GOTO Night with Charles Nutter SlidesAlexandra Masterson
 
Beyond JVM - YOW! Brisbane 2013
Beyond JVM - YOW! Brisbane 2013Beyond JVM - YOW! Brisbane 2013
Beyond JVM - YOW! Brisbane 2013Charles Nutter
 
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
 
The Enterprise Strikes Back
The Enterprise Strikes BackThe Enterprise Strikes Back
The Enterprise Strikes BackBurke Libbey
 
Java Bytecode For Discriminating Developers - GeeCON 2011
Java Bytecode For Discriminating Developers - GeeCON 2011Java Bytecode For Discriminating Developers - GeeCON 2011
Java Bytecode For Discriminating Developers - GeeCON 2011Anton Arhipov
 
How the HotSpot and Graal JVMs execute Java Code
How the HotSpot and Graal JVMs execute Java CodeHow the HotSpot and Graal JVMs execute Java Code
How the HotSpot and Graal JVMs execute Java CodeJim Gough
 
basic core java up to operator
basic core java up to operatorbasic core java up to operator
basic core java up to operatorkamal kotecha
 
A begineers guide of JAVA - Getting Started
 A begineers guide of JAVA - Getting Started A begineers guide of JAVA - Getting Started
A begineers guide of JAVA - Getting StartedRakesh Madugula
 
Java Programming and J2ME: The Basics
Java Programming and J2ME: The BasicsJava Programming and J2ME: The Basics
Java Programming and J2ME: The Basicstosine
 

Similaire à JavaOne 2011 - JVM Bytecode for Dummies (20)

Mastering Java Bytecode - JAX.de 2012
Mastering Java Bytecode - JAX.de 2012Mastering Java Bytecode - JAX.de 2012
Mastering Java Bytecode - JAX.de 2012
 
Mastering Java ByteCode
Mastering Java ByteCodeMastering Java ByteCode
Mastering Java ByteCode
 
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
 
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
 
The State of Managed Runtimes 2013, by Attila Szegedi
The State of Managed Runtimes 2013, by Attila SzegediThe State of Managed Runtimes 2013, by Attila Szegedi
The State of Managed Runtimes 2013, by Attila Szegedi
 
GOTO Night with Charles Nutter Slides
GOTO Night with Charles Nutter SlidesGOTO Night with Charles Nutter Slides
GOTO Night with Charles Nutter Slides
 
Java goes wild, lesson 1
Java goes wild, lesson 1Java goes wild, lesson 1
Java goes wild, lesson 1
 
Beyond JVM - YOW! Brisbane 2013
Beyond JVM - YOW! Brisbane 2013Beyond JVM - YOW! Brisbane 2013
Beyond JVM - YOW! Brisbane 2013
 
Understanding the Dalvik Virtual Machine
Understanding the Dalvik Virtual MachineUnderstanding the Dalvik Virtual Machine
Understanding the Dalvik Virtual Machine
 
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
 
Nashorn
NashornNashorn
Nashorn
 
The Enterprise Strikes Back
The Enterprise Strikes BackThe Enterprise Strikes Back
The Enterprise Strikes Back
 
Java for the Beginners
Java for the BeginnersJava for the Beginners
Java for the Beginners
 
Java Bytecode For Discriminating Developers - GeeCON 2011
Java Bytecode For Discriminating Developers - GeeCON 2011Java Bytecode For Discriminating Developers - GeeCON 2011
Java Bytecode For Discriminating Developers - GeeCON 2011
 
How the HotSpot and Graal JVMs execute Java Code
How the HotSpot and Graal JVMs execute Java CodeHow the HotSpot and Graal JVMs execute Java Code
How the HotSpot and Graal JVMs execute Java Code
 
Java introduction
Java introductionJava introduction
Java introduction
 
basic core java up to operator
basic core java up to operatorbasic core java up to operator
basic core java up to operator
 
A begineers guide of JAVA - Getting Started
 A begineers guide of JAVA - Getting Started A begineers guide of JAVA - Getting Started
A begineers guide of JAVA - Getting Started
 
Introduction to java programming part 1
Introduction to java programming   part 1Introduction to java programming   part 1
Introduction to java programming part 1
 
Java Programming and J2ME: The Basics
Java Programming and J2ME: The BasicsJava Programming and J2ME: The Basics
Java Programming and J2ME: The Basics
 

Plus de Charles Nutter

The Year of JRuby - RubyC 2018
The Year of JRuby - RubyC 2018The Year of JRuby - RubyC 2018
The Year of JRuby - RubyC 2018Charles Nutter
 
Ruby Performance - The Last Mile - RubyConf India 2016
Ruby Performance - The Last Mile - RubyConf India 2016Ruby Performance - The Last Mile - RubyConf India 2016
Ruby Performance - The Last Mile - RubyConf India 2016Charles Nutter
 
JRuby 9000 - Optimizing Above the JVM
JRuby 9000 - Optimizing Above the JVMJRuby 9000 - Optimizing Above the JVM
JRuby 9000 - Optimizing Above the JVMCharles Nutter
 
JRuby and Invokedynamic - Japan JUG 2015
JRuby and Invokedynamic - Japan JUG 2015JRuby and Invokedynamic - Japan JUG 2015
JRuby and Invokedynamic - Japan JUG 2015Charles Nutter
 
JRuby 9000 - Taipei Ruby User's Group 2015
JRuby 9000 - Taipei Ruby User's Group 2015JRuby 9000 - Taipei Ruby User's Group 2015
JRuby 9000 - Taipei Ruby User's Group 2015Charles Nutter
 
Open Source Software Needs You!
Open Source Software Needs You!Open Source Software Needs You!
Open Source Software Needs You!Charles Nutter
 
InvokeBinder: Fluent Programming for Method Handles
InvokeBinder: Fluent Programming for Method HandlesInvokeBinder: Fluent Programming for Method Handles
InvokeBinder: Fluent Programming for Method HandlesCharles Nutter
 
Over 9000: JRuby in 2015
Over 9000: JRuby in 2015Over 9000: JRuby in 2015
Over 9000: JRuby in 2015Charles Nutter
 
Doing Open Source the Right Way
Doing Open Source the Right WayDoing Open Source the Right Way
Doing Open Source the Right WayCharles Nutter
 
Bringing Concurrency to Ruby - RubyConf India 2014
Bringing Concurrency to Ruby - RubyConf India 2014Bringing Concurrency to Ruby - RubyConf India 2014
Bringing Concurrency to Ruby - RubyConf India 2014Charles Nutter
 
Beyond JVM - YOW! Sydney 2013
Beyond JVM - YOW! Sydney 2013Beyond JVM - YOW! Sydney 2013
Beyond JVM - YOW! Sydney 2013Charles Nutter
 
Beyond JVM - YOW Melbourne 2013
Beyond JVM - YOW Melbourne 2013Beyond JVM - YOW Melbourne 2013
Beyond JVM - YOW Melbourne 2013Charles Nutter
 
The Future of JRuby - Baruco 2013
The Future of JRuby - Baruco 2013The Future of JRuby - Baruco 2013
The Future of JRuby - Baruco 2013Charles Nutter
 
High Performance Ruby - E4E Conference 2013
High Performance Ruby - E4E Conference 2013High Performance Ruby - E4E Conference 2013
High Performance Ruby - E4E Conference 2013Charles Nutter
 
Invokedynamic in 45 Minutes
Invokedynamic in 45 MinutesInvokedynamic in 45 Minutes
Invokedynamic in 45 MinutesCharles Nutter
 
Invokedynamic: Tales from the Trenches
Invokedynamic: Tales from the TrenchesInvokedynamic: Tales from the Trenches
Invokedynamic: Tales from the TrenchesCharles Nutter
 
Why JRuby? - RubyConf 2012
Why JRuby? - RubyConf 2012Why JRuby? - RubyConf 2012
Why JRuby? - RubyConf 2012Charles Nutter
 
Aloha RubyConf 2012 - JRuby
Aloha RubyConf 2012 - JRubyAloha RubyConf 2012 - JRuby
Aloha RubyConf 2012 - JRubyCharles Nutter
 
High Performance Ruby - Golden Gate RubyConf 2012
High Performance Ruby - Golden Gate RubyConf 2012High Performance Ruby - Golden Gate RubyConf 2012
High Performance Ruby - Golden Gate RubyConf 2012Charles Nutter
 

Plus de Charles Nutter (20)

The Year of JRuby - RubyC 2018
The Year of JRuby - RubyC 2018The Year of JRuby - RubyC 2018
The Year of JRuby - RubyC 2018
 
Ruby Performance - The Last Mile - RubyConf India 2016
Ruby Performance - The Last Mile - RubyConf India 2016Ruby Performance - The Last Mile - RubyConf India 2016
Ruby Performance - The Last Mile - RubyConf India 2016
 
JRuby 9000 - Optimizing Above the JVM
JRuby 9000 - Optimizing Above the JVMJRuby 9000 - Optimizing Above the JVM
JRuby 9000 - Optimizing Above the JVM
 
JRuby and Invokedynamic - Japan JUG 2015
JRuby and Invokedynamic - Japan JUG 2015JRuby and Invokedynamic - Japan JUG 2015
JRuby and Invokedynamic - Japan JUG 2015
 
JRuby 9000 - Taipei Ruby User's Group 2015
JRuby 9000 - Taipei Ruby User's Group 2015JRuby 9000 - Taipei Ruby User's Group 2015
JRuby 9000 - Taipei Ruby User's Group 2015
 
Open Source Software Needs You!
Open Source Software Needs You!Open Source Software Needs You!
Open Source Software Needs You!
 
InvokeBinder: Fluent Programming for Method Handles
InvokeBinder: Fluent Programming for Method HandlesInvokeBinder: Fluent Programming for Method Handles
InvokeBinder: Fluent Programming for Method Handles
 
Over 9000: JRuby in 2015
Over 9000: JRuby in 2015Over 9000: JRuby in 2015
Over 9000: JRuby in 2015
 
Doing Open Source the Right Way
Doing Open Source the Right WayDoing Open Source the Right Way
Doing Open Source the Right Way
 
JRuby: The Hard Parts
JRuby: The Hard PartsJRuby: The Hard Parts
JRuby: The Hard Parts
 
Bringing Concurrency to Ruby - RubyConf India 2014
Bringing Concurrency to Ruby - RubyConf India 2014Bringing Concurrency to Ruby - RubyConf India 2014
Bringing Concurrency to Ruby - RubyConf India 2014
 
Beyond JVM - YOW! Sydney 2013
Beyond JVM - YOW! Sydney 2013Beyond JVM - YOW! Sydney 2013
Beyond JVM - YOW! Sydney 2013
 
Beyond JVM - YOW Melbourne 2013
Beyond JVM - YOW Melbourne 2013Beyond JVM - YOW Melbourne 2013
Beyond JVM - YOW Melbourne 2013
 
The Future of JRuby - Baruco 2013
The Future of JRuby - Baruco 2013The Future of JRuby - Baruco 2013
The Future of JRuby - Baruco 2013
 
High Performance Ruby - E4E Conference 2013
High Performance Ruby - E4E Conference 2013High Performance Ruby - E4E Conference 2013
High Performance Ruby - E4E Conference 2013
 
Invokedynamic in 45 Minutes
Invokedynamic in 45 MinutesInvokedynamic in 45 Minutes
Invokedynamic in 45 Minutes
 
Invokedynamic: Tales from the Trenches
Invokedynamic: Tales from the TrenchesInvokedynamic: Tales from the Trenches
Invokedynamic: Tales from the Trenches
 
Why JRuby? - RubyConf 2012
Why JRuby? - RubyConf 2012Why JRuby? - RubyConf 2012
Why JRuby? - RubyConf 2012
 
Aloha RubyConf 2012 - JRuby
Aloha RubyConf 2012 - JRubyAloha RubyConf 2012 - JRuby
Aloha RubyConf 2012 - JRuby
 
High Performance Ruby - Golden Gate RubyConf 2012
High Performance Ruby - Golden Gate RubyConf 2012High Performance Ruby - Golden Gate RubyConf 2012
High Performance Ruby - Golden Gate RubyConf 2012
 

Dernier

So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructureitnewsafrica
 
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...Karmanjay Verma
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...itnewsafrica
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Kaya Weers
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...itnewsafrica
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesBernd Ruecker
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024TopCSSGallery
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 

Dernier (20)

So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
 
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architectures
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 

JavaOne 2011 - JVM Bytecode for Dummies

  • 1. JVM Bytecode for Dummies (and for the rest of you, as well)
  • 2. Intro • Charles Oliver Nutter • “JRuby Guy” • Sun Microsystems 2006-2009 • Engine Yard 2009- • Primarily responsible for compiler, perf • Lots of bytecode generation
  • 3. Two Parts • JVM Bytecode • Inspection • Generation • How it works • JVM JIT • How it works • Monitoring • Assembly (don’t be scared!)
  • 4. Two Parts } • JVM Bytecode • Inspection Today • Generation • How it works } • JVM JIT • How it works Session 25141 Hilton Yosemite ABC • Monitoring Wednesday 10AM • Assembly (don’t be scared!)
  • 5. Bytecode Definition • “... instruction sets designed for efficient execution by a software interpreter ...” • “... suitable for further compilation into machine code.
  • 6. Byte Code • One-byte instructions • 256 possible “opcodes” • 200 in use on current JVMs • Room for more :-) • Little variation since Java 1.0
  • 7. Microsoft’s CLR • Stack-based, but not interpreted • Two-byte “Wordcodes” • Similar operations to JVM
  • 8. Why Learn It • Know your platform • Full understanding from top to bottom • Bytecode generation is fun and easy • Build your own language? • May need to read bytecode someday • Many libraries generate bytecode
  • 9. Hello World public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, world"); } }
  • 10. javap • Java class file disassembler • Basic operation shows class structure • Methods, superclasses, interface, etc • -c flag includes bytecode • -public, -private, -protected • -verbose for stack size, locals, args
  • 11. javap ~/projects/bytecode_for_dummies ➔ javap HelloWorld Compiled from "HelloWorld.java" public class HelloWorld extends java.lang.Object{ public HelloWorld(); public static void main(java.lang.String[]); }
  • 12. javap -c ~/projects/bytecode_for_dummies ➔ javap -c HelloWorld Compiled from "HelloWorld.java" public class HelloWorld extends java.lang.Object{ public HelloWorld(); 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 8:! return }
  • 13. javap -verbose ~/projects/bytecode_for_dummies ➔ javap -c -verbose HelloWorld Compiled from "HelloWorld.java" public class HelloWorld extends java.lang.Object SourceFile: "HelloWorld.java" minor version: 0 major version: 50 Constant pool: const #1 = Method! #6.#15;!// java/lang/Object."<init>":()V const #2 = Field!#16.#17;! / java/lang/System.out:Ljava/io/PrintStream; / const #3 = String! #18;! / Hello, world / const #4 = Method! #19.#20;! / java/io/PrintStream.println:(Ljava/lang/String;)V / const #5 = class!#21;! / HelloWorld / ... {
  • 14. javap -verbose ... public HelloWorld(); 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
  • 15. javap -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 3: 0 line 4: 8 }
  • 16. TraceClassVisitor $ java -cp <ASM stuff> org.objectweb.asm.util.TraceClassVisitor HelloWorld.class // class version 50.0 (50) // access flags 33 public class HelloWorld { // access flags 1 public <init>()V ALOAD 0 INVOKESPECIAL java/lang/Object.<init> ()V RETURN MAXSTACK = 1 MAXLOCALS = 1 // access flags 9 public static main([Ljava/lang/String;)V GETSTATIC java/lang/System.out : Ljava/io/PrintStream; LDC "Hello, world" INVOKEVIRTUAL java/io/PrintStream.println (Ljava/lang/String;)V RETURN MAXSTACK = 2 MAXLOCALS = 1 }
  • 17. ASMifierClassVisitor $ java -cp <ASM stuff> org.objectweb.asm.util.ASMifierClassVisitor HelloWorld.class import java.util.*; import org.objectweb.asm.*; import org.objectweb.asm.attrs.*; public class HelloWorldDump implements Opcodes { public static byte[] dump () throws Exception { ClassWriter cw = new ClassWriter(0); FieldVisitor fv; MethodVisitor mv; AnnotationVisitor av0; cw.visit(V1_6, ACC_PUBLIC + ACC_SUPER, "HelloWorld", null, "java/lang/Object", null); ...
  • 18. ... ASMifierClassVisitor { mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V"); mv.visitInsn(RETURN); mv.visitMaxs(1, 1); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC + ACC_STATIC, "main", "([Ljava/lang/String;)V", null, null); mv.visitCode(); mv.visitFieldInsn(GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;"); mv.visitLdcInsn("Hello, world"); mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/ String;)V"); mv.visitInsn(RETURN); mv.visitMaxs(2, 1); mv.visitEnd(); } cw.visitEnd(); return cw.toByteArray(); } }
  • 20. Thank you! (Just Kidding)
  • 21. Let’s try something a little easier...
  • 22. BiteScript • (J)Ruby DSL for emitting JVM bytecode • Internal DSL • Primitive “macro” support • Reads like javap -c (but nicer) • http://github.com/headius/bitescript
  • 23. Installation • Download JRuby from http://jruby.org • Unpack, optionally add bin/ to PATH • Ahead of PATH if you have Ruby already • [bin/]jruby -S gem install bitescript • `bite myfile.bs` to run myfile.bs file • `bitec myfile.bs` to compile myfile.bs file
  • 24. BiteScript Users • Mirah • Ruby-like language for writing Java code • BiteScript for JVM bytecode backend • BrainF*ck implementation • Other miscellaneous bytecode experiments
  • 25. JiteScript • Java API that mimics BiteScript • Using a few cute tricks ;-) • Pretty close to javap output • Typical Java library installation • http://github.com/qmx/jitescript
  • 26. JiteScript Users • dyn.js • invokedynamic-based JavaScript impl • ???
  • 27. javap -c ~/projects/bytecode_for_dummies ➔ javap -c HelloWorld Compiled from "HelloWorld.java" public class HelloWorld extends java.lang.Object{ public HelloWorld(); 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 8:! return }
  • 28. BiteScript main do getstatic java.lang.System, "out", java.io.PrintStream ldc "Hello, world!" invokevirtual java.io.PrintStream, "println", [java.lang.Void::TYPE, java.lang.Object] returnvoid end
  • 29. BiteScript import java.lang.System JRuby’s “import” import java.io.PrintStream for Java classes main do getstatic System, "out", PrintStream ldc "Hello, world!" invokevirtual PrintStream, "println", [void, object] returnvoid end Shortcuts for void, int, string, object, etc
  • 30. BiteScript main do ldc "Hello, world!" aprintln returnvoid A BiteScript “macro” end
  • 31. BiteScript macro :aprintln do getstatic System, "out", PrintStream swap invokevirtual PrintStream, "println", [void, object] end
  • 32. The Basics • Stack machine • Basic operations • Flow control • Class structures • Exception handling
  • 33. Stack Machine • The “operand stack” holds operands • Operations push and/or pop stack values • Exceptions: nop, wide, goto, jsr/ret • Stack must be consistent • Largest part of bytecode verifier • Stack is explicitly sized per method
  • 34. The JVM Stack Depth Value import java.lang.System import java.io.PrintStream 0 main do 1 getstatic System, "out", PrintStream ldc "Hello, world!" invokevirtual PrintStream, "println", 2 [void, object] returnvoid 3 end 4
  • 35. The JVM Stack Depth Value import java.lang.System import java.io.PrintStream 0 out (a PS) main do 1 getstatic System, "out", PrintStream ldc "Hello, world!" invokevirtual PrintStream, "println", 2 [void, object] returnvoid 3 end 4
  • 36. The JVM Stack Depth Value import java.lang.System import java.io.PrintStream 0 “Hello, world!” main do 1 out (a PS) getstatic System, "out", PrintStream ldc "Hello, world!" invokevirtual PrintStream, "println", 2 [void, object] returnvoid 3 end 4
  • 37. The JVM Stack Depth Value import java.lang.System import java.io.PrintStream 0 main do 1 getstatic System, "out", PrintStream ldc "Hello, world!" invokevirtual PrintStream, "println", 2 [void, object] returnvoid 3 end 4
  • 38. The JVM Stack Depth Value import java.lang.System import java.io.PrintStream 0 main do 1 getstatic System, "out", PrintStream ldc "Hello, world!" invokevirtual PrintStream, "println", 2 [void, object] returnvoid 3 end 4
  • 39. Basic Operations • Stack manipulation • Local variables • Math • Boolean
  • 40. Stack Operations 0x00 nop Do nothing. 0x57 pop Discard top value from stack 0x58 pop2 Discard top two values 0x59 dup Duplicate and push top value again 0x5A dup_x1 Dup and push top value below second value 0x5B dup_x2 Dup and push top value below third value 0x5C dup2 Dup top two values and push 0x5D dup2_x1 ...below second value 0x5E dup2_x2 ...below third value 0x5F swap Swap top two values
  • 41. Stack Juggling Depth Value dup 0 value_0 pop swap 1 value_1 dup_x1 2 dup2_x2 3 4
  • 42. Stack Juggling Depth Value dup 0 value_0 pop swap 1 value_0 dup_x1 2 value_1 dup2_x2 3 4
  • 43. Stack Juggling Depth Value dup 0 value_0 pop swap 1 value_1 dup_x1 2 dup2_x2 3 4
  • 44. Stack Juggling Depth Value dup 0 value_1 pop swap 1 value_0 dup_x1 2 dup2_x2 3 4
  • 45. Stack Juggling Depth Value dup 0 value_1 pop swap 1 value_0 dup_x1 2 value_1 dup2_x2 3 4
  • 46. Stack Juggling Depth Value dup 0 value_1 pop swap 1 value_0 dup_x1 2 value_1 dup2_x2 3 value_1 4 value_0
  • 47. Typed Opcodes <type><operation> b byte Constant values s short Local vars (load, store) c char Array operations (aload, astore) i int Math ops (add, sub, mul, div) l long Boolean and bitwise f float d double Comparisons a reference Conversions
  • 48. Where’s boolean? • Boolean is generally int 0 or 1 • Boolean operations push int 0 or 1 • Boolean branches expect 0 or nonzero • To set a boolean...use int 0 or 1
  • 49. Constant Values 0x01 aconst_null Push null on stack 0x02-0x08 iload_[m1-5] Push integer [-1 to 5] on stack 0x09-0x0A lconst_[0,1] Push long [0 or 1] on stack 0x0B-0x0D fconst_[0,1,2] Push float [0.0, 1.0, 2.0] on stack 0x0E-0x0F dconst_[0,1] Push double [0.0, 1.0] on stack 0x10 bipush Push byte value to stack as integer 0x11 sipush Push short value to stack as integer 0x12 ldc Push 32-bit constant to stack (int, float, string) 0x14 ldc2_w Push 64-bit constant to stack (long, double)
  • 50. Why So Many? • Reducing bytecode size • Special iconst_0 and friends take no args • bipush, sipush: only 8, 16 bits arguments • Pre-optimizing JVM • Specialized instructions can be optimized • Doesn’t matter at all now
  • 51. Constant Values Depth Value ldc "hello" 0 dconst_1 1 aconst_null bipush 4 2 ldc_float 2.0 3 4 5
  • 52. Constant Values Depth Value ldc "hello" 0 “hello” dconst_1 1 aconst_null bipush 4 2 ldc_float 2.0 3 4 5
  • 53. Constant Values Depth Value ldc "hello" 0 dconst_1 1.0d 1 aconst_null bipush 4 2 “hello” ldc_float 2.0 3 4 5
  • 54. Woah, Two Slots? • JVM stack slots (and local vars) are 32-bit • 64-bit values take up two slots • “wide” before or “w” suffix • 64-bit field updates not atomic! • Mind those concurrent longs/doubles!
  • 55. Constant Values Depth Value ldc "hello" 0 null dconst_1 1 aconst_null 1.0d bipush 4 2 ldc_float 2.0 3 “hello” 4 5
  • 56. Constant Values Depth Value ldc "hello" 0 4 dconst_1 1 null aconst_null bipush 4 2 ldc_float 2.0 1.0d 3 4 “hello” 5
  • 57. Constant Values Depth Value ldc "hello" 0 2.0f dconst_1 1 4 aconst_null bipush 4 2 null ldc_float 2.0 3 1.0 4 5 “hello”
  • 58. Local Variable Table • Local variables numbered from 0 • Instance methods have “this” at 0 • Separate table maps numbers to names • Explicitly sized in method definition
  • 59. Local Variables 0x15 iload Load integer from local variable onto stack 0x16 lload ...long... 0x17 fload ...float... 0x18 dload ...double... 0x19 aload ...reference... 0x1A-0x2D Packed loads iload_0, aload_3, etc 0x36 istore Store integer from stack into local variable 0x37 lstore ...long... 0x38 fstore ...float... 0x39 dstore ...double... 0x3A astore ...reference... 0x3B-0x4E Packed stores fstore_2, dstore_0, etc 0x84 iinc Add given amount to int local variable
  • 60. Local Variables Var Value Depth Value ldc "hello" 0 bipush 4 0 istore 3 1 dconst_0 1 dstore 1 2 astore 0 2 aload 0 3 iinc 3, 5 3 4 4
  • 61. Local Variables Var Value Depth Value ldc "hello" 0 bipush 4 0 “hello” istore 3 1 dconst_0 1 dstore 1 2 astore 0 2 aload 0 3 iinc 3, 5 3 4 4
  • 62. Local Variables Var Value Depth Value ldc "hello" 0 bipush 4 0 4 istore 3 1 dconst_0 1 “hello” dstore 1 2 astore 0 2 aload 0 3 iinc 3, 5 3 4 4
  • 63. Local Variables Var Value Depth Value ldc "hello" 0 bipush 4 0 “hello” istore 3 1 dconst_0 1 dstore 1 2 astore 0 2 aload 0 3 4 iinc 3, 5 3 4 4
  • 64. Local Variables Var Value Depth Value ldc "hello" 0 bipush 4 0 istore 3 0.0 1 dconst_0 1 dstore 1 2 astore 0 2 “hello” aload 0 3 4 iinc 3, 5 3 4 4
  • 65. Local Variables Var Value Depth Value ldc "hello" 0 bipush 4 0 “hello” istore 3 1 dconst_0 1 0.0 dstore 1 2 astore 0 2 aload 0 3 4 iinc 3, 5 3 4 4
  • 66. Local Variables Var Value Depth Value ldc "hello" 0 “hello” bipush 4 0 istore 3 1 dconst_0 1 0.0 dstore 1 2 astore 0 2 aload 0 3 4 iinc 3, 5 3 4 4
  • 67. Local Variables Var Value Depth Value ldc "hello" 0 “hello” bipush 4 0 “hello” istore 3 1 dconst_0 1 0.0 dstore 1 2 astore 0 2 aload 0 3 4 iinc 3, 5 3 4 4
  • 68. Local Variables Var Value Depth Value ldc "hello" 0 “hello” bipush 4 0 “hello” istore 3 1 dconst_0 1 0.0 dstore 1 2 astore 0 2 aload 0 3 9 iinc 3, 5 3 4 4
  • 69. Arrays 0x2E-0x35 [i,l,f,d,a,b,c,d]aload Load [int, long, ...] from array (on stack) to stack 0x4F-0x56 [i,l,f,d,a,b,c,d]astore Store [int, long, ...] from stack to array (on stack) 0xBC newarray Construct new primitive array 0xBD anewarray Construct new reference array 0xBE arraylength Get array length 0xC5 multianewarray Create multi-dimensional array
  • 70. Arrays Depth Value iconst_2 newarray int 0 dup iconst_0 1 iconst_m1 2 iastore iconst_0 3 iaload 4 5
  • 71. Arrays Depth Value iconst_2 newarray int 0 2 dup iconst_0 1 iconst_m1 2 iastore iconst_0 3 iaload 4 5
  • 72. Arrays Depth Value iconst_2 newarray int 0 int[2] {0,0} dup iconst_0 1 iconst_m1 2 iastore iconst_0 3 iaload 4 5
  • 73. Arrays Depth Value iconst_2 newarray int 0 int[2] {0,0} dup iconst_0 1 int[2] {0,0} iconst_m1 2 iastore iconst_0 3 iaload 4 5
  • 74. Arrays Depth Value iconst_2 newarray int 0 0 dup iconst_0 1 int[2] {0,0} iconst_m1 2 int[2] {0,0} iastore iconst_0 3 iaload 4 5
  • 75. Arrays Depth Value iconst_2 newarray int 0 -1 dup iconst_0 1 0 iconst_m1 2 int[2] {0,0} iastore iconst_0 3 int[2] {0,0} iaload 4 5
  • 76. Arrays Depth Value iconst_2 newarray int 0 int[2] {-1, 0} dup iconst_0 1 iconst_m1 2 iastore iconst_0 3 iaload 4 5
  • 77. Arrays Depth Value iconst_2 newarray int 0 0 dup iconst_0 1 int[2] {-1, 0} iconst_m1 2 iastore iconst_0 3 iaload 4 5
  • 78. Arrays Depth Value iconst_2 newarray int 0 -1 dup iconst_0 1 iconst_m1 2 iastore iconst_0 3 iaload 4 5
  • 79. Math Operations add subtract multiply divide remainder negate + - * / % -() int iadd isub imul idiv irem ineg long ladd lsub lmul ldiv lrem lneg float fadd fsub fmul fdiv frem fneg double dadd dsub dmul ddiv drem dneg
  • 80. Boolean and Bitwise unsigned shift left shift right and or xor shift right int ishl ishr iushr iand ior ixor
  • 81. Conversions To: int long float double byte char short int - i2l i2f i2d i2b i2c i2s From: long l2i - l2f l2d - - - float f2i f2l - f2d - - - double d2i d2l d2f - - - -
  • 82. Comparisons 0x94 lcmp Compare two longs, push int -1, 0, 1 0x95 fcmpl Compare two floats, push in -1, 0, 1 (-1 for NaN) 0x96 fcmpg Compare two floats, push in -1, 0, 1 (1 for NaN) 0x97 dcmpl Compare two doubles, push in -1, 0, 1 (-1 for NaN) 0x98 dcmpg Compare two doubles, push in -1, 0, 1 (1 for NaN)
  • 83. Flow Control • Inspect stack and branch • Or just branch, via goto • Labels mark branch targets • Wide variety of tests
  • 84. Flow Control 0x99 ifeq If zero on stack, branch 0x9A ifne If nonzero on stack, branch 0x9B iflt If stack value is less than zero, branch 0x9C ifge If stack value is greater than or equal to zero, branch 0x9D ifgt If stack value is greater than zero, branch 0x9E ifle If stack value is less than or equal to zero, branch 0x9F if_icmpeq If two integers on stack are eq, branch 0xA0 if_icmpne If two integers on stack are ne, branch 0xA1 if_icmplt If two integers on stack are lt, branch 0xA2 if_icmpge If two integers on stack are ge, branch 0xA3 if_icmpgt If tw If two integers on stack are gt, branch 0xA4 if_icmple If two integers on stack are le, branch 0xA5 if_acmpeq If two references on stack are the same, branch 0xA6 if_acmpne If two references on stack are different, branch 0xA7 goto GOTO!
  • 85. Other Flow Control 0xA8 jsr Jump to subroutine (deprecated) 0xA9 ret Return from subroutine (deprecated) 0xAA tableswitch Branch using an indexed table of jump offsets 0xAB lookupswitch Branch using a lookup-based table of jump offsets 0xAC-0xB0 [i,l,f,d,a]return Return (int, long, float, double, reference) value 0xB1 return Void return (exit method, return nothing) 0xC6 ifnull If reference on stack is null 0xC7 ifnonnull If reference on stack is not null
  • 86. Flow Control aload 0 ldc 0 aaload Depth Value ldc "branch" String[] invokevirtual string, "equals", 0 {“branch”} [boolean, object] ifne :branch 1 ldc "Not equal!" 2 aprintln goto :end 3 label :branch ldc "Equal!" 4 aprintln label :end 5 returnvoid
  • 87. Flow Control aload 0 ldc 0 aaload Depth Value ldc "branch" invokevirtual string, "equals", 0 0 [boolean, object] ifne :branch 1 String[]{“branch”} ldc "Not equal!" 2 aprintln goto :end 3 label :branch ldc "Equal!" 4 aprintln label :end 5 returnvoid
  • 88. Flow Control aload 0 ldc 0 aaload Depth Value ldc "branch" invokevirtual string, "equals", 0 “branch” [boolean, object] ifne :branch 1 ldc "Not equal!" 2 aprintln goto :end 3 label :branch ldc "Equal!" 4 aprintln label :end 5 returnvoid
  • 89. Flow Control aload 0 ldc 0 aaload Depth Value ldc "branch" invokevirtual string, "equals", 0 “branch” [boolean, object] ifne :branch 1 “branch” ldc "Not equal!" 2 aprintln goto :end 3 label :branch ldc "Equal!" 4 aprintln label :end 5 returnvoid
  • 90. Flow Control aload 0 ldc 0 aaload Depth Value ldc "branch" invokevirtual string, "equals", 0 1 [boolean, object] ifne :branch 1 ldc "Not equal!" 2 aprintln goto :end 3 label :branch ldc "Equal!" 4 aprintln label :end 5 returnvoid
  • 91. Flow Control aload 0 ldc 0 aaload Depth Value ldc "branch" invokevirtual string, "equals", 0 [boolean, object] ifne :branch 1 ldc "Not equal!" 2 aprintln goto :end 3 label :branch ldc "Equal!" 4 aprintln label :end 5 returnvoid
  • 92. Flow Control aload 0 ldc 0 aaload Depth Value ldc "branch" invokevirtual string, "equals", 0 [boolean, object] ifne :branch 1 ldc "Not equal!" 2 aprintln goto :end 3 label :branch ldc "Equal!" 4 aprintln label :end 5 returnvoid
  • 93. Flow Control aload 0 ldc 0 aaload Depth Value ldc "branch" invokevirtual string, "equals", 0 “Equal!” [boolean, object] ifne :branch 1 ldc "Not equal!" 2 aprintln goto :end 3 label :branch ldc "Equal!" 4 aprintln label :end 5 returnvoid
  • 94. Flow Control aload 0 ldc 0 aaload Depth Value ldc "branch" invokevirtual string, "equals", 0 [boolean, object] ifne :branch 1 ldc "Not equal!" 2 aprintln goto :end 3 label :branch ldc "Equal!" 4 aprintln label :end 5 returnvoid
  • 95. Classes and Types • Signatures!!! • Probably the most painful part • ...but not a big deal if you understand
  • 96. Using Classes 0xB2 getstatic Fetch static field from class 0xB3 putstatic Set static field in class 0xB4 getfield Get instance field from object 0xB5 setfield Set instance field in object 0xB6 invokevirtual Invoke instance method on object 0xB7 invokespecial Invoke constructor or “super” on object 0xB8 invokestatic Invoke static method on class 0xB9 invokeinterface Invoke interface method on object 0xBA invokedynamic Invoke method dynamically on object (Java 7) 0xBB new Construct new instance of object 0xC0 checkcast Attempt to cast object to type 0xC1 instanceof Push nonzero if object is instanceof specified type
  • 97. Using Classes new ArrayList dup invokespecial ArrayList, '<init>', Depth Value [void] an ArrayList checkcast Collection 0 (uninitialized) dup ldc "first element" 1 invokeinterface Collection, 'add', [boolean, object] 2 pop checkcast ArrayList 3 ldc 0 invokevirtual ArrayList, 'get', 4 [object, int] aprintln 5 returnvoid
  • 98. Using Classes new ArrayList dup invokespecial ArrayList, '<init>', Depth Value [void] an ArrayList checkcast Collection 0 (uninitialized) dup an ArrayList ldc "first element" 1 (uninitialized) invokeinterface Collection, 'add', [boolean, object] 2 pop checkcast ArrayList 3 ldc 0 invokevirtual ArrayList, 'get', 4 [object, int] aprintln 5 returnvoid
  • 99. Using Classes new ArrayList dup invokespecial ArrayList, '<init>', Depth Value [void] checkcast Collection 0 an ArrayList dup ldc "first element" 1 invokeinterface Collection, 'add', [boolean, object] 2 pop checkcast ArrayList 3 ldc 0 invokevirtual ArrayList, 'get', 4 [object, int] aprintln 5 returnvoid
  • 100. Using Classes new ArrayList dup invokespecial ArrayList, '<init>', Depth Value [void] checkcast Collection 0 a Collection dup ldc "first element" 1 invokeinterface Collection, 'add', [boolean, object] 2 pop checkcast ArrayList 3 ldc 0 invokevirtual ArrayList, 'get', 4 [object, int] aprintln 5 returnvoid
  • 101. Using Classes new ArrayList dup invokespecial ArrayList, '<init>', Depth Value [void] checkcast Collection 0 a Collection dup ldc "first element" 1 a Collection invokeinterface Collection, 'add', [boolean, object] 2 pop checkcast ArrayList 3 ldc 0 invokevirtual ArrayList, 'get', 4 [object, int] aprintln 5 returnvoid
  • 102. Using Classes new ArrayList dup invokespecial ArrayList, '<init>', Depth Value [void] “first checkcast Collection 0 element” dup ldc "first element" 1 a Collection invokeinterface Collection, 'add', [boolean, object] 2 a Collection pop checkcast ArrayList 3 ldc 0 invokevirtual ArrayList, 'get', 4 [object, int] aprintln 5 returnvoid
  • 103. Using Classes new ArrayList dup invokespecial ArrayList, '<init>', Depth Value [void] checkcast Collection 0 1 (true) dup ldc "first element" 1 a Collection invokeinterface Collection, 'add', [boolean, object] 2 pop checkcast ArrayList 3 ldc 0 invokevirtual ArrayList, 'get', 4 [object, int] aprintln 5 returnvoid
  • 104. Using Classes new ArrayList dup invokespecial ArrayList, '<init>', Depth Value [void] checkcast Collection 0 a Collection dup ldc "first element" 1 invokeinterface Collection, 'add', [boolean, object] 2 pop checkcast ArrayList 3 ldc 0 invokevirtual ArrayList, 'get', 4 [object, int] aprintln 5 returnvoid
  • 105. Using Classes new ArrayList dup invokespecial ArrayList, '<init>', Depth Value [void] checkcast Collection 0 an ArrayList dup ldc "first element" 1 invokeinterface Collection, 'add', [boolean, object] 2 pop checkcast ArrayList 3 ldc 0 invokevirtual ArrayList, 'get', 4 [object, int] aprintln 5 returnvoid
  • 106. Using Classes new ArrayList dup invokespecial ArrayList, '<init>', Depth Value [void] checkcast Collection 0 0 dup ldc "first element" 1 an ArrayList invokeinterface Collection, 'add', [boolean, object] 2 pop checkcast ArrayList 3 ldc 0 invokevirtual ArrayList, 'get', 4 [object, int] aprintln 5 returnvoid
  • 107. Using Classes new ArrayList dup invokespecial ArrayList, '<init>', Depth Value [void] “first checkcast Collection 0 element” dup ldc "first element" 1 invokeinterface Collection, 'add', [boolean, object] 2 pop checkcast ArrayList 3 ldc 0 invokevirtual ArrayList, 'get', 4 [object, int] aprintln 5 returnvoid
  • 108. Using Classes new ArrayList dup invokespecial ArrayList, '<init>', Depth Value [void] checkcast Collection 0 dup ldc "first element" 1 invokeinterface Collection, 'add', [boolean, object] 2 pop checkcast ArrayList 3 ldc 0 invokevirtual ArrayList, 'get', 4 [object, int] aprintln 5 returnvoid
  • 109. Invokedynamic • New bytecode in Java 7 • Target method is wired up by user code • Method handles are the wiring
  • 110. Emitting Invokedynamic • Signature is still required • But can be almost anything • Method name is still required • But can be almost anything • MethodHandle for bootstrapping • Bytecode-level function pointer, basically
  • 111. java.lang.invoke • MethodHandles • Function points • Adapters (arg juggling, catch, conditionals) • CallSites • Place to bind your MH chain • SwitchPoint • Zero-cost volatile boolean branch
  • 112. import java.lang.invoke.MethodHandle import java.lang.invoke.MethodType import java.lang.invoke.CallSite import java.lang.invoke.ConstantCallSite import java.lang.invoke.MethodHandles::Lookup JClass = java.lang.Class
  • 113. Target Method # The method we want to invoke, prints given string public_static_method :print, [], void, string do aload 0 aprintln returnvoid end
  • 114. Invokedynamic # Our main method, which does one invokedynamic main do # handle for our bootstrap, which binds invokedynamic to a CallSite bootstrap = mh_invokestatic this, 'bootstrap', CallSite, Lookup, string, MethodType ldc 'Hello, invokedynamic!' invokedynamic 'print', [void, string], bootstrap returnvoid end
  • 115. Invokedynamic # Our main method, which does one invokedynamic main do # handle for our bootstrap, which binds invokedynamic to a CallSite bootstrap = mh_invokestatic this, 'bootstrap', CallSite, Lookup, string, MethodType ldc 'Hello, invokedynamic!' invokedynamic 'print', [void, string], bootstrap returnvoid end
  • 116. Invokedynamic # Our main method, which does one invokedynamic main do # handle for our bootstrap, which binds invokedynamic to a CallSite bootstrap = mh_invokestatic this, 'bootstrap', CallSite, Lookup, string, MethodType ldc 'Hello, invokedynamic!' invokedynamic 'print', [void, string], bootstrap returnvoid end
  • 117. Invokedynamic # Our main method, which does one invokedynamic main do # handle for our bootstrap, which binds invokedynamic to a CallSite bootstrap = mh_invokestatic this, 'bootstrap', CallSite, Lookup, string, MethodType ldc 'Hello, invokedynamic!' invokedynamic 'print', [void, string], bootstrap returnvoid end
  • 118. Bootstrap # The bootstrap method, which binds our dynamic call public_static_method :bootstrap, [], CallSite, Lookup, string, MethodType do # Constant since we bind just once directly new ConstantCallSite dup # Locate the method indicated by name + type on current class aload 0 # Lookup ldc this # this class aload 1 # String aload 2 # MethodType invokevirtual Lookup, 'findStatic', [MethodHandle, JClass, string, MethodType] # finish constructing call site and return invokespecial ConstantCallSite, '<init>', [void, MethodHandle] areturn end
  • 119. Bootstrap # The bootstrap method, which binds our dynamic call public_static_method :bootstrap, [], CallSite, Lookup, string, MethodType do # Constant since we bind just once directly new ConstantCallSite dup # Locate the method indicated by name + type on current class aload 0 # Lookup ldc this # this class aload 1 # String aload 2 # MethodType invokevirtual Lookup, 'findStatic', [MethodHandle, JClass, string, MethodType] # finish constructing call site and return invokespecial ConstantCallSite, '<init>', [void, MethodHandle] areturn end
  • 120. Bootstrap # The bootstrap method, which binds our dynamic call public_static_method :bootstrap, [], CallSite, Lookup, string, MethodType do # Constant since we bind just once directly new ConstantCallSite dup # Locate the method indicated by name + type on current class aload 0 # Lookup ldc this # this class aload 1 # String aload 2 # MethodType invokevirtual Lookup, 'findStatic', [MethodHandle, JClass, string, MethodType] # finish constructing call site and return invokespecial ConstantCallSite, '<init>', [void, MethodHandle] areturn end
  • 121. Bootstrap # The bootstrap method, which binds our dynamic call public_static_method :bootstrap, [], CallSite, Lookup, string, MethodType do # Constant since we bind just once directly new ConstantCallSite dup # Locate the method indicated by name + type on current class aload 0 # Lookup ldc this # this class aload 1 # String aload 2 # MethodType invokevirtual Lookup, 'findStatic', [MethodHandle, JClass, string, MethodType] # finish constructing call site and return invokespecial ConstantCallSite, '<init>', [void, MethodHandle] areturn end
  • 122. Bootstrap # The bootstrap method, which binds our dynamic call public_static_method :bootstrap, [], CallSite, Lookup, string, MethodType do # Constant since we bind just once directly new ConstantCallSite dup # Locate the method indicated by name + type on current class aload 0 # Lookup ldc this # this class aload 1 # String aload 2 # MethodType invokevirtual Lookup, 'findStatic', [MethodHandle, JClass, string, MethodType] # finish constructing call site and return invokespecial ConstantCallSite, '<init>', [void, MethodHandle] areturn end
  • 123. Exceptions and Synchronization Table structure for a method indicating start/end of - trycatch try/catch and logic to run on exception 0xC2 monitorenter Enter synchronized block against object on stack 0xC3 monitorexit Exit synchronized block (against same object)
  • 124. More Examples • A simple loop • Fibonacci
  • 125. A Simple Loop main do aload 0 push_int 0 aaload label :top dup aprintln goto :top returnvoid end
  • 126. Fibonacci public_static_method "fib", [], int, int do iload 0 ldc 2 if_icmpge :recurse iload 0 ireturn label :recurse iload 0 ldc 1 isub invokestatic this, "fib", [int, int] iload 0 ldc 2 isub invokestatic this, "fib", [int, int] iadd ireturn end
  • 127. main do load_times istore 1 Fibonacci ldc "Raw bytecode fib(45) performance:" aprintln label :top iload 1 ifeq :done iinc 1, -1 start_timing 2 ldc 45 invokestatic this, "fib", [int, int] pop end_timing 2 ldc "Time: " aprintln lprintln 2 goto :top label :done returnvoid end
  • 128. main do load_times istore 1 Fibonacci ldc "Raw bytecode fib(45) performance:" aprintln label :top iload 1 ifeq :done iinc 1, -1 start_timing 2 Macros ldc 45 invokestatic this, "fib", [int, int] pop end_timing 2 ldc "Time: " aprintln lprintln 2 goto :top label :done returnvoid end
  • 129. Fibonacci macro :load_times do aload 0 ldc 0 aaload # number of times invokestatic JInteger, 'parseInt', [int, string] end
  • 130. Fibonacci macro :start_timing do |i| load_time lstore i end
  • 131. Fibonacci macro :load_time do invokestatic System, "currentTimeMillis", long end
  • 132. Fibonacci macro :end_timing do |i| load_time lload i lsub lstore i end
  • 133. Fibonacci macro :lprintln do |i| getstatic System, "out", PrintStream lload i invokevirtual PrintStream, "println", [void, long] end
  • 134. Real-world Cases • Reflection-free invocation • JRuby, Groovy, other languages • Bytecoded data objects • Hibernate, other data layers • java.lang.reflect.Proxy and others • Language compilers
  • 135. Tools • BiteScript • So much fun • Ruby, so that’s even better • JiteScript • ASM - defacto standard library
  • 136. Part 2 Topics • Tracking your bytecode • Dumping JVM JIT through the JVM assembly output • How the JVM optimizes • x86 assembler language running code for dummies! • Monitoring JVM JIT compilation • Inspecting JVM inlining
  • 137. Pluggity • Many thanks to Engine Yard • JRuby and Java PaaS • JRuby support and services • sales@engineyard.com
  • 139. Pluggity • Migrating to JRuby on Rails 5:30 Mon, Parc 55 Market Street • JVM JIT for Dummies Part 2 10:00 Wed, Parc 55 Market street • JRuby + Java + Cloud 3:00 Wed, Parc 55 Embarcadero • Real World JRuby 4:30 Wed, Parc 55 Market Street
  • 140. Pluggity • JRuby meetup/party Engine Yard HQ 500 Third Street, Suite 510 Tuesday, 6:30PM • Try JRuby on EY Cloud http://engineyard.com/tryjruby
  • 141. Thank you! • headius@headius.com, @headius • http://blog.headius.com • http://github.com/headius/bitescript • “java virtual machine specification” • “jvm opcodes”

Notes de l'éditeur

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n
  44. \n
  45. \n
  46. \n
  47. \n
  48. \n
  49. \n
  50. \n
  51. \n
  52. \n
  53. \n
  54. \n
  55. \n
  56. \n
  57. \n
  58. \n
  59. \n
  60. \n
  61. \n
  62. \n
  63. \n
  64. \n
  65. \n
  66. \n
  67. \n
  68. \n
  69. \n
  70. \n
  71. \n
  72. \n
  73. \n
  74. \n
  75. \n
  76. \n
  77. \n
  78. \n
  79. \n
  80. \n
  81. \n
  82. \n
  83. \n
  84. \n
  85. \n
  86. \n
  87. \n
  88. \n
  89. \n
  90. \n
  91. \n
  92. \n
  93. \n
  94. \n
  95. \n
  96. \n
  97. \n
  98. \n
  99. \n
  100. \n
  101. \n
  102. \n
  103. \n
  104. \n
  105. \n
  106. \n
  107. \n
  108. \n
  109. \n
  110. \n
  111. \n
  112. \n
  113. \n
  114. \n
  115. \n
  116. \n
  117. \n
  118. \n
  119. \n
  120. \n
  121. \n
  122. \n
  123. \n
  124. \n
  125. \n
  126. \n
  127. \n
  128. \n
  129. \n
  130. \n
  131. \n
  132. \n
  133. \n
  134. \n
  135. \n
  136. \n
  137. \n
  138. \n
  139. \n
  140. \n
  141. \n