InterpreterStackFrame.cpp 360 KB

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