From b60def0de453cec395af49453acaf13518dd73a7 Mon Sep 17 00:00:00 2001 From: Alexander Markov Date: Thu, 15 Aug 2019 16:45:10 +0000 Subject: [PATCH] [vm] Fix notifications of code observers from background compiler This CL fixes crash in vm/cc/DartAPI_DartInitializeCallsCodeObserver test after kernel service is switched to bytecode (so background compilations are more likely to happen). Change-Id: Idfc97f16f8658c953628ba0a878b1d6dd2d46186 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/113134 Reviewed-by: Ryan Macnak Reviewed-by: Martin Kustermann Commit-Queue: Alexander Markov --- runtime/vm/object.cc | 3 +++ runtime/vm/stub_code.cc | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/runtime/vm/object.cc b/runtime/vm/object.cc index 748802647c3..89c1cc2d22f 100644 --- a/runtime/vm/object.cc +++ b/runtime/vm/object.cc @@ -15053,6 +15053,7 @@ void Code::NotifyCodeObservers(const Function& function, const Code& code, bool optimized) { #if !defined(PRODUCT) + ASSERT(!function.IsNull()); ASSERT(!Thread::Current()->IsAtSafepoint()); // Calling ToLibNamePrefixedQualifiedCString is very expensive, // try to avoid it. @@ -15067,6 +15068,8 @@ void Code::NotifyCodeObservers(const char* name, const Code& code, bool optimized) { #if !defined(PRODUCT) + ASSERT(name != nullptr); + ASSERT(!code.IsNull()); ASSERT(!Thread::Current()->IsAtSafepoint()); if (CodeObservers::AreActive()) { const auto& instrs = Instructions::Handle(code.instructions()); diff --git a/runtime/vm/stub_code.cc b/runtime/vm/stub_code.cc index c578da0321f..d22df2bce68 100644 --- a/runtime/vm/stub_code.cc +++ b/runtime/vm/stub_code.cc @@ -210,7 +210,7 @@ RawCode* StubCode::GetAllocationStubForClass(const Class& cls) { // We notify code observers after finalizing the code in order to be // outside a [SafepointOperationScope]. - Code::NotifyCodeObservers(nullptr, stub, /*optimized=*/false); + Code::NotifyCodeObservers(name, stub, /*optimized=*/false); } #ifndef PRODUCT if (FLAG_support_disassembler && FLAG_disassemble_stubs) {