Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/hotspot/share/utilities/debug.hpp
40949 views
1
/*
2
* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
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.
8
*
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).
14
*
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.
18
*
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
21
* questions.
22
*
23
*/
24
25
#ifndef SHARE_UTILITIES_DEBUG_HPP
26
#define SHARE_UTILITIES_DEBUG_HPP
27
28
#include "utilities/breakpoint.hpp"
29
#include "utilities/compilerWarnings.hpp"
30
#include "utilities/macros.hpp"
31
32
#include <stddef.h>
33
34
// ShowRegistersOnAssert support (for now Linux only)
35
#if defined(LINUX) && !defined(ZERO)
36
#define CAN_SHOW_REGISTERS_ON_ASSERT
37
extern char* g_assert_poison;
38
#define TOUCH_ASSERT_POISON (*g_assert_poison) = 'X';
39
void initialize_assert_poison();
40
void disarm_assert_poison();
41
bool handle_assert_poison_fault(const void* ucVoid, const void* faulting_address);
42
#else
43
#define TOUCH_ASSERT_POISON
44
#endif // CAN_SHOW_REGISTERS_ON_ASSERT
45
46
// assertions
47
#ifndef ASSERT
48
#define vmassert(p, ...)
49
#else
50
// Note: message says "assert" rather than "vmassert" for backward
51
// compatibility with tools that parse/match the message text.
52
// Note: The signature is vmassert(p, format, ...), but the solaris
53
// compiler can't handle an empty ellipsis in a macro without a warning.
54
#define vmassert(p, ...) \
55
do { \
56
if (!(p)) { \
57
TOUCH_ASSERT_POISON; \
58
report_vm_error(__FILE__, __LINE__, "assert(" #p ") failed", __VA_ARGS__); \
59
BREAKPOINT; \
60
} \
61
} while (0)
62
#endif
63
64
// For backward compatibility.
65
#define assert(p, ...) vmassert(p, __VA_ARGS__)
66
67
#define precond(p) assert(p, "precond")
68
#define postcond(p) assert(p, "postcond")
69
70
#ifndef ASSERT
71
#define vmassert_status(p, status, msg)
72
#else
73
// This version of vmassert is for use with checking return status from
74
// library calls that return actual error values eg. EINVAL,
75
// ENOMEM etc, rather than returning -1 and setting errno.
76
// When the status is not what is expected it is very useful to know
77
// what status was actually returned, so we pass the status variable as
78
// an extra arg and use strerror to convert it to a meaningful string
79
// like "Invalid argument", "out of memory" etc
80
#define vmassert_status(p, status, msg) \
81
do { \
82
if (!(p)) { \
83
TOUCH_ASSERT_POISON; \
84
report_vm_status_error(__FILE__, __LINE__, "assert(" #p ") failed", \
85
status, msg); \
86
BREAKPOINT; \
87
} \
88
} while (0)
89
#endif
90
91
// For backward compatibility.
92
#define assert_status(p, status, msg) vmassert_status(p, status, msg)
93
94
// guarantee is like vmassert except it's always executed -- use it for
95
// cheap tests that catch errors that would otherwise be hard to find.
96
// guarantee is also used for Verify options.
97
#define guarantee(p, ...) \
98
do { \
99
if (!(p)) { \
100
TOUCH_ASSERT_POISON; \
101
report_vm_error(__FILE__, __LINE__, "guarantee(" #p ") failed", __VA_ARGS__); \
102
BREAKPOINT; \
103
} \
104
} while (0)
105
106
#define fatal(...) \
107
do { \
108
TOUCH_ASSERT_POISON; \
109
report_fatal(INTERNAL_ERROR, __FILE__, __LINE__, __VA_ARGS__); \
110
BREAKPOINT; \
111
} while (0)
112
113
// out of memory
114
#define vm_exit_out_of_memory(size, vm_err_type, ...) \
115
do { \
116
report_vm_out_of_memory(__FILE__, __LINE__, size, vm_err_type, __VA_ARGS__); \
117
BREAKPOINT; \
118
} while (0)
119
120
#define ShouldNotCallThis() \
121
do { \
122
TOUCH_ASSERT_POISON; \
123
report_should_not_call(__FILE__, __LINE__); \
124
BREAKPOINT; \
125
} while (0)
126
127
#define ShouldNotReachHere() \
128
do { \
129
TOUCH_ASSERT_POISON; \
130
report_should_not_reach_here(__FILE__, __LINE__); \
131
BREAKPOINT; \
132
} while (0)
133
134
#define Unimplemented() \
135
do { \
136
TOUCH_ASSERT_POISON; \
137
report_unimplemented(__FILE__, __LINE__); \
138
BREAKPOINT; \
139
} while (0)
140
141
#define Untested(msg) \
142
do { \
143
report_untested(__FILE__, __LINE__, msg); \
144
BREAKPOINT; \
145
} while (0);
146
147
148
// types of VM error - originally in vmError.hpp
149
enum VMErrorType {
150
INTERNAL_ERROR = 0xe0000000,
151
OOM_MALLOC_ERROR = 0xe0000001,
152
OOM_MMAP_ERROR = 0xe0000002,
153
OOM_MPROTECT_ERROR = 0xe0000003,
154
OOM_JAVA_HEAP_FATAL = 0xe0000004
155
};
156
157
// Set to suppress secondary error reporting.
158
// Really should have a qualified name or something.
159
extern bool Debugging;
160
161
// error reporting helper functions
162
void report_vm_error(const char* file, int line, const char* error_msg);
163
void report_vm_error(const char* file, int line, const char* error_msg,
164
const char* detail_fmt, ...) ATTRIBUTE_PRINTF(4, 5);
165
void report_vm_status_error(const char* file, int line, const char* error_msg,
166
int status, const char* detail);
167
void report_fatal(VMErrorType error_type, const char* file, int line, const char* detail_fmt, ...) ATTRIBUTE_PRINTF(4, 5);
168
void report_vm_out_of_memory(const char* file, int line, size_t size, VMErrorType vm_err_type,
169
const char* detail_fmt, ...) ATTRIBUTE_PRINTF(5, 6);
170
void report_should_not_call(const char* file, int line);
171
void report_should_not_reach_here(const char* file, int line);
172
void report_unimplemented(const char* file, int line);
173
void report_untested(const char* file, int line, const char* message);
174
175
void warning(const char* format, ...) ATTRIBUTE_PRINTF(1, 2);
176
177
// Compile-time asserts. Cond must be a compile-time constant expression that
178
// is convertible to bool. STATIC_ASSERT() can be used anywhere a declaration
179
// may appear.
180
//
181
// Implementation Note: STATIC_ASSERT_FAILURE<true> provides a value member
182
// rather than type member that could be used directly in the typedef, because
183
// a type member would require conditional use of "typename", depending on
184
// whether Cond is dependent or not. The use of a value member leads to the
185
// use of an array type.
186
187
template<bool x> struct STATIC_ASSERT_FAILURE;
188
template<> struct STATIC_ASSERT_FAILURE<true> { enum { value = 1 }; };
189
190
#define STATIC_ASSERT(Cond) \
191
typedef char PASTE_TOKENS(STATIC_ASSERT_DUMMY_TYPE_, __LINE__)[ \
192
STATIC_ASSERT_FAILURE< (Cond) >::value ]
193
194
// out of memory reporting
195
void report_java_out_of_memory(const char* message);
196
197
#endif // SHARE_UTILITIES_DEBUG_HPP
198
199