You can use the jinfo utility to set or unset HeapDumpOnOutOfMemoryError flag or to enable GC logs to a running Java process.
This can come in handy when you want to avoid a server restart, just to enable the above flags!
jinfo is command-line utility provided by JDK that gets configuration information from a running Java process or crash dump and prints the system properties or the command-line flags that were used to start the virtual machine.
Syntax:
jinfo <PID> // To get configuration ifnormation from a running Java Process
jinfo -flags <PID> // to print VM Flags set in a Java Process
Example :

contd…

contd…

NOTE:
For JDK 8 and above, it is suggested to use the latest utility, jcmd instead of the previous jinfo utility for enhanced diagnostics and reduced performance overhead. However jinfo comes in handy when you want to enable flags dynamically on a running Java process.
With the -flag option, the utility can dynamically set, unset, or change the value of certain Java VM flags for the specified Java process.
The flags that can be set dynamically are as follows :
HeapDumpOnOutOfMemoryError
HeapDumpPath
PrintGC
PrintGCDetails
PrintGCTimeStamps
PrintClassHistogram
PrintConcurrentLocks
Syntax :
jinfo -flag [+|-]<one_of_the_above_flag_name> <PID>
jinfo -flag +<one_of_the_above_Flags> <PID> // Use + to set a Flag
jinfo -flag -<one_of_the_above_Flags> <PID> // Use – to unset a Flag
Example :
jinfo -flag +HeapDumpOnOutOfMemoryError 1111 // This will add the HeapDumpOnOutOfMemoryError flag to running JVM with PID 1111
jinfo -flag -HeapDumpOnOutOfMemoryError 1111 // This will remove the HeapDumpOnOutOfMemoryError flag to a running JVM with PID 1111.

Reference :
https://docs.oracle.com/javase/8/docs/technotes/guides/troubleshoot/tooldescr013.html
https://docs.oracle.com/javase/7/docs/webnotes/tsg/TSG-VM/html/clopts.html#gdaxd
