SlideShare una empresa de Scribd logo
1 de 70
Descargar para leer sin conexión
Main sponsor




Mastering Java Bytecode
       With ASM
       Anton Arhipov
Me
Anton Arhipov
JRebel @
Product manager by
day, coding monkey by
night
anton@zeroturnaround.com
@antonarhipov
Bytecode
• One-byte instructions
• 256 possible opcodes (200+ in use)
• Stack based (pop, push)
ASM
• Low-level API for bytecode crunching
  • Core API – visitors
  • Tree API – nodes
    • Analysis package
• http://asm.ow2.org
Why?
• Compilers for JVM
• Programming model (AOP, ORM)
• Awesome tools for JVM
Mastering Java Bytecode With ASM - 33rd degree, 2012
public class Items implements Serializable {
  private List<Integer> ids
       = new ArrayList<Integer>();
  {
    ids.add(1);
    ids.add(100);
    ids.add(100000);
  }

    public int getId(int i) {
      return ids.get(i);
    }
}
public class Items implements Serializable {
  private List<Integer> ids
       = new ArrayList<Integer>();
  {
    ids.add(1);
    ids.add(100);
    ids.add(100000);
  }

    public int getId(int i) {
      return ids.get(i);
    }
}
public class Items implements Serializable {
  private List<Integer> ids
       = new ArrayList<Integer>();
  {
    ids.add(1);
    ids.add(100);
    ids.add(100000);
  }

    public int getId(int i) {
      return ids.get(i);
    }
}
public class Items implements Serializable {
  private List<Integer> ids
       = new ArrayList<Integer>();
  {
    ids.add(1);
    ids.add(100);
    ids.add(100000);
  }

    public int getId(int i) {
      return ids.get(i);
    }
}
public class Items implements Serializable {
  private List<Integer> ids
       = new ArrayList<Integer>();
  {
    ids.add(1);
    ids.add(100);
    ids.add(100000);
  }

    public int getId(int i) {
      return ids.get(i);
    }
}
Basic Process
• Construct ClassWriter
• Stack up the visitors for:
  • annotations, methods, fields, etc
• Write out bytes
javap
ClassWriter

ClassWriter cw = new ClassWriter(
     ClassWriter.COMPUTE_MAXS |
     ClassWriter.COMPUTE_FRAMES);
Visit Class
cw.visit(
   Opcodes.V1_6,
   Opcodes.ACC_PUBLIC,
   "zt/asm/Items",
   null,
   "java/lang/Object",
   new String[]
    {"java/io/Serializable"});
Visit Class
cw.visit(
   Opcodes.V1_6,
   Opcodes.ACC_PUBLIC,
   "zt/asm/Items",
   null,
   "java/lang/Object",
   new String[]
    {"java/io/Serializable"});
Visit Class
cw.visit(
   Opcodes.V1_6,
   Opcodes.ACC_PUBLIC,
   "zt/asm/Items",
   null,
   "java/lang/Object",
   new String[]
    {"java/io/Serializable"});
Visit Class
cw.visit(
   Opcodes.V1_6,
   Opcodes.ACC_PUBLIC,
   "zt/asm/Items",
   null,
   "java/lang/Object",
   new String[]
    {"java/io/Serializable"});
Visit Class
cw.visit(
   Opcodes.V1_6,
   Opcodes.ACC_PUBLIC,
   "zt/asm/Items",
   null,
   "java/lang/Object",
   new String[]
    {"java/io/Serializable"});
Field
private List<Integer> ids
       = new ArrayList<Integer>();




private List<Integer> ids;
public Items() {
  ids = new ArrayList<Integer>();
}
Visit Field
FieldVisitor fv = cw.visitField(
Opcodes.ACC_PRIVATE,
"ids",
"Ljava/util/List;",
"Ljava/util/List<Lj/l/Integer;>;",
 null);
Visit Field
FieldVisitor fv = cw.visitField(
Opcodes.ACC_PRIVATE,
"ids",
"Ljava/util/List;",
"Ljava/util/List<Lj/l/Integer;>;",
 null);
Descriptor

• Primitives
  • B, C, S, I, J, F, D, Z, V
• References
  • Ljava/lang/Object;
• Arrays
  • Prefixed with [, i.e. [Ljava/lang/Object;
Descriptor

  Ljava/util/List;

([Ljava/lang/String;)V
org.objectweb.asm.Type


Type.getObjectType("java/lang/String")

         Ljava/lang/String;
Visit Method

MethodVisitor constructor =
   cw.visitMethod(
      Opcodes.ACC_PUBLIC,
      "<init>",
      "()V",
      null,
      null);
Visit Method

MethodVisitor get =
   cw.visitMethod(
      Opcodes.ACC_PUBLIC,
      "get",
      "(I)I",
      null,
      null);
public class Items implements Serializable {
  private List<Integer> ids
       = new ArrayList<Integer>();
  {
    ids.add(1);
    ids.add(100);
    ids.add(100000);
  }

    public int getId(int i) {
      return ids.get(i);
    }
}
public class Items implements Serializable {
  private List<Integer> ids
       = new ArrayList<Integer>();
  {
    ids.add(1);
    ids.add(100);
    ids.add(100000);
  }

    public int getId(int i) {
      return ids.get(i);
    }
}
public Items() {
    super();

    ids = new ArrayList<Integer>();

    ids.add(1);
    ids.add(100);
    ids.add(100000);
}
public Items() {
    super();

    ids = new ArrayList<Integer>();

    ids.add(1);
    ids.add(100);
    ids.add(100000);
}
super()
   0: aload_0
   1: invokespecial #1 // Object.<init>


MethodVisitor mv = …
mv.visitVarInsn(ALOAD, 0);
mv.visitMethodInsn(INVOKESPECIAL,
 "java/lang/Object", "<init>", "()V");
public Items() {
    super();

    ids = new ArrayList<Integer>();

    ids.add(1);
    ids.add(100);
    ids.add(100000);
}
public Items() {
    super();

    ids = new ArrayList<Integer>();

    ids.add(1);
    ids.add(100);
    ids.add(100000);
}
Assignment
 4:   aload_0
 5:   new           #2 // ArrayList
 8:   dup
 9:   invokespecial #3 // <init>
12:   putfield      #4 // ids
Assignment
                       Create instance
 4:   aload_0
 5:   new           #2 // ArrayList
 8:   dup
 9:   invokespecial #3 // <init>
12:   putfield      #4 // ids
Assignment
 4:   aload_0
 5:   new           #2 // ArrayList
 8:   dup
 9:   invokespecial #3 // <init>
12:   putfield      #4 // ids

              Assign to a field
Assignment

 5:   new           #2 // ArrayList
 8:   dup
 9:   invokespecial #3 // <init>
12:   astore_1      #4 // ids

              Assign to local variable
Assignment
mv.visitVarInsn(ALOAD, 0);
mv.visitTypeInsn(NEW, "java/util/ArrayList");
mv.visitInsn(DUP);
mv.visitMethodInsn(INVOKESPECIAL,
"java/util/ArrayList", "<init>", "()V");
mv.visitFieldInsn(PUTFIELD,
"zt/asm/Items", "ids", "Ljava/util/List;");
Assignment
mv.visitVarInsn(ALOAD, 0);
mv.visitTypeInsn(NEW, "java/util/ArrayList");
mv.visitInsn(DUP);
mv.visitMethodInsn(INVOKESPECIAL,
"java/util/ArrayList", "<init>", "()V");
mv.visitFieldInsn(PUTFIELD,
"zt/asm/Items", "ids", "Ljava/util/List;");
public Items() {
    super();

    ids = new ArrayList<Integer>();

    ids.add(1);
    ids.add(100);
    ids.add(100000);
}
public Items() {
    super();

    ids = new ArrayList<Integer>();

    ids.add(1);
    ids.add(100);
    ids.add(100000);
}
ids.add(1)

15:   aload_0
16:   getfield   #4 // ids
19:   iconst_1
20:   invokestatic #5 // Integer.valueOf
23:   invokeinterface #6, 2 // List.add
28:   pop
ids.add(1)

15:   aload_0
16:   getfield   #4 // ids
19:   iconst_1
20:   invokestatic #5 // Integer.valueOf
23:   invokeinterface #6, 2 // List.add
28:   pop
ids.add(1)

15:   aload_0
16:   getfield   #4 // ids
19:   iconst_1
20:   invokestatic #5 // Integer.valueOf
23:   invokeinterface #6, 2 // List.add
28:   pop
ids.add(1)

15:   aload_0
16:   getfield   #4 // ids
19:   iconst_1
20:   invokestatic #5 // Integer.valueOf
23:   invokeinterface #6, 2 // List.add
28:   pop
ids.add(1)

15:   aload_0
16:   getfield   #4 // ids
19:   iconst_1
20:   invokestatic #5 // Integer.valueOf
23:   invokeinterface #6, 2 // List.add
28:   pop
ids.add(1)

15:   aload_0
16:   getfield   #4 // ids
19:   iconst_1
20:   invokestatic #5 // Integer.valueOf
23:   invokeinterface #6, 2 // List.add
28:   pop
ids.add(100)

15:   aload_0
16:   getfield   #4 // ids
19:   bipush 100
20:   invokestatic #5 // Integer.valueOf
23:   invokeinterface #6, 2 // List.add
28:   pop
ids.add(100_000)

15:   aload_0
16:   getfield   #4 // ids
19:   ldc #7 // int 100000
20:   invokestatic #5 // Integer.valueOf
23:   invokeinterface #6, 2 // List.add
28:   pop
mv.visitVarInsn(ALOAD, 0);
mv.visitFieldInsn(GETFIELD,
"zt/asm/Items", "ids",
"Ljava/util/List;");
mv.visitInsn(ICONST_1);
mv.visitMethodInsn(INVOKESTATIC, "java/lang
/Integer", "valueOf", "(I)Ljava/lang/Intege
r;");
mv.visitMethodInsn(INVOKEINTERFACE, "java/u
til/List", "add", "(Ljava/lang/Object;)Z");
mv.visitInsn(POP);
public class Items implements Serializable {
  private List<Integer> ids
       = new ArrayList<Integer>();
  {
    ids.add(1);
    ids.add(100);
    ids.add(100000);
  }

    public int getId(int i) {
      return ids.get(i);
    }
}
ASMified
mv = cw.visitMethod(ACC_PUBLIC, "getId", "(I)I", null, null);
mv.visitCode();
Label l0 = new Label();
mv.visitLabel(l0);
mv.visitLineNumber(16, l0);
mv.visitVarInsn(ALOAD, 0);
mv.visitFieldInsn(GETFIELD, "zt/asm/Items", "ids", "Ljava/util/List;");
mv.visitVarInsn(ILOAD, 1);
mv.visitMethodInsn(INVOKEINTERFACE, "java/util/List",
                                    "get", "(I)Ljava/lang/Object;");
mv.visitTypeInsn(CHECKCAST, "java/lang/Integer");
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Integer",
                                  "intValue", "()I");
mv.visitInsn(IRETURN);
Label l1 = new Label();
mv.visitLabel(l1);
mv.visitLocalVariable("this", "Lzt/asm/Items;", null, l0, l1, 0);
mv.visitLocalVariable("i", "I", null, l0, l1, 1);
mv.visitMaxs(2, 2);
mv.visitEnd();
ASMified
mv = cw.visitMethod(ACC_PUBLIC, "getId", "(I)I", null, null);
mv.visitCode();
Label l0 = new Label();
  java -cp asm-all-3.3.1.jar:asm-util-3.3.1.jar 
mv.visitLabel(l0);
mv.visitLineNumber(16, l0);
  org.objectweb.asm.util.ASMifierClassVisitor 
mv.visitVarInsn(ALOAD, 0);
  Items.class
mv.visitFieldInsn(GETFIELD, "zt/asm/Items", "ids", "Ljava/util/List;");
mv.visitVarInsn(ILOAD, 1);
mv.visitMethodInsn(INVOKEINTERFACE, "java/util/List",
                                    "get", "(I)Ljava/lang/Object;");
mv.visitTypeInsn(CHECKCAST, "java/lang/Integer");
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Integer",
                                  "intValue", "()I");
mv.visitInsn(IRETURN);
Label l1 = new Label();
mv.visitLabel(l1);
mv.visitLocalVariable("this", "Lzt/asm/Items;", null, l0, l1, 0);
mv.visitLocalVariable("i", "I", null, l0, l1, 1);
mv.visitMaxs(2, 2);
mv.visitEnd();
javap
public class zt.asm.deg.Items {
  public java.util.List<java.lang.Integer> ids;

    public int getId(int);
       Code:
         0: aload_0
         1: getfield          #4
         4: iload_1
         5: invokeinterface   #8,   2
        10: checkcast         #9
        13: invokevirtual     #10
        16: ireturn
}
Groovyfied
public class zt/asm/Items {
   public Ljava/util/List; ids

    @groovyx.ast.bytecode.Bytecode
    public int getId(int a) {
       aload 0
       getfield zt.asm.Items.ids >> List
       iload 1
       invokeinterface List.get(int) >> Object
       checkcast Integer
       invokevirtual Integer.intValue() >> int
       ireturn
    }
}
                 https://github.com/melix/groovy-bytecode-ast
Generating bytecode
            from scratch
                     is too simple …

Transforming the bytecode is
               much more fun! 
Instrument
  some bytecode
Ninja.class   Ninja.class’
10101010101   10101010101
11000101010   11100001010
10101010001   10101010001
00010001110   00010001110
11011101011   11011101110
How?
• Add –javaagent to hook into class loading
  process
• Implement ClassFileTransformer
• Use bytecode manipulation libraries
  (Javassist, cglib, asm) to add any custom logic

            java.lang.instrument
How ? (2)
• Use custom ClassLoader
  – Override ClassLoader#findClass
  – Use ClassReader(String) to read the class
    in and transform it via visitor chain
  – Call ClassLoader#defineClass explicitly
    with the result from the transformation
    step
java.lang.instrument

import java.lang.instrument.ClassFileTransformer;
import java.lang.instrument.Instrumentation;

public class Agent {
public static void premain(String args, Instrumentation inst)
  { inst.addTransformer(new ClassFileTransformer(), true); }

public static void agentmain(String args, Instrumentation inst)
  { premain(args,inst); }
}
java.lang.instrument

import java.lang.instrument.ClassFileTransformer;
import java.lang.instrument.Instrumentation;

public class Agent {
public static void premain(String args, Instrumentation inst)
  { inst.addTransformer(new ClassFileTransformer(), true); }

public static void agentmain(String args, Instrumentation inst)
  { premain(args,inst); }
}
java.lang.instrument

import java.lang.instrument.ClassFileTransformer;
import java.lang.instrument.Instrumentation;

public class Agent {
public static void premain(String args, Instrumentation inst)
  { inst.addTransformer(new ClassFileTransformer(), true); }

public static void agentmain(String args, Instrumentation inst)
  { premain(args,inst); }
}
   META-INF/MANIFEST.MF
   Premain-Class: Agent
                               java –javaagent:agent.jar …
   Agent-Class: Agent
j.l.instrument.ClassFileTransformer
new ClassFileTransformer() {
  public byte[] transform(ClassLoader loader, String className,
                          Class<?>classBeingRedefined,
                          ProtectionDomain protectionDomain,
                          byte[] classfileBuffer){

    ClassReader cr = new ClassReader(classfileBuffer);
    ClassWriter cw = new ClassWriter(cr,
                     ClassWriter.COMPUTE_MAXS |
                     ClassWriter.COMPUTE_FRAMES);
    MyAdapter ca = new MyAdapter(cw);
    cr.accept(ca, ClassReader.EXPAND_FRAMES);
    return cw.toByteArray();
}
j.l.instrument.ClassFileTransformer
new ClassFileTransformer() {
  public byte[] transform(ClassLoader loader, String className,
                          Class<?>classBeingRedefined,
                          ProtectionDomain protectionDomain,
                          byte[] classfileBuffer){

    ClassReader cr = new ClassReader(classfileBuffer);
    ClassWriter cw = new ClassWriter(cr,
                     ClassWriter.COMPUTE_MAXS |
                     ClassWriter.COMPUTE_FRAMES);
    MyAdapter ca = new MyAdapter(cw);
    cr.accept(ca, ClassReader.EXPAND_FRAMES);
    return cw.toByteArray();
}
j.l.instrument.ClassFileTransformer
new ClassFileTransformer() {
  public byte[] transform(ClassLoader loader, String className,
                          Class<?>classBeingRedefined,
                          ProtectionDomain protectionDomain,
                          byte[] classfileBuffer){

    ClassReader cr = new ClassReader(classfileBuffer);
    ClassWriter cw = new ClassWriter(cr,
                     ClassWriter.COMPUTE_MAXS |
                     ClassWriter.COMPUTE_FRAMES);

    MyAdapter ca = new MyAdapter(cw);
    cr.accept(ca, ClassReader.EXPAND_FRAMES);
    return cw.toByteArray();
}
public class MyClassLoader extends ClassLoader {

 protected Class findClass(String name)
                          throws ClassNotFoundException {

     ClassReader cr = new ClassReader(name);
     ClassWriter cw = new ClassWriter(cr,
                          ClassWriter.COMPUTE_MAXS |
                          ClassWriter.COMPUTE_FRAMES);

     MyClassAdapter ca =
             new MyClassAdapter(cw);
     cr.accept(ca, ClassReader.EXPAND_FRAMES);

     byte b[] = cw.toByteArray();
     return defineClass(name, b, 0, b.length);
 }
SLIDES
GOTO IDE
SLIDES
IDE: DEMO
@antonarhipov

anton@zeroturnaround.com

Más contenido relacionado

La actualidad más candente

Jbatch実践入門 #jdt2015
Jbatch実践入門 #jdt2015Jbatch実践入門 #jdt2015
Jbatch実践入門 #jdt2015Norito Agetsuma
 
Etsy Activity Feeds Architecture
Etsy Activity Feeds ArchitectureEtsy Activity Feeds Architecture
Etsy Activity Feeds ArchitectureDan McKinley
 
Managing Egress with Istio
Managing Egress with IstioManaging Egress with Istio
Managing Egress with IstioSolo.io
 
JavaOne 2012 - JVM JIT for Dummies
JavaOne 2012 - JVM JIT for DummiesJavaOne 2012 - JVM JIT for Dummies
JavaOne 2012 - JVM JIT for DummiesCharles Nutter
 
Java Performance Analysis on Linux with Flame Graphs
Java Performance Analysis on Linux with Flame GraphsJava Performance Analysis on Linux with Flame Graphs
Java Performance Analysis on Linux with Flame GraphsBrendan Gregg
 
State: You're Doing It Wrong - Alternative Concurrency Paradigms For The JVM
State: You're Doing It Wrong - Alternative Concurrency Paradigms For The JVMState: You're Doing It Wrong - Alternative Concurrency Paradigms For The JVM
State: You're Doing It Wrong - Alternative Concurrency Paradigms For The JVMJonas Bonér
 
Secrets of Performance Tuning Java on Kubernetes
Secrets of Performance Tuning Java on KubernetesSecrets of Performance Tuning Java on Kubernetes
Secrets of Performance Tuning Java on KubernetesBruno Borges
 
UM2019 Extended BPF: A New Type of Software
UM2019 Extended BPF: A New Type of SoftwareUM2019 Extended BPF: A New Type of Software
UM2019 Extended BPF: A New Type of SoftwareBrendan Gregg
 
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to RedisDvir Volk
 
Tomcatの実装から学ぶクラスローダリーク #渋谷Java
Tomcatの実装から学ぶクラスローダリーク #渋谷JavaTomcatの実装から学ぶクラスローダリーク #渋谷Java
Tomcatの実装から学ぶクラスローダリーク #渋谷JavaNorito Agetsuma
 
Spring Boot Actuator 2.0 & Micrometer #jjug_ccc #ccc_a1
Spring Boot Actuator 2.0 & Micrometer #jjug_ccc #ccc_a1Spring Boot Actuator 2.0 & Micrometer #jjug_ccc #ccc_a1
Spring Boot Actuator 2.0 & Micrometer #jjug_ccc #ccc_a1Toshiaki Maki
 
Big Data in Real-Time at Twitter
Big Data in Real-Time at TwitterBig Data in Real-Time at Twitter
Big Data in Real-Time at Twitternkallen
 
From cache to in-memory data grid. Introduction to Hazelcast.
From cache to in-memory data grid. Introduction to Hazelcast.From cache to in-memory data grid. Introduction to Hazelcast.
From cache to in-memory data grid. Introduction to Hazelcast.Taras Matyashovsky
 
Spring boot Introduction
Spring boot IntroductionSpring boot Introduction
Spring boot IntroductionJeevesh Pandey
 
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
 
Java EE 7 Batch processing in the Real World
Java EE 7 Batch processing in the Real WorldJava EE 7 Batch processing in the Real World
Java EE 7 Batch processing in the Real WorldRoberto Cortez
 
IBM JVM 소개 - Oracle JVM 과 비교
IBM JVM 소개 - Oracle JVM 과 비교IBM JVM 소개 - Oracle JVM 과 비교
IBM JVM 소개 - Oracle JVM 과 비교JungWoon Lee
 
为啥别读HotSpot VM的源码(2012-03-03)
为啥别读HotSpot VM的源码(2012-03-03)为啥别读HotSpot VM的源码(2012-03-03)
为啥别读HotSpot VM的源码(2012-03-03)Kris Mok
 

La actualidad más candente (20)

Jbatch実践入門 #jdt2015
Jbatch実践入門 #jdt2015Jbatch実践入門 #jdt2015
Jbatch実践入門 #jdt2015
 
Sql Antipatterns Strike Back
Sql Antipatterns Strike BackSql Antipatterns Strike Back
Sql Antipatterns Strike Back
 
Etsy Activity Feeds Architecture
Etsy Activity Feeds ArchitectureEtsy Activity Feeds Architecture
Etsy Activity Feeds Architecture
 
Managing Egress with Istio
Managing Egress with IstioManaging Egress with Istio
Managing Egress with Istio
 
JavaOne 2012 - JVM JIT for Dummies
JavaOne 2012 - JVM JIT for DummiesJavaOne 2012 - JVM JIT for Dummies
JavaOne 2012 - JVM JIT for Dummies
 
Java Performance Analysis on Linux with Flame Graphs
Java Performance Analysis on Linux with Flame GraphsJava Performance Analysis on Linux with Flame Graphs
Java Performance Analysis on Linux with Flame Graphs
 
State: You're Doing It Wrong - Alternative Concurrency Paradigms For The JVM
State: You're Doing It Wrong - Alternative Concurrency Paradigms For The JVMState: You're Doing It Wrong - Alternative Concurrency Paradigms For The JVM
State: You're Doing It Wrong - Alternative Concurrency Paradigms For The JVM
 
Secrets of Performance Tuning Java on Kubernetes
Secrets of Performance Tuning Java on KubernetesSecrets of Performance Tuning Java on Kubernetes
Secrets of Performance Tuning Java on Kubernetes
 
UM2019 Extended BPF: A New Type of Software
UM2019 Extended BPF: A New Type of SoftwareUM2019 Extended BPF: A New Type of Software
UM2019 Extended BPF: A New Type of Software
 
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to Redis
 
Tomcatの実装から学ぶクラスローダリーク #渋谷Java
Tomcatの実装から学ぶクラスローダリーク #渋谷JavaTomcatの実装から学ぶクラスローダリーク #渋谷Java
Tomcatの実装から学ぶクラスローダリーク #渋谷Java
 
Spring Boot Actuator 2.0 & Micrometer #jjug_ccc #ccc_a1
Spring Boot Actuator 2.0 & Micrometer #jjug_ccc #ccc_a1Spring Boot Actuator 2.0 & Micrometer #jjug_ccc #ccc_a1
Spring Boot Actuator 2.0 & Micrometer #jjug_ccc #ccc_a1
 
Big Data in Real-Time at Twitter
Big Data in Real-Time at TwitterBig Data in Real-Time at Twitter
Big Data in Real-Time at Twitter
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
From cache to in-memory data grid. Introduction to Hazelcast.
From cache to in-memory data grid. Introduction to Hazelcast.From cache to in-memory data grid. Introduction to Hazelcast.
From cache to in-memory data grid. Introduction to Hazelcast.
 
Spring boot Introduction
Spring boot IntroductionSpring boot Introduction
Spring boot Introduction
 
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
 
Java EE 7 Batch processing in the Real World
Java EE 7 Batch processing in the Real WorldJava EE 7 Batch processing in the Real World
Java EE 7 Batch processing in the Real World
 
IBM JVM 소개 - Oracle JVM 과 비교
IBM JVM 소개 - Oracle JVM 과 비교IBM JVM 소개 - Oracle JVM 과 비교
IBM JVM 소개 - Oracle JVM 과 비교
 
为啥别读HotSpot VM的源码(2012-03-03)
为啥别读HotSpot VM的源码(2012-03-03)为啥别读HotSpot VM的源码(2012-03-03)
为啥别读HotSpot VM的源码(2012-03-03)
 

Destacado

Mastering Java Bytecode - JAX.de 2012
Mastering Java Bytecode - JAX.de 2012Mastering Java Bytecode - JAX.de 2012
Mastering Java Bytecode - JAX.de 2012Anton Arhipov
 
JavaOne 2010: Top 10 Causes for Java Issues in Production and What to Do When...
JavaOne 2010: Top 10 Causes for Java Issues in Production and What to Do When...JavaOne 2010: Top 10 Causes for Java Issues in Production and What to Do When...
JavaOne 2010: Top 10 Causes for Java Issues in Production and What to Do When...srisatish ambati
 
JVM, byte codes & jvm languages
JVM, byte codes & jvm languagesJVM, byte codes & jvm languages
JVM, byte codes & jvm languagesEdgar Espina
 
JavaOne 2012 CON 3961 Innovative Testing Techniques Using Bytecode Instrument...
JavaOne 2012 CON 3961 Innovative Testing Techniques Using Bytecode Instrument...JavaOne 2012 CON 3961 Innovative Testing Techniques Using Bytecode Instrument...
JavaOne 2012 CON 3961 Innovative Testing Techniques Using Bytecode Instrument...PaulThwaite
 
Java 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
 
Java bytecode and classes
Java bytecode and classesJava bytecode and classes
Java bytecode and classesyoavwix
 
Make Java Profilers Lie Less
Make Java Profilers Lie LessMake Java Profilers Lie Less
Make Java Profilers Lie LessJaroslav Bachorik
 
GeeCon2016- High Performance Instrumentation (handout)
GeeCon2016- High Performance Instrumentation (handout)GeeCon2016- High Performance Instrumentation (handout)
GeeCon2016- High Performance Instrumentation (handout)Jaroslav Bachorik
 

Destacado (8)

Mastering Java Bytecode - JAX.de 2012
Mastering Java Bytecode - JAX.de 2012Mastering Java Bytecode - JAX.de 2012
Mastering Java Bytecode - JAX.de 2012
 
JavaOne 2010: Top 10 Causes for Java Issues in Production and What to Do When...
JavaOne 2010: Top 10 Causes for Java Issues in Production and What to Do When...JavaOne 2010: Top 10 Causes for Java Issues in Production and What to Do When...
JavaOne 2010: Top 10 Causes for Java Issues in Production and What to Do When...
 
JVM, byte codes & jvm languages
JVM, byte codes & jvm languagesJVM, byte codes & jvm languages
JVM, byte codes & jvm languages
 
JavaOne 2012 CON 3961 Innovative Testing Techniques Using Bytecode Instrument...
JavaOne 2012 CON 3961 Innovative Testing Techniques Using Bytecode Instrument...JavaOne 2012 CON 3961 Innovative Testing Techniques Using Bytecode Instrument...
JavaOne 2012 CON 3961 Innovative Testing Techniques Using Bytecode Instrument...
 
Java 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
 
Java bytecode and classes
Java bytecode and classesJava bytecode and classes
Java bytecode and classes
 
Make Java Profilers Lie Less
Make Java Profilers Lie LessMake Java Profilers Lie Less
Make Java Profilers Lie Less
 
GeeCon2016- High Performance Instrumentation (handout)
GeeCon2016- High Performance Instrumentation (handout)GeeCon2016- High Performance Instrumentation (handout)
GeeCon2016- High Performance Instrumentation (handout)
 

Similar a Mastering Java Bytecode With ASM - 33rd degree, 2012

Open Source Search: An Analysis
Open Source Search: An AnalysisOpen Source Search: An Analysis
Open Source Search: An AnalysisJustin Finkelstein
 
Real World Generics In Swift
Real World Generics In SwiftReal World Generics In Swift
Real World Generics In SwiftVadym Markov
 
jQuery - Introdução
jQuery - IntroduçãojQuery - Introdução
jQuery - IntroduçãoGustavo Dutra
 
JQuery do dia-a-dia Gustavo Dutra
JQuery do dia-a-dia Gustavo DutraJQuery do dia-a-dia Gustavo Dutra
JQuery do dia-a-dia Gustavo DutraTchelinux
 
Persisting Data on SQLite using Room
Persisting Data on SQLite using RoomPersisting Data on SQLite using Room
Persisting Data on SQLite using RoomNelson Glauber Leal
 
CouchDB on Android
CouchDB on AndroidCouchDB on Android
CouchDB on AndroidSven Haiges
 
Scala uma poderosa linguagem para a jvm
Scala   uma poderosa linguagem para a jvmScala   uma poderosa linguagem para a jvm
Scala uma poderosa linguagem para a jvmIsaias Barroso
 
Tips and Tricks of Developing .NET Application
Tips and Tricks of Developing .NET ApplicationTips and Tricks of Developing .NET Application
Tips and Tricks of Developing .NET ApplicationJoni
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript IntroductionDmitry Sheiko
 
Devoxx 2012 hibernate envers
Devoxx 2012   hibernate enversDevoxx 2012   hibernate envers
Devoxx 2012 hibernate enversRomain Linsolas
 
Softshake 2013: 10 reasons why java developers are jealous of Scala developers
Softshake 2013: 10 reasons why java developers are jealous of Scala developersSoftshake 2013: 10 reasons why java developers are jealous of Scala developers
Softshake 2013: 10 reasons why java developers are jealous of Scala developersMatthew Farwell
 
JavaScript and the AST
JavaScript and the ASTJavaScript and the AST
JavaScript and the ASTJarrod Overson
 
Taming that client side mess with Backbone.js
Taming that client side mess with Backbone.jsTaming that client side mess with Backbone.js
Taming that client side mess with Backbone.jsJarod Ferguson
 
Swift, functional programming, and the future of Objective-C
Swift, functional programming, and the future of Objective-CSwift, functional programming, and the future of Objective-C
Swift, functional programming, and the future of Objective-CAlexis Gallagher
 

Similar a Mastering Java Bytecode With ASM - 33rd degree, 2012 (20)

Open Source Search: An Analysis
Open Source Search: An AnalysisOpen Source Search: An Analysis
Open Source Search: An Analysis
 
Java Generics
Java GenericsJava Generics
Java Generics
 
Real World Generics In Swift
Real World Generics In SwiftReal World Generics In Swift
Real World Generics In Swift
 
jQuery - Introdução
jQuery - IntroduçãojQuery - Introdução
jQuery - Introdução
 
JQuery do dia-a-dia Gustavo Dutra
JQuery do dia-a-dia Gustavo DutraJQuery do dia-a-dia Gustavo Dutra
JQuery do dia-a-dia Gustavo Dutra
 
Persisting Data on SQLite using Room
Persisting Data on SQLite using RoomPersisting Data on SQLite using Room
Persisting Data on SQLite using Room
 
Spine JS
Spine JSSpine JS
Spine JS
 
CouchDB on Android
CouchDB on AndroidCouchDB on Android
CouchDB on Android
 
Scala uma poderosa linguagem para a jvm
Scala   uma poderosa linguagem para a jvmScala   uma poderosa linguagem para a jvm
Scala uma poderosa linguagem para a jvm
 
Miracle of std lib
Miracle of std libMiracle of std lib
Miracle of std lib
 
jQuery introduction
jQuery introductionjQuery introduction
jQuery introduction
 
Tips and Tricks of Developing .NET Application
Tips and Tricks of Developing .NET ApplicationTips and Tricks of Developing .NET Application
Tips and Tricks of Developing .NET Application
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript Introduction
 
Devoxx 2012 hibernate envers
Devoxx 2012   hibernate enversDevoxx 2012   hibernate envers
Devoxx 2012 hibernate envers
 
Softshake 2013: 10 reasons why java developers are jealous of Scala developers
Softshake 2013: 10 reasons why java developers are jealous of Scala developersSoftshake 2013: 10 reasons why java developers are jealous of Scala developers
Softshake 2013: 10 reasons why java developers are jealous of Scala developers
 
JavaScript and the AST
JavaScript and the ASTJavaScript and the AST
JavaScript and the AST
 
Taming that client side mess with Backbone.js
Taming that client side mess with Backbone.jsTaming that client side mess with Backbone.js
Taming that client side mess with Backbone.js
 
Jason parsing
Jason parsingJason parsing
Jason parsing
 
Swift, functional programming, and the future of Objective-C
Swift, functional programming, and the future of Objective-CSwift, functional programming, and the future of Objective-C
Swift, functional programming, and the future of Objective-C
 
Test
TestTest
Test
 

Más de Anton Arhipov

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

Más de Anton Arhipov (20)

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

Último

9 Steps For Building Winning Founding Team
9 Steps For Building Winning Founding Team9 Steps For Building Winning Founding Team
9 Steps For Building Winning Founding TeamAdam Moalla
 
NIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 WorkshopNIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 WorkshopBachir Benyammi
 
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfJamie (Taka) Wang
 
Videogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfVideogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfinfogdgmi
 
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IES VE
 
Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.YounusS2
 
Cybersecurity Workshop #1.pptx
Cybersecurity Workshop #1.pptxCybersecurity Workshop #1.pptx
Cybersecurity Workshop #1.pptxGDSC PJATK
 
Building AI-Driven Apps Using Semantic Kernel.pptx
Building AI-Driven Apps Using Semantic Kernel.pptxBuilding AI-Driven Apps Using Semantic Kernel.pptx
Building AI-Driven Apps Using Semantic Kernel.pptxUdaiappa Ramachandran
 
UiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation DevelopersUiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation DevelopersUiPathCommunity
 
UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6DianaGray10
 
UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7DianaGray10
 
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostKubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostMatt Ray
 
Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1DianaGray10
 
UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8DianaGray10
 
Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024D Cloud Solutions
 
Machine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdfMachine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdfAijun Zhang
 
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...Aggregage
 
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration WorkflowsIgniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration WorkflowsSafe Software
 

Último (20)

9 Steps For Building Winning Founding Team
9 Steps For Building Winning Founding Team9 Steps For Building Winning Founding Team
9 Steps For Building Winning Founding Team
 
NIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 WorkshopNIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 Workshop
 
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
 
Videogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfVideogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdf
 
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
 
Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.
 
20230104 - machine vision
20230104 - machine vision20230104 - machine vision
20230104 - machine vision
 
Cybersecurity Workshop #1.pptx
Cybersecurity Workshop #1.pptxCybersecurity Workshop #1.pptx
Cybersecurity Workshop #1.pptx
 
Building AI-Driven Apps Using Semantic Kernel.pptx
Building AI-Driven Apps Using Semantic Kernel.pptxBuilding AI-Driven Apps Using Semantic Kernel.pptx
Building AI-Driven Apps Using Semantic Kernel.pptx
 
UiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation DevelopersUiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation Developers
 
UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6
 
UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7
 
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostKubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
 
Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1
 
UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8
 
Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024
 
201610817 - edge part1
201610817 - edge part1201610817 - edge part1
201610817 - edge part1
 
Machine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdfMachine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdf
 
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
 
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration WorkflowsIgniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
 

Mastering Java Bytecode With ASM - 33rd degree, 2012

  • 1. Main sponsor Mastering Java Bytecode With ASM Anton Arhipov
  • 2. Me Anton Arhipov JRebel @ Product manager by day, coding monkey by night anton@zeroturnaround.com @antonarhipov
  • 3. Bytecode • One-byte instructions • 256 possible opcodes (200+ in use) • Stack based (pop, push)
  • 4. ASM • Low-level API for bytecode crunching • Core API – visitors • Tree API – nodes • Analysis package • http://asm.ow2.org
  • 5. Why? • Compilers for JVM • Programming model (AOP, ORM) • Awesome tools for JVM
  • 7. public class Items implements Serializable { private List<Integer> ids = new ArrayList<Integer>(); { ids.add(1); ids.add(100); ids.add(100000); } public int getId(int i) { return ids.get(i); } }
  • 8. public class Items implements Serializable { private List<Integer> ids = new ArrayList<Integer>(); { ids.add(1); ids.add(100); ids.add(100000); } public int getId(int i) { return ids.get(i); } }
  • 9. public class Items implements Serializable { private List<Integer> ids = new ArrayList<Integer>(); { ids.add(1); ids.add(100); ids.add(100000); } public int getId(int i) { return ids.get(i); } }
  • 10. public class Items implements Serializable { private List<Integer> ids = new ArrayList<Integer>(); { ids.add(1); ids.add(100); ids.add(100000); } public int getId(int i) { return ids.get(i); } }
  • 11. public class Items implements Serializable { private List<Integer> ids = new ArrayList<Integer>(); { ids.add(1); ids.add(100); ids.add(100000); } public int getId(int i) { return ids.get(i); } }
  • 12. Basic Process • Construct ClassWriter • Stack up the visitors for: • annotations, methods, fields, etc • Write out bytes
  • 13. javap
  • 14. ClassWriter ClassWriter cw = new ClassWriter( ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
  • 15. Visit Class cw.visit( Opcodes.V1_6, Opcodes.ACC_PUBLIC, "zt/asm/Items", null, "java/lang/Object", new String[] {"java/io/Serializable"});
  • 16. Visit Class cw.visit( Opcodes.V1_6, Opcodes.ACC_PUBLIC, "zt/asm/Items", null, "java/lang/Object", new String[] {"java/io/Serializable"});
  • 17. Visit Class cw.visit( Opcodes.V1_6, Opcodes.ACC_PUBLIC, "zt/asm/Items", null, "java/lang/Object", new String[] {"java/io/Serializable"});
  • 18. Visit Class cw.visit( Opcodes.V1_6, Opcodes.ACC_PUBLIC, "zt/asm/Items", null, "java/lang/Object", new String[] {"java/io/Serializable"});
  • 19. Visit Class cw.visit( Opcodes.V1_6, Opcodes.ACC_PUBLIC, "zt/asm/Items", null, "java/lang/Object", new String[] {"java/io/Serializable"});
  • 20. Field private List<Integer> ids = new ArrayList<Integer>(); private List<Integer> ids; public Items() { ids = new ArrayList<Integer>(); }
  • 21. Visit Field FieldVisitor fv = cw.visitField( Opcodes.ACC_PRIVATE, "ids", "Ljava/util/List;", "Ljava/util/List<Lj/l/Integer;>;", null);
  • 22. Visit Field FieldVisitor fv = cw.visitField( Opcodes.ACC_PRIVATE, "ids", "Ljava/util/List;", "Ljava/util/List<Lj/l/Integer;>;", null);
  • 23. Descriptor • Primitives • B, C, S, I, J, F, D, Z, V • References • Ljava/lang/Object; • Arrays • Prefixed with [, i.e. [Ljava/lang/Object;
  • 26. Visit Method MethodVisitor constructor = cw.visitMethod( Opcodes.ACC_PUBLIC, "<init>", "()V", null, null);
  • 27. Visit Method MethodVisitor get = cw.visitMethod( Opcodes.ACC_PUBLIC, "get", "(I)I", null, null);
  • 28. public class Items implements Serializable { private List<Integer> ids = new ArrayList<Integer>(); { ids.add(1); ids.add(100); ids.add(100000); } public int getId(int i) { return ids.get(i); } }
  • 29. public class Items implements Serializable { private List<Integer> ids = new ArrayList<Integer>(); { ids.add(1); ids.add(100); ids.add(100000); } public int getId(int i) { return ids.get(i); } }
  • 30. public Items() { super(); ids = new ArrayList<Integer>(); ids.add(1); ids.add(100); ids.add(100000); }
  • 31. public Items() { super(); ids = new ArrayList<Integer>(); ids.add(1); ids.add(100); ids.add(100000); }
  • 32. super() 0: aload_0 1: invokespecial #1 // Object.<init> MethodVisitor mv = … mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V");
  • 33. public Items() { super(); ids = new ArrayList<Integer>(); ids.add(1); ids.add(100); ids.add(100000); }
  • 34. public Items() { super(); ids = new ArrayList<Integer>(); ids.add(1); ids.add(100); ids.add(100000); }
  • 35. Assignment 4: aload_0 5: new #2 // ArrayList 8: dup 9: invokespecial #3 // <init> 12: putfield #4 // ids
  • 36. Assignment Create instance 4: aload_0 5: new #2 // ArrayList 8: dup 9: invokespecial #3 // <init> 12: putfield #4 // ids
  • 37. Assignment 4: aload_0 5: new #2 // ArrayList 8: dup 9: invokespecial #3 // <init> 12: putfield #4 // ids Assign to a field
  • 38. Assignment 5: new #2 // ArrayList 8: dup 9: invokespecial #3 // <init> 12: astore_1 #4 // ids Assign to local variable
  • 41. public Items() { super(); ids = new ArrayList<Integer>(); ids.add(1); ids.add(100); ids.add(100000); }
  • 42. public Items() { super(); ids = new ArrayList<Integer>(); ids.add(1); ids.add(100); ids.add(100000); }
  • 43. ids.add(1) 15: aload_0 16: getfield #4 // ids 19: iconst_1 20: invokestatic #5 // Integer.valueOf 23: invokeinterface #6, 2 // List.add 28: pop
  • 44. ids.add(1) 15: aload_0 16: getfield #4 // ids 19: iconst_1 20: invokestatic #5 // Integer.valueOf 23: invokeinterface #6, 2 // List.add 28: pop
  • 45. ids.add(1) 15: aload_0 16: getfield #4 // ids 19: iconst_1 20: invokestatic #5 // Integer.valueOf 23: invokeinterface #6, 2 // List.add 28: pop
  • 46. ids.add(1) 15: aload_0 16: getfield #4 // ids 19: iconst_1 20: invokestatic #5 // Integer.valueOf 23: invokeinterface #6, 2 // List.add 28: pop
  • 47. ids.add(1) 15: aload_0 16: getfield #4 // ids 19: iconst_1 20: invokestatic #5 // Integer.valueOf 23: invokeinterface #6, 2 // List.add 28: pop
  • 48. ids.add(1) 15: aload_0 16: getfield #4 // ids 19: iconst_1 20: invokestatic #5 // Integer.valueOf 23: invokeinterface #6, 2 // List.add 28: pop
  • 49. ids.add(100) 15: aload_0 16: getfield #4 // ids 19: bipush 100 20: invokestatic #5 // Integer.valueOf 23: invokeinterface #6, 2 // List.add 28: pop
  • 50. ids.add(100_000) 15: aload_0 16: getfield #4 // ids 19: ldc #7 // int 100000 20: invokestatic #5 // Integer.valueOf 23: invokeinterface #6, 2 // List.add 28: pop
  • 51. mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "zt/asm/Items", "ids", "Ljava/util/List;"); mv.visitInsn(ICONST_1); mv.visitMethodInsn(INVOKESTATIC, "java/lang /Integer", "valueOf", "(I)Ljava/lang/Intege r;"); mv.visitMethodInsn(INVOKEINTERFACE, "java/u til/List", "add", "(Ljava/lang/Object;)Z"); mv.visitInsn(POP);
  • 52. public class Items implements Serializable { private List<Integer> ids = new ArrayList<Integer>(); { ids.add(1); ids.add(100); ids.add(100000); } public int getId(int i) { return ids.get(i); } }
  • 53. ASMified mv = cw.visitMethod(ACC_PUBLIC, "getId", "(I)I", null, null); mv.visitCode(); Label l0 = new Label(); mv.visitLabel(l0); mv.visitLineNumber(16, l0); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "zt/asm/Items", "ids", "Ljava/util/List;"); mv.visitVarInsn(ILOAD, 1); mv.visitMethodInsn(INVOKEINTERFACE, "java/util/List", "get", "(I)Ljava/lang/Object;"); mv.visitTypeInsn(CHECKCAST, "java/lang/Integer"); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Integer", "intValue", "()I"); mv.visitInsn(IRETURN); Label l1 = new Label(); mv.visitLabel(l1); mv.visitLocalVariable("this", "Lzt/asm/Items;", null, l0, l1, 0); mv.visitLocalVariable("i", "I", null, l0, l1, 1); mv.visitMaxs(2, 2); mv.visitEnd();
  • 54. ASMified mv = cw.visitMethod(ACC_PUBLIC, "getId", "(I)I", null, null); mv.visitCode(); Label l0 = new Label(); java -cp asm-all-3.3.1.jar:asm-util-3.3.1.jar mv.visitLabel(l0); mv.visitLineNumber(16, l0); org.objectweb.asm.util.ASMifierClassVisitor mv.visitVarInsn(ALOAD, 0); Items.class mv.visitFieldInsn(GETFIELD, "zt/asm/Items", "ids", "Ljava/util/List;"); mv.visitVarInsn(ILOAD, 1); mv.visitMethodInsn(INVOKEINTERFACE, "java/util/List", "get", "(I)Ljava/lang/Object;"); mv.visitTypeInsn(CHECKCAST, "java/lang/Integer"); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Integer", "intValue", "()I"); mv.visitInsn(IRETURN); Label l1 = new Label(); mv.visitLabel(l1); mv.visitLocalVariable("this", "Lzt/asm/Items;", null, l0, l1, 0); mv.visitLocalVariable("i", "I", null, l0, l1, 1); mv.visitMaxs(2, 2); mv.visitEnd();
  • 55. javap public class zt.asm.deg.Items { public java.util.List<java.lang.Integer> ids; public int getId(int); Code: 0: aload_0 1: getfield #4 4: iload_1 5: invokeinterface #8, 2 10: checkcast #9 13: invokevirtual #10 16: ireturn }
  • 56. Groovyfied public class zt/asm/Items { public Ljava/util/List; ids @groovyx.ast.bytecode.Bytecode public int getId(int a) { aload 0 getfield zt.asm.Items.ids >> List iload 1 invokeinterface List.get(int) >> Object checkcast Integer invokevirtual Integer.intValue() >> int ireturn } } https://github.com/melix/groovy-bytecode-ast
  • 57. Generating bytecode from scratch is too simple … Transforming the bytecode is much more fun! 
  • 58. Instrument some bytecode
  • 59. Ninja.class Ninja.class’ 10101010101 10101010101 11000101010 11100001010 10101010001 10101010001 00010001110 00010001110 11011101011 11011101110
  • 60. How? • Add –javaagent to hook into class loading process • Implement ClassFileTransformer • Use bytecode manipulation libraries (Javassist, cglib, asm) to add any custom logic java.lang.instrument
  • 61. How ? (2) • Use custom ClassLoader – Override ClassLoader#findClass – Use ClassReader(String) to read the class in and transform it via visitor chain – Call ClassLoader#defineClass explicitly with the result from the transformation step
  • 62. java.lang.instrument import java.lang.instrument.ClassFileTransformer; import java.lang.instrument.Instrumentation; public class Agent { public static void premain(String args, Instrumentation inst) { inst.addTransformer(new ClassFileTransformer(), true); } public static void agentmain(String args, Instrumentation inst) { premain(args,inst); } }
  • 63. java.lang.instrument import java.lang.instrument.ClassFileTransformer; import java.lang.instrument.Instrumentation; public class Agent { public static void premain(String args, Instrumentation inst) { inst.addTransformer(new ClassFileTransformer(), true); } public static void agentmain(String args, Instrumentation inst) { premain(args,inst); } }
  • 64. java.lang.instrument import java.lang.instrument.ClassFileTransformer; import java.lang.instrument.Instrumentation; public class Agent { public static void premain(String args, Instrumentation inst) { inst.addTransformer(new ClassFileTransformer(), true); } public static void agentmain(String args, Instrumentation inst) { premain(args,inst); } } META-INF/MANIFEST.MF Premain-Class: Agent java –javaagent:agent.jar … Agent-Class: Agent
  • 65. j.l.instrument.ClassFileTransformer new ClassFileTransformer() { public byte[] transform(ClassLoader loader, String className, Class<?>classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer){ ClassReader cr = new ClassReader(classfileBuffer); ClassWriter cw = new ClassWriter(cr, ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES); MyAdapter ca = new MyAdapter(cw); cr.accept(ca, ClassReader.EXPAND_FRAMES); return cw.toByteArray(); }
  • 66. j.l.instrument.ClassFileTransformer new ClassFileTransformer() { public byte[] transform(ClassLoader loader, String className, Class<?>classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer){ ClassReader cr = new ClassReader(classfileBuffer); ClassWriter cw = new ClassWriter(cr, ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES); MyAdapter ca = new MyAdapter(cw); cr.accept(ca, ClassReader.EXPAND_FRAMES); return cw.toByteArray(); }
  • 67. j.l.instrument.ClassFileTransformer new ClassFileTransformer() { public byte[] transform(ClassLoader loader, String className, Class<?>classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer){ ClassReader cr = new ClassReader(classfileBuffer); ClassWriter cw = new ClassWriter(cr, ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES); MyAdapter ca = new MyAdapter(cw); cr.accept(ca, ClassReader.EXPAND_FRAMES); return cw.toByteArray(); }
  • 68. public class MyClassLoader extends ClassLoader { protected Class findClass(String name) throws ClassNotFoundException { ClassReader cr = new ClassReader(name); ClassWriter cw = new ClassWriter(cr, ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES); MyClassAdapter ca = new MyClassAdapter(cw); cr.accept(ca, ClassReader.EXPAND_FRAMES); byte b[] = cw.toByteArray(); return defineClass(name, b, 0, b.length); }

Notas del editor

  1. Programs are composed of classes, classes are thebytecode, blah blahblahJava bytecode is stack based: most of the operations push to the stack of consume values from the stack
  2. ObjectWeb ASM is the de-facto standard decomposing, modifying, and recomposing Javabytecode. ASM provides a simple library that exposes the internal aggregate components of a given Java class through its visitor oriented API. On top of visitor API ASM provides tree API that represents classes as object constructs.ASM is very popular and is used widely in various Java open-source projects. In fact, this could be the primary motivation for someone the learn this library.
  3. Why would learn Java bytecode and ASM at all?Well, creating a brand new JVM language might be a good idea  This is what all the cool kids are doing, right?Secondly – programming model that is exposed by many frameworks is backed with bytecode generation or instrumentation. AspectJ, for instance uses bytecode instrumentation extensively.Also, there are some many awesome tools that do awesome stuff, like …. JRebel for instance 
  4. This presentation gives some pointe
  5. Let’s start with an example: the class “Items” implements an interface,…
  6. Includes a field declaration &amp; assignment,..
  7. Initializer block, ..
  8. and a virtual method.
  9. The most common scenario to generate bytecode that corresponds to the example source, is to create ClassWriter, visit the structure – fields, methods, etc, and after the job is done, write out the final bytes.
  10. Actually, before going further, let’s mention javap– the Java class disassembler. The output of javap command isn’t particularly useful as there’s no way to modify it and compile back to the executable code. However, it is much more easier to read the bytecodes produced by javap, rather than the code that is written using ASM API. So, javap is good for reference when studying the bytecode.
  11. Let’s go on and construct a ClassWriter.. The constructor takes anint which is composed of different flags.COMPUTE_MAXS says that the sizes of local variables and operand stack parts will be computed automatically. Still have to call visitMaxs with any argumentsCOMPUTE_FRAMES – everything is computed automatically. ASM will compute the stack map, still have to call visitMaxs
  12. To create class signature, we’ll call ClassWriter#visit methodThe interface is full of constants, as one may notice.
  13. Java version. V1_1 – V1_7 are available.
  14. Accessor modifiers:ACC_PUBLIC, ACC_PRIVATEACC_SYNTHETIC, ACC_BRIDGE
  15. Types declared as strings 
  16. Even this API call, not that complex, but looks ugly
  17. Field declaration with assignment is actually split between the field declaration for the class, and assignment is performed in constructor. So this is something we need to keep in mind when generating the code.
  18. fisitField method creates the field declaration
  19. The ugliest part of ASM API is the descriptiors. Sorry, I’d like to rant the library a bit on this one 
  20. Blah blah descriptors, blah blah descriptors, blah blah…
  21. some descriptor examples…
  22. Fortunately, Type can help a bit with all this descriptor mess
  23. Let’s generate some methods nowFirst of all, the constructor. There isn’t a special API to generate a constructor, only the special name, &lt;init&gt;, tells that the method is actually a constructor.
  24. The real method isn’t any different from the constructor from the API point of view
  25. Now it is time to generate the constructor body
  26. The constructor consists of super() callField assignmentSome method calls
  27. The super() call for the regular class is the call to Obect.&lt;init&gt;
  28. Assigning a value to a field takes a series of opcodes to complete
  29. At first the value has to be created and placed on the stack
  30. Next,putfield, putstatic or xstoreopcode can be used to assign the value to the required location
  31. The ASM code doesn’t look very different to the javap-like code, besides all the noise it brings
  32. After the field is initialized, let’s add some values to the list: a byte, a short and an integer
  33. Adding the values to the list results in method calls with a parameter. The parameter has to be loaded to the stack in order to be passed to a method.As the autoboxing takes place, Integer.valueOf is called in order to add an Integer to the List
  34. The ASM code is getting uglier… and the captain doesn’t like it.
  35. Let’s take a step back and select a shortcut for the taks
  36. ASM code can be easily generated
  37. ... using ASMifierClassVisitor (ASMifier in ASM4). The output is rather noisy, with all the labels,but the noise is easy to remove.
  38. However,javap output is still the cleanest and easiest to read and there are some alternatives to ASM visitor API
  39. For instance, Groovy AST transformations make it possible to write code which is very close to javap output.