From 21a67c5c31cbb695d14ba2fc50e18172f8ac557d Mon Sep 17 00:00:00 2001 From: Ryan Macnak Date: Tue, 31 Mar 2026 08:38:50 -0700 Subject: [PATCH] [vm] Flatten stub code handle list. TEST=ci Change-Id: I852120f3af711f385534e5d1b007705fb3aec078 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/491684 Commit-Queue: Ryan Macnak Reviewed-by: Alexander Aprelev --- runtime/vm/stub_code.cc | 40 +++++++++++++++++++--------------------- runtime/vm/stub_code.h | 19 ++++++------------- 2 files changed, 25 insertions(+), 34 deletions(-) diff --git a/runtime/vm/stub_code.cc b/runtime/vm/stub_code.cc index 066f5b6fed6..7961702dddd 100644 --- a/runtime/vm/stub_code.cc +++ b/runtime/vm/stub_code.cc @@ -31,16 +31,7 @@ DEFINE_FLAG(bool, "Generate probe points for installation of user space probes"); #endif -StubCode::StubCodeEntry StubCode::entries_[kNumStubEntries] = { -#if defined(DART_PRECOMPILED_RUNTIME) -#define STUB_CODE_DECLARE(name) {nullptr, #name}, -#else -#define STUB_CODE_DECLARE(name) \ - {nullptr, #name, &compiler::StubCodeCompiler::Generate##name##Stub}, -#endif - VM_STUB_CODE_LIST(STUB_CODE_DECLARE) -#undef STUB_CODE_DECLARE -}; +Code* StubCode::handles_[kNumStubEntries] = {nullptr}; AcqRelAtomic StubCode::initialized_ = {false}; #if defined(DART_PRECOMPILED_RUNTIME) @@ -55,17 +46,24 @@ void StubCode::Init() { compiler::ObjectPoolBuilder object_pool_builder; // Generate all the stubs. - for (size_t i = 0; i < ARRAY_SIZE(entries_); i++) { - entries_[i].code = Code::ReadOnlyHandle(); - *(entries_[i].code) = - Generate(entries_[i].name, &object_pool_builder, entries_[i].generator); + static void (compiler::StubCodeCompiler::* const generators[])() = { +#define STUB_CODE_DECLARE(name) \ + &compiler::StubCodeCompiler::Generate##name##Stub, + VM_STUB_CODE_LIST(STUB_CODE_DECLARE) +#undef STUB_CODE_DECLARE + }; + + for (intptr_t i = 0; i < kNumStubEntries; i++) { + handles_[i] = Code::ReadOnlyHandle(); + *(handles_[i]) = + Generate(StubNames[i], &object_pool_builder, generators[i]); } const ObjectPool& object_pool = ObjectPool::Handle(ObjectPool::NewFromBuilder(object_pool_builder)); - for (size_t i = 0; i < ARRAY_SIZE(entries_); i++) { - entries_[i].code->set_object_pool(object_pool.ptr()); + for (intptr_t i = 0; i < kNumStubEntries; i++) { + handles_[i]->set_object_pool(object_pool.ptr()); } InitializationDone(); @@ -131,8 +129,8 @@ CodePtr StubCode::Generate(const char* name, void StubCode::Cleanup() { initialized_.store(false, std::memory_order_release); - for (size_t i = 0; i < ARRAY_SIZE(entries_); i++) { - entries_[i].code = nullptr; + for (intptr_t i = 0; i < kNumStubEntries; i++) { + handles_[i] = nullptr; } } @@ -349,9 +347,9 @@ const Code& StubCode::UnoptimizedStaticCallEntry(intptr_t num_args_tested) { void StubCode::ForEachStub( const std::function& callback) { - for (size_t i = 0; i < ARRAY_SIZE(entries_); i++) { - if (entries_[i].code != nullptr && !entries_[i].code->IsNull()) { - if (!callback(entries_[i].name, entries_[i].code->EntryPoint())) { + for (intptr_t i = 0; i < kNumStubEntries; i++) { + if (handles_[i] != nullptr && !handles_[i]->IsNull()) { + if (!callback(StubNames[i], handles_[i]->EntryPoint())) { return; } } diff --git a/runtime/vm/stub_code.h b/runtime/vm/stub_code.h index d24989974e3..615dfe47d26 100644 --- a/runtime/vm/stub_code.h +++ b/runtime/vm/stub_code.h @@ -69,7 +69,7 @@ class StubCode : public AllStatic { // Define the shared stub code accessors. #define STUB_CODE_ACCESSOR(name) \ - static const Code& name() { return *entries_[k##name##Index].code; } \ + static const Code& name() { return *handles_[k##name##Index]; } \ static intptr_t name##Size() { return name().Size(); } VM_STUB_CODE_LIST(STUB_CODE_ACCESSOR); #undef STUB_CODE_ACCESSOR @@ -108,13 +108,13 @@ class StubCode : public AllStatic { static const Code& UnoptimizedStaticCallEntry(intptr_t num_args_tested); - static const char* NameAt(intptr_t index) { return entries_[index].name; } + static const char* NameAt(intptr_t index) { return StubNames[index]; } - static const Code& EntryAt(intptr_t index) { return *(entries_[index].code); } + static const Code& EntryAt(intptr_t index) { return *(handles_[index]); } static void EntryAtPut(intptr_t index, Code* entry) { DEBUG_ASSERT(entry->IsReadOnlyHandle()); - ASSERT(entries_[index].code == nullptr); - entries_[index].code = entry; + ASSERT(handles_[index] == nullptr); + handles_[index] = entry; } static intptr_t NumEntries() { return kNumStubEntries; } @@ -140,14 +140,7 @@ class StubCode : public AllStatic { kNumStubEntries }; - struct StubCodeEntry { - Code* code; - const char* name; -#if !defined(DART_PRECOMPILED_RUNTIME) - void (compiler::StubCodeCompiler::*generator)(); -#endif - }; - static StubCodeEntry entries_[kNumStubEntries]; + static Code* handles_[kNumStubEntries]; static AcqRelAtomic initialized_; };