Skip to content

Commit 22b26e5

Browse files
alexmarkovCommit Queue
authored andcommitted
[vm, dynamic modules] Bugfixes in the bytecode reader and interpreter runtime
* Never unbox fields loaded from bytecode as interpreter works with boxed fields only. * Ensure classes are allocate-finalized in AllocateObject runtime entry as interpreter may allocate instances of certain built-in classes (such as _Closure, _Double etc) without prior allocate-finalization. * Fix type arguments vector in constant instances when class doesn't have type parameters but extends a generic class (so its instances have type arguments vector). TEST=ci Change-Id: I488287f84572a79ca7f1fddbd53aed1c3a038cea Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/412981 Commit-Queue: Alexander Markov <[email protected]> Reviewed-by: Slava Egorov <[email protected]>
1 parent 409e103 commit 22b26e5

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

runtime/vm/bytecode_reader.cc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,10 +1075,12 @@ ObjectPtr BytecodeReaderHelper::ReadConstObject(intptr_t tag) {
10751075
const Type& type = Type::CheckedHandle(Z, ReadObject());
10761076
const Class& cls = Class::Handle(Z, type.type_class());
10771077
const Instance& obj = Instance::Handle(Z, Instance::New(cls, Heap::kOld));
1078-
if (type.arguments() != TypeArguments::null()) {
1079-
const TypeArguments& type_args =
1080-
TypeArguments::Handle(Z, type.arguments());
1078+
if (cls.NumTypeArguments() > 0) {
1079+
auto& type_args = TypeArguments::Handle(Z, type.arguments());
1080+
type_args = cls.GetInstanceTypeArguments(thread_, type_args);
10811081
obj.SetTypeArguments(type_args);
1082+
} else {
1083+
ASSERT(type.arguments() == TypeArguments::null());
10821084
}
10831085
const intptr_t num_fields = reader_.ReadUInt();
10841086
Field& field = Field::Handle(Z);
@@ -1549,6 +1551,7 @@ void BytecodeReaderHelper::ReadFieldDeclarations(const Class& cls,
15491551
(flags & kIsReflectableFlag) != 0, is_late, script_class,
15501552
type, position, end_position);
15511553

1554+
field.set_is_unboxed(false);
15521555
field.set_has_pragma(has_pragma);
15531556
field.set_is_covariant((flags & kIsCovariantFlag) != 0);
15541557
field.set_is_generic_covariant_impl((flags & kIsCovariantByClassFlag) != 0);

runtime/vm/runtime_entry.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,16 @@ static void ThrowIfError(const Object& result) {
536536
// Return value: newly allocated object.
537537
DEFINE_RUNTIME_ENTRY(AllocateObject, 2) {
538538
const Class& cls = Class::CheckedHandle(zone, arguments.ArgAt(0));
539+
#if defined(DART_DYNAMIC_MODULES) && !defined(DART_PRECOMPILED_RUNTIME)
540+
if (!cls.is_allocate_finalized()) {
541+
const Error& error =
542+
Error::Handle(zone, cls.EnsureIsAllocateFinalized(thread));
543+
if (!error.IsNull()) {
544+
Exceptions::PropagateError(error);
545+
UNREACHABLE();
546+
}
547+
}
548+
#endif
539549
ASSERT(cls.is_allocate_finalized());
540550
const Instance& instance = Instance::Handle(
541551
zone, Instance::NewAlreadyFinalized(cls, SpaceForRuntimeAllocation()));

0 commit comments

Comments
 (0)