summaryrefslogtreecommitdiffstats
path: root/JavaScriptCore/bytecode/CodeBlock.h
diff options
context:
space:
mode:
Diffstat (limited to 'JavaScriptCore/bytecode/CodeBlock.h')
-rw-r--r--JavaScriptCore/bytecode/CodeBlock.h226
1 files changed, 135 insertions, 91 deletions
diff --git a/JavaScriptCore/bytecode/CodeBlock.h b/JavaScriptCore/bytecode/CodeBlock.h
index eb874cc..7eca72a 100644
--- a/JavaScriptCore/bytecode/CodeBlock.h
+++ b/JavaScriptCore/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 <cwzwarich@uwaterloo.ca>
*
* Redistribution and use in source and binary forms, with or without
@@ -36,10 +36,10 @@
#include "JSGlobalObject.h"
#include "JumpTable.h"
#include "Nodes.h"
-#include "PtrAndFlags.h"
#include "RegExp.h"
#include "UString.h"
#include <wtf/FastAllocBase.h>
+#include <wtf/PassOwnPtr.h>
#include <wtf/RefPtr.h>
#include <wtf/Vector.h>
@@ -47,8 +47,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;
@@ -63,6 +63,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<int>::max(); }
struct HandlerInfo {
@@ -91,74 +93,66 @@ 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)
{
}
-
- unsigned bytecodeIndex;
+
CodeLocationNearCall callReturnLocation;
CodeLocationDataLabelPtr hotPathBegin;
CodeLocationNearCall hotPathOther;
- PtrAndFlags<CodeBlock, HasSeenShouldRepatch> ownerCodeBlock;
+ CodeBlock* ownerCodeBlock;
CodeBlock* callee;
- unsigned position;
+ unsigned position : 31;
+ unsigned hasSeenShouldRepatch : 1;
void setUnlinked() { callee = 0; }
bool isLinked() { return callee; }
bool seenOnce()
{
- return ownerCodeBlock.isFlagSet(hasSeenShouldRepatch);
+ return hasSeenShouldRepatch;
}
void setSeen()
{
- ownerCodeBlock.setFlag(hasSeenShouldRepatch);
+ hasSeenShouldRepatch = true;
}
};
struct MethodCallLinkInfo {
MethodCallLinkInfo()
: cachedStructure(0)
+ , cachedPrototypeStructure(0)
{
}
bool seenOnce()
{
- return cachedPrototypeStructure.isFlagSet(hasSeenShouldRepatch);
+ ASSERT(!cachedStructure);
+ return cachedPrototypeStructure;
}
void setSeen()
{
- cachedPrototypeStructure.setFlag(hasSeenShouldRepatch);
+ ASSERT(!cachedStructure && !cachedPrototypeStructure);
+ // We use the values of cachedStructure & cachedPrototypeStructure to indicate the
+ // current state.
+ // - In the initial state, both are null.
+ // - 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;
}
CodeLocationCall callReturnLocation;
CodeLocationDataLabelPtr structureLabel;
Structure* cachedStructure;
- PtrAndFlags<Structure, HasSeenShouldRepatch> cachedPrototypeStructure;
- };
-
- struct FunctionRegisterInfo {
- FunctionRegisterInfo(unsigned bytecodeOffset, int functionRegisterIndex)
- : bytecodeOffset(bytecodeOffset)
- , functionRegisterIndex(functionRegisterIndex)
- {
- }
-
- unsigned bytecodeOffset;
- int functionRegisterIndex;
+ Structure* cachedPrototypeStructure;
};
struct GlobalResolveInfo {
@@ -178,15 +172,15 @@ 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.
@@ -206,7 +200,7 @@ namespace JSC {
return methodCallLinkInfo->callReturnLocation.executableAddress();
}
- inline unsigned getCallReturnOffset(CallReturnOffsetToBytecodeIndex* pc)
+ inline unsigned getCallReturnOffset(CallReturnOffsetToBytecodeOffset* pc)
{
return pc->callReturnOffset;
}
@@ -248,20 +242,13 @@ namespace JSC {
}
#endif
- struct ExceptionInfo : FastAllocBase {
- Vector<ExpressionRangeInfo> m_expressionInfo;
- Vector<LineInfo> m_lineInfo;
- Vector<GetByIdExceptionInfo> m_getByIdExceptionInfo;
-
-#if ENABLE(JIT)
- Vector<CallReturnOffsetToBytecodeIndex> m_callReturnIndexVector;
-#endif
- };
-
class CodeBlock : public FastAllocBase {
friend class JIT;
protected:
- CodeBlock(ScriptExecutable* ownerExecutable, CodeType, PassRefPtr<SourceProvider>, unsigned sourceOffset, SymbolTable* symbolTable);
+ CodeBlock(ScriptExecutable* ownerExecutable, CodeType, JSGlobalObject*, PassRefPtr<SourceProvider>, unsigned sourceOffset, SymbolTable* symbolTable, bool isConstructor);
+
+ JSGlobalObject* m_globalObject;
+
public:
virtual ~CodeBlock();
@@ -280,9 +267,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))
@@ -297,9 +286,8 @@ 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)
@@ -336,13 +324,21 @@ namespace JSC {
return *(binaryChop<MethodCallLinkInfo, void*, getMethodCallLinkInfoReturnLocation>(m_methodCallLinkInfos.begin(), m_methodCallLinkInfos.size(), returnAddress.value()));
}
- unsigned getBytecodeIndex(CallFrame* callFrame, ReturnAddressPtr returnAddress)
+ unsigned bytecodeOffset(ReturnAddressPtr returnAddress)
{
- reparseForExceptionInfoIfNecessary(callFrame);
- return binaryChop<CallReturnOffsetToBytecodeIndex, unsigned, getCallReturnOffset>(callReturnIndexVector().begin(), callReturnIndexVector().size(), ownerExecutable()->generatedJITCode().offsetOf(returnAddress.value()))->bytecodeIndex;
+ if (!m_rareData)
+ return 1;
+ Vector<CallReturnOffsetToBytecodeOffset>& callIndices = m_rareData->m_callReturnIndexVector;
+ if (!callIndices.size())
+ return 1;
+ return binaryChop<CallReturnOffsetToBytecodeOffset, unsigned, getCallReturnOffset>(callIndices.begin(), callIndices.size(), getJITCode().offsetOf(returnAddress.value()))->bytecodeOffset;
+ }
+#endif
+#if ENABLE(INTERPRETER)
+ unsigned bytecodeOffset(Instruction* returnAddress)
+ {
+ return static_cast<Instruction*>(returnAddress) - instructions().begin();
}
-
- bool functionRegisterForBytecodeOffset(unsigned bytecodeOffset, int& functionRegisterIndex);
#endif
void setIsNumericCompareFunction(bool isNumericCompareFunction) { m_isNumericCompareFunction = isNumericCompareFunction; }
@@ -357,8 +353,8 @@ 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; }
@@ -372,8 +368,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; }
@@ -385,11 +401,14 @@ namespace JSC {
unsigned jumpTarget(int index) const { return m_jumpTargets[index]; }
unsigned lastJumpTarget() const { return m_jumpTargets.last(); }
-#if !ENABLE(JIT)
+ void createActivation(CallFrame*);
+
+#if ENABLE(INTERPRETER)
void addPropertyAccessInstruction(unsigned propertyAccessInstruction) { m_propertyAccessInstructions.append(propertyAccessInstruction); }
void addGlobalResolveInstruction(unsigned globalResolveInstruction) { m_globalResolveInstructions.append(globalResolveInstruction); }
bool hasGlobalResolveInstructionAtBytecodeOffset(unsigned bytecodeOffset);
-#else
+#endif
+#if ENABLE(JIT)
size_t numberOfStructureStubInfos() const { return m_structureStubInfos.size(); }
void addStructureStubInfo(const StructureStubInfo& stubInfo) { m_structureStubInfos.append(stubInfo); }
StructureStubInfo& structureStubInfo(int index) { return m_structureStubInfos[index]; }
@@ -404,8 +423,6 @@ namespace JSC {
void addMethodCallLinkInfos(unsigned n) { 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
// Exception handling support
@@ -414,19 +431,36 @@ 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>& 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(); }
+ bool needsCallReturnIndices()
+ {
+ return m_rareData &&
+ (m_rareData->m_expressionInfo.size() || m_rareData->m_lineInfo.size() || m_rareData->m_exceptionHandlers.size());
+ }
#if ENABLE(JIT)
- Vector<CallReturnOffsetToBytecodeIndex>& callReturnIndexVector() { ASSERT(m_exceptionInfo); return m_exceptionInfo->m_callReturnIndexVector; }
+ Vector<CallReturnOffsetToBytecodeOffset>& callReturnIndexVector()
+ {
+ createRareDataIfNecessary();
+ return m_rareData->m_callReturnIndexVector;
+ }
#endif
// Constant Pool
@@ -450,6 +484,7 @@ namespace JSC {
unsigned addRegExp(RegExp* r) { createRareDataIfNecessary(); unsigned size = m_rareData->m_regexps.size(); m_rareData->m_regexps.append(r); return size; }
RegExp* regexp(int index) const { ASSERT(m_rareData); return m_rareData->m_regexps[index].get(); }
+ JSGlobalObject* globalObject() { return m_globalObject; }
// Jump Tables
@@ -477,7 +512,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)
@@ -491,12 +528,10 @@ namespace JSC {
void printPutByIdOp(ExecState*, int location, Vector<Instruction>::const_iterator&, const char* op) const;
#endif
- void reparseForExceptionInfoIfNecessary(CallFrame*);
-
void createRareDataIfNecessary()
{
if (!m_rareData)
- m_rareData.set(new RareData);
+ m_rareData = adoptPtr(new RareData);
}
ScriptExecutable* m_ownerExecutable;
@@ -508,21 +543,24 @@ 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;
RefPtr<SourceProvider> m_source;
unsigned m_sourceOffset;
-#if !ENABLE(JIT)
+#if ENABLE(INTERPRETER)
Vector<unsigned> m_propertyAccessInstructions;
Vector<unsigned> m_globalResolveInstructions;
-#else
+#endif
+#if ENABLE(JIT)
Vector<StructureStubInfo> m_structureStubInfos;
Vector<GlobalResolveInfo> m_globalResolveInfos;
Vector<CallLinkInfo> m_callLinkInfos;
@@ -540,8 +578,6 @@ namespace JSC {
SymbolTable* m_symbolTable;
- OwnPtr<ExceptionInfo> m_exceptionInfo;
-
struct RareData : FastAllocBase {
Vector<HandlerInfo> m_exceptionHandlers;
@@ -555,8 +591,12 @@ namespace JSC {
EvalCodeCache m_evalCodeCache;
+ // Expression info - present if debugging.
+ Vector<ExpressionRangeInfo> m_expressionInfo;
+ // Line info - present if profiling or debugging.
+ Vector<LineInfo> m_lineInfo;
#if ENABLE(JIT)
- Vector<FunctionRegisterInfo> m_functionRegisterInfos;
+ Vector<CallReturnOffsetToBytecodeOffset> m_callReturnIndexVector;
#endif
};
OwnPtr<RareData> m_rareData;
@@ -567,9 +607,8 @@ namespace JSC {
class GlobalCodeBlock : public CodeBlock {
public:
- GlobalCodeBlock(ScriptExecutable* ownerExecutable, CodeType codeType, PassRefPtr<SourceProvider> sourceProvider, unsigned sourceOffset, JSGlobalObject* globalObject)
- : CodeBlock(ownerExecutable, codeType, sourceProvider, sourceOffset, &m_unsharedSymbolTable)
- , m_globalObject(globalObject)
+ GlobalCodeBlock(ScriptExecutable* ownerExecutable, CodeType codeType, JSGlobalObject* globalObject, PassRefPtr<SourceProvider> sourceProvider, unsigned sourceOffset)
+ : CodeBlock(ownerExecutable, codeType, globalObject, sourceProvider, sourceOffset, &m_unsharedSymbolTable, false)
{
m_globalObject->codeBlocks().add(this);
}
@@ -583,14 +622,13 @@ namespace JSC {
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> sourceProvider)
- : GlobalCodeBlock(ownerExecutable, codeType, sourceProvider, 0, globalObject)
+ : GlobalCodeBlock(ownerExecutable, codeType, globalObject, sourceProvider, 0)
{
}
};
@@ -598,7 +636,7 @@ namespace JSC {
class EvalCodeBlock : public GlobalCodeBlock {
public:
EvalCodeBlock(EvalExecutable* ownerExecutable, JSGlobalObject* globalObject, PassRefPtr<SourceProvider> sourceProvider, int baseScopeDepth)
- : GlobalCodeBlock(ownerExecutable, EvalCode, sourceProvider, 0, globalObject)
+ : GlobalCodeBlock(ownerExecutable, EvalCode, globalObject, sourceProvider, 0)
, m_baseScopeDepth(baseScopeDepth)
{
}
@@ -624,8 +662,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> sourceProvider, unsigned sourceOffset)
- : CodeBlock(ownerExecutable, codeType, sourceProvider, sourceOffset, new SharedSymbolTable)
+ FunctionCodeBlock(FunctionExecutable* ownerExecutable, CodeType codeType, JSGlobalObject* globalObject, PassRefPtr<SourceProvider> sourceProvider, unsigned sourceOffset, bool isConstructor)
+ : CodeBlock(ownerExecutable, codeType, globalObject, sourceProvider, sourceOffset, SharedSymbolTable::create().leakRef(), isConstructor)
{
}
~FunctionCodeBlock()
@@ -642,6 +680,12 @@ namespace JSC {
return this[index];
}
+ inline Register& ExecState::uncheckedR(int index)
+ {
+ ASSERT(index < FirstConstantRegisterIndex);
+ return this[index];
+ }
+
} // namespace JSC
#endif // CodeBlock_h