InterpreterStackFrame.cpp 360 KB

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