announcements & review

35
Lecture 36: Programming Languages & Memory Management Announcements & Review Read Ch GU1 & GU2 Cohoon & Davidson Ch 14 Reges & Stepp Lab 10 set game due 4/26 Exam 2 Wed 5/2 5:30-7:30 GEO 2.216 Last few times: GUI Today: Research in Programming Languages introduction to memory management

Upload: cleo

Post on 25-Feb-2016

38 views

Category:

Documents


1 download

DESCRIPTION

Read Ch GU1 & GU2 Cohoon & Davidson Ch 14 Reges & Stepp Lab 10 set game due 4/26 Exam 2 Wed 5/2 5:30-7:30 GEO 2.216. Last few times: GUI Today: Research in Programming Languages introduction to memory management. Announcements & Review. Software Developer Dreams. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Announcements & Review

Lecture 36: Programming Languages & Memory Management

Announcements & Review

Read Ch GU1 & GU2 Cohoon & DavidsonCh 14 Reges & Stepp

Lab 10 set gamedue 4/26

Exam 2 Wed 5/2 5:30-7:30GEO 2.216

Last few times:GUI

Today: Research in Programming Languagesintroduction to memory management

Page 2: Announcements & Review

Lecture 36: Programming Languages & Memory Management

Software Developer Dreams

Page 3: Announcements & Review

Lecture 36: Programming Languages & Memory Management

Software Developer Dreams

• Easy to implement specifications• Easy to get correct• Robust to errors of all sorts• Easy to maintain• Runs fast

Page 4: Announcements & Review

Lecture 36: Programming Languages & Memory Management

Impediments to the Dream

• Applications growing bigger & more complex– Application knowledge spread thin– Testing is not enough

• Architectures growing more complex– Single core complexity– Multicore

• The glue is more complicated– Dynamic optimization & runtime systems– Coordination between multiple languages and runtime

systems– Impossible to test all scenarios

Difficult to understand the program or its runtime behavior

Page 5: Announcements & Review

Lecture 36: Programming Languages & Memory Management

Multi-pronged Approach to Correct High Performance

Software • Better languages

– Java and C# are not the last programming languages• Validation when possible

– We probably will not be able to validate substantial parallel applications any time soon

– Is application growth outpacing validation advances?• Analysis and development tools

– Static bug finding tools– Dynamic optimization– Dynamic bug finding tools

• Self healing systems– Don’t crash

• Dynamically updatable systems• Evaluation

Performance still mattersunobtrusive, low overhead approaches

Page 6: Announcements & Review

Lecture 36: Programming Languages & Memory Management

Java put garbage collection into

widespread use• In Java

– programs use “new”– objects abstract their location, i.e., a program never

records an object address – Therefore, objects can move– programs contain no “free/delete” – easier to program, since you don’t have to figure out

when an object becomes unreachable• In C and C++

– programmers use “new” and “free/delete”– programs can record the address of an object in

variables which causes errors, e.g., buffer overflow– Therefore, objects may not move

Page 7: Announcements & Review

Lecture 36: Programming Languages & Memory Management

Example• Program with classes for plates, bowls, & silverware• What happens in memory when the program says new?

Page 8: Announcements & Review

Lecture 36: Programming Languages & Memory Management

Select Plates, Bowls, Silverware Objects

Page 9: Announcements & Review

Lecture 36: Programming Languages & Memory Management

Select Plates, Bowls, Silverware

Page 10: Announcements & Review

Lecture 36: Programming Languages & Memory Management

Explicit Memory Management:

Hand Wash Dishes

Page 11: Announcements & Review

Lecture 36: Programming Languages & Memory Management

Explicit Memory Management:

Hand Wash Dishes

Page 12: Announcements & Review

Lecture 36: Programming Languages & Memory Management

Explicit Memory Management:

Hand Wash Dishes

Page 13: Announcements & Review

Lecture 36: Programming Languages & Memory Management

Explicit Memory Management:

Hand Wash Dishes

Page 14: Announcements & Review

Lecture 36: Programming Languages & Memory Management

Explicit Memory Management:

Hand Wash Dishes

Page 15: Announcements & Review

Lecture 36: Programming Languages & Memory Management

Dish Washer: Automatic Memory Management

Garbage Collection • Dad is the garbage collector• Do forever

– Prepare meal– Select plates, bowls, silverware– Serve food & Eat– Dad put dishes in dishwasher

• Dad checks if dishwasher full or • Out of plates, bowls or silverware

– Dad runs dishwasher

Page 16: Announcements & Review

Lecture 36: Programming Languages & Memory Management

Select Plates, Bowls, Silverware

Page 17: Announcements & Review

Lecture 36: Programming Languages & Memory Management

Select Plates, Bowls, Silverware

Page 18: Announcements & Review

Lecture 36: Programming Languages & Memory Management

Dad Runs Dish Washer

& Puts Up Dishes

Page 19: Announcements & Review

Lecture 36: Programming Languages & Memory Management

Memory System Organization

Registers

CPUCentral

Processing Unit

InstructionCache

DataCache

Level 2Cache

Memory

Page 20: Announcements & Review

Lecture 36: Programming Languages & Memory Management

Mapping Dishes to Computer

Resources

Class Declarations

chunks of memory

Page 21: Announcements & Review

Lecture 36: Programming Languages & Memory Management

Contiguous Allocation

Plate p = new Plate();

Page 22: Announcements & Review

Lecture 36: Programming Languages & Memory Management

Contiguous Allocation

Plate p1 = new Plate(); Plate p2 = new Plate(); Bowl b1 = new Bowl(); Fork f1 = new Fork(); Fork f2 = new Fork();Spoon s1 = new Spoon();

Page 23: Announcements & Review

Lecture 36: Programming Languages & Memory Management

Contiguous Allocation

etc.

Page 24: Announcements & Review

Lecture 36: Programming Languages & Memory Management

Explicit Memory Management

Free with Continuous Allocation

Free (b3)

Page 25: Announcements & Review

Lecture 36: Programming Languages & Memory Management

Free with Contiguous Allocation

Free (b3)Free (s1)

Page 26: Announcements & Review

Lecture 36: Programming Languages & Memory Management

Garbage Collectionwith Contiguous Allocation

Wait longer

Page 27: Announcements & Review

Lecture 36: Programming Languages & Memory Management

Garbage Collection with Contiguous

Allocation

Find live objects: L

L L

L L

Page 28: Announcements & Review

Lecture 36: Programming Languages & Memory Management

Find live objects: LCopy live objects to new area

L

Garbage Collection with Contiguous

Allocation

Page 29: Announcements & Review

Lecture 36: Programming Languages & Memory Management

Find live objects: LCopy live objects to new areaReclaim old space

L

Garbage Collection with Contiguous

Allocation

Page 30: Announcements & Review

Lecture 36: Programming Languages & Memory Management

Find live objects: LCopy them to new areaReclaim old spaceAllocate into new space

Garbage Collection with Contiguous

Allocation

Page 31: Announcements & Review

Lecture 36: Programming Languages & Memory Management

Allocation withSize-Class Free-Lists

Page 32: Announcements & Review

Lecture 36: Programming Languages & Memory Management

Free (b3)Free (s1)

Allocation withSize-Class Free-Lists

Page 33: Announcements & Review

Lecture 36: Programming Languages & Memory Management

We can use linked listsfor each list of free sizesto find the free ones

Allocation withSize-Class Free-Lists

...

...

free list size 24 bytes

free list size 20 bytes

Page 34: Announcements & Review

Lecture 36: Programming Languages & Memory Management

Memory Management• All memory management uses one of

these two basic mechanisms– Contiguous allocation – Size-Class Free-Lists

• Classic Computer Science Problem in Space-Time tradeoff

Page 35: Announcements & Review

Lecture 36: Programming Languages & Memory Management

Other Key Ideas in Memory Management

• Locality• Incrementality• Generational behavior• Older-first behavior

– My research group introduced this one!