InterpreterStackFrame.cpp 361 KB

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