<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=utf-8"><meta name=Generator content="Microsoft Word 12 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:Tahoma;
panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
{font-family:Consolas;
panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
pre
{mso-style-priority:99;
mso-style-link:"HTML Preformatted Char";
margin:0in;
margin-bottom:.0001pt;
font-size:10.0pt;
font-family:"Courier New";}
p.MsoAcetate, li.MsoAcetate, div.MsoAcetate
{mso-style-priority:99;
mso-style-link:"Balloon Text Char";
margin:0in;
margin-bottom:.0001pt;
font-size:8.0pt;
font-family:"Tahoma","sans-serif";}
span.HTMLPreformattedChar
{mso-style-name:"HTML Preformatted Char";
mso-style-priority:99;
mso-style-link:"HTML Preformatted";
font-family:Consolas;}
span.BalloonTextChar
{mso-style-name:"Balloon Text Char";
mso-style-priority:99;
mso-style-link:"Balloon Text";
font-family:"Tahoma","sans-serif";}
span.EmailStyle21
{mso-style-type:personal;
font-family:"Calibri","sans-serif";
color:#1F497D;}
span.EmailStyle22
{mso-style-type:personal;
font-family:"Calibri","sans-serif";
color:#1F497D;}
span.EmailStyle23
{mso-style-type:personal-reply;
font-family:"Calibri","sans-serif";
color:#1F497D;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-US link=blue vlink=purple><div class=WordSection1><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Bernd,<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Are you ok with the explanation and existing changes ?<o:p></o:p></span></p><div><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:#1F497D'>-Sharath Ballal<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p></div><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><div><div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in'><p class=MsoNormal><b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>From:</span></b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'> Sharath Ballal <br><b>Sent:</b> Friday, November 11, 2016 12:17 PM<br><b>To:</b> Bernd Eckenfels; serviceability-dev@openjdk.java.net<br><b>Subject:</b> RE: RFR: JDK-7107013: sun.jvm.hotspot.runtime.Bytes.swapLong conversion to long mishandled<o:p></o:p></span></p></div></div><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Hello Bernd,<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal>45 return (short) (((x >> 8) & 0xFF) | (x << 8));<span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Or<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>return (short)((x << 8) | ((x >> 8) & 0xFF));<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>In the above two lines of code, whichever you choose to write, they both will give the same result. Short will be implicitly converted to int and then the operation will take place.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>If you write the code as below (to make it consistent with int and long), you will get an error saying “possible lossy conversion from int to short†<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>return ((short) (x << 8) | ((x >> 8) & 0xFF));<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>or<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>return ((short) (x << 8) | (short)((x >> 8) & 0xFF));<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>So an explicit cast will be required in both the above cases.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Let me know if you would want to see the code changed to “return (short)((x << 8) | ((x >> 8) & 0xFF));†to make it look consistent with the rest of the code.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>(Since I was not in to/cc, it took me longer to see the mail)<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><div><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:#1F497D'>-Sharath Ballal<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p></div><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><div><div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in'><p class=MsoNormal><b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>From:</span></b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'> Bernd Eckenfels [<a href="mailto:ecki@zusammenkunft.net">mailto:ecki@zusammenkunft.net</a>] <br><b>Sent:</b> Thursday, November 10, 2016 2:12 PM<br><b>To:</b> <a href="mailto:serviceability-dev@openjdk.java.net">serviceability-dev@openjdk.java.net</a><br><b>Subject:</b> Re: RFR: JDK-7107013: sun.jvm.hotspot.runtime.Bytes.swapLong conversion to long mishandled<o:p></o:p></span></p></div></div><p class=MsoNormal><o:p> </o:p></p><div><p class=MsoNormal>Hello, I was talking about the code order not the semantics:<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal> 45 return (short) (((x >> 8) & 0xFF) | (x << 8));<o:p></o:p></p></div><div><p class=MsoNormal> 54 return ((int)swapShort((short) x) << 16) | (swapShort((short) (x >> 16)) & 0xFFFF);<o:p></o:p></p></div><div><p class=MsoNormal> 63 return ((long)swapInt((int) x) << 32) | (swapInt((int) (x >> 32)) & 0xFFFFFFFF);<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>In 45 the Low half is expressed first (and no masking) in 54 and 63 the MSB half is expressed first.<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>I guess casting and masking and order should be the same for all 3?<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p><div><p class=MsoNormal>Gruss<br>Bernd<br>-- <br><a href="http://bernd.eckenfels.net">http://bernd.eckenfels.net</a><o:p></o:p></p></div><p class=MsoNormal><o:p> </o:p></p></div><p class=MsoNormal style='margin-bottom:12.0pt'><o:p> </o:p></p><div><p class=MsoNormal style='margin-bottom:12.0pt'>On Thu, Nov 10, 2016 at 9:30 AM +0100, "Sharath Ballal" <<a href="mailto:sharath.ballal@oracle.com" target="_blank">sharath.ballal@oracle.com</a>> wrote:<o:p></o:p></p><div><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Hello Bernd,</span><o:p></o:p></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'> </span><o:p></o:p></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>For int also its “low 2 bytes | high 2 bytes†and again these two byte pairs are swapped by the swapshort as “lowbyte | highbyteâ€</span><o:p></o:p></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Similarly for long its “ low 4 bytes | high 4 bytes†and again these pairs are swapped recursively.</span><o:p></o:p></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'> </span><o:p></o:p></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>So for int if the little endian byte order was 3 2 1 0 it is now converted to 0 1 2 3 and similarly for long.</span><o:p></o:p></p><div><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:#1F497D'> </span><o:p></o:p></p><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:#1F497D'>-Sharath Ballal</span><o:p></o:p></p><p class=MsoNormal><span style='font-family:"Calibri","sans-serif";color:#1F497D'> </span><o:p></o:p></p></div><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'> </span><o:p></o:p></p><div><div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in'><p class=MsoNormal><b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>From:</span></b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'> Bernd Eckenfels [<a href="mailto:ecki@zusammenkunft.net">mailto:ecki@zusammenkunft.net</a>] <br><b>Sent:</b> Thursday, November 10, 2016 1:20 PM<br><b>To:</b> <a href="mailto:serviceability-dev@openjdk.java.net">serviceability-dev@openjdk.java.net</a>; Dmitry Samersoff; Sharath Ballal<br><b>Subject:</b> Re: RFR: JDK-7107013: sun.jvm.hotspot.runtime.Bytes.swapLong conversion to long mishandled</span><o:p></o:p></p></div></div><p class=MsoNormal> <o:p></o:p></p><div><p class=MsoNormal>Hello,<o:p></o:p></p></div><div><p class=MsoNormal> <o:p></o:p></p></div><div><p class=MsoNormal style='margin-bottom:12.0pt'>Is the a reason why swapShort has a " lowbyte | highbyyte" and the other two methods the other way around? I would all write in the natural order of. Igendianess (I.e. Change the first).<o:p></o:p></p><div><p class=MsoNormal>Gruss<br>Bernd<br>-- <br><a href="http://bernd.eckenfels.net">http://bernd.eckenfels.net</a><o:p></o:p></p></div><p class=MsoNormal> <o:p></o:p></p></div><p class=MsoNormal style='margin-bottom:12.0pt'><br><br><o:p></o:p></p><div><p class=MsoNormal style='margin-bottom:12.0pt'>On Thu, Nov 10, 2016 at 8:32 AM +0100, "Sharath Ballal" <<a href="mailto:sharath.ballal@oracle.com" target="_blank">sharath.ballal@oracle.com</a>> wrote:<o:p></o:p></p><div><pre>Thanks Dmitry. I have made the changes in line 54.<o:p></o:p></pre><pre><a href="http://cr.openjdk.java.net/~sballal/7107013/webrev.01/">http://cr.openjdk.java.net/~sballal/7107013/webrev.01/</a> <o:p></o:p></pre><pre> <o:p></o:p></pre><pre>I didn't change the recursive calls to swap functions because that looks more readable.<o:p></o:p></pre><pre> <o:p></o:p></pre><pre>-Sharath Ballal<o:p></o:p></pre><pre> <o:p></o:p></pre><pre> <o:p></o:p></pre><pre>-----Original Message-----<o:p></o:p></pre><pre>From: Dmitry Samersoff <o:p></o:p></pre><pre>Sent: Thursday, November 10, 2016 12:46 AM<o:p></o:p></pre><pre>To: Sharath Ballal; <a href="mailto:serviceability-dev@openjdk.java.net">serviceability-dev@openjdk.java.net</a><o:p></o:p></pre><pre>Subject: Re: RFR: JDK-7107013: sun.jvm.hotspot.runtime.Bytes.swapLong conversion to long mishandled<o:p></o:p></pre><pre> <o:p></o:p></pre><pre>Sharath,<o:p></o:p></pre><pre> <o:p></o:p></pre><pre>Please, add (int) to ll. 54 for better readability.<o:p></o:p></pre><pre> <o:p></o:p></pre><pre>PS:<o:p></o:p></pre><pre> <o:p></o:p></pre><pre>Despite the fact that C2 does a great job eliminating useless code (multiple calls to if (!swap) in this case) it would be nice to use simple, well known arithmetic directly instead of subsequent calls to other swap functions.<o:p></o:p></pre><pre> <o:p></o:p></pre><pre>-Dmitry<o:p></o:p></pre><pre> <o:p></o:p></pre><pre>On 2016-11-09 19:30, Sharath Ballal wrote:<o:p></o:p></pre><pre>> Hello,<o:p></o:p></pre><pre>> <o:p></o:p></pre><pre>> Pls review this small fix<o:p></o:p></pre><pre>> <o:p></o:p></pre><pre>> <o:p></o:p></pre><pre>> <o:p></o:p></pre><pre>> Issue: <a href="https://bugs.openjdk.java.net/browse/JDK-7107013">https://bugs.openjdk.java.net/browse/JDK-7107013</a><o:p></o:p></pre><pre>> <o:p></o:p></pre><pre>> Webrev: <a href="http://cr.openjdk.java.net/~sballal/7107013/webrev.00/">http://cr.openjdk.java.net/~sballal/7107013/webrev.00/</a><o:p></o:p></pre><pre>> <o:p></o:p></pre><pre>> <o:p></o:p></pre><pre>> <o:p></o:p></pre><pre>> <o:p></o:p></pre><pre>> <o:p></o:p></pre><pre>> -Sharath Ballal<o:p></o:p></pre><pre>> <o:p></o:p></pre><pre>> <o:p></o:p></pre><pre>> <o:p></o:p></pre><pre>> <o:p></o:p></pre><pre>> <o:p></o:p></pre><pre> <o:p></o:p></pre><pre> <o:p></o:p></pre><pre>--<o:p></o:p></pre><pre>Dmitry Samersoff<o:p></o:p></pre><pre>Oracle Java development team, Saint Petersburg, Russia<o:p></o:p></pre><pre>* I would love to change the world, but they won't give me the sources.<o:p></o:p></pre></div></div></div></div></div></body></html>