Presentation is loading. Please wait.

Presentation is loading. Please wait.

Oop JVM in Context. oop What’s a JVM uPlatform-independent execution environment lA different JVM is required for each operating system lAny JVM can run.

Similar presentations


Presentation on theme: "Oop JVM in Context. oop What’s a JVM uPlatform-independent execution environment lA different JVM is required for each operating system lAny JVM can run."— Presentation transcript:

1 oop JVM in Context

2 oop What’s a JVM uPlatform-independent execution environment lA different JVM is required for each operating system lAny JVM can run the same version of a Java program uConverts Java bytecode into machine language and executes it.

3 oop Platform independence uPrograms can run without change on any networked computer lSimple administration uPrograms can run on embedded devices lPrinters, scanners… uNetworks as homogeneous execution environments lEnables building distributed systems uReduce time and cost of development uMore potential customers

4 oop JVM in Java Architecture uJava’s architecture main technologies: lThe Java programming language Source files lThe Java class file format Compiled files lThe Java API Provide access to system resources lThe Java virtual machine Runs the class files

5 oop The Java Programming Environment Compile time environmentrun time environment A.Java B.Java C.Java Java Compiler A.class B.class C.class A.class B.class C.class Java Virtual Machine Object class String class

6 oop Same Program, Different Platforms Java Program Java Platform for Linux Java Platform for Linux Linux Box Java Program Java Platform for Win32 Java Platform for Win32 PC running Windows XP Java Program Java Platform for your Television Java Platform for your Television Your Television Java Program Java Platform for your Toaster Java Platform for your Toaster Your Toaster

7 oop The JVM Roles uLoad class files lBoth program and API files lOnly files from API that are actually needed by the program are loaded uExecute bytecode lInterpretation – one method bytecode at a time lJust in time compiler – compiles bytecodes of a method to native machine code the first time the method is invoked, cache the native code. lAdaptive optimizer – identifies the most heavily used areas, compile them to native code.

8 oop Basic JVM Components The Java Virtual Machine Class loader Execution engine Host operating system Program Class files The Java API’s class files Native methods invocation

9 oop The Java Class File uThe binary form for Java programs uRepresents a complete description of one Java class or interface uPlatform independent – bytecodes are the machine language of the JVM uNot necessarily linked to the java language: Compiler Program in Java Lang. Program in Java Lang. Program in other Lang. Program in other Lang. Program in Java Lang. Program in Java Lang. Java class files Java class files Other Binary format Other Binary format

10 oop The Java API uSet of runtime libraries uProvide access to system resources of the host computer uA required component of any implementation of the Java platform Java Program Java Methods (Java API) Native methods (dynamic libraries) Host operating system

11 oop JVM Major Subsystems and Memory Areas.

12 oop The Class Loader Subsystem uThe class loader performs three main functions of JVM, namely: loading, linking and initialization. uThe linking process consists of three sub-tasks, namely, verification, preparation, and resolution, as shown by the following figure. uThese activities are performed in a strict order as shown by the figure.

13 oop Class Loading uLoading means reading the class file for a type, parsing it to get its information, and storing the information in the method area. uFor each type, the JVM stores reflection information and bytecodes in the method area.

14 oop Linking : Verification uEnsuring that binary representation of a class is structurally correct. uChecks that each instruction will find a correctly formed stack and local variable array lchecks that the items on top of the stack, and in the local variables, are of the correct type for the instruction uNone of the following are allowed: lType errors lOperand stack overflow or underflow lAccess control violations (e.g., private fields and methods) lReading of uninitialized variables lUse of uninitialized objects lWild jumps

15 oop Preparation uAllocating memory for the class (i.e static) variables and sets them to default initial values. uClass variables are not initialized to their proper initial values until the initialization phase - no java code is executed until initialization. uThe default values for the various types are shown below:

16 oop Resolution uReplacing symbolic names for types, fields and methods used by a loaded type with their actual references. uSymbolic references are resolved into direct references by searching through the method area to locate the referenced entity.

17 oop Class Initialization uSetting class variables to their proper initial values - initial values desired by the programmer. uInitialization of a class consists of two steps: lInitializing its direct superclass (if any and if not already initialized) lExecuting its own initialization statements uThe above imply that, the first class that gets initialized is Object.

18 oop JVM Memory Areas uEach instance of the JVM has one method area, one heap, and one or more stacks - one for each thread. uWhen JVM loads a class file, it puts its information in the method area. uAs the program runs, all objects instantiated are stored in the heap. uThe stack area is used to store activation records as a program runs.

19 oop The Method Area uInformation about types lName, super class, modifiers… uConstant pool lConstants used by the type uFields and methods information uClass (static) variables uSize is not fixed uCan be garbage collected lUnreferenced classes can be unloaded

20 oop JVM Stack vs. Heap uJava stack lUsed for method activation frames lOne for each thread lNo restrictions in its layout lChecked for overflow uJava native stacks lNative methods are used like other JVM methods, except they are implemented in some other language (e.g. C) lCan be used for things that cannot be handled well in Java, e.g., integrating legacy code written in other languages lNative stacks are used to keep track of state of native methods lBehave like the stack in C uJava heap lUsed for allocating objects lManaged by a garbage collector lEach object is associated with a class stored in the method area

21 oop Activation Frames uOne is pushed on the Java stack for each method invocation uThe frame is popped when the invocation finishes uA frame contains lLocal variables array Organized as an array Contains method’s parameters and local variables Size is determined at compile-time lAn operand stack Used for passing method arguments and results Only the top (few) words are accessed by any instruction Size is determined at compile-time

22 oop Architectural Tradeoffs uProgram execution performance lInterpreted languages are slower than running compiled native code lJIT improves performance uMemory management control lGarbage collection improve robustness but adds a level of uncertainty to performance uPlatform independence lSupports only the “lowest common denominator” capabilities


Download ppt "Oop JVM in Context. oop What’s a JVM uPlatform-independent execution environment lA different JVM is required for each operating system lAny JVM can run."

Similar presentations


Ads by Google