-
Bug
-
Resolution: Fixed
-
P2
-
repo-valhalla
John outlined two ways to adjust the existing Unsafe.putX contract for values:
1. Create two new Unsafe operations “start buffer” and “finish buffer” on values; “start buffer” creates a true object instance (of undefined type) whose layout and contents is exactly the input value instance, and “finish buffer” reverses the process. In between, Unsafe.putInt on the buffer will have predictable effects. The JIT can easily EA away the buffer, especially since it will be an “Unsafe party foul” to do anything with the buffer other than finishing it and walking away with the resulting value.
2. For every operation like Unsafe.putInt create a corresponding operation Unsafe.withInt which operates on a value instance and returns the new value. (Remember that putInt returns void.) This requires not two new Unsafe API points but about 10 (prims + ref + value). Note that there is no need to worry about relaxed vs. volatile ordering; withInt can only have one ordering because the value instance is always local and unaliased.
John suggested to go with the “magic buffer” approach is more robust than the withfield APIs approach. That is a different approach than the one discussed at valhalla offsite 2018.
1. Create two new Unsafe operations “start buffer” and “finish buffer” on values; “start buffer” creates a true object instance (of undefined type) whose layout and contents is exactly the input value instance, and “finish buffer” reverses the process. In between, Unsafe.putInt on the buffer will have predictable effects. The JIT can easily EA away the buffer, especially since it will be an “Unsafe party foul” to do anything with the buffer other than finishing it and walking away with the resulting value.
2. For every operation like Unsafe.putInt create a corresponding operation Unsafe.withInt which operates on a value instance and returns the new value. (Remember that putInt returns void.) This requires not two new Unsafe API points but about 10 (prims + ref + value). Note that there is no need to worry about relaxed vs. volatile ordering; withInt can only have one ordering because the value instance is always local and unaliased.
John suggested to go with the “magic buffer” approach is more robust than the withfield APIs approach. That is a different approach than the one discussed at valhalla offsite 2018.
- relates to
-
JDK-8206144 [lworld] Adapt and add C2 intrinsics for value types Unsafe API
-
- Resolved
-