summaryrefslogtreecommitdiffstats
path: root/JavaScriptCore/bytecode/CodeBlock.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'JavaScriptCore/bytecode/CodeBlock.cpp')
-rw-r--r--JavaScriptCore/bytecode/CodeBlock.cpp98
1 files changed, 81 insertions, 17 deletions
diff --git a/JavaScriptCore/bytecode/CodeBlock.cpp b/JavaScriptCore/bytecode/CodeBlock.cpp
index b63e826..e22f25a 100644
--- a/JavaScriptCore/bytecode/CodeBlock.cpp
+++ b/JavaScriptCore/bytecode/CodeBlock.cpp
@@ -33,8 +33,6 @@
#include "JIT.h"
#include "JSValue.h"
#include "Interpreter.h"
-#include "JSFunction.h"
-#include "JSStaticScopeObject.h"
#include "Debugger.h"
#include "BytecodeGenerator.h"
#include <stdio.h>
@@ -1248,11 +1246,11 @@ void CodeBlock::dumpStatistics()
#endif
}
-CodeBlock::CodeBlock(ExecutableBase* ownerExecutable)
+CodeBlock::CodeBlock(ScopeNode* ownerNode)
: m_numCalleeRegisters(0)
, m_numVars(0)
, m_numParameters(0)
- , m_ownerExecutable(ownerExecutable)
+ , m_ownerNode(ownerNode)
, m_globalData(0)
#ifndef NDEBUG
, m_instructionCount(0)
@@ -1270,17 +1268,17 @@ CodeBlock::CodeBlock(ExecutableBase* ownerExecutable)
#endif
}
-CodeBlock::CodeBlock(ExecutableBase* ownerExecutable, CodeType codeType, PassRefPtr<SourceProvider> sourceProvider, unsigned sourceOffset)
+CodeBlock::CodeBlock(ScopeNode* ownerNode, CodeType codeType, PassRefPtr<SourceProvider> sourceProvider, unsigned sourceOffset)
: m_numCalleeRegisters(0)
, m_numVars(0)
, m_numParameters(0)
- , m_ownerExecutable(ownerExecutable)
+ , m_ownerNode(ownerNode)
, m_globalData(0)
#ifndef NDEBUG
, m_instructionCount(0)
#endif
- , m_needsFullScopeChain(ownerExecutable->needsActivation())
- , m_usesEval(ownerExecutable->usesEval())
+ , m_needsFullScopeChain(ownerNode->needsActivation())
+ , m_usesEval(ownerNode->usesEval())
, m_isNumericCompareFunction(false)
, m_codeType(codeType)
, m_source(sourceProvider)
@@ -1437,10 +1435,15 @@ void CodeBlock::markAggregate(MarkStack& markStack)
markStack.append(m_constantRegisters[i].jsValue());
}
- for (size_t i = 0; i < m_functionExprs.size(); ++i)
- m_functionExprs[i]->markAggregate(markStack);
- for (size_t i = 0; i < m_functionDecls.size(); ++i)
- m_functionDecls[i]->markAggregate(markStack);
+ for (size_t i = 0; i < m_functionExpressions.size(); ++i)
+ m_functionExpressions[i]->body()->markAggregate(markStack);
+
+ if (m_rareData) {
+ for (size_t i = 0; i < m_rareData->m_functions.size(); ++i)
+ m_rareData->m_functions[i]->body()->markAggregate(markStack);
+
+ m_rareData->m_evalCodeCache.markAggregate(markStack);
+ }
}
void CodeBlock::reparseForExceptionInfoIfNecessary(CallFrame* callFrame)
@@ -1462,7 +1465,56 @@ void CodeBlock::reparseForExceptionInfoIfNecessary(CallFrame* callFrame)
scopeChain = scopeChain->next;
}
- m_exceptionInfo.set(m_ownerExecutable->reparseExceptionInfo(m_globalData, scopeChain, this));
+ switch (m_codeType) {
+ case FunctionCode: {
+ FunctionBodyNode* ownerFunctionBodyNode = static_cast<FunctionBodyNode*>(m_ownerNode);
+ RefPtr<FunctionBodyNode> newFunctionBody = m_globalData->parser->reparse<FunctionBodyNode>(m_globalData, ownerFunctionBodyNode);
+ ASSERT(newFunctionBody);
+ newFunctionBody->finishParsing(ownerFunctionBodyNode->copyParameters(), ownerFunctionBodyNode->parameterCount());
+
+ m_globalData->scopeNodeBeingReparsed = newFunctionBody.get();
+
+ CodeBlock& newCodeBlock = newFunctionBody->bytecodeForExceptionInfoReparse(scopeChain, this);
+ ASSERT(newCodeBlock.m_exceptionInfo);
+ ASSERT(newCodeBlock.m_instructionCount == m_instructionCount);
+
+#if ENABLE(JIT)
+ JIT::compile(m_globalData, &newCodeBlock);
+ ASSERT(newFunctionBody->generatedJITCode().size() == ownerNode()->generatedJITCode().size());
+#endif
+
+ m_exceptionInfo.set(newCodeBlock.m_exceptionInfo.release());
+
+ m_globalData->scopeNodeBeingReparsed = 0;
+
+ break;
+ }
+ case EvalCode: {
+ EvalNode* ownerEvalNode = static_cast<EvalNode*>(m_ownerNode);
+ RefPtr<EvalNode> newEvalBody = m_globalData->parser->reparse<EvalNode>(m_globalData, ownerEvalNode);
+
+ m_globalData->scopeNodeBeingReparsed = newEvalBody.get();
+
+ EvalCodeBlock& newCodeBlock = newEvalBody->bytecodeForExceptionInfoReparse(scopeChain, this);
+ ASSERT(newCodeBlock.m_exceptionInfo);
+ ASSERT(newCodeBlock.m_instructionCount == m_instructionCount);
+
+#if ENABLE(JIT)
+ JIT::compile(m_globalData, &newCodeBlock);
+ ASSERT(newEvalBody->generatedJITCode().size() == ownerNode()->generatedJITCode().size());
+#endif
+
+ m_exceptionInfo.set(newCodeBlock.m_exceptionInfo.release());
+
+ m_globalData->scopeNodeBeingReparsed = 0;
+
+ break;
+ }
+ default:
+ // CodeBlocks for Global code blocks are transient and therefore to not gain from
+ // from throwing out there exception information.
+ ASSERT_NOT_REACHED();
+ }
}
HandlerInfo* CodeBlock::handlerForBytecodeOffset(unsigned bytecodeOffset)
@@ -1493,7 +1545,7 @@ int CodeBlock::lineNumberForBytecodeOffset(CallFrame* callFrame, unsigned byteco
ASSERT(m_exceptionInfo);
if (!m_exceptionInfo->m_lineInfo.size())
- return m_ownerExecutable->source().firstLine(); // Empty function
+ return m_ownerNode->source().firstLine(); // Empty function
int low = 0;
int high = m_exceptionInfo->m_lineInfo.size();
@@ -1506,7 +1558,7 @@ int CodeBlock::lineNumberForBytecodeOffset(CallFrame* callFrame, unsigned byteco
}
if (!low)
- return m_ownerExecutable->source().firstLine();
+ return m_ownerNode->source().firstLine();
return m_exceptionInfo->m_lineInfo[low - 1].lineNumber;
}
@@ -1649,6 +1701,18 @@ bool CodeBlock::hasGlobalResolveInfoAtBytecodeOffset(unsigned bytecodeOffset)
}
#endif
+#if ENABLE(JIT)
+void CodeBlock::setJITCode(JITCode jitCode)
+{
+ ASSERT(m_codeType != NativeCode);
+ ownerNode()->setJITCode(jitCode);
+#if !ENABLE(OPCODE_SAMPLING)
+ if (!BytecodeGenerator::dumpsGeneratedCode())
+ m_instructions.clear();
+#endif
+}
+#endif
+
void CodeBlock::shrinkToFit()
{
m_instructions.shrinkToFit();
@@ -1664,8 +1728,7 @@ void CodeBlock::shrinkToFit()
#endif
m_identifiers.shrinkToFit();
- m_functionDecls.shrinkToFit();
- m_functionExprs.shrinkToFit();
+ m_functionExpressions.shrinkToFit();
m_constantRegisters.shrinkToFit();
if (m_exceptionInfo) {
@@ -1676,6 +1739,7 @@ void CodeBlock::shrinkToFit()
if (m_rareData) {
m_rareData->m_exceptionHandlers.shrinkToFit();
+ m_rareData->m_functions.shrinkToFit();
m_rareData->m_regexps.shrinkToFit();
m_rareData->m_immediateSwitchJumpTables.shrinkToFit();
m_rareData->m_characterSwitchJumpTables.shrinkToFit();