How to set the directory where JVM stores MDMP files

Reto Merz reto.merz at abacus.ch
Tue Oct 1 12:13:39 UTC 2019


Hello,

(Not sure whether this is the correct place to ask this, so please forgive me if not.)

A) I want to change the location where the MDMP-file is created. I set the following JVM args:
        -XX:HeapDumpPath=C:/the_dumps
        -XX:ErrorFile=C:/the_dumps/hs_err_pid%p.log

According to a old stackoverflow answer [1] this should work.
But the MDMP-file is still created in the working directory. Is it possible to change it?
Below you will find the code to cause a crash [2].

Tested with java -version
    openjdk version "11.0.4" 2019-07-16
    OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.4+11)
    OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.4+11, mixed mode)

B) If there is a way to change the MDMP-file location, does the same apply for linux?
As far as I know linux will create a CORE file (instead of a MDMP).

Thanks
Reto Merz

[1] https://stackoverflow.com/questions/33666412/how-to-set-the-directory-where-jvm-stores-mdmp-files
[2] Code to crash JVM:

import java.lang.reflect.*;
public class Main {
    public static void main(String[] args) throws Exception {
        Class<?> clazz = Class.forName("sun.misc.Unsafe");
        Field field = clazz.getDeclaredField("theUnsafe");
        field.setAccessible(true);
        Object unsafe = field.get(null);
        Method putAddress = clazz.getDeclaredMethod("putAddress", long.class, long.class);
        putAddress.invoke(unsafe, 0L, 0L);
    }
}



More information about the jdk-dev mailing list