title: How to take heap dump?
body: <p>I want to collect heap dump on JVM crash</p>
  
  <p>So i wrote a simple code</p>
  
  <pre><code>public class Test {
  private String name;
  
  public Test(String name) {
      this.name = name;
  }
  
  public void execute() {
  
      Map&lt;String,String&gt; randomData = new HashMap&lt;String,String&gt;();
      for(int i=0;i&lt;1000000000;i++) {
         randomData.put("Key:" + i,"Value:" + i);
      }
  }
  
  public void addData() {
  }
  
  public static void main(String args[]) {
      String myName = "Aniket";
      Test tStart = new Test(myName);
      tStart.execute();
  }
  }
  </code></pre>
  
  <p>and I am running it as follows</p>
  
  <pre><code>[aniket@localhost Desktop]$ java -cp . -Xms2m -Xmx2m Test
  Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
      at Test.execute(Test.java:15)
      at Test.main(Test.java:25)
  </code></pre>
  
  <p>I got OutOfMemoryError which I wanted but there is no heap dump in the working directory(like <code>hs_err_pidXXXX.log</code> which I expected). What am I missing? How do I get a heap dump?</p>
  
  <p><strong>Update :</strong></p>
  
  <p>I tried <code>-XX:ErrorFile=.</code> still no use. If above is not the way to get the heap dump(Crash JVM) how can I crash my JVM to get those logs?</p>