Skip to content

Commit c532458

Browse files
alexmarkovcommit-bot@chromium.org
authored andcommitted
[vm/compiler] Fix for flaky crash in CallSpecializer::ReplaceWithInstanceOf
There were rare crashes ../../runtime/vm/compiler/call_specializer.cc: 1393: error: expected: call->MatchesCoreName(Symbols::_simpleInstanceOf()) version=2.3.0-edge.796ebc6069bde3a59475a9b45075f49e50b0cc34 (Thu May 9 09:38:28 2019 -0700) on "linux_x64" thread=82540, isolate=vm-service(0x558748c5d200) pc 0x000055874635dd6c fp 0x00007fa94dd3bf30 dart::Profiler::DumpStackTrace(void*) pc 0x0000558745f90332 fp 0x00007fa94dd3c010 dart::Assert::Fail(char const*, ...) pc 0x000055874653909b fp 0x00007fa94dd3c0a0 dart::CallSpecializer::ReplaceWithInstanceOf(dart::InstanceCallInstr*) pc 0x0000558746496ed6 fp 0x00007fa94dd3c0f0 dart::FlowGraphVisitor::VisitBlocks() when running tools/test.py --repeat 5000 -n dartkb-mixed-linux-debug-x64 language_2/null_test at the rate ~1-3 crashes per 30,000 test cases. The problem is that in function bool InstanceCallInstr::MatchesCoreName(const String& name) { return function_name().raw() == Library::PrivateCoreLibName(name).raw(); } 'function_name().raw()' is evaluated before PrivateCoreLibName(name) is called and saved in a temporary (register). PrivateCoreLibName may trigger GC and relocate objects. In such case, 'PrivateCoreLibName(name).raw()' results in a moved object, which is compared to a stale object address. This CL fixes InstanceCallInstr::MatchesCoreName and other similar places by introducing Library::IsPrivateCoreLibName, which is also a little bit more efficient as it avoids extra symbol table lookup. Change-Id: I4dc91c586b0c595a3e85d6da13b98fc2248fb8fd Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/102120 Commit-Queue: Alexander Markov <[email protected]> Reviewed-by: Aart Bik <[email protected]>
1 parent 2736dab commit c532458

File tree

4 files changed

+18
-5
lines changed

4 files changed

+18
-5
lines changed

runtime/vm/compiler/backend/il.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4260,7 +4260,7 @@ void InstanceCallInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
42604260
}
42614261

42624262
bool InstanceCallInstr::MatchesCoreName(const String& name) {
4263-
return function_name().raw() == Library::PrivateCoreLibName(name).raw();
4263+
return Library::IsPrivateCoreLibName(function_name(), name);
42644264
}
42654265

42664266
RawFunction* InstanceCallInstr::ResolveForReceiverClass(

runtime/vm/compiler/frontend/bytecode_flow_graph_builder.cc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -820,13 +820,12 @@ void BytecodeFlowGraphBuilder::BuildInterfaceCallCommon(
820820
intptr_t argument_count = arg_desc.Count();
821821
ASSERT(argument_count <= 2);
822822
checked_argument_count = argument_count;
823-
} else if (name.raw() ==
824-
Library::PrivateCoreLibName(Symbols::_simpleInstanceOf()).raw()) {
823+
} else if (Library::IsPrivateCoreLibName(name,
824+
Symbols::_simpleInstanceOf())) {
825825
ASSERT(arg_desc.Count() == 2);
826826
checked_argument_count = 2;
827827
token_kind = Token::kIS;
828-
} else if (name.raw() ==
829-
Library::PrivateCoreLibName(Symbols::_instanceOf()).raw()) {
828+
} else if (Library::IsPrivateCoreLibName(name, Symbols::_instanceOf())) {
830829
token_kind = Token::kIS;
831830
}
832831

runtime/vm/object.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11377,6 +11377,15 @@ const String& Library::PrivateCoreLibName(const String& member) {
1137711377
return private_name;
1137811378
}
1137911379

11380+
bool Library::IsPrivateCoreLibName(const String& name, const String& member) {
11381+
Zone* zone = Thread::Current()->zone();
11382+
const auto& core_lib = Library::Handle(zone, Library::CoreLibrary());
11383+
const auto& private_key = String::Handle(zone, core_lib.private_key());
11384+
11385+
ASSERT(core_lib.IsPrivate(member));
11386+
return name.EqualsConcat(member, private_key);
11387+
}
11388+
1138011389
RawClass* Library::LookupCoreClass(const String& class_name) {
1138111390
Thread* thread = Thread::Current();
1138211391
Zone* zone = thread->zone();

runtime/vm/object.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4031,8 +4031,13 @@ class Library : public Object {
40314031
#endif // defined(DART_NO_SNAPSHOT).
40324032

40334033
static bool IsPrivate(const String& name);
4034+
40344035
// Construct the full name of a corelib member.
40354036
static const String& PrivateCoreLibName(const String& member);
4037+
4038+
// Returns true if [name] matches full name of corelib [member].
4039+
static bool IsPrivateCoreLibName(const String& name, const String& member);
4040+
40364041
// Lookup class in the core lib which also contains various VM
40374042
// helper methods and classes. Allow look up of private classes.
40384043
static RawClass* LookupCoreClass(const String& class_name);

0 commit comments

Comments
 (0)