RFR: 8263392: Allow current thread to be specified in ExceptionMark

David Holmes dholmes at openjdk.java.net
Fri Mar 12 06:05:06 UTC 2021


On Thu, 11 Mar 2021 20:36:41 GMT, Ioi Lam <iklam at openjdk.org> wrote:

> `ExceptionMark`, usually used via the `EXCEPTION_MARK` marco, is used to guarantee that an exception is not thrown within a block of code. I made two changes to improve efficiency:
> 
> - Avoid calling `Thread::current()` if a thread object is already available.
> - Avoid passing a reference to the `ExceptionMark` constructor. This helps C++ generate slightly better code.
> 
> This new variant of `ExceptionMark` is mainly intended for future clean up of `TRAPS/CHECK/THREAD` code, where an exception context is temporarily needed but we will guarantee that all exceptions will be handled. I modified `SharedRuntime::monitor_exit_helper()` to use this pattern:
> 
> Old style:
> 
> void a_func_that_never_throws() {
>   EXCEPTION_MARK;
>   a_func_that_could_throw(THREAD);
>   if (HAS_PENDING_EXCEPTION) {
>       // handle it
>     CLEAR_PENDING_EXCEPTION;
>   }
> }
> 
> New style:
> 
> void a_func_that_never_throws(Thread* current) { // pass thread to avoid calling Thread::current()
>   ExceptionMark em(current);
>   Thread* THREAD = current; // For exception macros.
>   a_func_that_could_throw(THREAD);
>   if (HAS_PENDING_EXCEPTION) {
>       // handle it
>       CLEAR_PENDING_EXCEPTION;
>   }
> }

Looks good! Thanks for doing this cleanup.

David

-------------

Marked as reviewed by dholmes (Reviewer).

PR: https://git.openjdk.java.net/jdk/pull/2950


More information about the hotspot-dev mailing list