首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >`__the_thread__`宏在OpenJDK8中是什么?

`__the_thread__`宏在OpenJDK8中是什么?
EN

Stack Overflow用户
提问于 2017-10-26 09:34:11
回答 1查看 162关注 0票数 0

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

代码语言:javascript
复制
// 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宏仅用于抛出异常:

代码语言:javascript
复制
// 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 8的代码,结果发现这里只有一个地方有这个__the_thread__宏。有人能告诉我真正的宏观定义是什么吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-10-26 10:31:17

这里的__the_thread__是变量的名称,或者更确切地说是VM函数的参数,它可能引发异常。它总是通过THREADTRAPS宏访问,这就是为什么没有其他引用,并且变量的真实名称并不重要。

例如,定义

代码语言:javascript
复制
    jint find_field_offset(jobject field, int must_be_static, TRAPS)

被预处理器扩展为

代码语言:javascript
复制
    jint find_field_offset(jobject field, int must_be_static, Thread* __the_thread__)
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46950750

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档