diff --git a/runtime/tests/vm/dart/deferred_loading_and_weak_serialization_references_test.dart b/runtime/tests/vm/dart/deferred_loading_and_weak_serialization_references_test.dart new file mode 100644 index 00000000000..7447a06afcb --- /dev/null +++ b/runtime/tests/vm/dart/deferred_loading_and_weak_serialization_references_test.dart @@ -0,0 +1,16 @@ +// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +// These flags can cause WeakSerializationReferences to replace the owner of +// some Code, which must be accounted for in AssignLoadingUnitsCodeVisitor. + +// VMOptions=--no_retain_function_objects +// VMOptions=--dwarf_stack_traces + +import "splay_test.dart" deferred as splay; // Some non-trivial code. + +main() async { + await splay.loadLibrary(); + splay.main(); +} diff --git a/runtime/tests/vm/dart_2/deferred_loading_and_weak_serialization_references_test.dart b/runtime/tests/vm/dart_2/deferred_loading_and_weak_serialization_references_test.dart new file mode 100644 index 00000000000..7447a06afcb --- /dev/null +++ b/runtime/tests/vm/dart_2/deferred_loading_and_weak_serialization_references_test.dart @@ -0,0 +1,16 @@ +// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +// These flags can cause WeakSerializationReferences to replace the owner of +// some Code, which must be accounted for in AssignLoadingUnitsCodeVisitor. + +// VMOptions=--no_retain_function_objects +// VMOptions=--dwarf_stack_traces + +import "splay_test.dart" deferred as splay; // Some non-trivial code. + +main() async { + await splay.loadLibrary(); + splay.main(); +} diff --git a/runtime/vm/compiler/aot/precompiler.cc b/runtime/vm/compiler/aot/precompiler.cc index c604a7cc7f8..878ce4acd2c 100644 --- a/runtime/vm/compiler/aot/precompiler.cc +++ b/runtime/vm/compiler/aot/precompiler.cc @@ -391,7 +391,7 @@ void Precompiler::DoCompileAll() { TraceForRetainedFunctions(); FinalizeDispatchTable(); - ReplaceFunctionPCRelativeCallEntries(); + ReplaceFunctionStaticCallEntries(); DropFunctions(); DropFields(); @@ -1644,7 +1644,7 @@ void Precompiler::FinalizeDispatchTable() { printed.Release(); } -void Precompiler::ReplaceFunctionPCRelativeCallEntries() { +void Precompiler::ReplaceFunctionStaticCallEntries() { class StaticCallTableEntryFixer : public CodeVisitor { public: explicit StaticCallTableEntryFixer(Zone* zone) @@ -1660,7 +1660,9 @@ void Precompiler::ReplaceFunctionPCRelativeCallEntries() { for (auto& view : static_calls) { kind_and_offset_ = view.Get(); auto const kind = Code::KindField::decode(kind_and_offset_.Value()); - if (kind != Code::kPcRelativeCall) continue; + + if ((kind != Code::kCallViaCode) && (kind != Code::kPcRelativeCall)) + continue; target_function_ = view.Get(); if (target_function_.IsNull()) continue; @@ -1671,6 +1673,12 @@ void Precompiler::ReplaceFunctionPCRelativeCallEntries() { ASSERT(!target_code_.IsStubCode()); view.Set(target_code_); view.Set(Object::null_function()); + if (kind == Code::kCallViaCode) { + auto const pc_offset = + Code::OffsetField::decode(kind_and_offset_.Value()); + const uword pc = pc_offset + code.PayloadStart(); + CodePatcher::PatchStaticCallAt(pc, code, target_code_); + } if (FLAG_trace_precompiler) { THR_Print("Updated static call entry to %s in \"%s\"\n", target_function_.ToFullyQualifiedCString(), diff --git a/runtime/vm/compiler/aot/precompiler.h b/runtime/vm/compiler/aot/precompiler.h index 5f84a82559b..e80a81c11a5 100644 --- a/runtime/vm/compiler/aot/precompiler.h +++ b/runtime/vm/compiler/aot/precompiler.h @@ -301,7 +301,7 @@ class Precompiler : public ValueObject { void TraceForRetainedFunctions(); void FinalizeDispatchTable(); - void ReplaceFunctionPCRelativeCallEntries(); + void ReplaceFunctionStaticCallEntries(); void DropFunctions(); void DropFields(); void TraceTypesFromRetainedClasses(); diff --git a/runtime/vm/program_visitor.cc b/runtime/vm/program_visitor.cc index 13665eb1041..b5f73c39f3e 100644 --- a/runtime/vm/program_visitor.cc +++ b/runtime/vm/program_visitor.cc @@ -368,8 +368,7 @@ void ProgramVisitor::BindStaticCalls(Zone* zone, Isolate* isolate) { if (target_.IsNull()) { target_ = Code::RawCast(view.Get()); - ASSERT(!Code::Cast(target_).IsFunctionCode()); - // Allocation stub or AllocateContext or AllocateArray or ... + ASSERT(!target_.IsNull()); // Already bound. continue; } @@ -1314,7 +1313,7 @@ class AssignLoadingUnitsCodeVisitor : public CodeVisitor { void VisitCode(const Code& code) { intptr_t id; if (code.IsFunctionCode()) { - func_ ^= code.owner(); + func_ ^= code.function(); cls_ = func_.Owner(); lib_ = cls_.library(); unit_ = lib_.loading_unit();