mmtk / mmtk-core

Memory Management ToolKit
https://www.mmtk.io
Other
380 stars 69 forks source link

Debugging: how to know when a work packet is pushed to the queue #811

Open qinsoon opened 1 year ago

qinsoon commented 1 year ago

Our GC worker picks up work from the work queue. When debugging, we normally can easily find which work causes issues. But it is hard to track back to know the place where this work is generated, and pushed.

For example, with GDB or RR, we have a segfault in one work packet. It is not obvious and not easy to reverse and find the context where the work packet is generated.

wks commented 1 year ago

One possible way is assigning a unique ID to each work packet. This can help us identify "derived" work packets. This can also help us build visualisation tools to show the dependencies of work packets in a tree (or forest) structure.

We can record the "current work packet ID" for each worker so that when a work packet is inserted to the queue, we also record its "parent" packet ID. If we just want to debug, adding the two log statements should suffice:

And we can collect the logs and analyse offline.

If we use rr, we can watch the change of "current work packet ID" so that we can pause when it started executing the parent packet of an interested packet.

Currently, the only work packets NOT created by a GC worker are ScheduleCollection and EndOfGC. We can use 0 or None as their parent IDs.

qinsoon commented 1 year ago

This is a general issue specific for any shared queue system.

In terms of debugging object graph (the work for scanning object and tracing object), we can just check the validity of a child object when we scan the parent object (for example, using valid object bit). That will solve the issue.