InterpreterStackFrame.cpp 363 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft Corporation and contributors. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. #include "RuntimeLanguagePch.h"
  6. #include "RuntimeMathPch.h"
  7. #include "EHBailoutData.h"
  8. #include "Library/JavascriptRegularExpression.h"
  9. #if DBG_DUMP
  10. #include "ByteCode/OpCodeUtilAsmJs.h"
  11. #endif
  12. #include "Language/InterpreterStackFrame.h"
  13. #include "Library/JavascriptGeneratorFunction.h"
  14. #include "Library/ForInObjectEnumerator.h"
  15. #include "Library/AtomicsOperations.h"
  16. #include "../../WasmReader/WasmParseTree.h"
  17. ///----------------------------------------------------------------------------
  18. ///
  19. /// macros PROCESS_INtoOUT
  20. ///
  21. /// This set of macros defines standard patterns for processing OpCodes in
  22. /// RcInterpreter::Run(). Each macro is named for "in" - "out":
  23. /// - A: Var
  24. /// - I: Integer
  25. /// - R: Double
  26. /// - X: Nothing
  27. ///
  28. /// Examples:
  29. /// - "A2toA1" reads two registers, each storing an Var, and writes a single
  30. /// register with a new Var.
  31. /// - "A1I1toA2" reads two registers, first an Var and second an Int32, then
  32. /// writes two Var registers.
  33. ///
  34. /// Although these could use lookup tables to standard OpLayout types, this
  35. /// additional indirection would slow the main interpreter loop further by
  36. /// preventing the main 'switch' statement from using the OpCode to become a
  37. /// direct local-function jump.
  38. ///----------------------------------------------------------------------------
  39. #define PROCESS_FALLTHROUGH(name, func) \
  40. case OpCode::name:
  41. #define PROCESS_FALLTHROUGH_COMMON(name, func, suffix) \
  42. case OpCode::name:
  43. #define PROCESS_READ_LAYOUT(name, layout, suffix) \
  44. CompileAssert(OpCodeInfo<OpCode::name>::Layout == OpLayoutType::layout); \
  45. const unaligned OpLayout##layout##suffix * playout = m_reader.layout##suffix(ip); \
  46. Assert((playout != nullptr) == (Js::OpLayoutType::##layout != Js::OpLayoutType::Empty)); // Make sure playout is used
  47. #define PROCESS_NOP_COMMON(name, layout, suffix) \
  48. case OpCode::name: \
  49. { \
  50. PROCESS_READ_LAYOUT(name, layout, suffix); \
  51. break; \
  52. }
  53. #define PROCESS_NOP(name, layout) PROCESS_NOP_COMMON(name, layout,)
  54. #define PROCESS_CUSTOM_COMMON(name, func, layout, suffix) \
  55. case OpCode::name: \
  56. { \
  57. PROCESS_READ_LAYOUT(name, layout, suffix); \
  58. func(playout); \
  59. break; \
  60. }
  61. #define PROCESS_CUSTOM(name, func, layout) PROCESS_CUSTOM_COMMON(name, func, layout,)
  62. #define PROCESS_CUSTOM_L_COMMON(name, func, layout, regslot, suffix) \
  63. case OpCode::name: \
  64. { \
  65. PROCESS_READ_LAYOUT(name, layout, suffix); \
  66. func(playout); \
  67. break; \
  68. }
  69. #define PROCESS_CUSTOM_L(name, func, layout, regslot) PROCESS_CUSTOM_L_COMMON(name, func, layout, regslot,)
  70. #define PROCESS_CUSTOM_L_Arg_COMMON(name, func, suffix) PROCESS_CUSTOM_L_COMMON(name, func, Arg, Arg, suffix)
  71. #define PROCESS_CUSTOM_L_Arg2_COMMON(name, func, layout, suffix) PROCESS_CUSTOM_L_COMMON(name, func, layout, Arg, suffix)
  72. #define PROCESS_CUSTOM_L_Arg(name, func) PROCESS_CUSTOM_L_COMMON(name, func, Arg, Arg,)
  73. #define PROCESS_CUSTOM_ArgNoSrc_COMMON(name, func, suffix) PROCESS_CUSTOM_COMMON(name, func, ArgNoSrc, suffix)
  74. #define PROCESS_CUSTOM_ArgNoSrc(name, func) PROCESS_CUSTOM_COMMON(name, func, ArgNoSrc,)
  75. #define PROCESS_CUSTOM_L_R0_COMMON(name, func, layout, suffix) PROCESS_CUSTOM_L_COMMON(name, func, layout, R0, suffix)
  76. #define PROCESS_CUSTOM_L_R0(name, func, layout) PROCESS_CUSTOM_L_COMMON(name, func, layout, R0,)
  77. #define PROCESS_CUSTOM_L_Value_COMMON(name, func, layout, suffix) PROCESS_CUSTOM_L_COMMON(name, func, layout, Value, suffix)
  78. #define PROCESS_CUSTOM_L_Value(name, func, layout) PROCESS_CUSTOM_L_COMMON(name, func, layout, Value,)
  79. #define PROCESS_TRY(name, func) \
  80. case OpCode::name: \
  81. { \
  82. PROCESS_READ_LAYOUT(name, Br,); \
  83. func(playout); \
  84. ip = m_reader.GetIP(); \
  85. break; \
  86. }
  87. #define PROCESS_EMPTY(name, func) \
  88. case OpCode::name: \
  89. { \
  90. PROCESS_READ_LAYOUT(name, Empty, ); \
  91. func(); \
  92. ip = m_reader.GetIP(); \
  93. break; \
  94. }
  95. #define PROCESS_TRYBR2_COMMON(name, func, suffix) \
  96. case OpCode::name: \
  97. { \
  98. PROCESS_READ_LAYOUT(name, BrReg2, suffix); \
  99. func((const byte*)(playout + 1), playout->RelativeJumpOffset, playout->R1, playout->R2); \
  100. ip = m_reader.GetIP(); \
  101. break; \
  102. }
  103. #define PROCESS_CALL_COMMON(name, func, layout, suffix) \
  104. case OpCode::name: \
  105. { \
  106. PROCESS_READ_LAYOUT(name, layout, suffix); \
  107. func(playout); \
  108. break; \
  109. }
  110. #define PROCESS_CALL(name, func, layout) PROCESS_CALL_COMMON(name, func, layout,)
  111. #define PROCESS_CALL_FLAGS_None_COMMON(name, func, layout, suffix) PROCESS_CALL_COMMON(name, func, layout, suffix)
  112. #define PROCESS_CALL_FLAGS_Value_COMMON(name, func, layout, suffix) PROCESS_CALL_COMMON(name, func, layout, suffix)
  113. #define PROCESS_A1toXX_ALLOW_STACK_COMMON(name, func, suffix) \
  114. case OpCode::name: \
  115. { \
  116. PROCESS_READ_LAYOUT(name, Reg1, suffix); \
  117. func(GetRegAllowStackVar(playout->R0)); \
  118. break; \
  119. }
  120. #define PROCESS_A1toXX_COMMON(name, func, suffix) \
  121. case OpCode::name: \
  122. { \
  123. PROCESS_READ_LAYOUT(name, Reg1, suffix); \
  124. func(GetReg(playout->R0)); \
  125. break; \
  126. }
  127. #define PROCESS_A1toXX(name, func) PROCESS_A1toXX_COMMON(name, func,)
  128. #define PROCESS_A1toXXMem_COMMON(name, func, suffix) \
  129. case OpCode::name: \
  130. { \
  131. PROCESS_READ_LAYOUT(name, Reg1, suffix); \
  132. func(GetReg(playout->R0), GetScriptContext()); \
  133. break; \
  134. }
  135. #define PROCESS_A1toXXMem(name, func) PROCESS_A1toXXMem_COMMON(name, func,)
  136. #define PROCESS_A1toXXMemNonVar_COMMON(name, func, type, suffix) \
  137. case OpCode::name: \
  138. { \
  139. PROCESS_READ_LAYOUT(name, Reg1, suffix); \
  140. func((type)GetNonVarReg(playout->R0), GetScriptContext()); \
  141. break; \
  142. }
  143. #define PROCESS_A1toXXMemNonVar(name, func, type) PROCESS_A1toXXMemNonVar_COMMON(name, func, type,)
  144. #define PROCESS_XXtoA1_COMMON(name, func, suffix) \
  145. case OpCode::name: \
  146. { \
  147. PROCESS_READ_LAYOUT(name, Reg1, suffix); \
  148. SetReg(playout->R0, \
  149. func()); \
  150. break; \
  151. }
  152. #define PROCESS_XXtoA1(name, func) PROCESS_XXtoA1_COMMON(name, func,)
  153. #define PROCESS_XXtoA1NonVar_COMMON(name, func, suffix) \
  154. case OpCode::name: \
  155. { \
  156. PROCESS_READ_LAYOUT(name, Reg1, suffix); \
  157. SetNonVarReg(playout->R0, \
  158. func()); \
  159. break; \
  160. }
  161. #define PROCESS_XXtoA1NonVar(name, func) PROCESS_XXtoA1NonVar_COMMON(name, func,)
  162. #define PROCESS_XXtoA1Mem_COMMON(name, func, suffix) \
  163. case OpCode::name: \
  164. { \
  165. PROCESS_READ_LAYOUT(name, Reg1, suffix); \
  166. SetReg(playout->R0, \
  167. func(GetScriptContext())); \
  168. break; \
  169. }
  170. #define PROCESS_XXtoA1Mem(name, func) PROCESS_XXtoA1Mem_COMMON(name, func,)
  171. #define PROCESS_A1toA1_ALLOW_STACK_COMMON(name, func, suffix) \
  172. case OpCode::name: \
  173. { \
  174. PROCESS_READ_LAYOUT(name, Reg2, suffix); \
  175. SetRegAllowStackVar(playout->R0, \
  176. func(GetRegAllowStackVar(playout->R1))); \
  177. break; \
  178. }
  179. #define PROCESS_A1toA1_ALLOW_STACK(name, func) PROCESS_A1toA1_ALLOW_STACK_COMMON(name, func,)
  180. #define PROCESS_A1toA1_COMMON(name, func, suffix) \
  181. case OpCode::name: \
  182. { \
  183. PROCESS_READ_LAYOUT(name, Reg2, suffix); \
  184. SetReg(playout->R0, \
  185. func(GetReg(playout->R1))); \
  186. break; \
  187. }
  188. #define PROCESS_A1toA1(name, func) PROCESS_A1toA1_COMMON(name, func,)
  189. #define PROCESS_A1toA1Profiled_COMMON(name, func, suffix) \
  190. case OpCode::name: \
  191. { \
  192. PROCESS_READ_LAYOUT(name, ProfiledReg2, suffix); \
  193. SetReg(playout->R0, \
  194. func(GetReg(playout->R1), playout->profileId)); \
  195. break; \
  196. }
  197. #define PROCESS_A1toA1Profiled(name, func) PROCESS_A1toA1Profiled_COMMON(name, func,)
  198. #define PROCESS_A1toA1CallNoArg_COMMON(name, func, layout, suffix) \
  199. case OpCode::name: \
  200. { \
  201. PROCESS_READ_LAYOUT(name, layout, suffix); \
  202. SetReg(playout->R0, \
  203. func(playout)); \
  204. break; \
  205. }
  206. #define PROCESS_A1toA1CallNoArg(name, func, layout) PROCESS_A1toA1CallNoArg_COMMON(name, func, layout,)
  207. #define PROCESS_A1toA1Mem_COMMON(name, func, suffix) \
  208. case OpCode::name: \
  209. { \
  210. PROCESS_READ_LAYOUT(name, Reg2, suffix); \
  211. SetReg(playout->R0, \
  212. func(GetReg(playout->R1),GetScriptContext())); \
  213. break; \
  214. }
  215. #define PROCESS_A1toA1Mem(name, func) PROCESS_A1toA1Mem_COMMON(name, func,)
  216. #define PROCESS_A1toA1NonVar_COMMON(name, func, suffix) \
  217. case OpCode::name: \
  218. { \
  219. PROCESS_READ_LAYOUT(name, Reg2, suffix); \
  220. SetNonVarReg(playout->R0, \
  221. func(GetNonVarReg(playout->R1))); \
  222. break; \
  223. }
  224. #define PROCESS_A1toA1NonVar(name, func) PROCESS_A1toA1NonVar_COMMON(name, func,)
  225. #define PROCESS_A1toA1MemNonVar_COMMON(name, func, suffix) \
  226. case OpCode::name: \
  227. { \
  228. PROCESS_READ_LAYOUT(name, Reg2, suffix); \
  229. SetNonVarReg(playout->R0, \
  230. func(GetNonVarReg(playout->R1),GetScriptContext())); \
  231. break; \
  232. }
  233. #define PROCESS_A1toA1MemNonVar(name, func) PROCESS_A1toA1MemNonVar_COMMON(name, func,)
  234. #define PROCESS_INNERtoA1_COMMON(name, func, suffix) \
  235. case OpCode::name: \
  236. { \
  237. PROCESS_READ_LAYOUT(name, Reg1Unsigned1, suffix); \
  238. SetReg(playout->R0, InnerScopeFromIndex(playout->C1)); \
  239. break; \
  240. }
  241. #define PROCESS_INNERtoA1(name, fun) PROCESS_INNERtoA1_COMMON(name, func,)
  242. #define PROCESS_U1toINNERMemNonVar_COMMON(name, func, suffix) \
  243. case OpCode::name: \
  244. { \
  245. PROCESS_READ_LAYOUT(name, Unsigned1, suffix); \
  246. SetInnerScopeFromIndex(playout->C1, func(GetScriptContext())); \
  247. break; \
  248. }
  249. #define PROCESS_U1toINNERMemNonVar(name, func) PROCESS_U1toINNERMemNonVar_COMMON(name, func,)
  250. #define PROCESS_XXINNERtoA1MemNonVar_COMMON(name, func, suffix) \
  251. case OpCode::name: \
  252. { \
  253. PROCESS_READ_LAYOUT(name, Reg1Unsigned1, suffix); \
  254. SetNonVarReg(playout->R0, \
  255. func(InnerScopeFromIndex(playout->C1), GetScriptContext())); \
  256. break; \
  257. }
  258. #define PROCESS_XXINNERtoA1MemNonVar(name, func) PROCESS_XXINNERtoA1MemNonVar_COMMON(name, func,)
  259. #define PROCESS_A1INNERtoA1MemNonVar_COMMON(name, func, suffix) \
  260. case OpCode::name: \
  261. { \
  262. PROCESS_READ_LAYOUT(name, Reg2Int1, suffix); \
  263. SetNonVarReg(playout->R0, \
  264. func(InnerScopeFromIndex(playout->C1), GetNonVarReg(playout->R1), GetScriptContext())); \
  265. break; \
  266. }
  267. #define PROCESS_A1LOCALtoA1MemNonVar(name, func) PROCESS_A1LOCALtoA1MemNonVar_COMMON(name, func,)
  268. #define PROCESS_LOCALI1toA1_COMMON(name, func, suffix) \
  269. case OpCode::name: \
  270. { \
  271. PROCESS_READ_LAYOUT(name, Reg1Unsigned1, suffix); \
  272. SetReg(playout->R0, \
  273. func(this->localClosure, playout->C1)); \
  274. break; \
  275. }
  276. #define PROCESS_LOCALI1toA1(name, func) PROCESS_LOCALI1toA1_COMMON(name, func,)
  277. #define PROCESS_A1I1toA1_COMMON(name, func, suffix) \
  278. case OpCode::name: \
  279. { \
  280. PROCESS_READ_LAYOUT(name, Reg2Int1, suffix); \
  281. SetReg(playout->R0, \
  282. func(GetReg(playout->R1), playout->C1)); \
  283. break; \
  284. }
  285. #define PROCESS_A1I1toA1(name, func) PROCESS_A1I1toA1_COMMON(name, func,)
  286. #define PROCESS_A1I1toA1Mem_COMMON(name, func, suffix) \
  287. case OpCode::name: \
  288. { \
  289. PROCESS_READ_LAYOUT(name, Reg2Int1, suffix); \
  290. SetReg(playout->R0, \
  291. func(GetReg(playout->R1), playout->C1, GetScriptContext())); \
  292. break; \
  293. }
  294. #define PROCESS_A1I1toA1Mem(name, func) PROCESS_A1I1toA1Mem_COMMON(name, func,)
  295. #define PROCESS_RegextoA1_COMMON(name, func, suffix) \
  296. case OpCode::name: \
  297. { \
  298. PROCESS_READ_LAYOUT(name, Reg1Unsigned1, suffix); \
  299. SetReg(playout->R0, \
  300. func(this->m_functionBody->GetLiteralRegex(playout->C1), GetScriptContext())); \
  301. break; \
  302. }
  303. #define PROCESS_RegextoA1(name, func) PROCESS_RegextoA1_COMMON(name, func,)
  304. #define PROCESS_A2toXX_COMMON(name, func, suffix) \
  305. case OpCode::name: \
  306. { \
  307. PROCESS_READ_LAYOUT(name, Reg2, suffix); \
  308. func(GetReg(playout->R0), GetReg(playout->R1)); \
  309. break; \
  310. }
  311. #define PROCESS_A2toXX(name, func) PROCESS_A2toXX_COMMON(name, func,)
  312. #define PROCESS_A2toXXMemNonVar_COMMON(name, func, suffix) \
  313. case OpCode::name: \
  314. { \
  315. PROCESS_READ_LAYOUT(name, Reg2, suffix); \
  316. func(GetNonVarReg(playout->R0), GetNonVarReg(playout->R1), GetScriptContext()); \
  317. break; \
  318. }
  319. #define PROCESS_A2toXXMemNonVar(name, func) PROCESS_A2toXXMemNonVar_COMMON(name, func,)
  320. #define PROCESS_A1NonVarToA1_COMMON(name, func, suffix) \
  321. case OpCode::name: \
  322. { \
  323. PROCESS_READ_LAYOUT(name, Reg2, suffix); \
  324. SetReg(playout->R0, \
  325. func(GetNonVarReg(playout->R1))); \
  326. break; \
  327. }
  328. #define PROCESS_A2NonVarToA1Reg_COMMON(name, func, suffix) \
  329. case OpCode::name: \
  330. { \
  331. PROCESS_READ_LAYOUT(name, Reg3, suffix); \
  332. SetReg(playout->R0, \
  333. func(GetNonVarReg(playout->R1), playout->R2)); \
  334. break; \
  335. }
  336. #define PROCESS_A2toA1Mem_COMMON(name, func, suffix) \
  337. case OpCode::name: \
  338. { \
  339. PROCESS_READ_LAYOUT(name, Reg3, suffix); \
  340. SetReg(playout->R0, \
  341. func(GetReg(playout->R1), GetReg(playout->R2),GetScriptContext())); \
  342. break; \
  343. }
  344. #define PROCESS_A2toA1Mem(name, func) PROCESS_A2toA1Mem_COMMON(name, func,)
  345. #define PROCESS_A2toA1MemProfiled_COMMON(name, func, suffix) \
  346. case OpCode::name: \
  347. { \
  348. PROCESS_READ_LAYOUT(name, ProfiledReg3, suffix); \
  349. SetReg(playout->R0, \
  350. func(GetReg(playout->R1), GetReg(playout->R2),GetScriptContext(), playout->profileId)); \
  351. break; \
  352. }
  353. #define PROCESS_A2toA1MemProfiled(name, func) PROCESS_A2toA1MemProfiled_COMMON(name, func,)
  354. #define PROCESS_A2toA1NonVar_COMMON(name, func, suffix) \
  355. case OpCode::name: \
  356. { \
  357. PROCESS_READ_LAYOUT(name, Reg3, suffix); \
  358. SetNonVarReg(playout->R0, \
  359. func(GetNonVarReg(playout->R1), GetNonVarReg(playout->R2))); \
  360. break; \
  361. }
  362. #define PROCESS_A2toA1NonVar(name, func) PROCESS_A2toA1NonVar_COMMON(name, func,)
  363. #define PROCESS_A2toA1MemNonVar_COMMON(name, func, suffix) \
  364. case OpCode::name: \
  365. { \
  366. PROCESS_READ_LAYOUT(name, Reg3, suffix); \
  367. SetNonVarReg(playout->R0, \
  368. func(GetNonVarReg(playout->R1), GetNonVarReg(playout->R2),GetScriptContext())); \
  369. break; \
  370. }
  371. #define PROCESS_A2toA1MemNonVar(name, func) PROCESS_A2toA1MemNonVar_COMMON(name, func,)
  372. #define PROCESS_CMMem_COMMON(name, func, suffix) \
  373. case OpCode::name: \
  374. { \
  375. PROCESS_READ_LAYOUT(name, Reg3, suffix); \
  376. SetReg(playout->R0, \
  377. func(GetReg(playout->R1), GetReg(playout->R2), GetScriptContext()) ? JavascriptBoolean::OP_LdTrue(GetScriptContext()) : \
  378. JavascriptBoolean::OP_LdFalse(GetScriptContext())); \
  379. break; \
  380. }
  381. #define PROCESS_CMMem(name, func) PROCESS_CMMem_COMMON(name, func,)
  382. #define PROCESS_ELEM_RtU_to_XX_COMMON(name, func, suffix) \
  383. case OpCode::name: \
  384. { \
  385. PROCESS_READ_LAYOUT(name, ElementRootU, suffix); \
  386. func(playout->PropertyIdIndex); \
  387. break; \
  388. }
  389. #define PROCESS_ELEM_RtU_to_XX(name, func) PROCESS_ELEM_RtU_to_XX_COMMON(name, func,)
  390. #define PROCESS_ELEM_C2_to_XX_COMMON(name, func, suffix) \
  391. case OpCode::name: \
  392. { \
  393. PROCESS_READ_LAYOUT(name, ElementScopedC, suffix); \
  394. func(GetEnvForEvalCode(), playout->PropertyIdIndex, GetReg(playout->Value)); \
  395. break; \
  396. }
  397. #define PROCESS_ELEM_C2_to_XX(name, func) PROCESS_ELEM_C2_to_XX_COMMON(name, func,)
  398. #define PROCESS_GET_ELEM_SLOT_FB_COMMON(name, func, suffix) \
  399. case OpCode::name: \
  400. { \
  401. PROCESS_READ_LAYOUT(name, ElementSlot, suffix); \
  402. SetReg(playout->Value, \
  403. func((FrameDisplay*)GetNonVarReg(playout->Instance), this->m_functionBody->GetNestedFuncReference(playout->SlotIndex))); \
  404. break; \
  405. }
  406. #define PROCESS_GET_ELEM_SLOT_FB(name, func) PROCESS_GET_ELEM_SLOT_FB_COMMON(name, func,)
  407. #define PROCESS_GET_ELEM_SLOT_FB_HMO_COMMON(name, func, suffix) \
  408. case OpCode::name: \
  409. { \
  410. PROCESS_READ_LAYOUT(name, ElementSlotI3, suffix); \
  411. SetReg(playout->Value, \
  412. func((FrameDisplay*)GetNonVarReg(playout->Instance), this->m_functionBody->GetNestedFuncReference(playout->SlotIndex), GetReg(playout->HomeObj))); \
  413. break; \
  414. }
  415. #define PROCESS_GET_ELEM_SLOT_FB_HMO(name, func) PROCESS_GET_ELEM_SLOT_FB_HMO_COMMON(name, func,)
  416. #define PROCESS_GET_SLOT_FB_COMMON(name, func, suffix) \
  417. case OpCode::name: \
  418. { \
  419. PROCESS_READ_LAYOUT(name, ElementSlotI1, suffix); \
  420. SetReg(playout->Value, \
  421. func(this->GetFrameDisplayForNestedFunc(), this->m_functionBody->GetNestedFuncReference(playout->SlotIndex))); \
  422. break; \
  423. }
  424. #define PROCESS_GET_SLOT_FB(name, func) PROCESS_GET_SLOT_FB_COMMON(name, func,)
  425. #define PROCESS_GET_SLOT_FB_HMO_COMMON(name, func, suffix) \
  426. case OpCode::name: \
  427. { \
  428. PROCESS_READ_LAYOUT(name, ElementSlot, suffix); \
  429. SetReg(playout->Value, \
  430. func(this->GetFrameDisplayForNestedFunc(), this->m_functionBody->GetNestedFuncReference(playout->SlotIndex), GetReg(playout->Instance))); \
  431. break; \
  432. }
  433. #define PROCESS_GET_SLOT_FB_HMO(name, func) PROCESS_GET_SLOT_FB_HMO_COMMON(name, func,)
  434. #define PROCESS_GET_ELEM_IMem_COMMON(name, func, suffix) \
  435. case OpCode::name: \
  436. { \
  437. PROCESS_READ_LAYOUT(name, ElementI, suffix); \
  438. SetReg(playout->Value, \
  439. func(GetReg(playout->Instance), GetReg(playout->Element), GetScriptContext())); \
  440. break; \
  441. }
  442. #define PROCESS_GET_ELEM_IMem(name, func) PROCESS_GET_ELEM_IMem_COMMON(name, func,)
  443. #define PROCESS_GET_ELEM_IMem_Strict_COMMON(name, func, suffix) \
  444. case OpCode::name: \
  445. { \
  446. PROCESS_READ_LAYOUT(name, ElementI, suffix); \
  447. SetReg(playout->Value, \
  448. func(GetReg(playout->Instance), GetReg(playout->Element), GetScriptContext(), PropertyOperation_StrictMode)); \
  449. break; \
  450. }
  451. #define PROCESS_GET_ELEM_IMem_Strict(name, func) PROCESS_GET_ELEM_IMem_Strict_COMMON(name, func,)
  452. #define PROCESS_BR(name, func) \
  453. case OpCode::name: \
  454. { \
  455. PROCESS_READ_LAYOUT(name, Br,); \
  456. ip = func(playout); \
  457. break; \
  458. }
  459. #ifdef BYTECODE_BRANCH_ISLAND
  460. #define PROCESS_BRLONG(name, func) \
  461. case OpCode::name: \
  462. { \
  463. PROCESS_READ_LAYOUT(name, BrLong,); \
  464. ip = func(playout); \
  465. break; \
  466. }
  467. #endif
  468. #define PROCESS_BRS(name,func) \
  469. case OpCode::name: \
  470. { \
  471. PROCESS_READ_LAYOUT(name, BrS,); \
  472. if (func(playout->val,GetScriptContext())) \
  473. { \
  474. ip = m_reader.SetCurrentRelativeOffset(ip, playout->RelativeJumpOffset); \
  475. } \
  476. break; \
  477. }
  478. #define PROCESS_BRB_COMMON(name, func, suffix) \
  479. case OpCode::name: \
  480. { \
  481. PROCESS_READ_LAYOUT(name, BrReg1, suffix); \
  482. if (func(GetReg(playout->R1))) \
  483. { \
  484. ip = m_reader.SetCurrentRelativeOffset(ip, playout->RelativeJumpOffset); \
  485. } \
  486. break; \
  487. }
  488. #define PROCESS_BRB(name, func) PROCESS_BRB_COMMON(name, func,)
  489. #define PROCESS_BRB_ALLOW_STACK_COMMON(name, func, suffix) \
  490. case OpCode::name: \
  491. { \
  492. PROCESS_READ_LAYOUT(name, BrReg1, suffix); \
  493. if (func(GetRegAllowStackVar(playout->R1))) \
  494. { \
  495. ip = m_reader.SetCurrentRelativeOffset(ip, playout->RelativeJumpOffset); \
  496. } \
  497. break; \
  498. }
  499. #define PROCESS_BRB_ALLOW_STACK(name, func) PROCESS_BRB_ALLOW_STACK_COMMON(name, func,)
  500. #define PROCESS_BRBS_COMMON(name, func, suffix) \
  501. case OpCode::name: \
  502. { \
  503. PROCESS_READ_LAYOUT(name, BrReg1, suffix); \
  504. if (func(GetReg(playout->R1), GetScriptContext())) \
  505. { \
  506. ip = m_reader.SetCurrentRelativeOffset(ip, playout->RelativeJumpOffset); \
  507. } \
  508. break; \
  509. }
  510. #define PROCESS_BRBS(name, func) PROCESS_BRBS_COMMON(name, func,)
  511. #define PROCESS_BRBReturnP1toA1_COMMON(name, func, suffix) \
  512. case OpCode::name: \
  513. { \
  514. PROCESS_READ_LAYOUT(name, BrReg1Unsigned1, suffix); \
  515. SetReg(playout->R1, func(GetForInEnumerator(playout->C2))); \
  516. if (!GetReg(playout->R1)) \
  517. { \
  518. ip = m_reader.SetCurrentRelativeOffset(ip, playout->RelativeJumpOffset); \
  519. } \
  520. break; \
  521. }
  522. #define PROCESS_BRBReturnP1toA1(name, func) PROCESS_BRBReturnP1toA1_COMMON(name, func,)
  523. #define PROCESS_BRBMem_ALLOW_STACK_COMMON(name, func, suffix) \
  524. case OpCode::name: \
  525. { \
  526. PROCESS_READ_LAYOUT(name, BrReg1, suffix); \
  527. if (func(GetRegAllowStackVar(playout->R1),GetScriptContext())) \
  528. { \
  529. ip = m_reader.SetCurrentRelativeOffset(ip, playout->RelativeJumpOffset); \
  530. } \
  531. break; \
  532. }
  533. #define PROCESS_BRBMem_ALLOW_STACK(name, func) PROCESS_BRBMem_ALLOW_STACK_COMMON(name, func,)
  534. #define PROCESS_BRCMem_COMMON(name, func,suffix) \
  535. case OpCode::name: \
  536. { \
  537. PROCESS_READ_LAYOUT(name, BrReg2, suffix); \
  538. if (func(GetReg(playout->R1), GetReg(playout->R2),GetScriptContext())) \
  539. { \
  540. ip = m_reader.SetCurrentRelativeOffset(ip, playout->RelativeJumpOffset); \
  541. } \
  542. break; \
  543. }
  544. #define PROCESS_BRCMem(name, func) PROCESS_BRCMem_COMMON(name, func,)
  545. #define PROCESS_BRPROP(name, func) \
  546. case OpCode::name: \
  547. { \
  548. PROCESS_READ_LAYOUT(name, BrProperty,); \
  549. if (func(GetReg(playout->Instance), playout->PropertyIdIndex, GetScriptContext())) \
  550. { \
  551. ip = m_reader.SetCurrentRelativeOffset(ip, playout->RelativeJumpOffset); \
  552. } \
  553. break; \
  554. }
  555. #define PROCESS_BRLOCALPROP(name, func) \
  556. case OpCode::name: \
  557. { \
  558. PROCESS_READ_LAYOUT(name, BrLocalProperty,); \
  559. if (func(this->localClosure, playout->PropertyIdIndex, GetScriptContext())) \
  560. { \
  561. ip = m_reader.SetCurrentRelativeOffset(ip, playout->RelativeJumpOffset); \
  562. } \
  563. break; \
  564. }
  565. #define PROCESS_BRENVPROP(name, func) \
  566. case OpCode::name: \
  567. { \
  568. PROCESS_READ_LAYOUT(name, BrEnvProperty,); \
  569. if (func(LdEnv(), playout->SlotIndex, playout->PropertyIdIndex, GetScriptContext())) \
  570. { \
  571. ip = m_reader.SetCurrentRelativeOffset(ip, playout->RelativeJumpOffset); \
  572. } \
  573. break; \
  574. }
  575. #define PROCESS_W1(name, func) \
  576. case OpCode::name: \
  577. { \
  578. PROCESS_READ_LAYOUT(name, W1,); \
  579. func(playout->C1, GetScriptContext()); \
  580. break; \
  581. }
  582. #define PROCESS_U1toA1_COMMON(name, func, suffix) \
  583. case OpCode::name: \
  584. { \
  585. PROCESS_READ_LAYOUT(name, Reg1Unsigned1, suffix); \
  586. SetReg(playout->R0, \
  587. func(playout->C1,GetScriptContext())); \
  588. break; \
  589. }
  590. #define PROCESS_U1toA1(name, func) PROCESS_U1toA1_COMMON(name, func,)
  591. #define PROCESS_U1toA1NonVar_COMMON(name, func, suffix) \
  592. case OpCode::name: \
  593. { \
  594. PROCESS_READ_LAYOUT(name, Reg1Unsigned1, suffix); \
  595. SetNonVarReg(playout->R0, \
  596. func(playout->C1)); \
  597. break; \
  598. }
  599. #define PROCESS_U1toA1NonVar(name, func) PROCESS_U1toA1NonVar_COMMON(name, func,)
  600. #define PROCESS_U1toA1NonVar_FuncBody_COMMON(name, func, suffix) \
  601. case OpCode::name: \
  602. { \
  603. PROCESS_READ_LAYOUT(name, Reg1Unsigned1, suffix); \
  604. SetNonVarReg(playout->R0, \
  605. func(playout->C1,GetScriptContext(), this->m_functionBody)); \
  606. break; \
  607. }
  608. #define PROCESS_U1toA1NonVar_FuncBody(name, func) PROCESS_U1toA1NonVar_FuncBody_COMMON(name, func,)
  609. #define PROCESS_A1I2toXXNonVar_FuncBody(name, func) PROCESS_A1I2toXXNonVar_FuncBody_COMMON(name, func,)
  610. #define PROCESS_A1I2toXXNonVar_FuncBody_COMMON(name, func, suffix) \
  611. case OpCode::name: \
  612. { \
  613. PROCESS_READ_LAYOUT(name, Reg3, suffix); \
  614. func(playout->R0, playout->R1, playout->R2, GetScriptContext(), this->m_functionBody); \
  615. break; \
  616. }
  617. #define PROCESS_A1U1toXX_COMMON(name, func, suffix) \
  618. case OpCode::name: \
  619. { \
  620. PROCESS_READ_LAYOUT(name, Reg1Unsigned1, suffix); \
  621. func(GetReg(playout->R0), playout->C1); \
  622. break; \
  623. }
  624. #define PROCESS_A1U1toXX(name, func) PROCESS_A1U1toXX_COMMON(name, func,)
  625. #define PROCESS_A1U1toXXWithCache_COMMON(name, func, suffix) \
  626. case OpCode::name: \
  627. { \
  628. PROCESS_READ_LAYOUT(name, ProfiledReg1Unsigned1, suffix); \
  629. func(GetReg(playout->R0), playout->C1, playout->profileId); \
  630. break; \
  631. }
  632. #define PROCESS_A1U1toXXWithCache(name, func) PROCESS_A1U1toXXWithCache_COMMON(name, func,)
  633. #define PROCESS_EnvU1toXX_COMMON(name, func, suffix) \
  634. case OpCode::name: \
  635. { \
  636. PROCESS_READ_LAYOUT(name, Unsigned1, suffix); \
  637. func(LdEnv(), playout->C1); \
  638. break; \
  639. }
  640. #define PROCESS_EnvU1toXX(name, func) PROCESS_EnvU1toXX_COMMON(name, func,)
  641. #define PROCESS_GET_ELEM_SLOTNonVar_COMMON(name, func, layout, suffix) \
  642. case OpCode::name: \
  643. { \
  644. PROCESS_READ_LAYOUT(name, layout, suffix); \
  645. SetNonVarReg(playout->Value, func(GetNonVarReg(playout->Instance), playout)); \
  646. break; \
  647. }
  648. #define PROCESS_GET_ELEM_SLOTNonVar(name, func, layout) PROCESS_GET_ELEM_SLOTNonVar_COMMON(name, func, layout,)
  649. #define PROCESS_GET_ELEM_LOCALSLOTNonVar_COMMON(name, func, layout, suffix) \
  650. case OpCode::name: \
  651. { \
  652. PROCESS_READ_LAYOUT(name, layout, suffix); \
  653. SetNonVarReg(playout->Value, func((Var*)GetLocalClosure(), playout)); \
  654. break; \
  655. }
  656. #define PROCESS_GET_ELEM_LOCALSLOTNonVar(name, func, layout) PROCESS_GET_ELEM_LOCALSLOTNonVar_COMMON(name, func, layout,)
  657. #define PROCESS_GET_ELEM_PARAMSLOTNonVar_COMMON(name, func, layout, suffix) \
  658. case OpCode::name: \
  659. { \
  660. PROCESS_READ_LAYOUT(name, layout, suffix); \
  661. SetNonVarReg(playout->Value, func((Var*)GetParamClosure(), playout)); \
  662. break; \
  663. }
  664. #define PROCESS_GET_ELEM_PARAMSLOTNonVar(name, func, layout) PROCESS_GET_ELEM_PARAMSLOTNonVar_COMMON(name, func, layout,)
  665. #define PROCESS_GET_ELEM_INNERSLOTNonVar_COMMON(name, func, layout, suffix) \
  666. case OpCode::name: \
  667. { \
  668. PROCESS_READ_LAYOUT(name, layout, suffix); \
  669. SetNonVarReg(playout->Value, func(InnerScopeFromIndex(playout->SlotIndex1), playout)); \
  670. break; \
  671. }
  672. #define PROCESS_GET_ELEM_INNERSLOTNonVar(name, func, layout) PROCESS_GET_ELEM_INNERSLOTNonVar_COMMON(name, func, layout,)
  673. #define PROCESS_GET_ELEM_ENVSLOTNonVar_COMMON(name, func, layout, suffix) \
  674. case OpCode::name: \
  675. { \
  676. PROCESS_READ_LAYOUT(name, layout, suffix); \
  677. SetNonVarReg(playout->Value, func(LdEnv(), playout)); \
  678. break; \
  679. }
  680. #define PROCESS_GET_ELEM_ENVSLOTNonVar(name, func, layout) PROCESS_GET_ELEM_ENVSLOTNonVar_COMMON(name, func, layout,)
  681. #define PROCESS_SET_ELEM_SLOTNonVar_COMMON(name, func, suffix) \
  682. case OpCode::name: \
  683. { \
  684. PROCESS_READ_LAYOUT(name, ElementSlot, suffix); \
  685. func(GetNonVarReg(playout->Instance), playout->SlotIndex, GetRegAllowStackVarEnableOnly(playout->Value)); \
  686. break; \
  687. }
  688. #define PROCESS_SET_ELEM_SLOTNonVar(name, func) PROCESS_SET_ELEM_SLOTNonVar_COMMON(name, func,)
  689. #define PROCESS_SET_ELEM_LOCALSLOTNonVar_COMMON(name, func, suffix) \
  690. case OpCode::name: \
  691. { \
  692. PROCESS_READ_LAYOUT(name, ElementSlotI1, suffix); \
  693. func((Var*)GetLocalClosure(), playout->SlotIndex, GetRegAllowStackVarEnableOnly(playout->Value)); \
  694. break; \
  695. }
  696. #define PROCESS_SET_ELEM_LOCALSLOTNonVar(name, func) PROCESS_SET_ELEM_LOCALSLOTNonVar_COMMON(name, func,)
  697. #define PROCESS_SET_ELEM_PARAMSLOTNonVar_COMMON(name, func, suffix) \
  698. case OpCode::name: \
  699. { \
  700. PROCESS_READ_LAYOUT(name, ElementSlotI1, suffix); \
  701. func((Var*)GetParamClosure(), playout->SlotIndex, GetRegAllowStackVarEnableOnly(playout->Value)); \
  702. break; \
  703. }
  704. #define PROCESS_SET_ELEM_PARAMSLOTNonVar(name, func) PROCESS_SET_ELEM_PARAMSLOTNonVar_COMMON(name, func,); \
  705. #define PROCESS_SET_ELEM_INNERSLOTNonVar_COMMON(name, func, suffix) \
  706. case OpCode::name: \
  707. { \
  708. PROCESS_READ_LAYOUT(name, ElementSlotI2, suffix); \
  709. func(InnerScopeFromIndex(playout->SlotIndex1), playout->SlotIndex2, GetRegAllowStackVarEnableOnly(playout->Value)); \
  710. break; \
  711. }
  712. #define PROCESS_SET_ELEM_INNERSLOTNonVar(name, func) PROCESS_SET_ELEM_INNERSLOTNonVar_COMMON(name, func,)
  713. #define PROCESS_SET_ELEM_ENVSLOTNonVar_COMMON(name, func, suffix) \
  714. case OpCode::name: \
  715. { \
  716. PROCESS_READ_LAYOUT(name, ElementSlotI2, suffix); \
  717. func(LdEnv(), playout->SlotIndex1, playout->SlotIndex2, GetRegAllowStackVarEnableOnly(playout->Value)); \
  718. break; \
  719. }
  720. #define PROCESS_SET_ELEM_ENVSLOTNonVar(name, func) PROCESS_SET_ELEM_ENVSLOTNonVar_COMMON(name, func,)
  721. /*---------------------------------------------------------------------------------------------- */
  722. #define PROCESS_A3toA1Mem_COMMON(name, func, suffix) \
  723. case OpCode::name: \
  724. { \
  725. PROCESS_READ_LAYOUT(name, Reg4, suffix); \
  726. SetReg(playout->R0, \
  727. func(GetReg(playout->R1), GetReg(playout->R2), GetReg(playout->R3), GetScriptContext())); \
  728. break; \
  729. }
  730. #define PROCESS_A3toA1Mem(name, func) PROCESS_A3toA1Mem_COMMON(name, func,)
  731. /*---------------------------------------------------------------------------------------------- */
  732. #define PROCESS_A2I1toA1Mem_COMMON(name, func, suffix) \
  733. case OpCode::name: \
  734. { \
  735. PROCESS_READ_LAYOUT(name, Reg3B1, suffix); \
  736. SetReg(playout->R0, \
  737. func(GetReg(playout->R1), GetReg(playout->R2), playout->B3, GetScriptContext())); \
  738. break; \
  739. }
  740. #define PROCESS_A2I1toA1Mem(name, func) PROCESS_A2I1toA1Mem_COMMON(name, func,)
  741. /*---------------------------------------------------------------------------------------------- */
  742. #define PROCESS_A2I1toXXMem_COMMON(name, func, suffix) \
  743. case OpCode::name: \
  744. { \
  745. PROCESS_READ_LAYOUT(name, Reg2B1, suffix); \
  746. func(GetReg(playout->R0), GetReg(playout->R1), playout->B2, scriptContext); \
  747. break; \
  748. }
  749. #define PROCESS_A2I1toXXMem(name, func) PROCESS_A2I1toXXMem_COMMON(name, func,)
  750. /*---------------------------------------------------------------------------------------------- */
  751. #define PROCESS_A3I1toXXMem_COMMON(name, func, suffix) \
  752. case OpCode::name: \
  753. { \
  754. PROCESS_READ_LAYOUT(name, Reg3B1, suffix); \
  755. func(GetReg(playout->R0), GetReg(playout->R1), GetReg(playout->R2), playout->B3, scriptContext); \
  756. break; \
  757. }
  758. #define PROCESS_A3I1toXXMem(name, func) PROCESS_A3I1toXXMem_COMMON(name, func,)
  759. #if ENABLE_PROFILE_INFO
  760. #define PROCESS_IP_TARG_IMPL(name, func, layoutSize) \
  761. case OpCode::name: \
  762. { \
  763. Assert(!switchProfileMode); \
  764. ip = func<layoutSize, INTERPRETERPROFILE>(ip); \
  765. if(switchProfileMode) \
  766. { \
  767. m_reader.SetIP(ip); \
  768. return nullptr; \
  769. } \
  770. break; \
  771. }
  772. #else
  773. #define PROCESS_IP_TARG_IMPL(name, func, layoutSize) \
  774. case OpCode::name: \
  775. { \
  776. ip = func<layoutSize, INTERPRETERPROFILE>(ip); \
  777. break; \
  778. }
  779. #endif
  780. #define PROCESS_IP_TARG_COMMON(name, func, suffix) PROCESS_IP_TARG##suffix(name, func)
  781. #define PROCESS_IP_TARG_Large(name, func) PROCESS_IP_TARG_IMPL(name, func, Js::LargeLayout)
  782. #define PROCESS_IP_TARG_Medium(name, func) PROCESS_IP_TARG_IMPL(name, func, Js::MediumLayout)
  783. #define PROCESS_IP_TARG_Small(name, func) PROCESS_IP_TARG_IMPL(name, func, Js::SmallLayout)
  784. #if ENABLE_TTD
  785. #if ENABLE_TTD_DIAGNOSTICS_TRACING
  786. #define SHOULD_DO_TTD_STACK_STMT_OP(CTX) ((CTX)->ShouldPerformRecordOrReplayAction())
  787. #else
  788. #define SHOULD_DO_TTD_STACK_STMT_OP(CTX) ((CTX)->ShouldPerformRecordOrReplayDebuggerAction())
  789. #endif
  790. #endif
  791. namespace Js
  792. {
  793. Var InterpreterStackFrame::InnerScopeFromRegSlot(RegSlot reg) const
  794. {
  795. return InnerScopeFromIndex(reg - m_functionBody->GetFirstInnerScopeRegister());
  796. }
  797. Var InterpreterStackFrame::InnerScopeFromIndex(uint32 index) const
  798. {
  799. if (index >= m_functionBody->GetInnerScopeCount())
  800. {
  801. AssertMsg(false, "Illegal byte code: bad inner scope index");
  802. Js::Throw::FatalInternalError();
  803. }
  804. Assert(this->innerScopeArray != nullptr);
  805. return this->innerScopeArray[index];
  806. }
  807. void InterpreterStackFrame::SetInnerScopeFromIndex(uint32 index, Var scope)
  808. {
  809. if (index >= m_functionBody->GetInnerScopeCount())
  810. {
  811. AssertMsg(false, "Illegal byte code: bad inner scope index");
  812. Js::Throw::FatalInternalError();
  813. }
  814. Assert(this->innerScopeArray != nullptr);
  815. this->innerScopeArray[index] = scope;
  816. }
  817. const int k_stackFrameVarCount = (sizeof(InterpreterStackFrame) + sizeof(Var) - 1) / sizeof(Var);
  818. InterpreterStackFrame::Setup::Setup(Js::ScriptFunction * function, Js::Arguments& args, bool bailedOut, bool inlinee)
  819. : function(function), inParams(args.Values), inSlotsCount(args.Info.Count), executeFunction(function->GetFunctionBody()), callFlags(args.Info.Flags), bailedOutOfInlinee(inlinee), bailedOut(bailedOut)
  820. {
  821. SetupInternal();
  822. }
  823. InterpreterStackFrame::Setup::Setup(Js::ScriptFunction * function, Var * inParams, int inSlotsCount)
  824. : function(function), inParams(inParams), inSlotsCount(inSlotsCount), executeFunction(function->GetFunctionBody()), callFlags(CallFlags_None), bailedOutOfInlinee(false), bailedOut(false)
  825. {
  826. SetupInternal();
  827. }
  828. void InterpreterStackFrame::Setup::SetupInternal()
  829. {
  830. if (this->function->GetHasInlineCaches() && Js::ScriptFunctionWithInlineCache::Is(this->function))
  831. {
  832. this->inlineCaches = (void**)Js::ScriptFunctionWithInlineCache::FromVar(this->function)->GetInlineCaches();
  833. Assert(this->inlineCaches != nullptr);
  834. }
  835. else
  836. {
  837. this->inlineCaches = this->executeFunction->GetInlineCaches();
  838. }
  839. this->inlineCacheCount = this->executeFunction->GetInlineCacheCount();
  840. //
  841. // Compute the amount of memory needed on the stack:
  842. // - We compute this in 'Atoms' instead of 'bytes' to keep everything natural word aligned.
  843. //
  844. this->localCount = this->executeFunction->GetLocalsCount();
  845. uint extraVarCount = 0;
  846. #if ENABLE_PROFILE_INFO
  847. if (Js::DynamicProfileInfo::EnableImplicitCallFlags(this->executeFunction))
  848. {
  849. extraVarCount += (sizeof(ImplicitCallFlags) * this->executeFunction->GetLoopCount() + sizeof(Var) - 1) / sizeof(Var);
  850. }
  851. #endif
  852. // If we bailed out, we will use the JIT frame's for..in enumerators
  853. uint forInVarCount = bailedOut ? 0 : (this->executeFunction->GetForInLoopDepth() * (sizeof(Js::ForInObjectEnumerator) / sizeof(Var)));
  854. this->varAllocCount = k_stackFrameVarCount + localCount + this->executeFunction->GetOutParamMaxDepth() + forInVarCount +
  855. extraVarCount + this->executeFunction->GetInnerScopeCount();
  856. this->stackVarAllocCount = 0;
  857. if (this->executeFunction->DoStackNestedFunc() && this->executeFunction->GetNestedCount() != 0)
  858. {
  859. // Track stack funcs...
  860. this->stackVarAllocCount += (sizeof(StackScriptFunction) * this->executeFunction->GetNestedCount()) / sizeof(Var);
  861. if (!this->bailedOutOfInlinee)
  862. {
  863. // Frame display (if environment depth is statically known)...
  864. if (this->executeFunction->DoStackFrameDisplay())
  865. {
  866. uint16 envDepth = this->executeFunction->GetEnvDepth();
  867. Assert(envDepth != (uint16)-1);
  868. this->stackVarAllocCount += sizeof(FrameDisplay) / sizeof(Var) + (envDepth + 1);
  869. }
  870. // ...and scope slots (if any)
  871. if (this->executeFunction->DoStackScopeSlots())
  872. {
  873. uint32 scopeSlots = this->executeFunction->scopeSlotArraySize;
  874. Assert(scopeSlots != 0);
  875. this->stackVarAllocCount += scopeSlots + Js::ScopeSlots::FirstSlotIndex;
  876. }
  877. }
  878. }
  879. }
  880. InterpreterStackFrame *
  881. InterpreterStackFrame::Setup::InitializeAllocation(__in_ecount(varAllocCount) Var * allocation, __in_ecount(stackVarAllocCount) Var * stackAllocation
  882. , bool initParams, bool profileParams, LoopHeader* loopHeaderArray, DWORD_PTR stackAddr
  883. #if DBG
  884. , Var invalidStackVar
  885. #endif
  886. )
  887. {
  888. //
  889. // Initialize the new InterpreterStackFrame instance on the program stack.
  890. //
  891. //This will fail if InterpreterStackFrame ever gets a non-empty ctor (you'll need to use
  892. //placement_new(allocation, InterpreterStackFrame) instead, though that will cause problems
  893. //if the placement_new is surrounded by a try/finally since this would mix C++/SEH exception
  894. //handling.
  895. __analysis_assume(varAllocCount >= k_stackFrameVarCount + localCount);
  896. InterpreterStackFrame* newInstance = (InterpreterStackFrame*)allocation;
  897. newInstance->scriptContext = this->executeFunction->GetScriptContext();
  898. newInstance->m_inSlotsCount = this->inSlotsCount;
  899. newInstance->m_inParams = this->inParams;
  900. newInstance->m_callFlags = this->callFlags;
  901. newInstance->m_outParams = newInstance->m_localSlots + localCount;
  902. newInstance->m_outSp = newInstance->m_outParams;
  903. newInstance->m_outSpCached = nullptr;
  904. newInstance->m_arguments = NULL;
  905. newInstance->function = this->function;
  906. newInstance->m_functionBody = this->executeFunction;
  907. newInstance->inlineCaches = this->inlineCaches;
  908. newInstance->inlineCacheCount = this->inlineCacheCount;
  909. newInstance->currentLoopNum = LoopHeader::NoLoop;
  910. newInstance->currentLoopCounter = 0;
  911. newInstance->m_flags = InterpreterStackFrameFlags_None;
  912. newInstance->closureInitDone = false;
  913. newInstance->isParamScopeDone = false;
  914. newInstance->shouldCacheSP = true;
  915. #if ENABLE_PROFILE_INFO
  916. newInstance->switchProfileMode = false;
  917. newInstance->isAutoProfiling = false;
  918. newInstance->switchProfileModeOnLoopEndNumber = 0u - 1;
  919. #endif
  920. newInstance->ehBailoutData = nullptr;
  921. newInstance->nestedTryDepth = -1;
  922. newInstance->nestedCatchDepth = -1;
  923. newInstance->nestedFinallyDepth = -1;
  924. newInstance->retOffset = 0;
  925. newInstance->localFrameDisplay = nullptr;
  926. newInstance->localClosure = nullptr;
  927. newInstance->paramClosure = nullptr;
  928. newInstance->innerScopeArray = nullptr;
  929. newInstance->m_asmJsBuffer = nullptr;
  930. #ifdef ENABLE_WASM
  931. newInstance->m_wasmMemory = nullptr;
  932. #endif
  933. Var* outparamsEnd = newInstance->m_outParams + this->executeFunction->GetOutParamMaxDepth();
  934. #if DBG
  935. newInstance->m_outParamsEnd = outparamsEnd;
  936. #endif
  937. bool doInterruptProbe = newInstance->scriptContext->GetThreadContext()->DoInterruptProbe(this->executeFunction);
  938. #if ENABLE_NATIVE_CODEGEN
  939. bool doJITLoopBody =
  940. !this->executeFunction->GetScriptContext()->GetConfig()->IsNoNative() &&
  941. !(this->executeFunction->GetHasTry() && (PHASE_OFF((Js::JITLoopBodyInTryCatchPhase), this->executeFunction))) &&
  942. !(this->executeFunction->GetHasFinally() && (PHASE_OFF((Js::JITLoopBodyInTryFinallyPhase), this->executeFunction))) &&
  943. (this->executeFunction->ForceJITLoopBody() || this->executeFunction->IsJitLoopBodyPhaseEnabled()) &&
  944. !this->executeFunction->IsInDebugMode();
  945. #endif
  946. // Pick a version of the LoopBodyStart OpCode handlers that is hardcoded to do loop body JIT and
  947. // interrupt probes as needed.
  948. if (doInterruptProbe)
  949. {
  950. #if ENABLE_NATIVE_CODEGEN
  951. if (doJITLoopBody)
  952. {
  953. newInstance->opProfiledLoopBodyStart = &InterpreterStackFrame::ProfiledLoopBodyStart<true, true>;
  954. newInstance->opLoopBodyStart = &InterpreterStackFrame::LoopBodyStart<true, true>;
  955. }
  956. else
  957. #endif
  958. {
  959. #if ENABLE_PROFILE_INFO
  960. newInstance->opProfiledLoopBodyStart = &InterpreterStackFrame::ProfiledLoopBodyStart<true, false>;
  961. #endif
  962. newInstance->opLoopBodyStart = &InterpreterStackFrame::LoopBodyStart<true, false>;
  963. }
  964. }
  965. else
  966. {
  967. #if ENABLE_NATIVE_CODEGEN
  968. if (doJITLoopBody)
  969. {
  970. newInstance->opProfiledLoopBodyStart = &InterpreterStackFrame::ProfiledLoopBodyStart<false, true>;
  971. newInstance->opLoopBodyStart = &InterpreterStackFrame::LoopBodyStart<false, true>;
  972. }
  973. else
  974. #endif
  975. {
  976. #if ENABLE_PROFILE_INFO
  977. newInstance->opProfiledLoopBodyStart = &InterpreterStackFrame::ProfiledLoopBodyStart<false, false>;
  978. #endif
  979. newInstance->opLoopBodyStart = &InterpreterStackFrame::LoopBodyStart<false, false>;
  980. }
  981. }
  982. newInstance->loopHeaderArray = loopHeaderArray;
  983. newInstance->m_stackAddress = stackAddr;
  984. #if ENABLE_PROFILE_INFO
  985. // the savedLoopImplicitCallFlags is allocated at the end of the out param array
  986. newInstance->savedLoopImplicitCallFlags = nullptr;
  987. #endif
  988. char * nextAllocBytes = (char *)(outparamsEnd);
  989. // If we bailed out, we will use the JIT frame's for..in enumerators
  990. if (bailedOut || this->executeFunction->GetForInLoopDepth() == 0)
  991. {
  992. newInstance->forInObjectEnumerators = nullptr;
  993. }
  994. else
  995. {
  996. newInstance->forInObjectEnumerators = (ForInObjectEnumerator *)nextAllocBytes;
  997. nextAllocBytes += sizeof(ForInObjectEnumerator) * this->executeFunction->GetForInLoopDepth();
  998. }
  999. if (this->executeFunction->GetInnerScopeCount())
  1000. {
  1001. newInstance->innerScopeArray = (Var*)nextAllocBytes;
  1002. nextAllocBytes += this->executeFunction->GetInnerScopeCount() * sizeof(Var);
  1003. }
  1004. if (this->executeFunction->DoStackNestedFunc() && this->executeFunction->GetNestedCount() != 0)
  1005. {
  1006. char * stackAllocBytes = (stackAllocation != nullptr) ? (char*)stackAllocation : nextAllocBytes;
  1007. newInstance->InitializeStackFunctions((StackScriptFunction *)stackAllocBytes);
  1008. stackAllocBytes += sizeof(StackScriptFunction) * this->executeFunction->GetNestedCount();
  1009. if (!this->bailedOutOfInlinee)
  1010. {
  1011. if (this->executeFunction->DoStackFrameDisplay())
  1012. {
  1013. uint16 envDepth = this->executeFunction->GetEnvDepth();
  1014. Assert(envDepth != (uint16)-1);
  1015. newInstance->localFrameDisplay = (FrameDisplay*)stackAllocBytes;
  1016. newInstance->localFrameDisplay->SetLength(0); // Start with no scopes. It will get set in NewFrameDisplay
  1017. stackAllocBytes += sizeof(FrameDisplay) + (envDepth + 1) * sizeof(Var);
  1018. }
  1019. if (this->executeFunction->DoStackScopeSlots())
  1020. {
  1021. uint32 scopeSlots = this->executeFunction->scopeSlotArraySize;
  1022. Assert(scopeSlots != 0);
  1023. ScopeSlots((Field(Var)*)stackAllocBytes).SetCount(0); // Start with count as 0. It will get set in NewScopeSlots
  1024. newInstance->localClosure = stackAllocBytes;
  1025. stackAllocBytes += (scopeSlots + ScopeSlots::FirstSlotIndex) * sizeof(Var);
  1026. }
  1027. }
  1028. if (stackAllocation == nullptr)
  1029. {
  1030. nextAllocBytes = stackAllocBytes;
  1031. }
  1032. }
  1033. #if ENABLE_PROFILE_INFO
  1034. if (Js::DynamicProfileInfo::EnableImplicitCallFlags(this->executeFunction))
  1035. {
  1036. /*
  1037. __analysis_assume(varAllocCount == (k_stackFrameVarCount + localCount + executeFunction->GetOutParamMaxDepth()
  1038. + ((sizeof(ImplicitCallFlags) * executeFunction->GetLoopCount() + sizeof(Var) - 1) / sizeof(Var))));
  1039. */
  1040. newInstance->savedLoopImplicitCallFlags = (ImplicitCallFlags *)nextAllocBytes;
  1041. for (uint i = 0; i < this->executeFunction->GetLoopCount(); i++)
  1042. {
  1043. #pragma prefast(suppress:26015, "Above analysis assume doesn't work")
  1044. newInstance->savedLoopImplicitCallFlags[i] = ImplicitCall_None;
  1045. }
  1046. }
  1047. #endif
  1048. #if DBG
  1049. if (CONFIG_ISENABLED(InitializeInterpreterSlotsWithInvalidStackVarFlag))
  1050. {
  1051. // Fill the local slots with the invalid stack var so that we will crash deterministically if something goes wrong
  1052. for (uint i = 0; i < localCount; ++i)
  1053. {
  1054. newInstance->m_localSlots[i] = invalidStackVar;
  1055. }
  1056. }
  1057. else
  1058. {
  1059. memset(newInstance->m_localSlots, 0, sizeof(Js::Var) * localCount);
  1060. }
  1061. #else
  1062. if (newInstance->m_functionBody->IsInDebugMode())
  1063. {
  1064. // In the debug mode zero out the local slot, so this could prevent locals being uninitialized in the case of setNextStatement.
  1065. memset(newInstance->m_localSlots, 0, sizeof(Js::Var) * localCount);
  1066. }
  1067. else
  1068. {
  1069. Js::RegSlot varCount = function->GetFunctionBody()->GetVarCount();
  1070. if (varCount)
  1071. {
  1072. // Zero out the non-constant var slots.
  1073. Js::RegSlot constantCount = function->GetFunctionBody()->GetConstantCount();
  1074. memset(newInstance->m_localSlots + constantCount, 0, varCount * sizeof(Js::Var));
  1075. }
  1076. // Zero out the return slot. This is not a user local, so the byte code will not initialize
  1077. // it to "undefined". And it's not an expression temp, so, for instance, a jitted loop body may expect
  1078. // it to be valid on entry to the loop, where "valid" means either a var or null.
  1079. newInstance->SetNonVarReg(0, NULL);
  1080. }
  1081. #endif
  1082. // Wasm doesn't use const table
  1083. if (!executeFunction->IsWasmFunction())
  1084. {
  1085. // Initialize the low end of the local slots from the constant table.
  1086. // Skip the slot for the return value register.
  1087. this->executeFunction->InitConstantSlots(&newInstance->m_localSlots[FunctionBody::FirstRegSlot]);
  1088. }
  1089. // Set local FD/SS pointers to null until after we've successfully probed the stack in the process loop.
  1090. // That way we avoid trying to box these structures before they've been initialized in the byte code.
  1091. if (this->executeFunction->DoStackFrameDisplay())
  1092. {
  1093. newInstance->SetNonVarReg(executeFunction->GetLocalFrameDisplayRegister(), nullptr);
  1094. }
  1095. if (this->executeFunction->DoStackScopeSlots())
  1096. {
  1097. Assert(!executeFunction->HasScopeObject());
  1098. newInstance->SetNonVarReg(executeFunction->GetLocalClosureRegister(), nullptr);
  1099. }
  1100. Var *prestDest = &newInstance->m_localSlots[this->executeFunction->GetConstantCount()];
  1101. if (initParams)
  1102. {
  1103. #if ENABLE_PROFILE_INFO
  1104. Assert(!this->executeFunction->NeedEnsureDynamicProfileInfo());
  1105. #endif
  1106. if (profileParams)
  1107. {
  1108. #if ENABLE_PROFILE_INFO
  1109. Assert(this->executeFunction->HasExecutionDynamicProfileInfo());
  1110. #endif
  1111. FunctionBody* functionBody = this->executeFunction;
  1112. InitializeParams(newInstance, [functionBody](Var param, ArgSlot index)
  1113. {
  1114. #if ENABLE_PROFILE_INFO
  1115. functionBody->GetDynamicProfileInfo()->RecordParameterInfo(functionBody, index - 1, param);
  1116. #endif
  1117. }, &prestDest);
  1118. }
  1119. else
  1120. {
  1121. InitializeParams(newInstance, [](Var param, ArgSlot index) {}, &prestDest);
  1122. }
  1123. }
  1124. if (this->executeFunction->GetHasRestParameter())
  1125. {
  1126. InitializeRestParam(newInstance, prestDest);
  1127. }
  1128. Js::RegSlot envReg = executeFunction->GetEnvRegister();
  1129. if (envReg != Js::Constants::NoRegister && envReg < executeFunction->GetConstantCount())
  1130. {
  1131. Assert(this->executeFunction->GetThisRegisterForEventHandler() == Constants::NoRegister);
  1132. // The correct FD (possibly distinct from the one on the function) is passed in the constant table.
  1133. this->function->SetEnvironment((Js::FrameDisplay*)newInstance->GetNonVarReg(envReg));
  1134. }
  1135. return newInstance;
  1136. }
  1137. template <class Fn>
  1138. void InterpreterStackFrame::Setup::InitializeParams(InterpreterStackFrame * newInstance, Fn callback, Var **pprestDest)
  1139. {
  1140. ArgSlot requiredInParamCount = executeFunction->GetInParamsCount();
  1141. Assert(requiredInParamCount > 1);
  1142. if (this->inSlotsCount >= requiredInParamCount)
  1143. {
  1144. Var * pArg = &newInstance->m_localSlots[executeFunction->GetConstantCount()];
  1145. Var * paGivenSrc = this->inParams + 1;
  1146. ArgSlot paramIndex = 1;
  1147. do
  1148. {
  1149. Var src = *paGivenSrc++;
  1150. callback(src, paramIndex);
  1151. *pArg++ = src;
  1152. paramIndex++;
  1153. } while (paramIndex < requiredInParamCount);
  1154. *pprestDest = pArg;
  1155. }
  1156. else
  1157. {
  1158. InitializeParamsAndUndef(newInstance, callback, pprestDest);
  1159. }
  1160. }
  1161. template <class Fn>
  1162. void InterpreterStackFrame::Setup::InitializeParamsAndUndef(InterpreterStackFrame * newInstance, Fn callback, Var **pprestDest)
  1163. {
  1164. Var * pArg = &newInstance->m_localSlots[executeFunction->GetConstantCount()];
  1165. Var * paGivenSrc = this->inParams + 1;
  1166. ArgSlot requiredInParamCount = executeFunction->GetInParamsCount();
  1167. ArgSlot paramIndex = 1;
  1168. while (paramIndex < this->inSlotsCount)
  1169. {
  1170. Var src = *paGivenSrc++;
  1171. callback(src, paramIndex);
  1172. *pArg++ = src;
  1173. paramIndex++;
  1174. }
  1175. Var varUndef = executeFunction->GetScriptContext()->GetLibrary()->GetUndefined();
  1176. do
  1177. {
  1178. callback(varUndef, paramIndex);
  1179. *pArg++ = varUndef;
  1180. paramIndex++;
  1181. } while (paramIndex < requiredInParamCount);
  1182. *pprestDest = pArg;
  1183. }
  1184. void InterpreterStackFrame::Setup::InitializeRestParam(InterpreterStackFrame * newInstance, Var *dest)
  1185. {
  1186. Var *src = this->inParams + executeFunction->GetInParamsCount();
  1187. if (this->inSlotsCount > executeFunction->GetInParamsCount())
  1188. {
  1189. // Create the rest array and copy the args directly into the contiguous head segment.
  1190. int excess = this->inSlotsCount - executeFunction->GetInParamsCount();
  1191. *dest = JavascriptArray::OP_NewScArray(excess, executeFunction->GetScriptContext());
  1192. JavascriptArray *array = static_cast<JavascriptArray *>(*dest);
  1193. Field(Var)* elements = SparseArraySegment<Var>::From(array->GetHead())->elements;
  1194. CopyArray(elements, excess, src, excess);
  1195. }
  1196. else
  1197. {
  1198. // Rest is an empty array when there are no excess parameters.
  1199. *dest = JavascriptArray::OP_NewScArray(0, executeFunction->GetScriptContext());
  1200. }
  1201. }
  1202. FrameDisplay * InterpreterStackFrame::GetEnvForEvalCode()
  1203. {
  1204. FrameDisplay *pScope;
  1205. if (m_functionBody->GetIsStrictMode() && m_functionBody->GetIsGlobalFunc())
  1206. {
  1207. pScope = this->GetLocalFrameDisplay();
  1208. }
  1209. else
  1210. {
  1211. pScope = (FrameDisplay*)this->LdEnv();
  1212. }
  1213. return pScope;
  1214. }
  1215. void InterpreterStackFrame::InitializeClosures()
  1216. {
  1217. FunctionBody *executeFunction = this->function->GetFunctionBody();
  1218. Var environment;
  1219. if (executeFunction->IsParamAndBodyScopeMerged())
  1220. {
  1221. this->SetIsParamScopeDone(true);
  1222. }
  1223. RegSlot thisRegForEventHandler = executeFunction->GetThisRegisterForEventHandler();
  1224. if (thisRegForEventHandler != Constants::NoRegister)
  1225. {
  1226. Var varThis = OP_ArgIn0();
  1227. SetReg(thisRegForEventHandler, varThis);
  1228. environment = JavascriptOperators::OP_LdHandlerScope(varThis, GetScriptContext());
  1229. this->SetEnv((FrameDisplay*)environment);
  1230. }
  1231. else if (this->paramClosure != nullptr)
  1232. {
  1233. // When paramClosure is non-null we are calling this method to initialize the closure for body scope.
  1234. // In this case we have to use the param scope's closure as the parent for the body scope's frame display.
  1235. Assert(!executeFunction->IsParamAndBodyScopeMerged());
  1236. environment = this->GetLocalFrameDisplay();
  1237. }
  1238. else
  1239. {
  1240. environment = this->LdEnv();
  1241. }
  1242. Var funcExprScope = nullptr;
  1243. Js::RegSlot funcExprScopeReg = executeFunction->GetFuncExprScopeRegister();
  1244. if (funcExprScopeReg != Constants::NoRegister && this->paramClosure == nullptr)
  1245. {
  1246. // t0 = NewPseudoScope
  1247. // t1 = LdFrameDisplay t0 env
  1248. funcExprScope = JavascriptOperators::OP_NewPseudoScope(GetScriptContext());
  1249. SetReg(funcExprScopeReg, funcExprScope);
  1250. }
  1251. RegSlot closureReg = executeFunction->GetLocalClosureRegister();
  1252. if (closureReg != Js::Constants::NoRegister)
  1253. {
  1254. Assert(closureReg >= executeFunction->GetConstantCount());
  1255. if (executeFunction->HasScopeObject())
  1256. {
  1257. this->NewScopeObject();
  1258. }
  1259. else
  1260. {
  1261. this->NewScopeSlots();
  1262. }
  1263. this->SetNonVarReg(closureReg, nullptr);
  1264. }
  1265. Js::RegSlot frameDisplayReg = executeFunction->GetLocalFrameDisplayRegister();
  1266. if (frameDisplayReg != Js::Constants::NoRegister)
  1267. {
  1268. Assert(frameDisplayReg >= executeFunction->GetConstantCount());
  1269. if (funcExprScope != nullptr)
  1270. {
  1271. environment = OP_LdFrameDisplay(funcExprScope, environment, GetScriptContext());
  1272. }
  1273. if (closureReg != Js::Constants::NoRegister)
  1274. {
  1275. void *argHead = this->GetLocalClosure();
  1276. environment = this->NewFrameDisplay(argHead, environment);
  1277. }
  1278. this->SetLocalFrameDisplay((Js::FrameDisplay*)environment);
  1279. this->SetNonVarReg(frameDisplayReg, nullptr);
  1280. }
  1281. this->closureInitDone = true;
  1282. }
  1283. #ifdef _M_IX86
  1284. #ifdef ASMJS_PLAT
  1285. int InterpreterStackFrame::GetAsmJsArgSize(AsmJsCallStackLayout* stack)
  1286. {
  1287. JavascriptFunction * func = stack->functionObject;
  1288. AsmJsFunctionInfo* asmInfo = func->GetFunctionBody()->GetAsmJsFunctionInfo();
  1289. uint argSize = (uint)(asmInfo->GetArgByteSize());
  1290. argSize = ::Math::Align<int32>(argSize, 8);
  1291. // 2 * sizeof(Var) is for functionObject, and another push that DynamicInterpreterThunk does
  1292. return argSize + 2 * sizeof(Var);
  1293. }
  1294. int InterpreterStackFrame::GetDynamicRetType(AsmJsCallStackLayout* stack)
  1295. {
  1296. return GetRetType(stack->functionObject);
  1297. }
  1298. int InterpreterStackFrame::GetRetType(JavascriptFunction* func)
  1299. {
  1300. AsmJsFunctionInfo* asmInfo = func->GetFunctionBody()->GetAsmJsFunctionInfo();
  1301. return asmInfo->GetReturnType().which();
  1302. }
  1303. #ifdef ASMJS_PLAT
  1304. /*
  1305. AsmInterpreterThunk
  1306. -------------------
  1307. This is the entrypoint for all Asm Interpreter calls (external and internal)
  1308. TODO - Make this a dynamic Interpreter thunk to support ETW
  1309. Functionality:
  1310. 1) Prolog
  1311. 2) call AsmInterpreter passing the function object
  1312. 3) Get The return type
  1313. 4) Check for Double or Float return type
  1314. 5) If true then retrieve the value stored at a constant offset from the ScriptContext
  1315. 6) Get Argument Size for callee cleanup
  1316. 7) EpiLog
  1317. a) Retrieve the frame pointer
  1318. b) Store the return address in register (edx)
  1319. c) Clean the arguments based on the arguments size
  1320. d) push the return address back into the stack
  1321. */
  1322. __declspec(naked)
  1323. void InterpreterStackFrame::InterpreterAsmThunk(AsmJsCallStackLayout* layout)
  1324. {
  1325. __asm
  1326. {
  1327. //Prologue
  1328. push ebp;
  1329. mov ebp, esp;
  1330. // Allocate space to put the return value
  1331. sub esp, 16;
  1332. and esp, -16;
  1333. push esp;
  1334. push layout;
  1335. call InterpreterStackFrame::AsmJsInterpreter;
  1336. // we need to move stack around in order to do callee cleanup
  1337. // unfortunately, we don't really have enough registers to do this cleanly
  1338. //
  1339. // we are rearranging the stack from this:
  1340. // 0x14 caller push scriptArg1
  1341. // 0x10 caller push functionObject
  1342. // 0x0C DynamicInterpreterThunk return address
  1343. // 0x08 DynamicInterpreterThunk push ebp
  1344. // 0x04 DynamicInterpreterThunk push functionObject
  1345. // 0x00 InterpreterAsmThunk return address <- stack pointer
  1346. // to this:
  1347. // 0x14 DynamicInterpreterThunk return address
  1348. // 0x10 DynamicInterpreterThunk push ebp
  1349. // 0x0C InterpreterAsmThunk return address <- stack pointer
  1350. // Read return value into possible registers
  1351. movups xmm0, [esp];
  1352. mov edx, [esp + 4];
  1353. mov eax, [esp];
  1354. mov ecx, layout;
  1355. // Epilog, callee cleanup
  1356. mov esp, ebp;
  1357. pop ebp;
  1358. push eax; // save eax
  1359. push edx; // save edx
  1360. // we have to do +0x8 on all stack addresses because we saved 2 registers
  1361. push ecx; // ebp has been restored, we can't use parameters anymore
  1362. call InterpreterStackFrame::GetAsmJsArgSize;
  1363. mov ecx, eax;
  1364. lea eax, [esp + ecx * 1 + 0x8 + 0x8]; // eax will be our stack destination
  1365. mov edx, [esp + 0xC + 0x8];
  1366. mov[eax], edx; // move the dynamic interpreter thunk return location
  1367. mov edx, [esp + 0x8 + 0x8];
  1368. mov[eax - 0x4], edx; // move the dynamic interpreter thunk "push ebp" location
  1369. // skip "push functionObject"
  1370. mov edx, [esp + 0x0 + 0x8];
  1371. mov[eax - 0x8], edx; // move the return location
  1372. pop edx; // restore possible int64 return value
  1373. pop eax; // restore return value
  1374. add esp, ecx; // cleanup arguments
  1375. ret;
  1376. }
  1377. }
  1378. #endif
  1379. #endif
  1380. #endif
  1381. #if DYNAMIC_INTERPRETER_THUNK
  1382. #ifdef _M_IX86
  1383. __declspec(naked)
  1384. Var InterpreterStackFrame::AsmJsDelayDynamicInterpreterThunk(RecyclableObject* function, CallInfo callInfo, ...)
  1385. {
  1386. __asm
  1387. {
  1388. push ebp;
  1389. mov ebp, esp;
  1390. push[esp + 8]; // push function object
  1391. call WasmLibrary::EnsureWasmEntrypoint;
  1392. test eax, eax;
  1393. jne skipThunk;
  1394. push[esp + 8]; // push function object
  1395. call InterpreterStackFrame::EnsureDynamicInterpreterThunk;
  1396. skipThunk:
  1397. #ifdef _CONTROL_FLOW_GUARD
  1398. // verify that the call target is valid
  1399. mov ecx, eax;
  1400. call[__guard_check_icall_fptr];
  1401. mov eax, ecx;
  1402. #endif
  1403. pop ebp;
  1404. jmp eax;
  1405. }
  1406. }
  1407. __declspec(naked)
  1408. Var InterpreterStackFrame::DelayDynamicInterpreterThunk(RecyclableObject* function, CallInfo callInfo, ...)
  1409. {
  1410. __asm
  1411. {
  1412. push ebp;
  1413. mov ebp, esp;
  1414. push[esp + 8]; // push function object
  1415. call InterpreterStackFrame::EnsureDynamicInterpreterThunk;
  1416. #ifdef _CONTROL_FLOW_GUARD
  1417. // verify that the call target is valid
  1418. mov ecx, eax;
  1419. call[__guard_check_icall_fptr];
  1420. mov eax, ecx;
  1421. #endif
  1422. pop ebp;
  1423. jmp eax;
  1424. }
  1425. }
  1426. #elif !defined(_M_AMD64)
  1427. Var InterpreterStackFrame::AsmJsDelayDynamicInterpreterThunk(RecyclableObject* function, CallInfo callInfo, ...)
  1428. {
  1429. // Asm.js only supported on x64 and x86
  1430. AssertOrFailFast(UNREACHED);
  1431. return nullptr;
  1432. }
  1433. #endif
  1434. #endif
  1435. #if ENABLE_PROFILE_INFO
  1436. JavascriptMethod InterpreterStackFrame::EnsureDynamicInterpreterThunk(Js::ScriptFunction * function)
  1437. {
  1438. #if DYNAMIC_INTERPRETER_THUNK
  1439. Assert(function);
  1440. Js::FunctionBody *functionBody = function->GetFunctionBody();
  1441. JavascriptMethod entrypoint = functionBody->EnsureDynamicInterpreterThunk(function->GetFunctionEntryPointInfo());
  1442. Assert(!IsDelayDynamicInterpreterThunk(functionBody->GetDirectEntryPoint(function->GetEntryPointInfo())));
  1443. if (function->GetEntryPoint() == InterpreterStackFrame::DelayDynamicInterpreterThunk)
  1444. {
  1445. // If we are not profiling, or the function object is not cross site, this is the direct entry point.
  1446. // Change the entry point on the object
  1447. Assert(functionBody->GetDirectEntryPoint(function->GetEntryPointInfo()) == entrypoint);
  1448. function->ChangeEntryPoint(function->GetEntryPointInfo(), entrypoint);
  1449. }
  1450. // Return the original entry point to be called
  1451. return entrypoint;
  1452. #else
  1453. return function->GetEntryPoint();
  1454. #endif
  1455. }
  1456. #endif
  1457. bool InterpreterStackFrame::IsDelayDynamicInterpreterThunk(JavascriptMethod entryPoint)
  1458. {
  1459. return false
  1460. #if DYNAMIC_INTERPRETER_THUNK
  1461. || entryPoint == InterpreterStackFrame::DelayDynamicInterpreterThunk
  1462. #ifdef ASMJS_PLAT
  1463. || entryPoint == InterpreterStackFrame::AsmJsDelayDynamicInterpreterThunk
  1464. #endif
  1465. #endif
  1466. ;
  1467. }
  1468. #ifdef ENABLE_DEBUG_CONFIG_OPTIONS
  1469. THREAD_LOCAL int InterpreterThunkStackCountTracker::s_count = 0;
  1470. #endif
  1471. #if DYNAMIC_INTERPRETER_THUNK
  1472. #pragma optimize("", off)
  1473. #ifdef ASMJS_PLAT
  1474. void InterpreterStackFrame::StaticInterpreterAsmThunk(RecyclableObject* function, ...)
  1475. {
  1476. InterpreterAsmThunk((AsmJsCallStackLayout*)&function);
  1477. }
  1478. #endif
  1479. #if !defined(_M_ARM64)
  1480. Var InterpreterStackFrame::StaticInterpreterThunk(RecyclableObject* function, CallInfo callInfo, ...)
  1481. {
  1482. return InterpreterThunk((JavascriptCallStackLayout*)&function);
  1483. }
  1484. #else
  1485. // Language\arm64\arm64_Thunks.asm
  1486. #endif
  1487. #pragma optimize("", on)
  1488. Var InterpreterStackFrame::InterpreterThunk(JavascriptCallStackLayout* layout)
  1489. {
  1490. Js::ScriptFunction * function = Js::ScriptFunction::UnsafeFromVar(layout->functionObject);
  1491. Js::ArgumentReader args(&layout->callInfo, layout->args);
  1492. void* localReturnAddress = _ReturnAddress();
  1493. void* localAddressOfReturnAddress = _AddressOfReturnAddress();
  1494. return InterpreterHelper(function, args, localReturnAddress, localAddressOfReturnAddress);
  1495. }
  1496. #else
  1497. #pragma optimize("", off)
  1498. Var InterpreterStackFrame::InterpreterThunk(RecyclableObject* function, CallInfo callInfo, ...)
  1499. {
  1500. ARGUMENTS(args, callInfo);
  1501. void* localReturnAddress = _ReturnAddress();
  1502. void* localAddressOfReturnAddress = _AddressOfReturnAddress();
  1503. Assert(ScriptFunction::Is(function));
  1504. return InterpreterHelper(ScriptFunction::FromVar(function), args, localReturnAddress, localAddressOfReturnAddress);
  1505. }
  1506. #pragma optimize("", on)
  1507. #endif
  1508. const bool InterpreterStackFrame::ShouldDoProfile(FunctionBody* executeFunction)
  1509. {
  1510. #if ENABLE_PROFILE_INFO
  1511. const bool doProfile = executeFunction->GetInterpreterExecutionMode(false) == ExecutionMode::ProfilingInterpreter ||
  1512. (executeFunction->IsInDebugMode() && DynamicProfileInfo::IsEnabled(executeFunction));
  1513. return doProfile;
  1514. #else
  1515. return false;
  1516. #endif
  1517. }
  1518. InterpreterStackFrame* InterpreterStackFrame::CreateInterpreterStackFrameForGenerator(ScriptFunction* function, FunctionBody* executeFunction, JavascriptGenerator* generator, bool doProfile)
  1519. {
  1520. //
  1521. // Allocate a new InterpreterStackFrame instance on the recycler heap.
  1522. // It will live with the JavascriptGenerator object.
  1523. //
  1524. ScriptContext* functionScriptContext = function->GetScriptContext();
  1525. Arguments generatorArgs = generator->GetArguments();
  1526. InterpreterStackFrame::Setup setup(function, generatorArgs);
  1527. Assert(setup.GetStackAllocationVarCount() == 0);
  1528. size_t varAllocCount = setup.GetAllocationVarCount();
  1529. size_t varSizeInBytes = varAllocCount * sizeof(Var);
  1530. DWORD_PTR stackAddr = reinterpret_cast<DWORD_PTR>(&generator); // use any stack address from this frame to ensure correct debugging functionality
  1531. LoopHeader* loopHeaderArray = executeFunction->GetHasAllocatedLoopHeaders() ? executeFunction->GetLoopHeaderArrayPtr() : nullptr;
  1532. Var* allocation = RecyclerNewPlus(functionScriptContext->GetRecycler(), varSizeInBytes, Var);
  1533. AnalysisAssert(allocation);
  1534. InterpreterStackFrame* newInstance;
  1535. #if DBG
  1536. // Allocate invalidVar on GC instead of stack since this InterpreterStackFrame will out live the current real frame
  1537. Js::RecyclableObject* invalidVar = (Js::RecyclableObject*)RecyclerNewPlusLeaf(functionScriptContext->GetRecycler(), sizeof(Js::RecyclableObject), Var);
  1538. AnalysisAssert(invalidVar);
  1539. memset(reinterpret_cast<void*>(invalidVar), 0xFE, sizeof(Js::RecyclableObject));
  1540. #endif
  1541. newInstance = setup.InitializeAllocation(allocation, nullptr, executeFunction->GetHasImplicitArgIns(), doProfile, loopHeaderArray, stackAddr
  1542. #if DBG
  1543. , invalidVar
  1544. #endif
  1545. );
  1546. newInstance->m_reader.Create(executeFunction);
  1547. generator->SetFrame(newInstance, varSizeInBytes);
  1548. return newInstance;
  1549. }
  1550. Var InterpreterStackFrame::InterpreterHelper(ScriptFunction* function, ArgumentReader args, void* returnAddress, void* addressOfReturnAddress, AsmJsReturnStruct* asmJsReturn)
  1551. {
  1552. const bool isAsmJs = asmJsReturn != nullptr;
  1553. #ifdef ENABLE_DEBUG_CONFIG_OPTIONS
  1554. // Support for simulating partially initialized interpreter stack frame.
  1555. InterpreterThunkStackCountTracker tracker;
  1556. if (CONFIG_ISENABLED(InjectPartiallyInitializedInterpreterFrameErrorFlag) &&
  1557. CONFIG_FLAG(InjectPartiallyInitializedInterpreterFrameError) == InterpreterThunkStackCountTracker::GetCount())
  1558. {
  1559. switch (CONFIG_FLAG(InjectPartiallyInitializedInterpreterFrameErrorType))
  1560. {
  1561. case 0:
  1562. DebugBreak();
  1563. break;
  1564. case 1:
  1565. Js::JavascriptError::MapAndThrowError(function->GetScriptContext(), VBSERR_InternalError);
  1566. break;
  1567. default:
  1568. DebugBreak();
  1569. }
  1570. }
  1571. #endif
  1572. ScriptContext* functionScriptContext = function->GetScriptContext();
  1573. ThreadContext * threadContext = functionScriptContext->GetThreadContext();
  1574. Assert(!threadContext->IsDisableImplicitException());
  1575. functionScriptContext->VerifyAlive(!function->IsExternal());
  1576. Assert(threadContext->IsScriptActive());
  1577. Assert(threadContext->IsInScript());
  1578. FunctionBody* executeFunction = JavascriptFunction::UnsafeFromVar(function)->GetFunctionBody();
  1579. #ifdef ENABLE_DEBUG_CONFIG_OPTIONS
  1580. if (!isAsmJs && executeFunction->IsInDebugMode() != functionScriptContext->IsScriptContextInDebugMode()) // debug mode mismatch
  1581. {
  1582. if (executeFunction->GetUtf8SourceInfo()->GetIsLibraryCode())
  1583. {
  1584. Assert(!executeFunction->IsInDebugMode()); // Library script byteCode is never in debug mode
  1585. }
  1586. else
  1587. {
  1588. Throw::FatalInternalError();
  1589. }
  1590. }
  1591. #endif
  1592. if (executeFunction->GetInterpretedCount() == 0)
  1593. {
  1594. executeFunction->TraceInterpreterExecutionMode();
  1595. }
  1596. class AutoRestore
  1597. {
  1598. private:
  1599. ThreadContext * const threadContext;
  1600. const uint8 savedLoopDepth;
  1601. public:
  1602. AutoRestore(ThreadContext *const threadContext, FunctionBody *const executeFunction)
  1603. : threadContext(threadContext),
  1604. savedLoopDepth(threadContext->LoopDepth())
  1605. {
  1606. if (savedLoopDepth != 0 && !executeFunction->GetIsAsmJsFunction())
  1607. {
  1608. executeFunction->SetWasCalledFromLoop();
  1609. }
  1610. }
  1611. ~AutoRestore()
  1612. {
  1613. threadContext->SetLoopDepth(savedLoopDepth);
  1614. }
  1615. } autoRestore(threadContext, executeFunction);
  1616. #if ENABLE_PROFILE_INFO
  1617. DynamicProfileInfo * dynamicProfileInfo = nullptr;
  1618. const bool doProfile = ShouldDoProfile(executeFunction);
  1619. if (doProfile)
  1620. {
  1621. #if !DYNAMIC_INTERPRETER_THUNK
  1622. executeFunction->EnsureDynamicProfileInfo();
  1623. #endif
  1624. dynamicProfileInfo = executeFunction->GetDynamicProfileInfo();
  1625. threadContext->ClearImplicitCallFlags();
  1626. }
  1627. #else
  1628. const bool doProfile = false;
  1629. #endif
  1630. executeFunction->IncreaseInterpretedCount();
  1631. #ifdef BGJIT_STATS
  1632. functionScriptContext->interpretedCount++;
  1633. functionScriptContext->maxFuncInterpret = max(functionScriptContext->maxFuncInterpret, executeFunction->GetInterpretedCount());
  1634. #endif
  1635. AssertMsg(!executeFunction->IsDeferredParseFunction(),
  1636. "Non-intrinsic functions must provide byte-code to execute");
  1637. executeFunction->BeginExecution();
  1638. bool fReleaseAlloc = false;
  1639. InterpreterStackFrame* newInstance = nullptr;
  1640. if (!isAsmJs && executeFunction->IsCoroutine())
  1641. {
  1642. // If the FunctionBody is a generator then this call is being made by one of the three
  1643. // generator resuming methods: next(), throw(), or return(). They all pass the generator
  1644. // object as the first of two arguments. The real user arguments are obtained from the
  1645. // generator object. The second argument is the ResumeYieldData which is only needed
  1646. // when resuming a generator and so it only used here if a frame already exists on the
  1647. // generator object.
  1648. AssertOrFailFastMsg(args.Info.Count == 2 && ((args.Info.Flags & CallFlags_ExtraArg) == CallFlags_None), "Generator ScriptFunctions should only be invoked by generator APIs with the pair of arguments they pass in -- the generator object and a ResumeYieldData pointer");
  1649. JavascriptGenerator* generator = JavascriptGenerator::FromVar(args[0]);
  1650. newInstance = generator->GetFrame();
  1651. if (newInstance != nullptr)
  1652. {
  1653. ResumeYieldData* resumeYieldData = static_cast<ResumeYieldData*>(args[1]);
  1654. newInstance->SetNonVarReg(executeFunction->GetYieldRegister(), resumeYieldData);
  1655. // The debugger relies on comparing stack addresses of frames to decide when a step_out is complete so
  1656. // give the InterpreterStackFrame a legit enough stack address to make this comparison work.
  1657. newInstance->m_stackAddress = reinterpret_cast<DWORD_PTR>(&generator);
  1658. }
  1659. else
  1660. {
  1661. newInstance = CreateInterpreterStackFrameForGenerator(function, executeFunction, generator, doProfile);
  1662. }
  1663. }
  1664. else
  1665. {
  1666. InterpreterStackFrame::Setup setup(function, args);
  1667. size_t varAllocCount = setup.GetAllocationVarCount();
  1668. size_t stackVarAllocCount = setup.GetStackAllocationVarCount();
  1669. size_t varSizeInBytes;
  1670. //
  1671. // Allocate a new InterpreterStackFrame instance on the interpreter's virtual stack.
  1672. //
  1673. DWORD_PTR stackAddr;
  1674. Var* allocation;
  1675. Var* stackAllocation = nullptr;
  1676. // If the locals area exceeds a certain limit, allocate it from a private arena rather than
  1677. // this frame. The current limit is based on an old assert on the number of locals we would allow here.
  1678. if ((varAllocCount + stackVarAllocCount) > InterpreterStackFrame::LocalsThreshold)
  1679. {
  1680. ArenaAllocator *tmpAlloc = nullptr;
  1681. fReleaseAlloc = functionScriptContext->EnsureInterpreterArena(&tmpAlloc);
  1682. varSizeInBytes = varAllocCount * sizeof(Var);
  1683. allocation = (Var*)tmpAlloc->Alloc(varSizeInBytes);
  1684. stackAddr = reinterpret_cast<DWORD_PTR>(&allocation); // use a stack address so the debugger stepping logic works (step-out, for example, compares stack depths to determine when to complete the step)
  1685. if (stackVarAllocCount != 0)
  1686. {
  1687. size_t stackVarSizeInBytes = stackVarAllocCount * sizeof(Var);
  1688. PROBE_STACK_PARTIAL_INITIALIZED_INTERPRETER_FRAME(functionScriptContext, Js::Constants::MinStackInterpreter + stackVarSizeInBytes);
  1689. stackAllocation = (Var*)_alloca(stackVarSizeInBytes);
  1690. }
  1691. }
  1692. else
  1693. {
  1694. varSizeInBytes = (varAllocCount + stackVarAllocCount) * sizeof(Var);
  1695. PROBE_STACK_PARTIAL_INITIALIZED_INTERPRETER_FRAME(functionScriptContext, Js::Constants::MinStackInterpreter + varSizeInBytes);
  1696. allocation = (Var*)_alloca(varSizeInBytes);
  1697. #if DBG
  1698. memset(allocation, 0xFE, varSizeInBytes);
  1699. #endif
  1700. stackAddr = reinterpret_cast<DWORD_PTR>(allocation);
  1701. }
  1702. /*
  1703. * If the function has any loop headers, we allocate an array for the loop headers wrappers, and
  1704. * reference the wrappers in the array. We then push the pointer to the array onto the stack itself.
  1705. * We do this so that while the function is being interpreted, we don't want the jitted loop
  1706. * bodies to be collected, even if the loop body isn't being executed. The loop body will
  1707. * get collected when the function has been JITted, and when the function exits the interpreter.
  1708. * The array contains nulls if the loop body isn't jitted (or hasn't been jitted yet) but
  1709. * it's cheaper to just copy them all into the recycler array rather than just the ones that
  1710. * have been jitted.
  1711. */
  1712. LoopHeader* loopHeaderArray = nullptr;
  1713. if (executeFunction->GetHasAllocatedLoopHeaders())
  1714. {
  1715. // Loop header array is recycler allocated, so we push it on the stack
  1716. // When we scan the stack, we'll recognize it as a recycler allocated
  1717. // object, and mark it's contents and keep the individual loop header
  1718. // wrappers alive
  1719. loopHeaderArray = executeFunction->GetLoopHeaderArrayPtr();
  1720. }
  1721. #if DBG
  1722. Js::RecyclableObject * invalidStackVar = (Js::RecyclableObject*)_alloca(sizeof(Js::RecyclableObject));
  1723. memset(reinterpret_cast<void*>(invalidStackVar), 0xFE, sizeof(Js::RecyclableObject));
  1724. #endif
  1725. newInstance = setup.InitializeAllocation(allocation, stackAllocation, executeFunction->GetHasImplicitArgIns() && !isAsmJs, doProfile, loopHeaderArray, stackAddr
  1726. #if DBG
  1727. , invalidStackVar
  1728. #endif
  1729. );
  1730. newInstance->m_reader.Create(executeFunction);
  1731. }
  1732. //
  1733. // Execute the function's byte-code, returning the return-value:
  1734. // - Mark that the function is current executing and may not be modified.
  1735. //
  1736. #if ENABLE_TTD
  1737. TTD::TTDExceptionFramePopper exceptionFramePopper;
  1738. if (SHOULD_DO_TTD_STACK_STMT_OP(functionScriptContext))
  1739. {
  1740. bool isInFinally = newInstance->TestFlags(Js::InterpreterStackFrameFlags_WithinFinallyBlock);
  1741. threadContext->TTDExecutionInfo->PushCallEvent(function, args.Info.Count, args.Values, isInFinally);
  1742. exceptionFramePopper.PushInfo(threadContext->TTDExecutionInfo, function);
  1743. }
  1744. #endif
  1745. Var aReturn = nullptr;
  1746. {
  1747. #ifdef ENABLE_SCRIPT_DEBUGGING
  1748. if (!isAsmJs && executeFunction->IsInDebugMode())
  1749. {
  1750. #if DYNAMIC_INTERPRETER_THUNK
  1751. PushPopFrameHelper pushPopFrameHelper(newInstance, returnAddress, addressOfReturnAddress);
  1752. aReturn = newInstance->DebugProcess();
  1753. #else
  1754. aReturn = newInstance->DebugProcessThunk(_ReturnAddress(), _AddressOfReturnAddress());
  1755. #endif
  1756. }
  1757. else
  1758. #endif
  1759. {
  1760. #if DYNAMIC_INTERPRETER_THUNK
  1761. PushPopFrameHelper pushPopFrameHelper(newInstance, returnAddress, addressOfReturnAddress);
  1762. aReturn = newInstance->Process();
  1763. #else
  1764. aReturn = newInstance->ProcessThunk(_ReturnAddress(), _AddressOfReturnAddress());
  1765. #endif
  1766. }
  1767. }
  1768. executeFunction->EndExecution();
  1769. #if ENABLE_TTD
  1770. if (SHOULD_DO_TTD_STACK_STMT_OP(functionScriptContext))
  1771. {
  1772. exceptionFramePopper.PopInfo();
  1773. threadContext->TTDExecutionInfo->PopCallEvent(function, aReturn);
  1774. }
  1775. #endif
  1776. #ifdef ASMJS_PLAT
  1777. if (isAsmJs)
  1778. {
  1779. asmJsReturn->i = newInstance->GetRegRawInt(0);
  1780. asmJsReturn->l = newInstance->GetRegRawInt64(0);
  1781. asmJsReturn->d = newInstance->GetRegRawDouble(0);
  1782. asmJsReturn->f = newInstance->GetRegRawFloat(0);
  1783. asmJsReturn->simd = newInstance->GetRegRawSimd(0);
  1784. }
  1785. #endif
  1786. if (fReleaseAlloc)
  1787. {
  1788. functionScriptContext->ReleaseInterpreterArena();
  1789. }
  1790. #if ENABLE_PROFILE_INFO
  1791. if (doProfile)
  1792. {
  1793. dynamicProfileInfo->RecordImplicitCallFlags(threadContext->GetImplicitCallFlags());
  1794. }
  1795. #endif
  1796. return aReturn;
  1797. }
  1798. #ifdef ASMJS_PLAT
  1799. #if _M_IX86
  1800. void InterpreterStackFrame::AsmJsInterpreter(AsmJsCallStackLayout* stack, byte* retDst)
  1801. {
  1802. ScriptFunction * function = (ScriptFunction*)stack->functionObject;
  1803. Var* paramsAddr = stack->args;
  1804. int flags = CallFlags_Value;
  1805. ArgSlot nbArgs = ArgSlotMath::Add(function->GetFunctionBody()->GetAsmJsFunctionInfo()->GetArgCount(), 1);
  1806. CallInfo callInfo((CallFlags)flags, nbArgs);
  1807. ArgumentReader args(&callInfo, paramsAddr);
  1808. void* returnAddress = _ReturnAddress();
  1809. void* addressOfReturnAddress = _AddressOfReturnAddress();
  1810. #if ENABLE_PROFILE_INFO
  1811. function->GetFunctionBody()->EnsureDynamicProfileInfo();
  1812. #endif
  1813. AsmJsReturnStruct asmJsReturn = { 0 };
  1814. InterpreterHelper(function, args, returnAddress, addressOfReturnAddress, &asmJsReturn);
  1815. //Handle return value
  1816. AsmJsRetType::Which retType = (AsmJsRetType::Which) GetRetType(function);
  1817. switch (retType)
  1818. {
  1819. #ifdef ENABLE_WASM_SIMD
  1820. case AsmJsRetType::Int32x4:
  1821. case AsmJsRetType::Bool32x4:
  1822. case AsmJsRetType::Bool16x8:
  1823. case AsmJsRetType::Bool8x16:
  1824. case AsmJsRetType::Float32x4:
  1825. case AsmJsRetType::Float64x2:
  1826. case AsmJsRetType::Int16x8:
  1827. case AsmJsRetType::Int8x16:
  1828. case AsmJsRetType::Uint32x4:
  1829. case AsmJsRetType::Uint16x8:
  1830. case AsmJsRetType::Uint8x16:
  1831. Assert(Wasm::Simd::IsEnabled());
  1832. *(AsmJsSIMDValue*)retDst = asmJsReturn.simd;
  1833. break;
  1834. #endif
  1835. // double return
  1836. case AsmJsRetType::Double:
  1837. *(double*)retDst = asmJsReturn.d;
  1838. break;
  1839. // float return
  1840. case AsmJsRetType::Float:
  1841. *(float*)retDst = asmJsReturn.f;
  1842. break;
  1843. // signed or void return
  1844. case AsmJsRetType::Signed:
  1845. case AsmJsRetType::Void:
  1846. *(int*)retDst = asmJsReturn.i;
  1847. break;
  1848. case AsmJsRetType::Int64:
  1849. *(int64*)retDst = asmJsReturn.l;
  1850. break;
  1851. default:
  1852. Assume(false);
  1853. }
  1854. }
  1855. #elif _M_X64
  1856. typedef double(*AsmJsInterpreterDoubleEP)(AsmJsCallStackLayout*, void *);
  1857. typedef float(*AsmJsInterpreterFloatEP)(AsmJsCallStackLayout*, void *);
  1858. typedef int(*AsmJsInterpreterIntEP)(AsmJsCallStackLayout*, void *);
  1859. typedef int64(*AsmJsInterpreterInt64EP)(AsmJsCallStackLayout*, void *);
  1860. void * InterpreterStackFrame::GetAsmJsInterpreterEntryPoint(AsmJsCallStackLayout* stack)
  1861. {
  1862. JavascriptFunction * function = stack->functionObject;
  1863. void * entryPoint = nullptr;
  1864. switch (function->GetFunctionBody()->GetAsmJsFunctionInfo()->GetReturnType().which())
  1865. {
  1866. case Js::AsmJsRetType::Double:
  1867. {
  1868. entryPoint = (void*)(AsmJsInterpreterDoubleEP)Js::InterpreterStackFrame::AsmJsInterpreter < double >;
  1869. break;
  1870. }
  1871. case Js::AsmJsRetType::Float:
  1872. {
  1873. entryPoint = (void*)(AsmJsInterpreterFloatEP)Js::InterpreterStackFrame::AsmJsInterpreter < float >;
  1874. break;
  1875. }
  1876. case Js::AsmJsRetType::Signed:
  1877. case Js::AsmJsRetType::Void:
  1878. {
  1879. entryPoint = (void*)(AsmJsInterpreterIntEP)Js::InterpreterStackFrame::AsmJsInterpreter < int >;
  1880. break;
  1881. }
  1882. case Js::AsmJsRetType::Int64:
  1883. {
  1884. entryPoint = (void*)(AsmJsInterpreterInt64EP)Js::InterpreterStackFrame::AsmJsInterpreter < int64 >;
  1885. break;
  1886. }
  1887. #ifdef ENABLE_WASM_SIMD
  1888. case Js::AsmJsRetType::Int32x4:
  1889. case Js::AsmJsRetType::Bool32x4:
  1890. case Js::AsmJsRetType::Bool16x8:
  1891. case Js::AsmJsRetType::Bool8x16:
  1892. case Js::AsmJsRetType::Float32x4:
  1893. case Js::AsmJsRetType::Float64x2:
  1894. case Js::AsmJsRetType::Int16x8:
  1895. case Js::AsmJsRetType::Int8x16:
  1896. case Js::AsmJsRetType::Uint32x4:
  1897. case Js::AsmJsRetType::Uint16x8:
  1898. case Js::AsmJsRetType::Uint8x16:
  1899. {
  1900. entryPoint = (void*)Js::InterpreterStackFrame::AsmJsInterpreterSimdJs;
  1901. break;
  1902. }
  1903. #endif
  1904. default:
  1905. Assume(UNREACHED);
  1906. }
  1907. return entryPoint;
  1908. }
  1909. template<typename T>
  1910. T InterpreterStackFrame::AsmJsInterpreter(AsmJsCallStackLayout* layout)
  1911. {
  1912. Js::ScriptFunction * function = Js::ScriptFunction::FromVar(layout->functionObject);
  1913. int flags = CallFlags_Value;
  1914. ArgSlot nbArgs = ArgSlotMath::Add(function->GetFunctionBody()->GetAsmJsFunctionInfo()->GetArgCount(), 1);
  1915. CallInfo callInfo((CallFlags)flags, nbArgs);
  1916. ArgumentReader args(&callInfo, (Var*)layout->args);
  1917. void* returnAddress = _ReturnAddress();
  1918. void* addressOfReturnAddress = _AddressOfReturnAddress();
  1919. function->GetFunctionBody()->EnsureDynamicProfileInfo();
  1920. AsmJsReturnStruct asmJsReturn = { 0 };
  1921. InterpreterHelper(function, args, returnAddress, addressOfReturnAddress, &asmJsReturn);
  1922. return asmJsReturn.GetRetVal<T>();
  1923. }
  1924. __m128 InterpreterStackFrame::AsmJsInterpreterSimdJs(AsmJsCallStackLayout* layout)
  1925. {
  1926. return AsmJsInterpreter<X86SIMDValue>(layout).m128_value;
  1927. }
  1928. #endif
  1929. #endif
  1930. ///----------------------------------------------------------------------------
  1931. ///
  1932. /// InterpreterStackFrame::SetOut()
  1933. ///
  1934. /// SetOut() change the Var value stored in the specified "out parameter"
  1935. /// register.
  1936. ///
  1937. ///----------------------------------------------------------------------------
  1938. inline void InterpreterStackFrame::SetOut(ArgSlot outRegisterID, Var aValue)
  1939. {
  1940. //
  1941. // The "out" parameter slots are located at the end of the local register range, counting
  1942. // forwards. This results in the "in" parameter slots being disjoint from the rest of the
  1943. // InterpreterStackFrame.
  1944. // ..., InterpreterStackFrame A, Locals A[], ..., Out A:0, Out A:1, Out A:2, ...
  1945. // | In B:0, In B:1, ..., InterpreterStackFrame B, Locals B[], ...
  1946. // (current 'this') |
  1947. // (new 'this' after call)
  1948. //
  1949. Assert(m_outParams + outRegisterID < m_outSp);
  1950. m_outParams[outRegisterID] = aValue;
  1951. }
  1952. inline void InterpreterStackFrame::SetOut(ArgSlot_OneByte outRegisterID, Var aValue)
  1953. {
  1954. Assert(m_outParams + outRegisterID < m_outSp);
  1955. m_outParams[outRegisterID] = aValue;
  1956. }
  1957. inline void InterpreterStackFrame::OP_SetOutAsmDb(RegSlot outRegisterID, double val)
  1958. {
  1959. Assert(m_outParams + outRegisterID < m_outSp);
  1960. m_outParams[outRegisterID] = JavascriptNumber::NewWithCheck(val, scriptContext);
  1961. }
  1962. inline void InterpreterStackFrame::OP_SetOutAsmInt(RegSlot outRegisterID, int val)
  1963. {
  1964. Assert(m_outParams + outRegisterID < m_outSp);
  1965. m_outParams[outRegisterID] = JavascriptNumber::ToVar(val, scriptContext);
  1966. }
  1967. void InterpreterStackFrame::OP_SetOutAsmFlt(RegSlot outRegisterID, float val)
  1968. {
  1969. OP_SetOutAsmDb(outRegisterID, (double)val);
  1970. }
  1971. inline void InterpreterStackFrame::OP_I_SetOutAsmFlt(RegSlot outRegisterID, float val)
  1972. {
  1973. Assert(m_outParams + outRegisterID < m_outSp);
  1974. *(float*)(&(m_outParams[outRegisterID])) = val;
  1975. }
  1976. inline void InterpreterStackFrame::OP_I_SetOutAsmLong(RegSlot outRegisterID, int64 val)
  1977. {
  1978. Assert(m_outParams + outRegisterID < m_outSp);
  1979. *(int64*)(&(m_outParams[outRegisterID])) = val;
  1980. }
  1981. inline void InterpreterStackFrame::OP_I_SetOutAsmInt(RegSlot outRegisterID, int val)
  1982. {
  1983. Assert(m_outParams + outRegisterID < m_outSp);
  1984. *(int*)(&(m_outParams[outRegisterID])) = val;
  1985. }
  1986. inline void InterpreterStackFrame::OP_I_SetOutAsmDb(RegSlot outRegisterID, double val)
  1987. {
  1988. Assert(m_outParams + outRegisterID < m_outSp);
  1989. *(double*)(&(m_outParams[outRegisterID])) = val;
  1990. }
  1991. inline void InterpreterStackFrame::OP_I_SetOutAsmSimd(RegSlot outRegisterID, AsmJsSIMDValue val)
  1992. {
  1993. Assert(m_outParams + outRegisterID < m_outSp);
  1994. *(AsmJsSIMDValue*)(&(m_outParams[outRegisterID])) = val;
  1995. }
  1996. template<int type, bool toJs>
  1997. void InterpreterStackFrame::OP_InvalidWasmTypeConversion(...)
  1998. {
  1999. #ifdef ENABLE_WASM
  2000. CompileAssert(type < Wasm::WasmTypes::Limit);
  2001. const char16* fromType = toJs ? Wasm::WasmTypes::GetTypeName(static_cast<Wasm::WasmTypes::WasmType>(type)) : _u("Javascript Variable");
  2002. const char16* toType = toJs ? _u("Javascript Variable") : Wasm::WasmTypes::GetTypeName(static_cast<Wasm::WasmTypes::WasmType>(type));
  2003. JavascriptError::ThrowTypeErrorVar(scriptContext, WASMERR_InvalidTypeConversion, fromType, toType);
  2004. #else
  2005. Assert(UNREACHED); //shouldn't get there
  2006. JavascriptError::ThrowTypeErrorVar(scriptContext, WASMERR_InvalidTypeConversion, _u("unknown"), _u("unknown")); //throw for a release build
  2007. #endif
  2008. }
  2009. // This will be called in the beginning of the try_finally.
  2010. inline void InterpreterStackFrame::CacheSp()
  2011. {
  2012. // Before caching the current m_outSp, we will be storing the previous the previously stored value in the m_outSpCached.
  2013. *m_outSp++ = (Var)m_outSpCached;
  2014. *m_outSp++ = (Var)m_outParams;
  2015. m_outSpCached = m_outSp - 2;
  2016. }
  2017. inline void InterpreterStackFrame::RestoreSp()
  2018. {
  2019. // This will be called in the Finally block to restore from the previous SP cached.
  2020. // m_outSpCached can be null if the catch block is called.
  2021. if (m_outSpCached != nullptr)
  2022. {
  2023. Assert(m_outSpCached < m_outSp);
  2024. m_outSp = m_outSpCached;
  2025. m_outSpCached = (Var*)*m_outSp;
  2026. Assert(m_outSpCached == nullptr || m_outSpCached <= m_outSp);
  2027. m_outParams = (Var*)*(m_outSp + 1);
  2028. }
  2029. else
  2030. {
  2031. ResetOut();
  2032. }
  2033. }
  2034. inline void InterpreterStackFrame::PushOut(Var aValue)
  2035. {
  2036. *m_outSp++ = aValue;
  2037. }
  2038. inline void InterpreterStackFrame::PopOut(ArgSlot argCount)
  2039. {
  2040. ArgSlotMath::Inc(argCount);
  2041. m_outSp -= argCount;
  2042. m_outParams = (Var*)*m_outSp;
  2043. AssertMsg(m_localSlots + this->m_functionBody->GetLocalsCount() <= m_outSp &&
  2044. m_outSp < (m_localSlots + this->m_functionBody->GetLocalsCount() + this->m_functionBody->GetOutParamMaxDepth()),
  2045. "out args Stack pointer not in range after Pop");
  2046. }
  2047. void InterpreterStackFrame::ResetOut()
  2048. {
  2049. //
  2050. // Reset the m_outParams and m_outSp
  2051. //
  2052. m_outParams = m_localSlots + this->m_functionBody->GetLocalsCount();
  2053. m_outSp = m_outParams;
  2054. m_outSpCached = nullptr;
  2055. }
  2056. #ifdef ENABLE_SCRIPT_DEBUGGING
  2057. _NOINLINE
  2058. Var InterpreterStackFrame::DebugProcessThunk(void* returnAddress, void* addressOfReturnAddress)
  2059. {
  2060. PushPopFrameHelper pushPopFrameHelper(this, returnAddress, addressOfReturnAddress);
  2061. return this->DebugProcess();
  2062. }
  2063. //
  2064. // Under debug mode allow the exception to be swallowed and execution to continue
  2065. // if the debugger has specified that behavior.
  2066. //
  2067. Var InterpreterStackFrame::DebugProcess()
  2068. {
  2069. Assert(this->returnAddress != nullptr);
  2070. while (true)
  2071. {
  2072. JavascriptExceptionObject *exception = nullptr;
  2073. try
  2074. {
  2075. #if ENABLE_TTD
  2076. if (SHOULD_DO_TTD_STACK_STMT_OP(this->scriptContext))
  2077. {
  2078. return this->ProcessWithDebugging_PreviousStmtTracking();
  2079. }
  2080. else
  2081. {
  2082. return this->ProcessWithDebugging();
  2083. }
  2084. #else
  2085. return this->ProcessWithDebugging();
  2086. #endif
  2087. }
  2088. catch (const Js::JavascriptException& err)
  2089. {
  2090. JavascriptExceptionObject *exception_ = err.GetAndClear();
  2091. Assert(exception_);
  2092. exception = exception_;
  2093. }
  2094. if (exception)
  2095. {
  2096. bool skipException = false;
  2097. if (!exception->IsGeneratorReturnException() &&
  2098. exception != scriptContext->GetThreadContext()->GetPendingSOErrorObject() &&
  2099. exception != scriptContext->GetThreadContext()->GetPendingOOMErrorObject())
  2100. {
  2101. skipException = exception->IsDebuggerSkip();
  2102. }
  2103. if (skipException)
  2104. {
  2105. // If we are going to swallow the exception then advance to the beginning of the next user statement
  2106. if (exception->IsIgnoreAdvanceToNextStatement()
  2107. || this->scriptContext->GetDebugContext()->GetProbeContainer()->AdvanceToNextUserStatement(this->m_functionBody, &this->m_reader))
  2108. {
  2109. // We must fix up the return value to at least be undefined:
  2110. this->SetReg((RegSlot)0, this->scriptContext->GetLibrary()->GetUndefined());
  2111. // If we recover from the exception, there may be a chance the out pointers in the InterpreterStackframe are not in a proper state.
  2112. // Reset them to correct the stack.
  2113. ResetOut();
  2114. // If we can successfully advance then continuing processing
  2115. continue;
  2116. }
  2117. }
  2118. JavascriptExceptionOperators::DoThrowCheckClone(exception, scriptContext);
  2119. }
  2120. }
  2121. }
  2122. #endif
  2123. template<typename OpCodeType, Js::OpCode(ReadOpFunc)(const byte*&), void (TracingFunc)(InterpreterStackFrame*, OpCodeType)>
  2124. OpCodeType InterpreterStackFrame::ReadOp(const byte *& ip)
  2125. {
  2126. #if DBG || DBG_DUMP
  2127. //
  2128. // For debugging byte-code, store the current offset before the instruction is read:
  2129. // - We convert this to "void *" to encourage the debugger to always display in hex,
  2130. // which matches the displayed offsets used by ByteCodeDumper.
  2131. //
  2132. this->DEBUG_currentByteOffset = (void *)m_reader.GetCurrentOffset();
  2133. #endif
  2134. OpCodeType op = (OpCodeType)ReadOpFunc(ip);
  2135. #if DBG_DUMP
  2136. TracingFunc(this, op);
  2137. #endif
  2138. return op;
  2139. }
  2140. void InterpreterStackFrame::TraceOpCode(InterpreterStackFrame* that, Js::OpCode op)
  2141. {
  2142. #if DBG_DUMP
  2143. that->scriptContext->byteCodeHistogram[(int)op]++;
  2144. if (PHASE_TRACE(Js::InterpreterPhase, that->m_functionBody))
  2145. {
  2146. Output::Print(_u("%d.%d:Executing %s at offset 0x%X\n"), that->m_functionBody->GetSourceContextId(), that->m_functionBody->GetLocalFunctionId(), Js::OpCodeUtil::GetOpCodeName(op), that->DEBUG_currentByteOffset);
  2147. }
  2148. #endif
  2149. }
  2150. void InterpreterStackFrame::TraceAsmJsOpCode(InterpreterStackFrame* that, Js::OpCodeAsmJs op)
  2151. {
  2152. #if DBG_DUMP && defined(ASMJS_PLAT)
  2153. if (PHASE_TRACE(Js::AsmjsInterpreterPhase, that->m_functionBody))
  2154. {
  2155. Output::Print(_u("%d.%d:Executing %s at offset 0x%X\n"), that->m_functionBody->GetSourceContextId(), that->m_functionBody->GetLocalFunctionId(), Js::OpCodeUtilAsmJs::GetOpCodeName(op), that->DEBUG_currentByteOffset);
  2156. }
  2157. #endif
  2158. }
  2159. #if ENABLE_TTD
  2160. template<typename OpCodeType, Js::OpCode(ReadOpFunc)(const byte*&), void (TracingFunc)(InterpreterStackFrame*, OpCodeType)>
  2161. OpCodeType InterpreterStackFrame::ReadOp_WPreviousStmtTracking(const byte *& ip)
  2162. {
  2163. #if DBG || DBG_DUMP
  2164. //
  2165. // For debugging byte-code, store the current offset before the instruction is read:
  2166. // - We convert this to "void *" to encourage the debugger to always display in hex,
  2167. // which matches the displayed offsets used by ByteCodeDumper.
  2168. //
  2169. this->DEBUG_currentByteOffset = (void *)m_reader.GetCurrentOffset();
  2170. #endif
  2171. #if ENABLE_TTD
  2172. AssertMsg(this->scriptContext->GetThreadContext()->IsRuntimeInTTDMode(), "We never be fetching an opcode via this path if this is not true!!!");
  2173. #endif
  2174. if (SHOULD_DO_TTD_STACK_STMT_OP(this->scriptContext))
  2175. {
  2176. TTD::ExecutionInfoManager* executionMgr = this->scriptContext->GetThreadContext()->TTDExecutionInfo;
  2177. executionMgr->UpdateCurrentStatementInfo(m_reader.GetCurrentOffset());
  2178. }
  2179. OpCodeType op = (OpCodeType)ReadOpFunc(ip);
  2180. #if DBG_DUMP
  2181. TracingFunc(this, op);
  2182. #endif
  2183. return op;
  2184. }
  2185. #endif
  2186. _NOINLINE
  2187. Var InterpreterStackFrame::ProcessThunk(void* address, void* addressOfReturnAddress)
  2188. {
  2189. PushPopFrameHelper pushPopFrameHelper(this, address, addressOfReturnAddress);
  2190. return this->Process();
  2191. }
  2192. #ifdef ASMJS_PLAT
  2193. Var InterpreterStackFrame::ProcessAsmJsModule()
  2194. {
  2195. FunctionBody* asmJsModuleFunctionBody = GetFunctionBody();
  2196. AsmJsModuleInfo* info = asmJsModuleFunctionBody->GetAsmJsModuleInfo();
  2197. #ifdef ENABLE_DEBUG_CONFIG_OPTIONS
  2198. if (Configuration::Global.flags.ForceAsmJsLinkFail)
  2199. {
  2200. AsmJSCompiler::OutputError(this->scriptContext, _u("Asm.js Runtime Error : Forcing link failure"));
  2201. return this->ProcessLinkFailedAsmJsModule();
  2202. }
  2203. #endif
  2204. if (m_inSlotsCount != info->GetArgInCount() + 1)
  2205. {
  2206. // Error reparse without asm.js
  2207. AsmJSCompiler::OutputError(this->scriptContext, _u("Asm.js Runtime Error : Invalid module argument count"));
  2208. return this->ProcessLinkFailedAsmJsModule();
  2209. }
  2210. const AsmJsModuleMemory& moduleMemory = info->GetModuleMemory();
  2211. Field(Var)* moduleMemoryPtr = RecyclerNewArray(scriptContext->GetRecycler(), Field(Var), moduleMemory.mMemorySize);
  2212. Field(Var)* arrayBufferPtr = moduleMemoryPtr + moduleMemory.mArrayBufferOffset;
  2213. Assert(moduleMemory.mArrayBufferOffset == AsmJsModuleMemory::MemoryTableBeginOffset);
  2214. Field(Var)* stdLibPtr = moduleMemoryPtr + moduleMemory.mStdLibOffset;
  2215. int* localIntSlots = (int*)(moduleMemoryPtr + moduleMemory.mIntOffset);
  2216. float* localFloatSlots = (float*)(moduleMemoryPtr + moduleMemory.mFloatOffset);
  2217. double* localDoubleSlots = (double*)(moduleMemoryPtr + moduleMemory.mDoubleOffset);
  2218. Field(Var)* localFunctionImports = moduleMemoryPtr + moduleMemory.mFFIOffset;
  2219. Field(Var)* localModuleFunctions = moduleMemoryPtr + moduleMemory.mFuncOffset;
  2220. Field(Field(Var)*)* localFunctionTables = (Field(Field(Var)*)*)(moduleMemoryPtr + moduleMemory.mFuncPtrOffset);
  2221. ThreadContext* threadContext = this->scriptContext->GetThreadContext();
  2222. *stdLibPtr = (m_inSlotsCount > 1) ? m_inParams[1] : nullptr;
  2223. Var foreign = (m_inSlotsCount > 2) ? m_inParams[2] : nullptr;
  2224. *arrayBufferPtr = (m_inSlotsCount > 3) ? m_inParams[3] : nullptr;
  2225. //cache the current state of the disable implicit call flag
  2226. DisableImplicitFlags prevDisableImplicitFlags = threadContext->GetDisableImplicitFlags();
  2227. ImplicitCallFlags saveImplicitcallFlags = threadContext->GetImplicitCallFlags();
  2228. // Disable implicit calls to check if any of the VarImport or Function Import leads to implicit calls
  2229. threadContext->DisableImplicitCall();
  2230. threadContext->SetImplicitCallFlags(ImplicitCallFlags::ImplicitCall_None);
  2231. bool checkParamResult = ASMLink::CheckParams(this->scriptContext, info, *stdLibPtr, foreign, *arrayBufferPtr);
  2232. if (!checkParamResult)
  2233. {
  2234. // don't need to print, because checkParams will do it for us
  2235. goto linkFailure;
  2236. }
  2237. else if (this->CheckAndResetImplicitCall(prevDisableImplicitFlags, saveImplicitcallFlags))
  2238. {
  2239. AsmJSCompiler::OutputError(this->scriptContext, _u("Asm.js Runtime Error : Params have side effects"));
  2240. return this->ProcessLinkFailedAsmJsModule();
  2241. }
  2242. // Initialize Variables
  2243. for (int i = 0; i < info->GetVarCount(); i++)
  2244. {
  2245. const auto& var = info->GetVar(i);
  2246. const AsmJsVarType type(var.type);
  2247. if (type.isInt())
  2248. {
  2249. localIntSlots[var.location] = var.initialiser.intInit;
  2250. }
  2251. else if (type.isFloat())
  2252. {
  2253. localFloatSlots[var.location] = var.initialiser.floatInit;
  2254. }
  2255. else if (type.isDouble())
  2256. {
  2257. localDoubleSlots[var.location] = var.initialiser.doubleInit;
  2258. }
  2259. else
  2260. {
  2261. Assert(UNREACHED);
  2262. }
  2263. }
  2264. // Load constant variables
  2265. for (int i = 0; i < info->GetVarImportCount(); i++)
  2266. {
  2267. const auto& import = info->GetVarImport(i);
  2268. const AsmJsVarType type(import.type);
  2269. // this might throw, but it would anyway in non-asm.js
  2270. Var value = JavascriptOperators::OP_GetProperty(foreign, import.field, scriptContext);
  2271. // check if there is implicit call and if there is implicit call then clear the disableimplicitcall flag
  2272. if (this->CheckAndResetImplicitCall(prevDisableImplicitFlags, saveImplicitcallFlags))
  2273. {
  2274. AsmJSCompiler::OutputError(this->scriptContext, _u("Asm.js Runtime Error : Accessing var import %s has side effects"), this->scriptContext->GetPropertyName(import.field)->GetBuffer());
  2275. return this->ProcessLinkFailedAsmJsModule();
  2276. }
  2277. if (CONFIG_FLAG(AsmJsEdge))
  2278. {
  2279. // emscripten had a bug which caused this check to fail in some circumstances, so this check fails for some demos
  2280. if (!TaggedNumber::Is(value) && (!RecyclableObject::Is(value) || DynamicType::Is(RecyclableObject::FromVar(value)->GetTypeId())))
  2281. {
  2282. AsmJSCompiler::OutputError(this->scriptContext, _u("Asm.js Runtime Error : Var import %s must be primitive"), this->scriptContext->GetPropertyName(import.field)->GetBuffer());
  2283. goto linkFailure;
  2284. }
  2285. }
  2286. if (type.isInt())
  2287. {
  2288. int val = JavascriptMath::ToInt32(value, scriptContext);
  2289. localIntSlots[import.location] = val;
  2290. }
  2291. else if (type.isFloat())
  2292. {
  2293. float val = (float)JavascriptConversion::ToNumber(value, scriptContext);
  2294. localFloatSlots[import.location] = val;
  2295. }
  2296. else if (type.isDouble())
  2297. {
  2298. double val = JavascriptConversion::ToNumber(value, scriptContext);
  2299. localDoubleSlots[import.location] = val;
  2300. }
  2301. // check for implicit call after converting to number
  2302. if (this->CheckAndResetImplicitCall(prevDisableImplicitFlags, saveImplicitcallFlags))
  2303. {
  2304. // Runtime error
  2305. AsmJSCompiler::OutputError(this->scriptContext, _u("Asm.js Runtime Error : Accessing var import %s has side effects"), this->scriptContext->GetPropertyName(import.field)->GetBuffer());
  2306. return this->ProcessLinkFailedAsmJsModule();
  2307. }
  2308. }
  2309. // Load external functions
  2310. for (int i = 0; i < info->GetFunctionImportCount(); i++)
  2311. {
  2312. const auto& import = info->GetFunctionImport(i);
  2313. // this might throw, but it would anyway in non-asm.js
  2314. Var importFunc = JavascriptOperators::OP_GetProperty(foreign, import.field, scriptContext);
  2315. // check if there is implicit call and if there is implicit call then clear the disableimplicitcall flag
  2316. if (this->CheckAndResetImplicitCall(prevDisableImplicitFlags, saveImplicitcallFlags))
  2317. {
  2318. AsmJSCompiler::OutputError(this->scriptContext, _u("Asm.js Runtime Error : Accessing foreign function import %s has side effects"), this->scriptContext->GetPropertyName(import.field)->GetBuffer());
  2319. return this->ProcessLinkFailedAsmJsModule();
  2320. }
  2321. if (!JavascriptFunction::Is(importFunc))
  2322. {
  2323. AsmJSCompiler::OutputError(this->scriptContext, _u("Asm.js Runtime Error : Foreign function import %s is not a function"), this->scriptContext->GetPropertyName(import.field)->GetBuffer());
  2324. goto linkFailure;
  2325. }
  2326. localFunctionImports[import.location] = importFunc;
  2327. }
  2328. threadContext->SetDisableImplicitFlags(prevDisableImplicitFlags);
  2329. threadContext->SetImplicitCallFlags(saveImplicitcallFlags);
  2330. // scope
  2331. {
  2332. FrameDisplay* pDisplay = RecyclerNewPlus(scriptContext->GetRecycler(), sizeof(void*), FrameDisplay, 0);
  2333. //DynamicObject* asmModule = scriptContext->GetLibrary()->CreateObject(false, 1);
  2334. //JavascriptOperators::OP_SetProperty(asmModule, PropertyIds::module, moduleMemoryPtr, scriptContext);
  2335. //pDisplay->SetItem(0, this->function);
  2336. for (int i = 0; i < info->GetFunctionCount(); i++)
  2337. {
  2338. const auto& modFunc = info->GetFunction(i);
  2339. // TODO: add more runtime checks here
  2340. FunctionInfoPtrPtr functionInfo = m_functionBody->GetNestedFuncReference(i);
  2341. AsmJsScriptFunction* scriptFuncObj = AsmJsScriptFunction::OP_NewAsmJsFunc(pDisplay, functionInfo);
  2342. localModuleFunctions[modFunc.location] = scriptFuncObj;
  2343. if (scriptFuncObj->GetDynamicType()->GetEntryPoint() == DefaultDeferredDeserializeThunk)
  2344. {
  2345. JavascriptFunction::DeferredDeserialize(scriptFuncObj);
  2346. }
  2347. scriptFuncObj->GetDynamicType()->SetEntryPoint(AsmJsExternalEntryPoint);
  2348. scriptFuncObj->GetFunctionBody()->GetAsmJsFunctionInfo()->SetModuleFunctionBody(asmJsModuleFunctionBody);
  2349. scriptFuncObj->SetModuleEnvironment(moduleMemoryPtr);
  2350. if (!info->IsRuntimeProcessed())
  2351. {
  2352. // don't reset entrypoint upon relinking
  2353. FunctionEntryPointInfo* entrypointInfo = (FunctionEntryPointInfo*)scriptFuncObj->GetEntryPointInfo();
  2354. entrypointInfo->SetIsAsmJSFunction(true);
  2355. #if DYNAMIC_INTERPRETER_THUNK
  2356. if (!PHASE_ON1(AsmJsJITTemplatePhase))
  2357. {
  2358. entrypointInfo->jsMethod = AsmJsDefaultEntryThunk;
  2359. }
  2360. #endif
  2361. }
  2362. }
  2363. }
  2364. // Initialize function table arrays
  2365. for (int i = 0; i < info->GetFunctionTableCount(); i++)
  2366. {
  2367. const auto& modFuncTable = info->GetFunctionTable(i);
  2368. Field(Var)* funcTableArray = RecyclerNewArray(scriptContext->GetRecycler(), Field(Var), modFuncTable.size);
  2369. for (uint j = 0; j < modFuncTable.size; j++)
  2370. {
  2371. // get the module function index
  2372. const RegSlot index = modFuncTable.moduleFunctionIndex[j];
  2373. // assign the module function pointer to the array
  2374. Var functionPtr = localModuleFunctions[index];
  2375. funcTableArray[j] = functionPtr;
  2376. }
  2377. localFunctionTables[i] = funcTableArray;
  2378. }
  2379. // Do MTJRC/MAIC:0 check
  2380. #if ENABLE_DEBUG_CONFIG_OPTIONS
  2381. if (
  2382. (PHASE_ON1(Js::AsmJsJITTemplatePhase) && CONFIG_FLAG(MaxTemplatizedJitRunCount) == 0) ||
  2383. (!PHASE_ON1(Js::AsmJsJITTemplatePhase) && (CONFIG_FLAG(MaxAsmJsInterpreterRunCount) == 0 || CONFIG_FLAG(ForceNative)))
  2384. )
  2385. {
  2386. if (PHASE_TRACE1(AsmjsEntryPointInfoPhase))
  2387. {
  2388. Output::Print(_u("%s Scheduling For Full JIT at callcount:%d\n"), asmJsModuleFunctionBody->GetDisplayName(), 0);
  2389. Output::Flush();
  2390. }
  2391. for (int i = 0; i < info->GetFunctionCount(); i++)
  2392. {
  2393. ScriptFunction* functionObj = (ScriptFunction*)PointerValue(localModuleFunctions[i]);
  2394. AnalysisAssert(functionObj != nullptr);
  2395. // don't want to generate code for APIs like changeHeap
  2396. if (functionObj->GetEntryPoint() == Js::AsmJsExternalEntryPoint)
  2397. {
  2398. WAsmJs::JitFunctionIfReady(functionObj);
  2399. }
  2400. }
  2401. }
  2402. #endif
  2403. info->SetIsRuntimeProcessed(true);
  2404. // create export object
  2405. if (info->GetExportsCount())
  2406. {
  2407. Var newObj = JavascriptOperators::NewScObjectLiteral(GetScriptContext(), info->GetExportsIdArray(),
  2408. this->GetFunctionBody()->GetObjectLiteralTypeRef(0));
  2409. for (int i = 0; i < info->GetExportsCount(); i++)
  2410. {
  2411. auto ex = info->GetExport(i);
  2412. Var func = localModuleFunctions[*ex.location];
  2413. JavascriptOperators::OP_InitProperty(newObj, *ex.id, func);
  2414. }
  2415. SetReg((RegSlot)0, newObj);
  2416. return newObj;
  2417. }
  2418. // export only 1 function
  2419. {
  2420. Var exportFunc = localModuleFunctions[info->GetExportFunctionIndex()];
  2421. SetReg((RegSlot)0, exportFunc);
  2422. return exportFunc;
  2423. }
  2424. linkFailure:
  2425. threadContext->SetDisableImplicitFlags(prevDisableImplicitFlags);
  2426. threadContext->SetImplicitCallFlags(saveImplicitcallFlags);
  2427. return this->ProcessLinkFailedAsmJsModule();
  2428. }
  2429. Var InterpreterStackFrame::ProcessLinkFailedAsmJsModule()
  2430. {
  2431. AsmJSCompiler::OutputError(this->scriptContext, _u("asm.js linking failed."));
  2432. Js::FunctionBody* asmJsModuleFunctionBody = GetFunctionBody();
  2433. AsmJsModuleInfo* info = asmJsModuleFunctionBody->GetAsmJsModuleInfo();
  2434. // do not support relinking with failed relink
  2435. if (info->IsRuntimeProcessed())
  2436. {
  2437. Js::Throw::OutOfMemory();
  2438. }
  2439. ScriptFunction * funcObj = GetJavascriptFunction();
  2440. ScriptFunction::ReparseAsmJsModule(&funcObj);
  2441. const bool doProfile =
  2442. funcObj->GetFunctionBody()->GetInterpreterExecutionMode(false) == ExecutionMode::ProfilingInterpreter ||
  2443. (funcObj->GetFunctionBody()->IsInDebugMode() && DynamicProfileInfo::IsEnabled(funcObj->GetFunctionBody()));
  2444. DynamicProfileInfo * dynamicProfileInfo = nullptr;
  2445. if (doProfile)
  2446. {
  2447. dynamicProfileInfo = funcObj->GetFunctionBody()->GetDynamicProfileInfo();
  2448. funcObj->GetScriptContext()->GetThreadContext()->ClearImplicitCallFlags();
  2449. }
  2450. // after reparsing, we want to also use a new interpreter stack frame, as it will have different characteristics than the asm.js version
  2451. InterpreterStackFrame::Setup setup(funcObj, m_inParams, m_inSlotsCount);
  2452. size_t varAllocCount = setup.GetAllocationVarCount();
  2453. size_t stackVarAllocCount = setup.GetStackAllocationVarCount();
  2454. size_t varSizeInBytes;
  2455. Var* allocation = nullptr;
  2456. Var* stackAllocation = nullptr;
  2457. DWORD_PTR stackAddr;
  2458. bool fReleaseAlloc = false;
  2459. if ((varAllocCount + stackVarAllocCount) > InterpreterStackFrame::LocalsThreshold)
  2460. {
  2461. ArenaAllocator *tmpAlloc = nullptr;
  2462. fReleaseAlloc = GetScriptContext()->EnsureInterpreterArena(&tmpAlloc);
  2463. varSizeInBytes = varAllocCount * sizeof(Var);
  2464. allocation = (Var*)tmpAlloc->Alloc(varSizeInBytes);
  2465. if (stackVarAllocCount != 0)
  2466. {
  2467. size_t stackVarSizeInBytes = stackVarAllocCount * sizeof(Var);
  2468. PROBE_STACK_PARTIAL_INITIALIZED_INTERPRETER_FRAME(GetScriptContext(), Js::Constants::MinStackInterpreter + stackVarSizeInBytes);
  2469. stackAllocation = (Var*)_alloca(stackVarSizeInBytes);
  2470. }
  2471. // use a stack address so the debugger stepping logic works (step-out, for example, compares stack depths to determine when to complete the step)
  2472. // debugger stepping does not matter here, but it's worth being consistent with normal stack frame
  2473. stackAddr = reinterpret_cast<DWORD_PTR>(&allocation);
  2474. }
  2475. else
  2476. {
  2477. varSizeInBytes = (varAllocCount + stackVarAllocCount) * sizeof(Var);
  2478. PROBE_STACK_PARTIAL_INITIALIZED_INTERPRETER_FRAME(GetScriptContext(), Js::Constants::MinStackInterpreter + varSizeInBytes);
  2479. allocation = (Var*)_alloca(varSizeInBytes);
  2480. stackAddr = reinterpret_cast<DWORD_PTR>(allocation);
  2481. }
  2482. #if DBG
  2483. Var invalidStackVar = (Js::RecyclableObject*)_alloca(sizeof(Js::RecyclableObject));
  2484. memset(invalidStackVar, 0xFE, sizeof(Js::RecyclableObject));
  2485. #endif
  2486. InterpreterStackFrame * newInstance = setup.InitializeAllocation(allocation, stackAllocation, funcObj->GetFunctionBody()->GetHasImplicitArgIns(), doProfile, nullptr, stackAddr
  2487. #if DBG
  2488. , invalidStackVar
  2489. #endif
  2490. );
  2491. newInstance->m_reader.Create(funcObj->GetFunctionBody());
  2492. // now that we have set up the new frame, let's interpret it!
  2493. funcObj->GetFunctionBody()->BeginExecution();
  2494. PushPopFrameHelper pushPopFrameHelper(newInstance, this->returnAddress, this->addressOfReturnAddress);
  2495. Var retVal = newInstance->ProcessUnprofiled();
  2496. if (doProfile)
  2497. {
  2498. dynamicProfileInfo->RecordImplicitCallFlags(GetScriptContext()->GetThreadContext()->GetImplicitCallFlags());
  2499. }
  2500. if (fReleaseAlloc)
  2501. {
  2502. GetScriptContext()->ReleaseInterpreterArena();
  2503. }
  2504. return retVal;
  2505. }
  2506. #if ENABLE_DEBUG_CONFIG_OPTIONS
  2507. int AsmJsCallDepth = 0;
  2508. #endif
  2509. // Function memory allocation should be done the same way as
  2510. // T AsmJsCommunEntryPoint(Js::ScriptFunction* func, ...) (AsmJSJitTemplate.cpp)
  2511. // update any changes there
  2512. /*
  2513. This function does the following fixup
  2514. Stack Before Stack After
  2515. ============== ================
  2516. | VarConstants | | VarConstants |
  2517. |--------------| |-----------------
  2518. | IntConstants | | IntConstants |
  2519. |--------------| | ------------ |
  2520. | FloatConst | | Int Vars+Tmps |
  2521. |--------------| |----------------|
  2522. | DoubleConst | | FloatConst |
  2523. |--------------| | ---------- |
  2524. | Var&Temps | | Flt Vars+tmps |
  2525. |==============| |----------------|
  2526. | DoubleConst |
  2527. | ----------- |
  2528. | Dbl Vars+Tmps |
  2529. ================
  2530. intSrc,FltSrc&DblSrc are pointers to the stack before the change
  2531. m_localIntSlots,m_localFloatSlots,m_localDoubleSlots are pointers to the stack after the change
  2532. */
  2533. void InterpreterStackFrame::AlignMemoryForAsmJs()
  2534. {
  2535. FunctionBody *const functionBody = GetFunctionBody();
  2536. ScriptFunction* func = GetJavascriptFunction();
  2537. uint32& callCount = ((FunctionEntryPointInfo*)func->GetEntryPointInfo())->callsCount;
  2538. WAsmJs::JitFunctionIfReady(func, ++callCount);
  2539. AsmJsFunctionInfo* info = functionBody->GetAsmJsFunctionInfo();
  2540. // The const table is copied after the FirstRegSlot
  2541. byte* constTable = (byte*)(m_localSlots + FunctionBody::FirstRegSlot);
  2542. byte* slotsStart = (byte*)m_localSlots;
  2543. // Must do in reverse order to avoid overwriting const of other type as we move things around
  2544. for (int i = WAsmJs::LIMIT - 1; i >= 0; --i)
  2545. {
  2546. WAsmJs::Types type = (WAsmJs::Types)i;
  2547. auto typeInfo = info->GetTypedSlotInfo(type);
  2548. byte* destination = slotsStart + typeInfo->byteOffset;
  2549. switch (type)
  2550. {
  2551. case WAsmJs::INT32: m_localIntSlots = (int*)destination; break;
  2552. case WAsmJs::INT64: m_localInt64Slots = (int64*)destination; break;
  2553. case WAsmJs::FLOAT32: m_localFloatSlots = (float*)destination; break;
  2554. case WAsmJs::FLOAT64: m_localDoubleSlots = (double*)destination; break;
  2555. case WAsmJs::SIMD: m_localSimdSlots = (AsmJsSIMDValue*)destination; break;
  2556. default:
  2557. CompileAssert(WAsmJs::SIMD == WAsmJs::LastType);
  2558. Assert(false);
  2559. break;
  2560. }
  2561. byte* source = constTable + typeInfo->constSrcByteOffset;
  2562. if (typeInfo->constCount > 0 && source != destination)
  2563. {
  2564. // Make sure slots are aligned for this type
  2565. Assert(::Math::Align<intptr_t>((intptr_t)destination, (intptr_t)WAsmJs::GetTypeByteSize(type)) == (intptr_t)destination);
  2566. Assert(typeInfo->constSrcByteOffset != Js::Constants::InvalidOffset);
  2567. uint constByteSize = typeInfo->constCount * WAsmJs::GetTypeByteSize(type);
  2568. memmove_s(destination, constByteSize, source, constByteSize);
  2569. }
  2570. }
  2571. // Load module environment
  2572. AsmJsScriptFunction* asmJsFunc = AsmJsScriptFunction::FromVar(this->function);
  2573. m_localSlots[AsmJsFunctionMemory::ModuleEnvRegister] = asmJsFunc->GetModuleEnvironment();
  2574. m_localSlots[AsmJsFunctionMemory::ArrayBufferRegister] = nullptr;
  2575. #ifdef ENABLE_WASM
  2576. if (WasmScriptFunction::Is(func))
  2577. {
  2578. WasmScriptFunction* wasmFunc = WasmScriptFunction::FromVar(func);
  2579. m_wasmMemory = wasmFunc->GetWebAssemblyMemory();
  2580. m_signatures = func->GetFunctionBody()->GetAsmJsFunctionInfo()->GetWebAssemblyModule()->GetSignatures();
  2581. }
  2582. else
  2583. #endif
  2584. {
  2585. m_asmJsBuffer = asmJsFunc->GetAsmJsArrayBuffer();
  2586. }
  2587. m_localSlots[AsmJsFunctionMemory::ArraySizeRegister] = 0; // do not cache ArraySize in the interpreter
  2588. m_localSlots[AsmJsFunctionMemory::ScriptContextBufferRegister] = functionBody->GetScriptContext();
  2589. int* intArg = m_localIntSlots + info->GetTypedSlotInfo(WAsmJs::INT32)->constCount;
  2590. int64* int64Arg = m_localInt64Slots + info->GetTypedSlotInfo(WAsmJs::INT64)->constCount;
  2591. double* doubleArg = m_localDoubleSlots + info->GetTypedSlotInfo(WAsmJs::FLOAT64)->constCount;
  2592. float* floatArg = m_localFloatSlots + info->GetTypedSlotInfo(WAsmJs::FLOAT32)->constCount;
  2593. #ifdef ENABLE_WASM_SIMD
  2594. AsmJsSIMDValue* simdArg = m_localSimdSlots + info->GetTypedSlotInfo(WAsmJs::SIMD)->constCount;
  2595. #endif
  2596. // Move the arguments to the right location
  2597. ArgSlot argCount = info->GetArgCount();
  2598. #if _M_X64 && _WIN32
  2599. uint homingAreaSize = 0;
  2600. #endif
  2601. #if ENABLE_DEBUG_CONFIG_OPTIONS
  2602. const bool tracingFunc = PHASE_TRACE(AsmjsFunctionEntryPhase, functionBody);
  2603. if (tracingFunc)
  2604. {
  2605. if (AsmJsCallDepth)
  2606. {
  2607. Output::Print(_u("%*c"), AsmJsCallDepth, ' ');
  2608. }
  2609. Output::Print(_u("Executing function %s("), functionBody->GetDisplayName());
  2610. ++AsmJsCallDepth;
  2611. }
  2612. #endif
  2613. uintptr_t argAddress = (uintptr_t)m_inParams;
  2614. for (ArgSlot i = 0; i < argCount; i++)
  2615. {
  2616. #if _M_X64 && _WIN32
  2617. // 3rd Argument should be at the end of the homing area.
  2618. Assert(i != 3 || argAddress == (uintptr_t)m_inParams + homingAreaSize);
  2619. if (i < 3)
  2620. {
  2621. // for x64 we spill the first 3 floating point args below the rest of the arguments on the stack
  2622. // m_inParams will be from DynamicInterpreterThunk's frame. Floats are in InterpreterAsmThunk's frame. Stack will be set up like so:
  2623. // DIT arg2 <- first scriptArg, m_inParams points here
  2624. // DIT arg1
  2625. // padding
  2626. // IAT r9 home
  2627. // IAT r8 home
  2628. // IAT rdx home
  2629. // IAT rcx home
  2630. // IAT return address
  2631. // IAT push rbp
  2632. // IAT padding
  2633. // IAT xmm3 spill
  2634. // IAT xmm2 spill
  2635. // IAT xmm1 spill <- floatSpillAddress for arg1
  2636. #define FLOAT_SPILL_ADDRESS_OFFSET_WORDS 15
  2637. // floats are spilled as xmmwords
  2638. uintptr_t floatSpillAddress = (uintptr_t)m_inParams - MachPtr * (FLOAT_SPILL_ADDRESS_OFFSET_WORDS - 2 * i);
  2639. if (info->GetArgType(i).isInt())
  2640. {
  2641. *intArg = *(int*)argAddress;
  2642. #if ENABLE_DEBUG_CONFIG_OPTIONS
  2643. if (tracingFunc)
  2644. {
  2645. Output::Print(_u("%d, "), *intArg);
  2646. }
  2647. #endif
  2648. ++intArg;
  2649. homingAreaSize += MachPtr;
  2650. }
  2651. else if (info->GetArgType(i).isInt64())
  2652. {
  2653. *int64Arg = *(int64*)argAddress;
  2654. #if ENABLE_DEBUG_CONFIG_OPTIONS
  2655. if (tracingFunc)
  2656. {
  2657. Output::Print(_u("%lld, "), *int64Arg);
  2658. }
  2659. #endif
  2660. ++int64Arg;
  2661. homingAreaSize += MachPtr;
  2662. }
  2663. else if (info->GetArgType(i).isFloat())
  2664. {
  2665. *floatArg = *(float*)floatSpillAddress;
  2666. #if ENABLE_DEBUG_CONFIG_OPTIONS
  2667. if (tracingFunc)
  2668. {
  2669. Output::Print(_u("%.2f, "), *floatArg);
  2670. }
  2671. #endif
  2672. ++floatArg;
  2673. homingAreaSize += MachPtr;
  2674. }
  2675. else if (info->GetArgType(i).isDouble())
  2676. {
  2677. *doubleArg = *(double*)floatSpillAddress;
  2678. #if ENABLE_DEBUG_CONFIG_OPTIONS
  2679. if (tracingFunc)
  2680. {
  2681. Output::Print(_u("%.2f, "), *doubleArg);
  2682. }
  2683. #endif
  2684. ++doubleArg;
  2685. homingAreaSize += MachPtr;
  2686. }
  2687. else
  2688. {
  2689. #ifdef ENABLE_WASM_SIMD
  2690. Assert(info->GetArgType(i).isSIMD());
  2691. *simdArg = *(AsmJsSIMDValue*)floatSpillAddress;
  2692. ++simdArg;
  2693. homingAreaSize += sizeof(AsmJsSIMDValue);
  2694. #else
  2695. Assert(UNREACHED);
  2696. #endif
  2697. }
  2698. if (Wasm::Simd::IsEnabled() && i == 2) // last argument ?
  2699. {
  2700. // If we have simd arguments, the homing area in m_inParams can be larger than 3 64-bit slots. This is because SIMD values are unboxed there too.
  2701. // After unboxing, the homing area is overwritten by rdx, r8 and r9, and we read/skip 64-bit slots from the homing area (argAddress += MachPtr).
  2702. // After the last argument of the 3 is read, we need to advance argAddress to skip over the possible extra space and to the start of the rest of the arguments.
  2703. argAddress = (uintptr_t)m_inParams + homingAreaSize;
  2704. }
  2705. else
  2706. {
  2707. argAddress += MachPtr;
  2708. }
  2709. }
  2710. else
  2711. #endif
  2712. if (info->GetArgType(i).isInt())
  2713. {
  2714. *intArg = *(int*)argAddress;
  2715. #if ENABLE_DEBUG_CONFIG_OPTIONS
  2716. if (tracingFunc)
  2717. {
  2718. Output::Print(_u("%d, "), *intArg);
  2719. }
  2720. #endif
  2721. ++intArg;
  2722. argAddress += MachPtr;
  2723. }
  2724. else if (info->GetArgType(i).isInt64())
  2725. {
  2726. *int64Arg = *(int64*)argAddress;
  2727. #if ENABLE_DEBUG_CONFIG_OPTIONS
  2728. if (tracingFunc)
  2729. {
  2730. Output::Print(_u("%lld, "), *int64Arg);
  2731. }
  2732. #endif
  2733. ++int64Arg;
  2734. argAddress += sizeof(int64);
  2735. }
  2736. else if (info->GetArgType(i).isFloat())
  2737. {
  2738. *floatArg = *(float*)argAddress;
  2739. #if ENABLE_DEBUG_CONFIG_OPTIONS
  2740. if (tracingFunc)
  2741. {
  2742. Output::Print(_u("%.2f, "), *floatArg);
  2743. }
  2744. #endif
  2745. ++floatArg;
  2746. argAddress += MachPtr;
  2747. }
  2748. else if (info->GetArgType(i).isDouble())
  2749. {
  2750. Assert(info->GetArgType(i).isDouble());
  2751. *doubleArg = *(double*)argAddress;
  2752. #if ENABLE_DEBUG_CONFIG_OPTIONS
  2753. if (tracingFunc)
  2754. {
  2755. Output::Print(_u("%.2f, "), *doubleArg);
  2756. }
  2757. #endif
  2758. ++doubleArg;
  2759. argAddress += sizeof(double);
  2760. }
  2761. #ifdef ENABLE_WASM_SIMD
  2762. else if (Wasm::Simd::IsEnabled() && info->GetArgType(i).isSIMD())
  2763. {
  2764. *simdArg = *(AsmJsSIMDValue*)argAddress;
  2765. ++simdArg;
  2766. argAddress += sizeof(AsmJsSIMDValue);
  2767. }
  2768. #endif
  2769. else
  2770. {
  2771. AssertMsg(UNREACHED, "Invalid function arg type.");
  2772. }
  2773. }
  2774. #if ENABLE_DEBUG_CONFIG_OPTIONS
  2775. if (tracingFunc)
  2776. {
  2777. Output::Print(_u("){\n"));
  2778. Output::Flush();
  2779. }
  2780. #endif
  2781. }
  2782. #endif
  2783. ///----------------------------------------------------------------------------
  2784. ///
  2785. /// InterpreterStackFrame::Process
  2786. ///
  2787. /// Process() processes a single loop of execution for the current
  2788. /// JavascriptFunction being executed:
  2789. /// - Individual instructions are dispatched to specific handlers for different
  2790. /// OpCodes.
  2791. ///
  2792. ///----------------------------------------------------------------------------
  2793. #if ENABLE_PROFILE_INFO
  2794. #define INTERPRETERLOOPNAME ProcessProfiled
  2795. #define PROVIDE_INTERPRETERPROFILE
  2796. #include "InterpreterLoop.inl"
  2797. #undef PROVIDE_INTERPRETERPROFILE
  2798. #undef INTERPRETERLOOPNAME
  2799. #endif
  2800. #define INTERPRETERLOOPNAME ProcessUnprofiled
  2801. #include "InterpreterLoop.inl"
  2802. #undef INTERPRETERLOOPNAME
  2803. #if ENABLE_TTD_DIAGNOSTICS_TRACING
  2804. #define PROVIDE_INTERPRETER_STMTS
  2805. #define INTERPRETERLOOPNAME ProcessUnprofiled_PreviousStmtTracking
  2806. #include "InterpreterLoop.inl"
  2807. #undef INTERPRETERLOOPNAME
  2808. #undef PROVIDE_INTERPRETER_STMTS
  2809. #endif
  2810. #ifdef ASMJS_PLAT
  2811. #define INTERPRETERLOOPNAME ProcessAsmJs
  2812. #define INTERPRETER_ASMJS
  2813. #include "InterpreterProcessOpCodeAsmJs.h"
  2814. #include "InterpreterLoop.inl"
  2815. #undef INTERPRETER_ASMJS
  2816. #undef INTERPRETERLOOPNAME
  2817. #endif
  2818. // For now, always collect profile data when debugging,
  2819. // otherwise the backend will be confused if there's no profile data.
  2820. #ifdef ENABLE_SCRIPT_DEBUGGING
  2821. #define INTERPRETERLOOPNAME ProcessWithDebugging
  2822. #define PROVIDE_DEBUGGING
  2823. #if ENABLE_PROFILE_INFO
  2824. #define PROVIDE_INTERPRETERPROFILE
  2825. #endif
  2826. #include "InterpreterLoop.inl"
  2827. #if ENABLE_PROFILE_INFO
  2828. #undef PROVIDE_INTERPRETERPROFILE
  2829. #endif
  2830. #undef PROVIDE_DEBUGGING
  2831. #undef INTERPRETERLOOPNAME
  2832. #endif
  2833. #if ENABLE_TTD
  2834. #define PROVIDE_INTERPRETER_STMTS
  2835. #define INTERPRETERLOOPNAME ProcessWithDebugging_PreviousStmtTracking
  2836. #define PROVIDE_DEBUGGING
  2837. #if ENABLE_PROFILE_INFO
  2838. #define PROVIDE_INTERPRETERPROFILE
  2839. #endif
  2840. #include "InterpreterLoop.inl"
  2841. #if ENABLE_PROFILE_INFO
  2842. #undef PROVIDE_INTERPRETERPROFILE
  2843. #endif
  2844. #undef PROVIDE_DEBUGGING
  2845. #undef INTERPRETERLOOPNAME
  2846. #undef PROVIDE_INTERPRETER_STMTS
  2847. #endif
  2848. Var InterpreterStackFrame::Process()
  2849. {
  2850. #if ENABLE_PROFILE_INFO
  2851. class AutoRestore
  2852. {
  2853. private:
  2854. InterpreterStackFrame * const interpreterStackFrame;
  2855. const uint32 savedSwitchProfileModeOnLoopEndNumber;
  2856. const bool savedIsAutoProfiling;
  2857. const bool savedSwitchProfileMode;
  2858. public:
  2859. AutoRestore(InterpreterStackFrame *const interpreterStackFrame)
  2860. : interpreterStackFrame(interpreterStackFrame),
  2861. savedIsAutoProfiling(interpreterStackFrame->isAutoProfiling),
  2862. savedSwitchProfileMode(interpreterStackFrame->switchProfileMode),
  2863. savedSwitchProfileModeOnLoopEndNumber(interpreterStackFrame->switchProfileModeOnLoopEndNumber)
  2864. {
  2865. }
  2866. ~AutoRestore()
  2867. {
  2868. interpreterStackFrame->isAutoProfiling = savedIsAutoProfiling;
  2869. interpreterStackFrame->switchProfileMode = savedSwitchProfileMode;
  2870. interpreterStackFrame->switchProfileModeOnLoopEndNumber = savedSwitchProfileModeOnLoopEndNumber;
  2871. }
  2872. } autoRestore(this);
  2873. #endif
  2874. if (this->ehBailoutData && !this->TestFlags(InterpreterStackFrameFlags_FromBailOutInInlinee))
  2875. {
  2876. if (this->TestFlags(Js::InterpreterStackFrameFlags_FromBailOut) && !this->TestFlags(InterpreterStackFrameFlags_ProcessingBailOutFromEHCode))
  2877. {
  2878. this->OrFlags(Js::InterpreterStackFrameFlags_ProcessingBailOutFromEHCode);
  2879. EHBailoutData * topLevelEHBailoutData = this->ehBailoutData;
  2880. while (topLevelEHBailoutData->parent->nestingDepth != -1)
  2881. {
  2882. topLevelEHBailoutData->parent->child = topLevelEHBailoutData;
  2883. topLevelEHBailoutData = topLevelEHBailoutData->parent;
  2884. }
  2885. ProcessTryHandlerBailout(topLevelEHBailoutData, this->ehBailoutData->nestingDepth);
  2886. this->ClearFlags(Js::InterpreterStackFrameFlags_ProcessingBailOutFromEHCode);
  2887. this->ehBailoutData = nullptr;
  2888. }
  2889. }
  2890. #ifdef ASMJS_PLAT
  2891. if (GetFunctionBody()->GetIsAsmjsMode())
  2892. {
  2893. FunctionBody *const functionBody = GetFunctionBody();
  2894. AsmJsFunctionInfo* asmInfo = functionBody->GetAsmJsFunctionInfo();
  2895. if (asmInfo)
  2896. {
  2897. AlignMemoryForAsmJs();
  2898. Var returnVar = ProcessAsmJs();
  2899. #if ENABLE_DEBUG_CONFIG_OPTIONS
  2900. if (PHASE_TRACE(AsmjsFunctionEntryPhase, functionBody))
  2901. {
  2902. --AsmJsCallDepth;
  2903. if (AsmJsCallDepth)
  2904. {
  2905. Output::Print(_u("%*c}"), AsmJsCallDepth, ' ');
  2906. }
  2907. else
  2908. {
  2909. Output::Print(_u("}"));
  2910. }
  2911. switch (asmInfo->GetReturnType().which())
  2912. {
  2913. case AsmJsRetType::Void:
  2914. break;
  2915. case AsmJsRetType::Signed:
  2916. Output::Print(_u(" = %d"), m_localIntSlots[0]);
  2917. break;
  2918. case AsmJsRetType::Int64:
  2919. Output::Print(_u(" = %lld"), m_localInt64Slots[0]);
  2920. break;
  2921. case AsmJsRetType::Float:
  2922. Output::Print(_u(" = %.4f"), m_localFloatSlots[0]);
  2923. break;
  2924. case AsmJsRetType::Double:
  2925. Output::Print(_u(" = %.4f"), m_localDoubleSlots[0]);
  2926. break;
  2927. default:
  2928. break;
  2929. }
  2930. Output::Print(_u(";\n"));
  2931. Output::Flush();
  2932. }
  2933. #endif
  2934. return returnVar;
  2935. }
  2936. else
  2937. {
  2938. Assert(functionBody->GetAsmJsModuleInfo());
  2939. return ProcessAsmJsModule();
  2940. }
  2941. }
  2942. #endif
  2943. #if ENABLE_PROFILE_INFO
  2944. switchProfileMode = false;
  2945. switchProfileModeOnLoopEndNumber = 0u - 1;
  2946. #endif
  2947. #if ENABLE_PROFILE_INFO
  2948. FunctionBody *const functionBody = GetFunctionBody();
  2949. const ExecutionMode interpreterExecutionMode =
  2950. functionBody->GetInterpreterExecutionMode(TestFlags(InterpreterStackFrameFlags_FromBailOut));
  2951. if (interpreterExecutionMode == ExecutionMode::ProfilingInterpreter)
  2952. {
  2953. #if ENABLE_TTD
  2954. AssertMsg(!SHOULD_DO_TTD_STACK_STMT_OP(this->scriptContext), "We should have pinned into Interpreter mode in this case!!!");
  2955. #endif
  2956. isAutoProfiling = false;
  2957. return ProcessProfiled();
  2958. }
  2959. Assert(
  2960. interpreterExecutionMode == ExecutionMode::Interpreter ||
  2961. interpreterExecutionMode == ExecutionMode::AutoProfilingInterpreter);
  2962. isAutoProfiling = interpreterExecutionMode == ExecutionMode::AutoProfilingInterpreter;
  2963. Var result;
  2964. while (true)
  2965. {
  2966. Assert(!switchProfileMode);
  2967. #if ENABLE_TTD_DIAGNOSTICS_TRACING
  2968. if (this->scriptContext->ShouldPerformRecordOrReplayAction())
  2969. {
  2970. result = ProcessUnprofiled_PreviousStmtTracking();
  2971. }
  2972. else
  2973. {
  2974. result = ProcessUnprofiled();
  2975. }
  2976. #else
  2977. result = ProcessUnprofiled();
  2978. #endif
  2979. Assert(!(switchProfileMode && result));
  2980. if (switchProfileMode)
  2981. {
  2982. switchProfileMode = false;
  2983. }
  2984. else
  2985. {
  2986. break;
  2987. }
  2988. Assert(isAutoProfiling);
  2989. #if DBG_DUMP
  2990. if (PHASE_TRACE(InterpreterAutoProfilePhase, functionBody))
  2991. {
  2992. char16 debugStringBuffer[MAX_FUNCTION_BODY_DEBUG_STRING_SIZE];
  2993. Output::Print(_u("InterpreterAutoProfile - Func %s - Started profiling\n"), functionBody->GetDebugNumberSet(debugStringBuffer));
  2994. Output::Flush();
  2995. }
  2996. #endif
  2997. Assert(!switchProfileMode);
  2998. result = ProcessProfiled();
  2999. Assert(!(switchProfileMode && result));
  3000. if (switchProfileMode)
  3001. {
  3002. switchProfileMode = false;
  3003. }
  3004. else
  3005. {
  3006. break;
  3007. }
  3008. Assert(isAutoProfiling);
  3009. #if DBG_DUMP
  3010. if (PHASE_TRACE(InterpreterAutoProfilePhase, functionBody))
  3011. {
  3012. char16 debugStringBuffer[MAX_FUNCTION_BODY_DEBUG_STRING_SIZE];
  3013. Output::Print(_u("InterpreterAutoProfile - Func %s - Stopped profiling\n"), functionBody->GetDebugNumberSet(debugStringBuffer));
  3014. Output::Flush();
  3015. }
  3016. #endif
  3017. }
  3018. return result;
  3019. #else
  3020. #if ENABLE_TTD_DIAGNOSTICS_TRACING
  3021. if (this->scriptContext->ShouldPerformRecordOrReplayAction())
  3022. {
  3023. return ProcessUnprofiled_PreviousStmtTracking();
  3024. }
  3025. else
  3026. {
  3027. return ProcessUnprofiled();
  3028. }
  3029. #else
  3030. return ProcessUnprofiled();
  3031. #endif
  3032. #endif
  3033. }
  3034. template <class T>
  3035. void InterpreterStackFrame::OP_GetMethodProperty(unaligned T *playout)
  3036. {
  3037. Var varInstance = GetReg(playout->Instance);
  3038. OP_GetMethodProperty(varInstance, playout);
  3039. }
  3040. template <class T>
  3041. void InterpreterStackFrame::OP_GetLocalMethodProperty(unaligned T *playout)
  3042. {
  3043. OP_GetMethodProperty(this->localClosure, playout);
  3044. }
  3045. template <class T>
  3046. void InterpreterStackFrame::OP_GetMethodProperty(Var varInstance, unaligned T *playout)
  3047. {
  3048. #if ENABLE_COPYONACCESS_ARRAY
  3049. JavascriptLibrary::CheckAndConvertCopyOnAccessNativeIntArray<Var>(varInstance);
  3050. #endif
  3051. PropertyId propertyId = GetPropertyIdFromCacheId(playout->inlineCacheIndex);
  3052. RecyclableObject* obj = JavascriptOperators::TryFromVar<RecyclableObject>(varInstance);
  3053. if (obj)
  3054. {
  3055. ScriptFunction *fn = JavascriptOperators::TryFromVar<ScriptFunction>(obj);
  3056. if ((propertyId == PropertyIds::apply || propertyId == PropertyIds::call) && fn)
  3057. {
  3058. // If the property being loaded is "apply"/"call", make an optimistic assumption that apply/call is not overridden and
  3059. // undefer the function right here if it was defer parsed before. This is required so that the load of "apply"/"call"
  3060. // happens from the same "type". Otherwise, we will have a polymorphic cache for load of "apply"/"call".
  3061. if (fn->GetType()->GetEntryPoint() == JavascriptFunction::DeferredParsingThunk)
  3062. {
  3063. JavascriptFunction::DeferredParse(&fn);
  3064. }
  3065. }
  3066. }
  3067. InlineCache *inlineCache = this->GetInlineCache(playout->inlineCacheIndex);
  3068. PropertyValueInfo info;
  3069. PropertyValueInfo::SetCacheInfo(&info, GetFunctionBody(), inlineCache, playout->inlineCacheIndex, true);
  3070. Var aValue;
  3071. if (obj &&
  3072. CacheOperators::TryGetProperty<true, true, false, false, false, false, true, false, false, false>(
  3073. obj, false, obj, propertyId, &aValue, GetScriptContext(), nullptr, &info))
  3074. {
  3075. SetReg(playout->Value, aValue);
  3076. return;
  3077. }
  3078. OP_GetMethodProperty_NoFastPath(varInstance, playout);
  3079. }
  3080. template <class T>
  3081. _NOINLINE void InterpreterStackFrame::OP_GetMethodProperty_NoFastPath(Var instance, unaligned T *playout)
  3082. {
  3083. PropertyId propertyId = GetPropertyIdFromCacheId(playout->inlineCacheIndex);
  3084. Var value = JavascriptOperators::PatchGetMethod<false>(
  3085. GetFunctionBody(),
  3086. GetInlineCache(playout->inlineCacheIndex),
  3087. playout->inlineCacheIndex,
  3088. instance,
  3089. propertyId
  3090. );
  3091. #ifdef TELEMETRY_INTERPRETER
  3092. if (TELEMETRY_PROPERTY_OPCODE_FILTER(propertyId))
  3093. {
  3094. // `successful` will be true as PatchGetMethod throws an exception if not found.
  3095. this->scriptContext->GetTelemetry().GetOpcodeTelemetry().GetMethodProperty(instance, propertyId, value, true);
  3096. }
  3097. #endif
  3098. SetReg(playout->Value, value);
  3099. }
  3100. template <class T>
  3101. void InterpreterStackFrame::OP_GetRootMethodProperty(unaligned T *playout)
  3102. {
  3103. Assert(playout->inlineCacheIndex >= this->m_functionBody->GetRootObjectLoadInlineCacheStart());
  3104. Js::Var instance = this->GetRootObject();
  3105. PropertyId propertyId = GetPropertyIdFromCacheId(playout->inlineCacheIndex);
  3106. InlineCache *inlineCache = this->GetInlineCache(playout->inlineCacheIndex);
  3107. DynamicObject *obj = DynamicObject::UnsafeFromVar(instance);
  3108. PropertyValueInfo info;
  3109. PropertyValueInfo::SetCacheInfo(&info, GetFunctionBody(), inlineCache, playout->inlineCacheIndex, true);
  3110. Var aValue;
  3111. if (CacheOperators::TryGetProperty<true, true, false, false, false, false, true, false, false, false>(
  3112. obj, true, obj, propertyId, &aValue, GetScriptContext(), nullptr, &info))
  3113. {
  3114. SetReg(playout->Value, aValue);
  3115. return;
  3116. }
  3117. OP_GetRootMethodProperty_NoFastPath(playout);
  3118. }
  3119. template <class T>
  3120. _NOINLINE void InterpreterStackFrame::OP_GetRootMethodProperty_NoFastPath(unaligned T *playout)
  3121. {
  3122. PropertyId propertyId = GetPropertyIdFromCacheId(playout->inlineCacheIndex);
  3123. Var rootInstance = this->GetRootObject();
  3124. Var value = JavascriptOperators::PatchGetRootMethod<false>(
  3125. GetFunctionBody(),
  3126. GetInlineCache(playout->inlineCacheIndex),
  3127. playout->inlineCacheIndex,
  3128. DynamicObject::UnsafeFromVar(rootInstance),
  3129. propertyId
  3130. );
  3131. #ifdef TELEMETRY_INTERPRETER
  3132. if (TELEMETRY_PROPERTY_OPCODE_FILTER(propertyId))
  3133. {
  3134. // `successful` will be true as PatchGetMethod throws an exception if not found.
  3135. this->scriptContext->GetTelemetry().GetOpcodeTelemetry().GetMethodProperty(rootInstance, propertyId, value, true);
  3136. }
  3137. #endif
  3138. SetReg(playout->Value, value);
  3139. }
  3140. template <class T>
  3141. void InterpreterStackFrame::OP_GetMethodPropertyScoped(unaligned T *playout)
  3142. {
  3143. ThreadContext* threadContext = this->GetScriptContext()->GetThreadContext();
  3144. ImplicitCallFlags savedImplicitCallFlags = threadContext->GetImplicitCallFlags();
  3145. threadContext->ClearImplicitCallFlags();
  3146. Var varInstance = GetReg(playout->Instance);
  3147. PropertyId propertyId = GetPropertyIdFromCacheId(playout->inlineCacheIndex);
  3148. RecyclableObject* obj = NULL;
  3149. if (RecyclableObject::Is(varInstance))
  3150. {
  3151. obj = RecyclableObject::FromVar(varInstance);
  3152. }
  3153. InlineCache *inlineCache = this->GetInlineCache(playout->inlineCacheIndex);
  3154. PropertyValueInfo info;
  3155. PropertyValueInfo::SetCacheInfo(&info, GetFunctionBody(), inlineCache, playout->inlineCacheIndex, true);
  3156. Var aValue;
  3157. if (obj &&
  3158. CacheOperators::TryGetProperty<true, true, false, false, false, false, true, false, false, false>(
  3159. obj, false, obj, propertyId, &aValue, GetScriptContext(), nullptr, &info))
  3160. {
  3161. threadContext->CheckAndResetImplicitCallAccessorFlag();
  3162. threadContext->AddImplicitCallFlags(savedImplicitCallFlags);
  3163. SetReg(playout->Value, aValue);
  3164. return;
  3165. }
  3166. OP_GetMethodPropertyScoped_NoFastPath(playout);
  3167. threadContext->CheckAndResetImplicitCallAccessorFlag();
  3168. threadContext->AddImplicitCallFlags(savedImplicitCallFlags);
  3169. }
  3170. template <class T>
  3171. _NOINLINE void InterpreterStackFrame::OP_GetMethodPropertyScoped_NoFastPath(unaligned T *playout)
  3172. {
  3173. PropertyId propertyId = GetPropertyIdFromCacheId(playout->inlineCacheIndex);
  3174. Js::Var instance = GetReg(playout->Instance);
  3175. Js::Var value = JavascriptOperators::PatchScopedGetMethod<false>(
  3176. GetFunctionBody(),
  3177. GetInlineCache(playout->inlineCacheIndex),
  3178. playout->inlineCacheIndex,
  3179. instance,
  3180. propertyId
  3181. );
  3182. SetReg(playout->Value, value);
  3183. #ifdef TELEMETRY_INTERPRETER
  3184. if (TELEMETRY_PROPERTY_OPCODE_FILTER(propertyId))
  3185. {
  3186. // `successful` will be true as PatchGetMethod throws an exception if not found.
  3187. this->scriptContext->GetTelemetry().GetOpcodeTelemetry().GetMethodProperty(instance, propertyId, value, true);
  3188. }
  3189. #endif
  3190. }
  3191. template <class T>
  3192. void InterpreterStackFrame::OP_ProfiledGetMethodProperty(unaligned T *playout)
  3193. {
  3194. ProfiledGetProperty<T, false, true, false>(playout, GetReg(playout->Instance));
  3195. }
  3196. template <class T>
  3197. void InterpreterStackFrame::OP_ProfiledGetLocalMethodProperty(unaligned T *playout)
  3198. {
  3199. ProfiledGetProperty<T, false, true, false>(playout, this->localClosure);
  3200. }
  3201. template <class T>
  3202. void InterpreterStackFrame::OP_ProfiledGetRootMethodProperty(unaligned T *playout)
  3203. {
  3204. ProfiledGetProperty<T, true, true, false>(playout, GetRootObject());
  3205. }
  3206. RecyclableObject *
  3207. InterpreterStackFrame::OP_CallGetFunc(Var target)
  3208. {
  3209. return JavascriptOperators::GetCallableObjectOrThrow(target, GetScriptContext());
  3210. }
  3211. void InterpreterStackFrame::OP_AsmStartCall(const unaligned OpLayoutStartCall * playout)
  3212. {
  3213. OP_StartCall(playout->ArgCount / sizeof(Var));
  3214. m_outParams[0] = scriptContext->GetLibrary()->GetUndefined();
  3215. }
  3216. void InterpreterStackFrame::OP_StartCall(const unaligned OpLayoutStartCall * playout)
  3217. {
  3218. OP_StartCall(playout->ArgCount);
  3219. }
  3220. void InterpreterStackFrame::OP_StartCall(uint outParamCount)
  3221. {
  3222. // Save the outParams for the current callsite on the outparam stack
  3223. PushOut(m_outParams);
  3224. // Update outParams for the indicated callsite
  3225. m_outParams = m_outSp;
  3226. m_outSp += outParamCount;
  3227. AssertMsg(m_localSlots + this->m_functionBody->GetLocalsCount() < m_outSp &&
  3228. m_outSp <= (m_localSlots + this->m_functionBody->GetLocalsCount() + this->m_functionBody->GetOutParamMaxDepth()),
  3229. "out args Stack pointer not in range after Push");
  3230. }
  3231. #ifdef ASMJS_PLAT
  3232. void InterpreterStackFrame::OP_ProfiledCallAsmInternal(RegSlot funcReg, RegSlot returnReg, ProfileId profileId)
  3233. {
  3234. Var target = GetRegRawPtr(funcReg);
  3235. ScriptFunction* function = (ScriptFunction*)OP_CallGetFunc(target);
  3236. Js::FunctionBody * body = function->GetFunctionBody();
  3237. DynamicProfileInfo * dynamicProfileInfo = GetFunctionBody()->GetDynamicProfileInfo();
  3238. dynamicProfileInfo->RecordAsmJsCallSiteInfo(GetFunctionBody(), profileId, body);
  3239. return OP_CallAsmInternalCommon(function, returnReg);
  3240. }
  3241. void InterpreterStackFrame::OP_CallAsmInternal(RegSlot funcReg, RegSlot returnReg)
  3242. {
  3243. Var target = GetRegRawPtr(funcReg);
  3244. ScriptFunction* function = (ScriptFunction*)OP_CallGetFunc(target);
  3245. return OP_CallAsmInternalCommon(function, returnReg);
  3246. }
  3247. void InterpreterStackFrame::OP_CallAsmInternalCommon(ScriptFunction* function, RegSlot returnReg)
  3248. {
  3249. AsmJsScriptFunction* scriptFunc = AsmJsScriptFunction::FromVar(function);
  3250. AsmJsFunctionInfo* asmInfo = scriptFunc->GetFunctionBody()->GetAsmJsFunctionInfo();
  3251. uint alignedArgsSize = ::Math::Align<uint32>(asmInfo->GetArgByteSize(), 16);
  3252. #if _M_X64 && _WIN32
  3253. // convention is to always allocate spill space for rcx,rdx,r8,r9
  3254. if (alignedArgsSize < 0x20) alignedArgsSize = 0x20;
  3255. uint* argSizes = asmInfo->GetArgsSizesArray();
  3256. Assert(asmInfo->GetArgSizeArrayLength() >= 2);
  3257. byte* curOutParams = (byte*)m_outParams + sizeof(Var);
  3258. Assert(curOutParams + argSizes[0] + argSizes[1] + 16 <= (byte*)this->m_outParamsEnd);
  3259. // Prepare in advance the possible arguments that will need to be put in register
  3260. byte _declspec(align(16)) reg[3 * 16];
  3261. CompileAssert((FunctionBody::MinAsmJsOutParams() * sizeof(Var)) == (sizeof(Var) * 2 + sizeof(reg)));
  3262. js_memcpy_s(reg, 16, curOutParams, 16);
  3263. js_memcpy_s(reg + 16, 16, curOutParams + argSizes[0], 16);
  3264. js_memcpy_s(reg + 32, 16, curOutParams + argSizes[0] + argSizes[1], 16);
  3265. #else
  3266. byte* reg = nullptr;
  3267. #endif
  3268. ScriptContext * scriptContext = function->GetScriptContext();
  3269. Js::FunctionEntryPointInfo* entrypointInfo = (Js::FunctionEntryPointInfo*)function->GetEntryPointInfo();
  3270. PROBE_STACK_CALL(scriptContext, function, alignedArgsSize + Js::Constants::MinStackDefault);
  3271. // Calling the jsMethod might change the entrypoint, adding the variable here
  3272. // will save the method on the stack helping debug what really got called
  3273. JavascriptMethod jsMethod = entrypointInfo->jsMethod;
  3274. switch (asmInfo->GetReturnType().which())
  3275. {
  3276. case AsmJsRetType::Void:
  3277. JavascriptFunction::CallAsmJsFunction<int>(function, jsMethod, m_outParams, alignedArgsSize, reg);
  3278. break;
  3279. case AsmJsRetType::Signed:
  3280. m_localIntSlots[returnReg] = JavascriptFunction::CallAsmJsFunction<int>(function, jsMethod, m_outParams, alignedArgsSize, reg);
  3281. break;
  3282. case AsmJsRetType::Int64:
  3283. m_localInt64Slots[returnReg] = JavascriptFunction::CallAsmJsFunction<int64>(function, jsMethod, m_outParams, alignedArgsSize, reg);
  3284. break;
  3285. case AsmJsRetType::Double:
  3286. m_localDoubleSlots[returnReg] = JavascriptFunction::CallAsmJsFunction<double>(function, jsMethod, m_outParams, alignedArgsSize, reg);
  3287. break;
  3288. case AsmJsRetType::Float:
  3289. m_localFloatSlots[returnReg] = JavascriptFunction::CallAsmJsFunction<float>(function, jsMethod, m_outParams, alignedArgsSize, reg);
  3290. break;
  3291. #ifdef ENABLE_WASM_SIMD
  3292. case AsmJsRetType::Float32x4:
  3293. case AsmJsRetType::Int32x4:
  3294. case AsmJsRetType::Bool32x4:
  3295. case AsmJsRetType::Bool16x8:
  3296. case AsmJsRetType::Bool8x16:
  3297. case AsmJsRetType::Float64x2:
  3298. case AsmJsRetType::Int16x8:
  3299. case AsmJsRetType::Int8x16:
  3300. case AsmJsRetType::Uint32x4:
  3301. case AsmJsRetType::Uint16x8:
  3302. case AsmJsRetType::Uint8x16:
  3303. #if _WIN32 //WASM.SIMD ToDo: Enable thunk for Xplat
  3304. #if _M_X64
  3305. X86SIMDValue simdVal;
  3306. simdVal.m128_value = JavascriptFunction::CallAsmJsFunction<__m128>(function, jsMethod, m_outParams, alignedArgsSize, reg);
  3307. m_localSimdSlots[returnReg] = X86SIMDValue::ToSIMDValue(simdVal);
  3308. #else
  3309. m_localSimdSlots[returnReg] = JavascriptFunction::CallAsmJsFunction<AsmJsSIMDValue>(function, jsMethod, m_outParams, alignedArgsSize, reg);
  3310. #endif
  3311. #endif
  3312. break;
  3313. #endif
  3314. default:
  3315. Assume(UNREACHED);
  3316. }
  3317. const ArgSlot nVarToPop = (asmInfo->GetArgByteSize() / sizeof(Var)) + 1;
  3318. PopOut(nVarToPop);
  3319. Assert(function);
  3320. }
  3321. #endif
  3322. template <class T>
  3323. void InterpreterStackFrame::OP_AsmCall(const unaligned T* playout)
  3324. {
  3325. Var target = GetRegRawPtr(playout->Function);
  3326. RecyclableObject * function = OP_CallGetFunc(target);
  3327. #if DBG
  3328. if (this->IsInDebugMode())
  3329. {
  3330. JavascriptFunction::CheckValidDebugThunk(scriptContext, function);
  3331. }
  3332. #endif
  3333. BEGIN_SAFE_REENTRANT_REGION(this->scriptContext->GetThreadContext())
  3334. {
  3335. if (playout->Return == Js::Constants::NoRegister)
  3336. {
  3337. Arguments args(CallInfo(CallFlags_NotUsed, playout->ArgCount), m_outParams);
  3338. JavascriptFunction::CallFunction<true>(function, function->GetEntryPoint(), args);
  3339. }
  3340. else
  3341. {
  3342. Arguments args(CallInfo(CallFlags_Value, playout->ArgCount), m_outParams);
  3343. Var retVal = JavascriptFunction::CallFunction<true>(function, function->GetEntryPoint(), args);
  3344. SetRegRawPtr(playout->Return, retVal);
  3345. }
  3346. }
  3347. END_SAFE_REENTRANT_REGION
  3348. PopOut(playout->ArgCount);
  3349. }
  3350. template <class T>
  3351. void InterpreterStackFrame::OP_EnsureHeapAttached(const unaligned T* playout)
  3352. {
  3353. AsmJsModuleInfo::EnsureHeapAttached(this->function);
  3354. }
  3355. template <class T>
  3356. void InterpreterStackFrame::OP_CallCommon(const unaligned T * playout, RecyclableObject * function, unsigned flags, const Js::AuxArray<uint32> *spreadIndices)
  3357. {
  3358. // Always save and restore implicit call flags when calling out
  3359. // REVIEW: Can we avoid it if we don't collect dynamic profile info?
  3360. ThreadContext * threadContext = scriptContext->GetThreadContext();
  3361. Js::ImplicitCallFlags savedImplicitCallFlags = threadContext->GetImplicitCallFlags();
  3362. #ifdef ENABLE_SCRIPT_DEBUGGING
  3363. #if DBG
  3364. if (this->IsInDebugMode())
  3365. {
  3366. JavascriptFunction::CheckValidDebugThunk(scriptContext, function);
  3367. }
  3368. #endif
  3369. #endif
  3370. ArgSlot argCount = playout->ArgCount;
  3371. BEGIN_SAFE_REENTRANT_REGION(threadContext)
  3372. {
  3373. if (playout->Return == Js::Constants::NoRegister)
  3374. {
  3375. flags |= CallFlags_NotUsed;
  3376. Arguments args(CallInfo((CallFlags)flags, argCount), m_outParams);
  3377. AssertMsg(static_cast<unsigned>(args.Info.Flags) == flags, "Flags don't fit into the CallInfo field?");
  3378. argCount = args.GetArgCountWithExtraArgs();
  3379. if (spreadIndices != nullptr)
  3380. {
  3381. JavascriptFunction::CallSpreadFunction(function, args, spreadIndices);
  3382. }
  3383. else
  3384. {
  3385. JavascriptFunction::CallFunction<true>(function, function->GetEntryPoint(), args);
  3386. }
  3387. }
  3388. else
  3389. {
  3390. flags |= CallFlags_Value;
  3391. Arguments args(CallInfo((CallFlags)flags, argCount), m_outParams);
  3392. AssertMsg(static_cast<unsigned>(args.Info.Flags) == flags, "Flags don't fit into the CallInfo field?");
  3393. argCount = args.GetArgCountWithExtraArgs();
  3394. if (spreadIndices != nullptr)
  3395. {
  3396. SetReg((RegSlot)playout->Return, JavascriptFunction::CallSpreadFunction(function, args, spreadIndices));
  3397. }
  3398. else
  3399. {
  3400. SetReg((RegSlot)playout->Return, JavascriptFunction::CallFunction<true>(function, function->GetEntryPoint(), args));
  3401. }
  3402. }
  3403. }
  3404. END_SAFE_REENTRANT_REGION
  3405. threadContext->SetImplicitCallFlags(savedImplicitCallFlags);
  3406. PopOut(argCount);
  3407. }
  3408. template <class T>
  3409. void InterpreterStackFrame::OP_CallCommonI(const unaligned T * playout, RecyclableObject * function, unsigned flags)
  3410. {
  3411. OP_CallCommon(playout, function, flags); // CallCommon doesn't do anything with Member
  3412. }
  3413. #if ENABLE_PROFILE_INFO
  3414. template <class T>
  3415. void InterpreterStackFrame::OP_ProfileCallCommon(const unaligned T * playout, RecyclableObject * function, unsigned flags, ProfileId profileId, InlineCacheIndex inlineCacheIndex, const Js::AuxArray<uint32> *spreadIndices)
  3416. {
  3417. FunctionBody* functionBody = this->m_functionBody;
  3418. DynamicProfileInfo * dynamicProfileInfo = functionBody->GetDynamicProfileInfo();
  3419. FunctionInfo* functionInfo = function->GetTypeId() == TypeIds_Function ?
  3420. JavascriptFunction::FromVar(function)->GetFunctionInfo() : nullptr;
  3421. bool isConstructorCall = (CallFlags_New & flags) == CallFlags_New;
  3422. dynamicProfileInfo->RecordCallSiteInfo(functionBody, profileId, functionInfo, functionInfo ? static_cast<JavascriptFunction*>(function) : nullptr, playout->ArgCount, isConstructorCall, inlineCacheIndex);
  3423. OP_CallCommon<T>(playout, function, flags, spreadIndices);
  3424. if (playout->Return != Js::Constants::NoRegister)
  3425. {
  3426. dynamicProfileInfo->RecordReturnTypeOnCallSiteInfo(functionBody, profileId, GetReg((RegSlot)playout->Return));
  3427. }
  3428. }
  3429. template <class T>
  3430. void InterpreterStackFrame::OP_ProfileReturnTypeCallCommon(const unaligned T * playout, RecyclableObject * function, unsigned flags, ProfileId profileId, const Js::AuxArray<uint32> *spreadIndices)
  3431. {
  3432. OP_CallCommon<T>(playout, function, flags, spreadIndices);
  3433. FunctionBody* functionBody = this->m_functionBody;
  3434. DynamicProfileInfo * dynamicProfileInfo = functionBody->GetDynamicProfileInfo();
  3435. if (playout->Return != Js::Constants::NoRegister)
  3436. {
  3437. dynamicProfileInfo->RecordReturnType(functionBody, profileId, GetReg((RegSlot)playout->Return));
  3438. }
  3439. }
  3440. #endif
  3441. template <class T>
  3442. void InterpreterStackFrame::OP_GetRootProperty(unaligned T* playout)
  3443. {
  3444. // Same fast path as in the backend.
  3445. Assert(playout->inlineCacheIndex >= this->m_functionBody->GetRootObjectLoadInlineCacheStart());
  3446. Js::Var instance = this->GetRootObject();
  3447. InlineCache *inlineCache = this->GetInlineCache(playout->inlineCacheIndex);
  3448. PropertyId propertyId = GetPropertyIdFromCacheId(playout->inlineCacheIndex);
  3449. DynamicObject * obj = DynamicObject::UnsafeFromVar(instance);
  3450. PropertyValueInfo info;
  3451. PropertyValueInfo::SetCacheInfo(&info, GetFunctionBody(), inlineCache, playout->inlineCacheIndex, true);
  3452. Var value;
  3453. if (CacheOperators::TryGetProperty<true, false, false, false, false, false, true, false, false, false>(
  3454. obj, true, obj, propertyId, &value, GetScriptContext(), nullptr, &info))
  3455. {
  3456. SetReg(playout->Value, value);
  3457. return;
  3458. }
  3459. OP_GetRootProperty_NoFastPath(playout);
  3460. }
  3461. template <class T>
  3462. void InterpreterStackFrame::OP_GetRootPropertyForTypeOf(unaligned T* playout)
  3463. {
  3464. Var rootInstance = GetRootObject();
  3465. PropertyId propertyId = GetPropertyIdFromCacheId(playout->inlineCacheIndex);
  3466. Var value = JavascriptOperators::PatchGetRootValueForTypeOf<false>(
  3467. GetFunctionBody(),
  3468. GetInlineCache(playout->inlineCacheIndex),
  3469. playout->inlineCacheIndex,
  3470. DynamicObject::UnsafeFromVar(rootInstance),
  3471. propertyId
  3472. );
  3473. SetReg(playout->Value, value);
  3474. #ifdef TELEMETRY_INTERPRETER
  3475. if (TELEMETRY_PROPERTY_OPCODE_FILTER(propertyId))
  3476. {
  3477. // `successful` will be true as PatchGetRootValue throws an exception if not found.
  3478. this->scriptContext->GetTelemetry().GetOpcodeTelemetry().GetProperty(rootInstance, propertyId, value, /*successful:*/true);
  3479. }
  3480. #endif
  3481. }
  3482. template <class T>
  3483. _NOINLINE void InterpreterStackFrame::OP_GetRootProperty_NoFastPath(unaligned T* playout)
  3484. {
  3485. PropertyId propertyId = GetPropertyIdFromCacheId(playout->inlineCacheIndex);
  3486. Var rootInstance = this->GetRootObject();
  3487. Var value = JavascriptOperators::PatchGetRootValue<false>(
  3488. GetFunctionBody(),
  3489. GetInlineCache(playout->inlineCacheIndex),
  3490. playout->inlineCacheIndex,
  3491. DynamicObject::UnsafeFromVar(rootInstance),
  3492. propertyId
  3493. );
  3494. SetReg(playout->Value, value);
  3495. #ifdef TELEMETRY_INTERPRETER
  3496. if (TELEMETRY_PROPERTY_OPCODE_FILTER(propertyId))
  3497. {
  3498. // `successful` will be true as PatchGetRootValue throws an exception if not found.
  3499. this->scriptContext->GetTelemetry().GetOpcodeTelemetry().GetProperty(rootInstance, propertyId, value, /*successful:*/true);
  3500. }
  3501. #endif
  3502. }
  3503. #if ENABLE_PROFILE_INFO
  3504. template <class T>
  3505. void InterpreterStackFrame::UpdateFldInfoFlagsForGetSetInlineCandidate(unaligned T* playout, FldInfoFlags& fldInfoFlags, CacheType cacheType,
  3506. DynamicProfileInfo * dynamicProfileInfo, uint inlineCacheIndex, RecyclableObject * obj)
  3507. {
  3508. RecyclableObject *callee = nullptr;
  3509. //TODO: Setter case once we stop sharing inline caches for these callsites.
  3510. if ((cacheType & (CacheType_Getter | CacheType_Setter)) && GetInlineCache(inlineCacheIndex)->GetGetterSetter(obj->GetType(), &callee))
  3511. {
  3512. const auto functionBody = this->m_functionBody;
  3513. bool canInline = dynamicProfileInfo->RecordLdFldCallSiteInfo(functionBody, callee, false /*callApplyTarget*/);
  3514. if (canInline)
  3515. {
  3516. //updates this fldInfoFlags passed by reference.
  3517. fldInfoFlags = DynamicProfileInfo::MergeFldInfoFlags(fldInfoFlags, FldInfo_InlineCandidate);
  3518. }
  3519. }
  3520. }
  3521. template <class T>
  3522. void InterpreterStackFrame::UpdateFldInfoFlagsForCallApplyInlineCandidate(unaligned T* playout, FldInfoFlags& fldInfoFlags, CacheType cacheType,
  3523. DynamicProfileInfo * dynamicProfileInfo, uint inlineCacheIndex, RecyclableObject * obj)
  3524. {
  3525. RecyclableObject *callee = nullptr;
  3526. if (!(fldInfoFlags & FldInfo_Polymorphic) && GetInlineCache(inlineCacheIndex)->GetCallApplyTarget(obj, &callee))
  3527. {
  3528. const auto functionBody = this->m_functionBody;
  3529. bool canInline = dynamicProfileInfo->RecordLdFldCallSiteInfo(functionBody, callee, true /*callApplyTarget*/);
  3530. if (canInline)
  3531. {
  3532. //updates this fldInfoFlags passed by reference.
  3533. fldInfoFlags = DynamicProfileInfo::MergeFldInfoFlags(fldInfoFlags, FldInfo_InlineCandidate);
  3534. }
  3535. }
  3536. }
  3537. template <class T, bool Root, bool Method, bool CallApplyTarget>
  3538. void InterpreterStackFrame::ProfiledGetProperty(unaligned T* playout, const Var instance)
  3539. {
  3540. PropertyId propertyId = GetPropertyIdFromCacheId(playout->inlineCacheIndex);
  3541. Var value = ProfilingHelpers::ProfiledLdFld<Root, Method, CallApplyTarget>(
  3542. instance,
  3543. propertyId,
  3544. GetInlineCache(playout->inlineCacheIndex),
  3545. playout->inlineCacheIndex,
  3546. GetFunctionBody(),
  3547. instance);
  3548. SetReg(playout->Value, value);
  3549. #ifdef TELEMETRY_INTERPRETER
  3550. if (TELEMETRY_PROPERTY_OPCODE_FILTER(propertyId))
  3551. {
  3552. // `successful` will be true as PatchGetRootValue throws an exception if not found.
  3553. this->scriptContext->GetTelemetry().GetOpcodeTelemetry().GetProperty(instance, propertyId, value, /*successful:*/true);
  3554. }
  3555. #endif
  3556. }
  3557. template <class T>
  3558. void InterpreterStackFrame::OP_ProfiledGetRootProperty(unaligned T* playout)
  3559. {
  3560. ProfiledGetProperty<T, true, false, false>(playout, GetRootObject());
  3561. }
  3562. template <class T>
  3563. void InterpreterStackFrame::OP_ProfiledGetRootPropertyForTypeOf(unaligned T* playout)
  3564. {
  3565. Var rootInstance = GetRootObject();
  3566. PropertyId propertyId = GetPropertyIdFromCacheId(playout->inlineCacheIndex);
  3567. Var value = ProfilingHelpers::ProfiledLdFldForTypeOf<true, false, false>(
  3568. rootInstance,
  3569. propertyId,
  3570. GetInlineCache(playout->inlineCacheIndex),
  3571. playout->inlineCacheIndex,
  3572. GetFunctionBody());
  3573. SetReg(playout->Value, value);
  3574. #ifdef TELEMETRY_INTERPRETER
  3575. if (TELEMETRY_PROPERTY_OPCODE_FILTER(propertyId))
  3576. {
  3577. // `successful` will be true as PatchGetRootValue throws an exception if not found.
  3578. this->scriptContext->GetTelemetry().GetOpcodeTelemetry().GetProperty(rootInstance, propertyId, value, /*successful:*/true);
  3579. }
  3580. #endif
  3581. }
  3582. #endif
  3583. template <class T>
  3584. void InterpreterStackFrame::OP_GetPropertyForTypeOf(unaligned T* playout)
  3585. {
  3586. Var instance = GetReg(playout->Instance);
  3587. PropertyId propertyId = GetPropertyIdFromCacheId(playout->inlineCacheIndex);
  3588. Var value = JavascriptOperators::PatchGetValueForTypeOf<false>(
  3589. GetFunctionBody(),
  3590. GetInlineCache(playout->inlineCacheIndex),
  3591. playout->inlineCacheIndex,
  3592. instance,
  3593. propertyId
  3594. );
  3595. SetReg(playout->Value, value);
  3596. #ifdef TELEMETRY_INTERPRETER
  3597. if (TELEMETRY_PROPERTY_OPCODE_FILTER(propertyId))
  3598. {
  3599. // `successful` will be true as PatchGetRootValue throws an exception if not found.
  3600. this->scriptContext->GetTelemetry().GetOpcodeTelemetry().GetProperty(instance, propertyId, value, /*successful:*/true);
  3601. }
  3602. #endif
  3603. }
  3604. template <class T>
  3605. void InterpreterStackFrame::OP_GetProperty(unaligned T* playout)
  3606. {
  3607. // Same fast path as in the backend.
  3608. Var instance = GetReg(playout->Instance);
  3609. OP_GetProperty(instance, playout);
  3610. }
  3611. template <class T>
  3612. void InterpreterStackFrame::OP_GetLocalProperty(unaligned T* playout)
  3613. {
  3614. // Same fast path as in the backend.
  3615. Var instance = this->localClosure;
  3616. OP_GetProperty(instance, playout);
  3617. }
  3618. template <class T>
  3619. void InterpreterStackFrame::OP_GetProperty(Var instance, unaligned T* playout)
  3620. {
  3621. InlineCache *inlineCache = GetInlineCache(playout->inlineCacheIndex);
  3622. PropertyId propertyId = GetPropertyIdFromCacheId(playout->inlineCacheIndex);
  3623. RecyclableObject* obj = JavascriptOperators::TryFromVar<RecyclableObject>(instance);
  3624. if (obj)
  3625. {
  3626. PropertyValueInfo info;
  3627. PropertyValueInfo::SetCacheInfo(&info, GetFunctionBody(), inlineCache, playout->inlineCacheIndex, true);
  3628. Var value;
  3629. if (CacheOperators::TryGetProperty<true, false, false, false, false, false, true, false, false, false>(
  3630. obj, false, obj, propertyId, &value, GetScriptContext(), nullptr, &info))
  3631. {
  3632. SetReg(playout->Value, value);
  3633. return;
  3634. }
  3635. }
  3636. OP_GetProperty_NoFastPath(instance, playout);
  3637. }
  3638. template <class T>
  3639. void InterpreterStackFrame::OP_GetSuperProperty(unaligned T* playout)
  3640. {
  3641. // Same fast path as in the backend.
  3642. Var instance = GetReg(playout->Instance);
  3643. Var thisInstance = GetReg(playout->Value2);
  3644. InlineCache *inlineCache = GetInlineCache(playout->PropertyIdIndex);
  3645. PropertyId propertyId = GetPropertyIdFromCacheId(playout->PropertyIdIndex);
  3646. if (RecyclableObject::Is(instance) && RecyclableObject::Is(thisInstance))
  3647. {
  3648. RecyclableObject* superObj = RecyclableObject::FromVar(instance);
  3649. RecyclableObject* thisObj = RecyclableObject::FromVar(thisInstance);
  3650. PropertyValueInfo info;
  3651. PropertyValueInfo::SetCacheInfo(&info, GetFunctionBody(), inlineCache, playout->PropertyIdIndex, true);
  3652. Var value;
  3653. if (CacheOperators::TryGetProperty<true, false, false, false, false, false, true, false, false, false>(
  3654. thisObj, false, superObj, propertyId, &value, GetScriptContext(), nullptr, &info))
  3655. {
  3656. SetReg(playout->Value, value);
  3657. return;
  3658. }
  3659. }
  3660. SetReg(
  3661. playout->Value,
  3662. JavascriptOperators::PatchGetValueWithThisPtr<false>(
  3663. GetFunctionBody(),
  3664. GetInlineCache(playout->PropertyIdIndex),
  3665. playout->PropertyIdIndex,
  3666. GetReg(playout->Instance),
  3667. GetPropertyIdFromCacheId(playout->PropertyIdIndex),
  3668. GetReg(playout->Value2)));
  3669. }
  3670. template <class T>
  3671. _NOINLINE void InterpreterStackFrame::OP_GetProperty_NoFastPath(Var instance, unaligned T* playout)
  3672. {
  3673. PropertyId propertyId = GetPropertyIdFromCacheId(playout->inlineCacheIndex);
  3674. Var value = JavascriptOperators::PatchGetValue<false>(
  3675. GetFunctionBody(),
  3676. GetInlineCache(playout->inlineCacheIndex),
  3677. playout->inlineCacheIndex,
  3678. instance,
  3679. propertyId
  3680. );
  3681. #ifdef TELEMETRY_INTERPRETER
  3682. if (TELEMETRY_PROPERTY_OPCODE_FILTER(propertyId))
  3683. {
  3684. // `successful` will be true as PatchGetMethod throws an exception if not found.
  3685. this->scriptContext->GetTelemetry().GetOpcodeTelemetry().GetProperty(instance, propertyId, value, true);
  3686. }
  3687. #endif
  3688. SetReg(playout->Value, value);
  3689. }
  3690. #if ENABLE_PROFILE_INFO
  3691. template <class T>
  3692. void InterpreterStackFrame::OP_ProfiledGetProperty(unaligned T* playout)
  3693. {
  3694. ProfiledGetProperty<T, false, false, false>(playout, GetReg(playout->Instance));
  3695. }
  3696. template <class T>
  3697. void InterpreterStackFrame::OP_ProfiledGetLocalProperty(unaligned T* playout)
  3698. {
  3699. ProfiledGetProperty<T, false, false, false>(playout, this->localClosure);
  3700. }
  3701. template <class T>
  3702. void InterpreterStackFrame::OP_ProfiledGetSuperProperty(unaligned T* playout)
  3703. {
  3704. SetReg(
  3705. playout->Value,
  3706. ProfilingHelpers::ProfiledLdFld<false, false, false>(
  3707. GetReg(playout->Instance),
  3708. GetPropertyIdFromCacheId(playout->PropertyIdIndex),
  3709. GetInlineCache(playout->PropertyIdIndex),
  3710. playout->PropertyIdIndex,
  3711. GetFunctionBody(),
  3712. GetReg(playout->Value2)));
  3713. }
  3714. template <class T>
  3715. void InterpreterStackFrame::OP_ProfiledGetPropertyForTypeOf(unaligned T* playout)
  3716. {
  3717. Var instance = GetReg(playout->Instance);
  3718. PropertyId propertyId = GetPropertyIdFromCacheId(playout->inlineCacheIndex);
  3719. Var value = ProfilingHelpers::ProfiledLdFldForTypeOf<false, false, false>(
  3720. instance,
  3721. propertyId,
  3722. GetInlineCache(playout->inlineCacheIndex),
  3723. playout->inlineCacheIndex,
  3724. GetFunctionBody()
  3725. );
  3726. SetReg(playout->Value, value);
  3727. #ifdef TELEMETRY_INTERPRETER
  3728. if (TELEMETRY_PROPERTY_OPCODE_FILTER(propertyId))
  3729. {
  3730. // `successful` will be true as PatchGetMethod throws an exception if not found.
  3731. this->scriptContext->GetTelemetry().GetOpcodeTelemetry().GetProperty(instance, propertyId, value, true);
  3732. }
  3733. #endif
  3734. }
  3735. template <class T>
  3736. void InterpreterStackFrame::OP_ProfiledGetPropertyCallApplyTarget(unaligned T* playout)
  3737. {
  3738. ProfiledGetProperty<T, false, false, true>(playout, GetReg(playout->Instance));
  3739. }
  3740. #endif
  3741. template <typename T>
  3742. void InterpreterStackFrame::OP_GetPropertyScoped(const unaligned OpLayoutT_ElementP<T>* playout)
  3743. {
  3744. ThreadContext* threadContext = this->GetScriptContext()->GetThreadContext();
  3745. ImplicitCallFlags savedImplicitCallFlags = threadContext->GetImplicitCallFlags();
  3746. threadContext->ClearImplicitCallFlags();
  3747. // Get the property, using a scope stack rather than an individual instance.
  3748. // Use the cache
  3749. PropertyId propertyId = GetPropertyIdFromCacheId(playout->inlineCacheIndex);
  3750. FrameDisplay *pScope = this->GetEnvForEvalCode();
  3751. InlineCache *inlineCache = this->GetInlineCache(playout->inlineCacheIndex);
  3752. ScriptContext* scriptContext = GetScriptContext();
  3753. int length = pScope->GetLength();
  3754. if (1 == length)
  3755. {
  3756. RecyclableObject *obj = RecyclableObject::FromVar(pScope->GetItem(0));
  3757. PropertyValueInfo info;
  3758. PropertyValueInfo::SetCacheInfo(&info, GetFunctionBody(), inlineCache, playout->inlineCacheIndex, true);
  3759. Var value;
  3760. if (CacheOperators::TryGetProperty<true, false, false, false, false, false, true, false, false, false>(
  3761. obj, false, obj, propertyId, &value, scriptContext, nullptr, &info))
  3762. {
  3763. threadContext->CheckAndResetImplicitCallAccessorFlag();
  3764. threadContext->AddImplicitCallFlags(savedImplicitCallFlags);
  3765. SetReg(playout->Value, value);
  3766. return;
  3767. }
  3768. }
  3769. OP_GetPropertyScoped_NoFastPath(playout);
  3770. threadContext->CheckAndResetImplicitCallAccessorFlag();
  3771. threadContext->AddImplicitCallFlags(savedImplicitCallFlags);
  3772. }
  3773. template <typename T>
  3774. void InterpreterStackFrame::OP_GetPropertyForTypeOfScoped(const unaligned OpLayoutT_ElementP<T>* playout)
  3775. {
  3776. ThreadContext* threadContext = this->GetScriptContext()->GetThreadContext();
  3777. ImplicitCallFlags savedImplicitCallFlags = threadContext->GetImplicitCallFlags();
  3778. threadContext->ClearImplicitCallFlags();
  3779. // Get the property, using a scope stack rather than an individual instance.
  3780. // Use the cache
  3781. PropertyId propertyId = GetPropertyIdFromCacheId(playout->inlineCacheIndex);
  3782. FrameDisplay *pScope = this->GetEnvForEvalCode();
  3783. InlineCache *inlineCache = this->GetInlineCache(playout->inlineCacheIndex);
  3784. ScriptContext* scriptContext = GetScriptContext();
  3785. int length = pScope->GetLength();
  3786. if (1 == length)
  3787. {
  3788. DynamicObject *obj = (DynamicObject*)pScope->GetItem(0);
  3789. PropertyValueInfo info;
  3790. PropertyValueInfo::SetCacheInfo(&info, GetFunctionBody(), inlineCache, playout->inlineCacheIndex, true);
  3791. Var value;
  3792. if (CacheOperators::TryGetProperty<true, false, false, false, false, false, true, false, false, false>(
  3793. obj, false, obj, propertyId, &value, scriptContext, nullptr, &info))
  3794. {
  3795. threadContext->CheckAndResetImplicitCallAccessorFlag();
  3796. threadContext->AddImplicitCallFlags(savedImplicitCallFlags);
  3797. SetReg(playout->Value, value);
  3798. return;
  3799. }
  3800. }
  3801. SetReg(
  3802. playout->Value,
  3803. JavascriptOperators::PatchGetPropertyForTypeOfScoped<false>(
  3804. GetFunctionBody(),
  3805. GetInlineCache(playout->inlineCacheIndex),
  3806. playout->inlineCacheIndex,
  3807. GetEnvForEvalCode(),
  3808. GetPropertyIdFromCacheId(playout->inlineCacheIndex),
  3809. GetReg(Js::FunctionBody::RootObjectRegSlot)));
  3810. threadContext->CheckAndResetImplicitCallAccessorFlag();
  3811. threadContext->AddImplicitCallFlags(savedImplicitCallFlags);
  3812. }
  3813. template <typename T>
  3814. _NOINLINE void InterpreterStackFrame::OP_GetPropertyScoped_NoFastPath(const unaligned OpLayoutT_ElementP<T>* playout)
  3815. {
  3816. // Implicit root object as default instance
  3817. Var defaultInstance = GetReg(Js::FunctionBody::RootObjectRegSlot);
  3818. // PatchGetPropertyScoped doesn't update type and slotIndex if the scope is not an array of length 1.
  3819. SetReg(
  3820. playout->Value,
  3821. JavascriptOperators::PatchGetPropertyScoped<false>(
  3822. GetFunctionBody(),
  3823. GetInlineCache(playout->inlineCacheIndex),
  3824. playout->inlineCacheIndex,
  3825. GetEnvForEvalCode(),
  3826. GetPropertyIdFromCacheId(playout->inlineCacheIndex),
  3827. defaultInstance));
  3828. }
  3829. template <class T>
  3830. void InterpreterStackFrame::OP_SetPropertyScoped(unaligned T* playout, PropertyOperationFlags flags)
  3831. {
  3832. ThreadContext* threadContext = this->GetScriptContext()->GetThreadContext();
  3833. ImplicitCallFlags savedImplicitCallFlags = threadContext->GetImplicitCallFlags();
  3834. threadContext->ClearImplicitCallFlags();
  3835. // Set the property, using a scope stack rather than an individual instance.
  3836. // Use the cache
  3837. PropertyId propertyId = GetPropertyIdFromCacheId(playout->inlineCacheIndex);
  3838. FrameDisplay *pScope = this->GetEnvForEvalCode();
  3839. InlineCache *inlineCache = GetInlineCache(playout->inlineCacheIndex);
  3840. ScriptContext* scriptContext = GetScriptContext();
  3841. Var value = GetReg(playout->Value);
  3842. int length = pScope->GetLength();
  3843. if (1 == length)
  3844. {
  3845. RecyclableObject* obj = RecyclableObject::FromVar(pScope->GetItem(0));
  3846. PropertyValueInfo info;
  3847. PropertyValueInfo::SetCacheInfo(&info, GetFunctionBody(), inlineCache, playout->inlineCacheIndex, true);
  3848. if (CacheOperators::TrySetProperty<true, false, false, false, false, true, false, false>(
  3849. obj, false, propertyId, value, scriptContext, flags, nullptr, &info))
  3850. {
  3851. threadContext->CheckAndResetImplicitCallAccessorFlag();
  3852. threadContext->AddImplicitCallFlags(savedImplicitCallFlags);
  3853. return;
  3854. }
  3855. }
  3856. OP_SetPropertyScoped_NoFastPath(playout, flags);
  3857. threadContext->CheckAndResetImplicitCallAccessorFlag();
  3858. threadContext->AddImplicitCallFlags(savedImplicitCallFlags);
  3859. }
  3860. template <class T>
  3861. _NOINLINE void InterpreterStackFrame::OP_SetPropertyScoped_NoFastPath(unaligned T* playout, PropertyOperationFlags flags)
  3862. {
  3863. // Implicit root object as default instance
  3864. Var defaultInstance = GetReg(Js::FunctionBody::RootObjectRegSlot);
  3865. // PatchSetPropertyScoped doesn't update type and slotIndex if the scope is not an array of length 1.
  3866. JavascriptOperators::PatchSetPropertyScoped<false>(
  3867. GetFunctionBody(),
  3868. GetInlineCache(playout->inlineCacheIndex),
  3869. playout->inlineCacheIndex,
  3870. GetEnvForEvalCode(),
  3871. GetPropertyIdFromCacheId(playout->inlineCacheIndex),
  3872. GetReg(playout->Value),
  3873. defaultInstance,
  3874. flags);
  3875. }
  3876. template <class T>
  3877. void InterpreterStackFrame::OP_SetPropertyScopedStrict(unaligned T* playout)
  3878. {
  3879. OP_SetPropertyScoped(playout, PropertyOperation_StrictMode);
  3880. }
  3881. template <class T>
  3882. void InterpreterStackFrame::OP_ConsoleSetPropertyScoped(unaligned T* playout)
  3883. {
  3884. OP_SetPropertyScoped(playout, PropertyOperation_AllowUndeclInConsoleScope);
  3885. }
  3886. template <class T>
  3887. void InterpreterStackFrame::OP_ConsoleSetPropertyScopedStrict(unaligned T* playout)
  3888. {
  3889. OP_SetPropertyScoped(playout, (PropertyOperationFlags)(PropertyOperation_StrictMode | PropertyOperation_AllowUndeclInConsoleScope));
  3890. }
  3891. template <class T>
  3892. inline bool InterpreterStackFrame::TrySetPropertyLocalFastPath(unaligned T* playout, PropertyId pid, RecyclableObject* instance, InlineCache*& inlineCache, PropertyOperationFlags flags)
  3893. {
  3894. inlineCache = this->GetInlineCache(playout->inlineCacheIndex);
  3895. PropertyValueInfo info;
  3896. PropertyValueInfo::SetCacheInfo(&info, GetFunctionBody(), inlineCache, playout->inlineCacheIndex, true);
  3897. return
  3898. CacheOperators::TrySetProperty<true, false, false, false, false, true, false, false>(
  3899. instance,
  3900. !!(flags & PropertyOperation_Root),
  3901. pid,
  3902. GetReg(playout->Value),
  3903. GetScriptContext(),
  3904. flags,
  3905. nullptr,
  3906. &info);
  3907. }
  3908. template <class T>
  3909. inline void InterpreterStackFrame::DoSetProperty(unaligned T* playout, Var instance, PropertyOperationFlags flags)
  3910. {
  3911. // Same fast path as in the backend.
  3912. PropertyId propertyId = GetPropertyIdFromCacheId(playout->inlineCacheIndex);
  3913. InlineCache *inlineCache;
  3914. if (!TaggedNumber::Is(instance)
  3915. && TrySetPropertyLocalFastPath(playout, propertyId, RecyclableObject::UnsafeFromVar(instance), inlineCache, flags))
  3916. {
  3917. if (GetJavascriptFunction()->GetConstructorCache()->NeedsUpdateAfterCtor())
  3918. {
  3919. // This function has only 'this' statements and is being used as a constructor. When the constructor exits, the
  3920. // function object's constructor cache will be updated with the type produced by the constructor. From that
  3921. // point on, when the same function object is used as a constructor, the a new object with the final type will
  3922. // be created. Whatever is stored in the inline cache currently will cause cache misses after the constructor
  3923. // cache update. So, just clear it now so that the caches won't be flagged as polymorphic.
  3924. inlineCache->RemoveFromInvalidationListAndClear(this->GetScriptContext()->GetThreadContext());
  3925. }
  3926. return;
  3927. }
  3928. DoSetProperty_NoFastPath(playout, instance, flags);
  3929. }
  3930. template <class T>
  3931. inline void InterpreterStackFrame::DoSetSuperProperty(unaligned T* playout, Var instance, PropertyOperationFlags flags)
  3932. {
  3933. DoSetSuperProperty_NoFastPath(playout, instance, m_functionBody->GetIsStrictMode() ?
  3934. (PropertyOperationFlags)(flags | PropertyOperation_StrictMode) : flags);
  3935. }
  3936. template <class T>
  3937. _NOINLINE void InterpreterStackFrame::DoSetProperty_NoFastPath(unaligned T* playout, Var instance, PropertyOperationFlags flags)
  3938. {
  3939. #if ENABLE_COPYONACCESS_ARRAY
  3940. JavascriptLibrary::CheckAndConvertCopyOnAccessNativeIntArray<Var>(instance);
  3941. #endif
  3942. InlineCache *const inlineCache = GetInlineCache(playout->inlineCacheIndex);
  3943. const auto PatchPutRootValue = &JavascriptOperators::PatchPutRootValueNoLocalFastPath<false, InlineCache>;
  3944. const auto PatchPutValue = &JavascriptOperators::PatchPutValueNoLocalFastPath<false, InlineCache>;
  3945. const auto PatchPut = flags & PropertyOperation_Root ? PatchPutRootValue : PatchPutValue;
  3946. PatchPut(
  3947. GetFunctionBody(),
  3948. inlineCache,
  3949. playout->inlineCacheIndex,
  3950. instance,
  3951. GetPropertyIdFromCacheId(playout->inlineCacheIndex),
  3952. GetReg(playout->Value),
  3953. flags);
  3954. if (!TaggedNumber::Is(instance) && GetJavascriptFunction()->GetConstructorCache()->NeedsUpdateAfterCtor())
  3955. {
  3956. // This function has only 'this' statements and is being used as a constructor. When the constructor exits, the
  3957. // function object's constructor cache will be updated with the type produced by the constructor. From that
  3958. // point on, when the same function object is used as a constructor, the a new object with the final type will
  3959. // be created. Whatever is stored in the inline cache currently will cause cache misses after the constructor
  3960. // cache update. So, just clear it now so that the caches won't be flagged as polymorphic.
  3961. inlineCache->RemoveFromInvalidationListAndClear(this->GetScriptContext()->GetThreadContext());
  3962. }
  3963. }
  3964. template <class T>
  3965. _NOINLINE void InterpreterStackFrame::DoSetSuperProperty_NoFastPath(unaligned T* playout, Var instance, PropertyOperationFlags flags)
  3966. {
  3967. #if ENABLE_COPYONACCESS_ARRAY
  3968. JavascriptLibrary::CheckAndConvertCopyOnAccessNativeIntArray<Var>(instance);
  3969. #endif
  3970. InlineCache *const inlineCache = GetInlineCache(playout->PropertyIdIndex);
  3971. JavascriptOperators::PatchPutValueWithThisPtrNoLocalFastPath<false, InlineCache>(
  3972. GetFunctionBody(),
  3973. inlineCache,
  3974. playout->PropertyIdIndex,
  3975. instance,
  3976. GetPropertyIdFromCacheId(playout->PropertyIdIndex),
  3977. GetReg(playout->Value),
  3978. GetReg(playout->Value2),
  3979. flags);
  3980. if (!TaggedNumber::Is(instance) && GetJavascriptFunction()->GetConstructorCache()->NeedsUpdateAfterCtor())
  3981. {
  3982. // This function has only 'this' statements and is being used as a constructor. When the constructor exits, the
  3983. // function object's constructor cache will be updated with the type produced by the constructor. From that
  3984. // point on, when the same function object is used as a constructor, the a new object with the final type will
  3985. // be created. Whatever is stored in the inline cache currently will cause cache misses after the constructor
  3986. // cache update. So, just clear it now so that the caches won't be flagged as polymorphic.
  3987. inlineCache->RemoveFromInvalidationListAndClear(this->GetScriptContext()->GetThreadContext());
  3988. }
  3989. }
  3990. #if ENABLE_PROFILE_INFO
  3991. template <class T, bool Root>
  3992. void InterpreterStackFrame::ProfiledSetProperty(unaligned T* playout, Var instance, PropertyOperationFlags flags)
  3993. {
  3994. Assert(!Root || flags & PropertyOperation_Root);
  3995. ProfilingHelpers::ProfiledStFld<Root>(
  3996. instance,
  3997. GetPropertyIdFromCacheId(playout->inlineCacheIndex),
  3998. GetInlineCache(playout->inlineCacheIndex),
  3999. playout->inlineCacheIndex,
  4000. GetReg(playout->Value),
  4001. flags,
  4002. GetJavascriptFunction(),
  4003. instance);
  4004. }
  4005. template <class T, bool Root>
  4006. void InterpreterStackFrame::ProfiledSetSuperProperty(unaligned T* playout, Var instance, Var thisInstance, PropertyOperationFlags flags)
  4007. {
  4008. Assert(!Root || flags & PropertyOperation_Root);
  4009. ProfilingHelpers::ProfiledStFld<Root>(
  4010. instance,
  4011. GetPropertyIdFromCacheId(playout->PropertyIdIndex),
  4012. GetInlineCache(playout->PropertyIdIndex),
  4013. playout->PropertyIdIndex,
  4014. GetReg(playout->Value),
  4015. m_functionBody->GetIsStrictMode() ?
  4016. (PropertyOperationFlags)(flags | PropertyOperation_StrictMode) : flags,
  4017. GetJavascriptFunction(),
  4018. thisInstance);
  4019. }
  4020. #endif
  4021. template <class T>
  4022. void InterpreterStackFrame::OP_SetProperty(unaligned T* playout)
  4023. {
  4024. DoSetProperty(playout, GetReg(playout->Instance), PropertyOperation_None);
  4025. }
  4026. template <class T>
  4027. void InterpreterStackFrame::OP_SetLocalProperty(unaligned T* playout)
  4028. {
  4029. DoSetProperty(playout, this->localClosure, PropertyOperation_None);
  4030. }
  4031. template <class T>
  4032. void InterpreterStackFrame::OP_SetSuperProperty(unaligned T* playout)
  4033. {
  4034. DoSetSuperProperty(playout, GetReg(playout->Instance), PropertyOperation_None);
  4035. }
  4036. template <class T>
  4037. void InterpreterStackFrame::OP_ProfiledSetProperty(unaligned T* playout)
  4038. {
  4039. ProfiledSetProperty<T, false>(playout, GetReg(playout->Instance), PropertyOperation_None);
  4040. }
  4041. template <class T>
  4042. void InterpreterStackFrame::OP_ProfiledSetLocalProperty(unaligned T* playout)
  4043. {
  4044. ProfiledSetProperty<T, false>(playout, this->localClosure, PropertyOperation_None);
  4045. }
  4046. template <class T>
  4047. void InterpreterStackFrame::OP_ProfiledSetSuperProperty(unaligned T* playout)
  4048. {
  4049. ProfiledSetSuperProperty<T, false>(playout, GetReg(playout->Instance), GetReg(playout->Value2), PropertyOperation_None);
  4050. }
  4051. template <class T>
  4052. void InterpreterStackFrame::OP_SetRootProperty(unaligned T* playout)
  4053. {
  4054. DoSetProperty(playout, this->GetRootObject(), PropertyOperation_Root);
  4055. }
  4056. template <class T>
  4057. void InterpreterStackFrame::OP_ProfiledSetRootProperty(unaligned T* playout)
  4058. {
  4059. ProfiledSetProperty<T, true>(playout, this->GetRootObject(), PropertyOperation_Root);
  4060. }
  4061. template <class T>
  4062. void InterpreterStackFrame::OP_SetPropertyStrict(unaligned T* playout)
  4063. {
  4064. DoSetProperty(playout, GetReg(playout->Instance), PropertyOperation_StrictMode);
  4065. }
  4066. template <class T>
  4067. void InterpreterStackFrame::OP_ProfiledSetPropertyStrict(unaligned T* playout)
  4068. {
  4069. ProfiledSetProperty<T, false>(playout, GetReg(playout->Instance), PropertyOperation_StrictMode);
  4070. }
  4071. template <class T>
  4072. void InterpreterStackFrame::OP_SetRootPropertyStrict(unaligned T* playout)
  4073. {
  4074. DoSetProperty(playout, this->GetRootObject(), PropertyOperation_StrictModeRoot);
  4075. }
  4076. template <class T>
  4077. void InterpreterStackFrame::OP_ProfiledSetRootPropertyStrict(unaligned T* playout)
  4078. {
  4079. ProfiledSetProperty<T, true>(playout, this->GetRootObject(), PropertyOperation_StrictModeRoot);
  4080. }
  4081. #if ENABLE_PROFILE_INFO
  4082. template <bool doProfile>
  4083. Var InterpreterStackFrame::ProfiledDivide(Var aLeft, Var aRight, ScriptContext* scriptContext, ProfileId profileId)
  4084. {
  4085. Var result = JavascriptMath::Divide(aLeft, aRight, scriptContext);
  4086. if (doProfile)
  4087. {
  4088. Js::FunctionBody* body = this->m_functionBody;
  4089. body->GetDynamicProfileInfo()->RecordDivideResultType(body, profileId, result);
  4090. }
  4091. return result;
  4092. }
  4093. template <bool doProfile>
  4094. Var InterpreterStackFrame::ProfileModulus(Var aLeft, Var aRight, ScriptContext* scriptContext, ProfileId profileId)
  4095. {
  4096. // If both arguments are TaggedInt, then try to do integer division
  4097. // This case is not handled by the lowerer.
  4098. if (doProfile)
  4099. {
  4100. Js::FunctionBody* body = this->function->GetFunctionBody();
  4101. if (TaggedInt::IsPair(aLeft, aRight))
  4102. {
  4103. int nLeft = TaggedInt::ToInt32(aLeft);
  4104. int nRight = TaggedInt::ToInt32(aRight);
  4105. // nLeft is positive and nRight is +2^i
  4106. // Fast path for Power of 2 divisor
  4107. if (nLeft > 0 && ::Math::IsPow2(nRight))
  4108. {
  4109. body->GetDynamicProfileInfo()->RecordModulusOpType(body, profileId, /*isModByPowerOf2*/ true);
  4110. return TaggedInt::ToVarUnchecked(nLeft & (nRight - 1));
  4111. }
  4112. }
  4113. body->GetDynamicProfileInfo()->RecordModulusOpType(body, profileId, /*isModByPowerOf2*/ false);
  4114. }
  4115. return JavascriptMath::Modulus(aLeft, aRight, scriptContext);
  4116. }
  4117. template <bool doProfile>
  4118. Var InterpreterStackFrame::ProfiledSwitch(Var exp, ProfileId profileId)
  4119. {
  4120. if (doProfile)
  4121. {
  4122. Js::FunctionBody* body = this->m_functionBody;
  4123. body->GetDynamicProfileInfo()->RecordSwitchType(body, profileId, exp);
  4124. }
  4125. return exp;
  4126. }
  4127. #else
  4128. template <bool doProfile>
  4129. Var InterpreterStackFrame::ProfiledDivide(Var aLeft, Var aRight, ScriptContext* scriptContext, ProfileId profileId)
  4130. {
  4131. Assert(!doProfile);
  4132. return JavascriptMath::Divide(aLeft, aRight, scriptContext);
  4133. }
  4134. template <bool doProfile>
  4135. Var InterpreterStackFrame::ProfileModulus(Var aLeft, Var aRight, ScriptContext* scriptContext, ProfileId profileId)
  4136. {
  4137. Assert(!doProfile);
  4138. return JavascriptMath::Modulus(aLeft, aRight, scriptContext);
  4139. }
  4140. template <bool doProfile>
  4141. Var InterpreterStackFrame::ProfiledSwitch(Var exp, ProfileId profileId)
  4142. {
  4143. Assert(!doProfile);
  4144. return exp;
  4145. }
  4146. #endif
  4147. template <class T>
  4148. void InterpreterStackFrame::DoInitProperty(unaligned T* playout, Var instance)
  4149. {
  4150. // Same fast path as in the backend.
  4151. InlineCache *inlineCache = nullptr;
  4152. Assert(!TaggedNumber::Is(instance));
  4153. PropertyId propertyId = GetPropertyIdFromCacheId(playout->inlineCacheIndex);
  4154. if (TrySetPropertyLocalFastPath(playout, propertyId, RecyclableObject::UnsafeFromVar(instance), inlineCache))
  4155. {
  4156. return;
  4157. }
  4158. DoInitProperty_NoFastPath(playout, instance);
  4159. }
  4160. template <class T>
  4161. _NOINLINE void InterpreterStackFrame::DoInitProperty_NoFastPath(unaligned T* playout, Var instance)
  4162. {
  4163. JavascriptOperators::PatchInitValue<false>(
  4164. GetFunctionBody(),
  4165. GetInlineCache(playout->inlineCacheIndex),
  4166. playout->inlineCacheIndex,
  4167. RecyclableObject::FromVar(instance),
  4168. GetPropertyIdFromCacheId(playout->inlineCacheIndex),
  4169. GetReg(playout->Value));
  4170. }
  4171. template <class T>
  4172. void InterpreterStackFrame::OP_InitClassMember(const unaligned T * playout)
  4173. {
  4174. uint inlineCacheIndex = playout->inlineCacheIndex;
  4175. InlineCache * inlineCache = this->GetInlineCache(inlineCacheIndex);
  4176. Var instance = GetReg(playout->Instance);
  4177. PropertyOperationFlags flags = PropertyOperation_None;
  4178. Assert(!TaggedNumber::Is(instance));
  4179. PropertyId propertyId = GetPropertyIdFromCacheId(playout->inlineCacheIndex);
  4180. if (!TrySetPropertyLocalFastPath(playout, propertyId, RecyclableObject::UnsafeFromVar(instance), inlineCache, flags))
  4181. {
  4182. JavascriptOperators::OP_InitClassMember(instance, propertyId, GetReg(playout->Value));
  4183. }
  4184. }
  4185. template <class T>
  4186. void InterpreterStackFrame::OP_InitClassMemberGet(const unaligned T * playout)
  4187. {
  4188. JavascriptOperators::OP_InitClassMemberGet(
  4189. GetReg(playout->Instance),
  4190. m_functionBody->GetReferencedPropertyId(playout->PropertyIdIndex),
  4191. GetReg(playout->Value));
  4192. }
  4193. template <class T>
  4194. void InterpreterStackFrame::OP_InitClassMemberSet(const unaligned T * playout)
  4195. {
  4196. JavascriptOperators::OP_InitClassMemberSet(
  4197. GetReg(playout->Instance),
  4198. m_functionBody->GetReferencedPropertyId(playout->PropertyIdIndex),
  4199. GetReg(playout->Value));
  4200. }
  4201. template <class T>
  4202. void InterpreterStackFrame::OP_InitClassMemberSetComputedName(const unaligned T * playout)
  4203. {
  4204. JavascriptOperators::OP_InitClassMemberSetComputedName(
  4205. GetReg(playout->Instance),
  4206. GetReg(playout->Element),
  4207. GetReg(playout->Value),
  4208. m_functionBody->GetScriptContext());
  4209. }
  4210. template <class T>
  4211. void InterpreterStackFrame::OP_InitClassMemberGetComputedName(const unaligned T * playout)
  4212. {
  4213. JavascriptOperators::OP_InitClassMemberGetComputedName(
  4214. GetReg(playout->Instance),
  4215. GetReg(playout->Element),
  4216. GetReg(playout->Value),
  4217. m_functionBody->GetScriptContext());
  4218. }
  4219. template <class T>
  4220. void InterpreterStackFrame::OP_InitClassMemberComputedName(const unaligned T * playout)
  4221. {
  4222. JavascriptOperators::OP_InitClassMemberComputedName(
  4223. GetReg(playout->Instance),
  4224. GetReg(playout->Element),
  4225. GetReg(playout->Value),
  4226. m_functionBody->GetScriptContext());
  4227. }
  4228. template <class T>
  4229. void InterpreterStackFrame::DoInitLetFld(const unaligned T * playout, Var instance, PropertyOperationFlags flags)
  4230. {
  4231. uint inlineCacheIndex = playout->inlineCacheIndex;
  4232. InlineCache * inlineCache = this->GetInlineCache(inlineCacheIndex);
  4233. Assert(!TaggedNumber::Is(instance));
  4234. PropertyId propertyId = GetPropertyIdFromCacheId(playout->inlineCacheIndex);
  4235. if (!TrySetPropertyLocalFastPath(playout, propertyId, RecyclableObject::UnsafeFromVar(instance), inlineCache, flags))
  4236. {
  4237. JavascriptOperators::OP_InitLetProperty(instance, propertyId, GetReg(playout->Value));
  4238. }
  4239. }
  4240. template <class T>
  4241. void InterpreterStackFrame::DoInitConstFld(const unaligned T * playout, Var instance, PropertyOperationFlags flags)
  4242. {
  4243. uint inlineCacheIndex = playout->inlineCacheIndex;
  4244. InlineCache * inlineCache = this->GetInlineCache(inlineCacheIndex);
  4245. Assert(!TaggedNumber::Is(instance));
  4246. PropertyId propertyId = GetPropertyIdFromCacheId(playout->inlineCacheIndex);
  4247. if (!TrySetPropertyLocalFastPath(playout, propertyId, RecyclableObject::UnsafeFromVar(instance), inlineCache, flags))
  4248. {
  4249. JavascriptOperators::OP_InitConstProperty(instance, propertyId, GetReg(playout->Value));
  4250. }
  4251. }
  4252. template <class T>
  4253. void InterpreterStackFrame::OP_InitProperty(unaligned T* playout)
  4254. {
  4255. DoInitProperty(playout, GetReg(playout->Instance));
  4256. }
  4257. template <class T>
  4258. void InterpreterStackFrame::OP_InitLocalProperty(unaligned T* playout)
  4259. {
  4260. DoInitProperty(playout, this->localClosure);
  4261. }
  4262. template <class T>
  4263. void InterpreterStackFrame::OP_InitInnerFld(const unaligned T* playout)
  4264. {
  4265. DoInitProperty(playout, InnerScopeFromIndex(playout->scopeIndex));
  4266. }
  4267. template <class T>
  4268. void InterpreterStackFrame::OP_InitLetFld(const unaligned T * playout)
  4269. {
  4270. DoInitLetFld(playout, GetReg(playout->Instance));
  4271. }
  4272. template <class T>
  4273. void InterpreterStackFrame::OP_InitInnerLetFld(const unaligned T * playout)
  4274. {
  4275. DoInitLetFld(playout, InnerScopeFromIndex(playout->scopeIndex));
  4276. }
  4277. template <class T>
  4278. void InterpreterStackFrame::OP_InitLocalLetFld(const unaligned T * playout)
  4279. {
  4280. DoInitLetFld(playout, this->localClosure);
  4281. }
  4282. template <class T>
  4283. void InterpreterStackFrame::OP_InitConstFld(const unaligned T * playout)
  4284. {
  4285. DoInitConstFld(playout, GetReg(playout->Instance));
  4286. }
  4287. template <class T>
  4288. void InterpreterStackFrame::OP_InitRootProperty(unaligned T* playout)
  4289. {
  4290. Assert(playout->inlineCacheIndex >= this->m_functionBody->GetRootObjectLoadInlineCacheStart());
  4291. DoInitProperty(playout, this->GetRootObject());
  4292. }
  4293. template <class T>
  4294. void InterpreterStackFrame::OP_InitRootLetFld(const unaligned T * playout)
  4295. {
  4296. Assert(playout->inlineCacheIndex >= this->m_functionBody->GetRootObjectLoadInlineCacheStart());
  4297. DoInitLetFld(playout, this->GetRootObject(), PropertyOperation_Root);
  4298. }
  4299. template <class T>
  4300. void InterpreterStackFrame::OP_InitRootConstFld(const unaligned T * playout)
  4301. {
  4302. Assert(playout->inlineCacheIndex >= this->m_functionBody->GetRootObjectLoadInlineCacheStart());
  4303. DoInitConstFld(playout, this->GetRootObject(), PropertyOperation_Root);
  4304. }
  4305. template <class T>
  4306. void InterpreterStackFrame::OP_InitUndeclLetProperty(unaligned T* playout)
  4307. {
  4308. Var instance = InnerScopeFromIndex(playout->scopeIndex);
  4309. PropertyId propertyId = GetPropertyIdFromCacheId(playout->inlineCacheIndex);
  4310. JavascriptOperators::OP_InitLetProperty(instance, propertyId, this->scriptContext->GetLibrary()->GetUndeclBlockVar());
  4311. }
  4312. template <class T>
  4313. void InterpreterStackFrame::OP_InitUndeclLocalLetProperty(unaligned T* playout)
  4314. {
  4315. PropertyId propertyId = GetPropertyIdFromCacheId(playout->inlineCacheIndex);
  4316. JavascriptOperators::OP_InitLetProperty(this->localClosure, propertyId, this->scriptContext->GetLibrary()->GetUndeclBlockVar());
  4317. }
  4318. void InterpreterStackFrame::OP_InitUndeclRootLetProperty(uint propertyIdIndex)
  4319. {
  4320. Var instance = this->GetRootObject();
  4321. PropertyId propertyId = this->m_functionBody->GetReferencedPropertyId(propertyIdIndex);
  4322. JavascriptOperators::OP_InitUndeclRootLetProperty(instance, propertyId);
  4323. }
  4324. template <class T>
  4325. void InterpreterStackFrame::OP_InitUndeclConstProperty(unaligned T* playout)
  4326. {
  4327. Var instance = InnerScopeFromIndex(playout->scopeIndex);
  4328. PropertyId propertyId = GetPropertyIdFromCacheId(playout->inlineCacheIndex);
  4329. JavascriptOperators::OP_InitConstProperty(instance, propertyId, this->scriptContext->GetLibrary()->GetUndeclBlockVar());
  4330. }
  4331. template <class T>
  4332. void InterpreterStackFrame::OP_InitUndeclLocalConstProperty(unaligned T* playout)
  4333. {
  4334. PropertyId propertyId = GetPropertyIdFromCacheId(playout->inlineCacheIndex);
  4335. JavascriptOperators::OP_InitConstProperty(this->localClosure, propertyId, this->scriptContext->GetLibrary()->GetUndeclBlockVar());
  4336. }
  4337. void InterpreterStackFrame::OP_InitUndeclRootConstProperty(uint propertyIdIndex)
  4338. {
  4339. Var instance = this->GetRootObject();
  4340. PropertyId propertyId = this->m_functionBody->GetReferencedPropertyId(propertyIdIndex);
  4341. JavascriptOperators::OP_InitUndeclRootConstProperty(instance, propertyId);
  4342. }
  4343. template <class T>
  4344. void InterpreterStackFrame::OP_InitUndeclConsoleLetProperty(unaligned T* playout)
  4345. {
  4346. FrameDisplay* pScope = (FrameDisplay*)this->LdEnv();
  4347. AssertMsg(ConsoleScopeActivationObject::Is((DynamicObject*)pScope->GetItem(pScope->GetLength() - 1)), "How come we got this opcode without ConsoleScopeActivationObject?");
  4348. PropertyId propertyId = m_functionBody->GetReferencedPropertyId(playout->PropertyIdIndex);
  4349. JavascriptOperators::OP_InitLetProperty(pScope->GetItem(0), propertyId, this->scriptContext->GetLibrary()->GetUndeclBlockVar());
  4350. }
  4351. template <class T>
  4352. void InterpreterStackFrame::OP_InitUndeclConsoleConstProperty(unaligned T* playout)
  4353. {
  4354. FrameDisplay* pScope = (FrameDisplay*)this->LdEnv();
  4355. AssertMsg(ConsoleScopeActivationObject::Is((DynamicObject*)pScope->GetItem(pScope->GetLength() - 1)), "How come we got this opcode without ConsoleScopeActivationObject?");
  4356. PropertyId propertyId = m_functionBody->GetReferencedPropertyId(playout->PropertyIdIndex);
  4357. JavascriptOperators::OP_InitConstProperty(pScope->GetItem(0), propertyId, this->scriptContext->GetLibrary()->GetUndeclBlockVar());
  4358. }
  4359. #if ENABLE_PROFILE_INFO
  4360. template <class T>
  4361. void InterpreterStackFrame::ProfiledInitProperty(unaligned T* playout, Var instance)
  4362. {
  4363. ProfilingHelpers::ProfiledInitFld(
  4364. RecyclableObject::FromVar(instance),
  4365. GetPropertyIdFromCacheId(playout->inlineCacheIndex),
  4366. GetInlineCache(playout->inlineCacheIndex),
  4367. playout->inlineCacheIndex,
  4368. GetReg(playout->Value),
  4369. GetFunctionBody());
  4370. }
  4371. template <class T>
  4372. void InterpreterStackFrame::OP_ProfiledInitProperty(unaligned T* playout)
  4373. {
  4374. ProfiledInitProperty(playout, GetReg(playout->Instance));
  4375. }
  4376. template <class T>
  4377. void InterpreterStackFrame::OP_ProfiledInitLocalProperty(unaligned T* playout)
  4378. {
  4379. ProfiledInitProperty(playout, this->localClosure);
  4380. }
  4381. template <class T>
  4382. void InterpreterStackFrame::OP_ProfiledInitRootProperty(unaligned T* playout)
  4383. {
  4384. ProfiledInitProperty(playout, this->GetRootObject());
  4385. }
  4386. template <class T>
  4387. void InterpreterStackFrame::OP_ProfiledGetElementI(const unaligned OpLayoutDynamicProfile<T>* playout)
  4388. {
  4389. ThreadContext* threadContext = this->GetScriptContext()->GetThreadContext();
  4390. ImplicitCallFlags savedImplicitCallFlags = threadContext->GetImplicitCallFlags();
  4391. threadContext->ClearImplicitCallFlags();
  4392. SetReg(
  4393. playout->Value,
  4394. ProfilingHelpers::ProfiledLdElem(
  4395. GetReg(playout->Instance),
  4396. GetReg(playout->Element),
  4397. m_functionBody,
  4398. playout->profileId,
  4399. this->TestFlags(InterpreterStackFrameFlags_ProcessingBailOutOnArrayAccessHelperCall),
  4400. this->TestFlags(InterpreterStackFrameFlags_ProcessingBailOutOnArraySpecialization)));
  4401. this->ClearFlags(InterpreterStackFrameFlags_ProcessingBailOutOnArrayAccessHelperCall | InterpreterStackFrameFlags_ProcessingBailOutOnArraySpecialization);
  4402. threadContext->CheckAndResetImplicitCallAccessorFlag();
  4403. threadContext->AddImplicitCallFlags(savedImplicitCallFlags);
  4404. }
  4405. #endif
  4406. template <typename T>
  4407. void InterpreterStackFrame::OP_GetElementI(const unaligned T* playout)
  4408. {
  4409. ThreadContext* threadContext = this->GetScriptContext()->GetThreadContext();
  4410. ImplicitCallFlags savedImplicitCallFlags = threadContext->GetImplicitCallFlags();
  4411. threadContext->ClearImplicitCallFlags();
  4412. // Same fast path as in the backend.
  4413. Var instance = GetReg(playout->Instance);
  4414. // Only enable fast path if the javascript array is not cross site
  4415. Var element;
  4416. #if ENABLE_PROFILE_INFO
  4417. if (!TaggedNumber::Is(instance) && VirtualTableInfo<JavascriptArray>::HasVirtualTable(instance))
  4418. {
  4419. element =
  4420. ProfilingHelpers::ProfiledLdElem_FastPath(
  4421. JavascriptArray::UnsafeFromVar(instance),
  4422. GetReg(playout->Element),
  4423. GetScriptContext());
  4424. }
  4425. else
  4426. #endif
  4427. {
  4428. element = JavascriptOperators::OP_GetElementI(instance, GetReg(playout->Element), GetScriptContext());
  4429. }
  4430. this->ClearFlags(InterpreterStackFrameFlags_ProcessingBailOutOnArrayAccessHelperCall);
  4431. threadContext->CheckAndResetImplicitCallAccessorFlag();
  4432. threadContext->AddImplicitCallFlags(savedImplicitCallFlags);
  4433. SetReg(playout->Value, element);
  4434. }
  4435. template <typename T>
  4436. void InterpreterStackFrame::OP_SetElementI(const unaligned T* playout, PropertyOperationFlags flags)
  4437. {
  4438. ThreadContext* threadContext = this->GetScriptContext()->GetThreadContext();
  4439. ImplicitCallFlags savedImplicitCallFlags = threadContext->GetImplicitCallFlags();
  4440. threadContext->ClearImplicitCallFlags();
  4441. // Same fast path as in the backend.
  4442. Var instance = GetReg(playout->Instance);
  4443. const Var varIndex = GetReg(playout->Element);
  4444. const Var value = GetReg(playout->Value);
  4445. #if ENABLE_PROFILE_INFO
  4446. // Only enable fast path if the javascript array is not cross site
  4447. if (!TaggedNumber::Is(instance) &&
  4448. VirtualTableInfo<JavascriptArray>::HasVirtualTable(instance) &&
  4449. !JavascriptOperators::SetElementMayHaveImplicitCalls(GetScriptContext()))
  4450. {
  4451. ProfilingHelpers::ProfiledStElem_FastPath(
  4452. JavascriptArray::UnsafeFromVar(instance),
  4453. varIndex,
  4454. value,
  4455. GetScriptContext(),
  4456. flags);
  4457. }
  4458. else
  4459. #endif
  4460. {
  4461. JavascriptOperators::OP_SetElementI(instance, varIndex, value, GetScriptContext(), flags);
  4462. }
  4463. this->ClearFlags(InterpreterStackFrameFlags_ProcessingBailOutOnArrayAccessHelperCall);
  4464. threadContext->CheckAndResetImplicitCallAccessorFlag();
  4465. threadContext->AddImplicitCallFlags(savedImplicitCallFlags);
  4466. }
  4467. #if ENABLE_PROFILE_INFO
  4468. template <typename T>
  4469. void InterpreterStackFrame::OP_ProfiledSetElementI(
  4470. const unaligned OpLayoutDynamicProfile<T>* playout,
  4471. PropertyOperationFlags flags)
  4472. {
  4473. ThreadContext* threadContext = this->GetScriptContext()->GetThreadContext();
  4474. ImplicitCallFlags savedImplicitCallFlags = threadContext->GetImplicitCallFlags();
  4475. threadContext->ClearImplicitCallFlags();
  4476. ProfilingHelpers::ProfiledStElem(
  4477. GetReg(playout->Instance),
  4478. GetReg(playout->Element),
  4479. GetReg(playout->Value),
  4480. m_functionBody,
  4481. playout->profileId,
  4482. flags,
  4483. this->TestFlags(InterpreterStackFrameFlags_ProcessingBailOutOnArrayAccessHelperCall),
  4484. this->TestFlags(InterpreterStackFrameFlags_ProcessingBailOutOnArraySpecialization));
  4485. this->ClearFlags(InterpreterStackFrameFlags_ProcessingBailOutOnArrayAccessHelperCall | InterpreterStackFrameFlags_ProcessingBailOutOnArraySpecialization);
  4486. threadContext->CheckAndResetImplicitCallAccessorFlag();
  4487. threadContext->AddImplicitCallFlags(savedImplicitCallFlags);
  4488. }
  4489. #endif
  4490. template <typename T>
  4491. void InterpreterStackFrame::OP_SetElementIStrict(const unaligned T* playout)
  4492. {
  4493. ThreadContext* threadContext = this->GetScriptContext()->GetThreadContext();
  4494. ImplicitCallFlags savedImplicitCallFlags = threadContext->GetImplicitCallFlags();
  4495. threadContext->ClearImplicitCallFlags();
  4496. OP_SetElementI(playout, PropertyOperation_StrictMode);
  4497. threadContext->CheckAndResetImplicitCallAccessorFlag();
  4498. threadContext->AddImplicitCallFlags(savedImplicitCallFlags);
  4499. }
  4500. #if ENABLE_PROFILE_INFO
  4501. template <typename T>
  4502. void InterpreterStackFrame::OP_ProfiledSetElementIStrict(const unaligned OpLayoutDynamicProfile<T>* playout)
  4503. {
  4504. ThreadContext* threadContext = this->GetScriptContext()->GetThreadContext();
  4505. ImplicitCallFlags savedImplicitCallFlags = threadContext->GetImplicitCallFlags();
  4506. threadContext->ClearImplicitCallFlags();
  4507. OP_ProfiledSetElementI(playout, PropertyOperation_StrictMode);
  4508. threadContext->CheckAndResetImplicitCallAccessorFlag();
  4509. threadContext->AddImplicitCallFlags(savedImplicitCallFlags);
  4510. }
  4511. #endif
  4512. template <class T>
  4513. void InterpreterStackFrame::OP_LdArrayHeadSegment(const unaligned T* playout)
  4514. {
  4515. JavascriptArray* array = JavascriptArray::FromAnyArray(GetReg(playout->R1));
  4516. // The array is create by the built-in on the same script context
  4517. Assert(array->GetScriptContext() == GetScriptContext());
  4518. SetNonVarReg(playout->R0, array->GetHead());
  4519. }
  4520. template <class T>
  4521. void InterpreterStackFrame::OP_SetArraySegmentItem_CI4(const unaligned T* playout)
  4522. {
  4523. SparseArraySegment<Var> * segment = (SparseArraySegment<Var> *)GetNonVarReg(playout->Instance);
  4524. uint32 index = playout->Element;
  4525. Var value = GetReg(playout->Value);
  4526. Assert(segment->left == 0);
  4527. Assert(index < segment->length);
  4528. segment->elements[index] = value;
  4529. }
  4530. template <class T>
  4531. void InterpreterStackFrame::OP_NewScArray(const unaligned T * playout)
  4532. {
  4533. JavascriptArray *arr;
  4534. arr = scriptContext->GetLibrary()->CreateArrayLiteral(playout->C1);
  4535. #ifdef ENABLE_DEBUG_CONFIG_OPTIONS
  4536. arr->CheckForceES5Array();
  4537. #endif
  4538. SetReg(playout->R0, arr);
  4539. }
  4540. #if ENABLE_PROFILE_INFO
  4541. template <bool Profiled, class T>
  4542. void InterpreterStackFrame::ProfiledNewScArray(const unaligned OpLayoutDynamicProfile<T> * playout)
  4543. {
  4544. if (!Profiled && !isAutoProfiling)
  4545. {
  4546. OP_NewScArray(playout);
  4547. return;
  4548. }
  4549. SetReg(
  4550. playout->R0,
  4551. ProfilingHelpers::ProfiledNewScArray(
  4552. playout->C1,
  4553. m_functionBody,
  4554. playout->profileId));
  4555. }
  4556. #else
  4557. template <bool Profiled, class T>
  4558. void InterpreterStackFrame::ProfiledNewScArray(const unaligned OpLayoutDynamicProfile<T> * playout)
  4559. {
  4560. Assert(!Profiled);
  4561. OP_NewScArray(playout);
  4562. }
  4563. #endif
  4564. void InterpreterStackFrame::OP_NewScIntArray(const unaligned OpLayoutAuxiliary * playout)
  4565. {
  4566. const Js::AuxArray<int32> *ints = Js::ByteCodeReader::ReadAuxArray<int32>(playout->Offset, this->GetFunctionBody());
  4567. JavascriptNativeIntArray *arr = scriptContext->GetLibrary()->CreateNativeIntArrayLiteral(ints->count);
  4568. SparseArraySegment<int32> * segment = (SparseArraySegment<int32>*)arr->GetHead();
  4569. JavascriptOperators::AddIntsToArraySegment(segment, ints);
  4570. #ifdef ENABLE_DEBUG_CONFIG_OPTIONS
  4571. arr->CheckForceES5Array();
  4572. #endif
  4573. SetReg(playout->R0, arr);
  4574. }
  4575. #if ENABLE_PROFILE_INFO
  4576. template <bool Profiled>
  4577. void InterpreterStackFrame::ProfiledNewScIntArray(const unaligned OpLayoutDynamicProfile<OpLayoutAuxiliary> * playout)
  4578. {
  4579. if (!Profiled && !isAutoProfiling)
  4580. {
  4581. OP_NewScIntArray(playout);
  4582. return;
  4583. }
  4584. const Js::AuxArray<int32> *ints = Js::ByteCodeReader::ReadAuxArray<int32>(playout->Offset, this->GetFunctionBody());
  4585. Js::ProfileId profileId = playout->profileId;
  4586. FunctionBody *functionBody = this->m_functionBody;
  4587. ArrayCallSiteInfo *arrayInfo = functionBody->GetDynamicProfileInfo()->GetArrayCallSiteInfo(functionBody, profileId);
  4588. Assert(arrayInfo);
  4589. JavascriptArray *arr;
  4590. if (arrayInfo && arrayInfo->IsNativeIntArray())
  4591. {
  4592. #if ENABLE_COPYONACCESS_ARRAY
  4593. JavascriptLibrary *lib = scriptContext->GetLibrary();
  4594. if (JavascriptLibrary::IsCopyOnAccessArrayCallSite(lib, arrayInfo, ints->count))
  4595. {
  4596. Assert(lib->cacheForCopyOnAccessArraySegments);
  4597. arr = scriptContext->GetLibrary()->CreateCopyOnAccessNativeIntArrayLiteral(arrayInfo, functionBody, ints);
  4598. }
  4599. else
  4600. #endif
  4601. {
  4602. arr = scriptContext->GetLibrary()->CreateNativeIntArrayLiteral(ints->count);
  4603. SparseArraySegment<int32> *segment = (SparseArraySegment<int32>*)arr->GetHead();
  4604. JavascriptOperators::AddIntsToArraySegment(segment, ints);
  4605. }
  4606. JavascriptNativeIntArray *intArray = reinterpret_cast<JavascriptNativeIntArray*>(arr);
  4607. Recycler *recycler = scriptContext->GetRecycler();
  4608. intArray->SetArrayCallSite(profileId, recycler->CreateWeakReferenceHandle(functionBody));
  4609. }
  4610. else if (arrayInfo && arrayInfo->IsNativeFloatArray())
  4611. {
  4612. arr = scriptContext->GetLibrary()->CreateNativeFloatArrayLiteral(ints->count);
  4613. SparseArraySegment<double> * segment = (SparseArraySegment<double>*)arr->GetHead();
  4614. for (uint i = 0; i < ints->count; i++)
  4615. {
  4616. segment->elements[i] = (double)ints->elements[i];
  4617. }
  4618. JavascriptNativeFloatArray *floatArray = reinterpret_cast<JavascriptNativeFloatArray*>(arr);
  4619. Recycler *recycler = scriptContext->GetRecycler();
  4620. floatArray->SetArrayCallSite(profileId, recycler->CreateWeakReferenceHandle(functionBody));
  4621. }
  4622. else
  4623. {
  4624. arr = scriptContext->GetLibrary()->CreateArrayLiteral(ints->count);
  4625. SparseArraySegment<Var> * segment = (SparseArraySegment<Var>*)arr->GetHead();
  4626. for (uint i = 0; i < ints->count; i++)
  4627. {
  4628. segment->elements[i] = JavascriptNumber::ToVar(ints->elements[i], scriptContext);
  4629. }
  4630. }
  4631. #ifdef ENABLE_DEBUG_CONFIG_OPTIONS
  4632. arr->CheckForceES5Array();
  4633. #endif
  4634. SetReg(playout->R0, arr);
  4635. }
  4636. #else
  4637. template <bool Profiled>
  4638. void InterpreterStackFrame::ProfiledNewScIntArray(const unaligned OpLayoutDynamicProfile<OpLayoutAuxiliary> * playout)
  4639. {
  4640. OP_NewScIntArray(playout);
  4641. }
  4642. #endif
  4643. void InterpreterStackFrame::OP_NewScFltArray(const unaligned OpLayoutAuxiliary * playout)
  4644. {
  4645. const Js::AuxArray<double> *doubles = Js::ByteCodeReader::ReadAuxArray<double>(playout->Offset, this->GetFunctionBody());
  4646. JavascriptNativeFloatArray *arr = scriptContext->GetLibrary()->CreateNativeFloatArrayLiteral(doubles->count);
  4647. SparseArraySegment<double> * segment = (SparseArraySegment<double>*)arr->GetHead();
  4648. JavascriptOperators::AddFloatsToArraySegment(segment, doubles);
  4649. #ifdef ENABLE_DEBUG_CONFIG_OPTIONS
  4650. arr->CheckForceES5Array();
  4651. #endif
  4652. SetReg(playout->R0, arr);
  4653. }
  4654. #if ENABLE_PROFILE_INFO
  4655. template <bool Profiled>
  4656. void InterpreterStackFrame::ProfiledNewScFltArray(const unaligned OpLayoutDynamicProfile<OpLayoutAuxiliary> * playout)
  4657. {
  4658. if (!Profiled && !isAutoProfiling)
  4659. {
  4660. OP_NewScFltArray(playout);
  4661. return;
  4662. }
  4663. const Js::AuxArray<double> *doubles = Js::ByteCodeReader::ReadAuxArray<double>(playout->Offset, this->GetFunctionBody());
  4664. Js::ProfileId profileId = playout->profileId;
  4665. FunctionBody *functionBody = this->m_functionBody;
  4666. ArrayCallSiteInfo *arrayInfo = functionBody->GetDynamicProfileInfo()->GetArrayCallSiteInfo(functionBody, profileId);
  4667. Assert(arrayInfo);
  4668. JavascriptArray *arr;
  4669. if (arrayInfo && arrayInfo->IsNativeFloatArray())
  4670. {
  4671. arrayInfo->SetIsNotNativeIntArray();
  4672. arr = scriptContext->GetLibrary()->CreateNativeFloatArrayLiteral(doubles->count);
  4673. SparseArraySegment<double> * segment = (SparseArraySegment<double>*)arr->GetHead();
  4674. JavascriptOperators::AddFloatsToArraySegment(segment, doubles);
  4675. JavascriptNativeFloatArray *floatArray = reinterpret_cast<JavascriptNativeFloatArray*>(arr);
  4676. Recycler *recycler = scriptContext->GetRecycler();
  4677. floatArray->SetArrayCallSite(profileId, recycler->CreateWeakReferenceHandle(functionBody));
  4678. }
  4679. else
  4680. {
  4681. arr = scriptContext->GetLibrary()->CreateArrayLiteral(doubles->count);
  4682. SparseArraySegment<Var> * segment = (SparseArraySegment<Var>*)arr->GetHead();
  4683. for (uint i = 0; i < doubles->count; i++)
  4684. {
  4685. segment->elements[i] = JavascriptNumber::ToVarNoCheck(doubles->elements[i], scriptContext);
  4686. }
  4687. }
  4688. #ifdef ENABLE_DEBUG_CONFIG_OPTIONS
  4689. arr->CheckForceES5Array();
  4690. #endif
  4691. SetReg(playout->R0, arr);
  4692. }
  4693. #else
  4694. template <bool Profiled>
  4695. void InterpreterStackFrame::ProfiledNewScFltArray(const unaligned OpLayoutDynamicProfile<OpLayoutAuxiliary> * playout)
  4696. {
  4697. OP_NewScFltArray(playout);
  4698. }
  4699. #endif
  4700. void InterpreterStackFrame::OP_SetArraySegmentVars(const unaligned OpLayoutAuxiliary * playout)
  4701. {
  4702. const Js::VarArray *vars = Js::ByteCodeReader::ReadAuxArray<Var>(playout->Offset, this->GetFunctionBody());
  4703. SparseArraySegment<Var> * segment = (SparseArraySegment<Var> *)GetNonVarReg(playout->R0);
  4704. JavascriptOperators::AddVarsToArraySegment(segment, vars);
  4705. }
  4706. template <class T>
  4707. void InterpreterStackFrame::OP_SetArrayItemC_CI4(const unaligned T* playout)
  4708. {
  4709. JavascriptArray* array = JavascriptArray::FromAnyArray(GetReg(playout->Instance));
  4710. uint32 index = playout->Element;
  4711. Var value = GetReg(playout->Value);
  4712. #if ENABLE_COPYONACCESS_ARRAY
  4713. JavascriptLibrary::CheckAndConvertCopyOnAccessNativeIntArray<Var>(value);
  4714. #endif
  4715. // The array is create by the built-in on the same script context
  4716. Assert(array->GetScriptContext() == GetScriptContext());
  4717. TypeId typeId = array->GetTypeId();
  4718. if (typeId == TypeIds_NativeIntArray)
  4719. {
  4720. JavascriptArray::OP_SetNativeIntElementC(reinterpret_cast<JavascriptNativeIntArray*>(array), index, value, array->GetScriptContext());
  4721. }
  4722. else if (typeId == TypeIds_NativeFloatArray)
  4723. {
  4724. JavascriptArray::OP_SetNativeFloatElementC(reinterpret_cast<JavascriptNativeFloatArray*>(array), index, value, array->GetScriptContext());
  4725. }
  4726. else
  4727. {
  4728. array->SetArrayLiteralItem(index, value);
  4729. }
  4730. }
  4731. template <class T>
  4732. void InterpreterStackFrame::OP_SetArrayItemI_CI4(const unaligned T* playout)
  4733. {
  4734. // Note that this code assumes that we only get here when we see an array literal,
  4735. // so we know that the instance is truly an array, and the index is a uint32.
  4736. // If/when we use this for cases like "a[0] = x", we'll at least have to check
  4737. // whether "a" is really an array.
  4738. JavascriptArray* array = JavascriptArray::FromAnyArray(GetReg(playout->Instance));
  4739. // The array is create by the built-in on the same script context
  4740. Assert(array->GetScriptContext() == GetScriptContext());
  4741. uint32 index = playout->Element;
  4742. Var value = GetReg(playout->Value);
  4743. Assert(VirtualTableInfo<JavascriptArray>::HasVirtualTable(array));
  4744. SparseArraySegment<Var>* lastUsedSeg = (SparseArraySegment<Var>*)array->GetLastUsedSegment();
  4745. if (index >= lastUsedSeg->left)
  4746. {
  4747. uint32 index2 = index - lastUsedSeg->left;
  4748. if (index2 < lastUsedSeg->size)
  4749. {
  4750. // Successful fastpath
  4751. array->DirectSetItemInLastUsedSegmentAt(index2, value);
  4752. return;
  4753. }
  4754. }
  4755. ScriptContext* scriptContext = array->GetScriptContext();
  4756. JavascriptOperators::SetItem(array, array, index, value, scriptContext);
  4757. }
  4758. #if ENABLE_PROFILE_INFO
  4759. Var InterpreterStackFrame::OP_ProfiledLdThis(Var thisVar, int moduleID, ScriptContext *scriptContext)
  4760. {
  4761. FunctionBody * functionBody = this->m_functionBody;
  4762. DynamicProfileInfo * dynamicProfileInfo = functionBody->GetDynamicProfileInfo();
  4763. TypeId typeId = JavascriptOperators::GetTypeId(thisVar);
  4764. if (JavascriptOperators::IsThisSelf(typeId))
  4765. {
  4766. Assert(typeId != TypeIds_GlobalObject || ((Js::GlobalObject*)thisVar)->ToThis() == thisVar);
  4767. Assert(typeId != TypeIds_ModuleRoot || JavascriptOperators::GetThisFromModuleRoot(thisVar) == thisVar);
  4768. // Record the fact that we saw a trivial LdThis.
  4769. dynamicProfileInfo->RecordThisInfo(thisVar, ThisType_Simple);
  4770. return thisVar;
  4771. }
  4772. thisVar = JavascriptOperators::OP_GetThis(thisVar, moduleID, scriptContext);
  4773. // Record the fact that we saw a LdThis that had to map its source to something else, or at least
  4774. // forced us to call a helper, e.g., a FastDOM object with an unrecognized type ID.
  4775. dynamicProfileInfo->RecordThisInfo(thisVar, ThisType_Mapped);
  4776. return thisVar;
  4777. }
  4778. Var InterpreterStackFrame::OP_ProfiledStrictLdThis(Var thisVar, ScriptContext* scriptContext)
  4779. {
  4780. FunctionBody * functionBody = this->m_functionBody;
  4781. DynamicProfileInfo * dynamicProfileInfo = functionBody->GetDynamicProfileInfo();
  4782. TypeId typeId = JavascriptOperators::GetTypeId(thisVar);
  4783. if (typeId == TypeIds_ActivationObject)
  4784. {
  4785. thisVar = scriptContext->GetLibrary()->GetUndefined();
  4786. dynamicProfileInfo->RecordThisInfo(thisVar, ThisType_Mapped);
  4787. return thisVar;
  4788. }
  4789. dynamicProfileInfo->RecordThisInfo(thisVar, ThisType_Simple);
  4790. return thisVar;
  4791. }
  4792. #endif
  4793. void InterpreterStackFrame::OP_InitCachedFuncs(const unaligned OpLayoutAuxNoReg * playout)
  4794. {
  4795. const FuncInfoArray *info = Js::ByteCodeReader::ReadAuxArray<FuncInfoEntry>(playout->Offset, this->GetFunctionBody());
  4796. JavascriptOperators::OP_InitCachedFuncs(this->localClosure, GetLocalFrameDisplay(), info, GetScriptContext());
  4797. }
  4798. Var InterpreterStackFrame::OP_GetCachedFunc(Var instance, int32 index)
  4799. {
  4800. ActivationObjectEx *obj = ActivationObjectEx::FromVar(instance);
  4801. FuncCacheEntry *entry = obj->GetFuncCacheEntry((uint)index);
  4802. return entry->func;
  4803. }
  4804. void InterpreterStackFrame::OP_CommitScope()
  4805. {
  4806. const Js::PropertyIdArray *propIds = this->m_functionBody->GetFormalsPropIdArray();
  4807. this->OP_CommitScopeHelper(propIds);
  4808. }
  4809. void InterpreterStackFrame::OP_CommitScopeHelper(const PropertyIdArray *propIds)
  4810. {
  4811. ActivationObjectEx *obj = ActivationObjectEx::FromVar(this->localClosure);
  4812. ScriptFunction *func = obj->GetParentFunc();
  4813. Assert(obj->GetParentFunc() == func);
  4814. if (func->GetCachedScope() == obj)
  4815. {
  4816. PropertyId firstVarSlot = ActivationObjectEx::GetFirstVarSlot(propIds);
  4817. Var undef = scriptContext->GetLibrary()->GetUndefined();
  4818. for (uint i = firstVarSlot; i < propIds->count; i++)
  4819. {
  4820. obj->SetSlot(SetSlotArguments(propIds->elements[i], i, undef));
  4821. }
  4822. obj->SetCommit(true);
  4823. }
  4824. }
  4825. Var InterpreterStackFrame::OP_NewScObjectSimple()
  4826. {
  4827. Var object = scriptContext->GetLibrary()->CreateObject(true);
  4828. JS_ETW(EventWriteJSCRIPT_RECYCLER_ALLOCATE_OBJECT(object));
  4829. #if ENABLE_DEBUG_CONFIG_OPTIONS
  4830. if (Js::Configuration::Global.flags.IsEnabled(Js::autoProxyFlag))
  4831. {
  4832. object = JavascriptProxy::AutoProxyWrapper(object);
  4833. }
  4834. #endif
  4835. return object;
  4836. }
  4837. void InterpreterStackFrame::OP_NewScObjectLiteral(const unaligned OpLayoutAuxiliary * playout)
  4838. {
  4839. const Js::PropertyIdArray *propIds = Js::ByteCodeReader::ReadPropertyIdArray(playout->Offset, this->GetFunctionBody());
  4840. Var newObj = JavascriptOperators::NewScObjectLiteral(GetScriptContext(), propIds,
  4841. this->GetFunctionBody()->GetObjectLiteralTypeRef(playout->C1));
  4842. SetReg(playout->R0, newObj);
  4843. }
  4844. void InterpreterStackFrame::OP_NewScObjectLiteral_LS(const unaligned OpLayoutAuxiliary * playout, RegSlot& target)
  4845. {
  4846. const Js::PropertyIdArray *propIds = Js::ByteCodeReader::ReadPropertyIdArray(playout->Offset, this->GetFunctionBody());
  4847. target = playout->R0;
  4848. Var newObj = JavascriptOperators::NewScObjectLiteral(GetScriptContext(), propIds,
  4849. this->GetFunctionBody()->GetObjectLiteralTypeRef(playout->C1));
  4850. SetReg(playout->R0, newObj);
  4851. target = Js::Constants::NoRegister;
  4852. }
  4853. void InterpreterStackFrame::OP_LdPropIds(const unaligned OpLayoutAuxiliary * playout)
  4854. {
  4855. const Js::PropertyIdArray *propIds = Js::ByteCodeReader::ReadPropertyIdArray(playout->Offset, this->GetFunctionBody());
  4856. SetNonVarReg(playout->R0, (Var)propIds);
  4857. }
  4858. bool InterpreterStackFrame::IsCurrentLoopNativeAddr(void * codeAddr) const
  4859. {
  4860. if (this->GetCurrentLoopNum() == LoopHeader::NoLoop)
  4861. {
  4862. return false;
  4863. }
  4864. // TODO: Do more verification?
  4865. return true;
  4866. }
  4867. template <LayoutSize layoutSize, bool profiled>
  4868. const byte * InterpreterStackFrame::OP_ProfiledLoopBodyStart(const byte * ip)
  4869. {
  4870. uint32 loopId = m_reader.GetLayout<OpLayoutT_Unsigned1<LayoutSizePolicy<layoutSize>>>(ip)->C1;
  4871. return OP_ProfiledLoopBodyStart<layoutSize, profiled>(loopId);
  4872. }
  4873. #ifdef ASMJS_PLAT
  4874. template <LayoutSize layoutSize, bool profiled>
  4875. const byte * InterpreterStackFrame::OP_ProfiledWasmLoopBodyStart(const byte * ip)
  4876. {
  4877. uint32 loopId = m_reader.GetLayout<OpLayoutT_WasmLoopStart<LayoutSizePolicy<layoutSize>>>(ip)->loopId;
  4878. return OP_ProfiledLoopBodyStart<layoutSize, profiled>(loopId);
  4879. }
  4880. #endif
  4881. #if ENABLE_PROFILE_INFO
  4882. void InterpreterStackFrame::OP_RecordImplicitCall(uint loopNumber)
  4883. {
  4884. Assert(Js::DynamicProfileInfo::EnableImplicitCallFlags(GetFunctionBody()));
  4885. Assert(loopNumber < this->m_functionBody->GetLoopCount());
  4886. FunctionBody* functionBody = this->m_functionBody;
  4887. DynamicProfileInfo * dynamicProfileInfo = functionBody->GetDynamicProfileInfo();
  4888. ThreadContext * threadContext = scriptContext->GetThreadContext();
  4889. dynamicProfileInfo->RecordLoopImplicitCallFlags(functionBody, loopNumber, threadContext->GetImplicitCallFlags());
  4890. }
  4891. template <LayoutSize layoutSize, bool profiled>
  4892. const byte * InterpreterStackFrame::OP_ProfiledLoopStart(const byte * ip)
  4893. {
  4894. const uint32 C1 = m_reader.GetLayout<OpLayoutT_Unsigned1<LayoutSizePolicy<layoutSize>>>(ip)->C1;
  4895. if (!profiled && !isAutoProfiling)
  4896. {
  4897. return ip;
  4898. }
  4899. ThreadContext *const threadContext = GetScriptContext()->GetThreadContext();
  4900. threadContext->IncrementLoopDepth();
  4901. // Save the implicit call flags. The interpreter may switch to profiling mode during LoopBodyStart, so always do this.
  4902. Assert(Js::DynamicProfileInfo::EnableImplicitCallFlags(GetFunctionBody()));
  4903. this->savedLoopImplicitCallFlags[C1] = threadContext->GetImplicitCallFlags();
  4904. threadContext->SetImplicitCallFlags(ImplicitCall_None);
  4905. this->currentLoopCounter = 0;
  4906. if (!profiled)
  4907. {
  4908. return ip;
  4909. }
  4910. LayoutSize localLayoutSize;
  4911. OpCode peekOp = m_reader.PeekOp(ip, localLayoutSize);
  4912. Assert(peekOp != OpCode::LoopBodyStart);
  4913. if (peekOp == OpCode::ProfiledLoopBodyStart)
  4914. {
  4915. Assert(localLayoutSize == layoutSize);
  4916. ip += Js::OpCodeUtil::EncodedSize(peekOp, layoutSize);
  4917. // We are doing JIT loop body. Process the first ProfiledLoopBodyStart to avoid recording
  4918. // the implicit call before the first iteration
  4919. uint32 C2 = m_reader.GetLayout<OpLayoutT_Unsigned1<LayoutSizePolicy<layoutSize>>>(ip)->C1;
  4920. Assert(C1 == C2);
  4921. (this->*opProfiledLoopBodyStart)(C1, layoutSize, true /* isFirstIteration */);
  4922. return m_reader.GetIP();
  4923. }
  4924. return ip;
  4925. }
  4926. template <LayoutSize layoutSize, bool profiled>
  4927. const byte * InterpreterStackFrame::OP_ProfiledLoopEnd(const byte * ip)
  4928. {
  4929. uint32 loopNumber = m_reader.GetLayout<OpLayoutT_Unsigned1<LayoutSizePolicy<layoutSize>>>(ip)->C1;
  4930. if (!profiled && !isAutoProfiling)
  4931. {
  4932. return ip;
  4933. }
  4934. this->CheckIfLoopIsHot(this->currentLoopCounter);
  4935. Js::FunctionBody *fn = this->function->GetFunctionBody();
  4936. if (fn->HasDynamicProfileInfo())
  4937. {
  4938. fn->GetAnyDynamicProfileInfo()->SetLoopInterpreted(loopNumber);
  4939. // If the counter is 0, there is a high chance that some config disabled tracking that information. (ie: -off:jitloopbody)
  4940. // Assume it is valid for memop in this case.
  4941. if (this->currentLoopCounter >= (uint)CONFIG_FLAG(MinMemOpCount) ||
  4942. (this->currentLoopCounter == 0 && !this->m_functionBody->DoJITLoopBody())
  4943. )
  4944. {
  4945. // This flag becomes relevant only if the loop has been interpreted
  4946. fn->GetAnyDynamicProfileInfo()->SetMemOpMinReached(loopNumber);
  4947. }
  4948. }
  4949. this->currentLoopCounter = 0;
  4950. if (profiled)
  4951. {
  4952. Assert(Js::DynamicProfileInfo::EnableImplicitCallFlags(GetFunctionBody()));
  4953. OP_RecordImplicitCall(loopNumber);
  4954. if (switchProfileModeOnLoopEndNumber == loopNumber)
  4955. {
  4956. // Stop profiling since the jitted loop body would be exiting the loop
  4957. Assert(!switchProfileMode);
  4958. switchProfileMode = true;
  4959. switchProfileModeOnLoopEndNumber = 0u - 1;
  4960. }
  4961. }
  4962. // Restore the implicit call flags state and add with flags in the loop as well
  4963. ThreadContext *const threadContext = GetScriptContext()->GetThreadContext();
  4964. threadContext->AddImplicitCallFlags(this->savedLoopImplicitCallFlags[loopNumber]);
  4965. threadContext->DecrementLoopDepth();
  4966. return ip;
  4967. }
  4968. template <LayoutSize layoutSize, bool profiled>
  4969. const byte * InterpreterStackFrame::OP_ProfiledLoopBodyStart(uint loopId)
  4970. {
  4971. if (profiled || isAutoProfiling)
  4972. {
  4973. this->currentLoopCounter++;
  4974. }
  4975. if (profiled)
  4976. {
  4977. OP_RecordImplicitCall(loopId);
  4978. }
  4979. (this->*(profiled ? opProfiledLoopBodyStart : opLoopBodyStart))(loopId, layoutSize, false /* isFirstIteration */);
  4980. return m_reader.GetIP();
  4981. }
  4982. template<bool InterruptProbe, bool JITLoopBody>
  4983. void InterpreterStackFrame::ProfiledLoopBodyStart(uint32 loopNumber, LayoutSize layoutSize, bool isFirstIteration)
  4984. {
  4985. Assert(Js::DynamicProfileInfo::EnableImplicitCallFlags(GetFunctionBody()));
  4986. if (InterruptProbe)
  4987. {
  4988. this->DoInterruptProbe();
  4989. }
  4990. #if ENABLE_TTD
  4991. if (SHOULD_DO_TTD_STACK_STMT_OP(this->scriptContext))
  4992. {
  4993. this->scriptContext->GetThreadContext()->TTDExecutionInfo->UpdateLoopCountInfo();
  4994. }
  4995. #endif
  4996. if (!JITLoopBody || this->IsInCatchOrFinallyBlock())
  4997. {
  4998. // For functions having try-catch-finally, jit loop bodies for loops that are contained only in a try block,
  4999. // not even indirect containment in a Catch or Finally.
  5000. return;
  5001. }
  5002. LoopHeader const * loopHeader = DoLoopBodyStart(loopNumber, layoutSize, false, isFirstIteration);
  5003. Assert(loopHeader == nullptr || this->m_functionBody->GetLoopNumber(loopHeader) == loopNumber);
  5004. if (loopHeader != nullptr)
  5005. {
  5006. // We executed jitted loop body, no implicit call information available for this loop
  5007. uint currentOffset = m_reader.GetCurrentOffset();
  5008. if (!loopHeader->Contains(currentOffset) || (m_reader.PeekOp() == OpCode::ProfiledLoopEnd))
  5009. {
  5010. // Restore the outer loop's implicit call flags
  5011. scriptContext->GetThreadContext()->SetImplicitCallFlags(this->savedLoopImplicitCallFlags[loopNumber]);
  5012. }
  5013. else
  5014. {
  5015. // We bailout from the loop, just continue collect implicit call flags for this loop
  5016. }
  5017. }
  5018. }
  5019. #else
  5020. template <LayoutSize layoutSize, bool profiled>
  5021. const byte * InterpreterStackFrame::OP_ProfiledLoopStart(const byte * ip)
  5022. {
  5023. Assert(!profiled);
  5024. return ip;
  5025. }
  5026. template <LayoutSize layoutSize, bool profiled>
  5027. const byte * InterpreterStackFrame::OP_ProfiledLoopEnd(const byte * ip)
  5028. {
  5029. Assert(!profiled);
  5030. return ip;
  5031. }
  5032. template <LayoutSize layoutSize, bool profiled>
  5033. const byte * InterpreterStackFrame::OP_ProfiledLoopBodyStart(uint loopId)
  5034. {
  5035. Assert(!profiled);
  5036. (this->*opLoopBodyStart)(loopId, layoutSize, false /* isFirstIteration */);
  5037. return m_reader.GetIP();
  5038. }
  5039. #endif
  5040. template<bool InterruptProbe, bool JITLoopBody>
  5041. void InterpreterStackFrame::LoopBodyStart(uint32 loopNumber, LayoutSize layoutSize, bool isFirstIteration)
  5042. {
  5043. if (InterruptProbe)
  5044. {
  5045. this->DoInterruptProbe();
  5046. }
  5047. #if ENABLE_TTD
  5048. if (SHOULD_DO_TTD_STACK_STMT_OP(this->scriptContext))
  5049. {
  5050. this->scriptContext->GetThreadContext()->TTDExecutionInfo->UpdateLoopCountInfo();
  5051. }
  5052. #endif
  5053. if (!JITLoopBody || this->IsInCatchOrFinallyBlock())
  5054. {
  5055. // For functions having try-catch-finally, jit loop bodies for loops that are contained only in a try block,
  5056. // not even indirect containment in a Catch or Finally.
  5057. return;
  5058. }
  5059. DoLoopBodyStart(loopNumber, layoutSize, true, isFirstIteration);
  5060. }
  5061. LoopHeader const * InterpreterStackFrame::DoLoopBodyStart(uint32 loopNumber, LayoutSize layoutSize, const bool doProfileLoopCheck, const bool isFirstIteration)
  5062. {
  5063. #if ENABLE_PROFILE_INFO
  5064. class AutoRestoreLoopNumbers
  5065. {
  5066. private:
  5067. InterpreterStackFrame * const interpreterStackFrame;
  5068. uint32 loopNumber;
  5069. bool doProfileLoopCheck;
  5070. public:
  5071. AutoRestoreLoopNumbers(InterpreterStackFrame *const interpreterStackFrame, uint32 loopNumber, bool doProfileLoopCheck)
  5072. : interpreterStackFrame(interpreterStackFrame), loopNumber(loopNumber), doProfileLoopCheck(doProfileLoopCheck)
  5073. {
  5074. Assert(interpreterStackFrame->currentLoopNum == LoopHeader::NoLoop);
  5075. interpreterStackFrame->currentLoopNum = loopNumber;
  5076. interpreterStackFrame->m_functionBody->SetRecentlyBailedOutOfJittedLoopBody(false);
  5077. }
  5078. ~AutoRestoreLoopNumbers()
  5079. {
  5080. interpreterStackFrame->currentLoopNum = LoopHeader::NoLoop;
  5081. interpreterStackFrame->currentLoopCounter = 0;
  5082. Js::FunctionBody* fn = interpreterStackFrame->m_functionBody;
  5083. if (fn->RecentlyBailedOutOfJittedLoopBody())
  5084. {
  5085. if (doProfileLoopCheck && interpreterStackFrame->isAutoProfiling)
  5086. {
  5087. // Start profiling the loop after a bailout. Some bailouts require subsequent profile data collection such
  5088. // that the rejitted loop body would not bail out again for the same reason.
  5089. Assert(!interpreterStackFrame->switchProfileMode);
  5090. interpreterStackFrame->switchProfileMode = true;
  5091. Assert(interpreterStackFrame->switchProfileModeOnLoopEndNumber == 0u - 1);
  5092. interpreterStackFrame->switchProfileModeOnLoopEndNumber = loopNumber;
  5093. }
  5094. }
  5095. else
  5096. {
  5097. if (interpreterStackFrame->switchProfileModeOnLoopEndNumber == loopNumber)
  5098. {
  5099. // Stop profiling since the jitted loop body would be exiting the loop
  5100. Assert(!interpreterStackFrame->switchProfileMode);
  5101. interpreterStackFrame->switchProfileMode = true;
  5102. interpreterStackFrame->switchProfileModeOnLoopEndNumber = 0u - 1;
  5103. }
  5104. interpreterStackFrame->scriptContext->GetThreadContext()->DecrementLoopDepth();
  5105. }
  5106. }
  5107. };
  5108. #endif
  5109. Js::FunctionBody* fn = this->m_functionBody;
  5110. Assert(loopNumber < fn->GetLoopCount());
  5111. Assert(!this->IsInCatchOrFinallyBlock());
  5112. Js::LoopHeader *loopHeader = fn->GetLoopHeader(loopNumber);
  5113. loopHeader->isInTry = this->TestFlags(Js::InterpreterStackFrameFlags_WithinTryBlock);
  5114. loopHeader->isInTryFinally = this->TestFlags(Js::InterpreterStackFrameFlags_WithinTryFinallyBlock);
  5115. Js::LoopEntryPointInfo * entryPointInfo = loopHeader->GetCurrentEntryPointInfo();
  5116. if (fn->ForceJITLoopBody() && loopHeader->interpretCount == 0 &&
  5117. (entryPointInfo != NULL && entryPointInfo->IsNotScheduled()))
  5118. {
  5119. #if ENABLE_PROFILE_INFO
  5120. if (Js::DynamicProfileInfo::EnableImplicitCallFlags(GetFunctionBody()))
  5121. {
  5122. scriptContext->GetThreadContext()->AddImplicitCallFlags(this->savedLoopImplicitCallFlags[loopNumber]);
  5123. }
  5124. #endif
  5125. #if ENABLE_NATIVE_CODEGEN
  5126. GenerateLoopBody(scriptContext->GetNativeCodeGenerator(), fn, loopHeader, entryPointInfo, fn->GetLocalsCount(), this->m_localSlots);
  5127. #endif
  5128. }
  5129. #if ENABLE_NATIVE_CODEGEN
  5130. // If we have JITted the loop, call the JITted code
  5131. if (entryPointInfo != NULL && entryPointInfo->IsCodeGenDone())
  5132. {
  5133. #if DBG_DUMP
  5134. if (PHASE_TRACE1(Js::JITLoopBodyPhase) && CONFIG_FLAG(Verbose))
  5135. {
  5136. fn->DumpFunctionId(true);
  5137. Output::Print(_u(": %-20s LoopBody Execute Loop: %2d\n"), fn->GetDisplayName(), loopNumber);
  5138. Output::Flush();
  5139. }
  5140. loopHeader->nativeCount++;
  5141. #endif
  5142. #ifdef BGJIT_STATS
  5143. entryPointInfo->MarkAsUsed();
  5144. #endif
  5145. entryPointInfo->EnsureIsReadyToCall();
  5146. entryPointInfo->SetNativeEntryPointProcessed();
  5147. RegSlot envReg = this->m_functionBody->GetEnvRegister();
  5148. if (envReg != Constants::NoRegister)
  5149. {
  5150. this->SetNonVarReg(envReg, this->LdEnv());
  5151. }
  5152. RegSlot localClosureReg = this->m_functionBody->GetLocalClosureRegister();
  5153. RegSlot localFrameDisplayReg = this->m_functionBody->GetLocalFrameDisplayRegister();
  5154. RegSlot paramClosureReg = this->m_functionBody->GetParamClosureRegister();
  5155. if (entryPointInfo->HasJittedStackClosure())
  5156. {
  5157. // The jitted code is expecting the closure registers to point to known stack locations where
  5158. // the closures can be found and possibly boxed.
  5159. // In a jitted loop body, those locations are the local closure fields on the interpreter instance.
  5160. if (localClosureReg != Constants::NoRegister)
  5161. {
  5162. this->SetNonVarReg(localClosureReg, &this->localClosure);
  5163. }
  5164. if (localFrameDisplayReg != Constants::NoRegister)
  5165. {
  5166. this->SetNonVarReg(localFrameDisplayReg, &this->localFrameDisplay);
  5167. }
  5168. if (paramClosureReg != Constants::NoRegister)
  5169. {
  5170. this->SetNonVarReg(paramClosureReg, &this->paramClosure);
  5171. }
  5172. }
  5173. else
  5174. {
  5175. // In non-stack-closure jitted code, the closure registers are expected to hold the addresses
  5176. // of the actual structures.
  5177. if (localClosureReg != Constants::NoRegister)
  5178. {
  5179. this->SetNonVarReg(localClosureReg, this->localClosure);
  5180. }
  5181. if (localFrameDisplayReg != Constants::NoRegister)
  5182. {
  5183. this->SetNonVarReg(localFrameDisplayReg, this->localFrameDisplay);
  5184. }
  5185. if (paramClosureReg != Constants::NoRegister)
  5186. {
  5187. this->SetNonVarReg(paramClosureReg, this->paramClosure);
  5188. }
  5189. }
  5190. uint32 innerScopeCount = this->m_functionBody->GetInnerScopeCount();
  5191. for (uint32 i = 0; i < innerScopeCount; i++)
  5192. {
  5193. // As with the function-level scope, transfer the inner scopes from the interpreter's side storage
  5194. // to their dedicated register slots.
  5195. SetNonVarReg(this->m_functionBody->GetFirstInnerScopeRegister() + i, InnerScopeFromIndex(i));
  5196. }
  5197. uint newOffset = 0;
  5198. if (fn->GetIsAsmJsFunction())
  5199. {
  5200. AutoRestoreLoopNumbers autoRestore(this, loopNumber, doProfileLoopCheck);
  5201. newOffset = this->CallAsmJsLoopBody(entryPointInfo->jsMethod);
  5202. }
  5203. else
  5204. {
  5205. AutoRestoreLoopNumbers autoRestore(this, loopNumber, doProfileLoopCheck);
  5206. newOffset = this->CallLoopBody(entryPointInfo->jsMethod);
  5207. }
  5208. if (envReg != Constants::NoRegister)
  5209. {
  5210. SetNonVarReg(envReg, nullptr);
  5211. }
  5212. if (localClosureReg != Constants::NoRegister)
  5213. {
  5214. SetNonVarReg(localClosureReg, nullptr);
  5215. }
  5216. if (localFrameDisplayReg != Constants::NoRegister)
  5217. {
  5218. SetNonVarReg(localFrameDisplayReg, nullptr);
  5219. }
  5220. if (paramClosureReg != Constants::NoRegister)
  5221. {
  5222. SetNonVarReg(paramClosureReg, nullptr);
  5223. }
  5224. for (uint32 i = 0; i < innerScopeCount; i++)
  5225. {
  5226. // Get the (possibly updated) scopes from their registers and put them back in side storage.
  5227. // (Getting the updated values may not be necessary, actually, but it can't hurt.)
  5228. // Then null out the registers.
  5229. RegSlot reg = this->m_functionBody->GetFirstInnerScopeRegister() + i;
  5230. SetInnerScopeFromIndex(i, GetNonVarReg(reg));
  5231. SetNonVarReg(reg, nullptr);
  5232. }
  5233. Assert(Js::OpCodeUtil::GetOpCodeLayout(OpCode::ProfiledLoopBodyStart) == Js::OpLayoutType::Unsigned1);
  5234. Assert(Js::OpCodeUtil::GetOpCodeLayout(OpCode::LoopBodyStart) == Js::OpLayoutType::Unsigned1);
  5235. Assert(Js::OpCodeUtil::EncodedSize(Js::OpCode::LoopBodyStart, layoutSize) == Js::OpCodeUtil::EncodedSize(Js::OpCode::ProfiledLoopBodyStart, layoutSize));
  5236. uint byteCodeSize = Js::OpCodeUtil::EncodedSize(Js::OpCode::LoopBodyStart, layoutSize);
  5237. if (layoutSize == SmallLayout)
  5238. {
  5239. byteCodeSize += sizeof(OpLayoutUnsigned1_Small);
  5240. }
  5241. else if (layoutSize == MediumLayout)
  5242. {
  5243. byteCodeSize += sizeof(OpLayoutUnsigned1_Medium);
  5244. }
  5245. else
  5246. {
  5247. byteCodeSize += sizeof(OpLayoutUnsigned1_Large);
  5248. }
  5249. if (newOffset == loopHeader->startOffset || newOffset == m_reader.GetCurrentOffset() - byteCodeSize)
  5250. {
  5251. // If we bail out back the start of the loop, or start of this LoopBodyStart just skip and interpret the loop
  5252. // instead of trying to start the loop body again
  5253. // Increment the interpret count of the loop
  5254. loopHeader->interpretCount++;
  5255. }
  5256. else
  5257. {
  5258. this->CheckIfLoopIsHot(loopHeader->profiledLoopCounter);
  5259. if (newOffset >= loopHeader->endOffset)
  5260. {
  5261. // Reset the totalJittedLoopIterations for the next invocation of this loop entry point
  5262. entryPointInfo->totalJittedLoopIterations =
  5263. static_cast<uint8>(
  5264. min(
  5265. static_cast<uint>(static_cast<uint8>(CONFIG_FLAG(MinBailOutsBeforeRejit))) *
  5266. (Js::LoopEntryPointInfo::GetDecrLoopCountPerBailout() - 1),
  5267. entryPointInfo->totalJittedLoopIterations));
  5268. entryPointInfo->jittedLoopIterationsSinceLastBailout = 0;
  5269. }
  5270. m_reader.SetCurrentOffset(newOffset);
  5271. }
  5272. return loopHeader;
  5273. }
  5274. #endif
  5275. // Increment the interpret count of the loop
  5276. loopHeader->interpretCount += !isFirstIteration;
  5277. const uint loopInterpretCount = GetFunctionBody()->GetLoopInterpretCount(loopHeader);
  5278. if (loopHeader->interpretCount > loopInterpretCount)
  5279. {
  5280. if (this->scriptContext->GetConfig()->IsNoNative())
  5281. {
  5282. return nullptr;
  5283. }
  5284. if (!fn->DoJITLoopBody())
  5285. {
  5286. return nullptr;
  5287. }
  5288. #if ENABLE_NATIVE_CODEGEN
  5289. #if ENABLE_OOP_NATIVE_CODEGEN
  5290. // If for some reason OOP JIT isn't connected (e.g. it crashed), don't attempt to JIT a loop body
  5291. if (JITManager::GetJITManager()->IsOOPJITEnabled() && !JITManager::GetJITManager()->IsConnected())
  5292. {
  5293. return nullptr;
  5294. }
  5295. #endif
  5296. // If the job is not scheduled then we need to schedule it now.
  5297. // It is possible a job was scheduled earlier and we find ourselves looking at the same entry point
  5298. // again. For example, if the function with the loop was JITed and bailed out then as we finish
  5299. // the call in the interpreter we might encounter a loop for which we had scheduled a JIT job before
  5300. // the function was initially scheduled. In such cases, that old JIT job will complete. If it completes
  5301. // successfully then we can go ahead and use it. If it fails then it will eventually revert to the
  5302. // NotScheduled state. Since transitions from NotScheduled can only occur on the main thread,
  5303. // by checking the state we are safe from racing with the JIT thread when looking at the other fields
  5304. // of the entry point.
  5305. if (entryPointInfo != NULL && entryPointInfo->IsNotScheduled())
  5306. {
  5307. GenerateLoopBody(scriptContext->GetNativeCodeGenerator(), fn, loopHeader, entryPointInfo, fn->GetLocalsCount(), this->m_localSlots);
  5308. }
  5309. #endif
  5310. }
  5311. #if ENABLE_PROFILE_INFO
  5312. else if (
  5313. doProfileLoopCheck &&
  5314. isAutoProfiling &&
  5315. loopHeader->interpretCount > fn->GetLoopProfileThreshold(loopInterpretCount))
  5316. {
  5317. // Start profiling the loop so that the jitted loop body will have some profile data to use
  5318. Assert(!switchProfileMode);
  5319. switchProfileMode = true;
  5320. Assert(switchProfileModeOnLoopEndNumber == 0u - 1);
  5321. switchProfileModeOnLoopEndNumber = loopNumber;
  5322. }
  5323. #endif
  5324. return nullptr;
  5325. }
  5326. void
  5327. InterpreterStackFrame::CheckIfLoopIsHot(uint profiledLoopCounter)
  5328. {
  5329. Js::FunctionBody *fn = this->function->GetFunctionBody();
  5330. if (!fn->GetHasHotLoop() && profiledLoopCounter > (uint)CONFIG_FLAG(JitLoopBodyHotLoopThreshold))
  5331. {
  5332. #ifdef ENABLE_DEBUG_CONFIG_OPTIONS
  5333. if (PHASE_TRACE(Js::JITLoopBodyPhase, fn))
  5334. {
  5335. char16 debugStringBuffer[MAX_FUNCTION_BODY_DEBUG_STRING_SIZE];
  5336. Output::Print(
  5337. _u("Speculate Jit set for this function with loopbody: function: %s (%s)\n"),
  5338. fn->GetDisplayName(),
  5339. fn->GetDebugNumberSet(debugStringBuffer));
  5340. Output::Flush();
  5341. }
  5342. #endif
  5343. fn->SetHasHotLoop();
  5344. }
  5345. }
  5346. bool InterpreterStackFrame::CheckAndResetImplicitCall(DisableImplicitFlags prevDisableImplicitFlags, ImplicitCallFlags savedImplicitCallFlags)
  5347. {
  5348. ImplicitCallFlags curImplicitCallFlags = this->scriptContext->GetThreadContext()->GetImplicitCallFlags();
  5349. if (curImplicitCallFlags > ImplicitCall_None)
  5350. {
  5351. //error implicit bit is set , reparse without asmjs
  5352. this->scriptContext->GetThreadContext()->SetDisableImplicitFlags(prevDisableImplicitFlags);
  5353. this->scriptContext->GetThreadContext()->SetImplicitCallFlags(savedImplicitCallFlags);
  5354. return true;
  5355. }
  5356. return false;
  5357. }
  5358. uint
  5359. InterpreterStackFrame::CallLoopBody(JavascriptMethod address)
  5360. {
  5361. #ifdef _M_IX86
  5362. void *savedEsp = NULL;
  5363. __asm
  5364. {
  5365. // Save ESP
  5366. mov savedEsp, esp
  5367. // 8-byte align frame to improve floating point perf of our JIT'd code.
  5368. and esp, -8
  5369. // Add an extra 4-bytes to the stack since we'll be pushing 3 arguments
  5370. push eax
  5371. }
  5372. #endif
  5373. #if defined(_M_ARM32_OR_ARM64)
  5374. // For ARM we need to make sure that pipeline is synchronized with memory/cache for newly jitted code.
  5375. // Note: this does not seem to affect perf, but if it was, we could add a boolean isCalled to EntryPointInfo
  5376. // and do ISB only for 1st time this entry point is called (potential working set regression though).
  5377. _InstructionSynchronizationBarrier();
  5378. #endif
  5379. uint newOffset = ::Math::PointerCastToIntegral<uint>(
  5380. CALL_ENTRYPOINT_NOASSERT(address, function, CallInfo(CallFlags_InternalFrame, 1), this));
  5381. #ifdef _M_IX86
  5382. _asm
  5383. {
  5384. // Restore ESP
  5385. mov esp, savedEsp
  5386. }
  5387. #endif
  5388. return newOffset;
  5389. }
  5390. uint
  5391. InterpreterStackFrame::CallAsmJsLoopBody(JavascriptMethod address)
  5392. {
  5393. #ifdef _M_IX86
  5394. void *savedEsp = NULL;
  5395. __asm
  5396. {
  5397. // Save ESP
  5398. mov savedEsp, esp
  5399. // Add an extra 4-bytes to the stack since we'll be pushing 3 arguments
  5400. push eax
  5401. }
  5402. #endif
  5403. #if defined(_M_ARM32_OR_ARM64)
  5404. // For ARM we need to make sure that pipeline is synchronized with memory/cache for newly jitted code.
  5405. // Note: this does not seem to affect perf, but if it was, we could add a boolean isCalled to EntryPointInfo
  5406. // and do ISB only for 1st time this entry point is called (potential working set regression though).
  5407. _InstructionSynchronizationBarrier();
  5408. #endif
  5409. uint newOffset = ::Math::PointerCastToIntegral<uint>(
  5410. CALL_ENTRYPOINT_NOASSERT(address, function, CallInfo(CallFlags_InternalFrame, 1), this));
  5411. #ifdef _M_IX86
  5412. _asm
  5413. {
  5414. // Restore ESP
  5415. mov esp, savedEsp
  5416. }
  5417. #endif
  5418. return newOffset;
  5419. }
  5420. template <class T>
  5421. void InterpreterStackFrame::OP_NewScObjectNoCtorFull(const unaligned T* playout)
  5422. {
  5423. Var function = GetReg(playout->R1);
  5424. Var newObj = JavascriptOperators::NewScObjectNoCtorFull(function, GetScriptContext());
  5425. SetReg(playout->R0, newObj);
  5426. }
  5427. ///----------------------------------------------------------------------------
  5428. ///
  5429. /// InterpreterStackFrame::OP_NewScObject
  5430. ///
  5431. /// OP_NewScObject() allocates a new DynamicObject and initializes it with an
  5432. /// optional "constructor" function.
  5433. ///
  5434. /// NOTE: The return register must be carefully chosen to ensure proper
  5435. /// behavior:
  5436. /// 1. OpCode::NewInstance should never specify "R0" as the register to
  5437. /// store the new instance, because it will get whacked from the
  5438. /// "constructor" function's return value:
  5439. ///
  5440. /// var a1 = Date(); <-- a1 = string returned from Date() function
  5441. /// var a2 = new Date(); <-- a2 = instance return from NewInstance.
  5442. /// Date()'s return value is thrown away.
  5443. ///
  5444. /// 2. If an exception is thrown during construction, the destination
  5445. /// variable / field should __not__ be modified. Therefore, the destination
  5446. /// register should always be a temporary and never a valid local variable.
  5447. /// After successfully returning from the constructor function, the new
  5448. /// instance is valid and may be stored in its final destination variable /
  5449. /// field.
  5450. ///
  5451. /// OPCODE NewObject:
  5452. /// T1 = new DynamicObject(Function.Prototype)
  5453. /// OutArg[0] = T1
  5454. /// Call(Function, ArgCount)
  5455. /// Local[Return] = T1
  5456. ///
  5457. /// - R0: Destination "local" register
  5458. /// - R1: Optional constructor JavascriptFunction instance or 'null'
  5459. ///
  5460. ///----------------------------------------------------------------------------
  5461. template <class T, bool Profiled, bool ICIndex>
  5462. void InterpreterStackFrame::OP_NewScObject_Impl(const unaligned T* playout, InlineCacheIndex inlineCacheIndex, const Js::AuxArray<uint32> *spreadIndices)
  5463. {
  5464. if (ICIndex)
  5465. {
  5466. Assert(inlineCacheIndex != Js::Constants::NoInlineCacheIndex);
  5467. }
  5468. Var newVarInstance =
  5469. #if ENABLE_PROFILE_INFO
  5470. Profiled ?
  5471. ProfiledNewScObject_Helper(
  5472. GetReg(playout->Function),
  5473. playout->ArgCount,
  5474. static_cast<const unaligned OpLayoutDynamicProfile<T> *>(playout)->profileId,
  5475. inlineCacheIndex,
  5476. spreadIndices) :
  5477. #endif
  5478. NewScObject_Helper(GetReg(playout->Function), playout->ArgCount, spreadIndices);
  5479. SetReg((RegSlot)playout->Return, newVarInstance);
  5480. }
  5481. template <class T, bool Profiled>
  5482. void InterpreterStackFrame::OP_ProfiledNewScObjArray_Impl(const unaligned T* playout, const Js::AuxArray<uint32> *spreadIndices)
  5483. {
  5484. // Always profile this operation when auto-profiling so that array type changes are tracked
  5485. #if ENABLE_PROFILE_INFO
  5486. if (!Profiled && !isAutoProfiling)
  5487. #else
  5488. Assert(!Profiled);
  5489. #endif
  5490. {
  5491. OP_NewScObjArray_Impl<T, Profiled>(playout, spreadIndices);
  5492. return;
  5493. }
  5494. #if ENABLE_PROFILE_INFO
  5495. Arguments args(CallInfo(CallFlags_New, playout->ArgCount), m_outParams);
  5496. uint32 spreadSize = 0;
  5497. if (spreadIndices != nullptr)
  5498. {
  5499. spreadSize = JavascriptFunction::GetSpreadSize(args, spreadIndices, scriptContext);
  5500. // Allocate room on the stack for the spread args.
  5501. Arguments outArgs(CallInfo(CallFlags_New, 0), nullptr);
  5502. outArgs.Info.Count = spreadSize;
  5503. const unsigned STACK_ARGS_ALLOCA_THRESHOLD = 8; // Number of stack args we allow before using _alloca
  5504. Var stackArgs[STACK_ARGS_ALLOCA_THRESHOLD];
  5505. size_t outArgsSize = 0;
  5506. if (outArgs.Info.Count > STACK_ARGS_ALLOCA_THRESHOLD)
  5507. {
  5508. PROBE_STACK(scriptContext, outArgs.Info.Count * sizeof(Var) + Js::Constants::MinStackDefault); // args + function call
  5509. outArgsSize = outArgs.Info.Count * sizeof(Var);
  5510. outArgs.Values = (Var*)_alloca(outArgsSize);
  5511. ZeroMemory(outArgs.Values, outArgsSize);
  5512. }
  5513. else
  5514. {
  5515. outArgs.Values = stackArgs;
  5516. outArgsSize = STACK_ARGS_ALLOCA_THRESHOLD * sizeof(Var);
  5517. ZeroMemory(outArgs.Values, outArgsSize); // We may not use all of the elements
  5518. }
  5519. JavascriptFunction::SpreadArgs(args, outArgs, spreadIndices, scriptContext);
  5520. SetReg(
  5521. (RegSlot)playout->Return,
  5522. ProfilingHelpers::ProfiledNewScObjArray(
  5523. GetReg(playout->Function),
  5524. outArgs,
  5525. function,
  5526. static_cast<const unaligned OpLayoutDynamicProfile2<T> *>(playout)->profileId,
  5527. static_cast<const unaligned OpLayoutDynamicProfile2<T> *>(playout)->profileId2));
  5528. }
  5529. else
  5530. {
  5531. SetReg(
  5532. (RegSlot)playout->Return,
  5533. ProfilingHelpers::ProfiledNewScObjArray(
  5534. GetReg(playout->Function),
  5535. args,
  5536. function,
  5537. static_cast<const unaligned OpLayoutDynamicProfile2<T> *>(playout)->profileId,
  5538. static_cast<const unaligned OpLayoutDynamicProfile2<T> *>(playout)->profileId2));
  5539. }
  5540. PopOut(playout->ArgCount);
  5541. #endif
  5542. }
  5543. void InterpreterStackFrame::OP_NewScObject_A_Impl(const unaligned OpLayoutAuxiliary * playout, RegSlot *target)
  5544. {
  5545. const Js::VarArrayVarCount * vars = Js::ByteCodeReader::ReadVarArrayVarCount(playout->Offset, this->GetFunctionBody());
  5546. int count = Js::TaggedInt::ToInt32(vars->count);
  5547. // Push the parameters to stack
  5548. for (int i = 0; i < count; i++)
  5549. {
  5550. SetOut((ArgSlot)(i + 1), vars->elements[i]);
  5551. }
  5552. Var newVarInstance = NewScObject_Helper(GetReg((RegSlot)playout->C1), (ArgSlot)count + 1);
  5553. SetReg((RegSlot)playout->R0, newVarInstance);
  5554. }
  5555. Var InterpreterStackFrame::NewScObject_Helper(Var target, ArgSlot ArgCount, const Js::AuxArray<uint32> *spreadIndices)
  5556. {
  5557. Arguments args(CallInfo(CallFlags_New, ArgCount), m_outParams);
  5558. Var newVarInstance = nullptr;
  5559. BEGIN_SAFE_REENTRANT_CALL(this->scriptContext->GetThreadContext())
  5560. {
  5561. newVarInstance = JavascriptOperators::NewScObject(target, args, GetScriptContext(), spreadIndices);
  5562. }
  5563. END_SAFE_REENTRANT_CALL
  5564. PopOut(ArgCount);
  5565. JS_ETW(EventWriteJSCRIPT_RECYCLER_ALLOCATE_OBJECT(newVarInstance));
  5566. #if ENABLE_DEBUG_CONFIG_OPTIONS
  5567. if (Js::Configuration::Global.flags.IsEnabled(Js::autoProxyFlag))
  5568. {
  5569. newVarInstance = JavascriptProxy::AutoProxyWrapper(newVarInstance);
  5570. // this might come from a different scriptcontext.
  5571. newVarInstance = CrossSite::MarshalVar(GetScriptContext(), newVarInstance);
  5572. }
  5573. #endif
  5574. #ifdef ENABLE_BASIC_TELEMETRY
  5575. {
  5576. this->scriptContext->GetTelemetry().GetOpcodeTelemetry().NewScriptObject(target, args, newVarInstance);
  5577. }
  5578. #endif
  5579. return newVarInstance;
  5580. }
  5581. #if ENABLE_PROFILE_INFO
  5582. Var InterpreterStackFrame::ProfiledNewScObject_Helper(Var target, ArgSlot ArgCount, ProfileId profileId, InlineCacheIndex inlineCacheIndex, const Js::AuxArray<uint32> *spreadIndices)
  5583. {
  5584. Arguments args(CallInfo(CallFlags_New, ArgCount), m_outParams);
  5585. Var newVarInstance = nullptr;
  5586. BEGIN_SAFE_REENTRANT_CALL(this->scriptContext->GetThreadContext())
  5587. {
  5588. newVarInstance = ProfilingHelpers::ProfiledNewScObject(
  5589. target,
  5590. args,
  5591. GetFunctionBody(),
  5592. profileId,
  5593. inlineCacheIndex,
  5594. spreadIndices);
  5595. }
  5596. END_SAFE_REENTRANT_CALL
  5597. PopOut(ArgCount);
  5598. JS_ETW(EventWriteJSCRIPT_RECYCLER_ALLOCATE_OBJECT(newVarInstance));
  5599. #if ENABLE_DEBUG_CONFIG_OPTIONS
  5600. if (Js::Configuration::Global.flags.IsEnabled(Js::autoProxyFlag))
  5601. {
  5602. newVarInstance = JavascriptProxy::AutoProxyWrapper(newVarInstance);
  5603. // this might come from a different scriptcontext.
  5604. newVarInstance = CrossSite::MarshalVar(GetScriptContext(), newVarInstance);
  5605. }
  5606. #endif
  5607. #ifdef TELEMETRY_PROFILED
  5608. {
  5609. this->scriptContext->GetTelemetry().GetOpcodeTelemetry().NewScriptObject(target, args, newVarInstance);
  5610. }
  5611. #endif
  5612. return newVarInstance;
  5613. }
  5614. #endif
  5615. template <typename T>
  5616. void InterpreterStackFrame::OP_LdElementUndefined(const unaligned OpLayoutT_ElementU<T>* playout)
  5617. {
  5618. if (this->m_functionBody->IsEval())
  5619. {
  5620. JavascriptOperators::OP_LoadUndefinedToElementDynamic(GetReg(playout->Instance),
  5621. this->m_functionBody->GetReferencedPropertyId(playout->PropertyIdIndex), GetScriptContext());
  5622. }
  5623. else
  5624. {
  5625. JavascriptOperators::OP_LoadUndefinedToElement(GetReg(playout->Instance),
  5626. this->m_functionBody->GetReferencedPropertyId(playout->PropertyIdIndex));
  5627. }
  5628. }
  5629. template <typename T>
  5630. void InterpreterStackFrame::OP_LdLocalElementUndefined(const unaligned OpLayoutT_ElementRootU<T>* playout)
  5631. {
  5632. if (this->m_functionBody->IsEval())
  5633. {
  5634. JavascriptOperators::OP_LoadUndefinedToElementDynamic(this->localClosure,
  5635. this->m_functionBody->GetReferencedPropertyId(playout->PropertyIdIndex), GetScriptContext());
  5636. }
  5637. else
  5638. {
  5639. JavascriptOperators::OP_LoadUndefinedToElement(this->localClosure,
  5640. this->m_functionBody->GetReferencedPropertyId(playout->PropertyIdIndex));
  5641. }
  5642. }
  5643. template <typename T>
  5644. void InterpreterStackFrame::OP_LdElementUndefinedScoped(const unaligned OpLayoutT_ElementScopedU<T>* playout)
  5645. {
  5646. // Implicit root object as default instance
  5647. JavascriptOperators::OP_LoadUndefinedToElementScoped(GetEnvForEvalCode(),
  5648. this->m_functionBody->GetReferencedPropertyId(playout->PropertyIdIndex), GetReg(Js::FunctionBody::RootObjectRegSlot), GetScriptContext());
  5649. }
  5650. void InterpreterStackFrame::OP_ChkUndecl(Var aValue)
  5651. {
  5652. if (this->scriptContext->IsUndeclBlockVar(aValue))
  5653. {
  5654. JavascriptError::ThrowReferenceError(scriptContext, JSERR_UseBeforeDeclaration);
  5655. }
  5656. }
  5657. void InterpreterStackFrame::OP_ChkNewCallFlag()
  5658. {
  5659. if (!(this->m_callFlags & CallFlags_New) && !this->TestFlags(InterpreterStackFrameFlags_FromBailOutInInlinee))
  5660. {
  5661. JavascriptError::ThrowTypeError(scriptContext, JSERR_ClassConstructorCannotBeCalledWithoutNew);
  5662. }
  5663. }
  5664. void InterpreterStackFrame::OP_EnsureNoRootProperty(uint propertyIdIndex)
  5665. {
  5666. Var instance = this->GetRootObject();
  5667. JavascriptOperators::OP_EnsureNoRootProperty(instance, this->m_functionBody->GetReferencedPropertyId(propertyIdIndex));
  5668. }
  5669. void InterpreterStackFrame::OP_EnsureNoRootRedeclProperty(uint propertyIdIndex)
  5670. {
  5671. Var instance = this->GetRootObject();
  5672. JavascriptOperators::OP_EnsureNoRootRedeclProperty(instance, this->m_functionBody->GetReferencedPropertyId(propertyIdIndex));
  5673. }
  5674. void InterpreterStackFrame::OP_ScopedEnsureNoRedeclProperty(Var aValue, uint propertyIdIndex, Var aValue2)
  5675. {
  5676. Js::PropertyId propertyId = this->m_functionBody->GetReferencedPropertyId(propertyIdIndex);
  5677. JavascriptOperators::OP_ScopedEnsureNoRedeclProperty((FrameDisplay*)aValue, propertyId, aValue2);
  5678. }
  5679. Var InterpreterStackFrame::OP_InitUndecl()
  5680. {
  5681. return this->scriptContext->GetLibrary()->GetUndeclBlockVar();
  5682. }
  5683. void InterpreterStackFrame::OP_InitUndeclSlot(Var aValue, int32 slot)
  5684. {
  5685. this->OP_StSlot(aValue, slot, this->scriptContext->GetLibrary()->GetUndeclBlockVar());
  5686. }
  5687. void InterpreterStackFrame::OP_TryCatch(const unaligned OpLayoutBr* playout)
  5688. {
  5689. Js::JavascriptExceptionObject* exception = NULL;
  5690. try
  5691. {
  5692. this->nestedTryDepth++;
  5693. // mark the stackFrame as 'in try block'
  5694. this->OrFlags(InterpreterStackFrameFlags_WithinTryBlock);
  5695. Js::JavascriptExceptionOperators::AutoCatchHandlerExists autoCatchHandlerExists(scriptContext);
  5696. void * addrOfReturnAddr = _AddressOfReturnAddress();
  5697. Js::JavascriptExceptionOperators::TryHandlerAddrOfReturnAddrStack tryHandlerAddrOfReturnAddrStack(scriptContext, addrOfReturnAddr);
  5698. #ifdef ENABLE_SCRIPT_DEBUGGING
  5699. if (this->IsInDebugMode())
  5700. {
  5701. #if ENABLE_TTD
  5702. if (SHOULD_DO_TTD_STACK_STMT_OP(this->scriptContext))
  5703. {
  5704. this->ProcessWithDebugging_PreviousStmtTracking();
  5705. }
  5706. else
  5707. {
  5708. this->ProcessWithDebugging();
  5709. }
  5710. #else
  5711. this->ProcessWithDebugging();
  5712. #endif
  5713. this->TrySetRetOffset();
  5714. }
  5715. else
  5716. #endif
  5717. {
  5718. this->Process();
  5719. this->TrySetRetOffset();
  5720. }
  5721. }
  5722. catch (const Js::JavascriptException& err)
  5723. {
  5724. // We are using C++ exception handling which does not unwind the stack in the catch block.
  5725. // For stack overflow and OOM exceptions, we cannot run user code here because the stack is not unwind.
  5726. exception = err.GetAndClear();
  5727. }
  5728. if (--this->nestedTryDepth == -1)
  5729. {
  5730. // unmark the stackFrame as 'in try block'
  5731. this->ClearFlags(InterpreterStackFrameFlags_WithinTryBlock);
  5732. }
  5733. // Now that the stack is unwound, let's run the catch block.
  5734. if (exception)
  5735. {
  5736. if (exception->IsGeneratorReturnException())
  5737. {
  5738. // Generator return scenario, so no need to go into the catch block and we must rethrow to propagate the exception to down level
  5739. JavascriptExceptionOperators::DoThrow(exception, scriptContext);
  5740. }
  5741. exception = exception->CloneIfStaticExceptionObject(scriptContext);
  5742. // We've got a JS exception. Grab the exception object and assign it to the
  5743. // catch object's location, then call the handler (i.e., we consume the Catch op here).
  5744. Var catchObject = exception->GetThrownObject(scriptContext);
  5745. m_reader.SetCurrentRelativeOffset((const byte *)(playout + 1), playout->RelativeJumpOffset);
  5746. LayoutSize layoutSize;
  5747. OpCode catchOp = m_reader.ReadOp(layoutSize);
  5748. #ifdef BYTECODE_BRANCH_ISLAND
  5749. if (catchOp == Js::OpCode::BrLong)
  5750. {
  5751. Assert(layoutSize == SmallLayout);
  5752. auto playoutBrLong = m_reader.BrLong();
  5753. m_reader.SetCurrentRelativeOffset((const byte *)(playoutBrLong + 1), playoutBrLong->RelativeJumpOffset);
  5754. catchOp = m_reader.ReadOp(layoutSize);
  5755. }
  5756. #endif
  5757. AssertMsg(catchOp == OpCode::Catch, "Catch op not found at catch offset");
  5758. RegSlot reg = layoutSize == SmallLayout ? m_reader.Reg1_Small()->R0 :
  5759. layoutSize == MediumLayout ? m_reader.Reg1_Medium()->R0 : m_reader.Reg1_Large()->R0;
  5760. SetReg(reg, catchObject);
  5761. ResetOut();
  5762. this->nestedCatchDepth++;
  5763. // mark the stackFrame as 'in catch block'
  5764. this->OrFlags(InterpreterStackFrameFlags_WithinCatchBlock);
  5765. this->ProcessCatch();
  5766. if (--this->nestedCatchDepth == -1)
  5767. {
  5768. // unmark the stackFrame as 'in catch block'
  5769. this->ClearFlags(InterpreterStackFrameFlags_WithinCatchBlock);
  5770. }
  5771. }
  5772. }
  5773. void InterpreterStackFrame::ProcessCatch()
  5774. {
  5775. #if ENABLE_TTD
  5776. //Clear any previous Exception Info
  5777. if (SHOULD_DO_TTD_STACK_STMT_OP(this->scriptContext))
  5778. {
  5779. this->scriptContext->GetThreadContext()->TTDExecutionInfo->ProcessCatchInfoForLastExecutedStatements();
  5780. }
  5781. #endif
  5782. #ifdef ENABLE_SCRIPT_DEBUGGING
  5783. if (this->IsInDebugMode())
  5784. {
  5785. this->DebugProcess();
  5786. }
  5787. else
  5788. #endif
  5789. {
  5790. this->Process();
  5791. }
  5792. }
  5793. int InterpreterStackFrame::ProcessFinally()
  5794. {
  5795. this->nestedFinallyDepth++;
  5796. int newOffset = 0;
  5797. #ifdef ENABLE_SCRIPT_DEBUGGING
  5798. if (this->IsInDebugMode())
  5799. {
  5800. newOffset = ::Math::PointerCastToIntegral<int>(this->DebugProcess());
  5801. }
  5802. else
  5803. #endif
  5804. {
  5805. newOffset = ::Math::PointerCastToIntegral<int>(this->Process());
  5806. }
  5807. return newOffset;
  5808. }
  5809. void InterpreterStackFrame::ProcessTryHandlerBailout(EHBailoutData * ehBailoutData, uint32 tryNestingDepth)
  5810. {
  5811. int catchOffset = ehBailoutData->catchOffset;
  5812. int finallyOffset = ehBailoutData->finallyOffset;
  5813. Js::JavascriptExceptionObject* exception = NULL;
  5814. if (catchOffset != 0 || finallyOffset != 0)
  5815. {
  5816. try
  5817. {
  5818. this->nestedTryDepth++;
  5819. // mark the stackFrame as 'in try block'
  5820. this->OrFlags(InterpreterStackFrameFlags_WithinTryBlock);
  5821. if (finallyOffset != 0)
  5822. {
  5823. this->OrFlags(InterpreterStackFrameFlags_WithinTryFinallyBlock);
  5824. }
  5825. if (tryNestingDepth != 0)
  5826. {
  5827. this->ProcessTryHandlerBailout(ehBailoutData->child, --tryNestingDepth);
  5828. }
  5829. if (catchOffset != 0)
  5830. {
  5831. Js::JavascriptExceptionOperators::AutoCatchHandlerExists autoCatchHandlerExists(scriptContext);
  5832. }
  5833. #ifdef ENABLE_SCRIPT_DEBUGGING
  5834. if (this->IsInDebugMode())
  5835. {
  5836. #if ENABLE_TTD
  5837. if (SHOULD_DO_TTD_STACK_STMT_OP(this->scriptContext))
  5838. {
  5839. this->ProcessWithDebugging_PreviousStmtTracking();
  5840. }
  5841. else
  5842. {
  5843. this->ProcessWithDebugging();
  5844. }
  5845. #else
  5846. this->ProcessWithDebugging();
  5847. #endif
  5848. this->TrySetRetOffset();
  5849. }
  5850. else
  5851. #endif
  5852. {
  5853. this->Process();
  5854. this->TrySetRetOffset();
  5855. }
  5856. }
  5857. catch (const Js::JavascriptException& err)
  5858. {
  5859. // We are using C++ exception handling which does not unwind the stack in the catch block.
  5860. // For stack overflow and OOM exceptions, we cannot run user code here because the stack is not unwind.
  5861. exception = err.GetAndClear();
  5862. }
  5863. }
  5864. else if (ehBailoutData->ht == HandlerType::HT_Catch)
  5865. {
  5866. this->nestedCatchDepth++;
  5867. // mark the stackFrame as 'in catch block'
  5868. this->OrFlags(InterpreterStackFrameFlags_WithinCatchBlock);
  5869. if (tryNestingDepth != 0)
  5870. {
  5871. this->ProcessTryHandlerBailout(ehBailoutData->child, --tryNestingDepth);
  5872. }
  5873. this->ProcessCatch();
  5874. if (--this->nestedCatchDepth == -1)
  5875. {
  5876. // unmark the stackFrame as 'in catch block'
  5877. this->ClearFlags(InterpreterStackFrameFlags_WithinCatchBlock);
  5878. }
  5879. return;
  5880. }
  5881. else
  5882. {
  5883. Assert(ehBailoutData->ht == HandlerType::HT_Finally);
  5884. this->nestedFinallyDepth++;
  5885. // mark the stackFrame as 'in finally block'
  5886. this->OrFlags(InterpreterStackFrameFlags_WithinFinallyBlock);
  5887. if (tryNestingDepth != 0)
  5888. {
  5889. this->ProcessTryHandlerBailout(ehBailoutData->child, --tryNestingDepth);
  5890. }
  5891. Js::JavascriptExceptionObject * exceptionObj = this->scriptContext->GetThreadContext()->GetPendingFinallyException();
  5892. this->scriptContext->GetThreadContext()->SetPendingFinallyException(nullptr);
  5893. int finallyEndOffset = this->ProcessFinally();
  5894. if (--this->nestedFinallyDepth == -1)
  5895. {
  5896. // unmark the stackFrame as 'in finally block'
  5897. this->ClearFlags(InterpreterStackFrameFlags_WithinFinallyBlock);
  5898. }
  5899. // Finally exited with LeaveNull, We don't throw for early returns
  5900. if (finallyEndOffset == 0 && exceptionObj)
  5901. {
  5902. #if ENABLE_NATIVE_CODEGEN
  5903. if (scriptContext->GetThreadContext()->GetTryHandlerAddrOfReturnAddr() != nullptr)
  5904. {
  5905. JavascriptExceptionOperators::WalkStackForCleaningUpInlineeInfo(scriptContext, nullptr, scriptContext->GetThreadContext()->GetTryHandlerAddrOfReturnAddr());
  5906. }
  5907. #endif
  5908. JavascriptExceptionOperators::DoThrow(const_cast<Js::JavascriptExceptionObject *>(exceptionObj), scriptContext);
  5909. }
  5910. if (finallyEndOffset != 0)
  5911. {
  5912. m_reader.SetCurrentOffset(finallyEndOffset);
  5913. }
  5914. return;
  5915. }
  5916. if (--this->nestedTryDepth == -1)
  5917. {
  5918. // unmark the stackFrame as 'in try block'
  5919. this->ClearFlags(InterpreterStackFrameFlags_WithinTryBlock | InterpreterStackFrameFlags_WithinTryFinallyBlock);
  5920. }
  5921. // Now that the stack is unwound, let's run the catch block.
  5922. if (exception)
  5923. {
  5924. if (exception->IsGeneratorReturnException())
  5925. {
  5926. // Generator return scenario, so no need to go into the catch block and we must rethrow to propagate the exception to down level
  5927. JavascriptExceptionOperators::DoThrow(exception, scriptContext);
  5928. }
  5929. if (catchOffset != 0)
  5930. {
  5931. exception = exception->CloneIfStaticExceptionObject(scriptContext);
  5932. // We've got a JS exception. Grab the exception object and assign it to the
  5933. // catch object's location, then call the handler (i.e., we consume the Catch op here).
  5934. Var catchObject = exception->GetThrownObject(scriptContext);
  5935. m_reader.SetCurrentOffset(catchOffset);
  5936. LayoutSize layoutSize;
  5937. OpCode catchOp = m_reader.ReadOp(layoutSize);
  5938. #ifdef BYTECODE_BRANCH_ISLAND
  5939. if (catchOp == Js::OpCode::BrLong)
  5940. {
  5941. Assert(layoutSize == SmallLayout);
  5942. auto playoutBrLong = m_reader.BrLong();
  5943. m_reader.SetCurrentRelativeOffset((const byte *)(playoutBrLong + 1), playoutBrLong->RelativeJumpOffset);
  5944. catchOp = m_reader.ReadOp(layoutSize);
  5945. }
  5946. #endif
  5947. AssertMsg(catchOp == OpCode::Catch, "Catch op not found at catch offset");
  5948. RegSlot reg = layoutSize == SmallLayout ? m_reader.Reg1_Small()->R0 :
  5949. layoutSize == MediumLayout ? m_reader.Reg1_Medium()->R0 : m_reader.Reg1_Large()->R0;
  5950. SetReg(reg, catchObject);
  5951. ResetOut();
  5952. this->nestedCatchDepth++;
  5953. // mark the stackFrame as 'in catch block'
  5954. this->OrFlags(InterpreterStackFrameFlags_WithinCatchBlock);
  5955. this->ProcessCatch();
  5956. if (--this->nestedCatchDepth == -1)
  5957. {
  5958. // unmark the stackFrame as 'in catch block'
  5959. this->ClearFlags(InterpreterStackFrameFlags_WithinCatchBlock);
  5960. }
  5961. }
  5962. else
  5963. {
  5964. Assert(finallyOffset != 0);
  5965. exception = exception->CloneIfStaticExceptionObject(scriptContext);
  5966. m_reader.SetCurrentOffset(finallyOffset);
  5967. ResetOut();
  5968. this->nestedFinallyDepth++;
  5969. // mark the stackFrame as 'in finally block'
  5970. this->OrFlags(InterpreterStackFrameFlags_WithinFinallyBlock);
  5971. LayoutSize layoutSize;
  5972. OpCode finallyOp = m_reader.ReadOp(layoutSize);
  5973. #ifdef BYTECODE_BRANCH_ISLAND
  5974. if (finallyOp == Js::OpCode::BrLong)
  5975. {
  5976. Assert(layoutSize == SmallLayout);
  5977. auto playoutBrLong = m_reader.BrLong();
  5978. m_reader.SetCurrentRelativeOffset((const byte *)(playoutBrLong + 1), playoutBrLong->RelativeJumpOffset);
  5979. finallyOp = m_reader.ReadOp(layoutSize);
  5980. }
  5981. #endif
  5982. Assert(finallyOp == Js::OpCode::Finally);
  5983. int finallyEndOffset = this->ProcessFinally();
  5984. if (--this->nestedFinallyDepth == -1)
  5985. {
  5986. // unmark the stackFrame as 'in finally block'
  5987. this->ClearFlags(InterpreterStackFrameFlags_WithinFinallyBlock);
  5988. }
  5989. if (finallyEndOffset == 0)
  5990. {
  5991. JavascriptExceptionOperators::DoThrow(exception, scriptContext);
  5992. }
  5993. m_reader.SetCurrentOffset(finallyEndOffset);
  5994. }
  5995. }
  5996. else
  5997. {
  5998. if (finallyOffset != 0)
  5999. {
  6000. int currOffset = m_reader.GetCurrentOffset();
  6001. m_reader.SetCurrentOffset(finallyOffset);
  6002. this->nestedFinallyDepth++;
  6003. // mark the stackFrame as 'in finally block'
  6004. this->OrFlags(InterpreterStackFrameFlags_WithinFinallyBlock);
  6005. LayoutSize layoutSize;
  6006. OpCode finallyOp = m_reader.ReadOp(layoutSize);
  6007. #ifdef BYTECODE_BRANCH_ISLAND
  6008. if (finallyOp == Js::OpCode::BrLong)
  6009. {
  6010. Assert(layoutSize == SmallLayout);
  6011. auto playoutBrLong = m_reader.BrLong();
  6012. m_reader.SetCurrentRelativeOffset((const byte *)(playoutBrLong + 1), playoutBrLong->RelativeJumpOffset);
  6013. finallyOp = m_reader.ReadOp(layoutSize);
  6014. }
  6015. #endif
  6016. Assert(finallyOp == Js::OpCode::Finally);
  6017. int finallyEndOffset = this->ProcessFinally();
  6018. if (--this->nestedFinallyDepth == -1)
  6019. {
  6020. // unmark the stackFrame as 'in finally block'
  6021. this->ClearFlags(InterpreterStackFrameFlags_WithinFinallyBlock);
  6022. }
  6023. if (finallyEndOffset == 0)
  6024. {
  6025. m_reader.SetCurrentOffset(currOffset);
  6026. }
  6027. }
  6028. }
  6029. }
  6030. void InterpreterStackFrame::TrySetRetOffset()
  6031. {
  6032. Assert(this->TestFlags(Js::InterpreterStackFrameFlags_WithinTryBlock));
  6033. // It may happen that a JITted loop body returned the offset of RET. If the loop body was
  6034. // called from a try, the interpreter "Process()" should also just return.
  6035. if (this->retOffset != 0)
  6036. {
  6037. m_reader.SetCurrentOffset(this->retOffset);
  6038. }
  6039. }
  6040. bool InterpreterStackFrame::IsInCatchOrFinallyBlock()
  6041. {
  6042. return this->TestFlags(Js::InterpreterStackFrameFlags_WithinCatchBlock) ||
  6043. this->TestFlags(Js::InterpreterStackFrameFlags_WithinFinallyBlock);
  6044. }
  6045. void InterpreterStackFrame::OP_BeginBodyScope()
  6046. {
  6047. // Currently we are using the closures created for the param scope.
  6048. // This marks the beginning of the body scope, so let's create new closures for the body scope.
  6049. FunctionBody *executeFunction = this->function->GetFunctionBody();
  6050. Assert(!this->IsParamScopeDone() && !executeFunction->IsParamAndBodyScopeMerged());
  6051. // Save the current closure. We have to use this while copying the initial value of body symbols
  6052. // from the corresponding symbols in the param.
  6053. this->SetParamClosure(this->GetLocalClosure());
  6054. this->SetNonVarReg(executeFunction->GetParamClosureRegister(), nullptr);
  6055. this->SetIsParamScopeDone(true);
  6056. // Create a new local closure for the body when either body scope has scope slots allocated or
  6057. // eval is present which can leak declarations.
  6058. if (executeFunction->scopeSlotArraySize > 0 || executeFunction->HasScopeObject())
  6059. {
  6060. this->InitializeClosures();
  6061. }
  6062. }
  6063. void InterpreterStackFrame::OP_ResumeCatch()
  6064. {
  6065. this->OrFlags(InterpreterStackFrameFlags_WithinCatchBlock);
  6066. #ifdef ENABLE_SCRIPT_DEBUGGING
  6067. if (this->IsInDebugMode())
  6068. {
  6069. this->DebugProcess();
  6070. }
  6071. else
  6072. #endif
  6073. {
  6074. this->Process();
  6075. }
  6076. this->ClearFlags(InterpreterStackFrameFlags_WithinCatchBlock);
  6077. }
  6078. /// ---------------------------------------------------------------------------------------------------
  6079. /// The behavior we want is the following:
  6080. /// - If the control leaves the user's try without throwing, execute the finally and continue
  6081. /// after the end of the try.
  6082. /// - If the user code throws, catch this exception and then execute this finally while unwinding to
  6083. /// the handler (if any).
  6084. /// ---------------------------------------------------------------------------------------------------
  6085. void InterpreterStackFrame::ProcessTryFinally(const byte* ip, Js::JumpOffset jumpOffset, Js::RegSlot regException, Js::RegSlot regOffset, bool hasYield)
  6086. {
  6087. Js::JavascriptExceptionObject* pExceptionObject = nullptr;
  6088. bool skipFinallyBlock = false;
  6089. try
  6090. {
  6091. Js::Var result = nullptr;
  6092. this->nestedTryDepth++;
  6093. // mark the stackFrame as 'in try block'
  6094. this->OrFlags(InterpreterStackFrameFlags_WithinTryBlock | InterpreterStackFrameFlags_WithinTryFinallyBlock);
  6095. if (shouldCacheSP)
  6096. {
  6097. CacheSp();
  6098. }
  6099. #ifdef ENABLE_SCRIPT_DEBUGGING
  6100. if (this->IsInDebugMode())
  6101. {
  6102. #if ENABLE_TTD
  6103. if (SHOULD_DO_TTD_STACK_STMT_OP(this->scriptContext))
  6104. {
  6105. result = this->ProcessWithDebugging_PreviousStmtTracking();
  6106. }
  6107. else
  6108. {
  6109. result = this->ProcessWithDebugging();
  6110. }
  6111. #else
  6112. result = this->ProcessWithDebugging();
  6113. #endif
  6114. }
  6115. else
  6116. #endif
  6117. {
  6118. result = this->Process();
  6119. }
  6120. if (result == nullptr)
  6121. {
  6122. Assert(hasYield);
  6123. skipFinallyBlock = true;
  6124. }
  6125. }
  6126. catch (const Js::JavascriptException& err)
  6127. {
  6128. pExceptionObject = err.GetAndClear();
  6129. }
  6130. if (--this->nestedTryDepth == -1)
  6131. {
  6132. // unmark the stackFrame as 'in try block'
  6133. this->ClearFlags(InterpreterStackFrameFlags_WithinTryBlock | InterpreterStackFrameFlags_WithinTryFinallyBlock);
  6134. }
  6135. shouldCacheSP = !skipFinallyBlock;
  6136. if (skipFinallyBlock)
  6137. {
  6138. // A leave occurred due to a yield
  6139. return;
  6140. }
  6141. // Save the current IP so execution can continue there if the finally doesn't
  6142. // take control of the flow.
  6143. int newOffset = 0;
  6144. int currOffset = m_reader.GetCurrentOffset();
  6145. if (hasYield)
  6146. {
  6147. // save the exception if there is one to a register in case we yield during the finally block
  6148. // and need to get that exception object back upon resume in OP_ResumeFinally
  6149. SetNonVarReg(regException, pExceptionObject);
  6150. SetNonVarReg(regOffset, reinterpret_cast<Js::Var>(currOffset));
  6151. }
  6152. if (pExceptionObject && !pExceptionObject->IsGeneratorReturnException())
  6153. {
  6154. // Clone static exception object early in case finally block overwrites it
  6155. pExceptionObject = pExceptionObject->CloneIfStaticExceptionObject(scriptContext);
  6156. }
  6157. #ifdef ENABLE_SCRIPT_DEBUGGING
  6158. if (pExceptionObject && this->IsInDebugMode() &&
  6159. pExceptionObject != scriptContext->GetThreadContext()->GetPendingSOErrorObject())
  6160. {
  6161. // Swallowing an exception that has triggered a finally is not implemented
  6162. // (This appears to be the same behavior as ie8)
  6163. pExceptionObject->SetDebuggerSkip(false);
  6164. }
  6165. #endif
  6166. // Call into the finally by setting the IP, consuming the Finally, and letting the interpreter recurse.
  6167. m_reader.SetCurrentRelativeOffset(ip, jumpOffset);
  6168. RestoreSp();
  6169. // mark the stackFrame as 'in finally block'
  6170. this->OrFlags(InterpreterStackFrameFlags_WithinFinallyBlock);
  6171. LayoutSize layoutSize;
  6172. OpCode finallyOp = m_reader.ReadOp(layoutSize);
  6173. #ifdef BYTECODE_BRANCH_ISLAND
  6174. if (finallyOp == Js::OpCode::BrLong)
  6175. {
  6176. Assert(layoutSize == SmallLayout);
  6177. auto playoutBrLong = m_reader.BrLong();
  6178. m_reader.SetCurrentRelativeOffset((const byte *)(playoutBrLong + 1), playoutBrLong->RelativeJumpOffset);
  6179. finallyOp = m_reader.ReadOp(layoutSize);
  6180. }
  6181. #endif
  6182. AssertMsg(finallyOp == OpCode::Finally, "Finally op not found at catch offset");
  6183. newOffset = this->ProcessFinally();
  6184. if (--this->nestedFinallyDepth == -1)
  6185. {
  6186. // unmark the stackFrame as 'in finally block'
  6187. this->ClearFlags(InterpreterStackFrameFlags_WithinFinallyBlock);
  6188. }
  6189. bool endOfFinallyBlock = newOffset == 0;
  6190. if (endOfFinallyBlock)
  6191. {
  6192. // Finally completed without taking over the flow. Resume where we left off before calling it.
  6193. m_reader.SetCurrentOffset(currOffset);
  6194. }
  6195. else
  6196. {
  6197. // Finally seized the flow with a jump out of its scope. Resume at the jump target and
  6198. // force the runtime to return to this frame without executing the catch.
  6199. m_reader.SetCurrentOffset(newOffset);
  6200. return;
  6201. }
  6202. if (pExceptionObject && (endOfFinallyBlock || !pExceptionObject->IsGeneratorReturnException()))
  6203. {
  6204. JavascriptExceptionOperators::DoThrow(pExceptionObject, scriptContext);
  6205. }
  6206. }
  6207. void InterpreterStackFrame::OP_TryFinally(const unaligned OpLayoutBr* playout)
  6208. {
  6209. ProcessTryFinally((const byte*)(playout + 1), playout->RelativeJumpOffset);
  6210. }
  6211. void InterpreterStackFrame::OP_TryFinallyWithYield(const byte* ip, Js::JumpOffset jumpOffset, Js::RegSlot regException, Js::RegSlot regOffset)
  6212. {
  6213. ProcessTryFinally(ip, jumpOffset, regException, regOffset, true);
  6214. }
  6215. void InterpreterStackFrame::OP_ResumeFinally(const byte* ip, Js::JumpOffset jumpOffset, RegSlot exceptionRegSlot, RegSlot offsetRegSlot)
  6216. {
  6217. this->OrFlags(InterpreterStackFrameFlags_WithinFinallyBlock);
  6218. int newOffset = 0;
  6219. #ifdef ENABLE_SCRIPT_DEBUGGING
  6220. if (this->IsInDebugMode())
  6221. {
  6222. newOffset = ::Math::PointerCastToIntegral<int>(this->DebugProcess());
  6223. }
  6224. else
  6225. #endif
  6226. {
  6227. newOffset = ::Math::PointerCastToIntegral<int>(this->Process());
  6228. }
  6229. this->ClearFlags(InterpreterStackFrameFlags_WithinFinallyBlock);
  6230. bool endOfFinallyBlock = newOffset == 0;
  6231. if (endOfFinallyBlock)
  6232. {
  6233. // Finally completed without taking over the flow. Resume where we left off before calling it.
  6234. int currOffset = ::Math::PointerCastToIntegral<int>(GetNonVarReg(offsetRegSlot));
  6235. m_reader.SetCurrentOffset(currOffset);
  6236. }
  6237. else
  6238. {
  6239. // Finally seized the flow with a jump out of its scope. Resume at the jump target and
  6240. // force the runtime to return to this frame without executing the catch.
  6241. m_reader.SetCurrentOffset(newOffset);
  6242. return;
  6243. }
  6244. Js::JavascriptExceptionObject* exceptionObj = (Js::JavascriptExceptionObject*)GetNonVarReg(exceptionRegSlot);
  6245. if (exceptionObj && (endOfFinallyBlock || !exceptionObj->IsGeneratorReturnException()))
  6246. {
  6247. JavascriptExceptionOperators::DoThrow(exceptionObj, scriptContext);
  6248. }
  6249. }
  6250. template <typename T>
  6251. void InterpreterStackFrame::OP_IsInst(const unaligned T* playout)
  6252. {
  6253. Var instance = GetReg(playout->R1);
  6254. Var function = GetReg(playout->R2);
  6255. IsInstInlineCache *inlineCache = this->GetIsInstInlineCache(playout->inlineCacheIndex);
  6256. ScriptContext* scriptContext = GetScriptContext();
  6257. Var result = JavascriptOperators::OP_IsInst(instance, function, scriptContext, inlineCache);
  6258. #ifdef ENABLE_BASIC_TELEMETRY
  6259. {
  6260. this->scriptContext->GetTelemetry().GetOpcodeTelemetry().IsInstanceOf(instance, function, result);
  6261. }
  6262. #endif
  6263. SetReg(playout->R0, result);
  6264. }
  6265. template <typename T>
  6266. void InterpreterStackFrame::OP_ApplyArgs(const unaligned OpLayoutT_Reg5<T> * playout)
  6267. {
  6268. // Always save and restore implicit call flags when calling out
  6269. // REVIEW: Can we avoid it if we don't collect dynamic profile info?
  6270. ThreadContext * threadContext = scriptContext->GetThreadContext();
  6271. Js::ImplicitCallFlags savedImplicitCallFlags = threadContext->GetImplicitCallFlags();
  6272. // Currently ApplyArgs is equivalent to CallFldVoid (where we don't use the return value)
  6273. Var v = GetNonVarReg(playout->R4);
  6274. JavascriptOperators::OP_ApplyArgs(GetReg(playout->R1), GetReg(playout->R2),
  6275. (void**)GetNonVarReg(playout->R3), *((CallInfo*)&v), GetScriptContext());
  6276. threadContext->SetImplicitCallFlags(savedImplicitCallFlags);
  6277. }
  6278. void InterpreterStackFrame::OP_SpreadArrayLiteral(const unaligned OpLayoutReg2Aux * playout)
  6279. {
  6280. ThreadContext* threadContext = this->GetScriptContext()->GetThreadContext();
  6281. ImplicitCallFlags savedImplicitCallFlags = threadContext->GetImplicitCallFlags();
  6282. threadContext->ClearImplicitCallFlags();
  6283. Var instance = GetReg(playout->R1);
  6284. #if ENABLE_COPYONACCESS_ARRAY
  6285. JavascriptLibrary::CheckAndConvertCopyOnAccessNativeIntArray<Var>(instance);
  6286. #endif
  6287. const Js::AuxArray<uint32> *spreadIndices = m_reader.ReadAuxArray<uint32>(playout->Offset, this->GetFunctionBody());
  6288. ScriptContext* scriptContext = GetScriptContext();
  6289. Var result = JavascriptArray::SpreadArrayArgs(instance, spreadIndices, scriptContext);
  6290. threadContext->CheckAndResetImplicitCallAccessorFlag();
  6291. threadContext->AddImplicitCallFlags(savedImplicitCallFlags);
  6292. SetReg(playout->R0, result);
  6293. }
  6294. FrameDisplay *
  6295. InterpreterStackFrame::OP_LdInnerFrameDisplay(void *argHead, void *argEnv, ScriptContext *scriptContext)
  6296. {
  6297. JavascriptOperators::CheckInnerFrameDisplayArgument(argHead);
  6298. return OP_LdFrameDisplay(argHead, argEnv, scriptContext);
  6299. }
  6300. FrameDisplay *
  6301. InterpreterStackFrame::OP_LdInnerFrameDisplayNoParent(void *argHead, ScriptContext *scriptContext)
  6302. {
  6303. JavascriptOperators::CheckInnerFrameDisplayArgument(argHead);
  6304. return OP_LdFrameDisplayNoParent<true>(argHead, scriptContext);
  6305. }
  6306. FrameDisplay *
  6307. InterpreterStackFrame::OP_LdFrameDisplay(void *argHead, void *argEnv, ScriptContext *scriptContext)
  6308. {
  6309. FrameDisplay *frameDisplay;
  6310. bool strict = this->m_functionBody->GetIsStrictMode();
  6311. if (strict)
  6312. {
  6313. frameDisplay = JavascriptOperators::OP_LdStrictFrameDisplay(argHead, argEnv, scriptContext);
  6314. }
  6315. else
  6316. {
  6317. frameDisplay = JavascriptOperators::OP_LdFrameDisplay(argHead, argEnv, scriptContext);
  6318. }
  6319. return frameDisplay;
  6320. }
  6321. FrameDisplay *
  6322. InterpreterStackFrame::OP_LdFrameDisplaySetLocal(void *argHead, void *argEnv, ScriptContext *scriptContext)
  6323. {
  6324. FrameDisplay *frameDisplay = OP_LdFrameDisplay(argHead, argEnv, scriptContext);
  6325. this->SetLocalFrameDisplay(frameDisplay);
  6326. return frameDisplay;
  6327. }
  6328. FrameDisplay *
  6329. InterpreterStackFrame::NewFrameDisplay(void *argHead, void *argEnv)
  6330. {
  6331. FrameDisplay *frameDisplay;
  6332. bool strict = this->m_functionBody->GetIsStrictMode();
  6333. if (!this->m_functionBody->DoStackFrameDisplay() || !this->GetLocalFrameDisplay())
  6334. {
  6335. // Null local frame display probably indicates that we bailed out of an inlinee.
  6336. // Once we support stack closures in inlined functions, we can just assert that this value
  6337. // is never null if we should be allocating on the stack.
  6338. return this->OP_LdFrameDisplaySetLocal(argHead, argEnv, this->GetScriptContext());
  6339. }
  6340. frameDisplay = this->GetLocalFrameDisplay();
  6341. Assert(frameDisplay != nullptr);
  6342. frameDisplay->SetTag(true);
  6343. frameDisplay->SetStrictMode(strict);
  6344. frameDisplay->SetLength(this->m_functionBody->GetEnvDepth() + 1);
  6345. Assert(frameDisplay->GetLength() == ((FrameDisplay*)argEnv)->GetLength() + 1);
  6346. for (uint i = 0; i < ((FrameDisplay*)argEnv)->GetLength(); i++)
  6347. {
  6348. frameDisplay->SetItem(i + 1, ((FrameDisplay*)argEnv)->GetItem(i));
  6349. }
  6350. frameDisplay->SetItem(0, argHead);
  6351. return frameDisplay;
  6352. }
  6353. template<bool innerFD>
  6354. FrameDisplay *
  6355. InterpreterStackFrame::OP_LdFrameDisplayNoParent(void *argHead, ScriptContext *scriptContext)
  6356. {
  6357. FrameDisplay *frameDisplay;
  6358. bool strict = this->m_functionBody->GetIsStrictMode();
  6359. Var argEnv = nullptr;
  6360. if (innerFD && this->m_functionBody->GetLocalFrameDisplayRegister() != Constants::NoRegister)
  6361. {
  6362. argEnv = this->GetLocalFrameDisplay();
  6363. }
  6364. if (argEnv == nullptr && this->m_functionBody->GetEnvRegister() != Constants::NoRegister)
  6365. {
  6366. argEnv = this->LdEnv();
  6367. }
  6368. if (argEnv == nullptr)
  6369. {
  6370. if (strict)
  6371. {
  6372. frameDisplay = JavascriptOperators::OP_LdStrictFrameDisplayNoParent(argHead, scriptContext);
  6373. }
  6374. else
  6375. {
  6376. frameDisplay = JavascriptOperators::OP_LdFrameDisplayNoParent(argHead, scriptContext);
  6377. }
  6378. }
  6379. else
  6380. {
  6381. if (strict)
  6382. {
  6383. frameDisplay = JavascriptOperators::OP_LdStrictFrameDisplay(argHead, argEnv, scriptContext);
  6384. }
  6385. else
  6386. {
  6387. frameDisplay = JavascriptOperators::OP_LdFrameDisplay(argHead, argEnv, scriptContext);
  6388. }
  6389. }
  6390. return frameDisplay;
  6391. }
  6392. FrameDisplay *
  6393. InterpreterStackFrame::OP_LdFuncExprFrameDisplaySetLocal(void *argHead1, void *argHead2, ScriptContext *scriptContext)
  6394. {
  6395. FrameDisplay *frameDisplay = OP_LdFrameDisplayNoParent<false>(argHead2, scriptContext);
  6396. frameDisplay = OP_LdFrameDisplay(argHead1, frameDisplay, scriptContext);
  6397. this->SetLocalFrameDisplay(frameDisplay);
  6398. return frameDisplay;
  6399. }
  6400. FrameDisplay* InterpreterStackFrame::GetLocalFrameDisplay() const
  6401. {
  6402. Assert(this->localFrameDisplay == nullptr || this->IsClosureInitDone() || this->localFrameDisplay->GetLength() == 0);
  6403. return this->localFrameDisplay;
  6404. }
  6405. void InterpreterStackFrame::SetLocalFrameDisplay(FrameDisplay* frameDisplay)
  6406. {
  6407. this->localFrameDisplay = frameDisplay;
  6408. }
  6409. Var InterpreterStackFrame::GetLocalClosure() const
  6410. {
  6411. return this->localClosure;
  6412. }
  6413. void InterpreterStackFrame::SetLocalClosure(Var closure)
  6414. {
  6415. this->localClosure = closure;
  6416. }
  6417. Var InterpreterStackFrame::GetParamClosure() const
  6418. {
  6419. return this->paramClosure;
  6420. }
  6421. void InterpreterStackFrame::SetParamClosure(Var closure)
  6422. {
  6423. this->paramClosure = closure;
  6424. }
  6425. void
  6426. InterpreterStackFrame::OP_NewInnerScopeSlots(uint innerScopeIndex, uint count, int scopeIndex, ScriptContext *scriptContext, FunctionBody *functionBody)
  6427. {
  6428. Field(Var)* slotArray =
  6429. JavascriptOperators::OP_NewScopeSlotsWithoutPropIds(count, scopeIndex, scriptContext, functionBody);
  6430. this->SetInnerScopeFromIndex(innerScopeIndex, slotArray);
  6431. }
  6432. template <typename T>
  6433. void InterpreterStackFrame::OP_CloneInnerScopeSlots(const unaligned OpLayoutT_Unsigned1<T> *playout)
  6434. {
  6435. uint innerScopeIndex = playout->C1;
  6436. Field(Var) * slotArray;
  6437. slotArray = (Field(Var)*)this->InnerScopeFromIndex(innerScopeIndex);
  6438. slotArray = JavascriptOperators::OP_CloneScopeSlots(slotArray, scriptContext);
  6439. this->SetInnerScopeFromIndex(innerScopeIndex, slotArray);
  6440. }
  6441. template <typename T>
  6442. void InterpreterStackFrame::OP_CloneBlockScope(const unaligned OpLayoutT_Unsigned1<T> *playout)
  6443. {
  6444. uint innerScopeIndex = playout->C1;
  6445. Var scope = this->InnerScopeFromIndex(innerScopeIndex);
  6446. BlockActivationObject* blockScope = BlockActivationObject::FromVar(scope);
  6447. scope = JavascriptOperators::OP_CloneBlockScope(blockScope, scriptContext);
  6448. this->SetInnerScopeFromIndex(innerScopeIndex, scope);
  6449. }
  6450. Field(Var)*
  6451. InterpreterStackFrame::NewScopeSlots(unsigned int size, ScriptContext *scriptContext, Var scope)
  6452. {
  6453. Field(Var)* slotArray = JavascriptOperators::OP_NewScopeSlots(size, scriptContext, scope);
  6454. this->SetLocalClosure(slotArray);
  6455. return slotArray;
  6456. }
  6457. Field(Var)*
  6458. InterpreterStackFrame::NewScopeSlots()
  6459. {
  6460. Field(Var)* slotArray;
  6461. FunctionBody * functionBody = this->m_functionBody;
  6462. uint scopeSlotCount = this->IsParamScopeDone() ? functionBody->scopeSlotArraySize : functionBody->paramScopeSlotArraySize;
  6463. Assert(scopeSlotCount != 0);
  6464. if (!functionBody->DoStackScopeSlots())
  6465. {
  6466. return this->NewScopeSlots(
  6467. scopeSlotCount + ScopeSlots::FirstSlotIndex, this->GetScriptContext(), (Var)functionBody->GetFunctionInfo());
  6468. }
  6469. slotArray = (Field(Var)*)this->GetLocalClosure();
  6470. Assert(slotArray != nullptr);
  6471. ScopeSlots scopeSlots(slotArray);
  6472. scopeSlots.SetCount(scopeSlotCount);
  6473. scopeSlots.SetScopeMetadata((Var)functionBody->GetFunctionInfo());
  6474. Var undef = functionBody->GetScriptContext()->GetLibrary()->GetUndefined();
  6475. for (unsigned int i = 0; i < scopeSlotCount; i++)
  6476. {
  6477. scopeSlots.Set(i, undef);
  6478. }
  6479. return slotArray;
  6480. }
  6481. Var
  6482. InterpreterStackFrame::NewScopeObject()
  6483. {
  6484. Var scopeObject;
  6485. if (m_functionBody->HasCachedScopePropIds())
  6486. {
  6487. const Js::PropertyIdArray *propIds = this->m_functionBody->GetFormalsPropIdArray();
  6488. JavascriptFunction* funcExpr = this->GetFunctionExpression();
  6489. PropertyId objectId = ActivationObjectEx::GetLiteralObjectRef(propIds);
  6490. scopeObject = JavascriptOperators::OP_InitCachedScope(funcExpr, propIds,
  6491. this->GetFunctionBody()->GetObjectLiteralTypeRef(objectId),
  6492. propIds->hasNonSimpleParams, GetScriptContext());
  6493. }
  6494. else
  6495. {
  6496. scopeObject = JavascriptOperators::OP_NewScopeObject(GetScriptContext());
  6497. }
  6498. this->SetLocalClosure(scopeObject);
  6499. return scopeObject;
  6500. }
  6501. FrameDisplay *
  6502. InterpreterStackFrame::GetFrameDisplayForNestedFunc() const
  6503. {
  6504. if (this->localFrameDisplay == nullptr)
  6505. {
  6506. return (FrameDisplay*)LdEnv();
  6507. }
  6508. return this->localFrameDisplay;
  6509. }
  6510. template <class T>
  6511. void InterpreterStackFrame::OP_NewStackScFunc(const unaligned T * playout)
  6512. {
  6513. uint funcIndex = playout->SlotIndex;
  6514. FrameDisplay *frameDisplay = this->GetFrameDisplayForNestedFunc();
  6515. SetRegAllowStackVarEnableOnly(playout->Value,
  6516. StackScriptFunction::OP_NewStackScFunc(frameDisplay,
  6517. this->m_functionBody->GetNestedFuncReference(funcIndex),
  6518. this->GetStackNestedFunction(funcIndex)));
  6519. }
  6520. template <class T>
  6521. void InterpreterStackFrame::OP_NewInnerStackScFunc(const unaligned T * playout)
  6522. {
  6523. uint funcIndex = playout->SlotIndex;
  6524. FrameDisplay *frameDisplay = (FrameDisplay*)GetNonVarReg(playout->Instance);
  6525. SetRegAllowStackVarEnableOnly(playout->Value,
  6526. StackScriptFunction::OP_NewStackScFunc(frameDisplay,
  6527. this->m_functionBody->GetNestedFuncReference(funcIndex),
  6528. this->GetStackNestedFunction(funcIndex)));
  6529. }
  6530. template <class T>
  6531. void InterpreterStackFrame::OP_DeleteFld(const unaligned T * playout)
  6532. {
  6533. Var result = JavascriptOperators::OP_DeleteProperty(GetReg(playout->Instance), m_functionBody->GetReferencedPropertyId(playout->PropertyIdIndex), GetScriptContext());
  6534. SetReg(playout->Value, result);
  6535. }
  6536. template <class T>
  6537. void InterpreterStackFrame::OP_DeleteLocalFld(const unaligned T * playout)
  6538. {
  6539. Var result = JavascriptOperators::OP_DeleteProperty(this->localClosure, m_functionBody->GetReferencedPropertyId(playout->PropertyIdIndex), GetScriptContext());
  6540. SetReg(playout->Instance, result);
  6541. }
  6542. template <class T>
  6543. void InterpreterStackFrame::OP_DeleteRootFld(const unaligned T * playout)
  6544. {
  6545. Var result = JavascriptOperators::OP_DeleteRootProperty(GetReg(playout->Instance), m_functionBody->GetReferencedPropertyId(playout->PropertyIdIndex), GetScriptContext());
  6546. SetReg(playout->Value, result);
  6547. }
  6548. template <class T>
  6549. void InterpreterStackFrame::OP_DeleteFldStrict(const unaligned T * playout)
  6550. {
  6551. Var result = JavascriptOperators::OP_DeleteProperty(GetReg(playout->Instance), m_functionBody->GetReferencedPropertyId(playout->PropertyIdIndex), GetScriptContext(), PropertyOperation_StrictMode);
  6552. SetReg(playout->Value, result);
  6553. }
  6554. template <class T>
  6555. void InterpreterStackFrame::OP_DeleteRootFldStrict(const unaligned T * playout)
  6556. {
  6557. Var result = JavascriptOperators::OP_DeleteRootProperty(GetReg(playout->Instance), m_functionBody->GetReferencedPropertyId(playout->PropertyIdIndex), GetScriptContext(), PropertyOperation_StrictMode);
  6558. SetReg(playout->Value, result);
  6559. }
  6560. template <typename T>
  6561. void InterpreterStackFrame::OP_ScopedDeleteFld(const unaligned OpLayoutT_ElementScopedC<T> * playout)
  6562. {
  6563. // Implicit root object as default instance
  6564. Var result = JavascriptOperators::OP_DeletePropertyScoped(GetEnvForEvalCode(),
  6565. m_functionBody->GetReferencedPropertyId(playout->PropertyIdIndex),
  6566. GetReg(Js::FunctionBody::RootObjectRegSlot), GetScriptContext());
  6567. SetReg(playout->Value, result);
  6568. }
  6569. template <typename T>
  6570. void InterpreterStackFrame::OP_ScopedDeleteFldStrict(const unaligned OpLayoutT_ElementScopedC<T> * playout)
  6571. {
  6572. // Implicit root object as default instance
  6573. Var result = JavascriptOperators::OP_DeletePropertyScoped(GetEnvForEvalCode(),
  6574. m_functionBody->GetReferencedPropertyId(playout->PropertyIdIndex),
  6575. GetReg(Js::FunctionBody::RootObjectRegSlot), GetScriptContext(), PropertyOperation_StrictMode);
  6576. SetReg(playout->Value, result);
  6577. }
  6578. template <class T>
  6579. void InterpreterStackFrame::OP_ScopedLdInst(const unaligned T * playout)
  6580. {
  6581. Var thisVar = nullptr;
  6582. Var rootObject = GetFunctionBody()->GetRootObject();
  6583. Var result = JavascriptOperators::OP_GetInstanceScoped(GetEnvForEvalCode(),
  6584. m_functionBody->GetReferencedPropertyId(playout->PropertyIdIndex), rootObject, &thisVar, GetScriptContext());
  6585. SetReg(playout->Value, result);
  6586. SetReg(playout->Value2, thisVar);
  6587. }
  6588. template <typename T>
  6589. void InterpreterStackFrame::OP_ScopedInitFunc(const unaligned OpLayoutT_ElementScopedC<T> * playout)
  6590. {
  6591. JavascriptOperators::OP_InitFuncScoped(GetEnvForEvalCode(),
  6592. m_functionBody->GetReferencedPropertyId(playout->PropertyIdIndex),
  6593. GetReg(playout->Value), GetReg(Js::FunctionBody::RootObjectRegSlot), GetScriptContext());
  6594. }
  6595. template <class T>
  6596. void InterpreterStackFrame::OP_ClearAttributes(const unaligned T * playout)
  6597. {
  6598. JavascriptOperators::OP_ClearAttributes(GetReg(playout->Instance), m_functionBody->GetReferencedPropertyId(playout->PropertyIdIndex));
  6599. }
  6600. template <class T>
  6601. void InterpreterStackFrame::OP_InitGetFld(const unaligned T * playout)
  6602. {
  6603. JavascriptOperators::OP_InitGetter(GetReg(playout->Instance), m_functionBody->GetReferencedPropertyId(playout->PropertyIdIndex), GetReg(playout->Value));
  6604. }
  6605. template <class T>
  6606. void InterpreterStackFrame::OP_InitSetFld(const unaligned T * playout)
  6607. {
  6608. JavascriptOperators::OP_InitSetter(GetReg(playout->Instance), m_functionBody->GetReferencedPropertyId(playout->PropertyIdIndex), GetReg(playout->Value));
  6609. }
  6610. template <class T>
  6611. void InterpreterStackFrame::OP_InitSetElemI(const unaligned T * playout)
  6612. {
  6613. JavascriptOperators::OP_InitElemSetter(
  6614. GetReg(playout->Instance),
  6615. GetReg(playout->Element),
  6616. GetReg(playout->Value),
  6617. m_functionBody->GetScriptContext()
  6618. );
  6619. }
  6620. template <class T>
  6621. void InterpreterStackFrame::OP_InitGetElemI(const unaligned T * playout)
  6622. {
  6623. JavascriptOperators::OP_InitElemGetter(
  6624. GetReg(playout->Instance),
  6625. GetReg(playout->Element),
  6626. GetReg(playout->Value),
  6627. m_functionBody->GetScriptContext()
  6628. );
  6629. }
  6630. template <class T>
  6631. void InterpreterStackFrame::OP_InitComputedProperty(const unaligned T * playout)
  6632. {
  6633. JavascriptOperators::OP_InitComputedProperty(
  6634. GetReg(playout->Instance),
  6635. GetReg(playout->Element),
  6636. GetReg(playout->Value),
  6637. m_functionBody->GetScriptContext()
  6638. );
  6639. }
  6640. template <class T>
  6641. void InterpreterStackFrame::OP_InitProto(const unaligned T * playout)
  6642. {
  6643. JavascriptOperators::OP_InitProto(GetReg(playout->Instance), m_functionBody->GetReferencedPropertyId(playout->PropertyIdIndex), GetReg(playout->Value));
  6644. }
  6645. void InterpreterStackFrame::DoInterruptProbe()
  6646. {
  6647. PROBE_STACK(scriptContext, 0);
  6648. }
  6649. void InterpreterStackFrame::InitializeStackFunctions(StackScriptFunction * scriptFunctions)
  6650. {
  6651. this->stackNestedFunctions = scriptFunctions;
  6652. FunctionBody * functionBody = this->m_functionBody;
  6653. uint nestedCount = functionBody->GetNestedCount();
  6654. for (uint i = 0; i < nestedCount; i++)
  6655. {
  6656. StackScriptFunction * stackScriptFunction = scriptFunctions + i;
  6657. FunctionProxy* nestedProxy = functionBody->GetNestedFunctionProxy(i);
  6658. ScriptFunctionType* type = nestedProxy->EnsureDeferredPrototypeType();
  6659. new (stackScriptFunction)StackScriptFunction(nestedProxy, type);
  6660. }
  6661. }
  6662. StackScriptFunction * InterpreterStackFrame::GetStackNestedFunction(uint index)
  6663. {
  6664. Assert(index < this->m_functionBody->GetNestedCount());
  6665. // Re-check if we have disable stack nested function
  6666. if (this->m_functionBody->DoStackNestedFunc())
  6667. {
  6668. return this->stackNestedFunctions + index;
  6669. }
  6670. return nullptr;
  6671. }
  6672. void InterpreterStackFrame::SetExecutingStackFunction(ScriptFunction * scriptFunction)
  6673. {
  6674. Assert(ThreadContext::IsOnStack(this->function));
  6675. Assert(this->m_functionBody == scriptFunction->GetFunctionBody());
  6676. this->function = scriptFunction;
  6677. }
  6678. DWORD_PTR InterpreterStackFrame::GetStackAddress() const
  6679. {
  6680. return m_stackAddress;
  6681. }
  6682. void* InterpreterStackFrame::GetAddressOfReturnAddress() const
  6683. {
  6684. return this->addressOfReturnAddress;
  6685. }
  6686. template <class T>
  6687. const byte * InterpreterStackFrame::OP_Br(const unaligned T * playout)
  6688. {
  6689. return m_reader.SetCurrentRelativeOffset((const byte *)(playout + 1), playout->RelativeJumpOffset);
  6690. }
  6691. template <class T>
  6692. void InterpreterStackFrame::OP_InitClass(const unaligned OpLayoutT_Class<T> * playout)
  6693. {
  6694. JavascriptOperators::OP_InitClass(GetReg(playout->Constructor), playout->Extends != Js::Constants::NoRegister ? GetReg(playout->Extends) : NULL, GetScriptContext());
  6695. }
  6696. #ifdef ENABLE_SCRIPT_DEBUGGING
  6697. template <class T>
  6698. void InterpreterStackFrame::OP_EmitTmpRegCount(const unaligned OpLayoutT_Unsigned1<T> * playout)
  6699. {
  6700. this->scriptContext->GetDebugContext()->GetProbeContainer()->SetCurrentTmpRegCount(playout->C1);
  6701. }
  6702. #endif
  6703. Var InterpreterStackFrame::OP_LdHomeObj(ScriptContext * scriptContext)
  6704. {
  6705. return JavascriptOperators::OP_LdHomeObj(function, scriptContext);
  6706. }
  6707. Var InterpreterStackFrame::OP_LdFuncObj(ScriptContext * scriptContext)
  6708. {
  6709. return JavascriptOperators::OP_LdFuncObj(function, scriptContext);
  6710. }
  6711. Var InterpreterStackFrame::OP_ImportCall(Var specifier, ScriptContext *scriptContext)
  6712. {
  6713. return JavascriptOperators::OP_ImportCall(function, specifier, scriptContext);
  6714. }
  6715. void InterpreterStackFrame::ValidateRegValue(Var value, bool allowStackVar, bool allowStackVarOnDisabledStackNestedFunc) const
  6716. {
  6717. #if DBG
  6718. if (value != nullptr && !TaggedNumber::Is(value))
  6719. {
  6720. if (!allowStackVar || !this->m_functionBody->DoStackNestedFunc())
  6721. {
  6722. Assert(!ThreadContext::IsOnStack(value)
  6723. || (allowStackVar && allowStackVarOnDisabledStackNestedFunc && StackScriptFunction::IsBoxed(value)));
  6724. }
  6725. Assert(!CrossSite::NeedMarshalVar(value, GetScriptContext()));
  6726. }
  6727. #endif
  6728. }
  6729. template <typename RegSlotType>
  6730. Var InterpreterStackFrame::GetReg(RegSlotType localRegisterID) const
  6731. {
  6732. Var value = m_localSlots[localRegisterID];
  6733. ValidateRegValue(value);
  6734. return value;
  6735. }
  6736. template <typename RegSlotType>
  6737. void InterpreterStackFrame::SetReg(RegSlotType localRegisterID, Var value)
  6738. {
  6739. Assert(localRegisterID == 0 || localRegisterID >= m_functionBody->GetConstantCount());
  6740. ValidateRegValue(value);
  6741. m_localSlots[localRegisterID] = value;
  6742. #if ENABLE_OBJECT_SOURCE_TRACKING
  6743. if (value != nullptr && DynamicType::Is(Js::JavascriptOperators::GetTypeId(value)))
  6744. {
  6745. static_cast<DynamicObject*>(value)->SetDiagOriginInfoAsNeeded();
  6746. }
  6747. #endif
  6748. #if ENABLE_VALUE_TRACE
  6749. if (this->function->GetScriptContext()->ShouldPerformRecordOrReplayAction())
  6750. {
  6751. this->function->GetScriptContext()->GetThreadContext()->TTDExecutionInfo->GetTraceLogger()->WriteTraceValue(value);
  6752. }
  6753. #endif
  6754. }
  6755. template <typename T>
  6756. T InterpreterStackFrame::GetRegRaw(RegSlot localRegisterID) const
  6757. {
  6758. return (T)m_localIntSlots[localRegisterID];
  6759. }
  6760. // specialized version for doubles
  6761. template <>
  6762. double VECTORCALL InterpreterStackFrame::GetRegRaw(RegSlot localRegisterID) const
  6763. {
  6764. return (double)m_localDoubleSlots[localRegisterID];
  6765. }
  6766. template <>
  6767. float VECTORCALL InterpreterStackFrame::GetRegRaw(RegSlot localRegisterID) const
  6768. {
  6769. return (float)m_localFloatSlots[localRegisterID];
  6770. }
  6771. template <>
  6772. int64 InterpreterStackFrame::GetRegRaw(RegSlot localRegisterID) const
  6773. {
  6774. return m_localInt64Slots[localRegisterID];
  6775. }
  6776. template <typename T>
  6777. void InterpreterStackFrame::SetRegRaw(RegSlot localRegisterID, T bValue)
  6778. {
  6779. m_localIntSlots[localRegisterID] = (int)bValue;
  6780. }
  6781. template <>
  6782. void InterpreterStackFrame::SetRegRaw(RegSlot localRegisterID, float bValue)
  6783. {
  6784. m_localFloatSlots[localRegisterID] = (float)bValue;
  6785. }
  6786. template <>
  6787. void InterpreterStackFrame::SetRegRaw(RegSlot localRegisterID, double bValue)
  6788. {
  6789. m_localDoubleSlots[localRegisterID] = bValue;
  6790. }
  6791. template <>
  6792. void InterpreterStackFrame::SetRegRaw(RegSlot localRegisterID, int64 bValue)
  6793. {
  6794. m_localInt64Slots[localRegisterID] = bValue;
  6795. }
  6796. template <typename RegSlotType>
  6797. int InterpreterStackFrame::GetRegRawInt(RegSlotType localRegisterID) const
  6798. {
  6799. return m_localIntSlots[localRegisterID];
  6800. }
  6801. template <typename RegSlotType>
  6802. double InterpreterStackFrame::GetRegRawDouble(RegSlotType localRegisterID) const
  6803. {
  6804. return m_localDoubleSlots[localRegisterID];
  6805. }
  6806. template <typename RegSlotType>
  6807. float InterpreterStackFrame::GetRegRawFloat(RegSlotType localRegisterID) const
  6808. {
  6809. return m_localFloatSlots[localRegisterID];
  6810. }
  6811. template <typename RegSlotType>
  6812. void InterpreterStackFrame::SetRegRawInt(RegSlotType localRegisterID, int bValue)
  6813. {
  6814. m_localIntSlots[localRegisterID] = bValue;
  6815. }
  6816. template <typename RegSlotType>
  6817. int64 InterpreterStackFrame::GetRegRawInt64(RegSlotType localRegisterID) const
  6818. {
  6819. return m_localInt64Slots[localRegisterID];
  6820. }
  6821. template <typename RegSlotType>
  6822. void* InterpreterStackFrame::GetRegRawPtr(RegSlotType localRegisterID) const
  6823. {
  6824. #if TARGET_32
  6825. return (void*)m_localIntSlots[localRegisterID];
  6826. #elif TARGET_64
  6827. return (void*)m_localInt64Slots[localRegisterID];
  6828. #endif
  6829. }
  6830. template <typename RegSlotType>
  6831. void InterpreterStackFrame::SetRegRawPtr(RegSlotType localRegisterID, void* val)
  6832. {
  6833. #if TARGET_32
  6834. m_localIntSlots[localRegisterID] = (int32)val;
  6835. #elif TARGET_64
  6836. m_localInt64Slots[localRegisterID] = (int64)val;
  6837. #endif
  6838. }
  6839. template <typename RegSlotType>
  6840. void InterpreterStackFrame::SetRegRawInt64(RegSlotType localRegisterID, int64 bValue)
  6841. {
  6842. m_localInt64Slots[localRegisterID] = bValue;
  6843. }
  6844. template <typename RegSlotType>
  6845. void InterpreterStackFrame::SetRegRawDouble(RegSlotType localRegisterID, double bValue)
  6846. {
  6847. m_localDoubleSlots[localRegisterID] = bValue;
  6848. }
  6849. template <typename RegSlotType>
  6850. void InterpreterStackFrame::SetRegRawFloat(RegSlotType localRegisterID, float bValue)
  6851. {
  6852. m_localFloatSlots[localRegisterID] = bValue;
  6853. }
  6854. template <typename RegSlotType>
  6855. Var InterpreterStackFrame::GetRegAllowStackVar(RegSlotType localRegisterID) const
  6856. {
  6857. Var value = m_localSlots[localRegisterID];
  6858. ValidateRegValue(value, true);
  6859. return value;
  6860. }
  6861. template <typename RegSlotType>
  6862. void InterpreterStackFrame::SetRegAllowStackVar(RegSlotType localRegisterID, Var value)
  6863. {
  6864. Assert(localRegisterID == 0 || localRegisterID >= m_functionBody->GetConstantCount());
  6865. ValidateRegValue(value, true);
  6866. m_localSlots[localRegisterID] = value;
  6867. #if ENABLE_OBJECT_SOURCE_TRACKING
  6868. if (value != nullptr && DynamicType::Is(Js::JavascriptOperators::GetTypeId(value)))
  6869. {
  6870. static_cast<DynamicObject*>(value)->SetDiagOriginInfoAsNeeded();
  6871. }
  6872. #endif
  6873. #if ENABLE_VALUE_TRACE
  6874. if (this->function->GetScriptContext()->ShouldPerformRecordOrReplayAction())
  6875. {
  6876. this->function->GetScriptContext()->GetThreadContext()->TTDExecutionInfo->GetTraceLogger()->WriteTraceValue(value);
  6877. }
  6878. #endif
  6879. }
  6880. template <typename RegSlotType>
  6881. Var InterpreterStackFrame::GetRegAllowStackVarEnableOnly(RegSlotType localRegisterID) const
  6882. {
  6883. Var value = m_localSlots[localRegisterID];
  6884. ValidateRegValue(value, true, false);
  6885. return value;
  6886. }
  6887. template <typename RegSlotType>
  6888. void InterpreterStackFrame::SetRegAllowStackVarEnableOnly(RegSlotType localRegisterID, Var value)
  6889. {
  6890. Assert(localRegisterID == 0 || localRegisterID >= m_functionBody->GetConstantCount());
  6891. ValidateRegValue(value, true, false);
  6892. m_localSlots[localRegisterID] = value;
  6893. #if ENABLE_OBJECT_SOURCE_TRACKING
  6894. if (value != nullptr && DynamicType::Is(Js::JavascriptOperators::GetTypeId(value)))
  6895. {
  6896. static_cast<DynamicObject*>(value)->SetDiagOriginInfoAsNeeded();
  6897. }
  6898. #endif
  6899. #if ENABLE_VALUE_TRACE
  6900. if (this->function->GetScriptContext()->ShouldPerformRecordOrReplayAction())
  6901. {
  6902. this->function->GetScriptContext()->GetThreadContext()->TTDExecutionInfo->GetTraceLogger()->WriteTraceValue(value);
  6903. }
  6904. #endif
  6905. }
  6906. template <>
  6907. AsmJsSIMDValue InterpreterStackFrame::GetRegRaw(RegSlot localRegisterID) const
  6908. {
  6909. return (AsmJsSIMDValue)m_localSimdSlots[localRegisterID];
  6910. }
  6911. template<>
  6912. void InterpreterStackFrame::SetRegRaw(RegSlot localRegisterID, AsmJsSIMDValue bValue)
  6913. {
  6914. m_localSimdSlots[localRegisterID] = bValue;
  6915. }
  6916. template <typename RegSlotType>
  6917. AsmJsSIMDValue InterpreterStackFrame::GetRegRawSimd(RegSlotType localRegisterID) const
  6918. {
  6919. return m_localSimdSlots[localRegisterID];
  6920. }
  6921. template <typename RegSlotType>
  6922. void InterpreterStackFrame::SetRegRawSimd(RegSlotType localRegisterID, AsmJsSIMDValue bValue)
  6923. {
  6924. m_localSimdSlots[localRegisterID] = bValue;
  6925. }
  6926. int InterpreterStackFrame::OP_GetMemorySize()
  6927. {
  6928. #ifdef ENABLE_WASM
  6929. return (int)GetWebAssemblyMemory()->GetCurrentMemoryPages();
  6930. #else
  6931. Assert(UNREACHED);
  6932. return 0;
  6933. #endif
  6934. }
  6935. int InterpreterStackFrame::OP_GrowMemory(int32 delta)
  6936. {
  6937. #ifdef ENABLE_WASM
  6938. return GetWebAssemblyMemory()->GrowInternal((uint32)delta);
  6939. #else
  6940. Assert(UNREACHED);
  6941. return 0;
  6942. #endif
  6943. }
  6944. template <typename T, InterpreterStackFrame::AsmJsMathPtr<T> func> T InterpreterStackFrame::OP_UnsignedDivRemCheck(T aLeft, T aRight, ScriptContext* scriptContext)
  6945. {
  6946. if (aRight == 0)
  6947. {
  6948. JavascriptError::ThrowWebAssemblyRuntimeError(scriptContext, WASMERR_DivideByZero);
  6949. }
  6950. return func(aLeft, aRight);
  6951. }
  6952. template <typename T, InterpreterStackFrame::AsmJsMathPtr<T> func> T InterpreterStackFrame::OP_DivOverflow(T aLeft, T aRight, ScriptContext* scriptContext)
  6953. {
  6954. if (aRight == 0)
  6955. {
  6956. JavascriptError::ThrowWebAssemblyRuntimeError(scriptContext, WASMERR_DivideByZero);
  6957. }
  6958. if (aLeft == SignedTypeTraits<T>::MinValue && aRight == -1)
  6959. {
  6960. JavascriptError::ThrowWebAssemblyRuntimeError(scriptContext, VBSERR_Overflow);
  6961. }
  6962. return func(aLeft, aRight);
  6963. }
  6964. template <typename T, InterpreterStackFrame::AsmJsMathPtr<T> func> T InterpreterStackFrame::OP_RemOverflow(T aLeft, T aRight, ScriptContext* scriptContext)
  6965. {
  6966. if (aRight == 0)
  6967. {
  6968. JavascriptError::ThrowWebAssemblyRuntimeError(scriptContext, WASMERR_DivideByZero);
  6969. }
  6970. if (aLeft == SignedTypeTraits<T>::MinValue && aRight == -1)
  6971. {
  6972. return 0;
  6973. }
  6974. return func(aLeft, aRight);
  6975. }
  6976. void InterpreterStackFrame::OP_Unreachable()
  6977. {
  6978. JavascriptError::ThrowUnreachable(scriptContext);
  6979. }
  6980. template <class T>
  6981. void InterpreterStackFrame::OP_SimdLdArrGeneric(const unaligned T* playout)
  6982. {
  6983. Assert(playout->ViewType < Js::ArrayBufferView::TYPE_COUNT);
  6984. const uint64 index = ((uint64)(uint32)GetRegRawInt(playout->SlotIndex) + playout->Offset /* WASM only */) & (int64)(int)ArrayBufferView::ViewMask[playout->ViewType];
  6985. ArrayBufferBase* arr =
  6986. #ifdef ENABLE_WASM_SIMD
  6987. (m_functionBody->IsWasmFunction()) ?
  6988. m_wasmMemory->GetBuffer() :
  6989. #endif
  6990. GetAsmJsBuffer();
  6991. BYTE* buffer = arr->GetBuffer();
  6992. uint8 dataWidth = playout->DataWidth;
  6993. RegSlot dstReg = playout->Value;
  6994. if (index + dataWidth > arr->GetByteLength())
  6995. {
  6996. JavascriptError::ThrowRangeError(scriptContext, JSERR_ArgumentOutOfRange, _u("Simd typed array access"));
  6997. }
  6998. AsmJsSIMDValue *data = (AsmJsSIMDValue*)(buffer + index);
  6999. AsmJsSIMDValue value;
  7000. value = SIMDUtils::SIMDLdData(data, dataWidth);
  7001. SetRegRawSimd(dstReg, value);
  7002. }
  7003. template <class T>
  7004. void InterpreterStackFrame::OP_SimdLdArrConstIndex(const unaligned T* playout)
  7005. {
  7006. Assert(playout->ViewType < Js::ArrayBufferView::TYPE_COUNT);
  7007. const uint64 index = (uint32)playout->SlotIndex;
  7008. JavascriptArrayBuffer* arr = GetAsmJsBuffer();
  7009. BYTE* buffer = arr->GetBuffer();
  7010. uint8 dataWidth = playout->DataWidth;
  7011. RegSlot dstReg = playout->Value;
  7012. if (index + dataWidth > arr->GetByteLength())
  7013. {
  7014. JavascriptError::ThrowRangeError(scriptContext, JSERR_ArgumentOutOfRange, _u("Simd typed array access"));
  7015. }
  7016. AsmJsSIMDValue *data = (AsmJsSIMDValue*)(buffer + index);
  7017. AsmJsSIMDValue value;
  7018. value = SIMDUtils::SIMDLdData(data, dataWidth);
  7019. SetRegRawSimd(dstReg, value);
  7020. }
  7021. template <class T>
  7022. void InterpreterStackFrame::OP_SimdStArrGeneric(const unaligned T* playout)
  7023. {
  7024. Assert(playout->ViewType < Js::ArrayBufferView::TYPE_COUNT);
  7025. const uint64 index = ((uint64)(uint32)GetRegRawInt(playout->SlotIndex) + playout->Offset /* WASM only */) & (int64)(int)ArrayBufferView::ViewMask[playout->ViewType];
  7026. ArrayBufferBase* arr =
  7027. #ifdef ENABLE_WASM_SIMD
  7028. (m_functionBody->IsWasmFunction()) ?
  7029. m_wasmMemory->GetBuffer() :
  7030. #endif
  7031. GetAsmJsBuffer();
  7032. BYTE* buffer = arr->GetBuffer();
  7033. uint8 dataWidth = playout->DataWidth;
  7034. RegSlot srcReg = playout->Value;
  7035. if (index + dataWidth > arr->GetByteLength())
  7036. {
  7037. JavascriptError::ThrowRangeError(scriptContext, JSERR_ArgumentOutOfRange, _u("Simd typed array access"));
  7038. }
  7039. AsmJsSIMDValue *data = (AsmJsSIMDValue*)(buffer + index);
  7040. AsmJsSIMDValue value = GetRegRawSimd(srcReg);
  7041. SIMDUtils::SIMDStData(data, value, dataWidth);
  7042. }
  7043. template <class T>
  7044. void InterpreterStackFrame::OP_SimdStArrConstIndex(const unaligned T* playout)
  7045. {
  7046. Assert(playout->ViewType < Js::ArrayBufferView::TYPE_COUNT);
  7047. const uint64 index = (uint32)playout->SlotIndex;
  7048. JavascriptArrayBuffer* arr = GetAsmJsBuffer();
  7049. BYTE* buffer = arr->GetBuffer();
  7050. uint8 dataWidth = playout->DataWidth;
  7051. RegSlot srcReg = playout->Value;
  7052. if (index + dataWidth > arr->GetByteLength())
  7053. {
  7054. JavascriptError::ThrowRangeError(scriptContext, JSERR_ArgumentOutOfRange, _u("Simd typed array access"));
  7055. }
  7056. AsmJsSIMDValue *data = (AsmJsSIMDValue*)(buffer + index);
  7057. AsmJsSIMDValue value = GetRegRawSimd(srcReg);
  7058. SIMDUtils::SIMDStData(data, value, dataWidth);
  7059. }
  7060. bool InterpreterStackFrame::SIMDAnyNaN(AsmJsSIMDValue& input)
  7061. {
  7062. if (!GetFunctionBody()->IsWasmFunction())
  7063. {
  7064. return false;
  7065. }
  7066. AsmJsSIMDValue compResult = SIMDFloat32x4Operation::OpEqual(input, input);
  7067. return !SIMDBool32x4Operation::OpAllTrue(compResult);
  7068. }
  7069. // handler for SIMD.Int32x4.FromFloat32x4
  7070. template <class T>
  7071. void InterpreterStackFrame::OP_SimdInt32x4FromFloat32x4(const unaligned T* playout)
  7072. {
  7073. bool throws = false;
  7074. AsmJsSIMDValue input = GetRegRawSimd(playout->F4_1);
  7075. AsmJsSIMDValue result{ 0 };
  7076. #ifdef ENABLE_WASM_SIMD
  7077. throws = SIMDAnyNaN(input);
  7078. if (!throws)
  7079. #endif
  7080. {
  7081. result = SIMDInt32x4Operation::OpFromFloat32x4(input, throws);
  7082. }
  7083. // value is out of bound
  7084. if (throws)
  7085. {
  7086. JavascriptError::ThrowRangeError(scriptContext, JSERR_ArgumentOutOfRange, _u("SIMD.Int32x4.FromFloat32x4"));
  7087. }
  7088. SetRegRawSimd(playout->I4_0, result);
  7089. }
  7090. // handler for SIMD.Uint32x4.FromFloat32x4
  7091. template <class T>
  7092. void InterpreterStackFrame::OP_SimdUint32x4FromFloat32x4(const unaligned T* playout)
  7093. {
  7094. bool throws = false;
  7095. AsmJsSIMDValue input = GetRegRawSimd(playout->F4_1);
  7096. AsmJsSIMDValue result{ 0 };
  7097. #ifdef ENABLE_WASM_SIMD
  7098. throws = SIMDAnyNaN(input);
  7099. if (!throws)
  7100. #endif
  7101. {
  7102. result = SIMDUint32x4Operation::OpFromFloat32x4(input, throws);
  7103. }
  7104. if (throws)
  7105. {
  7106. JavascriptError::ThrowRangeError(scriptContext, JSERR_ArgumentOutOfRange, _u("SIMD.Int32x4.FromFloat32x4"));
  7107. }
  7108. SetRegRawSimd(playout->U4_0, result);
  7109. }
  7110. template <class T>
  7111. void InterpreterStackFrame::OP_WasmSimdConst(const unaligned T* playout)
  7112. {
  7113. AsmJsSIMDValue result{ playout->C1, playout->C2, playout->C3, playout->C4 };
  7114. SetRegRawSimd(playout->F4_0, result);
  7115. }
  7116. template <class T>
  7117. void InterpreterStackFrame::OP_SimdShuffleV8X16(const unaligned T* playout)
  7118. {
  7119. uint32 lanes[Wasm::Simd::MAX_LANES];
  7120. for (uint32 i = 0; i < Wasm::Simd::MAX_LANES; i++)
  7121. {
  7122. Assert(playout->INDICES[i] < Wasm::Simd::MAX_LANES * 2);
  7123. lanes[i] = playout->INDICES[i];
  7124. }
  7125. SetRegRawSimd(playout->R0, SIMDUtils::SIMD128InnerShuffle(GetRegRawSimd(playout->R1), GetRegRawSimd(playout->R2), Wasm::Simd::MAX_LANES, lanes));
  7126. }
  7127. template <class T>
  7128. void InterpreterStackFrame::OP_SimdInt16x8(const unaligned T* playout)
  7129. {
  7130. int16 values[8];
  7131. values[0] = (int16)GetRegRawInt(playout->I1);
  7132. values[1] = (int16)GetRegRawInt(playout->I2);
  7133. values[2] = (int16)GetRegRawInt(playout->I3);
  7134. values[3] = (int16)GetRegRawInt(playout->I4);
  7135. values[4] = (int16)GetRegRawInt(playout->I5);
  7136. values[5] = (int16)GetRegRawInt(playout->I6);
  7137. values[6] = (int16)GetRegRawInt(playout->I7);
  7138. values[7] = (int16)GetRegRawInt(playout->I8);
  7139. AsmJsSIMDValue result = SIMDInt16x8Operation::OpInt16x8(values);
  7140. SetRegRawSimd(playout->I8_0, result);
  7141. }
  7142. template <class T>
  7143. void InterpreterStackFrame::OP_SimdInt8x16(const unaligned T* playout)
  7144. {
  7145. int8 values[16];
  7146. values[0] = (int8)GetRegRawInt(playout->I1);
  7147. values[1] = (int8)GetRegRawInt(playout->I2);
  7148. values[2] = (int8)GetRegRawInt(playout->I3);
  7149. values[3] = (int8)GetRegRawInt(playout->I4);
  7150. values[4] = (int8)GetRegRawInt(playout->I5);
  7151. values[5] = (int8)GetRegRawInt(playout->I6);
  7152. values[6] = (int8)GetRegRawInt(playout->I7);
  7153. values[7] = (int8)GetRegRawInt(playout->I8);
  7154. values[8] = (int8)GetRegRawInt(playout->I9);
  7155. values[9] = (int8)GetRegRawInt(playout->I10);
  7156. values[10] = (int8)GetRegRawInt(playout->I11);
  7157. values[11] = (int8)GetRegRawInt(playout->I12);
  7158. values[12] = (int8)GetRegRawInt(playout->I13);
  7159. values[13] = (int8)GetRegRawInt(playout->I14);
  7160. values[14] = (int8)GetRegRawInt(playout->I15);
  7161. values[15] = (int8)GetRegRawInt(playout->I16);
  7162. AsmJsSIMDValue result = SIMDInt8x16Operation::OpInt8x16(values);
  7163. SetRegRawSimd(playout->I16_0, result);
  7164. }
  7165. template <class T>
  7166. void InterpreterStackFrame::OP_SimdUint16x8(const unaligned T* playout)
  7167. {
  7168. uint16 values[8];
  7169. values[0] = (uint16)GetRegRawInt(playout->I1);
  7170. values[1] = (uint16)GetRegRawInt(playout->I2);
  7171. values[2] = (uint16)GetRegRawInt(playout->I3);
  7172. values[3] = (uint16)GetRegRawInt(playout->I4);
  7173. values[4] = (uint16)GetRegRawInt(playout->I5);
  7174. values[5] = (uint16)GetRegRawInt(playout->I6);
  7175. values[6] = (uint16)GetRegRawInt(playout->I7);
  7176. values[7] = (uint16)GetRegRawInt(playout->I8);
  7177. AsmJsSIMDValue result = SIMDUint16x8Operation::OpUint16x8(values);
  7178. SetRegRawSimd(playout->U8_0, result);
  7179. }
  7180. template <class T>
  7181. void InterpreterStackFrame::OP_SimdUint8x16(const unaligned T* playout)
  7182. {
  7183. uint8 values[16];
  7184. values[0] = (uint8)GetRegRawInt(playout->I1);
  7185. values[1] = (uint8)GetRegRawInt(playout->I2);
  7186. values[2] = (uint8)GetRegRawInt(playout->I3);
  7187. values[3] = (uint8)GetRegRawInt(playout->I4);
  7188. values[4] = (uint8)GetRegRawInt(playout->I5);
  7189. values[5] = (uint8)GetRegRawInt(playout->I6);
  7190. values[6] = (uint8)GetRegRawInt(playout->I7);
  7191. values[7] = (uint8)GetRegRawInt(playout->I8);
  7192. values[8] = (uint8)GetRegRawInt(playout->I9);
  7193. values[9] = (uint8)GetRegRawInt(playout->I10);
  7194. values[10] = (uint8)GetRegRawInt(playout->I11);
  7195. values[11] = (uint8)GetRegRawInt(playout->I12);
  7196. values[12] = (uint8)GetRegRawInt(playout->I13);
  7197. values[13] = (uint8)GetRegRawInt(playout->I14);
  7198. values[14] = (uint8)GetRegRawInt(playout->I15);
  7199. values[15] = (uint8)GetRegRawInt(playout->I16);
  7200. AsmJsSIMDValue result = SIMDUint8x16Operation::OpUint8x16(values);
  7201. SetRegRawSimd(playout->U16_0, result);
  7202. }
  7203. // Bool constructors
  7204. template <class T>
  7205. void InterpreterStackFrame::OP_SimdBool32x4(const unaligned T* playout)
  7206. {
  7207. bool arg1 = GetRegRawInt(playout->I1) ? true : false;
  7208. bool arg2 = GetRegRawInt(playout->I2) ? true : false;
  7209. bool arg3 = GetRegRawInt(playout->I3) ? true : false;
  7210. bool arg4 = GetRegRawInt(playout->I4) ? true : false;
  7211. AsmJsSIMDValue result = SIMDBool32x4Operation::OpBool32x4(arg1, arg2, arg3, arg4);
  7212. SetRegRawSimd(playout->B4_0, result);
  7213. }
  7214. template <class T>
  7215. void InterpreterStackFrame::OP_SimdBool16x8(const unaligned T* playout)
  7216. {
  7217. bool values[8];
  7218. values[0] = GetRegRawInt(playout->I1) ? true : false;
  7219. values[1] = GetRegRawInt(playout->I2) ? true : false;
  7220. values[2] = GetRegRawInt(playout->I3) ? true : false;
  7221. values[3] = GetRegRawInt(playout->I4) ? true : false;
  7222. values[4] = GetRegRawInt(playout->I5) ? true : false;
  7223. values[5] = GetRegRawInt(playout->I6) ? true : false;
  7224. values[6] = GetRegRawInt(playout->I7) ? true : false;
  7225. values[7] = GetRegRawInt(playout->I8) ? true : false;
  7226. AsmJsSIMDValue result = SIMDBool16x8Operation::OpBool16x8(values);
  7227. SetRegRawSimd(playout->B8_0, result);
  7228. }
  7229. template <class T>
  7230. void InterpreterStackFrame::OP_SimdBool8x16(const unaligned T* playout)
  7231. {
  7232. bool values[16];
  7233. values[0] = GetRegRawInt(playout->I1) ? true : false;
  7234. values[1] = GetRegRawInt(playout->I2) ? true : false;
  7235. values[2] = GetRegRawInt(playout->I3) ? true : false;
  7236. values[3] = GetRegRawInt(playout->I4) ? true : false;
  7237. values[4] = GetRegRawInt(playout->I5) ? true : false;
  7238. values[5] = GetRegRawInt(playout->I6) ? true : false;
  7239. values[6] = GetRegRawInt(playout->I7) ? true : false;
  7240. values[7] = GetRegRawInt(playout->I8) ? true : false;
  7241. values[8] = GetRegRawInt(playout->I9) ? true : false;
  7242. values[9] = GetRegRawInt(playout->I10) ? true : false;
  7243. values[10] = GetRegRawInt(playout->I11) ? true : false;
  7244. values[11] = GetRegRawInt(playout->I12) ? true : false;
  7245. values[12] = GetRegRawInt(playout->I13) ? true : false;
  7246. values[13] = GetRegRawInt(playout->I14) ? true : false;
  7247. values[14] = GetRegRawInt(playout->I15) ? true : false;
  7248. values[15] = GetRegRawInt(playout->I16) ? true : false;
  7249. AsmJsSIMDValue result = SIMDBool8x16Operation::OpBool8x16(values);
  7250. SetRegRawSimd(playout->B16_0, result);
  7251. }
  7252. Var InterpreterStackFrame::GetNonVarReg(RegSlot localRegisterID) const
  7253. {
  7254. return m_localSlots[localRegisterID];
  7255. }
  7256. void InterpreterStackFrame::SetNonVarReg(RegSlot localRegisterID, Var aValue)
  7257. {
  7258. m_localSlots[localRegisterID] = aValue;
  7259. }
  7260. Var InterpreterStackFrame::GetRootObject() const
  7261. {
  7262. Assert(!this->GetFunctionBody()->IsJsBuiltInCode());
  7263. Var rootObject = GetReg(Js::FunctionBody::RootObjectRegSlot);
  7264. Assert(rootObject == this->GetFunctionBody()->LoadRootObject());
  7265. return rootObject;
  7266. }
  7267. Var InterpreterStackFrame::OP_ArgIn0()
  7268. {
  7269. return m_inParams[0];
  7270. }
  7271. #if ENABLE_PROFILE_INFO
  7272. template <class T>
  7273. void InterpreterStackFrame::OP_ProfiledArgOut_A(const unaligned T * playout)
  7274. {
  7275. FunctionBody* functionBody = this->m_functionBody;
  7276. DynamicProfileInfo * dynamicProfileInfo = functionBody->GetDynamicProfileInfo();
  7277. Assert(playout->Reg > FunctionBody::FirstRegSlot);
  7278. Var value = GetReg(playout->Reg);
  7279. dynamicProfileInfo->RecordParameterAtCallSite(functionBody, playout->profileId, value, playout->Arg, playout->Reg);
  7280. SetOut(playout->Arg, value);
  7281. }
  7282. #endif
  7283. template <class T>
  7284. void InterpreterStackFrame::OP_ArgOut_A(const unaligned T * playout)
  7285. {
  7286. SetOut(playout->Arg, GetReg(playout->Reg));
  7287. }
  7288. #if DBG
  7289. template <class T>
  7290. void InterpreterStackFrame::OP_ArgOut_ANonVar(const unaligned T * playout)
  7291. {
  7292. SetOut(playout->Arg, GetNonVarReg(playout->Reg));
  7293. }
  7294. #endif
  7295. template <class T>
  7296. void InterpreterStackFrame::OP_ArgOut_Env(const unaligned T * playout)
  7297. {
  7298. Var argEnv;
  7299. if (this->m_functionBody->GetLocalFrameDisplayRegister() != Constants::NoRegister)
  7300. {
  7301. argEnv = this->GetLocalFrameDisplay();
  7302. }
  7303. else
  7304. {
  7305. argEnv = this->LdEnv();
  7306. }
  7307. SetOut(playout->Arg, argEnv);
  7308. }
  7309. BOOL InterpreterStackFrame::OP_BrFalse_A(Var aValue, ScriptContext* scriptContext)
  7310. {
  7311. return !JavascriptConversion::ToBoolean(aValue, scriptContext);
  7312. }
  7313. BOOL InterpreterStackFrame::OP_BrTrue_A(Var aValue, ScriptContext* scriptContext)
  7314. {
  7315. return JavascriptConversion::ToBoolean(aValue, scriptContext);
  7316. }
  7317. BOOL InterpreterStackFrame::OP_BrNotNull_A(Var aValue)
  7318. {
  7319. return aValue != NULL;
  7320. }
  7321. BOOL InterpreterStackFrame::OP_BrUndecl_A(Var aValue)
  7322. {
  7323. return this->scriptContext->GetLibrary()->IsUndeclBlockVar(aValue);
  7324. }
  7325. BOOL InterpreterStackFrame::OP_BrNotUndecl_A(Var aValue)
  7326. {
  7327. return !this->scriptContext->GetLibrary()->IsUndeclBlockVar(aValue);
  7328. }
  7329. BOOL InterpreterStackFrame::OP_BrOnHasProperty(Var argInstance, uint propertyIdIndex, ScriptContext* scriptContext)
  7330. {
  7331. return JavascriptOperators::OP_HasProperty(argInstance,
  7332. this->m_functionBody->GetReferencedPropertyId(propertyIdIndex), scriptContext);
  7333. }
  7334. BOOL InterpreterStackFrame::OP_BrOnNoProperty(Var argInstance, uint propertyIdIndex, ScriptContext* scriptContext)
  7335. {
  7336. return !JavascriptOperators::OP_HasProperty(argInstance,
  7337. this->m_functionBody->GetReferencedPropertyId(propertyIdIndex), scriptContext);
  7338. }
  7339. BOOL InterpreterStackFrame::OP_BrOnNoEnvProperty(Var envInstance, int32 slotIndex, uint propertyIdIndex, ScriptContext* scriptContext)
  7340. {
  7341. Var instance = OP_LdFrameDisplaySlot(envInstance, slotIndex);
  7342. return !JavascriptOperators::OP_HasProperty(instance,
  7343. this->m_functionBody->GetReferencedPropertyId(propertyIdIndex), scriptContext);
  7344. }
  7345. BOOL InterpreterStackFrame::OP_BrOnClassConstructor(Var aValue)
  7346. {
  7347. return JavascriptOperators::IsClassConstructor(aValue);
  7348. }
  7349. BOOL InterpreterStackFrame::OP_BrOnBaseConstructorKind(Var aValue)
  7350. {
  7351. return JavascriptOperators::IsBaseConstructorKind(aValue);
  7352. }
  7353. template<class T>
  7354. void InterpreterStackFrame::OP_LdLen(const unaligned T * const playout)
  7355. {
  7356. Assert(playout);
  7357. ThreadContext* threadContext = this->GetScriptContext()->GetThreadContext();
  7358. ImplicitCallFlags savedImplicitCallFlags = threadContext->GetImplicitCallFlags();
  7359. threadContext->ClearImplicitCallFlags();
  7360. Var instance = GetReg(playout->Instance);
  7361. Var length = JavascriptOperators::OP_GetLength(instance, GetScriptContext());
  7362. threadContext->CheckAndResetImplicitCallAccessorFlag();
  7363. threadContext->AddImplicitCallFlags(savedImplicitCallFlags);
  7364. SetReg(playout->Value, length);
  7365. }
  7366. #if ENABLE_PROFILE_INFO
  7367. template<class T>
  7368. void InterpreterStackFrame::OP_ProfiledLdLen(const unaligned OpLayoutDynamicProfile<T> *const playout)
  7369. {
  7370. Assert(playout);
  7371. FunctionBody * functionBody = m_functionBody;
  7372. DynamicProfileInfo * profileData = functionBody->GetDynamicProfileInfo();
  7373. Var instance = GetReg(playout->Instance);
  7374. LdLenInfo ldLenInfo;
  7375. ldLenInfo.arrayType = ValueType::Uninitialized.Merge(instance);
  7376. if (this->TestFlags(InterpreterStackFrameFlags_ProcessingBailOutOnArraySpecialization))
  7377. {
  7378. ldLenInfo.disableAggressiveSpecialization = true;
  7379. this->ClearFlags(InterpreterStackFrameFlags_ProcessingBailOutOnArraySpecialization);
  7380. }
  7381. profileData->RecordLengthLoad(functionBody, playout->profileId, ldLenInfo);
  7382. ThreadContext* threadContext = this->GetScriptContext()->GetThreadContext();
  7383. ImplicitCallFlags savedImplicitCallFlags = threadContext->GetImplicitCallFlags();
  7384. threadContext->ClearImplicitCallFlags();
  7385. PropertyId propertyId = GetPropertyIdFromCacheId(playout->inlineCacheIndex);
  7386. Var value = ProfilingHelpers::ProfiledLdFld<false, false, false>(
  7387. instance,
  7388. propertyId,
  7389. GetInlineCache(playout->inlineCacheIndex),
  7390. playout->inlineCacheIndex,
  7391. GetFunctionBody(),
  7392. instance);
  7393. SetReg(playout->Value, value);
  7394. threadContext->CheckAndResetImplicitCallAccessorFlag();
  7395. threadContext->AddImplicitCallFlags(savedImplicitCallFlags);
  7396. }
  7397. #endif
  7398. #if ENABLE_PROFILE_INFO
  7399. template <bool doProfile>
  7400. Var InterpreterStackFrame::ProfiledIsIn(Var argProperty, Var instance, ScriptContext* scriptContext, ProfileId profileId)
  7401. {
  7402. if (doProfile)
  7403. {
  7404. DynamicProfileInfo * profileData = m_functionBody->GetDynamicProfileInfo();
  7405. LdElemInfo ldElemInfo;
  7406. ldElemInfo.arrayType = ValueType::Uninitialized.Merge(instance);
  7407. if (this->TestFlags(InterpreterStackFrameFlags_ProcessingBailOutOnArraySpecialization))
  7408. {
  7409. ldElemInfo.disableAggressiveSpecialization = true;
  7410. }
  7411. this->ClearFlags(InterpreterStackFrameFlags_ProcessingBailOutOnArraySpecialization);
  7412. profileData->RecordElementLoad(m_functionBody, profileId, ldElemInfo);
  7413. }
  7414. return JavascriptOperators::IsIn(argProperty, instance, scriptContext);
  7415. }
  7416. #else
  7417. template <bool doProfile>
  7418. Var InterpreterStackFrame::ProfiledIsIn(Var argProperty, Var instance, ScriptContext* scriptContext, ProfileId profileId)
  7419. {
  7420. Assert(!doProfile);
  7421. return JavascriptOperators::IsIn(argProperty, instance, scriptContext);
  7422. }
  7423. #endif
  7424. JavascriptFunction* InterpreterStackFrame::GetFunctionExpression()
  7425. {
  7426. // Make sure we get the boxed function object if is there, (or the function itself)
  7427. return StackScriptFunction::GetCurrentFunctionObject(this->function->GetRealFunctionObject());
  7428. }
  7429. template <class T>
  7430. void InterpreterStackFrame::OP_LdFunctionExpression(const unaligned T * playout)
  7431. {
  7432. SetRegAllowStackVar(playout->R0, this->GetFunctionExpression());
  7433. }
  7434. template <class T>
  7435. void InterpreterStackFrame::OP_StFunctionExpression(const unaligned T * playout)
  7436. {
  7437. OP_StFunctionExpression(GetReg(playout->Instance), GetReg(playout->Value), playout->PropertyIdIndex);
  7438. }
  7439. template <class T>
  7440. void InterpreterStackFrame::OP_StLocalFunctionExpression(const unaligned T * playout)
  7441. {
  7442. OP_StFunctionExpression(this->localClosure, GetReg(playout->Instance), playout->PropertyIdIndex);
  7443. }
  7444. void InterpreterStackFrame::OP_StFunctionExpression(Var instance, Var value, PropertyIdIndexType index)
  7445. {
  7446. JavascriptOperators::OP_StFunctionExpression(instance,
  7447. this->m_functionBody->GetReferencedPropertyId(index), value);
  7448. }
  7449. template <class T>
  7450. void InterpreterStackFrame::OP_LdNewTarget(const unaligned T* playout)
  7451. {
  7452. if (Js::CallInfo::HasNewTarget(this->m_callFlags))
  7453. {
  7454. SetRegAllowStackVar(playout->R0, (Js::RecyclableObject*)Js::CallInfo::GetNewTarget(this->m_callFlags, this->m_inParams, (ArgSlot)this->m_inSlotsCount));
  7455. }
  7456. else if (this->m_callFlags & CallFlags_New)
  7457. {
  7458. SetRegAllowStackVar(playout->R0, this->GetFunctionExpression());
  7459. }
  7460. else
  7461. {
  7462. SetReg(playout->R0, this->GetScriptContext()->GetLibrary()->GetUndefined());
  7463. }
  7464. }
  7465. Var InterpreterStackFrame::OP_Ld_A(Var aValue)
  7466. {
  7467. return aValue;
  7468. }
  7469. Var InterpreterStackFrame::LdEnv() const
  7470. {
  7471. return this->function->GetEnvironment();
  7472. }
  7473. void InterpreterStackFrame::SetEnv(FrameDisplay *frameDisplay)
  7474. {
  7475. this->function->SetEnvironment(frameDisplay);
  7476. }
  7477. Var InterpreterStackFrame::OP_LdLocalObj()
  7478. {
  7479. if (!VirtualTableInfo<ActivationObject>::HasVirtualTable(this->localClosure) &&
  7480. !VirtualTableInfo<ActivationObjectEx>::HasVirtualTable(this->localClosure))
  7481. {
  7482. Js::Throw::FatalInternalError();
  7483. }
  7484. return this->localClosure;
  7485. }
  7486. Var InterpreterStackFrame::OP_LdParamObj()
  7487. {
  7488. if (!VirtualTableInfo<ActivationObject>::HasVirtualTable(this->paramClosure) &&
  7489. !VirtualTableInfo<ActivationObjectEx>::HasVirtualTable(this->paramClosure))
  7490. {
  7491. Js::Throw::FatalInternalError();
  7492. }
  7493. return this->paramClosure;
  7494. }
  7495. #ifdef ASMJS_PLAT
  7496. template <typename ArrayType, typename RegType>
  7497. void InterpreterStackFrame::OP_StArr(uint32 index, RegSlot regSlot)
  7498. {
  7499. JavascriptArrayBuffer* arr = GetAsmJsBuffer();
  7500. if (index < arr->GetByteLength())
  7501. {
  7502. BYTE* buffer = arr->GetBuffer();
  7503. *(ArrayType*)(buffer + index) = (ArrayType)GetRegRaw<RegType>(regSlot);
  7504. }
  7505. }
  7506. #endif
  7507. template<> inline double InterpreterStackFrame::GetArrayViewOverflowVal()
  7508. {
  7509. return *(double*)&NumberConstants::k_Nan;
  7510. }
  7511. template<> inline float InterpreterStackFrame::GetArrayViewOverflowVal()
  7512. {
  7513. return (float)*(double*)&NumberConstants::k_Nan;
  7514. }
  7515. template<typename T> T InterpreterStackFrame::GetArrayViewOverflowVal()
  7516. {
  7517. return 0;
  7518. }
  7519. template <class T>
  7520. void InterpreterStackFrame::OP_LdArrFunc(const unaligned T* playout)
  7521. {
  7522. Var* arr = (Var*)GetRegRawPtr(playout->Instance);
  7523. const uint32 index = (uint32)GetRegRawInt(playout->SlotIndex);
  7524. SetRegRawPtr(playout->Value, arr[index]);
  7525. }
  7526. template <class T>
  7527. void InterpreterStackFrame::OP_LdArrWasmFunc(const unaligned T* playout)
  7528. {
  7529. #ifdef ENABLE_WASM
  7530. WebAssemblyTable * table = WebAssemblyTable::FromVar(GetRegRawPtr(playout->Instance));
  7531. const uint32 index = (uint32)GetRegRawInt(playout->SlotIndex);
  7532. if (index >= table->GetCurrentLength())
  7533. {
  7534. JavascriptError::ThrowWebAssemblyRuntimeError(GetScriptContext(), WASMERR_TableIndexOutOfRange);
  7535. }
  7536. Var func = table->DirectGetValue(index);
  7537. if (!func)
  7538. {
  7539. JavascriptError::ThrowWebAssemblyRuntimeError(GetScriptContext(), WASMERR_NeedWebAssemblyFunc);
  7540. }
  7541. SetRegRawPtr(playout->Value, func);
  7542. #endif
  7543. }
  7544. template <class T>
  7545. void InterpreterStackFrame::OP_CheckSignature(const unaligned T* playout)
  7546. {
  7547. #ifdef ENABLE_WASM
  7548. ScriptFunction * func = ScriptFunction::FromVar(GetRegRawPtr(playout->R0));
  7549. int sigIndex = playout->C1;
  7550. Wasm::WasmSignature * expected = &m_signatures[sigIndex];
  7551. if (func->GetFunctionInfo()->IsDeferredParseFunction())
  7552. {
  7553. // TODO: should be able to assert this once imports are converted to wasm functions
  7554. JavascriptError::ThrowWebAssemblyRuntimeError(GetScriptContext(), WASMERR_NeedWebAssemblyFunc);
  7555. }
  7556. AsmJsFunctionInfo * asmInfo = func->GetFunctionBody()->GetAsmJsFunctionInfo();
  7557. if (!asmInfo)
  7558. {
  7559. // TODO: should be able to assert this once imports are converted to wasm functions
  7560. JavascriptError::ThrowWebAssemblyRuntimeError(GetScriptContext(), WASMERR_NeedWebAssemblyFunc);
  7561. }
  7562. if (!expected->IsEquivalent(asmInfo->GetWasmSignature()))
  7563. {
  7564. JavascriptError::ThrowWebAssemblyRuntimeError(GetScriptContext(), WASMERR_SignatureMismatch);
  7565. }
  7566. #endif
  7567. }
  7568. #ifdef ASMJS_PLAT
  7569. template <typename ArrayType, typename RegType>
  7570. void InterpreterStackFrame::OP_LdArr(uint32 index, RegSlot regSlot)
  7571. {
  7572. JavascriptArrayBuffer* arr = GetAsmJsBuffer();
  7573. BYTE* buffer = arr->GetBuffer();
  7574. ArrayType val = index < (arr->GetByteLength()) ? *(ArrayType*)(buffer + index) : GetArrayViewOverflowVal<ArrayType>();
  7575. SetRegRaw<RegType>(regSlot, (RegType)val);
  7576. }
  7577. #endif
  7578. template <class T, typename T2>
  7579. void InterpreterStackFrame::OP_StSlotPrimitive(const unaligned T* playout)
  7580. {
  7581. T2* buffer = (T2*)GetNonVarReg(playout->Instance);
  7582. buffer[playout->SlotIndex] = GetRegRaw<T2>(playout->Value);
  7583. }
  7584. template <class T>
  7585. void InterpreterStackFrame::OP_LdAsmJsSlot(const unaligned T* playout)
  7586. {
  7587. Var * slotArray = (Var*)GetNonVarReg(playout->Instance);
  7588. SetRegRawPtr(playout->Value, slotArray[playout->SlotIndex]);
  7589. }
  7590. template <class T, typename T2>
  7591. void InterpreterStackFrame::OP_LdSlotPrimitive(const unaligned T* playout)
  7592. {
  7593. T2* buffer = (T2*)GetNonVarReg(playout->Instance);
  7594. SetRegRaw<T2>(playout->Value, buffer[playout->SlotIndex]);
  7595. }
  7596. #ifndef TEMP_DISABLE_ASMJS
  7597. template <class T>
  7598. void InterpreterStackFrame::OP_LdArrGeneric(const unaligned T* playout)
  7599. {
  7600. const uint32 index = (uint32)GetRegRawInt(playout->SlotIndex);
  7601. switch (playout->ViewType)
  7602. {
  7603. #define ARRAYBUFFER_VIEW(name, align, RegType, MemType, ...) \
  7604. case ArrayBufferView::ViewType::TYPE_##name: \
  7605. OP_LdArr<MemType, RegType>(index & ARRAYBUFFER_VIEW_MASK(align), playout->Value); \
  7606. return;
  7607. #include "AsmJsArrayBufferViews.h"
  7608. default:Assert(UNREACHED);
  7609. }
  7610. }
  7611. template<typename MemType>
  7612. void InterpreterStackFrame::WasmArrayBoundsCheck(uint64 index, uint32 byteLength)
  7613. {
  7614. if (index + sizeof(MemType) > byteLength)
  7615. {
  7616. JavascriptError::ThrowWebAssemblyRuntimeError(scriptContext, WASMERR_ArrayIndexOutOfRange);
  7617. }
  7618. }
  7619. template<typename MemType>
  7620. MemType* InterpreterStackFrame::WasmAtomicsArrayBoundsCheck(byte* buffer, uint64 index, uint32 byteLength)
  7621. {
  7622. MemType* readBuffer = (MemType*)(buffer + index);
  7623. // Do alignment check to be coherent with the order the jit does the checks
  7624. if (!::Math::IsAligned<intptr_t>((intptr_t)readBuffer, sizeof(MemType)))
  7625. {
  7626. JavascriptError::ThrowWebAssemblyRuntimeError(scriptContext, WASMERR_UnalignedAtomicAccess);
  7627. }
  7628. WasmArrayBoundsCheck<MemType>(index, byteLength);
  7629. return readBuffer;
  7630. }
  7631. template <class T>
  7632. void InterpreterStackFrame::OP_LdArrWasm(const unaligned T* playout)
  7633. {
  7634. #ifdef ENABLE_WASM
  7635. Assert(playout->ViewType < Js::ArrayBufferView::TYPE_COUNT);
  7636. const uint64 index = playout->Offset + (uint64)(uint32)GetRegRawInt(playout->SlotIndex);
  7637. ArrayBufferBase* arr = GetWebAssemblyMemory()->GetBuffer();
  7638. uint32 byteLength = arr->GetByteLength();
  7639. BYTE* buffer = arr->GetBuffer();
  7640. switch (playout->ViewType)
  7641. {
  7642. #define ARRAYBUFFER_VIEW(name, align, RegType, MemType, ...) \
  7643. case ArrayBufferView::ViewType::TYPE_##name: \
  7644. WasmArrayBoundsCheck<MemType>(index, byteLength); \
  7645. SetRegRaw<RegType>(playout->Value, (RegType)*(MemType*)(buffer + index)); \
  7646. return;
  7647. #include "AsmJsArrayBufferViews.h"
  7648. default:Assert(UNREACHED);
  7649. }
  7650. #else
  7651. Assert(UNREACHED);
  7652. #endif
  7653. }
  7654. template <class T>
  7655. void InterpreterStackFrame::OP_LdArrAtomic(const unaligned T* playout)
  7656. {
  7657. #ifdef ENABLE_WASM
  7658. Assert(Wasm::Threads::IsEnabled());
  7659. Assert(playout->ViewType < Js::ArrayBufferView::TYPE_COUNT);
  7660. const uint64 index = playout->Offset + (uint64)(uint32)GetRegRawInt(playout->SlotIndex);
  7661. ArrayBufferBase* arr = GetWebAssemblyMemory()->GetBuffer();
  7662. uint32 byteLength = arr->GetByteLength();
  7663. BYTE* buffer = arr->GetBuffer();
  7664. switch (playout->ViewType)
  7665. {
  7666. #define ARRAYBUFFER_VIEW_INT(name, align, RegType, MemType, ...) \
  7667. case ArrayBufferView::ViewType::TYPE_##name: {\
  7668. MemType* readBuffer = WasmAtomicsArrayBoundsCheck<MemType>(buffer, index, byteLength); \
  7669. MemType value = AtomicsOperations::Load<MemType>(readBuffer); \
  7670. SetRegRaw<RegType>(playout->Value, (RegType)value); \
  7671. return; \
  7672. }
  7673. #include "AsmJsArrayBufferViews.h"
  7674. default:Assert(UNREACHED);
  7675. }
  7676. #else
  7677. Assert(UNREACHED);
  7678. #endif
  7679. }
  7680. template <class T>
  7681. void InterpreterStackFrame::OP_StArrAtomic(const unaligned T* playout)
  7682. {
  7683. #ifdef ENABLE_WASM
  7684. Assert(Wasm::Threads::IsEnabled());
  7685. Assert(playout->ViewType < Js::ArrayBufferView::TYPE_COUNT);
  7686. const uint64 index = playout->Offset + (uint64)(uint32)GetRegRawInt(playout->SlotIndex);
  7687. ArrayBufferBase* arr = GetWebAssemblyMemory()->GetBuffer();
  7688. uint32 byteLength = arr->GetByteLength();
  7689. BYTE* buffer = arr->GetBuffer();
  7690. switch (playout->ViewType)
  7691. {
  7692. #define ARRAYBUFFER_VIEW_INT(name, align, RegType, MemType, ...) \
  7693. case ArrayBufferView::ViewType::TYPE_##name: {\
  7694. MemType* readBuffer = WasmAtomicsArrayBoundsCheck<MemType>(buffer, index, byteLength); \
  7695. MemType value = (MemType)GetRegRaw<RegType>(playout->Value); \
  7696. MemType storedValue = AtomicsOperations::Store<MemType>(readBuffer, value); \
  7697. Assert(storedValue == value); \
  7698. return; \
  7699. }
  7700. #include "AsmJsArrayBufferViews.h"
  7701. default:Assert(UNREACHED);
  7702. }
  7703. #else
  7704. Assert(UNREACHED);
  7705. #endif
  7706. }
  7707. template <class T>
  7708. void InterpreterStackFrame::OP_LdArrConstIndex(const unaligned T* playout)
  7709. {
  7710. switch (playout->ViewType)
  7711. {
  7712. #define ARRAYBUFFER_VIEW(name, align, RegType, MemType, ...) \
  7713. case ArrayBufferView::ViewType::TYPE_##name: \
  7714. OP_LdArr<MemType, RegType>(playout->SlotIndex, playout->Value); \
  7715. return;
  7716. #include "AsmJsArrayBufferViews.h"
  7717. default:Assert(UNREACHED);
  7718. }
  7719. }
  7720. template <class T>
  7721. void InterpreterStackFrame::OP_StArrGeneric(const unaligned T* playout)
  7722. {
  7723. const uint32 index = (uint32)GetRegRawInt(playout->SlotIndex);
  7724. switch (playout->ViewType)
  7725. {
  7726. #define ARRAYBUFFER_VIEW(name, align, RegType, MemType, ...) \
  7727. case ArrayBufferView::ViewType::TYPE_##name: \
  7728. OP_StArr<MemType, RegType>(index & ARRAYBUFFER_VIEW_MASK(align), playout->Value); \
  7729. return;
  7730. #include "AsmJsArrayBufferViews.h"
  7731. default:Assert(UNREACHED);
  7732. }
  7733. }
  7734. template <class T>
  7735. void InterpreterStackFrame::OP_StArrWasm(const unaligned T* playout)
  7736. {
  7737. #ifdef ENABLE_WASM
  7738. Assert(playout->ViewType < Js::ArrayBufferView::TYPE_COUNT);
  7739. const uint64 index = playout->Offset + (uint64)(uint32)GetRegRawInt(playout->SlotIndex);
  7740. ArrayBufferBase* arr = GetWebAssemblyMemory()->GetBuffer();
  7741. uint32 byteLength = arr->GetByteLength();
  7742. BYTE* buffer = arr->GetBuffer();
  7743. switch (playout->ViewType)
  7744. {
  7745. #define ARRAYBUFFER_VIEW(name, align, RegType, MemType, ...) \
  7746. case ArrayBufferView::ViewType::TYPE_##name: \
  7747. WasmArrayBoundsCheck<MemType>(index, byteLength); \
  7748. *(MemType*)(buffer + index) = (MemType)(GetRegRaw<RegType>(playout->Value)); \
  7749. break;
  7750. #include "AsmJsArrayBufferViews.h"
  7751. default:Assert(UNREACHED);
  7752. }
  7753. CompileAssert(ArrayBufferView::ViewType::TYPE_COUNT == 15);
  7754. #if DBG
  7755. if (PHASE_TRACE(WasmMemWritesPhase, m_functionBody))
  7756. {
  7757. GetWebAssemblyMemory()->TraceMemWrite(GetWebAssemblyMemory(), (uint32)GetRegRawInt(playout->SlotIndex), playout->Offset, playout->ViewType, (uint32)(size_t)this->DEBUG_currentByteOffset, scriptContext);
  7758. }
  7759. #endif
  7760. return;
  7761. #else
  7762. Assert(UNREACHED);
  7763. #endif
  7764. }
  7765. template <class T>
  7766. void InterpreterStackFrame::OP_StArrConstIndex(const unaligned T* playout)
  7767. {
  7768. switch (playout->ViewType)
  7769. {
  7770. #define ARRAYBUFFER_VIEW(name, align, RegType, MemType, ...) \
  7771. case ArrayBufferView::ViewType::TYPE_##name: \
  7772. OP_StArr<MemType, RegType>(playout->SlotIndex, playout->Value); \
  7773. return;
  7774. #include "AsmJsArrayBufferViews.h"
  7775. default:Assert(UNREACHED);
  7776. }
  7777. }
  7778. #endif
  7779. Var InterpreterStackFrame::OP_LdSlot(Var instance, int32 slotIndex)
  7780. {
  7781. if (!PHASE_OFF(ClosureRangeCheckPhase, this->m_functionBody))
  7782. {
  7783. if ((uintptr_t)((Var*)instance)[ScopeSlots::EncodedSlotCountSlotIndex] <= (uintptr_t)(slotIndex - ScopeSlots::FirstSlotIndex))
  7784. {
  7785. Js::Throw::FatalInternalError();
  7786. }
  7787. }
  7788. return ((Var*)(instance))[slotIndex];
  7789. }
  7790. template <class T>
  7791. Var InterpreterStackFrame::OP_LdSlot(Var instance, const unaligned T* playout)
  7792. {
  7793. return OP_LdSlot(instance, playout->SlotIndex);
  7794. }
  7795. #if ENABLE_PROFILE_INFO
  7796. template <class T>
  7797. Var InterpreterStackFrame::OP_ProfiledLdSlot(Var instance, const unaligned T* playout)
  7798. {
  7799. Var value = OP_LdSlot(instance, playout->SlotIndex);
  7800. ProfilingHelpers::ProfileLdSlot(value, GetFunctionBody(), playout->profileId);
  7801. return value;
  7802. }
  7803. #endif
  7804. template <class T>
  7805. Var InterpreterStackFrame::OP_LdInnerSlot(Var slotArray, const unaligned T* playout)
  7806. {
  7807. return OP_LdSlot(slotArray, playout->SlotIndex2);
  7808. }
  7809. #if ENABLE_PROFILE_INFO
  7810. template <class T>
  7811. Var InterpreterStackFrame::OP_ProfiledLdInnerSlot(Var slotArray, const unaligned T* playout)
  7812. {
  7813. Var value = OP_LdInnerSlot(slotArray, playout);
  7814. ProfilingHelpers::ProfileLdSlot(value, GetFunctionBody(), playout->profileId);
  7815. return value;
  7816. }
  7817. #endif
  7818. template <class T>
  7819. Var InterpreterStackFrame::OP_LdInnerObjSlot(Var slotArray, const unaligned T* playout)
  7820. {
  7821. return OP_LdObjSlot(slotArray, playout->SlotIndex2);
  7822. }
  7823. #if ENABLE_PROFILE_INFO
  7824. template <class T>
  7825. Var InterpreterStackFrame::OP_ProfiledLdInnerObjSlot(Var slotArray, const unaligned T* playout)
  7826. {
  7827. Var value = OP_LdInnerObjSlot(slotArray, playout);
  7828. ProfilingHelpers::ProfileLdSlot(value, GetFunctionBody(), playout->profileId);
  7829. return value;
  7830. }
  7831. #endif
  7832. Var InterpreterStackFrame::OP_LdFrameDisplaySlot(Var instance, int32 slotIndex)
  7833. {
  7834. if (!PHASE_OFF(ClosureRangeCheckPhase, this->m_functionBody))
  7835. {
  7836. if (((FrameDisplay*)instance)->GetLength() <= slotIndex - Js::FrameDisplay::GetOffsetOfScopes() / sizeof(Var))
  7837. {
  7838. Js::Throw::FatalInternalError();
  7839. }
  7840. }
  7841. return ((Var*)instance)[slotIndex];
  7842. }
  7843. template <class T>
  7844. Var InterpreterStackFrame::OP_LdEnvObj(Var instance, const unaligned T* playout)
  7845. {
  7846. return OP_LdFrameDisplaySlot(instance, playout->SlotIndex);
  7847. }
  7848. template <class T>
  7849. Var InterpreterStackFrame::OP_LdEnvSlot(Var instance, const unaligned T* playout)
  7850. {
  7851. Var slotArray = OP_LdFrameDisplaySlot(instance, playout->SlotIndex1);
  7852. return OP_LdSlot(slotArray, playout->SlotIndex2);
  7853. }
  7854. #if ENABLE_PROFILE_INFO
  7855. template <class T>
  7856. Var InterpreterStackFrame::OP_ProfiledLdEnvSlot(Var instance, const unaligned T* playout)
  7857. {
  7858. Var value = OP_LdEnvSlot(instance, playout);
  7859. ProfilingHelpers::ProfileLdSlot(value, GetFunctionBody(), playout->profileId);
  7860. return value;
  7861. }
  7862. #endif
  7863. Var InterpreterStackFrame::OP_LdObjSlot(Var instance, int32 slotIndex)
  7864. {
  7865. Var *slotArray = *(Var**)((char*)instance + DynamicObject::GetOffsetOfAuxSlots());
  7866. return slotArray[slotIndex];
  7867. }
  7868. template <class T>
  7869. Var InterpreterStackFrame::OP_LdObjSlot(Var instance, const unaligned T* playout)
  7870. {
  7871. return OP_LdObjSlot(instance, playout->SlotIndex);
  7872. }
  7873. #if ENABLE_PROFILE_INFO
  7874. template <class T>
  7875. Var InterpreterStackFrame::OP_ProfiledLdObjSlot(Var instance, const unaligned T* playout)
  7876. {
  7877. Var value = OP_LdObjSlot(instance, playout->SlotIndex);
  7878. ProfilingHelpers::ProfileLdSlot(value, GetFunctionBody(), playout->profileId);
  7879. return value;
  7880. }
  7881. #endif
  7882. template <class T>
  7883. Var InterpreterStackFrame::OP_LdEnvObjSlot(Var instance, const unaligned T* playout)
  7884. {
  7885. Var slotArray = OP_LdFrameDisplaySlot(instance, playout->SlotIndex1);
  7886. return OP_LdObjSlot(slotArray, playout->SlotIndex2);
  7887. }
  7888. template <class T>
  7889. Var InterpreterStackFrame::OP_LdModuleSlot(Var instance, const unaligned T* playout)
  7890. {
  7891. return JavascriptOperators::OP_LdModuleSlot(playout->SlotIndex1, playout->SlotIndex2, scriptContext);
  7892. }
  7893. inline void InterpreterStackFrame::OP_StModuleSlot(Var instance, uint32 slotIndex1, uint32 slotIndex2, Var value)
  7894. {
  7895. JavascriptOperators::OP_StModuleSlot(slotIndex1, slotIndex2, value, scriptContext);
  7896. }
  7897. #if ENABLE_PROFILE_INFO
  7898. template <class T>
  7899. Var InterpreterStackFrame::OP_ProfiledLdEnvObjSlot(Var instance, const unaligned T* playout)
  7900. {
  7901. Var value = OP_LdEnvObjSlot(instance, playout);
  7902. ProfilingHelpers::ProfileLdSlot(value, GetFunctionBody(), playout->profileId);
  7903. return value;
  7904. }
  7905. #endif
  7906. void InterpreterStackFrame::OP_StSlot(Var instance, int32 slotIndex, Var value)
  7907. {
  7908. // We emit OpCode::StSlot in the bytecode only for scope slot arrays, which are not recyclable objects.
  7909. if (!PHASE_OFF(ClosureRangeCheckPhase, this->m_functionBody))
  7910. {
  7911. if ((uintptr_t)((Var*)instance)[ScopeSlots::EncodedSlotCountSlotIndex] <= (uintptr_t)(slotIndex - ScopeSlots::FirstSlotIndex))
  7912. {
  7913. Js::Throw::FatalInternalError();
  7914. }
  7915. }
  7916. ((Field(Var)*)(instance))[slotIndex] = value;
  7917. }
  7918. void InterpreterStackFrame::OP_StEnvSlot(Var instance, int32 slotIndex1, int32 slotIndex2, Var value)
  7919. {
  7920. Var slotArray = (Var*)OP_LdFrameDisplaySlot(instance, slotIndex1);
  7921. OP_StSlot(slotArray, slotIndex2, value);
  7922. }
  7923. void InterpreterStackFrame::OP_StSlotChkUndecl(Var instance, int32 slotIndex, Var value)
  7924. {
  7925. // We emit OpCode::StSlot in the bytecode only for scope slot arrays, which are not recyclable objects.
  7926. if (!PHASE_OFF(ClosureRangeCheckPhase, this->m_functionBody))
  7927. {
  7928. if ((uintptr_t)((Var*)instance)[ScopeSlots::EncodedSlotCountSlotIndex] <= (uintptr_t)(slotIndex - ScopeSlots::FirstSlotIndex))
  7929. {
  7930. Js::Throw::FatalInternalError();
  7931. }
  7932. }
  7933. OP_ChkUndecl(((Field(Var)*)instance)[slotIndex]);
  7934. ((Field(Var)*)(instance))[slotIndex] = value;
  7935. }
  7936. void InterpreterStackFrame::OP_StEnvSlotChkUndecl(Var instance, int32 slotIndex1, int32 slotIndex2, Var value)
  7937. {
  7938. Var slotArray = OP_LdFrameDisplaySlot(instance, slotIndex1);
  7939. OP_StSlotChkUndecl(slotArray, slotIndex2, value);
  7940. }
  7941. void InterpreterStackFrame::OP_StObjSlot(Var instance, int32 slotIndex, Var value)
  7942. {
  7943. // It would be nice to assert that it's ok to store directly to slot, but we don't have the propertyId.
  7944. Field(Var) *slotArray = *(Field(Var)**)((char*)instance + DynamicObject::GetOffsetOfAuxSlots());
  7945. slotArray[slotIndex] = value;
  7946. }
  7947. void InterpreterStackFrame::OP_StObjSlotChkUndecl(Var instance, int32 slotIndex, Var value)
  7948. {
  7949. // It would be nice to assert that it's ok to store directly to slot, but we don't have the propertyId.
  7950. Field(Var) *slotArray = *(Field(Var)**)((char*)instance + DynamicObject::GetOffsetOfAuxSlots());
  7951. OP_ChkUndecl(slotArray[slotIndex]);
  7952. slotArray[slotIndex] = value;
  7953. }
  7954. void InterpreterStackFrame::OP_StEnvObjSlot(Var instance, int32 slotIndex1, int32 slotIndex2, Var value)
  7955. {
  7956. // It would be nice to assert that it's ok to store directly to slot, but we don't have the propertyId.
  7957. Var envInstance = (Var*)OP_LdFrameDisplaySlot(instance, slotIndex1);
  7958. OP_StObjSlot(envInstance, slotIndex2, value);
  7959. }
  7960. void InterpreterStackFrame::OP_StEnvObjSlotChkUndecl(Var instance, int32 slotIndex1, int32 slotIndex2, Var value)
  7961. {
  7962. // It would be nice to assert that it's ok to store directly to slot, but we don't have the propertyId.
  7963. Var envInstance = (Var*)OP_LdFrameDisplaySlot(instance, slotIndex1);
  7964. OP_StObjSlotChkUndecl(envInstance, slotIndex2, value);
  7965. }
  7966. Var InterpreterStackFrame::OP_LdStackArgPtr(void)
  7967. {
  7968. // Return the address of the first param after "this".
  7969. return m_inParams + 1;
  7970. }
  7971. ForInObjectEnumerator * InterpreterStackFrame::GetForInEnumerator(uint forInLoopLevel)
  7972. {
  7973. Assert(forInLoopLevel < this->m_functionBody->GetForInLoopDepth());
  7974. return &this->forInObjectEnumerators[forInLoopLevel];
  7975. }
  7976. void InterpreterStackFrame::OP_InitForInEnumerator(Var object, uint forInLoopLevel)
  7977. {
  7978. JavascriptOperators::OP_InitForInEnumerator(object, GetForInEnumerator(forInLoopLevel), this->GetScriptContext());
  7979. }
  7980. void InterpreterStackFrame::OP_InitForInEnumeratorWithCache(Var object, uint forInLoopLevel, ProfileId profileId)
  7981. {
  7982. JavascriptOperators::OP_InitForInEnumerator(object, GetForInEnumerator(forInLoopLevel), this->GetScriptContext(),
  7983. m_functionBody->GetForInCache(profileId));
  7984. }
  7985. // Called for the debug purpose, to create the arguments object explicitly even though script has not declared it.
  7986. Var InterpreterStackFrame::CreateHeapArguments(ScriptContext* scriptContext)
  7987. {
  7988. return JavascriptOperators::LoadHeapArguments(this->function->GetRealFunctionObject(), this->m_inSlotsCount - 1, &this->m_inParams[1], scriptContext->GetLibrary()->GetNull(), scriptContext->GetLibrary()->GetNull(), scriptContext, false);
  7989. }
  7990. template <bool letArgs>
  7991. Var InterpreterStackFrame::LdHeapArgumentsImpl(Var argsArray, ScriptContext* scriptContext)
  7992. {
  7993. Var frameObj;
  7994. if (m_functionBody->HasScopeObject() && argsArray != scriptContext->GetLibrary()->GetNull())
  7995. {
  7996. frameObj = this->localClosure;
  7997. Assert(frameObj);
  7998. }
  7999. else
  8000. {
  8001. frameObj = scriptContext->GetLibrary()->GetNull();
  8002. }
  8003. Var args = JavascriptOperators::LoadHeapArguments(this->function->GetRealFunctionObject(), this->m_inSlotsCount - 1, &this->m_inParams[1], frameObj, argsArray, scriptContext, letArgs);
  8004. this->m_arguments = args;
  8005. return args;
  8006. }
  8007. Var InterpreterStackFrame::OP_LdHeapArguments(ScriptContext* scriptContext)
  8008. {
  8009. Var argsArray = m_functionBody->GetFormalsPropIdArrayOrNullObj();
  8010. return LdHeapArgumentsImpl<false>(argsArray, scriptContext);
  8011. }
  8012. Var InterpreterStackFrame::OP_LdLetHeapArguments(ScriptContext* scriptContext)
  8013. {
  8014. Var argsArray = m_functionBody->GetFormalsPropIdArrayOrNullObj();
  8015. return LdHeapArgumentsImpl<true>(argsArray, scriptContext);
  8016. }
  8017. Var InterpreterStackFrame::OP_LdHeapArgsCached(ScriptContext* scriptContext)
  8018. {
  8019. uint32 formalsCount = this->m_functionBody->GetInParamsCount() - 1;
  8020. Var args = JavascriptOperators::LoadHeapArgsCached(this->function->GetRealFunctionObject(), this->m_inSlotsCount - 1, formalsCount, &this->m_inParams[1], this->localClosure, scriptContext, false);
  8021. this->m_arguments = args;
  8022. return args;
  8023. }
  8024. Var InterpreterStackFrame::OP_LdLetHeapArgsCached(ScriptContext* scriptContext)
  8025. {
  8026. uint32 formalsCount = this->m_functionBody->GetInParamsCount() - 1;
  8027. Var args = JavascriptOperators::LoadHeapArgsCached(this->function->GetRealFunctionObject(), this->m_inSlotsCount - 1, formalsCount, &this->m_inParams[1], this->localClosure, scriptContext, true);
  8028. this->m_arguments = args;
  8029. return args;
  8030. }
  8031. HeapArgumentsObject * InterpreterStackFrame::CreateEmptyHeapArgumentsObject(ScriptContext* scriptContext)
  8032. {
  8033. HeapArgumentsObject * args = JavascriptOperators::CreateHeapArguments(this->function->GetRealFunctionObject(), this->m_inSlotsCount - 1, 0, nullptr, scriptContext);
  8034. this->m_arguments = args;
  8035. return args;
  8036. }
  8037. void InterpreterStackFrame::TrySetFrameObjectInHeapArgObj(ScriptContext * scriptContext, bool hasNonSimpleParams, bool isScopeObjRestored)
  8038. {
  8039. Var frameObject = nullptr;
  8040. uint32 formalsCount = this->m_functionBody->GetInParamsCount() - 1;
  8041. Js::PropertyIdArray * propIds = nullptr;
  8042. Js::HeapArgumentsObject* heapArgObj = nullptr;
  8043. //We always set the Frame object to nullptr in BailOutRecord::EnsureArguments for stack args optimization.
  8044. if (m_arguments != nullptr && ((Js::HeapArgumentsObject*)(m_arguments))->GetFrameObject() == nullptr)
  8045. {
  8046. heapArgObj = (Js::HeapArgumentsObject*)m_arguments;
  8047. }
  8048. bool isCachedScope = false;
  8049. //For Non-simple params, we don't have a scope object created.
  8050. if (this->m_functionBody->NeedScopeObjectForArguments(hasNonSimpleParams))
  8051. {
  8052. frameObject = GetLocalClosure();
  8053. isCachedScope = m_functionBody->HasCachedScopePropIds();
  8054. propIds = this->m_functionBody->GetFormalsPropIdArray();
  8055. if (isScopeObjRestored && ActivationObject::Is(frameObject))
  8056. {
  8057. Assert(this->GetFunctionBody()->GetDoScopeObjectCreation());
  8058. isCachedScope = true;
  8059. if (PHASE_VERBOSE_TRACE1(Js::StackArgFormalsOptPhase) && m_functionBody->GetInParamsCount() > 1)
  8060. {
  8061. Output::Print(_u("StackArgFormals : %s (%d) :Using the restored scope object in the bail out path. \n"), m_functionBody->GetDisplayName(), m_functionBody->GetFunctionNumber());
  8062. Output::Flush();
  8063. }
  8064. }
  8065. else
  8066. {
  8067. if (isCachedScope)
  8068. {
  8069. Field(DynamicType*) literalType = nullptr;
  8070. Assert(!propIds->hasNonSimpleParams && !hasNonSimpleParams);
  8071. frameObject = JavascriptOperators::OP_InitCachedScope(this->GetJavascriptFunction(), propIds, &literalType, hasNonSimpleParams, scriptContext);
  8072. }
  8073. else
  8074. {
  8075. frameObject = JavascriptOperators::OP_NewScopeObject(GetScriptContext());
  8076. }
  8077. Assert(propIds != nullptr);
  8078. SetLocalClosure(frameObject);
  8079. if (PHASE_VERBOSE_TRACE1(Js::StackArgFormalsOptPhase) && m_functionBody->GetInParamsCount() > 1)
  8080. {
  8081. Output::Print(_u("StackArgFormals : %s (%d) :Creating scope object in the bail out path. \n"), m_functionBody->GetDisplayName(), m_functionBody->GetFunctionNumber());
  8082. Output::Flush();
  8083. }
  8084. }
  8085. }
  8086. else
  8087. {
  8088. //We reached here because, either we don't have any formals or we don't have a scope object (it could be in strict mode or have non-simple param list)
  8089. Assert(formalsCount == 0 || (m_functionBody->GetIsStrictMode() || hasNonSimpleParams));
  8090. frameObject = nullptr;
  8091. formalsCount = 0;
  8092. if (PHASE_VERBOSE_TRACE1(Js::StackArgOptPhase))
  8093. {
  8094. Output::Print(_u("StackArgOpt : %s (%d) :Creating NULL scope object in the bail out path. \n"), m_functionBody->GetDisplayName(), m_functionBody->GetFunctionNumber());
  8095. Output::Flush();
  8096. }
  8097. }
  8098. if (heapArgObj)
  8099. {
  8100. Assert(frameObject == nullptr || ActivationObject::Is(frameObject));
  8101. heapArgObj->SetFormalCount(formalsCount);
  8102. heapArgObj->SetFrameObject(frameObject != nullptr ?
  8103. static_cast<ActivationObject*>(frameObject) : nullptr);
  8104. if (PHASE_TRACE1(Js::StackArgFormalsOptPhase) && formalsCount > 0)
  8105. {
  8106. Output::Print(_u("StackArgFormals : %s (%d) :Attaching the scope object with the heap arguments object in the bail out path. \n"), m_functionBody->GetDisplayName(), m_functionBody->GetFunctionNumber());
  8107. Output::Flush();
  8108. }
  8109. }
  8110. //Fill the Heap arguments and scope object with values
  8111. // If there is no heap arguments object, then fill only the scope object with actuals.
  8112. JavascriptOperators::FillScopeObject(this->function->GetRealFunctionObject(), this->m_inSlotsCount - 1, formalsCount, frameObject, &this->m_inParams[1], propIds, heapArgObj, scriptContext, hasNonSimpleParams, isCachedScope);
  8113. }
  8114. Var InterpreterStackFrame::OP_LdArgumentsFromFrame()
  8115. {
  8116. return this->m_arguments;
  8117. }
  8118. void* InterpreterStackFrame::OP_LdArgCnt()
  8119. {
  8120. return (void*)m_inSlotsCount;
  8121. }
  8122. Var InterpreterStackFrame::OP_ResumeYield(Var yieldDataVar, RegSlot yieldStarIterator)
  8123. {
  8124. ResumeYieldData* yieldData = static_cast<ResumeYieldData*>(yieldDataVar);
  8125. RecyclableObject* iterator = yieldStarIterator != Constants::NoRegister ? RecyclableObject::FromVar(GetNonVarReg(yieldStarIterator)) : nullptr;
  8126. return JavascriptOperators::OP_ResumeYield(yieldData, iterator);
  8127. }
  8128. void* InterpreterStackFrame::operator new(size_t byteSize, void* previousAllocation) throw()
  8129. {
  8130. //
  8131. // Placement 'new' is used by InterpreterStackFrame to initialize the C++ object on the RcInterpreter's
  8132. // program stack:
  8133. // - Unlike most other allocations, the previously allocated memory will __not__ be
  8134. // zero-initialized, as we do not want the overhead of zero-initializing the frame when
  8135. // calling functions.
  8136. //
  8137. // NOTE: If we wanted to add C# semantics of all locals are automatically zero-initialized,
  8138. // need to determine the most efficient mechanism for this.
  8139. //
  8140. return previousAllocation;
  8141. }
  8142. void __cdecl InterpreterStackFrame::operator delete(void * allocationToFree, void * previousAllocation) throw()
  8143. {
  8144. AssertMsg(allocationToFree == previousAllocation, "Memory locations should match");
  8145. AssertMsg(false, "This function should never actually be called");
  8146. }
  8147. void InterpreterStackFrame::OP_WasmPrintFunc(int regIndex)
  8148. {
  8149. #if defined(ENABLE_DEBUG_CONFIG_OPTIONS) && defined(ENABLE_WASM)
  8150. Assert(m_functionBody->IsWasmFunction());
  8151. uint index = GetRegRawInt(regIndex);
  8152. Wasm::WasmFunctionInfo* info = m_functionBody->GetAsmJsFunctionInfo()->GetWebAssemblyModule()->GetWasmFunctionInfo(index);
  8153. int col = WAsmJs::Tracing::GetPrintCol();
  8154. if (col > 0)
  8155. {
  8156. Output::SkipToColumn(col);
  8157. }
  8158. info->GetBody()->DumpFullFunctionName();
  8159. Output::Print(_u("("));
  8160. #endif
  8161. }
  8162. JavascriptArrayBuffer* InterpreterStackFrame::GetAsmJsBuffer() const
  8163. {
  8164. AssertMsg(!m_functionBody->IsWasmFunction(), "Do not use GetAsmJsBuffer for WebAssembly, Use GetWebAssemblyMemory instead");
  8165. return m_asmJsBuffer;
  8166. }
  8167. #ifdef ENABLE_WASM
  8168. WebAssemblyMemory* InterpreterStackFrame::GetWebAssemblyMemory() const
  8169. {
  8170. AssertMsg(m_functionBody->IsWasmFunction(), "Do not use GetWebAssemblyMemory for Asm.js, Use GetAsmJsBuffer instead");
  8171. return m_wasmMemory;
  8172. }
  8173. #endif
  8174. template void* Js::InterpreterStackFrame::GetReg<unsigned int>(unsigned int) const;
  8175. template void Js::InterpreterStackFrame::SetReg<unsigned int>(unsigned int, void*);
  8176. } // namespace Js
  8177. // Make sure the macro and the layout for the op is consistent
  8178. #define DEF2(x, op, ...) \
  8179. CompileAssert(!Js::OpCodeInfo<Js::OpCode::op>::HasMultiSizeLayout); \
  8180. CompileAssert(!Js::OpCodeInfo<Js::OpCode::op>::IsExtendedOpcode);
  8181. #define DEF3(x, op, ...) DEF2(x, op)
  8182. #define EXDEF2(x, op, ...) \
  8183. CompileAssert(!Js::OpCodeInfo<Js::OpCode::op>::HasMultiSizeLayout); \
  8184. CompileAssert(Js::OpCodeInfo<Js::OpCode::op>::IsExtendedOpcode);
  8185. #define EXDEF3(x, op, ...) EXDEF2(x, op)
  8186. #define DEF2_WMS(x, op, ...) \
  8187. CompileAssert(Js::OpCodeInfo<Js::OpCode::op>::HasMultiSizeLayout); \
  8188. CompileAssert(!Js::OpCodeInfo<Js::OpCode::op>::IsExtendedOpcode);
  8189. #define DEF3_WMS(x, op, ...) DEF2_WMS(x, op)
  8190. #define EXDEF2_WMS(x, op, ...) \
  8191. CompileAssert(Js::OpCodeInfo<Js::OpCode::op>::HasMultiSizeLayout); \
  8192. CompileAssert(Js::OpCodeInfo<Js::OpCode::op>::IsExtendedOpcode);
  8193. #define EXDEF3_WMS(x, op, ...) EXDEF2_WMS(x, op)
  8194. #include "InterpreterHandler.inl"
  8195. // Make sure the macro and the layout for the op is consistent
  8196. #define DEF2(x, op, ...) \
  8197. CompileAssert(!Js::OpCodeInfoAsmJs<Js::OpCodeAsmJs::op>::HasMultiSizeLayout); \
  8198. CompileAssert(!Js::OpCodeInfoAsmJs<Js::OpCodeAsmJs::op>::IsExtendedOpcode);
  8199. #define DEF3(x, op, ...) DEF2(x, op)
  8200. #define DEF4(x, op, ...) DEF2(x, op)
  8201. #define EXDEF2(x, op, ...) \
  8202. CompileAssert(!Js::OpCodeInfoAsmJs<Js::OpCodeAsmJs::op>::HasMultiSizeLayout); \
  8203. CompileAssert(Js::OpCodeInfoAsmJs<Js::OpCodeAsmJs::op>::IsExtendedOpcode);
  8204. #define EXDEF3(x, op, ...) EXDEF2(x, op)
  8205. #define EXDEF4(x, op, ...) EXDEF2(x, op)
  8206. #define DEF2_WMS(x, op, ...) \
  8207. CompileAssert(Js::OpCodeInfoAsmJs<Js::OpCodeAsmJs::op>::HasMultiSizeLayout); \
  8208. CompileAssert(!Js::OpCodeInfoAsmJs<Js::OpCodeAsmJs::op>::IsExtendedOpcode);
  8209. #define DEF3_WMS(x, op, ...) DEF2_WMS(x, op)
  8210. #define DEF4_WMS(x, op, ...) DEF2_WMS(x, op)
  8211. #define EXDEF2_WMS(x, op, ...) \
  8212. CompileAssert(Js::OpCodeInfoAsmJs<Js::OpCodeAsmJs::op>::HasMultiSizeLayout); \
  8213. CompileAssert(Js::OpCodeInfoAsmJs<Js::OpCodeAsmJs::op>::IsExtendedOpcode);
  8214. #define EXDEF3_WMS(x, op, ...) EXDEF2_WMS(x, op)
  8215. #define EXDEF4_WMS(x, op, ...) EXDEF2_WMS(x, op)
  8216. #include "InterpreterHandlerAsmJs.inl"