RFR: 8267118: OutOfMemoryError cannot be caught as a Throwable [v2]
David Holmes
david.holmes at oracle.com
Mon May 31 22:40:03 UTC 2021
Hi Coleen,
On 1/06/2021 8:35 am, Coleen Phillimore wrote:
> On Mon, 31 May 2021 06:39:49 GMT, David Holmes <dholmes at openjdk.org> wrote:
>
>>> This interesting little quirk was discovered by @iklam. During verification, the catch-type in a catch clause is normally resolved as part of being checked to see that it is a subclass of Throwable. At runtime when an exception is thrown, we also have to check if the exception being thrown is assignable to the catch-type and so handled by that catch block. For the case where the catch-type is Throwable itself, the verification subclass check trivially passes (due to a name match) without actually resolving the CP entry for the catch-type. So at runtime when the exception is thrown we have to perform the CP resolution of the catch-type. But the resolution process itself can trigger exceptions and in particular if we have thrown OutOfMemoryError, the resolution may throw a secondary OutOfMemoryError, which prevents the first from being caught by the catch block!
>>>
>>> The fix is to force resolution of the catch-type at verification time, when it is Throwable.
>>>
>>> To aid in debugging the original problem I've also added some new logging statements that show how we find a catch block and if we encounter further exceptions in trying to catch the exception - see example in the JBS issue.
>>>
>>> Testing: tiers 1-3, plus the new test
>>>
>>> Thanks,
>>> David
>>
>> David Holmes 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 two additional commits since the last revision:
>>
>> - Merge branch 'master' into 8267118-oome
>> - 8267118: OutOfMemoryError cannot be caught as a Throwable
>
> This seems reasonable to me.
Thanks for taking a look.
> src/hotspot/share/oops/method.cpp line 232:
>
>> 230: if (do_logging) {
>> 231: ResourceMark rm(THREAD);
>> 232: log_info(exceptions)("Looking for catch handler for exception of type \"%s\" in method \"%s\"",
>
> I think these should be log_debug, since this is useful for debugging but many people outside of hotspot engineers use -Xlog:exceptions.
Every existing piece of logging for exceptions is done at Info level. If
throwing is logged at Info, shouldn't catching also be logged at Info?
Thanks,
David
> -------------
>
> Changes requested by coleenp (Reviewer).
>
> PR: https://git.openjdk.java.net/jdk/pull/4266
>
More information about the hotspot-runtime-dev
mailing list