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

Coleen Phillimore coleenp at openjdk.java.net
Mon Mar 15 19:01:13 UTC 2021


On Mon, 15 Mar 2021 18:41:34 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;
>>   }
>> }
>
> 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

This looks good.  It would be nice to replace more EXCEPTION_MARK as we find them.

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

Marked as reviewed by coleenp (Reviewer).

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


More information about the hotspot-dev mailing list