Mastering Java Bytecode - JAX.de 2012
Upcoming SlideShare
Loading in...5
×
 

Mastering Java Bytecode - JAX.de 2012

on

  • 6,797 views

 

Statistics

Views

Total Views
6,797
Views on SlideShare
3,544
Embed Views
3,253

Actions

Likes
17
Downloads
151
Comments
0

46 Embeds 3,253

http://arhipov.blogspot.com 2030
http://arhipov.blogspot.in 225
http://arhipov.blogspot.de 130
http://arhipov.blogspot.co.uk 107
http://feeds.feedburner.com 74
http://arhipov.blogspot.com.au 69
http://arhipov.blogspot.ru 58
http://arhipov.blogspot.ca 57
http://arhipov.blogspot.fr 53
http://arhipov.blogspot.it 42
http://rondroid.tumblr.com 36
http://arhipov.blogspot.com.es 31
http://arhipov.blogspot.cz 27
http://arhipov.blogspot.com.br 24
http://arhipov.blogspot.ch 24
http://arhipov.blogspot.be 24
http://arhipov.blogspot.nl 22
http://arhipov.blogspot.co.il 19
http://arhipov.blogspot.se 19
http://arhipov.blogspot.no 15
http://arhipov.blogspot.co.at 14
http://arhipov.blogspot.jp 13
http://arhipov.blogspot.ro 13
http://www.arhipov.blogspot.ru 12
http://arhipov.blogspot.ie 11
http://arhipov.blogspot.com.ar 9
http://arhipov.blogspot.pt 9
http://arhipov.blogspot.dk 9
http://arhipov.blogspot.hk 8
http://arhipov.blogspot.fi 8
http://arhipov.blogspot.hu 8
http://arhipov.blogspot.kr 7
http://arhipov.blogspot.sg 7
http://arhipov.blogspot.sk 6
http://arhipov.blogspot.tw 6
http://arhipov.blogspot.mx 6
http://arhipov.blogspot.co.nz 5
http://arhipov.blogspot.com.tr 3
http://www.hanrss.com 2
http://paper.li 2
http://arhipov.blogspot.gr 2
http://www.arhipov.blogspot.com 2
http://webcache.googleusercontent.com 2
http://reader.aol.com 1
http://www.linkedin.com 1
http://localhost 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Mastering Java Bytecode - JAX.de 2012 Mastering Java Bytecode - JAX.de 2012 Presentation Transcript

    • Mastering Java BytecodeAnton Arhipov | ZeroTurnaround
    • whoami• Anton Arhipov• Java Dev / Product Lead• ZeroTurnaround, JRebel• @antonarhipov @javarebel
    • Today – Java Core• Mastering Java Bytecode• The Future of Java on Multi- Core, Lambdas, Spliterators and Methods• OpenJDK JVM Internals• Invokedynamic Deep Dive
    • Why Bytecode?• Know your platform!• Create your own compiler?• Programming model (AOP, ORM)• Awesome tools (JRebel )• … just bored?
    • THE INTRO
    • 1+2
    • 1+212+
    • 1+212+
    • 1+212+ PUSH 1 1
    • 1+212+ PUSH 1 PUSH 2 2 1
    • 1+212+ PUSH 1 PUSH 2 3 ADD
    • 1+212+ ICONST_1 ICONST_2 3 IADD
    • ?=1+2
    • TAXONOMY
    • Bytecode• One-byte instructions• 256 possible opcodes• 200+ in use
    • TYPE OPERATION
    • TYPE OPERATION• <TYPE> ::= b, s, c, i, l, f, d, a
    • TYPE OPERATION• <TYPE> ::= b, s, c, i, l, f, d, a• constant values (ldc, iconst_1)
    • TYPE OPERATION• <TYPE> ::= b, s, c, i, l, f, d, a• constant values (ldc, iconst_1)• Local variables and stack interaction (load/store)• Array operations (aload, astore)• Math (add, sub, mul, div)• Boolean/bitwise operations (iand, ixor)• Comparisons (cmpg, cmpl, ifne, ifeq)• Conversions (l2d, i2l)
    • Bytecode Taxonomy
    • Bytecode Taxonomy StackManipulation
    • Bytecode Taxonomy Stack FlowManipulation Control
    • Bytecode Taxonomy Stack FlowManipulation Control Object Model
    • Bytecode Taxonomy Stack FlowManipulation Control Object Arithmetics Model
    • Bytecode Taxonomy Stack FlowManipulation Control monitorenter monitorexit Object Arithmetics Model
    • TOOLING
    • javap• Java class file disassembler• Used with no options shows class structure only – Methods, superclass, interfaces, etc• -c shows the bytecode• -private shows all methods and members• -s prints internal signatures• -l prints line numbers and local variable tables
    • HELLO WORLD!
    • C:workgeeconclasses>javap Hello -c
    • C:workgeeconclasses>javap Hello -cCompiled from "Hello.java"public class Hello extends java.lang.Object{public Hello(); Code: 0: aload_0 1: invokespecial #1; //Method java/lang/Object."<init>":()V 4: return
    • C:workgeeconclasses>javap Hello -cCompiled from "Hello.java"public class Hello extends java.lang.Object{public Hello(); Code: the default constructor 0: aload_0 1: invokespecial #1; //Method java/lang/Object."<init>":()V 4: return
    • C:workgeeconclasses>javap Hello -cCompiled from "Hello.java"public class Hello extends java.lang.Object{public Hello(); Code: push this to stack 0: aload_0 1: invokespecial #1; //Method java/lang/Object."<init>":()V 4: return
    • C:workgeeconclasses>javap Hello -cCompiled from "Hello.java"public class Hello extends java.lang.Object{public Hello(); Code: 0: aload_0 1: invokespecial #1; //Method java/lang/Object."<init>":()V 4: return invoke <init> on this
    • C:workgeeconclasses>javap Hello -cCompiled from "Hello.java"public class Hello extends java.lang.Object{public Hello(); Code: 0: aload_0 1: invokespecial #1; //Method java/lang/Object."<init>":()V 4: return
    • C:workgeeconclasses>javap Hello -cCompiled from "Hello.java"public class Hello extends java.lang.Object{public Hello(); Code: 0: aload_0 1: invokespecial #1; //Method java/lang/Object."<init>":()V 4: returnpublic static void main(java.lang.String[]); Code: 0: getstatic #2; //Field java/lang/System.out:Ljava/io/PrintStream; 3: ldc #3; //String Hello, World! 5: invokevirtual #4; //Method java/io/PrintStream.println:(Ljava/lang/String;)V
    • C:workgeeconclasses>javap Hello -cCompiled from "Hello.java"public class Hello extends java.lang.Object{public Hello(); Code: 0: aload_0 1: invokespecial #1; //Method java/lang/Object."<init>":()V 4: return get static fieldpublic static void main(java.lang.String[]); Code: 0: getstatic #2; //Field java/lang/System.out:Ljava/io/PrintStream; 3: ldc #3; //String Hello, World! 5: invokevirtual #4; //Method java/io/PrintStream.println:(Ljava/lang/String;)V
    • C:workgeeconclasses>javap Hello -cCompiled from "Hello.java"public class Hello extends java.lang.Object{public Hello(); Code: 0: aload_0 1: invokespecial #1; //Method java/lang/Object."<init>":()V 4: returnpublic static void main(java.lang.String[]); Code: 0: getstatic #2; //Field java/lang/System.out:Ljava/io/PrintStream; 3: ldc #3; //String Hello, World! 5: invokevirtual #4; //Method java/io/PrintStream.println:(Ljava/lang/String;)V load string to the stack
    • C:workgeeconclasses>javap Hello -cCompiled from "Hello.java"public class Hello extends java.lang.Object{public Hello(); Code: 0: aload_0 1: invokespecial #1; //Method java/lang/Object."<init>":()V 4: returnpublic static void main(java.lang.String[]); Code: 0: getstatic #2; //Field java/lang/System.out:Ljava/io/PrintStream; 3: ldc #3; //String Hello, World! 5: invokevirtual #4; //Method java/io/PrintStream.println:(Ljava/lang/String;)V invoke method with parameter
    • C:workgeeconclasses>javap Hello -cCompiled from "Hello.java"public class Hello extends java.lang.Object{public Hello(); Code: 0: aload_0 1: invokespecial #1; //Method java/lang/Object."<init>":()V 4: returnpublic static void main(java.lang.String[]); Code: 0: getstatic #2; //Field java/lang/System.out:Ljava/io/PrintStream; 3: ldc #3; //String Hello, World! 5: invokevirtual #4; //Method java/io/PrintStream.println:(Ljava/lang/String;)V
    • What’s #1,#2, etc ?C:workgeeconclasses>javap Hello -cCompiled from "Hello.java"public class Hello extends java.lang.Object{public Hello(); Code: 0: aload_0 1: invokespecial #1; //Method java/lang/Object."<init>":()V 4: returnpublic static void main(java.lang.String[]); Code: 0: getstatic #2; //Field java/lang/System.out:Ljava/io/PrintStream; 3: ldc #3; //String Hello, World! 5: invokevirtual #4; //Method java/io/PrintStream.println:(Ljava/lang/String;)V
    • C:workgeeconclasses>javap Hello -c -verbose
    • C:workgeeconclasses>javap Hello -c -verbose
    • C:workgeeconclasses>javap Hello -c -verboseCompiled from "Hello.java“public class Hello extends java.lang.Object SourceFile: "Hello.java" minor version: 0 major version: 50 Constant pool:const #1 = Method #6.#20; // java/lang/Object."<init>":()Vconst #2 = Field #21.#22; // java/lang/System.out:Ljava/io/PrintStream;const #3 = String #23; // Hello, World!const #4 = Method #24.#25; // java/io/PrintStream.println:(Ljava/lang/String;)Vconst #5 = class #26; // Helloconst #6 = class #27; // java/lang/Objectconst #7 = Asciz <init>;const #8 = Asciz ()V;
    • C:workgeeconclasses>javap Hello -c -verboseCompiled from "Hello.java“public class Hello extends java.lang.Object SourceFile: "Hello.java" minor version: 0 major version: 50 Constant pool:const #1 = Method #6.#20; // java/lang/Object."<init>":()Vconst #2 = Field #21.#22; // java/lang/System.out:Ljava/io/PrintStream;const #3 = String #23; // Hello, World!const #4 = Method #24.#25; // java/io/PrintStream.println:(Ljava/lang/String;)Vconst #5 = class #26; // Helloconst #6 = class #27; // java/lang/Objectconst #7 = Asciz <init>;const #8 = Asciz ()V;
    • C:workgeeconclasses>javap Hello -c -verbose…public Hello(); Code: Stack=1, Locals=1, Args_size=1 0: aload_0 1: invokespecial #1; //Method java/lang/Object."<init>":()V 4: return LineNumberTable: line 1: 0 LocalVariableTable: Start Length Slot Name Signature 0 5 0 this LHello;
    • C:workgeeconclasses>javap Hello -c -verbose…public Hello(); Code: Stack=1, Locals=1, Args_size=1 0: aload_0 1: invokespecial #1; //Method java/lang/Object."<init>":()V 4: return LineNumberTable: line 1: 0 LocalVariableTable: Start Length Slot Name Signature 0 5 0 this LHello;
    • C:workgeeconclasses>javap Hello -c -verbose…public Hello(); Code: Stack=1, Locals=1, Args_size=1 0: aload_0 1: invokespecial #1; //Method java/lang/Object."<init>":()V 4: return LineNumberTable: line 1: 0 LocalVariableTable: Start Length Slot Name Signature 0 5 0 this LHello;
    • C:workgeeconclasses>javap Hello -c -verbose…public static void main(java.lang.String[]); Code: Stack=2, Locals=1, Args_size=1 0: getstatic #2; //Field java/lang/System.out:Ljava/io/PrintStream; 3: ldc #3; //String Hello, World! 5: invokevirtual #4; //Method java/io/PrintStream.println:(Ljava/lang/String;)V 8: return LineNumberTable: line 4: 0 line 5: 8 LocalVariableTable: Start Length Slot Name Signature 0 9 0 args [Ljava/lang/String;
    • MODEL OFCOMPUTATION
    • Stack Machine
    • Stack Machine• JVM is a stack-based machine
    • Stack Machine• JVM is a stack-based machine• Each thread has a stack
    • Stack Machine• JVM is a stack-based machine• Each thread has a stack• Stack stores frames
    • Stack Machine• JVM is a stack-based machine• Each thread has a stack• Stack stores frames• Frame is created on method invocation
    • Stack Machine• JVM is a stack-based machine• Each thread has a stack• Stack stores frames• Frame is created on method invocation• Frame consists of: – Operand stack – Array of local variables
    • The FrameLocal variables0 1 2 … NOperand stack #1 Constant Pool
    • public java.lang.String getName(); Code: Stack=1, Locals=1, Args_size=1 0: aload_0 1: getfield #2; //Field name:Ljava/lang/String; 4: areturnLocalVariableTable: Start Length Slot Name Signature 0 5 0 this LGet;
    • 0 1 2 3 4 aload_0 getfield 00 02 areturnpublic java.lang.String getName(); Code: Stack=1, Locals=1, Args_size=1 0: aload_0 1: getfield #2; //Field name:Ljava/lang/String; 4: areturnLocalVariableTable: Start Length Slot Name Signature 0 5 0 this LGet;
    • 0 1 2 3 4 2A B4 00 02 B0public java.lang.String getName(); Code: Stack=1, Locals=1, Args_size=1 0: aload_0 1: getfield #2; //Field name:Ljava/lang/String; 4: areturnLocalVariableTable: Start Length Slot Name Signature 0 5 0 this LGet;
    • public java.lang.String getName(); Code: Stack=1, Locals=1, Args_size=1 0: aload_0 1: getfield #2; //Field name:Ljava/lang/String; 4: areturnLocalVariableTable: Start Length Slot Name Signature 0 5 0 this LGet;
    • STACK CRUNCHING
    • dup Apop Bswapdup_x1dup2_x1
    • dup Apop Aswap Bdup_x1dup2_x1
    • dup Apop Bswapdup_x1dup2_x1
    • dup Bpop Aswapdup_x1dup2_x1
    • dup Bpop Aswap Bdup_x1dup2_x1
    • dup Bpop Aswap Bdup_x1 Bdup2_x1 A
    • dup2_x2 How do youswap doubles?
    • dup2_x2
    • dup2_x2dconst_0 0.0
    • dup2_x2dconst_0dconst_1 1.0 0.0
    • dup2_x2dconst_0dconst_1 1.0swap 0.0
    • dup2_x2dconst_0dconst_1 1.0swap not allowed! 0.0
    • dup2_x2dconst_0dconst_1 1.0swap2 0.0
    • dup2_x2dconst_0dconst_1 1.0 doesn’tswap2 exist 0.0
    • dup2_x2dconst_0dconst_1 1.0dup2_x2 0.0 1.0
    • dup2_x2dconst_0dconst_1 0.0dup2_x2pop2 1.0
    • dup2_x2dconst_0dconst_1 0.0dup2_x2pop2 1.0profit! 
    • LOCAL VARIABLES
    • Local Variables
    • Local Variablespublic int calculate(int); Code: Stack=2, Locals=2, Args_size=2 … LocalVariableTable: Start Length Slot Name Signature 0 5 0 this LLocalVariables; 0 5 1 value I
    • Local Variablespublic int calculate(int); Code: Stack=2, Locals=2, Args_size=2 … LocalVariableTable: Start Length Slot Name Signature 0 5 0 this LLocalVariables; 0 5 1 value I
    • Local Variablespublic int calculate(int); Code: Stack=2, Locals=2, Args_size=2 … LocalVariableTable: Start Length Slot Name Signature 0 5 0 this LLocalVariables; 0 5 1 value I
    • Local Variables The tablepublic int calculate(int); Code: maps Stack=2, Locals=2, Args_size=2 numbers to … names LocalVariableTable: Start Length Slot Name Signature 0 5 0 this LLocalVariables; 0 5 1 value I
    • Local Variablespublic int calculate(int); Code: Stack=2, Locals=2, Args_size=2 Sized explicitly … LocalVariableTable: Start Length Slot Name Signature 0 5 0 this LLocalVariables; 0 5 1 value I
    • Local Variables Stackvar value depth value ldc "Hello"0 0 astore_01 iconst_1 1 astore_12 aload_0 23 34 4
    • Local Variables Stackvar value depth value ldc "Hello"0 0 "Hello" astore_01 iconst_1 1 astore_12 aload_0 23 34 4
    • Local Variables Stackvar value depth value ldc "Hello"0 "Hello" 0 astore_01 iconst_1 1 astore_12 aload_0 23 34 4
    • Local Variables Stackvar value depth value ldc "Hello"0 "Hello" 0 1 astore_01 iconst_1 1 astore_12 aload_0 23 34 4
    • Local Variables Stackvar value depth value ldc "Hello"0 "Hello" 0 astore_01 1 iconst_1 1 astore_12 aload_0 23 34 4
    • Local Variables Stackvar value depth value ldc "Hello"0 "Hello" 0 "Hello" astore_01 1 iconst_1 1 astore_12 aload_0 23 34 4
    • load LocalVariables Stack Table store
    • OBJECTS
    • Object Initializationnew 0xBB <init> Instance initialization method <clinit> Class and interface initialization method
    • Object Initialization: static {} static {}; Code: 0: iconst_1 1: putstatic #2; //Field a:I 4: iconst_2 5: putstatic #3; //Field b:I 8: return
    • Object Initialization: static {} <clinit> static {}; Code: 0: iconst_1 1: putstatic #2; //Field a:I 4: iconst_2 5: putstatic #3; //Field b:I 8: return
    • Object Initialization: new
    • Object Initialization: new
    • Object Initialization: newpublic Initializer(); Code:
    • Object Initialization: newpublic Initializer(); Code: 0: aload_0
    • Object Initialization: newpublic Initializer(); Code: 0: aload_0 1: invokespecial #1; //Method java/lang/Object."<init>":()V
    • Object Initialization: newpublic Initializer(); Code: 0: aload_0 1: invokespecial #1; //Method java/lang/Object."<init>":()V 4: aload_0
    • Object Initialization: newpublic Initializer(); Code: 0: aload_0 1: invokespecial #1; //Method java/lang/Object."<init>":()V 4: aload_0 5: new #2; //class java/lang/Object 8: dup
    • Object Initialization: newpublic Initializer(); Code: 0: aload_0 1: invokespecial #1; //Method java/lang/Object."<init>":()V 4: aload_0 5: new #2; //class java/lang/Object 8: dup 9: invokespecial #1; //Method java/lang/Object."<init>":()V12: putfield #3; //Field o:Ljava/lang/Object;
    • Object Initialization: newpublic Initializer(); Code: 0: aload_0 1: invokespecial #1; //Method java/lang/Object."<init>":()V 4: aload_0 5: new #2; //class java/lang/Object 8: dup 9: invokespecial #1; //Method java/lang/Object."<init>":()V12: putfield #3; //Field o:Ljava/lang/Object;15: return
    • Object Initialization: newpublic Initializer(); Code: 0: aload_0 1: invokespecial #1; //Method java/lang/Object."<init>":()V 4: aload_0 5: new #2; //class java/lang/Object 8: dup 9: invokespecial #1; //Method java/lang/Object."<init>":()V12: putfield #3; //Field o:Ljava/lang/Object;15: return
    • Object Initialization: {}
    • Object Initialization: {}
    • Object Initialization: {} public Initializer(int); Code: 0:aload_0 1:invokespecial #1; // ..<init> 4:aload_0 5:iconst_1 6:putfield #2; //Field a:I 9:aload_0 10:iconst_2 11: putfield #3; //Field c:I 14:aload_0 15:iload_1 16:putfield #4; //Field b:I 19:return
    • There’s no initializer
    • METHODINVOCATION
    • invokeXXX• invokestatic• invokespecial• invokevirtual• invokeinterface• invokedynamic
    • invokestatic• invokestatic• invokespecial• invokevirtual Integer.valueOf(“42”)• invokeinterface• invokedynamic
    • invokespecial• invokestatic <init>• invokespecial• invokevirtual private void foo();• invokeinterface• invokedynamic super.method();
    • invokevirtual class A• invokestatic A/method1 A/method2• invokespecial• invokevirtual• invokeinterface• invokedynamic
    • invokevirtual class A• invokestatic A/method1 A/method2• invokespecial class B• invokevirtual• invokeinterface• invokedynamic
    • invokevirtual class A• invokestatic A/method1 A/method2• invokespecial class B• invokevirtual A/method1 B/method2• invokeinterface B/method3• invokedynamic
    • invokeinterface class A• invokestatic A/method1 A/method2• invokespecial class B impl X• invokevirtual A/method1 B/method2• invokeinterface B/method3 X/methodX• invokedynamic
    • invokeinterface class A• invokestatic A/method1 A/method2• invokespecial class B impl X• invokevirtual A/method1• invokeinterface B/method2 B/method3 D impl X X/methodX D/method1• invokedynamic X/methodX
    • invokeinterface class A• invokestatic A/method1 A/method2• invokespecial class B impl X• invokevirtual A/method1• invokeinterface B/method2 B/method3 D impl X X/methodX D/method1• invokedynamic X/methodX
    • invokeinterface class A • invokestatic A/method1 A/method2 • invokespecial class B impl X • invokevirtual A/method1 • invokeinterface B/method2 B/method3 D impl X X/methodX D/method1 • invokedynamic X/methodXEfficient Implementation of Java Interfaces: Invokeinterface ConsideredHarmless, Bowen Alpern, Anthony Cocchi, Stephen Fink, David Grove, andDerek Lieber, OOPSLA’01
    • Method Invocation
    • Method Invocationobj.method(param1, param2);
    • Method Invocationobj.method(param1, param2);
    • Method Invocationobj.method(param1, param2); push obj push param1 push param2 call method
    • Method Invocationobj.method(param1, param2); obj push obj push param1 push param2 call method
    • Method Invocationobj.method(param1, param2); param1 push obj obj push param1 push param2 call method
    • Method Invocationobj.method(param1, param2); param2 push obj param1 push param1 push param2 obj call method
    • Method Invocationobj.method(param1, param2); obj? push obj push param1 push param2 call method
    • Method Invocationthis.add(1, 2);0: aload_01: iconst_12: iconst_23: invokevirtual #2; //Method add:(II)I
    • INNER CLASSES
    • Inner Classes
    • Inner Classes
    • Inner Classesclass Car$Engine extends j.l.Object{final Car this$0;Car$Engine(Car);public void start(); Code: 0: aload_0 1: getfield #1; //Field this$0:LCar; 4: invokestatic #3; // Car.access$000:(LCar;)V 7: return}
    • Inner Classes public class Car extends j.l.Object{ public Car(); private void move();class Car$Engine extends j.l.Object{final Car this$0; static void access$000(Car); Code:Car$Engine(Car); 0: aload_0 1: invokespecial #1; // move: ()V;public void start(); 4: return Code: } 0: aload_0 1: getfield #1; //Field this$0:LCar; 4: invokestatic #3; // Car.access$000:(LCar;)V 7: return}
    • Inner Classes public class Car extends j.l.Object{ public Car(); private void move();class Car$Engine extends j.l.Object{final Car this$0; static void access$000(Car); Code:Car$Engine(Car); 0: aload_0 1: invokespecial #1; // move: ()V;public void start(); 4: return Code: } 0: aload_0 1: getfield #1; //Field this$0:LCar; 4: invokestatic #3; // Car.access$000:(LCar;)V 7: return}
    • “HOW DO THEY DO THAT?”
    • object Singleton { def test={}}
    • object Singleton { def test={} } $> scalac Singleton.scalaSingleton.class Singleton$.class
    • public final class Singleton extends java.lang.Object {public static final void test(); Code: 0: getstatic #11; //Field Singleton$.MODULE$:LSingleton$; 3: invokevirtual #13; //Method Singleton$.test:()V 6: return}
    • public final class Singleton extends java.lang.Object {public static final void test(); Code: 0: getstatic #11; //Field Singleton$.MODULE$:LSingleton$; 3: invokevirtual #13; //Method Singleton$.test:()V 6: return}
    • public final class Singleton extends java.lang.Object {public static final void test(); Code: 0: getstatic #11; //Field Singleton$.MODULE$:LSingleton$; 3: invokevirtual #13; //Method Singleton$.test:()V 6: return}
    • public final class Singleton extends java.lang.Object {public static final void test(); Code: 0: getstatic #11; //Field Singleton$.MODULE$:LSingleton$; 3: invokevirtual #13; //Method Singleton$.test:()V 6: return}public final class Singleton$ extends java.lang.Object implementsscala.ScalaObject {public static final Singleton$ MODULE$;public static {}; Code: 0: new #9; //class Singleton$ 3: invokespecial #12; //Method "<init>":()V 6: returnpublic void test();private Singleton$();}
    • public final class Singleton extends java.lang.Object {public static final void test(); Code: 0: getstatic #11; //Field Singleton$.MODULE$:LSingleton$; 3: invokevirtual #13; //Method Singleton$.test:()V 6: return}public final class Singleton$ extends java.lang.Object implementsscala.ScalaObject {public static final Singleton$ MODULE$;public static {}; Code: 0: new #9; //class Singleton$ 3: invokespecial #12; //Method "<init>":()V 6: returnpublic void test();private Singleton$();}
    • public final class Singleton extends java.lang.Object {public static final void test(); Code: 0: getstatic #11; //Field Singleton$.MODULE$:LSingleton$; 3: invokevirtual #13; //Method Singleton$.test:()V 6: return}public final class Singleton$ extends java.lang.Object implementsscala.ScalaObject {public static final Singleton$ MODULE$;public static {}; Code: 0: new #9; //class Singleton$ 3: invokespecial #12; //Method "<init>":()V 6: returnpublic void test();private Singleton$();}
    • public final class Singleton extends java.lang.Object {public static final void test(); Code: 0: getstatic #11; //Field Singleton$.MODULE$:LSingleton$; 3: invokevirtual #13; //Method Singleton$.test:()V 6: return}public final class Singleton$ extends java.lang.Object implementsscala.ScalaObject {public static final Singleton$ MODULE$;public static {};public void test();private Singleton$();Code: 0: aload_0 1: invokespecial #17; //Method java/lang/Object."<init>":()V 4: aload_0 5: putstatic #19; //Field MODULE$:LSingleton$; 8: return
    • object Singleton { def test={}}
    • public class Singleton { public void test(){ Singleton$.MODULE$.test(); } }object Singleton { def test={}}
    • public class Singleton { public void test(){ Singleton$.MODULE$.test(); } } public final class Singleton$object Singleton { implements scala.ScalaObject { def test={} public static final Singleton$ MODULE$;} static { new Singleton$(); } private Singleton$(){ MODULE$ = this; } public void test() { } }
    • class Groovy { }
    • class Groovy { }$> groovyc Groovy.groovy$> javap –c –p Groovy
    • class Groovy { }$> groovyc Groovy.groovy$> javap –c –p Groovypublic class Test extends java.lang.Object implements groovy.lang.GroovyObject{ private static org.codehaus.groovy.reflection.ClassInfo $staticClassInfo; private transient groovy.lang.MetaClass metaClass; public static java.lang.Long __timeStamp; public static java.lang.Long __timeStamp__239_neverHappen1304807931117; private static java.lang.ref.SoftReference $callSiteArray; private static java.lang.Class $class$groovy$lang$MetaClass; private static java.lang.Class $class$Test; private static java.lang.Class $class$java$lang$String; public java.lang.Object this$dist$invoke$2(java.lang.String, java.lang.Object); public void this$dist$set$2(java.lang.String, java.lang.Object); public java.lang.Object this$dist$get$2(java.lang.String); protected groovy.lang.MetaClass $getStaticMetaClass(); public groovy.lang.MetaClass getMetaClass(); public void setMetaClass(groovy.lang.MetaClass); public java.lang.Object invokeMethod(java.lang.String, java.lang.Object); public java.lang.Object getProperty(java.lang.String); public void setProperty(java.lang.String, java.lang.Object);
    • OBJECTWEB ASM
    • SLIDESGOTO IDESLIDESIDE: DEMO
    • https://github.com/antonarhipov
    • @antonarhipovanton@zeroturnaround.com