On 02/17/2015 10:53 AM, Andrew Haley wrote:
> I see. So the question could also be whether escape analysis would
> notice that a ByteBuffer does not escape. I hope to know that soon.
Close but no cigar.
long getLong(byte[] bytes, int i) {
return ByteBuffer.wrap(bytes).getLong(i);
}
Everything gets inlined nicely and the ByteBuffer is not created, but
a store fence remains because of the final fields in HeapByteBuffer.
So the resulting code for getLong (minus the prologue and epilogue) looks like
this:
0x000003ff7426dc34: ldr w11, [x2,#12] ;*arraylength
; - java.nio.ByteBuffer::wrap@3
(line 396)
; -
bytebuffertests.ByteBufferTests3::getLong@1 (line 23)
; implicit exception:
dispatches to 0x000003ff7426dca4
;; B2: # B5 B3 <- B1 Freq: 0.999999
0x000003ff7426dc38: dmb ish ;*synchronization entry
; -
java.nio.HeapByteBuffer::<init>@-1 (line 84)
; - java.nio.ByteBuffer::wrap@7
(line 373)
; - java.nio.ByteBuffer::wrap@4
(line 396)
; -
bytebuffertests.ByteBufferTests3::getLong@1 (line 23)
0x000003ff7426dc3c: sub w12, w11, w3 ;*isub
; -
java.nio.Buffer::checkIndex@10 (line 545)
; -
java.nio.HeapByteBuffer::getLong@18 (line 465)
; -
bytebuffertests.ByteBufferTests3::getLong@5 (line 23)
0x000003ff7426dc40: cmp w3, #0x0
0x000003ff7426dc44: b.lt 0x000003ff7426dc70 ;*iflt
; -
java.nio.Buffer::checkIndex@1 (line 545)
; -
java.nio.HeapByteBuffer::getLong@18 (line 465)
; -
bytebuffertests.ByteBufferTests3::getLong@5 (line 23)
;; B3: # B6 B4 <- B2 Freq: 0.999999
0x000003ff7426dc48: cmp w12, #0x8
0x000003ff7426dc4c: b.lt 0x000003ff7426dc88 ;*if_icmple
; -
java.nio.Buffer::checkIndex@11 (line 545)
; -
java.nio.HeapByteBuffer::getLong@18 (line 465)
; -
bytebuffertests.ByteBufferTests3::getLong@5 (line 23)
;; B4: # N92 <- B3 Freq: 0.999998
0x000003ff7426dc50: add x10, x2, w3, sxtw
0x000003ff7426dc54: ldr x10, [x10,#16]
0x000003ff7426dc58: rev x0, x10 ;*invokestatic reverseBytes
; - java.nio.Bits::swap@1 (line
61)
; -
java.nio.HeapByteBuffer::getLong@41 (line 466)
; -
bytebuffertests.ByteBufferTests3::getLong@5 (line 23)
If it weren't for the stray DMB ISH it'd be almost perfect.
Andrew.