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

Ioi Lam iklam at openjdk.java.net
Mon Mar 15 22:23:11 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;
>   }
> }

This pull request has now been integrated.

Changeset: 1e570870
Author:    Ioi Lam <iklam at openjdk.org>
URL:       https://git.openjdk.java.net/jdk/commit/1e570870
Stats:     34 lines in 8 files changed: 16 ins; 3 del; 15 mod

8263392: Allow current thread to be specified in ExceptionMark

Reviewed-by: dholmes, ccheung, coleenp, minqi

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

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


More information about the hotspot-dev mailing list