CC UNIT - 4 Chapter-2 Notes - 20200412091732

You might also like

Download as pdf
Download as pdf
You are on page 1of 14
o Db. oy ss , sea consmeacrtica | PoKP ATH, rR COMPLUER CONSTRUCTION Poly J 7 LTD “iS yo MvsRbe | } a Glee mwak al ; ; ers i = Lone! Unit-4. (part-1) *\ — obshrartions, weans a. eae up-Time Environments fae temas Stores dala ates Run-Time operrhes,. Oh, 2 comer utd the tore allecstn and rove aces to varies and ata. a 2 $e seman “ha cornet, 12 de es mee Garbage collection frond Wake Crenbr ard manny cd trace Ee chine _auvite ninenk, oan Tm which 1b Attiames 2 Storage Organization frat el eas & —Prom eympiley point of View, the ave being ove : tavadl pnognamn Shar if Linder 3 y = prey Axetution , wil nun in 1B Own Logical space, jn which enc progeawe has tr bo tatin ~ Manngunnt & vr goniachi of Logic Spee ig Shaved bly Compiley, oe aod freg etm mat ne « . oparety Syren: = 0S mops Logik etavew into phy sical oddvers: Sto wtthte Space af nnndive Fo Meminnm tibuy ‘L other awene STALK rere = ston a, cre {| Sub-dir are weds axe opp,ends of eAANEO Statics. Dynamic Allocation Sprcer seshatk qnows towards |. © Statics Compile time, Dynami: Runtine sloeation lower addrereds and Beap ghout fonards . nego. oddveres ‘¢ Many compilers use some combination of following C7, Sgihstoragefr toca variaies, parameters and io on ‘ vt ens ean strag;date tht ayo the call tothe procedure that ested it 2 eat” * stack allocation is a valid allocation for procedures since procedure calls are nested Starks b wred 40 Shove dala. Srxnetnwu tamed ip elwetion eco, abs dolaogeneraked din procedure Pca : Scanned with CamScanner IR PVC ITVY un ANAGEMENT ders with moinl — HEAP TS ov poxtivo oF arowage Hv aL in, navi nesidee for parognow) exc plicnthy deletes it: ue aa wit Weop woauns denen maton duchy with the » He cto heap shot - tong tive, Ww alMcmouManager, Keeps Eratk of © Twobasic functions: reege an veqana le wees © location —— Wm WIE an Vasiobe [ober tdaes wo Foy + eatesaton meen onlin heap nom + properties of memory maagers: ov op ncaperted afae. «Space eteeney an © Program efficiency memo en «eens dentlased | bpace. tote tere. 1 ee oe pool 9) nee Spexte , aihocativns seciucerdn alae 1h com Teme Fre Space Ee Je eusfert £9: eatishy othew alto cocbiro neque’ Spoce ef fidencys se memovy Manrgor choo abnieys wintwige He tok heap space needed hy @ Preanag Doing Bo, . makes Lowgur Programs to @ xem in atw yivivel | Addon $202 no4nown ef Aciendy: Memory WAhngey thon ena af ee mernony Sab Syste, tp atlory pregrans, Nun Sh. gt Scanned with CamScanner Typicnk Memory Hurae: tori quucacttene *- ARN Memo) Heociy Oe 2 Typ Sas ‘ype Accs Fines psn Feeatareay pe | asta . tr ‘256MB - 268 ‘Physical Memory 100 + 150 ns! t : vwsxo-un [ante Cae 0-00 i (reliance, vw-oixn [tel Cae Seats saws’ [niga (rae " Legistérs (I ) 1 ele vivian i i =P ‘The conventional wisdom is that programs spend 90% of ther time executing 10% of the code: ei: '* Prograins often contain many instructions that are never executed. ** Onlya smal fraction ofthe code that could be invoked is actually executed ina typical run of the program. ‘© The typical program spends mast ofits time executing innermost loops and tight recursive cycles in a program. Part of a Heay onby tinked free aa ng hike A het Chunk Bd Chak Iwan 1 120 . grows park ‘of o Yeap; with Bu Chanks . ArBiC i. ap Side 100 > been de-oltoceted nal Bien cto free ete . a Fae Ts apt olf 9 = pbove. fg adjacent Scanned with CamScanner HE Po sph fo aloo Pree ta He above emample- Do. Apbs Boo bytes Tree Spacer ; ae i AB wD Be #!s : a a not oawarttable Fox a 7 a ; — $0, ABR are tv be conlesced & we gho! Nemove one of tem from fhee - Jren, it TS Potsble Te tmromsprare pol nrers, . the bal te meplace AUB by ove ewaterced Bhim dD Jd Jd on Doth That Cannot. be mefenened ie called wd ey rave pwbowable yourbye- cottectoy mechamicwa ' A Garbage Collection ‘Programming is easier ifthe run-time system “garbage-collects" makes space belonging to ‘unusable data available for reuse vy * Java does it; C does not, * But stack allocation inC gets some of the advantage. vance metties: 1. Speed ~- low overhead for garbage collector _Be Tittle program interruption. ‘+ Many collectors shut down the program to hunt for garbage. _A® Locality ~ data thats used togethers placed together on pages, cache-ines + AC Overall execution time = Je ast be glow , ob epencling pon the a sae Snip oP daly Me had to Z " 7 : 7% Pause time ae ghowtd leak. voit ) | avoid Fv Aan Gowen tives | ond “Maka w bed c wet ve pf He ownstanle tow" memory « . hats wilh u Bee ni $0) YE AE important po ininiraige He FAME time for Brogeony comed by GC BEITUCCU ET ' Scanned with CamScanner nts number of + "The simples (butimpertet) method eto give each ceca reference counts numberof ences to this object. © Oki objects have no internal references. ‘© Initially, object has one reference. » # freference count becomes 0, object is garbage and its space becomes availabe. : saan eta lero ee Tae ean hy Pe Praene 3 a eter ak yassanbles 5 So harmaainrpaiig hold i | & tne Sack: df fraeels > pecctrererme 77 PP Or aly nendhnble rob: Bil ohjeck> HO te corns Disadvantages ofreferencecountingare: OY Lg > Expensive von nenchals > cannot collect cyclic data structures _objesk Atlotattongs tease axe Performed bp mine Oe! whith ebwnt a neforoncé Fo he. Ten} i chunk, of memory S objects owe. pared Pro artvochor pings Relea en fom. parame Uy at neferon weorts + Say UY as Loference Og Ds: “tse, “un neffo obser, Je Moy ove ~ z ey Log: oviginal refs 5 Br eaten objec, yon iF 1S ataoled Scanned with CamScanner | a Almost out phe“ Compilers. Fors slowge. Hoar» wre/ x 7 protedwces “0s umilr of Unerrdelined raphors 7 t | manage , attest ov prt of bhery Nwn~tine memory mm Stach A if ‘ », / oo Eovh we He Stack Allocation of Spac: ee 7 proteduwt’ do toed , Sprce For when pnotednrt dy Forminabed, Lotal vars ds pashed Spoce do popped Promy Stauk> OMA MH Om inte Stau pss -astows, FS ehaankado Con | Ekoengic space , negowd ion oP ne - Leamence of pnotedure € Sighasionsean elu a Stare owocdin will & nik be wel, Th og Proceclave cols 4 Ov € “Debivelions” of. protec did nok nese to Hie: ats Axvomple will © Susbrntale phe necting of function, Calls € = Barlow giver Seawonsess Sggorh He seamen * @anatonctmiicset CUM Monk wight Dubulk Frew on everrtin OF He prtognam+ . Go. Pas. enerdtion, Hre tae to powtthion (1,4) syebavn , $0 ali] throngh nC2) bold demeniz les Hon He chosen Separator vent Ve wivie~We lage, © tano ofa) * 3, @ elements are 1 als) rent mcbivedions owe necked Cc = fo tre mbove Rrorrlty | PMO snocedave P_ Cals ¢ , 1 a Me taaie arse ond befowe Ps a ; NN . Scanned with CamScanner bbe 4% commm Cases Mader oy ok Po ens ay bm sible ne narcmally + € Activadinos for, ‘Quick Sort! x achwichn of ~ ne aie pro Lede * cued ~ ve by Cey will end, whith Bg wy execs ko hertiealt “yscowhiont + : etre a 4 : aetivation of GY iN Sree a dorminakes beat of 7 | sere nan Io «Hew IPs reave nut) ay , wile y represents activations of procedaved duvig ms He nunnirg of embive prugrom hy d ‘ aN = Both AVAL ts one frees r (1,9) achvichon. pus 2 — monty jo poy 0,3) as 9) the a rode es mh of Re ra) “q(1,0. t.9) ats. 5) (7-8) oti eating Goo 2 cede cals andetuns are seuly managed by anne tack alld the contol stack A Eactive activation hasan activation record (sometimes coiled a frame) The root of activation tees atthe bottom of the stack “the catent execution ath species the content of he stack with the las activation has record inthe top of the stack. l General ctivation Reco j Jose a yun-time Stack enables Fhe followin ie navy ‘ heby een Athivedion tree porgabes 7 hohaviowls Gear r of procedure calle covrusponda 2 : pre-odiy cavatnl » ity te —' Se eo Po L2 weg eR te oelor traversal, Scanned with CamScanner A Geneeal’ ’ Activatinn = owising From tvals of exp. & (oni be stored oa across e = pushed lines io He chal Ered go tv | ere os Hoar have TS ended e = nr oueroy “O in globes gpace Sn aitocated (2 or be been ody of a ond bi Rest call, 1m bod Se lea pe pearl D) contwol efi pant)» P do alt)3). Sw abirabth Gallingseauence ( Protedwnt cata ave G_| Tmmplemented by calling Strmnint ft sya) | - The caller evaluates the actual parameters The caller stores a return address and the old value of top-sp into the callee's activation record. Tecile ovestereiterwhesanatersatisitomton, Re of Gace + tha cate initializes local data and begins execution: poiader vation record Foi “CLs Comteant Space Foy Leeab — The Top of istncte, ar a betfow ohteycoams, t me) s | Veer aol’ pebwens Crvamn Axe ccctivation 3% | neve why em ual: Hae newrd Foy MAM, py Sack is popped Jeanie Scanned with CamScanner 2 tener ben wenthes = fo ca ow, (ute SND Wh Poommeburcs 1,95 % ee necord for Hus ea : at stack. en _ is placed g a pene conaans Space for fa : Fe . yo & focal vanes Ze ; og a Degg ang seguneg (Privcsples bx Aesi40"% catlrg Seayuenee) , ria ‘alues communicated between caller and calle are general placed at the beginning of ealle's. vation record '* _Fixed-length items: are generally placed at the middle ee Whose size may not be known early enough: are placed at the end of activation record nd of activation reco We must locate the top-of stack pointer judiciously: a common approach isto have it point to the end of fixed length fields. Phove ig. shot how entley amd cauee wight i ‘ Sak f Lo-opernke 1 enoNey’ NG He eg a vegistor top—sp_, points tend of machine. Feld in He Currant “top athivation cauee’s A gp tre Callen Con nerovd« sviciue — Netord qnas postive wilhie the a be made po wrowo + be caller, cating “mp 80, befove HE aoible For nebte 40 cablee: control > P are can gear ekvenn Colley h grown in Page Nos ©. collew *! Scanned with CamScanner ‘The callee places the return value next to the parameters Using information inthe machine-status fed, the calle restores top-sp and other registers, and then branches othe return address thatthe caller placed inthe status eld relative to ‘Although top-sp has been decremented, the caller knows where the return value is, ‘the current value of top-sp; the caller therefore may use that value. Ms iy vinnie lavas ole ra bees a = Compile — bere aint 9 possible: Jn modern lang,, gbiers cal] aah = fir do aloo potsible ib auiocbe — pkjerts_ ref whote sae bs cnleno™ t on Atal to Save, terse, 2 gdatte 2? weed | 4 menor © ‘ 2 = Si ‘Access to Nonk ck inthis ection, we consider how procedures access thele data, Espectally important is the mechanism for finding data used within a procedure p but that dass nat elaig top. Accs _ languages where procedures con-be declaced iside-other.pcncedufes, We therefore begin with na simple case of € functions, and then introduce a language, MI. that permits both nested function eclarations and functions 35“fist-class objects" that i, functions can take functions as arguments and return functions as values. Scanned with CamScanner — $n cc & ib velated long, variables ae Voeatty “on globally » Bere) SFE empath WD Fe er cadte, i vikh in Procedue, whose Scope is — 7 For langtiages that do not atlow nested procedure declgrations allocation of storage for variables and acceés to those variables s simple: 7 ‘© Global Variables are allocated static storage. The locations of these variables remain fixed and ‘re known at compile time, Soto access any variable that is not local to the currently executing Procedure, we simply use the statically determined address. viet * Any other name must be local to the activation atthe top of the stack. We may access these variables through the topsp pointer of the stack. Issues with Nested Procedures, > Access becomes far more complicated when a language allows procedure declarations to be nested and also uses the normal static scoping rule; that is, a procedure can access variables of ‘the procedures whose declarations surround its own declaration, > The reason is that knowing at compile time that the declaration of p is immediately nested Within q does not tell us the relative positions of their activation records at run time. In fact, sinee either p or qor both may be recutsive, there may be several activation records of p and/or gon the stack 7 > Finding the declaration that applies to a nonlocal name x in a nested procedure p is 2 static decision; it can be done by an extension of the static-scope rule for blocks. Suppose x is declared in the enclosing procedure @, Finding the relevant activation of q froman activation of p is a ‘dynamic decision; it requires additional run-time information about activations. One péssible solution to this problem isto use "access links" 5 ‘Aanguage with Nested Procedure Declarations «fat is a functional language, meaning that variables, once decared and intsizes, are not changed. * ‘There are only a few exceptions, such as the array, whose elements can be changed by special function calls. « Variables are defined, and have their unchangeable values initialized, by ‘a statement of the form: \ val (name) = (expression) “ « Functions are defined using the syntax: Ls = =o = = =2 2 Scanned with CamScanner = Sete ay ented end rag. to Fond. TIP osetyay Be gf thon called aubeksoveLis4) to Sant | overt dp oar = The acces LOX. from ayrcesoct lt 9) pots Ee a Deund phe Sock, RE become, gtk is the oe cs ne A" nerved firs” twerbunding OV" a4 Tun (name) (arguments) )= (body) palo enope __ For function bodies we shall use letstatements ofthe form: let (ist of definitions) in (statements) end example, © [Nesting Depth % Let us give nesting depth 1 to procedures that are not nested within any other procedure. Fer rit al C functions are at nesting depth 1. However, if a procedure p is defined immediately procedure at nesting depti, then ave pthe nesting depth + step bhabic = mal ong ww GT Ascesstinks — 8 diverts plement otha by ad ed Funchio ont | Msator called Yo Acces Late #9 On <2 Gp procedme”P isp ee jnanediiodel within prote “ai yn Source code, atteys ake = (b) ) aceess tink | [Pion sore Cinpnt Ble , oweprt 6 ) oa os foro C10) 9 fan nenddveng Linpeb File) = 019) Aan onsttkse Lyn) = Vee Scanned with CamScanner Tit te calla. Pusdin ©) dao wih 1p a foray bd & | 7 attain parrmetor do: fan e(@) 2 ot) et leiy et can esckivabion werd for prove Hea fae ov He gyacks The ocest ink for “¢ potds fo the, necord for “R, Bate C n_defined one problero w Ye teen lL Sinw opproadn {B, +o non-loesl data ts Peat IP the neitg depth gue | Loge, We may have tv follow “Long Chiind of Ike to don wee med. A Mort edfrnet lymphemantettio neal HE ten Nes ewe woes awonlinoy Nm Called Bey Perey dar ena s nerity depth, Scanned with CamScanner a 3 fl We DTN e dle ok wa Her) dCi) IS & path eT oe a higher acHendion netovd on Staak for Arf pocedne ob mah?G deptta 2+ Lo ale) hols» pe the higher yerrd oF dept %- and A ne higher com ot den pawn , clave “py ~ sas “re yok iE pnocee = — pavontege of SUE MO obo axteetsy element yy Quer ond Te nee oc, belonging +9 Sve only io aL we follow i : ‘wy wore 19 —" powtcestan vocbie? wp Ce 3S be hatiay , ye y \ Scanned with CamScanner

You might also like