From 1b9be4570898624327ff2ac21ae38b0d1f70293a Mon Sep 17 00:00:00 2001 From: Seonghyun Kim Date: Tue, 26 Dec 2023 12:33:46 +0900 Subject: [PATCH] Add Generic-BlockInfo for reducing memory usage of BlockInfo Signed-off-by: Seonghyun Kim --- src/codecache/CodeCacheReaderWriter.cpp | 57 ++++---- src/heap/LeakCheckerBridge.cpp | 2 +- src/interpreter/ByteCode.cpp | 6 +- src/interpreter/ByteCodeBlockData.h | 1 + src/interpreter/ByteCodeInterpreter.cpp | 10 +- src/parser/CodeBlock.cpp | 176 ++++++++++++++---------- src/parser/CodeBlock.h | 156 +++++++++++++++++---- src/parser/Script.cpp | 6 +- src/parser/ScriptParser.cpp | 14 +- src/parser/ast/ForInOfStatementNode.h | 28 ++-- src/parser/ast/ForStatementNode.h | 34 ++--- src/parser/esprima_cpp/esprima.cpp | 2 +- src/runtime/EnvironmentRecord.h | 12 +- src/runtime/GlobalObject.cpp | 2 +- 14 files changed, 323 insertions(+), 183 deletions(-) diff --git a/src/codecache/CodeCacheReaderWriter.cpp b/src/codecache/CodeCacheReaderWriter.cpp index c9f14f8da..e8f45e406 100644 --- a/src/codecache/CodeCacheReaderWriter.cpp +++ b/src/codecache/CodeCacheReaderWriter.cpp @@ -172,18 +172,17 @@ void CodeCacheWriter::storeInterpretedCodeBlock(InterpretedCodeBlock* codeBlock) size = blockInfoVector.size(); m_buffer.ensureSize(sizeof(size_t)); m_buffer.put(size); - // FIXME ignore BlockInfo::m_loc member for (size_t i = 0; i < size; i++) { m_buffer.ensureSize(2 * sizeof(bool) + 3 * sizeof(uint16_t)); const InterpretedCodeBlock::BlockInfo* info = blockInfoVector[i]; - m_buffer.put(info->m_canAllocateEnvironmentOnStack); - m_buffer.put(info->m_shouldAllocateEnvironment); - m_buffer.put((uint16_t)info->m_nodeType); - m_buffer.put((uint16_t)info->m_parentBlockIndex); - m_buffer.put((uint16_t)info->m_blockIndex); + m_buffer.put(info->canAllocateEnvironmentOnStack()); + m_buffer.put(info->shouldAllocateEnvironment()); + m_buffer.put(info->fromCatchClauseNode()); + m_buffer.put((uint16_t)info->parentBlockIndex()); + m_buffer.put((uint16_t)info->blockIndex()); // InterpretedCodeBlock::BlockInfo::m_identifiers - const InterpretedCodeBlock::BlockIdentifierInfoVector& infoVector = info->m_identifiers; + const InterpretedCodeBlock::BlockIdentifierInfoVector& infoVector = info->identifiers(); const size_t vectorSize = infoVector.size(); m_buffer.ensureSize(sizeof(size_t) + vectorSize * (2 * sizeof(bool) + 2 * sizeof(size_t))); m_buffer.put(vectorSize); @@ -738,27 +737,31 @@ InterpretedCodeBlock* CodeCacheReader::loadInterpretedCodeBlock(Context* context size = m_buffer.get(); blockInfoVector.resizeWithUninitializedValues(size); for (size_t i = 0; i < size; i++) { - InterpretedCodeBlock::BlockInfo* info = new InterpretedCodeBlock::BlockInfo( -#ifndef NDEBUG - ExtendedNodeLOC(0, 0, 0) -#endif - ); - - info->m_canAllocateEnvironmentOnStack = m_buffer.get(); - info->m_shouldAllocateEnvironment = m_buffer.get(); - info->m_nodeType = (ASTNodeType)m_buffer.get(); - info->m_parentBlockIndex = (LexicalBlockIndex)m_buffer.get(); - info->m_blockIndex = (LexicalBlockIndex)m_buffer.get(); - + bool canAllocateEnvironmentOnStack = m_buffer.get(); + bool shouldAllocateEnvironment = m_buffer.get(); + bool fromCatchClauseNode = m_buffer.get(); + LexicalBlockIndex parentBlockIndex = (LexicalBlockIndex)m_buffer.get(); + LexicalBlockIndex blockIndex = (LexicalBlockIndex)m_buffer.get(); size_t vectorSize = m_buffer.get(); - info->m_identifiers.resizeWithUninitializedValues(vectorSize); - for (size_t j = 0; j < vectorSize; j++) { - InterpretedCodeBlock::BlockIdentifierInfo idInfo; - idInfo.m_needToAllocateOnStack = m_buffer.get(); - idInfo.m_isMutable = m_buffer.get(); - idInfo.m_indexForIndexedStorage = m_buffer.get(); - idInfo.m_name = m_stringTable->get(m_buffer.get()); - info->m_identifiers[j] = idInfo; + + InterpretedCodeBlock::BlockInfo* info = InterpretedCodeBlock::BlockInfo::create( + canAllocateEnvironmentOnStack, + shouldAllocateEnvironment, + fromCatchClauseNode, + parentBlockIndex, + blockIndex, + vectorSize); + if (vectorSize) { + ASSERT(!info->isGenericBlockInfo()); + info->identifiers().resizeWithUninitializedValues(vectorSize); + for (size_t j = 0; j < vectorSize; j++) { + InterpretedCodeBlock::BlockIdentifierInfo idInfo; + idInfo.m_needToAllocateOnStack = m_buffer.get(); + idInfo.m_isMutable = m_buffer.get(); + idInfo.m_indexForIndexedStorage = m_buffer.get(); + idInfo.m_name = m_stringTable->get(m_buffer.get()); + info->identifiers()[j] = idInfo; + } } blockInfoVector[i] = info; diff --git a/src/heap/LeakCheckerBridge.cpp b/src/heap/LeakCheckerBridge.cpp index f6ccc43ed..4a689d6c5 100644 --- a/src/heap/LeakCheckerBridge.cpp +++ b/src/heap/LeakCheckerBridge.cpp @@ -35,7 +35,7 @@ namespace Escargot { Value builtinRegisterLeakCheck(ExecutionState& state, Value thisValue, size_t argc, Value* argv, Optional newTarget) { if (!argv[0].isPointerValue()) { - ErrorObject::throwBuiltinError(state, ErrorObject::None, "builtinRegisterLeakCheck should get pointer-type argument"); + ErrorObject::throwBuiltinError(state, ErrorCode::None, "builtinRegisterLeakCheck should get pointer-type argument"); } PointerValue* ptr = argv[0].asPointerValue(); diff --git a/src/interpreter/ByteCode.cpp b/src/interpreter/ByteCode.cpp index da94829d6..9c2eaa26f 100644 --- a/src/interpreter/ByteCode.cpp +++ b/src/interpreter/ByteCode.cpp @@ -263,8 +263,8 @@ void ByteCodeBlock::initFunctionDeclarationWithinBlock(ByteCodeGenerateContext* context->m_isFunctionDeclarationBindingInitialization = true; } - for (size_t i = 0; i < blockInfo->m_identifiers.size(); i++) { - if (blockInfo->m_identifiers[i].m_name == child->functionName()) { + for (size_t i = 0; i < blockInfo->identifiers().size(); i++) { + if (blockInfo->identifiers()[i].m_name == child->functionName()) { context->m_isLexicallyDeclaredBindingInitialization = true; break; } @@ -286,7 +286,7 @@ ByteCodeBlock::ByteCodeLexicalBlockContext ByteCodeBlock::pushLexicalBlock(ByteC ByteCodeBlock::ByteCodeLexicalBlockContext ctx; ctx.lexicallyDeclaredNamesCount = context->m_lexicallyDeclaredNames->size(); - if (blockInfo->m_shouldAllocateEnvironment) { + if (blockInfo->shouldAllocateEnvironment()) { ctx.lexicalBlockSetupStartPosition = currentCodeSize(); context->m_recursiveStatementStack.push_back(std::make_pair(ByteCodeGenerateContext::Block, ctx.lexicalBlockSetupStartPosition)); this->pushCode(BlockOperation(ByteCodeLOC(node->m_loc.index), blockInfo), context, SIZE_MAX); diff --git a/src/interpreter/ByteCodeBlockData.h b/src/interpreter/ByteCodeBlockData.h index 25a05ef09..e6de0768a 100644 --- a/src/interpreter/ByteCodeBlockData.h +++ b/src/interpreter/ByteCodeBlockData.h @@ -26,6 +26,7 @@ namespace Escargot { class ByteCodeBlockData { typedef ComputeReservedCapacityFunctionWithLog2<200> ComputeReservedCapacityFunction; + public: ByteCodeBlockData() : m_buffer(nullptr) diff --git a/src/interpreter/ByteCodeInterpreter.cpp b/src/interpreter/ByteCodeInterpreter.cpp index 061604e9a..c17c27f43 100644 --- a/src/interpreter/ByteCodeInterpreter.cpp +++ b/src/interpreter/ByteCodeInterpreter.cpp @@ -3575,13 +3575,13 @@ NEVER_INLINE void InterpreterSlowPath::replaceBlockLexicalEnvironmentOperation(E bool shouldUseIndexedStorage = byteCodeBlock->m_codeBlock->canUseIndexedVariableStorage(); InterpretedCodeBlock::BlockInfo* blockInfo = reinterpret_cast(code->m_blockInfo); - ASSERT(blockInfo && blockInfo->m_shouldAllocateEnvironment); + ASSERT(blockInfo && blockInfo->shouldAllocateEnvironment()); if (LIKELY(shouldUseIndexedStorage)) { newRecord = new DeclarativeEnvironmentRecordIndexed(state, blockInfo); } else { newRecord = new DeclarativeEnvironmentRecordNotIndexed(state); - auto& iv = blockInfo->m_identifiers; + auto& iv = blockInfo->identifiers(); auto siz = iv.size(); for (size_t i = 0; i < siz; i++) { newRecord->createBinding(state, iv[i].m_name, false, iv[i].m_isMutable, false); @@ -3608,13 +3608,13 @@ NEVER_INLINE Value InterpreterSlowPath::blockOperation(ExecutionState*& state, B if (LIKELY(!inPauserResumeProcess)) { InterpretedCodeBlock::BlockInfo* blockInfo = reinterpret_cast(code->m_blockInfo); - ASSERT(blockInfo->m_shouldAllocateEnvironment); + ASSERT(blockInfo->shouldAllocateEnvironment()); if (LIKELY(shouldUseIndexedStorage)) { newRecord = new DeclarativeEnvironmentRecordIndexed(*state, blockInfo); } else { - newRecord = new DeclarativeEnvironmentRecordNotIndexed(*state, false, blockInfo->m_nodeType == ASTNodeType::CatchClause); + newRecord = new DeclarativeEnvironmentRecordNotIndexed(*state, false, blockInfo->fromCatchClauseNode()); - auto& iv = blockInfo->m_identifiers; + auto& iv = blockInfo->identifiers(); auto siz = iv.size(); for (size_t i = 0; i < siz; i++) { newRecord->createBinding(*state, iv[i].m_name, false, iv[i].m_isMutable, false); diff --git a/src/parser/CodeBlock.cpp b/src/parser/CodeBlock.cpp index 787d95d5e..da1583bbe 100644 --- a/src/parser/CodeBlock.cpp +++ b/src/parser/CodeBlock.cpp @@ -127,31 +127,31 @@ void InterpretedCodeBlock::initBlockScopeInformation(ASTScopeContext* scopeCtx) const ASTBlockContextVector& blockScopes = scopeCtx->m_childBlockScopes; m_blockInfos.resizeWithUninitializedValues(blockScopes.size()); for (size_t i = 0; i < blockScopes.size(); i++) { - BlockInfo* info = new BlockInfo( -#ifndef NDEBUG - blockScopes[i]->m_loc -#endif - ); - // if block comes from switch statement, we should allocate variables on heap. // because our we can track only heap variables are initialized by user // we can track that {let, const} variables are initialized by user only if variables are allocated in heap - bool everyVariablesShouldUseHeapStorage = info->m_nodeType == ASTNodeType::SwitchStatement; + bool everyVariablesShouldUseHeapStorage = blockScopes[i]->m_nodeType == ASTNodeType::SwitchStatement; m_canAllocateEnvironmentOnStack = m_canAllocateEnvironmentOnStack && !everyVariablesShouldUseHeapStorage; - info->m_canAllocateEnvironmentOnStack = m_canAllocateEnvironmentOnStack; - info->m_shouldAllocateEnvironment = true; - info->m_nodeType = blockScopes[i]->m_nodeType; - info->m_parentBlockIndex = blockScopes[i]->m_parentBlockIndex; - info->m_blockIndex = blockScopes[i]->m_blockIndex; - - info->m_identifiers.resizeWithUninitializedValues(blockScopes[i]->m_names.size()); - for (size_t j = 0; j < blockScopes[i]->m_names.size(); j++) { - BlockIdentifierInfo idInfo; - idInfo.m_needToAllocateOnStack = m_canUseIndexedVariableStorage && !everyVariablesShouldUseHeapStorage; - idInfo.m_isMutable = !blockScopes[i]->m_names[j].isConstBinding(); - idInfo.m_indexForIndexedStorage = SIZE_MAX; - idInfo.m_name = blockScopes[i]->m_names[j].name(); - info->m_identifiers[j] = idInfo; + + BlockInfo* info = BlockInfo::create( + m_canAllocateEnvironmentOnStack, + false, + blockScopes[i]->m_nodeType == ASTNodeType::CatchClause, + blockScopes[i]->m_parentBlockIndex, + blockScopes[i]->m_blockIndex, + blockScopes[i]->m_names.size()); + + if (blockScopes[i]->m_names.size()) { + ASSERT(!info->isGenericBlockInfo()); + info->identifiers().resizeWithUninitializedValues(blockScopes[i]->m_names.size()); + for (size_t j = 0; j < blockScopes[i]->m_names.size(); j++) { + BlockIdentifierInfo idInfo; + idInfo.m_needToAllocateOnStack = m_canUseIndexedVariableStorage && !everyVariablesShouldUseHeapStorage; + idInfo.m_isMutable = !blockScopes[i]->m_names[j].isConstBinding(); + idInfo.m_indexForIndexedStorage = SIZE_MAX; + idInfo.m_name = blockScopes[i]->m_names[j].name(); + info->identifiers()[j] = idInfo; + } } m_blockInfos[i] = info; @@ -429,7 +429,7 @@ std::pair InterpretedCodeBlock::tryCaptureIdentifiersFromChildCode auto r = findNameWithinBlock(blockIndex, name); if (std::get<0>(r)) { - auto& id = m_blockInfos[std::get<1>(r)]->m_identifiers[std::get<2>(r)]; + auto& id = m_blockInfos[std::get<1>(r)]->identifiers()[std::get<2>(r)]; ASSERT(id.m_name == name); id.m_needToAllocateOnStack = false; return std::make_pair(true, std::get<1>(r)); @@ -455,24 +455,32 @@ void InterpretedCodeBlock::markHeapAllocatedEnvironmentFromHere(LexicalBlockInde InterpretedCodeBlock* c = this; while (c) { + size_t blockArrayIndex = SIZE_MAX; InterpretedCodeBlock::BlockInfo* bi = nullptr; for (size_t i = 0; i < c->m_blockInfos.size(); i++) { - if (c->m_blockInfos[i]->m_blockIndex == blockIndex) { + if (c->m_blockInfos[i]->blockIndex() == blockIndex) { bi = c->m_blockInfos[i]; + blockArrayIndex = i; break; } } - while (bi && bi->m_canAllocateEnvironmentOnStack) { - bi->m_canAllocateEnvironmentOnStack = false; + while (bi && bi->canAllocateEnvironmentOnStack()) { + if (bi->isGenericBlockInfo()) { + bi = BlockInfo::genericBlockInfo(false, bi->shouldAllocateEnvironment()); + c->m_blockInfos[blockArrayIndex] = bi; + } else { + bi->setCanAllocateEnvironmentOnStack(false); + } - if (bi->m_parentBlockIndex == LEXICAL_BLOCK_INDEX_MAX) { + if (bi->parentBlockIndex() == LEXICAL_BLOCK_INDEX_MAX) { break; } for (size_t i = 0; i < c->m_blockInfos.size(); i++) { - if (c->m_blockInfos[i]->m_blockIndex == bi->m_parentBlockIndex) { + if (c->m_blockInfos[i]->blockIndex() == bi->parentBlockIndex()) { bi = c->m_blockInfos[i]; + blockArrayIndex = i; break; } } @@ -492,9 +500,11 @@ void InterpretedCodeBlock::markHeapAllocatedEnvironmentFromHere(LexicalBlockInde void InterpretedCodeBlock::computeBlockVariables(LexicalBlockIndex currentBlockIndex, size_t currentStackAllocatedVariableIndex, size_t& maxStackAllocatedVariableDepth) { InterpretedCodeBlock::BlockInfo* bi = nullptr; + size_t arrayIndex = SIZE_MAX; for (size_t i = 0; i < m_blockInfos.size(); i++) { - if (m_blockInfos[i]->m_blockIndex == currentBlockIndex) { + if (m_blockInfos[i]->blockIndex() == currentBlockIndex) { bi = m_blockInfos[i]; + arrayIndex = i; break; } } @@ -503,35 +513,40 @@ void InterpretedCodeBlock::computeBlockVariables(LexicalBlockIndex currentBlockI size_t heapIndex = 0; size_t stackSize = 0; - for (size_t i = 0; i < bi->m_identifiers.size(); i++) { + for (size_t i = 0; i < bi->identifiers().size(); i++) { if (!m_canAllocateVariablesOnStack) { - bi->m_identifiers[i].m_needToAllocateOnStack = false; + bi->identifiers()[i].m_needToAllocateOnStack = false; } - if (bi->m_identifiers[i].m_needToAllocateOnStack) { - bi->m_identifiers[i].m_indexForIndexedStorage = currentStackAllocatedVariableIndex; + if (bi->identifiers()[i].m_needToAllocateOnStack) { + bi->identifiers()[i].m_indexForIndexedStorage = currentStackAllocatedVariableIndex; stackSize++; currentStackAllocatedVariableIndex++; maxStackAllocatedVariableDepth = std::max(maxStackAllocatedVariableDepth, currentStackAllocatedVariableIndex); } else { - bi->m_identifiers[i].m_indexForIndexedStorage = heapIndex++; - bi->m_canAllocateEnvironmentOnStack = false; + bi->identifiers()[i].m_indexForIndexedStorage = heapIndex++; + bi->setCanAllocateEnvironmentOnStack(false); } } // if there is no heap indexed variable, we can skip allocate env bool isThereHeapVariable = false; - for (size_t i = 0; i < bi->m_identifiers.size(); i++) { - if (!bi->m_identifiers[i].m_needToAllocateOnStack) { + for (size_t i = 0; i < bi->identifiers().size(); i++) { + if (!bi->identifiers()[i].m_needToAllocateOnStack) { isThereHeapVariable = true; } } - bi->m_shouldAllocateEnvironment = isThereHeapVariable; + if (bi->isGenericBlockInfo()) { + bi = BlockInfo::genericBlockInfo(bi->canAllocateEnvironmentOnStack(), isThereHeapVariable); + m_blockInfos[arrayIndex] = bi; + } else { + bi->setShouldAllocateEnvironment(isThereHeapVariable); + } for (size_t i = 0; i < m_blockInfos.size(); i++) { - if (m_blockInfos[i]->m_parentBlockIndex == currentBlockIndex) { - computeBlockVariables(m_blockInfos[i]->m_blockIndex, currentStackAllocatedVariableIndex, maxStackAllocatedVariableDepth); + if (m_blockInfos[i]->parentBlockIndex() == currentBlockIndex) { + computeBlockVariables(m_blockInfos[i]->blockIndex(), currentStackAllocatedVariableIndex, maxStackAllocatedVariableDepth); } } } @@ -622,11 +637,15 @@ void InterpretedCodeBlock::computeVariables() if (!canUseIndexedVariableStorage()) { for (size_t i = 0; i < m_blockInfos.size(); i++) { - m_blockInfos[i]->m_canAllocateEnvironmentOnStack = false; - m_blockInfos[i]->m_shouldAllocateEnvironment = m_blockInfos[i]->m_identifiers.size(); - for (size_t j = 0; j < m_blockInfos[i]->m_identifiers.size(); j++) { - m_blockInfos[i]->m_identifiers[j].m_indexForIndexedStorage = SIZE_MAX; - m_blockInfos[i]->m_identifiers[j].m_needToAllocateOnStack = false; + if (m_blockInfos[i]->isGenericBlockInfo()) { + m_blockInfos[i] = BlockInfo::genericBlockInfo(false, m_blockInfos[i]->identifiers().size()); + } else { + m_blockInfos[i]->setCanAllocateEnvironmentOnStack(false); + m_blockInfos[i]->setShouldAllocateEnvironment(m_blockInfos[i]->identifiers().size()); + } + for (size_t j = 0; j < m_blockInfos[i]->identifiers().size(); j++) { + m_blockInfos[i]->identifiers()[j].m_indexForIndexedStorage = SIZE_MAX; + m_blockInfos[i]->identifiers()[j].m_needToAllocateOnStack = false; } } } else { @@ -639,21 +658,27 @@ void InterpretedCodeBlock::computeVariables() } InterpretedCodeBlock::BlockInfo* bi = nullptr; + size_t arrayIndex = SIZE_MAX; for (size_t i = 0; i < m_blockInfos.size(); i++) { - if (m_blockInfos[i]->m_blockIndex == 0) { + if (m_blockInfos[i]->blockIndex() == 0) { bi = m_blockInfos[i]; + arrayIndex = i; break; } } ASSERT(!!bi); // global {let, const} declaration should be processed on ModuleEnvironmentRecord - for (size_t i = 0; i < bi->m_identifiers.size(); i++) { - bi->m_identifiers[i].m_indexForIndexedStorage = i + identifierInfos().size(); - bi->m_identifiers[i].m_needToAllocateOnStack = false; + for (size_t i = 0; i < bi->identifiers().size(); i++) { + bi->identifiers()[i].m_indexForIndexedStorage = i + identifierInfos().size(); + bi->identifiers()[i].m_needToAllocateOnStack = false; } - bi->m_shouldAllocateEnvironment = false; + if (bi->isGenericBlockInfo()) { + m_blockInfos[arrayIndex] = BlockInfo::genericBlockInfo(bi->canAllocateEnvironmentOnStack(), false); + } else { + bi->setShouldAllocateEnvironment(false); + } } else { if (m_isEvalCodeInFunction) { AtomicString arguments = m_context->staticStrings().arguments; @@ -690,11 +715,15 @@ void InterpretedCodeBlock::computeVariables() if (!canUseIndexedVariableStorage()) { for (size_t i = 0; i < m_blockInfos.size(); i++) { - m_blockInfos[i]->m_canAllocateEnvironmentOnStack = false; - m_blockInfos[i]->m_shouldAllocateEnvironment = m_blockInfos[i]->m_identifiers.size(); - for (size_t j = 0; j < m_blockInfos[i]->m_identifiers.size(); j++) { - m_blockInfos[i]->m_identifiers[j].m_indexForIndexedStorage = SIZE_MAX; - m_blockInfos[i]->m_identifiers[j].m_needToAllocateOnStack = false; + if (m_blockInfos[i]->isGenericBlockInfo()) { + m_blockInfos[i] = BlockInfo::genericBlockInfo(false, m_blockInfos[i]->identifiers().size()); + } else { + m_blockInfos[i]->setCanAllocateEnvironmentOnStack(false); + m_blockInfos[i]->setShouldAllocateEnvironment(m_blockInfos[i]->identifiers().size()); + } + for (size_t j = 0; j < m_blockInfos[i]->identifiers().size(); j++) { + m_blockInfos[i]->identifiers()[j].m_indexForIndexedStorage = SIZE_MAX; + m_blockInfos[i]->identifiers()[j].m_needToAllocateOnStack = false; } } } else { @@ -708,21 +737,28 @@ void InterpretedCodeBlock::computeVariables() if (isGlobalCodeBlock()) { InterpretedCodeBlock::BlockInfo* bi = nullptr; + size_t arrayIndex = SIZE_MAX; for (size_t i = 0; i < m_blockInfos.size(); i++) { - if (m_blockInfos[i]->m_blockIndex == 0) { + if (m_blockInfos[i]->blockIndex() == 0) { bi = m_blockInfos[i]; + arrayIndex = i; break; } } ASSERT(!!bi); // global {let, const} declaration should be processed on GlobalEnvironmentRecord - for (size_t i = 0; i < bi->m_identifiers.size(); i++) { - bi->m_identifiers[i].m_indexForIndexedStorage = SIZE_MAX; - bi->m_identifiers[i].m_needToAllocateOnStack = false; + for (size_t i = 0; i < bi->identifiers().size(); i++) { + bi->identifiers()[i].m_indexForIndexedStorage = SIZE_MAX; + bi->identifiers()[i].m_needToAllocateOnStack = false; } - bi->m_shouldAllocateEnvironment = false; + if (bi->isGenericBlockInfo()) { + bi = BlockInfo::genericBlockInfo(bi->canAllocateEnvironmentOnStack(), false); + m_blockInfos[arrayIndex] = bi; + } else { + bi->setShouldAllocateEnvironment(false); + } } } } @@ -762,7 +798,7 @@ InterpretedCodeBlock::IndexedIdentifierInfo InterpretedCodeBlock::indexedIdentif while (true) { InterpretedCodeBlock::BlockInfo* bi = nullptr; for (size_t i = 0; i < blk->m_blockInfos.size(); i++) { - if (blk->m_blockInfos[i]->m_blockIndex == blockIndex) { + if (blk->m_blockInfos[i]->blockIndex() == blockIndex) { bi = blk->m_blockInfos[i]; break; } @@ -770,20 +806,20 @@ InterpretedCodeBlock::IndexedIdentifierInfo InterpretedCodeBlock::indexedIdentif ASSERT(bi); - for (size_t i = 0; i < bi->m_identifiers.size(); i++) { - if (bi->m_identifiers[i].m_name == name) { + for (size_t i = 0; i < bi->identifiers().size(); i++) { + if (bi->identifiers()[i].m_name == name) { info.m_isResultSaved = true; - info.m_isStackAllocated = bi->m_identifiers[i].m_needToAllocateOnStack; - info.m_index = bi->m_identifiers[i].m_indexForIndexedStorage; + info.m_isStackAllocated = bi->identifiers()[i].m_needToAllocateOnStack; + info.m_index = bi->identifiers()[i].m_indexForIndexedStorage; if (info.m_isStackAllocated) { info.m_index += identifierOnStackCount(); } info.m_upperIndex = upperIndex; - info.m_isMutable = bi->m_identifiers[i].m_isMutable; + info.m_isMutable = bi->identifiers()[i].m_isMutable; info.m_type = IndexedIdentifierInfo::DeclarationType::LexicallyDeclared; - info.m_blockIndex = bi->m_blockIndex; + info.m_blockIndex = bi->blockIndex(); - if (blk->isGlobalCodeBlock() && !blk->script()->isModule() && bi->m_parentBlockIndex == LEXICAL_BLOCK_INDEX_MAX) { + if (blk->isGlobalCodeBlock() && !blk->script()->isModule() && bi->parentBlockIndex() == LEXICAL_BLOCK_INDEX_MAX) { info.m_isGlobalLexicalVariable = true; } else { info.m_isGlobalLexicalVariable = false; @@ -793,14 +829,14 @@ InterpretedCodeBlock::IndexedIdentifierInfo InterpretedCodeBlock::indexedIdentif } } - if (bi->m_shouldAllocateEnvironment) { + if (bi->shouldAllocateEnvironment()) { upperIndex++; } - if (bi->m_parentBlockIndex == LEXICAL_BLOCK_INDEX_MAX) { + if (bi->parentBlockIndex() == LEXICAL_BLOCK_INDEX_MAX) { break; } - blockIndex = bi->m_parentBlockIndex; + blockIndex = bi->parentBlockIndex(); } if (blk->isGlobalCodeBlock() && !blk->script()->isModule()) { diff --git a/src/parser/CodeBlock.h b/src/parser/CodeBlock.h index e6c36f998..be6483f94 100644 --- a/src/parser/CodeBlock.h +++ b/src/parser/CodeBlock.h @@ -253,35 +253,135 @@ class InterpretedCodeBlock : public CodeBlock { typedef TightVector> BlockIdentifierInfoVector; - struct BlockInfo : public gc { - bool m_canAllocateEnvironmentOnStack : 1; - bool m_shouldAllocateEnvironment : 1; - ASTNodeType m_nodeType : 16; - LexicalBlockIndex m_parentBlockIndex; - LexicalBlockIndex m_blockIndex; - BlockIdentifierInfoVector m_identifiers; + class BlockInfo : public gc { + public: + BlockInfo(bool isGenericBlockInfo = false, + bool canAllocateEnvironmentOnStack = false, + bool shouldAllocateEnvironment = false, + bool fromCatchClauseNode = false, + LexicalBlockIndex parentBlockIndex = LEXICAL_BLOCK_INDEX_MAX, + LexicalBlockIndex blockIndex = LEXICAL_BLOCK_INDEX_MAX) + : m_isGenericBlockInfo(isGenericBlockInfo) + , m_canAllocateEnvironmentOnStack(canAllocateEnvironmentOnStack) + , m_shouldAllocateEnvironment(shouldAllocateEnvironment) + , m_fromCatchClauseNode(fromCatchClauseNode) + , m_parentBlockIndex(parentBlockIndex) + , m_blockIndex(blockIndex) + { + } -#ifndef NDEBUG - ExtendedNodeLOC m_loc; -#endif - BlockInfo( -#ifndef NDEBUG - ExtendedNodeLOC loc -#endif - ) - : m_canAllocateEnvironmentOnStack(false) - , m_shouldAllocateEnvironment(false) - , m_nodeType(ASTNodeType::ASTNodeTypeError) - , m_parentBlockIndex(LEXICAL_BLOCK_INDEX_MAX) - , m_blockIndex(LEXICAL_BLOCK_INDEX_MAX) -#ifndef NDEBUG - , m_loc(loc) -#endif + static BlockInfo* genericBlockInfo(bool canAllocateEnvironmentOnStack, bool shouldAllocateEnvironment) + { + static BlockInfo s_genericBlockInfo[4] = { + BlockInfo( + true, false, false, false, + LEXICAL_BLOCK_INDEX_MAX, 0), + BlockInfo( + true, false, true, false, + LEXICAL_BLOCK_INDEX_MAX, 0), + BlockInfo( + true, true, false, false, + LEXICAL_BLOCK_INDEX_MAX, 0), + BlockInfo( + true, true, true, false, + LEXICAL_BLOCK_INDEX_MAX, 0) + }; + + size_t idx = (canAllocateEnvironmentOnStack ? 2 : 0) + (shouldAllocateEnvironment ? 1 : 0); + + return &s_genericBlockInfo[idx]; + } + + static BlockInfo* create(bool canAllocateEnvironmentOnStack, + bool shouldAllocateEnvironment, + bool fromCatchClauseNode, + LexicalBlockIndex parentBlockIndex, + LexicalBlockIndex blockIndex, + size_t identifierCount) + { + if (!fromCatchClauseNode && parentBlockIndex == LEXICAL_BLOCK_INDEX_MAX && blockIndex == 0 && identifierCount == 0) { + return genericBlockInfo(canAllocateEnvironmentOnStack, shouldAllocateEnvironment); + } + return new BlockInfo( + false, canAllocateEnvironmentOnStack, shouldAllocateEnvironment, + fromCatchClauseNode, parentBlockIndex, blockIndex); + } + + bool isGenericBlockInfo() const + { + return m_isGenericBlockInfo; + } + + bool canAllocateEnvironmentOnStack() const + { + return m_canAllocateEnvironmentOnStack; + } + + void setCanAllocateEnvironmentOnStack(bool b) + { + ASSERT(!isGenericBlockInfo()); + m_canAllocateEnvironmentOnStack = b; + } + + bool shouldAllocateEnvironment() const { + return m_shouldAllocateEnvironment; } + void setShouldAllocateEnvironment(bool b) + { + ASSERT(!isGenericBlockInfo()); + m_shouldAllocateEnvironment = b; + } + + bool fromCatchClauseNode() const + { + return m_fromCatchClauseNode; + } + + LexicalBlockIndex parentBlockIndex() const + { + return m_parentBlockIndex; + } + + void setParentBlockIndex(LexicalBlockIndex b) + { + ASSERT(!isGenericBlockInfo()); + m_parentBlockIndex = b; + } + + LexicalBlockIndex blockIndex() const + { + return m_blockIndex; + } + + void setBlockIndex(LexicalBlockIndex b) + { + ASSERT(!isGenericBlockInfo()); + m_blockIndex = b; + } + + BlockIdentifierInfoVector& identifiers() + { + return m_identifiers; + } + + const BlockIdentifierInfoVector& identifiers() const + { + return m_identifiers; + } + + private: void* operator new(size_t size); void* operator new[](size_t size) = delete; + + bool m_isGenericBlockInfo : 1; + bool m_canAllocateEnvironmentOnStack : 1; + bool m_shouldAllocateEnvironment : 1; + bool m_fromCatchClauseNode : 1; + LexicalBlockIndex m_parentBlockIndex; + LexicalBlockIndex m_blockIndex; + BlockIdentifierInfoVector m_identifiers; }; typedef TightVector> BlockInfoVector; @@ -727,7 +827,7 @@ class InterpretedCodeBlock : public CodeBlock { BlockInfo* blockInfo(LexicalBlockIndex blockIndex) { for (size_t i = 0; i < m_blockInfos.size(); i++) { - if (m_blockInfos[i]->m_blockIndex == blockIndex) { + if (m_blockInfos[i]->blockIndex() == blockIndex) { return m_blockInfos[i]; } } @@ -915,7 +1015,7 @@ class InterpretedCodeBlock : public CodeBlock { size_t blockVectorIndex = SIZE_MAX; size_t blockInfoSize = m_blockInfos.size(); for (size_t i = 0; i < blockInfoSize; i++) { - if (m_blockInfos[i]->m_blockIndex == blockIndex) { + if (m_blockInfos[i]->blockIndex() == blockIndex) { b = m_blockInfos[i]; blockVectorIndex = i; break; @@ -924,7 +1024,7 @@ class InterpretedCodeBlock : public CodeBlock { ASSERT(b != nullptr); while (true) { - auto& v = b->m_identifiers; + auto& v = b->identifiers(); size_t idSize = v.size(); for (size_t i = 0; i < idSize; i++) { if (v[i].m_name == name) { @@ -932,7 +1032,7 @@ class InterpretedCodeBlock : public CodeBlock { } } - if (b->m_parentBlockIndex == LEXICAL_BLOCK_INDEX_MAX) { + if (b->parentBlockIndex() == LEXICAL_BLOCK_INDEX_MAX) { break; } @@ -940,7 +1040,7 @@ class InterpretedCodeBlock : public CodeBlock { bool finded = false; #endif for (size_t i = 0; i < blockInfoSize; i++) { - if (m_blockInfos[i]->m_blockIndex == b->m_parentBlockIndex) { + if (m_blockInfos[i]->blockIndex() == b->parentBlockIndex()) { b = m_blockInfos[i]; blockVectorIndex = i; #ifndef NDEBUG diff --git a/src/parser/Script.cpp b/src/parser/Script.cpp index c593feb0a..5e81aac97 100644 --- a/src/parser/Script.cpp +++ b/src/parser/Script.cpp @@ -410,7 +410,7 @@ Value Script::execute(ExecutionState& state, bool isExecuteOnEvalFunction, bool const InterpretedCodeBlock::IdentifierInfoVector& identifierVector = m_topCodeBlock->identifierInfos(); size_t identifierVectorLen = identifierVector.size(); - const auto& globalLexicalVector = m_topCodeBlock->blockInfo(0)->m_identifiers; + const auto& globalLexicalVector = m_topCodeBlock->blockInfo(0)->identifiers(); size_t globalLexicalVectorLen = globalLexicalVector.size(); if (!isExecuteOnEvalFunction) { @@ -1015,9 +1015,9 @@ Value Script::moduleInitializeEnvironment(ExecutionState& state) InterpretedCodeBlock::BlockInfo* bi = m_topCodeBlock->blockInfo(0); if (bi) { - len = bi->m_identifiers.size(); + len = bi->identifiers().size(); for (size_t i = 0; i < len; i++) { - moduleRecord->createBinding(state, bi->m_identifiers[i].m_name, false, bi->m_identifiers[i].m_isMutable, false); + moduleRecord->createBinding(state, bi->identifiers()[i].m_name, false, bi->identifiers()[i].m_isMutable, false); } } diff --git a/src/parser/ScriptParser.cpp b/src/parser/ScriptParser.cpp index 0a265ef4e..240986c00 100644 --- a/src/parser/ScriptParser.cpp +++ b/src/parser/ScriptParser.cpp @@ -239,7 +239,7 @@ InterpretedCodeBlock* ScriptParser::generateCodeBlockTreeFromASTWalker(Context* if (r.first) { // if variable is global variable, we don't need to capture it - if (!codeBlock->hasAncestorUsesNonIndexedVariableStorage() && !c->isKindOfFunction() && (r.second == SIZE_MAX || c->blockInfos()[r.second]->m_parentBlockIndex == LEXICAL_BLOCK_INDEX_MAX)) { + if (!codeBlock->hasAncestorUsesNonIndexedVariableStorage() && !c->isKindOfFunction() && (r.second == SIZE_MAX || c->blockInfos()[r.second]->parentBlockIndex() == LEXICAL_BLOCK_INDEX_MAX)) { } else { if (r.second == SIZE_MAX) { // captured variable is `var` declared variable @@ -764,17 +764,17 @@ void ScriptParser::dumpCodeBlockTree(InterpretedCodeBlock* topCodeBlock) for (size_t i = 0; i < cb->m_blockInfos.size(); i++) { puts(""); PRINT_TAB_BLOCK() - printf("Block %p %d:%d [%d parent(%d)]: %s, %s", cb->m_blockInfos[i], (int)cb->scopeContext()->m_childBlockScopes[i]->m_loc.line, (int)cb->scopeContext()->m_childBlockScopes[i]->m_loc.column, (int)cb->m_blockInfos[i]->m_blockIndex, (int)cb->m_blockInfos[i]->m_parentBlockIndex, cb->m_blockInfos[i]->m_canAllocateEnvironmentOnStack ? "Stack" : "Heap", cb->m_blockInfos[i]->m_shouldAllocateEnvironment ? "Allocated" : "Skipped"); + printf("Block %p %d:%d [%d parent(%d)]: %s, %s", cb->m_blockInfos[i], (int)cb->scopeContext()->m_childBlockScopes[i]->m_loc.line, (int)cb->scopeContext()->m_childBlockScopes[i]->m_loc.column, (int)cb->m_blockInfos[i]->blockIndex(), (int)cb->m_blockInfos[i]->parentBlockIndex(), cb->m_blockInfos[i]->canAllocateEnvironmentOnStack() ? "Stack" : "Heap", cb->m_blockInfos[i]->shouldAllocateEnvironment() ? "Allocated" : "Skipped"); puts(""); PRINT_TAB_BLOCK() printf("Names : "); - for (size_t j = 0; j < cb->m_blockInfos[i]->m_identifiers.size(); j++) { - printf("%s(%s, %s, %d), ", cb->m_blockInfos[i]->m_identifiers[j].m_name.string()->toUTF8StringData().data(), - cb->m_blockInfos[i]->m_identifiers[j].m_needToAllocateOnStack ? "Stack" : "Heap", - cb->m_blockInfos[i]->m_identifiers[j].m_isMutable ? "Mutable" : "Inmmutable", - (int)cb->m_blockInfos[i]->m_identifiers[j].m_indexForIndexedStorage); + for (size_t j = 0; j < cb->m_blockInfos[i]->identifiers().size(); j++) { + printf("%s(%s, %s, %d), ", cb->m_blockInfos[i]->identifiers()[j].m_name.string()->toUTF8StringData().data(), + cb->m_blockInfos[i]->identifiers()[j].m_needToAllocateOnStack ? "Stack" : "Heap", + cb->m_blockInfos[i]->identifiers()[j].m_isMutable ? "Mutable" : "Inmmutable", + (int)cb->m_blockInfos[i]->identifiers()[j].m_indexForIndexedStorage); } puts(""); diff --git a/src/parser/ast/ForInOfStatementNode.h b/src/parser/ast/ForInOfStatementNode.h index 9dda3cd81..a0796921a 100644 --- a/src/parser/ast/ForInOfStatementNode.h +++ b/src/parser/ast/ForInOfStatementNode.h @@ -65,12 +65,12 @@ class ForInOfStatementNode : public StatementNode { if (m_iterationLexicalBlockIndex != LEXICAL_BLOCK_INDEX_MAX) { InterpretedCodeBlock::BlockInfo* bi = codeBlock->m_codeBlock->blockInfo(m_iterationLexicalBlockIndex); std::vector nameRegisters; - for (size_t i = 0; i < bi->m_identifiers.size(); i++) { + for (size_t i = 0; i < bi->identifiers().size(); i++) { nameRegisters.push_back(newContext.getRegister()); } - for (size_t i = 0; i < bi->m_identifiers.size(); i++) { - IdentifierNode* id = new (tmpIdentifierNode) IdentifierNode(bi->m_identifiers[i].m_name); + for (size_t i = 0; i < bi->identifiers().size(); i++) { + IdentifierNode* id = new (tmpIdentifierNode) IdentifierNode(bi->identifiers()[i].m_name); id->m_loc = m_loc; id->generateExpressionByteCode(codeBlock, &newContext, nameRegisters[i]); } @@ -78,13 +78,13 @@ class ForInOfStatementNode : public StatementNode { newContext.m_lexicalBlockIndex = m_iterationLexicalBlockIndex; iterationBlockContext = codeBlock->pushLexicalBlock(&newContext, bi, this); - for (size_t i = 0; i < bi->m_identifiers.size(); i++) { - newContext.addLexicallyDeclaredNames(bi->m_identifiers[i].m_name); + for (size_t i = 0; i < bi->identifiers().size(); i++) { + newContext.addLexicallyDeclaredNames(bi->identifiers()[i].m_name); } - size_t reverse = bi->m_identifiers.size() - 1; - for (size_t i = 0; i < bi->m_identifiers.size(); i++, reverse--) { - IdentifierNode* id = new (tmpIdentifierNode) IdentifierNode(bi->m_identifiers[reverse].m_name); + size_t reverse = bi->identifiers().size() - 1; + for (size_t i = 0; i < bi->identifiers().size(); i++, reverse--) { + IdentifierNode* id = new (tmpIdentifierNode) IdentifierNode(bi->identifiers()[reverse].m_name); id->m_loc = m_loc; newContext.m_isLexicallyDeclaredBindingInitialization = m_hasLexicalDeclarationOnInit; id->generateStoreByteCode(codeBlock, &newContext, nameRegisters[reverse], true); @@ -101,12 +101,12 @@ class ForInOfStatementNode : public StatementNode { if (m_iterationLexicalBlockIndex != LEXICAL_BLOCK_INDEX_MAX) { InterpretedCodeBlock::BlockInfo* bi = codeBlock->m_codeBlock->blockInfo(m_iterationLexicalBlockIndex); std::vector nameRegisters; - for (size_t i = 0; i < bi->m_identifiers.size(); i++) { + for (size_t i = 0; i < bi->identifiers().size(); i++) { nameRegisters.push_back(newContext.getRegister()); } - for (size_t i = 0; i < bi->m_identifiers.size(); i++) { - IdentifierNode* id = new (tmpIdentifierNode) IdentifierNode(bi->m_identifiers[i].m_name); + for (size_t i = 0; i < bi->identifiers().size(); i++) { + IdentifierNode* id = new (tmpIdentifierNode) IdentifierNode(bi->identifiers()[i].m_name); id->m_loc = m_loc; id->generateExpressionByteCode(codeBlock, &newContext, nameRegisters[i]); } @@ -114,9 +114,9 @@ class ForInOfStatementNode : public StatementNode { codeBlock->finalizeLexicalBlock(&newContext, iterationBlockContext); newContext.m_lexicalBlockIndex = iterationLexicalBlockIndexBefore; - size_t reverse = bi->m_identifiers.size() - 1; - for (size_t i = 0; i < bi->m_identifiers.size(); i++, reverse--) { - IdentifierNode* id = new (tmpIdentifierNode) IdentifierNode(bi->m_identifiers[reverse].m_name); + size_t reverse = bi->identifiers().size() - 1; + for (size_t i = 0; i < bi->identifiers().size(); i++, reverse--) { + IdentifierNode* id = new (tmpIdentifierNode) IdentifierNode(bi->identifiers()[reverse].m_name); id->m_loc = m_loc; newContext.m_isLexicallyDeclaredBindingInitialization = m_hasLexicalDeclarationOnInit; id->generateStoreByteCode(codeBlock, &newContext, nameRegisters[reverse], true); diff --git a/src/parser/ast/ForStatementNode.h b/src/parser/ast/ForStatementNode.h index 8361dd7ab..57b508aad 100644 --- a/src/parser/ast/ForStatementNode.h +++ b/src/parser/ast/ForStatementNode.h @@ -85,12 +85,12 @@ class ForStatementNode : public StatementNode { if (m_iterationLexicalBlockIndex != LEXICAL_BLOCK_INDEX_MAX) { InterpretedCodeBlock::BlockInfo* bi = codeBlock->m_codeBlock->blockInfo(m_iterationLexicalBlockIndex); std::vector nameRegisters; - for (size_t i = 0; i < bi->m_identifiers.size(); i++) { + for (size_t i = 0; i < bi->identifiers().size(); i++) { nameRegisters.push_back(newContext.getRegister()); } - for (size_t i = 0; i < bi->m_identifiers.size(); i++) { - IdentifierNode* id = new (tempNode) IdentifierNode(bi->m_identifiers[i].m_name); + for (size_t i = 0; i < bi->identifiers().size(); i++) { + IdentifierNode* id = new (tempNode) IdentifierNode(bi->identifiers()[i].m_name); id->m_loc = m_loc; id->generateExpressionByteCode(codeBlock, &newContext, nameRegisters[i]); } @@ -98,13 +98,13 @@ class ForStatementNode : public StatementNode { newContext.m_lexicalBlockIndex = m_iterationLexicalBlockIndex; iterationBlockContext = codeBlock->pushLexicalBlock(&newContext, bi, this); - for (size_t i = 0; i < bi->m_identifiers.size(); i++) { - newContext.addLexicallyDeclaredNames(bi->m_identifiers[i].m_name); + for (size_t i = 0; i < bi->identifiers().size(); i++) { + newContext.addLexicallyDeclaredNames(bi->identifiers()[i].m_name); } - size_t reverse = bi->m_identifiers.size() - 1; - for (size_t i = 0; i < bi->m_identifiers.size(); i++, reverse--) { - IdentifierNode* id = new (tempNode) IdentifierNode(bi->m_identifiers[reverse].m_name); + size_t reverse = bi->identifiers().size() - 1; + for (size_t i = 0; i < bi->identifiers().size(); i++, reverse--) { + IdentifierNode* id = new (tempNode) IdentifierNode(bi->identifiers()[reverse].m_name); id->m_loc = m_loc; newContext.m_isLexicallyDeclaredBindingInitialization = m_hasLexicalDeclarationOnInit; id->generateStoreByteCode(codeBlock, &newContext, nameRegisters[reverse], true); @@ -114,7 +114,7 @@ class ForStatementNode : public StatementNode { // we should increase this count here. // because the block was created after newContext creation - if (bi->m_shouldAllocateEnvironment) { + if (bi->shouldAllocateEnvironment()) { newContext.m_complexJumpContinueIgnoreCount++; newContext.m_complexJumpBreakIgnoreCount++; } @@ -157,16 +157,16 @@ class ForStatementNode : public StatementNode { // replace env if needed if (m_iterationLexicalBlockIndex != LEXICAL_BLOCK_INDEX_MAX) { InterpretedCodeBlock::BlockInfo* bi = codeBlock->m_codeBlock->blockInfo(m_iterationLexicalBlockIndex); - if (bi->m_shouldAllocateEnvironment) { + if (bi->shouldAllocateEnvironment()) { newContext.getRegister(); std::vector nameRegisters; - for (size_t i = 0; i < bi->m_identifiers.size(); i++) { + for (size_t i = 0; i < bi->identifiers().size(); i++) { nameRegisters.push_back(newContext.getRegister()); } - for (size_t i = 0; i < bi->m_identifiers.size(); i++) { - IdentifierNode* id = new (tempNode) IdentifierNode(bi->m_identifiers[i].m_name); + for (size_t i = 0; i < bi->identifiers().size(); i++) { + IdentifierNode* id = new (tempNode) IdentifierNode(bi->identifiers()[i].m_name); id->m_loc = m_loc; id->generateExpressionByteCode(codeBlock, &newContext, nameRegisters[i]); } @@ -175,9 +175,9 @@ class ForStatementNode : public StatementNode { codeBlock->initFunctionDeclarationWithinBlock(&newContext, bi, this); - size_t reverse = bi->m_identifiers.size() - 1; - for (size_t i = 0; i < bi->m_identifiers.size(); i++, reverse--) { - IdentifierNode* id = new (tempNode) IdentifierNode(bi->m_identifiers[reverse].m_name); + size_t reverse = bi->identifiers().size() - 1; + for (size_t i = 0; i < bi->identifiers().size(); i++, reverse--) { + IdentifierNode* id = new (tempNode) IdentifierNode(bi->identifiers()[reverse].m_name); id->m_loc = m_loc; newContext.m_isLexicallyDeclaredBindingInitialization = m_hasLexicalDeclarationOnInit; id->generateStoreByteCode(codeBlock, &newContext, nameRegisters[reverse], true); @@ -213,7 +213,7 @@ class ForStatementNode : public StatementNode { InterpretedCodeBlock::BlockInfo* bi = codeBlock->m_codeBlock->blockInfo(m_iterationLexicalBlockIndex); codeBlock->finalizeLexicalBlock(&newContext, iterationBlockContext); newContext.m_lexicalBlockIndex = iterationLexicalBlockIndexBefore; - if (bi->m_shouldAllocateEnvironment) { + if (bi->shouldAllocateEnvironment()) { newContext.m_complexJumpContinueIgnoreCount--; } } diff --git a/src/parser/esprima_cpp/esprima.cpp b/src/parser/esprima_cpp/esprima.cpp index 008d17181..52d8a1979 100644 --- a/src/parser/esprima_cpp/esprima.cpp +++ b/src/parser/esprima_cpp/esprima.cpp @@ -3708,7 +3708,7 @@ class Parser { if (this->isParsingSingleFunction) { bool finded = false; for (size_t i = 0; i < this->codeBlock->blockInfos().size(); i++) { - if (this->codeBlock->blockInfos()[i]->m_blockIndex == ctx.childLexicalBlockIndex) { + if (this->codeBlock->blockInfos()[i]->blockIndex() == ctx.childLexicalBlockIndex) { finded = true; break; } diff --git a/src/runtime/EnvironmentRecord.h b/src/runtime/EnvironmentRecord.h index 6a4d2c484..874c35cfc 100644 --- a/src/runtime/EnvironmentRecord.h +++ b/src/runtime/EnvironmentRecord.h @@ -411,7 +411,7 @@ class DeclarativeEnvironmentRecordIndexed : public DeclarativeEnvironmentRecord , m_blockInfo(blockInfo) , m_heapStorage() { - const auto& v = m_blockInfo->m_identifiers; + const auto& v = m_blockInfo->identifiers(); size_t cnt = 0; size_t siz = v.size(); @@ -447,7 +447,7 @@ class DeclarativeEnvironmentRecordIndexed : public DeclarativeEnvironmentRecord virtual GetBindingValueResult getBindingValue(ExecutionState& state, const AtomicString& name) override { - const auto& v = m_blockInfo->m_identifiers; + const auto& v = m_blockInfo->identifiers(); for (size_t i = 0; i < v.size(); i++) { if (v[i].m_name == name) { @@ -459,7 +459,7 @@ class DeclarativeEnvironmentRecordIndexed : public DeclarativeEnvironmentRecord virtual BindingSlot hasBinding(ExecutionState& state, const AtomicString& name) override { - const auto& v = m_blockInfo->m_identifiers; + const auto& v = m_blockInfo->identifiers(); for (size_t i = 0; i < v.size(); i++) { if (v[i].m_name == name) { return BindingSlot(this, v[i].m_indexForIndexedStorage, true); @@ -501,7 +501,7 @@ class DeclarativeEnvironmentRecordIndexed : public DeclarativeEnvironmentRecord void throwReferenceError(ExecutionState& state, const size_t idx) { - const auto& v = m_blockInfo->m_identifiers; + const auto& v = m_blockInfo->identifiers(); size_t cnt = 0; for (size_t i = 0; i < v.size(); i++) { if (!v[i].m_needToAllocateOnStack) { @@ -515,7 +515,7 @@ class DeclarativeEnvironmentRecordIndexed : public DeclarativeEnvironmentRecord virtual void setMutableBinding(ExecutionState& state, const AtomicString& name, const Value& V) override { - const auto& v = m_blockInfo->m_identifiers; + const auto& v = m_blockInfo->identifiers(); for (size_t i = 0; i < v.size(); i++) { if (v[i].m_name == name) { @@ -528,7 +528,7 @@ class DeclarativeEnvironmentRecordIndexed : public DeclarativeEnvironmentRecord virtual void initializeBinding(ExecutionState& state, const AtomicString& name, const Value& V) override { - const auto& v = m_blockInfo->m_identifiers; + const auto& v = m_blockInfo->identifiers(); for (size_t i = 0; i < v.size(); i++) { if (v[i].m_name == name) { diff --git a/src/runtime/GlobalObject.cpp b/src/runtime/GlobalObject.cpp index b04c10c75..17df327a1 100644 --- a/src/runtime/GlobalObject.cpp +++ b/src/runtime/GlobalObject.cpp @@ -102,7 +102,7 @@ static Value builtinIsBlockAllocatedOnStack(ExecutionState& state, Value thisVal if (arg.isObject() && arg.asObject()->isScriptFunctionObject()) { auto bi = arg.asObject()->asScriptFunctionObject()->interpretedCodeBlock()->blockInfo((uint16_t)blockIndex); if (bi) { - result = bi->m_canAllocateEnvironmentOnStack; + result = bi->canAllocateEnvironmentOnStack(); } }