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;
96 // Both op_construct and op_instanceof require a use of op_get_by_id to get
97 // the prototype property from an object. The exception messages for exceptions
98 // thrown by these instances op_get_by_id need to reflect this.
99 struct GetByIdExceptionInfo {
100 unsigned bytecodeOffset : 31;
101 bool isOpCreateThis : 1;
105 struct CallLinkInfo {
109 , hasSeenShouldRepatch(0)
113 unsigned bytecodeOffset;
114 CodeLocationNearCall callReturnLocation;
115 CodeLocationDataLabelPtr hotPathBegin;
116 CodeLocationNearCall hotPathOther;
117 CodeBlock* ownerCodeBlock;
119 unsigned position : 31;
120 unsigned hasSeenShouldRepatch : 1;
122 void setUnlinked() { callee = 0; }
123 bool isLinked() { return callee; }
127 return hasSeenShouldRepatch;
132 hasSeenShouldRepatch = true;
136 struct MethodCallLinkInfo {
139 , cachedPrototypeStructure(0)
145 ASSERT(!cachedStructure);
146 return cachedPrototypeStructure;
151 ASSERT(!cachedStructure && !cachedPrototypeStructure);
152 // We use the values of cachedStructure & cachedPrototypeStructure to indicate the
154 // - In the initial state, both are null.
155 // - Once this transition has been taken once, cachedStructure is
156 // null and cachedPrototypeStructure is set to a nun-null value.
157 // - Once the call is linked both structures are set to non-null values.
158 cachedPrototypeStructure = (Structure*)1;
161 CodeLocationCall callReturnLocation;
162 CodeLocationDataLabelPtr structureLabel;
163 Structure* cachedStructure;
164 Structure* cachedPrototypeStructure;
167 struct FunctionRegisterInfo {
168 FunctionRegisterInfo(unsigned bytecodeOffset, int functionRegisterIndex)
169 : bytecodeOffset(bytecodeOffset)
170 , functionRegisterIndex(functionRegisterIndex)
174 unsigned bytecodeOffset;
175 int functionRegisterIndex;
178 struct GlobalResolveInfo {
179 GlobalResolveInfo(unsigned bytecodeOffset)
182 , bytecodeOffset(bytecodeOffset)
186 Structure* structure;
188 unsigned bytecodeOffset;
191 // This structure is used to map from a call return location
192 // (given as an offset in bytes into the JIT code) back to
193 // the bytecode index of the corresponding bytecode operation.
194 // This is then used to look up the corresponding handler.
195 struct CallReturnOffsetToBytecodeOffset {
196 CallReturnOffsetToBytecodeOffset(unsigned callReturnOffset, unsigned bytecodeOffset)
197 : callReturnOffset(callReturnOffset)
198 , bytecodeOffset(bytecodeOffset)
202 unsigned callReturnOffset;
203 unsigned bytecodeOffset;
206 // valueAtPosition helpers for the binaryChop algorithm below.
208 inline void* getStructureStubInfoReturnLocation(StructureStubInfo* structureStubInfo)
210 return structureStubInfo->callReturnLocation.executableAddress();
213 inline void* getCallLinkInfoReturnLocation(CallLinkInfo* callLinkInfo)
215 return callLinkInfo->callReturnLocation.executableAddress();
218 inline void* getMethodCallLinkInfoReturnLocation(MethodCallLinkInfo* methodCallLinkInfo)
220 return methodCallLinkInfo->callReturnLocation.executableAddress();
223 inline unsigned getCallReturnOffset(CallReturnOffsetToBytecodeOffset* pc)
225 return pc->callReturnOffset;
228 // Binary chop algorithm, calls valueAtPosition on pre-sorted elements in array,
229 // compares result with key (KeyTypes should be comparable with '--', '<', '>').
230 // Optimized for cases where the array contains the key, checked by assertions.
231 template<typename ArrayType, typename KeyType, KeyType(*valueAtPosition)(ArrayType*)>
232 inline ArrayType* binaryChop(ArrayType* array, size_t size, KeyType key)
234 // The array must contain at least one element (pre-condition, array does conatin key).
235 // If the array only contains one element, no need to do the comparison.
237 // Pick an element to check, half way through the array, and read the value.
238 int pos = (size - 1) >> 1;
239 KeyType val = valueAtPosition(&array[pos]);
241 // If the key matches, success!
244 // The item we are looking for is smaller than the item being check; reduce the value of 'size',
245 // chopping off the right hand half of the array.
248 // Discard all values in the left hand half of the array, up to and including the item at pos.
254 // 'size' should never reach zero.
258 // If we reach this point we've chopped down to one element, no need to check it matches
260 ASSERT(key == valueAtPosition(&array[0]));
265 struct ExceptionInfo : FastAllocBase {
266 Vector<ExpressionRangeInfo> m_expressionInfo;
267 Vector<LineInfo> m_lineInfo;
268 Vector<GetByIdExceptionInfo> m_getByIdExceptionInfo;
271 Vector<CallReturnOffsetToBytecodeOffset> m_callReturnIndexVector;
275 class CodeBlock : public FastAllocBase {
278 CodeBlock(ScriptExecutable* ownerExecutable, CodeType, JSGlobalObject*, PassRefPtr<SourceProvider>, unsigned sourceOffset, SymbolTable* symbolTable, bool isConstructor);
280 JSGlobalObject* m_globalObject;
283 virtual ~CodeBlock();
285 void markAggregate(MarkStack&);
286 void refStructures(Instruction* vPC) const;
287 void derefStructures(Instruction* vPC) const;
288 #if ENABLE(JIT_OPTIMIZE_CALL)
289 void unlinkCallers();
292 static void dumpStatistics();
294 #if !defined(NDEBUG) || ENABLE_OPCODE_SAMPLING
295 void dump(ExecState*) const;
296 void printStructures(const Instruction*) const;
297 void printStructure(const char* name, const Instruction*, int operand) const;
300 bool isStrictMode() const { return m_isStrictMode; }
302 inline bool isKnownNotImmediate(int index)
304 if (index == m_thisRegister && !m_isStrictMode)
307 if (isConstantRegisterIndex(index))
308 return getConstant(index).isCell();
313 ALWAYS_INLINE bool isTemporaryRegisterIndex(int index)
315 return index >= m_numVars;
318 HandlerInfo* handlerForBytecodeOffset(unsigned bytecodeOffset);
319 int lineNumberForBytecodeOffset(CallFrame*, unsigned bytecodeOffset);
320 int expressionRangeForBytecodeOffset(CallFrame*, unsigned bytecodeOffset, int& divot, int& startOffset, int& endOffset);
321 bool getByIdExceptionInfoForBytecodeOffset(CallFrame*, unsigned bytecodeOffset, OpcodeID&);
324 void addCaller(CallLinkInfo* caller)
326 caller->callee = this;
327 caller->position = m_linkedCallerList.size();
328 m_linkedCallerList.append(caller);
331 void removeCaller(CallLinkInfo* caller)
333 unsigned pos = caller->position;
334 unsigned lastPos = m_linkedCallerList.size() - 1;
336 if (pos != lastPos) {
337 m_linkedCallerList[pos] = m_linkedCallerList[lastPos];
338 m_linkedCallerList[pos]->position = pos;
340 m_linkedCallerList.shrink(lastPos);
343 StructureStubInfo& getStubInfo(ReturnAddressPtr returnAddress)
345 return *(binaryChop<StructureStubInfo, void*, getStructureStubInfoReturnLocation>(m_structureStubInfos.begin(), m_structureStubInfos.size(), returnAddress.value()));
348 CallLinkInfo& getCallLinkInfo(ReturnAddressPtr returnAddress)
350 return *(binaryChop<CallLinkInfo, void*, getCallLinkInfoReturnLocation>(m_callLinkInfos.begin(), m_callLinkInfos.size(), returnAddress.value()));
353 MethodCallLinkInfo& getMethodCallLinkInfo(ReturnAddressPtr returnAddress)
355 return *(binaryChop<MethodCallLinkInfo, void*, getMethodCallLinkInfoReturnLocation>(m_methodCallLinkInfos.begin(), m_methodCallLinkInfos.size(), returnAddress.value()));
358 unsigned bytecodeOffset(CallFrame* callFrame, ReturnAddressPtr returnAddress)
360 if (!reparseForExceptionInfoIfNecessary(callFrame))
362 return binaryChop<CallReturnOffsetToBytecodeOffset, unsigned, getCallReturnOffset>(callReturnIndexVector().begin(), callReturnIndexVector().size(), getJITCode().offsetOf(returnAddress.value()))->bytecodeOffset;
365 bool functionRegisterForBytecodeOffset(unsigned bytecodeOffset, int& functionRegisterIndex);
367 #if ENABLE(INTERPRETER)
368 unsigned bytecodeOffset(CallFrame*, Instruction* returnAddress)
370 return static_cast<Instruction*>(returnAddress) - instructions().begin();
374 void setIsNumericCompareFunction(bool isNumericCompareFunction) { m_isNumericCompareFunction = isNumericCompareFunction; }
375 bool isNumericCompareFunction() { return m_isNumericCompareFunction; }
377 Vector<Instruction>& instructions() { return m_instructions; }
378 void discardBytecode() { m_instructions.clear(); }
381 unsigned instructionCount() { return m_instructionCount; }
382 void setInstructionCount(unsigned instructionCount) { m_instructionCount = instructionCount; }
386 JITCode& getJITCode() { return m_isConstructor ? ownerExecutable()->generatedJITCodeForConstruct() : ownerExecutable()->generatedJITCodeForCall(); }
387 ExecutablePool* executablePool() { return getJITCode().getExecutablePool(); }
390 ScriptExecutable* ownerExecutable() const { return m_ownerExecutable; }
392 void setGlobalData(JSGlobalData* globalData) { m_globalData = globalData; }
394 void setThisRegister(int thisRegister) { m_thisRegister = thisRegister; }
395 int thisRegister() const { return m_thisRegister; }
397 void setNeedsFullScopeChain(bool needsFullScopeChain) { m_needsFullScopeChain = needsFullScopeChain; }
398 bool needsFullScopeChain() const { return m_needsFullScopeChain; }
399 void setUsesEval(bool usesEval) { m_usesEval = usesEval; }
400 bool usesEval() const { return m_usesEval; }
402 void setArgumentsRegister(int argumentsRegister)
404 ASSERT(argumentsRegister != -1);
405 m_argumentsRegister = argumentsRegister;
406 ASSERT(usesArguments());
408 int argumentsRegister()
410 ASSERT(usesArguments());
411 return m_argumentsRegister;
413 void setActivationRegister(int activationRegister)
415 m_activationRegister = activationRegister;
417 int activationRegister()
419 ASSERT(needsFullScopeChain());
420 return m_activationRegister;
422 bool usesArguments() const { return m_argumentsRegister != -1; }
424 CodeType codeType() const { return m_codeType; }
426 SourceProvider* source() const { return m_source.get(); }
427 unsigned sourceOffset() const { return m_sourceOffset; }
429 size_t numberOfJumpTargets() const { return m_jumpTargets.size(); }
430 void addJumpTarget(unsigned jumpTarget) { m_jumpTargets.append(jumpTarget); }
431 unsigned jumpTarget(int index) const { return m_jumpTargets[index]; }
432 unsigned lastJumpTarget() const { return m_jumpTargets.last(); }
434 void createActivation(CallFrame*);
436 #if ENABLE(INTERPRETER)
437 void addPropertyAccessInstruction(unsigned propertyAccessInstruction) { m_propertyAccessInstructions.append(propertyAccessInstruction); }
438 void addGlobalResolveInstruction(unsigned globalResolveInstruction) { m_globalResolveInstructions.append(globalResolveInstruction); }
439 bool hasGlobalResolveInstructionAtBytecodeOffset(unsigned bytecodeOffset);
442 size_t numberOfStructureStubInfos() const { return m_structureStubInfos.size(); }
443 void addStructureStubInfo(const StructureStubInfo& stubInfo) { m_structureStubInfos.append(stubInfo); }
444 StructureStubInfo& structureStubInfo(int index) { return m_structureStubInfos[index]; }
446 void addGlobalResolveInfo(unsigned globalResolveInstruction) { m_globalResolveInfos.append(GlobalResolveInfo(globalResolveInstruction)); }
447 GlobalResolveInfo& globalResolveInfo(int index) { return m_globalResolveInfos[index]; }
448 bool hasGlobalResolveInfoAtBytecodeOffset(unsigned bytecodeOffset);
450 size_t numberOfCallLinkInfos() const { return m_callLinkInfos.size(); }
451 void addCallLinkInfo() { m_callLinkInfos.append(CallLinkInfo()); }
452 CallLinkInfo& callLinkInfo(int index) { return m_callLinkInfos[index]; }
454 void addMethodCallLinkInfos(unsigned n) { m_methodCallLinkInfos.grow(n); }
455 MethodCallLinkInfo& methodCallLinkInfo(int index) { return m_methodCallLinkInfos[index]; }
457 void addFunctionRegisterInfo(unsigned bytecodeOffset, int functionIndex) { createRareDataIfNecessary(); m_rareData->m_functionRegisterInfos.append(FunctionRegisterInfo(bytecodeOffset, functionIndex)); }
460 // Exception handling support
462 size_t numberOfExceptionHandlers() const { return m_rareData ? m_rareData->m_exceptionHandlers.size() : 0; }
463 void addExceptionHandler(const HandlerInfo& hanler) { createRareDataIfNecessary(); return m_rareData->m_exceptionHandlers.append(hanler); }
464 HandlerInfo& exceptionHandler(int index) { ASSERT(m_rareData); return m_rareData->m_exceptionHandlers[index]; }
466 bool hasExceptionInfo() const { return m_exceptionInfo; }
467 void clearExceptionInfo() { m_exceptionInfo.clear(); }
468 PassOwnPtr<ExceptionInfo> extractExceptionInfo();
470 void addExpressionInfo(const ExpressionRangeInfo& expressionInfo) { ASSERT(m_exceptionInfo); m_exceptionInfo->m_expressionInfo.append(expressionInfo); }
471 void addGetByIdExceptionInfo(const GetByIdExceptionInfo& info) { ASSERT(m_exceptionInfo); m_exceptionInfo->m_getByIdExceptionInfo.append(info); }
473 size_t numberOfLineInfos() const { ASSERT(m_exceptionInfo); return m_exceptionInfo->m_lineInfo.size(); }
474 void addLineInfo(const LineInfo& lineInfo) { ASSERT(m_exceptionInfo); m_exceptionInfo->m_lineInfo.append(lineInfo); }
475 LineInfo& lastLineInfo() { ASSERT(m_exceptionInfo); return m_exceptionInfo->m_lineInfo.last(); }
478 Vector<CallReturnOffsetToBytecodeOffset>& callReturnIndexVector() { ASSERT(m_exceptionInfo); return m_exceptionInfo->m_callReturnIndexVector; }
483 size_t numberOfIdentifiers() const { return m_identifiers.size(); }
484 void addIdentifier(const Identifier& i) { return m_identifiers.append(i); }
485 Identifier& identifier(int index) { return m_identifiers[index]; }
487 size_t numberOfConstantRegisters() const { return m_constantRegisters.size(); }
488 void addConstantRegister(const Register& r) { return m_constantRegisters.append(r); }
489 Register& constantRegister(int index) { return m_constantRegisters[index - FirstConstantRegisterIndex]; }
490 ALWAYS_INLINE bool isConstantRegisterIndex(int index) const { return index >= FirstConstantRegisterIndex; }
491 ALWAYS_INLINE JSValue getConstant(int index) const { return m_constantRegisters[index - FirstConstantRegisterIndex].jsValue(); }
493 unsigned addFunctionDecl(NonNullPassRefPtr<FunctionExecutable> n) { unsigned size = m_functionDecls.size(); m_functionDecls.append(n); return size; }
494 FunctionExecutable* functionDecl(int index) { return m_functionDecls[index].get(); }
495 int numberOfFunctionDecls() { return m_functionDecls.size(); }
496 unsigned addFunctionExpr(NonNullPassRefPtr<FunctionExecutable> n) { unsigned size = m_functionExprs.size(); m_functionExprs.append(n); return size; }
497 FunctionExecutable* functionExpr(int index) { return m_functionExprs[index].get(); }
499 unsigned addRegExp(RegExp* r) { createRareDataIfNecessary(); unsigned size = m_rareData->m_regexps.size(); m_rareData->m_regexps.append(r); return size; }
500 RegExp* regexp(int index) const { ASSERT(m_rareData); return m_rareData->m_regexps[index].get(); }
502 JSGlobalObject* globalObject() { return m_globalObject; }
506 size_t numberOfImmediateSwitchJumpTables() const { return m_rareData ? m_rareData->m_immediateSwitchJumpTables.size() : 0; }
507 SimpleJumpTable& addImmediateSwitchJumpTable() { createRareDataIfNecessary(); m_rareData->m_immediateSwitchJumpTables.append(SimpleJumpTable()); return m_rareData->m_immediateSwitchJumpTables.last(); }
508 SimpleJumpTable& immediateSwitchJumpTable(int tableIndex) { ASSERT(m_rareData); return m_rareData->m_immediateSwitchJumpTables[tableIndex]; }
510 size_t numberOfCharacterSwitchJumpTables() const { return m_rareData ? m_rareData->m_characterSwitchJumpTables.size() : 0; }
511 SimpleJumpTable& addCharacterSwitchJumpTable() { createRareDataIfNecessary(); m_rareData->m_characterSwitchJumpTables.append(SimpleJumpTable()); return m_rareData->m_characterSwitchJumpTables.last(); }
512 SimpleJumpTable& characterSwitchJumpTable(int tableIndex) { ASSERT(m_rareData); return m_rareData->m_characterSwitchJumpTables[tableIndex]; }
514 size_t numberOfStringSwitchJumpTables() const { return m_rareData ? m_rareData->m_stringSwitchJumpTables.size() : 0; }
515 StringJumpTable& addStringSwitchJumpTable() { createRareDataIfNecessary(); m_rareData->m_stringSwitchJumpTables.append(StringJumpTable()); return m_rareData->m_stringSwitchJumpTables.last(); }
516 StringJumpTable& stringSwitchJumpTable(int tableIndex) { ASSERT(m_rareData); return m_rareData->m_stringSwitchJumpTables[tableIndex]; }
519 SymbolTable* symbolTable() { return m_symbolTable; }
520 SharedSymbolTable* sharedSymbolTable() { ASSERT(m_codeType == FunctionCode); return static_cast<SharedSymbolTable*>(m_symbolTable); }
522 EvalCodeCache& evalCodeCache() { createRareDataIfNecessary(); return m_rareData->m_evalCodeCache; }
526 // FIXME: Make these remaining members private.
528 int m_numCalleeRegisters;
530 int m_numCapturedVars;
532 bool m_isConstructor;
535 #if !defined(NDEBUG) || ENABLE(OPCODE_SAMPLING)
536 void dump(ExecState*, const Vector<Instruction>::const_iterator& begin, Vector<Instruction>::const_iterator&) const;
538 CString registerName(ExecState*, int r) const;
539 void printUnaryOp(ExecState*, int location, Vector<Instruction>::const_iterator&, const char* op) const;
540 void printBinaryOp(ExecState*, int location, Vector<Instruction>::const_iterator&, const char* op) const;
541 void printConditionalJump(ExecState*, const Vector<Instruction>::const_iterator&, Vector<Instruction>::const_iterator&, int location, const char* op) const;
542 void printGetByIdOp(ExecState*, int location, Vector<Instruction>::const_iterator&, const char* op) const;
543 void printPutByIdOp(ExecState*, int location, Vector<Instruction>::const_iterator&, const char* op) const;
546 bool reparseForExceptionInfoIfNecessary(CallFrame*) WARN_UNUSED_RETURN;
548 void createRareDataIfNecessary()
551 m_rareData = adoptPtr(new RareData);
554 ScriptExecutable* m_ownerExecutable;
555 JSGlobalData* m_globalData;
557 Vector<Instruction> m_instructions;
559 unsigned m_instructionCount;
563 int m_argumentsRegister;
564 int m_activationRegister;
566 bool m_needsFullScopeChain;
568 bool m_isNumericCompareFunction;
573 RefPtr<SourceProvider> m_source;
574 unsigned m_sourceOffset;
576 #if ENABLE(INTERPRETER)
577 Vector<unsigned> m_propertyAccessInstructions;
578 Vector<unsigned> m_globalResolveInstructions;
581 Vector<StructureStubInfo> m_structureStubInfos;
582 Vector<GlobalResolveInfo> m_globalResolveInfos;
583 Vector<CallLinkInfo> m_callLinkInfos;
584 Vector<MethodCallLinkInfo> m_methodCallLinkInfos;
585 Vector<CallLinkInfo*> m_linkedCallerList;
588 Vector<unsigned> m_jumpTargets;
591 Vector<Identifier> m_identifiers;
592 Vector<Register> m_constantRegisters;
593 Vector<RefPtr<FunctionExecutable> > m_functionDecls;
594 Vector<RefPtr<FunctionExecutable> > m_functionExprs;
596 SymbolTable* m_symbolTable;
598 OwnPtr<ExceptionInfo> m_exceptionInfo;
600 struct RareData : FastAllocBase {
601 Vector<HandlerInfo> m_exceptionHandlers;
604 Vector<RefPtr<RegExp> > m_regexps;
607 Vector<SimpleJumpTable> m_immediateSwitchJumpTables;
608 Vector<SimpleJumpTable> m_characterSwitchJumpTables;
609 Vector<StringJumpTable> m_stringSwitchJumpTables;
611 EvalCodeCache m_evalCodeCache;
614 Vector<FunctionRegisterInfo> m_functionRegisterInfos;
617 OwnPtr<RareData> m_rareData;
620 // Program code is not marked by any function, so we make the global object
621 // responsible for marking it.
623 class GlobalCodeBlock : public CodeBlock {
625 GlobalCodeBlock(ScriptExecutable* ownerExecutable, CodeType codeType, JSGlobalObject* globalObject, PassRefPtr<SourceProvider> sourceProvider, unsigned sourceOffset)
626 : CodeBlock(ownerExecutable, codeType, globalObject, sourceProvider, sourceOffset, &m_unsharedSymbolTable, false)
628 m_globalObject->codeBlocks().add(this);
634 m_globalObject->codeBlocks().remove(this);
637 void clearGlobalObject() { m_globalObject = 0; }
640 SymbolTable m_unsharedSymbolTable;
643 class ProgramCodeBlock : public GlobalCodeBlock {
645 ProgramCodeBlock(ProgramExecutable* ownerExecutable, CodeType codeType, JSGlobalObject* globalObject, PassRefPtr<SourceProvider> sourceProvider)
646 : GlobalCodeBlock(ownerExecutable, codeType, globalObject, sourceProvider, 0)
651 class EvalCodeBlock : public GlobalCodeBlock {
653 EvalCodeBlock(EvalExecutable* ownerExecutable, JSGlobalObject* globalObject, PassRefPtr<SourceProvider> sourceProvider, int baseScopeDepth)
654 : GlobalCodeBlock(ownerExecutable, EvalCode, globalObject, sourceProvider, 0)
655 , m_baseScopeDepth(baseScopeDepth)
659 int baseScopeDepth() const { return m_baseScopeDepth; }
661 const Identifier& variable(unsigned index) { return m_variables[index]; }
662 unsigned numVariables() { return m_variables.size(); }
663 void adoptVariables(Vector<Identifier>& variables)
665 ASSERT(m_variables.isEmpty());
666 m_variables.swap(variables);
670 int m_baseScopeDepth;
671 Vector<Identifier> m_variables;
674 class FunctionCodeBlock : public CodeBlock {
676 // Rather than using the usual RefCounted::create idiom for SharedSymbolTable we just use new
677 // as we need to initialise the CodeBlock before we could initialise any RefPtr to hold the shared
678 // symbol table, so we just pass as a raw pointer with a ref count of 1. We then manually deref
679 // in the destructor.
680 FunctionCodeBlock(FunctionExecutable* ownerExecutable, CodeType codeType, JSGlobalObject* globalObject, PassRefPtr<SourceProvider> sourceProvider, unsigned sourceOffset, bool isConstructor)
681 : CodeBlock(ownerExecutable, codeType, globalObject, sourceProvider, sourceOffset, SharedSymbolTable::create().leakRef(), isConstructor)
686 sharedSymbolTable()->deref();
690 inline PassOwnPtr<ExceptionInfo> CodeBlock::extractExceptionInfo()
692 ASSERT(m_exceptionInfo);
693 return m_exceptionInfo.release();
696 inline Register& ExecState::r(int index)
698 CodeBlock* codeBlock = this->codeBlock();
699 if (codeBlock->isConstantRegisterIndex(index))
700 return codeBlock->constantRegister(index);
706 #endif // CodeBlock_h