1 / 16

Programming with Regions

Programming with Regions. Chris Durham CSCI 297 June 16 th , 2005. Paper. Language Support for Regions , David Gay and Alex Aiken; UC Berkeley, 2001. Memory Management Issues. Allocation / Deallocation mismatch malloc() / free() Dereference ‘dangling’ pointers

alta
Download Presentation

Programming with Regions

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Programming with Regions Chris Durham CSCI 297 June 16th, 2005

  2. Paper Language Support for Regions, David Gay and Alex Aiken; UC Berkeley, 2001

  3. Memory Management Issues • Allocation / Deallocation mismatch • malloc() / free() • Dereference ‘dangling’ pointers • Heap fragmentation, boundary issues • Sizing, when to allocate • Remembering to free() !

  4. Garbage Collection Questions • When to scan? • How often? • Rearranging? Paper states that they did some work with gcc and the Boehm-Weiser garbage collector

  5. Regions Concept to address some of these issues • All allocations of a particular ‘type’ allocated to same ‘region’ • Reference count kept to the ‘region’ • Can only deallocate region after no references exist; deallocates all ‘objects’ within the region • Best used for complex data structures

  6. Example (1) reference count = 1

  7. Example (2) reference count = 2

  8. Example (3) reference count = 2

  9. Region Benefits • Region can only be de-allocated when reference count == 0; attempts abort program when checking enabled • Rely on region library to optimize heap usage and make garbage collection easier - presumably, implementation of regions is well structured and uses knowledge of allocator • Programmer doesn’t necessarily have to focus on memory management to same degree as with traditional malloc()/free() • In some ways, this concept is similar to resource pooling as in Apache, but is unstructured

  10. RC Compiler A library and compiler (rcc), compiles annotated code to C code. Introduces several annotations http://www.cs.berkeley.edu/~dgay/rc Also: Cyclone has its own region sub-system

  11. Code snippet struct rlist {struct rlist *sameregion next; struct finfo *sameregion data; } *rl, *last = NULL; region r = newregion(); while (…) { rl = ralloc(r,struct rlist); rl->data = ralloc(r,struct rlist); /* fill in data */ rl->next = last; last = rl; } output_rlist(last); deleteregion(r);

  12. Pointer annotations et al • sameregion: in same region • traditional: not in a region at all • parentptr: you can have sub-regions, this means this pointer exists in the region one level higher • struct Foo *sameregion foo; • struct Bar *traditional bar; • struct Parent *parentptr parent; • struct region has a member ‘rc’ for reference count • regionof() to determine what region an identifier is in Also: a constraint inference system that proves some type safety situations was built into rcc, enables them to remove some runtime checks that verify the type constraints to speed things up

  13. Results

  14. Conclusions Regions can help make memory management easier by eliminating the need for the programmer to concentrate on some memory management issues and it even speeds up things a bit over traditional methods As we discussed previously, benchmarks and real life are two different things - no real test of the robustness of the region library itself

  15. Original Problems? / New Problems Of the original problems, which ones do regions address? What new challenges are there for the programmer? What are the security implications here?

  16. References • Language Support for Regions; David Gay and Alex Aiken; UC Berkeley, 2001 • Region-Based Memory Mapping in Cyclone, Dan Grossman, Greg Morrisett, Trevor Jim, Michael Hicks, Yanling Wang, James Cheney; Cornell University 2002

More Related