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







