Costs of caught exceptions during method handle resolve

Mark Reinhold mark.reinhold at oracle.com
Tue Aug 13 22:05:55 UTC 2024


2024/8/9 7:15:38 -0400, Jan Bernitt <jaanbernitt at gmail.com>:
> Hi everyone!
> 
> I recently found a performance issue in my library that goes back to large
> numbers of exceptions being thrown and caught where the costs are dominated
> by filling in the stack trace and resolving method handles.
> 
> So I investigated ways to avoid causing the exceptions. One of the reasons
> for the exceptions
> was somewhere internally in the method handle resolve. I ended up caching
> the method handles to avoid this happening over and over again as my
> library uses method handles all the time :D
> 
> As far as I can tell this should be something the JDK can solve differently
> internally to avoid the cost of throwing and catching the exception which
> should improve performance of method handles significantly if you use them
> (including the lookup) in a hot loop. You can find more details here
> https://github.com/dhis2/json-tree/pull/66
> 
> If this is of interest to some feel free to ask for more details.
> Also if anyone sees that I am just using methods handles wrong and
> therefore cause the internal exception please let me know.

This list is not for technical discussions.  It is for “general
discussion about the OpenJDK Community, including proposals of new
Projects and Groups” [1].

The core-libs-dev list would be a reasonable place to ask specific
questions about method handles, but please don’t expect anyone there
to review random PRs on GitHub.

- Mark


[1] https://mail.openjdk.org/mailman/listinfo/discuss


More information about the discuss mailing list