Valhalla and value types to change the way developers code in Java

In 2014, just as Java 8 was released, JavaOne was looking towards the future and talking about what was coming with Java 9. In 2015, Java 9 is still in the future, but that hasn't stopped the architects at Oracle from prognosticating about what might get included in Java 10.

The JavaOne 2015 opening keynote highlighted many of Oracle's newer services from the developer's cloud to advances in the Java SE cloud service. Upcoming language and JDK changes expected in Java 9 were also explored by Chief Architect Mark Reinhold, with a strong focus on modularity to solve classpath problems and break down the monolithic JDK. But data and hardware experts will be most interested in the brief presentation midway through the talk by Java Language Architect Brian Goetz.

Targetting bare-metal

As Goetz pointed out, modern hardware is a moving target. Java was originally developed in the era of the single core processor, a time when sockets were few, data was small, and everything was an object. In those days, performance was easy to understand and fairly predictable. Today, hardware is sophisticated and high-tech. It is designed to provide far more resources than ever before to deliver the memory capacity and computing power required by today's data-rich applications.

What might have been great decisions about how Java handles memory layout in 1995 may not be optimal for today's hardware.

Java Language Architect Brian Goetz

At the same time, the underlying costs of accessing data have changed and the way Java leverages hardware hasn't quite caught up. Data requests that used to cost a few clock cycles to go from core to main memory can now take hundreds of cycles if the data needed isn't already cached. A modern core can also issue a higher number of instructions per cycle, increasing the total number of clock cycles even more. This increased complexity is starting to take a toll. Goetz hit the nail on the head, "What might have been great decisions about how Java handles memory layout in 1995 may not be optimal for today's hardware."

Forward towards Valhalla

To address this shortcoming, the open JDK community is taking a look at where the JVM meets the metal. One project in line for Java 10 and 11 is of special interest: Valhalla. Goetz gave a sneak peek at how this initiative may tip the scales in favor of better performance. The advanced JVM and language features addressed in this update will assume that there are times when a user really needs to access data—not objects.

There's already a well-known feature in the Java language that will be used to implement this concept: the value type. Instead of declaring a point as a class, developers will someday be able to declare it as a value class. Goetz described what this experience feels like from a programming perspective. "Visually, it will look like a class, but its behavior in the heap will be like a primitive. We refer to this capability as being able to code like a class and behave like an int!"

By stripping off the object identity, Valhalla is expected to provide a way to create denser, flatter data layout that is cache friendly and memory efficient. When headers are compressed and pointers are removed, the number of clock cycles required to fetch data would be minimized, providing substantial gains in speed. Locality and caching can also be improved with this simplified layout since the prefetcher can easily pull in the next chunk of data in the array.

Embracing the concept of pure data

The flexibility of object layout will still be useful in many situations. But, as Goetz suggested, "If there was a way to say to the system, 'I want to work with this data as pure data.' There might be a way for the system to reward us with a better layout." The rewards are on the way as Valhalla opens the door to this simpler alternative by enhancing functions that developers already use on a daily basis. The hardware requires it. Big data demands it. Java will provide it.

What changes do you hope to see in Java 9 and Java 10? Let us know.

Dig Deeper on Core Java APIs and programming techniques

App Architecture
Software Quality
Cloud Computing
Security
SearchAWS
Close