InterpreterStackFrame.cpp 326 KB

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