Data and value types

The JVM specification considers two data types and associated value types:

  • Primitive types are stored on the stack.
  • Reference types are stored on the heap and references are stored in the stack.

The JVM assumes that type checking has taken place in the compiler and does not need to be performed at run-time. The JVM instruction set differentiates between operand types using instructions specific to their types.

Primitive

Primitive types are either numeric, boolean, or returnAddress.

Numeric

Integral:

  • byte (27-2^7 to 2712^7-1)
  • short (215-2^15 to 2512^5-1)
  • int (231-2^31 to 23112^31-1)
  • long (264-2^64 to 26312^63-1)
  • char (0 to 21612^16-1)

Floating-point:

  • float (IEEE 754 binary32)
  • double (IEEE 754 binary64)

Not-a-Number values are represented as either Float.NaN or Double.NaN.

boolean

Stores values true and false, introduced in the second edition. No instructions dedicated to boolean values, and instead are treated internally as ints. Boolean arrays can be created with newarray and modified using the byte array instructions baload and bastore.

returnAddress

pointers to opcodes of JVM instructions; doesn't correspond to a Java programming language type and isn't modifiable by the running program.

Used by the jsr, ret, and jsr_w instructions.

Reference

Reference types are class, array, and interface types.

class

Class types are created with the new instruction.

interface

Interface methods are invoked using the invokeinterface instruction.

array

Comprises:

  • Component, which may itself be another array type, but eventually must be a non-array (primitive, class or interface) type known as the element type.
  • Dimension (depth)

null

A reference to no object. Has no run-time type, but may be cast to any type.

References