{"id":2608,"date":"2012-12-27T22:56:10","date_gmt":"2012-12-28T03:56:10","guid":{"rendered":"http:\/\/appcrawler.com\/wordpress\/?p=2608"},"modified":"2012-12-27T22:56:10","modified_gmt":"2012-12-28T03:56:10","slug":"handling-out-of-memory-errors-in-hotspot","status":"publish","type":"post","link":"http:\/\/appcrawler.com\/wordpress\/2012\/12\/27\/handling-out-of-memory-errors-in-hotspot\/","title":{"rendered":"Handling out of memory errors in Hotspot"},"content":{"rendered":"<p>The Hotspot compiler does not have an ExitOnOutOfMemoryError as the JRockit compiler does.  You can simulate it on linux with something like what is below.<\/p>\n<p>We start with our test code that will ensure an out of memory condition&#8230;<\/p>\n<pre lang=\"java\">\r\nimport java.util.*;\r\n\r\npublic class oom {\r\n  public static void main(String args[]) {\r\n    try {\r\n      int[] a = new int[Integer.MAX_VALUE];\r\n    }\r\n    catch( Error e ) {\r\n      e.printStackTrace();\r\n    }\r\n    String s = \"\";\r\n    try {\r\n      Thread.sleep(5000);\r\n    }\r\n    catch( Exception e ) {\r\n      e.printStackTrace();\r\n    }\r\n    for (int i = 1; i <= 1000; i++) {\r\n\t  s = s + \"x\";\r\n\t}\r\n\tArrayList al = new ArrayList();\r\n\tfor (int i = 1; i <= 10; i++) {\r\n\t  al.add(new String(s));\r\n\t}\r\n  }\r\n}\r\n<\/pre>\n<p>...and the following commmand line and output...<\/p>\n<pre lang=\"text\">\r\n[atg@expressdb1 ~]$ java -XX:OnOutOfMemoryError=\"jmap %p;kill -9 %p\" oom\r\n#\r\n# java.lang.OutOfMemoryError: Java heap space\r\n# -XX:OnOutOfMemoryError=\"jmap %p;kill -9 %p\"\r\n#   Executing \/bin\/sh -c \"jmap 18128\"...\r\nAttaching to process ID 18128, please wait...\r\nDebugger attached successfully.\r\nServer compiler detected.\r\nJVM version is 20.0-b12\r\n\r\nusing thread-local object allocation.\r\nParallel GC with 2 thread(s)\r\n\r\nHeap Configuration:\r\n   MinHeapFreeRatio = 40\r\n   MaxHeapFreeRatio = 70\r\n   MaxHeapSize      = 788529152 (752.0MB)\r\n   NewSize          = 1310720 (1.25MB)\r\n   MaxNewSize       = 17592186044415 MB\r\n   OldSize          = 5439488 (5.1875MB)\r\n   NewRatio         = 2\r\n   SurvivorRatio    = 8\r\n   PermSize         = 21757952 (20.75MB)\r\n   MaxPermSize      = 174063616 (166.0MB)\r\n\r\nHeap Usage:\r\nPS Young Generation\r\nEden Space:\r\n   capacity = 12320768 (11.75MB)\r\n   used     = 0 (0.0MB)\r\n   free     = 12320768 (11.75MB)\r\n   0.0% used\r\nFrom Space:\r\n   capacity = 2031616 (1.9375MB)\r\n   used     = 0 (0.0MB)\r\n   free     = 2031616 (1.9375MB)\r\n   0.0% used\r\nTo Space:\r\n   capacity = 2031616 (1.9375MB)\r\n   used     = 0 (0.0MB)\r\n   free     = 2031616 (1.9375MB)\r\n   0.0% used\r\nPS Old Generation\r\n   capacity = 525729792 (501.375MB)\r\n   used     = 114680 (0.10936737060546875MB)\r\n   free     = 525615112 (501.26563262939453MB)\r\n   0.02181348703175642% used\r\nPS Perm Generation\r\n   capacity = 21757952 (20.75MB)\r\n   used     = 2789736 (2.6604995727539062MB)\r\n   free     = 18968216 (18.089500427246094MB)\r\n   12.821684687970633% used\r\n#   Executing \/bin\/sh -c \"kill -9 18128\"...\r\nKilled\r\n[atg@expressdb1 ~]$\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The Hotspot compiler does not have an ExitOnOutOfMemoryError as the JRockit compiler does. You can simulate it on linux with something like what is below. We start with our test code that will ensure an out of memory condition&#8230; import&hellip;<\/p>\n<p class=\"more-link-p\"><a class=\"more-link\" href=\"http:\/\/appcrawler.com\/wordpress\/2012\/12\/27\/handling-out-of-memory-errors-in-hotspot\/\">Read more &rarr;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"footnotes":""},"categories":[24,25],"tags":[],"_links":{"self":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/2608"}],"collection":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/comments?post=2608"}],"version-history":[{"count":4,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/2608\/revisions"}],"predecessor-version":[{"id":2689,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/2608\/revisions\/2689"}],"wp:attachment":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/media?parent=2608"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/categories?post=2608"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/tags?post=2608"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}