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
211 // the exception and is only needed for syntactic correctness. The _0 ending is a shortcut for
212 // _(0) since this is a frequent case. Example:
213 //
214 // int result = this_function_may_trap(x_arg, y_arg, CHECK_0);
215 //
216 // CAUTION: make sure that the function call using a CHECK macro is not the only statement of a
217 // conditional branch w/o enclosing {} braces, since the CHECK macros expand into several state-
218 // ments! Also make sure it is not used on a function call that is part of a return statement!
219
220 #define PENDING_EXCEPTION (((ThreadShadow*)THREAD)->pending_exception())
221 #define HAS_PENDING_EXCEPTION (((ThreadShadow*)THREAD)->has_pending_exception())
222 #define CLEAR_PENDING_EXCEPTION (((ThreadShadow*)THREAD)->clear_pending_exception())
223
224 #define CHECK THREAD); if (HAS_PENDING_EXCEPTION) return ; (void)(0
225 #define CHECK_(result) THREAD); if (HAS_PENDING_EXCEPTION) return result; (void)(0
226 #define CHECK_0 CHECK_(0)
227 #define CHECK_NH CHECK_(Handle())
228 #define CHECK_NULL CHECK_(nullptr)
229 #define CHECK_false CHECK_(false)
230 #define CHECK_JNI_ERR CHECK_(JNI_ERR)
231
232 // CAUTION: These macros clears all exceptions including async exceptions, use it with caution.
233 #define CHECK_AND_CLEAR THREAD); if (HAS_PENDING_EXCEPTION) { CLEAR_PENDING_EXCEPTION; return; } (void)(0
234 #define CHECK_AND_CLEAR_(result) THREAD); if (HAS_PENDING_EXCEPTION) { CLEAR_PENDING_EXCEPTION; return result; } (void)(0
235 #define CHECK_AND_CLEAR_0 CHECK_AND_CLEAR_(0)
236 #define CHECK_AND_CLEAR_NH CHECK_AND_CLEAR_(Handle())
237 #define CHECK_AND_CLEAR_NULL CHECK_AND_CLEAR_(nullptr)
238 #define CHECK_AND_CLEAR_false CHECK_AND_CLEAR_(false)
239
240 // CAUTION: These macros clears all exceptions except probable async exceptions j.l.InternalError.
241 // So use it with caution.
242 #define CLEAR_PENDING_NONASYNC_EXCEPTION (((ThreadShadow*)THREAD)->clear_pending_nonasync_exception())
243 #define CHECK_AND_CLEAR_NONASYNC THREAD); if (HAS_PENDING_EXCEPTION) { CLEAR_PENDING_NONASYNC_EXCEPTION; return; } (void)(0
244 #define CHECK_AND_CLEAR_NONASYNC_(result) THREAD); if (HAS_PENDING_EXCEPTION) { CLEAR_PENDING_NONASYNC_EXCEPTION; return result; } (void)(0
245 #define CHECK_AND_CLEAR_NONASYNC_0 CHECK_AND_CLEAR_NONASYNC_(0)
246 #define CHECK_AND_CLEAR_NONASYNC_NH CHECK_AND_CLEAR_NONASYNC_(Handle())
247 #define CHECK_AND_CLEAR_NONASYNC_NULL CHECK_AND_CLEAR_NONASYNC_(nullptr)
248 #define CHECK_AND_CLEAR_NONASYNC_false CHECK_AND_CLEAR_NONASYNC_(false)
249
250 // The THROW... macros should be used to throw an exception. They require a THREAD variable to be
251 // visible within the scope containing the THROW. Usually this is achieved by declaring the function
252 // with a TRAPS argument.
253
254 #define THREAD_AND_LOCATION THREAD, __FILE__, __LINE__
255
256 #define THROW_OOP(e) \
257 { Exceptions::_throw_oop(THREAD_AND_LOCATION, e); return; }
258
259 #define THROW_HANDLE(e) \
260 { Exceptions::_throw(THREAD_AND_LOCATION, e); return; }
261
262 #define THROW(name) \
263 { Exceptions::_throw_msg(THREAD_AND_LOCATION, name, nullptr); return; }
264
265 #define THROW_MSG(name, message) \
266 { Exceptions::_throw_msg(THREAD_AND_LOCATION, name, message); return; }
267
268 #define THROW_CAUSE(name, cause) \
269 { 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
215 // the exception and is only needed for syntactic correctness. The _0 ending is a shortcut for
216 // _(0) since this is a frequent case. Example:
217 //
218 // int result = this_function_may_trap(x_arg, y_arg, CHECK_0);
219 //
220 // CAUTION: make sure that the function call using a CHECK macro is not the only statement of a
221 // conditional branch w/o enclosing {} braces, since the CHECK macros expand into several state-
222 // ments! Also make sure it is not used on a function call that is part of a return statement!
223
224 #define PENDING_EXCEPTION (((ThreadShadow*)THREAD)->pending_exception())
225 #define HAS_PENDING_EXCEPTION (((ThreadShadow*)THREAD)->has_pending_exception())
226 #define CLEAR_PENDING_EXCEPTION (((ThreadShadow*)THREAD)->clear_pending_exception())
227
228 #define CHECK THREAD); if (HAS_PENDING_EXCEPTION) return ; (void)(0
229 #define CHECK_(result) THREAD); if (HAS_PENDING_EXCEPTION) return result; (void)(0
230 #define CHECK_0 CHECK_(0)
231 #define CHECK_NH CHECK_(Handle())
232 #define CHECK_NULL CHECK_(nullptr)
233 #define CHECK_false CHECK_(false)
234 #define CHECK_JNI_ERR CHECK_(JNI_ERR)
235 #define CHECK_PREEMPTABLE THREAD); if (HAS_PENDING_EXCEPTION) { THREAD->check_preempted_exception(); return; } (void)(0
236 #define CHECK_PREEMPTABLE_false THREAD); if (HAS_PENDING_EXCEPTION) { THREAD->check_preempted_exception(); return false; } (void)(0
237
238 // CAUTION: These macros clears all exceptions including async exceptions, use it with caution.
239 #define CHECK_AND_CLEAR THREAD); if (HAS_PENDING_EXCEPTION) { CLEAR_PENDING_EXCEPTION; return; } (void)(0
240 #define CHECK_AND_CLEAR_(result) THREAD); if (HAS_PENDING_EXCEPTION) { CLEAR_PENDING_EXCEPTION; return result; } (void)(0
241 #define CHECK_AND_CLEAR_0 CHECK_AND_CLEAR_(0)
242 #define CHECK_AND_CLEAR_NH CHECK_AND_CLEAR_(Handle())
243 #define CHECK_AND_CLEAR_NULL CHECK_AND_CLEAR_(nullptr)
244 #define CHECK_AND_CLEAR_false CHECK_AND_CLEAR_(false)
245
246 // CAUTION: These macros clears all exceptions except probable async exceptions j.l.InternalError.
247 // So use it with caution.
248 #define CLEAR_PENDING_NONASYNC_EXCEPTION (((ThreadShadow*)THREAD)->clear_pending_nonasync_exception())
249 #define CHECK_AND_CLEAR_NONASYNC THREAD); if (HAS_PENDING_EXCEPTION) { CLEAR_PENDING_NONASYNC_EXCEPTION; return; } (void)(0
250 #define CHECK_AND_CLEAR_NONASYNC_(result) THREAD); if (HAS_PENDING_EXCEPTION) { CLEAR_PENDING_NONASYNC_EXCEPTION; return result; } (void)(0
251 #define CHECK_AND_CLEAR_NONASYNC_0 CHECK_AND_CLEAR_NONASYNC_(0)
252 #define CHECK_AND_CLEAR_NONASYNC_NH CHECK_AND_CLEAR_NONASYNC_(Handle())
253 #define CHECK_AND_CLEAR_NONASYNC_NULL CHECK_AND_CLEAR_NONASYNC_(nullptr)
254 #define CHECK_AND_CLEAR_NONASYNC_false CHECK_AND_CLEAR_NONASYNC_(false)
255
256 #define CLEAR_PENDING_PREEMPTED_EXCEPTION (((ThreadShadow*)THREAD)->clear_pending_preempted_exception())
257 #define CHECK_AND_CLEAR_PREEMPTED THREAD); if (HAS_PENDING_EXCEPTION) { CLEAR_PENDING_PREEMPTED_EXCEPTION; return; } (void)(0
258
259
260 // The THROW... macros should be used to throw an exception. They require a THREAD variable to be
261 // visible within the scope containing the THROW. Usually this is achieved by declaring the function
262 // with a TRAPS argument.
263
264 #define THREAD_AND_LOCATION THREAD, __FILE__, __LINE__
265
266 #define THROW_OOP(e) \
267 { Exceptions::_throw_oop(THREAD_AND_LOCATION, e); return; }
268
269 #define THROW_HANDLE(e) \
270 { Exceptions::_throw(THREAD_AND_LOCATION, e); return; }
271
272 #define THROW(name) \
273 { Exceptions::_throw_msg(THREAD_AND_LOCATION, name, nullptr); return; }
274
275 #define THROW_MSG(name, message) \
276 { Exceptions::_throw_msg(THREAD_AND_LOCATION, name, message); return; }
277
278 #define THROW_CAUSE(name, cause) \
279 { Exceptions::_throw_cause(THREAD_AND_LOCATION, name, cause); return; }
|