17 Modern internals

 

This chapter covers

  • Introducing JVM internals
  • Reflection internals
  • Method handles
  • Invokedynamic
  • Recent internal changes
  • Unsafe

Java’s virtual machine (JVM) is an extremely sophisticated runtime environment that has, for decades, prioritized stability and production-grade engineering. For these reasons, many Java developers have never needed to poke about in the internals, because it is simply not necessary to do so most of the time.

This chapter, on the other hand, is for the curious—the people who would like to know more, who would like to draw back the curtain and see some of the details of how the JVM is implemented. Let’s start with method invocation.

17.1 Introducing JVM internals: Method invocation

To get going, let’s look at a simple example, defined by the classes Pet, Cat, and Bear and the interface Furry. This can be seen in figure 17.1

Figure 17.1 Simple inheritance hierarchy

We might also suppose that other subclasses of Pet exist (e.g., Dog and Fish) that aren’t shown in the diagram to keep things clear. We’ll use this example to explain in detail how the different invoke opcodes work, starting with invokevirtual.

17.1.1 Invoking virtual methods

17.1.2 Invoking interface methods

17.1.3 Invoking “special” methods

17.1.4 Final methods

17.2 Reflection internals

17.3 Method handles

17.3.1 MethodHandle

sitemap