8252148: vmError::controlled_crash should be #ifdef ASSERT and move tests to gtest

Reviewed-by: iklam, stuefe
This commit is contained in:
Coleen Phillimore 2020-12-15 20:48:18 +00:00
parent 2273f9555a
commit c37eabe73b
18 changed files with 190 additions and 216 deletions

@ -290,9 +290,6 @@
develop(uintx, MetadataAllocationFailALotInterval, 1000, \
"Metadata allocation failure a lot interval") \
\
product(bool, ExecutingUnitTests, false, \
"Whether the JVM is running unit tests or not") \
\
product(bool, UseTLAB, true, \
"Use thread-local object allocation") \
\

@ -3800,10 +3800,14 @@ static jint JNI_CreateJavaVM_inner(JavaVM **vm, void **penv, void *args) {
#ifndef PRODUCT
if (ReplayCompiles) ciReplay::replay(thread);
#endif
#ifdef ASSERT
// Some platforms (like Win*) need a wrapper around these test
// functions in order to properly handle error conditions.
VMError::test_error_handler();
if (ErrorHandlerTest != 0) {
VMError::controlled_crash(ErrorHandlerTest);
}
#endif
// Since this is not a JVM_ENTRY we have to set the thread state manually before leaving.

@ -493,19 +493,24 @@ const intx ObjectAlignmentInBytes = 8;
develop(bool, ZapFillerObjects, trueInDebug, \
"Zap filler objects with 0xDEAFBABE") \
\
notproduct(uintx, ErrorHandlerTest, 0, \
product(bool, ExecutingUnitTests, false, \
"Whether the JVM is running unit tests or not") \
\
develop(uintx, ErrorHandlerTest, 0, \
"If > 0, provokes an error after VM initialization; the value " \
"determines which error to provoke. See test_error_handler() " \
"determines which error to provoke. See controlled_crash() " \
"in vmError.cpp.") \
range(0, 17) \
\
notproduct(uintx, TestCrashInErrorHandler, 0, \
develop(uintx, TestCrashInErrorHandler, 0, \
"If > 0, provokes an error inside VM error handler (a secondary " \
"crash). see test_error_handler() in vmError.cpp") \
"crash). see controlled_crash() in vmError.cpp") \
range(0, 17) \
\
notproduct(bool, TestSafeFetchInErrorHandler, false, \
develop(bool, TestSafeFetchInErrorHandler, false , \
"If true, tests SafeFetch inside error handler.") \
\
notproduct(bool, TestUnresponsiveErrorHandler, false, \
develop(bool, TestUnresponsiveErrorHandler, false, \
"If true, simulates an unresponsive error handler.") \
\
develop(bool, Verbose, false, \

@ -238,6 +238,36 @@ void report_vm_error(const char* file, int line, const char* error_msg)
report_vm_error(file, line, error_msg, "%s", "");
}
static void print_error_for_unit_test(const char* message, const char* detail_fmt, va_list detail_args) {
#ifdef ASSERT
if (ExecutingUnitTests) {
char detail_msg[256];
if (detail_fmt != NULL) {
// Special handling for the sake of gtest death tests which expect the assert
// message to be printed in one short line to stderr (see TEST_VM_ASSERT_MSG) and
// cannot be tweaked to accept our normal assert message.
va_list detail_args_copy;
va_copy(detail_args_copy, detail_args);
jio_vsnprintf(detail_msg, sizeof(detail_msg), detail_fmt, detail_args_copy);
// the VM assert tests look for "assert failed: "
if (message == NULL) {
fprintf(stderr, "assert failed: %s", detail_msg);
} else {
if (strlen(detail_msg) > 0) {
fprintf(stderr, "assert failed: %s: %s", message, detail_msg);
} else {
fprintf(stderr, "assert failed: Error: %s", message);
}
}
::fflush(stderr);
va_end(detail_args_copy);
}
}
#endif // ASSERT
}
void report_vm_error(const char* file, int line, const char* error_msg, const char* detail_fmt, ...)
{
if (Debugging || error_is_suppressed(file, line)) return;
@ -250,20 +280,7 @@ void report_vm_error(const char* file, int line, const char* error_msg, const ch
}
#endif // CAN_SHOW_REGISTERS_ON_ASSERT
#ifdef ASSERT
if (detail_fmt != NULL && ExecutingUnitTests) {
// Special handling for the sake of gtest death tests which expect the assert
// message to be printed in one short line to stderr (see TEST_VM_ASSERT_MSG) and
// cannot be tweaked to accept our normal assert message.
va_list detail_args_copy;
va_copy(detail_args_copy, detail_args);
::fputs("assert failed: ", stderr);
::vfprintf(stderr, detail_fmt, detail_args_copy);
::fputs("\n", stderr);
::fflush(stderr);
va_end(detail_args_copy);
}
#endif
print_error_for_unit_test(error_msg, detail_fmt, detail_args);
VMError::report_and_die(Thread::current_or_null(), context, file, line, error_msg, detail_fmt, detail_args);
va_end(detail_args);
@ -285,6 +302,9 @@ void report_fatal(const char* file, int line, const char* detail_fmt, ...)
context = g_assertion_context;
}
#endif // CAN_SHOW_REGISTERS_ON_ASSERT
print_error_for_unit_test("fatal error", detail_fmt, detail_args);
VMError::report_and_die(Thread::current_or_null(), context, file, line, "fatal error", detail_fmt, detail_args);
va_end(detail_args);
}
@ -294,6 +314,9 @@ void report_vm_out_of_memory(const char* file, int line, size_t size,
if (Debugging) return;
va_list detail_args;
va_start(detail_args, detail_fmt);
print_error_for_unit_test(NULL, detail_fmt, detail_args);
VMError::report_and_die(Thread::current_or_null(), file, line, size, vm_err_type, detail_fmt, detail_args);
va_end(detail_args);

@ -444,7 +444,7 @@ void VMError::report(outputStream* st, bool _verbose) {
"Runtime Environment to continue.");
}
#ifndef PRODUCT
#ifdef ASSERT
// Error handler self tests
// test secondary error handling. Test it twice, to test that resetting
@ -503,7 +503,7 @@ void VMError::report(outputStream* st, bool _verbose) {
st->print_cr("not possible; skipped.");
}
}
#endif // PRODUCT
#endif // ASSERT
STEP("printing type of error")
@ -1737,7 +1737,7 @@ bool VMError::check_timeout() {
}
#ifndef PRODUCT
#ifdef ASSERT
typedef void (*voidfun_t)();
// Crash with an authentic sigfpe
@ -1765,47 +1765,13 @@ static void crash_with_segfault() {
} // end: crash_with_segfault
void VMError::test_error_handler() {
controlled_crash(ErrorHandlerTest);
}
// crash in a controlled way:
// how can be one of:
// 1,2 - asserts
// 3,4 - guarantee
// 5-7 - fatal
// 8 - vm_exit_out_of_memory
// 9 - ShouldNotCallThis
// 10 - ShouldNotReachHere
// 11 - Unimplemented
// 12,13 - (not guaranteed) crashes
// 1 - assert
// 2 - guarantee
// 14 - SIGSEGV
// 15 - SIGFPE
void VMError::controlled_crash(int how) {
if (how == 0) return;
// If asserts are disabled, use the corresponding guarantee instead.
NOT_DEBUG(if (how <= 2) how += 2);
const char* const str = "hello";
const size_t num = (size_t)os::vm_page_size();
const char* const eol = os::line_separator();
const char* const msg = "this message should be truncated during formatting";
char * const dataPtr = NULL; // bad data pointer
const void (*funcPtr)(void); // bad function pointer
#if defined(PPC64) && !defined(ABI_ELFv2)
struct FunctionDescriptor functionDescriptor;
functionDescriptor.set_entry((address) 0xF);
funcPtr = (const void(*)()) &functionDescriptor;
#else
funcPtr = (const void(*)()) 0xF;
#endif
// Keep this in sync with test/hotspot/jtreg/runtime/ErrorHandling/ErrorHandler.java
// which tests cases 1 thru 13.
// Case 14 is tested by test/hotspot/jtreg/runtime/ErrorHandling/SafeFetchInErrorHandlingTest.java.
// Case 15 is tested by test/hotspot/jtreg/runtime/ErrorHandling/SecondaryErrorTest.java.
// Case 16 is tested by test/hotspot/jtreg/runtime/ErrorHandling/ThreadsListHandleInErrorHandlingTest.java.
@ -1821,30 +1787,10 @@ void VMError::controlled_crash(int how) {
}
switch (how) {
case 1: vmassert(str == NULL, "expected null"); break;
case 2: vmassert(num == 1023 && *str == 'X',
"num=" SIZE_FORMAT " str=\"%s\"", num, str); break;
case 3: guarantee(str == NULL, "expected null"); break;
case 4: guarantee(num == 1023 && *str == 'X',
"num=" SIZE_FORMAT " str=\"%s\"", num, str); break;
case 5: fatal("expected null"); break;
case 6: fatal("num=" SIZE_FORMAT " str=\"%s\"", num, str); break;
case 7: fatal("%s%s# %s%s# %s%s# %s%s# %s%s# "
"%s%s# %s%s# %s%s# %s%s# %s%s# "
"%s%s# %s%s# %s%s# %s%s# %s",
msg, eol, msg, eol, msg, eol, msg, eol, msg, eol,
msg, eol, msg, eol, msg, eol, msg, eol, msg, eol,
msg, eol, msg, eol, msg, eol, msg, eol, msg); break;
case 8: vm_exit_out_of_memory(num, OOM_MALLOC_ERROR, "ChunkPool::allocate"); break;
case 9: ShouldNotCallThis(); break;
case 10: ShouldNotReachHere(); break;
case 11: Unimplemented(); break;
// There's no guarantee the bad data pointer will crash us
// so "break" out to the ShouldNotReachHere().
case 12: *dataPtr = '\0'; break;
// There's no guarantee the bad function pointer will crash us
// so "break" out to the ShouldNotReachHere().
case 13: (*funcPtr)(); break;
case 1: assert(how == 0, "test assert"); break;
case 2: guarantee(how == 0, "test guarantee"); break;
// The other cases are unused.
case 14: crash_with_segfault(); break;
case 15: crash_with_sigfpe(); break;
case 16: {
@ -1858,19 +1804,11 @@ void VMError::controlled_crash(int how) {
fatal("Force crash with a nested ThreadsListHandle.");
}
}
case 18: {
// Check for assert when allocating from resource area without a
// ResourceMark. There must not be a ResourceMark on the
// current stack when invoking this test case.
ResourceArea* area = Thread::current()->resource_area();
assert(area->nesting() == 0, "unexpected ResourceMark");
area->allocate_bytes(100);
break;
}
default: tty->print_cr("ERROR: %d: unexpected test_num value.", how);
default:
// If another number is given, give a generic crash.
fatal("Crashing with number %d", how);
}
tty->print_cr("VMError::controlled_crash: survived intentional crash. Did you suppress the assert?");
tty->print_cr("controlled_crash: survived intentional crash. Did you suppress the assert?");
ShouldNotReachHere();
}
#endif // !PRODUCT
#endif // !ASSERT

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -183,9 +183,7 @@ public:
// Support for avoiding multiple asserts
static bool is_error_reported();
// Test vmassert(), fatal(), guarantee(), etc.
NOT_PRODUCT(static void test_error_handler();)
NOT_PRODUCT(static void controlled_crash(int how);)
DEBUG_ONLY(static void controlled_crash(int how);)
// returns an address which is guaranteed to generate a SIGSEGV on read,
// for test purposes, which is not NULL and contains bits in every word

@ -160,19 +160,19 @@ TEST_VM(G1ServiceTaskQueue, add_ordered) {
#ifdef ASSERT
TEST_VM_ASSERT_MSG(G1ServiceTaskQueue, pop_empty,
"Should never try to verify empty queue") {
".*Should never try to verify empty queue") {
G1ServiceTaskQueue queue;
queue.pop();
}
TEST_VM_ASSERT_MSG(G1ServiceTaskQueue, peek_empty,
"Should never try to verify empty queue") {
".*Should never try to verify empty queue") {
G1ServiceTaskQueue queue;
queue.peek();
}
TEST_VM_ASSERT_MSG(G1ServiceTaskQueue, set_time_in_queue,
"Not allowed to update time while in queue") {
".*Not allowed to update time while in queue") {
G1ServiceTaskQueue queue;
TestTask a(100);
queue.add_ordered(&a);

@ -44,7 +44,7 @@ using metaspace::Settings;
// Note: We use TEST_VM_ASSERT_MSG. However, an assert is only triggered if allocation
// guards are enabled; if guards are disabled for the gtests, this test would fail.
// So for that case, we trigger a fake assert.
TEST_VM_ASSERT_MSG(metaspace, test_overwriter, "Corrupt block") {
TEST_VM_ASSERT_MSG(metaspace, test_overwriter, ".*failed: Corrupt block") {
if (Settings::use_allocation_guard()) {
MetaspaceGtestContext context;

@ -218,7 +218,7 @@ TEST_VM(metaspace, BlockTree_print_test) {
}
// Test that an overwritten node would result in an assert and a printed tree
TEST_VM_ASSERT_MSG(metaspace, BlockTree_overwriter_test, "Invalid node") {
TEST_VM_ASSERT_MSG(metaspace, BlockTree_overwriter_test, ".*failed: Invalid node") {
static const size_t sizes1[] = { 30, 17, 0 };
static const size_t sizes2[] = { 12, 12, 0 };

@ -45,7 +45,7 @@ TEST_OTHER_VM(MutexRank, mutex_lock_rank_in_order) {
}
TEST_VM_ASSERT_MSG(MutexRank, mutex_lock_rank_out_of_orderA,
"Attempting to acquire lock mutex_rankA_plus_one/51 out of order with lock mutex_rankA/50 -- possible deadlock") {
".* Attempting to acquire lock mutex_rankA_plus_one/51 out of order with lock mutex_rankA/50 -- possible deadlock") {
JavaThread* THREAD = JavaThread::current();
ThreadInVMfromNative invm(THREAD);
@ -59,7 +59,7 @@ TEST_VM_ASSERT_MSG(MutexRank, mutex_lock_rank_out_of_orderA,
}
TEST_VM_ASSERT_MSG(MutexRank, mutex_lock_rank_out_of_orderB,
"Attempting to acquire lock mutex_rankB/50 out of order with lock mutex_rankA/50 -- possible deadlock") {
".* Attempting to acquire lock mutex_rankB/50 out of order with lock mutex_rankA/50 -- possible deadlock") {
JavaThread* THREAD = JavaThread::current();
ThreadInVMfromNative invm(THREAD);
@ -89,7 +89,7 @@ TEST_OTHER_VM(MutexRank, mutex_trylock_rank_out_of_orderA) {
}
TEST_VM_ASSERT_MSG(MutexRank, mutex_trylock_rank_out_of_orderB,
"Attempting to acquire lock mutex_rankA_plus_one/51 out of order with lock mutex_rankA/50 -- possible deadlock") {
".* Attempting to acquire lock mutex_rankA_plus_one/51 out of order with lock mutex_rankA/50 -- possible deadlock") {
JavaThread* THREAD = JavaThread::current();
ThreadInVMfromNative invm(THREAD);
@ -119,7 +119,7 @@ TEST_OTHER_VM(MutexRank, monitor_wait_rank_in_order) {
}
TEST_VM_ASSERT_MSG(MutexRank, monitor_wait_rank_out_of_order,
"Attempting to wait on monitor monitor_rankA_plus_one/51 while holding lock monitor_rankA/50 "
".* Attempting to wait on monitor monitor_rankA_plus_one/51 while holding lock monitor_rankA/50 "
"-- possible deadlock. Should wait on the least ranked monitor from all owned locks.") {
JavaThread* THREAD = JavaThread::current();
ThreadInVMfromNative invm(THREAD);
@ -135,7 +135,7 @@ TEST_VM_ASSERT_MSG(MutexRank, monitor_wait_rank_out_of_order,
}
TEST_VM_ASSERT_MSG(MutexRank, monitor_wait_rank_out_of_order_trylock,
"Attempting to wait on monitor monitor_rankA_plus_one/51 while holding lock monitor_rankA/50 "
".* Attempting to wait on monitor monitor_rankA_plus_one/51 while holding lock monitor_rankA/50 "
"-- possible deadlock. Should wait on the least ranked monitor from all owned locks.") {
JavaThread* THREAD = JavaThread::current();
ThreadInVMfromNative invm(THREAD);
@ -151,7 +151,7 @@ TEST_VM_ASSERT_MSG(MutexRank, monitor_wait_rank_out_of_order_trylock,
}
TEST_VM_ASSERT_MSG(MutexRank, monitor_wait_rank_special,
"Attempting to wait on monitor monitor_rank_special_minus_one/5 while holding lock monitor_rank_special/6 "
".* Attempting to wait on monitor monitor_rank_special_minus_one/5 while holding lock monitor_rank_special/6 "
"-- possible deadlock. Should not block\\(wait\\) while holding a lock of rank special.") {
JavaThread* THREAD = JavaThread::current();
ThreadInVMfromNative invm(THREAD);

@ -150,7 +150,8 @@ TEST(os, test_random) {
}
#ifdef ASSERT
TEST_VM_ASSERT_MSG(os, page_size_for_region_with_zero_min_pages, "sanity") {
TEST_VM_ASSERT_MSG(os, page_size_for_region_with_zero_min_pages,
"assert.min_pages > 0. failed: sanity") {
size_t region_size = 16 * os::vm_page_size();
os::page_size_for_region_aligned(region_size, 0); // should assert
}
@ -445,7 +446,7 @@ TEST_VM(os, release_multi_mappings) {
// On debug this would assert. Test that too.
// On other platforms, we are unable to recognize bad ranges.
#ifdef ASSERT
TEST_VM_ASSERT_MSG(os, release_bad_ranges, "bad release") {
TEST_VM_ASSERT_MSG(os, release_bad_ranges, ".*bad release") {
#else
TEST_VM(os, release_bad_ranges) {
#endif

@ -31,25 +31,25 @@
// Test mismatched safepoint check flag on lock declaration vs. lock acquisition.
TEST_VM_ASSERT_MSG(SafepointLockAssertTest, always_check,
"This lock should always have a safepoint check for Java threads") {
".*This lock should always have a safepoint check for Java threads: SFPT_Test_lock") {
MutexLocker ml(new Mutex(Mutex::leaf, "SFPT_Test_lock", true, Mutex::_safepoint_check_always),
Mutex::_no_safepoint_check_flag);
}
TEST_VM_ASSERT_MSG(SafepointLockAssertTest, never_check,
"This lock should never have a safepoint check for Java thread") {
".*This lock should never have a safepoint check for Java threads: SFPT_Test_lock") {
MutexLocker ml(new Mutex(Mutex::leaf, "SFPT_Test_lock", true, Mutex::_safepoint_check_never),
Mutex::_safepoint_check_flag);
}
TEST_VM_ASSERT_MSG(SafepointLockAssertTest, special_locks,
"Special locks or below should never safepoint") {
".*Special locks or below should never safepoint") {
MutexLocker ml(new Mutex(Mutex::special, "SpecialTest_lock", /*vm_block*/true, Mutex::_safepoint_check_always),
Mutex::_safepoint_check_flag);
}
TEST_VM_ASSERT_MSG(SafepointLockAssertTest, possible_safepoint_lock,
"Possible safepoint reached by thread that does not allow it") {
".* Possible safepoint reached by thread that does not allow it") {
JavaThread* thread = JavaThread::current();
ThreadInVMfromNative in_native(thread);
MutexLocker ml(new Mutex(Mutex::special, "SpecialTest_lock", /*vm_block*/true, Mutex::_safepoint_check_never),

@ -496,14 +496,14 @@ TEST_VM_F(GrowableArrayTest, where) {
}
TEST_VM_ASSERT_MSG(GrowableArrayAssertingTest, copy_with_embedded_cheap,
"Copying of CHeap arrays not supported") {
"assert.!on_C_heap... failed: Copying of CHeap arrays not supported") {
WithEmbeddedArray s(1, mtTest);
// Intentionally asserts that copy of CHeap arrays are not allowed
WithEmbeddedArray c(s);
}
TEST_VM_ASSERT_MSG(GrowableArrayAssertingTest, assignment_with_embedded_cheap,
"Assignment of CHeap arrays not supported") {
"assert.!on_C_heap... failed: Assignment of CHeap arrays not supported") {
WithEmbeddedArray s(1, mtTest);
WithEmbeddedArray c(1, mtTest);

@ -0,0 +1,99 @@
/*
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
#include "precompiled.hpp"
#include "unittest.hpp"
#include "memory/allocation.hpp"
#include "memory/resourceArea.inline.hpp"
#include "runtime/thread.hpp"
#ifdef ASSERT
TEST_VM_ASSERT_MSG(vmErrorTest, resourceMark,
"fatal error: memory leak: allocating without ResourceMark") {
// Check for assert when allocating from resource area without a
// ResourceMark. There must not be a ResourceMark on the
// current stack when invoking this test case.
ResourceArea* area = Thread::current()->resource_area();
assert(area->nesting() == 0, "unexpected ResourceMark");
area->allocate_bytes(100);
}
const char* const str = "hello";
const size_t num = 500;
TEST_VM_ASSERT_MSG(vmErrorTest, assert1, "assert.str == NULL. failed: expected null") {
vmassert(str == NULL, "expected null");
}
TEST_VM_ASSERT_MSG(vmErrorTest, assert2, "assert.num == 1023 && .str == 'X'. failed: num=500 str=\"hello\"") {
vmassert(num == 1023 && *str == 'X',
"num=" SIZE_FORMAT " str=\"%s\"", num, str);
}
TEST_VM_ASSERT_MSG(vmErrorTest, guarantee1, "guarantee.str == NULL. failed: expected null") {
guarantee(str == NULL, "expected null");
}
TEST_VM_ASSERT_MSG(vmErrorTest, guarantee2, "guarantee.num == 1023 && .str == 'X'. failed: num=500 str=\"hello\"") {
guarantee(num == 1023 && *str == 'X',
"num=" SIZE_FORMAT " str=\"%s\"", num, str);
}
TEST_VM_ASSERT_MSG(vmErrorTest, fatal1, "fatal error: expected null") {
fatal("expected null");
}
TEST_VM_ASSERT_MSG(vmErrorTest, fatal2, "fatal error: num=500 str=\"hello\"") {
fatal("num=" SIZE_FORMAT " str=\"%s\"", num, str);
}
TEST_VM_ASSERT_MSG(vmErrorTest, fatal3, "fatal error: this message should be truncated during formatting") {
const char* const eol = os::line_separator();
const char* const msg = "this message should be truncated during formatting";
fatal("%s%s# %s%s# %s%s# %s%s# %s%s# "
"%s%s# %s%s# %s%s# %s%s# %s%s# "
"%s%s# %s%s# %s%s# %s%s# %s",
msg, eol, msg, eol, msg, eol, msg, eol, msg, eol,
msg, eol, msg, eol, msg, eol, msg, eol, msg, eol,
msg, eol, msg, eol, msg, eol, msg, eol, msg);
}
TEST_VM_ASSERT_MSG(vmErrorTest, out_of_memory1, "ChunkPool::allocate") {
const size_t num = (size_t)os::vm_page_size();
vm_exit_out_of_memory(num, OOM_MALLOC_ERROR, "ChunkPool::allocate");
}
TEST_VM_ASSERT_MSG(vmErrorTest, shouldnotcallthis1, "Error: ShouldNotCall") {
ShouldNotCallThis();
}
TEST_VM_ASSERT_MSG(vmErrorTest, shouldnotreachhere1, "Error: ShouldNotReachHere") {
ShouldNotReachHere();
}
TEST_VM_ASSERT_MSG(vmErrorTest, unimplemented1, "Error: Unimplemented") {
Unimplemented();
}
#endif // ASSERT

@ -276,7 +276,6 @@ tier1_runtime = \
-runtime/CompressedOops/UseCompressedOops.java \
-runtime/ConstantPool/IntfMethod.java \
-runtime/ErrorHandling/CreateCoredumpOnCrash.java \
-runtime/ErrorHandling/ErrorHandler.java \
-runtime/ErrorHandling/TestHeapDumpOnOutOfMemoryError.java \
-runtime/ErrorHandling/TestHeapDumpOnOutOfMemoryErrorInMetaspace.java \
-runtime/ErrorHandling/TimeoutInErrorHandlingTest.java \

@ -1,90 +0,0 @@
/*
* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @requires (vm.debug == true)
* @bug 6888954
* @bug 8015884
* @summary Exercise HotSpot error handling code by invoking java with
* -XX:ErrorHandlerTest option to cause an error report. Check the results.
* @modules java.base/jdk.internal.misc
* @library /test/lib
* @run driver ErrorHandler
*/
import jdk.test.lib.Platform;
import jdk.test.lib.process.ProcessTools;
import jdk.test.lib.process.OutputAnalyzer;
public class ErrorHandler {
public static OutputAnalyzer runTest(int testcase) throws Exception {
// The -XX:ErrorHandlerTest=N option requires debug bits.
return new OutputAnalyzer(
ProcessTools.createJavaProcessBuilder(
"-XX:-CreateCoredumpOnCrash", "-XX:ErrorHandlerTest=" + testcase)
.start());
}
public static void main(String[] args) throws Exception {
// Keep this in sync with hotspot/src/share/vm/utilities/debug.cpp
int i = 1;
String[] strings = {
"assert(str == NULL) failed: expected null",
"assert(num == 1023 && *str == 'X') failed: num=",
"guarantee(str == NULL) failed: expected null",
"guarantee(num == 1023 && *str == 'X') failed: num=",
"fatal error: expected null",
"fatal error: num=",
"fatal error: this message should be truncated during formatting",
"ChunkPool::allocate",
"Error: ShouldNotCall()",
"Error: ShouldNotReachHere()",
"Error: Unimplemented()"
};
String[] patterns = {
"(SIGILL|SIGSEGV|EXCEPTION_ACCESS_VIOLATION).* at pc=",
// -XX:ErrorHandlerTest=13 is too unreliable. It sometimes fails to crash in the expected way.
// -XX:ErrorHandlerTest=14 is tested by SafeFetchInErrorHandlingTest.java
// -XX:ErrorHandlerTest=15 is tested by SecondaryErrorTest.java
// -XX:ErrorHandlerTest=16 is tested by ThreadsListHandleInErrorHandlingTest.java
// -XX:ErrorHandlerTest=17 is tested by NestedThreadsListHandleInErrorHandlingTest.java
};
for (String s : strings) {
runTest(i++).shouldContain(s);
}
for (String p : patterns) {
runTest(i++).shouldMatch(p);
}
// Tests after here could be handled by above iterations, but doing
// so would renumber ErrorHandlerTest cases, requiring updates a
// bunch of other test programs.
runTest(18).shouldContain("memory leak: allocating without ResourceMark");
}
}

@ -56,7 +56,7 @@ public class ShowRegistersOnAssertTest {
" with " + (show_registers_on_assert ? "-XX:+ShowRegistersOnAssert" : "-XX:-ShowRegistersOnAssert") + "...");
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
"-XX:+UnlockDiagnosticVMOptions", "-Xmx100M", "-XX:-CreateCoredumpOnCrash",
"-XX:ErrorHandlerTest=" + (do_assert ? "1" : "3"),
"-XX:ErrorHandlerTest=" + (do_assert ? "1" : "2"),
(suppress_assert ? "-XX:SuppressErrorAt=/vmError.cpp" : ""),
(show_registers_on_assert ? "-XX:+ShowRegistersOnAssert" : "-XX:-ShowRegistersOnAssert"),
"-version");

@ -42,7 +42,7 @@ public class TestOnError {
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
"-XX:-CreateCoredumpOnCrash",
"-XX:ErrorHandlerTest=12", // trigger potential SEGV
"-XX:ErrorHandlerTest=14", // trigger potential SEGV
"-XX:OnError=echo " + msg,
TestOnError.class.getName());