Phoenix Lifetime Object

I like to use word "common" since .NET was born :). In Phoenix, all components use "common" keyword as well. It uses common IR, common type system, common symbol system and so on, maybe more will come soon. Anyway, I want to explain lifetime object conceptually.

When a compiler executed, it allocated dynamic memory to hold objects. In C, we use malloc to allocate and de-allocation methods to release or de-allocate memory when the work of compiler phase is done. During the period when compiler works, we need "objects" to hold "other objects". In Phoenix, object who manages the use of dynamic memory for other object called Lifetime.
 
Lifetime has limited time of period by its nature and differs radically between managed and unmanaged builds of Phoenix. In managed code, Phoenix uses CLR. For unmanaged, Phoenix itself will responsible. A Lifetime is like a broker for dynamic memory. It asks the Windows OS for chunks of memory as required, and takes care of automatically expanding the pool of memory under its care. A Lifetime starts life by requesting a few thousand bytes of memory – typically a page – from the OS. Each call to Allocate simply bumps a ‘next-free’ pointer, by the number of bytes requested. When the page is exhausted, the Lifetime automatically requests more pages from the OS.

A Lifetime pads the space between successive allocations, if required, to ensure objects are well-aligned in memory (typically to a multiple of a pointer on the host machine). A Lifetime also ensures correct results, even when calls to its Allocate method are made by multiple threads of execution, overlapped in time.

There are many kinds of Lifetime, usually can be specified by parameters during its creation, as follows: {Func, Alias, IR, Graph, SSA, Tmp, Static, Global, TmpString, Phase, Module, Profile, Sym}. You should define what kind that best matches your need on memory. Implementing Lifetime by our self will be very difficult task. We are lucky because MSR has done it for us.

Share this post: | | | |
Published Tuesday, September 05, 2006 9:29 AM by Risman Adnan Mattotorang

Comments

No Comments

Leave a Comment

(required) 
(required) 
(optional)
(required) 

Enter the numbers above: