Skip to content

Commit

Permalink
Fix an error in calculation of ExecutionPause length for Code Cache
Browse files Browse the repository at this point in the history
Signed-off-by: HyukWoo Park <[email protected]>
  • Loading branch information
clover2123 committed Oct 24, 2023
1 parent 97e698d commit 59f5e00
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 15 deletions.
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

0 comments on commit 59f5e00

Please sign in to comment.