Skip to content

Commit 1501d68

Browse files
rmacnak-googleCommit Queue
authored and
Commit Queue
committed
[vm] Avoid allocation when printing type names.
Avoids recursive assertion failures when a GC assertion failure occurs during a compile. TEST=ci Change-Id: I2fd2b29c1a7d83c426ceb437f3880746a4c8d8b9 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/349142 Commit-Queue: Ryan Macnak <[email protected]> Reviewed-by: Alexander Aprelev <[email protected]>
1 parent 8c5407b commit 1501d68

File tree

8 files changed

+39
-32
lines changed

8 files changed

+39
-32
lines changed

runtime/lib/object.cc

+2-4
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,8 @@ DEFINE_NATIVE_ENTRY(Object_instanceOf, 0, 4) {
209209
THR_Print("Native Object.instanceOf: result %s\n", result_str);
210210
const AbstractType& instance_type =
211211
AbstractType::Handle(zone, instance.GetType(Heap::kNew));
212-
THR_Print(" instance type: %s\n",
213-
String::Handle(zone, instance_type.Name()).ToCString());
214-
THR_Print(" test type: %s\n",
215-
String::Handle(zone, type.Name()).ToCString());
212+
THR_Print(" instance type: %s\n", instance_type.NameCString());
213+
THR_Print(" test type: %s\n", type.NameCString());
216214
}
217215
return Bool::Get(is_instance_of).ptr();
218216
}

runtime/vm/compiler/api/print_filter.cc

+1-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ static bool PassesFilter(const char* filter,
4848
#endif
4949

5050
char* save_ptr; // Needed for strtok_r.
51-
const char* scrubbed_name =
52-
String::Handle(function.QualifiedScrubbedName()).ToCString();
51+
const char* scrubbed_name = function.QualifiedScrubbedNameCString();
5352
const char* function_name = function.ToFullyQualifiedCString();
5453
intptr_t function_name_len = strlen(function_name);
5554

runtime/vm/compiler/backend/il.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -6218,7 +6218,7 @@ void CheckNullInstr::AddMetadataForRuntimeCall(CheckNullInstr* check_null,
62186218
void BoxAllocationSlowPath::EmitNativeCode(FlowGraphCompiler* compiler) {
62196219
if (compiler::Assembler::EmittingComments()) {
62206220
__ Comment("%s slow path allocation of %s", instruction()->DebugName(),
6221-
String::Handle(cls_.ScrubbedName()).ToCString());
6221+
cls_.ScrubbedNameCString());
62226222
}
62236223
__ Bind(entry_label());
62246224
const auto& stub = Code::ZoneHandle(

runtime/vm/compiler/backend/il_printer.cc

+5-5
Original file line numberDiff line numberDiff line change
@@ -423,8 +423,8 @@ void FlowGraphPrinter::PrintTypeCheck(const ParsedFunction& parsed_function,
423423
"%s type check: compile type %s is %s specific than "
424424
"type '%s' of '%s'.\n",
425425
eliminated ? "Eliminated" : "Generated", compile_type_name,
426-
eliminated ? "more" : "not more",
427-
String::Handle(dst_type.Name()).ToCString(), dst_name.ToCString());
426+
eliminated ? "more" : "not more", dst_type.NameCString(),
427+
dst_name.ToCString());
428428
}
429429

430430
static void PrintTargetsHelper(BaseTextBuffer* f,
@@ -970,7 +970,7 @@ void StoreStaticFieldInstr::PrintOperandsTo(BaseTextBuffer* f) const {
970970

971971
void InstanceOfInstr::PrintOperandsTo(BaseTextBuffer* f) const {
972972
value()->PrintTo(f);
973-
f->Printf(" IS %s,", String::Handle(type().Name()).ToCString());
973+
f->Printf(" IS %s,", type().NameCString());
974974
f->AddString(" instantiator_type_args(");
975975
instantiator_type_arguments()->PrintTo(f);
976976
f->AddString("), function_type_args(");
@@ -996,15 +996,15 @@ void AllocationInstr::PrintOperandsTo(BaseTextBuffer* f) const {
996996
}
997997

998998
void AllocateObjectInstr::PrintOperandsTo(BaseTextBuffer* f) const {
999-
f->Printf("cls=%s", String::Handle(cls().ScrubbedName()).ToCString());
999+
f->Printf("cls=%s", cls().ScrubbedNameCString());
10001000
if (InputCount() > 0 || Identity().IsNotAliased()) {
10011001
f->AddString(", ");
10021002
}
10031003
AllocationInstr::PrintOperandsTo(f);
10041004
}
10051005

10061006
void MaterializeObjectInstr::PrintOperandsTo(BaseTextBuffer* f) const {
1007-
f->Printf("%s", String::Handle(cls_.ScrubbedName()).ToCString());
1007+
f->Printf("%s", cls_.ScrubbedNameCString());
10081008
for (intptr_t i = 0; i < InputCount(); i++) {
10091009
f->AddString(", ");
10101010
f->Printf("%s: ", slots_[i]->Name());

runtime/vm/compiler/backend/type_propagator.cc

+2-4
Original file line numberDiff line numberDiff line change
@@ -1038,11 +1038,9 @@ void CompileType::PrintTo(BaseTextBuffer* f) const {
10381038
} else if ((cid_ != kIllegalCid) && (cid_ != kDynamicCid)) {
10391039
const Class& cls =
10401040
Class::Handle(IsolateGroup::Current()->class_table()->At(cid_));
1041-
type_name = String::Handle(cls.ScrubbedName()).ToCString();
1041+
type_name = cls.ScrubbedNameCString();
10421042
} else if (type_ != nullptr) {
1043-
type_name = type_->IsDynamicType()
1044-
? "*"
1045-
: String::Handle(type_->ScrubbedName()).ToCString();
1043+
type_name = type_->IsDynamicType() ? "*" : type_->ScrubbedNameCString();
10461044
} else if (!is_nullable()) {
10471045
type_name = "!null";
10481046
}

runtime/vm/object.cc

+15-3
Original file line numberDiff line numberDiff line change
@@ -21446,24 +21446,36 @@ const char* AbstractType::NullabilitySuffix(
2144621446
}
2144721447

2144821448
StringPtr AbstractType::Name() const {
21449+
return Symbols::New(Thread::Current(), NameCString());
21450+
}
21451+
21452+
const char* AbstractType::NameCString() const {
2144921453
Thread* thread = Thread::Current();
2145021454
ZoneTextBuffer printer(thread->zone());
2145121455
PrintName(kInternalName, &printer);
21452-
return Symbols::New(thread, printer.buffer());
21456+
return printer.buffer();
2145321457
}
2145421458

2145521459
StringPtr AbstractType::UserVisibleName() const {
21460+
return Symbols::New(Thread::Current(), UserVisibleNameCString());
21461+
}
21462+
21463+
const char* AbstractType::UserVisibleNameCString() const {
2145621464
Thread* thread = Thread::Current();
2145721465
ZoneTextBuffer printer(thread->zone());
2145821466
PrintName(kUserVisibleName, &printer);
21459-
return Symbols::New(thread, printer.buffer());
21467+
return printer.buffer();
2146021468
}
2146121469

2146221470
StringPtr AbstractType::ScrubbedName() const {
21471+
return Symbols::New(Thread::Current(), ScrubbedNameCString());
21472+
}
21473+
21474+
const char* AbstractType::ScrubbedNameCString() const {
2146321475
Thread* thread = Thread::Current();
2146421476
ZoneTextBuffer printer(thread->zone());
2146521477
PrintName(kScrubbedName, &printer);
21466-
return Symbols::New(thread, printer.buffer());
21478+
return printer.buffer();
2146721479
}
2146821480

2146921481
void AbstractType::PrintName(NameVisibility name_visibility,

runtime/vm/object.h

+6-3
Original file line numberDiff line numberDiff line change
@@ -9087,15 +9087,18 @@ class AbstractType : public Instance {
90879087
virtual const char* NullabilitySuffix(NameVisibility name_visibility) const;
90889088

90899089
// The name of this type, including the names of its type arguments, if any.
9090-
virtual StringPtr Name() const;
9090+
StringPtr Name() const;
9091+
const char* NameCString() const;
90919092

90929093
// The name of this type, including the names of its type arguments, if any.
90939094
// Names of internal classes are mapped to their public interfaces.
9094-
virtual StringPtr UserVisibleName() const;
9095+
StringPtr UserVisibleName() const;
9096+
const char* UserVisibleNameCString() const;
90959097

90969098
// The name of this type, including the names of its type arguments, if any.
90979099
// Privacy suffixes are dropped.
9098-
virtual StringPtr ScrubbedName() const;
9100+
StringPtr ScrubbedName() const;
9101+
const char* ScrubbedNameCString() const;
90999102

91009103
// Return the internal or public name of this type, including the names of its
91019104
// type arguments, if any.

runtime/vm/runtime_entry.cc

+7-10
Original file line numberDiff line numberDiff line change
@@ -626,9 +626,8 @@ static void PrintSubtypeCheck(const AbstractType& subtype,
626626

627627
LogBlock lb;
628628
THR_Print("SubtypeCheck: '%s' %d %s '%s' %d (pc: %#" Px ").\n",
629-
String::Handle(subtype.Name()).ToCString(), subtype.type_class_id(),
630-
result ? "is" : "is !",
631-
String::Handle(supertype.Name()).ToCString(),
629+
subtype.NameCString(), subtype.type_class_id(),
630+
result ? "is" : "is !", supertype.NameCString(),
632631
supertype.type_class_id(), caller_frame->pc());
633632

634633
const Function& function =
@@ -840,21 +839,19 @@ static void PrintTypeCheck(const char* message,
840839
LogBlock lb;
841840
if (type.IsInstantiated()) {
842841
THR_Print("%s: '%s' %d %s '%s' %d (pc: %#" Px ").\n", message,
843-
String::Handle(instance_type.Name()).ToCString(),
844-
instance_type.type_class_id(),
842+
instance_type.NameCString(), instance_type.type_class_id(),
845843
(result.ptr() == Bool::True().ptr()) ? "is" : "is !",
846-
String::Handle(type.Name()).ToCString(), type.type_class_id(),
847-
caller_frame->pc());
844+
type.NameCString(), type.type_class_id(), caller_frame->pc());
848845
} else {
849846
// Instantiate type before printing.
850847
const AbstractType& instantiated_type = AbstractType::Handle(
851848
type.InstantiateFrom(instantiator_type_arguments,
852849
function_type_arguments, kAllFree, Heap::kOld));
853850
THR_Print("%s: '%s' %s '%s' instantiated from '%s' (pc: %#" Px ").\n",
854-
message, String::Handle(instance_type.Name()).ToCString(),
851+
message, instance_type.NameCString(),
855852
(result.ptr() == Bool::True().ptr()) ? "is" : "is !",
856-
String::Handle(instantiated_type.Name()).ToCString(),
857-
String::Handle(type.Name()).ToCString(), caller_frame->pc());
853+
instantiated_type.NameCString(), type.NameCString(),
854+
caller_frame->pc());
858855
}
859856
const Function& function =
860857
Function::Handle(caller_frame->LookupDartFunction());

0 commit comments

Comments
 (0)