SlideShare a Scribd company logo
Handling “Out of Memory” Errors
John Tang Boyland
ECOOP EHWS, July 25, 2005
Handling “Out Of Memory” Errors
H Current advice for handling OutOfMemoryError
– Use to find memory limits.
– Don’t! There’s nothing you can do.
– . . . but Eclipse does!
H The “Hedge” technique.
– allocate a large hedge;
– free when recovering from low memory condition.
H Desiderata
– Language Specification: What is safe if memory is low?
– Compilers: Don’t move allocation later or deallocation earlier.
– Runtime: per-thread memory restrictions.
ECOOP EHWS Handling OutOfMemoryError 1
An OutOfMemoryError occurs
?
Exception thrown here
H Recovery difficult because of “low memory” condition.
H When exception is thrown, last request is not fulfilled.
ECOOP EHWS Handling OutOfMemoryError 2
Measuring Available Memory
Exception thrown and caught
Object allocated and discarded
H A loop:
– Try allocating a HUGE array;
– Catch the exception and try again with a smaller amount.
– Repeat until no exception is thrown.
H A rough underestimate of available memory.
(More accurate than Runtime.freeMemory().)
ECOOP EHWS Handling OutOfMemoryError 3
Reasoning About OutOfMemoryError
H Could occur at any time:
– even in code “proven” not to raise an exception;
– OutOfMemoryError is a subclass of Error,
(in principle) “unpredictable” and “unpreventable” errors.
H . . . well, almost any time:
– if memory needed (allocation, boxing, concatenation);
– if stack needed (call, local var. frame);
– if exception created (NPE, ArrayStoreException, etc).
H Typical advice: don’t try to handle it.
H Alternate advice: use soft/weak references.
ECOOP EHWS Handling OutOfMemoryError 4
A “Real” Program Must Handle the Error
H Almost no realistic program can provably avoid running out
of memory.
H For example: Eclipse
– uses more memory if more files are being edited;
– memory is used by many different parts (GUI, Compiler, as-
sistance, markers etc)
H Crashing on OOME is unacceptable:
– user’s work is lost, and
– workbench left (perhaps) in inconsistent state, but
– logging errors or saving files taken memory;
H The error must be handled.
ECOOP EHWS Handling OutOfMemoryError 5
Handling OutOfMemoryError in Eclipse (1 of 2)
H Eclipse catches OOME and displays warning dialog:
– but memory is low;
– dialog appears after emergency exit fails;
– otherwise only error messages on Unix stdout.
H Eclipse 3.1 uses a larger max heap size than previously
– Normally degradation (thrashing) long precedes OOME.
– Artificially lowering the heap size gets previous behavior.
ECOOP EHWS Handling OutOfMemoryError 6
Handling OutOfMemoryError in Eclipse (2 of 2)
Exception in thread "...JavaReconciler" java.lang.OutOfMemoryError
Exception in thread "...JavaReconciler" java.lang.OutOfMemoryError
Exception in thread "...JavaReconciler" java.lang.OutOfMemoryError
Error while logging event loop exception:
java.lang.OutOfMemoryError: Java heap space
Logging exception:
java.lang.OutOfMemoryError: Java heap space
Error while informing user about event loop exception:
java.lang.OutOfMemoryError: Java heap space
Dialog open exception:
java.lang.OutOfMemoryError: Java heap space
Fatal error happened during workbench emergency close.
java.lang.OutOfMemoryError: Java heap space
Unhandled event loop exception
Reason: Java heap space
H Then dialog brought up.
ECOOP EHWS Handling OutOfMemoryError 7
The “Hedge” Technique
H Pre-allocate a large area (the “hedge”);
H When OutOfMemoryError happens, release it;
H After recovery re-allocate hedge.
Recovery time
Hedge
ECOOP EHWS Handling OutOfMemoryError 8
Difficulties Using the Hedge Technique
H Need to overestimate memory required for recovery;
H Interrupted computation may leave data inconsistent;
H finally clauses before recovery may re-throw OOME;
H Error may be thrown in thread other than the “guilty” one;
H Compiler may move allocation later or deallocation earlier;
H Cannot be made automatic.
(see next slides)
ECOOP EHWS Handling OutOfMemoryError 9
One Problem Leads To Another (1 of 3)
H To avoid corruption, we introduce “finally”:
void performAction()
{
start();
doIt();
cleanup();
}
©
void performAction()
{
start();
try {
doIt();
} finally {
cleanup();
}
}
H But what if cleanup needs memory (heap/stack) ?
ECOOP EHWS Handling OutOfMemoryError 10
One Problem Leads To Another (2 of 3)
H So we pre-allocate some memory:
void performAction()
{
start();
int[] space = new int[1000];
// Point A
try {
doIt();
} finally {
// Point B
space = null;
cleanup();
}
}
H But what if the compiler . . .
– moves the allocation later (B)?
– moves the deallocation earlier (A)?
ECOOP EHWS Handling OutOfMemoryError 11
One Problem Leads To Another (3 of 3)
H Fake uses force early allocation.
H Fake tests force late deallocation.
void performAction()
{
start();
int[] space = new int[1000];
space[45] = 1+space[fact(6)];
try {
doIt();
} finally {
if (space[45] > space[44]) {
space = null;
cleanup();
}
}
}
H We have obfuscated our program.
ECOOP EHWS Handling OutOfMemoryError 12
Placing Hedge Recovery
H At outer level
+ few code changes;
+ lock state clear;
- work undone;
H Close to allocation
+ recovery fast;
- state unclear;
H If automatic, then how is recovery invoked?
– at error point, then re-entrancy problems;
– elsewhere, then finally is still an issue.
ECOOP EHWS Handling OutOfMemoryError 13
Experiences With Hedge Recovery
H Importing Java Into Internal Representation:
– Must persist in “eras”;
– As few eras as possible;
– No easy way to use weak/soft references;
H Converted JDK 1.4.2 provided source
– 4500 source files;
– 12 hours;
– 11 OutOfMemoryErrors generated;
– (300 Mb max heap on Solaris x86).
H Avoided threading issues (single-threaded code).
ECOOP EHWS Handling OutOfMemoryError 14
Conclusions
H Hedge recovery can work.
Perhaps Eclipse could use it.
H Hedge recovery would be safer if:
– Language specified what operations need memory;
– Compilers don’t move allocation/deallocation past try-finally
boundaries;
– Threads had own memory restrictions.
H Thrashing is a good alternative for interactive programs.
ECOOP EHWS Handling OutOfMemoryError 15

More Related Content

Viewers also liked

A tool for teaching and learning
A tool for teaching and learningA tool for teaching and learning
A tool for teaching and learningKru Mew Jangtrakool
 
Everydayenglisexpressions2 091016015334-phpapp01
Everydayenglisexpressions2 091016015334-phpapp01Everydayenglisexpressions2 091016015334-phpapp01
Everydayenglisexpressions2 091016015334-phpapp01
Thabo
 
Michael louca thesis
Michael louca thesisMichael louca thesis
Michael louca thesisMichael Louca
 
سفر الخروج العهد القديم - الكتاب المقدس
سفر الخروج   العهد القديم - الكتاب المقدسسفر الخروج   العهد القديم - الكتاب المقدس
سفر الخروج العهد القديم - الكتاب المقدسIbrahimia Church Ftriends
 
Sarah ساره القس الياس مقار
Sarah ساره  القس الياس مقارSarah ساره  القس الياس مقار
Sarah ساره القس الياس مقار
Ibrahimia Church Ftriends
 
Mgt. process & organizational behaviour complete
Mgt. process & organizational behaviour completeMgt. process & organizational behaviour complete
Mgt. process & organizational behaviour completeRohit Mishra
 
تأثير الخطية و حتمية الصليب
تأثير الخطية و حتمية الصليبتأثير الخطية و حتمية الصليب
تأثير الخطية و حتمية الصليبIbrahimia Church Ftriends
 
2. ubuntu brandmark and circle of friends
2. ubuntu brandmark and circle of friends2. ubuntu brandmark and circle of friends
2. ubuntu brandmark and circle of friendsKonstantin Stalinsky
 

Viewers also liked (11)

A tool for teaching and learning
A tool for teaching and learningA tool for teaching and learning
A tool for teaching and learning
 
Everydayenglisexpressions2 091016015334-phpapp01
Everydayenglisexpressions2 091016015334-phpapp01Everydayenglisexpressions2 091016015334-phpapp01
Everydayenglisexpressions2 091016015334-phpapp01
 
Michael louca thesis
Michael louca thesisMichael louca thesis
Michael louca thesis
 
سفر الخروج العهد القديم - الكتاب المقدس
سفر الخروج   العهد القديم - الكتاب المقدسسفر الخروج   العهد القديم - الكتاب المقدس
سفر الخروج العهد القديم - الكتاب المقدس
 
Week 3
Week 3Week 3
Week 3
 
Scanitec 2012
Scanitec 2012Scanitec 2012
Scanitec 2012
 
Sarah ساره القس الياس مقار
Sarah ساره  القس الياس مقارSarah ساره  القس الياس مقار
Sarah ساره القس الياس مقار
 
Mgt. process & organizational behaviour complete
Mgt. process & organizational behaviour completeMgt. process & organizational behaviour complete
Mgt. process & organizational behaviour complete
 
تأثير الخطية و حتمية الصليب
تأثير الخطية و حتمية الصليبتأثير الخطية و حتمية الصليب
تأثير الخطية و حتمية الصليب
 
10.1007_s40090-015-0039-7 (1)
10.1007_s40090-015-0039-7 (1)10.1007_s40090-015-0039-7 (1)
10.1007_s40090-015-0039-7 (1)
 
2. ubuntu brandmark and circle of friends
2. ubuntu brandmark and circle of friends2. ubuntu brandmark and circle of friends
2. ubuntu brandmark and circle of friends
 

Similar to Memory error-talk

Exceptions in java
Exceptions in javaExceptions in java
Exceptions in java
Rajkattamuri
 
A exception ekon16
A exception ekon16A exception ekon16
A exception ekon16
Max Kleiner
 
Exceptions in java
Exceptions in javaExceptions in java
Exceptions in java
Manav Prasad
 
exceptions in java
exceptions in javaexceptions in java
exceptions in java
javeed_mhd
 
Introduction & Parellelization on large scale clusters
Introduction & Parellelization on large scale clustersIntroduction & Parellelization on large scale clusters
Introduction & Parellelization on large scale clustersSri Prasanna
 
Exception hierarchy
Exception hierarchyException hierarchy
Exception hierarchy
Ashfaaq Mahroof
 
EclipseMAT
EclipseMATEclipseMAT
EclipseMATAli Bahu
 
Distributed computing presentation
Distributed computing presentationDistributed computing presentation
Distributed computing presentation
Delhi/NCR HUG
 
Tutorial de forms 10g
Tutorial de forms 10gTutorial de forms 10g
Tutorial de forms 10g
miguel
 
Exception handling c++
Exception handling c++Exception handling c++
Exception handling c++
Jayant Dalvi
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
gopalrajput11
 
41c
41c41c
10 exceptionsin java
10 exceptionsin java10 exceptionsin java
10 exceptionsin javaAPU
 
Tomcatx troubleshooting-production
Tomcatx troubleshooting-productionTomcatx troubleshooting-production
Tomcatx troubleshooting-productionVladimir Khokhryakov
 
Synchronization problem with threads
Synchronization problem with threadsSynchronization problem with threads
Synchronization problem with threads
Syed Zaid Irshad
 
JVM memory metrics and rules for detecting likely OOM caused crash
JVM memory metrics and rules for detecting likely OOM caused crashJVM memory metrics and rules for detecting likely OOM caused crash
JVM memory metrics and rules for detecting likely OOM caused crash
Ajit Bhingarkar
 
JVM memory metrics and rules for detecting possible OOM caused crash
JVM memory metrics and rules for detecting possible OOM caused crashJVM memory metrics and rules for detecting possible OOM caused crash
JVM memory metrics and rules for detecting possible OOM caused crash
Atharva Bhingarkar
 
Exception handling and templates
Exception handling and templatesException handling and templates
Exception handling and templatesfarhan amjad
 
Exception Handling
Exception HandlingException Handling
Exception Handling
Ferdin Joe John Joseph PhD
 

Similar to Memory error-talk (20)

Exceptions in java
Exceptions in javaExceptions in java
Exceptions in java
 
A exception ekon16
A exception ekon16A exception ekon16
A exception ekon16
 
Kernel
KernelKernel
Kernel
 
Exceptions in java
Exceptions in javaExceptions in java
Exceptions in java
 
exceptions in java
exceptions in javaexceptions in java
exceptions in java
 
Introduction & Parellelization on large scale clusters
Introduction & Parellelization on large scale clustersIntroduction & Parellelization on large scale clusters
Introduction & Parellelization on large scale clusters
 
Exception hierarchy
Exception hierarchyException hierarchy
Exception hierarchy
 
EclipseMAT
EclipseMATEclipseMAT
EclipseMAT
 
Distributed computing presentation
Distributed computing presentationDistributed computing presentation
Distributed computing presentation
 
Tutorial de forms 10g
Tutorial de forms 10gTutorial de forms 10g
Tutorial de forms 10g
 
Exception handling c++
Exception handling c++Exception handling c++
Exception handling c++
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
 
41c
41c41c
41c
 
10 exceptionsin java
10 exceptionsin java10 exceptionsin java
10 exceptionsin java
 
Tomcatx troubleshooting-production
Tomcatx troubleshooting-productionTomcatx troubleshooting-production
Tomcatx troubleshooting-production
 
Synchronization problem with threads
Synchronization problem with threadsSynchronization problem with threads
Synchronization problem with threads
 
JVM memory metrics and rules for detecting likely OOM caused crash
JVM memory metrics and rules for detecting likely OOM caused crashJVM memory metrics and rules for detecting likely OOM caused crash
JVM memory metrics and rules for detecting likely OOM caused crash
 
JVM memory metrics and rules for detecting possible OOM caused crash
JVM memory metrics and rules for detecting possible OOM caused crashJVM memory metrics and rules for detecting possible OOM caused crash
JVM memory metrics and rules for detecting possible OOM caused crash
 
Exception handling and templates
Exception handling and templatesException handling and templates
Exception handling and templates
 
Exception Handling
Exception HandlingException Handling
Exception Handling
 

More from Jay Thakkar

Mongo db m101j
Mongo db m101jMongo db m101j
Mongo db m101j
Jay Thakkar
 
O pening Files w ith LOCI Bio - Formats
O pening Files w ith LOCI Bio - FormatsO pening Files w ith LOCI Bio - Formats
O pening Files w ith LOCI Bio - Formats
Jay Thakkar
 
Talk 8-Kevin-Imagej2
Talk 8-Kevin-Imagej2 Talk 8-Kevin-Imagej2
Talk 8-Kevin-Imagej2
Jay Thakkar
 
Basic image processing
Basic image processingBasic image processing
Basic image processingJay Thakkar
 
Architectural Design
Architectural DesignArchitectural Design
Architectural Design
Jay Thakkar
 
Learn Java 3D
Learn Java 3D Learn Java 3D
Learn Java 3D
Jay Thakkar
 
Dicom standard-of-china 2011-03
Dicom standard-of-china 2011-03Dicom standard-of-china 2011-03
Dicom standard-of-china 2011-03
Jay Thakkar
 

More from Jay Thakkar (7)

Mongo db m101j
Mongo db m101jMongo db m101j
Mongo db m101j
 
O pening Files w ith LOCI Bio - Formats
O pening Files w ith LOCI Bio - FormatsO pening Files w ith LOCI Bio - Formats
O pening Files w ith LOCI Bio - Formats
 
Talk 8-Kevin-Imagej2
Talk 8-Kevin-Imagej2 Talk 8-Kevin-Imagej2
Talk 8-Kevin-Imagej2
 
Basic image processing
Basic image processingBasic image processing
Basic image processing
 
Architectural Design
Architectural DesignArchitectural Design
Architectural Design
 
Learn Java 3D
Learn Java 3D Learn Java 3D
Learn Java 3D
 
Dicom standard-of-china 2011-03
Dicom standard-of-china 2011-03Dicom standard-of-china 2011-03
Dicom standard-of-china 2011-03
 

Recently uploaded

Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
Globus
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
abdulrafaychaudhry
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
Philip Schwarz
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Globus
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
vrstrong314
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
Globus
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
Adele Miller
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
wottaspaceseo
 
RISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent EnterpriseRISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent Enterprise
Srikant77
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
Ortus Solutions, Corp
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
Matt Welsh
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Natan Silnitsky
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
takuyayamamoto1800
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
Cyanic lab
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Globus
 
Graphic Design Crash Course for beginners
Graphic Design Crash Course for beginnersGraphic Design Crash Course for beginners
Graphic Design Crash Course for beginners
e20449
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
Tendenci - The Open Source AMS (Association Management Software)
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns
 

Recently uploaded (20)

Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
 
RISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent EnterpriseRISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent Enterprise
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
 
Graphic Design Crash Course for beginners
Graphic Design Crash Course for beginnersGraphic Design Crash Course for beginners
Graphic Design Crash Course for beginners
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
 

Memory error-talk

  • 1. Handling “Out of Memory” Errors John Tang Boyland ECOOP EHWS, July 25, 2005
  • 2. Handling “Out Of Memory” Errors H Current advice for handling OutOfMemoryError – Use to find memory limits. – Don’t! There’s nothing you can do. – . . . but Eclipse does! H The “Hedge” technique. – allocate a large hedge; – free when recovering from low memory condition. H Desiderata – Language Specification: What is safe if memory is low? – Compilers: Don’t move allocation later or deallocation earlier. – Runtime: per-thread memory restrictions. ECOOP EHWS Handling OutOfMemoryError 1
  • 3. An OutOfMemoryError occurs ? Exception thrown here H Recovery difficult because of “low memory” condition. H When exception is thrown, last request is not fulfilled. ECOOP EHWS Handling OutOfMemoryError 2
  • 4. Measuring Available Memory Exception thrown and caught Object allocated and discarded H A loop: – Try allocating a HUGE array; – Catch the exception and try again with a smaller amount. – Repeat until no exception is thrown. H A rough underestimate of available memory. (More accurate than Runtime.freeMemory().) ECOOP EHWS Handling OutOfMemoryError 3
  • 5. Reasoning About OutOfMemoryError H Could occur at any time: – even in code “proven” not to raise an exception; – OutOfMemoryError is a subclass of Error, (in principle) “unpredictable” and “unpreventable” errors. H . . . well, almost any time: – if memory needed (allocation, boxing, concatenation); – if stack needed (call, local var. frame); – if exception created (NPE, ArrayStoreException, etc). H Typical advice: don’t try to handle it. H Alternate advice: use soft/weak references. ECOOP EHWS Handling OutOfMemoryError 4
  • 6. A “Real” Program Must Handle the Error H Almost no realistic program can provably avoid running out of memory. H For example: Eclipse – uses more memory if more files are being edited; – memory is used by many different parts (GUI, Compiler, as- sistance, markers etc) H Crashing on OOME is unacceptable: – user’s work is lost, and – workbench left (perhaps) in inconsistent state, but – logging errors or saving files taken memory; H The error must be handled. ECOOP EHWS Handling OutOfMemoryError 5
  • 7. Handling OutOfMemoryError in Eclipse (1 of 2) H Eclipse catches OOME and displays warning dialog: – but memory is low; – dialog appears after emergency exit fails; – otherwise only error messages on Unix stdout. H Eclipse 3.1 uses a larger max heap size than previously – Normally degradation (thrashing) long precedes OOME. – Artificially lowering the heap size gets previous behavior. ECOOP EHWS Handling OutOfMemoryError 6
  • 8. Handling OutOfMemoryError in Eclipse (2 of 2) Exception in thread "...JavaReconciler" java.lang.OutOfMemoryError Exception in thread "...JavaReconciler" java.lang.OutOfMemoryError Exception in thread "...JavaReconciler" java.lang.OutOfMemoryError Error while logging event loop exception: java.lang.OutOfMemoryError: Java heap space Logging exception: java.lang.OutOfMemoryError: Java heap space Error while informing user about event loop exception: java.lang.OutOfMemoryError: Java heap space Dialog open exception: java.lang.OutOfMemoryError: Java heap space Fatal error happened during workbench emergency close. java.lang.OutOfMemoryError: Java heap space Unhandled event loop exception Reason: Java heap space H Then dialog brought up. ECOOP EHWS Handling OutOfMemoryError 7
  • 9. The “Hedge” Technique H Pre-allocate a large area (the “hedge”); H When OutOfMemoryError happens, release it; H After recovery re-allocate hedge. Recovery time Hedge ECOOP EHWS Handling OutOfMemoryError 8
  • 10. Difficulties Using the Hedge Technique H Need to overestimate memory required for recovery; H Interrupted computation may leave data inconsistent; H finally clauses before recovery may re-throw OOME; H Error may be thrown in thread other than the “guilty” one; H Compiler may move allocation later or deallocation earlier; H Cannot be made automatic. (see next slides) ECOOP EHWS Handling OutOfMemoryError 9
  • 11. One Problem Leads To Another (1 of 3) H To avoid corruption, we introduce “finally”: void performAction() { start(); doIt(); cleanup(); } © void performAction() { start(); try { doIt(); } finally { cleanup(); } } H But what if cleanup needs memory (heap/stack) ? ECOOP EHWS Handling OutOfMemoryError 10
  • 12. One Problem Leads To Another (2 of 3) H So we pre-allocate some memory: void performAction() { start(); int[] space = new int[1000]; // Point A try { doIt(); } finally { // Point B space = null; cleanup(); } } H But what if the compiler . . . – moves the allocation later (B)? – moves the deallocation earlier (A)? ECOOP EHWS Handling OutOfMemoryError 11
  • 13. One Problem Leads To Another (3 of 3) H Fake uses force early allocation. H Fake tests force late deallocation. void performAction() { start(); int[] space = new int[1000]; space[45] = 1+space[fact(6)]; try { doIt(); } finally { if (space[45] > space[44]) { space = null; cleanup(); } } } H We have obfuscated our program. ECOOP EHWS Handling OutOfMemoryError 12
  • 14. Placing Hedge Recovery H At outer level + few code changes; + lock state clear; - work undone; H Close to allocation + recovery fast; - state unclear; H If automatic, then how is recovery invoked? – at error point, then re-entrancy problems; – elsewhere, then finally is still an issue. ECOOP EHWS Handling OutOfMemoryError 13
  • 15. Experiences With Hedge Recovery H Importing Java Into Internal Representation: – Must persist in “eras”; – As few eras as possible; – No easy way to use weak/soft references; H Converted JDK 1.4.2 provided source – 4500 source files; – 12 hours; – 11 OutOfMemoryErrors generated; – (300 Mb max heap on Solaris x86). H Avoided threading issues (single-threaded code). ECOOP EHWS Handling OutOfMemoryError 14
  • 16. Conclusions H Hedge recovery can work. Perhaps Eclipse could use it. H Hedge recovery would be safer if: – Language specified what operations need memory; – Compilers don’t move allocation/deallocation past try-finally boundaries; – Threads had own memory restrictions. H Thrashing is a good alternative for interactive programs. ECOOP EHWS Handling OutOfMemoryError 15