By QIvan

2019-01-05 18:09:14 8 Comments

I got the below assembly list as result for JIT compilation for my java program.

mov    0x14(%rsp),%r10d
inc    %r10d              

mov    0x1c(%rsp),%r8d
inc    %r8d               

test   %eax,(%r11)         ; <--- this instruction

mov    (%rsp),%r9
mov    0x40(%rsp),%r14d
mov    0x18(%rsp),%r11d
mov    %ebp,%r13d
mov    0x8(%rsp),%rbx
mov    0x20(%rsp),%rbp
mov    0x10(%rsp),%ecx
mov    0x28(%rsp),%rax    

movzbl 0x18(%r9),%edi     
movslq %r8d,%rsi          

cmp    0x30(%rsp),%rsi
jge    0x00007fd3d27c4f17 

My understanding the test instruction is useless here because the main idea of the test is

The flags SF, ZF, PF are modified while the result of the AND is discarded.

and here we don't use these result flags.

Is it a bug in JIT or do I miss something? If it is, where the best place for reporting it? Thanks!


@Aleksey Shipilev 2019-01-05 19:07:55

That must be the thread-local handshake poll. Look where %r11 is read from. If it is read from some offset off the %r15 (thread-local storage), that's the guy. See the example here:

  0.31%  ↗  ...70: movzbl 0x94(%r9),%r10d    
  0.19%  │  ...78: mov    0x108(%r15),%r11  ; read the thread-local page addr
 25.62%  │  ...7f: add    $0x1,%rbp          
 35.10%  │  ...83: test   %eax,(%r11)       ; thread-local handshake poll
 34.91%  │  ...86: test   %r10d,%r10d
         ╰  ...89: je     ...70

It is not useless, it would cause SEGV once the guard page is marked non-readable, and that would transfer control to JVM's SEGV handler. This is part of JVM's mechanics to safepoint Java threads, e.g. for GC.

UPD: Hopefully, more details here.

Related Questions

Sponsored Content

33 Answered Questions

[SOLVED] How do you assert that a certain exception is thrown in JUnit 4 tests?

14 Answered Questions

[SOLVED] What's the purpose of the LEA instruction?

11 Answered Questions

1 Answered Questions

[SOLVED] Tracing call stack in disassembled code

2 Answered Questions

[SOLVED] Why doesn't the JVM emit prefetch instructions on Windows x86

1 Answered Questions

[SOLVED] Does AMD have different CPU registers? How is "rax" different from "eax"?

4 Answered Questions

2 Answered Questions

[SOLVED] llvm jit windows 8.1

0 Answered Questions

JVM crash reason

  • 2013-07-05 07:25:55
  • wendli
  • 657 View
  • 0 Score
  • 0 Answer
  • Tags:   java assembly jvm

2 Answered Questions

Sponsored Content