For the next code:
void test (A new_next) {
A prev_next = a.next;
a.next = new_next;
if (prev_next == null) {
a.n = a.get_n();
}
}
C2 prodes next incorrect assembler code (64 bit x86) with Zero based COOP produces:
02c movl RBP, [RSI + #12 (8-bit)] # compressed ptr ! Field Test.a
030 cmpl R12, [R12 + RBP << 3 + #16] (compressed oop addressing) # compressed ptr (R12_heapbase==0)
035 NullCheck RBP
035
035 B2: # B4 B3 <- B1 Freq: 0.999999
035 decode_heap_oop_not_null RSI,RBP
039 encode_heap_oop R11,RDX
040 movl [R12 + RBP << 3 + #16] (compressed oop addressing), R11 # compressed ptr ! Field A.next
045 movq R10, RSI # ptr -> long
048 shrq R10, #9
04c movq R11, 0xfffffd7ff4a1c000 # ptr
056 movb [R11 + R10], R12 # short/char (R12_heapbase==0)
05a cmpl R12, [R12 + RBP << 3 + #16] (compressed oop addressing) # compressed ptr (R12_heapbase==0)
05f je,s B4 P=0.100000 C=-1.000000
05f
The test in 05a checks wrong (new_next) value.
% /java/re/jdk/6u21/latest/binaries/solaris-amd64/bin/java -d64 -XX:+UseCompressedOops -XX:+UnlockDiagnosticVMOptions -XX:+PrintCompressedOopsMode -Xbatch -XX:+PrintCompilation -Xcomp -XX:CompileOnly=Test Test
heap address: 0x00000003fc800000, zero based Compressed Oops
1 b Test::main (91 bytes)
1 made not entrant Test::main (91 bytes)
2 b Test::<init> (5 bytes)
3 b Test::test (35 bytes)
Wrong value: 1 expected: 2
I will include the test into the C2 regression tests.