Re: RFR: 8071571: Move substring of same string to slow path

2015-05-13 Thread Ivan Gerasimov
Hi Martin! On 13.05.2015 0:22, Martin Buchholz wrote: All your changes look good. But: --- Not your bug, but it looks like the below should instead be: throw new StringIndexOutOfBoundsException(beginIndex); Perhaps fix in a follow-on change. 1935 if (subLen 0) { 1936

Re: RFR: 8071571: Move substring of same string to slow path

2015-05-13 Thread Ivan Gerasimov
On 14.05.2015 2:06, Vitaly Davidovich wrote: Why not look at the generated asm and not guess? :) The branch avoiding versions may cause data dependence hazards whereas the branchy one just has branches but assuming perfectly predicted (and microbenchmarks typically are) can pipeline

Re: RFR: 8071571: Move substring of same string to slow path

2015-05-13 Thread Martin Buchholz
On Wed, May 13, 2015 at 2:25 PM, Ivan Gerasimov ivan.gerasi...@oracle.com wrote: Benchmark Mode Cnt Score Error Units MyBenchmark.testMethod_1 thrpt 60 1132911599.680 ± 42375177.640 ops/s MyBenchmark.testMethod_2 thrpt 60 813737659.576 ±

Re: RFR: 8071571: Move substring of same string to slow path

2015-05-13 Thread Martin Buchholz
On Wed, May 13, 2015 at 4:06 PM, Vitaly Davidovich vita...@gmail.com wrote: :) The branch avoiding versions may cause data dependence hazards whereas the branchy one just has branches but assuming perfectly predicted (and microbenchmarks typically are) can pipeline through. Ivan, could you

Re: RFR: 8071571: Move substring of same string to slow path

2015-05-13 Thread Vitaly Davidovich
Yes, that should be the general rule of thumb for code targeting out of order chips. The caveat is that microbenchmarks have the advantage of being the only (typically very small) code running on the cpu, and will get full use of execution resources; specifically in this case, it's very likely

Re: RFR: 8071571: Move substring of same string to slow path

2015-05-13 Thread Vitaly Davidovich
Need JIT generated assembly, not bytecode :). That will tell you at least which optimizations JIT applied, how it register allocated things, etc. If nothing obvious there, see my other reply regarding cpu event based profiling. I'm sure Aleksey Shipilev could help out if you're really inclined

Re: RFR: 8071571: Move substring of same string to slow path

2015-05-13 Thread Vitaly Davidovich
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

Re: RFR: 8071571: Move substring of same string to slow path

2015-05-13 Thread Vitaly Davidovich
By the way, this is pure speculation on my part by just looking at the code. To truly find out, at least say for Intel, you'd have to run these benchmarks under a cpu event profiler and see what it tells you for IPC, branch mispredictions, the various stalls, etc. JMH has perfasm I believe which

Re: RFR: 8071571: Move substring of same string to slow path

2015-05-13 Thread Vitaly Davidovich
Why not look at the generated asm and not guess? :) The branch avoiding versions may cause data dependence hazards whereas the branchy one just has branches but assuming perfectly predicted (and microbenchmarks typically are) can pipeline through. Ivan, could you please post the asm here?

Re: RFR: 8071571: Move substring of same string to slow path

2015-05-13 Thread John Rose
On May 13, 2015, at 2:25 PM, Ivan Gerasimov ivan.gerasi...@oracle.com wrote: 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

Re: RFR: 8071571: Move substring of same string to slow path

2015-05-13 Thread John Rose
On May 13, 2015, at 4:46 PM, Vitaly Davidovich vita...@gmail.com wrote: I'd add And always look at generated asm for these types of constructs. +1, with caveats about micro-versions changing stuff at that level

Re: RFR: 8071571: Move substring of same string to slow path

2015-05-12 Thread Martin Buchholz
Hi Ivan, The code below looks wrong to me - sb.length() resolves to sb.count, not v2.length. If I'm correct, then there's a missing test to be added, since this error should be caught by some test. private boolean nonSyncContentEquals(AbstractStringBuilder sb) { -char v1[] = value;

Re: RFR: 8071571: Move substring of same string to slow path

2015-05-12 Thread Ivan Gerasimov
On 12.05.2015 20:34, Martin Buchholz wrote: Hi Ivan, The code below looks wrong to me - sb.length() resolves to sb.count, not v2.length. If I'm correct, then there's a missing test to be added, since this error should be caught by some test. private boolean

Re: RFR: 8071571: Move substring of same string to slow path

2015-05-12 Thread Martin Buchholz
All your changes look good. But: --- Not your bug, but it looks like the below should instead be: throw new StringIndexOutOfBoundsException(beginIndex); Perhaps fix in a follow-on change. 1935 if (subLen 0) { 1936 throw new StringIndexOutOfBoundsException(subLen); --- We

Re: RFR: 8071571: Move substring of same string to slow path

2015-05-11 Thread Ivan Gerasimov
I have to take over this fix. The latest webrev from the review thread above (with a few minor changes) is here: http://cr.openjdk.java.net/~igerasim/8071571/00/webrev/ Would you please review/approve the fix at your convenience? Sincerely yours, Ivan

Re: RFR: 8071571: Move substring of same string to slow path

2015-03-31 Thread John Rose
On Mar 27, 2015, at 3:01 PM, Martin Buchholz marti...@google.com wrote: final Type foo = this.foo; There are IMO a few places where local finals pay for themselves, even after Java 8. One is Martin's idiom. The key thing to observe is that 'foo' is a read-only snapshot or view of 'this.foo'.

Re: RFR: 8071571: Move substring of same string to slow path

2015-03-30 Thread Lev Priima
Martin, So I've updated webrev w/o adding final everywhere: http://cr.openjdk.java.net/~lpriima/8071571/3/ . Lev On 03/28/2015 01:15 AM, Lev Priima wrote: On 03/28/2015 12:59 AM, Martin Buchholz wrote: I was only suggesting using final in the stylized final Type foo = this.foo; Using

Re: RFR: 8071571: Move substring of same string to slow path

2015-03-28 Thread Remi Forax
On 03/27/2015 10:59 PM, Martin Buchholz wrote: [...] OTOH, if you touch code that uses the denigrated char foo[] please change it to char[] foo This is yet another of those global changes to the entire jdk sources that nobody ever gets around to. on the same subject, the Java grammar

Re: RFR: 8071571: Move substring of same string to slow path

2015-03-28 Thread Remi Forax
On 03/27/2015 11:01 PM, Martin Buchholz wrote: On Fri, Mar 27, 2015 at 2:57 PM, Roger Riggs roger.ri...@oracle.com wrote: Hi, @Martin: does the final have some functional reason to be present? I see it just bulks up the source, reducing readability. If it is useful to improve performance

RFR: 8071571: Move substring of same string to slow path

2015-03-27 Thread Lev Priima
Please review small cleanup in java.lang.String: Issue: https://bugs.openjdk.java.net/browse/JDK-8071571 Webrev: http://cr.openjdk.java.net/~lpriima/8071571/0/webrev/ 46 tests from jdk9/dev/jdk/test/java/lang/String* passed locally. -- Lev

Re: RFR: 8071571: Move substring of same string to slow path

2015-03-27 Thread Lev Priima
Hi Ivan, Thanks! Agree. Updated: http://cr.openjdk.java.net/~lpriima/8071571/1/webrev/ Lev On 03/27/2015 06:17 PM, Ivan Gerasimov wrote: Hi Lev! Why don't you want to also simplify String#trim()? -return ((st 0) || (len value.length)) ? substring(st, len) : this; +

Re: RFR: 8071571: Move substring of same string to slow path

2015-03-27 Thread Martin Buchholz
On Fri, Mar 27, 2015 at 1:49 PM, Lev Priima lev.pri...@oracle.com wrote: Martin, You mean it should be like this: char[] val = value;/* avoid getfield opcode */ int end = val.length; ? Yes. (although I personally like to write it like this: final char[] value =

Re: RFR: 8071571: Move substring of same string to slow path

2015-03-27 Thread Martin Buchholz
Here you copy the field into a local, but then don't make use of it to grab the length. 2888 int len = value.length; 2889 int st = 0; 2890 char[] val = value;/* avoid getfield opcode */ Also, 'beg' and 'end' would be much better names for the locals 'st' and 'len'.

Re: RFR: 8071571: Move substring of same string to slow path

2015-03-27 Thread Lev Priima
Martin, You mean it should be like this: char[] val = value;/* avoid getfield opcode */ int end = val.length; ? Lev On 03/27/2015 11:37 PM, Martin Buchholz wrote: Here you copy the field into a local, but then don't make use of it to grab the length. 2888 int len

Re: RFR: 8071571: Move substring of same string to slow path

2015-03-27 Thread Lev Priima
Updated and put some more final in other(not @Deprecated) methods: http://cr.openjdk.java.net/~lpriima/8071571/2/ Lev On 03/27/2015 11:50 PM, Martin Buchholz wrote: On Fri, Mar 27, 2015 at 1:49 PM, Lev Priima lev.pri...@oracle.com mailto:lev.pri...@oracle.com wrote: Martin, You

Re: RFR: 8071571: Move substring of same string to slow path

2015-03-27 Thread Lev Priima
I'm closer to Martins opinion. In my opinion, Immutability really improves readability of code, but longer declaration doesn't. That's why some contemporary languages use shorter var/val for declarations. Lev On 03/28/2015 01:01 AM, Martin Buchholz wrote: On Fri, Mar 27, 2015 at 2:57 PM,

Re: RFR: 8071571: Move substring of same string to slow path

2015-03-27 Thread Roger Riggs
Hi, @Martin: does the final have some functional reason to be present? I see it just bulks up the source, reducing readability. If it is useful to improve performance then fine. Roger On 3/27/2015 5:51 PM, Lev Priima wrote: Updated and put some more final in other(not @Deprecated)

Re: RFR: 8071571: Move substring of same string to slow path

2015-03-27 Thread Martin Buchholz
I was only suggesting using final in the stylized final Type foo = this.foo; Using final for other local variables is going further than most jdk maintainers (including myself) go. OTOH, if you touch code that uses the denigrated char foo[] please change it to char[] foo This is yet another

Re: RFR: 8071571: Move substring of same string to slow path

2015-03-27 Thread Martin Buchholz
On Fri, Mar 27, 2015 at 2:57 PM, Roger Riggs roger.ri...@oracle.com wrote: Hi, @Martin: does the final have some functional reason to be present? I see it just bulks up the source, reducing readability. If it is useful to improve performance then fine. If you use the idiom final Type foo