Presentation is loading. Please wait.

Presentation is loading. Please wait.

RealTimeSystems Lab 2001.10.24 Jong-Koo, Lim

Similar presentations


Presentation on theme: "RealTimeSystems Lab 2001.10.24 Jong-Koo, Lim"— Presentation transcript:

1 RealTimeSystems Lab 2001.10.24 Jong-Koo, Lim unlimited@palgong.knu.ac.kr

2 RealTimeSystems Lab 2 Contents  Java Architecture  Java Programming Environment  What is ‘Java virtual machine’ ?  Architecture of Java virtual machine  ClassLoader Subsystem  Method Area  Heap  PC Register  Java Stacks  Native Method Stacks  Execution Engine  Next Works

3 RealTimeSystems Lab 3 Java Architecture  have Four Components(technologies)  Java programming language  Java class file  Java API  Java virtual machine

4 RealTimeSystems Lab 4 Java Programming Environment A.javaB.javaC.java Java compiler A.classB.classC.class Your program’s source files Your program’s class files Compile-time environment A.classB.classC.class Object.classString.class Your program’s class files Java API’s class files run-time environment Java Virtual Machine Your class files move locally or through a network Java Interpreter

5 RealTimeSystems Lab 5 What is ‘Java Virtual Machine’ …? H/W Platform & OS Java Virtual Machine Compiled Java Program ByteCode (class files) JVMJVMJVM Linux Win NT Mac  The abstract specification  A concrete implementation  A run-time instance

6 RealTimeSystems Lab 6 Basic Block diagram of JVM Your program’s class files Java API’s class files Host Operating System Class Loader Execution Engine ByteCodes Native method invocation Java Virtual Machine

7 RealTimeSystems Lab 7 Architecture of Java Virtual Machine Class Loader Subsystem Execution Engine Method Area Method Area heap Java Stacks PC Registers PC Registers Native Method Stacks Run-time Data Areas Native method Interface Native method Interface Native method library Class files

8 RealTimeSystems Lab 8 Class Loader Architecture User-defined class loader Objects on the heap part of the Java Virtual Machine implementation Bootstrap class loader Class Loader Subsystem part of the Java Application implementation

9 RealTimeSystems Lab 9 Loading, Linking, Initialization ( ⅰ ) Loading Linking Verification Preparation Resolution Initialization Class Loader Subsystem

10 RealTimeSystems Lab 10 Loading, Linking, Initialization ( ⅱ )  Loading  Finding the binary form of class or interface type  By reading from disk or over network  Linking : “ binary form → runtime state form”  Verification : ensuring the correctness of the imported type  Preparation : allocating memory for class variables  Resolution : symbolic reference → direct reference  Initialization  Invoking Java code that initializes class variables Class Loader Subsystem

11 RealTimeSystems Lab 11 Run-time Data Areas Object Heap Object Method Area Class data Stack frame thread 1 Stack frame thread 2 Stack frame thread 3 Java Stacks thread 1 thread 2 thread 3 Native Method Stacks This areas are shared among all threadsThis areas are exclusive among all threads PC Registers

12 RealTimeSystems Lab 12 Method Area ( ⅰ )  is analogous to the storage area for compiled code such as ‘data section’ in UNIX process  ‘type information’ + ‘additional information’  Type information  fully qualified name of the type (ex : java.lang.object)  fully qualified name of the type’s direct superclass  which or not the type is a class or an interface  type’s modifiers (public, abstract, or final)  ordered list of the fully qualified names of any direct superinterfaces

13 RealTimeSystems Lab 13  Additional information  Constant Pool : an ordered set of constants used by the type  Field information : field’s name, field’s type, field’s modifiers  Method information : method’s name, method’s return type, method’s modifier, the number and type of the method’s parameters  Class variables  Reference to class ClassLoader  Reference to class Class Method Area ( ⅱ )

14 RealTimeSystems Lab 14 An Example of Method Area Use class Tico { private int speed = 5; void drive() { } class Car { public static void main(String[] args) { Tico tico = new Tico(); tico.drive(); } } ※ Sequence  to run ‘Car’ application,  give ‘Car’ to JVM  JVM finds and reads ‘Car.class’  extract the definition of class ‘Car’ from the binary data  places the information into the method area  JVM invokes the main() method by interpreting the bytecodes stored in the method area Method Area

15 RealTimeSystems Lab 15 Heap  A Java application runs inside its own exclusive JVM instance.  There is only one heap inside a JVM instance  Whenever new object [class instance] is create in a running Java application, the memory for the new object is allocated from a single heap.  All threads in a Java application share the heap  JVM itself is responsible for deciding whether and when to free memory occupied by objects that are no longer referenced by the running application.  It is known as “garbage collection”

16 RealTimeSystems Lab 16 PC (Program Counter) Register  Each thread of a running program has its own PC register  PC register is created when the thread is started  One word in size  Hold both a ‘ native pointer’ and a ‘ returnAddress’  native pointer : the instruction currently being executed  returnAddress : the address of JVM instruction currently being executed  As a thread executes a Java method, PC register contains the instruction currently being executed by the thread  If a thread is executing a native method, the value of PC register is undefined.

17 RealTimeSystems Lab 17 Java Stack  When a new thread is launched, the JVM creates a new Java stack for the thread  When a thread invokes a Java method, the JVM creates and pushes a new stack frame onto the thread’s Java stack  It holds parameter, local variables, intermediate computations, and other data  Exceptional conditions  StackOverflowError  OutOfMemoryError

18 RealTimeSystems Lab 18 Stack frame  has three parts  Local variables section : method’s parameter and local variables  Type int, float, reference, and returnAddress occupy one entry  Type long and double occupy two consecutive entries  Type byte, short, and char are converted to int before being stroed in the local variables  Operand stack : An array of words  JVM use the operand stack as a work space  Frame data  Includes data to support constant pool resolution, normal method return, and exception dispatch Java Stack

19 Method parameters on the local variables section public static int runClassMethod (int i, long l, float f, double d, Object o, byte b) { return 0; } public int runInstanceMethod (char c, double d, short s, boolean b) { return 0; } int long float double reference int Int i long l float f double d Object o byte b 0 1 3 4 6 7 runClassMethod() indextypeparameter int double reference int char c short s double d hidden this boolean b 0 1 2 4 5 runInstanceMethod() indextypeparameter int Java Stack

20 RealTimeSystems Lab 20 Adding two local variables iload_0 // push the int in local variable 0 iload_1// push the int in local variable 1 iadd// pop two ints, add them, push result istore_2// pop int, store into local variable 2 100 98 0 1 2 before local variables starting Operand stack 100 98 100 98 100 98 100 98 198 100 98 198 after iload_0 after iload_1 after iadd after istore_2 Java Stack

21 RealTimeSystems Lab 21 Implementation of the Java Stack ( ⅰ ) Java Stack Class Example { public static void addAndPrint() { double result = addTwoTypes(1, 22.22); System.out.println(result); } public static double addTwoTypes (int i, double d) { return i + d; } Example Source

22 Implementation of the Java Stack ( ⅱ ) Java Stack Separate-frames approach 1 22.22 Before invocation of addTwoTypes() local variables frame data operand stack 22 After invocation of addTwoTypes() 1 22.22 23.22 0 1 0 1 0 1 0 1 After addTwoTypes() returns Frame for addAndPrint() Frame for addTwoTypes()

23 Implementation of the Java Stack ( ⅲ ) Java Stack Overlapping-frames approach 1 22.22 Before invocation of addTwoTypes() local variables frame data operand stack 23 After invocation of addTwoTypes() 1 22.22 23.22 0 1 0 1 0 1 0 1 After addTwoTypes() returns Frame for addAndPrint() Frame for addTwoTypes()

24 RealTimeSystems Lab 24 Native Method Stacks Stack frame this Java method invokes a native method the current frame Java stacks native method stack this C function invokes another C function this C function invokes another a Java method

25 RealTimeSystems Lab 25 Execution Engine ( ⅰ )  Three sense  Abstract specification  Behavior of execution engine  Concrete implementation  Software or hardware  Run-time instance  Thread  In JVM Spec,  Execution engine is defined in terms of an instruction set  describes in detail what an implementation should do  however, say little about how

26 RealTimeSystems Lab 26 Execution Engine ( ⅱ ) class Act { public static void doMathForever() { int i = 0; for ( ; ; ) { i += 1; i *= 2; } } // Bytecode Stream : 03 3b 84 00 01 1a 05 68 3b a7 ff f9 // Disassembly : // Method void doMathForever() 0125678901256789 iconst_0// 03 istore_0// 3b iinc 0, 1// 84 00 01 iload_0// 1a iconst_2// 05 imul// 68 istore_0// 3b goto 2// a7 ff f9 Offset of instruction from beginning of method Instruction mnemonics and any operands comment

27 RealTimeSystems Lab 27 Next Works  Study on ‘inside JVM’ : continue…  Java Class File, Linking Model  Garbage Collection, Exception Handling  Thread Synchronization  RT-Java Spec  Which of JVM Source ‘CDC(CVM)’ or ‘CLDC(KVM)’  Analysis of JVM Source Code  Implementation of RT-JVM


Download ppt "RealTimeSystems Lab 2001.10.24 Jong-Koo, Lim"

Similar presentations


Ads by Google