RFR: 8260605: Various java.lang.invoke cleanups [v5]

Claes Redestad redestad at openjdk.java.net
Wed Mar 17 18:00:56 UTC 2021


On Mon, 15 Mar 2021 18:10:56 GMT, Mandy Chung <mchung at openjdk.org> wrote:

>> Claes Redestad 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 seven additional commits since the last revision:
>> 
>>  - Revert pattern matching changes covered by #2913
>>  - Merge branch 'master' into invoke_cleanup
>>  - Missing .values
>>  - More cleanup, reduce allocations in InvokerBytecodeGenerator
>>  - Missing outstanding changes
>>  - Avoid unnecessary reboxing checks, inline and simplify class/mt invokes
>>  - j.l.invoke cleanups
>
> src/java.base/share/classes/java/lang/invoke/BootstrapMethodInvoker.java line 151:
> 
>> 149:                     maybeReBoxElements(argv);
>> 150:                     if (argv.length > 6) {
>> 151:                         result = invokeWithManyArguments(bootstrapMethod, caller, name, type, argv);
> 
> it'd be cleaner to move this to the default case in line 162 and 174 instead of having this special if-block.

Good catch!

> src/java.base/share/classes/java/lang/invoke/InvokerBytecodeGenerator.java line 342:
> 
>> 340:         setClassWriter(cw);
>> 341:         cw.visit(Opcodes.V1_8, NOT_ACC_PUBLIC + Opcodes.ACC_FINAL + Opcodes.ACC_SUPER,
>> 342:                 CLASS_PREFIX.concat(className), null, INVOKER_SUPER_NAME, null);
> 
> I prefer to use the existing common pattern using `+` as I believe this gain is in the noise.

The goal here was to remove/reduce allocations and excess calls - and using String.concat might have been excessive.

The bulk of the overhead is the potentially many `CLASS_PREFIX + className` calls, often via `className()`. Calculating this once and storing it in an instance field `prefixedClassName` is more profitable and help better disambiguates between `className` and `className()` - which sound like they should be the same but aren't.

-------------

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


More information about the core-libs-dev mailing list