Skip to main content

Does HotSpot optimise this?

1 reply [Last post]
alexlamsl
Offline
Joined: 2004-09-02
Points: 0

Does HotSpot optimise the following code? Would the behaviour also depends on how heavily biased the if-else branches are reached?

Just being curious you see ;-)

<br />
boolean c(A a) {<br />
    /* ... */<br />
}</p>
<p>void s(A a) {<br />
    /* ... */<br />
    if (c(a)) {<br />
        /* ... */<br />
    } else {<br />
        /* ... */<br />
    }<br />
    /* ... */<br />
}</p>
<p>void t(A a) {<br />
    /* ... */<br />
    if (c(a)) {<br />
        /* ... */<br />
    } else {<br />
        /* ... */<br />
    }<br />
    /* ... */<br />
}</p>
<p>void m(A a) {<br />
    /* ... */<br />
    if (c(a)) {<br />
        s(a);<br />
    } else {<br />
        t(a);<br />
    }<br />
    /* ... */<br />
}</p>
<p>void n(A a) {<br />
    /* ... */<br />
    if (c(a)) {<br />
        t(a);<br />
    } else {<br />
        s(a);<br />
    }<br />
    /* ... */<br />
}<br />

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
ronaldyang
Offline
Joined: 2003-06-19
Points: 0

That depends what method "c" does. How about:

boolean c(A a) {
return Math.random() < .5;
}

If you cared to, you could use vm options to show hotspotted machine code.