05-runtime - Runtime organization The procedure abstraction...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Runtime organization The procedure abstraction supports separate compilation: allows us to build large programs keeps compile times reasonable requires independent procedures The linkage convention: a social contract machine dependent division of responsibility The linkage convention ensures that procedures inherit a valid run-time environment and that they restore one for their parents Linkages execute at run time Code to make the linkage is generated at compile time Copyright c 2007 by Antony L. Hosking. Permission to make digital or hard copies of part or all of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for proFt or commercial advantage and that copies bear this notice and full citation on the Frst page. To copy otherwise, to republish, to post on servers, or to redistribute to lists, requires prior speciFc permission and/or fee. Request permission to publish from hosking@cs.purdue.edu. CS502 Runtime organization 1 The procedure abstraction The essentials: on entry , establish p s environment at a call , preserve p s environment on exit , tear down p s environment in between , addressability and proper lifetimes pre-call post-return prologue procedure p epilogue prologue procedure q epilogue Each system has a standard linkage CS502 Runtime organization 2 Procedure linkages Assume that each procedure activation has an associated activation record or frame ( at run time ) Assumptions: RISC architecture can always expand an allocated block locals stored in frame arguments incoming arguments outgoing argument n argument 2 argument 1 . . . saved registers temporaries return address argument 2 argument 1 . . . argument m higher addresses lower addresses pointer stack frame pointer local variables previous framenext frame current frame CS502 Runtime organization 3 Procedure linkages The linkage divides responsibility between caller and callee Caller Callee Call pre-call prologue 1. allocate basic frame 2. evaluate & store params. 3. store return address 4. jump to child 1. save registers, state 2. store FP (dynamic link) 3. set new FP 4. store static link 5. extend basic frame (for local data) 6. initialize locals 7. fall through to code Return post-call epilogue 1. copy return value 2. deallocate basic frame 3. restore parameters (if copy out) 1. store return value 2. restore state 3. cut back to basic frame 4. restore parents FP 5. jump to return address At compile time, generate the code to do this At run time, that code manipulates the frame & data areas CS502 Runtime organization 4 Run-time storage organization To maintain the illusion of procedures, the compiler can adopt some conventions to govern memory use: Code space Fxed size statically allocated ( link time ) Data space Fxed-sized data may be statically allocated variable-sized data must be dynamically allocated some data is dynamically allocated in code...
View Full Document

Page1 / 7

05-runtime - Runtime organization The procedure abstraction...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online