Commit f0c01b8e authored by oliver@apple.com's avatar oliver@apple.com

Reduce parser overhead in JSC

https://bugs.webkit.org/show_bug.cgi?id=101127

Reviewed by Filip Pizlo.

An exciting journey into the world of architecture in which our hero
adds yet another layer to JSC codegeneration.

This patch adds a marginally more compact form of bytecode that is
free from any data specific to a given execution context, and that
does store any data structures necessary for execution.  To actually
execute this UnlinkedBytecode we still need to instantiate a real
CodeBlock, but this is a much faster linear time operation than any
of the earlier parsing or code generation passes.

As the unlinked code is context free we can then simply use a cache
from source to unlinked code mapping to completely avoid all of the
old parser overhead.  The cache is currently very simple and memory
heavy, using the complete source text as a key (rather than SourceCode
or equivalent), and a random eviction policy.

This seems to produce a substantial win when loading identical content
in different contexts.

* API/tests/testapi.c:
(main):
* CMakeLists.txt:
* GNUmakefile.list.am:
* JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.vcproj:
* JavaScriptCore.xcodeproj/project.pbxproj:
* bytecode/CodeBlock.cpp:
* bytecode/CodeBlock.h:
    Moved a number of fields, and a bunch of logic to UnlinkedCodeBlock.h/cpp
* bytecode/Opcode.h:
    Added a global const init no op instruction needed to get correct
    behaviour without any associated semantics.
* bytecode/UnlinkedCodeBlock.cpp: Added.
* bytecode/UnlinkedCodeBlock.h: Added.
    A fairly shallow, GC allocated version of the old CodeBlock
    classes with a 32bit instruction size, and just metadata
    size tracking.
* bytecompiler/BytecodeGenerator.cpp:
* bytecompiler/BytecodeGenerator.h:
    Replace direct access to m_symbolTable with access through
    symbolTable().  ProgramCode no longer has a symbol table at
    all so some previously unconditional (and pointless) uses
    of symbolTable get null checks.
    A few other changes to deal with type changes due to us generating
    unlinked code (eg. pointer free, so profile indices rather than
    pointers).
* dfg/DFGByteCodeParser.cpp:
* dfg/DFGCapabilities.h:
    Support global_init_nop
* interpreter/Interpreter.cpp:
    Now get the ProgramExecutable to initialise new global properties
    before starting execution.
* jit/JIT.cpp:
* jit/JITDriver.h:
* jit/JITStubs.cpp:
* llint/LLIntData.cpp:
* llint/LLIntSlowPaths.cpp:
* llint/LowLevelInterpreter.asm:
* llint/LowLevelInterpreter32_64.asm:
* llint/LowLevelInterpreter64.asm:
    Adding init_global_const_nop everywhere else
* parser/Parser.h:
* parser/ParserModes.h: Added.
* parser/ParserTokens.h:
    Parser no longer needs a global object or callframe to function
* runtime/CodeCache.cpp: Added.
* runtime/CodeCache.h: Added.
    A simple, random eviction, Source->UnlinkedCode cache
* runtime/Executable.cpp:
* runtime/Executable.h:
    Executables now reference their unlinked counterparts, and
    request code specifically for the target global object.
* runtime/JSGlobalData.cpp:
* runtime/JSGlobalData.h:
    GlobalData now owns a CodeCache and a set of new structures
    for the unlinked code types.
* runtime/JSGlobalObject.cpp:
* runtime/JSGlobalObject.h:
    Utility functions used by executables to perform compilation

* runtime/JSType.h:
  Add new JSTypes for unlinked code

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@133688 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 376cae42
......@@ -59,6 +59,7 @@ SET(JavaScriptCore_SOURCES
bytecode/SpecialPointer.cpp
bytecode/StructureStubClearingWatchpoint.cpp
bytecode/StructureStubInfo.cpp
bytecode/UnlinkedCodeBlock.cpp
bytecode/Watchpoint.cpp
bytecompiler/BytecodeGenerator.cpp
......@@ -174,6 +175,7 @@ SET(JavaScriptCore_SOURCES
runtime/BooleanObject.cpp
runtime/BooleanPrototype.cpp
runtime/CallData.cpp
runtime/CodeCache.cpp
runtime/CommonIdentifiers.cpp
runtime/Completion.cpp
runtime/ConstructData.cpp
......
2012-11-06 Oliver Hunt <oliver@apple.com>
Reduce parser overhead in JSC
https://bugs.webkit.org/show_bug.cgi?id=101127
Reviewed by Filip Pizlo.
An exciting journey into the world of architecture in which our hero
adds yet another layer to JSC codegeneration.
This patch adds a marginally more compact form of bytecode that is
free from any data specific to a given execution context, and that
does store any data structures necessary for execution. To actually
execute this UnlinkedBytecode we still need to instantiate a real
CodeBlock, but this is a much faster linear time operation than any
of the earlier parsing or code generation passes.
As the unlinked code is context free we can then simply use a cache
from source to unlinked code mapping to completely avoid all of the
old parser overhead. The cache is currently very simple and memory
heavy, using the complete source text as a key (rather than SourceCode
or equivalent), and a random eviction policy.
This seems to produce a substantial win when loading identical content
in different contexts.
* API/tests/testapi.c:
(main):
* CMakeLists.txt:
* GNUmakefile.list.am:
* JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.vcproj:
* JavaScriptCore.xcodeproj/project.pbxproj:
* bytecode/CodeBlock.cpp:
* bytecode/CodeBlock.h:
Moved a number of fields, and a bunch of logic to UnlinkedCodeBlock.h/cpp
* bytecode/Opcode.h:
Added a global const init no op instruction needed to get correct
behaviour without any associated semantics.
* bytecode/UnlinkedCodeBlock.cpp: Added.
* bytecode/UnlinkedCodeBlock.h: Added.
A fairly shallow, GC allocated version of the old CodeBlock
classes with a 32bit instruction size, and just metadata
size tracking.
* bytecompiler/BytecodeGenerator.cpp:
* bytecompiler/BytecodeGenerator.h:
Replace direct access to m_symbolTable with access through
symbolTable(). ProgramCode no longer has a symbol table at
all so some previously unconditional (and pointless) uses
of symbolTable get null checks.
A few other changes to deal with type changes due to us generating
unlinked code (eg. pointer free, so profile indices rather than
pointers).
* dfg/DFGByteCodeParser.cpp:
* dfg/DFGCapabilities.h:
Support global_init_nop
* interpreter/Interpreter.cpp:
Now get the ProgramExecutable to initialise new global properties
before starting execution.
* jit/JIT.cpp:
* jit/JITDriver.h:
* jit/JITStubs.cpp:
* llint/LLIntData.cpp:
* llint/LLIntSlowPaths.cpp:
* llint/LowLevelInterpreter.asm:
* llint/LowLevelInterpreter32_64.asm:
* llint/LowLevelInterpreter64.asm:
Adding init_global_const_nop everywhere else
* parser/Parser.h:
* parser/ParserModes.h: Added.
* parser/ParserTokens.h:
Parser no longer needs a global object or callframe to function
* runtime/CodeCache.cpp: Added.
* runtime/CodeCache.h: Added.
A simple, random eviction, Source->UnlinkedCode cache
* runtime/Executable.cpp:
* runtime/Executable.h:
Executables now reference their unlinked counterparts, and
request code specifically for the target global object.
* runtime/JSGlobalData.cpp:
* runtime/JSGlobalData.h:
GlobalData now owns a CodeCache and a set of new structures
for the unlinked code types.
* runtime/JSGlobalObject.cpp:
* runtime/JSGlobalObject.h:
Utility functions used by executables to perform compilation
* runtime/JSType.h:
Add new JSTypes for unlinked code
2012-11-06 Michael Saboff <msaboff@apple.com>
JSStringCreateWithCFString() Should create an 8 bit String if possible
......@@ -2017,7 +2106,7 @@
(JSC::JIT::emit_op_next_pname):
(JSC::JIT::compileOpStrictEq):
(JSC::JIT::emit_op_catch):
(JSC::JIT::emit_op_throw_reference_error):
(JSC::JIT::emit_op_throw_static_error):
(JSC::JIT::emit_op_eq_null):
(JSC::JIT::emit_op_neq_null):
(JSC::JIT::emit_op_create_activation):
......
......@@ -138,6 +138,8 @@ javascriptcore_sources += \
Source/JavaScriptCore/bytecode/StructureStubInfo.h \
Source/JavaScriptCore/bytecode/StructureStubClearingWatchpoint.cpp \
Source/JavaScriptCore/bytecode/StructureStubClearingWatchpoint.h \
Source/JavaScriptCore/bytecode/UnlinkedCodeBlock.cpp \
Source/JavaScriptCore/bytecode/UnlinkedCodeBlock.h \
Source/JavaScriptCore/bytecode/ValueProfile.h \
Source/JavaScriptCore/bytecode/ValueRecovery.h \
Source/JavaScriptCore/bytecode/VirtualRegister.h \
......@@ -444,6 +446,7 @@ javascriptcore_sources += \
Source/JavaScriptCore/parser/ParserTokens.h \
Source/JavaScriptCore/parser/Parser.cpp \
Source/JavaScriptCore/parser/Parser.h \
Source/JavaScriptCore/parser/ParserModes.h \
Source/JavaScriptCore/parser/ResultType.h \
Source/JavaScriptCore/parser/SourceCode.h \
Source/JavaScriptCore/parser/SourceProvider.h \
......@@ -484,6 +487,8 @@ javascriptcore_sources += \
Source/JavaScriptCore/runtime/CallData.cpp \
Source/JavaScriptCore/runtime/CallData.h \
Source/JavaScriptCore/runtime/ClassInfo.h \
Source/JavaScriptCore/runtime/CodeCache.cpp \
Source/JavaScriptCore/runtime/CodeCache.h \
Source/JavaScriptCore/runtime/CodeSpecializationKind.h \
Source/JavaScriptCore/runtime/CommonIdentifiers.cpp \
Source/JavaScriptCore/runtime/CommonIdentifiers.h \
......
......@@ -637,6 +637,14 @@
RelativePath="..\..\runtime\ClassInfo.h"
>
</File>
<File
RelativePath="..\..\runtime\CodeCache.cpp"
>
</File>
<File
RelativePath="..\..\runtime\CodeCache.h"
>
</File>
<File
RelativePath="..\..\runtime\CommonIdentifiers.cpp"
>
......@@ -1745,6 +1753,14 @@
RelativePath="..\..\bytecode\StructureStubInfo.h"
>
</File>
<File
RelativePath="..\..\bytecode\UnlinkedCodeBlock.cpp"
>
</File>
<File
RelativePath="..\..\bytecode\UnlinkedCodeBlock.h"
>
</File>
<File
RelativePath="..\..\bytecode\ValueProfile.h"
>
......@@ -2229,6 +2245,10 @@
RelativePath="..\..\parser\Parser.h"
>
</File>
<File
RelativePath="..\..\parser\ParserModes.h"
>
</File>
<File
RelativePath="..\..\parser\ParserArena.cpp"
>
......
......@@ -580,12 +580,17 @@
A75706DE118A2BCF0057F88F /* JITArithmetic32_64.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A75706DD118A2BCF0057F88F /* JITArithmetic32_64.cpp */; };
A766B44F0EE8DCD1009518CA /* ExecutableAllocator.h in Headers */ = {isa = PBXBuildFile; fileRef = A7B48DB50EE74CFC00DCBDB6 /* ExecutableAllocator.h */; settings = {ATTRIBUTES = (Private, ); }; };
A76C51761182748D00715B05 /* JSInterfaceJIT.h in Headers */ = {isa = PBXBuildFile; fileRef = A76C51741182748D00715B05 /* JSInterfaceJIT.h */; settings = {ATTRIBUTES = (Private, ); }; };
A76F279415F13C9600517D67 /* UnlinkedCodeBlock.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A79E781E15EECBA80047C855 /* UnlinkedCodeBlock.cpp */; };
A76F54A313B28AAB00EF2BCE /* JITWriteBarrier.h in Headers */ = {isa = PBXBuildFile; fileRef = A76F54A213B28AAB00EF2BCE /* JITWriteBarrier.h */; };
A77F1821164088B200640A47 /* CodeCache.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A77F181F164088B200640A47 /* CodeCache.cpp */; };
A77F1822164088B200640A47 /* CodeCache.h in Headers */ = {isa = PBXBuildFile; fileRef = A77F1820164088B200640A47 /* CodeCache.h */; settings = {ATTRIBUTES = (Private, ); }; };
A77F1825164192C700640A47 /* ParserModes.h in Headers */ = {isa = PBXBuildFile; fileRef = A77F18241641925400640A47 /* ParserModes.h */; settings = {ATTRIBUTES = (Private, ); }; };
A784A26111D16622005776AC /* ASTBuilder.h in Headers */ = {isa = PBXBuildFile; fileRef = A7A7EE7411B98B8D0065A14F /* ASTBuilder.h */; };
A784A26411D16622005776AC /* SyntaxChecker.h in Headers */ = {isa = PBXBuildFile; fileRef = A7A7EE7711B98B8D0065A14F /* SyntaxChecker.h */; };
A7AFC17915F7EFE30048F57B /* ResolveOperation.h in Headers */ = {isa = PBXBuildFile; fileRef = A7AFC17715F7EFE30048F57B /* ResolveOperation.h */; settings = {ATTRIBUTES = (Private, ); }; };
A7B48F490EE8936F00DCBDB6 /* ExecutableAllocator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7B48DB60EE74CFC00DCBDB6 /* ExecutableAllocator.cpp */; };
A7B4ACAF1484C9CE00B38A36 /* JSExportMacros.h in Headers */ = {isa = PBXBuildFile; fileRef = A7B4ACAE1484C9CE00B38A36 /* JSExportMacros.h */; settings = {ATTRIBUTES = (Private, ); }; };
A7B601821639FD2A00372BA3 /* UnlinkedCodeBlock.h in Headers */ = {isa = PBXBuildFile; fileRef = A79E781F15EECBA80047C855 /* UnlinkedCodeBlock.h */; settings = {ATTRIBUTES = (Private, ); }; };
A7C1E8E4112E72EF00A37F98 /* JITPropertyAccess32_64.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7C1E8C8112E701C00A37F98 /* JITPropertyAccess32_64.cpp */; };
A7DCB97312E5193F00911940 /* WriteBarrier.h in Headers */ = {isa = PBXBuildFile; fileRef = A7DCB77912E3D90500911940 /* WriteBarrier.h */; settings = {ATTRIBUTES = (Private, ); }; };
A7E2EA6B0FB460CF00601F06 /* LiteralParser.h in Headers */ = {isa = PBXBuildFile; fileRef = A7E2EA690FB460CF00601F06 /* LiteralParser.h */; };
......@@ -1378,6 +1383,11 @@
A767FF9F14F4502900789059 /* JSCTypedArrayStubs.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSCTypedArrayStubs.h; sourceTree = "<group>"; };
A76C51741182748D00715B05 /* JSInterfaceJIT.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSInterfaceJIT.h; sourceTree = "<group>"; };
A76F54A213B28AAB00EF2BCE /* JITWriteBarrier.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JITWriteBarrier.h; sourceTree = "<group>"; };
A77F181F164088B200640A47 /* CodeCache.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CodeCache.cpp; sourceTree = "<group>"; };
A77F1820164088B200640A47 /* CodeCache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CodeCache.h; sourceTree = "<group>"; };
A77F18241641925400640A47 /* ParserModes.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ParserModes.h; sourceTree = "<group>"; };
A79E781E15EECBA80047C855 /* UnlinkedCodeBlock.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UnlinkedCodeBlock.cpp; sourceTree = "<group>"; };
A79E781F15EECBA80047C855 /* UnlinkedCodeBlock.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UnlinkedCodeBlock.h; sourceTree = "<group>"; };
A79EDB0811531CD60019E912 /* JSObjectRefPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSObjectRefPrivate.h; sourceTree = "<group>"; };
A7A7EE7411B98B8D0065A14F /* ASTBuilder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASTBuilder.h; sourceTree = "<group>"; };
A7A7EE7711B98B8D0065A14F /* SyntaxChecker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SyntaxChecker.h; sourceTree = "<group>"; };
......@@ -2063,6 +2073,7 @@
E49DC15112EF272200184A1F /* SourceProviderCache.h */,
E49DC14912EF261A00184A1F /* SourceProviderCacheItem.h */,
A7A7EE7711B98B8D0065A14F /* SyntaxChecker.h */,
A77F18241641925400640A47 /* ParserModes.h */,
);
path = parser;
sourceTree = "<group>";
......@@ -2297,6 +2308,8 @@
1420BE7A10AA6DDB00F455D2 /* WeakRandom.h */,
A7DCB77912E3D90500911940 /* WriteBarrier.h */,
C2D58C3315912FEE0021A844 /* GCActivityCallback.cpp */,
A77F181F164088B200640A47 /* CodeCache.cpp */,
A77F1820164088B200640A47 /* CodeCache.h */,
);
path = runtime;
sourceTree = "<group>";
......@@ -2567,6 +2580,8 @@
0F93329914CA7DC10085F3C6 /* PutByIdStatus.cpp */,
0F93329A14CA7DC10085F3C6 /* PutByIdStatus.h */,
0F93329B14CA7DC10085F3C6 /* StructureSet.h */,
A79E781E15EECBA80047C855 /* UnlinkedCodeBlock.cpp */,
A79E781F15EECBA80047C855 /* UnlinkedCodeBlock.h */,
);
path = bytecode;
sourceTree = "<group>";
......@@ -2993,6 +3008,9 @@
0FEB3ECD16237F4D00AB67AD /* TypedArrayDescriptor.h in Headers */,
0F256C361627B0AD007F2783 /* DFGCallArrayAllocatorSlowPathGenerator.h in Headers */,
C2239D1B16262BDD005AC5FD /* GCThread.h in Headers */,
A7B601821639FD2A00372BA3 /* UnlinkedCodeBlock.h in Headers */,
A77F1822164088B200640A47 /* CodeCache.h in Headers */,
A77F1825164192C700640A47 /* ParserModes.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -3569,6 +3587,8 @@
C24D31E2161CD695002AA4DB /* HeapStatistics.cpp in Sources */,
C2239D1716262BDD005AC5FD /* CopyVisitor.cpp in Sources */,
C2239D1A16262BDD005AC5FD /* GCThread.cpp in Sources */,
A76F279415F13C9600517D67 /* UnlinkedCodeBlock.cpp in Sources */,
A77F1821164088B200640A47 /* CodeCache.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......
......@@ -69,6 +69,7 @@ SOURCES += \
bytecode/SpeculatedType.cpp \
bytecode/StructureStubClearingWatchpoint.cpp \
bytecode/StructureStubInfo.cpp \
bytecode/UnlinkedCodeBlock.cpp \
bytecode/Watchpoint.cpp \
bytecompiler/BytecodeGenerator.cpp \
bytecompiler/NodesCodegen.cpp \
......@@ -184,6 +185,7 @@ SOURCES += \
runtime/BooleanObject.cpp \
runtime/BooleanPrototype.cpp \
runtime/CallData.cpp \
runtime/CodeCache.cpp \
runtime/CommonIdentifiers.cpp \
runtime/Completion.cpp \
runtime/ConstructData.cpp \
......
This diff is collapsed.
......@@ -118,7 +118,8 @@ namespace JSC {
macro(op_put_to_base, 5) \
macro(op_put_to_base_variable, 5) \
\
macro(op_init_global_const, 3) \
macro(op_init_global_const_nop, 5) \
macro(op_init_global_const, 5) \
macro(op_init_global_const_check, 5) \
macro(op_get_by_id, 9) /* has value profiling */ \
macro(op_get_by_id_out_of_line, 9) /* has value profiling */ \
......@@ -204,7 +205,7 @@ namespace JSC {
\
macro(op_catch, 2) \
macro(op_throw, 2) \
macro(op_throw_reference_error, 2) \
macro(op_throw_static_error, 3) \
\
macro(op_debug, 5) \
macro(op_profile_will_call, 2) \
......
This diff is collapsed.
This diff is collapsed.
......@@ -41,6 +41,7 @@
#include "SymbolTable.h"
#include "Debugger.h"
#include "Nodes.h"
#include "UnlinkedCodeBlock.h"
#include <wtf/PassRefPtr.h>
#include <wtf/SegmentedVector.h>
#include <wtf/Vector.h>
......@@ -211,18 +212,18 @@ namespace JSC {
JS_EXPORT_PRIVATE static void setDumpsGeneratedCode(bool dumpsGeneratedCode);
static bool dumpsGeneratedCode();
BytecodeGenerator(ProgramNode*, JSScope*, SharedSymbolTable*, ProgramCodeBlock*, CompilationKind);
BytecodeGenerator(FunctionBodyNode*, JSScope*, SharedSymbolTable*, CodeBlock*, CompilationKind);
BytecodeGenerator(EvalNode*, JSScope*, SharedSymbolTable*, EvalCodeBlock*, CompilationKind);
BytecodeGenerator(JSGlobalData&, ProgramNode*, UnlinkedProgramCodeBlock*, DebuggerMode, ProfilerMode);
BytecodeGenerator(JSGlobalData&, FunctionBodyNode*, UnlinkedFunctionCodeBlock*, DebuggerMode, ProfilerMode);
BytecodeGenerator(JSGlobalData&, EvalNode*, UnlinkedEvalCodeBlock*, DebuggerMode, ProfilerMode);
~BytecodeGenerator();
JSGlobalData* globalData() const { return m_globalData; }
const CommonIdentifiers& propertyNames() const { return *m_globalData->propertyNames; }
bool isConstructor() { return m_codeBlock->m_isConstructor; }
bool isConstructor() { return m_codeBlock->isConstructor(); }
JSObject* generate();
ParserError generate();
bool isArgumentNumber(const Identifier&, int);
......@@ -332,10 +333,7 @@ namespace JSC {
void emitExpressionInfo(unsigned divot, unsigned startOffset, unsigned endOffset)
{
if (!m_shouldEmitRichSourceInfo)
return;
divot -= m_codeBlock->sourceOffset();
divot -= m_scopeNode->source().startOffset();
if (divot > ExpressionRangeInfo::MaxDivot) {
// Overflow has occurred, we can only give line number info for errors for this region
divot = 0;
......@@ -508,8 +506,6 @@ namespace JSC {
bool shouldEmitProfileHooks() { return m_shouldEmitProfileHooks; }
bool isStrictMode() const { return m_codeBlock->isStrictMode(); }
JSScope* scope() const { return m_scope.get(); }
private:
friend class Label;
......@@ -527,11 +523,10 @@ namespace JSC {
#endif
void emitOpcode(OpcodeID);
ArrayProfile* newArrayProfile();
ValueProfile* emitProfiledOpcode(OpcodeID);
UnlinkedArrayProfile newArrayProfile();
UnlinkedValueProfile emitProfiledOpcode(OpcodeID);
void retrieveLastBinaryOp(int& dstIndex, int& src1Index, int& src2Index);
void retrieveLastUnaryOp(int& dstIndex, int& srcIndex);
void retrieveLastUnaryOp(WriteBarrier<Unknown>*& dstPointer, int& srcIndex);
ALWAYS_INLINE void rewindBinaryOp();
ALWAYS_INLINE void rewindUnaryOp();
......@@ -574,10 +569,6 @@ namespace JSC {
}
// Returns the index of the added var.
enum ConstantMode { IsConstant, IsVariable };
enum FunctionMode { IsFunctionToSpecialize, NotFunctionOrNotSpecializable };
int addGlobalVar(const Identifier&, ConstantMode, FunctionMode);
void addParameter(const Identifier&, int parameterIndex);
RegisterID* resolveCallee(FunctionBodyNode*);
void addCallee(FunctionBodyNode*, RegisterID*);
......@@ -604,17 +595,22 @@ namespace JSC {
unsigned addConstantBuffer(unsigned length);
UnlinkedFunctionExecutable* makeFunction(FunctionBodyNode* body)
{
return UnlinkedFunctionExecutable::create(m_globalData, m_scopeNode->source(), body);
}
JSString* addStringConstant(const Identifier&);
void addLineInfo(unsigned lineNo)
{
m_codeBlock->addLineInfo(instructions().size(), lineNo);
m_codeBlock->addLineInfo(instructions().size(), lineNo - m_scopeNode->firstLine());
}
RegisterID* emitInitLazyRegister(RegisterID*);
public:
Vector<Instruction>& instructions() { return m_instructions; }
Vector<UnlinkedInstruction>& instructions() { return m_instructions; }
SharedSymbolTable& symbolTable() { return *m_symbolTable; }
#if ENABLE(BYTECODE_COMMENTS)
......@@ -652,13 +648,11 @@ namespace JSC {
void createActivationIfNecessary();
RegisterID* createLazyRegisterIfNecessary(RegisterID*);
Vector<Instruction> m_instructions;
Vector<UnlinkedInstruction> m_instructions;
bool m_shouldEmitDebugHooks;
bool m_shouldEmitProfileHooks;
bool m_shouldEmitRichSourceInfo;
Strong<JSScope> m_scope;
SharedSymbolTable* m_symbolTable;
#if ENABLE(BYTECODE_COMMENTS)
......@@ -667,7 +661,7 @@ namespace JSC {
#endif
ScopeNode* m_scopeNode;
CodeBlock* m_codeBlock;
Strong<UnlinkedCodeBlock> m_codeBlock;
// Some of these objects keep pointers to one another. They are arranged
// to ensure a sane destruction order that avoids references to freed memory.
......@@ -685,7 +679,6 @@ namespace JSC {
RefPtr<RegisterID> m_lastVar;
int m_finallyDepth;
int m_dynamicScopeDepth;
int m_baseScopeDepth;
CodeType m_codeType;
Vector<ControlFlowContext> m_scopeContextStack;
......
......@@ -80,6 +80,7 @@ inline void Recompiler::operator()(JSCell* cell)
ExecState* exec = function->scope()->globalObject()->JSGlobalObject::globalExec();
executable->clearCodeIfNotCompiling();
executable->clearUnlinkedCodeIfNotCompiling();
if (m_debugger == function->scope()->globalObject()->debugger())
m_sourceProviders.add(executable->source().provider(), exec);
}
......
......@@ -158,7 +158,7 @@ public:
// Nope, so try to parse one.
JSObject* exception;
value.owned = true;
value.codeBlock = key.executable()->produceCodeBlockFor(scope, OptimizingCompilation, key.kind(), exception).leakPtr();
value.codeBlock = key.executable()->produceCodeBlockFor(scope, key.kind(), exception).leakPtr();
}
// Check if there is any reason to reject this from our cache. If so, then
......
......@@ -2614,6 +2614,10 @@ bool ByteCodeParser::parseBlock(unsigned limit)
NEXT_OPCODE(op_put_by_id);
}
case op_init_global_const_nop: {
NEXT_OPCODE(op_init_global_const_nop);
}
case op_init_global_const: {
NodeIndex value = get(currentInstruction[2].u.operand);
addToGraph(
......@@ -2851,10 +2855,10 @@ bool ByteCodeParser::parseBlock(unsigned limit)
addToGraph(Throw, get(currentInstruction[1].u.operand));
LAST_OPCODE(op_throw);
case op_throw_reference_error:
case op_throw_static_error:
flushArgumentsAndCapturedVariables();
addToGraph(ThrowReferenceError);
LAST_OPCODE(op_throw_reference_error);
LAST_OPCODE(op_throw_static_error);
case op_call:
handleCall(interpreter, currentInstruction, Call, CodeForCall);
......@@ -3597,7 +3601,7 @@ void ByteCodeParser::parseCodeBlock()
dataLog("Parsing code block %p. codeType = %s, captureCount = %u, needsFullScopeChain = %s, needsActivation = %s, isStrictMode = %s\n",
codeBlock,
codeTypeToString(codeBlock->codeType()),
codeBlock->symbolTable()->captureCount(),
codeBlock->symbolTable() ? codeBlock->symbolTable()->captureCount() : 0,
codeBlock->needsFullScopeChain()?"true":"false",
codeBlock->ownerExecutable()->needsActivation()?"true":"false",
codeBlock->ownerExecutable()->isStrictMode()?"true":"false");
......
......@@ -166,6 +166,7 @@ inline CapabilityLevel canCompileOpcode(OpcodeID opcodeID, CodeBlock*, Instructi
case op_put_by_id_transition_direct_out_of_line:
case op_put_by_id_transition_normal:
case op_put_by_id_transition_normal_out_of_line:
case op_init_global_const_nop:
case op_init_global_const:
case op_init_global_const_check:
case op_jmp:
......@@ -199,7 +200,7 @@ inline CapabilityLevel canCompileOpcode(OpcodeID opcodeID, CodeBlock*, Instructi
case op_strcat:
case op_to_primitive:
case op_throw:
case op_throw_reference_error:
case op_throw_static_error:
case op_call:
case op_construct:
case op_new_regexp:
......
......@@ -1157,8 +1157,7 @@ JSCell* DFG_OPERATION operationCreateActivation(ExecState* exec)
{
JSGlobalData& globalData = exec->globalData();
NativeCallFrameTracer tracer(&globalData, exec);
JSActivation* activation = JSActivation::create(
globalData, exec, static_cast<FunctionExecutable*>(exec->codeBlock()->ownerExecutable()));
JSActivation* activation = JSActivation::create(globalData, exec, exec->codeBlock());
exec->setScope(activation);
return activation;
}
......
......@@ -36,6 +36,7 @@
#include "JSLock.h"
#include "JSONObject.h"
#include "Tracing.h"
#include "UnlinkedCodeBlock.h"
#include "WeakSetInlines.h"
#include <algorithm>
#include <wtf/RAMSize.h>
......@@ -484,13 +485,13 @@ void Heap::markRoots(bool fullGC)
}
}
#endif
if (m_globalData->codeBlocksBeingCompiled.size()) {
GCPHASE(VisitActiveCodeBlock);
for (size_t i = 0; i < m_globalData->codeBlocksBeingCompiled.size(); i++)
m_globalData->codeBlocksBeingCompiled[i]->visitAggregate(visitor);
}
{
GCPHASE(VisitMachineRoots);
MARK_LOG_ROOT(visitor, "C++ Stack");
......
......@@ -74,10 +74,18 @@ inline void MarkedAllocator::init(Heap* heap, MarkedSpace* markedSpace, size_t c
inline void* MarkedAllocator::allocate(size_t bytes)
{
MarkedBlock::FreeCell* head = m_freeList.head;
if (UNLIKELY(!head))
return allocateSlowCase(bytes);
if (UNLIKELY(!head)) {
void* result = allocateSlowCase(bytes);
#ifndef NDEBUG
memset(result, 0xCD, bytes);
#endif
return result;
}
m_freeList.head = head->next;
#ifndef NDEBUG
memset(head, 0xCD, bytes);
#endif
return head;
}
......
......@@ -294,6 +294,8 @@ ALWAYS_INLINE void SlotVisitor::internalAppend(JSValue* slot)
if (!cell)
return;
validate(cell);
if (m_shouldHashConst && cell->isString()) {
JSString* string = jsCast<JSString*>(cell);
if (string->shouldTryHashConst() && string->tryHashConstLock()) {
......@@ -355,6 +357,10 @@ void SlotVisitor::validate(JSCell* cell)
cell->structure()->structure(), parentClassName, cell, cell->structure(), ourClassName);
CRASH();
}
// Make sure we can walk the ClassInfo chain
const ClassInfo* info = cell->classInfo();
do { } while ((info = info->parentClass));
}
#else
void SlotVisitor::validate(JSCell*)
......
......@@ -948,10 +948,13 @@ failedJSONP:
// object.
// Compile source to bytecode if necessary:
JSObject* error = program->compile(callFrame, scope);
if (error)
if (JSObject* error = program->initalizeGlobalProperties(globalData, callFrame, scope))
return checkedReturn(throwError(callFrame, error));
CodeBlock* codeBlock = &program->generatedBytecode();
if (JSObject* error = program->compile(callFrame, scope))
return checkedReturn(throwError(callFrame, error));
ProgramCodeBlock* codeBlock = &program->generatedBytecode();
// Push the call frame for this invocation:
ASSERT(codeBlock->numParameters() == 1); // 1 parameter for 'this'.
......
......@@ -335,6 +335,8 @@ void JIT::privateCompileMainPass()
DEFINE_OP(op_put_by_index)
DEFINE_OP(op_put_by_val)
DEFINE_OP(op_put_getter_setter)
case op_init_global_const_nop:
NEXT_OPCODE(op_init_global_const_nop);
DEFINE_OP(op_init_global_const)
DEFINE_OP(op_init_global_const_check)
......@@ -371,7 +373,7 @@ void JIT::privateCompileMainPass()
DEFINE_OP(op_tear_off_activation)
DEFINE_OP(op_tear_off_arguments)
DEFINE_OP(op_throw)
DEFINE_OP(op_throw_reference_error)
DEFINE_OP(op_throw_static_error)
DEFINE_OP(op_to_jsnumber)
DEFINE_OP(op_to_primitive)
......
......@@ -731,7 +731,7 @@ namespace JSC {
void emit_op_tear_off_activation(Instruction*);
void emit_op_tear_off_arguments(Instruction*);
void emit_op_throw(Instruction*);
void emit_op_throw_reference_error(Instruction*);
void emit_op_throw_static_error(Instruction*);
void emit_op_to_jsnumber(Instruction*);
void emit_op_to_primitive(Instruction*);
void emit_op_unexpected_load(Instruction*);
......
......@@ -75,7 +75,7 @@ inline bool jitCompileIfAppropriate(ExecState* exec, OwnPtr<CodeBlockType>& code
return true;
}
inline bool jitCompileFunctionIfAppropriate(ExecState* exec, OwnPtr<FunctionCodeBlock>& codeBlock, JITCode& jitCode, MacroAssemblerCodePtr& jitCodeWithArityCheck, WriteBarrier<SharedSymbolTable>& symbolTable, JITCode::JITType jitType, unsigned bytecodeIndex, JITCompilationEffort effort)
inline bool jitCompileFunctionIfAppropriate(ExecState* exec, OwnPtr<FunctionCodeBlock>& codeBlock, JITCode& jitCode, MacroAssemblerCodePtr& jitCodeWithArityCheck, JITCode::JITType jitType, unsigned bytecodeIndex, JITCompilationEffort effort)
{
JSGlobalData& globalData = exec->globalData();
......@@ -99,7 +99,6 @@ inline bool jitCompileFunctionIfAppropriate(ExecState* exec, OwnPtr<FunctionCode
} else {
if (codeBlock->alternative()) {
codeBlock = static_pointer_cast<FunctionCodeBlock>(codeBlock->releaseAlternative());
symbolTable.set(exec->globalData(), codeBlock->ownerExecutable(), codeBlock->symbolTable());
jitCode = oldJITCode;