SlideShare une entreprise Scribd logo
1  sur  31
@LAFK_pl, Polish JUG, May 2014 2
@LAFK_pl, Polish JUG, May 2014 3
MANAGEMENT!!
@LAFK_pl, Polish JUG, May 2014 4
Posted in 2012...
@LAFK_pl, Polish JUG, May 2014 5
... and still not corrected
@LAFK_pl, Polish JUG, May 2014 6
Leslie Lamport
● Distributed system
clocks
● Happens-before
● Sequential
Consistency
@LAFK_pl, Polish JUG, May 2014 7
Bill Pugh
● FindBugs
● Java Memory Model
is broken
● Final - Volatile
● Double-checked
locking
● New JMM
@LAFK_pl, Polish JUG, May 2014 8
Sarita Adve
● Java Memory Model
is broken
● Number of great
papers on memory
(consistency) models
● Best definition of
MCM I found
@LAFK_pl, Polish JUG, May 2014 9
Within these 15-20 minutes
Intro
Memory model means?
Hardware
Java stuff
@LAFK_pl, Polish JUG, May 2014 10
Memory model?
If NOT about GC then...
what's it about?
@LAFK_pl, Polish JUG, May 2014 11
Memory CONSISTENCY
● Allowed optimizations
● Possible behaviours / executions of a (possibly
multithreaded!) program
● Which cores / threads see which values
● How to make it consistent for us, programmers
@LAFK_pl, Polish JUG, May 2014 12
@LAFK_pl, Polish JUG, May 2014 13
@LAFK_pl, Polish JUG, May 2014 14
Where it matters?
● Javac / Jython / ...
● JIT
● Hardware of course
● So JMM is a
LANGUAGE memory
consistency model
@LAFK_pl, Polish JUG, May 2014 15
Hardware
● CISC or RISC CPU
● Number of registers
● Caches size or type
● How many functional units per CPU
● Pipeline:
● Instruction decode > address decode > memory
fetch > register fetch > compute ...
@LAFK_pl, Polish JUG, May 2014 16
Program / code optimizations?
● Reorder
● (e.g. prescient store)
● Remove what's unnecessary
● (e.g. synchronize)
● Replace instructions / shorten machine code
● Function optimizations
● (e.g. Inlining)
● ...
@LAFK_pl, Polish JUG, May 2014 17
Exemplary CPU
@LAFK_pl, Polish JUG, May 2014 18
Barriers / fences
„once memory has been pushed to the cache
then a protocol of messages will occur to
ensure all caches are coherent for any shared
data. The techniques for making memory
visible from a processor core are known as
memory barriers or fences.
– Martin Thompson, Mechanical Sympathy
differs per architecture / CPU / cache type!
@LAFK_pl, Polish JUG, May 2014 19
Barriers / Fences
● CPU instruction
● Means „Flush now!”
● Forces update
● Starts cache
coherency protocols
● Read / Write / Full
@LAFK_pl, Polish JUG, May 2014 20
@LAFK_pl, Polish JUG, May 2014 21
Summarizing Java Language Spec:
● Describes whether the execution trace is a legal
execution of the program
● Works by examining each read and checking
write observed by that read
● Write is valid when it follows certain rules
● Describes possible behaviours of the program
● Implementor adhering to above can optimize
code as he likes
@LAFK_pl, Polish JUG, May 2014 22
What rules?
● Write is valid when it follows certain rules
@LAFK_pl, Polish JUG, May 2014 23
Before, or after?
@LAFK_pl, Polish JUG, May 2014 24
Before, or after?
@LAFK_pl, Polish JUG, May 2014 25
JSR-133 = new JM(C)M
@LAFK_pl, Polish JUG, May 2014 26
Class Reordering {
int x = 0, y = 0;
public void writer() {
x = 1;
y = 2;
}
public void reader() {
int r1 = y; // TUTAJ: y == 2 => x == ?
int r2 = x;
}
}
Reordering - classic example
@LAFK_pl, Polish JUG, May 2014 27
What was wrong with old JM(C)M?
You took a look, read the specs entire and...
@LAFK_pl, Polish JUG, May 2014 28
@LAFK_pl, Polish JUG, May 2014 29
New Java Memory Model
●
SC on single-core and single-thread CPU is
fine but it doesn't cut it now
●
To ensure visibility, JVM JMM spec ensures:
●
final
●
volatile
●
Synchronized
are done well thistime
@LAFK_pl, Polish JUG, May 2014 30
Barriers in Java – rules
● JMM
● volatile – sfence after write, lfence before read
● final – sfence after init (field visibility)
● Atomic instructions (like lock) = mfence
@LAFK_pl, Polish JUG, May 2014 31
Further topics
● Why MCM and not a threading library?
H.Boehm
● Better MCM? Sarita Adve
● Possible optimizations and their gains
● Performance of Java and hardware MCMs?
Clashes?
● JMCM rules in more detail

Contenu connexe

En vedette

Metody mierzenia architektury
Metody mierzenia architekturyMetody mierzenia architektury
Metody mierzenia architekturyTomek Borek
 
AR drone - Polish JUG short demo
AR drone - Polish JUG short demoAR drone - Polish JUG short demo
AR drone - Polish JUG short demoTomek Borek
 
Łukasz Romaszewski on Internet of Things Raspberry Pi and Java Embedded JavaC...
Łukasz Romaszewski on Internet of Things Raspberry Pi and Java Embedded JavaC...Łukasz Romaszewski on Internet of Things Raspberry Pi and Java Embedded JavaC...
Łukasz Romaszewski on Internet of Things Raspberry Pi and Java Embedded JavaC...Tomek Borek
 
Meta on HCI - keyword analysis and trends
Meta on HCI - keyword analysis and trendsMeta on HCI - keyword analysis and trends
Meta on HCI - keyword analysis and trendsTomek Borek
 
It's not always the application's fault
It's not always the application's faultIt's not always the application's fault
It's not always the application's faultTomek Borek
 
Dev con wrocław_2013
Dev con wrocław_2013Dev con wrocław_2013
Dev con wrocław_2013Tomek Borek
 
Seeing through the smoke
Seeing through the smokeSeeing through the smoke
Seeing through the smokeTomek Borek
 
Git nie dla początkujących
Git nie dla początkującychGit nie dla początkujących
Git nie dla początkującychTomek Borek
 
Java Memory Consistency Model - concepts and context
Java Memory Consistency Model - concepts and contextJava Memory Consistency Model - concepts and context
Java Memory Consistency Model - concepts and contextTomek Borek
 

En vedette (9)

Metody mierzenia architektury
Metody mierzenia architekturyMetody mierzenia architektury
Metody mierzenia architektury
 
AR drone - Polish JUG short demo
AR drone - Polish JUG short demoAR drone - Polish JUG short demo
AR drone - Polish JUG short demo
 
Łukasz Romaszewski on Internet of Things Raspberry Pi and Java Embedded JavaC...
Łukasz Romaszewski on Internet of Things Raspberry Pi and Java Embedded JavaC...Łukasz Romaszewski on Internet of Things Raspberry Pi and Java Embedded JavaC...
Łukasz Romaszewski on Internet of Things Raspberry Pi and Java Embedded JavaC...
 
Meta on HCI - keyword analysis and trends
Meta on HCI - keyword analysis and trendsMeta on HCI - keyword analysis and trends
Meta on HCI - keyword analysis and trends
 
It's not always the application's fault
It's not always the application's faultIt's not always the application's fault
It's not always the application's fault
 
Dev con wrocław_2013
Dev con wrocław_2013Dev con wrocław_2013
Dev con wrocław_2013
 
Seeing through the smoke
Seeing through the smokeSeeing through the smoke
Seeing through the smoke
 
Git nie dla początkujących
Git nie dla początkującychGit nie dla początkujących
Git nie dla początkujących
 
Java Memory Consistency Model - concepts and context
Java Memory Consistency Model - concepts and contextJava Memory Consistency Model - concepts and context
Java Memory Consistency Model - concepts and context
 

Similaire à Java Memory (Consistency) Model - Polish JUG One Beer Talk #2

4Developers 2015: Java Memory Consistency Model or intro to multithreaded pro...
4Developers 2015: Java Memory Consistency Model or intro to multithreaded pro...4Developers 2015: Java Memory Consistency Model or intro to multithreaded pro...
4Developers 2015: Java Memory Consistency Model or intro to multithreaded pro...PROIDEA
 
Lock free programming - pro tips devoxx uk
Lock free programming - pro tips devoxx ukLock free programming - pro tips devoxx uk
Lock free programming - pro tips devoxx ukJean-Philippe BEMPEL
 
Java Performance: Speedup your application with hardware counters
Java Performance: Speedup your application with hardware countersJava Performance: Speedup your application with hardware counters
Java Performance: Speedup your application with hardware countersSergey Kuksenko
 
Efficient Django
Efficient DjangoEfficient Django
Efficient DjangoDavid Arcos
 
Data Science Salon: A Journey of Deploying a Data Science Engine to Production
Data Science Salon: A Journey of Deploying a Data Science Engine to ProductionData Science Salon: A Journey of Deploying a Data Science Engine to Production
Data Science Salon: A Journey of Deploying a Data Science Engine to ProductionFormulatedby
 
Java 8 -12: da Oracle a Eclipse. Due anni e una rivoluzione
Java 8 -12: da Oracle a Eclipse. Due anni e una rivoluzioneJava 8 -12: da Oracle a Eclipse. Due anni e una rivoluzione
Java 8 -12: da Oracle a Eclipse. Due anni e una rivoluzioneThinkOpen
 
Howto createOpenFlow Switchusing FPGA (at FPGAX#6)
Howto createOpenFlow Switchusing FPGA (at FPGAX#6)Howto createOpenFlow Switchusing FPGA (at FPGAX#6)
Howto createOpenFlow Switchusing FPGA (at FPGAX#6)Kentaro Ebisawa
 
OpenLineage for Stream Processing | Kafka Summit London
OpenLineage for Stream Processing | Kafka Summit LondonOpenLineage for Stream Processing | Kafka Summit London
OpenLineage for Stream Processing | Kafka Summit LondonHostedbyConfluent
 
BUD17-300: Journey of a packet
BUD17-300: Journey of a packetBUD17-300: Journey of a packet
BUD17-300: Journey of a packetLinaro
 
Understanding eBPF in a Hurry!
Understanding eBPF in a Hurry!Understanding eBPF in a Hurry!
Understanding eBPF in a Hurry!Ray Jenkins
 
MMLSpark: Lessons from Building a SparkML-Compatible Machine Learning Library...
MMLSpark: Lessons from Building a SparkML-Compatible Machine Learning Library...MMLSpark: Lessons from Building a SparkML-Compatible Machine Learning Library...
MMLSpark: Lessons from Building a SparkML-Compatible Machine Learning Library...Spark Summit
 
Prometheus as exposition format for eBPF programs running on Kubernetes
Prometheus as exposition format for eBPF programs running on KubernetesPrometheus as exposition format for eBPF programs running on Kubernetes
Prometheus as exposition format for eBPF programs running on KubernetesLeonardo Di Donato
 
Linux Device Driver parallelism using SMP and Kernel Pre-emption
Linux Device Driver parallelism using SMP and Kernel Pre-emptionLinux Device Driver parallelism using SMP and Kernel Pre-emption
Linux Device Driver parallelism using SMP and Kernel Pre-emptionHemanth Venkatesh
 
Omp tutorial cpugpu_programming_cdac
Omp tutorial cpugpu_programming_cdacOmp tutorial cpugpu_programming_cdac
Omp tutorial cpugpu_programming_cdacGanesan Narayanasamy
 
Sharing (or stealing) the jewels of python with big data & the jvm (1)
Sharing (or stealing) the jewels of python with big data & the jvm (1)Sharing (or stealing) the jewels of python with big data & the jvm (1)
Sharing (or stealing) the jewels of python with big data & the jvm (1)Holden Karau
 
Are general purpose big data systems eating the world?
Are general purpose big data systems eating the world?Are general purpose big data systems eating the world?
Are general purpose big data systems eating the world?Holden Karau
 
Inside the JVM - Follow the white rabbit!
Inside the JVM - Follow the white rabbit!Inside the JVM - Follow the white rabbit!
Inside the JVM - Follow the white rabbit!Sylvain Wallez
 
Overview of ppOpen-AT/Static for ppOpen-APPL/FDM ver. 0.2.0
Overview of ppOpen-AT/Static for ppOpen-APPL/FDM ver. 0.2.0Overview of ppOpen-AT/Static for ppOpen-APPL/FDM ver. 0.2.0
Overview of ppOpen-AT/Static for ppOpen-APPL/FDM ver. 0.2.0Takahiro Katagiri
 

Similaire à Java Memory (Consistency) Model - Polish JUG One Beer Talk #2 (20)

4Developers 2015: Java Memory Consistency Model or intro to multithreaded pro...
4Developers 2015: Java Memory Consistency Model or intro to multithreaded pro...4Developers 2015: Java Memory Consistency Model or intro to multithreaded pro...
4Developers 2015: Java Memory Consistency Model or intro to multithreaded pro...
 
Lock free programming - pro tips devoxx uk
Lock free programming - pro tips devoxx ukLock free programming - pro tips devoxx uk
Lock free programming - pro tips devoxx uk
 
Java Performance: Speedup your application with hardware counters
Java Performance: Speedup your application with hardware countersJava Performance: Speedup your application with hardware counters
Java Performance: Speedup your application with hardware counters
 
Efficient Django
Efficient DjangoEfficient Django
Efficient Django
 
Introduction to Embedded Systems a Practical Approach
Introduction to Embedded Systems a Practical ApproachIntroduction to Embedded Systems a Practical Approach
Introduction to Embedded Systems a Practical Approach
 
Data Science Salon: A Journey of Deploying a Data Science Engine to Production
Data Science Salon: A Journey of Deploying a Data Science Engine to ProductionData Science Salon: A Journey of Deploying a Data Science Engine to Production
Data Science Salon: A Journey of Deploying a Data Science Engine to Production
 
Java 8 -12: da Oracle a Eclipse. Due anni e una rivoluzione
Java 8 -12: da Oracle a Eclipse. Due anni e una rivoluzioneJava 8 -12: da Oracle a Eclipse. Due anni e una rivoluzione
Java 8 -12: da Oracle a Eclipse. Due anni e una rivoluzione
 
Howto createOpenFlow Switchusing FPGA (at FPGAX#6)
Howto createOpenFlow Switchusing FPGA (at FPGAX#6)Howto createOpenFlow Switchusing FPGA (at FPGAX#6)
Howto createOpenFlow Switchusing FPGA (at FPGAX#6)
 
OpenLineage for Stream Processing | Kafka Summit London
OpenLineage for Stream Processing | Kafka Summit LondonOpenLineage for Stream Processing | Kafka Summit London
OpenLineage for Stream Processing | Kafka Summit London
 
BUD17-300: Journey of a packet
BUD17-300: Journey of a packetBUD17-300: Journey of a packet
BUD17-300: Journey of a packet
 
Understanding eBPF in a Hurry!
Understanding eBPF in a Hurry!Understanding eBPF in a Hurry!
Understanding eBPF in a Hurry!
 
MMLSpark: Lessons from Building a SparkML-Compatible Machine Learning Library...
MMLSpark: Lessons from Building a SparkML-Compatible Machine Learning Library...MMLSpark: Lessons from Building a SparkML-Compatible Machine Learning Library...
MMLSpark: Lessons from Building a SparkML-Compatible Machine Learning Library...
 
Prometheus as exposition format for eBPF programs running on Kubernetes
Prometheus as exposition format for eBPF programs running on KubernetesPrometheus as exposition format for eBPF programs running on Kubernetes
Prometheus as exposition format for eBPF programs running on Kubernetes
 
Linux Device Driver parallelism using SMP and Kernel Pre-emption
Linux Device Driver parallelism using SMP and Kernel Pre-emptionLinux Device Driver parallelism using SMP and Kernel Pre-emption
Linux Device Driver parallelism using SMP and Kernel Pre-emption
 
Single cycle cpu
Single cycle cpuSingle cycle cpu
Single cycle cpu
 
Omp tutorial cpugpu_programming_cdac
Omp tutorial cpugpu_programming_cdacOmp tutorial cpugpu_programming_cdac
Omp tutorial cpugpu_programming_cdac
 
Sharing (or stealing) the jewels of python with big data & the jvm (1)
Sharing (or stealing) the jewels of python with big data & the jvm (1)Sharing (or stealing) the jewels of python with big data & the jvm (1)
Sharing (or stealing) the jewels of python with big data & the jvm (1)
 
Are general purpose big data systems eating the world?
Are general purpose big data systems eating the world?Are general purpose big data systems eating the world?
Are general purpose big data systems eating the world?
 
Inside the JVM - Follow the white rabbit!
Inside the JVM - Follow the white rabbit!Inside the JVM - Follow the white rabbit!
Inside the JVM - Follow the white rabbit!
 
Overview of ppOpen-AT/Static for ppOpen-APPL/FDM ver. 0.2.0
Overview of ppOpen-AT/Static for ppOpen-APPL/FDM ver. 0.2.0Overview of ppOpen-AT/Static for ppOpen-APPL/FDM ver. 0.2.0
Overview of ppOpen-AT/Static for ppOpen-APPL/FDM ver. 0.2.0
 

Plus de Tomek Borek

Noc informatyka - co ja wiem o testowaniu
Noc informatyka - co ja wiem  o testowaniuNoc informatyka - co ja wiem  o testowaniu
Noc informatyka - co ja wiem o testowaniuTomek Borek
 
Teaching PostgreSQL to new people
Teaching PostgreSQL to new peopleTeaching PostgreSQL to new people
Teaching PostgreSQL to new peopleTomek Borek
 
Nowoczesne architektury
Nowoczesne architekturyNowoczesne architektury
Nowoczesne architekturyTomek Borek
 
Java tuning on GNU/Linux for busy dev
Java tuning on GNU/Linux for busy devJava tuning on GNU/Linux for busy dev
Java tuning on GNU/Linux for busy devTomek Borek
 
Jvm tuning in a rush! - Lviv JUG
Jvm tuning in a rush! - Lviv JUGJvm tuning in a rush! - Lviv JUG
Jvm tuning in a rush! - Lviv JUGTomek Borek
 
Testing SAAS, how to go about it?
Testing SAAS, how to go about it?Testing SAAS, how to go about it?
Testing SAAS, how to go about it?Tomek Borek
 
Spróbujmy szczęścia bo zaciskanie pięści nie działa
Spróbujmy szczęścia bo zaciskanie pięści nie działaSpróbujmy szczęścia bo zaciskanie pięści nie działa
Spróbujmy szczęścia bo zaciskanie pięści nie działaTomek Borek
 
Few words about happiness (Polish talk) / O szczęściu słów kilka
Few words about happiness (Polish talk) / O szczęściu słów kilkaFew words about happiness (Polish talk) / O szczęściu słów kilka
Few words about happiness (Polish talk) / O szczęściu słów kilkaTomek Borek
 
Jak użytecznie, prawdziwie i solidnie odpowiedzieć na pytanie "jak było"
Jak użytecznie, prawdziwie i solidnie odpowiedzieć na pytanie "jak było"Jak użytecznie, prawdziwie i solidnie odpowiedzieć na pytanie "jak było"
Jak użytecznie, prawdziwie i solidnie odpowiedzieć na pytanie "jak było"Tomek Borek
 
To nie zawsze wina aplikacji!
To nie zawsze wina aplikacji!To nie zawsze wina aplikacji!
To nie zawsze wina aplikacji!Tomek Borek
 
Wprowadzenie do optymalizacji wielokryterialnej / Intro to multicriteria opti...
Wprowadzenie do optymalizacji wielokryterialnej / Intro to multicriteria opti...Wprowadzenie do optymalizacji wielokryterialnej / Intro to multicriteria opti...
Wprowadzenie do optymalizacji wielokryterialnej / Intro to multicriteria opti...Tomek Borek
 
Architecture visualizers - tools usability study
Architecture visualizers - tools usability studyArchitecture visualizers - tools usability study
Architecture visualizers - tools usability studyTomek Borek
 
"Narco" emotions - description of study on whether Twitter can be used to gle...
"Narco" emotions - description of study on whether Twitter can be used to gle..."Narco" emotions - description of study on whether Twitter can be used to gle...
"Narco" emotions - description of study on whether Twitter can be used to gle...Tomek Borek
 
Polish Java User Group - One Beer Talks - Ubung macht den Meister
Polish Java User Group - One Beer Talks -  Ubung macht den MeisterPolish Java User Group - One Beer Talks -  Ubung macht den Meister
Polish Java User Group - One Beer Talks - Ubung macht den MeisterTomek Borek
 
Early deciding factors
Early deciding factorsEarly deciding factors
Early deciding factorsTomek Borek
 

Plus de Tomek Borek (18)

Noc informatyka - co ja wiem o testowaniu
Noc informatyka - co ja wiem  o testowaniuNoc informatyka - co ja wiem  o testowaniu
Noc informatyka - co ja wiem o testowaniu
 
Teaching PostgreSQL to new people
Teaching PostgreSQL to new peopleTeaching PostgreSQL to new people
Teaching PostgreSQL to new people
 
Nowoczesne architektury
Nowoczesne architekturyNowoczesne architektury
Nowoczesne architektury
 
Java tuning on GNU/Linux for busy dev
Java tuning on GNU/Linux for busy devJava tuning on GNU/Linux for busy dev
Java tuning on GNU/Linux for busy dev
 
Jvm tuning in a rush! - Lviv JUG
Jvm tuning in a rush! - Lviv JUGJvm tuning in a rush! - Lviv JUG
Jvm tuning in a rush! - Lviv JUG
 
Testing SAAS, how to go about it?
Testing SAAS, how to go about it?Testing SAAS, how to go about it?
Testing SAAS, how to go about it?
 
Spróbujmy szczęścia bo zaciskanie pięści nie działa
Spróbujmy szczęścia bo zaciskanie pięści nie działaSpróbujmy szczęścia bo zaciskanie pięści nie działa
Spróbujmy szczęścia bo zaciskanie pięści nie działa
 
Few words about happiness (Polish talk) / O szczęściu słów kilka
Few words about happiness (Polish talk) / O szczęściu słów kilkaFew words about happiness (Polish talk) / O szczęściu słów kilka
Few words about happiness (Polish talk) / O szczęściu słów kilka
 
Jak użytecznie, prawdziwie i solidnie odpowiedzieć na pytanie "jak było"
Jak użytecznie, prawdziwie i solidnie odpowiedzieć na pytanie "jak było"Jak użytecznie, prawdziwie i solidnie odpowiedzieć na pytanie "jak było"
Jak użytecznie, prawdziwie i solidnie odpowiedzieć na pytanie "jak było"
 
To nie zawsze wina aplikacji!
To nie zawsze wina aplikacji!To nie zawsze wina aplikacji!
To nie zawsze wina aplikacji!
 
Wprowadzenie do optymalizacji wielokryterialnej / Intro to multicriteria opti...
Wprowadzenie do optymalizacji wielokryterialnej / Intro to multicriteria opti...Wprowadzenie do optymalizacji wielokryterialnej / Intro to multicriteria opti...
Wprowadzenie do optymalizacji wielokryterialnej / Intro to multicriteria opti...
 
Architecture visualizers - tools usability study
Architecture visualizers - tools usability studyArchitecture visualizers - tools usability study
Architecture visualizers - tools usability study
 
"Narco" emotions - description of study on whether Twitter can be used to gle...
"Narco" emotions - description of study on whether Twitter can be used to gle..."Narco" emotions - description of study on whether Twitter can be used to gle...
"Narco" emotions - description of study on whether Twitter can be used to gle...
 
Polish Java User Group - One Beer Talks - Ubung macht den Meister
Polish Java User Group - One Beer Talks -  Ubung macht den MeisterPolish Java User Group - One Beer Talks -  Ubung macht den Meister
Polish Java User Group - One Beer Talks - Ubung macht den Meister
 
Confitura 2013
Confitura 2013Confitura 2013
Confitura 2013
 
Wesele
WeseleWesele
Wesele
 
Po co mierzyć?
Po co mierzyć?Po co mierzyć?
Po co mierzyć?
 
Early deciding factors
Early deciding factorsEarly deciding factors
Early deciding factors
 

Dernier

A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 

Dernier (20)

A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 

Java Memory (Consistency) Model - Polish JUG One Beer Talk #2

  • 1.
  • 3. @LAFK_pl, Polish JUG, May 2014 3 MANAGEMENT!!
  • 4. @LAFK_pl, Polish JUG, May 2014 4 Posted in 2012...
  • 5. @LAFK_pl, Polish JUG, May 2014 5 ... and still not corrected
  • 6. @LAFK_pl, Polish JUG, May 2014 6 Leslie Lamport ● Distributed system clocks ● Happens-before ● Sequential Consistency
  • 7. @LAFK_pl, Polish JUG, May 2014 7 Bill Pugh ● FindBugs ● Java Memory Model is broken ● Final - Volatile ● Double-checked locking ● New JMM
  • 8. @LAFK_pl, Polish JUG, May 2014 8 Sarita Adve ● Java Memory Model is broken ● Number of great papers on memory (consistency) models ● Best definition of MCM I found
  • 9. @LAFK_pl, Polish JUG, May 2014 9 Within these 15-20 minutes Intro Memory model means? Hardware Java stuff
  • 10. @LAFK_pl, Polish JUG, May 2014 10 Memory model? If NOT about GC then... what's it about?
  • 11. @LAFK_pl, Polish JUG, May 2014 11 Memory CONSISTENCY ● Allowed optimizations ● Possible behaviours / executions of a (possibly multithreaded!) program ● Which cores / threads see which values ● How to make it consistent for us, programmers
  • 12. @LAFK_pl, Polish JUG, May 2014 12
  • 13. @LAFK_pl, Polish JUG, May 2014 13
  • 14. @LAFK_pl, Polish JUG, May 2014 14 Where it matters? ● Javac / Jython / ... ● JIT ● Hardware of course ● So JMM is a LANGUAGE memory consistency model
  • 15. @LAFK_pl, Polish JUG, May 2014 15 Hardware ● CISC or RISC CPU ● Number of registers ● Caches size or type ● How many functional units per CPU ● Pipeline: ● Instruction decode > address decode > memory fetch > register fetch > compute ...
  • 16. @LAFK_pl, Polish JUG, May 2014 16 Program / code optimizations? ● Reorder ● (e.g. prescient store) ● Remove what's unnecessary ● (e.g. synchronize) ● Replace instructions / shorten machine code ● Function optimizations ● (e.g. Inlining) ● ...
  • 17. @LAFK_pl, Polish JUG, May 2014 17 Exemplary CPU
  • 18. @LAFK_pl, Polish JUG, May 2014 18 Barriers / fences „once memory has been pushed to the cache then a protocol of messages will occur to ensure all caches are coherent for any shared data. The techniques for making memory visible from a processor core are known as memory barriers or fences. – Martin Thompson, Mechanical Sympathy differs per architecture / CPU / cache type!
  • 19. @LAFK_pl, Polish JUG, May 2014 19 Barriers / Fences ● CPU instruction ● Means „Flush now!” ● Forces update ● Starts cache coherency protocols ● Read / Write / Full
  • 20. @LAFK_pl, Polish JUG, May 2014 20
  • 21. @LAFK_pl, Polish JUG, May 2014 21 Summarizing Java Language Spec: ● Describes whether the execution trace is a legal execution of the program ● Works by examining each read and checking write observed by that read ● Write is valid when it follows certain rules ● Describes possible behaviours of the program ● Implementor adhering to above can optimize code as he likes
  • 22. @LAFK_pl, Polish JUG, May 2014 22 What rules? ● Write is valid when it follows certain rules
  • 23. @LAFK_pl, Polish JUG, May 2014 23 Before, or after?
  • 24. @LAFK_pl, Polish JUG, May 2014 24 Before, or after?
  • 25. @LAFK_pl, Polish JUG, May 2014 25 JSR-133 = new JM(C)M
  • 26. @LAFK_pl, Polish JUG, May 2014 26 Class Reordering { int x = 0, y = 0; public void writer() { x = 1; y = 2; } public void reader() { int r1 = y; // TUTAJ: y == 2 => x == ? int r2 = x; } } Reordering - classic example
  • 27. @LAFK_pl, Polish JUG, May 2014 27 What was wrong with old JM(C)M? You took a look, read the specs entire and...
  • 28. @LAFK_pl, Polish JUG, May 2014 28
  • 29. @LAFK_pl, Polish JUG, May 2014 29 New Java Memory Model ● SC on single-core and single-thread CPU is fine but it doesn't cut it now ● To ensure visibility, JVM JMM spec ensures: ● final ● volatile ● Synchronized are done well thistime
  • 30. @LAFK_pl, Polish JUG, May 2014 30 Barriers in Java – rules ● JMM ● volatile – sfence after write, lfence before read ● final – sfence after init (field visibility) ● Atomic instructions (like lock) = mfence
  • 31. @LAFK_pl, Polish JUG, May 2014 31 Further topics ● Why MCM and not a threading library? H.Boehm ● Better MCM? Sarita Adve ● Possible optimizations and their gains ● Performance of Java and hardware MCMs? Clashes? ● JMCM rules in more detail