Re: RFR 8214971 : Replace use of string.equals("") with isEmpty()

2018-12-10 Thread Tobias Hartmann
Hi Claes, the difference is the "array encoding" (ae) argument passed to the intrinsic. See MacroAssembler::string_compare(... int ae). If we compare an UTF16 String, we know that the number of bytes is always even (two byte / char encoding), whereas a Latin1 string has a byte encoding. So

Re: RFR 8214971 : Replace use of string.equals("") with isEmpty()

2018-12-07 Thread Roger Riggs
Hi Claes, Early in the design there was a question about whether the coder was in the array or the String. That probably translated into following the general pattern that the UTF16 coding was nearly identical and parallel to Latin1 with minimal differences for the size of the data. $.02,

Re: RFR 8214971 : Replace use of string.equals("") with isEmpty()

2018-12-07 Thread Claes Redestad
This is an interesting point: can anyone explain why there are two distinct methods for LATIN1 and UTF16 equality, with corresponding intrinsics? Aleksey? Tobias? Testing with Arrays.equals then performance profile is quite different due vectorization (often better, sometimes worse), but this

Re: RFR 8214971 : Replace use of string.equals("") with isEmpty()

2018-12-07 Thread Stuart Marks
On 12/7/18 4:51 AM, Claes Redestad wrote: One possible improvement would to wrap coder() == aString.coder() in a method isSameCoder(String): private boolean isSameCoder(String other) {     return COMPACT_STRINGS ? coder == other.coder : true; } .. one less method call, but still perfectly

Re: RFR 8214971 : Replace use of string.equals("") with isEmpty()

2018-12-07 Thread Roger Riggs
Hi Hannes, I'd take that up as a separate issue.  [1] A nice thing about the current patch is that the change is uniform and easier to review. It would also be good to look at a utility method that efficiently does the combined check. Thanks, Roger [1] 8215014

Re: RFR 8214971 : Replace use of string.equals("") with isEmpty()

2018-12-07 Thread Claes Redestad
Hi, On 2018-12-07 03:56, Stuart Marks wrote: On 12/6/18 2:42 PM, Claes Redestad wrote: I filed this bug after seeing it in startup profiles, where isEmpty() avoids an instanceof and four(!) method calls, so getting rid of a few of these has a measurable impact on startup. It seemed prudent to

Re: RFR 8214971 : Replace use of string.equals("") with isEmpty()

2018-12-07 Thread Daniel Fuchs
Hi Hannes, On 07/12/2018 09:24, Hannes Wallnöfer wrote: Hi Roger, There are quite a few occurrences of the reverse calling pattern "".equals(str) in core libs. This is a bit more tricky because it allows str to be null, but when used following a null/not-null check it could be replaced with

Re: RFR 8214971 : Replace use of string.equals("") with isEmpty()

2018-12-07 Thread Hannes Wallnöfer
Hi Roger, There are quite a few occurrences of the reverse calling pattern "".equals(str) in core libs. This is a bit more tricky because it allows str to be null, but when used following a null/not-null check it could be replaced with isEmpty() as well. I wonder if these should be included

Re: RFR 8214971 : Replace use of string.equals("") with isEmpty()

2018-12-06 Thread James Laskey
Or simply; if (anObject instanceof String) { String aString = (String)anObject; if (coder() == aString.coder()) return Arrays.equals(value, aString.value); } } Sent from my iPhone > On Dec 6, 2018, at 10:56 PM, Stuart Marks wrote: > >>

Re: RFR 8214971 : Replace use of string.equals("") with isEmpty()

2018-12-06 Thread Roger Riggs
Hi, I'm pretty sure, it is assumed that the JVM compiler will optimize this code and produce an optimal result.  Lots of perf work went into the string size optimizations. Also possible is to compare the value.length values before dispatching to Latin1 vs UTF16. For unequal length strings,

Re: RFR 8214971 : Replace use of string.equals("") with isEmpty()

2018-12-06 Thread Stuart Marks
On 12/6/18 2:42 PM, Claes Redestad wrote: I filed this bug after seeing it in startup profiles, where isEmpty() avoids an instanceof and four(!) method calls, so getting rid of a few of these has a measurable impact on startup. It seemed prudent to just replace it all while we're at it.

Re: RFR 8214971 : Replace use of string.equals("") with isEmpty()

2018-12-06 Thread Lance Andersen
+1 > On Dec 6, 2018, at 6:03 PM, Roger Riggs wrote: > > I missed reverting other Apache source files that should be unchanged. > > Webrev: > http://cr.openjdk.java.net/~rriggs/webrev-string-isempty-8214971-3/ > > Thanks, Roger > > > On 12/6/18 5:37 PM, Roger Riggs wrote: >> Hi Claes, >> >>

Re: RFR 8214971 : Replace use of string.equals("") with isEmpty()

2018-12-06 Thread Claes Redestad
On 2018-12-07 00:03, Roger Riggs wrote: Webrev: http://cr.openjdk.java.net/~rriggs/webrev-string-isempty-8214971-3/ Looks good! /Claes

Re: RFR 8214971 : Replace use of string.equals("") with isEmpty()

2018-12-06 Thread Roger Riggs
I missed reverting other Apache source files that should be unchanged. Webrev: http://cr.openjdk.java.net/~rriggs/webrev-string-isempty-8214971-3/ Thanks, Roger On 12/6/18 5:37 PM, Roger Riggs wrote: Hi Claes, Thanks for the reminder about xalan sources. Updated to revert changes to xalan.

Re: RFR 8214971 : Replace use of string.equals("") with isEmpty()

2018-12-06 Thread Roger Riggs
Hi Claes, Thanks for the reminder about xalan sources. Updated to revert changes to xalan. Webrev: http://cr.openjdk.java.net/~rriggs/webrev-string-isempty-8214971-2/ Thanks, Roger On 12/6/18 4:48 PM, Claes Redestad wrote: Should changes to various com.sun.org.apache.xalan classes in

Re: RFR 8214971 : Replace use of string.equals("") with isEmpty()

2018-12-06 Thread Claes Redestad
I filed this bug after seeing it in startup profiles, where isEmpty() avoids an instanceof and four(!) method calls, so getting rid of a few of these has a measurable impact on startup. It seemed prudent to just replace it all while we're at it. C2 should be able to optimize equals("") to the

Re: RFR 8214971 : Replace use of string.equals("") with isEmpty()

2018-12-06 Thread Joseph D. Darcy
On 12/6/2018 1:08 PM, Pavel Rappo wrote: Roger, changes look good. On a side note, it's impressive how many cases we have when we check for string not being null and empty. We should have had something for that *internally* in the JDK. Or perhaps that should be a utility method on String or

Re: RFR 8214971 : Replace use of string.equals("") with isEmpty()

2018-12-06 Thread Roger Riggs
Hi Jim, Yes, it is likely that the compiler gets to the same optimization. But we save a little bit too by not making the compiler work so hard. And it helps during startup before the compiler kicks in. IntelliJ did the hard work and a full CI build/test is in progress. And isEmpty reads

Re: RFR 8214971 : Replace use of string.equals("") with isEmpty()

2018-12-06 Thread Claes Redestad
Should changes to various com.sun.org.apache.xalan classes in java.xml be deferred to upstream? Otherwise looks good to me! /Claes On 2018-12-06 21:04, Roger Riggs wroe te: Please review changing string.equals("") to string.isEmpty(). isEmpty is preferred, performs better and is easier to

Re: RFR 8214971 : Replace use of string.equals("") with isEmpty()

2018-12-06 Thread Pavel Rappo
Roger, changes look good. On a side note, it's impressive how many cases we have when we check for string not being null and empty. We should have had something for that *internally* in the JDK. And it's a pity that `String.trim().isEmpty()` not equivalent to `String.isBlank`. Seems to be a

Re: RFR 8214971 : Replace use of string.equals("") with isEmpty()

2018-12-06 Thread Daniel Fuchs
Hi Roger, The changes look good. best regards, -- daniel On 06/12/18 20:04, Roger Riggs wrote: Please review changing string.equals("") to string.isEmpty(). isEmpty is preferred, performs better and is easier to optimize. The change is a literal substitution in all files and only in these

Re: RFR 8214971 : Replace use of string.equals("") with isEmpty()

2018-12-06 Thread Lance Andersen
HI Roger, Changes seem good > On Dec 6, 2018, at 3:04 PM, Roger Riggs wrote: > > Please review changing string.equals("") to string.isEmpty(). > isEmpty is preferred, performs better and is easier to optimize. > > The change is a literal substitution in all files and only in these modules: >

Re: RFR 8214971 : Replace use of string.equals("") with isEmpty()

2018-12-06 Thread Pavel Rappo
> On 6 Dec 2018, at 20:27, Jim Laskey wrote: > > I assume you automated this change, might be worthwhile to automate a > verification (compare the -+ pairs.) Eyeballing the patch it seems complete, > one comment changed as well. > > Question: Is it probably that vm optimizes .equals(“”) to

Re: RFR 8214971 : Replace use of string.equals("") with isEmpty()

2018-12-06 Thread Jim Laskey
I assume you automated this change, might be worthwhile to automate a verification (compare the -+ pairs.) Eyeballing the patch it seems complete, one comment changed as well. Question: Is it probably that vm optimizes .equals(“”) to .isEmpty() and there is no net win, ie., more of an esthetic

RFR 8214971 : Replace use of string.equals("") with isEmpty()

2018-12-06 Thread Roger Riggs
Please review changing string.equals("") to string.isEmpty(). isEmpty is preferred, performs better and is easier to optimize. The change is a literal substitution in all files and only in these modules: java.base java.logging java.management java.management.rmi java.naming