Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.



Published on

Published in: Education, Technology
  • Be the first to comment


  1. 1. By,PRITY KUMARI205111037NIT-Trichy(MCA)
  2. 2.  JVM is an interpreter for bytecode. JVM needs to be implemented on eachplatform. Enhance portability. Assure security. Encourage Fast execution of the program. Def : JVM is a component of the Java systemthat interprets and executes the instructions inour class files.
  3. 3.  Compiled code to be executed by the JavaVirtual Machine is represented using ahardware- and operating system-independentbinary format, typically (but not necessarily)stored in a file, known as the class file format. The class file format precisely defines therepresentation of a class or interface, includingdetails such as byte ordering that might betaken for granted in a platform-specific objectfile format.
  4. 4.  Like the Java programming language, the JavaVirtual Machine operates on two kinds of types:primitive types and reference types. There are, correspondingly, two kinds of valuesthat can be stored in variables, passed asarguments, returned by methods, and operatedupon: primitive values and reference values. The instruction set of the Java Virtual Machinedistinguishes its operand types using instructionsintended to operate on values of specific types. For instance, iadd, ladd, fadd, and dadd
  5. 5.  numeric types, the boolean type returnAddress type1)Numeric typesThe integral types are: Byte(8-bit signed twos-complement integers) Short (16-bit signed twos-complement integers) Int(32-bit signed twos-complement integers) Long(64-bit signed twos-complement integers) Char(16-bit unsigned )and default value is the nullcode point (u0000)
  6. 6. 2) Floating-point: float, whose values are elements of the float value setand whose default value is positive zero double, whose values are elements of the double valueand whose default value is positive zero3)Boolean-type: encode the truth values true and false, and the defaultvalue is false.4)returnAddress Type: The values of the returnAddress type are pointers tothe opcodes of Java Virtual Machine instructions. Of the primitive types, only the returnAddress type isnot directly associated with a Java programminglanguage type.
  7. 7.  There are three kinds of reference types:class typesarray typesinterface types. Their values are references to dynamically createdclass instances, arrays, or class instances or arraysthat implement interfaces, respectively. A reference value may also be the special nullreference, a reference to no object, which will bedenoted here by null The Java Virtual Machine specification does notmandate a concrete value encoding null.
  8. 8. FIG: Memory Configuration of JVM
  9. 9. The JVM defines various run-time data areas thatare used during execution of a program. Someof these data areas are created on JVM start-upand are destroyed only when the Java VirtualMachine exits.Other data areas are per thread. Per-thread dataareas are created when a thread is created anddestroyed when the thread exits.
  10. 10. 1)The pc Register: The JVM can support many threads of execution at once Each Java Virtual Machine thread has its own pc (programcounter) register.2) JVM Stacks: Each JVM thread has a private JVM stack, created at the sametime as the thread. It holds local variables and partial results, and plays a part inmethod invocation and return. Because the JVM stack is never manipulated directly except topush and pop frames, frames may be heap allocated. The memory for a JVM stack does not need to be contiguous. Throws two exceptions- OutOfMemoryError.- StackOverflowError.
  11. 11. 3) Heap The JVM has a heap that is shared among all Java VirtualMachine threads. The heap is the run-time data area from which memory forall class instances and arrays is allocated. The heap is created on virtual machine start-up. Throws one exception- OutOfMemoryError4) Method Area The method area is analogous to the storage area forcompiled code of a conventional language or analogous tothe "text" segment in an operating system process. It stores per-class structures such as the run-time constantpool, field and method data, and the code for methods andconstructors, including the special methods used in classand instance initialization and interface initialization. Throws one exception- OutOfMemoryError
  12. 12. 5) Run-Time Constant PoolIt contains several kinds of constants, ranging from numericliterals known at compile-time to method and field referencesthat must be resolved at run-time. The run-time constant pool serves a function similar to that of asymbol.6) Native Method Stacks An implementation of the Java Virtual Machine may useconventional stacks, called "C stacks," to support nativemethods Java Virtual Machine implementations that cannot load nativemethods and that do not themselves rely on conventionalstacks need not supply native method stacks. If supplied, native method stacks are typically allocated perthread when each thread is created.
  13. 13. Figure 2: Content of Memory Blocks at runtime.
  14. 14.  Loading means reading the class file for a type, parsing it to get itsinformation, and storing the information in the method area. For each type it loads, the JVM must store the following information in themethod area: The fully qualified name of the type Whether the type is a class or an interface The types modifiers ( public, abstract, final, etc) Method info: name, return type, number & types of parameters, modifiers,bytecodes, size of stack frame and exception table.
  15. 15. The end of the loading process is the creation of an instance ofjava.lang.Class for the loaded type.The purpose is to give access to some of the informationcaptured in the method area for the type, to the programmer.Some of the methods of the class java.lang.Class are:Note that for any loaded type T, only one instance of java.lang.Class iscreated even if T is used several times in an application.public String getName()public Class getSupClass()public boolean isInterface()public Class[] getInterfaces()public Method[] getMethods()public Fields[] getFields()public Constructor[] getConstructors()
  16. 16.  The next process handled by the class loader is Linking. Thisinvolves three sub-processes: Verification, Preparation andResolution Example of some of the things that are checked at verification are: Every method is provided with a structurally correct signature Every instruction obeys the type discipline of the Java language Every branch instruction branches to the start not middle ofanother instruction
  17. 17.  In this phase, the JVM allocates memory for the class (i.e static)variables and sets them to default initial values. Note that class variables are not initialized to their properinitial values until the initialization phase - no java code isexecuted until initialization. The default values for the various types are shown below:
  18. 18.  Resolution is the process of replacing symbolic namesfor types, fields and methods used by a loaded typewith their actual references. Symbolic references are resolved into a direct referencesby searching through the method area to locate thereferenced entity. For the class below, at the loading phase, the classloader would have loaded the classes: TestClassClass,String, System and Object. The names of these classes would have been stored inpublic class TestClassClass{public static void main(String[] args){String name = new String(“Ahmed”);Class nameClassInfo = name.getClass();System.out.println("Parent is: “ + nameClassInfo.getSuperclass());}}
  19. 19.  After a class is loaded, linked, and initialized, it isready for use. Its static fields and static methods can beused and it can be instantiated. When a new class instance is created, memory isallocated for all its instance variables in the heap. Memory is also allocated recursively for all the instancevariables declared in its super class and all classes up isinheritance hierarchy. All instance variables in the new object and those of itssuperclasses are then initialized to their default values. Finally, the reference to the newly created object isreturned as the result.
  20. 20. Rules for processing a constructor: Assign the arguments for the constructor to its parametervariables. If this constructor begins with an explicit invocation of anotherconstructor in the same class (using this), then evaluate thearguments and process that constructor invocation recursively. If this constructor is for a class other than Object, then it will beginwith an explicit or implicit invocation of a superclass constructor(using super). Evaluate the arguments and process thatsuperclass constructor invocation recursively. Initialize the instance variables for this class with their propervalues. Execute the rest of the body of this constructor.