Rakudo Memory / Garbage Collection Methods

I understand that this question borders on specific areas of implementation, but at that point, specific Rakudo / MoarVM answers would also help me.

I am working on some NativeCall modules and wondering how to debug memory leaks. Some memory is being processed in the C library, and I have a nice pen. I know that the domain is my responsibility, and there is nothing MoarVM can do there. What can I do in the MoarVM domain? what is the best way to check for dangling objects, circular links, etc.?

Is there a way at the end of a series of operations where, as I think, all my Perl objects are unavailable to say "Run garbage collection and tell me everything that remains"?

Is there any specific Rakudo / NQP / MoarVM code that I can run to help me? This is not a production release, but only for testing / diagnostics during development.

Garbage collection in MoarVM gives a tantalizing overview, but I don’t have enough information to do something with it.

+8
perl6
source share
1 answer

Firstly, while a memory leak on the C side is not your problem in this case, you should know that Rakudo installs perl6-valgrind-m , which runs the program under valgrind. I used this several times to figure out segfaults and leaks when writing my library bindings.

To search for objects managed by MoarVM, you can force the VM to dump heap snapshots. They are taken after each start of the GC, and an additional GC start is forced and the final shot taken at the end of the program. To record snapshots, run with --profile=heap . Then the output file can be transferred to moar-ha , which can be installed using zef install App::MoarVM::HeapAnalyzer (it is implemented in Perl 6, which may be useful to know if you want to expand it in some way to help you solve problems).

If you have any idea what kind of objects can leak, then it can be useful to look for objects of this type with the find . There is a path command that shows how this object is kept alive. It may also be useful to look at the number of objects between different heap snapshots to see what is growing in use. Unfortunately, there is no snapshot function yet.

It should be noted that snapshots include everything that runs on a virtual machine. This means that the Perl 6 compiler will be in memory, as well as a bunch of objects for things from embedded languages. (The tool was designed to track managed leaks in the compiler and built-in modules, so this is considered a feature. :-) Some sort of filtering may be possible in the future.)

Finally, you mentioned circular links. This is not a problem in Perl 6, because the GC is done by tracing rather than reference counting.

+7
source share

All Articles