+{"files":[{"patch":"@@ -113,0 +113,5 @@\n+\/\/ Message details for OOME objects, preallocate these objects since they could be\n+\/\/ used when throwing OOME, we should try to avoid further allocation in such case\n+OopHandle Universe::_msg_metaspace;\n+OopHandle Universe::_msg_class_metaspace;\n+\n@@ -543,1 +548,0 @@\n-\n@@ -643,0 +647,8 @@\n+bool Universe::is_out_of_memory_error_metaspace(oop ex_obj) {\n+ return java_lang_Throwable::message(ex_obj) == _msg_metaspace.resolve();\n+}\n+\n+bool Universe::is_out_of_memory_error_class_metaspace(oop ex_obj) {\n+ return java_lang_Throwable::message(ex_obj) == _msg_class_metaspace.resolve();\n+}\n+\n@@ -662,0 +674,1 @@\n+ _msg_metaspace = OopHandle(vm_global(), msg());\n@@ -665,0 +678,1 @@\n+ _msg_class_metaspace = OopHandle(vm_global(), msg());\n","filename":"src\/hotspot\/share\/memory\/universe.cpp","additions":15,"deletions":1,"binary":false,"changes":16,"status":"modified"},{"patch":"@@ -135,0 +135,4 @@\n+ \/\/ preallocated message detail strings for error objects\n+ static OopHandle _msg_metaspace;\n+ static OopHandle _msg_class_metaspace;\n+\n@@ -297,0 +301,4 @@\n+ \/\/ If it's a certain type of OOME object\n+ static bool is_out_of_memory_error_metaspace(oop ex_obj);\n+ static bool is_out_of_memory_error_class_metaspace(oop ex_obj);\n+\n","filename":"src\/hotspot\/share\/memory\/universe.hpp","additions":8,"deletions":0,"binary":false,"changes":8,"status":"modified"},{"patch":"@@ -464,1 +464,1 @@\n- if (exception() == Universe::out_of_memory_error_metaspace()) {\n+ if (Universe::is_out_of_memory_error_metaspace(exception())) {\n@@ -466,1 +466,1 @@\n- } else if (exception() == Universe::out_of_memory_error_class_metaspace()) {\n+ } else if (Universe::is_out_of_memory_error_metaspace(exception())) {\n","filename":"src\/hotspot\/share\/utilities\/exceptions.cpp","additions":2,"deletions":2,"binary":false,"changes":4,"status":"modified"},{"patch":"@@ -0,0 +1,62 @@\n+\/*\n+ * Copyright (c) 2021, Alibaba Group Holding Limited. All rights reserved.\n+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.\n+ *\n+ * This code is free software; you can redistribute it and\/or modify it\n+ * under the terms of the GNU General Public License version 2 only, as\n+ * published by the Free Software Foundation.\n+ *\n+ * This code is distributed in the hope that it will be useful, but WITHOUT\n+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or\n+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License\n+ * version 2 for more details (a copy is included in the LICENSE file that\n+ * accompanied this code).\n+ *\n+ * You should have received a copy of the GNU General Public License version\n+ * 2 along with this work; if not, write to the Free Software Foundation,\n+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.\n+ *\n+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA\n+ * or visit www.oracle.com if you need additional information or have any\n+ * questions.\n+ *\/\n+\n+\n+\/*\n+ * @test\n+ * @bug 8278125\n+ * @summary Test if OOME has proper stacktrace\n+ * @library \/test\/lib\n+ * @run main\/othervm -Xmx100m -Xms100m GenOutOfMemoryError\n+ *\/\n+\n+import jdk.test.lib.Asserts;\n+\n+public class GenOutOfMemoryError {\n+ private static int OOME_HAS_STACK_CNT = 0;\n+\n+ private void badMethod(int n){\n+ try {\n+ System.out.format(\"bad method was invoked %n\", n);\n+ \/\/ Try to allocate an array the same size as the heap - it will throw OOME without\n+ \/\/ actually consuming available memory.\n+ Integer[] array = new Integer[1000 * 1000 * 100];\n+ array.hashCode();\n+ } catch (Throwable t){\n+ StackTraceElement[] traces = t.getStackTrace();\n+ if (traces.length != 0) {\n+ OOME_HAS_STACK_CNT++;\n+ }\n+ t.printStackTrace();\n+ }\n+ }\n+\n+ public static void main(String[] args) {\n+ GenOutOfMemoryError genOutOfMemoryError = new GenOutOfMemoryError();\n+\n+ for (int i = 0; i < 7; i++) {\n+ genOutOfMemoryError.badMethod(i + 1);\n+ }\n+ Asserts.assertTrue(4\/*PreallocatedOutOfMemoryErrorCount defaults to 4*\/ == OOME_HAS_STACK_CNT, \"Some OOMEs do not have stacktraces\");\n+ }\n+}\n","filename":"test\/hotspot\/jtreg\/runtime\/ErrorHandling\/GenOutOfMemoryError.java","additions":62,"deletions":0,"binary":false,"changes":62,"status":"added"}]}
0 commit comments