RFR: 8230662: Remove dead code from MethodTypeForm
Peter Levart
peter.levart at gmail.com
Mon Sep 9 10:31:17 UTC 2019
Hi Claes,
Your changes look good. But I spotted a pre-existing and unusual use of
@Stable annotation in java.lang.invoke.MethodTypeForm class:
// Cached adapter information:
@Stable final SoftReference<MethodHandle>[] methodHandles;
// Cached lambda form information, for basic types only:
final @Stable SoftReference<LambdaForm>[] lambdaForms;
This declarations are paired with the following caching logic that
returns pre-existing entry if it is already set and not yet cleared or
cache new entry and return it:
public synchronized MethodHandle setCachedMethodHandle(int which,
MethodHandle mh) {
// Simulate a CAS, to avoid racy duplication of results.
SoftReference<MethodHandle> entry = methodHandles[which];
if (entry != null) {
MethodHandle prev = entry.get();
if (prev != null) {
return prev;
}
}
methodHandles[which] = new SoftReference<>(mh);
return mh;
}
and:
public synchronized LambdaForm setCachedLambdaForm(int which,
LambdaForm form) {
// Simulate a CAS, to avoid racy duplication of results.
SoftReference<LambdaForm> entry = lambdaForms[which];
if (entry != null) {
LambdaForm prev = entry.get();
if (prev != null) {
return prev;
}
}
lambdaForms[which] = new SoftReference<>(form);
return form;
}
If these two @Stable annotations had any effect on JIT optimization,
then I think the caching logic would become ineffective for slots in
which SoftReference(s) got cleared by GC. In that case, such slots would
constantly be overwritten with new SoftReference(s) only to see old
constant-folded SoftReference(s) next time around.
So I think that these @Stable annotations do no good here. Either they
are ineffective in cases where MethodTypeForm instances are not
constant-folded, or they render caching ineffective when MethodTypeForm
instances are constant-folder and SoftReference(s) are cleared. In
either case it would be better without them.
What do you think?
Regards, Peter
On 9/5/19 4:41 PM, Claes Redestad wrote:
> Hi,
>
> I noticed some unused methods in java.lang.invoke.MethodTypeForm and
> ended up with a rather substantial cleanup after pulling that particular
> thread for a bit:
>
> http://cr.openjdk.java.net/~redestad/8230662/jdk.00/
> https://bugs.openjdk.java.net/browse/JDK-8230662
>
> Testing: tier1-3
>
> Thanks!
>
> /Claes
More information about the core-libs-dev
mailing list