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 JSGlobalObject* m_globalObject;
254 virtual ~CodeBlock();
256 void markAggregate(MarkStack&);
257 void refStructures(Instruction* vPC) const;
258 void derefStructures(Instruction* vPC) const;
259 #if ENABLE(JIT_OPTIMIZE_CALL)
260 void unlinkCallers();
263 static void dumpStatistics();
265 #if !defined(NDEBUG) || ENABLE_OPCODE_SAMPLING
266 void dump(ExecState*) const;
267 void printStructures(const Instruction*) const;
268 void printStructure(const char* name, const Instruction*, int operand) const;
271 bool isStrictMode() const { return m_isStrictMode; }
273 inline bool isKnownNotImmediate(int index)
275 if (index == m_thisRegister && !m_isStrictMode)
278 if (isConstantRegisterIndex(index))
279 return getConstant(index).isCell();
284 ALWAYS_INLINE bool isTemporaryRegisterIndex(int index)
286 return index >= m_numVars;
289 HandlerInfo* handlerForBytecodeOffset(unsigned bytecodeOffset);
290 int lineNumberForBytecodeOffset(unsigned bytecodeOffset);
291 void expressionRangeForBytecodeOffset(unsigned bytecodeOffset, int& divot, int& startOffset, int& endOffset);
294 void addCaller(CallLinkInfo* caller)
296 caller->callee = this;
297 caller->position = m_linkedCallerList.size();
298 m_linkedCallerList.append(caller);
301 void removeCaller(CallLinkInfo* caller)
303 unsigned pos = caller->position;
304 unsigned lastPos = m_linkedCallerList.size() - 1;
306 if (pos != lastPos) {
307 m_linkedCallerList[pos] = m_linkedCallerList[lastPos];
308 m_linkedCallerList[pos]->position = pos;
310 m_linkedCallerList.shrink(lastPos);
313 StructureStubInfo& getStubInfo(ReturnAddressPtr returnAddress)
315 return *(binaryChop<StructureStubInfo, void*, getStructureStubInfoReturnLocation>(m_structureStubInfos.begin(), m_structureStubInfos.size(), returnAddress.value()));
318 CallLinkInfo& getCallLinkInfo(ReturnAddressPtr returnAddress)
320 return *(binaryChop<CallLinkInfo, void*, getCallLinkInfoReturnLocation>(m_callLinkInfos.begin(), m_callLinkInfos.size(), returnAddress.value()));
323 MethodCallLinkInfo& getMethodCallLinkInfo(ReturnAddressPtr returnAddress)
325 return *(binaryChop<MethodCallLinkInfo, void*, getMethodCallLinkInfoReturnLocation>(m_methodCallLinkInfos.begin(), m_methodCallLinkInfos.size(), returnAddress.value()));
328 unsigned bytecodeOffset(ReturnAddressPtr returnAddress)
332 Vector<CallReturnOffsetToBytecodeOffset>& callIndices = m_rareData->m_callReturnIndexVector;
333 if (!callIndices.size())
335 return binaryChop<CallReturnOffsetToBytecodeOffset, unsigned, getCallReturnOffset>(callIndices.begin(), callIndices.size(), getJITCode().offsetOf(returnAddress.value()))->bytecodeOffset;
338 #if ENABLE(INTERPRETER)
339 unsigned bytecodeOffset(Instruction* returnAddress)
341 return static_cast<Instruction*>(returnAddress) - instructions().begin();
345 void setIsNumericCompareFunction(bool isNumericCompareFunction) { m_isNumericCompareFunction = isNumericCompareFunction; }
346 bool isNumericCompareFunction() { return m_isNumericCompareFunction; }
348 Vector<Instruction>& instructions() { return m_instructions; }
349 void discardBytecode() { m_instructions.clear(); }
352 unsigned instructionCount() { return m_instructionCount; }
353 void setInstructionCount(unsigned instructionCount) { m_instructionCount = instructionCount; }
357 JITCode& getJITCode() { return m_isConstructor ? ownerExecutable()->generatedJITCodeForConstruct() : ownerExecutable()->generatedJITCodeForCall(); }
358 ExecutablePool* executablePool() { return getJITCode().getExecutablePool(); }
361 ScriptExecutable* ownerExecutable() const { return m_ownerExecutable; }
363 void setGlobalData(JSGlobalData* globalData) { m_globalData = globalData; }
365 void setThisRegister(int thisRegister) { m_thisRegister = thisRegister; }
366 int thisRegister() const { return m_thisRegister; }
368 void setNeedsFullScopeChain(bool needsFullScopeChain) { m_needsFullScopeChain = needsFullScopeChain; }
369 bool needsFullScopeChain() const { return m_needsFullScopeChain; }
370 void setUsesEval(bool usesEval) { m_usesEval = usesEval; }
371 bool usesEval() const { return m_usesEval; }
373 void setArgumentsRegister(int argumentsRegister)
375 ASSERT(argumentsRegister != -1);
376 m_argumentsRegister = argumentsRegister;
377 ASSERT(usesArguments());
379 int argumentsRegister()
381 ASSERT(usesArguments());
382 return m_argumentsRegister;
384 void setActivationRegister(int activationRegister)
386 m_activationRegister = activationRegister;
388 int activationRegister()
390 ASSERT(needsFullScopeChain());
391 return m_activationRegister;
393 bool usesArguments() const { return m_argumentsRegister != -1; }
395 CodeType codeType() const { return m_codeType; }
397 SourceProvider* source() const { return m_source.get(); }
398 unsigned sourceOffset() const { return m_sourceOffset; }
400 size_t numberOfJumpTargets() const { return m_jumpTargets.size(); }
401 void addJumpTarget(unsigned jumpTarget) { m_jumpTargets.append(jumpTarget); }
402 unsigned jumpTarget(int index) const { return m_jumpTargets[index]; }
403 unsigned lastJumpTarget() const { return m_jumpTargets.last(); }
405 void createActivation(CallFrame*);
407 #if ENABLE(INTERPRETER)
408 void addPropertyAccessInstruction(unsigned propertyAccessInstruction) { m_propertyAccessInstructions.append(propertyAccessInstruction); }
409 void addGlobalResolveInstruction(unsigned globalResolveInstruction) { m_globalResolveInstructions.append(globalResolveInstruction); }
410 bool hasGlobalResolveInstructionAtBytecodeOffset(unsigned bytecodeOffset);
413 size_t numberOfStructureStubInfos() const { return m_structureStubInfos.size(); }
414 void addStructureStubInfo(const StructureStubInfo& stubInfo) { m_structureStubInfos.append(stubInfo); }
415 StructureStubInfo& structureStubInfo(int index) { return m_structureStubInfos[index]; }
417 void addGlobalResolveInfo(unsigned globalResolveInstruction) { m_globalResolveInfos.append(GlobalResolveInfo(globalResolveInstruction)); }
418 GlobalResolveInfo& globalResolveInfo(int index) { return m_globalResolveInfos[index]; }
419 bool hasGlobalResolveInfoAtBytecodeOffset(unsigned bytecodeOffset);
421 size_t numberOfCallLinkInfos() const { return m_callLinkInfos.size(); }
422 void addCallLinkInfo() { m_callLinkInfos.append(CallLinkInfo()); }
423 CallLinkInfo& callLinkInfo(int index) { return m_callLinkInfos[index]; }
425 void addMethodCallLinkInfos(unsigned n) { m_methodCallLinkInfos.grow(n); }
426 MethodCallLinkInfo& methodCallLinkInfo(int index) { return m_methodCallLinkInfos[index]; }
429 // Exception handling support
431 size_t numberOfExceptionHandlers() const { return m_rareData ? m_rareData->m_exceptionHandlers.size() : 0; }
432 void addExceptionHandler(const HandlerInfo& hanler) { createRareDataIfNecessary(); return m_rareData->m_exceptionHandlers.append(hanler); }
433 HandlerInfo& exceptionHandler(int index) { ASSERT(m_rareData); return m_rareData->m_exceptionHandlers[index]; }
435 void addExpressionInfo(const ExpressionRangeInfo& expressionInfo)
437 createRareDataIfNecessary();
438 m_rareData->m_expressionInfo.append(expressionInfo);
441 void addLineInfo(unsigned bytecodeOffset, int lineNo)
443 createRareDataIfNecessary();
444 Vector<LineInfo>& lineInfo = m_rareData->m_lineInfo;
445 if (!lineInfo.size() || lineInfo.last().lineNumber != lineNo) {
446 LineInfo info = { bytecodeOffset, lineNo };
447 lineInfo.append(info);
451 bool hasExpressionInfo() { return m_rareData && m_rareData->m_expressionInfo.size(); }
452 bool hasLineInfo() { return m_rareData && m_rareData->m_lineInfo.size(); }
453 bool needsCallReturnIndices()
456 (m_rareData->m_expressionInfo.size() || m_rareData->m_lineInfo.size() || m_rareData->m_exceptionHandlers.size());
460 Vector<CallReturnOffsetToBytecodeOffset>& callReturnIndexVector()
462 createRareDataIfNecessary();
463 return m_rareData->m_callReturnIndexVector;
469 size_t numberOfIdentifiers() const { return m_identifiers.size(); }
470 void addIdentifier(const Identifier& i) { return m_identifiers.append(i); }
471 Identifier& identifier(int index) { return m_identifiers[index]; }
473 size_t numberOfConstantRegisters() const { return m_constantRegisters.size(); }
474 void addConstantRegister(const Register& r) { return m_constantRegisters.append(r); }
475 Register& constantRegister(int index) { return m_constantRegisters[index - FirstConstantRegisterIndex]; }
476 ALWAYS_INLINE bool isConstantRegisterIndex(int index) const { return index >= FirstConstantRegisterIndex; }
477 ALWAYS_INLINE JSValue getConstant(int index) const { return m_constantRegisters[index - FirstConstantRegisterIndex].jsValue(); }
479 unsigned addFunctionDecl(NonNullPassRefPtr<FunctionExecutable> n) { unsigned size = m_functionDecls.size(); m_functionDecls.append(n); return size; }
480 FunctionExecutable* functionDecl(int index) { return m_functionDecls[index].get(); }
481 int numberOfFunctionDecls() { return m_functionDecls.size(); }
482 unsigned addFunctionExpr(NonNullPassRefPtr<FunctionExecutable> n) { unsigned size = m_functionExprs.size(); m_functionExprs.append(n); return size; }
483 FunctionExecutable* functionExpr(int index) { return m_functionExprs[index].get(); }
485 unsigned addRegExp(RegExp* r) { createRareDataIfNecessary(); unsigned size = m_rareData->m_regexps.size(); m_rareData->m_regexps.append(r); return size; }
486 RegExp* regexp(int index) const { ASSERT(m_rareData); return m_rareData->m_regexps[index].get(); }
488 JSGlobalObject* globalObject() { return m_globalObject; }
492 size_t numberOfImmediateSwitchJumpTables() const { return m_rareData ? m_rareData->m_immediateSwitchJumpTables.size() : 0; }
493 SimpleJumpTable& addImmediateSwitchJumpTable() { createRareDataIfNecessary(); m_rareData->m_immediateSwitchJumpTables.append(SimpleJumpTable()); return m_rareData->m_immediateSwitchJumpTables.last(); }
494 SimpleJumpTable& immediateSwitchJumpTable(int tableIndex) { ASSERT(m_rareData); return m_rareData->m_immediateSwitchJumpTables[tableIndex]; }
496 size_t numberOfCharacterSwitchJumpTables() const { return m_rareData ? m_rareData->m_characterSwitchJumpTables.size() : 0; }
497 SimpleJumpTable& addCharacterSwitchJumpTable() { createRareDataIfNecessary(); m_rareData->m_characterSwitchJumpTables.append(SimpleJumpTable()); return m_rareData->m_characterSwitchJumpTables.last(); }
498 SimpleJumpTable& characterSwitchJumpTable(int tableIndex) { ASSERT(m_rareData); return m_rareData->m_characterSwitchJumpTables[tableIndex]; }
500 size_t numberOfStringSwitchJumpTables() const { return m_rareData ? m_rareData->m_stringSwitchJumpTables.size() : 0; }
501 StringJumpTable& addStringSwitchJumpTable() { createRareDataIfNecessary(); m_rareData->m_stringSwitchJumpTables.append(StringJumpTable()); return m_rareData->m_stringSwitchJumpTables.last(); }
502 StringJumpTable& stringSwitchJumpTable(int tableIndex) { ASSERT(m_rareData); return m_rareData->m_stringSwitchJumpTables[tableIndex]; }
505 SymbolTable* symbolTable() { return m_symbolTable; }
506 SharedSymbolTable* sharedSymbolTable() { ASSERT(m_codeType == FunctionCode); return static_cast<SharedSymbolTable*>(m_symbolTable); }
508 EvalCodeCache& evalCodeCache() { createRareDataIfNecessary(); return m_rareData->m_evalCodeCache; }
512 // FIXME: Make these remaining members private.
514 int m_numCalleeRegisters;
516 int m_numCapturedVars;
518 bool m_isConstructor;
521 #if !defined(NDEBUG) || ENABLE(OPCODE_SAMPLING)
522 void dump(ExecState*, const Vector<Instruction>::const_iterator& begin, Vector<Instruction>::const_iterator&) const;
524 CString registerName(ExecState*, int r) const;
525 void printUnaryOp(ExecState*, int location, Vector<Instruction>::const_iterator&, const char* op) const;
526 void printBinaryOp(ExecState*, int location, Vector<Instruction>::const_iterator&, const char* op) const;
527 void printConditionalJump(ExecState*, const Vector<Instruction>::const_iterator&, Vector<Instruction>::const_iterator&, int location, const char* op) const;
528 void printGetByIdOp(ExecState*, int location, Vector<Instruction>::const_iterator&, const char* op) const;
529 void printPutByIdOp(ExecState*, int location, Vector<Instruction>::const_iterator&, const char* op) const;
532 void createRareDataIfNecessary()
535 m_rareData = adoptPtr(new RareData);
538 ScriptExecutable* m_ownerExecutable;
539 JSGlobalData* m_globalData;
541 Vector<Instruction> m_instructions;
543 unsigned m_instructionCount;
547 int m_argumentsRegister;
548 int m_activationRegister;
550 bool m_needsFullScopeChain;
552 bool m_isNumericCompareFunction;
557 RefPtr<SourceProvider> m_source;
558 unsigned m_sourceOffset;
560 #if ENABLE(INTERPRETER)
561 Vector<unsigned> m_propertyAccessInstructions;
562 Vector<unsigned> m_globalResolveInstructions;
565 Vector<StructureStubInfo> m_structureStubInfos;
566 Vector<GlobalResolveInfo> m_globalResolveInfos;
567 Vector<CallLinkInfo> m_callLinkInfos;
568 Vector<MethodCallLinkInfo> m_methodCallLinkInfos;
569 Vector<CallLinkInfo*> m_linkedCallerList;
572 Vector<unsigned> m_jumpTargets;
575 Vector<Identifier> m_identifiers;
576 Vector<Register> m_constantRegisters;
577 Vector<RefPtr<FunctionExecutable> > m_functionDecls;
578 Vector<RefPtr<FunctionExecutable> > m_functionExprs;
580 SymbolTable* m_symbolTable;
583 WTF_MAKE_FAST_ALLOCATED;
585 Vector<HandlerInfo> m_exceptionHandlers;
588 Vector<RefPtr<RegExp> > m_regexps;
591 Vector<SimpleJumpTable> m_immediateSwitchJumpTables;
592 Vector<SimpleJumpTable> m_characterSwitchJumpTables;
593 Vector<StringJumpTable> m_stringSwitchJumpTables;
595 EvalCodeCache m_evalCodeCache;
597 // Expression info - present if debugging.
598 Vector<ExpressionRangeInfo> m_expressionInfo;
599 // Line info - present if profiling or debugging.
600 Vector<LineInfo> m_lineInfo;
602 Vector<CallReturnOffsetToBytecodeOffset> m_callReturnIndexVector;
606 friend void WTF::deleteOwnedPtr<RareData>(RareData*);
608 OwnPtr<RareData> m_rareData;
611 // Program code is not marked by any function, so we make the global object
612 // responsible for marking it.
614 class GlobalCodeBlock : public CodeBlock {
616 GlobalCodeBlock(ScriptExecutable* ownerExecutable, CodeType codeType, JSGlobalObject* globalObject, PassRefPtr<SourceProvider> sourceProvider, unsigned sourceOffset)
617 : CodeBlock(ownerExecutable, codeType, globalObject, sourceProvider, sourceOffset, &m_unsharedSymbolTable, false)
619 m_globalObject->codeBlocks().add(this);
625 m_globalObject->codeBlocks().remove(this);
628 void clearGlobalObject() { m_globalObject = 0; }
631 SymbolTable m_unsharedSymbolTable;
634 class ProgramCodeBlock : public GlobalCodeBlock {
636 ProgramCodeBlock(ProgramExecutable* ownerExecutable, CodeType codeType, JSGlobalObject* globalObject, PassRefPtr<SourceProvider> sourceProvider)
637 : GlobalCodeBlock(ownerExecutable, codeType, globalObject, sourceProvider, 0)
642 class EvalCodeBlock : public GlobalCodeBlock {
644 EvalCodeBlock(EvalExecutable* ownerExecutable, JSGlobalObject* globalObject, PassRefPtr<SourceProvider> sourceProvider, int baseScopeDepth)
645 : GlobalCodeBlock(ownerExecutable, EvalCode, globalObject, sourceProvider, 0)
646 , m_baseScopeDepth(baseScopeDepth)
650 int baseScopeDepth() const { return m_baseScopeDepth; }
652 const Identifier& variable(unsigned index) { return m_variables[index]; }
653 unsigned numVariables() { return m_variables.size(); }
654 void adoptVariables(Vector<Identifier>& variables)
656 ASSERT(m_variables.isEmpty());
657 m_variables.swap(variables);
661 int m_baseScopeDepth;
662 Vector<Identifier> m_variables;
665 class FunctionCodeBlock : public CodeBlock {
667 // Rather than using the usual RefCounted::create idiom for SharedSymbolTable we just use new
668 // as we need to initialise the CodeBlock before we could initialise any RefPtr to hold the shared
669 // symbol table, so we just pass as a raw pointer with a ref count of 1. We then manually deref
670 // in the destructor.
671 FunctionCodeBlock(FunctionExecutable* ownerExecutable, CodeType codeType, JSGlobalObject* globalObject, PassRefPtr<SourceProvider> sourceProvider, unsigned sourceOffset, bool isConstructor)
672 : CodeBlock(ownerExecutable, codeType, globalObject, sourceProvider, sourceOffset, SharedSymbolTable::create().leakRef(), isConstructor)
677 sharedSymbolTable()->deref();
681 inline Register& ExecState::r(int index)
683 CodeBlock* codeBlock = this->codeBlock();
684 if (codeBlock->isConstantRegisterIndex(index))
685 return codeBlock->constantRegister(index);
689 inline Register& ExecState::uncheckedR(int index)
691 ASSERT(index < FirstConstantRegisterIndex);
697 #endif // CodeBlock_h