the basics major concerns
play

The Basics Major concerns Explicit memory management Reclaiming - PowerPoint PPT Presentation

The Basics Major concerns Explicit memory management Reclaiming objects at the right time Garbage collection Discriminating live objects from garbage Both Fast allocation Fast reclamation Low fragmentation 2


  1. The Basics

  2. Major concerns  Explicit memory management  Reclaiming objects at the right time  Garbage collection  Discriminating live objects from garbage  Both  Fast allocation  Fast reclamation  Low fragmentation 2

  3. Automated memory management  Runtime system automatically  Detects dead objects (garbage detection)  Reclaims dead objects (garbage reclamation)  Garbage collection  Preserves software development time  Relieves programmer burden  Less prone to errors  Utilized by most modern OOP and scripting languages  Python, Java, C#, php 3

  4. Runtime system performs GC  E.g. Java virtual machine (JVM)  Software execution engine that executes your Java programs  Java interpreter that converts byte code into OS specific commands  Handles related tasks  Memory management (GC implemented in JVM)  Security  Multithreading 4

  5. Major concerns  Explicit memory management  Reclaiming objects at the right time  Garbage collection  Discriminating live objects from garbage  Both  Fast allocation  Fast reclamation  Low fragmentation 5

  6. Layout of a program in memory High address Command line args and environment variables stack heap Uninitialized data Initialized to 0 by exec (bss) Initialized data Read from program file by exec Text / code Low address 6

  7. Determining object liveness  Live objects are needed in the computation  Now or in the future  Prove that an object is not live (dead) and reclaim its storage  Reclaim dead objects soon, after it is last used  How do we estimate liveness in practice?  Approximate liveness by reachability from outside the heap  Unreachable objects are garbage (reclaim storage)  Reachable objects are live and must not be reclaimed 7

  8. Identifying garbage  reference counting stack heap (reachability)  An integer is associated with every object, summing 2 0  Stack references 1 1  Heap references 1 1  Objects with reference 0 0 count of zero are dead 0 2 8

  9. Problems with reference counting • Standard problem is that stack heap objects in cycles (and those touched by such objects) cannot be collected (reclaimed) 1 0 1 1 • Overhead of counting 1 1 can be high 0 0 0 2 9

  10. Identifying garbage  Tracing (reachability)  Trace reachability from root set  Processor registers  Program stack  Global variables  Objects traced are reachable  All other objects are unreachable (garbage) 10

  11. The marking phase  To find the dead objects, use the process of calculatus eliminatus  Find all live objects  All others are dead 11

  12. The marking phase • To discover the dead stack heap objects, we – Find live objects • Pointers from the stack to the heap make objects live 12

  13. The marking phase • To discover the dead stack heap objects, we – Find live objects • Pointers from the stack to the heap make objects live • These objects make other objects live 13

  14. The sweep phase • To discover the dead stack heap objects, we – Find live objects – Sweep all others away as dead 14

  15. Mark and sweep: Tracing example • To discover the dead stack heap objects, we – Find live objects – Sweep all others away as dead – Perhaps compact the heap – Problem: – Mark phase can take unbounded time 15

  16. Garbage collection design choices  Stop-the-world  Incrementality  Hybrid  Concurrency  Parallelism 16

  17. Stop-the-world collectors  Typically used on uniprocessor systems  Suspend application  Run collector from start to finish  Resume application 17

  18. Stop-the-world collectors  Execution costs?  Pause time  Discovery of live objects (how long does it take?)  Instruction overhead (per instruction)  Delay between object death and collection  Number of collectible objects collected  Overall execution time  Worst-case vs average case performance  frequency 18

  19. Incremental collection  Interleave GC with application  Note: for full heap tracing  Pause time increases with heap size  Incremental tracing  Bounded tracing time  Conservative assumption  All other objects in heap are live  Remember pointers from objects in heap  Add such pointers to root set for tracing 19

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend