Integrated: 8267118: OutOfMemoryError cannot be caught as a Throwable
David Holmes
dholmes at openjdk.java.net
Wed Jun 2 10:45:38 UTC 2021
On Mon, 31 May 2021 04:43:23 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
This pull request has now been integrated.
Changeset: 71425ddf
Author: David Holmes <dholmes at openjdk.org>
URL: https://git.openjdk.java.net/jdk/commit/71425ddfb4a7cc9e2d1c7c12cfac61c4d9d7fdf4
Stats: 125 lines in 3 files changed: 124 ins; 0 del; 1 mod
8267118: OutOfMemoryError cannot be caught as a Throwable
Co-authored-by: Ioi Lam <iklam at openjdk.org>
Reviewed-by: coleenp
-------------
PR: https://git.openjdk.java.net/jdk/pull/4266
More information about the hotspot-runtime-dev
mailing list