Sundararajan's Weblog

  • Java
    October 24, 2006

So you want to read HotSpot source?

Guest Author

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{
    0: aload_0
    1: invokespecial #1; //Method java/lang/Object."":()V
    4: return
    public static void main(java.lang.String[]);
    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:

Join the discussion

Comments ( 5 )
  • Vasileios Anagnostopoulos Wednesday, October 25, 2006
    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?
  • A. Sundararajan Wednesday, October 25, 2006
    I don't understand the context! I'm blogging about Sun's HotSpot Java Virtual Machine source - are you talking about some other HotSpot??
  • Vasileios Anagnostopoulos Wednesday, October 25, 2006
    No I just ask if reading hotSpot source is more difficult than reading driver source in Solaris. Thanks.
  • Tarun Wednesday, October 25, 2006
    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. :-)
  • A. Sundararajan Wednesday, October 25, 2006

    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 :-)

Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.