visualvm
visualvm copied to clipboard
Profiling is unstable when using LaunchWrapper
Something LaunchWrapper does breaks profiling (not sampling), and sometimes causes everything to freeze. This mainly causes issues with profiling Minecraft modifications. It's likely to be an issue with LaunchWrapper as I don't remember it ever working reliably with profiling, but it seems like it got much worse in 1.4.1. Also note that LaunchWrapper does NOT work with java 9 and above.
When trying to start profiling when the application is already running, it sometimes works but most of the time (especially when profiling all classes) it the application will stop responding. When using startup profiling, it will almost always freeze at some point, usually in the same place, when loading some class.
I was able to reproduce the issue just by wrapping an existing project that I could profile without any issues in LaunchWrapper, but no matter what small synthetic test I came up with, everything worked fine. So this means I don't have a small test case that reproduces the issue.
This is example thread dump I got when it froze: https://pastebin.com/raw/Zfw7ZWss
LaunchWrapper modifies bytecode of the loaded application and this collides with the profiling, which does the same. Maybe there is a way to carefully set cpu profiler settings to avoid this problem. Try some experiments and let us know. In case you need info, how CPU profiler settings works, please see Profiling with VisualVM part 1 and Profiling with VisualVM part 2.
Launch wrapper does not modify already loaded classes, it modifies the byte code before the classes are loaded, so I don't think that should be a problem.
And I did try to exclude classes, packages, profile only some things. None of it worked. Whatever I tried, it would randomly freeze the whole thing early when starting profiling, or, when using startup profiling, reliably freeze in a specific spot.