in practice source code source code javac scalac groovyc
play

in practice source code source code javac scalac groovyc jrubyc - PowerPoint PPT Presentation

Java byte code in practice source code source code javac scalac groovyc jrubyc 0xCAFEBABE byte code source code javac scalac groovyc jrubyc 0xCAFEBABE byte code class loader interpreter JIT compiler JVM source code javac


  1. source code byte code pkg/Bar.class package pkg; class Bar { void foo () { 0x0000 0x0000 0x0001 return; 0xB1 } 0x0000 0x0001 } 0x0000: foo 0x0001: ()V 0x0002: pkg/Bar constant pool (i.a. UTF-8) operand stack ///////////////// 0 : this local variable array

  2. Java type JVM type (non-array) JVM descriptor stack slots boolean Z 1 byte B 1 short I S 1 char C 1 int I 1 long L J 2 float F F 1 double D D 2 void - V 0 java.lang.Object A Ljava/lang/Object; 1

  3. source code byte code package pkg; class Bar { int foo ( int i ) { return foo ( i + 1 ); } }

  4. source code byte code package pkg; class Bar { int foo ( int i ) { ILOAD_1 return foo ( i + 1 ); ICONST_1 } IADD }

  5. source code byte code package pkg; class Bar { int foo ( int i ) { ILOAD_1 return foo ( i + 1 ); ICONST_1 } IADD } INVOKEVIRTUAL

  6. source code byte code package pkg; class Bar { int foo ( int i ) { ILOAD_1 return foo ( i + 1 ); ICONST_1 } IADD } INVOKEVIRTUAL pkg/Bar foo (I)I

  7. source code byte code package pkg; class Bar { int foo ( int i ) { ILOAD_1 return foo ( i + 1 ); ICONST_1 } IADD } INVOKEVIRTUAL pkg/Bar foo (I)I 1 : i 0 : this local variable array

  8. source code byte code package pkg; class Bar { int foo ( int i ) { ILOAD_1 return foo ( i + 1 ); ICONST_1 } IADD } INVOKEVIRTUAL pkg/Bar foo (I)I 1 : i 0 : this local variable array

  9. source code byte code package pkg; class Bar { ALOAD_0 int foo ( int i ) { ILOAD_1 return foo ( i + 1 ); ICONST_1 } IADD } INVOKEVIRTUAL pkg/Bar foo (I)I 1 : i 0 : this local variable array

  10. source code byte code package pkg; class Bar { ALOAD_0 int foo ( int i ) { ILOAD_1 return foo ( i + 1 ); ICONST_1 } IADD } INVOKEVIRTUAL pkg/Bar foo (I)I IRETURN 1 : i 0 : this local variable array

  11. source code byte code package pkg; class Bar { ALOAD_0 int foo ( int i ) { ILOAD_1 return foo ( i + 1 ); ICONST_1 } IADD } INVOKEVIRTUAL pkg/Bar foo (I)I IRETURN operand stack 1 : i 0 : this local variable array

  12. source code byte code package pkg; class Bar { ALOAD_0 int foo ( int i ) { ILOAD_1 return foo ( i + 1 ); ICONST_1 } IADD } INVOKEVIRTUAL pkg/Bar foo (I)I IRETURN this operand stack 1 : i 0 : this local variable array

  13. source code byte code package pkg; class Bar { ALOAD_0 int foo ( int i ) { ILOAD_1 return foo ( i + 1 ); ICONST_1 } IADD } INVOKEVIRTUAL pkg/Bar foo (I)I IRETURN i this operand stack 1 : i 0 : this local variable array

  14. source code byte code package pkg; class Bar { ALOAD_0 int foo ( int i ) { ILOAD_1 return foo ( i + 1 ); ICONST_1 } IADD } INVOKEVIRTUAL pkg/Bar foo (I)I IRETURN 1 i this operand stack 1 : i 0 : this local variable array

  15. source code byte code package pkg; class Bar { ALOAD_0 int foo ( int i ) { ILOAD_1 return foo ( i + 1 ); ICONST_1 } IADD } INVOKEVIRTUAL pkg/Bar foo (I)I IRETURN i + 1 this operand stack 1 : i 0 : this local variable array

  16. source code byte code package pkg; class Bar { ALOAD_0 int foo ( int i ) { ILOAD_1 return foo ( i + 1 ); ICONST_1 } IADD } INVOKEVIRTUAL pkg/Bar foo (I)I IRETURN foo(i + 1) operand stack 1 : i 0 : this local variable array

  17. source code byte code package pkg; class Bar { ALOAD_0 int foo ( int i ) { ILOAD_1 return foo ( i + 1 ); ICONST_1 } IADD } INVOKEVIRTUAL pkg/Bar foo (I)I IRETURN operand stack 1 : i 0 : this local variable array

  18. source code byte code package pkg; class Bar { 0x2A int foo ( int i ) { 0x1B return foo ( i + 1 ); 0x04 } 0x60 } INVOKEVIRTUAL pkg/Bar foo (I)I 0xAC operand stack 1 : i 0 : this local variable array

  19. source code byte code package pkg; class Bar { 0x2A int foo ( int i ) { 0x1B return foo ( i + 1 ); 0x04 } 0x60 } 0xB6 pkg/Bar foo (I)I 0xAC operand stack 1 : i 0 : this local variable array

  20. source code byte code package pkg; class Bar { 0x2A int foo ( int i ) { 0x1B return foo ( i + 1 ); 0x04 } 0x60 } 0xB6 0x0002 0x0000 0x0001 0xAC constant pool operand stack 1 : i 0 : this local variable array

  21. INVOKESTATIC pkg/Bar foo ()V Invokes a static method.

  22. INVOKESTATIC pkg/Bar foo ()V Invokes a static method. INVOKEVIRTUAL pkg/Bar foo ()V Invokes the most-specific version of an inherited method on a non-interface class.

  23. INVOKESTATIC pkg/Bar foo ()V Invokes a static method. INVOKEVIRTUAL pkg/Bar foo ()V Invokes the most-specific version of an inherited method on a non-interface class. INVOKESPECIAL pkg/Bar foo ()V Invokes a super class‘s version of an inherited method. Invokes a “constructor method”. Invokes a private method. Invokes an interface default method (Java 8).

  24. INVOKESTATIC pkg/Bar foo ()V Invokes a static method. INVOKEVIRTUAL pkg/Bar foo ()V Invokes the most-specific version of an inherited method on a non-interface class. INVOKESPECIAL pkg/Bar foo ()V Invokes a super class‘s version of an inherited method. Invokes a “constructor method”. Invokes a private method. Invokes an interface default method (Java 8). INVOKEINTERFACE pkg/Bar foo ()V Invokes an interface method. (Similar to INVOKEVIRTUAL but without virtual method table index optimization.)

  25. INVOKESTATIC pkg/Bar foo ()V Invokes a static method. INVOKEVIRTUAL pkg/Bar foo ()V Invokes the most-specific version of an inherited method on a non-interface class. INVOKESPECIAL pkg/Bar foo ()V Invokes a super class‘s version of an inherited method. Invokes a “constructor method”. Invokes a private method. Invokes an interface default method (Java 8). INVOKEINTERFACE pkg/Bar foo ()V Invokes an interface method. (Similar to INVOKEVIRTUAL but without virtual method table index optimization.) INVOKEDYNAMIC foo ()V bootstrap Queries the given bootstrap method for locating a method implementation at runtime. ( MethodHandle : Combines a specific method and an INVOKE* instruction.)

  26. INVOKESTATIC pkg/Bar foo ()V Invokes a static method. INVOKEVIRTUAL pkg/Bar foo ()V Invokes the most-specific version of an inherited method on a non-interface class. INVOKESPECIAL pkg/Bar foo ()V Invokes a super class‘s version of an inherited method. Invokes a “constructor method”. Invokes a private method. Invokes an interface default method (Java 8). INVOKEINTERFACE pkg/Bar foo ()V Invokes an interface method. (Similar to INVOKEVIRTUAL but without virtual method table index optimization.) INVOKEDYNAMIC foo ()V bootstrap Queries the given bootstrap method for locating a method implementation at runtime. ( MethodHandle : Combines a specific method and an INVOKE* instruction.)

  27. void foo () { ??? (); // invokedynamic } foo() ?

  28. void foo () { ??? (); // invokedynamic } foo() ? bootstrap()

  29. void foo () { ??? (); // invokedynamic } foo() bar() ? bootstrap()

  30. void foo () { bar (); } foo() bar() ? bootstrap()

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend