These kinds of issues with VM are notoriously tricky to replicate. And the main debugging method is "staring intently at the code".