InterpreterStackFrame.cpp 360 KB

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