Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've programmed in Java for about 8 years and I know the language quite well as a developer, but my goal is to deepen my knowledge of the internals. I've taken undergraduate courses in PL design, but they were very broad academic overviews (in Scheme, IIRC).

Can someone suggest a route to start delving into the details? Specifically, are there particular topics (say, garbage collection) that might be more approachable or be a good starting point? Is there a decent high-level book on the internals of the JVM and the design of the Java programming language? My current approach is going to be to start with the JVM spec and research as needed.

share|improve this question

closed as too broad by gnat, durron597, MichaelT, Ixrec, Yannis Jun 10 '15 at 11:11

There are either too many possible answers, or good answers would be too long for this format. Please add details to narrow the answer set or to isolate an issue that can be answered in a few paragraphs.If this question can be reworded to fit the rules in the help center, please edit the question.

My personal approach would be (and is) to find the real reason for all that little "why exactly does it work like this" cases in Java. How is auto-boxing defined, how do generic types work. What about var-args? What does the SUPER flag in the class files actually do? Most of that is described in the JVM spec itself, but it requires some work to get it out of there and into your brain ;-) – Joachim Sauer Jun 1 '12 at 12:05
up vote 13 down vote accepted

I did a bit of this when I started with Java, years ago. My approach was to read the VM spec, and to look at the output of javap -c, which displays the disassembled bytecode of a class. I also tried creating java classes with particular bytecode, using a java bytecode assembler. There is an assembler called jasmin, if you want to try that.

You might also want to look at the Lambda Expression Translation document that Brian Goetz of Oracle has posted, which covers the strategy that will be used to translate the lambdas (closures, essentially) that are being added in Java 8.

You can also get the source code for the Hotspot VM from OpenJDK, and the early access version of the javac compiler with lambda support (hg repository) for JDK 8, if you really feel like diving into the deep end of the pool.

Looking into garbage collection is probably a good idea. A quick search turned up this Dr. Dobbs article on Java's garbage-first GC. I don't know if that's a good introduction. I assume you already know about mark-and-sweep and generational garbage collectors; if not, you will want to read up on those first.

share|improve this answer

Some additional ideas:

  • Get involved in the OpenJDK project. Nothing beats understanding the internals of some software by hacking on it!
  • Look at how other JVM languages (e.g. Clojure or Scala) generate code for the JVM
  • Do a mini-project that interests you and requires use of JVM internals. Perhaps using something like ASM to manipulate bytecode..
share|improve this answer

If you are not familiar yet with the Java bytecode format, then consider writing a tiny compiler which creates valid Java byte code (or Jasmin assembler) and make it run correctly.

Seeing "Hello World" or "4" (given 2+2) generated by your code is very satisfying.

share|improve this answer

In addition to what everyone else have said, check out the Java Performance Tuning page. It contains a lot of articles on garbage collection and performance tuning in general. It also contains a list of performance tuning books that might be interesting for you as well.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.