CodeBlock.h 61 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631
  1. /*
  2. * Copyright (C) 2008, 2009, 2010, 2011, 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. #ifndef CodeBlock_h
  30. #define CodeBlock_h
  31. #include "ArrayProfile.h"
  32. #include "ByValInfo.h"
  33. #include "BytecodeConventions.h"
  34. #include "CallLinkInfo.h"
  35. #include "CallReturnOffsetToBytecodeOffset.h"
  36. #include "CodeBlockHash.h"
  37. #include "CodeOrigin.h"
  38. #include "CodeType.h"
  39. #include "CompactJITCodeMap.h"
  40. #include "DFGCodeBlocks.h"
  41. #include "DFGCommon.h"
  42. #include "DFGExitProfile.h"
  43. #include "DFGMinifiedGraph.h"
  44. #include "DFGOSREntry.h"
  45. #include "DFGOSRExit.h"
  46. #include "DFGVariableEventStream.h"
  47. #include "EvalCodeCache.h"
  48. #include "ExecutionCounter.h"
  49. #include "ExpressionRangeInfo.h"
  50. #include "HandlerInfo.h"
  51. #include "ObjectAllocationProfile.h"
  52. #include "Options.h"
  53. #include "Instruction.h"
  54. #include "JITCode.h"
  55. #include "JITWriteBarrier.h"
  56. #include "JSCBridge.h"
  57. #include "JSCBridgeToll.h"
  58. #include "JSGlobalObject.h"
  59. #include "JumpReplacementWatchpoint.h"
  60. #include "JumpTable.h"
  61. #include "LLIntCallLinkInfo.h"
  62. #include "LazyOperandValueProfile.h"
  63. #include "LineInfo.h"
  64. #include "ProfilerCompilation.h"
  65. #include "RegExpObject.h"
  66. #include "ResolveOperation.h"
  67. #include "StructureStubInfo.h"
  68. #include "UnconditionalFinalizer.h"
  69. #include "ValueProfile.h"
  70. #include "Watchpoint.h"
  71. #include <wtf/RefCountedArray.h>
  72. #include <wtf/FastAllocBase.h>
  73. #include <wtf/PassOwnPtr.h>
  74. #include <wtf/Platform.h>
  75. #include <wtf/RefPtr.h>
  76. #include <wtf/SegmentedVector.h>
  77. #include <wtf/Vector.h>
  78. #include <wtf/text/WTFString.h>
  79. namespace JSC {
  80. class DFGCodeBlocks;
  81. class ExecState;
  82. class LLIntOffsetsExtractor;
  83. class RepatchBuffer;
  84. inline int unmodifiedArgumentsRegister(int argumentsRegister) { return argumentsRegister - 1; }
  85. static ALWAYS_INLINE int missingThisObjectMarker() { return std::numeric_limits<int>::max(); }
  86. class CodeBlock : public UnconditionalFinalizer, public WeakReferenceHarvester {
  87. #if ENABLE(JIT) && ENABLE(DETACHED_JIT)
  88. DETACHED_JIT_MAKE_SHARED_DATA_ALLOCATED;
  89. #else
  90. WTF_MAKE_FAST_ALLOCATED;
  91. #endif
  92. friend class JIT;
  93. friend class LLIntOffsetsExtractor;
  94. public:
  95. enum CopyParsedBlockTag { CopyParsedBlock };
  96. #if ENABLE(DETACHED_JIT)
  97. typedef enum {
  98. CodeBlockFunction,
  99. CodeBlockGlobal
  100. } CodeBlockType;
  101. #endif
  102. protected:
  103. CodeBlock(CopyParsedBlockTag, CodeBlock& other
  104. #if ENABLE(DETACHED_JIT)
  105. , CodeBlockType
  106. #endif
  107. );
  108. CodeBlock(ScriptExecutable* ownerExecutable, UnlinkedCodeBlock*, JSGlobalObject*, unsigned baseScopeDepth, PassRefPtr<SourceProvider>, unsigned sourceOffset, unsigned firstLineColumnOffset, PassOwnPtr<CodeBlock> alternative
  109. #if ENABLE(DETACHED_JIT)
  110. , CodeBlockType
  111. #endif
  112. );
  113. WriteBarrier<JSGlobalObject> m_globalObject;
  114. Heap* m_heap;
  115. public:
  116. JS_EXPORT_PRIVATE DETACHED_JIT_VIRTUAL_DTOR ~CodeBlock();
  117. public:
  118. UnlinkedCodeBlock* unlinkedCodeBlock() const { return m_unlinkedCode.get(); }
  119. String inferredName() const;
  120. CodeBlockHash hash() const;
  121. String sourceCodeForTools() const; // Not quite the actual source we parsed; this will do things like prefix the source for a function with a reified signature.
  122. String sourceCodeOnOneLine() const; // As sourceCodeForTools(), but replaces all whitespace runs with a single space.
  123. void dumpAssumingJITType(PrintStream&, JITCode::JITType) const;
  124. void dump(PrintStream&) const;
  125. int numParameters() const { return m_numParameters; }
  126. void setNumParameters(int newValue);
  127. int* addressOfNumParameters() { return &m_numParameters; }
  128. static ptrdiff_t offsetOfNumParameters() { return OBJECT_OFFSETOF(CodeBlock, m_numParameters); }
  129. CodeBlock* alternative() { return m_alternative.get(); }
  130. PassOwnPtr<CodeBlock> releaseAlternative() { return m_alternative.release(); }
  131. void setAlternative(PassOwnPtr<CodeBlock> alternative) { ASSERT_NOT_REACHED_BY_DETACHED_JIT(); m_alternative = alternative; }
  132. CodeSpecializationKind specializationKind() const
  133. {
  134. return specializationFromIsConstruct(m_isConstructor);
  135. }
  136. #if ENABLE(JIT)
  137. CodeBlock* baselineVersion()
  138. {
  139. CodeBlock* result = replacement();
  140. if (!result)
  141. return 0; // This can happen if we're in the process of creating the baseline version.
  142. while (result->alternative())
  143. result = result->alternative();
  144. ASSERT(result);
  145. ASSERT(JITCode::isBaselineCode(result->getJITType()));
  146. return result;
  147. }
  148. #else
  149. CodeBlock* baselineVersion()
  150. {
  151. return this;
  152. }
  153. #endif
  154. void visitAggregate(SlotVisitor&);
  155. static void dumpStatistics();
  156. void dumpBytecode(PrintStream& = WTF::dataFile());
  157. void dumpBytecode(PrintStream&, unsigned bytecodeOffset);
  158. void printStructures(PrintStream&, const Instruction*);
  159. void printStructure(PrintStream&, const char* name, const Instruction*, int operand);
  160. bool isStrictMode() const { return m_isStrictMode; }
  161. inline bool isKnownNotImmediate(int index)
  162. {
  163. if (index == m_thisRegister && !m_isStrictMode)
  164. return true;
  165. if (isConstantRegisterIndex(index))
  166. return getConstant(index).isCell();
  167. return false;
  168. }
  169. ALWAYS_INLINE bool isTemporaryRegisterIndex(int index)
  170. {
  171. return index >= m_numVars;
  172. }
  173. HandlerInfo* handlerForBytecodeOffset(unsigned bytecodeOffset);
  174. unsigned lineNumberForBytecodeOffset(unsigned bytecodeOffset);
  175. unsigned columnNumberForBytecodeOffset(unsigned bytecodeOffset);
  176. void expressionRangeForBytecodeOffset(unsigned bytecodeOffset, int& divot,
  177. int& startOffset, int& endOffset, unsigned& line, unsigned& column);
  178. #if ENABLE(JIT)
  179. StructureStubInfo& getStubInfo(ReturnAddressPtr returnAddress)
  180. {
  181. return *(binarySearch<StructureStubInfo, void*>(m_structureStubInfos, m_structureStubInfos.size(), returnAddress.value(), getStructureStubInfoReturnLocation));
  182. }
  183. StructureStubInfo& getStubInfo(unsigned bytecodeIndex)
  184. {
  185. return *(binarySearch<StructureStubInfo, unsigned>(m_structureStubInfos, m_structureStubInfos.size(), bytecodeIndex, getStructureStubInfoBytecodeIndex));
  186. }
  187. void resetStub(StructureStubInfo&);
  188. ByValInfo& getByValInfo(unsigned bytecodeIndex)
  189. {
  190. return *(binarySearch<ByValInfo, unsigned>(m_byValInfos, m_byValInfos.size(), bytecodeIndex, getByValInfoBytecodeIndex));
  191. }
  192. CallLinkInfo& getCallLinkInfo(ReturnAddressPtr returnAddress)
  193. {
  194. return *(binarySearch<CallLinkInfo, void*>(m_callLinkInfos, m_callLinkInfos.size(), returnAddress.value(), getCallLinkInfoReturnLocation));
  195. }
  196. CallLinkInfo& getCallLinkInfo(unsigned bytecodeIndex)
  197. {
  198. ASSERT(JITCode::isBaselineCode(getJITType()));
  199. return *(binarySearch<CallLinkInfo, unsigned>(m_callLinkInfos, m_callLinkInfos.size(), bytecodeIndex, getCallLinkInfoBytecodeIndex));
  200. }
  201. #endif // ENABLE(JIT)
  202. #if ENABLE(LLINT)
  203. Instruction* adjustPCIfAtCallSite(Instruction*);
  204. #endif
  205. unsigned bytecodeOffset(ExecState*, ReturnAddressPtr);
  206. #if ENABLE(JIT)
  207. unsigned bytecodeOffsetForCallAtIndex(unsigned index)
  208. {
  209. if (!m_rareData)
  210. return 1;
  211. Vector_shared<CallReturnOffsetToBytecodeOffset, 0, UnsafeVectorOverflow>& callIndices = m_rareData->m_callReturnIndexVector;
  212. if (!callIndices.size())
  213. return 1;
  214. // FIXME: Fix places in DFG that call out to C that don't set the CodeOrigin. https://bugs.webkit.org/show_bug.cgi?id=118315
  215. ASSERT(index < m_rareData->m_callReturnIndexVector.size());
  216. if (index >= m_rareData->m_callReturnIndexVector.size())
  217. return 1;
  218. return m_rareData->m_callReturnIndexVector[index].bytecodeOffset;
  219. }
  220. void unlinkCalls();
  221. bool hasIncomingCalls() { return m_incomingCalls.begin() != m_incomingCalls.end(); }
  222. void linkIncomingCall(CallLinkInfo* incoming)
  223. {
  224. m_incomingCalls.push(incoming);
  225. }
  226. bool isIncomingCallAlreadyLinked(CallLinkInfo* incoming)
  227. {
  228. return m_incomingCalls.isOnList(incoming);
  229. }
  230. #endif // ENABLE(JIT)
  231. #if ENABLE(LLINT)
  232. void linkIncomingCall(LLIntCallLinkInfo* incoming)
  233. {
  234. m_incomingLLIntCalls.push(incoming);
  235. }
  236. #endif // ENABLE(LLINT)
  237. void unlinkIncomingCalls();
  238. #if ENABLE(DFG_JIT) || ENABLE(LLINT)
  239. void setJITCodeMap(PassOwnPtr<CompactJITCodeMap> jitCodeMap)
  240. {
  241. m_jitCodeMap = jitCodeMap;
  242. }
  243. CompactJITCodeMap* jitCodeMap()
  244. {
  245. return m_jitCodeMap.get();
  246. }
  247. #endif
  248. #if ENABLE(DFG_JIT)
  249. void createDFGDataIfNecessary()
  250. {
  251. if (!!m_dfgData)
  252. return;
  253. m_dfgData = adoptPtr(new DFGData);
  254. }
  255. #if !ENABLE(DETACHED_JIT)
  256. void saveCompilation(PassRefPtr<Profiler::Compilation> compilation)
  257. {
  258. createDFGDataIfNecessary();
  259. m_dfgData->compilation = compilation;
  260. }
  261. Profiler::Compilation* compilation()
  262. {
  263. if (!m_dfgData)
  264. return 0;
  265. return m_dfgData->compilation.get();
  266. }
  267. #endif
  268. DFG::OSREntryData* appendDFGOSREntryData(unsigned bytecodeIndex, unsigned machineCodeOffset)
  269. {
  270. createDFGDataIfNecessary();
  271. DFG::OSREntryData entry;
  272. entry.m_bytecodeIndex = bytecodeIndex;
  273. entry.m_machineCodeOffset = machineCodeOffset;
  274. m_dfgData->osrEntry.append(entry);
  275. return &m_dfgData->osrEntry.last();
  276. }
  277. unsigned numberOfDFGOSREntries() const
  278. {
  279. if (!m_dfgData)
  280. return 0;
  281. return m_dfgData->osrEntry.size();
  282. }
  283. DFG::OSREntryData* dfgOSREntryData(unsigned i) { return &m_dfgData->osrEntry[i]; }
  284. DFG::OSREntryData* dfgOSREntryDataForBytecodeIndex(unsigned bytecodeIndex)
  285. {
  286. if (!m_dfgData)
  287. return 0;
  288. return tryBinarySearch<DFG::OSREntryData, unsigned>(
  289. m_dfgData->osrEntry, m_dfgData->osrEntry.size(), bytecodeIndex,
  290. DFG::getOSREntryDataBytecodeIndex);
  291. }
  292. unsigned appendOSRExit(const DFG::OSRExit& osrExit)
  293. {
  294. createDFGDataIfNecessary();
  295. unsigned result = m_dfgData->osrExit.size();
  296. m_dfgData->osrExit.append(osrExit);
  297. return result;
  298. }
  299. DFG::OSRExit& lastOSRExit()
  300. {
  301. return m_dfgData->osrExit.last();
  302. }
  303. unsigned appendSpeculationRecovery(const DFG::SpeculationRecovery& recovery)
  304. {
  305. createDFGDataIfNecessary();
  306. unsigned result = m_dfgData->speculationRecovery.size();
  307. m_dfgData->speculationRecovery.append(recovery);
  308. return result;
  309. }
  310. unsigned appendWatchpoint(const JumpReplacementWatchpoint& watchpoint)
  311. {
  312. createDFGDataIfNecessary();
  313. unsigned result = m_dfgData->watchpoints.size();
  314. m_dfgData->watchpoints.append(watchpoint);
  315. return result;
  316. }
  317. unsigned numberOfOSRExits()
  318. {
  319. if (!m_dfgData)
  320. return 0;
  321. return m_dfgData->osrExit.size();
  322. }
  323. unsigned numberOfSpeculationRecoveries()
  324. {
  325. if (!m_dfgData)
  326. return 0;
  327. return m_dfgData->speculationRecovery.size();
  328. }
  329. unsigned numberOfWatchpoints()
  330. {
  331. if (!m_dfgData)
  332. return 0;
  333. return m_dfgData->watchpoints.size();
  334. }
  335. DFG::OSRExit& osrExit(unsigned index)
  336. {
  337. return m_dfgData->osrExit[index];
  338. }
  339. DFG::SpeculationRecovery& speculationRecovery(unsigned index)
  340. {
  341. return m_dfgData->speculationRecovery[index];
  342. }
  343. JumpReplacementWatchpoint& watchpoint(unsigned index)
  344. {
  345. return m_dfgData->watchpoints[index];
  346. }
  347. void appendWeakReference(JSCell* target)
  348. {
  349. createDFGDataIfNecessary();
  350. m_dfgData->weakReferences.append(WriteBarrier<JSCell>(*vm(), ownerExecutable(), target));
  351. }
  352. void appendWeakReferenceTransition(JSCell* codeOrigin, JSCell* from, JSCell* to)
  353. {
  354. createDFGDataIfNecessary();
  355. m_dfgData->transitions.append(
  356. WeakReferenceTransition(*vm(), ownerExecutable(), codeOrigin, from, to));
  357. }
  358. DFG::MinifiedGraph& minifiedDFG()
  359. {
  360. createDFGDataIfNecessary();
  361. return m_dfgData->minifiedDFG;
  362. }
  363. DFG::VariableEventStream& variableEventStream()
  364. {
  365. createDFGDataIfNecessary();
  366. return m_dfgData->variableEventStream;
  367. }
  368. #endif
  369. unsigned bytecodeOffset(Instruction* returnAddress)
  370. {
  371. RELEASE_ASSERT(returnAddress >= instructions().begin() && returnAddress < instructions().end());
  372. return static_cast<Instruction*>(returnAddress) - instructions().begin();
  373. }
  374. bool isNumericCompareFunction() { return m_unlinkedCode->isNumericCompareFunction(); }
  375. unsigned numberOfInstructions() const { return m_instructions.size(); }
  376. RefCountedArray_shared<Instruction>& instructions() { return m_instructions; }
  377. const RefCountedArray_shared<Instruction>& instructions() const { return m_instructions; }
  378. size_t predictedMachineCodeSize();
  379. bool usesOpcode(OpcodeID);
  380. unsigned instructionCount() { return m_instructions.size(); }
  381. int argumentIndexAfterCapture(size_t argument);
  382. #if ENABLE(JIT)
  383. void setJITCode(const JITCode& code, MacroAssemblerCodePtr codeWithArityCheck)
  384. {
  385. m_jitCode = code;
  386. m_jitCodeWithArityCheck = codeWithArityCheck;
  387. #if ENABLE(DFG_JIT)
  388. if (m_jitCode.jitType() == JITCode::DFGJIT) {
  389. createDFGDataIfNecessary();
  390. m_vm->heap.m_dfgCodeBlocks.m_set.add(this);
  391. }
  392. #endif
  393. }
  394. JITCode& getJITCode() { return m_jitCode; }
  395. MacroAssemblerCodePtr getJITCodeWithArityCheck() { return m_jitCodeWithArityCheck; }
  396. JITCode::JITType getJITType() const { return m_jitCode.jitType(); }
  397. ExecutableMemoryHandle* executableMemory() { return getJITCode().getExecutableMemory(); }
  398. virtual JSObject* compileOptimized(ExecState*, JSScope*, unsigned bytecodeIndex) = 0;
  399. void jettison();
  400. enum JITCompilationResult { AlreadyCompiled, CouldNotCompile, CompiledSuccessfully };
  401. JITCompilationResult jitCompile(ExecState* exec)
  402. {
  403. if (getJITType() != JITCode::InterpreterThunk) {
  404. ASSERT(getJITType() == JITCode::BaselineJIT);
  405. return AlreadyCompiled;
  406. }
  407. #if ENABLE(JIT)
  408. if (jitCompileImpl(exec))
  409. return CompiledSuccessfully;
  410. return CouldNotCompile;
  411. #else
  412. UNUSED_PARAM(exec);
  413. return CouldNotCompile;
  414. #endif
  415. }
  416. #if ENABLE(DETACHED_JIT)
  417. CodeBlock* replacement();
  418. #else
  419. virtual CodeBlock* replacement() = 0;
  420. #endif
  421. virtual DFG::CapabilityLevel canCompileWithDFGInternal() = 0;
  422. DFG::CapabilityLevel canCompileWithDFG()
  423. {
  424. #if ENABLE(DETACHED_JIT) && BUILDING_DETACHED_JIT
  425. return JSCBridge::sharedInstance()->toll()->forCodeBlock(this).m_dfgCapabilityLevel;
  426. #else
  427. DFG::CapabilityLevel result = canCompileWithDFGInternal();
  428. m_canCompileWithDFGState = result;
  429. return result;
  430. #endif
  431. }
  432. DFG::CapabilityLevel canCompileWithDFGState() { return m_canCompileWithDFGState; }
  433. bool hasOptimizedReplacement()
  434. {
  435. ASSERT(JITCode::isBaselineCode(getJITType()));
  436. bool result = replacement()->getJITType() > getJITType();
  437. #if !ASSERT_DISABLED
  438. if (result)
  439. ASSERT(replacement()->getJITType() == JITCode::DFGJIT);
  440. else {
  441. ASSERT(JITCode::isBaselineCode(replacement()->getJITType()));
  442. ASSERT(replacement() == this);
  443. }
  444. #endif
  445. return result;
  446. }
  447. #else
  448. JITCode::JITType getJITType() const { return JITCode::BaselineJIT; }
  449. #endif
  450. ScriptExecutable* ownerExecutable() const { return m_ownerExecutable.get(); }
  451. void setVM(VM* vm) { m_vm = vm; }
  452. VM* vm() { return m_vm; }
  453. void setThisRegister(int thisRegister) { m_thisRegister = thisRegister; }
  454. int thisRegister() const { return m_thisRegister; }
  455. bool needsFullScopeChain() const { return m_unlinkedCode->needsFullScopeChain(); }
  456. bool usesEval() const { return m_unlinkedCode->usesEval(); }
  457. void setArgumentsRegister(int argumentsRegister)
  458. {
  459. ASSERT(argumentsRegister != -1);
  460. m_argumentsRegister = argumentsRegister;
  461. ASSERT(usesArguments());
  462. }
  463. int argumentsRegister() const
  464. {
  465. ASSERT(usesArguments());
  466. return m_argumentsRegister;
  467. }
  468. int uncheckedArgumentsRegister()
  469. {
  470. if (!usesArguments())
  471. return InvalidVirtualRegister;
  472. return argumentsRegister();
  473. }
  474. void setActivationRegister(int activationRegister)
  475. {
  476. m_activationRegister = activationRegister;
  477. }
  478. int activationRegister() const
  479. {
  480. ASSERT(needsFullScopeChain());
  481. return m_activationRegister;
  482. }
  483. int uncheckedActivationRegister()
  484. {
  485. if (!needsFullScopeChain())
  486. return InvalidVirtualRegister;
  487. return activationRegister();
  488. }
  489. bool usesArguments() const { return m_argumentsRegister != -1; }
  490. bool needsActivation() const
  491. {
  492. return needsFullScopeChain() && codeType() != GlobalCode;
  493. }
  494. bool isCaptured(int operand, InlineCallFrame* inlineCallFrame = 0) const
  495. {
  496. if (operandIsArgument(operand))
  497. return operandToArgument(operand) && usesArguments();
  498. if (inlineCallFrame)
  499. return inlineCallFrame->capturedVars.get(operand);
  500. // The activation object isn't in the captured region, but it's "captured"
  501. // in the sense that stores to its location can be observed indirectly.
  502. if (needsActivation() && operand == activationRegister())
  503. return true;
  504. // Ditto for the arguments object.
  505. if (usesArguments() && operand == argumentsRegister())
  506. return true;
  507. // Ditto for the arguments object.
  508. if (usesArguments() && operand == unmodifiedArgumentsRegister(argumentsRegister()))
  509. return true;
  510. // We're in global code so there are no locals to capture
  511. if (!symbolTable())
  512. return false;
  513. return operand >= symbolTable()->captureStart()
  514. && operand < symbolTable()->captureEnd();
  515. }
  516. #if ENABLE(DETACHED_JIT) && BUILDING_DETACHED_JIT
  517. CodeType codeType() const { return JSCBridge::sharedInstance()->toll()->forCodeBlock(this).m_codeType; }
  518. #else
  519. CodeType codeType() const { return m_unlinkedCode->codeType(); }
  520. #endif
  521. SourceProvider* source() const { return m_source.get(); }
  522. unsigned sourceOffset() const { return m_sourceOffset; }
  523. unsigned firstLineColumnOffset() const { return m_firstLineColumnOffset; }
  524. #if ENABLE(DETACHED_JIT) && BUILDING_DETACHED_JIT
  525. inline size_t numberOfJumpTargets() const { return JSCBridge::sharedInstance()->toll()->forCodeBlock(this).m_numberOfJumpTargets; }
  526. inline unsigned jumpTarget(int index) const { assert(index < numberOfJumpTargets()); return JSCBridge::sharedInstance()->toll()->forCodeBlock(this).m_jumpTargets[index]; }
  527. #else
  528. size_t numberOfJumpTargets() const { return m_unlinkedCode->numberOfJumpTargets(); }
  529. unsigned jumpTarget(int index) const { return m_unlinkedCode->jumpTarget(index); }
  530. #endif
  531. void createActivation(CallFrame*);
  532. void clearEvalCache();
  533. String nameForRegister(int registerNumber);
  534. #if ENABLE(JIT)
  535. void setNumberOfStructureStubInfos(size_t size) { m_structureStubInfos.grow(size); }
  536. size_t numberOfStructureStubInfos() const { return m_structureStubInfos.size(); }
  537. StructureStubInfo& structureStubInfo(int index) { return m_structureStubInfos[index]; }
  538. void setNumberOfByValInfos(size_t size) { m_byValInfos.grow(size); }
  539. size_t numberOfByValInfos() const { return m_byValInfos.size(); }
  540. ByValInfo& byValInfo(size_t index) { return m_byValInfos[index]; }
  541. void setNumberOfCallLinkInfos(size_t size) { m_callLinkInfos.grow(size); }
  542. size_t numberOfCallLinkInfos() const { return m_callLinkInfos.size(); }
  543. CallLinkInfo& callLinkInfo(int index) { return m_callLinkInfos[index]; }
  544. #endif
  545. #if ENABLE(VALUE_PROFILER)
  546. unsigned numberOfArgumentValueProfiles()
  547. {
  548. ASSERT(m_numParameters >= 0);
  549. ASSERT(m_argumentValueProfiles.size() == static_cast<unsigned>(m_numParameters));
  550. return m_argumentValueProfiles.size();
  551. }
  552. ValueProfile* valueProfileForArgument(unsigned argumentIndex)
  553. {
  554. ValueProfile* result = &m_argumentValueProfiles[argumentIndex];
  555. ASSERT(result->m_bytecodeOffset == -1);
  556. return result;
  557. }
  558. unsigned numberOfValueProfiles() { return m_valueProfiles.size(); }
  559. ValueProfile* valueProfile(int index) { return &m_valueProfiles[index]; }
  560. ValueProfile* valueProfileForBytecodeOffset(int bytecodeOffset)
  561. {
  562. ValueProfile* result = binarySearch<ValueProfile, int>(
  563. m_valueProfiles, m_valueProfiles.size(), bytecodeOffset,
  564. getValueProfileBytecodeOffset<ValueProfile>);
  565. ASSERT(result->m_bytecodeOffset != -1);
  566. ASSERT(instructions()[bytecodeOffset + opcodeLength(
  567. m_vm->interpreter->getOpcodeID(
  568. instructions()[
  569. bytecodeOffset].u.opcode)) - 1].u.profile == result);
  570. return result;
  571. }
  572. SpeculatedType valueProfilePredictionForBytecodeOffset(int bytecodeOffset)
  573. {
  574. return valueProfileForBytecodeOffset(bytecodeOffset)->computeUpdatedPrediction();
  575. }
  576. unsigned totalNumberOfValueProfiles()
  577. {
  578. return numberOfArgumentValueProfiles() + numberOfValueProfiles();
  579. }
  580. ValueProfile* getFromAllValueProfiles(unsigned index)
  581. {
  582. if (index < numberOfArgumentValueProfiles())
  583. return valueProfileForArgument(index);
  584. return valueProfile(index - numberOfArgumentValueProfiles());
  585. }
  586. RareCaseProfile* addRareCaseProfile(int bytecodeOffset)
  587. {
  588. m_rareCaseProfiles.append(RareCaseProfile(bytecodeOffset));
  589. return &m_rareCaseProfiles.last();
  590. }
  591. unsigned numberOfRareCaseProfiles() { return m_rareCaseProfiles.size(); }
  592. RareCaseProfile* rareCaseProfile(int index) { return &m_rareCaseProfiles[index]; }
  593. RareCaseProfile* rareCaseProfileForBytecodeOffset(int bytecodeOffset)
  594. {
  595. return tryBinarySearch<RareCaseProfile, int>(
  596. m_rareCaseProfiles, m_rareCaseProfiles.size(), bytecodeOffset,
  597. getRareCaseProfileBytecodeOffset);
  598. }
  599. bool likelyToTakeSlowCase(int bytecodeOffset)
  600. {
  601. if (!numberOfRareCaseProfiles())
  602. return false;
  603. unsigned value = rareCaseProfileForBytecodeOffset(bytecodeOffset)->m_counter;
  604. return value >= Options::likelyToTakeSlowCaseMinimumCount();
  605. }
  606. bool couldTakeSlowCase(int bytecodeOffset)
  607. {
  608. if (!numberOfRareCaseProfiles())
  609. return false;
  610. unsigned value = rareCaseProfileForBytecodeOffset(bytecodeOffset)->m_counter;
  611. return value >= Options::couldTakeSlowCaseMinimumCount();
  612. }
  613. RareCaseProfile* addSpecialFastCaseProfile(int bytecodeOffset)
  614. {
  615. m_specialFastCaseProfiles.append(RareCaseProfile(bytecodeOffset));
  616. return &m_specialFastCaseProfiles.last();
  617. }
  618. unsigned numberOfSpecialFastCaseProfiles() { return m_specialFastCaseProfiles.size(); }
  619. RareCaseProfile* specialFastCaseProfile(int index) { return &m_specialFastCaseProfiles[index]; }
  620. RareCaseProfile* specialFastCaseProfileForBytecodeOffset(int bytecodeOffset)
  621. {
  622. return tryBinarySearch<RareCaseProfile, int>(
  623. m_specialFastCaseProfiles, m_specialFastCaseProfiles.size(), bytecodeOffset,
  624. getRareCaseProfileBytecodeOffset);
  625. }
  626. bool likelyToTakeSpecialFastCase(int bytecodeOffset)
  627. {
  628. if (!numberOfRareCaseProfiles())
  629. return false;
  630. unsigned specialFastCaseCount = specialFastCaseProfileForBytecodeOffset(bytecodeOffset)->m_counter;
  631. return specialFastCaseCount >= Options::likelyToTakeSlowCaseMinimumCount();
  632. }
  633. bool couldTakeSpecialFastCase(int bytecodeOffset)
  634. {
  635. if (!numberOfRareCaseProfiles())
  636. return false;
  637. unsigned specialFastCaseCount = specialFastCaseProfileForBytecodeOffset(bytecodeOffset)->m_counter;
  638. return specialFastCaseCount >= Options::couldTakeSlowCaseMinimumCount();
  639. }
  640. bool likelyToTakeDeepestSlowCase(int bytecodeOffset)
  641. {
  642. if (!numberOfRareCaseProfiles())
  643. return false;
  644. unsigned slowCaseCount = rareCaseProfileForBytecodeOffset(bytecodeOffset)->m_counter;
  645. unsigned specialFastCaseCount = specialFastCaseProfileForBytecodeOffset(bytecodeOffset)->m_counter;
  646. unsigned value = slowCaseCount - specialFastCaseCount;
  647. return value >= Options::likelyToTakeSlowCaseMinimumCount();
  648. }
  649. bool likelyToTakeAnySlowCase(int bytecodeOffset)
  650. {
  651. if (!numberOfRareCaseProfiles())
  652. return false;
  653. unsigned slowCaseCount = rareCaseProfileForBytecodeOffset(bytecodeOffset)->m_counter;
  654. unsigned specialFastCaseCount = specialFastCaseProfileForBytecodeOffset(bytecodeOffset)->m_counter;
  655. unsigned value = slowCaseCount + specialFastCaseCount;
  656. return value >= Options::likelyToTakeSlowCaseMinimumCount();
  657. }
  658. unsigned numberOfArrayProfiles() const { return m_arrayProfiles.size(); }
  659. const ArrayProfileVector& arrayProfiles() { return m_arrayProfiles; }
  660. ArrayProfile* addArrayProfile(unsigned bytecodeOffset)
  661. {
  662. m_arrayProfiles.append(ArrayProfile(bytecodeOffset));
  663. return &m_arrayProfiles.last();
  664. }
  665. ArrayProfile* getArrayProfile(unsigned bytecodeOffset);
  666. ArrayProfile* getOrAddArrayProfile(unsigned bytecodeOffset);
  667. #endif
  668. // Exception handling support
  669. size_t numberOfExceptionHandlers() const { return m_rareData ? m_rareData->m_exceptionHandlers.size() : 0; }
  670. void allocateHandlers(const Vector<UnlinkedHandlerInfo>& unlinkedHandlers)
  671. {
  672. size_t count = unlinkedHandlers.size();
  673. if (!count)
  674. return;
  675. createRareDataIfNecessary();
  676. m_rareData->m_exceptionHandlers.resize(count);
  677. for (size_t i = 0; i < count; ++i) {
  678. m_rareData->m_exceptionHandlers[i].start = unlinkedHandlers[i].start;
  679. m_rareData->m_exceptionHandlers[i].end = unlinkedHandlers[i].end;
  680. m_rareData->m_exceptionHandlers[i].target = unlinkedHandlers[i].target;
  681. m_rareData->m_exceptionHandlers[i].scopeDepth = unlinkedHandlers[i].scopeDepth;
  682. }
  683. }
  684. HandlerInfo& exceptionHandler(int index) { RELEASE_ASSERT(m_rareData); return m_rareData->m_exceptionHandlers[index]; }
  685. bool hasExpressionInfo() { ASSERT_NOT_REACHED_BY_DETACHED_JIT(); return m_unlinkedCode->hasExpressionInfo(); }
  686. #if ENABLE(JIT)
  687. Vector_shared<CallReturnOffsetToBytecodeOffset, 0, UnsafeVectorOverflow>& callReturnIndexVector()
  688. {
  689. createRareDataIfNecessary();
  690. return m_rareData->m_callReturnIndexVector;
  691. }
  692. #endif
  693. #if ENABLE(DFG_JIT)
  694. SegmentedVector_shared<InlineCallFrame, 4>& inlineCallFrames()
  695. {
  696. createRareDataIfNecessary();
  697. return m_rareData->m_inlineCallFrames;
  698. }
  699. Vector_shared<CodeOriginAtCallReturnOffset, 0, UnsafeVectorOverflow>& codeOrigins()
  700. {
  701. createRareDataIfNecessary();
  702. return m_rareData->m_codeOrigins;
  703. }
  704. // Having code origins implies that there has been some inlining.
  705. bool hasCodeOrigins()
  706. {
  707. return m_rareData && !!m_rareData->m_codeOrigins.size();
  708. }
  709. bool codeOriginForReturn(ReturnAddressPtr, CodeOrigin&);
  710. bool canGetCodeOrigin(unsigned index)
  711. {
  712. if (!m_rareData)
  713. return false;
  714. return m_rareData->m_codeOrigins.size() > index;
  715. }
  716. CodeOrigin codeOrigin(unsigned index)
  717. {
  718. RELEASE_ASSERT(m_rareData);
  719. return m_rareData->m_codeOrigins[index].codeOrigin;
  720. }
  721. #if !(ENABLE(DETACHED_JIT) && BUILDING_DETACHED_JIT)
  722. bool addFrequentExitSite(const DFG::FrequentExitSite& site)
  723. {
  724. ASSERT(JITCode::isBaselineCode(getJITType()));
  725. return m_exitProfile.add(site);
  726. }
  727. #endif
  728. bool hasExitSite(const DFG::FrequentExitSite& site) const { return m_exitProfile.hasExitSite(site); }
  729. DFG::ExitProfile& exitProfile() { return m_exitProfile; }
  730. CompressedLazyOperandValueProfileHolder& lazyOperandValueProfiles()
  731. {
  732. return m_lazyOperandValueProfiles;
  733. }
  734. #endif
  735. // Constant Pool
  736. size_t numberOfIdentifiers() const { return m_identifiers.size(); }
  737. void addIdentifier(const Identifier& i) { return m_identifiers.append(i); }
  738. Identifier& identifier(int index) { return m_identifiers[index]; }
  739. size_t numberOfConstantRegisters() const { return m_constantRegisters.size(); }
  740. unsigned addConstant(JSValue v)
  741. {
  742. unsigned result = m_constantRegisters.size();
  743. m_constantRegisters.append(WriteBarrier<Unknown>());
  744. m_constantRegisters.last().set(m_globalObject->vm(), m_ownerExecutable.get(), v);
  745. return result;
  746. }
  747. unsigned addOrFindConstant(JSValue);
  748. WriteBarrier<Unknown>& constantRegister(int index) { return m_constantRegisters[index - FirstConstantRegisterIndex]; }
  749. ALWAYS_INLINE bool isConstantRegisterIndex(int index) const { return index >= FirstConstantRegisterIndex; }
  750. ALWAYS_INLINE JSValue getConstant(int index) const { return m_constantRegisters[index - FirstConstantRegisterIndex].get(); }
  751. FunctionExecutable* functionDecl(int index) { return m_functionDecls[index].get(); }
  752. int numberOfFunctionDecls() { return m_functionDecls.size(); }
  753. FunctionExecutable* functionExpr(int index) { return m_functionExprs[index].get(); }
  754. RegExp* regexp(int index) const { return m_unlinkedCode->regexp(index); }
  755. unsigned numberOfConstantBuffers() const
  756. {
  757. if (!m_rareData)
  758. return 0;
  759. return m_rareData->m_constantBuffers.size();
  760. }
  761. unsigned addConstantBuffer(const Vector_shared<JSValue>& buffer)
  762. {
  763. createRareDataIfNecessary();
  764. unsigned size = m_rareData->m_constantBuffers.size();
  765. m_rareData->m_constantBuffers.append(buffer);
  766. return size;
  767. }
  768. Vector_shared<JSValue>& constantBufferAsVector(unsigned index)
  769. {
  770. ASSERT(m_rareData);
  771. return m_rareData->m_constantBuffers[index];
  772. }
  773. JSValue* constantBuffer(unsigned index)
  774. {
  775. return constantBufferAsVector(index).data();
  776. }
  777. JSGlobalObject* globalObject() { return m_globalObject.get(); }
  778. JSGlobalObject* globalObjectFor(CodeOrigin);
  779. // Jump Tables
  780. size_t numberOfImmediateSwitchJumpTables() const { return m_rareData ? m_rareData->m_immediateSwitchJumpTables.size() : 0; }
  781. SimpleJumpTable& addImmediateSwitchJumpTable() { createRareDataIfNecessary(); m_rareData->m_immediateSwitchJumpTables.append(SimpleJumpTable()); return m_rareData->m_immediateSwitchJumpTables.last(); }
  782. SimpleJumpTable& immediateSwitchJumpTable(int tableIndex) { RELEASE_ASSERT(m_rareData); return m_rareData->m_immediateSwitchJumpTables[tableIndex]; }
  783. size_t numberOfCharacterSwitchJumpTables() const { return m_rareData ? m_rareData->m_characterSwitchJumpTables.size() : 0; }
  784. SimpleJumpTable& addCharacterSwitchJumpTable() { createRareDataIfNecessary(); m_rareData->m_characterSwitchJumpTables.append(SimpleJumpTable()); return m_rareData->m_characterSwitchJumpTables.last(); }
  785. SimpleJumpTable& characterSwitchJumpTable(int tableIndex) { RELEASE_ASSERT(m_rareData); return m_rareData->m_characterSwitchJumpTables[tableIndex]; }
  786. size_t numberOfStringSwitchJumpTables() const { return m_rareData ? m_rareData->m_stringSwitchJumpTables.size() : 0; }
  787. StringJumpTable& addStringSwitchJumpTable() { createRareDataIfNecessary(); m_rareData->m_stringSwitchJumpTables.append(StringJumpTable()); return m_rareData->m_stringSwitchJumpTables.last(); }
  788. StringJumpTable& stringSwitchJumpTable(int tableIndex) { RELEASE_ASSERT(m_rareData); return m_rareData->m_stringSwitchJumpTables[tableIndex]; }
  789. SharedSymbolTable* symbolTable() const { return m_unlinkedCode->symbolTable(); }
  790. EvalCodeCache& evalCodeCache() { createRareDataIfNecessary(); return m_rareData->m_evalCodeCache; }
  791. enum ShrinkMode {
  792. // Shrink prior to generating machine code that may point directly into vectors.
  793. EarlyShrink,
  794. // Shrink after generating machine code, and after possibly creating new vectors
  795. // and appending to others. At this time it is not safe to shrink certain vectors
  796. // because we would have generated machine code that references them directly.
  797. LateShrink
  798. };
  799. void shrinkToFit(ShrinkMode);
  800. void copyPostParseDataFrom(CodeBlock* alternative);
  801. void copyPostParseDataFromAlternative();
  802. // Functions for controlling when JITting kicks in, in a mixed mode
  803. // execution world.
  804. bool checkIfJITThresholdReached()
  805. {
  806. return m_llintExecuteCounter.checkIfThresholdCrossedAndSet(this);
  807. }
  808. void dontJITAnytimeSoon()
  809. {
  810. m_llintExecuteCounter.deferIndefinitely();
  811. }
  812. void jitAfterWarmUp()
  813. {
  814. m_llintExecuteCounter.setNewThreshold(Options::thresholdForJITAfterWarmUp(), this);
  815. }
  816. void jitSoon()
  817. {
  818. m_llintExecuteCounter.setNewThreshold(Options::thresholdForJITSoon(), this);
  819. }
  820. const ExecutionCounter& llintExecuteCounter() const
  821. {
  822. return m_llintExecuteCounter;
  823. }
  824. // Functions for controlling when tiered compilation kicks in. This
  825. // controls both when the optimizing compiler is invoked and when OSR
  826. // entry happens. Two triggers exist: the loop trigger and the return
  827. // trigger. In either case, when an addition to m_jitExecuteCounter
  828. // causes it to become non-negative, the optimizing compiler is
  829. // invoked. This includes a fast check to see if this CodeBlock has
  830. // already been optimized (i.e. replacement() returns a CodeBlock
  831. // that was optimized with a higher tier JIT than this one). In the
  832. // case of the loop trigger, if the optimized compilation succeeds
  833. // (or has already succeeded in the past) then OSR is attempted to
  834. // redirect program flow into the optimized code.
  835. // These functions are called from within the optimization triggers,
  836. // and are used as a single point at which we define the heuristics
  837. // for how much warm-up is mandated before the next optimization
  838. // trigger files. All CodeBlocks start out with optimizeAfterWarmUp(),
  839. // as this is called from the CodeBlock constructor.
  840. // When we observe a lot of speculation failures, we trigger a
  841. // reoptimization. But each time, we increase the optimization trigger
  842. // to avoid thrashing.
  843. unsigned reoptimizationRetryCounter() const;
  844. void countReoptimization();
  845. int32_t codeTypeThresholdMultiplier() const;
  846. int32_t counterValueForOptimizeAfterWarmUp();
  847. int32_t counterValueForOptimizeAfterLongWarmUp();
  848. int32_t counterValueForOptimizeSoon();
  849. int32_t* addressOfJITExecuteCounter()
  850. {
  851. return &m_jitExecuteCounter.m_counter;
  852. }
  853. static ptrdiff_t offsetOfJITExecuteCounter() { return OBJECT_OFFSETOF(CodeBlock, m_jitExecuteCounter) + OBJECT_OFFSETOF(ExecutionCounter, m_counter); }
  854. static ptrdiff_t offsetOfJITExecutionActiveThreshold() { return OBJECT_OFFSETOF(CodeBlock, m_jitExecuteCounter) + OBJECT_OFFSETOF(ExecutionCounter, m_activeThreshold); }
  855. static ptrdiff_t offsetOfJITExecutionTotalCount() { return OBJECT_OFFSETOF(CodeBlock, m_jitExecuteCounter) + OBJECT_OFFSETOF(ExecutionCounter, m_totalCount); }
  856. const ExecutionCounter& jitExecuteCounter() const { return m_jitExecuteCounter; }
  857. unsigned optimizationDelayCounter() const { return m_optimizationDelayCounter; }
  858. // Check if the optimization threshold has been reached, and if not,
  859. // adjust the heuristics accordingly. Returns true if the threshold has
  860. // been reached.
  861. bool checkIfOptimizationThresholdReached();
  862. // Call this to force the next optimization trigger to fire. This is
  863. // rarely wise, since optimization triggers are typically more
  864. // expensive than executing baseline code.
  865. void optimizeNextInvocation();
  866. // Call this to prevent optimization from happening again. Note that
  867. // optimization will still happen after roughly 2^29 invocations,
  868. // so this is really meant to delay that as much as possible. This
  869. // is called if optimization failed, and we expect it to fail in
  870. // the future as well.
  871. void dontOptimizeAnytimeSoon();
  872. // Call this to reinitialize the counter to its starting state,
  873. // forcing a warm-up to happen before the next optimization trigger
  874. // fires. This is called in the CodeBlock constructor. It also
  875. // makes sense to call this if an OSR exit occurred. Note that
  876. // OSR exit code is code generated, so the value of the execute
  877. // counter that this corresponds to is also available directly.
  878. void optimizeAfterWarmUp();
  879. // Call this to force an optimization trigger to fire only after
  880. // a lot of warm-up.
  881. void optimizeAfterLongWarmUp();
  882. // Call this to cause an optimization trigger to fire soon, but
  883. // not necessarily the next one. This makes sense if optimization
  884. // succeeds. Successfuly optimization means that all calls are
  885. // relinked to the optimized code, so this only affects call
  886. // frames that are still executing this CodeBlock. The value here
  887. // is tuned to strike a balance between the cost of OSR entry
  888. // (which is too high to warrant making every loop back edge to
  889. // trigger OSR immediately) and the cost of executing baseline
  890. // code (which is high enough that we don't necessarily want to
  891. // have a full warm-up). The intuition for calling this instead of
  892. // optimizeNextInvocation() is for the case of recursive functions
  893. // with loops. Consider that there may be N call frames of some
  894. // recursive function, for a reasonably large value of N. The top
  895. // one triggers optimization, and then returns, and then all of
  896. // the others return. We don't want optimization to be triggered on
  897. // each return, as that would be superfluous. It only makes sense
  898. // to trigger optimization if one of those functions becomes hot
  899. // in the baseline code.
  900. void optimizeSoon();
  901. uint32_t osrExitCounter() const { return m_osrExitCounter; }
  902. void countOSRExit() { m_osrExitCounter++; }
  903. uint32_t* addressOfOSRExitCounter() { return &m_osrExitCounter; }
  904. static ptrdiff_t offsetOfOSRExitCounter() { return OBJECT_OFFSETOF(CodeBlock, m_osrExitCounter); }
  905. #if ENABLE(JIT)
  906. uint32_t adjustedExitCountThreshold(uint32_t desiredThreshold);
  907. uint32_t exitCountThresholdForReoptimization();
  908. uint32_t exitCountThresholdForReoptimizationFromLoop();
  909. bool shouldReoptimizeNow();
  910. bool shouldReoptimizeFromLoopNow();
  911. #endif
  912. #if ENABLE(VALUE_PROFILER)
  913. bool shouldOptimizeNow();
  914. void updateAllValueProfilePredictions(OperationInProgress = NoOperation);
  915. void updateAllArrayPredictions(OperationInProgress = NoOperation);
  916. void updateAllPredictions(OperationInProgress = NoOperation);
  917. #else
  918. bool shouldOptimizeNow() { return false; }
  919. void updateAllValueProfilePredictions(OperationInProgress = NoOperation) { }
  920. void updateAllArrayPredictions(OperationInProgress = NoOperation) { }
  921. void updateAllPredictions(OperationInProgress = NoOperation) { }
  922. #endif
  923. #if ENABLE(JIT)
  924. void reoptimize();
  925. #endif
  926. #if ENABLE(VERBOSE_VALUE_PROFILE)
  927. void dumpValueProfiles();
  928. #endif
  929. // FIXME: Make these remaining members private.
  930. int m_numCalleeRegisters;
  931. int m_numVars;
  932. bool m_isConstructor;
  933. protected:
  934. #if ENABLE(JIT)
  935. virtual bool jitCompileImpl(ExecState*) = 0;
  936. virtual void jettisonImpl() = 0;
  937. #endif
  938. virtual void visitWeakReferences(SlotVisitor&);
  939. virtual void finalizeUnconditionally();
  940. #if ENABLE(DFG_JIT)
  941. void tallyFrequentExitSites();
  942. #else
  943. void tallyFrequentExitSites() { }
  944. #endif
  945. private:
  946. friend class DFGCodeBlocks;
  947. double optimizationThresholdScalingFactor();
  948. #if ENABLE(JIT)
  949. ClosureCallStubRoutine* findClosureCallForReturnPC(ReturnAddressPtr);
  950. #endif
  951. #if ENABLE(VALUE_PROFILER)
  952. void updateAllPredictionsAndCountLiveness(OperationInProgress, unsigned& numberOfLiveNonArgumentValueProfiles, unsigned& numberOfSamplesInProfiles);
  953. #endif
  954. void setIdentifiers(const Vector_shared<Identifier>& identifiers)
  955. {
  956. RELEASE_ASSERT(m_identifiers.isEmpty());
  957. m_identifiers.appendVector(identifiers);
  958. }
  959. void setConstantRegisters(const Vector<WriteBarrier<Unknown> >& constants)
  960. {
  961. size_t count = constants.size();
  962. m_constantRegisters.resize(count);
  963. for (size_t i = 0; i < count; i++)
  964. m_constantRegisters[i].set(*m_vm, ownerExecutable(), constants[i].get());
  965. }
  966. void dumpBytecode(PrintStream&, ExecState*, const Instruction* begin, const Instruction*&);
  967. CString registerName(ExecState*, int r) const;
  968. void printUnaryOp(PrintStream&, ExecState*, int location, const Instruction*&, const char* op);
  969. void printBinaryOp(PrintStream&, ExecState*, int location, const Instruction*&, const char* op);
  970. void printConditionalJump(PrintStream&, ExecState*, const Instruction*, const Instruction*&, int location, const char* op);
  971. void printGetByIdOp(PrintStream&, ExecState*, int location, const Instruction*&);
  972. void printGetByIdCacheStatus(PrintStream&, ExecState*, int location);
  973. enum CacheDumpMode { DumpCaches, DontDumpCaches };
  974. void printCallOp(PrintStream&, ExecState*, int location, const Instruction*&, const char* op, CacheDumpMode);
  975. void printPutByIdOp(PrintStream&, ExecState*, int location, const Instruction*&, const char* op);
  976. void beginDumpProfiling(PrintStream&, bool& hasPrintedProfiling);
  977. void dumpValueProfiling(PrintStream&, const Instruction*&, bool& hasPrintedProfiling);
  978. void dumpArrayProfiling(PrintStream&, const Instruction*&, bool& hasPrintedProfiling);
  979. #if ENABLE(VALUE_PROFILER)
  980. void dumpRareCaseProfile(PrintStream&, const char* name, RareCaseProfile*, bool& hasPrintedProfiling);
  981. #endif
  982. void visitStructures(SlotVisitor&, Instruction* vPC);
  983. #if ENABLE(DFG_JIT)
  984. bool shouldImmediatelyAssumeLivenessDuringScan()
  985. {
  986. // Null m_dfgData means that this is a baseline JIT CodeBlock. Baseline JIT
  987. // CodeBlocks don't need to be jettisoned when their weak references go
  988. // stale. So if a basline JIT CodeBlock gets scanned, we can assume that
  989. // this means that it's live.
  990. if (!m_dfgData)
  991. return true;
  992. // For simplicity, we don't attempt to jettison code blocks during GC if
  993. // they are executing. Instead we strongly mark their weak references to
  994. // allow them to continue to execute soundly.
  995. if (m_dfgData->mayBeExecuting)
  996. return true;
  997. if (Options::forceDFGCodeBlockLiveness())
  998. return true;
  999. return false;
  1000. }
  1001. #else
  1002. bool shouldImmediatelyAssumeLivenessDuringScan() { return true; }
  1003. #endif
  1004. void performTracingFixpointIteration(SlotVisitor&);
  1005. void stronglyVisitStrongReferences(SlotVisitor&);
  1006. void stronglyVisitWeakReferences(SlotVisitor&);
  1007. void createRareDataIfNecessary()
  1008. {
  1009. if (!m_rareData)
  1010. m_rareData = adoptPtr(new RareData);
  1011. }
  1012. #if ENABLE(JIT)
  1013. void resetStubInternal(RepatchBuffer&, StructureStubInfo&);
  1014. void resetStubDuringGCInternal(RepatchBuffer&, StructureStubInfo&);
  1015. #endif
  1016. WriteBarrier<UnlinkedCodeBlock> m_unlinkedCode;
  1017. int m_numParameters;
  1018. WriteBarrier<ScriptExecutable> m_ownerExecutable;
  1019. VM* m_vm;
  1020. RefCountedArray_shared<Instruction> m_instructions;
  1021. int m_thisRegister;
  1022. int m_argumentsRegister;
  1023. int m_activationRegister;
  1024. bool m_isStrictMode;
  1025. bool m_needsActivation;
  1026. RefPtr<SourceProvider> m_source;
  1027. unsigned m_sourceOffset;
  1028. unsigned m_firstLineColumnOffset;
  1029. unsigned m_codeType;
  1030. #if ENABLE(LLINT)
  1031. SegmentedVector_shared<LLIntCallLinkInfo, 8> m_llintCallLinkInfos;
  1032. SentinelLinkedList<LLIntCallLinkInfo, BasicRawSentinelNode<LLIntCallLinkInfo> > m_incomingLLIntCalls;
  1033. #endif
  1034. #if ENABLE(JIT)
  1035. Vector_shared<StructureStubInfo> m_structureStubInfos;
  1036. Vector_shared<ByValInfo> m_byValInfos;
  1037. Vector_shared<CallLinkInfo> m_callLinkInfos;
  1038. JITCode m_jitCode;
  1039. MacroAssemblerCodePtr m_jitCodeWithArityCheck;
  1040. SentinelLinkedList<CallLinkInfo, BasicRawSentinelNode<CallLinkInfo> > m_incomingCalls;
  1041. #endif
  1042. #if ENABLE(DFG_JIT) || ENABLE(LLINT)
  1043. OwnPtr<CompactJITCodeMap> m_jitCodeMap;
  1044. #endif
  1045. #if ENABLE(DFG_JIT)
  1046. struct WeakReferenceTransition {
  1047. WeakReferenceTransition() { }
  1048. WeakReferenceTransition(VM& vm, JSCell* owner, JSCell* codeOrigin, JSCell* from, JSCell* to)
  1049. : m_from(vm, owner, from)
  1050. , m_to(vm, owner, to)
  1051. {
  1052. if (!!codeOrigin)
  1053. m_codeOrigin.set(vm, owner, codeOrigin);
  1054. }
  1055. WriteBarrier<JSCell> m_codeOrigin;
  1056. WriteBarrier<JSCell> m_from;
  1057. WriteBarrier<JSCell> m_to;
  1058. };
  1059. struct DFGData {
  1060. DFGData()
  1061. : mayBeExecuting(false)
  1062. , isJettisoned(false)
  1063. {
  1064. }
  1065. Vector_shared<DFG::OSREntryData> osrEntry;
  1066. SegmentedVector_shared<DFG::OSRExit, 8> osrExit;
  1067. Vector_shared<DFG::SpeculationRecovery> speculationRecovery;
  1068. SegmentedVector_shared<JumpReplacementWatchpoint, 1, 0> watchpoints;
  1069. Vector_shared<WeakReferenceTransition> transitions;
  1070. Vector_shared<WriteBarrier<JSCell> > weakReferences;
  1071. DFG::VariableEventStream variableEventStream;
  1072. DFG::MinifiedGraph minifiedDFG;
  1073. #if !ENABLE(DETACHED_JIT)
  1074. RefPtr<Profiler::Compilation> compilation;
  1075. #endif
  1076. bool mayBeExecuting;
  1077. bool isJettisoned;
  1078. bool livenessHasBeenProved; // Initialized and used on every GC.
  1079. bool allTransitionsHaveBeenMarked; // Initialized and used on every GC.
  1080. unsigned visitAggregateHasBeenCalled; // Unsigned to make it work seamlessly with the broadest set of CAS implementations.
  1081. #if ENABLE(DETACHED_JIT)
  1082. DETACHED_JIT_MAKE_SHARED_DATA_ALLOCATED;
  1083. #endif
  1084. };
  1085. OwnPtr<DFGData> m_dfgData;
  1086. // This is relevant to non-DFG code blocks that serve as the profiled code block
  1087. // for DFG code blocks.
  1088. DFG::ExitProfile m_exitProfile;
  1089. CompressedLazyOperandValueProfileHolder m_lazyOperandValueProfiles;
  1090. #endif
  1091. #if ENABLE(VALUE_PROFILER)
  1092. Vector_shared<ValueProfile> m_argumentValueProfiles;
  1093. SegmentedVector_shared<ValueProfile, 8> m_valueProfiles;
  1094. SegmentedVector_shared<RareCaseProfile, 8> m_rareCaseProfiles;
  1095. SegmentedVector_shared<RareCaseProfile, 8> m_specialFastCaseProfiles;
  1096. SegmentedVector_shared<ArrayAllocationProfile, 8> m_arrayAllocationProfiles;
  1097. ArrayProfileVector m_arrayProfiles;
  1098. #endif
  1099. SegmentedVector_shared<ObjectAllocationProfile, 8> m_objectAllocationProfiles;
  1100. // Constant Pool
  1101. Vector_shared<Identifier> m_identifiers;
  1102. COMPILE_ASSERT(sizeof(Register) == sizeof(WriteBarrier<Unknown>), Register_must_be_same_size_as_WriteBarrier_Unknown);
  1103. // TODO: This could just be a pointer to m_unlinkedCodeBlock's data, but the DFG mutates
  1104. // it, so we're stuck with it for now.
  1105. Vector_shared<WriteBarrier<Unknown> > m_constantRegisters;
  1106. Vector_shared<WriteBarrier<FunctionExecutable> > m_functionDecls;
  1107. Vector_shared<WriteBarrier<FunctionExecutable> > m_functionExprs;
  1108. OwnPtr<CodeBlock> m_alternative;
  1109. ExecutionCounter m_llintExecuteCounter;
  1110. ExecutionCounter m_jitExecuteCounter;
  1111. int32_t m_totalJITExecutions;
  1112. uint32_t m_osrExitCounter;
  1113. uint16_t m_optimizationDelayCounter;
  1114. uint16_t m_reoptimizationRetryCounter;
  1115. Vector_shared<ResolveOperations> m_resolveOperations;
  1116. Vector_shared<PutToBaseOperation, 1> m_putToBaseOperations;
  1117. struct RareData {
  1118. #if ENABLE(JIT) && ENABLE(DETACHED_JIT)
  1119. DETACHED_JIT_MAKE_SHARED_DATA_ALLOCATED;
  1120. #else
  1121. WTF_MAKE_FAST_ALLOCATED;
  1122. #endif
  1123. public:
  1124. Vector_shared<HandlerInfo> m_exceptionHandlers;
  1125. // Buffers used for large array literals
  1126. Vector_shared<Vector_shared<JSValue> > m_constantBuffers;
  1127. // Jump Tables
  1128. Vector_shared<SimpleJumpTable> m_immediateSwitchJumpTables;
  1129. Vector_shared<SimpleJumpTable> m_characterSwitchJumpTables;
  1130. Vector_shared<StringJumpTable> m_stringSwitchJumpTables;
  1131. EvalCodeCache m_evalCodeCache;
  1132. #if ENABLE(JIT)
  1133. Vector_shared<CallReturnOffsetToBytecodeOffset, 0, UnsafeVectorOverflow> m_callReturnIndexVector;
  1134. #endif
  1135. #if ENABLE(DFG_JIT)
  1136. SegmentedVector_shared<InlineCallFrame, 4> m_inlineCallFrames;
  1137. Vector_shared<CodeOriginAtCallReturnOffset, 0, UnsafeVectorOverflow> m_codeOrigins;
  1138. #endif
  1139. };
  1140. #if COMPILER(MSVC)
  1141. friend void WTF::deleteOwnedPtr<RareData>(RareData*);
  1142. #endif
  1143. OwnPtr<RareData> m_rareData;
  1144. #if ENABLE(JIT)
  1145. DFG::CapabilityLevel m_canCompileWithDFGState;
  1146. #endif
  1147. #if ENABLE(DETACHED_JIT)
  1148. private:
  1149. CodeBlockType m_type;
  1150. #endif
  1151. };
  1152. // Program code is not marked by any function, so we make the global object
  1153. // responsible for marking it.
  1154. class GlobalCodeBlock : public CodeBlock {
  1155. protected:
  1156. #if ENABLE(DETACHED_JIT)
  1157. enum GlobalCodeBlockType {
  1158. GlobalCodeBlockEval,
  1159. GlobalCodeBlockProgram
  1160. };
  1161. GlobalCodeBlock(CopyParsedBlockTag, GlobalCodeBlock& other, GlobalCodeBlockType type)
  1162. : CodeBlock(CopyParsedBlock, other, CodeBlock::CodeBlockGlobal)
  1163. , m_type(type)
  1164. {
  1165. }
  1166. GlobalCodeBlock(ScriptExecutable* ownerExecutable, UnlinkedCodeBlock* unlinkedCodeBlock, JSGlobalObject* globalObject, unsigned baseScopeDepth, PassRefPtr<SourceProvider> sourceProvider, unsigned sourceOffset, unsigned firstLineColumnOffset, PassOwnPtr<CodeBlock> alternative, GlobalCodeBlockType type)
  1167. : CodeBlock(ownerExecutable, unlinkedCodeBlock, globalObject, baseScopeDepth, sourceProvider, sourceOffset, firstLineColumnOffset, alternative, CodeBlock::CodeBlockGlobal)
  1168. , m_type(type)
  1169. {
  1170. }
  1171. #else
  1172. GlobalCodeBlock(CopyParsedBlockTag, GlobalCodeBlock& other)
  1173. : CodeBlock(CopyParsedBlock, other)
  1174. {
  1175. }
  1176. GlobalCodeBlock(ScriptExecutable* ownerExecutable, UnlinkedCodeBlock* unlinkedCodeBlock, JSGlobalObject* globalObject, unsigned baseScopeDepth, PassRefPtr<SourceProvider> sourceProvider, unsigned sourceOffset, unsigned firstLineColumnOffset, PassOwnPtr<CodeBlock> alternative)
  1177. : CodeBlock(ownerExecutable, unlinkedCodeBlock, globalObject, baseScopeDepth, sourceProvider, sourceOffset, firstLineColumnOffset, alternative)
  1178. {
  1179. }
  1180. #endif
  1181. #if ENABLE(DETACHED_JIT)
  1182. JS_EXPORT_PRIVATE DETACHED_JIT_VIRTUAL_DTOR ~GlobalCodeBlock() {}
  1183. #endif
  1184. private:
  1185. #if ENABLE(DETACHED_JIT)
  1186. friend CodeBlock * CodeBlock::replacement();
  1187. CodeBlock * replacement();
  1188. GlobalCodeBlockType m_type;
  1189. #endif
  1190. };
  1191. class ProgramCodeBlock : public GlobalCodeBlock {
  1192. #if ENABLE(DETACHED_JIT)
  1193. friend class GlobalCodeBlock;
  1194. #endif
  1195. public:
  1196. ProgramCodeBlock(CopyParsedBlockTag, ProgramCodeBlock& other)
  1197. : GlobalCodeBlock(CopyParsedBlock, other
  1198. #if ENABLE(DETACHED_JIT)
  1199. , GlobalCodeBlock::GlobalCodeBlockProgram
  1200. #endif
  1201. )
  1202. {
  1203. }
  1204. ProgramCodeBlock(ProgramExecutable* ownerExecutable, UnlinkedProgramCodeBlock* unlinkedCodeBlock, JSGlobalObject* globalObject, PassRefPtr<SourceProvider> sourceProvider, unsigned firstLineColumnOffset, PassOwnPtr<CodeBlock> alternative)
  1205. : GlobalCodeBlock(ownerExecutable, unlinkedCodeBlock, globalObject, 0, sourceProvider, 0, firstLineColumnOffset, alternative
  1206. #if ENABLE(DETACHED_JIT)
  1207. , GlobalCodeBlock::GlobalCodeBlockProgram
  1208. #endif
  1209. )
  1210. {
  1211. }
  1212. #if ENABLE(JIT)
  1213. protected:
  1214. virtual JSObject* compileOptimized(ExecState*, JSScope*, unsigned bytecodeIndex);
  1215. virtual void jettisonImpl();
  1216. virtual bool jitCompileImpl(ExecState*);
  1217. DETACHED_JIT_VIRTUAL CodeBlock* replacement();
  1218. virtual DFG::CapabilityLevel canCompileWithDFGInternal();
  1219. #endif
  1220. };
  1221. class EvalCodeBlock : public GlobalCodeBlock {
  1222. #if ENABLE(DETACHED_JIT)
  1223. friend class GlobalCodeBlock;
  1224. #endif
  1225. public:
  1226. EvalCodeBlock(CopyParsedBlockTag, EvalCodeBlock& other)
  1227. : GlobalCodeBlock(CopyParsedBlock, other
  1228. #if ENABLE(DETACHED_JIT)
  1229. , GlobalCodeBlock::GlobalCodeBlockEval
  1230. #endif
  1231. )
  1232. {
  1233. }
  1234. EvalCodeBlock(EvalExecutable* ownerExecutable, UnlinkedEvalCodeBlock* unlinkedCodeBlock, JSGlobalObject* globalObject, PassRefPtr<SourceProvider> sourceProvider, int baseScopeDepth, PassOwnPtr<CodeBlock> alternative)
  1235. : GlobalCodeBlock(ownerExecutable, unlinkedCodeBlock, globalObject, baseScopeDepth, sourceProvider, 0, 1, alternative
  1236. #if ENABLE(DETACHED_JIT)
  1237. , GlobalCodeBlock::GlobalCodeBlockEval
  1238. #endif
  1239. )
  1240. {
  1241. }
  1242. const Identifier& variable(unsigned index) { return unlinkedEvalCodeBlock()->variable(index); }
  1243. unsigned numVariables() { return unlinkedEvalCodeBlock()->numVariables(); }
  1244. #if ENABLE(JIT)
  1245. protected:
  1246. virtual JSObject* compileOptimized(ExecState*, JSScope*, unsigned bytecodeIndex);
  1247. virtual void jettisonImpl();
  1248. virtual bool jitCompileImpl(ExecState*);
  1249. DETACHED_JIT_VIRTUAL CodeBlock* replacement();
  1250. virtual DFG::CapabilityLevel canCompileWithDFGInternal();
  1251. #endif
  1252. private:
  1253. UnlinkedEvalCodeBlock* unlinkedEvalCodeBlock() const { return jsCast<UnlinkedEvalCodeBlock*>(unlinkedCodeBlock()); }
  1254. };
  1255. class FunctionCodeBlock : public CodeBlock {
  1256. #if ENABLE(DETACHED_JIT)
  1257. friend CodeBlock * CodeBlock::replacement();
  1258. #endif
  1259. public:
  1260. FunctionCodeBlock(CopyParsedBlockTag, FunctionCodeBlock& other)
  1261. : CodeBlock(CopyParsedBlock, other
  1262. #if ENABLE(DETACHED_JIT)
  1263. , CodeBlock::CodeBlockFunction
  1264. #endif
  1265. )
  1266. {
  1267. }
  1268. FunctionCodeBlock(FunctionExecutable* ownerExecutable, UnlinkedFunctionCodeBlock* unlinkedCodeBlock, JSGlobalObject* globalObject, PassRefPtr<SourceProvider> sourceProvider, unsigned sourceOffset, unsigned firstLineColumnOffset, PassOwnPtr<CodeBlock> alternative = nullptr)
  1269. : CodeBlock(ownerExecutable, unlinkedCodeBlock, globalObject, 0, sourceProvider, sourceOffset, firstLineColumnOffset, alternative
  1270. #if ENABLE(DETACHED_JIT)
  1271. , CodeBlock::CodeBlockFunction
  1272. #endif
  1273. )
  1274. {
  1275. }
  1276. #if ENABLE(DETACHED_JIT)
  1277. JS_EXPORT_PRIVATE DETACHED_JIT_VIRTUAL_DTOR ~FunctionCodeBlock() {}
  1278. #endif
  1279. #if ENABLE(JIT)
  1280. protected:
  1281. virtual JSObject* compileOptimized(ExecState*, JSScope*, unsigned bytecodeIndex);
  1282. virtual void jettisonImpl();
  1283. virtual bool jitCompileImpl(ExecState*);
  1284. DETACHED_JIT_VIRTUAL CodeBlock* replacement();
  1285. virtual DFG::CapabilityLevel canCompileWithDFGInternal();
  1286. #endif
  1287. };
  1288. inline CodeBlock* baselineCodeBlockForInlineCallFrame(InlineCallFrame* inlineCallFrame)
  1289. {
  1290. DEFINE_STATIC_sFunctionExecutableClassInfo;
  1291. RELEASE_ASSERT(inlineCallFrame);
  1292. ExecutableBase* executable = inlineCallFrame->executable.get();
  1293. RELEASE_ASSERT(executable->structure()->classInfo() == sFunctionExecutableClassInfo);
  1294. return static_cast<FunctionExecutable*>(executable)->baselineCodeBlockFor(inlineCallFrame->isCall ? CodeForCall : CodeForConstruct);
  1295. }
  1296. inline CodeBlock* baselineCodeBlockForOriginAndBaselineCodeBlock(const CodeOrigin& codeOrigin, CodeBlock* baselineCodeBlock)
  1297. {
  1298. if (codeOrigin.inlineCallFrame)
  1299. return baselineCodeBlockForInlineCallFrame(codeOrigin.inlineCallFrame);
  1300. return baselineCodeBlock;
  1301. }
  1302. inline int CodeBlock::argumentIndexAfterCapture(size_t argument)
  1303. {
  1304. if (argument >= static_cast<size_t>(symbolTable()->parameterCount()))
  1305. return CallFrame::argumentOffset(argument);
  1306. const SlowArgument* slowArguments = symbolTable()->slowArguments();
  1307. if (!slowArguments || slowArguments[argument].status == SlowArgument::Normal)
  1308. return CallFrame::argumentOffset(argument);
  1309. ASSERT(slowArguments[argument].status == SlowArgument::Captured);
  1310. return slowArguments[argument].index;
  1311. }
  1312. inline Register& ExecState::r(int index)
  1313. {
  1314. CodeBlock* codeBlock = this->codeBlock();
  1315. if (codeBlock->isConstantRegisterIndex(index))
  1316. return *reinterpret_cast<Register*>(&codeBlock->constantRegister(index));
  1317. return this[index];
  1318. }
  1319. inline Register& ExecState::uncheckedR(int index)
  1320. {
  1321. RELEASE_ASSERT(index < FirstConstantRegisterIndex);
  1322. return this[index];
  1323. }
  1324. #if ENABLE(DFG_JIT)
  1325. inline bool ExecState::isInlineCallFrame()
  1326. {
  1327. if (LIKELY(!codeBlock() || codeBlock()->getJITType() != JITCode::DFGJIT))
  1328. return false;
  1329. return isInlineCallFrameSlow();
  1330. }
  1331. #endif
  1332. inline JSValue ExecState::argumentAfterCapture(size_t argument)
  1333. {
  1334. if (argument >= argumentCount())
  1335. return jsUndefined();
  1336. if (!codeBlock())
  1337. return this[argumentOffset(argument)].jsValue();
  1338. return this[codeBlock()->argumentIndexAfterCapture(argument)].jsValue();
  1339. }
  1340. #if ENABLE(DFG_JIT)
  1341. inline void DFGCodeBlocks::mark(void* candidateCodeBlock)
  1342. {
  1343. // We have to check for 0 and -1 because those are used by the HashMap as markers.
  1344. uintptr_t value = reinterpret_cast<uintptr_t>(candidateCodeBlock);
  1345. // This checks for both of those nasty cases in one go.
  1346. // 0 + 1 = 1
  1347. // -1 + 1 = 0
  1348. if (value + 1 <= 1)
  1349. return;
  1350. HashSet<CodeBlock*>::iterator iter = m_set.find(static_cast<CodeBlock*>(candidateCodeBlock));
  1351. if (iter == m_set.end())
  1352. return;
  1353. (*iter)->m_dfgData->mayBeExecuting = true;
  1354. }
  1355. #endif
  1356. } // namespace JSC
  1357. #if ENABLE(DETACHED_JIT)
  1358. namespace WTF {
  1359. template <> inline void deleteOwnedPtr<JSC::CodeBlock>(JSC::CodeBlock * ptr)
  1360. {
  1361. if (ptr)
  1362. DETACHED_JIT_VIRTUAL_DELETE(ptr);
  1363. }
  1364. template <> inline void deleteOwnedPtr<JSC::FunctionCodeBlock>(JSC::FunctionCodeBlock * ptr)
  1365. {
  1366. if (ptr)
  1367. DETACHED_JIT_VIRTUAL_DELETE(ptr);
  1368. }
  1369. template <> inline void deleteOwnedPtr<JSC::GlobalCodeBlock>(JSC::GlobalCodeBlock * ptr)
  1370. {
  1371. if (ptr)
  1372. DETACHED_JIT_VIRTUAL_DELETE(ptr);
  1373. }
  1374. }
  1375. #endif
  1376. #endif // CodeBlock_h