X-Git-Url: https://git.saurik.com/apple/javascriptcore.git/blobdiff_plain/4e4e5a6f2694187498445a6ac6f1634ce8141119..14957cd040308e3eeec43d26bae5d76da13fcd85:/bytecode/CodeBlock.h?ds=sidebyside diff --git a/bytecode/CodeBlock.h b/bytecode/CodeBlock.h index 63d9b8a..7aa356e 100644 --- a/bytecode/CodeBlock.h +++ b/bytecode/CodeBlock.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008, 2009 Apple Inc. All rights reserved. + * Copyright (C) 2008, 2009, 2010 Apple Inc. All rights reserved. * Copyright (C) 2008 Cameron Zwarich * * Redistribution and use in source and binary forms, with or without @@ -33,12 +33,14 @@ #include "EvalCodeCache.h" #include "Instruction.h" #include "JITCode.h" +#include "JITWriteBarrier.h" #include "JSGlobalObject.h" #include "JumpTable.h" #include "Nodes.h" -#include "RegExp.h" +#include "RegExpObject.h" #include "UString.h" #include +#include #include #include @@ -46,8 +48,8 @@ #include "StructureStubInfo.h" #endif -// Register numbers used in bytecode operations have different meaning accoring to their ranges: -// 0x80000000-0xFFFFFFFF Negative indicies from the CallFrame pointer are entries in the call frame, see RegisterFile.h. +// Register numbers used in bytecode operations have different meaning according to their ranges: +// 0x80000000-0xFFFFFFFF Negative indices from the CallFrame pointer are entries in the call frame, see RegisterFile.h. // 0x00000000-0x3FFFFFFF Forwards indices from the CallFrame pointer are local vars and temporaries with the function's callframe. // 0x40000000-0x7FFFFFFF Positive indices from 0x40000000 specify entries in the constant pool on the CodeBlock. static const int FirstConstantRegisterIndex = 0x40000000; @@ -62,6 +64,8 @@ namespace JSC { enum CodeType { GlobalCode, EvalCode, FunctionCode }; + inline int unmodifiedArgumentsRegister(int argumentsRegister) { return argumentsRegister - 1; } + static ALWAYS_INLINE int missingThisObjectMarker() { return std::numeric_limits::max(); } struct HandlerInfo { @@ -90,34 +94,27 @@ namespace JSC { int32_t lineNumber; }; - // Both op_construct and op_instanceof require a use of op_get_by_id to get - // the prototype property from an object. The exception messages for exceptions - // thrown by these instances op_get_by_id need to reflect this. - struct GetByIdExceptionInfo { - unsigned bytecodeOffset : 31; - bool isOpConstruct : 1; - }; - #if ENABLE(JIT) struct CallLinkInfo { CallLinkInfo() - : callee(0) - , position(0) - , hasSeenShouldRepatch(0) + : hasSeenShouldRepatch(false) + , isCall(false) { } - unsigned bytecodeIndex; CodeLocationNearCall callReturnLocation; CodeLocationDataLabelPtr hotPathBegin; CodeLocationNearCall hotPathOther; - CodeBlock* ownerCodeBlock; - CodeBlock* callee; - unsigned position : 31; - unsigned hasSeenShouldRepatch : 1; - - void setUnlinked() { callee = 0; } + JITWriteBarrier callee; + bool hasSeenShouldRepatch : 1; + bool isCall : 1; + bool isLinked() { return callee; } + void unlink() + { + hasSeenShouldRepatch = false; + callee.clear(); + } bool seenOnce() { @@ -132,15 +129,13 @@ namespace JSC { struct MethodCallLinkInfo { MethodCallLinkInfo() - : cachedStructure(0) - , cachedPrototypeStructure(0) { } bool seenOnce() { ASSERT(!cachedStructure); - return cachedPrototypeStructure; + return cachedPrototypeStructure.isFlagged(); } void setSeen() @@ -152,35 +147,26 @@ namespace JSC { // - Once this transition has been taken once, cachedStructure is // null and cachedPrototypeStructure is set to a nun-null value. // - Once the call is linked both structures are set to non-null values. - cachedPrototypeStructure = (Structure*)1; + cachedPrototypeStructure.setFlagOnBarrier(); } CodeLocationCall callReturnLocation; - CodeLocationDataLabelPtr structureLabel; - Structure* cachedStructure; - Structure* cachedPrototypeStructure; - }; - - struct FunctionRegisterInfo { - FunctionRegisterInfo(unsigned bytecodeOffset, int functionRegisterIndex) - : bytecodeOffset(bytecodeOffset) - , functionRegisterIndex(functionRegisterIndex) - { - } - - unsigned bytecodeOffset; - int functionRegisterIndex; + JITWriteBarrier cachedStructure; + JITWriteBarrier cachedPrototypeStructure; + // We'd like this to actually be JSFunction, but InternalFunction and JSFunction + // don't have a common parent class and we allow specialisation on both + JITWriteBarrier cachedFunction; + JITWriteBarrier cachedPrototype; }; struct GlobalResolveInfo { GlobalResolveInfo(unsigned bytecodeOffset) - : structure(0) - , offset(0) + : offset(0) , bytecodeOffset(bytecodeOffset) { } - Structure* structure; + WriteBarrier structure; unsigned offset; unsigned bytecodeOffset; }; @@ -189,18 +175,18 @@ namespace JSC { // (given as an offset in bytes into the JIT code) back to // the bytecode index of the corresponding bytecode operation. // This is then used to look up the corresponding handler. - struct CallReturnOffsetToBytecodeIndex { - CallReturnOffsetToBytecodeIndex(unsigned callReturnOffset, unsigned bytecodeIndex) + struct CallReturnOffsetToBytecodeOffset { + CallReturnOffsetToBytecodeOffset(unsigned callReturnOffset, unsigned bytecodeOffset) : callReturnOffset(callReturnOffset) - , bytecodeIndex(bytecodeIndex) + , bytecodeOffset(bytecodeOffset) { } unsigned callReturnOffset; - unsigned bytecodeIndex; + unsigned bytecodeOffset; }; - // valueAtPosition helpers for the binaryChop algorithm below. + // valueAtPosition helpers for the binarySearch algorithm. inline void* getStructureStubInfoReturnLocation(StructureStubInfo* structureStubInfo) { @@ -217,71 +203,25 @@ namespace JSC { return methodCallLinkInfo->callReturnLocation.executableAddress(); } - inline unsigned getCallReturnOffset(CallReturnOffsetToBytecodeIndex* pc) + inline unsigned getCallReturnOffset(CallReturnOffsetToBytecodeOffset* pc) { return pc->callReturnOffset; } - - // Binary chop algorithm, calls valueAtPosition on pre-sorted elements in array, - // compares result with key (KeyTypes should be comparable with '--', '<', '>'). - // Optimized for cases where the array contains the key, checked by assertions. - template - inline ArrayType* binaryChop(ArrayType* array, size_t size, KeyType key) - { - // The array must contain at least one element (pre-condition, array does conatin key). - // If the array only contains one element, no need to do the comparison. - while (size > 1) { - // Pick an element to check, half way through the array, and read the value. - int pos = (size - 1) >> 1; - KeyType val = valueAtPosition(&array[pos]); - - // If the key matches, success! - if (val == key) - return &array[pos]; - // The item we are looking for is smaller than the item being check; reduce the value of 'size', - // chopping off the right hand half of the array. - else if (key < val) - size = pos; - // Discard all values in the left hand half of the array, up to and including the item at pos. - else { - size -= (pos + 1); - array += (pos + 1); - } - - // 'size' should never reach zero. - ASSERT(size); - } - - // If we reach this point we've chopped down to one element, no need to check it matches - ASSERT(size == 1); - ASSERT(key == valueAtPosition(&array[0])); - return &array[0]; - } -#endif - - struct ExceptionInfo : FastAllocBase { - Vector m_expressionInfo; - Vector m_lineInfo; - Vector m_getByIdExceptionInfo; - -#if ENABLE(JIT) - Vector m_callReturnIndexVector; #endif - }; - class CodeBlock : public FastAllocBase { + class CodeBlock { + WTF_MAKE_FAST_ALLOCATED; friend class JIT; protected: - CodeBlock(ScriptExecutable* ownerExecutable, CodeType, PassRefPtr, unsigned sourceOffset, SymbolTable* symbolTable); + CodeBlock(ScriptExecutable* ownerExecutable, CodeType, JSGlobalObject*, PassRefPtr, unsigned sourceOffset, SymbolTable* symbolTable, bool isConstructor); + + WriteBarrier m_globalObject; + Heap* m_heap; + public: virtual ~CodeBlock(); - void markAggregate(MarkStack&); - void refStructures(Instruction* vPC) const; - void derefStructures(Instruction* vPC) const; -#if ENABLE(JIT_OPTIMIZE_CALL) - void unlinkCallers(); -#endif + void visitAggregate(SlotVisitor&); static void dumpStatistics(); @@ -291,9 +231,11 @@ namespace JSC { void printStructure(const char* name, const Instruction*, int operand) const; #endif + bool isStrictMode() const { return m_isStrictMode; } + inline bool isKnownNotImmediate(int index) { - if (index == m_thisRegister) + if (index == m_thisRegister && !m_isStrictMode) return true; if (isConstantRegisterIndex(index)) @@ -308,55 +250,41 @@ namespace JSC { } HandlerInfo* handlerForBytecodeOffset(unsigned bytecodeOffset); - int lineNumberForBytecodeOffset(CallFrame*, unsigned bytecodeOffset); - int expressionRangeForBytecodeOffset(CallFrame*, unsigned bytecodeOffset, int& divot, int& startOffset, int& endOffset); - bool getByIdExceptionInfoForBytecodeOffset(CallFrame*, unsigned bytecodeOffset, OpcodeID&); + int lineNumberForBytecodeOffset(unsigned bytecodeOffset); + void expressionRangeForBytecodeOffset(unsigned bytecodeOffset, int& divot, int& startOffset, int& endOffset); #if ENABLE(JIT) - void addCaller(CallLinkInfo* caller) - { - caller->callee = this; - caller->position = m_linkedCallerList.size(); - m_linkedCallerList.append(caller); - } - - void removeCaller(CallLinkInfo* caller) - { - unsigned pos = caller->position; - unsigned lastPos = m_linkedCallerList.size() - 1; - - if (pos != lastPos) { - m_linkedCallerList[pos] = m_linkedCallerList[lastPos]; - m_linkedCallerList[pos]->position = pos; - } - m_linkedCallerList.shrink(lastPos); - } StructureStubInfo& getStubInfo(ReturnAddressPtr returnAddress) { - return *(binaryChop(m_structureStubInfos.begin(), m_structureStubInfos.size(), returnAddress.value())); + return *(binarySearch(m_structureStubInfos.begin(), m_structureStubInfos.size(), returnAddress.value())); } CallLinkInfo& getCallLinkInfo(ReturnAddressPtr returnAddress) { - return *(binaryChop(m_callLinkInfos.begin(), m_callLinkInfos.size(), returnAddress.value())); + return *(binarySearch(m_callLinkInfos.begin(), m_callLinkInfos.size(), returnAddress.value())); } MethodCallLinkInfo& getMethodCallLinkInfo(ReturnAddressPtr returnAddress) { - return *(binaryChop(m_methodCallLinkInfos.begin(), m_methodCallLinkInfos.size(), returnAddress.value())); + return *(binarySearch(m_methodCallLinkInfos.begin(), m_methodCallLinkInfos.size(), returnAddress.value())); } - unsigned getBytecodeIndex(CallFrame* callFrame, ReturnAddressPtr returnAddress) + unsigned bytecodeOffset(ReturnAddressPtr returnAddress) { - reparseForExceptionInfoIfNecessary(callFrame); - return binaryChop(callReturnIndexVector().begin(), callReturnIndexVector().size(), ownerExecutable()->generatedJITCode().offsetOf(returnAddress.value()))->bytecodeIndex; + if (!m_rareData) + return 1; + Vector& callIndices = m_rareData->m_callReturnIndexVector; + if (!callIndices.size()) + return 1; + return binarySearch(callIndices.begin(), callIndices.size(), getJITCode().offsetOf(returnAddress.value()))->bytecodeOffset; } - - bool functionRegisterForBytecodeOffset(unsigned bytecodeOffset, int& functionRegisterIndex); + + void unlinkCalls(); #endif + #if ENABLE(INTERPRETER) - unsigned bytecodeOffset(CallFrame*, Instruction* returnAddress) + unsigned bytecodeOffset(Instruction* returnAddress) { return static_cast(returnAddress) - instructions().begin(); } @@ -374,11 +302,11 @@ namespace JSC { #endif #if ENABLE(JIT) - JITCode& getJITCode() { return ownerExecutable()->generatedJITCode(); } - ExecutablePool* executablePool() { return ownerExecutable()->getExecutablePool(); } + JITCode& getJITCode() { return m_isConstructor ? ownerExecutable()->generatedJITCodeForConstruct() : ownerExecutable()->generatedJITCodeForCall(); } + ExecutablePool* executablePool() { return getJITCode().getExecutablePool(); } #endif - ScriptExecutable* ownerExecutable() const { return m_ownerExecutable; } + ScriptExecutable* ownerExecutable() const { return m_ownerExecutable.get(); } void setGlobalData(JSGlobalData* globalData) { m_globalData = globalData; } @@ -389,8 +317,28 @@ namespace JSC { bool needsFullScopeChain() const { return m_needsFullScopeChain; } void setUsesEval(bool usesEval) { m_usesEval = usesEval; } bool usesEval() const { return m_usesEval; } - void setUsesArguments(bool usesArguments) { m_usesArguments = usesArguments; } - bool usesArguments() const { return m_usesArguments; } + + void setArgumentsRegister(int argumentsRegister) + { + ASSERT(argumentsRegister != -1); + m_argumentsRegister = argumentsRegister; + ASSERT(usesArguments()); + } + int argumentsRegister() + { + ASSERT(usesArguments()); + return m_argumentsRegister; + } + void setActivationRegister(int activationRegister) + { + m_activationRegister = activationRegister; + } + int activationRegister() + { + ASSERT(needsFullScopeChain()); + return m_activationRegister; + } + bool usesArguments() const { return m_argumentsRegister != -1; } CodeType codeType() const { return m_codeType; } @@ -402,17 +350,37 @@ namespace JSC { unsigned jumpTarget(int index) const { return m_jumpTargets[index]; } unsigned lastJumpTarget() const { return m_jumpTargets.last(); } + void createActivation(CallFrame*); + + void clearEvalCache(); + #if ENABLE(INTERPRETER) - void addPropertyAccessInstruction(unsigned propertyAccessInstruction) { m_propertyAccessInstructions.append(propertyAccessInstruction); } - void addGlobalResolveInstruction(unsigned globalResolveInstruction) { m_globalResolveInstructions.append(globalResolveInstruction); } + void addPropertyAccessInstruction(unsigned propertyAccessInstruction) + { + if (!m_globalData->canUseJIT()) + m_propertyAccessInstructions.append(propertyAccessInstruction); + } + void addGlobalResolveInstruction(unsigned globalResolveInstruction) + { + if (!m_globalData->canUseJIT()) + m_globalResolveInstructions.append(globalResolveInstruction); + } bool hasGlobalResolveInstructionAtBytecodeOffset(unsigned bytecodeOffset); #endif #if ENABLE(JIT) size_t numberOfStructureStubInfos() const { return m_structureStubInfos.size(); } - void addStructureStubInfo(const StructureStubInfo& stubInfo) { m_structureStubInfos.append(stubInfo); } + void addStructureStubInfo(const StructureStubInfo& stubInfo) + { + if (m_globalData->canUseJIT()) + m_structureStubInfos.append(stubInfo); + } StructureStubInfo& structureStubInfo(int index) { return m_structureStubInfos[index]; } - void addGlobalResolveInfo(unsigned globalResolveInstruction) { m_globalResolveInfos.append(GlobalResolveInfo(globalResolveInstruction)); } + void addGlobalResolveInfo(unsigned globalResolveInstruction) + { + if (m_globalData->canUseJIT()) + m_globalResolveInfos.append(GlobalResolveInfo(globalResolveInstruction)); + } GlobalResolveInfo& globalResolveInfo(int index) { return m_globalResolveInfos[index]; } bool hasGlobalResolveInfoAtBytecodeOffset(unsigned bytecodeOffset); @@ -420,11 +388,17 @@ namespace JSC { void addCallLinkInfo() { m_callLinkInfos.append(CallLinkInfo()); } CallLinkInfo& callLinkInfo(int index) { return m_callLinkInfos[index]; } - void addMethodCallLinkInfos(unsigned n) { m_methodCallLinkInfos.grow(n); } + void addMethodCallLinkInfos(unsigned n) { ASSERT(m_globalData->canUseJIT()); m_methodCallLinkInfos.grow(n); } MethodCallLinkInfo& methodCallLinkInfo(int index) { return m_methodCallLinkInfos[index]; } - - void addFunctionRegisterInfo(unsigned bytecodeOffset, int functionIndex) { createRareDataIfNecessary(); m_rareData->m_functionRegisterInfos.append(FunctionRegisterInfo(bytecodeOffset, functionIndex)); } #endif + unsigned globalResolveInfoCount() const + { +#if ENABLE(JIT) + if (m_globalData->canUseJIT()) + return m_globalResolveInfos.size(); +#endif + return 0; + } // Exception handling support @@ -432,19 +406,38 @@ namespace JSC { void addExceptionHandler(const HandlerInfo& hanler) { createRareDataIfNecessary(); return m_rareData->m_exceptionHandlers.append(hanler); } HandlerInfo& exceptionHandler(int index) { ASSERT(m_rareData); return m_rareData->m_exceptionHandlers[index]; } - bool hasExceptionInfo() const { return m_exceptionInfo; } - void clearExceptionInfo() { m_exceptionInfo.clear(); } - ExceptionInfo* extractExceptionInfo() { ASSERT(m_exceptionInfo); return m_exceptionInfo.release(); } + void addExpressionInfo(const ExpressionRangeInfo& expressionInfo) + { + createRareDataIfNecessary(); + m_rareData->m_expressionInfo.append(expressionInfo); + } - void addExpressionInfo(const ExpressionRangeInfo& expressionInfo) { ASSERT(m_exceptionInfo); m_exceptionInfo->m_expressionInfo.append(expressionInfo); } - void addGetByIdExceptionInfo(const GetByIdExceptionInfo& info) { ASSERT(m_exceptionInfo); m_exceptionInfo->m_getByIdExceptionInfo.append(info); } + void addLineInfo(unsigned bytecodeOffset, int lineNo) + { + createRareDataIfNecessary(); + Vector& lineInfo = m_rareData->m_lineInfo; + if (!lineInfo.size() || lineInfo.last().lineNumber != lineNo) { + LineInfo info = { bytecodeOffset, lineNo }; + lineInfo.append(info); + } + } - size_t numberOfLineInfos() const { ASSERT(m_exceptionInfo); return m_exceptionInfo->m_lineInfo.size(); } - void addLineInfo(const LineInfo& lineInfo) { ASSERT(m_exceptionInfo); m_exceptionInfo->m_lineInfo.append(lineInfo); } - LineInfo& lastLineInfo() { ASSERT(m_exceptionInfo); return m_exceptionInfo->m_lineInfo.last(); } + bool hasExpressionInfo() { return m_rareData && m_rareData->m_expressionInfo.size(); } + bool hasLineInfo() { return m_rareData && m_rareData->m_lineInfo.size(); } + // We only generate exception handling info if the user is debugging + // (and may want line number info), or if the function contains exception handler. + bool needsCallReturnIndices() + { + return m_rareData && + (m_rareData->m_expressionInfo.size() || m_rareData->m_lineInfo.size() || m_rareData->m_exceptionHandlers.size()); + } #if ENABLE(JIT) - Vector& callReturnIndexVector() { ASSERT(m_exceptionInfo); return m_exceptionInfo->m_callReturnIndexVector; } + Vector& callReturnIndexVector() + { + createRareDataIfNecessary(); + return m_rareData->m_callReturnIndexVector; + } #endif // Constant Pool @@ -454,20 +447,57 @@ namespace JSC { Identifier& identifier(int index) { return m_identifiers[index]; } size_t numberOfConstantRegisters() const { return m_constantRegisters.size(); } - void addConstantRegister(const Register& r) { return m_constantRegisters.append(r); } - Register& constantRegister(int index) { return m_constantRegisters[index - FirstConstantRegisterIndex]; } + void addConstant(JSValue v) + { + m_constantRegisters.append(WriteBarrier()); + m_constantRegisters.last().set(m_globalObject->globalData(), m_ownerExecutable.get(), v); + } + WriteBarrier& constantRegister(int index) { return m_constantRegisters[index - FirstConstantRegisterIndex]; } ALWAYS_INLINE bool isConstantRegisterIndex(int index) const { return index >= FirstConstantRegisterIndex; } - ALWAYS_INLINE JSValue getConstant(int index) const { return m_constantRegisters[index - FirstConstantRegisterIndex].jsValue(); } + ALWAYS_INLINE JSValue getConstant(int index) const { return m_constantRegisters[index - FirstConstantRegisterIndex].get(); } - unsigned addFunctionDecl(NonNullPassRefPtr n) { unsigned size = m_functionDecls.size(); m_functionDecls.append(n); return size; } + unsigned addFunctionDecl(FunctionExecutable* n) + { + unsigned size = m_functionDecls.size(); + m_functionDecls.append(WriteBarrier()); + m_functionDecls.last().set(m_globalObject->globalData(), m_ownerExecutable.get(), n); + return size; + } FunctionExecutable* functionDecl(int index) { return m_functionDecls[index].get(); } int numberOfFunctionDecls() { return m_functionDecls.size(); } - unsigned addFunctionExpr(NonNullPassRefPtr n) { unsigned size = m_functionExprs.size(); m_functionExprs.append(n); return size; } + unsigned addFunctionExpr(FunctionExecutable* n) + { + unsigned size = m_functionExprs.size(); + m_functionExprs.append(WriteBarrier()); + m_functionExprs.last().set(m_globalObject->globalData(), m_ownerExecutable.get(), n); + return size; + } FunctionExecutable* functionExpr(int index) { return m_functionExprs[index].get(); } - unsigned addRegExp(RegExp* r) { createRareDataIfNecessary(); unsigned size = m_rareData->m_regexps.size(); m_rareData->m_regexps.append(r); return size; } + unsigned addRegExp(RegExp* r) + { + createRareDataIfNecessary(); + unsigned size = m_rareData->m_regexps.size(); + m_rareData->m_regexps.append(WriteBarrier(*m_globalData, ownerExecutable(), r)); + return size; + } RegExp* regexp(int index) const { ASSERT(m_rareData); return m_rareData->m_regexps[index].get(); } + unsigned addConstantBuffer(unsigned length) + { + createRareDataIfNecessary(); + unsigned size = m_rareData->m_constantBuffers.size(); + m_rareData->m_constantBuffers.append(Vector(length)); + return size; + } + + JSValue* constantBuffer(unsigned index) + { + ASSERT(m_rareData); + return m_rareData->m_constantBuffers[index].data(); + } + + JSGlobalObject* globalObject() { return m_globalObject.get(); } // Jump Tables @@ -495,7 +525,9 @@ namespace JSC { int m_numCalleeRegisters; int m_numVars; + int m_numCapturedVars; int m_numParameters; + bool m_isConstructor; private: #if !defined(NDEBUG) || ENABLE(OPCODE_SAMPLING) @@ -508,16 +540,15 @@ namespace JSC { void printGetByIdOp(ExecState*, int location, Vector::const_iterator&, const char* op) const; void printPutByIdOp(ExecState*, int location, Vector::const_iterator&, const char* op) const; #endif - - void reparseForExceptionInfoIfNecessary(CallFrame*); + void visitStructures(SlotVisitor&, Instruction* vPC) const; void createRareDataIfNecessary() { if (!m_rareData) - m_rareData.set(new RareData); + m_rareData = adoptPtr(new RareData); } - ScriptExecutable* m_ownerExecutable; + WriteBarrier m_ownerExecutable; JSGlobalData* m_globalData; Vector m_instructions; @@ -526,11 +557,13 @@ namespace JSC { #endif int m_thisRegister; + int m_argumentsRegister; + int m_activationRegister; bool m_needsFullScopeChain; bool m_usesEval; - bool m_usesArguments; bool m_isNumericCompareFunction; + bool m_isStrictMode; CodeType m_codeType; @@ -546,27 +579,30 @@ namespace JSC { Vector m_globalResolveInfos; Vector m_callLinkInfos; Vector m_methodCallLinkInfos; - Vector m_linkedCallerList; #endif Vector m_jumpTargets; // Constant Pool Vector m_identifiers; - Vector m_constantRegisters; - Vector > m_functionDecls; - Vector > m_functionExprs; + COMPILE_ASSERT(sizeof(Register) == sizeof(WriteBarrier), Register_must_be_same_size_as_WriteBarrier_Unknown); + Vector > m_constantRegisters; + Vector > m_functionDecls; + Vector > m_functionExprs; SymbolTable* m_symbolTable; - OwnPtr m_exceptionInfo; - - struct RareData : FastAllocBase { + struct RareData { + WTF_MAKE_FAST_ALLOCATED; + public: Vector m_exceptionHandlers; // Rare Constants - Vector > m_regexps; + Vector > m_regexps; + // Buffers used for large array literals + Vector > m_constantBuffers; + // Jump Tables Vector m_immediateSwitchJumpTables; Vector m_characterSwitchJumpTables; @@ -574,10 +610,17 @@ namespace JSC { EvalCodeCache m_evalCodeCache; + // Expression info - present if debugging. + Vector m_expressionInfo; + // Line info - present if profiling or debugging. + Vector m_lineInfo; #if ENABLE(JIT) - Vector m_functionRegisterInfos; + Vector m_callReturnIndexVector; #endif }; +#if COMPILER(MSVC) + friend void WTF::deleteOwnedPtr(RareData*); +#endif OwnPtr m_rareData; }; @@ -586,30 +629,19 @@ namespace JSC { class GlobalCodeBlock : public CodeBlock { public: - GlobalCodeBlock(ScriptExecutable* ownerExecutable, CodeType codeType, PassRefPtr sourceProvider, unsigned sourceOffset, JSGlobalObject* globalObject) - : CodeBlock(ownerExecutable, codeType, sourceProvider, sourceOffset, &m_unsharedSymbolTable) - , m_globalObject(globalObject) - { - m_globalObject->codeBlocks().add(this); - } - - ~GlobalCodeBlock() + GlobalCodeBlock(ScriptExecutable* ownerExecutable, CodeType codeType, JSGlobalObject* globalObject, PassRefPtr sourceProvider, unsigned sourceOffset) + : CodeBlock(ownerExecutable, codeType, globalObject, sourceProvider, sourceOffset, &m_unsharedSymbolTable, false) { - if (m_globalObject) - m_globalObject->codeBlocks().remove(this); } - void clearGlobalObject() { m_globalObject = 0; } - private: - JSGlobalObject* m_globalObject; // For program and eval nodes, the global object that marks the constant pool. SymbolTable m_unsharedSymbolTable; }; class ProgramCodeBlock : public GlobalCodeBlock { public: ProgramCodeBlock(ProgramExecutable* ownerExecutable, CodeType codeType, JSGlobalObject* globalObject, PassRefPtr sourceProvider) - : GlobalCodeBlock(ownerExecutable, codeType, sourceProvider, 0, globalObject) + : GlobalCodeBlock(ownerExecutable, codeType, globalObject, sourceProvider, 0) { } }; @@ -617,7 +649,7 @@ namespace JSC { class EvalCodeBlock : public GlobalCodeBlock { public: EvalCodeBlock(EvalExecutable* ownerExecutable, JSGlobalObject* globalObject, PassRefPtr sourceProvider, int baseScopeDepth) - : GlobalCodeBlock(ownerExecutable, EvalCode, sourceProvider, 0, globalObject) + : GlobalCodeBlock(ownerExecutable, EvalCode, globalObject, sourceProvider, 0) , m_baseScopeDepth(baseScopeDepth) { } @@ -643,8 +675,8 @@ namespace JSC { // as we need to initialise the CodeBlock before we could initialise any RefPtr to hold the shared // symbol table, so we just pass as a raw pointer with a ref count of 1. We then manually deref // in the destructor. - FunctionCodeBlock(FunctionExecutable* ownerExecutable, CodeType codeType, PassRefPtr sourceProvider, unsigned sourceOffset) - : CodeBlock(ownerExecutable, codeType, sourceProvider, sourceOffset, new SharedSymbolTable) + FunctionCodeBlock(FunctionExecutable* ownerExecutable, CodeType codeType, JSGlobalObject* globalObject, PassRefPtr sourceProvider, unsigned sourceOffset, bool isConstructor) + : CodeBlock(ownerExecutable, codeType, globalObject, sourceProvider, sourceOffset, SharedSymbolTable::create().leakRef(), isConstructor) { } ~FunctionCodeBlock() @@ -657,10 +689,16 @@ namespace JSC { { CodeBlock* codeBlock = this->codeBlock(); if (codeBlock->isConstantRegisterIndex(index)) - return codeBlock->constantRegister(index); + return *reinterpret_cast(&codeBlock->constantRegister(index)); return this[index]; } + inline Register& ExecState::uncheckedR(int index) + { + ASSERT(index < FirstConstantRegisterIndex); + return this[index]; + } + } // namespace JSC #endif // CodeBlock_h