Java Virtual Machine, Call stack, Java Byte Code

Embed Size (px)

DESCRIPTION

Java Virtual Machine의 내부 구조, method call stack, java byte code를 읽기 위해 opcode 이해를 다룬다.

Text of Java Virtual Machine, Call stack, Java Byte Code

  • 1. JVM Call Stack
  • 2. Java Virtual Machine
  • 3. JVM
  • 4. Java Virtual Machine Class Loader System Operating System Java Threads Execution Engine Run-time Data Area Garbage Collector Java Application Java API Native Method Libraries
  • 5. ByteCode Link Verify Prepare Class Load Class Loader Resolve Initialize ByteCode Class File Memory
  • 6. Java API Execution Class Loader Engine Java Class System Runtime Data Areas PC Registers JVM Stacks Files Native Method Libraries Method Area Heap Native Method Stacks JVM Class Loader Byte Code Runtime Data Areas Method Area Load.
  • 7. Execution Engine Class Loader System Operating System Java Threads Execution Engine Run-time Data Area Garbage Collector Java Application Java API Native Method Libraries
  • 8. Java API Execution Class Loader Engine Java Class System Runtime Data Areas PC Registers JVM Stacks Files Native Method Libraries Method Area Heap Native Method Stacks JVM Execution Engine Method Area Load Byte Code . Execution Engine ByteCode (interpreting ).
  • 9. Method Area Thread . Class(Type), Method, Field . .
  • 10. Method Area Thread . Method Area Type Information : Constant Pool : , Symbolic Reference Field Information : Field , Data Type, Modifier Method Information : Method , DataType, Modifier Class Variables : static Reference to Class Class Loader : Type Load ClassLoader Reference to Class class Method Table : Class Method Direct Reference .
  • 11. Java API Execution Class Loader Engine Java Class System Runtime Data Areas PC Registers JVM Stacks Files Native Method Libraries Method Area Heap Native Method Stacks Method Area Byte Code JVM Stacks, Native Method Stacks .
  • 12. JVM Stacks, Native Method Stacks Thread . Thread . Thread method .
  • 13. Java API Execution Class Loader Engine Java Class System Runtime Data Areas PC Registers JVM Stacks Files Native Method Libraries Method Area Heap Native Method Stacks JVM Heap Array .
  • 14. Method Area Thread A ( A) JVM Stacks main() Stack frame Operand Stack Local Variable 0 args constant pool JVM Stack . JVM Stack Stack Frame . JVM Stacks main() Stack frame Operand Stack Local Variable 0 args JVM Heap Thread B ( B)
  • 15. JVM Heap Method Area Thread . Method Area constant pool JVM Heap Thread A ( A) Thread B ( B)
  • 16. Method Area ByteCode . Thread JVM Heap . Method Area constant pool JVM Heap Thread A ( A) Thread B ( B)
  • 17. Heap Thread . JVM . JVM Memory , (Garbage Collection) Heap .
  • 18. package net.slipp; public class Adder { int add(int i, int j) { return i + j; } public static void main(String[] args) { Adder adder = new Adder(); int result = adder.add(5,2); System.out.println(result); } }
  • 19. package net.slipp; public class Adder { int add(int i, int j) { return i + j; } public static void main(String[] args) { Adder adder = new Adder(); int result = adder.add(5,2); System.out.println(result); } } JVM Stacks main() Stack frame Operand Stack Local Variable 0 args 1. main method stack frame
  • 20. package net.slipp; public class Adder { int add(int i, int j) { return i + j; } public static void main(String[] args) { Adder adder = new Adder(); int result = adder.add(5,2); System.out.println(result); } } JVM Stacks main() Stack frame Operand Stack Local Variable 0 args 1. main method stack frame 2. Adder stack frame Adder Stack frame Operand Stack Local Variable 0 this
  • 21. package net.slipp; public class Adder { int add(int i, int j) { return i + j; } public static void main(String[] args) { Adder adder = new Adder(); int result = adder.add(5,2); System.out.println(result); } } JVM Stacks main() Stack frame Operand Stack Local Variable 0 args 1. main method stack frame 2. Adder stack frame 3. Adder stack frame
  • 22. JVM Stacks main() Stack frame Operand Stack Local Variable 0 args package net.slipp; public class Adder { int add(int i, int j) { return i + j; } public static void main(String[] args) { Adder adder = new Adder(); int result = adder.add(5,2); System.out.println(result); } 1. main method stack frame 2. Adder stack frame 3. Adder stack frame 4. add method stack frame } add method Stack frame Operand Stack Local Variable 2 2 1 5 0 this
  • 23. JVM Stacks main() Stack frame Operand Stack Local Variable 0 args package net.slipp; public class Adder { int add(int i, int j) { return i + j; } public static void main(String[] args) { Adder adder = new Adder(); int result = adder.add(5,2); System.out.println(result); } 1. main method stack frame 2. Adder stack frame 3. Adder stack frame 4. add method stack frame 5. add method stack frame }
  • 24. JVM Stacks package net.slipp; public class Adder { int add(int i, int j) { return i + j; } public static void main(String[] args) { Adder adder = new Adder(); int result = adder.add(5,2); System.out.println(result); } 1. main method stack frame 2. Adder stack frame 3. Adder stack frame 4. add method stack frame 5. add method stack frame 6. main method stack frame }
  • 25.
  • 26. Execution Engine .
  • 27. public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } javap c HelloWorld.class } D:next-workspaceworkspacejavabin>javap -c HelloWorld.class Compiled from "HelloWorld.java" public class HelloWorld { public HelloWorld(); Code: 0: aload_0 1: invokespecial #8 // Method java/lang/Object."":()V 4: return public static void main(java.lang.String[]); Code: 0: getstatic #16 // Field java/lang/System.out:Ljava/io/PrintStream; 3: ldc #22 // String Hello World! 5: invokevirtual #24 // Method java/io/PrintStream.println:(Ljava/lang/String