Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix an error in calculation of ExecutionPause length for Code Cache #1262

Merged
merged 1 commit into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/codecache/CodeCacheReaderWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,18 @@ void CodeCacheWriter::storeByteCodeStream(ByteCodeBlock* block)
break;
}
case GetObjectPreComputedCaseSimpleInlineCacheOpcode:
case ExecutionPauseOpcode: {
// add tail data length
ExecutionPause* bc = static_cast<ExecutionPause*>(currentCode);
if (bc->m_reason == ExecutionPause::Reason::Yield) {
code += bc->m_yieldData.m_tailDataLength;
} else if (bc->m_reason == ExecutionPause::Reason::Await) {
code += bc->m_awaitData.m_tailDataLength;
} else if (bc->m_reason == ExecutionPause::Reason::GeneratorsInitialize) {
code += bc->m_asyncGeneratorInitializeData.m_tailDataLength;
}
break;
}
case ExecutionResumeOpcode:
RELEASE_ASSERT_NOT_REACHED();
break;
Expand Down
26 changes: 17 additions & 9 deletions src/interpreter/ByteCode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,15 +317,23 @@ void ByteCodeBlock::finalizeLexicalBlock(ByteCodeGenerateContext* context, const

void ByteCodeBlock::pushPauseStatementExtraData(ByteCodeGenerateContext* context)
{
auto iter = context->m_recursiveStatementStack.begin();
while (iter != context->m_recursiveStatementStack.end()) {
size_t pos = m_code.size();
m_code.resizeWithUninitializedValues(pos + sizeof(ByteCodeGenerateContext::RecursiveStatementKind));
new (m_code.data() + pos) size_t(iter->first);
pos = m_code.size();
m_code.resizeWithUninitializedValues(pos + sizeof(size_t));
new (m_code.data() + pos) size_t(iter->second);
iter++;
if (context->m_recursiveStatementStack.size()) {
size_t startSize = m_code.size();
size_t tailDataLength = context->m_recursiveStatementStack.size() * (sizeof(ByteCodeGenerateContext::RecursiveStatementKind) + sizeof(size_t));
m_code.resizeWithUninitializedValues(startSize + tailDataLength);

auto* codeAddr = m_code.data();
auto iter = context->m_recursiveStatementStack.begin();
size_t pos = startSize;
while (iter != context->m_recursiveStatementStack.end()) {
new (codeAddr + pos) size_t(iter->first);
pos += sizeof(ByteCodeGenerateContext::RecursiveStatementKind);
new (codeAddr + pos) size_t(iter->second);
pos += sizeof(size_t);
iter++;
}

ASSERT(tailDataLength == (pos - startSize));
}
}

Expand Down
6 changes: 0 additions & 6 deletions src/parser/ScriptParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,12 +419,6 @@ ScriptParser::InitializeScriptResult ScriptParser::initializeScript(String* orig
if (LIKELY(needByteCodeGeneration)) {
try {
#if defined(ENABLE_CODE_CACHE)
// give up if there is top-level-await
if (topCodeBlock->isAsync()) {
cacheable = false;
deleteCodeBlockCacheInfo();
}

// Store cache
if (cacheable) {
codeCache->prepareCacheWriting(srcHash);
Expand Down