If you search for how to get a memory dump for a java process many will recommend jmap.
On a server, jmap is the tool to use since jvisualvm requires some ui and that is rarely available in our setup.
The command to use is simple:
jmap -heap.format:b <pid>
The problem is that it “freezes” your java application as the heap is being dumped and when you have a process that uses a bit of memory it takes a long time (very long time). The app I tried to get information from was using 2.3 Gb and after 30 minutes it was not done writing to the heap.bin. Had to abandon.