Re: RFR: 8076549: Update JAX-WS RI integration to latest version (2.2.11-b150402.1412)
One Question: Look to these classes: MIMEPart MIMEMessage why do not implement AutoClosable instead Closable? Other suggestions: On class MIMEMessage, you can use diamond resource. private final List partsList = new ArrayList<>(); private final Map partsMap = new HashMap<>(); on ContextFinder class try(final InputStream resourceStream = (classLoader == null) ? ClassLoader.getSystemResourceAsStream(resource) : classLoader.getResourceAsStream(resource)) { }catch (IOException e) { throw new JAXBException(e); } on ServiceLoaderUtil class: static String propertyFileLookup(final String configFullPath, final String factoryId) throws IOException { Path path = Paths.get(configFullPath); if (Files.exists(path)) { Properties props = new Properties(); try(InputStream stream = Files.newInputStream(path)) { props.load(stream); return props.getProperty(factoryId); } } return null; } On Fri, Apr 10, 2015 at 7:09 AM, Aleksej Efimov wrote: > Hi Joe, > > Yes, the extensive testing took place before syncing the standalone > implementation to JDK: JCK, sets of jaxws/b unit tests, JPRT testing. > > Thank you for your comments and suggestions - we'll try to address them > and integrate during the next integration. About diamond operator in > MIMEMessage - not sure that we can put it there - AFAIK the standalone > JAXWS/B still supports JDK6 and we can't use "diamonds" there. > > With Best Regards, > Aleksej > > On 04/10/2015 09:50 AM, huizhe wang wrote: > >> Hi Aleksej, >> >> I assume the JAX-WS/JAXB standalone releases are well tested for this >> integration, esp. the service finder code. >> >> I see a great number of "<>" to "<>" changes that was suggested by >> Alan in the last integration. Besides that, you may consider removing , >> using {@literal @} to replace @, and the diamond operator in new >> expression in MIMEMessage. Also, new StringBuilder().append("META- >> INF/services/").append(jaxbContextFQCN).toString() isn't any better than >> "META-INF/services/"+jaxbContextFQCN since they'll be compiled into the >> same. >> >> None of the above should prevent you from pushing your changes. >> >> Cheers, >> Joe >> >> On 4/8/2015 1:57 PM, Aleksej Efimov wrote: >> >>> Hi, >>> Can I kindly ask for a review of this JAX-WS update? >>> >>> With Best Regards, >>> Aleksej >>> >>> On 04/03/2015 06:20 PM, Aleksej Efimov wrote: >>> >>>> Hello, >>>> >>>> Can I have a review for a JDK9 bulk update of JAX-B/WS from upstream >>>> projects. >>>> Webrev: >>>> More details in issue description: https://bugs.openjdk.java.net/ >>>> browse/JDK-8076549 >>>> >>>> Thank you, >>>> Aleksej >>>> >>> >>> >> > -- Otávio Gonçalves de Santana blog: http://otaviosantana.blogspot.com.br/ twitter: http://twitter.com/otaviojava site: *http://about.me/otaviojava <http://about.me/otaviojava>*
Re: Using StringBuilder instead StringBuffer[JAXP]
On Tue, Dec 23, 2014 at 7:46 AM, Otávio Gonçalves de Santana < otavioj...@java.net> wrote: > > *Motivation:* StringBuffer is synchronized while StringBuilder is not > which makes StringBuilder faster than StringBuffer[1]. The strategy was > removed the StringBuffer when it is not necessary. > > > WebRev: > https://dl.dropboxusercontent.com/u/16109193/open_jdk/jaxp/buffer2builder/index.html > > > [1] > > @State(Scope.Thread) > @OutputTimeUnit(TimeUnit.SECONDS) > public class StringBufferBenchmark { > > > private List texts; > @Param("1000") > private int param; > > @Setup > public void setup() { > texts = new LinkedList<>(); > Random random = new Random(); > for (int index = 0; index < param; index++) { > char a = (char) random.nextInt(); > texts.add(String.valueOf(a)); > } > } > > @GenerateMicroBenchmark > public void stringBuffer(BlackHole bh) { > StringBuffer sb = new StringBuffer(); > texts.stream().forEach(sb::append); > bh.consume(sb.toString()); > } > > @GenerateMicroBenchmark > public void stringBuilder(BlackHole bh) { > StringBuilder sb = new StringBuilder(); > texts.stream().forEach(sb::append); > bh.consume(sb.toString()); > } > } > > > java -jar target/microbenchmarks.jar ".*StringBufferBenchmark*." -wi 20 -i > 20 -f 1 > > Benchmark(param) Mode Samples > Mean Mean errorUnits > m.StringBufferBenchmark.stringBuffer 1000 thrpt20 > 3.2080.406ops/s > m.StringBufferBenchmark.stringBuilder 1000 thrpt20 > 4.795 0.037 ops/s > -- > > Otávio Gonçalves de Santana > > twitter: http://twitter.com/otaviojava > site: *http://about.me/otaviojava <http://about.me/otaviojava>* > 55 (11) 98255-3513 > -- Otávio Gonçalves de Santana blog: http://otaviosantana.blogspot.com.br/ twitter: http://twitter.com/otaviojava site: *http://about.me/otaviojava <http://about.me/otaviojava>* 55 (11) 98255-3513
Re: inefficient indexof when String has one length
Thank you. My email: otavioj...@java.net On Sun, Jan 25, 2015 at 8:47 PM, Claes Redestad wrote: > > On 2015-01-25 23:30, Otávio Gonçalves de Santana wrote: > >> Can anyone help me as sponsor? >> > > Sure, why not. > > I'll remove the escaped double-quote as per Paul's request and run it > through a > quick sanity test. Which e-mail do you want to get credited? > > /Claes > -- Otávio Gonçalves de Santana blog: http://otaviosantana.blogspot.com.br/ twitter: http://twitter.com/otaviojava site: *http://about.me/otaviojava <http://about.me/otaviojava>* 55 (11) 98255-3513
Re: inefficient indexof when String has one length
Can anyone help me as sponsor? On May 27, 2014 2:17 PM, "Otávio Gonçalves de Santana" < otaviopolianasant...@gmail.com> wrote: > Can anyone help me as sponsor? > On May 12, 2014 1:57 PM, "Paul Sandoz" wrote: > >> On Apr 26, 2014, at 12:56 PM, Otávio Gonçalves de Santana < >> otavioj...@java.net> wrote: >> > When a String has length just one, could be replaced by equivalent >> > character literals, gaining some performance enhancement. >> > >> > I found 107 changes. >> > >> >> This looks good to me, just one small issue: >> >> --- >> a/src/share/classes/javax/security/auth/PrivateCredentialPermission.java >> Wed Apr 23 11:35:40 2014 -0700 >> +++ >> b/src/share/classes/javax/security/auth/PrivateCredentialPermission.java >> Sat Apr 26 07:31:04 2014 -0300 >> @@ -495,7 +495,7 @@ >> >> // perform new initialization from the permission name >> >> -if (getName().indexOf(" ") == -1 && getName().indexOf("\"") == >> -1) { >> +if (getName().indexOf(' ') == -1 && getName().indexOf('\"') == >> -1) { >> >> You no longer need to escape the double quote. >> >> Can someone else sponsor this? unfortunately i do not have the time at >> the moment. >> >> Paul. >> >
IndexOf with Char instead of String
These String literals may be replaced by equivalent character literals[1], gaining some performance enhancement. Webrev: https://dl.dropboxusercontent.com/u/16109193/open_jdk/jdk/index_of_character/index.html [1] @State(Scope.Thread) @OutputTimeUnit(TimeUnit.SECONDS) public class IndexOfBenchmark { private static final String WORDS = "I love java Language 8 because has Lambda, Stream and MetaSpace"; @Param("1") private int param; @GenerateMicroBenchmark public void indexOfString(BlackHole bh) { for (int i = 0; i <= param; i++) { int index = WORDS.indexOf(","); bh.consume(index); } } @GenerateMicroBenchmark public void indexOfChar(BlackHole bh) { for (int i = 0; i <= param; i++) { int index = WORDS.indexOf(','); bh.consume(index); } } } Benchmark (param) Mode Samples Mean Mean errorUnits m.IndexOfBenchmark.indexOfChar1 thrpt10 5579.120 114.179ops/s m.IndexOfBenchmark.indexOfString 1 thrpt 10 4562.178 46.751ops/s -- Otávio Gonçalves de Santana blog: http://otaviosantana.blogspot.com.br/ twitter: http://twitter.com/otaviojava site: *http://about.me/otaviojava <http://about.me/otaviojava>* 55 (11) 98255-3513 # HG changeset patch # User Otavio Santana # Date 1421101042 7200 # Mon Jan 12 20:17:22 2015 -0200 # Node ID a30b25a498f51a6de42a278c27612817925ff941 # Parent c06b6d58e6a9c10cea9f0b8946846c3de4f59feb uses indexOf with Character indexOf String diff --git a/src/java.desktop/share/classes/com/sun/java/swing/plaf/gtk/Metacity.java b/src/java.desktop/share/classes/com/sun/java/swing/plaf/gtk/Metacity.java --- a/src/java.desktop/share/classes/com/sun/java/swing/plaf/gtk/Metacity.java +++ b/src/java.desktop/share/classes/com/sun/java/swing/plaf/gtk/Metacity.java @@ -547,7 +547,7 @@ i = strLowerCase.indexOf("", i); if (i > 0) { i += "".length(); -int i2 = str.indexOf("<", i); +int i2 = str.indexOf('<', i); return str.substring(i, i2); } } diff --git a/src/java.base/share/classes/com/sun/java/util/jar/pack/ConstantPool.java b/src/java.base/share/classes/com/sun/java/util/jar/pack/ConstantPool.java --- a/src/java.base/share/classes/com/sun/java/util/jar/pack/ConstantPool.java +++ b/src/java.base/share/classes/com/sun/java/util/jar/pack/ConstantPool.java @@ -512,7 +512,7 @@ } static String qualifiedStringValue(String s1, String s234) { // Qualification by dot must decompose uniquely. Second string might already be qualified. -assert(s1.indexOf(".") < 0); +assert(s1.indexOf('.') < 0); return s1+"."+s234; } diff --git a/src/java.corba/share/classes/com/sun/jndi/cosnaming/CorbanameUrl.java b/src/java.corba/share/classes/com/sun/jndi/cosnaming/CorbanameUrl.java --- a/src/java.corba/share/classes/com/sun/jndi/cosnaming/CorbanameUrl.java +++ b/src/java.corba/share/classes/com/sun/jndi/cosnaming/CorbanameUrl.java @@ -102,7 +102,7 @@ } location = url.substring(addrStart, addrEnd); -int keyStart = location.indexOf("/"); +int keyStart = location.indexOf('/'); if (keyStart >= 0) { // Has key string if (keyStart == (location.length() -1)) { diff --git a/src/jdk.naming.rmi/share/classes/com/sun/jndi/rmi/registry/RegistryContext.java b/src/jdk.naming.rmi/share/classes/com/sun/jndi/rmi/registry/RegistryContext.java --- a/src/jdk.naming.rmi/share/classes/com/sun/jndi/rmi/registry/RegistryContext.java +++ b/src/jdk.naming.rmi/share/classes/com/sun/jndi/rmi/registry/RegistryContext.java @@ -336,7 +336,7 @@ String url = "rmi://"; // Enclose IPv6 literal address in '[' and ']' -url = (host.indexOf(":") > -1) ? url + "[" + host + "]" : +url = (host.indexOf(':') > -1) ? url + "[" + host + "]" : url + host; if (port > 0) { url += ":" + Integer.toString(port); diff --git a/src/java.naming/share/classes/com/sun/jndi/toolkit/url/GenericURLContext.java b/src/java.naming/share/classes/com/sun/jndi/toolkit/url/GenericURLContext.java --- a/src/java.naming/share/classes/com/sun/jndi/toolkit/url/GenericURLContext.java +++ b/src/java.naming/share/classes/com/sun/jndi/toolkit/url/GenericURLContext.java @@ -149,7 +149,7 @@ * foo:rest/of/namefoo:
New JEP: Adding JSR 354 Money & Currency API
Hi everyone, Could any commiter help us in this JSR to JEP? If there is any question, please tell me. - Forwarded message -- From: Date: 2014-11-05 20:16 GMT+01:00 Subject: Re: New JEP: Adding JSR 354 Money & Currency API To: Anatole Tresch Cc: jep-sub...@openjdk.java.net 2014/10/30 8:11 -0700, atsti...@gmail.com: > Dear all > find attached out JEP for adding JSR 354 Money & Currency to the Java > platform version 9. > In case of any questions, just drop me a mail ;) Thanks for your submission, but we no longer accept JEP submissions via e-mail. We're transitioning to the JEP 2.0 Process [1], in which JEPs are created and maintained as a custom issue type in the JDK Bug System (JBS) [2]. The JEP Process is open to OpenJDK Contributors; to become one you'll need to submit an Oracle Contributor Agreement [3]. Since you're not already an OpenJDK Committer you'll need to find someone who is and is willing to draft and submit this JEP on your behalf. - Mark [1] http://cr.openjdk.java.net/~mr/jep/jep-2.0-02.html [2] https://bugs.openjdk.java.net/ [3] http://openjdk.java.net/legal/ -- Otávio Gonçalves de Santana twitter: http://twitter.com/otaviojava site: *http://about.me/otaviojava <http://about.me/otaviojava>* 55 (11) 98255-3513
Re: Review request: JDK-8055723 Replace concat String to append in StringBuilder parameters
Ok, you're right. On Wed, Nov 12, 2014 at 11:19 PM, Wang Weijun wrote: > I hope we can restrict the code change to what the bug description is > about. IMHO this bug should only include cleanup and introduce no obvious > behavior change. > > Any other fix can go to another bug. > > --Max > > > On Nov 13, 2014, at 08:57, Otávio Gonçalves de Santana < > otavioj...@java.net> wrote: > > > > But this class is an Exception, doesn't make sense an exception get > another > > Exception. > > IMHO: I prefer this way > > > > On Wed, Nov 12, 2014 at 8:36 AM, Ulf Zibis wrote: > > > >> Hi Otávio, > >> I now think you could replace > >> if (!expected.isEmpty()) > >> with > >> assert !expected.isEmpty(); > >> > >> If expected ever would be empty, the only thing which happens is, that a > >> "'" is missing in a message which anyway doesn't make sense without > >> arguments. > >> > >> -Ulf > >> > >> > .. -- Otávio Gonçalves de Santana blog: http://otaviosantana.blogspot.com.br/ twitter: http://twitter.com/otaviojava site: *http://about.me/otaviojava <http://about.me/otaviojava>* 55 (11) 98255-3513
Re: Review request: JDK-8055723 Replace concat String to append in StringBuilder parameters
But this class is an Exception, doesn't make sense an exception get another Exception. IMHO: I prefer this way On Wed, Nov 12, 2014 at 8:36 AM, Ulf Zibis wrote: > Hi Otávio, > I now think you could replace > if (!expected.isEmpty()) > with > assert !expected.isEmpty(); > > If expected ever would be empty, the only thing which happens is, that a > "'" is missing in a message which anyway doesn't make sense without > arguments. > > -Ulf > > > > Am 12.11.2014 um 08:19 schrieb Otávio Gonçalves de Santana: > >> Thank you Ulf. >> http://cr.openjdk.java.net/~weijun/8055723/webrev.01/ < >> http://cr.openjdk.java.net/%7Eweijun/8055723/webrev.01/> >> >> >> On Sat, Nov 8, 2014 at 3:46 PM, Ulf Zibis > ulf.zi...@cosoco.de>> wrote: >> >> Hi Otávio, >> in sun/tools/jstat/SyntaxException.java I see a possible enhencement >> (maybe applies to other >> places too): >> >> 65 public SyntaxException(int lineno, Set expected, >> Token found) { >> 66 StringBuilder msg = new StringBuilder(A + B * >> expected.size()); >> 67 >> 68 msg.append("Syntax error at line >> ").append(lineno).append(": Expected one of \'"); >> 69 >> 71 for (String keyWord : expected) { >> 72 msg.append(keyWord).append('|'); >> 73 } >> 74 // if (!expected.isEmpty()) // only needed if expected >> may be empty. >> 75 msg.setLength(msg.length() - 1); >> 76 >> 81 message = msg.append("\', Found >> ").append(found.toMessage()).toString(); >> 83 } >> >> * Additionally at many places you could similarly introduce the >> foreach syntax. >> >> -Ulf >> >> >> Am 02.11.2014 um 15:45 schrieb Otávio Gonçalves de Santana: >> >> Could another reviewer look these codes, please. >> http://cr.openjdk.java.net/~weijun/8055723/webrev.00/ >> <http://cr.openjdk.java.net/%7Eweijun/8055723/webrev.00/> >> <http://cr.openjdk.java.net/%7Eweijun/8055723/webrev.00/> >> >> On Fri, Oct 24, 2014 at 3:25 AM, Otávio Gonçalves de Santana < >> otavioj...@java.net >> <mailto:otavioj...@java.net> <mailto:otavioj...@java.net > otavioj...@java.net>>> wrote: >> >> Thank you Ulf. >> I removed the fix in toString method and in debug classes: >> http://cr.openjdk.java.net/~weijun/8055723/webrev.00/ >> <http://cr.openjdk.java.net/%7Eweijun/8055723/webrev.00/> >> <http://cr.openjdk.java.net/%7Eweijun/8055723/webrev.00/> >> >> On Mon, Oct 20, 2014 at 10:26 PM, Ulf Zibis < >> ulf.zi...@cosoco.de >> <mailto:ulf.zi...@cosoco.de> <mailto:ulf.zi...@cosoco.de > ulf.zi...@cosoco.de>>> >> wrote: >> >> >> Am 21.10.2014 um 01:02 schrieb Otávio Gonçalves de >> Santana: >> >> BUGURL: https://bugs.openjdk.java.net/ >> browse/JDK-8055723 >> >> >> WEBREV: http://cr.openjdk.java.net/~ >> weijun/8055723/client/webrev.02/ >> <http://cr.openjdk.java.net/%7Eweijun/8055723/client/webrev.02/> >> <http://cr.openjdk.java.net/%7Eweijun/8055723/client/ >> webrev.02/> >> WEBREV: http://cr.openjdk.java.net/~ >> weijun/8055723/core/webrev.03/ >> <http://cr.openjdk.java.net/%7Eweijun/8055723/core/webrev.03/> >> <http://cr.openjdk.java.net/% >> 7Eweijun/8055723/core/webrev.03/> >> >> >> I did not look through all sources. >> In Scanner.java I discovered: >> 1307 sb.append("[delimiters="). >> append(delimPattern).append(']'); >> 1308 sb.append("[position="). >> append(position).append(']'); >> ... >> Maybe better: >> 1307 sb.append("[delimiters=").append(delimPattern); >> 1308 sb.append("][position=").append(position); >> ... >> >> -Ulf >> >> >> >> >> -- Otávio Gonçalves de Santana >> >> blog: http://otaviosantana.blogspot.com.br/ >> twitter: http://twitter.com/otaviojava >> site: _http://about.me/otaviojava_ >> 55 (11) 98255-3513 >> >> >> >> >> >> -- Otávio Gonçalves de Santana >> >> blog: http://otaviosantana.blogspot.com.br/ >> twitter: http://twitter.com/otaviojava >> site: _http://about.me/otaviojava_ >> 55 (11) 98255-3513 >> >> >> >> >> >> >> -- >> Otávio Gonçalves de Santana >> >> blog: http://otaviosantana.blogspot.com.br/ >> twitter: http://twitter.com/otaviojava >> site: _http://about.me/otaviojava_ >> 55 (11) 98255-3513 >> > > -- Otávio Gonçalves de Santana blog: http://otaviosantana.blogspot.com.br/ twitter: http://twitter.com/otaviojava site: *http://about.me/otaviojava <http://about.me/otaviojava>* 55 (11) 98255-3513
Re: Review request: JDK-8055723 Replace concat String to append in StringBuilder parameters
Thank you Ulf. http://cr.openjdk.java.net/~weijun/8055723/webrev.01/ On Sat, Nov 8, 2014 at 3:46 PM, Ulf Zibis wrote: > Hi Otávio, > in sun/tools/jstat/SyntaxException.java I see a possible enhencement > (maybe applies to other places too): > > 65 public SyntaxException(int lineno, Set expected, Token > found) { > 66 StringBuilder msg = new StringBuilder(A + B * > expected.size()); > 67 > 68 msg.append("Syntax error at line ").append(lineno).append(": > Expected one of \'"); > 69 > 71 for (String keyWord : expected) { > 72 msg.append(keyWord).append('|'); > 73 } > 74 // if (!expected.isEmpty()) // only needed if expected may be > empty. > 75 msg.setLength(msg.length() - 1); > 76 > 81 message = msg.append("\', Found ").append(found.toMessage()). > toString(); > 83 } > > * Additionally at many places you could similarly introduce the > foreach syntax. > > -Ulf > > > Am 02.11.2014 um 15:45 schrieb Otávio Gonçalves de Santana: > >> Could another reviewer look these codes, please. >> http://cr.openjdk.java.net/~weijun/8055723/webrev.00/ < >> http://cr.openjdk.java.net/%7Eweijun/8055723/webrev.00/> >> >> On Fri, Oct 24, 2014 at 3:25 AM, Otávio Gonçalves de Santana < >> otavioj...@java.net <mailto:otavioj...@java.net>> wrote: >> >> Thank you Ulf. >> I removed the fix in toString method and in debug classes: >> http://cr.openjdk.java.net/~weijun/8055723/webrev.00/ >> <http://cr.openjdk.java.net/%7Eweijun/8055723/webrev.00/> >> >> On Mon, Oct 20, 2014 at 10:26 PM, Ulf Zibis > <mailto:ulf.zi...@cosoco.de>> >> wrote: >> >> >> Am 21.10.2014 um 01:02 schrieb Otávio Gonçalves de Santana: >> >> BUGURL: https://bugs.openjdk.java.net/browse/JDK-8055723 >> >> >> WEBREV: http://cr.openjdk.java.net/~ >> weijun/8055723/client/webrev.02/ >> <http://cr.openjdk.java.net/%7Eweijun/8055723/client/ >> webrev.02/> >> WEBREV: http://cr.openjdk.java.net/~ >> weijun/8055723/core/webrev.03/ >> <http://cr.openjdk.java.net/%7Eweijun/8055723/core/webrev.03/ >> > >> >> >> I did not look through all sources. >> In Scanner.java I discovered: >> 1307 sb.append("[delimiters=").append(delimPattern).append(']'); >> 1308 sb.append("[position=").append(position).append(']'); >> ... >> Maybe better: >> 1307 sb.append("[delimiters=").append(delimPattern); >> 1308 sb.append("][position=").append(position); >> ... >> >> -Ulf >> >> >> >> >> -- Otávio Gonçalves de Santana >> >> blog: http://otaviosantana.blogspot.com.br/ >> twitter: http://twitter.com/otaviojava >> site: _http://about.me/otaviojava_ >> 55 (11) 98255-3513 >> >> >> >> >> -- >> Otávio Gonçalves de Santana >> >> blog: http://otaviosantana.blogspot.com.br/ >> twitter: http://twitter.com/otaviojava >> site: _http://about.me/otaviojava_ >> 55 (11) 98255-3513 >> > > -- Otávio Gonçalves de Santana blog: http://otaviosantana.blogspot.com.br/ twitter: http://twitter.com/otaviojava site: *http://about.me/otaviojava <http://about.me/otaviojava>* 55 (11) 98255-3513
Re: Review request: JDK-8055723 Replace concat String to append in StringBuilder parameters
Could another reviewer look these codes, please. http://cr.openjdk.java.net/~weijun/8055723/webrev.00/ On Fri, Oct 24, 2014 at 3:25 AM, Otávio Gonçalves de Santana < otavioj...@java.net> wrote: > Thank you Ulf. > I removed the fix in toString method and in debug classes: > http://cr.openjdk.java.net/~weijun/8055723/webrev.00/ > > On Mon, Oct 20, 2014 at 10:26 PM, Ulf Zibis wrote: > >> >> Am 21.10.2014 um 01:02 schrieb Otávio Gonçalves de Santana: >> >>> BUGURL: https://bugs.openjdk.java.net/browse/JDK-8055723 >>> >>> >>> WEBREV: http://cr.openjdk.java.net/~weijun/8055723/client/webrev.02/ >>> WEBREV: http://cr.openjdk.java.net/~weijun/8055723/core/webrev.03/ >>> >> >> I did not look through all sources. >> In Scanner.java I discovered: >> 1307 sb.append("[delimiters=").append(delimPattern).append(']'); >> 1308 sb.append("[position=").append(position).append(']'); >> ... >> Maybe better: >> 1307 sb.append("[delimiters=").append(delimPattern); >> 1308 sb.append("][position=").append(position); >> ... >> >> -Ulf >> >> > > > -- > Otávio Gonçalves de Santana > > blog: http://otaviosantana.blogspot.com.br/ > twitter: http://twitter.com/otaviojava > site: *http://about.me/otaviojava <http://about.me/otaviojava>* > 55 (11) 98255-3513 > -- Otávio Gonçalves de Santana blog: http://otaviosantana.blogspot.com.br/ twitter: http://twitter.com/otaviojava site: *http://about.me/otaviojava <http://about.me/otaviojava>* 55 (11) 98255-3513
Re: Review request: JDK-8055723 Replace concat String to append in StringBuilder parameters
Thank you Ulf. I removed the fix in toString method and in debug classes: http://cr.openjdk.java.net/~weijun/8055723/webrev.00/ On Mon, Oct 20, 2014 at 10:26 PM, Ulf Zibis wrote: > > Am 21.10.2014 um 01:02 schrieb Otávio Gonçalves de Santana: > >> BUGURL: https://bugs.openjdk.java.net/browse/JDK-8055723 >> >> >> WEBREV: http://cr.openjdk.java.net/~weijun/8055723/client/webrev.02/ >> WEBREV: http://cr.openjdk.java.net/~weijun/8055723/core/webrev.03/ >> > > I did not look through all sources. > In Scanner.java I discovered: > 1307 sb.append("[delimiters=").append(delimPattern).append(']'); > 1308 sb.append("[position=").append(position).append(']'); > ... > Maybe better: > 1307 sb.append("[delimiters=").append(delimPattern); > 1308 sb.append("][position=").append(position); > ... > > -Ulf > > -- Otávio Gonçalves de Santana blog: http://otaviosantana.blogspot.com.br/ twitter: http://twitter.com/otaviojava site: *http://about.me/otaviojava <http://about.me/otaviojava>* 55 (11) 98255-3513
Review request: JDK-8055723 Replace concat String to append in StringBuilder parameters
BUGURL: https://bugs.openjdk.java.net/browse/JDK-8055723 WEBREV: http://cr.openjdk.java.net/~weijun/8055723/client/webrev.02/ WEBREV: http://cr.openjdk.java.net/~weijun/8055723/core/webrev.03/ -- Otávio Gonçalves de Santana blog: http://otaviosantana.blogspot.com.br/ twitter: http://twitter.com/otaviojava 55 (11) 98255-3513
Re: JEP 198: Light-Weight JSON API
Hi everyone. Is there any reason to not implement the JSR that already exist and that was born? https://jcp.org/en/jsr/detail?id=367 https://jcp.org/en/jsr/detail?id=353 Which especific cases what the OpenJDK need and this JSR don't care? Why just work together with these JSRs and each one has your implementation? For example, one to OpenJDK and another to JavaEE, this way each one implements according your necessity. The question is: it's really make sense have two APIs with similar goal? It would great to the Java developer should to know two API to do the same thing? obs: Sorry to question a lot, I just would like know more to be more useful. On Thu, Jul 31, 2014 at 1:28 AM, Mario Torre wrote: > I never gave a +1 with more enthusiasm! :) > > Cheers, > Mario > Il 31/lug/2014 03:27 "Wang Weijun" ha scritto: > > > > > On Jul 31, 2014, at 8:35, Remi Forax wrote: > > > > > > > > On 07/25/2014 04:45 PM, mark.reinh...@oracle.com wrote: > > >> New JEP Candidate: http://openjdk.java.net/jeps/198 > > >> > > >> - Mark > > > > > > Hi Mark, Hi Mike, > > > Implementing a json API was one of the use case I've used during the > > development of the lambdas, > > > so maybe you are interested by this gist > > > https://gist.github.com/forax/81a56cf2684bfa2e46ec > > > > I am reading "[ \"foo\", \"bar\" ]" and feel we need a JEP for new styles > > of literal strings. Long long ago there was a proposal for multi-line raw > > strings. Still alive? > > > > Thanks > > Max > > > > > > > -- Otávio Gonçalves de Santana blog: http://otaviosantana.blogspot.com.br/ twitter: http://twitter.com/otaviojava site: *http://about.me/otaviojava <http://about.me/otaviojava>* 55 (11) 98255-3513
Re: Replace uses of StringBuffer with StringBuilder[JAXP]
I haven't acess to cr.openjdk.java.net yet. But I uploaded another way. https://dl.dropboxusercontent.com/u/16109193/open_jdk/jaxp/string_buffer_2_string_builder/index.html On Fri, Sep 12, 2014 at 7:02 AM, Alan Bateman wrote: > On 12/09/2014 10:40, Otávio Gonçalves de Santana wrote: > >> @Alan >> Yes, I would like help the jaxp in openjdk project. >> But I thought that were different projects, but how are the same. >> I believe will the same process. >> So I will waiting to a sponsor. >> >> I understand it can be a bit confusing. In summary, the JAXP project on > java.net is dead and the development is now in OpenJDK. > > I can't speak for Joe (Huizhe) but I think part of this point was that he > didn't want to have the Xerces/Xalan code diverge too much from the > upstream Apache projects. If so then this shouldn't prevent doing clean-up > on the non-Apache code in the jaxp repository. Maybe you could trim back to > the changes and send them to someone that can upload them to > cr.openjdk.java.net for discussion. > > -Alan > > > -- Otávio Gonçalves de Santana blog: http://otaviosantana.blogspot.com.br/ twitter: http://twitter.com/otaviojava site: *http://about.me/otaviojava <http://about.me/otaviojava>* 55 (11) 98255-3513
Re: Replace uses of StringBuffer with StringBuilder[JAXP]
@Alan Yes, I would like help the jaxp in openjdk project. But I thought that were different projects, but how are the same. I believe will the same process. So I will waiting to a sponsor. @huizhe Yes, I see the code is a little deprecated, I will try improve it as I can. On Fri, Sep 12, 2014 at 5:05 AM, Alan Bateman wrote: > On 12/09/2014 05:57, huizhe wang wrote: > >> I see. So you're looking for a sponsor. Unfortunately, I personally don't >> have circles. It would be great if you could find a sponsor. >> >> JAXP sources came from Apache that still supports JDK 1.4. A very large >> amount of code therefore are obsolete with regards to the source level. But >> it's not currently a high priority. We can clean them up (along with many >> improvement) when we touch those classes for bug fixes or update relevant >> component. >> >> -Joe >> > I assume Otávio is looking to contribute the changes to OpenJDK rather > than the defunct JAXP project. But perhaps your concern is changing the > Xerces and Xalan code so that it diverges from the upstream sources? I > assume there isn't any issue with switching the JAXP API and other > non-Apache code to use StringBuilder. > > -Alan. > -- Otávio Gonçalves de Santana blog: http://otaviosantana.blogspot.com.br/ twitter: http://twitter.com/otaviojava site: *http://about.me/otaviojava <http://about.me/otaviojava>* 55 (11) 98255-3513
Re: Replace uses of StringBuffer with StringBuilder[JAXP]
Hi Huizhe. Done. creates new remote head d053915e3689! On Wed, Sep 10, 2014 at 7:13 PM, huizhe wang wrote: > Hi Otavio, > > Please let me know once you've submitted it. > > Best, > Joe > > > On 9/10/2014 10:40 AM, Otávio Gonçalves de Santana wrote: > > Hi Wang. > Thank you for this information. > I have the OCA > On Sep 10, 2014 2:11 PM, "huizhe wang" wrote: > >> Hi Otavio, >> >> I'm glad to know you're interested in contributing to the JAXP project. >> The JAXP standalone itself has reached end-of-life. We're now concentrating >> on JAXP in OpenJDK. The repo is here: >> http://hg.openjdk.java.net/jdk9/dev/jaxp >> >> If you are interested in contributing to OpenJDK/jaxp, please read 'How >> to contribute' and sign the OCA: >> http://openjdk.java.net/contribute/ >> >> Thanks, >> Joe >> >> On 9/9/2014 6:10 PM, Otávio Gonçalves de Santana wrote: >> >>> Similar to: https://bugs.openjdk.java.net/browse/JDK-8041679 >>> >>> But in JAXP project: >>> >>> >>> https://dl.dropboxusercontent.com/u/16109193/open_jdk/jax%E1%B9%95/string_buffer_2_string_builder.zip >>> >>> >> > -- Otávio Gonçalves de Santana blog: http://otaviosantana.blogspot.com.br/ twitter: http://twitter.com/otaviojava site: *http://about.me/otaviojava <http://about.me/otaviojava>* 55 (11) 98255-3513
Re: Replace uses of StringBuffer with StringBuilder[JAXP]
Hi Wang. Thank you for this information. I have the OCA On Sep 10, 2014 2:11 PM, "huizhe wang" wrote: > Hi Otavio, > > I'm glad to know you're interested in contributing to the JAXP project. > The JAXP standalone itself has reached end-of-life. We're now concentrating > on JAXP in OpenJDK. The repo is here: http://hg.openjdk.java.net/ > jdk9/dev/jaxp > > If you are interested in contributing to OpenJDK/jaxp, please read 'How to > contribute' and sign the OCA: > http://openjdk.java.net/contribute/ > > Thanks, > Joe > > On 9/9/2014 6:10 PM, Otávio Gonçalves de Santana wrote: > >> Similar to: https://bugs.openjdk.java.net/browse/JDK-8041679 >> >> But in JAXP project: >> >> https://dl.dropboxusercontent.com/u/16109193/open_jdk/jax% >> E1%B9%95/string_buffer_2_string_builder.zip >> >> >
Re: Replace concat String to append in StringBuilder parameters
I believe yes. Using the -XX:+OptimizeStringConcat: java -jar -XX:+OptimizeStringConcat target/microbenchmarks.jar ".*StringBuilderConcatBenchMark.*" -wi 10 -i 10 -f 1 The same thing happened: Benchmark Mode Samples Mean Mean errorUnits m.StringBuilderConcatBenchMark.stringBuilder thrpt10 6316489.783 211751.479ops/s m.StringBuilderConcatBenchMark.stringBuilderWithConcatthrpt10 3206244.21560752.652ops/s So, can you review these changes, please. https://bugs.openjdk.java.net/browse/JDK-8055723 http://cr.openjdk.java.net/~weijun/8055723/client/webrev.02/ http://cr.openjdk.java.net/~weijun/8055723/core/webrev.02/ http://cr.openjdk.java.net/~weijun/8055723/core/webrev.03/ On Fri, Aug 29, 2014 at 5:01 AM, Wang Weijun wrote: > So it's not that the optimization fails but there is no optimization on > them yet. > > I do see the .append("x") case will be easy to deal with, but it looks > like historically javac has not been a place to do many optimizations. It > mostly converts the java source to byte codes in a 1-to-1 mapping and let > VM do whatever it wants (to optimize). When you talked about compiling > multiple concatenation into using a single StringBuilder, it's more like > choosing the correct implementation rather than an optimization. > > I don't expect to see big change on this in the near future, so shall we > go on with the current enhancement? > > Thanks > Max > > On Aug 29, 2014, at 2:17, Ulf Zibis wrote: > > > I mean: > > It does not output byte code that only uses a single char array to > compose the entire String in question. > > With "optimization fails", I also mean, there is used an additional > "StringComposer" e.g. another StringBuilder or a StringJoiner in addition > to the 1st StringBuilder. > > > > -Ulf > > > > Am 27.08.2014 um 14:02 schrieb Pavel Rappo: > >> Could you please explain what you mean by "javac optimization fails" > here? > >> > >> -Pavel > >> > >> On 27 Aug 2014, at 10:41, Ulf Zibis wrote: > >> > >>> 4.) Now we see, that javac optimization fails again if StringBuilder, > concatenation, toString(), append(String), append(Collection) etc. and > StringJoiner use is mixed. > >> > > > > -- Otávio Gonçalves de Santana blog: http://otaviosantana.blogspot.com.br/ twitter: http://twitter.com/otaviojava site: *http://about.me/otaviojava <http://about.me/otaviojava>* 55 (11) 98255-3513
Re: Replace concat String to append in StringBuilder parameters
Could anyone help me as sponsor, please? On Tue, Aug 12, 2014 at 8:01 PM, Otávio Gonçalves de Santana < otavioj...@java.net> wrote: > Thank you Roger. > Done > > https://dl.dropboxusercontent.com/u/16109193/open_jdk/string_builder_concat_6.zip > > > On Tue, Aug 12, 2014 at 10:15 AM, roger riggs > wrote: > >> fyi, >> >> There's a Perl script normalizer.pl that detects/fixes most of the >> simple tab/white space issues. >> The script is in the /make/scripts/normalizer.pl >> >> Roger >> >> >> On 8/12/2014 3:48 AM, Andrej Golovnin wrote: >> >>> Hi Otávio, >>> >>> I think you should fix the indentation in a lot of classes. You use the >>> tab-character for the indentation. As far as I know we should use the >>> space >>> character for the indentation in the JDK sources (Oracle devs feel free >>> to >>> correct me if I'm wrong. And it would be really nice if the style guide >>> for >>> the source code would be a part of the JDK repository. So we don't need >>> to >>> search for it on the internet/wiki. Just clone the repository, read the >>> style guide and follow it. :-) ). Here is the not complete list of >>> classes >>> where you used the tab-character for the indentation: >>> >>> src/share/classes/com/sun/crypto/provider/OAEPParameters.java >>> src/share/classes/java/lang/management/MemoryUsage.java >>> src/share/classes/java/security/KeyStore.java >>> src/share/classes/java/security/PermissionCollection.java >>> src/share/classes/java/security/ProtectionDomain.java >>> src/share/classes/java/security/cert/CertPath.java >>> src/share/classes/java/security/cert/PKIXCertPathBuilderResult.java >>> src/share/classes/java/security/cert/PKIXParameters.java >>> src/share/classes/java/security/cert/PolicyQualifierInfo.java >>> src/share/classes/java/security/cert/TrustAnchor.java >>> src/share/classes/java/security/cert/X509CertSelector.java >>> src/share/classes/javax/crypto/CryptoPermission.java >>> src/share/classes/javax/management/relation/Role.java >>> >>> >>> In src/share/classes/com/sun/jmx/snmp/IPAcl/Parser.jj in the line 423 a >>> dot >>> is missed before append: >>> >>> 423 {jjtn000.name.append( '.')append(t.image); } >>> >>> Best regards, >>> Andrej Golovnin >>> >> >> > > > -- > Otávio Gonçalves de Santana > > blog: http://otaviosantana.blogspot.com.br/ > twitter: http://twitter.com/otaviojava > site: *http://about.me/otaviojava <http://about.me/otaviojava>* > 55 (11) 98255-3513 > -- Otávio Gonçalves de Santana blog: http://otaviosantana.blogspot.com.br/ twitter: http://twitter.com/otaviojava site: *http://about.me/otaviojava <http://about.me/otaviojava>* 55 (11) 98255-3513
Re: RFR: 8049892: Replace uses of 'new Integer()' with appropriate alternative across core classes
http://cr.openjdk.java.net/~prr/8049892.1/ On Fri, Jul 11, 2014 at 6:41 AM, Pavel Rappo wrote: > Hi Otavio, > > Other than things already spotted by Andrej, the change looks good to me. > Thank you for doing this. > > -Pavel > > On 11 Jul 2014, at 02:36, Otávio Gonçalves de Santana < > otaviopolianasant...@gmail.com> wrote: > > > https://bugs.openjdk.java.net/browse/JDK-8049892 > > http://cr.openjdk.java.net/~prr/8049892/ > > > > -- > > Cheers!. > > > > Otávio Gonçalves de Santana > > > > blog: http://otaviosantana.blogspot.com.br/ > > twitter: http://twitter.com/otaviojava > > site: *http://about.me/otaviojava <http://about.me/otaviojava>* > > 55 (11) 98255-3513 > > -- Atenciosamente. Otávio Gonçalves de Santana blog: http://otaviosantana.blogspot.com.br/ twitter: http://twitter.com/otaviojava site: http://www.otaviojava.com.br (11) 98255-3513
RFR: 8049892: Replace uses of 'new Integer()' with appropriate alternative across core classes
https://bugs.openjdk.java.net/browse/JDK-8049892 http://cr.openjdk.java.net/~prr/8049892/ -- Cheers!. Otávio Gonçalves de Santana blog: http://otaviosantana.blogspot.com.br/ twitter: http://twitter.com/otaviojava site: *http://about.me/otaviojava <http://about.me/otaviojava>* 55 (11) 98255-3513
Re: Character, Byte, Short valueOf instead of new instance
Thank you Remi. The long[1] also was included? [1]https://bugs.openjdk.java.net/browse/JDK-8048267 On Tue, Jul 1, 2014 at 7:28 PM, Remi Forax wrote: > > On 07/01/2014 11:01 PM, Andrej Golovnin wrote: > >> Hi Pavel, >> >> Thanks a lot! I've separated out all the changes from the >>> 'jdk.internal.org.objectweb.asm' package. So I'll update both threads >>> with new webrevs. >>> >>> http://cr.openjdk.java.net/~prappo/8048874/webrev.02 >>> >> Looks good to me. >> >> @Otávio: Could you please submit the ASM related changes to the ASM >> project [1]? Thanks! >> >> Best regards, >> Andrej Golovnin >> >> [1] http://asm.ow2.org/ >> > > Paul Sandoz had already sent the changes related to ASM. > I'm currently reviewing them. > > Rémi > > -- Atenciosamente. Otávio Gonçalves de Santana blog: http://otaviosantana.blogspot.com.br/ twitter: http://twitter.com/otaviojava site: http://www.otaviojava.com.br (11) 98255-3513
Re: Long valueOf instead of new Long
I found more two unnecessary valueOf. About Andrej, is it not possible add two people in "Contributed-by:" tag? diff -r d02b062bc827 src/share/classes/com/sun/tools/example/debug/tty/Commands.java --- a/src/share/classes/com/sun/tools/example/debug/tty/Commands.java Fri Jun 13 11:21:30 2014 -0700 +++ b/src/share/classes/com/sun/tools/example/debug/tty/Commands.java Fri Jun 27 20:06:28 2014 -0300 @@ -935,7 +935,7 @@ try { methodInfo = loc.sourceName() + MessageOutput.format("line number", - new Object [] {new Long(lineNumber)}); + new Object [] {lineNumber}); } catch (AbsentInformationException e) { methodInfo = MessageOutput.format("unknown"); } @@ -946,7 +946,7 @@ meth.declaringType().name(), meth.name(), methodInfo, - new Long(pc)}); + pc}); } else { MessageOutput.println("stack frame dump", new Object [] {new Integer(frameNumber + 1), On Fri, Jun 27, 2014 at 5:16 PM, Andrej Golovnin wrote: > Hi Pavel, > > I'm not sure what the style guide for the source code says, but > there is a space between the cast operator and the field name in > src/share/classes/com/sun/jmx/snmp/daemon/SnmpAdaptorServer.java (line > 881): > > @Override > public Long getSnmpOutGenErrs() { > -return new Long(snmpOutGenErrs); > +return (long) snmpOutGenErrs; > > } > > In all other changes there is no space after the cast operator. > > > > Also, I removed one useless creation of a Long object here: > > > > (line 191): > > > > > http://cr.openjdk.java.net/~prappo/8048267/webrev.01/src/share/classes/sun/security/krb5/internal/KerberosTime.java.sdiff.html > > > http://cr.openjdk.java.net/~prappo/8048267/webrev.02/src/share/classes/sun/security/krb5/internal/KerberosTime.java.sdiff.html > > And I have found one more :-) in KerberosTime.java: > > 252 public int getSeconds() { > 253 Long temp_long = kerberosTime / 1000L; > 254 return temp_long.intValue(); > 255 } > > This can be changed to: > > 252 public int getSeconds() { > 253 long temp_long = kerberosTime / 1000L; > 254 return (int) temp_long; > 255 } > > > > > > I wonder if we should leave a cast to int here: > > > > (line 383): > > > > > http://cr.openjdk.java.net/~prappo/8048267/webrev.01/src/share/classes/sun/management/snmp/jvminstr/JvmMemoryImpl.java.sdiff.html > > > http://cr.openjdk.java.net/~prappo/8048267/webrev.02/src/share/classes/sun/management/snmp/jvminstr/JvmMemoryImpl.java.sdiff.html > > > > Well it's probably nothing to worry about, but strictly speaking this > changes the behaviour. Before the change, long was truncated to fit int. > And now it's not. > > I would not change the behavior now. I think it is better to file a new > issue and change > it in a separate commit. Having this change in a separate commit may > simplify tracking > this change back in case it would cause some problems (I don't believe it). > And in the new issue you may provide better description for this change. > > And a minor comment for JvmMemoryImpl.java: > Maybe it is better to use Long0 in the line 387. So the code of the method > JvmMemoryImpl.getJvmMemoryPendingFinalCount() will look similar to the code > of other methods in the JvmMemoryImpl class. They all use the Long0 > constant > to return 0L. > > In sun/management/snmp/jvminstr/JvmThreadingImpl.java in the line 313: > > 312 public Long getJvmThreadPeakCount() throws SnmpStatusException { > 313 return (long)getThreadMXBean().getPeakThreadCount(); > 314 } > > There is one space too much between "return" and the cast operator. The > additional space > was in the original version too, but maybe we can clean up here the code a > little bit. > > > > > P.S. Andrej, it looks like you don't have an 'Author' status. Well, > that's a pity. We could mention you in the 'Reviewed-by' line. Your > contributions are really good. > > Thanks! But I don't really care about it as long as I can help to improve > the overall code quality. > > Best regards, > Andrej Golovnin > > -- Atenciosamente. Otávio Gonçalves de Santana blog: http://otaviosantana.blogspot.com.br/ twitter: http://twitter.com/otaviojava site: http://www.otaviojava.com.br (11) 98255-3513
Re: Long valueOf instead of new Long
Thank you Chris. I don't know if is better, but I did with all wrapper in this path. http://mail.openjdk.java.net/pipermail/core-libs-dev/2014-June/027285.html But if will better, I can split each wrapper as path. On Thu, Jun 26, 2014 at 6:58 AM, Chris Hegarty wrote: > Otavio, > > I skimmed over the patches and they look ok to me. I think they would be > suitable for inclusion in jdk9/dev. > > -Chris. > > P.S. I do not currently have time to sponsor this, but I cc’ed Pavel who > may be able to help get his in. > > On 14 Jun 2014, at 14:46, Otávio Gonçalves de Santana > wrote: > > > Reason: The Long class has cache and using it, will save memory and will > > faster than using create new instance of Long. > > > > webrev: > > https://dl.dropboxusercontent.com/u/16109193/open_jdk/long_value_of.zip > > > > similar: https://bugs.openjdk.java.net/browse/JDK-8044461 > > -- > > Otávio Gonçalves de Santana > > > > blog: http://otaviosantana.blogspot.com.br/ > > twitter: http://twitter.com/otaviojava > > site: http://www.otaviojava.com.br > > (11) 98255-3513 > > > > > -- Atenciosamente. Otávio Gonçalves de Santana blog: http://otaviosantana.blogspot.com.br/ twitter: http://twitter.com/otaviojava site: http://www.otaviojava.com.br (11) 98255-3513
Re: Character, Byte, Short valueOf instead of new instance
Could anyone see my this path, please? On Sat, Jun 14, 2014 at 1:38 PM, Otávio Gonçalves de Santana < otavioj...@java.net> wrote: > Reason: The Character, Byte, Short classes have cache and using it, will > save memory and will faster than using create new instance. > > webrev: > https://dl.dropboxusercontent.com/u/16109193/open_jdk/byte_short_character_value_of.zip > > similar: https://bugs.openjdk.java.net/browse/JDK-8044461 > > -- > Atenciosamente. > > Otávio Gonçalves de Santana > > blog: http://otaviosantana.blogspot.com.br/ > twitter: http://twitter.com/otaviojava > site: http://www.otaviojava.com.br > (11) 98255-3513 > > -- Atenciosamente. Otávio Gonçalves de Santana blog: http://otaviosantana.blogspot.com.br/ twitter: http://twitter.com/otaviojava site: http://www.otaviojava.com.br (11) 98255-3513
Re: Long valueOf instead of new Long
Could anyone see my this path, please? On Sat, Jun 14, 2014 at 10:46 AM, Otávio Gonçalves de Santana < otavioj...@java.net> wrote: > Reason: The Long class has cache and using it, will save memory and will > faster than using create new instance of Long. > > webrev: > https://dl.dropboxusercontent.com/u/16109193/open_jdk/long_value_of.zip > > similar: https://bugs.openjdk.java.net/browse/JDK-8044461 > -- > Otávio Gonçalves de Santana > > blog: http://otaviosantana.blogspot.com.br/ > twitter: http://twitter.com/otaviojava > site: http://www.otaviojava.com.br > (11) 98255-3513 > > -- Atenciosamente. Otávio Gonçalves de Santana blog: http://otaviosantana.blogspot.com.br/ twitter: http://twitter.com/otaviojava site: http://www.otaviojava.com.br (11) 98255-3513
Character, Byte, Short valueOf instead of new instance
Reason: The Character, Byte, Short classes have cache and using it, will save memory and will faster than using create new instance. webrev: https://dl.dropboxusercontent.com/u/16109193/open_jdk/byte_short_character_value_of.zip similar: https://bugs.openjdk.java.net/browse/JDK-8044461 -- Atenciosamente. Otávio Gonçalves de Santana blog: http://otaviosantana.blogspot.com.br/ twitter: http://twitter.com/otaviojava site: http://www.otaviojava.com.br (11) 98255-3513 diff -r d02b062bc827 src/share/classes/sun/tools/jconsole/inspector/Utils.java --- a/src/share/classes/sun/tools/jconsole/inspector/Utils.java Fri Jun 13 11:21:30 2014 -0700 +++ b/src/share/classes/sun/tools/jconsole/inspector/Utils.java Sat Jun 14 13:33:30 2014 -0300 @@ -342,14 +342,14 @@ Object result; if (primitiveToWrapper.containsKey(type)) { if (type.equals(Character.TYPE.getName())) { -result = new Character(value.charAt(0)); +result = value.charAt(0); } else { result = newStringConstructor( ((Class) primitiveToWrapper.get(type)).getName(), value); } } else if (type.equals(Character.class.getName())) { -result = new Character(value.charAt(0)); +result = value.charAt(0); } else if (Number.class.isAssignableFrom(Utils.getClass(type))) { result = createNumberFromStringValue(value); } else if (value == null || value.equals("null")) { diff -r d02b062bc827 src/share/classes/sun/security/pkcs/PKCS9Attribute.java --- a/src/share/classes/sun/security/pkcs/PKCS9Attribute.java Fri Jun 13 11:21:30 2014 -0700 +++ b/src/share/classes/sun/security/pkcs/PKCS9Attribute.java Sat Jun 14 13:33:30 2014 -0300 @@ -309,26 +309,26 @@ */ private static final Byte[][] PKCS9_VALUE_TAGS = { null, -{new Byte(DerValue.tag_IA5String)}, // EMailAddress -{new Byte(DerValue.tag_IA5String), // UnstructuredName - new Byte(DerValue.tag_PrintableString)}, -{new Byte(DerValue.tag_ObjectId)},// ContentType -{new Byte(DerValue.tag_OctetString)}, // MessageDigest -{new Byte(DerValue.tag_UtcTime)}, // SigningTime -{new Byte(DerValue.tag_Sequence)},// Countersignature -{new Byte(DerValue.tag_PrintableString), - new Byte(DerValue.tag_T61String)}, // ChallengePassword -{new Byte(DerValue.tag_PrintableString), - new Byte(DerValue.tag_T61String)}, // UnstructuredAddress -{new Byte(DerValue.tag_SetOf)}, // ExtendedCertificateAttributes -{new Byte(DerValue.tag_Sequence)},// issuerAndSerialNumber +{DerValue.tag_IA5String}, // EMailAddress +{DerValue.tag_IA5String, // UnstructuredName + DerValue.tag_PrintableString}, +{DerValue.tag_ObjectId},// ContentType +{DerValue.tag_OctetString}, // MessageDigest +{DerValue.tag_UtcTime}, // SigningTime +{DerValue.tag_Sequence},// Countersignature +{DerValue.tag_PrintableString, + DerValue.tag_T61String}, // ChallengePassword +{DerValue.tag_PrintableString, + DerValue.tag_T61String}, // UnstructuredAddress +{DerValue.tag_SetOf}, // ExtendedCertificateAttributes +{DerValue.tag_Sequence},// issuerAndSerialNumber null, null, null, -{new Byte(DerValue.tag_Sequence)},// extensionRequest -{new Byte(DerValue.tag_Sequence)},// SMIMECapability -{new Byte(DerValue.tag_Sequence)},// SigningCertificate -{new Byte(DerValue.tag_Sequence)} // SignatureTimestampToken +{DerValue.tag_Sequence},// extensionRequest +{DerValue.tag_Sequence},// SMIMECapability +{DerValue.tag_Sequence},// SigningCertificate +{DerValue.tag_Sequence} // SignatureTimestampToken }; private static final Class[] VALUE_CLASSES = new Class[18]; @@ -511,7 +511,7 @@ // check for illegal element tags Byte tag; for (int i=0; i < elems.length; i++) { -tag = new Byte(elems[i].tag); +tag = elems[i].tag; if (indexOf(tag, PKCS9_VALUE_TAGS[index], 0) == -1) throwTagException(tag); diff -r d02b062bc827 src/share/classes/sun/security/x509/AVA.java --- a/src/share/classes/sun/security/x509/AVA.java Fri Jun 13 11:21:30 2014 -0700 +++ b/src/share/classes/sun/security/x509/AVA.java Sat Jun 14 13:33:30 2014 -0300 @@ -517,7 +517,7 @@ if (hexDigits.indexOf(Character.toUpperCase((char)c2)) >= 0) { int hi = Character.digit((char)c1, 16); int lo = Character.digit((char)c2, 16); -return new Byte((byte)((hi<<4) + lo)); +return (byte)((hi<<4) + lo); } else
Fwd: Boolean valueOf instead of new Boolean
-- Forwarded message -- From: roger riggs Date: Tue, May 27, 2014 at 3:02 PM Subject: Re: Boolean valueOf instead of new Boolean To: core-libs-dev@openjdk.java.net Hi Otávio, I can sponsor these two (Boolean and single char strings) for you. Because they cross over different repositories and require different reviews it would be more convenient to process each of them in two batches (client vs core) Please can you break out the 'client' changes into a separate webrev? The client packages are: (java and javax...) java2d, awt, swing, font, print, beans, media, imageio, applet, sound and accessibility. The client webrevs should be posted to awt-dev and the other two to core-libs, net-dev and servicability-dev. Thanks, Roger On 5/27/2014 1:16 PM, Otávio Gonçalves de Santana wrote: > Can anyone help me as sponsor? > On May 25, 2014 2:08 AM, "Otávio Gonçalves de Santana" < > otavioj...@java.net> > wrote: > > > -- Atenciosamente. Otávio Gonçalves de Santana blog: http://otaviosantana.blogspot.com.br/ twitter: http://twitter.com/otaviojava site: http://www.otaviojava.com.br (11) 98255-3513 diff -r e323c74edabd src/share/classes/sun/applet/AppletClassLoader.java --- a/src/share/classes/sun/applet/AppletClassLoader.java Wed Apr 23 11:35:40 2014 -0700 +++ b/src/share/classes/sun/applet/AppletClassLoader.java Tue May 27 21:47:24 2014 -0300 @@ -168,7 +168,7 @@ */ protected Class findClass(String name) throws ClassNotFoundException { -int index = name.indexOf(";"); +int index = name.indexOf(';'); String cookie = ""; if(index != -1) { cookie = name.substring(index, name.length()); @@ -608,7 +608,7 @@ // deal with URL rewriting String cookie = null; -int index = name.indexOf(";"); +int index = name.indexOf(';'); if(index != -1) { cookie = name.substring(index, name.length()); name = name.substring(0, index); diff -r e323c74edabd src/share/classes/sun/awt/FontConfiguration.java --- a/src/share/classes/sun/awt/FontConfiguration.java Wed Apr 23 11:35:40 2014 -0700 +++ b/src/share/classes/sun/awt/FontConfiguration.java Tue May 27 21:47:24 2014 -0300 @@ -272,9 +272,9 @@ if (configFile != null) { return configFile; } -int decimalPointIndex = osVersion.indexOf("."); +int decimalPointIndex = osVersion.indexOf('.'); if (decimalPointIndex != -1) { -osMajorVersion = osVersion.substring(0, osVersion.indexOf(".")); +osMajorVersion = osVersion.substring(0, osVersion.indexOf('.')); configFile = findImpl(baseName + "." + osName + "." + osMajorVersion); if (configFile != null) { return configFile; diff -r e323c74edabd src/share/classes/sun/font/Type1Font.java --- a/src/share/classes/sun/font/Type1Font.java Wed Apr 23 11:35:40 2014 -0700 +++ b/src/share/classes/sun/font/Type1Font.java Tue May 27 21:47:24 2014 -0300 @@ -492,7 +492,7 @@ //Conversion: Expand abbreviations in style portion (everything after '-'), //replace '-' with space and insert missing spaces -pos = name.indexOf("-"); +pos = name.indexOf('-'); if (pos >= 0) { res = expandName(name.substring(0, pos), false); res += " " + expandName(name.substring(pos+1), true); @@ -513,8 +513,8 @@ //Conversion: Truncate style portion (everything after '-') //and insert missing spaces -if (tmp.indexOf("-") > 0) { -tmp = tmp.substring(0, tmp.indexOf("-")); +if (tmp.indexOf('-') > 0) { +tmp = tmp.substring(0, tmp.indexOf('-')); } return expandName(tmp, false); diff -r e323c74edabd src/share/classes/sun/jvmstat/monitor/AbstractMonitor.java --- a/src/share/classes/sun/jvmstat/monitor/AbstractMonitor.javaWed Apr 23 11:35:40 2014 -0700 +++ b/src/share/classes/sun/jvmstat/monitor/AbstractMonitor.javaTue May 27 21:47:24 2014 -0300 @@ -84,7 +84,7 @@ * {@inheritDoc} */ public String getBaseName() { -int baseIndex = name.lastIndexOf(".")+1; +int baseIndex = name.lastIndexOf('.') + 1; return name.substring(baseIndex); } diff -r e323c74edabd src/share/classes/sun/jvmstat/monitor/HostIdentifier.java --- a/src/share/classes/sun/jvmstat/monitor/HostIdentifier.java Wed Apr 23 11:35:40 2014 -0700 +++ b/src/share/classes/sun/jvmstat/monitor/HostIdentifier.java Tue May 27 21:47:24 2014 -0300 @@ -138,8 +13
Re: inefficient indexof when String has one length
Can anyone help me as sponsor? On May 12, 2014 1:57 PM, "Paul Sandoz" wrote: > On Apr 26, 2014, at 12:56 PM, Otávio Gonçalves de Santana < > otavioj...@java.net> wrote: > > When a String has length just one, could be replaced by equivalent > > character literals, gaining some performance enhancement. > > > > I found 107 changes. > > > > This looks good to me, just one small issue: > > --- > a/src/share/classes/javax/security/auth/PrivateCredentialPermission.java > Wed Apr 23 11:35:40 2014 -0700 > +++ > b/src/share/classes/javax/security/auth/PrivateCredentialPermission.java > Sat Apr 26 07:31:04 2014 -0300 > @@ -495,7 +495,7 @@ > > // perform new initialization from the permission name > > -if (getName().indexOf(" ") == -1 && getName().indexOf("\"") == > -1) { > +if (getName().indexOf(' ') == -1 && getName().indexOf('\"') == > -1) { > > You no longer need to escape the double quote. > > Can someone else sponsor this? unfortunately i do not have the time at the > moment. > > Paul. >
Re: Boolean valueOf instead of new Boolean
Can anyone help me as sponsor? On May 25, 2014 2:08 AM, "Otávio Gonçalves de Santana" wrote: > Really Happy to hear that. > Done. > > > On Sat, May 24, 2014 at 5:10 PM, Andrej Golovnin < > andrej.golov...@gmail.com> wrote: > >> Hi Otávio, >> >> it would be nice, if you would not modify the classes >> sun.reflect.UnsafeXXXFieldAccessorImpl. >> This classes should be changed as a part of the fix for the issue >> JDK-5043030. >> The patch for this issue is already in work. >> >> Best regards, >> Andrej Golovnin >> >> On 24.05.2014, at 16:34, Otávio Gonçalves de Santana >> wrote: >> >> > The Boolean class has cache for true and false and using it, will save >> > memory and will faster than using create new instance of boolean. >> > Using JMH[1] with a code test[2] the result was: >> > Benchmark Mode >> Samples >> >Mean Mean errorUnits >> > m.BooleanBenchmark.newInstanceBooleanthrpt20 >> 49801.326 >> > 369.897 ops/s >> > m.BooleanBenchmark.newInstanceString thrpt20 >> > 365.080 27.537ops/s >> > m.BooleanBenchmark.valueOfBoolean thrpt20 >> 764906233.316 >> > 9623009.653 ops/s >> > m.BooleanBenchmark.valueOfString thrpt20 >> > 371.174 28.216 ops/s >> > >> > >> > >> > The diff is on attachment or can is downloading the webdrev here: >> > >> https://dl.dropboxusercontent.com/u/16109193/open_jdk/boolean_instance_of.zip >> > >> > [1] http://openjdk.java.net/projects/code-tools/jmh/ >> > >> > [2] >> > >> > @State(Scope.Thread) >> > >> > @OutputTimeUnit(TimeUnit.SECONDS) >> > >> > public class BooleanBenchmark { >> > >> > private static final int SIZE = 1_000_000; >> > >> > private List booleanString; >> > >> > private boolean[] booleans; >> > >> > { >> > >> > booleans = new boolean[SIZE]; >> > >> > booleanString = new ArrayList<>(SIZE); >> > >> > for (int index = 0; index < SIZE; index++) { >> > >> > if (index % 2 == 0) { >> > >> > booleans[index] = true; >> > >> > booleanString.add(Boolean.TRUE.toString()); >> > >> > } else { >> > >> > booleans[index] = false; >> > >> > booleanString.add(Boolean.FALSE.toString()); >> > >> > } >> > >> > } >> > >> > } >> > >> > @GenerateMicroBenchmark >> > >> > public void valueOfBoolean() { >> > >> > >> > for(boolean b: booleans) { >> > >> > Boolean result = b; >> > >> > } >> > >> > } >> > >> > @GenerateMicroBenchmark >> > >> > public void valueOfString() { >> > >> > for(String b: booleanString) { >> > >> > Boolean result = Boolean.valueOf(b); >> > >> > } >> > >> > } >> > >> > @GenerateMicroBenchmark >> > >> > public void newInstanceBoolean() { >> > >> > >> > for(boolean b: booleans) { >> > >> > Boolean result = new Boolean(b); >> > >> > } >> > >> > } >> > >> > @GenerateMicroBenchmark >> > >> > public void newInstanceString() { >> > >> > for(String b: booleanString) { >> > >> > Boolean result = new Boolean(b); >> > >> > } >> > >> > } >> > >> > } >> > >> > -- >> > Atenciosamente. >> > >> > Otávio Gonçalves de Santana >> > >> > blog: http://otaviosantana.blogspot.com.br/ >> > twitter: http://twitter.com/otaviojava >> > site: http://www.otaviojava.com.br >> > (11) 98255-3513 >> > >> >> > > > -- > Atenciosamente. > > Otávio Gonçalves de Santana > > blog: http://otaviosantana.blogspot.com.br/ > twitter: http://twitter.com/otaviojava > site: http://www.otaviojava.com.br > (11) 98255-3513 > >
Re: Boolean valueOf instead of new Boolean
Really Happy to hear that. Done. On Sat, May 24, 2014 at 5:10 PM, Andrej Golovnin wrote: > Hi Otávio, > > it would be nice, if you would not modify the classes > sun.reflect.UnsafeXXXFieldAccessorImpl. > This classes should be changed as a part of the fix for the issue > JDK-5043030. > The patch for this issue is already in work. > > Best regards, > Andrej Golovnin > > On 24.05.2014, at 16:34, Otávio Gonçalves de Santana > wrote: > > > The Boolean class has cache for true and false and using it, will save > > memory and will faster than using create new instance of boolean. > > Using JMH[1] with a code test[2] the result was: > > Benchmark Mode > Samples > >Mean Mean errorUnits > > m.BooleanBenchmark.newInstanceBooleanthrpt20 > 49801.326 > > 369.897 ops/s > > m.BooleanBenchmark.newInstanceString thrpt20 > > 365.080 27.537ops/s > > m.BooleanBenchmark.valueOfBoolean thrpt20 > 764906233.316 > > 9623009.653 ops/s > > m.BooleanBenchmark.valueOfString thrpt20 > > 371.174 28.216 ops/s > > > > > > > > The diff is on attachment or can is downloading the webdrev here: > > > https://dl.dropboxusercontent.com/u/16109193/open_jdk/boolean_instance_of.zip > > > > [1] http://openjdk.java.net/projects/code-tools/jmh/ > > > > [2] > > > > @State(Scope.Thread) > > > > @OutputTimeUnit(TimeUnit.SECONDS) > > > > public class BooleanBenchmark { > > > > private static final int SIZE = 1_000_000; > > > > private List booleanString; > > > > private boolean[] booleans; > > > > { > > > > booleans = new boolean[SIZE]; > > > > booleanString = new ArrayList<>(SIZE); > > > > for (int index = 0; index < SIZE; index++) { > > > > if (index % 2 == 0) { > > > > booleans[index] = true; > > > > booleanString.add(Boolean.TRUE.toString()); > > > > } else { > > > > booleans[index] = false; > > > > booleanString.add(Boolean.FALSE.toString()); > > > > } > > > > } > > > > } > > > > @GenerateMicroBenchmark > > > > public void valueOfBoolean() { > > > > > > for(boolean b: booleans) { > > > > Boolean result = b; > > > > } > > > > } > > > > @GenerateMicroBenchmark > > > > public void valueOfString() { > > > > for(String b: booleanString) { > > > > Boolean result = Boolean.valueOf(b); > > > > } > > > > } > > > > @GenerateMicroBenchmark > > > > public void newInstanceBoolean() { > > > > > > for(boolean b: booleans) { > > > > Boolean result = new Boolean(b); > > > > } > > > > } > > > > @GenerateMicroBenchmark > > > > public void newInstanceString() { > > > > for(String b: booleanString) { > > > > Boolean result = new Boolean(b); > > > > } > > > > } > > > > } > > > > -- > > Atenciosamente. > > > > Otávio Gonçalves de Santana > > > > blog: http://otaviosantana.blogspot.com.br/ > > twitter: http://twitter.com/otaviojava > > site: http://www.otaviojava.com.br > > (11) 98255-3513 > > > > -- Atenciosamente. Otávio Gonçalves de Santana blog: http://otaviosantana.blogspot.com.br/ twitter: http://twitter.com/otaviojava site: http://www.otaviojava.com.br (11) 98255-3513 diff -r 28d1de89ff27 src/share/classes/java/net/Socket.java --- a/src/share/classes/java/net/Socket.javaThu May 22 12:54:02 2014 -0700 +++ b/src/share/classes/java/net/Socket.javaSat May 24 10:55:43 2014 -0300 @@ -1017,7 +1017,7 @@ if (isClosed()) throw new SocketException("Socket is closed"); if (!on) { -getImpl().setOption(SocketOptions.SO_LINGER, new Boolean(on)); +getImpl().setOption(SocketOptions.SO_LINGER, on); } else { if (linger < 0) { throw new IllegalArgumentException("invalid value for SO_LINGER"); diff -r 28d1de89ff27 src/share/classes/sun/font/SunFontManager.java --- a/src/share/classes/sun/font/SunFontManager.javaThu May 22 12:54:02 2014 -0700 +++ b/src/share/classes/sun/font/SunFontManager.javaSat May 24 10:55:43 2014 -0300 @@ -2871,8 +2871,7 @@ new java.security.PrivilegedAction() { public
Re: Boolean valueOf instead of new Boolean
Hi Alexis. Thank you for fixes the benchMarck. About the class GSSManagerImpl, yes it is necessary because the System.getProperty(USE_NATIVE_PROP) returns a String. On Sat, May 24, 2014 at 12:19 PM, Aleksey Shipilev < aleksey.shipi...@oracle.com> wrote: > On 05/24/2014 06:34 PM, Otávio Gonçalves de Santana wrote: > > The Boolean class has cache for true and false and using it, will save > > memory and will faster than using create new instance of boolean. > > Using JMH[1] with a code test[2] the result was: > > I agree Boolean.valueOf (whether explicit or implicit) should be used if > identity is not required. Do you really need explicit Boolean.valueOf > in, say, GSSManagerImpl, instead of relying on autoboxing? > > That said, your benchmark is not correct. At very least, you have to use > explicit BlackHoles to avoid DCE [1][2]. This is how you do it: > > @State(Scope.Thread) > @OutputTimeUnit(TimeUnit.SECONDS) > public class BooleanBenchmark { > > @Param("100") > private int size; > > private List booleanString; > private boolean[] booleans; > > @Setup > public void s() { > booleans = new boolean[size]; > booleanString = new ArrayList(size); > > for (int index = 0; index < size; index++) { > if (index % 2 == 0) { > booleans[index] = true; > booleanString.add(Boolean.TRUE.toString()); > } else { > booleans[index] = false; > booleanString.add(Boolean.FALSE.toString()); > } > } > } > > @GenerateMicroBenchmark > public void valueOfBoolean(BlackHole bh) { > for (boolean b : booleans) { > Boolean result = b; > bh.consume(result); > } > } > > @GenerateMicroBenchmark > public void valueOfString(BlackHole bh) { > for (String b : booleanString) { > Boolean result = Boolean.valueOf(b); > bh.consume(result); > } > } > > @GenerateMicroBenchmark > public void newInstanceBoolean(BlackHole bh) { > for (boolean b : booleans) { > Boolean result = new Boolean(b); > bh.consume(result); > } > } > > @GenerateMicroBenchmark > public void newInstanceString(BlackHole bh) { > for (String b : booleanString) { > Boolean result = new Boolean(b); > bh.consume(result); > } > } > } > > Thanks, > -Aleksey. > > > [1] > > http://hg.openjdk.java.net/code-tools/jmh/file/75f8b23444f6/jmh-samples/src/main/java/org/openjdk/jmh/samples/JMHSample_08_DeadCode.java > [2] > > http://hg.openjdk.java.net/code-tools/jmh/file/75f8b23444f6/jmh-samples/src/main/java/org/openjdk/jmh/samples/JMHSample_09_Blackholes.java > > -- Atenciosamente. Otávio Gonçalves de Santana blog: http://otaviosantana.blogspot.com.br/ twitter: http://twitter.com/otaviojava site: http://www.otaviojava.com.br (11) 98255-3513
Boolean valueOf instead of new Boolean
The Boolean class has cache for true and false and using it, will save memory and will faster than using create new instance of boolean. Using JMH[1] with a code test[2] the result was: Benchmark Mode Samples Mean Mean errorUnits m.BooleanBenchmark.newInstanceBooleanthrpt20 49801.326 369.897 ops/s m.BooleanBenchmark.newInstanceString thrpt20 365.080 27.537ops/s m.BooleanBenchmark.valueOfBoolean thrpt20764906233.316 9623009.653 ops/s m.BooleanBenchmark.valueOfString thrpt20 371.174 28.216 ops/s The diff is on attachment or can is downloading the webdrev here: https://dl.dropboxusercontent.com/u/16109193/open_jdk/boolean_instance_of.zip [1] http://openjdk.java.net/projects/code-tools/jmh/ [2] @State(Scope.Thread) @OutputTimeUnit(TimeUnit.SECONDS) public class BooleanBenchmark { private static final int SIZE = 1_000_000; private List booleanString; private boolean[] booleans; { booleans = new boolean[SIZE]; booleanString = new ArrayList<>(SIZE); for (int index = 0; index < SIZE; index++) { if (index % 2 == 0) { booleans[index] = true; booleanString.add(Boolean.TRUE.toString()); } else { booleans[index] = false; booleanString.add(Boolean.FALSE.toString()); } } } @GenerateMicroBenchmark public void valueOfBoolean() { for(boolean b: booleans) { Boolean result = b; } } @GenerateMicroBenchmark public void valueOfString() { for(String b: booleanString) { Boolean result = Boolean.valueOf(b); } } @GenerateMicroBenchmark public void newInstanceBoolean() { for(boolean b: booleans) { Boolean result = new Boolean(b); } } @GenerateMicroBenchmark public void newInstanceString() { for(String b: booleanString) { Boolean result = new Boolean(b); } } } -- Atenciosamente. Otávio Gonçalves de Santana blog: http://otaviosantana.blogspot.com.br/ twitter: http://twitter.com/otaviojava site: http://www.otaviojava.com.br (11) 98255-3513 diff -r 28d1de89ff27 src/share/classes/java/net/Socket.java --- a/src/share/classes/java/net/Socket.javaThu May 22 12:54:02 2014 -0700 +++ b/src/share/classes/java/net/Socket.javaSat May 24 10:55:43 2014 -0300 @@ -1017,7 +1017,7 @@ if (isClosed()) throw new SocketException("Socket is closed"); if (!on) { -getImpl().setOption(SocketOptions.SO_LINGER, new Boolean(on)); +getImpl().setOption(SocketOptions.SO_LINGER, on); } else { if (linger < 0) { throw new IllegalArgumentException("invalid value for SO_LINGER"); diff -r 28d1de89ff27 src/share/classes/sun/font/SunFontManager.java --- a/src/share/classes/sun/font/SunFontManager.javaThu May 22 12:54:02 2014 -0700 +++ b/src/share/classes/sun/font/SunFontManager.javaSat May 24 10:55:43 2014 -0300 @@ -2871,8 +2871,7 @@ new java.security.PrivilegedAction() { public Object run() { SecurityManager sm = System.getSecurityManager(); -return new Boolean -(sm instanceof sun.applet.AppletSecurity); +return sm instanceof sun.applet.AppletSecurity; } }); return appletSM.booleanValue(); diff -r 28d1de89ff27 src/share/classes/sun/management/StackTraceElementCompositeData.java --- a/src/share/classes/sun/management/StackTraceElementCompositeData.java Thu May 22 12:54:02 2014 -0700 +++ b/src/share/classes/sun/management/StackTraceElementCompositeData.java Sat May 24 10:55:43 2014 -0300 @@ -68,7 +68,7 @@ ste.getMethodName(), ste.getFileName(), new Integer(ste.getLineNumber()), -new Boolean(ste.isNativeMethod()), +ste.isNativeMethod(), }; try { return new CompositeDataSupport(stackTraceElementCompositeType, diff -r 28d1de89ff27 src/share/classes/sun/management/ThreadInfoCompositeData.java --- a/src/share/classes/sun/management/ThreadInfoCompositeData.java Thu May 22 12:54:02 2014 -0700 +++ b/src/share/classes/sun/management/ThreadInfoCompositeData.java Sat May 24 10:55:43 2014 -0300 @@ -120,8 +120,8 @@ new Long(threadInfo.getLockOwnerId()), threadInfo.getLockOwnerName(), stackTraceData, -new Boolean(threadInfo.isSuspended()), -new Boolean(threadInfo.isInNative()), +threadInfo.isSuspended(), +threadInfo.isInNative(), lockedMonitorsData, lockedSyncsData, }; diff -r 28d1de89ff27 src/share/classes/sun/management/VMOptionCompositeData.java --- a/src/share/classes/sun/management/VMOptionCompositeData.java
Re: inefficient indexof when String has one length
link: https://dl.dropboxusercontent.com/u/16109193/open_jdk/index_of_with_char.zip On Mon, Apr 28, 2014 at 10:25 AM, Otávio Gonçalves de Santana < otavioj...@java.net> wrote: > > link: > https://dl.dropboxusercontent.com/u/16109193/open_jdk/index_of_with_char.zip > > > On Mon, Apr 28, 2014 at 4:42 AM, Paul Sandoz wrote: > >> On Apr 27, 2014, at 2:22 PM, Claes Redestad >> wrote: >> > Possibly a few bytes in static class footprint, sure. Maybe this is >> something javac should optimize (javap on some trivial examples suggests >> this doesn't happen) rather than trying to root out all suboptimal cases, >> especially since there are bound to be a lot more code out there using >> similar patterns? >> > >> >> While javac can and perhaps should be smarter in certain cases like this >> i am still supportive of this change in the JDK esp. so if it is something >> trivially detectable by IDEs; it's low-hanging fruit. >> >> Paul. >> > > > > -- > Atenciosamente. > > Otávio Gonçalves de Santana > > blog: http://otaviosantana.blogspot.com.br/ > twitter: http://twitter.com/otaviojava > site: http://www.otaviojava.com.br > (11) 98255-3513 > > -- Atenciosamente. Otávio Gonçalves de Santana blog: http://otaviosantana.blogspot.com.br/ twitter: http://twitter.com/otaviojava site: http://www.otaviojava.com.br (11) 98255-3513
Re: Remove redundant calls of toString()
Done. Link: https://dl.dropboxusercontent.com/u/16109193/open_jdk/string_to_string_uncessary.zip On Mon, Apr 28, 2014 at 4:34 AM, Paul Sandoz wrote: > Hi Otávio, > > Is there anyway you can experiment with publishing a webrev to dropbox or > github, preferably so that it is browsable, otherwise the zip? > > Unfortunately the patches are hard to review, especially in response to > reviews where code is updated. > > I realize until you have an openjdk account you are somewhat in "no-mans" > land, but i strongly suspect using one of the above mentioned services is > fairly easy to use, and therefore will make it easier to accept such > patches. > > Paul. > > On Apr 27, 2014, at 3:15 PM, Otávio Gonçalves de Santana < > otaviopolianasant...@gmail.com> wrote: > > > There is an issue that was opened to remove redundant calls of toString() > > on String objects. [1] > > I went deep on all JVM sources and I found all, 32 changes. > > -- Atenciosamente. Otávio Gonçalves de Santana blog: http://otaviosantana.blogspot.com.br/ twitter: http://twitter.com/otaviojava site: http://www.otaviojava.com.br (11) 98255-3513
Re: Remove redundant calls of toString()
Yes you are right, but I mean it doesn't too much expensive enough to don't use the requireNonNull. IMHO. On Mon, Apr 28, 2014 at 3:57 AM, David Holmes wrote: > On 28/04/2014 1:05 PM, Otávio Gonçalves de Santana wrote: > >> In my opinion not, because Objects.requireNonNull is more readable than >> just string.toString. This way is more understandable which field is >> required and doesn't impact on performance. >> > > An invocation of requireNonNull is potentially more expensive than the > implicit null check that happens with foo.toString(). > > David > - > > >> On Sun, Apr 27, 2014 at 11:33 PM, David Holmes > <mailto:david.hol...@oracle.com>> wrote: >> >> On 28/04/2014 3:41 AM, Otávio Gonçalves de Santana wrote: >> >> sorry. >> I tried answer and the message was twice. >>But Yes when has null pointer possibility I replaced to >> Objects.requireNonNull. >> >> >> In my opinion that is making the code worse not better. >> >> David >> - >> >> >> I am review the code again. >> The code below: >> >> diff -r e323c74edabd >> src/share/classes/com/sun/__tools/example/debug/tty/__ >> Commands.java >> --- >> a/src/share/classes/com/sun/__tools/example/debug/tty/__ >> Commands.java >> Wed >> Apr 23 11:35:40 2014 -0700 >> +++ >> b/src/share/classes/com/sun/__tools/example/debug/tty/__ >> Commands.java >> Sun >> Apr 27 14:33:45 2014 -0300 >> @@ -1653,20 +1653,20 @@ >>String expr = t.nextToken(""); >>Value val = evaluate(expr); >>if (val == null) { >> -MessageOutput.println("expr is null", >> expr.toString()); >> +MessageOutput.println("expr is >> null",Objects.requireNonNull(__expr)); >>} else if (dumpObject && (val instanceof >> ObjectReference) && >> !(val instanceof StringReference)) { >>ObjectReference obj = (ObjectReference)val; >>ReferenceType refType = obj.referenceType(); >>MessageOutput.println("expr is value", >> - new Object [] >> {expr.toString(), >> + new Object [] >> {Objects.requireNonNull(expr), >> >> MessageOutput.format("grouping begin character")}); >>dump(obj, refType, refType); >>MessageOutput.println("__grouping end >> character"); >>} else { >> String strVal = getStringValue(); >> if (strVal != null) { >> - MessageOutput.println("expr is value", new >> Object [] >> {expr.toString(), >> + MessageOutput.println("expr is value", new >> Object [] >> {Objects.requireNonNull(expr), >> >>strVal}); >> } >>} >> diff -r e323c74edabd >> src/share/classes/java/lang/__annotation/__ >> IncompleteAnnotationException.__java >> --- >> a/src/share/classes/java/lang/__annotation/__ >> IncompleteAnnotationException.__java >> Wed >> Apr 23 11:35:40 2014 -0700 >> +++ >> b/src/share/classes/java/lang/__annotation/__ >> IncompleteAnnotationException.__java >> Sun >> Apr 27 14:33:45 2014 -0300 >> @@ -25,6 +25,8 @@ >> >>package java.lang.annotation; >> >> +import java.util.Objects; >> + >>/** >> * Thrown to indicate that a program has attempted to access >> an element of >> * an annotation type that was added to the annotation type >> definition >> after >> @@ -56,7 +58,7 @@ >>Class annotationType, >>String elementName) { >>super(annotationType.getName() + " missing el
Re: Remove redundant calls of toString()
In my opinion not, because Objects.requireNonNull is more readable than just string.toString. This way is more understandable which field is required and doesn't impact on performance. On Sun, Apr 27, 2014 at 11:33 PM, David Holmes wrote: > On 28/04/2014 3:41 AM, Otávio Gonçalves de Santana wrote: > >> sorry. >> I tried answer and the message was twice. >> But Yes when has null pointer possibility I replaced to >> Objects.requireNonNull. >> > > In my opinion that is making the code worse not better. > > David > - > > > I am review the code again. >> The code below: >> >> diff -r e323c74edabd >> src/share/classes/com/sun/tools/example/debug/tty/Commands.java >> --- a/src/share/classes/com/sun/tools/example/debug/tty/Commands.java Wed >> Apr 23 11:35:40 2014 -0700 >> +++ b/src/share/classes/com/sun/tools/example/debug/tty/Commands.java Sun >> Apr 27 14:33:45 2014 -0300 >> @@ -1653,20 +1653,20 @@ >> String expr = t.nextToken(""); >> Value val = evaluate(expr); >> if (val == null) { >> -MessageOutput.println("expr is null", expr.toString()); >> +MessageOutput.println("expr is >> null",Objects.requireNonNull(expr)); >> } else if (dumpObject && (val instanceof ObjectReference) && >> !(val instanceof StringReference)) { >> ObjectReference obj = (ObjectReference)val; >> ReferenceType refType = obj.referenceType(); >> MessageOutput.println("expr is value", >> - new Object [] {expr.toString(), >> + new Object [] >> {Objects.requireNonNull(expr), >> >> MessageOutput.format("grouping begin character")}); >> dump(obj, refType, refType); >> MessageOutput.println("grouping end character"); >> } else { >> String strVal = getStringValue(); >> if (strVal != null) { >> - MessageOutput.println("expr is value", new Object [] >> {expr.toString(), >> + MessageOutput.println("expr is value", new Object [] >> {Objects.requireNonNull(expr), >> >> strVal}); >> } >> } >> diff -r e323c74edabd >> src/share/classes/java/lang/annotation/IncompleteAnnotationException.java >> --- >> a/src/share/classes/java/lang/annotation/IncompleteAnnotationException.java >> Wed >> Apr 23 11:35:40 2014 -0700 >> +++ >> b/src/share/classes/java/lang/annotation/IncompleteAnnotationException.java >> Sun >> Apr 27 14:33:45 2014 -0300 >> @@ -25,6 +25,8 @@ >> >> package java.lang.annotation; >> >> +import java.util.Objects; >> + >> /** >>* Thrown to indicate that a program has attempted to access an element >> of >>* an annotation type that was added to the annotation type definition >> after >> @@ -56,7 +58,7 @@ >> Class annotationType, >> String elementName) { >> super(annotationType.getName() + " missing element " + >> - elementName.toString()); >> +Objects.requireNonNull(elementName)); >> >> this.annotationType = annotationType; >> this.elementName = elementName; >> diff -r e323c74edabd src/share/classes/java/text/DateFormatSymbols.java >> --- a/src/share/classes/java/text/DateFormatSymbols.java Wed Apr 23 >> 11:35:40 2014 -0700 >> +++ b/src/share/classes/java/text/DateFormatSymbols.java Sun Apr 27 >> 14:33:45 2014 -0300 >> @@ -594,7 +594,7 @@ >>*/ >> public void setLocalPatternChars(String newLocalPatternChars) { >> // Call toString() to throw an NPE in case the argument is null >> -localPatternChars = newLocalPatternChars.toString(); >> +localPatternChars = Objects.requireNonNull( >> newLocalPatternChars); >> cachedHashCode = 0; >> } >> >> diff -r e323c74edabd >> src/share/classes/javax/management/modelmbean/DescriptorSupport.java >> --- a/src/share/classes/javax/management/modelmbean/DescriptorSupport.java >> Wed >> Apr 23 11:35:40 2014 -0700 >> +++ b/src/share/classes/javax/management/modelmbean/DescriptorSupport.java >> Sun >> Apr 27 14:33:45 2014 -0300 >> @@
Re: Remove redundant calls of toString()
quot;; public static final int primTypeID = makePrimTypeID(); diff -r e323c74edabd src/share/classes/sun/java2d/loops/TransformBlit.java --- a/src/share/classes/sun/java2d/loops/TransformBlit.java Wed Apr 23 11:35:40 2014 -0700 +++ b/src/share/classes/sun/java2d/loops/TransformBlit.java Sun Apr 27 14:33:45 2014 -0300 @@ -47,7 +47,7 @@ public class TransformBlit extends GraphicsPrimitive { public static final String methodSignature = -"TransformBlit(...)".toString(); +"TransformBlit(...)"; public static final int primTypeID = makePrimTypeID(); diff -r e323c74edabd src/share/classes/sun/java2d/loops/TransformHelper.java --- a/src/share/classes/sun/java2d/loops/TransformHelper.java Wed Apr 23 11:35:40 2014 -0700 +++ b/src/share/classes/sun/java2d/loops/TransformHelper.java Sun Apr 27 14:33:45 2014 -0300 @@ -46,7 +46,7 @@ public class TransformHelper extends GraphicsPrimitive { public static final String methodSignature = -"TransformHelper(...)".toString(); +"TransformHelper(...)"; public static final int primTypeID = makePrimTypeID(); diff -r e323c74edabd src/share/classes/sun/misc/ExtensionInfo.java --- a/src/share/classes/sun/misc/ExtensionInfo.java Wed Apr 23 11:35:40 2014 -0700 +++ b/src/share/classes/sun/misc/ExtensionInfo.java Sun Apr 27 14:33:45 2014 -0300 @@ -25,6 +25,7 @@ package sun.misc; +import java.util.Objects; import java.util.StringTokenizer; import java.util.jar.Attributes; import java.util.jar.Attributes.Name; @@ -260,11 +261,11 @@ // Convert token into meaning number for comparision if (stk.hasMoreTokens()) -n = convertToken(stk.nextToken().toString()); +n = convertToken(Objects.requireNonNull(stk.nextToken())); // Convert token into meaning number for comparision if (ttk.hasMoreTokens()) -m = convertToken(ttk.nextToken().toString()); +m = convertToken(Objects.requireNonNull(ttk.nextToken())); if (n > m) return 1; diff -r e323c74edabd src/share/classes/sun/tools/jconsole/inspector/Utils.java --- a/src/share/classes/sun/tools/jconsole/inspector/Utils.java Wed Apr 23 11:35:40 2014 -0700 +++ b/src/share/classes/sun/tools/jconsole/inspector/Utils.java Sun Apr 27 14:33:45 2014 -0300 @@ -378,7 +378,7 @@ if (userInput instanceof XObject) { result[i] = ((XObject) userInput).getObject(); } else { -result[i] = createObjectFromString(params[i].toString(), +result[i] = createObjectFromString(Objects.requireNonNull(params[i]), (String) userInput); } } On Sun, Apr 27, 2014 at 1:09 PM, Remi Forax wrote: > On 04/27/2014 03:15 PM, Otávio Gonçalves de Santana wrote: > >> There is an issue that was opened to remove redundant calls of toString() >> on String objects. [1] >> I went deep on all JVM sources and I found all, 32 changes. >> >> >> [1]https://bugs.openjdk.java.net/browse/JDK-8015470 >> > > Otavio, > calling toString() on a String has the side effect to implicitly check > that the reference is not null. > Do you have checked that for each redundant call, the String can never be > null ? > > regards, > Rémi > > > >> >> diff -r e323c74edabd >> src/share/classes/com/sun/tools/example/debug/tty/Commands.java >> --- a/src/share/classes/com/sun/tools/example/debug/tty/Commands.java Wed >> Apr 23 11:35:40 2014 -0700 >> +++ b/src/share/classes/com/sun/tools/example/debug/tty/Commands.java Sat >> Apr 26 01:40:27 2014 -0300 >> @@ -1653,20 +1653,20 @@ >> String expr = t.nextToken(""); >> Value val = evaluate(expr); >> if (val == null) { >> -MessageOutput.println("expr is null", expr.toString()); >> +MessageOutput.println("expr is null", expr); >> } else if (dumpObject && (val instanceof ObjectReference) && >> !(val instanceof StringReference)) { >> ObjectReference obj = (ObjectReference)val; >> ReferenceType refType = obj.referenceType(); >> MessageOutput.println("expr is value", >> - new Object [] {expr.toString(), >> + new Object [] {expr, >> >> MessageOutput.format("grouping begin character")}); >> dump(obj, refType, refType); >> MessageOutput.println("grouping end character"); >> } else { >> String strVal = getStringValue(); >&g
Remove redundant calls of toString()
mTypeID = makePrimTypeID(); diff -r e323c74edabd src/share/classes/sun/java2d/loops/TransformHelper.java --- a/src/share/classes/sun/java2d/loops/TransformHelper.java Wed Apr 23 11:35:40 2014 -0700 +++ b/src/share/classes/sun/java2d/loops/TransformHelper.java Sat Apr 26 01:40:27 2014 -0300 @@ -46,7 +46,7 @@ public class TransformHelper extends GraphicsPrimitive { public static final String methodSignature = -"TransformHelper(...)".toString(); +"TransformHelper(...)"; public static final int primTypeID = makePrimTypeID(); diff -r e323c74edabd src/share/classes/sun/misc/ExtensionInfo.java --- a/src/share/classes/sun/misc/ExtensionInfo.java Wed Apr 23 11:35:40 2014 -0700 +++ b/src/share/classes/sun/misc/ExtensionInfo.java Sat Apr 26 01:40:27 2014 -0300 @@ -260,11 +260,11 @@ // Convert token into meaning number for comparision if (stk.hasMoreTokens()) -n = convertToken(stk.nextToken().toString()); +n = convertToken(stk.nextToken()); // Convert token into meaning number for comparision if (ttk.hasMoreTokens()) -m = convertToken(ttk.nextToken().toString()); +m = convertToken(ttk.nextToken()); if (n > m) return 1; diff -r e323c74edabd src/share/classes/sun/tools/jconsole/inspector/Utils.java --- a/src/share/classes/sun/tools/jconsole/inspector/Utils.java Wed Apr 23 11:35:40 2014 -0700 +++ b/src/share/classes/sun/tools/jconsole/inspector/Utils.java Sat Apr 26 01:40:27 2014 -0300 @@ -378,7 +378,7 @@ if (userInput instanceof XObject) { result[i] = ((XObject) userInput).getObject(); } else { -result[i] = createObjectFromString(params[i].toString(), +result[i] = createObjectFromString(params[i], (String) userInput); } } -- Atenciosamente. Otávio Gonçalves de Santana blog: http://otaviosantana.blogspot.com.br/ twitter: http://twitter.com/otaviojava site: http://www.otaviojava.com.br (11) 98255-3513
Remove redundant calls of toString()
mTypeID = makePrimTypeID(); diff -r e323c74edabd src/share/classes/sun/java2d/loops/TransformHelper.java --- a/src/share/classes/sun/java2d/loops/TransformHelper.java Wed Apr 23 11:35:40 2014 -0700 +++ b/src/share/classes/sun/java2d/loops/TransformHelper.java Sat Apr 26 01:40:27 2014 -0300 @@ -46,7 +46,7 @@ public class TransformHelper extends GraphicsPrimitive { public static final String methodSignature = -"TransformHelper(...)".toString(); +"TransformHelper(...)"; public static final int primTypeID = makePrimTypeID(); diff -r e323c74edabd src/share/classes/sun/misc/ExtensionInfo.java --- a/src/share/classes/sun/misc/ExtensionInfo.java Wed Apr 23 11:35:40 2014 -0700 +++ b/src/share/classes/sun/misc/ExtensionInfo.java Sat Apr 26 01:40:27 2014 -0300 @@ -260,11 +260,11 @@ // Convert token into meaning number for comparision if (stk.hasMoreTokens()) -n = convertToken(stk.nextToken().toString()); +n = convertToken(stk.nextToken()); // Convert token into meaning number for comparision if (ttk.hasMoreTokens()) -m = convertToken(ttk.nextToken().toString()); +m = convertToken(ttk.nextToken()); if (n > m) return 1; diff -r e323c74edabd src/share/classes/sun/tools/jconsole/inspector/Utils.java --- a/src/share/classes/sun/tools/jconsole/inspector/Utils.java Wed Apr 23 11:35:40 2014 -0700 +++ b/src/share/classes/sun/tools/jconsole/inspector/Utils.java Sat Apr 26 01:40:27 2014 -0300 @@ -378,7 +378,7 @@ if (userInput instanceof XObject) { result[i] = ((XObject) userInput).getObject(); } else { -result[i] = createObjectFromString(params[i].toString(), +result[i] = createObjectFromString(params[i], (String) userInput); } } -- Cheers!. Otávio Gonçalves de Santana blog: http://otaviosantana.blogspot.com.br/ twitter: http://twitter.com/otaviojava site: *http://about.me/otaviojava <http://about.me/otaviojava>* 55 (11) 98255-3513
Re: getFirst and getLast on Iterable
Yes I did a mistake, please ignore. I sent twice but it had one week as delay. Sorry On Apr 23, 2014 2:01 PM, "Brian Goetz" wrote: > Didn’t we just discuss this like a week ago? > > > http://mail.openjdk.java.net/pipermail/core-libs-dev/2014-April/026506.html > > > > On Apr 17, 2014, at 12:30 AM, Otávio Gonçalves de Santana < > otaviopolianasant...@gmail.com> wrote: > > I would to add for news methods on Iterable, I believe it will helpful for > many Java Developers. > > > diff -r 3dd165facde7 test/java/util/Iterator/IteratorDefaults.java > > --- a/test/java/util/Iterator/IteratorDefaults.java Wed Apr 09 12:26:00 > 2014 -0700 > > +++ b/test/java/util/Iterator/IteratorDefaults.java Wed Apr 16 23:25:56 > 2014 -0300 > > @@ -399,6 +399,48 @@ > > } > > } > > > > + public void testgetFirst() { > > + > > +List source = Arrays.asList(1, 2, 3, 4); > > +int first = source.getFirst(); > > +assertEquals(first, 1); > > + > > +List emptySource = Collections.emptyList(); > > +assertNull(emptySource.getFirst()); > > +} > > + > > +public void testgetFirstWithDefaultElement() { > > + > > +List source = Arrays.asList(1, 2, 3, 4); > > +Integer defaultElement = 5; > > +assertEquals(source.getFirst(defaultElement), Integer.valueOf(1)); > > + > > +List emptySource = Collections.emptyList(); > > +assertEquals(emptySource.getFirst(defaultElement), > defaultElement); > > + > > +} > > + > > +public void testgetLast() { > > + > > +List source = Arrays.asList(1, 2, 3, 4); > > +int last = source.getLast(); > > +assertEquals(last, 4); > > + > > +List emptySource = Collections.emptyList(); > > +assertNull(emptySource.getLast()); > > +} > > + > > +public void testgetLastWithDefaultElement() { > > + > > +List source = Arrays.asList(1, 2, 3, 4); > > +Integer defaultElement = 5; > > +assertEquals(source.getLast(defaultElement), Integer.valueOf(4)); > > + > > +List emptySource = Collections.emptyList(); > > +assertEquals(emptySource.getLast(defaultElement), defaultElement); > > + > > +} > > + > > static class IteratorWithRemove implements Iterator { > > > > public boolean removed; > > > > > diff -r 3dd165facde7 src/share/classes/java/lang/Iterable.java > > --- a/src/share/classes/java/lang/Iterable.java Wed Apr 09 12:26:00 2014 > -0700 > > +++ b/src/share/classes/java/lang/Iterable.java Wed Apr 16 23:16:21 2014 > -0300 > > @@ -100,4 +100,55 @@ > > default Spliterator spliterator() { > > return Spliterators.spliteratorUnknownSize(iterator(), 0); > > } > > + > > + > > + /** > > + * returns the first element, if empty will return {@code null} > > + * @return the first element or {@code null} > > + * @since 1.8 > > + */ > > +default T getFirst() { > > +return getFirst(null); > > +} > > + > > +/** > > + * returns the first element, if empty will return the default > > + * @param defaultValue - the default value to return if the iterable > is empty > > + * @return the first element or default element > > + * @since 1.8 > > + */ > > +default T getFirst(T defaultValue) { > > +for (T element : this) { > > +return element; > > +} > > +return defaultValue; > > +} > > + > > + /** > > + * returns the last element, if empty will return {@code null} > > + * @return the first element or {@code null} > > + * @since 1.8 > > + */ > > +default T getLast() { > > + > > +return getLast(null); > > + } > > + > > +/** > > + * returns the last element, if empty will return the default > > + * @param defaultValue - the default value to return if the iterable > is empty > > + * @return the last element or default element > > + * @since 1.8 > > + */ > > +default T getLast(T defaultValue) { > > + > > +T last = null; > > +for (T element : this) { > > +last = element; > > +} > > +if (Objects.isNull(last)) { > > +return defaultValue; > > +} > > +return last; > > +} > > } > > > -- > Atenciosamente. > > Otávio Gonçalves de Santana > > blog: http://otaviosantana.blogspot.com.br/ > twitter: http://twitter.com/otaviojava > site: http://www.otaviojava.com.br > (11) 98255-3513 > > >
Conditions with that always returns true is 'if' necessary?
Hello everyone, one question. Conditions that always returns true, is 'if' necessary? I found one. diff -r 57c1da89ae1a src/share/classes/java/lang/invoke/BoundMethodHandle.java --- a/src/share/classes/java/lang/invoke/BoundMethodHandle.java Wed Apr 16 12:32:36 2014 -0700 +++ b/src/share/classes/java/lang/invoke/BoundMethodHandle.java Mon Apr 21 09:50:29 2014 -0300 @@ -66,8 +66,7 @@ try { switch (xtype) { case 'L': -if (true) return bindSingle(type, form, x); // Use known fast path. -return (BoundMethodHandle) SpeciesData.EMPTY.extendWithType('L').constructor[0].invokeBasic(type, form, x); +return bindSingle(type, form, x); // Use known fast path. case 'I': return (BoundMethodHandle) SpeciesData.EMPTY.extendWithType('I').constructor[0].invokeBasic(type, form, ValueConversions.widenSubword(x)); case 'J': -- Atenciosamente. Otávio Gonçalves de Santana blog: http://otaviosantana.blogspot.com.br/ twitter: http://twitter.com/otaviojava site: http://www.otaviojava.com.br (11) 98255-3513
StringBuilder instead of StringBuffer in java.util package
diff -r 57c1da89ae1a src/share/classes/java/util/prefs/Base64.java --- a/src/share/classes/java/util/prefs/Base64.java Wed Apr 16 12:32:36 2014 -0700 +++ b/src/share/classes/java/util/prefs/Base64.java Mon Apr 21 20:20:57 2014 -0300 @@ -57,7 +57,7 @@ int numFullGroups = aLen/3; int numBytesInPartialGroup = aLen - 3*numFullGroups; int resultLen = 4*((aLen + 2)/3); -StringBuffer result = new StringBuffer(resultLen); +StringBuilder result = new StringBuilder(resultLen); char[] intToAlpha = (alternate ? intToAltBase64 : intToBase64); // Translate all full groups from byte array elements to Base64 @@ -259,3 +259,4 @@ } } } + diff -r 57c1da89ae1a src/share/classes/java/util/regex/PatternSyntaxException.java --- a/src/share/classes/java/util/regex/PatternSyntaxException.java Wed Apr 16 12:32:36 2014 -0700 +++ b/src/share/classes/java/util/regex/PatternSyntaxException.java Mon Apr 21 20:21:52 2014 -0300 @@ -105,7 +105,7 @@ * @return The full detail message */ public String getMessage() { -StringBuffer sb = new StringBuffer(); +StringBuilder sb = new StringBuilder(); sb.append(desc); if (index >= 0) { sb.append(" near index "); @@ -122,3 +122,4 @@ } } + diff -r 57c1da89ae1a src/share/classes/java/util/Properties.java --- a/src/share/classes/java/util/Properties.java Wed Apr 16 12:32:36 2014 -0700 +++ b/src/share/classes/java/util/Properties.java Mon Apr 21 20:22:44 2014 -0300 @@ -602,7 +602,7 @@ if (bufLen < 0) { bufLen = Integer.MAX_VALUE; } -StringBuffer outBuffer = new StringBuffer(bufLen); +StringBuilder outBuffer = new StringBuilder(bufLen); for(int x=0; xhttp://otaviosantana.blogspot.com.br/ twitter: http://twitter.com/otaviojava site: http://www.otaviojava.com.br (11) 98255-3513
getFirst and getLast on Iterable
I would to add for news methods on Iterable, I believe it will helpful for many Java Developers. diff -r 3dd165facde7 test/java/util/Iterator/IteratorDefaults.java --- a/test/java/util/Iterator/IteratorDefaults.java Wed Apr 09 12:26:00 2014 -0700 +++ b/test/java/util/Iterator/IteratorDefaults.java Wed Apr 16 23:25:56 2014 -0300 @@ -399,6 +399,48 @@ } } + public void testgetFirst() { + +List source = Arrays.asList(1, 2, 3, 4); +int first = source.getFirst(); +assertEquals(first, 1); + +List emptySource = Collections.emptyList(); +assertNull(emptySource.getFirst()); +} + +public void testgetFirstWithDefaultElement() { + +List source = Arrays.asList(1, 2, 3, 4); +Integer defaultElement = 5; +assertEquals(source.getFirst(defaultElement), Integer.valueOf(1)); + +List emptySource = Collections.emptyList(); +assertEquals(emptySource.getFirst(defaultElement), defaultElement); + +} + +public void testgetLast() { + +List source = Arrays.asList(1, 2, 3, 4); +int last = source.getLast(); +assertEquals(last, 4); + +List emptySource = Collections.emptyList(); +assertNull(emptySource.getLast()); +} + +public void testgetLastWithDefaultElement() { + +List source = Arrays.asList(1, 2, 3, 4); +Integer defaultElement = 5; +assertEquals(source.getLast(defaultElement), Integer.valueOf(4)); + +List emptySource = Collections.emptyList(); +assertEquals(emptySource.getLast(defaultElement), defaultElement); + +} + static class IteratorWithRemove implements Iterator { public boolean removed; diff -r 3dd165facde7 src/share/classes/java/lang/Iterable.java --- a/src/share/classes/java/lang/Iterable.java Wed Apr 09 12:26:00 2014 -0700 +++ b/src/share/classes/java/lang/Iterable.java Wed Apr 16 23:16:21 2014 -0300 @@ -100,4 +100,55 @@ default Spliterator spliterator() { return Spliterators.spliteratorUnknownSize(iterator(), 0); } + + + /** + * returns the first element, if empty will return {@code null} + * @return the first element or {@code null} + * @since 1.8 + */ +default T getFirst() { +return getFirst(null); +} + +/** + * returns the first element, if empty will return the default + * @param defaultValue - the default value to return if the iterable is empty + * @return the first element or default element + * @since 1.8 + */ +default T getFirst(T defaultValue) { +for (T element : this) { +return element; +} +return defaultValue; +} + + /** + * returns the last element, if empty will return {@code null} + * @return the first element or {@code null} + * @since 1.8 + */ +default T getLast() { + +return getLast(null); +} + +/** + * returns the last element, if empty will return the default + * @param defaultValue - the default value to return if the iterable is empty + * @return the last element or default element + * @since 1.8 + */ +default T getLast(T defaultValue) { + +T last = null; +for (T element : this) { +last = element; +} +if (Objects.isNull(last)) { +return defaultValue; +} +return last; +} } -- Atenciosamente. Otávio Gonçalves de Santana blog: http://otaviosantana.blogspot.com.br/ twitter: http://twitter.com/otaviojava site: http://www.otaviojava.com.br (11) 98255-3513
Re: Conditions with that always returns true is 'if' necessary?
Thank for your opinion. Done this way to keep the pattern. diff -r 57c1da89ae1a src/share/classes/java/lang/invoke/BoundMethodHandle.java --- a/src/share/classes/java/lang/invoke/BoundMethodHandle.java Wed Apr 16 12:32:36 2014 -0700 +++ b/src/share/classes/java/lang/invoke/BoundMethodHandle.java Mon Apr 21 09:50:29 2014 -0300 @@ -66,8 +66,7 @@ try { switch (xtype) { case 'L': -if (true) return bindSingle(type, form, x); // Use known fast path. -return (BoundMethodHandle) SpeciesData.EMPTY.extendWithType('L').constructor[0].invokeBasic(type, form, x); + return bindSingle(type, form, x); + // Use known fast path. case 'I': return (BoundMethodHandle) SpeciesData.EMPTY.extendWithType('I').constructor[0].invokeBasic(type, form, ValueConversions.widenSubword(x)); case 'J': On Tue, Apr 22, 2014 at 5:07 AM, Paul Sandoz wrote: > Hi Otávio, > > On Apr 21, 2014, at 3:06 PM, Otávio Gonçalves de Santana < > otavioj...@java.net> wrote: > > > Hello everyone, one question. > > Conditions that always returns true, is 'if' necessary? > > I can imagine it is a left over from hacking in the fast path. IMHO better > to remove the if and comment the line below to retain the general pattern. > > Could easily be tacked on to an existing change e.g. if Vladimir is not > fed up updating his basic types patch :-) > > http://cr.openjdk.java.net/~vlivanov/8037210 > > Paul. > > > I found one. > > > > diff -r 57c1da89ae1a > > src/share/classes/java/lang/invoke/BoundMethodHandle.java > > --- a/src/share/classes/java/lang/invoke/BoundMethodHandle.java Wed Apr > 16 > > 12:32:36 2014 -0700 > > +++ b/src/share/classes/java/lang/invoke/BoundMethodHandle.java Mon Apr > 21 > > 09:50:29 2014 -0300 > > @@ -66,8 +66,7 @@ > > try { > > switch (xtype) { > > case 'L': > > -if (true) return bindSingle(type, form, x); // Use > known > > fast path. > > -return (BoundMethodHandle) > > SpeciesData.EMPTY.extendWithType('L').constructor[0].invokeBasic(type, > > form, x); > > +return bindSingle(type, form, x); // Use known fast > path. > > case 'I': > > return (BoundMethodHandle) > > SpeciesData.EMPTY.extendWithType('I').constructor[0].invokeBasic(type, > > form, ValueConversions.widenSubword(x)); > > case 'J': > > > > > > -- > > Atenciosamente. > > > > Otávio Gonçalves de Santana > > > > blog: http://otaviosantana.blogspot.com.br/ > > twitter: http://twitter.com/otaviojava > > site: http://www.otaviojava.com.br > > (11) 98255-3513 > > -- Atenciosamente. Otávio Gonçalves de Santana blog: http://otaviosantana.blogspot.com.br/ twitter: http://twitter.com/otaviojava site: http://www.otaviojava.com.br (11) 98255-3513
StringBuilder instead of StringBuffer in java.util package
diff -r 57c1da89ae1a src/share/classes/java/util/prefs/Base64.java --- a/src/share/classes/java/util/prefs/Base64.java Wed Apr 16 12:32:36 2014 -0700 +++ b/src/share/classes/java/util/prefs/Base64.java Mon Apr 21 20:20:57 2014 -0300 @@ -57,7 +57,7 @@ int numFullGroups = aLen/3; int numBytesInPartialGroup = aLen - 3*numFullGroups; int resultLen = 4*((aLen + 2)/3); -StringBuffer result = new StringBuffer(resultLen); +StringBuilder result = new StringBuilder(resultLen); char[] intToAlpha = (alternate ? intToAltBase64 : intToBase64); // Translate all full groups from byte array elements to Base64 @@ -259,3 +259,4 @@ } } } + diff -r 57c1da89ae1a src/share/classes/java/util/regex/PatternSyntaxException.java --- a/src/share/classes/java/util/regex/PatternSyntaxException.java Wed Apr 16 12:32:36 2014 -0700 +++ b/src/share/classes/java/util/regex/PatternSyntaxException.java Mon Apr 21 20:21:52 2014 -0300 @@ -105,7 +105,7 @@ * @return The full detail message */ public String getMessage() { -StringBuffer sb = new StringBuffer(); +StringBuilder sb = new StringBuilder(); sb.append(desc); if (index >= 0) { sb.append(" near index "); @@ -122,3 +122,4 @@ } } + diff -r 57c1da89ae1a src/share/classes/java/util/Properties.java --- a/src/share/classes/java/util/Properties.java Wed Apr 16 12:32:36 2014 -0700 +++ b/src/share/classes/java/util/Properties.java Mon Apr 21 20:22:44 2014 -0300 @@ -602,7 +602,7 @@ if (bufLen < 0) { bufLen = Integer.MAX_VALUE; } -StringBuffer outBuffer = new StringBuffer(bufLen); +StringBuilder outBuffer = new StringBuilder(bufLen); for(int x=0; xhttp://otaviosantana.blogspot.com.br/ twitter: http://twitter.com/otaviojava site: http://www.otaviojava.com.br (11) 98255-3513
Conditions with that always returns true is 'if' necessary?
Hello everyone, one question. Conditions that always returns true, is 'if' necessary? I found one. diff -r 57c1da89ae1a src/share/classes/java/lang/invoke/BoundMethodHandle.java --- a/src/share/classes/java/lang/invoke/BoundMethodHandle.java Wed Apr 16 12:32:36 2014 -0700 +++ b/src/share/classes/java/lang/invoke/BoundMethodHandle.java Mon Apr 21 09:50:29 2014 -0300 @@ -66,8 +66,7 @@ try { switch (xtype) { case 'L': -if (true) return bindSingle(type, form, x); // Use known fast path. -return (BoundMethodHandle) SpeciesData.EMPTY.extendWithType('L').constructor[0].invokeBasic(type, form, x); +return bindSingle(type, form, x); // Use known fast path. case 'I': return (BoundMethodHandle) SpeciesData.EMPTY.extendWithType('I').constructor[0].invokeBasic(type, form, ValueConversions.widenSubword(x)); case 'J': -- Atenciosamente. Otávio Gonçalves de Santana blog: http://otaviosantana.blogspot.com.br/ twitter: http://twitter.com/otaviojava site: http://www.otaviojava.com.br (11) 98255-3513
getFirst and getLast on Iterable
I would to add for news methods on Iterable, I believe it will helpful for many Java Developers. diff -r 3dd165facde7 test/java/util/Iterator/IteratorDefaults.java --- a/test/java/util/Iterator/IteratorDefaults.java Wed Apr 09 12:26:00 2014 -0700 +++ b/test/java/util/Iterator/IteratorDefaults.java Wed Apr 16 23:25:56 2014 -0300 @@ -399,6 +399,48 @@ } } + public void testgetFirst() { + +List source = Arrays.asList(1, 2, 3, 4); +int first = source.getFirst(); +assertEquals(first, 1); + +List emptySource = Collections.emptyList(); +assertNull(emptySource.getFirst()); +} + +public void testgetFirstWithDefaultElement() { + +List source = Arrays.asList(1, 2, 3, 4); +Integer defaultElement = 5; +assertEquals(source.getFirst(defaultElement), Integer.valueOf(1)); + +List emptySource = Collections.emptyList(); +assertEquals(emptySource.getFirst(defaultElement), defaultElement); + +} + +public void testgetLast() { + +List source = Arrays.asList(1, 2, 3, 4); +int last = source.getLast(); +assertEquals(last, 4); + +List emptySource = Collections.emptyList(); +assertNull(emptySource.getLast()); +} + +public void testgetLastWithDefaultElement() { + +List source = Arrays.asList(1, 2, 3, 4); +Integer defaultElement = 5; +assertEquals(source.getLast(defaultElement), Integer.valueOf(4)); + +List emptySource = Collections.emptyList(); +assertEquals(emptySource.getLast(defaultElement), defaultElement); + +} + static class IteratorWithRemove implements Iterator { public boolean removed; diff -r 3dd165facde7 src/share/classes/java/lang/Iterable.java --- a/src/share/classes/java/lang/Iterable.java Wed Apr 09 12:26:00 2014 -0700 +++ b/src/share/classes/java/lang/Iterable.java Wed Apr 16 23:16:21 2014 -0300 @@ -100,4 +100,55 @@ default Spliterator spliterator() { return Spliterators.spliteratorUnknownSize(iterator(), 0); } + + + /** + * returns the first element, if empty will return {@code null} + * @return the first element or {@code null} + * @since 1.8 + */ +default T getFirst() { +return getFirst(null); +} + +/** + * returns the first element, if empty will return the default + * @param defaultValue - the default value to return if the iterable is empty + * @return the first element or default element + * @since 1.8 + */ +default T getFirst(T defaultValue) { +for (T element : this) { +return element; +} +return defaultValue; +} + + /** + * returns the last element, if empty will return {@code null} + * @return the first element or {@code null} + * @since 1.8 + */ +default T getLast() { + +return getLast(null); +} + +/** + * returns the last element, if empty will return the default + * @param defaultValue - the default value to return if the iterable is empty + * @return the last element or default element + * @since 1.8 + */ +default T getLast(T defaultValue) { + +T last = null; +for (T element : this) { +last = element; +} +if (Objects.isNull(last)) { +return defaultValue; +} +return last; +} } -- Atenciosamente. Otávio Gonçalves de Santana blog: http://otaviosantana.blogspot.com.br/ twitter: http://twitter.com/otaviojava site: http://www.otaviojava.com.br (11) 98255-3513
Re: Inefficient use StringBuffer or StringBuilder[Optimization|clean-up] {Package: sun.*}
ode=" + mode); +sb.append("?mode=").append(mode); } String vmidStr = sb.toString(); diff --git a/src/share/classes/sun/font/StandardGlyphVector.java b/src/share/classes/sun/font/StandardGlyphVector.java --- a/src/share/classes/sun/font/StandardGlyphVector.java +++ b/src/share/classes/sun/font/StandardGlyphVector.java @@ -1894,7 +1894,7 @@ } } catch(Exception e) { -buf.append(" " + e.getMessage()); +buf.append(' ').append(e.getMessage()); } buf.append("}"); diff --git a/src/share/classes/sun/awt/datatransfer/SunClipboard.java b/src/share/classes/sun/awt/datatransfer/SunClipboard.java --- a/src/share/classes/sun/awt/datatransfer/SunClipboard.java +++ b/src/share/classes/sun/awt/datatransfer/SunClipboard.java @@ -87,7 +87,7 @@ public SunClipboard(String name) { super(name); -CLIPBOARD_FLAVOR_LISTENER_KEY = new StringBuffer(name + "_CLIPBOARD_FLAVOR_LISTENER_KEY"); +CLIPBOARD_FLAVOR_LISTENER_KEY = new StringBuffer(name).append("_CLIPBOARD_FLAVOR_LISTENER_KEY"); } public synchronized void setContents(Transferable contents, diff --git a/src/share/classes/sun/security/acl/AclEntryImpl.java b/src/share/classes/sun/security/acl/AclEntryImpl.java --- a/src/share/classes/sun/security/acl/AclEntryImpl.java +++ b/src/share/classes/sun/security/acl/AclEntryImpl.java @@ -147,7 +147,7 @@ s.append("Group."); else s.append("User."); -s.append(user + "="); +s.append(user).append('='); Enumeration e = permissions(); while(e.hasMoreElements()) { Permission p = e.nextElement(); diff --git a/src/share/classes/sun/security/krb5/internal/crypto/dk/DkCrypto.java b/src/share/classes/sun/security/krb5/internal/crypto/dk/DkCrypto.java --- a/src/share/classes/sun/security/krb5/internal/crypto/dk/DkCrypto.java +++ b/src/share/classes/sun/security/krb5/internal/crypto/dk/DkCrypto.java @@ -640,7 +640,7 @@ for (int i = 0; i < digest.length; i++) { if ((digest[i] & 0x00ff) < 0x10) { -digestString.append("0" + +digestString.append('0').append( Integer.toHexString(digest[i] & 0x00ff)); } else { digestString.append( diff --git a/src/share/classes/sun/security/ssl/HandshakeMessage.java b/src/share/classes/sun/security/ssl/HandshakeMessage.java --- a/src/share/classes/sun/security/ssl/HandshakeMessage.java +++ b/src/share/classes/sun/security/ssl/HandshakeMessage.java @@ -1478,7 +1478,7 @@ boolean opened = false; for (SignatureAndHashAlgorithm signAlg : algorithms) { if (opened) { -buffer.append(", " + signAlg.getAlgorithmName()); +buffer.append(", ").append(signAlg.getAlgorithmName()); } else { buffer.append(signAlg.getAlgorithmName()); opened = true; diff --git a/src/share/classes/sun/security/krb5/KrbException.java b/src/share/classes/sun/security/krb5/KrbException.java --- a/src/share/classes/sun/security/krb5/KrbException.java +++ b/src/share/classes/sun/security/krb5/KrbException.java @@ -96,7 +96,7 @@ public String krbErrorMessage() { -StringBuffer strbuf = new StringBuffer("krb_error " + returnCode); +StringBuffer strbuf = new StringBuffer("krb_error ").append(returnCode); String msg = getMessage(); if (msg != null) { strbuf.append(" "); diff --git a/src/share/classes/sun/security/x509/PolicyInformation.java b/src/share/classes/sun/security/x509/PolicyInformation.java --- a/src/share/classes/sun/security/x509/PolicyInformation.java +++ b/src/share/classes/sun/security/x509/PolicyInformation.java @@ -258,8 +258,8 @@ * Return a printable representation of the PolicyInformation. */ public String toString() { -StringBuilder s = new StringBuilder(" [" + policyIdentifier.toString()); -s.append(policyQualifiers + " ]\n"); +StringBuilder s = new StringBuilder(" [").append( policyIdentifier.toString()); +s.append(policyQualifiers).append(" ]\n"); return s.toString(); } diff --git a/src/share/classes/sun/security/pkcs/SigningCertificateInfo.java b/src/share/classes/sun/security/pkcs/SigningCertificateInfo.java --- a/src/share/classes/sun/security/pkcs/SigningCertificateInfo.java +++ b/src/share/classes/sun/security/pkcs/SigningCertificateInfo.java @@ -158,8 +158,8 @@ } buffer.append(hexDumper.encode(certHash)); if (issuer != null && serialNumber
Re: Inefficient use StringBuffer or StringBuilder[Optimization|clean-up] {Package: java. * without Swing}
I did one more refactoring in this packages. diff --git a/src/share/classes/javax/management/openmbean/ArrayType.java b/src/share/classes/javax/management/openmbean/ArrayType.java --- a/src/share/classes/javax/management/openmbean/ArrayType.java +++ b/src/share/classes/javax/management/openmbean/ArrayType.java @@ -459,7 +459,7 @@ isPrimitiveArray = at.isPrimitiveArray(); } StringBuilder result = -new StringBuilder(dimension + "-dimension array of "); +new StringBuilder(dimension).append("-dimension array of "); final String elementClassName = elementType.getClassName(); if (isPrimitiveArray) { // Convert from wrapper type to primitive type diff --git a/src/share/classes/javax/sound/sampled/AudioFileFormat.java b/src/share/classes/javax/sound/sampled/AudioFileFormat.java --- a/src/share/classes/javax/sound/sampled/AudioFileFormat.java +++ b/src/share/classes/javax/sound/sampled/AudioFileFormat.java @@ -288,19 +288,20 @@ //$$fb2002-11-01: fix for 4672864: AudioFileFormat.toString() throws unexpected NullPointerException if (type != null) { -buf.append(type.toString() + " (." + type.getExtension() + ") file"); +buf.append(type.toString()).append(" (.").append(type.getExtension()).append(") file"); + } else { buf.append("unknown file format"); } if (byteLength != AudioSystem.NOT_SPECIFIED) { -buf.append(", byte length: " + byteLength); +buf.append(", byte length: ").append(byteLength); } -buf.append(", data format: " + format); +buf.append(", data format: ").append(format); if (frameLength != AudioSystem.NOT_SPECIFIED) { -buf.append(", frame length: " + frameLength); +buf.append(", frame length: ").append(frameLength); } return new String(buf); diff --git a/src/share/classes/javax/naming/directory/BasicAttribute.java b/src/share/classes/javax/naming/directory/BasicAttribute.java --- a/src/share/classes/javax/naming/directory/BasicAttribute.java +++ b/src/share/classes/javax/naming/directory/BasicAttribute.java @@ -211,7 +211,7 @@ * @return The non-null string representation of this attribute. */ public String toString() { -StringBuffer answer = new StringBuffer(attrID + ": "); +StringBuffer answer = new StringBuffer(attrID).append(": "); if (values.size() == 0) { answer.append("No values"); } else { diff --git a/src/share/classes/javax/naming/BinaryRefAddr.java b/src/share/classes/javax/naming/BinaryRefAddr.java --- a/src/share/classes/javax/naming/BinaryRefAddr.java +++ b/src/share/classes/javax/naming/BinaryRefAddr.java @@ -169,7 +169,7 @@ str.append("AddressContents: "); for (int i = 0; i= 32) str.append(" ...\n"); diff --git a/src/share/classes/javax/imageio/plugins/jpeg/JPEGQTable.java b/src/share/classes/javax/imageio/plugins/jpeg/JPEGQTable.java --- a/src/share/classes/javax/imageio/plugins/jpeg/JPEGQTable.java +++ b/src/share/classes/javax/imageio/plugins/jpeg/JPEGQTable.java @@ -197,7 +197,7 @@ */ public String toString() { String ls = System.getProperty("line.separator", "\n"); -StringBuilder sb = new StringBuilder("JPEGQTable:"+ls); +StringBuilder sb = new StringBuilder("JPEGQTable:").append(ls); for (int i=0; i < qTable.length; i++) { if (i % 8 == 0) { sb.append('\t'); diff --git a/src/share/classes/javax/naming/NameImpl.java b/src/share/classes/javax/naming/NameImpl.java --- a/src/share/classes/javax/naming/NameImpl.java +++ b/src/share/classes/javax/naming/NameImpl.java @@ -170,7 +170,7 @@ endQuote = one ? syntaxEndQuote1 : syntaxEndQuote2; i += syntaxTypevalSeparator.length(); -answer.append(syntaxTypevalSeparator+beginQuote); // add back + answer.append(syntaxTypevalSeparator).append(beginQuote); // add back // consume string until matching quote for (i += beginQuote.length(); On Fri, Jun 7, 2013 at 10:25 AM, Otávio Gonçalves de Santana < otavioj...@java.net> wrote: > > The string addition in the parameter will create another string buffer, > append all the components, then convert that to a string so the you can be > appended to your string buffer. > > So I replace this: > > sb.append("xxx: [" + getXXX() + "]\n"); > > for this: > > sb.append("xxx: [").append(getXXX()).append("]\n"); > > The classes are:
Re: Inefficient use StringBuffer or StringBuilder[Optimization|clean-up] {Package: con.sun. * java.lang*}
ternal/security/encryption/XMLCipher.java --- a/src/share/classes/com/sun/org/apache/xml/internal/security/encryption/XMLCipher.java +++ b/src/share/classes/com/sun/org/apache/xml/internal/security/encryption/XMLCipher.java @@ -1932,7 +1932,7 @@ StringBuffer sb; sb = new StringBuffer(); -sb.append("<"+tagname); +sb.append("<").append(tagname); // Run through each node up to the document node and find any // xmlns: nodes On Fri, Jun 7, 2013 at 5:42 PM, Victor Polischuk wrote: > Excuse me for asking something stupid but do empty appends in > "com.sun.tools.hat.internal.model.JavaValueArray" make any sense? > >result.append("").append(val); > > //Victor > > --- Original message --- > From: "Otávio Gonçalves de Santana" > Date: 7 June 2013, 16:20:02 > > > > Inefficient use StringBuffer or StringBuilder[Optimization|clean-up] > > > > The string addition in the parameter will create another string buffer, > > append all the components, then convert that to a string so the you can > be > > appended to your string buffer. > > > > So I replace this: > > > > sb.append("xxx: [" + getXXX() + "]\n"); > > > > for this: > > > > sb.append("xxx: [").append(getXXX()).append("]\n"); > > > > The classes are: > > > > -- com.sun > > com.sun.tools.hat.internal.model.JavaValueArray > > com.sun.jmx.snmp.IPAcl.NetMaskImpl > > com.sun.jndi.ldap.sasl.DefaultCallbackHandler > > com.sun.media.sound.WaveExtensibleFileReader > > com.sun.org.apache.xml.internal.security.encryption.XMLCipher > > com.sun.org.apache.xml.internal.security.utils.RFC2253Parser > > com.sun.security.sasl.CramMD5Base > > com.sun.security.sasl.digest.DigestMD5Base > > com.sun.tools.example.debug.gui.ContextManager > > com.sun.tools.jdi.VirtualMachineImpl > > > > -- java.lang > > java.lang.invoke.LambdaForm > > > > > > The diff bellow: > > > > > > diff --git > > a/src/share/classes/com/sun/tools/example/debug/gui/ContextManager.java > > b/src/share/classes/com/sun/tools/example/debug/gui/ContextManager.java > > --- > a/src/share/classes/com/sun/tools/example/debug/gui/ContextManager.java > > +++ > b/src/share/classes/com/sun/tools/example/debug/gui/ContextManager.java > > @@ -338,10 +338,10 @@ > > if (classpath.isEmpty()) { > > String envcp = System.getProperty("env.class.path"); > > if ((envcp != null) && (envcp.length() > 0)) { > > -munged.append(" -classpath " + envcp); > > +munged.append(" -classpath ").append(envcp); > > } > > } else { > > -munged.append(" -classpath " + classpath.asString()); > > +munged.append(" -classpath > ").append(classpath.asString()); > > } > > return munged.toString(); > > } else { > > > > > > > > > > diff --git a/src/share/classes/com/sun/security/sasl/CramMD5Base.java > > b/src/share/classes/com/sun/security/sasl/CramMD5Base.java > > --- a/src/share/classes/com/sun/security/sasl/CramMD5Base.java > > +++ b/src/share/classes/com/sun/security/sasl/CramMD5Base.java > > @@ -199,8 +199,7 @@ > > > > for (i = 0; i < digest.length; i++) { > > if ((digest[i] & 0x00ff) < 0x10) { > > -digestString.append("0" + > > -Integer.toHexString(digest[i] & 0x00ff)); > > + > > digestString.append("0").append(Integer.toHexString(digest[i] & > > 0x00ff)); > > } else { > > digestString.append( > > Integer.toHexString(digest[i] & 0x00ff)); > > > > > > > > > > diff --git > > a/src/share/classes/com/sun/jndi/ldap/sasl/DefaultCallbackHandler.java > > b/src/share/classes/com/sun/jndi/ldap/sasl/DefaultCallbackHandler.java > > --- > a/src/share/classes/com/sun/jndi/ldap/sasl/DefaultCallbackHandler.java > > +++ > b/src/share/classes/com/sun/jndi/ldap/sasl/DefaultCallbackHandler.java > > @@ -90,7 +90,7 @@ > > if (selected == -1) { > > StringBuffer allChoices = new StringBuffer(); > > for (int j = 0; j < choices.length; j++) { > > -allChoices.append(choices[j] + ","); > > + > allChoices.append(choices[j]).append(','); > > } > > throw new IOException("Cannot match " + >
Re: Inefficient use StringBuffer or StringBuilder[Optimization|clean-up] {Package: con.sun. * java.lang*}
I wrote a simple test. public class BuilderTest{ public void testAppend(String name){ StringBuilder sb=new StringBuilder(); sb.append("hello").append(" World: ").append(name); } public void testConcat(String name){ StringBuilder sb=new StringBuilder(); sb.append("hello" +" World: "+name); } } public void testAppend(java.lang.String); Code: Stack=2, Locals=3, Args_size=2 0: new #2; //class java/lang/StringBuilder 3: dup 4: invokespecial #3; //Method java/lang/StringBuilder."":()V 7: astore_2 8: aload_2 9: ldc #4; //String hello 11: invokevirtual #5; //Method java/lang/StringBuilder.append:(Ljava/lang/ String;)Ljava/lang/StringBuilder; 14: ldc #6; //String World: 16: invokevirtual #5; //Method java/lang/StringBuilder.append:(Ljava/lang/ String;)Ljava/lang/StringBuilder; 19: aload_1 20: invokevirtual #5; //Method java/lang/StringBuilder.append:(Ljava/lang/ String;)Ljava/lang/StringBuilder; 23: pop 24: return public void testConcat(java.lang.String); Code: Stack=3, Locals=3, Args_size=2 0: new #2; //class java/lang/StringBuilder 3: dup 4: invokespecial #3; //Method java/lang/StringBuilder."":()V 7: astore_2 8: aload_2 9: new #2; //class java/lang/StringBuilder 12: dup 13: invokespecial #3; //Method java/lang/StringBuilder."":()V 16: ldc #7; //String hello World: 18: invokevirtual #5; //Method java/lang/StringBuilder.append:(Ljava/lang/ String;)Ljava/lang/StringBuilder; 21: aload_1 22: invokevirtual #5; //Method java/lang/StringBuilder.append:(Ljava/lang/ String;)Ljava/lang/StringBuilder; 25: invokevirtual #8; //Method java/lang/StringBuilder.toString:()Ljava/la ng/String; 28: invokevirtual #5; //Method java/lang/StringBuilder.append:(Ljava/lang/ String;)Ljava/lang/StringBuilder; 31: pop 32: return } In the second method it creates a second StringBuilder with the toString() of the first one. I think doing this get some performance. On Fri, Jun 7, 2013 at 11:09 AM, Tom Hawtin wrote: > On 07/06/2013 14:54, Andrew Haley wrote: > >> On 06/07/2013 02:18 PM, Otávio Gonçalves de Santana wrote: >> > > sb.append("xxx: [" + getXXX() + "]\n"); >>> >>> for this: >>> >>> sb.append("xxx: [").append(getXXX()).append("]**\n"); >>> >> >> Hmm. I wonder that a JIT can't do this automatically. Perhaps >> it already does; I haven't looked. >> > > The capacity of the StringBuilder may be different for the two statements. > So even a "high-level rewriting" wouldn't be sufficiently equivalent. > > Tom > -- Atenciosamente. Otávio Gonçalves de Santana blog: http://otaviosantana.blogspot.com.br/ twitter: http://twitter.com/otaviojava site: http://www.otaviojava.com.br (11) 98255-3513
Inefficient use StringBuffer or StringBuilder[Optimization|clean-up] {Package: java. * without Swing}
The string addition in the parameter will create another string buffer, append all the components, then convert that to a string so the you can be appended to your string buffer. So I replace this: sb.append("xxx: [" + getXXX() + "]\n"); for this: sb.append("xxx: [").append(getXXX()).append("]\n"); The classes are: javax.imageio.plugins.jpeg.JPEGQTable javax.management.openmbean.ArrayType javax.naming.BinaryRefAddr javax.naming.directory.BasicAttribute javax.naming.NameImpl javax.sound.sampled.AudioFileFormat The diff bellow: diff --git a/src/share/classes/javax/management/openmbean/ArrayType.java b/src/share/classes/javax/management/openmbean/ArrayType.java --- a/src/share/classes/javax/management/openmbean/ArrayType.java +++ b/src/share/classes/javax/management/openmbean/ArrayType.java @@ -459,7 +459,7 @@ isPrimitiveArray = at.isPrimitiveArray(); } StringBuilder result = -new StringBuilder(dimension + "-dimension array of "); +new StringBuilder(dimension).append("-dimension array of "); final String elementClassName = elementType.getClassName(); if (isPrimitiveArray) { // Convert from wrapper type to primitive type diff --git a/src/share/classes/javax/sound/sampled/AudioFileFormat.java b/src/share/classes/javax/sound/sampled/AudioFileFormat.java --- a/src/share/classes/javax/sound/sampled/AudioFileFormat.java +++ b/src/share/classes/javax/sound/sampled/AudioFileFormat.java @@ -288,19 +288,20 @@ //$$fb2002-11-01: fix for 4672864: AudioFileFormat.toString() throws unexpected NullPointerException if (type != null) { -buf.append(type.toString() + " (." + type.getExtension() + ") file"); +buf.append(type.toString()).append(" (.").append(type.getExtension()).append(") file"); + } else { buf.append("unknown file format"); } if (byteLength != AudioSystem.NOT_SPECIFIED) { -buf.append(", byte length: " + byteLength); +buf.append(", byte length: ").append(byteLength); } -buf.append(", data format: " + format); +buf.append(", data format: ").append(format); if (frameLength != AudioSystem.NOT_SPECIFIED) { -buf.append(", frame length: " + frameLength); +buf.append(", frame length: ").append(frameLength); } return new String(buf); diff --git a/src/share/classes/javax/naming/directory/BasicAttribute.java b/src/share/classes/javax/naming/directory/BasicAttribute.java --- a/src/share/classes/javax/naming/directory/BasicAttribute.java +++ b/src/share/classes/javax/naming/directory/BasicAttribute.java @@ -211,7 +211,7 @@ * @return The non-null string representation of this attribute. */ public String toString() { -StringBuffer answer = new StringBuffer(attrID + ": "); +StringBuffer answer = new StringBuffer(attrID).append(": "); if (values.size() == 0) { answer.append("No values"); } else { diff --git a/src/share/classes/javax/naming/BinaryRefAddr.java b/src/share/classes/javax/naming/BinaryRefAddr.java --- a/src/share/classes/javax/naming/BinaryRefAddr.java +++ b/src/share/classes/javax/naming/BinaryRefAddr.java @@ -169,7 +169,7 @@ str.append("AddressContents: "); for (int i = 0; i= 32) str.append(" ...\n"); diff --git a/src/share/classes/javax/imageio/plugins/jpeg/JPEGQTable.java b/src/share/classes/javax/imageio/plugins/jpeg/JPEGQTable.java --- a/src/share/classes/javax/imageio/plugins/jpeg/JPEGQTable.java +++ b/src/share/classes/javax/imageio/plugins/jpeg/JPEGQTable.java @@ -197,7 +197,7 @@ */ public String toString() { String ls = System.getProperty("line.separator", "\n"); -StringBuilder sb = new StringBuilder("JPEGQTable:"+ls); +StringBuilder sb = new StringBuilder("JPEGQTable:").append(ls); for (int i=0; i < qTable.length; i++) { if (i % 8 == 0) { sb.append('\t'); diff --git a/src/share/classes/javax/naming/NameImpl.java b/src/share/classes/javax/naming/NameImpl.java --- a/src/share/classes/javax/naming/NameImpl.java +++ b/src/share/classes/javax/naming/NameImpl.java @@ -170,7 +170,7 @@ endQuote = one ? syntaxEndQuote1 : syntaxEndQuote2; i += syntaxTypevalSeparator.length(); -answer.append(syntaxTypevalSeparator+beginQuote); // add back +answer.append(syntaxTypevalSeparator).append(beginQuote); // add back // consume string until matching quote for (i += beginQuote.length(); -- Atenciosamente. Otávio Gonçalves de Santana blog: http://otaviosantana.blogspot.com.br/ twitter: http://twitter.com/otaviojava site: http://www.otaviojava.com.br (11) 98255-3513
Inefficient use StringBuffer or StringBuilder[Optimization|clean-up] {Package: sun.*}
Return a printable representation of the PolicyInformation. */ public String toString() { -StringBuilder s = new StringBuilder(" [" + policyIdentifier.toString()); -s.append(policyQualifiers + " ]\n"); +StringBuilder s = new StringBuilder(" [").append( policyIdentifier.toString()); +s.append(policyQualifiers).append(" ]\n"); return s.toString(); } diff --git a/src/share/classes/sun/security/pkcs/SigningCertificateInfo.java b/src/share/classes/sun/security/pkcs/SigningCertificateInfo.java --- a/src/share/classes/sun/security/pkcs/SigningCertificateInfo.java +++ b/src/share/classes/sun/security/pkcs/SigningCertificateInfo.java @@ -158,8 +158,8 @@ } buffer.append(hexDumper.encode(certHash)); if (issuer != null && serialNumber != null) { -buffer.append("\n\tIssuer: " + issuer + "\n"); -buffer.append("\t" + serialNumber); +buffer.append("\n\tIssuer: " ).append( issuer ).append( "\n"); +buffer.append("\t").append( serialNumber); } buffer.append("\n]"); return buffer.toString(); -- Atenciosamente. Otávio Gonçalves de Santana blog: http://otaviosantana.blogspot.com.br/ twitter: http://twitter.com/otaviojava site: http://www.otaviojava.com.br (11) 98255-3513
Inefficient use StringBuffer or StringBuilder[Optimization|clean-up] {Package: con.sun. * java.lang*}
ringBuffer(); -sb.append("<"+tagname); +sb.append("<").append(tagname); // Run through each node up to the document node and find any // xmlns: nodes diff --git a/src/share/classes/com/sun/tools/jdi/VirtualMachineImpl.java b/src/share/classes/com/sun/tools/jdi/VirtualMachineImpl.java --- a/src/share/classes/com/sun/tools/jdi/VirtualMachineImpl.java +++ b/src/share/classes/com/sun/tools/jdi/VirtualMachineImpl.java @@ -881,10 +881,10 @@ } else if (tag == JDWP.TypeTag.ARRAY) { sb.append("ArrayType"); } else { -sb.append("UNKNOWN TAG: " + tag); +sb.append("UNKNOWN TAG: ").append(tag); } if (signature != null) { -sb.append(", signature='" + signature + "'"); +sb.append(", signature='").append(signature).append("'"); } sb.append(", id=" + id); vm.printTrace(sb.toString()); diff --git a/src/share/classes/com/sun/media/sound/WaveExtensibleFileReader.java b/src/share/classes/com/sun/media/sound/WaveExtensibleFileReader.java --- a/src/share/classes/com/sun/media/sound/WaveExtensibleFileReader.java +++ b/src/share/classes/com/sun/media/sound/WaveExtensibleFileReader.java @@ -167,9 +167,9 @@ for (int i = 0; i < allchannelnames.length; i++) { if ((channelmask & m) != 0L) { if (i < channelnames.length) { -sb.append(channelnames[i] + " "); +sb.append(channelnames[i]).append(" "); } else { -sb.append(allchannelnames[i] + " "); +sb.append(allchannelnames[i]).append(" "); } } m *= 2L; diff --git a/src/share/classes/com/sun/org/apache/xml/internal/security/encryption/XMLCipher.java b/src/share/classes/com/sun/org/apache/xml/internal/security/encryption/XMLCipher.java --- a/src/share/classes/com/sun/org/apache/xml/internal/security/encryption/XMLCipher.java +++ b/src/share/classes/com/sun/org/apache/xml/internal/security/encryption/XMLCipher.java @@ -1932,7 +1932,7 @@ StringBuffer sb; sb = new StringBuffer(); -sb.append("<"+tagname); +sb.append("<").append(tagname); // Run through each node up to the document node and find any // xmlns: nodes -- java_lang diff --git a/src/share/classes/java/lang/invoke/LambdaForm.java b/src/share/classes/java/lang/invoke/LambdaForm.java --- a/src/share/classes/java/lang/invoke/LambdaForm.java +++ b/src/share/classes/java/lang/invoke/LambdaForm.java @@ -708,7 +708,7 @@ } public String toString() { -StringBuilder buf = new StringBuilder(debugName+"=Lambda("); +StringBuilder buf = new StringBuilder(debugName).append("=Lambda("); for (int i = 0; i < names.length; i++) { if (i == arity) buf.append(")=>{"); Name n = names[i]; -- Atenciosamente. Otávio Gonçalves de Santana blog: http://otaviosantana.blogspot.com.br/ twitter: http://twitter.com/otaviojava site: http://www.otaviojava.com.br (11) 98255-3513
Re: 8015470: (ann) IncompleteAnnotationException does not need to call toString
Thank you everyone. I searched classes with this situation and I find these classes: - sun.tools.java.MemberDefinition - sun.rmi.rmic.Main - sun.tools.jconsole.inspector.Utils - com.sun.jndi.toolkit.dir.SearchFilter - javax.swing.text.html.FormView The diffs is in attachment On Tue, May 28, 2013 at 10:31 PM, David Holmes wrote: > On 28/05/2013 11:08 PM, Remi Forax wrote: > >> On 05/28/2013 02:48 PM, David Holmes wrote: >> >>> Sorry it didn't register that getName() already returns a String - >>> hence the toString() is redundant - but minimally so. >>> >>> David >>> >> >> The second call to toString() also performs an implicit nullcheck >> (elementName can not be null). >> So if we have to fix something, it's only to remove the call to >> toString() after the call to getName(). >> > > Good catch Remi! > > Otavio: I don't want to dissuade you from getting involved but as Remi > indicates your suggested change becomes simply > > > -super(annotationType.getName()**.toString() + > +super(annotationType.getName() + > > and this is such a minor change to interpreted performance (the JIT will > remove the toString call) that I don't think it is worth the process > overhead (testing etc) to actually make this change. As I said in other > email sometimes there are non-obvious reasons (like null checks :) ) that > code has to be kept in its current form. > > David > - > > > cheers, >> Rémi >> >> >>> On 28/05/2013 9:15 PM, David Holmes wrote: >>> >>>> Please see my reply under your original subject line. >>>> >>>> This is not a bug. >>>> >>>> David >>>> >>>> On 28/05/2013 7:37 PM, Otávio Gonçalves de Santana wrote: >>>> >>>>> diff --git >>>>> a/src/share/classes/java/lang/**annotation/** >>>>> IncompleteAnnotationException.**java >>>>> >>>>> >>>>> b/src/share/classes/java/lang/**annotation/** >>>>> IncompleteAnnotationException.**java >>>>> >>>>> >>>>> --- >>>>> a/src/share/classes/java/lang/**annotation/** >>>>> IncompleteAnnotationException.**java >>>>> >>>>> >>>>> +++ >>>>> b/src/share/classes/java/lang/**annotation/** >>>>> IncompleteAnnotationException.**java >>>>> >>>>> >>>>> @@ -55,9 +55,9 @@ >>>>> public IncompleteAnnotationException( >>>>> Class annotationType, >>>>> String elementName) { >>>>> -super(annotationType.getName()**.toString() + >>>>> +super(annotationType.getName() + >>>>> " missing element " + >>>>> - elementName.toString()); >>>>> + elementName); >>>>> >>>>> this.annotationType = annotationType; >>>>> this.elementName = elementName; >>>>> >>>>> >>>>> >> -- Atenciosamente. Otávio Gonçalves de Santana blog: http://otaviosantana.blogspot.com.br/ twitter: http://twitter.com/otaviojava site: http://www.otaviojava.com.br (11) 98255-3513
Re: 8015470: (ann) IncompleteAnnotationException does not need to call toString
Hello everyone my name is Otávio Santana and I do part of some Java user groups in Brazil, including SouJava. I know it is not an error, but an optimization. I have studying about OpenJDK and I hope help you. How I am a beginner in OpenJDK, I only can help with simple things like refactoring and clean-up, but I hope help always more and with complex code in the future. On Tue, May 28, 2013 at 10:08 AM, Remi Forax wrote: > On 05/28/2013 02:48 PM, David Holmes wrote: > >> Sorry it didn't register that getName() already returns a String - hence >> the toString() is redundant - but minimally so. >> >> David >> > > The second call to toString() also performs an implicit nullcheck > (elementName can not be null). > So if we have to fix something, it's only to remove the call to toString() > after the call to getName(). > > cheers, > Rémi > > > >> On 28/05/2013 9:15 PM, David Holmes wrote: >> >>> Please see my reply under your original subject line. >>> >>> This is not a bug. >>> >>> David >>> >>> On 28/05/2013 7:37 PM, Otávio Gonçalves de Santana wrote: >>> >>>> diff --git >>>> a/src/share/classes/java/lang/**annotation/** >>>> IncompleteAnnotationException.**java >>>> >>>> b/src/share/classes/java/lang/**annotation/** >>>> IncompleteAnnotationException.**java >>>> >>>> --- >>>> a/src/share/classes/java/lang/**annotation/** >>>> IncompleteAnnotationException.**java >>>> >>>> +++ >>>> b/src/share/classes/java/lang/**annotation/** >>>> IncompleteAnnotationException.**java >>>> >>>> @@ -55,9 +55,9 @@ >>>> public IncompleteAnnotationException( >>>> Class annotationType, >>>> String elementName) { >>>> -super(annotationType.getName()**.toString() + >>>> +super(annotationType.getName() + >>>> " missing element " + >>>> - elementName.toString()); >>>> + elementName); >>>> >>>> this.annotationType = annotationType; >>>> this.elementName = elementName; >>>> >>>> >>>> > -- Atenciosamente. Otávio Gonçalves de Santana blog: http://otaviosantana.blogspot.com.br/ twitter: http://twitter.com/otaviojava site: http://www.otaviojava.com.br (11) 98255-3513
8015470: (ann) IncompleteAnnotationException does not need to call toString
diff --git a/src/share/classes/java/lang/annotation/IncompleteAnnotationException.java b/src/share/classes/java/lang/annotation/IncompleteAnnotationException.java --- a/src/share/classes/java/lang/annotation/IncompleteAnnotationException.java +++ b/src/share/classes/java/lang/annotation/IncompleteAnnotationException.java @@ -55,9 +55,9 @@ public IncompleteAnnotationException( Class annotationType, String elementName) { -super(annotationType.getName().toString() + +super(annotationType.getName() + " missing element " + - elementName.toString()); + elementName); this.annotationType = annotationType; this.elementName = elementName; -- Atenciosamente. Otávio Gonçalves de Santana blog: http://otaviosantana.blogspot.com.br/ twitter: http://twitter.com/otaviojava site: http://www.otaviojava.com.br (11) 98255-3513