RFR: 8263392: Allow current thread to be specified in ExceptionMark
Ioi Lam
iklam at openjdk.java.net
Thu Mar 11 22:06:18 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;
}
}
-------------
Commit messages:
- fixed build
- 8263392: Allow current thread to be specified in ExceptionMark
Changes: https://git.openjdk.java.net/jdk/pull/2950/files
Webrev: https://webrevs.openjdk.java.net/?repo=jdk&pr=2950&range=00
Issue: https://bugs.openjdk.java.net/browse/JDK-8263392
Stats: 35 lines in 8 files changed: 17 ins; 3 del; 15 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