2
* Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
24
#include "precompiled.hpp"
25
#include "unittest.hpp"
26
#include "memory/allocation.hpp"
27
#include "memory/resourceArea.inline.hpp"
28
#include "runtime/thread.hpp"
32
TEST_VM_ASSERT_MSG(vmErrorTest, resourceMark,
33
"fatal error: memory leak: allocating without ResourceMark") {
35
// Check for assert when allocating from resource area without a
36
// ResourceMark. There must not be a ResourceMark on the
37
// current stack when invoking this test case.
38
ResourceArea* area = Thread::current()->resource_area();
39
assert(area->nesting() == 0, "unexpected ResourceMark");
40
area->allocate_bytes(100);
43
const char* const str = "hello";
44
const size_t num = 500;
46
TEST_VM_ASSERT_MSG(vmErrorTest, assert1, "assert.str == nullptr. failed: expected null") {
47
vmassert(str == nullptr, "expected null");
50
TEST_VM_ASSERT_MSG(vmErrorTest, assert2, "assert.num == 1023 && .str == 'X'. failed: num=500 str=\"hello\"") {
51
vmassert(num == 1023 && *str == 'X',
52
"num=" SIZE_FORMAT " str=\"%s\"", num, str);
55
TEST_VM_ASSERT_MSG(vmErrorTest, guarantee1, "guarantee.str == nullptr. failed: expected null") {
56
guarantee(str == nullptr, "expected null");
59
TEST_VM_ASSERT_MSG(vmErrorTest, guarantee2, "guarantee.num == 1023 && .str == 'X'. failed: num=500 str=\"hello\"") {
60
guarantee(num == 1023 && *str == 'X',
61
"num=" SIZE_FORMAT " str=\"%s\"", num, str);
64
TEST_VM_ASSERT_MSG(vmErrorTest, fatal1, "fatal error: expected null") {
65
fatal("expected null");
68
TEST_VM_ASSERT_MSG(vmErrorTest, fatal2, "fatal error: num=500 str=\"hello\"") {
69
fatal("num=" SIZE_FORMAT " str=\"%s\"", num, str);
72
TEST_VM_ASSERT_MSG(vmErrorTest, fatal3, "fatal error: this message should be truncated during formatting") {
73
const char* const eol = os::line_separator();
74
const char* const msg = "this message should be truncated during formatting";
75
fatal("%s%s# %s%s# %s%s# %s%s# %s%s# "
76
"%s%s# %s%s# %s%s# %s%s# %s%s# "
77
"%s%s# %s%s# %s%s# %s%s# %s",
78
msg, eol, msg, eol, msg, eol, msg, eol, msg, eol,
79
msg, eol, msg, eol, msg, eol, msg, eol, msg, eol,
80
msg, eol, msg, eol, msg, eol, msg, eol, msg);
83
TEST_VM_ASSERT_MSG(vmErrorTest, out_of_memory1, "ChunkPool::allocate") {
84
const size_t num = (size_t)os::vm_page_size();
85
vm_exit_out_of_memory(num, OOM_MALLOC_ERROR, "ChunkPool::allocate");
88
TEST_VM_ASSERT_MSG(vmErrorTest, shouldnotcallthis1, "Error: ShouldNotCall") {
92
TEST_VM_ASSERT_MSG(vmErrorTest, shouldnotreachhere1, "Error: ShouldNotReachHere") {
96
TEST_VM_ASSERT_MSG(vmErrorTest, unimplemented1, "Error: Unimplemented") {