Garbage Collection for RealTime Java Jangwoo Shin shinjgradient
Garbage Collection for Real-Time Java Jangwoo Shin (shinj@gradient. cis. upenn. edu) 8/13/2001
Overview • • • What is real-time garbage collector? Memory Organization for KVM-RT Baker’s Tri-coloring Algorithm Implementational Details References 8/13/2001
Real-Time GC • Incremental GC – Collector interleaved with mutator • Constant Time-bound operations – Root scanning, evacuation, referencing • Allocation time is proportional to size • Efficiency – Trade-off between time and space – Compaction vs. non-compaction 8/13/2001
Memory Organization • Memory as collection of cells • Objects in Memory = Directed Rooted Graph • Header contains size and type + info – depends on the GC scheme used • Memory as directed rooted graph • Compaction or not? – Fragmentation occurs w/o compaction 8/13/2001
Tri-coloring by Baker[1] • A variation of copy collector by Cheney[2] • Memory divided into From- and To-space – All allocation goes into To-space only – From-space is read-only from mutator’s view – To-space is subdivided into: • Object creation area(grows downward) • Object evacuation area(grows upward) – Areas flipped when evacuation ends 8/13/2001
Tri-coloring[cont] • Reachable objects in From-space are incrementally scavenged and evacuated into To-space, then space flipped • Read-barrier prevents mutator from accessing to objects in From-space • At any moment, an object in memory: – White: used in From-space, but not scanned – Gray: scanned but not fully scavenged – Black: fully scavenged 8/13/2001
Tri-coloring[cont] • Compared to other GC’s – Advantages: • • Exact(non-conservative) s. t. space-saving Compaction = no fragmentation – Disadvantages: • • • 8/13/2001 Wastes half the memory, roughly High overload for copying Extra code for read-barrier
Implementation • Basic operations and algorithm – Root-set scanning • – Referencing(read barrier) • – Move an object from From- to To-space Allocation • – If object in From-space then return after evacuation Evacuation • – Evacuate referred objects Create object in To-space and evacuate all referred obj’s. Scavenging While (scavenge-ptr < evacuation-ptr) if referred resides in From-space then evacuate and set forwarding pointer accordingly 8/13/2001
Implementation[cont] To-Space From-Space ADDR high ADDR mid original object to be GC’d allocation-ptr (grow downward) A. object gets evacuated to To-Space root-set referenced object B. any back-references to the From-Space are scanned for scavenging evacuated object C. scavenging copies referenced objects to To-space evacuation-ptr (grow upward) scavenge-ptr mid+1 low Fig. 1. Schematic diagram of GC algorithm 8/13/2001
Implementation[cont] • Timing Analysis – – – – Rootset scanning = O(size(rootset)) Referencing = O(indirect reference) Evacuation = O(cost of copy), can be mixed with mutator Allocation = O(size(object)) Scavenging= O(cost of copy) can be mixed with mutator Flipping: O(change few pointer values) Maximum pause: max of all above. 8/13/2001
Implementation[cont] • Object = Header + Data – Header(32 bit cell) • • • – 24 bit length field 6 bit type field 1 bit forward flag Data • • • 8/13/2001 Type and size specified by the header Contains To-space target when forwarded 2 byte tail attached if byte data header Object-ptr data
Extensions • • Generational GC: using multiple subheaps, short-lived objects are collected more quickly and frequently[3] Baker’s Treadmill: non-copying, in-place collector using doubly linked lists[4] 8/13/2001
Reference • [1] H. Baker, List Processing for Resolving Conflicts in Dynamic Storage Allocation, CACM, 21(4): 280 -294, April 1978. • [2] C. J. Cheney, A nonrecursive list compacting algorithm, CACM, 13(11): 677 -678, Nov. 1970. • [3] H. Lieberman and C. Hewitt, A Real-Time Garbage Collector Based on the Lifetimes of Objects, CACM, 26(6): 419 -429, June 1983. • [4] H. Baker, The Treadmill: Real-Time Garbage Collection Without Motion Sickness, ACM Sigplan Notices, 27(3): 66 -70, March 1992. • [5] P. Wilson, Uniprocessor Garbage Collection Techniques, In Proceedings of the International Workshop on Memory Management St Malo, France, pp. 1 -42 Springer-Verlag, September 1992, LNCS 637. 8/13/2001
- Slides: 13