BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News JavaOne 2015 Keynotes (Part 2)

JavaOne 2015 Keynotes (Part 2)

During the JavaOne 2015 keynote, Oracle Java Platform leads Georges Saab, Mark Reinhold, Brian Goetz, among many others, talked about the 20 year journey of Java. InfoQ covered Reinhold’s keynote in part 1 of this article. Today, we cover Brian Goetz, Java language architect - Java Platform Group, who peeked into the crystal ball for all things Java 10 and beyond, particularly talking about projects Valhalla and Panama, two venues for incubating improvements to the Java Virtual Machine (JVM) and the Java language itself. These improvements are aimed at enriching the connection between the JVM and the underlying hardware (and operating system), as well as  non-Java APIs.

Motivation

Over time, increased sophistication in CPU core design has impacted the cost models for clock cycles and issue slots for the underlying hardware/CPU core. A cache miss can be very expensive, especially if you have to fetch from the main memory. Hence there is a need for Java and the JVM to have denser and flatter memory layouts to provide better cache and memory efficiency to keep up with modern hardware.

Project Valhalla

Goetz mentioned that Project Valhalla includes Java language and JVM features for working with pure data without all of the overhead that objects impose. He then walked us through the following example and explanation:

Consider a simple domain object Point class:

class Point {
 final int x;
 final int y;
}

An array of x-y Point instances comes with an overhead of 150% just to represent two words of data; a two word object header (common to all objects), with elements as references to the Point objects, plus another header for each of those Point objects:

1

Value Types

If Point were immutable, we wouldn’t require its identity; we could declare Point as a pure data point in the form of a value class:

value class Point {
 final int x;
 final int y;
}

In this example, the array of such a value type will have no indirection and as a result we get a cache friendly layout which is not only memory efficient but also has much better locality.

2

According to Goetz:

Value types are sort of halfway between classes and primitives… They code like a class, but behave like an int.

Specialized Generics

There is a proposal to enhance the Java language and the JVM to support generics over primitives. The good thing about value types is that they get boxed just like primitives. As a result, generics will eventually be supported over value types.

According to Goetz, even if you are working with: 

ArrayList<Integer>

you actually only want:

ArrayList<int>

Since there is currently no way in the core Java libraries to ask for the latter, you go with the former. But when you specify

ArrayList<Integer>

the inefficiencies in memory handling and overhead are similar to that showcased in the first example of array of x-y Point class.

With the specialization of Box<T> for T=int, and extension to value types, one can realize greater cost benefits as explained above in the value types example.

Project Panama

Goetz then moved on to talk about Project Panama, aimed at providing JVM access to native data (e.g. data in the native heap) and native code (e.g. functions in C) in a faster, more reliable and more secure way.

In Panama, a native header file import tool called jextract extracts the layout metadata (e.g. the C header files) and generates Java interfaces to call native methods or to access native structures. During runtime, the JVM will generate code similar to the JNI code that users may write.

Goetz walked us through an example that needed to pass pointers to structs in-order to call gettimeofday() from time.h. Hence, jextract was employed to parse the header file and also get information on the type of the machine. The resultant jar file had the structure definitions and method declarations.

3

Hence, all that was needed to call the above was a reference to the time library and also a struct creation as shown in the code below:

4

After that it is as simple as calling the getters to get the fields as shown above.

Additional Resources

For more information on projects Valhalla and Panama, please refer to:

State of the Specialization

State of the Values

http://mail.openjdk.java.net/pipermail/announce/2014-June/000172.html

https://blogs.oracle.com/jrose/entry/the_isthmus_in_the_vm

Rate this Article

Adoption
Style

BT