什么是 OpenJDK8 中的 `__the_thread__` 宏

What is the `__the_thread__` macro in OpenJDK8

hotspot/src/share/vm/utilities/exceptions.hpp中,有一些代码:

// 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

THREAD宏仅用于抛出异常:

// 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) {......}

然而,我用grep搜索了所有OpenJDK8的代码,却发现这里只有一个地方有这个__the_thread__宏。 谁能告诉我真正的宏定义是什么?

__the_thread__ 这里是一个变量的名称,或者更确切地说是一个可能抛出异常的 VM 函数的参数。它总是通过 THREADTRAPS 宏访问,这就是为什么没有其他引用,变量的真实名称无关紧要。

例如定义

    jint find_field_offset(jobject field, int must_be_static, TRAPS)

被预处理器扩展为

    jint find_field_offset(jobject field, int must_be_static, Thread* __the_thread__)