Java_Magazine_NovemberDecember_2018

(singke) #1

56


//java future/


I


n this article, I’ll introduce value types, a potential future feature for the Java language and the
JVM. This change is so deep and far-reaching that it affects every aspect of the platform—
from performance to generics, even down to the fundamental way that Java represents data.
To understand what value types are, and how they’ll change the way you program, you need
to understand a bit about how Java represents data right now—as of Java 11. This will allow you
to put value types in context by seeing what this major change involves and the consequences
for how you might use Java in the future.

Current Types of Values
Since version 1.0 of the Java platform, the virtual machine has supported only two kinds of val-
ues: primitive types and object references. Primitive types (such as int and double) encode the
value that they represent directly as a bit pattern with no additional metadata. Object refer-
ences, on the other hand, are pointers that represent an address in the Java heap, which is an
area of memory that is solely managed by the virtual machine through garbage collection.
In other words, the Java environment deliberately does not provide full low-level control over
memory layout. In particular, this means that currently Java has no equivalent to C’s structs;
any composite data type can be defined and accessed only by the use of a reference.
Note that different Java implementations may have slightly different mechanisms and
representations of objects and their references. To keep things clear, I’ll talk only about the
representation used in the Java HotSpot VM implementation (that is, the virtual machine used
by Oracle’s JDK and OpenJDK).

Value Types Are Coming


to the JVM
How Project Valhalla will simplify access to many Java objects

PHOTOGRAPH BY JOHN BLYTHE

BEN E VA N S

Free download pdf