Project Valhalla Update
JVM Language Summit Feedback
#JVMLS_jp
Agenda
Project Valhalla
Project Valhalla - Reboot JVM relationship with data in memory
Project Valhalla - Reboot JVM relationship with data in memory
 Value Types
 Generic Specialization
Will be discussed in JVMLS 2020...
Why are flatter and denser memory layouts required?
e.g. Intel Broadwell-EP
L1 L2 Main Memory
Intel® 64 and IA-32 Architectures Optimization Reference Manual
https://software.intel.com/sites/default/files/managed/9e/bc/64-ia-32-architectures-optimization-manual.pdf
L3
Cache
For example...
class Point {
int x;
int y;
}
public class App {
...
Point[] points = new Point[5];
points[0] = new Point();
...
}
As is...
header
x
y
header
x
y
header
x
y
header
x
y
header
x
y
header
To be...
header
x
y
header
x
y
header
x
y
header
x
y
header
x
y
header header
x
y
x
y
x
y
x
y
x
y
Who cares about project Valhalla?
Value Type is available in CLR
System.ValueType
https://docs.microsoft.com/ja-jp/dotnet/csharp/language-reference/keywords/value-types
What the project has done
Drilling from JVM side and programming model side
L World
Early prototypes (M1-M3)
Compiler-only
Exploring language side
• Specialized generics, wildcards
• Informed VM requirements
• Many of these problems still
require considerable work
“MVT” prototype
VM-only
Exploring the “Q-World” model
For more detail, check the
JVMLS 2018 video!
Current prototype
VM and compiler support
No support yet for specialized
generics or migration
Still drilling...
Q World
Q
qload
Worked, but...
L World
a*
L World benefits
L World costs
Project status
Milestone
L2 (LW2)
https://wiki.openjdk.java.net/display/valhalla/LW2
LW2 prototype binary
http://jdk.java.net/valhalla/
Inline class
value class Point {
int x;
int y;
}
inline class Point {
int x;
int y;
}
Compiler optimizations
Considerations
Construction
defaultvalue withfield
class Point {
int x;
int y;
Point() {
this.x = 0;
this.y = 0;
}
Point(int x, int y) {
this.x = x;
this.y = y;
}
}
Point(int, int);
descriptor: (II)V
flags: (0x0000)
Code:
stack=2, locals=3, args_size=3
0: aload_0
1: invokespecial #1
// Method java/lang/Object."<init>":()V
4: aload_0
5: iload_1
6: putfield #7 // Field x:I
9: aload_0
10: iload_2
11: putfield #13 // Field y:I
14: return
LineNumberTable:
line 10: 0
line 11: 4
line 12: 9
line 13: 14
inline class Point {
final int x;
final int y;
Point() {
this.x = 0;
this.y = 0;
}
Point(int x, int y) {
this.x = x;
this.y = y;
}
}
static Point Point(int, int);
descriptor: (II)QPoint;
flags: (0x0008) ACC_STATIC
Code:
stack=2, locals=3, args_size=2
0: defaultvalue #1 // class Point
3: astore_2
4: iload_0
5: aload_2
6: swap
7: withfield #3 // Field x:I
10: astore_2
11: iload_1
12: aload_2
13: swap
14: withfield #7 // Field y:I
17: astore_2
18: aload_2
19: areturn
LineNumberTable:
line 10: 0
line 11: 4
line 12: 11
line 13: 18
}
Arrays
Default values
Foo.default
x = T.default
x = null
Default values
Flattening
Value types are flattenable, but flattening is not mandatory in every scene.
Flattening
V?
(
http://hg.openjdk.java.net/valhalla/valhalla/file/a32457198d
3e/test/jdk/valhalla/valuetypes/NonFlattenValue.java
public inline class NonFlattenValue {
Point? nfp;
NonFlattenValue() {
this.nfp = Point.makePoint(0,0);
}
NonFlattenValue(Point p) {
this.nfp = p;
}
public Point? point() {
return nfp;
}
public Point pointValue() {
return (Point) nfp;
}
...
}
Generics – specialized and erased
Foo<V>
Foo<V?>
New top types (not yet in LW2, under discussion)
New top types (not yet in LW2, under discussion)
By bringing ref-ness and val-ness into the type system
x instance of RefObject
RefObject m() { ... }
void m(RefObject o) { … }
class Foo<T extents RefObject> { ... }
Nullity
Nullity
Options
Equality
Equality
Options
Migration
https://docs.oracle.com/en/java/javase/12/docs/api/java.base/java/lang/doc-
files/ValueBased.html
https://docs.oracle.com/javase/jp/12/docs/api/java.base/java/lang/doc-files/ValueBased.html
Other identity-sensitive operations
Next action
Tons of things to do!
From Brian Goetz...
Resources
Resources
https://youtu.be/1H4vmT-Va4o
https://youtu.be/_26KZAegYRM
https://youtu.be/49GUljUmGHg
https://www.slideshare.net/DavidBuck7/valhalla-update-jjug-ccc-spring-2019
Jvmls 2019 feedback   valhalla update

Jvmls 2019 feedback valhalla update