77 virtual void unused_initial_virtual() { }
78
79 public:
80 oop pending_exception() const { return _pending_exception; }
81 bool has_pending_exception() const { return _pending_exception != nullptr; }
82 const char* exception_file() const { return _exception_file; }
83 int exception_line() const { return _exception_line; }
84
85 // Code generation support
86 static ByteSize pending_exception_offset() { return byte_offset_of(ThreadShadow, _pending_exception); }
87
88 // use THROW whenever possible!
89 void set_pending_exception(oop exception, const char* file, int line);
90
91 // use CLEAR_PENDING_EXCEPTION whenever possible!
92 void clear_pending_exception();
93
94 // use CLEAR_PENDING_NONASYNC_EXCEPTION to clear probable nonasync exception.
95 void clear_pending_nonasync_exception();
96
97 ThreadShadow() : _pending_exception(nullptr),
98 _exception_file(nullptr), _exception_line(0) {}
99 };
100
101
102 // Exceptions is a helper class that encapsulates all operations
103 // that require access to the thread interface and which are
104 // relatively rare. The Exceptions operations should only be
105 // used directly if the macros below are insufficient.
106
107 class Exceptions {
108 // Either `exception` or `symbol` must be non-null but not both.
109 static bool special_exception(JavaThread* thread, const char* file, int line, Handle exception, Symbol* name = nullptr, const char* message = nullptr);
110
111 // Count out of memory errors that are interesting in error diagnosis
112 static volatile int _out_of_memory_error_java_heap_errors;
113 static volatile int _out_of_memory_error_metaspace_errors;
114 static volatile int _out_of_memory_error_class_metaspace_errors;
115
116 // Count linkage errors
213 // the exception and is only needed for syntactic correctness. The _0 ending is a shortcut for
214 // _(0) since this is a frequent case. Example:
215 //
216 // int result = this_function_may_trap(x_arg, y_arg, CHECK_0);
217 //
218 // CAUTION: make sure that the function call using a CHECK macro is not the only statement of a
219 // conditional branch w/o enclosing {} braces, since the CHECK macros expand into several state-
220 // ments! Also make sure it is not used on a function call that is part of a return statement!
221
222 #define PENDING_EXCEPTION (((ThreadShadow*)THREAD)->pending_exception())
223 #define HAS_PENDING_EXCEPTION (((ThreadShadow*)THREAD)->has_pending_exception())
224 #define CLEAR_PENDING_EXCEPTION (((ThreadShadow*)THREAD)->clear_pending_exception())
225
226 #define CHECK THREAD); if (HAS_PENDING_EXCEPTION) return ; (void)(0
227 #define CHECK_(result) THREAD); if (HAS_PENDING_EXCEPTION) return result; (void)(0
228 #define CHECK_0 CHECK_(0)
229 #define CHECK_NH CHECK_(Handle())
230 #define CHECK_NULL CHECK_(nullptr)
231 #define CHECK_false CHECK_(false)
232 #define CHECK_JNI_ERR CHECK_(JNI_ERR)
233
234 // CAUTION: These macros clears all exceptions including async exceptions, use it with caution.
235 #define CHECK_AND_CLEAR THREAD); if (HAS_PENDING_EXCEPTION) { CLEAR_PENDING_EXCEPTION; return; } (void)(0
236 #define CHECK_AND_CLEAR_(result) THREAD); if (HAS_PENDING_EXCEPTION) { CLEAR_PENDING_EXCEPTION; return result; } (void)(0
237 #define CHECK_AND_CLEAR_0 CHECK_AND_CLEAR_(0)
238 #define CHECK_AND_CLEAR_NH CHECK_AND_CLEAR_(Handle())
239 #define CHECK_AND_CLEAR_NULL CHECK_AND_CLEAR_(nullptr)
240 #define CHECK_AND_CLEAR_false CHECK_AND_CLEAR_(false)
241
242 // CAUTION: These macros clears all exceptions except probable async exceptions j.l.InternalError.
243 // So use it with caution.
244 #define CLEAR_PENDING_NONASYNC_EXCEPTION (((ThreadShadow*)THREAD)->clear_pending_nonasync_exception())
245 #define CHECK_AND_CLEAR_NONASYNC THREAD); if (HAS_PENDING_EXCEPTION) { CLEAR_PENDING_NONASYNC_EXCEPTION; return; } (void)(0
246 #define CHECK_AND_CLEAR_NONASYNC_(result) THREAD); if (HAS_PENDING_EXCEPTION) { CLEAR_PENDING_NONASYNC_EXCEPTION; return result; } (void)(0
247 #define CHECK_AND_CLEAR_NONASYNC_0 CHECK_AND_CLEAR_NONASYNC_(0)
248 #define CHECK_AND_CLEAR_NONASYNC_NH CHECK_AND_CLEAR_NONASYNC_(Handle())
249 #define CHECK_AND_CLEAR_NONASYNC_NULL CHECK_AND_CLEAR_NONASYNC_(nullptr)
250 #define CHECK_AND_CLEAR_NONASYNC_false CHECK_AND_CLEAR_NONASYNC_(false)
251
252 // The THROW... macros should be used to throw an exception. They require a THREAD variable to be
253 // visible within the scope containing the THROW. Usually this is achieved by declaring the function
254 // with a TRAPS argument.
255
256 #define THREAD_AND_LOCATION THREAD, __FILE__, __LINE__
257
258 #define THROW_OOP(e) \
259 { Exceptions::_throw_oop(THREAD_AND_LOCATION, e); return; }
260
261 #define THROW_HANDLE(e) \
262 { Exceptions::_throw(THREAD_AND_LOCATION, e); return; }
263
264 #define THROW(name) \
265 { Exceptions::_throw_msg(THREAD_AND_LOCATION, name, nullptr); return; }
266
267 #define THROW_MSG(name, message) \
268 { Exceptions::_throw_msg(THREAD_AND_LOCATION, name, message); return; }
269
270 #define THROW_CAUSE(name, cause) \
271 { Exceptions::_throw_cause(THREAD_AND_LOCATION, name, cause); return; }
|
77 virtual void unused_initial_virtual() { }
78
79 public:
80 oop pending_exception() const { return _pending_exception; }
81 bool has_pending_exception() const { return _pending_exception != nullptr; }
82 const char* exception_file() const { return _exception_file; }
83 int exception_line() const { return _exception_line; }
84
85 // Code generation support
86 static ByteSize pending_exception_offset() { return byte_offset_of(ThreadShadow, _pending_exception); }
87
88 // use THROW whenever possible!
89 void set_pending_exception(oop exception, const char* file, int line);
90
91 // use CLEAR_PENDING_EXCEPTION whenever possible!
92 void clear_pending_exception();
93
94 // use CLEAR_PENDING_NONASYNC_EXCEPTION to clear probable nonasync exception.
95 void clear_pending_nonasync_exception();
96
97 void set_pending_preempted_exception();
98 void clear_pending_preempted_exception();
99 void check_preempted_exception() NOT_DEBUG_RETURN;
100
101 ThreadShadow() : _pending_exception(nullptr),
102 _exception_file(nullptr), _exception_line(0) {}
103 };
104
105
106 // Exceptions is a helper class that encapsulates all operations
107 // that require access to the thread interface and which are
108 // relatively rare. The Exceptions operations should only be
109 // used directly if the macros below are insufficient.
110
111 class Exceptions {
112 // Either `exception` or `symbol` must be non-null but not both.
113 static bool special_exception(JavaThread* thread, const char* file, int line, Handle exception, Symbol* name = nullptr, const char* message = nullptr);
114
115 // Count out of memory errors that are interesting in error diagnosis
116 static volatile int _out_of_memory_error_java_heap_errors;
117 static volatile int _out_of_memory_error_metaspace_errors;
118 static volatile int _out_of_memory_error_class_metaspace_errors;
119
120 // Count linkage errors
217 // the exception and is only needed for syntactic correctness. The _0 ending is a shortcut for
218 // _(0) since this is a frequent case. Example:
219 //
220 // int result = this_function_may_trap(x_arg, y_arg, CHECK_0);
221 //
222 // CAUTION: make sure that the function call using a CHECK macro is not the only statement of a
223 // conditional branch w/o enclosing {} braces, since the CHECK macros expand into several state-
224 // ments! Also make sure it is not used on a function call that is part of a return statement!
225
226 #define PENDING_EXCEPTION (((ThreadShadow*)THREAD)->pending_exception())
227 #define HAS_PENDING_EXCEPTION (((ThreadShadow*)THREAD)->has_pending_exception())
228 #define CLEAR_PENDING_EXCEPTION (((ThreadShadow*)THREAD)->clear_pending_exception())
229
230 #define CHECK THREAD); if (HAS_PENDING_EXCEPTION) return ; (void)(0
231 #define CHECK_(result) THREAD); if (HAS_PENDING_EXCEPTION) return result; (void)(0
232 #define CHECK_0 CHECK_(0)
233 #define CHECK_NH CHECK_(Handle())
234 #define CHECK_NULL CHECK_(nullptr)
235 #define CHECK_false CHECK_(false)
236 #define CHECK_JNI_ERR CHECK_(JNI_ERR)
237 #define CHECK_PREEMPTABLE THREAD); if (HAS_PENDING_EXCEPTION) { THREAD->check_preempted_exception(); return; } (void)(0
238 #define CHECK_PREEMPTABLE_false THREAD); if (HAS_PENDING_EXCEPTION) { THREAD->check_preempted_exception(); return false; } (void)(0
239
240 // CAUTION: These macros clears all exceptions including async exceptions, use it with caution.
241 #define CHECK_AND_CLEAR THREAD); if (HAS_PENDING_EXCEPTION) { CLEAR_PENDING_EXCEPTION; return; } (void)(0
242 #define CHECK_AND_CLEAR_(result) THREAD); if (HAS_PENDING_EXCEPTION) { CLEAR_PENDING_EXCEPTION; return result; } (void)(0
243 #define CHECK_AND_CLEAR_0 CHECK_AND_CLEAR_(0)
244 #define CHECK_AND_CLEAR_NH CHECK_AND_CLEAR_(Handle())
245 #define CHECK_AND_CLEAR_NULL CHECK_AND_CLEAR_(nullptr)
246 #define CHECK_AND_CLEAR_false CHECK_AND_CLEAR_(false)
247
248 // CAUTION: These macros clears all exceptions except probable async exceptions j.l.InternalError.
249 // So use it with caution.
250 #define CLEAR_PENDING_NONASYNC_EXCEPTION (((ThreadShadow*)THREAD)->clear_pending_nonasync_exception())
251 #define CHECK_AND_CLEAR_NONASYNC THREAD); if (HAS_PENDING_EXCEPTION) { CLEAR_PENDING_NONASYNC_EXCEPTION; return; } (void)(0
252 #define CHECK_AND_CLEAR_NONASYNC_(result) THREAD); if (HAS_PENDING_EXCEPTION) { CLEAR_PENDING_NONASYNC_EXCEPTION; return result; } (void)(0
253 #define CHECK_AND_CLEAR_NONASYNC_0 CHECK_AND_CLEAR_NONASYNC_(0)
254 #define CHECK_AND_CLEAR_NONASYNC_NH CHECK_AND_CLEAR_NONASYNC_(Handle())
255 #define CHECK_AND_CLEAR_NONASYNC_NULL CHECK_AND_CLEAR_NONASYNC_(nullptr)
256 #define CHECK_AND_CLEAR_NONASYNC_false CHECK_AND_CLEAR_NONASYNC_(false)
257
258 #define CLEAR_PENDING_PREEMPTED_EXCEPTION (((ThreadShadow*)THREAD)->clear_pending_preempted_exception())
259 #define CHECK_AND_CLEAR_PREEMPTED THREAD); if (HAS_PENDING_EXCEPTION) { CLEAR_PENDING_PREEMPTED_EXCEPTION; return; } (void)(0
260
261
262 // The THROW... macros should be used to throw an exception. They require a THREAD variable to be
263 // visible within the scope containing the THROW. Usually this is achieved by declaring the function
264 // with a TRAPS argument.
265
266 #define THREAD_AND_LOCATION THREAD, __FILE__, __LINE__
267
268 #define THROW_OOP(e) \
269 { Exceptions::_throw_oop(THREAD_AND_LOCATION, e); return; }
270
271 #define THROW_HANDLE(e) \
272 { Exceptions::_throw(THREAD_AND_LOCATION, e); return; }
273
274 #define THROW(name) \
275 { Exceptions::_throw_msg(THREAD_AND_LOCATION, name, nullptr); return; }
276
277 #define THROW_MSG(name, message) \
278 { Exceptions::_throw_msg(THREAD_AND_LOCATION, name, message); return; }
279
280 #define THROW_CAUSE(name, cause) \
281 { Exceptions::_throw_cause(THREAD_AND_LOCATION, name, cause); return; }
|