Skip to content

Incorrect write-barrier elimination #43786

Closed
@mkustermann

Description

This example:

main() {
  List root = List(128);
  var last = root;
  for (int i = 0; i < 10 * 1024; ++i) {
    final nc = List(128);
    last[0] = nc;
    last = nc;
  }
  print(root.length);
}

Will hit the write barrier verification code in AOT for the store into the array inside the loop. The write barrier got eliminated for this store, but our code in the GC that will restore invariants after GC explicitly does not take arrays into account:

See runtime/vm/thread.cc

class RestoreWriteBarrierInvariantVisitor : public ObjectPointerVisitor {
 public:
  RestoreWriteBarrierInvariantVisitor(IsolateGroup* group,
                                      Thread* thread,
                                      Thread::RestoreWriteBarrierInvariantOp op)
      : ObjectPointerVisitor(group),
        thread_(thread),
        current_(Thread::Current()),
        op_(op) {}

  void VisitPointers(ObjectPtr* first, ObjectPtr* last) {
    ...

      // To avoid adding too much work into the remembered set, skip
      // arrays. Write barrier elimination will not remove the barrier
      // if we can trigger GC between array allocation and store.
      if (obj->GetClassId() == kArrayCid) continue;

      // Dart code won't store into VM-internal objects except Contexts and
      // UnhandledExceptions. This assumption is checked by an assertion in
      // WriteBarrierElimination::UpdateVectorForBlock.
      if (!obj->IsDartInstance() && !obj->IsContext() &&
          !obj->IsUnhandledException())
        continue;

    ...
  }
  ...
}

/cc @rmacnak-google @a-siva @mraleph This might be our GC related bug!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

P1A high priority bug; for example, a single project is unusable or has many test failuresarea-vmUse area-vm for VM related issues, including code coverage, and the AOT and JIT backends.type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions