[9] RFR [XS] 8054492: Casting can result in redundant null checks in generated code
Vladimir Kozlov
vladimir.kozlov at oracle.com
Wed Oct 15 19:39:18 UTC 2014
Thank you, David
I do not have time to investigate new Paul's cases. I will do that most
likely next week and I will send new updated webrev. And I will add
test. So we can delay review for this until then.
Thanks,
Vladimir
On 10/15/14 11:11 AM, David Chase wrote:
> The changes look good to me;
> did you find anything more out about Paul Sandoz’s problem?
>
> David
>
>
> On 2014-10-14, at 4:15 PM, Vladimir Kozlov <vladimir.kozlov at oracle.com> wrote:
>
>> Thank you, Paul
>>
>> I will look on that.
>>
>> Vladimir
>>
>> On 10/14/14 9:58 AM, Paul Sandoz wrote:
>>> Here is a simpler test case that just uses a MH to Class.cast that exhibits the same behaviour.
>>>
>>> The commented out use of the BiFunction created from a lambda expressions works fine.
>>>
>>> This suggests there might be something about the MH invocation that is stopping the optimization from kicking in.
>>>
>>> Paul.
>>>
>>> import java.lang.invoke.MethodHandle;
>>> import java.lang.invoke.MethodHandles;
>>> import java.lang.invoke.MethodType;
>>> import java.util.function.BiFunction;
>>>
>>> public class NullCheckDroppingsMHCastTest {
>>>
>>> static final MethodHandle MH_CAST;
>>>
>>> static {
>>> try {
>>> MH_CAST = MethodHandles.lookup().findVirtual(Class.class,
>>> "cast",
>>> MethodType.methodType(Object.class, Object.class));
>>> }
>>> catch (Exception e) {
>>> throw new Error(e);
>>> }
>>> }
>>>
>>> static final BiFunction<Class, Object, Object> fCast = (c, o) -> c.cast(o);
>>>
>>>
>>> volatile String svalue = "A";
>>> volatile String snull = null;
>>> String ssink;
>>>
>>> public static void main(String[] args) {
>>> NullCheckDroppingsMHCastTest t = new NullCheckDroppingsMHCastTest();
>>> t.testLoop();
>>> }
>>>
>>> void testLoop() {
>>> // Ensure testLoopOne is compiled and does not
>>> // see a null value
>>> for (int i = 0; i < 1000000; i++) {
>>> testLoopOne(svalue);
>>> // Uncomment the following and the call outside
>>> // the loop should not result in any deoptimization
>>> // testLoopOne(snull);
>>> }
>>>
>>> // Sleep just to create delay in the compilation log
>>> try {
>>> Thread.currentThread().sleep(1000);
>>> }
>>> catch (Exception e) {
>>> }
>>>
>>> // This should cause a de-optimisation
>>> // if testLoopOne is compiled with a null-check
>>> testLoopOne(snull);
>>> }
>>>
>>> void testLoopOne(String s) {
>>> try {
>>> ssink = (String) (Object) MH_CAST.invokeExact(String.class, (Object) s);
>>> // ssink = (String) fCast.apply(String.class, s);
>>> }
>>> catch (Throwable t) {
>>> throw new Error(t);
>>> }
>>> }
>>> }
>>>
>
More information about the hotspot-compiler-dev
mailing list