In hotspot/src/share/vm/utilities/exceptions.hpp
, there's some code:
// The THREAD & TRAPS macros facilitate the declaration of functions that throw exceptions.
// Convention: Use the TRAPS macro as the last argument of such a function; e.g.:
//
// int this_function_may_trap(int x, float y, TRAPS)
#define THREAD __the_thread__
#define TRAPS Thread* THREAD
The THREAD
macro only use for throw an exception:
// The THROW... macros should be used to throw an exception. They require a THREAD variable to be
// visible within the scope containing the THROW. Usually this is achieved by declaring the function
// with a TRAPS argument.
#define THREAD_AND_LOCATION THREAD, __FILE__, __LINE__
#define THROW_OOP(e) \
{ Exceptions::_throw_oop(THREAD_AND_LOCATION, e); return; }
#define THROW_HANDLE(e) \
{ Exceptions::_throw(THREAD_AND_LOCATION, e); return; }
// the real place to use __the_thread__ macro
void Exceptions::_throw(Thread* thread, const char* file, int line, Handle h_exception, const char* message) {......}
However, I use grep
to search all OpenJDK8's code, only to find there's only one place here has this __the_thread__
macro.
Can someone tell me what does the real macro define?
__the_thread__
here is the name of a variable or rather an argument to VM functions that may throw an exception. It is always accessed through a THREAD
or TRAPS
macro, that's why there are no other references, and the real name of the variable does not matter.
For example, the definition
jint find_field_offset(jobject field, int must_be_static, TRAPS)
is expanded by preprocessor to
jint find_field_offset(jobject field, int must_be_static, Thread* __the_thread__)