SlideShare ist ein Scribd-Unternehmen logo
1 von 16
Downloaden Sie, um offline zu lesen
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

Weitere ähnliche Inhalte

Andere mochten auch

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-phpapp01Thabo
 
Michael louca thesis
Michael louca thesisMichael louca thesis
Michael louca thesisMichael Louca
 
سفر الخروج العهد القديم - الكتاب المقدس
سفر الخروج   العهد القديم - الكتاب المقدسسفر الخروج   العهد القديم - الكتاب المقدس
سفر الخروج العهد القديم - الكتاب المقدس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
 

Andere mochten auch (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
 

Ähnlich wie Memory error-talk

Exceptions in java
Exceptions in javaExceptions in java
Exceptions in javaRajkattamuri
 
A exception ekon16
A exception ekon16A exception ekon16
A exception ekon16Max Kleiner
 
Exceptions in java
Exceptions in javaExceptions in java
Exceptions in javaManav Prasad
 
exceptions in java
exceptions in javaexceptions in java
exceptions in javajaveed_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
 
EclipseMAT
EclipseMATEclipseMAT
EclipseMATAli Bahu
 
Distributed computing presentation
Distributed computing presentationDistributed computing presentation
Distributed computing presentationDelhi/NCR HUG
 
Tutorial de forms 10g
Tutorial de forms 10gTutorial de forms 10g
Tutorial de forms 10gmiguel
 
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 javagopalrajput11
 
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 threadsSyed Zaid Irshad
 
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 crashAtharva Bhingarkar
 
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 crashAjit Bhingarkar
 
Exception handling and templates
Exception handling and templatesException handling and templates
Exception handling and templatesfarhan amjad
 

Ähnlich wie 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 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
 
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
 
Exception handling and templates
Exception handling and templatesException handling and templates
Exception handling and templates
 
Exception Handling
Exception HandlingException Handling
Exception Handling
 

Mehr von 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 - FormatsJay 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 DesignJay Thakkar
 
Dicom standard-of-china 2011-03
Dicom standard-of-china 2011-03Dicom standard-of-china 2011-03
Dicom standard-of-china 2011-03Jay Thakkar
 

Mehr von 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
 

Kürzlich hochgeladen

Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...SelfMade bd
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastPapp Krisztián
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024VictoriaMetrics
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...Jittipong Loespradit
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park masabamasaba
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationJuha-Pekka Tolvanen
 
tonesoftg
tonesoftgtonesoftg
tonesoftglanshi9
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...Shane Coughlan
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrandmasabamasaba
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...masabamasaba
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...masabamasaba
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2
 

Kürzlich hochgeladen (20)

Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaS
 

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