So you want to read HotSpot source?

I joined Sun Microsystems as a sustaining engineer - so I had to read code more often than writing new code (which is true in general for many of us!). I like to read great source code and learn from it. Sun's HotSpot Virtual Machine is one such gold mine!

May be, you've already downloaded the source bundles from http://jdk6.dev.java.net. Or you may be waiting for the "open source" announcement. In any case, if you are planning to read HotSpot source, you may want to know the prerequisites for reading HotSpot Java Virtual Machine sources. If so, read ahead ...

  1. Knowlegdge of C and C++ - You need not know each and every corner of C++ (for example it is okay to not know what explicit or mutable means nor you need to know "partial specialization of templates" etc.) - a decent level of understanding is enough :-)
  2. Knowledge of assembly language (of SPARC or X86 or AMD64) - no assembler is used. In fact, assembler is actually a C++ class - but you need assembler level understanding.
  3. Knowledge of Java

In addition to programming/assembly language(s), you may want to read the Java Virtual Machine Specification (2'nd Edition). To understand Java Virtual Machine Specification, I've used Java assembler(s) - working at the level of Java bytecode helps a lot. I used Jasmin Assembler.

You may also use a byte code engineering libraries such as

In addition, it is better to view/analyze existing .class files [may be, you compiled your .java files to create those files]. For that purpose, you can use .class viewers such as

  • javap - The java Class File Disassembler - use javap -c -p your_class. Output of javap -c on a simple Hello class looks as follows:
    
    Compiled from "Hello.java"
    class Hello extends java.lang.Object{
    Hello();
      Code:
       0:   aload_0
       1:   invokespecial   #1; //Method java/lang/Object."":()V
       4:   return
    
    public static void main(java.lang.String[]);
      Code:
       0:   getstatic       #2; //Field java/lang/System.out:Ljava/io/PrintStream;
       3:   ldc     #3; //String hello, world
       5:   invokevirtual   #4; //Method java/io/PrintStream.println:(Ljava/lang/String;)V
       8:   return
    
    }
    
    
  • jclasslib - bytecode viewer is a tool that visualizes all aspects of compiled Java class files.

I like to generate hypertext for source base and browse it. Tools that I used (and still use!) are:
Comments:

Hi, I have a small question. Can you explain to me what is involved in reading driver code. I have just instaled Nexenta andI would like to see how I can add Bluetooth support(if I have time). Have you done it before?

Posted by Vasileios Anagnostopoulos on October 25, 2006 at 05:33 AM IST #

I don't understand the context! I'm blogging about Sun's HotSpot Java Virtual Machine source - are you talking about some other HotSpot??

Posted by A. Sundararajan on October 25, 2006 at 05:50 AM IST #

No I just ask if reading hotSpot source is more difficult than reading driver source in Solaris. Thanks.

Posted by Vasileios Anagnostopoulos on October 25, 2006 at 08:24 AM IST #

Hi Sundarajan! This was rather useful..I was puzzled wondering which assembler was used. And please dont stop at this! :-). Currently, there look to be no docs whatsoever on the Hotspot source code..so do post your tips regularly for lesser mortals. :-) Thanks, Tarun

Posted by Tarun on October 25, 2006 at 08:55 AM IST #

Hi Vasileios Anagnostopoulos: HotSpot source is definitely "complex" - but, I am not sure I can compare the difficulty with device drivers or other parts of Solaris code (I don't know much about Solaris code). For Solaris, there is Solaris Internals book.

Hi Tarun: As I mentioned, there is no assembler. Assembler in HotSpot source is a C++ class. On continuing the "tips": I am not an expert in HotSpot! But, I do plan to post "random stuff" about HotSpot in future. So, stay tuned :-)

Posted by A. Sundararajan on October 25, 2006 at 11:37 AM IST #

Post a Comment:
Comments are closed for this entry.
About

sundararajan

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today
Bookmarks
Links

No bookmarks in folder

Blogroll

No bookmarks in folder

News

No bookmarks in folder