RFR: 8292914: Drop the counter from lambda class names [v6]

ExE Boss duke at openjdk.org
Thu Feb 16 19:47:32 UTC 2023


On Thu, 16 Feb 2023 19:35:54 GMT, David M. Lloyd <duke at openjdk.org> wrote:

>> The class generated for lambda proxies is now defined as a hidden class. This means that the counter, which was used to ensure a unique class name and avoid clashes, is now redundant. In addition to performing redundant work, this also impacts build reproducibility for native image generators which might already have a strategy to cope with hidden classes but cannot cope with indeterminate definition order for lambda proxy classes.
>> 
>> This solves JDK-8292914 by making lambda proxy names always be stable without any configuration needed. This would also replace #10024.
>
> David M. Lloyd has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Use a unique index for the dumped lambda class instead of a time stamp

src/java.base/share/classes/java/lang/invoke/InnerClassLambdaMetafactory.java line 208:

> 206:             name = name.replace('/', '_');
> 207:         }
> 208:         return name.replace('.', '/') + "$$Lambda$";

Using `String::concat` uses the same code path as indy‑based String concatenation[^1].
Suggestion:

        return name.replace('.', '/').concat("$$Lambda");


[^1]: The JDK uses `StringBuilder`‑based String concatenation:
https://github.com/openjdk/jdk/blob/a39cf2e3b242298fbf5fafdb8aa9b5d4562061ef/make/modules/java.base/Java.gmk#L28

src/java.base/share/classes/java/lang/invoke/ProxyClassesDumper.java line 103:

> 101:         final int len = className.length();
> 102:         // add some padding to `len` for the index
> 103:         StringBuilder sb = new StringBuilder(len + 5);

Suggestion:

        StringBuilder sb = new StringBuilder(len + 6);

src/java.base/share/classes/java/lang/invoke/ProxyClassesDumper.java line 124:

> 122:             }
> 123:         }
> 124:         sb.append(counter.incrementAndGet());

Suggestion:

        sb.append('$').append(counter.incrementAndGet());

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

PR: https://git.openjdk.org/jdk/pull/12579


More information about the core-libs-dev mailing list