Project Issues Changes I made in my project

  • Slides: 6
Download presentation
Project Issues • Changes I made in my project: – AST. h: Ichanged the

Project Issues • Changes I made in my project: – AST. h: Ichanged the declaration of method generate in the ASTExpression class to this: virtual string generate() const = 0; Get familiar with the stl string class and its methods data, append, and erase. – Modified Garnet. h to declare extern ofstream jfile; – I modified main to • • Take a single argument (a filename like prog. g), Store the base filename (like prog) Manufacture the jfilename (like prog. j) Do jfile. open(jfilename) – I modified garnet. y to| jfile << $1 ->generate(). data() << endl; Lecture #29 PLP Spring 2004, UF CISE 1

What does a generate method look like? string ASTExpression. List. Compound: : generate() const

What does a generate method look like? string ASTExpression. List. Compound: : generate() const { return (left->generate()). append(“popn”). append(right->generate()); } string ASTExpression. List. Empty: : generate() const { return “getstatic Garnet. Ptr/Nil. Object LGarnet. Ptr; n”; } Lecture #29 PLP Spring 2004, UF CISE 2

Dynamic Memory Management • Heap storage is used to allocate data objects whose extent

Dynamic Memory Management • Heap storage is used to allocate data objects whose extent is unknown. Data objects whose extent is bound to a block can be allocated on the program stack (inside an activation record). • When heap storage is used, either the programmer is responsible for storage recovery or an automated garbage collector can perform that task. • In all systems providing heap allocation, a storage manager must keep track of that storage which is available to be allocated (the free store). Various methods for allocation of storage are used (boundary-tag, buddy system, etc. ), and those algorithms are beyond the scope of this course. • All storage management systems, however, are subject to problems arising from fragmentation of available space. Different management algorithms deal with this issue in different ways. • In some systems, it may be possible to compact the free store. In such systems, we must be able to rewrite (update) any pointers to objects in the store. Lecture #29 PLP Spring 2004, UF CISE 3

Storage Reclamation (Reference Counting) • Referencing counting is a simple mechanism for attempting to

Storage Reclamation (Reference Counting) • Referencing counting is a simple mechanism for attempting to automate the reclamation of inaccessible data. • In this scheme, each allocated address is associated with a reference count that keeps track of the number of pointers pointing to that address. Whenever the reference count reaches 0, the object can be reclaimed. • Reference counting requires – pointer assignments must update the reference count – no circular structures are created. (If a circular structure is created, then no element’s reference count can reach 0 in any legitimate use of the structure. Lecture #29 PLP Spring 2004, UF CISE 4

Storage Reclamation (Garbage Collection) • The time-honored and easiest to understand method of garbage

Storage Reclamation (Garbage Collection) • The time-honored and easiest to understand method of garbage collection is the mark-and-sweep collector. In such a collector, each storage location is outfitted with a single used/unused bit initialized to unused. • We start from each statically available pointer in the program, recursively marking each unused storage block we come to as used. Whenever we encounter a used storage block, we backtrack. • When we’ve finished the marking task, we look at each storage block in memory, linking all unused blocks into a free block list. • Finally we swap the sense of the used/unused bit values, because next time we collect garbage, we’ll need to change the bit value of some blocks currently marked used. • Copying collectors move data from a dirty store to a free store. • Generational collectors try to group data of the same age together. Experience (and lots of data) has shown that doing this can led to better locality in garbage collection. Old storage that has stayed around and not become garbage is less likely to become garbage than new storage. Lecture #29 PLP Spring 2004, UF CISE 5

Exception Handling: Not the same as Procedure Activation • Exceptions handlers do not have

Exception Handling: Not the same as Procedure Activation • Exceptions handlers do not have activation records on the stack. • Exceptions may be raised by any instruction, and the handler must be determined dynamically. • In most languages, the applicable exception handler is determined by the type of the exception raised. This means that type information must be stored at runtime. Proper handling of exceptions is partly what motivated C++ run-time type identification (RTTI). • Because exception handlers are bound dynamically, they provide an interesting control structure to programmers. Consider that you can use a throw to cause control to transfer to a dynamically enclosing context potentially many activation records up the stack frame. Lecture #29 PLP Spring 2004, UF CISE 6