RFR: 8288140: Avoid redundant Hashtable.get call in Signal.handle

David M. Lloyd duke at openjdk.java.net
Thu Jun 9 21:15:06 UTC 2022


On Thu, 9 Jun 2022 07:35:43 GMT, Andrey Turbanov <aturbanov at openjdk.org> wrote:

> https://github.com/openjdk/jdk/blob/bc28baeba9360991e9b7575e1fbe178d873ccfc1/src/java.base/share/classes/jdk/internal/misc/Signal.java#L177-L178
> 
> Instead of separate Hashtable.get/remove calls we can just use value returned by `remove`,
> It results in cleaner and a bit faster code.

src/java.base/share/classes/jdk/internal/misc/Signal.java line 180:

> 178:             if (newH == 2) {
> 179:                 handlers.put(sig, handler);
> 180:             }

If you made this change instead:

Suggestion:

            Signal.Handler oldHandler;
            if (newH == 2) {
                oldHandler = handlers.replace(sig, handler);
            } else {
                oldHandler = handlers.remove(sig);
            }


Wouldn't you be able to remove the entire `synchronized` block?

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

PR: https://git.openjdk.org/jdk/pull/9100


More information about the core-libs-dev mailing list