acmp/cas retries and null arguments
Aleksey Shipilev
shade at redhat.com
Tue Sep 13 14:06:03 UTC 2016
Hi,
I have a question about read barriers and null handling. It seems to me
that in acmp/cas comparison, if one of the arguments is null, and
comparison had failed, this means it had failed for good, i.e. it is
never a false negative. I.e. comparing the non-null from-copy with null
produces the same result as comparing the non-null to-copy with null.
Comparing null with null would not trigger a false negative.
If so, I wonder if we can coalesce the null checking code in acmp/cas
retries with the actual retries, instead of jumping over the barrier. We
currently do, e.g. in acmp (in some weird linear pseudo-assembly):
acmp(%a, %b):
test %a, %b
je <true>
test %a, %a
je <anull>
mov %a, (%a - 8);
anull:
test %b, %b
je <bnull>
mov %b, (%b - 8);
bnull:
test %a, %b;
je <true>
ret false;
true:
ret true;
...while instead we could generate:
acmp(%a, %b):
test %a, %b
je <true>
test %a, %a
je <false> // %a is null, guaranteed "false"
mov %a, (%a - 8);
test %b, %b
je <false> // %b is null, guaranteed "false"
mov %b, (%b - 8);
test %a, %b;
je <true>
false:
ret false;
true:
ret true;
This saves read barriers if one of the arguments is not null.
Thanks,
-Aleksey
More information about the shenandoah-dev
mailing list