Java flag modification in runtime

I have recently come across a beautiful article which describes a method to modify JVM flags in runtime. I loved the idea and immediately started to write test code for the concept.

In this article I'll briefly describe steps to do this.

First, locate libjvm.so in your process memory. In Linux reading /proc/self/maps is just enough to get that. Then use an executavle parser (for example, this one) to find symbol address for the flag you want to change. Last step is to use sun.misc.Unsafe to modify the flag.

Word of caution: not all flags can be changed in runtime. For example, changing -XX:+StackTraceInThrowable would result in a Segmentation Fault.

You can browse through my experimental code.