From a9f4fe7394f1297187c751c1948ef3147384a5bb Mon Sep 17 00:00:00 2001 From: renguangxuan Date: Sat, 16 Nov 2024 19:46:21 +0800 Subject: [PATCH] Roll back es2abc memory optimization Issue: #IB4U6V Signed-off-by: renguangxuan Change-Id: I906027892e984b9b5b080cbfa64c59cfdbc55c40 --- abc2program/dump_utils.cpp | 1 + .../cpp_sources/abc2program_test_utils.cpp | 11 +++--- .../tests/ts/HelloWorldDebugDumpExpected.txt | 4 --- .../tests/ts/HelloWorldDumpExpected.txt | 4 --- assembler/assembly-debug.h | 3 +- assembler/assembly-emitter.cpp | 35 +++++++++---------- assembler/assembly-emitter.h | 6 ---- assembler/assembly-function.h | 3 +- assembler/assembly-parser.cpp | 8 +++-- assembler/tests/assembler_emitter_test.cpp | 18 +++------- bytecode_optimizer/tests/codegen_test.cpp | 23 ++++-------- 11 files changed, 42 insertions(+), 74 deletions(-) diff --git a/abc2program/dump_utils.cpp b/abc2program/dump_utils.cpp index 951147fff5..35fd69987d 100644 --- a/abc2program/dump_utils.cpp +++ b/abc2program/dump_utils.cpp @@ -112,6 +112,7 @@ pandasm::Ins PandasmDumperUtils::DeepCopyIns(const pandasm::Ins &input) auto &debug_ins = res.ins_debug; debug_ins.line_number = input.ins_debug.line_number; debug_ins.column_number = input.ins_debug.column_number; + debug_ins.whole_line = input.ins_debug.whole_line; debug_ins.bound_left = input.ins_debug.bound_left; debug_ins.bound_right = input.ins_debug.bound_right; return res; diff --git a/abc2program/tests/cpp_sources/abc2program_test_utils.cpp b/abc2program/tests/cpp_sources/abc2program_test_utils.cpp index 1543e27b48..4065f22c32 100644 --- a/abc2program/tests/cpp_sources/abc2program_test_utils.cpp +++ b/abc2program/tests/cpp_sources/abc2program_test_utils.cpp @@ -54,13 +54,10 @@ std::set Abc2ProgramTestUtils::helloworld_expected_program_strings_ "toString", "varA", "x"}; -std::vector Abc2ProgramTestUtils::helloworld_expected_record_names_ = { - "_ESConcurrentModuleRequestsAnnotation", - "_ESModuleRecord", - "_ESSlotNumberAnnotation", - "_ESScopeNamesRecord", - "_GLOBAL" -}; +std::vector Abc2ProgramTestUtils::helloworld_expected_record_names_ = {"_ESModuleRecord", + "_ESSlotNumberAnnotation", + "_ESScopeNamesRecord", + "_GLOBAL"}; std::vector Abc2ProgramTestUtils::helloworld_expected_literal_array_keys_ = {"_ESModuleRecord", "_ESScopeNamesRecord", "_GLOBAL", diff --git a/abc2program/tests/ts/HelloWorldDebugDumpExpected.txt b/abc2program/tests/ts/HelloWorldDebugDumpExpected.txt index 1902b721db..31723baef7 100644 --- a/abc2program/tests/ts/HelloWorldDebugDumpExpected.txt +++ b/abc2program/tests/ts/HelloWorldDebugDumpExpected.txt @@ -26,10 +26,6 @@ _GLOBAL_1799 { 10 [ tag_value:2, i32:2, tag_value:5, string:"4newTarget", tag_va # ==================== # RECORDS -.record _ESConcurrentModuleRequestsAnnotation { -} -.record.source_file - .record _ESModuleRecord { u32 arkcompiler/runtime_core/abc2program/tests/ts/HelloWorld.ts _ESModuleRecord_3278 } diff --git a/abc2program/tests/ts/HelloWorldDumpExpected.txt b/abc2program/tests/ts/HelloWorldDumpExpected.txt index d5363c1c10..c6c9c2096e 100644 --- a/abc2program/tests/ts/HelloWorldDumpExpected.txt +++ b/abc2program/tests/ts/HelloWorldDumpExpected.txt @@ -24,10 +24,6 @@ _GLOBAL_1584 { 10 [ tag_value:5, string:"NestedLiteralArray", tag_value:6, metho # ==================== # RECORDS -.record _ESConcurrentModuleRequestsAnnotation { -} -.record.source_file - .record _ESModuleRecord { u32 arkcompiler/runtime_core/abc2program/tests/ts/HelloWorld.ts _ESModuleRecord_1466 } diff --git a/assembler/assembly-debug.h b/assembler/assembly-debug.h index 9742a8203c..ba1c9d7d5f 100644 --- a/assembler/assembly-debug.h +++ b/assembler/assembly-debug.h @@ -23,6 +23,7 @@ namespace panda::pandasm::debuginfo { struct Ins { size_t line_number = 0; uint32_t column_number = 0; + std::string whole_line = ""; // TODO(mbolshov): redundant given file and line_number size_t bound_left = 0; size_t bound_right = 0; @@ -38,7 +39,7 @@ struct Ins { Ins() = default; Ins(size_t l_n, std::string &f_c, size_t b_l, size_t b_r) - : line_number(l_n), bound_left(b_l), bound_right(b_r) + : line_number(l_n), whole_line(std::move(f_c)), bound_left(b_l), bound_right(b_r) { } }; diff --git a/assembler/assembly-emitter.cpp b/assembler/assembly-emitter.cpp index 2a6869b847..cffcc649d1 100644 --- a/assembler/assembly-emitter.cpp +++ b/assembler/assembly-emitter.cpp @@ -1189,11 +1189,9 @@ bool AsmEmitter::AddMethodAndParamsAnnotations(ItemContainer *items, const Progr auto ¶m_items = method->GetParams(); for (size_t proto_idx = 0; proto_idx < param_items.size(); proto_idx++) { size_t param_idx = method->IsStatic() ? proto_idx : proto_idx + 1; + auto ¶m = func.params[param_idx]; auto ¶m_item = param_items[proto_idx]; - // The ArkTs language does not collect this metadata data information. - // Thereore, this parameter is set to the default value to ensure code consistency and compatibility. - auto metadata = extensions::MetadataExtension::CreateParamMetadata(pandasm::extensions::Language::ECMASCRIPT); - if (!AddAnnotations(¶m_item, items, *metadata, program, entities)) { + if (!AddAnnotations(¶m_item, items, *param.metadata, program, entities)) { SetLastError("Cannot emit annotations for parameter a" + std::to_string(param_idx) + "of function " + func.name + ": " + GetLastError()); return false; @@ -1360,7 +1358,7 @@ bool AsmEmitter::MakeItemsForSingleProgram(ItemContainer *items, const Program & } // temp plan for ic slot number, should be deleted after method refactoring -void MakeSlotNumberRecord(Program *prog) +static void MakeSlotNumberRecord(Program *prog) { static const std::string SLOT_NUMBER = "_ESSlotNumberAnnotation"; pandasm::Record record(SLOT_NUMBER, pandasm::extensions::Language::ECMASCRIPT); @@ -1369,7 +1367,7 @@ void MakeSlotNumberRecord(Program *prog) } // temp plan for ic slot number, should be deleted after method refactoring -void MakeSlotNumberAnnotation(Program *prog) +static void MakeSlotNumberAnnotation(Program *prog) { static const std::string SLOT_NUMBER = "_ESSlotNumberAnnotation"; static const std::string ELEMENT_NAME = "SlotNumber"; @@ -1389,7 +1387,7 @@ void MakeSlotNumberAnnotation(Program *prog) } } -void MakeConcurrentModuleRequestsRecord(Program *prog) +static void MakeConcurrentModuleRequestsRecord(Program *prog) { static const std::string CONCURRENT_MODULE_REQUESTS = "_ESConcurrentModuleRequestsAnnotation"; pandasm::Record record(CONCURRENT_MODULE_REQUESTS, pandasm::extensions::Language::ECMASCRIPT); @@ -1397,7 +1395,7 @@ void MakeConcurrentModuleRequestsRecord(Program *prog) prog->record_table.emplace(CONCURRENT_MODULE_REQUESTS, std::move(record)); } -void MakeConcurrentModuleRequestsAnnotation(Program *prog) +static void MakeConcurrentModuleRequestsAnnotation(Program *prog) { static const std::string CONCURRENT_MODULE_REQUESTS = "_ESConcurrentModuleRequestsAnnotation"; static const std::string ELEMENT_NAME = "ConcurrentModuleRequest"; @@ -1425,11 +1423,16 @@ void MakeConcurrentModuleRequestsAnnotation(Program *prog) } } -// The function releases the data in progs in advance for the sake of the peak memory at compiler time. bool AsmEmitter::EmitPrograms(const std::string &filename, const std::vector &progs, bool emit_debug_info, uint8_t api, std::string subApi) { ASSERT(!progs.empty()); + for (auto *prog : progs) { + MakeSlotNumberRecord(prog); + MakeSlotNumberAnnotation(prog); + MakeConcurrentModuleRequestsRecord(prog); + MakeConcurrentModuleRequestsAnnotation(prog); + } ItemContainer::SetApi(api); ItemContainer::SetSubApi(subApi); @@ -1438,31 +1441,25 @@ bool AsmEmitter::EmitPrograms(const std::string &filename, const std::vectorstrings.clear(); - prog->literalarray_table.clear(); - prog->array_types.clear(); } - for (auto *prog : progs) { + for (const auto *prog : progs) { if (!MakeFunctionDebugInfoAndAnnotations(&items, *prog, entities, emit_debug_info)) { return false; } - prog->function_synonyms.clear(); } items.ReLayout(); items.ComputeLayout(); - for (auto *prog : progs) { + for (const auto *prog : progs) { if (!EmitFunctions(&items, *prog, entities, emit_debug_info)) { return false; } - prog->function_table.clear(); - prog->record_table.clear(); } auto writer = FileWriter(filename); @@ -1478,6 +1475,8 @@ bool AsmEmitter::EmitPrograms(const std::string &filename, const std::vector(&program)); + MakeSlotNumberAnnotation(const_cast(&program)); auto primitive_types = CreatePrimitiveTypes(items); auto entities = AsmEmitter::AsmEntityCollections {}; diff --git a/assembler/assembly-emitter.h b/assembler/assembly-emitter.h index f403d0c7c7..ce8dcde4b8 100644 --- a/assembler/assembly-emitter.h +++ b/assembler/assembly-emitter.h @@ -31,12 +31,6 @@ #include "pgo.h" namespace panda::pandasm { - -void MakeConcurrentModuleRequestsAnnotation(Program *prog); -void MakeConcurrentModuleRequestsRecord(Program *prog); -void MakeSlotNumberAnnotation(Program *prog); -void MakeSlotNumberRecord(Program *prog); - class AsmEmitter { public: struct PandaFileToPandaAsmMaps { diff --git a/assembler/assembly-function.h b/assembler/assembly-function.h index ca1ddf4fbd..3ca32aca6f 100755 --- a/assembler/assembly-function.h +++ b/assembler/assembly-function.h @@ -61,9 +61,10 @@ struct Function { struct Parameter { Type type; + std::unique_ptr metadata; Parameter(Type t, panda::panda_file::SourceLang lang) - : type(std::move(t)) + : type(std::move(t)), metadata(extensions::MetadataExtension::CreateParamMetadata(lang)) { } }; diff --git a/assembler/assembly-parser.cpp b/assembler/assembly-parser.cpp index 9eccf9655c..331775ff9b 100644 --- a/assembler/assembly-parser.cpp +++ b/assembler/assembly-parser.cpp @@ -680,7 +680,7 @@ void Parser::ParseResetFunctionLabelsAndParams() const auto &debug = curr_func_->ins[v.first - 1].ins_debug; context_.err = Error("Register width mismatch.", debug.line_number, Error::ErrorType::ERR_BAD_NAME_REG, "", - debug.bound_left, debug.bound_right, ""); + debug.bound_left, debug.bound_right, debug.whole_line); SetError(); break; } @@ -714,7 +714,7 @@ void Parser::ParseResetFunctionTable() const auto &debug = insn_it->ins_debug; context_.err = Error("Unable to resolve ambiguous function call", debug.line_number, Error::ErrorType::ERR_FUNCTION_MULTIPLE_ALTERNATIVES, "", debug.bound_left, - debug.bound_right, ""); + debug.bound_right, debug.whole_line); SetError(); break; } else { @@ -731,7 +731,7 @@ void Parser::ParseResetFunctionTable() const auto &debug = insn_it->ins_debug; context_.err = Error("Function argument mismatch.", debug.line_number, Error::ErrorType::ERR_FUNCTION_ARGUMENT_MISMATCH, "", debug.bound_left, - debug.bound_right, ""); + debug.bound_right, debug.whole_line); SetError(); } } @@ -2077,6 +2077,7 @@ void Parser::SetOperationInformation() context_.ins_number = curr_func_->ins.size(); auto &curr_debug = curr_func_->ins.back().ins_debug; curr_debug.line_number = line_stric_; + curr_debug.whole_line = context_.tokens[context_.number - 1].whole_line; curr_debug.bound_left = context_.tokens[context_.number - 1].bound_left; curr_debug.bound_right = context_.tokens[context_.number - 1].bound_right; } @@ -2147,6 +2148,7 @@ bool Parser::ParseFunctionArg() ++context_; Function::Parameter parameter(type, program_.lang); + metadata_ = parameter.metadata.get(); if (*context_ == Token::Type::DEL_LT && !ParseMetaDef()) { return false; diff --git a/assembler/tests/assembler_emitter_test.cpp b/assembler/tests/assembler_emitter_test.cpp index 81dc4b116c..af41c3e3d4 100644 --- a/assembler/tests/assembler_emitter_test.cpp +++ b/assembler/tests/assembler_emitter_test.cpp @@ -1009,7 +1009,6 @@ HWTEST_F(AssemblyEmitterTest, assembly_emitter_test_015, TestSize.Level1) ScalarValue insn_order_anno(ScalarValue::Create(annotation)); - panda::pandasm::MakeSlotNumberRecord(&program.Value()); program.Value().record_table.at("R").field_list[0].metadata->SetValue(insn_order_anno); auto pf4 = AsmEmitter::Emit(program.Value()); EXPECT_NE(pf4, nullptr); @@ -1199,15 +1198,14 @@ HWTEST_F(AssemblyEmitterTest, assembly_emitter_test_021, TestSize.Level1) auto source = R"( .function any foo(any a0) )"; + auto res = p.Parse(source); + EXPECT_EQ(p.ShowError().err, Error::ErrorType::ERR_NONE); + + std::vector progs; + progs.push_back(&res.Value()); // api 11 { - auto res = p.Parse(source); - EXPECT_EQ(p.ShowError().err, Error::ErrorType::ERR_NONE); - - std::vector progs; - progs.push_back(&res.Value()); - std::string descriptor; const std::string filename_api11 = "source_021_api11.abc"; auto is_emitted = AsmEmitter::EmitPrograms(filename_api11, progs, false, 11); @@ -1234,12 +1232,6 @@ HWTEST_F(AssemblyEmitterTest, assembly_emitter_test_021, TestSize.Level1) // api 12 { - auto res = p.Parse(source); - EXPECT_EQ(p.ShowError().err, Error::ErrorType::ERR_NONE); - - std::vector progs; - progs.push_back(&res.Value()); - std::string descriptor; const std::string filename_api12 = "source_021_api12.abc"; auto is_emitted = AsmEmitter::EmitPrograms(filename_api12, progs, false, 12); diff --git a/bytecode_optimizer/tests/codegen_test.cpp b/bytecode_optimizer/tests/codegen_test.cpp index 6cea77de88..a5194d9736 100644 --- a/bytecode_optimizer/tests/codegen_test.cpp +++ b/bytecode_optimizer/tests/codegen_test.cpp @@ -428,14 +428,8 @@ HWTEST_F(CodegenTest, codegen_test_012, TestSize.Level1) BytecodeOptimizerRuntimeAdapter runtime_adapter(*pfile.get()); RuntimeInterface::MethodPtr caller = nullptr; - auto class_id = pfile->GetClassId(utf::CStringAsMutf8("L_GLOBAL;")); - EXPECT_TRUE(class_id.IsValid()); - panda_file::ClassDataAccessor cda(*pfile.get(), class_id); - - cda.EnumerateMethods([&](panda_file::MethodDataAccessor &mda) { - BytecodeOptimizerRuntimeAdapter::MethodId id = mda.GetMethodId().GetOffset(); - EXPECT_EQ(runtime_adapter.GetMethodArgumentsCount(caller, id), 0); - }); + BytecodeOptimizerRuntimeAdapter::MethodId id = 178; // foo method_id + EXPECT_EQ(runtime_adapter.GetMethodArgumentsCount(caller, id), 0); } /** @@ -456,16 +450,11 @@ HWTEST_F(CodegenTest, codegen_test_013, TestSize.Level1) std::unique_ptr pfile = ParseAndEmit(source); BytecodeOptimizerRuntimeAdapter runtime_adapter(*pfile.get()); - auto class_id = pfile->GetClassId(utf::CStringAsMutf8("L_GLOBAL;")); - EXPECT_TRUE(class_id.IsValid()); - panda_file::ClassDataAccessor cda(*pfile.get(), class_id); + int f = 178; // foo method_id + RuntimeInterface::MethodPtr method; + method=(void*)(long)f; - cda.EnumerateMethods([&](panda_file::MethodDataAccessor &mda) { - BytecodeOptimizerRuntimeAdapter::MethodId id = mda.GetMethodId().GetOffset(); - RuntimeInterface::MethodPtr method; - method=(void*)(long)id; - EXPECT_EQ(runtime_adapter.GetMethodFullName(method, false), "L_GLOBAL;::foo"); - }); + EXPECT_EQ(runtime_adapter.GetMethodFullName(method, false), "L_GLOBAL;::foo"); } /**