January 15, 2016

What are important components of JVM?

Answer: The important components are:

  1. a) Class loader subsystem – provides the loading mechanism for types (class, interfaces) in java.
  2. b) Runtime data areas: constitute of
  • 1) Method Area
  • 2) Heap
  • 3) java stacks
  • 4) program counter (registers)
  • 5) Native method stacks
  • these areas provides memory to store byte-codes , object created, method parameters, return values ,local variables and intermediate result of computations

    1. c) Execution engine: It helps to execute the instruction contained in methods of loaded classes.

     

    Method area: It holds the information about loaded types. For each type it loads, a Java virtual machine must store the following kinds of information in the method area: type’s means classes and interfaces.

    1) The fully qualified name of the type

    2) The fully qualified name of the type’s direct superclass (unless the type is an interface or class java.lang.Object, neither of which have a superclass)

    3) Whether or not the type is a class or an interface

    4) The type’s modifiers ( some subset of` public, abstract, final)An ordered list of the fully qualified names of any direct superinterfaces

     

    Note: All threads share the same method area, so access to the method area’s data structures designed to be thread-safe. If two threads are attempting to find a class named Abc, for example, and Abc has not yet been loaded, only one thread should be allowed to load it while the other one waits.

     

    Heap: Whenever a class instance or array is created in a running Java application, the memory for the new object is allocated from a single heap. As there is only one heap inside a Java virtual machine instance, all threads share it.

     

    Java Stacks:

    1) When a new thread is launched, the Java virtual machine creates a new Java stack for the thread.

    2) A Java stack stores a thread’s state in discrete frames. The Java virtual machine only performs two operations directly on Java Stacks: it pushes and pops frames.

    3) As the method executes, it is used to store parameters, local variables, intermediate computations, and other data.

     

    Program counter:

    1) Each thread of a running program has its own program counter, which is created when the thread is started.

    2) The pc register is one word in size, so it can hold both a native pointer and a returnAddress.

    3) As a thread executes a Java method, the pc register contains the address of the current instruction being executed by the thread

     

    Native method stack:

    1) A running Java application may use other data areas created by or for native methods.

    2) When a thread invokes a native method, however, that thread leaves the Java stack behind. Instead of pushing a new frame onto the thread’s Java stack, the Java virtual machine will simply dynamically link to and directly invoke the native method.