RFR: 8292914: Drop the counter from lambda class names [v7]
Ioi Lam
iklam at openjdk.org
Fri Feb 17 18:11:57 UTC 2023
On Fri, 17 Feb 2023 17:02:56 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:
>
> Updated to use hidden class suffix for dumps when possible, else use the counter with a `failed` suffix. Also, remove the extra trailing `$` from the lambda class name and update tests accordingly.
>
> This combines the suggestions made by @mlchung and @ExE-Boss and hopefully will resolve the Windows testing issue.
If you really want a stable name, an alternative approach is to walk the stack and find the caller of `LambdaMetafactory.metafactory` and get the constant pool index of the invokedynamic instruction. (This probably needs to be done with a native method).
Javac uses a unique CP index for each call site (15 vs 23 in the following example).
class Test {
static void f1() {
doit(() -> foo());
}
static void f2() {
doit(() -> foo());
}
....
}
$ javap -c -v Test.class
static void f1();
Code:
0: invokedynamic #15, 0 // InvokeDynamic #0:run:()Ljava/lang/Runnable;
5: invokestatic #19 // Method doit:(Ljava/lang/Runnable;)V
8: return
static void f2();
stack=1, locals=0, args_size=0
0: invokedynamic #23, 0 // InvokeDynamic #1:run:()Ljava/lang/Runnable;
5: invokestatic #19 // Method doit:(Ljava/lang/Runnable;)V
8: return
-------------
PR: https://git.openjdk.org/jdk/pull/12579
More information about the core-libs-dev
mailing list