Posts

JVM Exceptional Conditions

1) When the Computation in Java Thread requires Larger stack size than what is permitted, then Java Virtual Machine throws StackOverFlorError. 2) At initial stage of creating stack for a new thread, if insufficient memory is available then JVM throws OutOfMemoryError. 3) If the thread stack allowd to dynamically expanded, and if the expansion is attemted at runtime, and if insufficient memory is avaiable for that expansion, then JVM throws OutOfMemoryError 4) If sufficient memory is not availabe while allocating memory for method area then it will throw OutOfMemoryError

Method Area

JVM has a method area, It is shared across all the Threas of the JVM. Method area stores compiled code. Method area is getting created at the JVM start time. Method ares stores class strucure -runtime constant pool -fields -method data -constructors etc The allocated memory for the method area is not required to be contiguous. This method area is either of fixed size or it can be enlarge as per the computation. The memory consumed by the method area is not garbage collected or it not be compacted after allocated. If required memory space is not available for method area then JVM will give your OutOfMemoryError.

Heap

JVM has a heap area, which is shared across all the JVM threads. Heap is used to dynamically allocate memory for the class objects and arrays. Memory allocated by the obejcts is reclaimed by the Garbage Collector. Garbage Collector technique is not fixex, It is getting decided based on the requirements of the System implemantation. The heap area can be of fixed size, or it can be enlarged based on the computation. The heap memory area is not required to be contiguous.  If required heap memory cannot be made available by the automatic storage management of JVM then JVM will give you OutOfMemoryError.

Operand Stacks

Each frame has its LIFO stack, it is called operand stack. The size of operand stack is determined at the compile time. Some JVM instructions loads values into operand stack from local variables or fields. Some JVM instructions takes operands from the operand stand, then it perform operation on them and push the result value back on the operand stack.

Frames Local Variable

Each frame has the array of local variables. The size of local variables array is determined at the compile time, and it passed in the bytcode for that class. Local variables are used by index. First local variable is store at 0th index. Second local raviable is store at 1st index and so on. long and double type local variables occupies two consecutive local variables in the Local Array, But the value for that long or double variable will be indexed using the lesser index. 

Frame

Frame is used to store local data, results. It is used to returned values for methods, and dispatch the excaptions.  Whenever a method is called or invoked a new Frame is created. Whenever a method execution is over normal or execeptional then the frame is destroyed. Each frame has followings 1) Array of Local variables 2) Stack of Operand 3) A reference to the class of the current called method. At a time only one frame is having in the active state, for the called method, in the current thread stack. That frame is known as a current frame and the method is known as a current method. The class in which the current method is there is called the current class. A frame for one thread is local for that thread only, it cannot be referenced by other thread. 

Java Virtual Machine Stacks

Each Thread in a JVM has a private Stack allocated, It is called Java Virtual Machine stack for that Thread. Here, each stack stores Frames(read topic Frames for understanding) Stack holds local variables, partial results, and it involves in calling a Method. Stack never altered directly, but it manipulated by pop and push operations. Memory allocated for the Stack is not required to be contiguous. Stack size can be fixed or it can be allocated dynamically.