InterpreterStackFrame.cpp 362 KB

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