#ifndef CodeOrigin_h
#define CodeOrigin_h
#include "CodeBlockHash.h"
#include "CodeSpecializationKind.h"
#include "ValueRecovery.h"
#include "WriteBarrier.h"
#include <wtf/BitVector.h>
#include <wtf/PrintStream.h>
#include <wtf/StdLibExtras.h>
#include <wtf/Vector.h>
namespace JSC {
struct InlineCallFrame;
class ExecState;
class ExecutableBase;
class JSFunction;
struct CodeOrigin {
static const unsigned maximumBytecodeIndex = (1u << 29) - 1;
unsigned bytecodeIndex : 29;
unsigned valueProfileOffset : 3;
InlineCallFrame* inlineCallFrame;
CodeOrigin()
: bytecodeIndex(maximumBytecodeIndex)
, valueProfileOffset(0)
, inlineCallFrame(0)
{
}
explicit CodeOrigin(unsigned bytecodeIndex, InlineCallFrame* inlineCallFrame = 0, unsigned valueProfileOffset = 0)
: bytecodeIndex(bytecodeIndex)
, valueProfileOffset(valueProfileOffset)
, inlineCallFrame(inlineCallFrame)
{
RELEASE_ASSERT(bytecodeIndex <= maximumBytecodeIndex);
RELEASE_ASSERT(valueProfileOffset < (1u << 3));
}
bool isSet() const { return bytecodeIndex != maximumBytecodeIndex; }
unsigned bytecodeIndexForValueProfile() const
{
return bytecodeIndex + valueProfileOffset;
}
unsigned inlineDepth() const;
ExecutableBase* codeOriginOwner() const;
unsigned stackOffset() const;
static unsigned inlineDepthForCallFrame(InlineCallFrame*);
bool operator==(const CodeOrigin& other) const;
bool operator!=(const CodeOrigin& other) const { return !(*this == other); }
Vector<CodeOrigin> inlineStack() const;
void dump(PrintStream&) const;
};
struct InlineCallFrame {
Vector<ValueRecovery> arguments;
WriteBarrier<ExecutableBase> executable;
WriteBarrier<JSFunction> callee; CodeOrigin caller;
BitVector capturedVars; unsigned stackOffset : 31;
bool isCall : 1;
CodeSpecializationKind specializationKind() const { return specializationFromIsCall(isCall); }
bool isClosureCall() const { return !callee; }
JSFunction* calleeForCallFrame(ExecState*) const;
String inferredName() const;
CodeBlockHash hash() const;
CodeBlock* baselineCodeBlock() const;
void dumpBriefFunctionInformation(PrintStream&) const;
void dump(PrintStream&) const;
MAKE_PRINT_METHOD(InlineCallFrame, dumpBriefFunctionInformation, briefFunctionInformation);
};
struct CodeOriginAtCallReturnOffset {
CodeOrigin codeOrigin;
unsigned callReturnOffset;
};
inline unsigned CodeOrigin::stackOffset() const
{
if (!inlineCallFrame)
return 0;
return inlineCallFrame->stackOffset;
}
inline bool CodeOrigin::operator==(const CodeOrigin& other) const
{
return bytecodeIndex == other.bytecodeIndex
&& inlineCallFrame == other.inlineCallFrame;
}
inline unsigned getCallReturnOffsetForCodeOrigin(CodeOriginAtCallReturnOffset* data)
{
return data->callReturnOffset;
}
inline ExecutableBase* CodeOrigin::codeOriginOwner() const
{
if (!inlineCallFrame)
return 0;
return inlineCallFrame->executable.get();
}
}
#endif // CodeOrigin_h