From 59f5e00871fbdde6e12fbb2f1ba4831ecdfc7d06 Mon Sep 17 00:00:00 2001 From: HyukWoo Park Date: Tue, 24 Oct 2023 22:15:25 +0900 Subject: [PATCH] Fix an error in calculation of ExecutionPause length for Code Cache Signed-off-by: HyukWoo Park --- src/codecache/CodeCacheReaderWriter.cpp | 12 ++++++++++++ src/interpreter/ByteCode.cpp | 26 ++++++++++++++++--------- src/parser/ScriptParser.cpp | 6 ------ 3 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/codecache/CodeCacheReaderWriter.cpp b/src/codecache/CodeCacheReaderWriter.cpp index 8ccae78c0..aba780941 100644 --- a/src/codecache/CodeCacheReaderWriter.cpp +++ b/src/codecache/CodeCacheReaderWriter.cpp @@ -613,6 +613,18 @@ void CodeCacheWriter::storeByteCodeStream(ByteCodeBlock* block) break; } case GetObjectPreComputedCaseSimpleInlineCacheOpcode: + case ExecutionPauseOpcode: { + // add tail data length + ExecutionPause* bc = static_cast(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; diff --git a/src/interpreter/ByteCode.cpp b/src/interpreter/ByteCode.cpp index 49ab5e1cd..19953fc25 100644 --- a/src/interpreter/ByteCode.cpp +++ b/src/interpreter/ByteCode.cpp @@ -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)); } } diff --git a/src/parser/ScriptParser.cpp b/src/parser/ScriptParser.cpp index ee2289f0f..ac789866f 100644 --- a/src/parser/ScriptParser.cpp +++ b/src/parser/ScriptParser.cpp @@ -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);