RFR: 8267118: OutOfMemoryError cannot be caught as a Throwable [v5]
David Holmes
dholmes at openjdk.java.net
Tue Jun 1 23:39:07 UTC 2021
> 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 six additional commits since the last revision:
- Merge branch 'master' into 8267118-oome
- Simplified logging to reuse Info statements as suggested by @coleenp
- Fix mh() usage
- Reworked the new logging to seperate Info and Debug levels to reduce verbosity, per
feedback from @coleenp @iklam
- Merge branch 'master' into 8267118-oome
- 8267118: OutOfMemoryError cannot be caught as a Throwable
-------------
Changes:
- all: https://git.openjdk.java.net/jdk/pull/4266/files
- new: https://git.openjdk.java.net/jdk/pull/4266/files/ce8496bd..9732c43b
Webrevs:
- full: https://webrevs.openjdk.java.net/?repo=jdk&pr=4266&range=04
- incr: https://webrevs.openjdk.java.net/?repo=jdk&pr=4266&range=03-04
Stats: 24818 lines in 857 files changed: 4076 ins; 19201 del; 1541 mod
Patch: https://git.openjdk.java.net/jdk/pull/4266.diff
Fetch: git fetch https://git.openjdk.java.net/jdk pull/4266/head:pull/4266
PR: https://git.openjdk.java.net/jdk/pull/4266
More information about the hotspot-runtime-dev
mailing list