Busy Java Developer's Guide to JVM Bytecode

ted@tedneward.com | Blog: http://blogs.tedneward.com | Twitter: tedneward | Github: tedneward | LinkedIn: tedneward

Objectives

JVM Bytecode

From the top

JVM Bytecode

From data to code

JVM Bytecode

JVM Bytecode Instruction Set

JVM Bytecode

Why use an intermediate language like this?

JVM Bytecode

JVM provides "managed environment"

JVM Bytecode

"So what? I know Java!"

Example1

public class Hello
{
  public static void main(String[] args)
  {
    System.out.println("Hello, Java bytecode!");
  }
}
Compiled from "Hello.java"
public class Hello extends java.lang.Object{
public Hello();
  Code:
   0:	aload_0
   1:	invokespecial	#1; //Method java/lang/Object."<init>":()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, Java bytecode!
   5:	invokevirtual	#4; //Method java/io/PrintStream.println:(Ljava/lang/String;)V
   8:	return

}

JVMIS Design Principles

What drives the look-and-feel of JVM bytecode

JVMIS Design Principles

Smallest atom of code: class

JVMIS Design Principles

Stack-based, no registers

JVMIS Design Principles

Names are fully-qualified class names

JVMIS Opcodes

Organized loosely by function

JVM Instruction Set

Stack manipulation

JVM Instruction Set

Arithmetic operations

JVM Instruction Set

Branching, control flow

JVM Instruction Set

Object model instructions

JVMIS Code Structure

Not necessarily opcodes

JVM Instruction Set

Exception Handling

Quiz Time!

Test what you've learned!

Question

"How are inner classes implemented?"

Question

"What's the cost of using assert?"

Question

"How are generics implemented (in 1.5)?"

Question

"Lambdas: How are they implemented (in 1.8)?"

Question

"Lambdas: How do they capture references (in 1.8)?"

Summary

JVMIS is good to know

Resources

Books

Credentials

Who is this guy?