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

Like this? Share it with your network

Share
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
6,989
On Slideshare
3,697
From Embeds
3,292
Number of Embeds
46

Actions

Shares
Downloads
152
Comments
0
Likes
17

Embeds 3,292

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

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Mastering Java BytecodeAnton Arhipov | ZeroTurnaround
  • 2. whoami• Anton Arhipov• Java Dev / Product Lead• ZeroTurnaround, JRebel• @antonarhipov @javarebel
  • 3. Today – Java Core• Mastering Java Bytecode• The Future of Java on Multi- Core, Lambdas, Spliterators and Methods• OpenJDK JVM Internals• Invokedynamic Deep Dive
  • 4. Why Bytecode?• Know your platform!• Create your own compiler?• Programming model (AOP, ORM)• Awesome tools (JRebel )• … just bored?
  • 5. THE INTRO
  • 6. 1+2
  • 7. 1+212+
  • 8. 1+212+
  • 9. 1+212+ PUSH 1 1
  • 10. 1+212+ PUSH 1 PUSH 2 2 1
  • 11. 1+212+ PUSH 1 PUSH 2 3 ADD
  • 12. 1+212+ ICONST_1 ICONST_2 3 IADD
  • 13. ?=1+2
  • 14. TAXONOMY
  • 15. Bytecode• One-byte instructions• 256 possible opcodes• 200+ in use
  • 16. TYPE OPERATION
  • 17. TYPE OPERATION• <TYPE> ::= b, s, c, i, l, f, d, a
  • 18. TYPE OPERATION• <TYPE> ::= b, s, c, i, l, f, d, a• constant values (ldc, iconst_1)
  • 19. 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)
  • 20. Bytecode Taxonomy
  • 21. Bytecode Taxonomy StackManipulation
  • 22. Bytecode Taxonomy Stack FlowManipulation Control
  • 23. Bytecode Taxonomy Stack FlowManipulation Control Object Model
  • 24. Bytecode Taxonomy Stack FlowManipulation Control Object Arithmetics Model
  • 25. Bytecode Taxonomy Stack FlowManipulation Control monitorenter monitorexit Object Arithmetics Model
  • 26. TOOLING
  • 27. 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
  • 28. HELLO WORLD!
  • 29. C:workgeeconclasses>javap Hello -c
  • 30. 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
  • 31. 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
  • 32. 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
  • 33. 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
  • 34. 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
  • 35. 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
  • 36. 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
  • 37. 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
  • 38. 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
  • 39. 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
  • 40. 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
  • 41. C:workgeeconclasses>javap Hello -c -verbose
  • 42. C:workgeeconclasses>javap Hello -c -verbose
  • 43. 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;
  • 44. 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;
  • 45. 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;
  • 46. 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;
  • 47. C:workgeeconclasses>javap Hello -c -verbose…public Hello(); Code: Stack=1, Locals=1, Args_size=1 0: aload_0 1: invokespecial #1; //Method java/lang/Object."<init>":()V 4: return LineNumberTable: line 1: 0 LocalVariableTable: Start Length Slot Name Signature 0 5 0 this LHello;
  • 48. C:workgeeconclasses>javap Hello -c -verbose…public 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;
  • 49. MODEL OFCOMPUTATION
  • 50. Stack Machine
  • 51. Stack Machine• JVM is a stack-based machine
  • 52. Stack Machine• JVM is a stack-based machine• Each thread has a stack
  • 53. Stack Machine• JVM is a stack-based machine• Each thread has a stack• Stack stores frames
  • 54. Stack Machine• JVM is a stack-based machine• Each thread has a stack• Stack stores frames• Frame is created on method invocation
  • 55. 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
  • 56. The FrameLocal variables0 1 2 … NOperand stack #1 Constant Pool
  • 57. 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;
  • 58. 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;
  • 59. 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;
  • 60. 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;
  • 61. STACK CRUNCHING
  • 62. dup Apop Bswapdup_x1dup2_x1
  • 63. dup Apop Aswap Bdup_x1dup2_x1
  • 64. dup Apop Bswapdup_x1dup2_x1
  • 65. dup Bpop Aswapdup_x1dup2_x1
  • 66. dup Bpop Aswap Bdup_x1dup2_x1
  • 67. dup Bpop Aswap Bdup_x1 Bdup2_x1 A
  • 68. dup2_x2 How do youswap doubles?
  • 69. dup2_x2
  • 70. dup2_x2dconst_0 0.0
  • 71. dup2_x2dconst_0dconst_1 1.0 0.0
  • 72. dup2_x2dconst_0dconst_1 1.0swap 0.0
  • 73. dup2_x2dconst_0dconst_1 1.0swap not allowed! 0.0
  • 74. dup2_x2dconst_0dconst_1 1.0swap2 0.0
  • 75. dup2_x2dconst_0dconst_1 1.0 doesn’tswap2 exist 0.0
  • 76. dup2_x2dconst_0dconst_1 1.0dup2_x2 0.0 1.0
  • 77. dup2_x2dconst_0dconst_1 0.0dup2_x2pop2 1.0
  • 78. dup2_x2dconst_0dconst_1 0.0dup2_x2pop2 1.0profit! 
  • 79. LOCAL VARIABLES
  • 80. Local Variables
  • 81. 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
  • 82. 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
  • 83. 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
  • 84. 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
  • 85. 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
  • 86. Local Variables Stackvar value depth value ldc "Hello"0 0 astore_01 iconst_1 1 astore_12 aload_0 23 34 4
  • 87. Local Variables Stackvar value depth value ldc "Hello"0 0 "Hello" astore_01 iconst_1 1 astore_12 aload_0 23 34 4
  • 88. Local Variables Stackvar value depth value ldc "Hello"0 "Hello" 0 astore_01 iconst_1 1 astore_12 aload_0 23 34 4
  • 89. Local Variables Stackvar value depth value ldc "Hello"0 "Hello" 0 1 astore_01 iconst_1 1 astore_12 aload_0 23 34 4
  • 90. Local Variables Stackvar value depth value ldc "Hello"0 "Hello" 0 astore_01 1 iconst_1 1 astore_12 aload_0 23 34 4
  • 91. 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
  • 92. load LocalVariables Stack Table store
  • 93. OBJECTS
  • 94. Object Initializationnew 0xBB <init> Instance initialization method <clinit> Class and interface initialization method
  • 95. 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
  • 96. 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
  • 97. Object Initialization: new
  • 98. Object Initialization: new
  • 99. Object Initialization: newpublic Initializer(); Code:
  • 100. Object Initialization: newpublic Initializer(); Code: 0: aload_0
  • 101. Object Initialization: newpublic Initializer(); Code: 0: aload_0 1: invokespecial #1; //Method java/lang/Object."<init>":()V
  • 102. Object Initialization: newpublic Initializer(); Code: 0: aload_0 1: invokespecial #1; //Method java/lang/Object."<init>":()V 4: aload_0
  • 103. 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
  • 104. 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;
  • 105. 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
  • 106. 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
  • 107. Object Initialization: {}
  • 108. Object Initialization: {}
  • 109. 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
  • 110. There’s no initializer
  • 111. METHODINVOCATION
  • 112. invokeXXX• invokestatic• invokespecial• invokevirtual• invokeinterface• invokedynamic
  • 113. invokestatic• invokestatic• invokespecial• invokevirtual Integer.valueOf(“42”)• invokeinterface• invokedynamic
  • 114. invokespecial• invokestatic <init>• invokespecial• invokevirtual private void foo();• invokeinterface• invokedynamic super.method();
  • 115. invokevirtual class A• invokestatic A/method1 A/method2• invokespecial• invokevirtual• invokeinterface• invokedynamic
  • 116. invokevirtual class A• invokestatic A/method1 A/method2• invokespecial class B• invokevirtual• invokeinterface• invokedynamic
  • 117. invokevirtual class A• invokestatic A/method1 A/method2• invokespecial class B• invokevirtual A/method1 B/method2• invokeinterface B/method3• invokedynamic
  • 118. invokeinterface class A• invokestatic A/method1 A/method2• invokespecial class B impl X• invokevirtual A/method1 B/method2• invokeinterface B/method3 X/methodX• invokedynamic
  • 119. 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
  • 120. 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
  • 121. 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
  • 122. Method Invocation
  • 123. Method Invocationobj.method(param1, param2);
  • 124. Method Invocationobj.method(param1, param2);
  • 125. Method Invocationobj.method(param1, param2); push obj push param1 push param2 call method
  • 126. Method Invocationobj.method(param1, param2); obj push obj push param1 push param2 call method
  • 127. Method Invocationobj.method(param1, param2); param1 push obj obj push param1 push param2 call method
  • 128. Method Invocationobj.method(param1, param2); param2 push obj param1 push param1 push param2 obj call method
  • 129. Method Invocationobj.method(param1, param2); obj? push obj push param1 push param2 call method
  • 130. Method Invocationthis.add(1, 2);0: aload_01: iconst_12: iconst_23: invokevirtual #2; //Method add:(II)I
  • 131. INNER CLASSES
  • 132. Inner Classes
  • 133. Inner Classes
  • 134. 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}
  • 135. 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}
  • 136. 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}
  • 137. “HOW DO THEY DO THAT?”
  • 138. object Singleton { def test={}}
  • 139. object Singleton { def test={} } $> scalac Singleton.scalaSingleton.class Singleton$.class
  • 140. 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}
  • 141. 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}
  • 142. 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}
  • 143. public final class Singleton extends java.lang.Object {public static final void test(); Code: 0: getstatic #11; //Field Singleton$.MODULE$:LSingleton$; 3: invokevirtual #13; //Method Singleton$.test:()V 6: return}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$();}
  • 144. public final class Singleton extends java.lang.Object {public static final void test(); Code: 0: getstatic #11; //Field Singleton$.MODULE$:LSingleton$; 3: invokevirtual #13; //Method Singleton$.test:()V 6: return}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$();}
  • 145. public final class Singleton extends java.lang.Object {public static final void test(); Code: 0: getstatic #11; //Field Singleton$.MODULE$:LSingleton$; 3: invokevirtual #13; //Method Singleton$.test:()V 6: return}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$();}
  • 146. public final class Singleton extends java.lang.Object {public static final void test(); Code: 0: getstatic #11; //Field Singleton$.MODULE$:LSingleton$; 3: invokevirtual #13; //Method Singleton$.test:()V 6: return}public final class Singleton$ extends java.lang.Object 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
  • 147. object Singleton { def test={}}
  • 148. public class Singleton { public void test(){ Singleton$.MODULE$.test(); } }object Singleton { def test={}}
  • 149. 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() { } }
  • 150. class Groovy { }
  • 151. class Groovy { }$> groovyc Groovy.groovy$> javap –c –p Groovy
  • 152. 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);
  • 153. OBJECTWEB ASM
  • 154. SLIDESGOTO IDESLIDESIDE: DEMO
  • 155. https://github.com/antonarhipov
  • 156. @antonarhipovanton@zeroturnaround.com