RFR: 8263392: Allow current thread to be specified in ExceptionMark [v2]

Ioi Lam iklam at openjdk.java.net
Mon Mar 15 18:41:34 UTC 2021


> `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;
>   }
> }

Ioi Lam has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains four additional commits since the last revision:

 - Merge branch 'master' into 8263392-ExceptionMark-with-thread
 - removed THREAD declaration because ObjectSynchronizer::exit no longer needs it since JDK-8262910
 - fixed build
 - 8263392: Allow current thread to be specified in ExceptionMark

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

Changes:
  - all: https://git.openjdk.java.net/jdk/pull/2950/files
  - new: https://git.openjdk.java.net/jdk/pull/2950/files/91eefd71..53a016d7

Webrevs:
 - full: https://webrevs.openjdk.java.net/?repo=jdk&pr=2950&range=01
 - incr: https://webrevs.openjdk.java.net/?repo=jdk&pr=2950&range=00-01

  Stats: 25563 lines in 1185 files changed: 21219 ins; 2025 del; 2319 mod
  Patch: https://git.openjdk.java.net/jdk/pull/2950.diff
  Fetch: git fetch https://git.openjdk.java.net/jdk pull/2950/head:pull/2950

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


More information about the hotspot-dev mailing list