The document outlines a product direction intended for information purposes only and is not binding. Any features or functionality described may change or be removed at Oracle's sole discretion. Statements relating to Oracle's plans are forward-looking and subject to risks. All information is current as of September 2019. Oracle undertakes no duty to update any statement in light of new information or future events. The document is intended to provide a non-binding overview of Oracle's general product direction and is not a commitment to deliver any functionality.
6. JVM Sustaining Engineer
OpenJDK Update Project
Maintainer
JavaOne Rock Star
Co-author of Oracle WebLogic
Server 11g 構築・運用ガイド
@DavidBuckJP
https://blogs.oracle.com/buck/
Who am I? David Buck (left)
10. Web Server
picture: Coolcaesar at the English language Wikipedia [GFDL (http://www.gnu.org/copyleft/fdl.html) or CC-BY-SA-3.0 (http://creativecommons.org/licenses/by-sa/3.0/)]
12. Libraries
picture: David Vignoni / ICON KING (http://icon-king.com) [LGPL (http://www.gnu.org/licenses/lgpl.html) or LGPL (http://www.gnu.org/licenses/lgpl.html)]
13. Batch Processing
picture: US Social Security Administration (http://www.ssa.gov/history/acalcs.html) [Public domain]
16. Race Conditions
picture: Sakurambo at English Wikipedia [GFDL (http://www.gnu.org/copyleft/fdl.html) or CC-BY-SA-3.0 (http://creativecommons.org/licenses/by-sa/3.0/)]
35. Out of Order Execution
picture: Amit6, original version (File:Superscalarpipeline.png) by User:Poil (Own work) [CC BY-SA 3.0 (http://creativecommons.org/licenses/by-sa/3.0)]
36. CPU Differences
Type Alpha ARMv7
PA-
RISC
POWER
SPARC
RMO
SPARC
PSO
SPARC
TSO
x86
x86
oostore
AMD64 IA-64 zSeries
load-
load
Y Y Y Y Y Y Y
load-
store
Y Y Y Y Y Y Y
store-
store
Y Y Y Y Y Y Y Y
store-
load
Y Y Y Y Y Y Y Y Y Y Y Y
Atomic
(loads)
Y Y Y Y Y
Atomic
(stores)
Y Y Y Y Y Y
Depend
ent
loads
Y
instruct
ion
cache
Y Y Y Y Y Y Y Y Y Y
chart source: https://en.wikipedia.org/wiki/Memory_ordering
49. Tangent 1: Special Relativity
Observed order depends on viewer's frame of reference
A
B
C
A, B, C C, B, A
50. No single “correct” timeline
Special Relativity
Observed order of events depends on frame of reference
51. No single “correct” timeline
Special Relativity
Observed order of events depends on frame of reference
Multithreaded Code
Observed order of events depends on thread
55. Java Memory Model (JMM)
Write once, run anywhere
1995
Part of the formal language
specification
Happened-before
picture: Peter Campbell [GFDL (http://www.gnu.org/copyleft/fdl.html) or CC BY-SA 4.0-3.0-2.5-2.0-1.0 (http://creativecommons.org/licenses/by-sa/4.0-3.0-2.5-2.0-1.0)]
66. Problems with the Original JMM
volatile does not establish a happened-before relationship
final values can change
Many important runtime optimization were not allowed
67. Doug Lea
Author of the Java Multithreaded
bible
Introduced his own OSS high-
level multithreaded library
68. Java SE 5.0
Modern JMM introduced
Lea’s library added to official JDK
picture: Zvi Roger [CC BY 3.0 (http://creativecommons.org/licenses/by/3.0)]
83. Tangent 2: HSDIS (HotSpot
Disassembler)
Lets us see code generated by JIT
Requires a disassembler plugin
GNU binutils-based plugin
base-hsdis
Command line options
+PrintAssembly
+CompileCommand=print,*MyClass.myMethod
102. JEP-188/JMM9
Not delivered with JDK 9 (JMM9 != JDK 9)
JVM-level specification
Compatibility with C11/C++11
Cover new features added since JDK 5
(e.g. AtomicX.weakCompareAndSet())
105. Code against the specification
Intermittent bugs are common
Behavior changes with JRE / platform
Stuff to avoid
synchronized (new Object()) { }
Randomly adding volatile declarations until it magically starts working
106. Testing
As close to production environment as possible
Same hardware
Same JRE (including version)
Same settings
107. Testing
As much variety as possible
Various hardware
Various JREs (including version)
Various settings
108. Java Concurrency in Practice
Java Concurrency Bible
Covers JSR-133 / JSR-166
109. Summary
Avoid low-level APIs
Code against the standard, not the implementation
Testing is always indispensible
Must read Java Concurrency in Practice (JCiP)