-
Enhancement
-
Resolution: Unresolved
-
P4
-
7, 9, 10
-
x86
-
generic
A DESCRIPTION OF THE REQUEST :
See source code and disassembly below.
Copying an int value to a byte[] in java code is only declarable in subsequent byte copies
I guess, copying the 4 bytes could be done at once after HotSpot compilation.
JUSTIFICATION :
I guess, copying the 4 bytes at once would be much faster, and save footprint.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The source code could be compiled to something like:
mov 0x24(%esp),%edi
..
mov %eax,%ebx
bswap %ebx ; only little-endian architectures
mov 0x20(%esp),%esi
mov 0x8(%esi),%edx ; implicit exception: dispatches to 0x00ba49e4
cmp %edx,%edi
jae 0x00ba49a5
mov 0x24(%esp),%ebp
add $0x3,%ebp
cmp %edx,%ebp
jae 0x00ba49c1
mov %ebx,0xc(%esi,%edi,4) ;*bastore
...
ACTUAL -
Output from disassembly:
0x00ba48d6: mov 0x24(%esp),%edi
...
0x00ba492a: mov %eax,%ebx
0x00ba492c: sar $0x18,%ebx ;*ishr
; - sun.nio.cs.ext.EUC_TW_C_d_b_c1_f3_shortMap4$Encoder::encode@93 (line 491)
0x00ba492f: mov 0x20(%esp),%esi
0x00ba4933: mov 0x8(%esi),%edx ; implicit exception: dispatches to 0x00ba49e4
0x00ba4936: cmp %edx,%edi
0x00ba4938: jae 0x00ba49a5
0x00ba493a: mov %bl,0xc(%esi,%edi,1) ;*bastore
; - sun.nio.cs.ext.EUC_TW_C_d_b_c1_f3_shortMap4$Encoder::encode@95 (line 491)
0x00ba493e: mov 0x24(%esp),%ebp
0x00ba4942: add $0x3,%ebp
0x00ba4945: mov %eax,%ecx
0x00ba4947: sar $0x10,%ecx ;*ishr
; - sun.nio.cs.ext.EUC_TW_C_d_b_c1_f3_shortMap4$Encoder::encode@104 (line 492)
0x00ba494a: cmp %edx,%ebp
0x00ba494c: jae 0x00ba49c1
0x00ba494e: mov %cl,0xd(%esi,%edi,1) ;*bastore
; - sun.nio.cs.ext.EUC_TW_C_d_b_c1_f3_shortMap4$Encoder::encode@106 (line 492)
0x00ba4952: mov %eax,%ebx
0x00ba4954: sar $0x8,%ebx
0x00ba4957: mov %bl,0xe(%esi,%edi,1) ;*bastore
; - sun.nio.cs.ext.EUC_TW_C_d_b_c1_f3_shortMap4$Encoder::encode@117 (line 493)
0x00ba495b: mov %al,0xf(%esi,%edi,1) ;*bastore
; - sun.nio.cs.ext.EUC_TW_C_d_b_c1_f3_shortMap4$Encoder::encode@125 (line 494)
...
Complete output here (line 2497):
https://java-nio-charset-enhanced.dev.java.net/source/browse/java-nio-charset-enhanced/branches/j7_EUC_TW/log/C_d_b_c1_f3_shortMap4_PA_2.xml?rev=888&view=markup
---------- BEGIN SOURCE ----------
In my code I have following snippet:
byte[] da = ...;
int dp = ...;
int qb = ...;
da[dp+3] = (byte)qb;
da[dp+2] = (byte)(qb >> 8);
da[dp+1] = (byte)(qb >> 16);
da[dp+0] = (byte)(qb >> 24);
Complete source code (line 451):
https://java-nio-charset-enhanced.dev.java.net/source/browse/java-nio-charset-enhanced/branches/j7_EUC_TW/src/sun/nio/cs/ext/EUC_TW_C_d_b_c1_f3_shortMap4.java?rev=888
Complete project:
https://java-nio-charset-enhanced.dev.java.net/source/browse/java-nio-charset-enhanced/branches/j7_EUC_TW?rev=888
Run from NetBeans 6.8 using:
https://java-nio-charset-enhanced.dev.java.net/source/browse/java-nio-charset-enhanced/branches/j7_EUC_TW/nbproject/configs/C_d_b_c1_f3_shortMap4_PA.properties?rev=887&view=markup
---------- END SOURCE ----------
See source code and disassembly below.
Copying an int value to a byte[] in java code is only declarable in subsequent byte copies
I guess, copying the 4 bytes could be done at once after HotSpot compilation.
JUSTIFICATION :
I guess, copying the 4 bytes at once would be much faster, and save footprint.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The source code could be compiled to something like:
mov 0x24(%esp),%edi
..
mov %eax,%ebx
bswap %ebx ; only little-endian architectures
mov 0x20(%esp),%esi
mov 0x8(%esi),%edx ; implicit exception: dispatches to 0x00ba49e4
cmp %edx,%edi
jae 0x00ba49a5
mov 0x24(%esp),%ebp
add $0x3,%ebp
cmp %edx,%ebp
jae 0x00ba49c1
mov %ebx,0xc(%esi,%edi,4) ;*bastore
...
ACTUAL -
Output from disassembly:
0x00ba48d6: mov 0x24(%esp),%edi
...
0x00ba492a: mov %eax,%ebx
0x00ba492c: sar $0x18,%ebx ;*ishr
; - sun.nio.cs.ext.EUC_TW_C_d_b_c1_f3_shortMap4$Encoder::encode@93 (line 491)
0x00ba492f: mov 0x20(%esp),%esi
0x00ba4933: mov 0x8(%esi),%edx ; implicit exception: dispatches to 0x00ba49e4
0x00ba4936: cmp %edx,%edi
0x00ba4938: jae 0x00ba49a5
0x00ba493a: mov %bl,0xc(%esi,%edi,1) ;*bastore
; - sun.nio.cs.ext.EUC_TW_C_d_b_c1_f3_shortMap4$Encoder::encode@95 (line 491)
0x00ba493e: mov 0x24(%esp),%ebp
0x00ba4942: add $0x3,%ebp
0x00ba4945: mov %eax,%ecx
0x00ba4947: sar $0x10,%ecx ;*ishr
; - sun.nio.cs.ext.EUC_TW_C_d_b_c1_f3_shortMap4$Encoder::encode@104 (line 492)
0x00ba494a: cmp %edx,%ebp
0x00ba494c: jae 0x00ba49c1
0x00ba494e: mov %cl,0xd(%esi,%edi,1) ;*bastore
; - sun.nio.cs.ext.EUC_TW_C_d_b_c1_f3_shortMap4$Encoder::encode@106 (line 492)
0x00ba4952: mov %eax,%ebx
0x00ba4954: sar $0x8,%ebx
0x00ba4957: mov %bl,0xe(%esi,%edi,1) ;*bastore
; - sun.nio.cs.ext.EUC_TW_C_d_b_c1_f3_shortMap4$Encoder::encode@117 (line 493)
0x00ba495b: mov %al,0xf(%esi,%edi,1) ;*bastore
; - sun.nio.cs.ext.EUC_TW_C_d_b_c1_f3_shortMap4$Encoder::encode@125 (line 494)
...
Complete output here (line 2497):
https://java-nio-charset-enhanced.dev.java.net/source/browse/java-nio-charset-enhanced/branches/j7_EUC_TW/log/C_d_b_c1_f3_shortMap4_PA_2.xml?rev=888&view=markup
---------- BEGIN SOURCE ----------
In my code I have following snippet:
byte[] da = ...;
int dp = ...;
int qb = ...;
da[dp+3] = (byte)qb;
da[dp+2] = (byte)(qb >> 8);
da[dp+1] = (byte)(qb >> 16);
da[dp+0] = (byte)(qb >> 24);
Complete source code (line 451):
https://java-nio-charset-enhanced.dev.java.net/source/browse/java-nio-charset-enhanced/branches/j7_EUC_TW/src/sun/nio/cs/ext/EUC_TW_C_d_b_c1_f3_shortMap4.java?rev=888
Complete project:
https://java-nio-charset-enhanced.dev.java.net/source/browse/java-nio-charset-enhanced/branches/j7_EUC_TW?rev=888
Run from NetBeans 6.8 using:
https://java-nio-charset-enhanced.dev.java.net/source/browse/java-nio-charset-enhanced/branches/j7_EUC_TW/nbproject/configs/C_d_b_c1_f3_shortMap4_PA.properties?rev=887&view=markup
---------- END SOURCE ----------
- blocks
-
JDK-8158786 ZIP libraries could benefit from new intrinsic accessors to byte arrays
- Open
-
JDK-8026049 (bf) Intrinsify ByteBuffer.put{Int,Double,Float,...} methods
- Resolved