...
- builds on work of the previous Minimal Values Types prototype (MVT)
- provides a new type which is: immutable, identity-agnostic, non-nullable, non-synchronizable, final
- Value Types contained in References, other Value Types or in Arrays are flatten-able
- Value Types can contain primitives or references
- JVMS class file model for MVT:
- Separate descriptors to distinguish value types from object types using "Q" signatures (Q-Types) similar to how Object descriptors begin with "L" (L-Types).
- Separate bytecodes, starting with "v", called "v-bytecodes" to distinguish from reference "a-bytecodes".
- MVT limitations:
- No direct support for methods
- No compatibility with existing Objects and Interfaces
- Enabled exploration of potential maximum optimizations for value types with minimal impact on existing objects (object identity types)
...
- Value Types may be referred to by the same "L-Type" descriptors the VM has always operated on:
- May implement interfaces with value types
- May pass a value type as a java.lang.Object, or an interface through existing APIs
- Value Type characteristics:
- immutable: unmodifiable instance fields
- may contain primitives, other value types, references to mutable objects
- identity-less:
- synchronization including use of wait(*), notify*() will fail with exception: IllegalMonitorStateException
- reference equality with "
==" (if_acmp<eq|ne>) always returns false, value equality requires using the "equals()" method - freely substitutable when equal, no visible change in behavior if equals()
- final
- JVMS class file model for "LWorld"
- Re-uses "L" descriptors
- Re-uses "a-bytecodes"
- There are only two new byte-codes, otherwise existing byte-codes have been engineered to accept and maintain value type characteristics (identity-less, flattenable, pass by value):
- "default" - will create a new default value
- "withfield"- allows updating value type fields via a copy-on-write semantic, i.e. new value based on the old value combined with new field value.
...
LW1 initial prototype is intended to get this into your hands as early as possible so you can provide us with feedback. There are some switches for potential incremental improvements that we will be exploring as we provide updates to LW1, mostly for performance optimizations and bug fixes.
Javac source support:
- Requires source level >= JDK11
- A class declaration may be tagged as being a value type by using the "__ByValue" modifier
- Interfaces, annotation types, enums can not be value types
- Top level, inner, nested, local classes may be value types. Value types may declare inner, nested, local types
- Value Types are implicitly final, so cannot be abstract)
- All instance fields of a value class are implicitly final
- Value types may to declare fields of its own type directly or indirectly
- Value Types may not declare an explicit super class. They implicitly extend java.lang.Object akin to enums, annotation types and interfaces
- Value Types may declare explicit interfaces
- Value Types constructors may not pass the "this" handle until all instance fields are definitely assigned.
- All instance fields of a value class are implicitly final
- Value types may not to declare fields of its own type directly or indirectly
- java.lang.Object methods:
- javac automatically generates hashCode, equals, longHashCode and toString computed solely from the instance's state and not from its identity
- javac does not clone(), finalize(), wait*), notify*() on value receivers
- javac does not allow comparison of values using ==, !=
- Value Types can not be assigned null, null can not be cast to or compared with value types
- Value Types cannot be type arguments in generic type parameterizations, type witnesses in generic method invocations, wildcard bounds
- Type migration, including partial recompilation is not supported
...
- Support for java.lang.Object methods:
- equals, hashCode and toString implementations are computed solely from the instance's star and not from its identity or the state of any other object or variables
- value types can not be cloned or finalizedTODO
- Class.isValue() new API
- Class.newInstance() on a value type throws IllegalAccessException
- SetAccessible() on a value type throws InaccessibleObjectException
...
- platforms: x64 Linux, x64 Mac OS X, Windows
- no support for value class with no instance fields
- no support for atomic fields containing value types (work-in-progress for an update)
- no support for @Contended value type fields
- static fields are not flattenable
- no AOT, CDS, ZGC, serviceability agent
- -Xint and C2 only, no C1, no tiered-compilation, no Graal
- unsafe field and array accessor APIs are not supported for value types
- VarHandles support value types
- however: they do not enforce immutability or non-nullability for value types
- note that immutable types can be copied, so updates may not be seen
- low-level unsafe APIs are UNSAFE and will not be changed to support value types
- risks: If a value type has been flattened in a container, unsafe does not know the layout
- getObject could return the first flattened element rather than the expected reference
- interpreter is not optimized, focus is on JIT optimization
- Need Please provide additional USE CASES for optimizations
- Working on additional test cases
...
Send email to valhalla-dev@openjdk.java.net
- Use cases that worked for you, including any positive performance or footprint information
- Bugs or questions about surprise behavior
- Use cases that you would like to see optimized PLEASE
...