2 * Copyright (C) 2008, 2009, 2010 Apple Inc. All rights reserved.
3 * Copyright (C) 2008 Cameron Zwarich <cwzwarich@uwaterloo.ca>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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.
33 #include "EvalCodeCache.h"
34 #include "Instruction.h"
36 #include "JSGlobalObject.h"
37 #include "JumpTable.h"
41 #include <wtf/FastAllocBase.h>
42 #include <wtf/PassOwnPtr.h>
43 #include <wtf/RefPtr.h>
44 #include <wtf/Vector.h>
47 #include "StructureStubInfo.h"
50 // Register numbers used in bytecode operations have different meaning according to their ranges:
51 // 0x80000000-0xFFFFFFFF Negative indices from the CallFrame pointer are entries in the call frame, see RegisterFile.h.
52 // 0x00000000-0x3FFFFFFF Forwards indices from the CallFrame pointer are local vars and temporaries with the function's callframe.
53 // 0x40000000-0x7FFFFFFF Positive indices from 0x40000000 specify entries in the constant pool on the CodeBlock.
54 static const int FirstConstantRegisterIndex = 0x40000000;
58 enum HasSeenShouldRepatch {
64 enum CodeType { GlobalCode, EvalCode, FunctionCode };
66 inline int unmodifiedArgumentsRegister(int argumentsRegister) { return argumentsRegister - 1; }
68 static ALWAYS_INLINE int missingThisObjectMarker() { return std::numeric_limits<int>::max(); }
76 CodeLocationLabel nativeCode;
80 struct ExpressionRangeInfo {
82 MaxOffset = (1 << 7) - 1,
83 MaxDivot = (1 << 25) - 1
85 uint32_t instructionOffset : 25;
86 uint32_t divotPoint : 25;
87 uint32_t startOffset : 7;
88 uint32_t endOffset : 7;
92 uint32_t instructionOffset;
101 , hasSeenShouldRepatch(0)
105 CodeLocationNearCall callReturnLocation;
106 CodeLocationDataLabelPtr hotPathBegin;
107 CodeLocationNearCall hotPathOther;
108 CodeBlock* ownerCodeBlock;
110 unsigned position : 31;
111 unsigned hasSeenShouldRepatch : 1;
113 void setUnlinked() { callee = 0; }
114 bool isLinked() { return callee; }
118 return hasSeenShouldRepatch;
123 hasSeenShouldRepatch = true;
127 struct MethodCallLinkInfo {
130 , cachedPrototypeStructure(0)
136 ASSERT(!cachedStructure);
137 return cachedPrototypeStructure;
142 ASSERT(!cachedStructure && !cachedPrototypeStructure);
143 // We use the values of cachedStructure & cachedPrototypeStructure to indicate the
145 // - In the initial state, both are null.
146 // - Once this transition has been taken once, cachedStructure is
147 // null and cachedPrototypeStructure is set to a nun-null value.
148 // - Once the call is linked both structures are set to non-null values.
149 cachedPrototypeStructure = (Structure*)1;
152 CodeLocationCall callReturnLocation;
153 CodeLocationDataLabelPtr structureLabel;
154 Structure* cachedStructure;
155 Structure* cachedPrototypeStructure;
158 struct GlobalResolveInfo {
159 GlobalResolveInfo(unsigned bytecodeOffset)
162 , bytecodeOffset(bytecodeOffset)
166 Structure* structure;
168 unsigned bytecodeOffset;
171 // This structure is used to map from a call return location
172 // (given as an offset in bytes into the JIT code) back to
173 // the bytecode index of the corresponding bytecode operation.
174 // This is then used to look up the corresponding handler.
175 struct CallReturnOffsetToBytecodeOffset {
176 CallReturnOffsetToBytecodeOffset(unsigned callReturnOffset, unsigned bytecodeOffset)
177 : callReturnOffset(callReturnOffset)
178 , bytecodeOffset(bytecodeOffset)
182 unsigned callReturnOffset;
183 unsigned bytecodeOffset;
186 // valueAtPosition helpers for the binaryChop algorithm below.
188 inline void* getStructureStubInfoReturnLocation(StructureStubInfo* structureStubInfo)
190 return structureStubInfo->callReturnLocation.executableAddress();
193 inline void* getCallLinkInfoReturnLocation(CallLinkInfo* callLinkInfo)
195 return callLinkInfo->callReturnLocation.executableAddress();
198 inline void* getMethodCallLinkInfoReturnLocation(MethodCallLinkInfo* methodCallLinkInfo)
200 return methodCallLinkInfo->callReturnLocation.executableAddress();
203 inline unsigned getCallReturnOffset(CallReturnOffsetToBytecodeOffset* pc)
205 return pc->callReturnOffset;
208 // Binary chop algorithm, calls valueAtPosition on pre-sorted elements in array,
209 // compares result with key (KeyTypes should be comparable with '--', '<', '>').
210 // Optimized for cases where the array contains the key, checked by assertions.
211 template<typename ArrayType, typename KeyType, KeyType(*valueAtPosition)(ArrayType*)>
212 inline ArrayType* binaryChop(ArrayType* array, size_t size, KeyType key)
214 // The array must contain at least one element (pre-condition, array does conatin key).
215 // If the array only contains one element, no need to do the comparison.
217 // Pick an element to check, half way through the array, and read the value.
218 int pos = (size - 1) >> 1;
219 KeyType val = valueAtPosition(&array[pos]);
221 // If the key matches, success!
224 // The item we are looking for is smaller than the item being check; reduce the value of 'size',
225 // chopping off the right hand half of the array.
228 // Discard all values in the left hand half of the array, up to and including the item at pos.
234 // 'size' should never reach zero.
238 // If we reach this point we've chopped down to one element, no need to check it matches
240 ASSERT(key == valueAtPosition(&array[0]));
246 WTF_MAKE_FAST_ALLOCATED;
249 CodeBlock(ScriptExecutable* ownerExecutable, CodeType, JSGlobalObject*, PassRefPtr<SourceProvider>, unsigned sourceOffset, SymbolTable* symbolTable, bool isConstructor);
251 DeprecatedPtr<JSGlobalObject> m_globalObject;
255 virtual ~CodeBlock();
257 void markAggregate(MarkStack&);
258 void refStructures(Instruction* vPC) const;
259 void derefStructures(Instruction* vPC) const;
260 #if ENABLE(JIT_OPTIMIZE_CALL)
261 void unlinkCallers();
264 static void dumpStatistics();
266 #if !defined(NDEBUG) || ENABLE_OPCODE_SAMPLING
267 void dump(ExecState*) const;
268 void printStructures(const Instruction*) const;
269 void printStructure(const char* name, const Instruction*, int operand) const;
272 bool isStrictMode() const { return m_isStrictMode; }
274 inline bool isKnownNotImmediate(int index)
276 if (index == m_thisRegister && !m_isStrictMode)
279 if (isConstantRegisterIndex(index))
280 return getConstant(index).isCell();
285 ALWAYS_INLINE bool isTemporaryRegisterIndex(int index)
287 return index >= m_numVars;
290 HandlerInfo* handlerForBytecodeOffset(unsigned bytecodeOffset);
291 int lineNumberForBytecodeOffset(unsigned bytecodeOffset);
292 void expressionRangeForBytecodeOffset(unsigned bytecodeOffset, int& divot, int& startOffset, int& endOffset);
295 void addCaller(CallLinkInfo* caller)
297 caller->callee = this;
298 caller->position = m_linkedCallerList.size();
299 m_linkedCallerList.append(caller);
302 void removeCaller(CallLinkInfo* caller)
304 unsigned pos = caller->position;
305 unsigned lastPos = m_linkedCallerList.size() - 1;
307 if (pos != lastPos) {
308 m_linkedCallerList[pos] = m_linkedCallerList[lastPos];
309 m_linkedCallerList[pos]->position = pos;
311 m_linkedCallerList.shrink(lastPos);
314 StructureStubInfo& getStubInfo(ReturnAddressPtr returnAddress)
316 return *(binaryChop<StructureStubInfo, void*, getStructureStubInfoReturnLocation>(m_structureStubInfos.begin(), m_structureStubInfos.size(), returnAddress.value()));
319 CallLinkInfo& getCallLinkInfo(ReturnAddressPtr returnAddress)
321 return *(binaryChop<CallLinkInfo, void*, getCallLinkInfoReturnLocation>(m_callLinkInfos.begin(), m_callLinkInfos.size(), returnAddress.value()));
324 MethodCallLinkInfo& getMethodCallLinkInfo(ReturnAddressPtr returnAddress)
326 return *(binaryChop<MethodCallLinkInfo, void*, getMethodCallLinkInfoReturnLocation>(m_methodCallLinkInfos.begin(), m_methodCallLinkInfos.size(), returnAddress.value()));
329 unsigned bytecodeOffset(ReturnAddressPtr returnAddress)
333 Vector<CallReturnOffsetToBytecodeOffset>& callIndices = m_rareData->m_callReturnIndexVector;
334 if (!callIndices.size())
336 return binaryChop<CallReturnOffsetToBytecodeOffset, unsigned, getCallReturnOffset>(callIndices.begin(), callIndices.size(), getJITCode().offsetOf(returnAddress.value()))->bytecodeOffset;
339 #if ENABLE(INTERPRETER)
340 unsigned bytecodeOffset(Instruction* returnAddress)
342 return static_cast<Instruction*>(returnAddress) - instructions().begin();
346 void setIsNumericCompareFunction(bool isNumericCompareFunction) { m_isNumericCompareFunction = isNumericCompareFunction; }
347 bool isNumericCompareFunction() { return m_isNumericCompareFunction; }
349 Vector<Instruction>& instructions() { return m_instructions; }
350 void discardBytecode() { m_instructions.clear(); }
353 unsigned instructionCount() { return m_instructionCount; }
354 void setInstructionCount(unsigned instructionCount) { m_instructionCount = instructionCount; }
358 JITCode& getJITCode() { return m_isConstructor ? ownerExecutable()->generatedJITCodeForConstruct() : ownerExecutable()->generatedJITCodeForCall(); }
359 ExecutablePool* executablePool() { return getJITCode().getExecutablePool(); }
362 ScriptExecutable* ownerExecutable() const { return m_ownerExecutable; }
364 void setGlobalData(JSGlobalData* globalData) { m_globalData = globalData; }
366 void setThisRegister(int thisRegister) { m_thisRegister = thisRegister; }
367 int thisRegister() const { return m_thisRegister; }
369 void setNeedsFullScopeChain(bool needsFullScopeChain) { m_needsFullScopeChain = needsFullScopeChain; }
370 bool needsFullScopeChain() const { return m_needsFullScopeChain; }
371 void setUsesEval(bool usesEval) { m_usesEval = usesEval; }
372 bool usesEval() const { return m_usesEval; }
374 void setArgumentsRegister(int argumentsRegister)
376 ASSERT(argumentsRegister != -1);
377 m_argumentsRegister = argumentsRegister;
378 ASSERT(usesArguments());
380 int argumentsRegister()
382 ASSERT(usesArguments());
383 return m_argumentsRegister;
385 void setActivationRegister(int activationRegister)
387 m_activationRegister = activationRegister;
389 int activationRegister()
391 ASSERT(needsFullScopeChain());
392 return m_activationRegister;
394 bool usesArguments() const { return m_argumentsRegister != -1; }
396 CodeType codeType() const { return m_codeType; }
398 SourceProvider* source() const { return m_source.get(); }
399 unsigned sourceOffset() const { return m_sourceOffset; }
401 size_t numberOfJumpTargets() const { return m_jumpTargets.size(); }
402 void addJumpTarget(unsigned jumpTarget) { m_jumpTargets.append(jumpTarget); }
403 unsigned jumpTarget(int index) const { return m_jumpTargets[index]; }
404 unsigned lastJumpTarget() const { return m_jumpTargets.last(); }
406 void createActivation(CallFrame*);
408 #if ENABLE(INTERPRETER)
409 void addPropertyAccessInstruction(unsigned propertyAccessInstruction) { m_propertyAccessInstructions.append(propertyAccessInstruction); }
410 void addGlobalResolveInstruction(unsigned globalResolveInstruction) { m_globalResolveInstructions.append(globalResolveInstruction); }
411 bool hasGlobalResolveInstructionAtBytecodeOffset(unsigned bytecodeOffset);
414 size_t numberOfStructureStubInfos() const { return m_structureStubInfos.size(); }
415 void addStructureStubInfo(const StructureStubInfo& stubInfo) { m_structureStubInfos.append(stubInfo); }
416 StructureStubInfo& structureStubInfo(int index) { return m_structureStubInfos[index]; }
418 void addGlobalResolveInfo(unsigned globalResolveInstruction) { m_globalResolveInfos.append(GlobalResolveInfo(globalResolveInstruction)); }
419 GlobalResolveInfo& globalResolveInfo(int index) { return m_globalResolveInfos[index]; }
420 bool hasGlobalResolveInfoAtBytecodeOffset(unsigned bytecodeOffset);
422 size_t numberOfCallLinkInfos() const { return m_callLinkInfos.size(); }
423 void addCallLinkInfo() { m_callLinkInfos.append(CallLinkInfo()); }
424 CallLinkInfo& callLinkInfo(int index) { return m_callLinkInfos[index]; }
426 void addMethodCallLinkInfos(unsigned n) { m_methodCallLinkInfos.grow(n); }
427 MethodCallLinkInfo& methodCallLinkInfo(int index) { return m_methodCallLinkInfos[index]; }
430 // Exception handling support
432 size_t numberOfExceptionHandlers() const { return m_rareData ? m_rareData->m_exceptionHandlers.size() : 0; }
433 void addExceptionHandler(const HandlerInfo& hanler) { createRareDataIfNecessary(); return m_rareData->m_exceptionHandlers.append(hanler); }
434 HandlerInfo& exceptionHandler(int index) { ASSERT(m_rareData); return m_rareData->m_exceptionHandlers[index]; }
436 void addExpressionInfo(const ExpressionRangeInfo& expressionInfo)
438 createRareDataIfNecessary();
439 m_rareData->m_expressionInfo.append(expressionInfo);
442 void addLineInfo(unsigned bytecodeOffset, int lineNo)
444 createRareDataIfNecessary();
445 Vector<LineInfo>& lineInfo = m_rareData->m_lineInfo;
446 if (!lineInfo.size() || lineInfo.last().lineNumber != lineNo) {
447 LineInfo info = { bytecodeOffset, lineNo };
448 lineInfo.append(info);
452 bool hasExpressionInfo() { return m_rareData && m_rareData->m_expressionInfo.size(); }
453 bool hasLineInfo() { return m_rareData && m_rareData->m_lineInfo.size(); }
454 bool needsCallReturnIndices()
457 (m_rareData->m_expressionInfo.size() || m_rareData->m_lineInfo.size() || m_rareData->m_exceptionHandlers.size());
461 Vector<CallReturnOffsetToBytecodeOffset>& callReturnIndexVector()
463 createRareDataIfNecessary();
464 return m_rareData->m_callReturnIndexVector;
470 size_t numberOfIdentifiers() const { return m_identifiers.size(); }
471 void addIdentifier(const Identifier& i) { return m_identifiers.append(i); }
472 Identifier& identifier(int index) { return m_identifiers[index]; }
474 size_t numberOfConstantRegisters() const { return m_constantRegisters.size(); }
475 void addConstantRegister(const Register& r) { return m_constantRegisters.append(r); }
476 Register& constantRegister(int index) { return m_constantRegisters[index - FirstConstantRegisterIndex]; }
477 ALWAYS_INLINE bool isConstantRegisterIndex(int index) const { return index >= FirstConstantRegisterIndex; }
478 ALWAYS_INLINE JSValue getConstant(int index) const { return m_constantRegisters[index - FirstConstantRegisterIndex].jsValue(); }
480 unsigned addFunctionDecl(NonNullPassRefPtr<FunctionExecutable> n) { unsigned size = m_functionDecls.size(); m_functionDecls.append(n); return size; }
481 FunctionExecutable* functionDecl(int index) { return m_functionDecls[index].get(); }
482 int numberOfFunctionDecls() { return m_functionDecls.size(); }
483 unsigned addFunctionExpr(NonNullPassRefPtr<FunctionExecutable> n) { unsigned size = m_functionExprs.size(); m_functionExprs.append(n); return size; }
484 FunctionExecutable* functionExpr(int index) { return m_functionExprs[index].get(); }
486 unsigned addRegExp(RegExp* r) { createRareDataIfNecessary(); unsigned size = m_rareData->m_regexps.size(); m_rareData->m_regexps.append(r); return size; }
487 RegExp* regexp(int index) const { ASSERT(m_rareData); return m_rareData->m_regexps[index].get(); }
489 JSGlobalObject* globalObject() { return m_globalObject.get(); }
493 size_t numberOfImmediateSwitchJumpTables() const { return m_rareData ? m_rareData->m_immediateSwitchJumpTables.size() : 0; }
494 SimpleJumpTable& addImmediateSwitchJumpTable() { createRareDataIfNecessary(); m_rareData->m_immediateSwitchJumpTables.append(SimpleJumpTable()); return m_rareData->m_immediateSwitchJumpTables.last(); }
495 SimpleJumpTable& immediateSwitchJumpTable(int tableIndex) { ASSERT(m_rareData); return m_rareData->m_immediateSwitchJumpTables[tableIndex]; }
497 size_t numberOfCharacterSwitchJumpTables() const { return m_rareData ? m_rareData->m_characterSwitchJumpTables.size() : 0; }
498 SimpleJumpTable& addCharacterSwitchJumpTable() { createRareDataIfNecessary(); m_rareData->m_characterSwitchJumpTables.append(SimpleJumpTable()); return m_rareData->m_characterSwitchJumpTables.last(); }
499 SimpleJumpTable& characterSwitchJumpTable(int tableIndex) { ASSERT(m_rareData); return m_rareData->m_characterSwitchJumpTables[tableIndex]; }
501 size_t numberOfStringSwitchJumpTables() const { return m_rareData ? m_rareData->m_stringSwitchJumpTables.size() : 0; }
502 StringJumpTable& addStringSwitchJumpTable() { createRareDataIfNecessary(); m_rareData->m_stringSwitchJumpTables.append(StringJumpTable()); return m_rareData->m_stringSwitchJumpTables.last(); }
503 StringJumpTable& stringSwitchJumpTable(int tableIndex) { ASSERT(m_rareData); return m_rareData->m_stringSwitchJumpTables[tableIndex]; }
506 SymbolTable* symbolTable() { return m_symbolTable; }
507 SharedSymbolTable* sharedSymbolTable() { ASSERT(m_codeType == FunctionCode); return static_cast<SharedSymbolTable*>(m_symbolTable); }
509 EvalCodeCache& evalCodeCache() { createRareDataIfNecessary(); return m_rareData->m_evalCodeCache; }
513 // FIXME: Make these remaining members private.
515 int m_numCalleeRegisters;
517 int m_numCapturedVars;
519 bool m_isConstructor;
522 #if !defined(NDEBUG) || ENABLE(OPCODE_SAMPLING)
523 void dump(ExecState*, const Vector<Instruction>::const_iterator& begin, Vector<Instruction>::const_iterator&) const;
525 CString registerName(ExecState*, int r) const;
526 void printUnaryOp(ExecState*, int location, Vector<Instruction>::const_iterator&, const char* op) const;
527 void printBinaryOp(ExecState*, int location, Vector<Instruction>::const_iterator&, const char* op) const;
528 void printConditionalJump(ExecState*, const Vector<Instruction>::const_iterator&, Vector<Instruction>::const_iterator&, int location, const char* op) const;
529 void printGetByIdOp(ExecState*, int location, Vector<Instruction>::const_iterator&, const char* op) const;
530 void printPutByIdOp(ExecState*, int location, Vector<Instruction>::const_iterator&, const char* op) const;
533 void createRareDataIfNecessary()
536 m_rareData = adoptPtr(new RareData);
539 ScriptExecutable* m_ownerExecutable;
540 JSGlobalData* m_globalData;
542 Vector<Instruction> m_instructions;
544 unsigned m_instructionCount;
548 int m_argumentsRegister;
549 int m_activationRegister;
551 bool m_needsFullScopeChain;
553 bool m_isNumericCompareFunction;
558 RefPtr<SourceProvider> m_source;
559 unsigned m_sourceOffset;
561 #if ENABLE(INTERPRETER)
562 Vector<unsigned> m_propertyAccessInstructions;
563 Vector<unsigned> m_globalResolveInstructions;
566 Vector<StructureStubInfo> m_structureStubInfos;
567 Vector<GlobalResolveInfo> m_globalResolveInfos;
568 Vector<CallLinkInfo> m_callLinkInfos;
569 Vector<MethodCallLinkInfo> m_methodCallLinkInfos;
570 Vector<CallLinkInfo*> m_linkedCallerList;
573 Vector<unsigned> m_jumpTargets;
576 Vector<Identifier> m_identifiers;
577 Vector<Register> m_constantRegisters;
578 Vector<RefPtr<FunctionExecutable> > m_functionDecls;
579 Vector<RefPtr<FunctionExecutable> > m_functionExprs;
581 SymbolTable* m_symbolTable;
584 WTF_MAKE_FAST_ALLOCATED;
586 Vector<HandlerInfo> m_exceptionHandlers;
589 Vector<RefPtr<RegExp> > m_regexps;
592 Vector<SimpleJumpTable> m_immediateSwitchJumpTables;
593 Vector<SimpleJumpTable> m_characterSwitchJumpTables;
594 Vector<StringJumpTable> m_stringSwitchJumpTables;
596 EvalCodeCache m_evalCodeCache;
598 // Expression info - present if debugging.
599 Vector<ExpressionRangeInfo> m_expressionInfo;
600 // Line info - present if profiling or debugging.
601 Vector<LineInfo> m_lineInfo;
603 Vector<CallReturnOffsetToBytecodeOffset> m_callReturnIndexVector;
607 friend void WTF::deleteOwnedPtr<RareData>(RareData*);
609 OwnPtr<RareData> m_rareData;
612 // Program code is not marked by any function, so we make the global object
613 // responsible for marking it.
615 class GlobalCodeBlock : public CodeBlock {
617 GlobalCodeBlock(ScriptExecutable* ownerExecutable, CodeType codeType, JSGlobalObject* globalObject, PassRefPtr<SourceProvider> sourceProvider, unsigned sourceOffset)
618 : CodeBlock(ownerExecutable, codeType, globalObject, sourceProvider, sourceOffset, &m_unsharedSymbolTable, false)
620 m_heap->codeBlocks().add(this);
625 m_heap->codeBlocks().remove(this);
629 SymbolTable m_unsharedSymbolTable;
632 class ProgramCodeBlock : public GlobalCodeBlock {
634 ProgramCodeBlock(ProgramExecutable* ownerExecutable, CodeType codeType, JSGlobalObject* globalObject, PassRefPtr<SourceProvider> sourceProvider)
635 : GlobalCodeBlock(ownerExecutable, codeType, globalObject, sourceProvider, 0)
640 class EvalCodeBlock : public GlobalCodeBlock {
642 EvalCodeBlock(EvalExecutable* ownerExecutable, JSGlobalObject* globalObject, PassRefPtr<SourceProvider> sourceProvider, int baseScopeDepth)
643 : GlobalCodeBlock(ownerExecutable, EvalCode, globalObject, sourceProvider, 0)
644 , m_baseScopeDepth(baseScopeDepth)
648 int baseScopeDepth() const { return m_baseScopeDepth; }
650 const Identifier& variable(unsigned index) { return m_variables[index]; }
651 unsigned numVariables() { return m_variables.size(); }
652 void adoptVariables(Vector<Identifier>& variables)
654 ASSERT(m_variables.isEmpty());
655 m_variables.swap(variables);
659 int m_baseScopeDepth;
660 Vector<Identifier> m_variables;
663 class FunctionCodeBlock : public CodeBlock {
665 // Rather than using the usual RefCounted::create idiom for SharedSymbolTable we just use new
666 // as we need to initialise the CodeBlock before we could initialise any RefPtr to hold the shared
667 // symbol table, so we just pass as a raw pointer with a ref count of 1. We then manually deref
668 // in the destructor.
669 FunctionCodeBlock(FunctionExecutable* ownerExecutable, CodeType codeType, JSGlobalObject* globalObject, PassRefPtr<SourceProvider> sourceProvider, unsigned sourceOffset, bool isConstructor)
670 : CodeBlock(ownerExecutable, codeType, globalObject, sourceProvider, sourceOffset, SharedSymbolTable::create().leakRef(), isConstructor)
675 sharedSymbolTable()->deref();
679 inline Register& ExecState::r(int index)
681 CodeBlock* codeBlock = this->codeBlock();
682 if (codeBlock->isConstantRegisterIndex(index))
683 return codeBlock->constantRegister(index);
687 inline Register& ExecState::uncheckedR(int index)
689 ASSERT(index < FirstConstantRegisterIndex);
695 #endif // CodeBlock_h