Safely Shoot Yourself in the Foot with Java 9
summary
Java 9 replaces Unsafe-era hacks with VarHandles and method-handles lookups but shows exactly how to regain old powers using --add-opens/--add-exports, including poking a String’s internal byte[] (can't write finals directly, must copy bytes), accessing Thread.probe for LongAdder striping, forcing unmap of MappedByteBuffer via Cleaner/Unsafe, and patching BigInteger to expose a private square method; demos use jshell, note Stream methods (takeWhile/dropWhile) can break assumptions, and recommend migrating GC configs to G1 soon.
AI-written summary · about
chapters (12)
- 0:00Introduction
- 0:52Project Jigsaw and security
- 3:35The unsafe class legacy
- 8:10Var handles in Java 9
- 10:50Concurrency and memory
- 15:40Modifying internal fields
- 20:42Java 9 JShell scripting
- 24:45Handling native memory
- 32:41Memory padding and contention
- 35:45Stream and GC changes
- 37:32Accessing private internals
- 44:06Hashing behavior puzzle
related talks
50mSafely Shoot Yourself in the Foot with Java 9
46mUnsafe (and Java 9/10) (RU)
18mThe Secret History and Tragic Fate of sun.misc.Unsafe
39mSafety first
42mJava 9 - What are we going to love/hate this time
48mJava 9 Performance
49mA Post Apocalyptic sun misc Unsafe World
01h 14mNovel but practical uses of Java
