RFR: 8260337: Optimize ImageReader lookup, used by Class.getResource

Alan Bateman alanb at openjdk.java.net
Mon Jan 25 15:50:44 UTC 2021

On Mon, 25 Jan 2021 00:05:52 GMT, Claes Redestad <redestad at openjdk.org> wrote:

> This patch optimizes the code paths exercised by `String.class.getResource("String.class")` by:
> - Adding an ASCII fast-path to methods verifying strings in the jimage, which can then be done allocation-free
> - Avoiding the allocation of the `long[8]` attributes when verifying only for the purpose of verifying a path exists
> - Using the `JNUA.create` fast-path in `SystemModuleReader` (which should be OK since we just verified the given name is a JRT path)
> - Remove a redundant check in `Class::resolveName` and fitting the `StringBuilder` to size

src/java.base/share/classes/jdk/internal/module/SystemModuleFinders.java line 439:

> 437:          * if not found.
> 438:          */
> 439:         private boolean containsLocation(String name) throws IOException {

Can you rename this to containsImageLocation to keep it consistent with findImageLocation? Alternative rename findImageLocation. Also would be better for the description to be "Returns true if the given resource exists, false if not found".

The changes to the jimage code will take time to review, probably should have 2 reviewers.


PR: https://git.openjdk.java.net/jdk/pull/2212

More information about the core-libs-dev mailing list