~/talk

Java 9 VarHandles Best practices, and why?

Talkat Devoxx Belgium 2017 · 2017-11-06..11-10· [java]
links:none on file
slides:none on file

Java 9 VarHandles provide atomic operations and fine-grained memory ordering on any field type (instance/static/array/bytebuffer) as a safe replacement for sun.misc.Unsafe and some Atomic types. API exposes five access modes (plain, opaque, release/acquire, volatile) plus fences (load/load, store/store, release, acquire, full) so code can merge sync points or use weaker ordering for speed. Best practices: declare the handle private static final*, back fields volatile to fail fast on mistakes. JVM work aims for Unsafe-level codegen (example reducing three sets to three move instructions), optimization still in progress.

AI-written summary · about

  1. 0:00Introduction and agenda
  2. 1:38Understanding memory models
  3. 9:23Key memory model rules
  4. 13:45Synchronization trade-offs
  5. 15:28Limitations of old solutions
  6. 16:44Introducing VarHandles
  7. 18:48VarHandle access modes
  8. 19:27How to create VarHandles
  9. 20:21Coding tips and practices
  10. 24:02Memory ordering modes
  11. 30:21Using fences
  12. 31:05Fence examples and benefits
  13. 34:55Comparison with unsafe
  14. 36:02Performance goals
  15. 37:18Conclusion and Q&A
~/search
type to search 6,249 conferences, 138,987 speakers and 185,172 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.