Sunday, January 07, 2007

JVM Internals – Part II (Space Organization)

(Click on the main title to go for Part I)

In my previous post, I forgot to write about JVM specification (mind it, it’s a specification, Sun implementation of this is HotSpot, there are many others). JVM specification is written by Tim and Frank (The JavaTM Virtual Machine Specification, this is a free download book written by them). This specification is basically written in three parts ...saying:

~ A set of instructions – Bytecode
~ A binary format – Class file format
~ An algorithm for identifying programs that can’t compromise the integrity of the JVM – verification.


Yes, so coming to the point. JVM is divided into 4 conceptual data spaces:

# Class Area – where the code and constants are kept
# Heap – home for object
# Java Stack – keep tracks on method invocation and data associated with that
# Native Method Stacks – Something to do with native method

Lets take an example … where is our lovely class Foo :)

Class Foo {

public static void main(String[] args)
{
System.out.println(“Hello World(s)”);
}
}

So tell me how many object we have?

We have 3 objects: args, out and Hello World(s). All goes into Heap.

Class Area:

Class: Foo
Method: main ( actually we have main method descriptor here)

Java Stack:

It has stack handling the push and pop of local variables like Hello World(s), out and args.

Native Method Stack: I am relaxing :)

Stack going up and down is a bogus story.

So, I am directly moving on Garbage Collector >>>

2 comments:

Bipin "3~" Upadhyay said...

Hi Bhaiya,
So by Local variables we mean all the static members (blocks, variables, methods) go to the Java Stack.
Am I getting it right?

One more thing, where is the track of the methods being executed maintained? [I am referring to the stack based execution of a Java program].

Waiting for other posts bhaiya.

Bipin.

Vaibhav Choudhary said...

yes bipin, you are getting it correct ! track of method is done by two things :

. for java method its the java stack

. for C++ method(function) its the native stake.


Ya I will try to do some post, but :(