RFR: 8071571: Move substring of same string to slow path
vitalyd at gmail.com
Wed May 13 23:46:08 UTC 2015
I'd add "And always look at generated asm for these types of constructs".
There's really nothing to profile in terms of "|" outcome unless JIT starts
tracking bit position values, and it's a cheap instruction on its own. I'd
be surprised if conditional moves are emitted here since these branches
should be perfectly predicted (we're not testing the error path right?) and
cmovs themselves have data dependence.
sent from my phone
On May 13, 2015 7:34 PM, "John Rose" <john.r.rose at oracle.com> wrote:
> On May 13, 2015, at 2:25 PM, Ivan Gerasimov <ivan.gerasimov at oracle.com>
> > My third concern is this: Wouldn't it be possible to implement this
> type of optimization at jvm level?
> > At least some conditions can automatically be combined into one.
> > Given the information about which execution path is expected to be fast,
> hotspot should be able to quickly perform that one combined condition check
> and move to the fast path in most situations.
> I think this is the high-order bit: Such optimizations are done, or
> should be done, at the JVM level. If you can tell there's a missing JVM
> optimization, file a bug against the JVM JIT, and keep the clearest code
> style. If you can't tell, still try to keep the clean code style.
> HotSpot's optimizing JIT does not respond equally well to all source
> (bytecode) code styles; it works harder to optimize commonly encountered
> cases, like the simpler JMH cases in the current example. Writing strange
> code that seems to map to smaller or less branchy assembly code might work
> for one micro-version of the JVM, and then be defeated by the next
> Here are two reasons "||" might be preferable to "|" in your source code:
> 1. The JVM interpreter profiles "||" outcomes but not "|". (Side effect
> of profiling branches *in the interpreter*.)
> 2. The C2 JIT looks for small control flow diamonds that it can turn into
> conditional moves or other consolidated instructions.
> If the "||" gets suboptimal assembly code for you, and if your code has a
> commonly-occuring shape, it would be better for all of us to leave the code
> alone and fix the optimizer.
> — John
More information about the core-libs-dev