CodeBlock.cpp 138 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485
  1. /*
  2. * Copyright (C) 2008, 2009, 2010, 2012, 2013 Apple Inc. All rights reserved.
  3. * Copyright (C) 2008 Cameron Zwarich <cwzwarich@uwaterloo.ca>
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. *
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
  15. * its contributors may be used to endorse or promote products derived
  16. * from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
  19. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  20. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21. * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
  22. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  23. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  24. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  25. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  27. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. */
  29. #include "config.h"
  30. #include "CodeBlock.h"
  31. #include "BytecodeGenerator.h"
  32. #include "CallLinkStatus.h"
  33. #include "DFGCapabilities.h"
  34. #include "DFGCommon.h"
  35. #include "DFGNode.h"
  36. #include "DFGRepatch.h"
  37. #include "Debugger.h"
  38. #include "Interpreter.h"
  39. #include "JIT.h"
  40. #include "JITStubs.h"
  41. #include "JSActivation.h"
  42. #include "JSCJSValue.h"
  43. #include "JSFunction.h"
  44. #include "JSNameScope.h"
  45. #include "LowLevelInterpreter.h"
  46. #include "Operations.h"
  47. #include "ReduceWhitespace.h"
  48. #include "RepatchBuffer.h"
  49. #include "SlotVisitorInlines.h"
  50. #include <stdio.h>
  51. #include <wtf/CommaPrinter.h>
  52. #include <wtf/StringExtras.h>
  53. #include <wtf/StringPrintStream.h>
  54. #if ENABLE(DFG_JIT)
  55. #include "DFGOperations.h"
  56. #endif
  57. #if ENABLE(DETACHED_JIT)
  58. #pragma message "[SECURE JSCORE] CodeBlock::compilation has been disabled"
  59. #endif
  60. #define DUMP_CODE_BLOCK_STATISTICS 0
  61. namespace JSC {
  62. #if !(ENABLE(DETACHED_JIT) && BUILDING_DETACHED_JIT)
  63. #if ENABLE(DFG_JIT)
  64. using namespace DFG;
  65. #endif
  66. String CodeBlock::inferredName() const
  67. {
  68. switch (codeType()) {
  69. case GlobalCode:
  70. return "<global>";
  71. case EvalCode:
  72. return "<eval>";
  73. case FunctionCode:
  74. return jsCast<FunctionExecutable*>(ownerExecutable())->inferredName().string();
  75. default:
  76. CRASH();
  77. return String();
  78. }
  79. }
  80. CodeBlockHash CodeBlock::hash() const
  81. {
  82. return CodeBlockHash(ownerExecutable()->source(), specializationKind());
  83. }
  84. String CodeBlock::sourceCodeForTools() const
  85. {
  86. if (codeType() != FunctionCode)
  87. return ownerExecutable()->source().toString();
  88. SourceProvider* provider = source();
  89. FunctionExecutable* executable = jsCast<FunctionExecutable*>(ownerExecutable());
  90. UnlinkedFunctionExecutable* unlinked = executable->unlinkedExecutable();
  91. unsigned unlinkedStartOffset = unlinked->startOffset();
  92. unsigned linkedStartOffset = executable->source().startOffset();
  93. int delta = linkedStartOffset - unlinkedStartOffset;
  94. StringBuilder builder;
  95. builder.append("function ");
  96. builder.append(provider->getRange(
  97. delta + unlinked->functionStartOffset(),
  98. delta + unlinked->startOffset() + unlinked->sourceLength()));
  99. return builder.toString();
  100. }
  101. String CodeBlock::sourceCodeOnOneLine() const
  102. {
  103. return reduceWhitespace(sourceCodeForTools());
  104. }
  105. void CodeBlock::dumpAssumingJITType(PrintStream& out, JITCode::JITType jitType) const
  106. {
  107. out.print(inferredName(), "#", hash(), ":[", RawPointer(this), "->", RawPointer(ownerExecutable()), ", ", jitType, codeType());
  108. if (codeType() == FunctionCode)
  109. out.print(specializationKind());
  110. out.print("]");
  111. }
  112. void CodeBlock::dump(PrintStream& out) const
  113. {
  114. dumpAssumingJITType(out, getJITType());
  115. }
  116. static String escapeQuotes(const String& str)
  117. {
  118. String result = str;
  119. size_t pos = 0;
  120. while ((pos = result.find('\"', pos)) != notFound) {
  121. result = makeString(result.substringSharingImpl(0, pos), "\"\\\"\"", result.substringSharingImpl(pos + 1));
  122. pos += 4;
  123. }
  124. return result;
  125. }
  126. static String valueToSourceString(ExecState* exec, JSValue val)
  127. {
  128. if (!val)
  129. return ASCIILiteral("0");
  130. if (val.isString())
  131. return makeString("\"", escapeQuotes(val.toString(exec)->value(exec)), "\"");
  132. return toString(val);
  133. }
  134. static CString constantName(ExecState* exec, int k, JSValue value)
  135. {
  136. return makeString(valueToSourceString(exec, value), "(@k", String::number(k - FirstConstantRegisterIndex), ")").utf8();
  137. }
  138. static CString idName(int id0, const Identifier& ident)
  139. {
  140. return makeString(ident.string(), "(@id", String::number(id0), ")").utf8();
  141. }
  142. CString CodeBlock::registerName(ExecState* exec, int r) const
  143. {
  144. if (r == missingThisObjectMarker())
  145. return "<null>";
  146. if (isConstantRegisterIndex(r))
  147. return constantName(exec, r, getConstant(r));
  148. return makeString("r", String::number(r)).utf8();
  149. }
  150. static String regexpToSourceString(RegExp* regExp)
  151. {
  152. char postfix[5] = { '/', 0, 0, 0, 0 };
  153. int index = 1;
  154. if (regExp->global())
  155. postfix[index++] = 'g';
  156. if (regExp->ignoreCase())
  157. postfix[index++] = 'i';
  158. if (regExp->multiline())
  159. postfix[index] = 'm';
  160. return makeString("/", regExp->pattern(), postfix);
  161. }
  162. static CString regexpName(int re, RegExp* regexp)
  163. {
  164. return makeString(regexpToSourceString(regexp), "(@re", String::number(re), ")").utf8();
  165. }
  166. static String pointerToSourceString(void* p)
  167. {
  168. char buffer[2 + 2 * sizeof(void*) + 1]; // 0x [two characters per byte] \0
  169. snprintf(buffer, sizeof(buffer), "%p", p);
  170. return buffer;
  171. }
  172. NEVER_INLINE static const char* debugHookName(int debugHookID)
  173. {
  174. switch (static_cast<DebugHookID>(debugHookID)) {
  175. case DidEnterCallFrame:
  176. return "didEnterCallFrame";
  177. case WillLeaveCallFrame:
  178. return "willLeaveCallFrame";
  179. case WillExecuteStatement:
  180. return "willExecuteStatement";
  181. case WillExecuteProgram:
  182. return "willExecuteProgram";
  183. case DidExecuteProgram:
  184. return "didExecuteProgram";
  185. case DidReachBreakpoint:
  186. return "didReachBreakpoint";
  187. }
  188. RELEASE_ASSERT_NOT_REACHED();
  189. return "";
  190. }
  191. void CodeBlock::printUnaryOp(PrintStream& out, ExecState* exec, int location, const Instruction*& it, const char* op)
  192. {
  193. int r0 = (++it)->u.operand;
  194. int r1 = (++it)->u.operand;
  195. out.printf("[%4d] %s\t\t %s, %s", location, op, registerName(exec, r0).data(), registerName(exec, r1).data());
  196. }
  197. void CodeBlock::printBinaryOp(PrintStream& out, ExecState* exec, int location, const Instruction*& it, const char* op)
  198. {
  199. int r0 = (++it)->u.operand;
  200. int r1 = (++it)->u.operand;
  201. int r2 = (++it)->u.operand;
  202. out.printf("[%4d] %s\t\t %s, %s, %s", location, op, registerName(exec, r0).data(), registerName(exec, r1).data(), registerName(exec, r2).data());
  203. }
  204. void CodeBlock::printConditionalJump(PrintStream& out, ExecState* exec, const Instruction*, const Instruction*& it, int location, const char* op)
  205. {
  206. int r0 = (++it)->u.operand;
  207. int offset = (++it)->u.operand;
  208. out.printf("[%4d] %s\t\t %s, %d(->%d)", location, op, registerName(exec, r0).data(), offset, location + offset);
  209. }
  210. void CodeBlock::printGetByIdOp(PrintStream& out, ExecState* exec, int location, const Instruction*& it)
  211. {
  212. const char* op;
  213. switch (exec->interpreter()->getOpcodeID(it->u.opcode)) {
  214. case op_get_by_id:
  215. op = "get_by_id";
  216. break;
  217. case op_get_by_id_out_of_line:
  218. op = "get_by_id_out_of_line";
  219. break;
  220. case op_get_by_id_self:
  221. op = "get_by_id_self";
  222. break;
  223. case op_get_by_id_proto:
  224. op = "get_by_id_proto";
  225. break;
  226. case op_get_by_id_chain:
  227. op = "get_by_id_chain";
  228. break;
  229. case op_get_by_id_getter_self:
  230. op = "get_by_id_getter_self";
  231. break;
  232. case op_get_by_id_getter_proto:
  233. op = "get_by_id_getter_proto";
  234. break;
  235. case op_get_by_id_getter_chain:
  236. op = "get_by_id_getter_chain";
  237. break;
  238. case op_get_by_id_custom_self:
  239. op = "get_by_id_custom_self";
  240. break;
  241. case op_get_by_id_custom_proto:
  242. op = "get_by_id_custom_proto";
  243. break;
  244. case op_get_by_id_custom_chain:
  245. op = "get_by_id_custom_chain";
  246. break;
  247. case op_get_by_id_generic:
  248. op = "get_by_id_generic";
  249. break;
  250. case op_get_array_length:
  251. op = "array_length";
  252. break;
  253. case op_get_string_length:
  254. op = "string_length";
  255. break;
  256. default:
  257. RELEASE_ASSERT_NOT_REACHED();
  258. op = 0;
  259. }
  260. int r0 = (++it)->u.operand;
  261. int r1 = (++it)->u.operand;
  262. int id0 = (++it)->u.operand;
  263. out.printf("[%4d] %s\t %s, %s, %s", location, op, registerName(exec, r0).data(), registerName(exec, r1).data(), idName(id0, m_identifiers[id0]).data());
  264. it += 4; // Increment up to the value profiler.
  265. }
  266. #if ENABLE(JIT) || ENABLE(LLINT) // unused in some configurations
  267. static void dumpStructure(PrintStream& out, const char* name, ExecState* exec, Structure* structure, Identifier& ident)
  268. {
  269. if (!structure)
  270. return;
  271. out.printf("%s = %p", name, structure);
  272. PropertyOffset offset = structure->get(exec->vm(), ident);
  273. if (offset != invalidOffset)
  274. out.printf(" (offset = %d)", offset);
  275. }
  276. #endif
  277. #if ENABLE(JIT) // unused when not ENABLE(JIT), leading to silly warnings
  278. static void dumpChain(PrintStream& out, ExecState* exec, StructureChain* chain, Identifier& ident)
  279. {
  280. out.printf("chain = %p: [", chain);
  281. bool first = true;
  282. for (WriteBarrier<Structure>* currentStructure = chain->head();
  283. *currentStructure;
  284. ++currentStructure) {
  285. if (first)
  286. first = false;
  287. else
  288. out.printf(", ");
  289. dumpStructure(out, "struct", exec, currentStructure->get(), ident);
  290. }
  291. out.printf("]");
  292. }
  293. #endif
  294. void CodeBlock::printGetByIdCacheStatus(PrintStream& out, ExecState* exec, int location)
  295. {
  296. Instruction* instruction = instructions().begin() + location;
  297. Identifier& ident = identifier(instruction[3].u.operand);
  298. UNUSED_PARAM(ident); // tell the compiler to shut up in certain platform configurations.
  299. #if ENABLE(LLINT)
  300. if (exec->interpreter()->getOpcodeID(instruction[0].u.opcode) == op_get_array_length)
  301. out.printf(" llint(array_length)");
  302. else if (Structure* structure = instruction[4].u.structure.get()) {
  303. out.printf(" llint(");
  304. dumpStructure(out, "struct", exec, structure, ident);
  305. out.printf(")");
  306. }
  307. #endif
  308. #if ENABLE(JIT)
  309. if (numberOfStructureStubInfos()) {
  310. StructureStubInfo& stubInfo = getStubInfo(location);
  311. if (stubInfo.seen) {
  312. out.printf(" jit(");
  313. Structure* baseStructure = 0;
  314. Structure* prototypeStructure = 0;
  315. StructureChain* chain = 0;
  316. PolymorphicAccessStructureList* structureList = 0;
  317. int listSize = 0;
  318. switch (stubInfo.accessType) {
  319. case access_get_by_id_self:
  320. out.printf("self");
  321. baseStructure = stubInfo.u.getByIdSelf.baseObjectStructure.get();
  322. break;
  323. case access_get_by_id_proto:
  324. out.printf("proto");
  325. baseStructure = stubInfo.u.getByIdProto.baseObjectStructure.get();
  326. prototypeStructure = stubInfo.u.getByIdProto.prototypeStructure.get();
  327. break;
  328. case access_get_by_id_chain:
  329. out.printf("chain");
  330. baseStructure = stubInfo.u.getByIdChain.baseObjectStructure.get();
  331. chain = stubInfo.u.getByIdChain.chain.get();
  332. break;
  333. case access_get_by_id_self_list:
  334. out.printf("self_list");
  335. structureList = stubInfo.u.getByIdSelfList.structureList;
  336. listSize = stubInfo.u.getByIdSelfList.listSize;
  337. break;
  338. case access_get_by_id_proto_list:
  339. out.printf("proto_list");
  340. structureList = stubInfo.u.getByIdProtoList.structureList;
  341. listSize = stubInfo.u.getByIdProtoList.listSize;
  342. break;
  343. case access_unset:
  344. out.printf("unset");
  345. break;
  346. case access_get_by_id_generic:
  347. out.printf("generic");
  348. break;
  349. case access_get_array_length:
  350. out.printf("array_length");
  351. break;
  352. case access_get_string_length:
  353. out.printf("string_length");
  354. break;
  355. default:
  356. RELEASE_ASSERT_NOT_REACHED();
  357. break;
  358. }
  359. if (baseStructure) {
  360. out.printf(", ");
  361. dumpStructure(out, "struct", exec, baseStructure, ident);
  362. }
  363. if (prototypeStructure) {
  364. out.printf(", ");
  365. dumpStructure(out, "prototypeStruct", exec, baseStructure, ident);
  366. }
  367. if (chain) {
  368. out.printf(", ");
  369. dumpChain(out, exec, chain, ident);
  370. }
  371. if (structureList) {
  372. out.printf(", list = %p: [", structureList);
  373. for (int i = 0; i < listSize; ++i) {
  374. if (i)
  375. out.printf(", ");
  376. out.printf("(");
  377. dumpStructure(out, "base", exec, structureList->list[i].base.get(), ident);
  378. if (structureList->list[i].isChain) {
  379. if (structureList->list[i].u.chain.get()) {
  380. out.printf(", ");
  381. dumpChain(out, exec, structureList->list[i].u.chain.get(), ident);
  382. }
  383. } else {
  384. if (structureList->list[i].u.proto.get()) {
  385. out.printf(", ");
  386. dumpStructure(out, "proto", exec, structureList->list[i].u.proto.get(), ident);
  387. }
  388. }
  389. out.printf(")");
  390. }
  391. out.printf("]");
  392. }
  393. out.printf(")");
  394. }
  395. }
  396. #endif
  397. }
  398. void CodeBlock::printCallOp(PrintStream& out, ExecState* exec, int location, const Instruction*& it, const char* op, CacheDumpMode cacheDumpMode)
  399. {
  400. int func = (++it)->u.operand;
  401. int argCount = (++it)->u.operand;
  402. int registerOffset = (++it)->u.operand;
  403. out.printf("[%4d] %s\t %s, %d, %d", location, op, registerName(exec, func).data(), argCount, registerOffset);
  404. if (cacheDumpMode == DumpCaches) {
  405. #if ENABLE(LLINT)
  406. LLIntCallLinkInfo* callLinkInfo = it[1].u.callLinkInfo;
  407. if (callLinkInfo->lastSeenCallee) {
  408. out.printf(
  409. " llint(%p, exec %p)",
  410. callLinkInfo->lastSeenCallee.get(),
  411. callLinkInfo->lastSeenCallee->executable());
  412. }
  413. #endif
  414. #if ENABLE(JIT)
  415. if (numberOfCallLinkInfos()) {
  416. JSFunction* target = getCallLinkInfo(location).lastSeenCallee.get();
  417. if (target)
  418. out.printf(" jit(%p, exec %p)", target, target->executable());
  419. }
  420. #endif
  421. out.print(" status(", CallLinkStatus::computeFor(this, location), ")");
  422. }
  423. it += 2;
  424. }
  425. void CodeBlock::printPutByIdOp(PrintStream& out, ExecState* exec, int location, const Instruction*& it, const char* op)
  426. {
  427. int r0 = (++it)->u.operand;
  428. int id0 = (++it)->u.operand;
  429. int r1 = (++it)->u.operand;
  430. out.printf("[%4d] %s\t %s, %s, %s", location, op, registerName(exec, r0).data(), idName(id0, m_identifiers[id0]).data(), registerName(exec, r1).data());
  431. it += 5;
  432. }
  433. void CodeBlock::printStructure(PrintStream& out, const char* name, const Instruction* vPC, int operand)
  434. {
  435. unsigned instructionOffset = vPC - instructions().begin();
  436. out.printf(" [%4d] %s: %s\n", instructionOffset, name, pointerToSourceString(vPC[operand].u.structure).utf8().data());
  437. }
  438. void CodeBlock::printStructures(PrintStream& out, const Instruction* vPC)
  439. {
  440. Interpreter* interpreter = m_vm->interpreter;
  441. unsigned instructionOffset = vPC - instructions().begin();
  442. if (vPC[0].u.opcode == interpreter->getOpcode(op_get_by_id)) {
  443. printStructure(out, "get_by_id", vPC, 4);
  444. return;
  445. }
  446. if (vPC[0].u.opcode == interpreter->getOpcode(op_get_by_id_self)) {
  447. printStructure(out, "get_by_id_self", vPC, 4);
  448. return;
  449. }
  450. if (vPC[0].u.opcode == interpreter->getOpcode(op_get_by_id_proto)) {
  451. out.printf(" [%4d] %s: %s, %s\n", instructionOffset, "get_by_id_proto", pointerToSourceString(vPC[4].u.structure).utf8().data(), pointerToSourceString(vPC[5].u.structure).utf8().data());
  452. return;
  453. }
  454. if (vPC[0].u.opcode == interpreter->getOpcode(op_put_by_id_transition)) {
  455. out.printf(" [%4d] %s: %s, %s, %s\n", instructionOffset, "put_by_id_transition", pointerToSourceString(vPC[4].u.structure).utf8().data(), pointerToSourceString(vPC[5].u.structure).utf8().data(), pointerToSourceString(vPC[6].u.structureChain).utf8().data());
  456. return;
  457. }
  458. if (vPC[0].u.opcode == interpreter->getOpcode(op_get_by_id_chain)) {
  459. out.printf(" [%4d] %s: %s, %s\n", instructionOffset, "get_by_id_chain", pointerToSourceString(vPC[4].u.structure).utf8().data(), pointerToSourceString(vPC[5].u.structureChain).utf8().data());
  460. return;
  461. }
  462. if (vPC[0].u.opcode == interpreter->getOpcode(op_put_by_id)) {
  463. printStructure(out, "put_by_id", vPC, 4);
  464. return;
  465. }
  466. if (vPC[0].u.opcode == interpreter->getOpcode(op_put_by_id_replace)) {
  467. printStructure(out, "put_by_id_replace", vPC, 4);
  468. return;
  469. }
  470. // These m_instructions doesn't ref Structures.
  471. ASSERT(vPC[0].u.opcode == interpreter->getOpcode(op_get_by_id_generic) || vPC[0].u.opcode == interpreter->getOpcode(op_put_by_id_generic) || vPC[0].u.opcode == interpreter->getOpcode(op_call) || vPC[0].u.opcode == interpreter->getOpcode(op_call_eval) || vPC[0].u.opcode == interpreter->getOpcode(op_construct));
  472. }
  473. void CodeBlock::dumpBytecode(PrintStream& out)
  474. {
  475. // We only use the ExecState* for things that don't actually lead to JS execution,
  476. // like converting a JSString to a String. Hence the globalExec is appropriate.
  477. ExecState* exec = m_globalObject->globalExec();
  478. size_t instructionCount = 0;
  479. for (size_t i = 0; i < instructions().size(); i += opcodeLengths[exec->interpreter()->getOpcodeID(instructions()[i].u.opcode)])
  480. ++instructionCount;
  481. out.print(*this);
  482. out.printf(
  483. ": %lu m_instructions; %lu bytes; %d parameter(s); %d callee register(s); %d variable(s)",
  484. static_cast<unsigned long>(instructions().size()),
  485. static_cast<unsigned long>(instructions().size() * sizeof(Instruction)),
  486. m_numParameters, m_numCalleeRegisters, m_numVars);
  487. if (symbolTable() && symbolTable()->captureCount()) {
  488. out.printf(
  489. "; %d captured var(s) (from r%d to r%d, inclusive)",
  490. symbolTable()->captureCount(), symbolTable()->captureStart(), symbolTable()->captureEnd() - 1);
  491. }
  492. if (usesArguments()) {
  493. out.printf(
  494. "; uses arguments, in r%d, r%d",
  495. argumentsRegister(),
  496. unmodifiedArgumentsRegister(argumentsRegister()));
  497. }
  498. if (needsFullScopeChain() && codeType() == FunctionCode)
  499. out.printf("; activation in r%d", activationRegister());
  500. out.print("\n\nSource: ", sourceCodeOnOneLine(), "\n\n");
  501. const Instruction* begin = instructions().begin();
  502. const Instruction* end = instructions().end();
  503. for (const Instruction* it = begin; it != end; ++it)
  504. dumpBytecode(out, exec, begin, it);
  505. if (!m_identifiers.isEmpty()) {
  506. out.printf("\nIdentifiers:\n");
  507. size_t i = 0;
  508. do {
  509. out.printf(" id%u = %s\n", static_cast<unsigned>(i), m_identifiers[i].string().utf8().data());
  510. ++i;
  511. } while (i != m_identifiers.size());
  512. }
  513. if (!m_constantRegisters.isEmpty()) {
  514. out.printf("\nConstants:\n");
  515. size_t i = 0;
  516. do {
  517. out.printf(" k%u = %s\n", static_cast<unsigned>(i), valueToSourceString(exec, m_constantRegisters[i].get()).utf8().data());
  518. ++i;
  519. } while (i < m_constantRegisters.size());
  520. }
  521. if (size_t count = m_unlinkedCode->numberOfRegExps()) {
  522. out.printf("\nm_regexps:\n");
  523. size_t i = 0;
  524. do {
  525. out.printf(" re%u = %s\n", static_cast<unsigned>(i), regexpToSourceString(m_unlinkedCode->regexp(i)).utf8().data());
  526. ++i;
  527. } while (i < count);
  528. }
  529. #if ENABLE(JIT)
  530. if (!m_structureStubInfos.isEmpty())
  531. out.printf("\nStructures:\n");
  532. #endif
  533. if (m_rareData && !m_rareData->m_exceptionHandlers.isEmpty()) {
  534. out.printf("\nException Handlers:\n");
  535. unsigned i = 0;
  536. do {
  537. out.printf("\t %d: { start: [%4d] end: [%4d] target: [%4d] depth: [%4d] }\n", i + 1, m_rareData->m_exceptionHandlers[i].start, m_rareData->m_exceptionHandlers[i].end, m_rareData->m_exceptionHandlers[i].target, m_rareData->m_exceptionHandlers[i].scopeDepth);
  538. ++i;
  539. } while (i < m_rareData->m_exceptionHandlers.size());
  540. }
  541. if (m_rareData && !m_rareData->m_immediateSwitchJumpTables.isEmpty()) {
  542. out.printf("Immediate Switch Jump Tables:\n");
  543. unsigned i = 0;
  544. do {
  545. out.printf(" %1d = {\n", i);
  546. int entry = 0;
  547. Vector<int32_t>::const_iterator end = m_rareData->m_immediateSwitchJumpTables[i].branchOffsets.end();
  548. for (Vector<int32_t>::const_iterator iter = m_rareData->m_immediateSwitchJumpTables[i].branchOffsets.begin(); iter != end; ++iter, ++entry) {
  549. if (!*iter)
  550. continue;
  551. out.printf("\t\t%4d => %04d\n", entry + m_rareData->m_immediateSwitchJumpTables[i].min, *iter);
  552. }
  553. out.printf(" }\n");
  554. ++i;
  555. } while (i < m_rareData->m_immediateSwitchJumpTables.size());
  556. }
  557. if (m_rareData && !m_rareData->m_characterSwitchJumpTables.isEmpty()) {
  558. out.printf("\nCharacter Switch Jump Tables:\n");
  559. unsigned i = 0;
  560. do {
  561. out.printf(" %1d = {\n", i);
  562. int entry = 0;
  563. Vector<int32_t>::const_iterator end = m_rareData->m_characterSwitchJumpTables[i].branchOffsets.end();
  564. for (Vector<int32_t>::const_iterator iter = m_rareData->m_characterSwitchJumpTables[i].branchOffsets.begin(); iter != end; ++iter, ++entry) {
  565. if (!*iter)
  566. continue;
  567. ASSERT(!((i + m_rareData->m_characterSwitchJumpTables[i].min) & ~0xFFFF));
  568. UChar ch = static_cast<UChar>(entry + m_rareData->m_characterSwitchJumpTables[i].min);
  569. out.printf("\t\t\"%s\" => %04d\n", String(&ch, 1).utf8().data(), *iter);
  570. }
  571. out.printf(" }\n");
  572. ++i;
  573. } while (i < m_rareData->m_characterSwitchJumpTables.size());
  574. }
  575. if (m_rareData && !m_rareData->m_stringSwitchJumpTables.isEmpty()) {
  576. out.printf("\nString Switch Jump Tables:\n");
  577. unsigned i = 0;
  578. do {
  579. out.printf(" %1d = {\n", i);
  580. StringJumpTable::StringOffsetTable::const_iterator end = m_rareData->m_stringSwitchJumpTables[i].offsetTable.end();
  581. for (StringJumpTable::StringOffsetTable::const_iterator iter = m_rareData->m_stringSwitchJumpTables[i].offsetTable.begin(); iter != end; ++iter)
  582. out.printf("\t\t\"%s\" => %04d\n", String(iter->key).utf8().data(), iter->value.branchOffset);
  583. out.printf(" }\n");
  584. ++i;
  585. } while (i < m_rareData->m_stringSwitchJumpTables.size());
  586. }
  587. out.printf("\n");
  588. }
  589. void CodeBlock::beginDumpProfiling(PrintStream& out, bool& hasPrintedProfiling)
  590. {
  591. if (hasPrintedProfiling) {
  592. out.print("; ");
  593. return;
  594. }
  595. out.print(" ");
  596. hasPrintedProfiling = true;
  597. }
  598. void CodeBlock::dumpValueProfiling(PrintStream& out, const Instruction*& it, bool& hasPrintedProfiling)
  599. {
  600. ++it;
  601. #if ENABLE(VALUE_PROFILER)
  602. CString description = it->u.profile->briefDescription();
  603. if (!description.length())
  604. return;
  605. beginDumpProfiling(out, hasPrintedProfiling);
  606. out.print(description);
  607. #else
  608. UNUSED_PARAM(out);
  609. UNUSED_PARAM(hasPrintedProfiling);
  610. #endif
  611. }
  612. void CodeBlock::dumpArrayProfiling(PrintStream& out, const Instruction*& it, bool& hasPrintedProfiling)
  613. {
  614. ++it;
  615. #if ENABLE(VALUE_PROFILER)
  616. CString description = it->u.arrayProfile->briefDescription(this);
  617. if (!description.length())
  618. return;
  619. beginDumpProfiling(out, hasPrintedProfiling);
  620. out.print(description);
  621. #else
  622. UNUSED_PARAM(out);
  623. UNUSED_PARAM(hasPrintedProfiling);
  624. #endif
  625. }
  626. #if ENABLE(VALUE_PROFILER)
  627. void CodeBlock::dumpRareCaseProfile(PrintStream& out, const char* name, RareCaseProfile* profile, bool& hasPrintedProfiling)
  628. {
  629. if (!profile || !profile->m_counter)
  630. return;
  631. beginDumpProfiling(out, hasPrintedProfiling);
  632. out.print(name, profile->m_counter);
  633. }
  634. #endif
  635. void CodeBlock::dumpBytecode(PrintStream& out, ExecState* exec, const Instruction* begin, const Instruction*& it)
  636. {
  637. int location = it - begin;
  638. bool hasPrintedProfiling = false;
  639. switch (exec->interpreter()->getOpcodeID(it->u.opcode)) {
  640. case op_enter: {
  641. out.printf("[%4d] enter", location);
  642. break;
  643. }
  644. case op_create_activation: {
  645. int r0 = (++it)->u.operand;
  646. out.printf("[%4d] create_activation %s", location, registerName(exec, r0).data());
  647. break;
  648. }
  649. case op_create_arguments: {
  650. int r0 = (++it)->u.operand;
  651. out.printf("[%4d] create_arguments\t %s", location, registerName(exec, r0).data());
  652. break;
  653. }
  654. case op_init_lazy_reg: {
  655. int r0 = (++it)->u.operand;
  656. out.printf("[%4d] init_lazy_reg\t %s", location, registerName(exec, r0).data());
  657. break;
  658. }
  659. case op_get_callee: {
  660. int r0 = (++it)->u.operand;
  661. out.printf("[%4d] op_get_callee %s\n", location, registerName(exec, r0).data());
  662. ++it;
  663. break;
  664. }
  665. case op_create_this: {
  666. int r0 = (++it)->u.operand;
  667. int r1 = (++it)->u.operand;
  668. unsigned inferredInlineCapacity = (++it)->u.operand;
  669. out.printf("[%4d] create_this %s, %s, %u", location, registerName(exec, r0).data(), registerName(exec, r1).data(), inferredInlineCapacity);
  670. break;
  671. }
  672. case op_convert_this: {
  673. int r0 = (++it)->u.operand;
  674. out.printf("[%4d] convert_this\t %s", location, registerName(exec, r0).data());
  675. ++it; // Skip value profile.
  676. break;
  677. }
  678. case op_new_object: {
  679. int r0 = (++it)->u.operand;
  680. unsigned inferredInlineCapacity = (++it)->u.operand;
  681. out.printf("[%4d] new_object\t %s, %u", location, registerName(exec, r0).data(), inferredInlineCapacity);
  682. ++it; // Skip object allocation profile.
  683. break;
  684. }
  685. case op_new_array: {
  686. int dst = (++it)->u.operand;
  687. int argv = (++it)->u.operand;
  688. int argc = (++it)->u.operand;
  689. out.printf("[%4d] new_array\t %s, %s, %d", location, registerName(exec, dst).data(), registerName(exec, argv).data(), argc);
  690. ++it; // Skip array allocation profile.
  691. break;
  692. }
  693. case op_new_array_with_size: {
  694. int dst = (++it)->u.operand;
  695. int length = (++it)->u.operand;
  696. out.printf("[%4d] new_array_with_size\t %s, %s", location, registerName(exec, dst).data(), registerName(exec, length).data());
  697. ++it; // Skip array allocation profile.
  698. break;
  699. }
  700. case op_new_array_buffer: {
  701. int dst = (++it)->u.operand;
  702. int argv = (++it)->u.operand;
  703. int argc = (++it)->u.operand;
  704. out.printf("[%4d] new_array_buffer\t %s, %d, %d", location, registerName(exec, dst).data(), argv, argc);
  705. ++it; // Skip array allocation profile.
  706. break;
  707. }
  708. case op_new_regexp: {
  709. int r0 = (++it)->u.operand;
  710. int re0 = (++it)->u.operand;
  711. out.printf("[%4d] new_regexp\t %s, ", location, registerName(exec, r0).data());
  712. if (r0 >=0 && r0 < (int)m_unlinkedCode->numberOfRegExps())
  713. out.printf("%s", regexpName(re0, regexp(re0)).data());
  714. else
  715. out.printf("bad_regexp(%d)", re0);
  716. break;
  717. }
  718. case op_mov: {
  719. int r0 = (++it)->u.operand;
  720. int r1 = (++it)->u.operand;
  721. out.printf("[%4d] mov\t\t %s, %s", location, registerName(exec, r0).data(), registerName(exec, r1).data());
  722. break;
  723. }
  724. case op_not: {
  725. printUnaryOp(out, exec, location, it, "not");
  726. break;
  727. }
  728. case op_eq: {
  729. printBinaryOp(out, exec, location, it, "eq");
  730. break;
  731. }
  732. case op_eq_null: {
  733. printUnaryOp(out, exec, location, it, "eq_null");
  734. break;
  735. }
  736. case op_neq: {
  737. printBinaryOp(out, exec, location, it, "neq");
  738. break;
  739. }
  740. case op_neq_null: {
  741. printUnaryOp(out, exec, location, it, "neq_null");
  742. break;
  743. }
  744. case op_stricteq: {
  745. printBinaryOp(out, exec, location, it, "stricteq");
  746. break;
  747. }
  748. case op_nstricteq: {
  749. printBinaryOp(out, exec, location, it, "nstricteq");
  750. break;
  751. }
  752. case op_less: {
  753. printBinaryOp(out, exec, location, it, "less");
  754. break;
  755. }
  756. case op_lesseq: {
  757. printBinaryOp(out, exec, location, it, "lesseq");
  758. break;
  759. }
  760. case op_greater: {
  761. printBinaryOp(out, exec, location, it, "greater");
  762. break;
  763. }
  764. case op_greatereq: {
  765. printBinaryOp(out, exec, location, it, "greatereq");
  766. break;
  767. }
  768. case op_inc: {
  769. int r0 = (++it)->u.operand;
  770. out.printf("[%4d] pre_inc\t\t %s", location, registerName(exec, r0).data());
  771. break;
  772. }
  773. case op_dec: {
  774. int r0 = (++it)->u.operand;
  775. out.printf("[%4d] pre_dec\t\t %s", location, registerName(exec, r0).data());
  776. break;
  777. }
  778. case op_to_number: {
  779. printUnaryOp(out, exec, location, it, "to_number");
  780. break;
  781. }
  782. case op_negate: {
  783. printUnaryOp(out, exec, location, it, "negate");
  784. break;
  785. }
  786. case op_add: {
  787. printBinaryOp(out, exec, location, it, "add");
  788. ++it;
  789. break;
  790. }
  791. case op_mul: {
  792. printBinaryOp(out, exec, location, it, "mul");
  793. ++it;
  794. break;
  795. }
  796. case op_div: {
  797. printBinaryOp(out, exec, location, it, "div");
  798. ++it;
  799. break;
  800. }
  801. case op_mod: {
  802. printBinaryOp(out, exec, location, it, "mod");
  803. break;
  804. }
  805. case op_sub: {
  806. printBinaryOp(out, exec, location, it, "sub");
  807. ++it;
  808. break;
  809. }
  810. case op_lshift: {
  811. printBinaryOp(out, exec, location, it, "lshift");
  812. break;
  813. }
  814. case op_rshift: {
  815. printBinaryOp(out, exec, location, it, "rshift");
  816. break;
  817. }
  818. case op_urshift: {
  819. printBinaryOp(out, exec, location, it, "urshift");
  820. break;
  821. }
  822. case op_bitand: {
  823. printBinaryOp(out, exec, location, it, "bitand");
  824. ++it;
  825. break;
  826. }
  827. case op_bitxor: {
  828. printBinaryOp(out, exec, location, it, "bitxor");
  829. ++it;
  830. break;
  831. }
  832. case op_bitor: {
  833. printBinaryOp(out, exec, location, it, "bitor");
  834. ++it;
  835. break;
  836. }
  837. case op_check_has_instance: {
  838. int r0 = (++it)->u.operand;
  839. int r1 = (++it)->u.operand;
  840. int r2 = (++it)->u.operand;
  841. int offset = (++it)->u.operand;
  842. out.printf("[%4d] check_has_instance\t\t %s, %s, %s, %d(->%d)", location, registerName(exec, r0).data(), registerName(exec, r1).data(), registerName(exec, r2).data(), offset, location + offset);
  843. break;
  844. }
  845. case op_instanceof: {
  846. int r0 = (++it)->u.operand;
  847. int r1 = (++it)->u.operand;
  848. int r2 = (++it)->u.operand;
  849. out.printf("[%4d] instanceof\t\t %s, %s, %s", location, registerName(exec, r0).data(), registerName(exec, r1).data(), registerName(exec, r2).data());
  850. break;
  851. }
  852. case op_typeof: {
  853. printUnaryOp(out, exec, location, it, "typeof");
  854. break;
  855. }
  856. case op_is_undefined: {
  857. printUnaryOp(out, exec, location, it, "is_undefined");
  858. break;
  859. }
  860. case op_is_boolean: {
  861. printUnaryOp(out, exec, location, it, "is_boolean");
  862. break;
  863. }
  864. case op_is_number: {
  865. printUnaryOp(out, exec, location, it, "is_number");
  866. break;
  867. }
  868. case op_is_string: {
  869. printUnaryOp(out, exec, location, it, "is_string");
  870. break;
  871. }
  872. case op_is_object: {
  873. printUnaryOp(out, exec, location, it, "is_object");
  874. break;
  875. }
  876. case op_is_function: {
  877. printUnaryOp(out, exec, location, it, "is_function");
  878. break;
  879. }
  880. case op_in: {
  881. printBinaryOp(out, exec, location, it, "in");
  882. break;
  883. }
  884. case op_put_to_base_variable:
  885. case op_put_to_base: {
  886. int base = (++it)->u.operand;
  887. int id0 = (++it)->u.operand;
  888. int value = (++it)->u.operand;
  889. int resolveInfo = (++it)->u.operand;
  890. out.printf("[%4d] put_to_base\t %s, %s, %s, %d", location, registerName(exec, base).data(), idName(id0, m_identifiers[id0]).data(), registerName(exec, value).data(), resolveInfo);
  891. break;
  892. }
  893. case op_resolve:
  894. case op_resolve_global_property:
  895. case op_resolve_global_var:
  896. case op_resolve_scoped_var:
  897. case op_resolve_scoped_var_on_top_scope:
  898. case op_resolve_scoped_var_with_top_scope_check: {
  899. int r0 = (++it)->u.operand;
  900. int id0 = (++it)->u.operand;
  901. int resolveInfo = (++it)->u.operand;
  902. out.printf("[%4d] resolve\t\t %s, %s, %d", location, registerName(exec, r0).data(), idName(id0, m_identifiers[id0]).data(), resolveInfo);
  903. dumpValueProfiling(out, it, hasPrintedProfiling);
  904. break;
  905. }
  906. case op_get_scoped_var: {
  907. int r0 = (++it)->u.operand;
  908. int index = (++it)->u.operand;
  909. int skipLevels = (++it)->u.operand;
  910. out.printf("[%4d] get_scoped_var\t %s, %d, %d", location, registerName(exec, r0).data(), index, skipLevels);
  911. dumpValueProfiling(out, it, hasPrintedProfiling);
  912. break;
  913. }
  914. case op_put_scoped_var: {
  915. int index = (++it)->u.operand;
  916. int skipLevels = (++it)->u.operand;
  917. int r0 = (++it)->u.operand;
  918. out.printf("[%4d] put_scoped_var\t %d, %d, %s", location, index, skipLevels, registerName(exec, r0).data());
  919. break;
  920. }
  921. case op_init_global_const_nop: {
  922. out.printf("[%4d] init_global_const_nop\t", location);
  923. it++;
  924. it++;
  925. it++;
  926. it++;
  927. break;
  928. }
  929. case op_init_global_const: {
  930. WriteBarrier<Unknown>* registerPointer = (++it)->u.registerPointer;
  931. int r0 = (++it)->u.operand;
  932. out.printf("[%4d] init_global_const\t g%d(%p), %s", location, m_globalObject->findRegisterIndex(registerPointer), registerPointer, registerName(exec, r0).data());
  933. it++;
  934. it++;
  935. break;
  936. }
  937. case op_init_global_const_check: {
  938. WriteBarrier<Unknown>* registerPointer = (++it)->u.registerPointer;
  939. int r0 = (++it)->u.operand;
  940. out.printf("[%4d] init_global_const_check\t g%d(%p), %s", location, m_globalObject->findRegisterIndex(registerPointer), registerPointer, registerName(exec, r0).data());
  941. it++;
  942. it++;
  943. break;
  944. }
  945. case op_resolve_base_to_global:
  946. case op_resolve_base_to_global_dynamic:
  947. case op_resolve_base_to_scope:
  948. case op_resolve_base_to_scope_with_top_scope_check:
  949. case op_resolve_base: {
  950. int r0 = (++it)->u.operand;
  951. int id0 = (++it)->u.operand;
  952. int isStrict = (++it)->u.operand;
  953. int resolveInfo = (++it)->u.operand;
  954. int putToBaseInfo = (++it)->u.operand;
  955. out.printf("[%4d] resolve_base%s\t %s, %s, %d, %d", location, isStrict ? "_strict" : "", registerName(exec, r0).data(), idName(id0, m_identifiers[id0]).data(), resolveInfo, putToBaseInfo);
  956. dumpValueProfiling(out, it, hasPrintedProfiling);
  957. break;
  958. }
  959. case op_resolve_with_base: {
  960. int r0 = (++it)->u.operand;
  961. int r1 = (++it)->u.operand;
  962. int id0 = (++it)->u.operand;
  963. int resolveInfo = (++it)->u.operand;
  964. int putToBaseInfo = (++it)->u.operand;
  965. out.printf("[%4d] resolve_with_base %s, %s, %s, %d, %d", location, registerName(exec, r0).data(), registerName(exec, r1).data(), idName(id0, m_identifiers[id0]).data(), resolveInfo, putToBaseInfo);
  966. dumpValueProfiling(out, it, hasPrintedProfiling);
  967. break;
  968. }
  969. case op_resolve_with_this: {
  970. int r0 = (++it)->u.operand;
  971. int r1 = (++it)->u.operand;
  972. int id0 = (++it)->u.operand;
  973. int resolveInfo = (++it)->u.operand;
  974. out.printf("[%4d] resolve_with_this %s, %s, %s, %d", location, registerName(exec, r0).data(), registerName(exec, r1).data(), idName(id0, m_identifiers[id0]).data(), resolveInfo);
  975. dumpValueProfiling(out, it, hasPrintedProfiling);
  976. break;
  977. }
  978. case op_get_by_id:
  979. case op_get_by_id_out_of_line:
  980. case op_get_by_id_self:
  981. case op_get_by_id_proto:
  982. case op_get_by_id_chain:
  983. case op_get_by_id_getter_self:
  984. case op_get_by_id_getter_proto:
  985. case op_get_by_id_getter_chain:
  986. case op_get_by_id_custom_self:
  987. case op_get_by_id_custom_proto:
  988. case op_get_by_id_custom_chain:
  989. case op_get_by_id_generic:
  990. case op_get_array_length:
  991. case op_get_string_length: {
  992. printGetByIdOp(out, exec, location, it);
  993. printGetByIdCacheStatus(out, exec, location);
  994. dumpValueProfiling(out, it, hasPrintedProfiling);
  995. break;
  996. }
  997. case op_get_arguments_length: {
  998. printUnaryOp(out, exec, location, it, "get_arguments_length");
  999. it++;
  1000. break;
  1001. }
  1002. case op_put_by_id: {
  1003. printPutByIdOp(out, exec, location, it, "put_by_id");
  1004. break;
  1005. }
  1006. case op_put_by_id_out_of_line: {
  1007. printPutByIdOp(out, exec, location, it, "put_by_id_out_of_line");
  1008. break;
  1009. }
  1010. case op_put_by_id_replace: {
  1011. printPutByIdOp(out, exec, location, it, "put_by_id_replace");
  1012. break;
  1013. }
  1014. case op_put_by_id_transition: {
  1015. printPutByIdOp(out, exec, location, it, "put_by_id_transition");
  1016. break;
  1017. }
  1018. case op_put_by_id_transition_direct: {
  1019. printPutByIdOp(out, exec, location, it, "put_by_id_transition_direct");
  1020. break;
  1021. }
  1022. case op_put_by_id_transition_direct_out_of_line: {
  1023. printPutByIdOp(out, exec, location, it, "put_by_id_transition_direct_out_of_line");
  1024. break;
  1025. }
  1026. case op_put_by_id_transition_normal: {
  1027. printPutByIdOp(out, exec, location, it, "put_by_id_transition_normal");
  1028. break;
  1029. }
  1030. case op_put_by_id_transition_normal_out_of_line: {
  1031. printPutByIdOp(out, exec, location, it, "put_by_id_transition_normal_out_of_line");
  1032. break;
  1033. }
  1034. case op_put_by_id_generic: {
  1035. printPutByIdOp(out, exec, location, it, "put_by_id_generic");
  1036. break;
  1037. }
  1038. case op_put_getter_setter: {
  1039. int r0 = (++it)->u.operand;
  1040. int id0 = (++it)->u.operand;
  1041. int r1 = (++it)->u.operand;
  1042. int r2 = (++it)->u.operand;
  1043. out.printf("[%4d] put_getter_setter\t %s, %s, %s, %s", location, registerName(exec, r0).data(), idName(id0, m_identifiers[id0]).data(), registerName(exec, r1).data(), registerName(exec, r2).data());
  1044. break;
  1045. }
  1046. case op_del_by_id: {
  1047. int r0 = (++it)->u.operand;
  1048. int r1 = (++it)->u.operand;
  1049. int id0 = (++it)->u.operand;
  1050. out.printf("[%4d] del_by_id\t %s, %s, %s", location, registerName(exec, r0).data(), registerName(exec, r1).data(), idName(id0, m_identifiers[id0]).data());
  1051. break;
  1052. }
  1053. case op_get_by_val: {
  1054. int r0 = (++it)->u.operand;
  1055. int r1 = (++it)->u.operand;
  1056. int r2 = (++it)->u.operand;
  1057. out.printf("[%4d] get_by_val\t %s, %s, %s", location, registerName(exec, r0).data(), registerName(exec, r1).data(), registerName(exec, r2).data());
  1058. dumpArrayProfiling(out, it, hasPrintedProfiling);
  1059. dumpValueProfiling(out, it, hasPrintedProfiling);
  1060. break;
  1061. }
  1062. case op_get_argument_by_val: {
  1063. int r0 = (++it)->u.operand;
  1064. int r1 = (++it)->u.operand;
  1065. int r2 = (++it)->u.operand;
  1066. out.printf("[%4d] get_argument_by_val\t %s, %s, %s", location, registerName(exec, r0).data(), registerName(exec, r1).data(), registerName(exec, r2).data());
  1067. ++it;
  1068. dumpValueProfiling(out, it, hasPrintedProfiling);
  1069. break;
  1070. }
  1071. case op_get_by_pname: {
  1072. int r0 = (++it)->u.operand;
  1073. int r1 = (++it)->u.operand;
  1074. int r2 = (++it)->u.operand;
  1075. int r3 = (++it)->u.operand;
  1076. int r4 = (++it)->u.operand;
  1077. int r5 = (++it)->u.operand;
  1078. out.printf("[%4d] get_by_pname\t %s, %s, %s, %s, %s, %s", location, registerName(exec, r0).data(), registerName(exec, r1).data(), registerName(exec, r2).data(), registerName(exec, r3).data(), registerName(exec, r4).data(), registerName(exec, r5).data());
  1079. break;
  1080. }
  1081. case op_put_by_val: {
  1082. int r0 = (++it)->u.operand;
  1083. int r1 = (++it)->u.operand;
  1084. int r2 = (++it)->u.operand;
  1085. out.printf("[%4d] put_by_val\t %s, %s, %s", location, registerName(exec, r0).data(), registerName(exec, r1).data(), registerName(exec, r2).data());
  1086. dumpArrayProfiling(out, it, hasPrintedProfiling);
  1087. break;
  1088. }
  1089. case op_del_by_val: {
  1090. int r0 = (++it)->u.operand;
  1091. int r1 = (++it)->u.operand;
  1092. int r2 = (++it)->u.operand;
  1093. out.printf("[%4d] del_by_val\t %s, %s, %s", location, registerName(exec, r0).data(), registerName(exec, r1).data(), registerName(exec, r2).data());
  1094. break;
  1095. }
  1096. case op_put_by_index: {
  1097. int r0 = (++it)->u.operand;
  1098. unsigned n0 = (++it)->u.operand;
  1099. int r1 = (++it)->u.operand;
  1100. out.printf("[%4d] put_by_index\t %s, %u, %s", location, registerName(exec, r0).data(), n0, registerName(exec, r1).data());
  1101. break;
  1102. }
  1103. case op_jmp: {
  1104. int offset = (++it)->u.operand;
  1105. out.printf("[%4d] jmp\t\t %d(->%d)", location, offset, location + offset);
  1106. break;
  1107. }
  1108. case op_jtrue: {
  1109. printConditionalJump(out, exec, begin, it, location, "jtrue");
  1110. break;
  1111. }
  1112. case op_jfalse: {
  1113. printConditionalJump(out, exec, begin, it, location, "jfalse");
  1114. break;
  1115. }
  1116. case op_jeq_null: {
  1117. printConditionalJump(out, exec, begin, it, location, "jeq_null");
  1118. break;
  1119. }
  1120. case op_jneq_null: {
  1121. printConditionalJump(out, exec, begin, it, location, "jneq_null");
  1122. break;
  1123. }
  1124. case op_jneq_ptr: {
  1125. int r0 = (++it)->u.operand;
  1126. Special::Pointer pointer = (++it)->u.specialPointer;
  1127. int offset = (++it)->u.operand;
  1128. out.printf("[%4d] jneq_ptr\t\t %s, %d (%p), %d(->%d)", location, registerName(exec, r0).data(), pointer, m_globalObject->actualPointerFor(pointer), offset, location + offset);
  1129. break;
  1130. }
  1131. case op_jless: {
  1132. int r0 = (++it)->u.operand;
  1133. int r1 = (++it)->u.operand;
  1134. int offset = (++it)->u.operand;
  1135. out.printf("[%4d] jless\t\t %s, %s, %d(->%d)", location, registerName(exec, r0).data(), registerName(exec, r1).data(), offset, location + offset);
  1136. break;
  1137. }
  1138. case op_jlesseq: {
  1139. int r0 = (++it)->u.operand;
  1140. int r1 = (++it)->u.operand;
  1141. int offset = (++it)->u.operand;
  1142. out.printf("[%4d] jlesseq\t\t %s, %s, %d(->%d)", location, registerName(exec, r0).data(), registerName(exec, r1).data(), offset, location + offset);
  1143. break;
  1144. }
  1145. case op_jgreater: {
  1146. int r0 = (++it)->u.operand;
  1147. int r1 = (++it)->u.operand;
  1148. int offset = (++it)->u.operand;
  1149. out.printf("[%4d] jgreater\t\t %s, %s, %d(->%d)", location, registerName(exec, r0).data(), registerName(exec, r1).data(), offset, location + offset);
  1150. break;
  1151. }
  1152. case op_jgreatereq: {
  1153. int r0 = (++it)->u.operand;
  1154. int r1 = (++it)->u.operand;
  1155. int offset = (++it)->u.operand;
  1156. out.printf("[%4d] jgreatereq\t\t %s, %s, %d(->%d)", location, registerName(exec, r0).data(), registerName(exec, r1).data(), offset, location + offset);
  1157. break;
  1158. }
  1159. case op_jnless: {
  1160. int r0 = (++it)->u.operand;
  1161. int r1 = (++it)->u.operand;
  1162. int offset = (++it)->u.operand;
  1163. out.printf("[%4d] jnless\t\t %s, %s, %d(->%d)", location, registerName(exec, r0).data(), registerName(exec, r1).data(), offset, location + offset);
  1164. break;
  1165. }
  1166. case op_jnlesseq: {
  1167. int r0 = (++it)->u.operand;
  1168. int r1 = (++it)->u.operand;
  1169. int offset = (++it)->u.operand;
  1170. out.printf("[%4d] jnlesseq\t\t %s, %s, %d(->%d)", location, registerName(exec, r0).data(), registerName(exec, r1).data(), offset, location + offset);
  1171. break;
  1172. }
  1173. case op_jngreater: {
  1174. int r0 = (++it)->u.operand;
  1175. int r1 = (++it)->u.operand;
  1176. int offset = (++it)->u.operand;
  1177. out.printf("[%4d] jngreater\t\t %s, %s, %d(->%d)", location, registerName(exec, r0).data(), registerName(exec, r1).data(), offset, location + offset);
  1178. break;
  1179. }
  1180. case op_jngreatereq: {
  1181. int r0 = (++it)->u.operand;
  1182. int r1 = (++it)->u.operand;
  1183. int offset = (++it)->u.operand;
  1184. out.printf("[%4d] jngreatereq\t\t %s, %s, %d(->%d)", location, registerName(exec, r0).data(), registerName(exec, r1).data(), offset, location + offset);
  1185. break;
  1186. }
  1187. case op_loop_hint: {
  1188. out.printf("[%4d] loop_hint", location);
  1189. break;
  1190. }
  1191. case op_switch_imm: {
  1192. int tableIndex = (++it)->u.operand;
  1193. int defaultTarget = (++it)->u.operand;
  1194. int scrutineeRegister = (++it)->u.operand;
  1195. out.printf("[%4d] switch_imm\t %d, %d(->%d), %s", location, tableIndex, defaultTarget, location + defaultTarget, registerName(exec, scrutineeRegister).data());
  1196. break;
  1197. }
  1198. case op_switch_char: {
  1199. int tableIndex = (++it)->u.operand;
  1200. int defaultTarget = (++it)->u.operand;
  1201. int scrutineeRegister = (++it)->u.operand;
  1202. out.printf("[%4d] switch_char\t %d, %d(->%d), %s", location, tableIndex, defaultTarget, location + defaultTarget, registerName(exec, scrutineeRegister).data());
  1203. break;
  1204. }
  1205. case op_switch_string: {
  1206. int tableIndex = (++it)->u.operand;
  1207. int defaultTarget = (++it)->u.operand;
  1208. int scrutineeRegister = (++it)->u.operand;
  1209. out.printf("[%4d] switch_string\t %d, %d(->%d), %s", location, tableIndex, defaultTarget, location + defaultTarget, registerName(exec, scrutineeRegister).data());
  1210. break;
  1211. }
  1212. case op_new_func: {
  1213. int r0 = (++it)->u.operand;
  1214. int f0 = (++it)->u.operand;
  1215. int shouldCheck = (++it)->u.operand;
  1216. out.printf("[%4d] new_func\t\t %s, f%d, %s", location, registerName(exec, r0).data(), f0, shouldCheck ? "<Checked>" : "<Unchecked>");
  1217. break;
  1218. }
  1219. case op_new_func_exp: {
  1220. int r0 = (++it)->u.operand;
  1221. int f0 = (++it)->u.operand;
  1222. out.printf("[%4d] new_func_exp\t %s, f%d", location, registerName(exec, r0).data(), f0);
  1223. break;
  1224. }
  1225. case op_call: {
  1226. printCallOp(out, exec, location, it, "call", DumpCaches);
  1227. break;
  1228. }
  1229. case op_call_eval: {
  1230. printCallOp(out, exec, location, it, "call_eval", DontDumpCaches);
  1231. break;
  1232. }
  1233. case op_call_varargs: {
  1234. int callee = (++it)->u.operand;
  1235. int thisValue = (++it)->u.operand;
  1236. int arguments = (++it)->u.operand;
  1237. int firstFreeRegister = (++it)->u.operand;
  1238. out.printf("[%4d] call_varargs\t %s, %s, %s, %d", location, registerName(exec, callee).data(), registerName(exec, thisValue).data(), registerName(exec, arguments).data(), firstFreeRegister);
  1239. break;
  1240. }
  1241. case op_tear_off_activation: {
  1242. int r0 = (++it)->u.operand;
  1243. out.printf("[%4d] tear_off_activation\t %s", location, registerName(exec, r0).data());
  1244. break;
  1245. }
  1246. case op_tear_off_arguments: {
  1247. int r0 = (++it)->u.operand;
  1248. int r1 = (++it)->u.operand;
  1249. out.printf("[%4d] tear_off_arguments %s, %s", location, registerName(exec, r0).data(), registerName(exec, r1).data());
  1250. break;
  1251. }
  1252. case op_ret: {
  1253. int r0 = (++it)->u.operand;
  1254. out.printf("[%4d] ret\t\t %s", location, registerName(exec, r0).data());
  1255. break;
  1256. }
  1257. case op_call_put_result: {
  1258. int r0 = (++it)->u.operand;
  1259. out.printf("[%4d] call_put_result\t\t %s", location, registerName(exec, r0).data());
  1260. dumpValueProfiling(out, it, hasPrintedProfiling);
  1261. break;
  1262. }
  1263. case op_ret_object_or_this: {
  1264. int r0 = (++it)->u.operand;
  1265. int r1 = (++it)->u.operand;
  1266. out.printf("[%4d] constructor_ret\t\t %s %s", location, registerName(exec, r0).data(), registerName(exec, r1).data());
  1267. break;
  1268. }
  1269. case op_construct: {
  1270. printCallOp(out, exec, location, it, "construct", DumpCaches);
  1271. break;
  1272. }
  1273. case op_strcat: {
  1274. int r0 = (++it)->u.operand;
  1275. int r1 = (++it)->u.operand;
  1276. int count = (++it)->u.operand;
  1277. out.printf("[%4d] strcat\t\t %s, %s, %d", location, registerName(exec, r0).data(), registerName(exec, r1).data(), count);
  1278. break;
  1279. }
  1280. case op_to_primitive: {
  1281. int r0 = (++it)->u.operand;
  1282. int r1 = (++it)->u.operand;
  1283. out.printf("[%4d] to_primitive\t %s, %s", location, registerName(exec, r0).data(), registerName(exec, r1).data());
  1284. break;
  1285. }
  1286. case op_get_pnames: {
  1287. int r0 = it[1].u.operand;
  1288. int r1 = it[2].u.operand;
  1289. int r2 = it[3].u.operand;
  1290. int r3 = it[4].u.operand;
  1291. int offset = it[5].u.operand;
  1292. out.printf("[%4d] get_pnames\t %s, %s, %s, %s, %d(->%d)", location, registerName(exec, r0).data(), registerName(exec, r1).data(), registerName(exec, r2).data(), registerName(exec, r3).data(), offset, location + offset);
  1293. it += OPCODE_LENGTH(op_get_pnames) - 1;
  1294. break;
  1295. }
  1296. case op_next_pname: {
  1297. int dest = it[1].u.operand;
  1298. int base = it[2].u.operand;
  1299. int i = it[3].u.operand;
  1300. int size = it[4].u.operand;
  1301. int iter = it[5].u.operand;
  1302. int offset = it[6].u.operand;
  1303. out.printf("[%4d] next_pname\t %s, %s, %s, %s, %s, %d(->%d)", location, registerName(exec, dest).data(), registerName(exec, base).data(), registerName(exec, i).data(), registerName(exec, size).data(), registerName(exec, iter).data(), offset, location + offset);
  1304. it += OPCODE_LENGTH(op_next_pname) - 1;
  1305. break;
  1306. }
  1307. case op_push_with_scope: {
  1308. int r0 = (++it)->u.operand;
  1309. out.printf("[%4d] push_with_scope\t %s", location, registerName(exec, r0).data());
  1310. break;
  1311. }
  1312. case op_pop_scope: {
  1313. out.printf("[%4d] pop_scope", location);
  1314. break;
  1315. }
  1316. case op_push_name_scope: {
  1317. int id0 = (++it)->u.operand;
  1318. int r1 = (++it)->u.operand;
  1319. unsigned attributes = (++it)->u.operand;
  1320. out.printf("[%4d] push_name_scope \t%s, %s, %u", location, idName(id0, m_identifiers[id0]).data(), registerName(exec, r1).data(), attributes);
  1321. break;
  1322. }
  1323. case op_catch: {
  1324. int r0 = (++it)->u.operand;
  1325. out.printf("[%4d] catch\t\t %s", location, registerName(exec, r0).data());
  1326. break;
  1327. }
  1328. case op_throw: {
  1329. int r0 = (++it)->u.operand;
  1330. out.printf("[%4d] throw\t\t %s", location, registerName(exec, r0).data());
  1331. break;
  1332. }
  1333. case op_throw_static_error: {
  1334. int k0 = (++it)->u.operand;
  1335. int k1 = (++it)->u.operand;
  1336. out.printf("[%4d] throw_static_error\t %s, %s", location, constantName(exec, k0, getConstant(k0)).data(), k1 ? "true" : "false");
  1337. break;
  1338. }
  1339. case op_debug: {
  1340. int debugHookID = (++it)->u.operand;
  1341. int firstLine = (++it)->u.operand;
  1342. int lastLine = (++it)->u.operand;
  1343. int column = (++it)->u.operand;
  1344. out.printf("[%4d] debug\t\t %s, %d, %d, %d", location, debugHookName(debugHookID), firstLine, lastLine, column);
  1345. break;
  1346. }
  1347. case op_profile_will_call: {
  1348. int function = (++it)->u.operand;
  1349. out.printf("[%4d] profile_will_call %s", location, registerName(exec, function).data());
  1350. break;
  1351. }
  1352. case op_profile_did_call: {
  1353. int function = (++it)->u.operand;
  1354. out.printf("[%4d] profile_did_call\t %s", location, registerName(exec, function).data());
  1355. break;
  1356. }
  1357. case op_end: {
  1358. int r0 = (++it)->u.operand;
  1359. out.printf("[%4d] end\t\t %s", location, registerName(exec, r0).data());
  1360. break;
  1361. }
  1362. #if ENABLE(LLINT_C_LOOP)
  1363. default:
  1364. RELEASE_ASSERT_NOT_REACHED();
  1365. #endif
  1366. }
  1367. #if ENABLE(VALUE_PROFILER)
  1368. dumpRareCaseProfile(out, "rare case: ", rareCaseProfileForBytecodeOffset(location), hasPrintedProfiling);
  1369. dumpRareCaseProfile(out, "special fast case: ", specialFastCaseProfileForBytecodeOffset(location), hasPrintedProfiling);
  1370. #endif
  1371. #if ENABLE(DFG_JIT)
  1372. Vector<FrequentExitSite> exitSites = exitProfile().exitSitesFor(location);
  1373. if (!exitSites.isEmpty()) {
  1374. out.print(" !! frequent exits: ");
  1375. CommaPrinter comma;
  1376. for (unsigned i = 0; i < exitSites.size(); ++i)
  1377. out.print(comma, exitSites[i].kind());
  1378. }
  1379. #else // ENABLE(DFG_JIT)
  1380. UNUSED_PARAM(location);
  1381. #endif // ENABLE(DFG_JIT)
  1382. out.print("\n");
  1383. }
  1384. void CodeBlock::dumpBytecode(PrintStream& out, unsigned bytecodeOffset)
  1385. {
  1386. ExecState* exec = m_globalObject->globalExec();
  1387. const Instruction* it = instructions().begin() + bytecodeOffset;
  1388. dumpBytecode(out, exec, instructions().begin(), it);
  1389. }
  1390. #if DUMP_CODE_BLOCK_STATISTICS
  1391. static HashSet<CodeBlock*> liveCodeBlockSet;
  1392. #endif
  1393. #define FOR_EACH_MEMBER_VECTOR(macro) \
  1394. macro(instructions) \
  1395. macro(globalResolveInfos) \
  1396. macro(structureStubInfos) \
  1397. macro(callLinkInfos) \
  1398. macro(linkedCallerList) \
  1399. macro(identifiers) \
  1400. macro(functionExpressions) \
  1401. macro(constantRegisters)
  1402. #define FOR_EACH_MEMBER_VECTOR_RARE_DATA(macro) \
  1403. macro(regexps) \
  1404. macro(functions) \
  1405. macro(exceptionHandlers) \
  1406. macro(immediateSwitchJumpTables) \
  1407. macro(characterSwitchJumpTables) \
  1408. macro(stringSwitchJumpTables) \
  1409. macro(evalCodeCache) \
  1410. macro(expressionInfo) \
  1411. macro(lineInfo) \
  1412. macro(callReturnIndexVector)
  1413. template<typename T>
  1414. static size_t sizeInBytes(const Vector<T>& vector)
  1415. {
  1416. return vector.capacity() * sizeof(T);
  1417. }
  1418. void CodeBlock::dumpStatistics()
  1419. {
  1420. #if DUMP_CODE_BLOCK_STATISTICS
  1421. #define DEFINE_VARS(name) size_t name##IsNotEmpty = 0; size_t name##TotalSize = 0;
  1422. FOR_EACH_MEMBER_VECTOR(DEFINE_VARS)
  1423. FOR_EACH_MEMBER_VECTOR_RARE_DATA(DEFINE_VARS)
  1424. #undef DEFINE_VARS
  1425. // Non-vector data members
  1426. size_t evalCodeCacheIsNotEmpty = 0;
  1427. size_t symbolTableIsNotEmpty = 0;
  1428. size_t symbolTableTotalSize = 0;
  1429. size_t hasRareData = 0;
  1430. size_t isFunctionCode = 0;
  1431. size_t isGlobalCode = 0;
  1432. size_t isEvalCode = 0;
  1433. HashSet<CodeBlock*>::const_iterator end = liveCodeBlockSet.end();
  1434. for (HashSet<CodeBlock*>::const_iterator it = liveCodeBlockSet.begin(); it != end; ++it) {
  1435. CodeBlock* codeBlock = *it;
  1436. #define GET_STATS(name) if (!codeBlock->m_##name.isEmpty()) { name##IsNotEmpty++; name##TotalSize += sizeInBytes(codeBlock->m_##name); }
  1437. FOR_EACH_MEMBER_VECTOR(GET_STATS)
  1438. #undef GET_STATS
  1439. if (codeBlock->symbolTable() && !codeBlock->symbolTable()->isEmpty()) {
  1440. symbolTableIsNotEmpty++;
  1441. symbolTableTotalSize += (codeBlock->symbolTable()->capacity() * (sizeof(SymbolTable::KeyType) + sizeof(SymbolTable::MappedType)));
  1442. }
  1443. if (codeBlock->m_rareData) {
  1444. hasRareData++;
  1445. #define GET_STATS(name) if (!codeBlock->m_rareData->m_##name.isEmpty()) { name##IsNotEmpty++; name##TotalSize += sizeInBytes(codeBlock->m_rareData->m_##name); }
  1446. FOR_EACH_MEMBER_VECTOR_RARE_DATA(GET_STATS)
  1447. #undef GET_STATS
  1448. if (!codeBlock->m_rareData->m_evalCodeCache.isEmpty())
  1449. evalCodeCacheIsNotEmpty++;
  1450. }
  1451. switch (codeBlock->codeType()) {
  1452. case FunctionCode:
  1453. ++isFunctionCode;
  1454. break;
  1455. case GlobalCode:
  1456. ++isGlobalCode;
  1457. break;
  1458. case EvalCode:
  1459. ++isEvalCode;
  1460. break;
  1461. }
  1462. }
  1463. size_t totalSize = 0;
  1464. #define GET_TOTAL_SIZE(name) totalSize += name##TotalSize;
  1465. FOR_EACH_MEMBER_VECTOR(GET_TOTAL_SIZE)
  1466. FOR_EACH_MEMBER_VECTOR_RARE_DATA(GET_TOTAL_SIZE)
  1467. #undef GET_TOTAL_SIZE
  1468. totalSize += symbolTableTotalSize;
  1469. totalSize += (liveCodeBlockSet.size() * sizeof(CodeBlock));
  1470. dataLogF("Number of live CodeBlocks: %d\n", liveCodeBlockSet.size());
  1471. dataLogF("Size of a single CodeBlock [sizeof(CodeBlock)]: %zu\n", sizeof(CodeBlock));
  1472. dataLogF("Size of all CodeBlocks: %zu\n", totalSize);
  1473. dataLogF("Average size of a CodeBlock: %zu\n", totalSize / liveCodeBlockSet.size());
  1474. dataLogF("Number of FunctionCode CodeBlocks: %zu (%.3f%%)\n", isFunctionCode, static_cast<double>(isFunctionCode) * 100.0 / liveCodeBlockSet.size());
  1475. dataLogF("Number of GlobalCode CodeBlocks: %zu (%.3f%%)\n", isGlobalCode, static_cast<double>(isGlobalCode) * 100.0 / liveCodeBlockSet.size());
  1476. dataLogF("Number of EvalCode CodeBlocks: %zu (%.3f%%)\n", isEvalCode, static_cast<double>(isEvalCode) * 100.0 / liveCodeBlockSet.size());
  1477. dataLogF("Number of CodeBlocks with rare data: %zu (%.3f%%)\n", hasRareData, static_cast<double>(hasRareData) * 100.0 / liveCodeBlockSet.size());
  1478. #define PRINT_STATS(name) dataLogF("Number of CodeBlocks with " #name ": %zu\n", name##IsNotEmpty); dataLogF("Size of all " #name ": %zu\n", name##TotalSize);
  1479. FOR_EACH_MEMBER_VECTOR(PRINT_STATS)
  1480. FOR_EACH_MEMBER_VECTOR_RARE_DATA(PRINT_STATS)
  1481. #undef PRINT_STATS
  1482. dataLogF("Number of CodeBlocks with evalCodeCache: %zu\n", evalCodeCacheIsNotEmpty);
  1483. dataLogF("Number of CodeBlocks with symbolTable: %zu\n", symbolTableIsNotEmpty);
  1484. dataLogF("Size of all symbolTables: %zu\n", symbolTableTotalSize);
  1485. #else
  1486. dataLogF("Dumping CodeBlock statistics is not enabled.\n");
  1487. #endif
  1488. }
  1489. CodeBlock::CodeBlock(CopyParsedBlockTag, CodeBlock& other
  1490. #if ENABLE(DETACHED_JIT)
  1491. , CodeBlockType type
  1492. #endif
  1493. )
  1494. : m_globalObject(other.m_globalObject)
  1495. , m_heap(other.m_heap)
  1496. , m_numCalleeRegisters(other.m_numCalleeRegisters)
  1497. , m_numVars(other.m_numVars)
  1498. , m_isConstructor(other.m_isConstructor)
  1499. , m_unlinkedCode(*other.m_vm, other.m_ownerExecutable.get(), other.m_unlinkedCode.get())
  1500. , m_ownerExecutable(*other.m_vm, other.m_ownerExecutable.get(), other.m_ownerExecutable.get())
  1501. , m_vm(other.m_vm)
  1502. , m_instructions(other.m_instructions)
  1503. , m_thisRegister(other.m_thisRegister)
  1504. , m_argumentsRegister(other.m_argumentsRegister)
  1505. , m_activationRegister(other.m_activationRegister)
  1506. , m_isStrictMode(other.m_isStrictMode)
  1507. , m_needsActivation(other.m_needsActivation)
  1508. , m_source(other.m_source)
  1509. , m_sourceOffset(other.m_sourceOffset)
  1510. , m_firstLineColumnOffset(other.m_firstLineColumnOffset)
  1511. , m_codeType(other.m_codeType)
  1512. , m_identifiers(other.m_identifiers)
  1513. , m_constantRegisters(other.m_constantRegisters)
  1514. , m_functionDecls(other.m_functionDecls)
  1515. , m_functionExprs(other.m_functionExprs)
  1516. , m_osrExitCounter(0)
  1517. , m_optimizationDelayCounter(0)
  1518. , m_reoptimizationRetryCounter(0)
  1519. , m_resolveOperations(other.m_resolveOperations)
  1520. , m_putToBaseOperations(other.m_putToBaseOperations)
  1521. #if ENABLE(JIT)
  1522. , m_canCompileWithDFGState(DFG::CapabilityLevelNotSet)
  1523. #endif
  1524. #if ENABLE(DETACHED_JIT)
  1525. , m_type(type)
  1526. #endif
  1527. {
  1528. setNumParameters(other.numParameters());
  1529. optimizeAfterWarmUp();
  1530. jitAfterWarmUp();
  1531. if (other.m_rareData) {
  1532. createRareDataIfNecessary();
  1533. m_rareData->m_exceptionHandlers = other.m_rareData->m_exceptionHandlers;
  1534. m_rareData->m_constantBuffers = other.m_rareData->m_constantBuffers;
  1535. m_rareData->m_immediateSwitchJumpTables = other.m_rareData->m_immediateSwitchJumpTables;
  1536. m_rareData->m_characterSwitchJumpTables = other.m_rareData->m_characterSwitchJumpTables;
  1537. m_rareData->m_stringSwitchJumpTables = other.m_rareData->m_stringSwitchJumpTables;
  1538. }
  1539. }
  1540. CodeBlock::CodeBlock(ScriptExecutable* ownerExecutable, UnlinkedCodeBlock* unlinkedCodeBlock, JSGlobalObject* globalObject, unsigned baseScopeDepth, PassRefPtr<SourceProvider> sourceProvider, unsigned sourceOffset, unsigned firstLineColumnOffset, PassOwnPtr<CodeBlock> alternative
  1541. #if ENABLE(DETACHED_JIT)
  1542. , CodeBlockType type
  1543. #endif
  1544. )
  1545. : m_globalObject(globalObject->vm(), ownerExecutable, globalObject)
  1546. , m_heap(&m_globalObject->vm().heap)
  1547. , m_numCalleeRegisters(unlinkedCodeBlock->m_numCalleeRegisters)
  1548. , m_numVars(unlinkedCodeBlock->m_numVars)
  1549. , m_isConstructor(unlinkedCodeBlock->isConstructor())
  1550. , m_unlinkedCode(globalObject->vm(), ownerExecutable, unlinkedCodeBlock)
  1551. , m_ownerExecutable(globalObject->vm(), ownerExecutable, ownerExecutable)
  1552. , m_vm(unlinkedCodeBlock->vm())
  1553. , m_thisRegister(unlinkedCodeBlock->thisRegister())
  1554. , m_argumentsRegister(unlinkedCodeBlock->argumentsRegister())
  1555. , m_activationRegister(unlinkedCodeBlock->activationRegister())
  1556. , m_isStrictMode(unlinkedCodeBlock->isStrictMode())
  1557. , m_needsActivation(unlinkedCodeBlock->needsFullScopeChain())
  1558. , m_source(sourceProvider)
  1559. , m_sourceOffset(sourceOffset)
  1560. , m_firstLineColumnOffset(firstLineColumnOffset)
  1561. , m_codeType(unlinkedCodeBlock->codeType())
  1562. , m_alternative(alternative)
  1563. , m_osrExitCounter(0)
  1564. , m_optimizationDelayCounter(0)
  1565. , m_reoptimizationRetryCounter(0)
  1566. #if ENABLE(DETACHED_JIT)
  1567. , m_type(type)
  1568. #endif
  1569. {
  1570. m_vm->startedCompiling(this);
  1571. ASSERT(m_source);
  1572. setNumParameters(unlinkedCodeBlock->numParameters());
  1573. #if DUMP_CODE_BLOCK_STATISTICS
  1574. liveCodeBlockSet.add(this);
  1575. #endif
  1576. setIdentifiers(unlinkedCodeBlock->identifiers());
  1577. setConstantRegisters(unlinkedCodeBlock->constantRegisters());
  1578. if (unlinkedCodeBlock->usesGlobalObject())
  1579. m_constantRegisters[unlinkedCodeBlock->globalObjectRegister()].set(*m_vm, ownerExecutable, globalObject);
  1580. m_functionDecls.grow(unlinkedCodeBlock->numberOfFunctionDecls());
  1581. for (size_t count = unlinkedCodeBlock->numberOfFunctionDecls(), i = 0; i < count; ++i) {
  1582. UnlinkedFunctionExecutable* unlinkedExecutable = unlinkedCodeBlock->functionDecl(i);
  1583. unsigned lineCount = unlinkedExecutable->lineCount();
  1584. unsigned firstLine = ownerExecutable->lineNo() + unlinkedExecutable->firstLineOffset();
  1585. unsigned startColumn = unlinkedExecutable->functionStartColumn();
  1586. startColumn += (unlinkedExecutable->firstLineOffset() ? 1 : ownerExecutable->startColumn());
  1587. unsigned startOffset = sourceOffset + unlinkedExecutable->startOffset();
  1588. unsigned sourceLength = unlinkedExecutable->sourceLength();
  1589. SourceCode code(m_source, startOffset, startOffset + sourceLength, firstLine, startColumn);
  1590. FunctionExecutable* executable = FunctionExecutable::create(*m_vm, code, unlinkedExecutable, firstLine, firstLine + lineCount, startColumn);
  1591. m_functionDecls[i].set(*m_vm, ownerExecutable, executable);
  1592. }
  1593. m_functionExprs.grow(unlinkedCodeBlock->numberOfFunctionExprs());
  1594. for (size_t count = unlinkedCodeBlock->numberOfFunctionExprs(), i = 0; i < count; ++i) {
  1595. UnlinkedFunctionExecutable* unlinkedExecutable = unlinkedCodeBlock->functionExpr(i);
  1596. unsigned lineCount = unlinkedExecutable->lineCount();
  1597. unsigned firstLine = ownerExecutable->lineNo() + unlinkedExecutable->firstLineOffset();
  1598. unsigned startColumn = unlinkedExecutable->functionStartColumn();
  1599. startColumn += (unlinkedExecutable->firstLineOffset() ? 1 : ownerExecutable->startColumn());
  1600. unsigned startOffset = sourceOffset + unlinkedExecutable->startOffset();
  1601. unsigned sourceLength = unlinkedExecutable->sourceLength();
  1602. SourceCode code(m_source, startOffset, startOffset + sourceLength, firstLine, startColumn);
  1603. FunctionExecutable* executable = FunctionExecutable::create(*m_vm, code, unlinkedExecutable, firstLine, firstLine + lineCount, startColumn);
  1604. m_functionExprs[i].set(*m_vm, ownerExecutable, executable);
  1605. }
  1606. if (unlinkedCodeBlock->hasRareData()) {
  1607. createRareDataIfNecessary();
  1608. if (size_t count = unlinkedCodeBlock->constantBufferCount()) {
  1609. m_rareData->m_constantBuffers.grow(count);
  1610. for (size_t i = 0; i < count; i++) {
  1611. const UnlinkedCodeBlock::ConstantBuffer& buffer = unlinkedCodeBlock->constantBuffer(i);
  1612. m_rareData->m_constantBuffers[i] = buffer;
  1613. }
  1614. }
  1615. if (size_t count = unlinkedCodeBlock->numberOfExceptionHandlers()) {
  1616. m_rareData->m_exceptionHandlers.grow(count);
  1617. for (size_t i = 0; i < count; i++) {
  1618. const UnlinkedHandlerInfo& handler = unlinkedCodeBlock->exceptionHandler(i);
  1619. m_rareData->m_exceptionHandlers[i].start = handler.start;
  1620. m_rareData->m_exceptionHandlers[i].end = handler.end;
  1621. m_rareData->m_exceptionHandlers[i].target = handler.target;
  1622. m_rareData->m_exceptionHandlers[i].scopeDepth = handler.scopeDepth + baseScopeDepth;
  1623. #if ENABLE(JIT) && ENABLE(LLINT)
  1624. m_rareData->m_exceptionHandlers[i].nativeCode = CodeLocationLabel(MacroAssemblerCodePtr::createFromExecutableAddress(LLInt::getCodePtr(llint_op_catch)));
  1625. #endif
  1626. }
  1627. }
  1628. if (size_t count = unlinkedCodeBlock->numberOfStringSwitchJumpTables()) {
  1629. m_rareData->m_stringSwitchJumpTables.grow(count);
  1630. for (size_t i = 0; i < count; i++) {
  1631. UnlinkedStringJumpTable::StringOffsetTable::iterator ptr = unlinkedCodeBlock->stringSwitchJumpTable(i).offsetTable.begin();
  1632. UnlinkedStringJumpTable::StringOffsetTable::iterator end = unlinkedCodeBlock->stringSwitchJumpTable(i).offsetTable.end();
  1633. for (; ptr != end; ++ptr) {
  1634. OffsetLocation offset;
  1635. offset.branchOffset = ptr->value;
  1636. m_rareData->m_stringSwitchJumpTables[i].offsetTable.add(ptr->key, offset);
  1637. }
  1638. }
  1639. }
  1640. if (size_t count = unlinkedCodeBlock->numberOfImmediateSwitchJumpTables()) {
  1641. m_rareData->m_immediateSwitchJumpTables.grow(count);
  1642. for (size_t i = 0; i < count; i++) {
  1643. UnlinkedSimpleJumpTable& sourceTable = unlinkedCodeBlock->immediateSwitchJumpTable(i);
  1644. SimpleJumpTable& destTable = m_rareData->m_immediateSwitchJumpTables[i];
  1645. destTable.branchOffsets = sourceTable.branchOffsets;
  1646. destTable.min = sourceTable.min;
  1647. }
  1648. }
  1649. if (size_t count = unlinkedCodeBlock->numberOfCharacterSwitchJumpTables()) {
  1650. m_rareData->m_characterSwitchJumpTables.grow(count);
  1651. for (size_t i = 0; i < count; i++) {
  1652. UnlinkedSimpleJumpTable& sourceTable = unlinkedCodeBlock->characterSwitchJumpTable(i);
  1653. SimpleJumpTable& destTable = m_rareData->m_characterSwitchJumpTables[i];
  1654. destTable.branchOffsets = sourceTable.branchOffsets;
  1655. destTable.min = sourceTable.min;
  1656. }
  1657. }
  1658. }
  1659. // Allocate metadata buffers for the bytecode
  1660. #if ENABLE(LLINT)
  1661. if (size_t size = unlinkedCodeBlock->numberOfLLintCallLinkInfos())
  1662. m_llintCallLinkInfos.grow(size);
  1663. #endif
  1664. #if ENABLE(DFG_JIT)
  1665. if (size_t size = unlinkedCodeBlock->numberOfArrayProfiles())
  1666. m_arrayProfiles.grow(size);
  1667. if (size_t size = unlinkedCodeBlock->numberOfArrayAllocationProfiles())
  1668. m_arrayAllocationProfiles.grow(size);
  1669. if (size_t size = unlinkedCodeBlock->numberOfValueProfiles())
  1670. m_valueProfiles.grow(size);
  1671. #endif
  1672. if (size_t size = unlinkedCodeBlock->numberOfObjectAllocationProfiles())
  1673. m_objectAllocationProfiles.grow(size);
  1674. if (size_t size = unlinkedCodeBlock->numberOfResolveOperations())
  1675. m_resolveOperations.grow(size);
  1676. if (size_t putToBaseCount = unlinkedCodeBlock->numberOfPutToBaseOperations()) {
  1677. m_putToBaseOperations.reserveInitialCapacity(putToBaseCount);
  1678. for (size_t i = 0; i < putToBaseCount; ++i)
  1679. m_putToBaseOperations.uncheckedAppend(PutToBaseOperation(isStrictMode()));
  1680. }
  1681. // Copy and translate the UnlinkedInstructions
  1682. size_t instructionCount = unlinkedCodeBlock->instructions().size();
  1683. UnlinkedInstruction* pc = unlinkedCodeBlock->instructions().data();
  1684. Vector_shared<Instruction, 0, UnsafeVectorOverflow> instructions(instructionCount);
  1685. for (size_t i = 0; i < unlinkedCodeBlock->instructions().size(); ) {
  1686. unsigned opLength = opcodeLength(pc[i].u.opcode);
  1687. instructions[i] = vm()->interpreter->getOpcode(pc[i].u.opcode);
  1688. for (size_t j = 1; j < opLength; ++j) {
  1689. if (sizeof(int32_t) != sizeof(intptr_t))
  1690. instructions[i + j].u.pointer = 0;
  1691. instructions[i + j].u.operand = pc[i + j].u.operand;
  1692. }
  1693. switch (pc[i].u.opcode) {
  1694. #if ENABLE(DFG_JIT)
  1695. case op_get_by_val:
  1696. case op_get_argument_by_val: {
  1697. int arrayProfileIndex = pc[i + opLength - 2].u.operand;
  1698. m_arrayProfiles[arrayProfileIndex] = ArrayProfile(i);
  1699. instructions[i + opLength - 2] = &m_arrayProfiles[arrayProfileIndex];
  1700. // fallthrough
  1701. }
  1702. case op_convert_this:
  1703. case op_get_by_id:
  1704. case op_call_put_result:
  1705. case op_get_callee: {
  1706. ValueProfile* profile = &m_valueProfiles[pc[i + opLength - 1].u.operand];
  1707. ASSERT(profile->m_bytecodeOffset == -1);
  1708. profile->m_bytecodeOffset = i;
  1709. instructions[i + opLength - 1] = profile;
  1710. break;
  1711. }
  1712. case op_put_by_val: {
  1713. int arrayProfileIndex = pc[i + opLength - 1].u.operand;
  1714. m_arrayProfiles[arrayProfileIndex] = ArrayProfile(i);
  1715. instructions[i + opLength - 1] = &m_arrayProfiles[arrayProfileIndex];
  1716. break;
  1717. }
  1718. case op_new_array:
  1719. case op_new_array_buffer:
  1720. case op_new_array_with_size: {
  1721. int arrayAllocationProfileIndex = pc[i + opLength - 1].u.operand;
  1722. instructions[i + opLength - 1] = &m_arrayAllocationProfiles[arrayAllocationProfileIndex];
  1723. break;
  1724. }
  1725. #endif
  1726. case op_resolve_base:
  1727. case op_resolve_base_to_global:
  1728. case op_resolve_base_to_global_dynamic:
  1729. case op_resolve_base_to_scope:
  1730. case op_resolve_base_to_scope_with_top_scope_check: {
  1731. instructions[i + 4].u.resolveOperations = &m_resolveOperations[pc[i + 4].u.operand];
  1732. instructions[i + 5].u.putToBaseOperation = &m_putToBaseOperations[pc[i + 5].u.operand];
  1733. #if ENABLE(DFG_JIT)
  1734. ValueProfile* profile = &m_valueProfiles[pc[i + opLength - 1].u.operand];
  1735. ASSERT(profile->m_bytecodeOffset == -1);
  1736. profile->m_bytecodeOffset = i;
  1737. ASSERT((opLength - 1) > 5);
  1738. instructions[i + opLength - 1] = profile;
  1739. #endif
  1740. break;
  1741. }
  1742. case op_resolve_global_property:
  1743. case op_resolve_global_var:
  1744. case op_resolve_scoped_var:
  1745. case op_resolve_scoped_var_on_top_scope:
  1746. case op_resolve_scoped_var_with_top_scope_check: {
  1747. instructions[i + 3].u.resolveOperations = &m_resolveOperations[pc[i + 3].u.operand];
  1748. break;
  1749. }
  1750. case op_put_to_base:
  1751. case op_put_to_base_variable: {
  1752. instructions[i + 4].u.putToBaseOperation = &m_putToBaseOperations[pc[i + 4].u.operand];
  1753. break;
  1754. }
  1755. case op_resolve: {
  1756. #if ENABLE(DFG_JIT)
  1757. ValueProfile* profile = &m_valueProfiles[pc[i + opLength - 1].u.operand];
  1758. ASSERT(profile->m_bytecodeOffset == -1);
  1759. profile->m_bytecodeOffset = i;
  1760. ASSERT((opLength - 1) > 3);
  1761. instructions[i + opLength - 1] = profile;
  1762. #endif
  1763. instructions[i + 3].u.resolveOperations = &m_resolveOperations[pc[i + 3].u.operand];
  1764. break;
  1765. }
  1766. case op_resolve_with_base:
  1767. case op_resolve_with_this: {
  1768. instructions[i + 4].u.resolveOperations = &m_resolveOperations[pc[i + 4].u.operand];
  1769. if (pc[i].u.opcode != op_resolve_with_this)
  1770. instructions[i + 5].u.putToBaseOperation = &m_putToBaseOperations[pc[i + 5].u.operand];
  1771. #if ENABLE(DFG_JIT)
  1772. ValueProfile* profile = &m_valueProfiles[pc[i + opLength - 1].u.operand];
  1773. ASSERT(profile->m_bytecodeOffset == -1);
  1774. profile->m_bytecodeOffset = i;
  1775. instructions[i + opLength - 1] = profile;
  1776. #endif
  1777. break;
  1778. }
  1779. case op_new_object: {
  1780. int objectAllocationProfileIndex = pc[i + opLength - 1].u.operand;
  1781. ObjectAllocationProfile* objectAllocationProfile = &m_objectAllocationProfiles[objectAllocationProfileIndex];
  1782. int inferredInlineCapacity = pc[i + opLength - 2].u.operand;
  1783. instructions[i + opLength - 1] = objectAllocationProfile;
  1784. objectAllocationProfile->initialize(*vm(),
  1785. m_ownerExecutable.get(), m_globalObject->objectPrototype(), inferredInlineCapacity);
  1786. break;
  1787. }
  1788. case op_get_scoped_var: {
  1789. #if ENABLE(DFG_JIT)
  1790. ValueProfile* profile = &m_valueProfiles[pc[i + opLength - 1].u.operand];
  1791. ASSERT(profile->m_bytecodeOffset == -1);
  1792. profile->m_bytecodeOffset = i;
  1793. instructions[i + opLength - 1] = profile;
  1794. #endif
  1795. break;
  1796. }
  1797. case op_call:
  1798. case op_call_eval: {
  1799. #if ENABLE(DFG_JIT)
  1800. int arrayProfileIndex = pc[i + opLength - 1].u.operand;
  1801. m_arrayProfiles[arrayProfileIndex] = ArrayProfile(i);
  1802. instructions[i + opLength - 1] = &m_arrayProfiles[arrayProfileIndex];
  1803. #endif
  1804. #if ENABLE(LLINT)
  1805. instructions[i + 4] = &m_llintCallLinkInfos[pc[i + 4].u.operand];
  1806. #endif
  1807. break;
  1808. }
  1809. case op_construct:
  1810. #if ENABLE(LLINT)
  1811. instructions[i + 4] = &m_llintCallLinkInfos[pc[i + 4].u.operand];
  1812. #endif
  1813. break;
  1814. case op_get_by_id_out_of_line:
  1815. case op_get_by_id_self:
  1816. case op_get_by_id_proto:
  1817. case op_get_by_id_chain:
  1818. case op_get_by_id_getter_self:
  1819. case op_get_by_id_getter_proto:
  1820. case op_get_by_id_getter_chain:
  1821. case op_get_by_id_custom_self:
  1822. case op_get_by_id_custom_proto:
  1823. case op_get_by_id_custom_chain:
  1824. case op_get_by_id_generic:
  1825. case op_get_array_length:
  1826. case op_get_string_length:
  1827. CRASH();
  1828. case op_init_global_const_nop: {
  1829. ASSERT(codeType() == GlobalCode);
  1830. Identifier ident = identifier(pc[i + 4].u.operand);
  1831. SymbolTableEntry entry = globalObject->symbolTable()->get(ident.impl());
  1832. if (entry.isNull())
  1833. break;
  1834. if (entry.couldBeWatched()) {
  1835. instructions[i + 0] = vm()->interpreter->getOpcode(op_init_global_const_check);
  1836. instructions[i + 1] = &globalObject->registerAt(entry.getIndex());
  1837. instructions[i + 3] = entry.addressOfIsWatched();
  1838. break;
  1839. }
  1840. instructions[i + 0] = vm()->interpreter->getOpcode(op_init_global_const);
  1841. instructions[i + 1] = &globalObject->registerAt(entry.getIndex());
  1842. break;
  1843. }
  1844. case op_debug: {
  1845. instructions[i + 4] = columnNumberForBytecodeOffset(i);
  1846. break;
  1847. }
  1848. default:
  1849. break;
  1850. }
  1851. i += opLength;
  1852. }
  1853. m_instructions = WTF::RefCountedArray_shared<Instruction>(instructions);
  1854. // Set optimization thresholds only after m_instructions is initialized, since these
  1855. // rely on the instruction count (and are in theory permitted to also inspect the
  1856. // instruction stream to more accurate assess the cost of tier-up).
  1857. optimizeAfterWarmUp();
  1858. jitAfterWarmUp();
  1859. if (Options::dumpGeneratedBytecodes())
  1860. dumpBytecode();
  1861. m_vm->finishedCompiling(this);
  1862. }
  1863. CodeBlock::~CodeBlock()
  1864. {
  1865. #if ENABLE(DETACHED_JIT)
  1866. #pragma message "[SECURE JSCORE] profiler is disabled"
  1867. #else
  1868. if (m_vm->m_perBytecodeProfiler)
  1869. m_vm->m_perBytecodeProfiler->notifyDestruction(this);
  1870. #endif
  1871. #if ENABLE(DFG_JIT)
  1872. // Remove myself from the set of DFG code blocks. Note that I may not be in this set
  1873. // (because I'm not a DFG code block), in which case this is a no-op anyway.
  1874. m_vm->heap.m_dfgCodeBlocks.m_set.remove(this);
  1875. #endif
  1876. #if ENABLE(VERBOSE_VALUE_PROFILE)
  1877. dumpValueProfiles();
  1878. #endif
  1879. #if ENABLE(LLINT)
  1880. while (m_incomingLLIntCalls.begin() != m_incomingLLIntCalls.end())
  1881. m_incomingLLIntCalls.begin()->remove();
  1882. #endif // ENABLE(LLINT)
  1883. #if ENABLE(JIT)
  1884. // We may be destroyed before any CodeBlocks that refer to us are destroyed.
  1885. // Consider that two CodeBlocks become unreachable at the same time. There
  1886. // is no guarantee about the order in which the CodeBlocks are destroyed.
  1887. // So, if we don't remove incoming calls, and get destroyed before the
  1888. // CodeBlock(s) that have calls into us, then the CallLinkInfo vector's
  1889. // destructor will try to remove nodes from our (no longer valid) linked list.
  1890. while (m_incomingCalls.begin() != m_incomingCalls.end())
  1891. m_incomingCalls.begin()->remove();
  1892. // Note that our outgoing calls will be removed from other CodeBlocks'
  1893. // m_incomingCalls linked lists through the execution of the ~CallLinkInfo
  1894. // destructors.
  1895. for (size_t size = m_structureStubInfos.size(), i = 0; i < size; ++i)
  1896. m_structureStubInfos[i].deref();
  1897. #endif // ENABLE(JIT)
  1898. #if DUMP_CODE_BLOCK_STATISTICS
  1899. liveCodeBlockSet.remove(this);
  1900. #endif
  1901. }
  1902. void CodeBlock::setNumParameters(int newValue)
  1903. {
  1904. m_numParameters = newValue;
  1905. #if ENABLE(VALUE_PROFILER)
  1906. m_argumentValueProfiles.resizeToFit(newValue);
  1907. #endif
  1908. }
  1909. void CodeBlock::visitStructures(SlotVisitor& visitor, Instruction* vPC)
  1910. {
  1911. Interpreter* interpreter = m_vm->interpreter;
  1912. if (vPC[0].u.opcode == interpreter->getOpcode(op_get_by_id) && vPC[4].u.structure) {
  1913. visitor.append(&vPC[4].u.structure);
  1914. return;
  1915. }
  1916. if (vPC[0].u.opcode == interpreter->getOpcode(op_get_by_id_self) || vPC[0].u.opcode == interpreter->getOpcode(op_get_by_id_getter_self) || vPC[0].u.opcode == interpreter->getOpcode(op_get_by_id_custom_self)) {
  1917. visitor.append(&vPC[4].u.structure);
  1918. return;
  1919. }
  1920. if (vPC[0].u.opcode == interpreter->getOpcode(op_get_by_id_proto) || vPC[0].u.opcode == interpreter->getOpcode(op_get_by_id_getter_proto) || vPC[0].u.opcode == interpreter->getOpcode(op_get_by_id_custom_proto)) {
  1921. visitor.append(&vPC[4].u.structure);
  1922. visitor.append(&vPC[5].u.structure);
  1923. return;
  1924. }
  1925. if (vPC[0].u.opcode == interpreter->getOpcode(op_get_by_id_chain) || vPC[0].u.opcode == interpreter->getOpcode(op_get_by_id_getter_chain) || vPC[0].u.opcode == interpreter->getOpcode(op_get_by_id_custom_chain)) {
  1926. visitor.append(&vPC[4].u.structure);
  1927. if (vPC[5].u.structureChain)
  1928. visitor.append(&vPC[5].u.structureChain);
  1929. return;
  1930. }
  1931. if (vPC[0].u.opcode == interpreter->getOpcode(op_put_by_id_transition)) {
  1932. visitor.append(&vPC[4].u.structure);
  1933. visitor.append(&vPC[5].u.structure);
  1934. if (vPC[6].u.structureChain)
  1935. visitor.append(&vPC[6].u.structureChain);
  1936. return;
  1937. }
  1938. if (vPC[0].u.opcode == interpreter->getOpcode(op_put_by_id) && vPC[4].u.structure) {
  1939. visitor.append(&vPC[4].u.structure);
  1940. return;
  1941. }
  1942. if (vPC[0].u.opcode == interpreter->getOpcode(op_put_by_id_replace)) {
  1943. visitor.append(&vPC[4].u.structure);
  1944. return;
  1945. }
  1946. // These instructions don't ref their Structures.
  1947. ASSERT(vPC[0].u.opcode == interpreter->getOpcode(op_get_by_id) || vPC[0].u.opcode == interpreter->getOpcode(op_put_by_id) || vPC[0].u.opcode == interpreter->getOpcode(op_get_by_id_generic) || vPC[0].u.opcode == interpreter->getOpcode(op_put_by_id_generic) || vPC[0].u.opcode == interpreter->getOpcode(op_get_array_length) || vPC[0].u.opcode == interpreter->getOpcode(op_get_string_length));
  1948. }
  1949. void EvalCodeCache::visitAggregate(SlotVisitor& visitor)
  1950. {
  1951. EvalCacheMap::iterator end = m_cacheMap.end();
  1952. for (EvalCacheMap::iterator ptr = m_cacheMap.begin(); ptr != end; ++ptr)
  1953. visitor.append(&ptr->value);
  1954. }
  1955. void CodeBlock::visitAggregate(SlotVisitor& visitor)
  1956. {
  1957. #if ENABLE(PARALLEL_GC) && ENABLE(DFG_JIT)
  1958. if (!!m_dfgData) {
  1959. // I may be asked to scan myself more than once, and it may even happen concurrently.
  1960. // To this end, use a CAS loop to check if I've been called already. Only one thread
  1961. // may proceed past this point - whichever one wins the CAS race.
  1962. unsigned oldValue;
  1963. do {
  1964. oldValue = m_dfgData->visitAggregateHasBeenCalled;
  1965. if (oldValue) {
  1966. // Looks like someone else won! Return immediately to ensure that we don't
  1967. // trace the same CodeBlock concurrently. Doing so is hazardous since we will
  1968. // be mutating the state of ValueProfiles, which contain JSValues, which can
  1969. // have word-tearing on 32-bit, leading to awesome timing-dependent crashes
  1970. // that are nearly impossible to track down.
  1971. // Also note that it must be safe to return early as soon as we see the
  1972. // value true (well, (unsigned)1), since once a GC thread is in this method
  1973. // and has won the CAS race (i.e. was responsible for setting the value true)
  1974. // it will definitely complete the rest of this method before declaring
  1975. // termination.
  1976. return;
  1977. }
  1978. } while (!WTF::weakCompareAndSwap(&m_dfgData->visitAggregateHasBeenCalled, 0, 1));
  1979. }
  1980. #endif // ENABLE(PARALLEL_GC) && ENABLE(DFG_JIT)
  1981. if (!!m_alternative)
  1982. m_alternative->visitAggregate(visitor);
  1983. visitor.append(&m_unlinkedCode);
  1984. // There are three things that may use unconditional finalizers: lazy bytecode freeing,
  1985. // inline cache clearing, and jettisoning. The probability of us wanting to do at
  1986. // least one of those things is probably quite close to 1. So we add one no matter what
  1987. // and when it runs, it figures out whether it has any work to do.
  1988. visitor.addUnconditionalFinalizer(this);
  1989. if (shouldImmediatelyAssumeLivenessDuringScan()) {
  1990. // This code block is live, so scan all references strongly and return.
  1991. stronglyVisitStrongReferences(visitor);
  1992. stronglyVisitWeakReferences(visitor);
  1993. return;
  1994. }
  1995. #if ENABLE(DFG_JIT)
  1996. // We get here if we're live in the sense that our owner executable is live,
  1997. // but we're not yet live for sure in another sense: we may yet decide that this
  1998. // code block should be jettisoned based on its outgoing weak references being
  1999. // stale. Set a flag to indicate that we're still assuming that we're dead, and
  2000. // perform one round of determining if we're live. The GC may determine, based on
  2001. // either us marking additional objects, or by other objects being marked for
  2002. // other reasons, that this iteration should run again; it will notify us of this
  2003. // decision by calling harvestWeakReferences().
  2004. m_dfgData->livenessHasBeenProved = false;
  2005. m_dfgData->allTransitionsHaveBeenMarked = false;
  2006. performTracingFixpointIteration(visitor);
  2007. // GC doesn't have enough information yet for us to decide whether to keep our DFG
  2008. // data, so we need to register a handler to run again at the end of GC, when more
  2009. // information is available.
  2010. if (!(m_dfgData->livenessHasBeenProved && m_dfgData->allTransitionsHaveBeenMarked))
  2011. visitor.addWeakReferenceHarvester(this);
  2012. #else // ENABLE(DFG_JIT)
  2013. RELEASE_ASSERT_NOT_REACHED();
  2014. #endif // ENABLE(DFG_JIT)
  2015. }
  2016. void CodeBlock::performTracingFixpointIteration(SlotVisitor& visitor)
  2017. {
  2018. UNUSED_PARAM(visitor);
  2019. #if ENABLE(DFG_JIT)
  2020. // Evaluate our weak reference transitions, if there are still some to evaluate.
  2021. if (!m_dfgData->allTransitionsHaveBeenMarked) {
  2022. bool allAreMarkedSoFar = true;
  2023. for (unsigned i = 0; i < m_dfgData->transitions.size(); ++i) {
  2024. if ((!m_dfgData->transitions[i].m_codeOrigin
  2025. || Heap::isMarked(m_dfgData->transitions[i].m_codeOrigin.get()))
  2026. && Heap::isMarked(m_dfgData->transitions[i].m_from.get())) {
  2027. // If the following three things are live, then the target of the
  2028. // transition is also live:
  2029. // - This code block. We know it's live already because otherwise
  2030. // we wouldn't be scanning ourselves.
  2031. // - The code origin of the transition. Transitions may arise from
  2032. // code that was inlined. They are not relevant if the user's
  2033. // object that is required for the inlinee to run is no longer
  2034. // live.
  2035. // - The source of the transition. The transition checks if some
  2036. // heap location holds the source, and if so, stores the target.
  2037. // Hence the source must be live for the transition to be live.
  2038. visitor.append(&m_dfgData->transitions[i].m_to);
  2039. } else
  2040. allAreMarkedSoFar = false;
  2041. }
  2042. if (allAreMarkedSoFar)
  2043. m_dfgData->allTransitionsHaveBeenMarked = true;
  2044. }
  2045. // Check if we have any remaining work to do.
  2046. if (m_dfgData->livenessHasBeenProved)
  2047. return;
  2048. // Now check all of our weak references. If all of them are live, then we
  2049. // have proved liveness and so we scan our strong references. If at end of
  2050. // GC we still have not proved liveness, then this code block is toast.
  2051. bool allAreLiveSoFar = true;
  2052. for (unsigned i = 0; i < m_dfgData->weakReferences.size(); ++i) {
  2053. if (!Heap::isMarked(m_dfgData->weakReferences[i].get())) {
  2054. allAreLiveSoFar = false;
  2055. break;
  2056. }
  2057. }
  2058. // If some weak references are dead, then this fixpoint iteration was
  2059. // unsuccessful.
  2060. if (!allAreLiveSoFar)
  2061. return;
  2062. // All weak references are live. Record this information so we don't
  2063. // come back here again, and scan the strong references.
  2064. m_dfgData->livenessHasBeenProved = true;
  2065. stronglyVisitStrongReferences(visitor);
  2066. #endif // ENABLE(DFG_JIT)
  2067. }
  2068. void CodeBlock::visitWeakReferences(SlotVisitor& visitor)
  2069. {
  2070. performTracingFixpointIteration(visitor);
  2071. }
  2072. #endif // !(ENABLE(DETACHED_JIT) && BUILDING_DETACHED_JIT)
  2073. #if ENABLE(JIT_VERBOSE_OSR)
  2074. static const bool verboseUnlinking = true;
  2075. #else
  2076. static const bool verboseUnlinking = false;
  2077. #endif
  2078. #if !(ENABLE(DETACHED_JIT) && BUILDING_DETACHED_JIT)
  2079. void CodeBlock::finalizeUnconditionally()
  2080. {
  2081. #if ENABLE(LLINT)
  2082. Interpreter* interpreter = m_vm->interpreter;
  2083. if (!!numberOfInstructions()) {
  2084. const Vector<unsigned>& propertyAccessInstructions = m_unlinkedCode->propertyAccessInstructions();
  2085. for (size_t size = propertyAccessInstructions.size(), i = 0; i < size; ++i) {
  2086. Instruction* curInstruction = &instructions()[propertyAccessInstructions[i]];
  2087. switch (interpreter->getOpcodeID(curInstruction[0].u.opcode)) {
  2088. case op_get_by_id:
  2089. case op_get_by_id_out_of_line:
  2090. case op_put_by_id:
  2091. case op_put_by_id_out_of_line:
  2092. if (!curInstruction[4].u.structure || Heap::isMarked(curInstruction[4].u.structure.get()))
  2093. break;
  2094. if (verboseUnlinking)
  2095. dataLogF("Clearing LLInt property access with structure %p.\n", curInstruction[4].u.structure.get());
  2096. curInstruction[4].u.structure.clear();
  2097. curInstruction[5].u.operand = 0;
  2098. break;
  2099. case op_put_by_id_transition_direct:
  2100. case op_put_by_id_transition_normal:
  2101. case op_put_by_id_transition_direct_out_of_line:
  2102. case op_put_by_id_transition_normal_out_of_line:
  2103. if (Heap::isMarked(curInstruction[4].u.structure.get())
  2104. && Heap::isMarked(curInstruction[6].u.structure.get())
  2105. && Heap::isMarked(curInstruction[7].u.structureChain.get()))
  2106. break;
  2107. if (verboseUnlinking) {
  2108. dataLogF("Clearing LLInt put transition with structures %p -> %p, chain %p.\n",
  2109. curInstruction[4].u.structure.get(),
  2110. curInstruction[6].u.structure.get(),
  2111. curInstruction[7].u.structureChain.get());
  2112. }
  2113. curInstruction[4].u.structure.clear();
  2114. curInstruction[6].u.structure.clear();
  2115. curInstruction[7].u.structureChain.clear();
  2116. curInstruction[0].u.opcode = interpreter->getOpcode(op_put_by_id);
  2117. break;
  2118. case op_get_array_length:
  2119. break;
  2120. default:
  2121. RELEASE_ASSERT_NOT_REACHED();
  2122. }
  2123. }
  2124. for (unsigned i = 0; i < m_llintCallLinkInfos.size(); ++i) {
  2125. if (m_llintCallLinkInfos[i].isLinked() && !Heap::isMarked(m_llintCallLinkInfos[i].callee.get())) {
  2126. if (verboseUnlinking)
  2127. dataLog("Clearing LLInt call from ", *this, "\n");
  2128. m_llintCallLinkInfos[i].unlink();
  2129. }
  2130. if (!!m_llintCallLinkInfos[i].lastSeenCallee && !Heap::isMarked(m_llintCallLinkInfos[i].lastSeenCallee.get()))
  2131. m_llintCallLinkInfos[i].lastSeenCallee.clear();
  2132. }
  2133. }
  2134. #endif // ENABLE(LLINT)
  2135. #if ENABLE(DFG_JIT)
  2136. // Check if we're not live. If we are, then jettison.
  2137. if (!(shouldImmediatelyAssumeLivenessDuringScan() || m_dfgData->livenessHasBeenProved)) {
  2138. if (verboseUnlinking)
  2139. dataLog(*this, " has dead weak references, jettisoning during GC.\n");
  2140. if (DFG::shouldShowDisassembly()) {
  2141. dataLog(*this, " will be jettisoned because of the following dead references:\n");
  2142. for (unsigned i = 0; i < m_dfgData->transitions.size(); ++i) {
  2143. WeakReferenceTransition& transition = m_dfgData->transitions[i];
  2144. JSCell* origin = transition.m_codeOrigin.get();
  2145. JSCell* from = transition.m_from.get();
  2146. JSCell* to = transition.m_to.get();
  2147. if ((!origin || Heap::isMarked(origin)) && Heap::isMarked(from))
  2148. continue;
  2149. dataLog(" Transition under ", JSValue(origin), ", ", JSValue(from), " -> ", JSValue(to), ".\n");
  2150. }
  2151. for (unsigned i = 0; i < m_dfgData->weakReferences.size(); ++i) {
  2152. JSCell* weak = m_dfgData->weakReferences[i].get();
  2153. if (Heap::isMarked(weak))
  2154. continue;
  2155. dataLog(" Weak reference ", JSValue(weak), ".\n");
  2156. }
  2157. }
  2158. jettison();
  2159. return;
  2160. }
  2161. #endif // ENABLE(DFG_JIT)
  2162. for (size_t size = m_putToBaseOperations.size(), i = 0; i < size; ++i) {
  2163. if (m_putToBaseOperations[i].m_structure && !Heap::isMarked(m_putToBaseOperations[i].m_structure.get())) {
  2164. if (verboseUnlinking)
  2165. dataLog("Clearing putToBase info in ", *this, "\n");
  2166. m_putToBaseOperations[i].m_structure.clear();
  2167. }
  2168. }
  2169. for (size_t size = m_resolveOperations.size(), i = 0; i < size; ++i) {
  2170. if (m_resolveOperations[i].isEmpty())
  2171. continue;
  2172. #ifndef NDEBUG
  2173. for (size_t insnSize = m_resolveOperations[i].size() - 1, k = 0; k < insnSize; ++k)
  2174. ASSERT(!m_resolveOperations[i][k].m_structure);
  2175. #endif
  2176. m_resolveOperations[i].last().m_structure.clear();
  2177. if (m_resolveOperations[i].last().m_structure && !Heap::isMarked(m_resolveOperations[i].last().m_structure.get())) {
  2178. if (verboseUnlinking)
  2179. dataLog("Clearing resolve info in ", *this, "\n");
  2180. m_resolveOperations[i].last().m_structure.clear();
  2181. }
  2182. }
  2183. #if ENABLE(JIT)
  2184. // Handle inline caches.
  2185. if (!!getJITCode()) {
  2186. RepatchBuffer repatchBuffer(this);
  2187. for (unsigned i = 0; i < numberOfCallLinkInfos(); ++i) {
  2188. if (callLinkInfo(i).isLinked()) {
  2189. if (ClosureCallStubRoutine* stub = callLinkInfo(i).stub.get()) {
  2190. if (!Heap::isMarked(stub->structure())
  2191. || !Heap::isMarked(stub->executable())) {
  2192. if (verboseUnlinking) {
  2193. dataLog(
  2194. "Clearing closure call from ", *this, " to ",
  2195. stub->executable()->hashFor(callLinkInfo(i).specializationKind()),
  2196. ", stub routine ", RawPointer(stub), ".\n");
  2197. }
  2198. callLinkInfo(i).unlink(*m_vm, repatchBuffer);
  2199. }
  2200. } else if (!Heap::isMarked(callLinkInfo(i).callee.get())) {
  2201. if (verboseUnlinking) {
  2202. dataLog(
  2203. "Clearing call from ", *this, " to ",
  2204. RawPointer(callLinkInfo(i).callee.get()), " (",
  2205. callLinkInfo(i).callee.get()->executable()->hashFor(
  2206. callLinkInfo(i).specializationKind()),
  2207. ").\n");
  2208. }
  2209. callLinkInfo(i).unlink(*m_vm, repatchBuffer);
  2210. }
  2211. }
  2212. if (!!callLinkInfo(i).lastSeenCallee
  2213. && !Heap::isMarked(callLinkInfo(i).lastSeenCallee.get()))
  2214. callLinkInfo(i).lastSeenCallee.clear();
  2215. }
  2216. for (size_t size = m_structureStubInfos.size(), i = 0; i < size; ++i) {
  2217. StructureStubInfo& stubInfo = m_structureStubInfos[i];
  2218. if (stubInfo.visitWeakReferences())
  2219. continue;
  2220. resetStubDuringGCInternal(repatchBuffer, stubInfo);
  2221. }
  2222. }
  2223. #endif
  2224. }
  2225. #endif // !(ENABLE(DETACHED_JIT) && BUILDING_DETACHED_JIT)
  2226. #if ENABLE(JIT)
  2227. void CodeBlock::resetStub(StructureStubInfo& stubInfo)
  2228. {
  2229. if (stubInfo.accessType == access_unset)
  2230. return;
  2231. RepatchBuffer repatchBuffer(this);
  2232. resetStubInternal(repatchBuffer, stubInfo);
  2233. }
  2234. void CodeBlock::resetStubInternal(RepatchBuffer& repatchBuffer, StructureStubInfo& stubInfo)
  2235. {
  2236. AccessType accessType = static_cast<AccessType>(stubInfo.accessType);
  2237. if (verboseUnlinking)
  2238. dataLog("Clearing structure cache (kind ", static_cast<int>(stubInfo.accessType), ") in ", *this, ".\n");
  2239. if (isGetByIdAccess(accessType)) {
  2240. if (getJITCode().jitType() == JITCode::DFGJIT)
  2241. DFG::dfgResetGetByID(repatchBuffer, stubInfo);
  2242. else
  2243. JIT::resetPatchGetById(repatchBuffer, &stubInfo);
  2244. } else {
  2245. ASSERT(isPutByIdAccess(accessType));
  2246. if (getJITCode().jitType() == JITCode::DFGJIT)
  2247. DFG::dfgResetPutByID(repatchBuffer, stubInfo);
  2248. else
  2249. JIT::resetPatchPutById(repatchBuffer, &stubInfo);
  2250. }
  2251. stubInfo.reset();
  2252. }
  2253. #endif // ENABLE(JIT)
  2254. #if !(ENABLE(DETACHED_JIT) && BUILDING_DETACHED_JIT)
  2255. #if ENABLE(JIT)
  2256. void CodeBlock::resetStubDuringGCInternal(RepatchBuffer& repatchBuffer, StructureStubInfo& stubInfo)
  2257. {
  2258. resetStubInternal(repatchBuffer, stubInfo);
  2259. stubInfo.resetByGC = true;
  2260. }
  2261. #endif
  2262. void CodeBlock::stronglyVisitStrongReferences(SlotVisitor& visitor)
  2263. {
  2264. visitor.append(&m_globalObject);
  2265. visitor.append(&m_ownerExecutable);
  2266. visitor.append(&m_unlinkedCode);
  2267. if (m_rareData)
  2268. m_rareData->m_evalCodeCache.visitAggregate(visitor);
  2269. visitor.appendValues(m_constantRegisters.data(), m_constantRegisters.size());
  2270. for (size_t i = 0; i < m_functionExprs.size(); ++i)
  2271. visitor.append(&m_functionExprs[i]);
  2272. for (size_t i = 0; i < m_functionDecls.size(); ++i)
  2273. visitor.append(&m_functionDecls[i]);
  2274. for (unsigned i = 0; i < m_objectAllocationProfiles.size(); ++i)
  2275. m_objectAllocationProfiles[i].visitAggregate(visitor);
  2276. updateAllPredictions(Collection);
  2277. }
  2278. void CodeBlock::stronglyVisitWeakReferences(SlotVisitor& visitor)
  2279. {
  2280. UNUSED_PARAM(visitor);
  2281. #if ENABLE(DFG_JIT)
  2282. if (!m_dfgData)
  2283. return;
  2284. for (unsigned i = 0; i < m_dfgData->transitions.size(); ++i) {
  2285. if (!!m_dfgData->transitions[i].m_codeOrigin)
  2286. visitor.append(&m_dfgData->transitions[i].m_codeOrigin); // Almost certainly not necessary, since the code origin should also be a weak reference. Better to be safe, though.
  2287. visitor.append(&m_dfgData->transitions[i].m_from);
  2288. visitor.append(&m_dfgData->transitions[i].m_to);
  2289. }
  2290. for (unsigned i = 0; i < m_dfgData->weakReferences.size(); ++i)
  2291. visitor.append(&m_dfgData->weakReferences[i]);
  2292. #endif
  2293. }
  2294. HandlerInfo* CodeBlock::handlerForBytecodeOffset(unsigned bytecodeOffset)
  2295. {
  2296. RELEASE_ASSERT(bytecodeOffset < instructions().size());
  2297. if (!m_rareData)
  2298. return 0;
  2299. Vector_shared<HandlerInfo>& exceptionHandlers = m_rareData->m_exceptionHandlers;
  2300. for (size_t i = 0; i < exceptionHandlers.size(); ++i) {
  2301. // Handlers are ordered innermost first, so the first handler we encounter
  2302. // that contains the source address is the correct handler to use.
  2303. if (exceptionHandlers[i].start <= bytecodeOffset && exceptionHandlers[i].end > bytecodeOffset)
  2304. return &exceptionHandlers[i];
  2305. }
  2306. return 0;
  2307. }
  2308. unsigned CodeBlock::lineNumberForBytecodeOffset(unsigned bytecodeOffset)
  2309. {
  2310. RELEASE_ASSERT(bytecodeOffset < instructions().size());
  2311. return m_ownerExecutable->lineNo() + m_unlinkedCode->lineNumberForBytecodeOffset(bytecodeOffset);
  2312. }
  2313. unsigned CodeBlock::columnNumberForBytecodeOffset(unsigned bytecodeOffset)
  2314. {
  2315. int divot;
  2316. int startOffset;
  2317. int endOffset;
  2318. unsigned line;
  2319. unsigned column;
  2320. expressionRangeForBytecodeOffset(bytecodeOffset, divot, startOffset, endOffset, line, column);
  2321. return column;
  2322. }
  2323. void CodeBlock::expressionRangeForBytecodeOffset(unsigned bytecodeOffset, int& divot, int& startOffset, int& endOffset, unsigned& line, unsigned& column)
  2324. {
  2325. m_unlinkedCode->expressionRangeForBytecodeOffset(bytecodeOffset, divot, startOffset, endOffset, line, column);
  2326. divot += m_sourceOffset;
  2327. column += line ? 1 : firstLineColumnOffset();
  2328. line += m_ownerExecutable->lineNo();
  2329. }
  2330. #endif // #if !(ENABLE(DETACHED_JIT) && BUILDING_DETACHED_JIT)
  2331. void CodeBlock::shrinkToFit(ShrinkMode shrinkMode)
  2332. {
  2333. #if ENABLE(LLINT)
  2334. m_llintCallLinkInfos.shrinkToFit();
  2335. #endif
  2336. #if ENABLE(JIT)
  2337. m_structureStubInfos.shrinkToFit();
  2338. m_callLinkInfos.shrinkToFit();
  2339. #endif
  2340. #if ENABLE(VALUE_PROFILER)
  2341. m_rareCaseProfiles.shrinkToFit();
  2342. m_specialFastCaseProfiles.shrinkToFit();
  2343. #endif
  2344. if (shrinkMode == EarlyShrink) {
  2345. m_identifiers.shrinkToFit();
  2346. m_functionDecls.shrinkToFit();
  2347. m_functionExprs.shrinkToFit();
  2348. m_constantRegisters.shrinkToFit();
  2349. } // else don't shrink these, because we would have already pointed pointers into these tables.
  2350. if (m_rareData) {
  2351. m_rareData->m_exceptionHandlers.shrinkToFit();
  2352. m_rareData->m_immediateSwitchJumpTables.shrinkToFit();
  2353. m_rareData->m_characterSwitchJumpTables.shrinkToFit();
  2354. m_rareData->m_stringSwitchJumpTables.shrinkToFit();
  2355. #if ENABLE(JIT)
  2356. m_rareData->m_callReturnIndexVector.shrinkToFit();
  2357. #endif
  2358. #if ENABLE(DFG_JIT)
  2359. m_rareData->m_inlineCallFrames.shrinkToFit();
  2360. m_rareData->m_codeOrigins.shrinkToFit();
  2361. #endif
  2362. }
  2363. #if ENABLE(DFG_JIT)
  2364. if (m_dfgData) {
  2365. m_dfgData->osrEntry.shrinkToFit();
  2366. m_dfgData->osrExit.shrinkToFit();
  2367. m_dfgData->speculationRecovery.shrinkToFit();
  2368. m_dfgData->weakReferences.shrinkToFit();
  2369. m_dfgData->transitions.shrinkToFit();
  2370. m_dfgData->minifiedDFG.prepareAndShrink();
  2371. m_dfgData->variableEventStream.shrinkToFit();
  2372. }
  2373. #endif
  2374. }
  2375. #if !(ENABLE(DETACHED_JIT) && BUILDING_DETACHED_JIT)
  2376. void CodeBlock::createActivation(CallFrame* callFrame)
  2377. {
  2378. ASSERT(codeType() == FunctionCode);
  2379. ASSERT(needsFullScopeChain());
  2380. ASSERT(!callFrame->uncheckedR(activationRegister()).jsValue());
  2381. JSActivation* activation = JSActivation::create(callFrame->vm(), callFrame, this);
  2382. callFrame->uncheckedR(activationRegister()) = JSValue(activation);
  2383. callFrame->setScope(activation);
  2384. }
  2385. unsigned CodeBlock::addOrFindConstant(JSValue v)
  2386. {
  2387. unsigned numberOfConstants = numberOfConstantRegisters();
  2388. for (unsigned i = 0; i < numberOfConstants; ++i) {
  2389. if (getConstant(FirstConstantRegisterIndex + i) == v)
  2390. return i;
  2391. }
  2392. return addConstant(v);
  2393. }
  2394. #if ENABLE(JIT)
  2395. void CodeBlock::unlinkCalls()
  2396. {
  2397. if (!!m_alternative)
  2398. m_alternative->unlinkCalls();
  2399. #if ENABLE(LLINT)
  2400. for (size_t i = 0; i < m_llintCallLinkInfos.size(); ++i) {
  2401. if (m_llintCallLinkInfos[i].isLinked())
  2402. m_llintCallLinkInfos[i].unlink();
  2403. }
  2404. #endif
  2405. if (!m_callLinkInfos.size())
  2406. return;
  2407. if (!m_vm->canUseJIT())
  2408. return;
  2409. RepatchBuffer repatchBuffer(this);
  2410. for (size_t i = 0; i < m_callLinkInfos.size(); i++) {
  2411. if (!m_callLinkInfos[i].isLinked())
  2412. continue;
  2413. m_callLinkInfos[i].unlink(*m_vm, repatchBuffer);
  2414. }
  2415. }
  2416. void CodeBlock::unlinkIncomingCalls()
  2417. {
  2418. #if ENABLE(LLINT)
  2419. while (m_incomingLLIntCalls.begin() != m_incomingLLIntCalls.end())
  2420. m_incomingLLIntCalls.begin()->unlink();
  2421. #endif
  2422. if (m_incomingCalls.isEmpty())
  2423. return;
  2424. RepatchBuffer repatchBuffer(this);
  2425. while (m_incomingCalls.begin() != m_incomingCalls.end())
  2426. m_incomingCalls.begin()->unlink(*m_vm, repatchBuffer);
  2427. }
  2428. #endif // ENABLE(JIT)
  2429. #if ENABLE(LLINT)
  2430. Instruction* CodeBlock::adjustPCIfAtCallSite(Instruction* potentialReturnPC)
  2431. {
  2432. ASSERT(potentialReturnPC);
  2433. unsigned returnPCOffset = potentialReturnPC - instructions().begin();
  2434. Instruction* adjustedPC;
  2435. unsigned opcodeLength;
  2436. // If we are at a callsite, the LLInt stores the PC after the call
  2437. // instruction rather than the PC of the call instruction. This requires
  2438. // some correcting. If so, we can rely on the fact that the preceding
  2439. // instruction must be one of the call instructions, so either it's a
  2440. // call_varargs or it's a call, construct, or eval.
  2441. //
  2442. // If we are not at a call site, then we need to guard against the
  2443. // possibility of peeking past the start of the bytecode range for this
  2444. // codeBlock. Hence, we do a bounds check before we peek at the
  2445. // potential "preceding" instruction.
  2446. // The bounds check is done by comparing the offset of the potential
  2447. // returnPC with the length of the opcode. If there is room for a call
  2448. // instruction before the returnPC, then the offset of the returnPC must
  2449. // be greater than the size of the call opcode we're looking for.
  2450. // The determination of the call instruction present (if we are at a
  2451. // callsite) depends on the following assumptions. So, assert that
  2452. // they are still true:
  2453. ASSERT(OPCODE_LENGTH(op_call_varargs) <= OPCODE_LENGTH(op_call));
  2454. ASSERT(OPCODE_LENGTH(op_call) == OPCODE_LENGTH(op_construct));
  2455. ASSERT(OPCODE_LENGTH(op_call) == OPCODE_LENGTH(op_call_eval));
  2456. // Check for the case of a preceeding op_call_varargs:
  2457. opcodeLength = OPCODE_LENGTH(op_call_varargs);
  2458. adjustedPC = potentialReturnPC - opcodeLength;
  2459. if ((returnPCOffset >= opcodeLength)
  2460. && (adjustedPC->u.pointer == LLInt::getCodePtr(llint_op_call_varargs))) {
  2461. return adjustedPC;
  2462. }
  2463. // Check for the case of the other 3 call instructions:
  2464. opcodeLength = OPCODE_LENGTH(op_call);
  2465. adjustedPC = potentialReturnPC - opcodeLength;
  2466. if ((returnPCOffset >= opcodeLength)
  2467. && (adjustedPC->u.pointer == LLInt::getCodePtr(llint_op_call)
  2468. || adjustedPC->u.pointer == LLInt::getCodePtr(llint_op_construct)
  2469. || adjustedPC->u.pointer == LLInt::getCodePtr(llint_op_call_eval))) {
  2470. return adjustedPC;
  2471. }
  2472. // Not a call site. No need to adjust PC. Just return the original.
  2473. return potentialReturnPC;
  2474. }
  2475. #endif // ENABLE(LLINT)
  2476. #if ENABLE(JIT)
  2477. ClosureCallStubRoutine* CodeBlock::findClosureCallForReturnPC(ReturnAddressPtr returnAddress)
  2478. {
  2479. for (unsigned i = m_callLinkInfos.size(); i--;) {
  2480. CallLinkInfo& info = m_callLinkInfos[i];
  2481. if (!info.stub)
  2482. continue;
  2483. if (!info.stub->code().executableMemory()->contains(returnAddress.value()))
  2484. continue;
  2485. RELEASE_ASSERT(info.stub->codeOrigin().bytecodeIndex < CodeOrigin::maximumBytecodeIndex);
  2486. return info.stub.get();
  2487. }
  2488. // The stub routine may have been jettisoned. This is rare, but we have to handle it.
  2489. const JITStubRoutineSet& set = m_vm->heap.jitStubRoutines();
  2490. for (unsigned i = set.size(); i--;) {
  2491. GCAwareJITStubRoutine* genericStub = set.at(i);
  2492. if (!genericStub->isClosureCall())
  2493. continue;
  2494. ClosureCallStubRoutine* stub = static_cast<ClosureCallStubRoutine*>(genericStub);
  2495. if (!stub->code().executableMemory()->contains(returnAddress.value()))
  2496. continue;
  2497. RELEASE_ASSERT(stub->codeOrigin().bytecodeIndex < CodeOrigin::maximumBytecodeIndex);
  2498. return stub;
  2499. }
  2500. return 0;
  2501. }
  2502. #endif
  2503. unsigned CodeBlock::bytecodeOffset(ExecState* exec, ReturnAddressPtr returnAddress)
  2504. {
  2505. UNUSED_PARAM(exec);
  2506. UNUSED_PARAM(returnAddress);
  2507. #if ENABLE(LLINT)
  2508. #if !ENABLE(LLINT_C_LOOP)
  2509. // When using the JIT, we could have addresses that are not bytecode
  2510. // addresses. We check if the return address is in the LLint glue and
  2511. // opcode handlers range here to ensure that we are looking at bytecode
  2512. // before attempting to convert the return address into a bytecode offset.
  2513. //
  2514. // In the case of the C Loop LLInt, the JIT is disabled, and the only
  2515. // valid return addresses should be bytecode PCs. So, we can and need to
  2516. // forego this check because when we do not ENABLE(COMPUTED_GOTO_OPCODES),
  2517. // then the bytecode "PC"s are actually the opcodeIDs and are not bounded
  2518. // by llint_begin and llint_end.
  2519. if (returnAddress.value() >= LLInt::getCodePtr(llint_begin)
  2520. && returnAddress.value() <= LLInt::getCodePtr(llint_end))
  2521. #endif
  2522. {
  2523. RELEASE_ASSERT(exec->codeBlock());
  2524. RELEASE_ASSERT(exec->codeBlock() == this);
  2525. RELEASE_ASSERT(JITCode::isBaselineCode(getJITType()));
  2526. Instruction* instruction = exec->currentVPC();
  2527. RELEASE_ASSERT(instruction);
  2528. instruction = adjustPCIfAtCallSite(instruction);
  2529. return bytecodeOffset(instruction);
  2530. }
  2531. #endif // !ENABLE(LLINT)
  2532. #if ENABLE(JIT)
  2533. if (!m_rareData)
  2534. return 1;
  2535. Vector_shared<CallReturnOffsetToBytecodeOffset, 0, UnsafeVectorOverflow>& callIndices = m_rareData->m_callReturnIndexVector;
  2536. if (!callIndices.size())
  2537. return 1;
  2538. if (getJITCode().getExecutableMemory()->contains(returnAddress.value())) {
  2539. unsigned callReturnOffset = getJITCode().offsetOf(returnAddress.value());
  2540. CallReturnOffsetToBytecodeOffset* result =
  2541. binarySearch<CallReturnOffsetToBytecodeOffset, unsigned>(
  2542. callIndices, callIndices.size(), callReturnOffset, getCallReturnOffset);
  2543. RELEASE_ASSERT(result->callReturnOffset == callReturnOffset);
  2544. RELEASE_ASSERT(result->bytecodeOffset < instructionCount());
  2545. return result->bytecodeOffset;
  2546. }
  2547. ClosureCallStubRoutine* closureInfo = findClosureCallForReturnPC(returnAddress);
  2548. CodeOrigin origin = closureInfo->codeOrigin();
  2549. while (InlineCallFrame* inlineCallFrame = origin.inlineCallFrame) {
  2550. if (inlineCallFrame->baselineCodeBlock() == this)
  2551. break;
  2552. origin = inlineCallFrame->caller;
  2553. RELEASE_ASSERT(origin.bytecodeIndex < CodeOrigin::maximumBytecodeIndex);
  2554. }
  2555. RELEASE_ASSERT(origin.bytecodeIndex < CodeOrigin::maximumBytecodeIndex);
  2556. unsigned bytecodeIndex = origin.bytecodeIndex;
  2557. RELEASE_ASSERT(bytecodeIndex < instructionCount());
  2558. return bytecodeIndex;
  2559. #endif // ENABLE(JIT)
  2560. #if !ENABLE(LLINT) && !ENABLE(JIT)
  2561. return 1;
  2562. #endif
  2563. }
  2564. #if ENABLE(DFG_JIT)
  2565. bool CodeBlock::codeOriginForReturn(ReturnAddressPtr returnAddress, CodeOrigin& codeOrigin)
  2566. {
  2567. if (!hasCodeOrigins())
  2568. return false;
  2569. if (!getJITCode().getExecutableMemory()->contains(returnAddress.value())) {
  2570. ClosureCallStubRoutine* stub = findClosureCallForReturnPC(returnAddress);
  2571. ASSERT(stub);
  2572. if (!stub)
  2573. return false;
  2574. codeOrigin = stub->codeOrigin();
  2575. return true;
  2576. }
  2577. unsigned offset = getJITCode().offsetOf(returnAddress.value());
  2578. CodeOriginAtCallReturnOffset* entry =
  2579. tryBinarySearch<CodeOriginAtCallReturnOffset, unsigned>(
  2580. codeOrigins(), codeOrigins().size(), offset,
  2581. getCallReturnOffsetForCodeOrigin);
  2582. if (!entry)
  2583. return false;
  2584. codeOrigin = entry->codeOrigin;
  2585. return true;
  2586. }
  2587. #endif // ENABLE(DFG_JIT)
  2588. void CodeBlock::clearEvalCache()
  2589. {
  2590. if (!!m_alternative)
  2591. m_alternative->clearEvalCache();
  2592. if (!m_rareData)
  2593. return;
  2594. m_rareData->m_evalCodeCache.clear();
  2595. }
  2596. template<typename T, size_t inlineCapacity, typename U, typename V, bool shared>
  2597. inline void replaceExistingEntries(Vector<T, inlineCapacity, U, shared>& target, Vector<T, inlineCapacity, V, shared>& source)
  2598. {
  2599. ASSERT(target.size() <= source.size());
  2600. for (size_t i = 0; i < target.size(); ++i)
  2601. target[i] = source[i];
  2602. }
  2603. void CodeBlock::copyPostParseDataFrom(CodeBlock* alternative)
  2604. {
  2605. if (!alternative)
  2606. return;
  2607. replaceExistingEntries(m_constantRegisters, alternative->m_constantRegisters);
  2608. replaceExistingEntries(m_functionDecls, alternative->m_functionDecls);
  2609. replaceExistingEntries(m_functionExprs, alternative->m_functionExprs);
  2610. if (!!m_rareData && !!alternative->m_rareData)
  2611. replaceExistingEntries(m_rareData->m_constantBuffers, alternative->m_rareData->m_constantBuffers);
  2612. }
  2613. void CodeBlock::copyPostParseDataFromAlternative()
  2614. {
  2615. copyPostParseDataFrom(m_alternative.get());
  2616. }
  2617. #if ENABLE(JIT)
  2618. void CodeBlock::reoptimize()
  2619. {
  2620. ASSERT(replacement() != this);
  2621. ASSERT(replacement()->alternative() == this);
  2622. if (DFG::shouldShowDisassembly())
  2623. dataLog(*replacement(), " will be jettisoned due to reoptimization of ", *this, ".\n");
  2624. replacement()->jettison();
  2625. countReoptimization();
  2626. }
  2627. #endif // ENABLE(JIT)
  2628. #endif // #if !(ENABLE(DETACHED_JIT) && BUILDING_DETACHED_JIT)
  2629. #if ENABLE(JIT)
  2630. CodeBlock* ProgramCodeBlock::replacement()
  2631. {
  2632. return &static_cast<ProgramExecutable*>(ownerExecutable())->generatedBytecode();
  2633. }
  2634. CodeBlock* EvalCodeBlock::replacement()
  2635. {
  2636. return &static_cast<EvalExecutable*>(ownerExecutable())->generatedBytecode();
  2637. }
  2638. CodeBlock* FunctionCodeBlock::replacement()
  2639. {
  2640. return &static_cast<FunctionExecutable*>(ownerExecutable())->generatedBytecodeFor(m_isConstructor ? CodeForConstruct : CodeForCall);
  2641. }
  2642. #endif
  2643. #if !(ENABLE(DETACHED_JIT) && BUILDING_DETACHED_JIT)
  2644. #if ENABLE(JIT)
  2645. JSObject* ProgramCodeBlock::compileOptimized(ExecState* exec, JSScope* scope, unsigned bytecodeIndex)
  2646. {
  2647. if (replacement()->getJITType() == JITCode::nextTierJIT(getJITType()))
  2648. return 0;
  2649. JSObject* error = static_cast<ProgramExecutable*>(ownerExecutable())->compileOptimized(exec, scope, bytecodeIndex);
  2650. return error;
  2651. }
  2652. JSObject* EvalCodeBlock::compileOptimized(ExecState* exec, JSScope* scope, unsigned bytecodeIndex)
  2653. {
  2654. if (replacement()->getJITType() == JITCode::nextTierJIT(getJITType()))
  2655. return 0;
  2656. JSObject* error = static_cast<EvalExecutable*>(ownerExecutable())->compileOptimized(exec, scope, bytecodeIndex);
  2657. return error;
  2658. }
  2659. JSObject* FunctionCodeBlock::compileOptimized(ExecState* exec, JSScope* scope, unsigned bytecodeIndex)
  2660. {
  2661. if (replacement()->getJITType() == JITCode::nextTierJIT(getJITType()))
  2662. return 0;
  2663. JSObject* error = static_cast<FunctionExecutable*>(ownerExecutable())->compileOptimizedFor(exec, scope, bytecodeIndex, m_isConstructor ? CodeForConstruct : CodeForCall);
  2664. return error;
  2665. }
  2666. DFG::CapabilityLevel ProgramCodeBlock::canCompileWithDFGInternal()
  2667. {
  2668. return DFG::canCompileProgram(this);
  2669. }
  2670. DFG::CapabilityLevel EvalCodeBlock::canCompileWithDFGInternal()
  2671. {
  2672. return DFG::canCompileEval(this);
  2673. }
  2674. DFG::CapabilityLevel FunctionCodeBlock::canCompileWithDFGInternal()
  2675. {
  2676. if (m_isConstructor)
  2677. return DFG::canCompileFunctionForConstruct(this);
  2678. return DFG::canCompileFunctionForCall(this);
  2679. }
  2680. void CodeBlock::jettison()
  2681. {
  2682. ASSERT(JITCode::isOptimizingJIT(getJITType()));
  2683. ASSERT(this == replacement());
  2684. alternative()->optimizeAfterWarmUp();
  2685. tallyFrequentExitSites();
  2686. if (DFG::shouldShowDisassembly())
  2687. dataLog("Jettisoning ", *this, ".\n");
  2688. jettisonImpl();
  2689. }
  2690. void ProgramCodeBlock::jettisonImpl()
  2691. {
  2692. static_cast<ProgramExecutable*>(ownerExecutable())->jettisonOptimizedCode(*vm());
  2693. }
  2694. void EvalCodeBlock::jettisonImpl()
  2695. {
  2696. static_cast<EvalExecutable*>(ownerExecutable())->jettisonOptimizedCode(*vm());
  2697. }
  2698. void FunctionCodeBlock::jettisonImpl()
  2699. {
  2700. static_cast<FunctionExecutable*>(ownerExecutable())->jettisonOptimizedCodeFor(*vm(), m_isConstructor ? CodeForConstruct : CodeForCall);
  2701. }
  2702. bool ProgramCodeBlock::jitCompileImpl(ExecState* exec)
  2703. {
  2704. ASSERT(getJITType() == JITCode::InterpreterThunk);
  2705. ASSERT(this == replacement());
  2706. return static_cast<ProgramExecutable*>(ownerExecutable())->jitCompile(exec);
  2707. }
  2708. bool EvalCodeBlock::jitCompileImpl(ExecState* exec)
  2709. {
  2710. ASSERT(getJITType() == JITCode::InterpreterThunk);
  2711. ASSERT(this == replacement());
  2712. return static_cast<EvalExecutable*>(ownerExecutable())->jitCompile(exec);
  2713. }
  2714. bool FunctionCodeBlock::jitCompileImpl(ExecState* exec)
  2715. {
  2716. ASSERT(getJITType() == JITCode::InterpreterThunk);
  2717. ASSERT(this == replacement());
  2718. return static_cast<FunctionExecutable*>(ownerExecutable())->jitCompileFor(exec, m_isConstructor ? CodeForConstruct : CodeForCall);
  2719. }
  2720. #endif
  2721. #endif // #if !(ENABLE(DETACHED_JIT) && BUILDING_DETACHED_JIT)
  2722. JSGlobalObject* CodeBlock::globalObjectFor(CodeOrigin codeOrigin)
  2723. {
  2724. if (!codeOrigin.inlineCallFrame)
  2725. return globalObject();
  2726. return jsCast<FunctionExecutable*>(codeOrigin.inlineCallFrame->executable.get())->generatedBytecode().globalObject();
  2727. }
  2728. unsigned CodeBlock::reoptimizationRetryCounter() const
  2729. {
  2730. ASSERT(m_reoptimizationRetryCounter <= Options::reoptimizationRetryCounterMax());
  2731. return m_reoptimizationRetryCounter;
  2732. }
  2733. void CodeBlock::countReoptimization()
  2734. {
  2735. m_reoptimizationRetryCounter++;
  2736. if (m_reoptimizationRetryCounter > Options::reoptimizationRetryCounterMax())
  2737. m_reoptimizationRetryCounter = Options::reoptimizationRetryCounterMax();
  2738. }
  2739. int32_t CodeBlock::codeTypeThresholdMultiplier() const
  2740. {
  2741. if (codeType() == EvalCode)
  2742. return Options::evalThresholdMultiplier();
  2743. return 1;
  2744. }
  2745. double CodeBlock::optimizationThresholdScalingFactor()
  2746. {
  2747. // This expression arises from doing a least-squares fit of
  2748. //
  2749. // F[x_] =: a * Sqrt[x + b] + Abs[c * x] + d
  2750. //
  2751. // against the data points:
  2752. //
  2753. // x F[x_]
  2754. // 10 0.9 (smallest reasonable code block)
  2755. // 200 1.0 (typical small-ish code block)
  2756. // 320 1.2 (something I saw in 3d-cube that I wanted to optimize)
  2757. // 1268 5.0 (something I saw in 3d-cube that I didn't want to optimize)
  2758. // 4000 5.5 (random large size, used to cause the function to converge to a shallow curve of some sort)
  2759. // 10000 6.0 (similar to above)
  2760. //
  2761. // I achieve the minimization using the following Mathematica code:
  2762. //
  2763. // MyFunctionTemplate[x_, a_, b_, c_, d_] := a*Sqrt[x + b] + Abs[c*x] + d
  2764. //
  2765. // samples = {{10, 0.9}, {200, 1}, {320, 1.2}, {1268, 5}, {4000, 5.5}, {10000, 6}}
  2766. //
  2767. // solution =
  2768. // Minimize[Plus @@ ((MyFunctionTemplate[#[[1]], a, b, c, d] - #[[2]])^2 & /@ samples),
  2769. // {a, b, c, d}][[2]]
  2770. //
  2771. // And the code below (to initialize a, b, c, d) is generated by:
  2772. //
  2773. // Print["const double " <> ToString[#[[1]]] <> " = " <>
  2774. // If[#[[2]] < 0.00001, "0.0", ToString[#[[2]]]] <> ";"] & /@ solution
  2775. //
  2776. // We've long known the following to be true:
  2777. // - Small code blocks are cheap to optimize and so we should do it sooner rather
  2778. // than later.
  2779. // - Large code blocks are expensive to optimize and so we should postpone doing so,
  2780. // and sometimes have a large enough threshold that we never optimize them.
  2781. // - The difference in cost is not totally linear because (a) just invoking the
  2782. // DFG incurs some base cost and (b) for large code blocks there is enough slop
  2783. // in the correlation between instruction count and the actual compilation cost
  2784. // that for those large blocks, the instruction count should not have a strong
  2785. // influence on our threshold.
  2786. //
  2787. // I knew the goals but I didn't know how to achieve them; so I picked an interesting
  2788. // example where the heuristics were right (code block in 3d-cube with instruction
  2789. // count 320, which got compiled early as it should have been) and one where they were
  2790. // totally wrong (code block in 3d-cube with instruction count 1268, which was expensive
  2791. // to compile and didn't run often enough to warrant compilation in my opinion), and
  2792. // then threw in additional data points that represented my own guess of what our
  2793. // heuristics should do for some round-numbered examples.
  2794. //
  2795. // The expression to which I decided to fit the data arose because I started with an
  2796. // affine function, and then did two things: put the linear part in an Abs to ensure
  2797. // that the fit didn't end up choosing a negative value of c (which would result in
  2798. // the function turning over and going negative for large x) and I threw in a Sqrt
  2799. // term because Sqrt represents my intution that the function should be more sensitive
  2800. // to small changes in small values of x, but less sensitive when x gets large.
  2801. // Note that the current fit essentially eliminates the linear portion of the
  2802. // expression (c == 0.0).
  2803. const double a = 0.061504;
  2804. const double b = 1.02406;
  2805. const double c = 0.0;
  2806. const double d = 0.825914;
  2807. double instructionCount = this->instructionCount();
  2808. ASSERT(instructionCount); // Make sure this is called only after we have an instruction stream; otherwise it'll just return the value of d, which makes no sense.
  2809. double result = d + a * sqrt(instructionCount + b) + c * instructionCount;
  2810. #if ENABLE(JIT_VERBOSE_OSR)
  2811. dataLog(*this, ": instruction count is ", instructionCount, ", scaling execution counter by ", result, " * ", codeTypeThresholdMultiplier(), "\n");
  2812. #endif
  2813. return result * codeTypeThresholdMultiplier();
  2814. }
  2815. static int32_t clipThreshold(double threshold)
  2816. {
  2817. if (threshold < 1.0)
  2818. return 1;
  2819. if (threshold > static_cast<double>(std::numeric_limits<int32_t>::max()))
  2820. return std::numeric_limits<int32_t>::max();
  2821. return static_cast<int32_t>(threshold);
  2822. }
  2823. int32_t CodeBlock::counterValueForOptimizeAfterWarmUp()
  2824. {
  2825. return clipThreshold(
  2826. Options::thresholdForOptimizeAfterWarmUp() *
  2827. optimizationThresholdScalingFactor() *
  2828. (1 << reoptimizationRetryCounter()));
  2829. }
  2830. int32_t CodeBlock::counterValueForOptimizeAfterLongWarmUp()
  2831. {
  2832. return clipThreshold(
  2833. Options::thresholdForOptimizeAfterLongWarmUp() *
  2834. optimizationThresholdScalingFactor() *
  2835. (1 << reoptimizationRetryCounter()));
  2836. }
  2837. #if !(ENABLE(DETACHED_JIT) && BUILDING_DETACHED_JIT)
  2838. int32_t CodeBlock::counterValueForOptimizeSoon()
  2839. {
  2840. return clipThreshold(
  2841. Options::thresholdForOptimizeSoon() *
  2842. optimizationThresholdScalingFactor() *
  2843. (1 << reoptimizationRetryCounter()));
  2844. }
  2845. bool CodeBlock::checkIfOptimizationThresholdReached()
  2846. {
  2847. return m_jitExecuteCounter.checkIfThresholdCrossedAndSet(this);
  2848. }
  2849. void CodeBlock::optimizeNextInvocation()
  2850. {
  2851. m_jitExecuteCounter.setNewThreshold(0, this);
  2852. }
  2853. void CodeBlock::dontOptimizeAnytimeSoon()
  2854. {
  2855. m_jitExecuteCounter.deferIndefinitely();
  2856. }
  2857. void CodeBlock::optimizeAfterWarmUp()
  2858. {
  2859. m_jitExecuteCounter.setNewThreshold(counterValueForOptimizeAfterWarmUp(), this);
  2860. }
  2861. void CodeBlock::optimizeAfterLongWarmUp()
  2862. {
  2863. m_jitExecuteCounter.setNewThreshold(counterValueForOptimizeAfterLongWarmUp(), this);
  2864. }
  2865. void CodeBlock::optimizeSoon()
  2866. {
  2867. m_jitExecuteCounter.setNewThreshold(counterValueForOptimizeSoon(), this);
  2868. }
  2869. #endif // #if !(ENABLE(DETACHED_JIT) && BUILDING_DETACHED_JIT)
  2870. #if ENABLE(JIT)
  2871. uint32_t CodeBlock::adjustedExitCountThreshold(uint32_t desiredThreshold)
  2872. {
  2873. ASSERT(getJITType() == JITCode::DFGJIT);
  2874. // Compute this the lame way so we don't saturate. This is called infrequently
  2875. // enough that this loop won't hurt us.
  2876. unsigned result = desiredThreshold;
  2877. for (unsigned n = baselineVersion()->reoptimizationRetryCounter(); n--;) {
  2878. unsigned newResult = result << 1;
  2879. if (newResult < result)
  2880. return std::numeric_limits<uint32_t>::max();
  2881. result = newResult;
  2882. }
  2883. return result;
  2884. }
  2885. uint32_t CodeBlock::exitCountThresholdForReoptimization()
  2886. {
  2887. return adjustedExitCountThreshold(Options::osrExitCountForReoptimization() * codeTypeThresholdMultiplier());
  2888. }
  2889. uint32_t CodeBlock::exitCountThresholdForReoptimizationFromLoop()
  2890. {
  2891. return adjustedExitCountThreshold(Options::osrExitCountForReoptimizationFromLoop() * codeTypeThresholdMultiplier());
  2892. }
  2893. bool CodeBlock::shouldReoptimizeNow()
  2894. {
  2895. return osrExitCounter() >= exitCountThresholdForReoptimization();
  2896. }
  2897. bool CodeBlock::shouldReoptimizeFromLoopNow()
  2898. {
  2899. return osrExitCounter() >= exitCountThresholdForReoptimizationFromLoop();
  2900. }
  2901. #endif
  2902. #if ENABLE(VALUE_PROFILER)
  2903. ArrayProfile* CodeBlock::getArrayProfile(unsigned bytecodeOffset)
  2904. {
  2905. for (unsigned i = 0; i < m_arrayProfiles.size(); ++i) {
  2906. if (m_arrayProfiles[i].bytecodeOffset() == bytecodeOffset)
  2907. return &m_arrayProfiles[i];
  2908. }
  2909. return 0;
  2910. }
  2911. ArrayProfile* CodeBlock::getOrAddArrayProfile(unsigned bytecodeOffset)
  2912. {
  2913. ArrayProfile* result = getArrayProfile(bytecodeOffset);
  2914. if (result)
  2915. return result;
  2916. return addArrayProfile(bytecodeOffset);
  2917. }
  2918. #endif
  2919. #if !(ENABLE(DETACHED_JIT) && BUILDING_DETACHED_JIT)
  2920. #if ENABLE(VALUE_PROFILER)
  2921. void CodeBlock::updateAllPredictionsAndCountLiveness(
  2922. OperationInProgress operation, unsigned& numberOfLiveNonArgumentValueProfiles, unsigned& numberOfSamplesInProfiles)
  2923. {
  2924. numberOfLiveNonArgumentValueProfiles = 0;
  2925. numberOfSamplesInProfiles = 0; // If this divided by ValueProfile::numberOfBuckets equals numberOfValueProfiles() then value profiles are full.
  2926. for (unsigned i = 0; i < totalNumberOfValueProfiles(); ++i) {
  2927. ValueProfile* profile = getFromAllValueProfiles(i);
  2928. unsigned numSamples = profile->totalNumberOfSamples();
  2929. if (numSamples > ValueProfile::numberOfBuckets)
  2930. numSamples = ValueProfile::numberOfBuckets; // We don't want profiles that are extremely hot to be given more weight.
  2931. numberOfSamplesInProfiles += numSamples;
  2932. if (profile->m_bytecodeOffset < 0) {
  2933. profile->computeUpdatedPrediction(operation);
  2934. continue;
  2935. }
  2936. if (profile->numberOfSamples() || profile->m_prediction != SpecNone)
  2937. numberOfLiveNonArgumentValueProfiles++;
  2938. profile->computeUpdatedPrediction(operation);
  2939. }
  2940. #if ENABLE(DFG_JIT)
  2941. m_lazyOperandValueProfiles.computeUpdatedPredictions(operation);
  2942. #endif
  2943. }
  2944. void CodeBlock::updateAllValueProfilePredictions(OperationInProgress operation)
  2945. {
  2946. unsigned ignoredValue1, ignoredValue2;
  2947. updateAllPredictionsAndCountLiveness(operation, ignoredValue1, ignoredValue2);
  2948. }
  2949. void CodeBlock::updateAllArrayPredictions(OperationInProgress operation)
  2950. {
  2951. for (unsigned i = m_arrayProfiles.size(); i--;)
  2952. m_arrayProfiles[i].computeUpdatedPrediction(this, operation);
  2953. // Don't count these either, for similar reasons.
  2954. for (unsigned i = m_arrayAllocationProfiles.size(); i--;)
  2955. m_arrayAllocationProfiles[i].updateIndexingType();
  2956. }
  2957. void CodeBlock::updateAllPredictions(OperationInProgress operation)
  2958. {
  2959. updateAllValueProfilePredictions(operation);
  2960. updateAllArrayPredictions(operation);
  2961. }
  2962. bool CodeBlock::shouldOptimizeNow()
  2963. {
  2964. #if ENABLE(JIT_VERBOSE_OSR)
  2965. dataLog("Considering optimizing ", *this, "...\n");
  2966. #endif
  2967. #if ENABLE(VERBOSE_VALUE_PROFILE)
  2968. dumpValueProfiles();
  2969. #endif
  2970. if (m_optimizationDelayCounter >= Options::maximumOptimizationDelay())
  2971. return true;
  2972. updateAllArrayPredictions();
  2973. unsigned numberOfLiveNonArgumentValueProfiles;
  2974. unsigned numberOfSamplesInProfiles;
  2975. updateAllPredictionsAndCountLiveness(NoOperation, numberOfLiveNonArgumentValueProfiles, numberOfSamplesInProfiles);
  2976. #if ENABLE(JIT_VERBOSE_OSR)
  2977. dataLogF("Profile hotness: %lf (%u / %u), %lf (%u / %u)\n", (double)numberOfLiveNonArgumentValueProfiles / numberOfValueProfiles(), numberOfLiveNonArgumentValueProfiles, numberOfValueProfiles(), (double)numberOfSamplesInProfiles / ValueProfile::numberOfBuckets / numberOfValueProfiles(), numberOfSamplesInProfiles, ValueProfile::numberOfBuckets * numberOfValueProfiles());
  2978. #endif
  2979. if ((!numberOfValueProfiles() || (double)numberOfLiveNonArgumentValueProfiles / numberOfValueProfiles() >= Options::desiredProfileLivenessRate())
  2980. && (!totalNumberOfValueProfiles() || (double)numberOfSamplesInProfiles / ValueProfile::numberOfBuckets / totalNumberOfValueProfiles() >= Options::desiredProfileFullnessRate())
  2981. && static_cast<unsigned>(m_optimizationDelayCounter) + 1 >= Options::minimumOptimizationDelay())
  2982. return true;
  2983. ASSERT(m_optimizationDelayCounter < std::numeric_limits<uint8_t>::max());
  2984. m_optimizationDelayCounter++;
  2985. optimizeAfterWarmUp();
  2986. return false;
  2987. }
  2988. #endif
  2989. #if ENABLE(DFG_JIT)
  2990. void CodeBlock::tallyFrequentExitSites()
  2991. {
  2992. ASSERT(getJITType() == JITCode::DFGJIT);
  2993. ASSERT(alternative()->getJITType() == JITCode::BaselineJIT);
  2994. ASSERT(!!m_dfgData);
  2995. CodeBlock* profiledBlock = alternative();
  2996. for (unsigned i = 0; i < m_dfgData->osrExit.size(); ++i) {
  2997. DFG::OSRExit& exit = m_dfgData->osrExit[i];
  2998. if (!exit.considerAddingAsFrequentExitSite(profiledBlock))
  2999. continue;
  3000. #if DFG_ENABLE(DEBUG_VERBOSE)
  3001. dataLog("OSR exit #", i, " (bc#", exit.m_codeOrigin.bytecodeIndex, ", ", exit.m_kind, ") for ", *this, " occurred frequently: counting as frequent exit site.\n");
  3002. #endif
  3003. }
  3004. }
  3005. #endif // ENABLE(DFG_JIT)
  3006. #if ENABLE(VERBOSE_VALUE_PROFILE)
  3007. void CodeBlock::dumpValueProfiles()
  3008. {
  3009. dataLog("ValueProfile for ", *this, ":\n");
  3010. for (unsigned i = 0; i < totalNumberOfValueProfiles(); ++i) {
  3011. ValueProfile* profile = getFromAllValueProfiles(i);
  3012. if (profile->m_bytecodeOffset < 0) {
  3013. ASSERT(profile->m_bytecodeOffset == -1);
  3014. dataLogF(" arg = %u: ", i);
  3015. } else
  3016. dataLogF(" bc = %d: ", profile->m_bytecodeOffset);
  3017. if (!profile->numberOfSamples() && profile->m_prediction == SpecNone) {
  3018. dataLogF("<empty>\n");
  3019. continue;
  3020. }
  3021. profile->dump(WTF::dataFile());
  3022. dataLogF("\n");
  3023. }
  3024. dataLog("RareCaseProfile for ", *this, ":\n");
  3025. for (unsigned i = 0; i < numberOfRareCaseProfiles(); ++i) {
  3026. RareCaseProfile* profile = rareCaseProfile(i);
  3027. dataLogF(" bc = %d: %u\n", profile->m_bytecodeOffset, profile->m_counter);
  3028. }
  3029. dataLog("SpecialFastCaseProfile for ", *this, ":\n");
  3030. for (unsigned i = 0; i < numberOfSpecialFastCaseProfiles(); ++i) {
  3031. RareCaseProfile* profile = specialFastCaseProfile(i);
  3032. dataLogF(" bc = %d: %u\n", profile->m_bytecodeOffset, profile->m_counter);
  3033. }
  3034. }
  3035. #endif // ENABLE(VERBOSE_VALUE_PROFILE)
  3036. #endif // #if !(ENABLE(DETACHED_JIT) && BUILDING_DETACHED_JIT)
  3037. size_t CodeBlock::predictedMachineCodeSize()
  3038. {
  3039. // This will be called from CodeBlock::CodeBlock before either m_vm or the
  3040. // instructions have been initialized. It's OK to return 0 because what will really
  3041. // matter is the recomputation of this value when the slow path is triggered.
  3042. if (!m_vm)
  3043. return 0;
  3044. if (!m_vm->machineCodeBytesPerBytecodeWordForBaselineJIT)
  3045. return 0; // It's as good of a prediction as we'll get.
  3046. // Be conservative: return a size that will be an overestimation 84% of the time.
  3047. double multiplier = m_vm->machineCodeBytesPerBytecodeWordForBaselineJIT.mean() +
  3048. m_vm->machineCodeBytesPerBytecodeWordForBaselineJIT.standardDeviation();
  3049. // Be paranoid: silently reject bogus multipiers. Silently doing the "wrong" thing
  3050. // here is OK, since this whole method is just a heuristic.
  3051. if (multiplier < 0 || multiplier > 1000)
  3052. return 0;
  3053. double doubleResult = multiplier * m_instructions.size();
  3054. // Be even more paranoid: silently reject values that won't fit into a size_t. If
  3055. // the function is so huge that we can't even fit it into virtual memory then we
  3056. // should probably have some other guards in place to prevent us from even getting
  3057. // to this point.
  3058. if (doubleResult > std::numeric_limits<size_t>::max())
  3059. return 0;
  3060. return static_cast<size_t>(doubleResult);
  3061. }
  3062. #if !(ENABLE(DETACHED_JIT) && BUILDING_DETACHED_JIT)
  3063. bool CodeBlock::usesOpcode(OpcodeID opcodeID)
  3064. {
  3065. Interpreter* interpreter = vm()->interpreter;
  3066. Instruction* instructionsBegin = instructions().begin();
  3067. unsigned instructionCount = instructions().size();
  3068. for (unsigned bytecodeOffset = 0; bytecodeOffset < instructionCount; ) {
  3069. switch (interpreter->getOpcodeID(instructionsBegin[bytecodeOffset].u.opcode)) {
  3070. #define DEFINE_OP(curOpcode, length) \
  3071. case curOpcode: \
  3072. if (curOpcode == opcodeID) \
  3073. return true; \
  3074. bytecodeOffset += length; \
  3075. break;
  3076. FOR_EACH_OPCODE_ID(DEFINE_OP)
  3077. #undef DEFINE_OP
  3078. default:
  3079. RELEASE_ASSERT_NOT_REACHED();
  3080. break;
  3081. }
  3082. }
  3083. return false;
  3084. }
  3085. String CodeBlock::nameForRegister(int registerNumber)
  3086. {
  3087. SymbolTable::iterator end = symbolTable()->end();
  3088. for (SymbolTable::iterator ptr = symbolTable()->begin(); ptr != end; ++ptr) {
  3089. if (ptr->value.getIndex() == registerNumber)
  3090. return String(ptr->key);
  3091. }
  3092. if (needsActivation() && registerNumber == activationRegister())
  3093. return ASCIILiteral("activation");
  3094. if (registerNumber == thisRegister())
  3095. return ASCIILiteral("this");
  3096. if (usesArguments()) {
  3097. if (registerNumber == argumentsRegister())
  3098. return ASCIILiteral("arguments");
  3099. if (unmodifiedArgumentsRegister(argumentsRegister()) == registerNumber)
  3100. return ASCIILiteral("real arguments");
  3101. }
  3102. if (registerNumber < 0) {
  3103. int argumentPosition = -registerNumber;
  3104. argumentPosition -= JSStack::CallFrameHeaderSize + 1;
  3105. return String::format("arguments[%3d]", argumentPosition - 1).impl();
  3106. }
  3107. return "";
  3108. }
  3109. #endif // #if !(ENABLE(DETACHED_JIT) && BUILDING_DETACHED_JIT)
  3110. #if ENABLE(DETACHED_JIT)
  3111. void JSC::CodeBlock::DETACHED_JIT_DTOR()
  3112. {
  3113. switch (m_type) {
  3114. case CodeBlockFunction:
  3115. reinterpret_cast<FunctionCodeBlock*>(this)->DETACHED_JIT_DTOR();
  3116. return;
  3117. case CodeBlockGlobal:
  3118. reinterpret_cast<GlobalCodeBlock*>(this)->DETACHED_JIT_DTOR();
  3119. return;
  3120. }
  3121. // we don't have 'delete this' as CodeBlock is an abstract class
  3122. RELEASE_ASSERT_NOT_REACHED();
  3123. return;
  3124. }
  3125. CodeBlock * CodeBlock::replacement()
  3126. {
  3127. switch (m_type) {
  3128. case CodeBlockFunction:
  3129. return reinterpret_cast<FunctionCodeBlock*>(this)->replacement();
  3130. case CodeBlockGlobal:
  3131. return reinterpret_cast<GlobalCodeBlock*>(this)->replacement();
  3132. }
  3133. RELEASE_ASSERT_NOT_REACHED();
  3134. return NULL;
  3135. }
  3136. void JSC::FunctionCodeBlock::DETACHED_JIT_DTOR()
  3137. {
  3138. delete this;
  3139. }
  3140. void JSC::GlobalCodeBlock::DETACHED_JIT_DTOR()
  3141. {
  3142. delete this;
  3143. }
  3144. CodeBlock * GlobalCodeBlock::replacement()
  3145. {
  3146. switch (m_type) {
  3147. case GlobalCodeBlockEval:
  3148. return reinterpret_cast<EvalCodeBlock*>(this)->replacement();
  3149. case GlobalCodeBlockProgram:
  3150. return reinterpret_cast<ProgramCodeBlock*>(this)->replacement();
  3151. }
  3152. RELEASE_ASSERT_NOT_REACHED();
  3153. return NULL;
  3154. }
  3155. #endif
  3156. } // namespace JSC