How to use PRINT_REG to debug C1 compiler's logical issue?

Leslie Zhai lesliezhai at llvm.org.cn
Fri May 11 07:33:24 UTC 2018


Hi HotSpot developers,

Thanks for your teaching[1], I am familiar with debugging C1 compiler's 
internal error now, but unlike segfault, it is much more difficult to 
catch the bugs for logical issues, for example, wrongly use LD/ST 
instructions for T_INT type, then it failed to handle the negative 
number, and it might be lead ArrayIndexOutOfBoundsException or 
StringIndexOutOfBoundsException. So PRINT_REG[2] is very helpful to 
monitor the value of GP or FP for checking whether or not there is a 
logical issue, `print_reg_helper(REG, MSG)` prototype might work as:


33596  271    b  3       java.nio.Buffer::<init> (121 bytes)
=============== DEBUG MESSAGE: reg2reg T_INT ================
GP1: ffffffffffffffff
=============== DEBUG MESSAGE: reg2reg T_INT ================
GP2: 0
=============== DEBUG MESSAGE: reg2reg T_INT ================
GP3: cf
=============== DEBUG MESSAGE: reg2reg T_INT ================
GP4: 2000
   33839  272    b  4       java.nio.Buffer::<init> (121 bytes)
   33861  271       3       java.nio.Buffer::<init> (121 bytes)   made 
not entrant
=============== DEBUG MESSAGE: lir_cond_greaterEqual opr1 ================
GP4: 2000
=============== DEBUG MESSAGE: lir_cond_less opr1 ================
GP4: 2000
=============== DEBUG MESSAGE: reg2reg T_INT ================
GP5: cf
   33861  273    b  3       java.nio.Buffer::limit (62 bytes)
=============== DEBUG MESSAGE: reg2reg T_INT ================
GP1: cf
   33892  274    b  4       java.nio.Buffer::limit (62 bytes)
   33908  273       3       java.nio.Buffer::limit (62 bytes) made not 
entrant
=============== DEBUG MESSAGE: lir_cond_greater print reg_op2 opr1 and 
opr2 ================
GP2: 2000
=============== DEBUG MESSAGE: lir_cond_greater print reg_op1 opr1 and 
opr2 ================
GP1: cf
=============== DEBUG MESSAGE: lir_cond_greater print reg_op2 opr1 and 
opr2 ================
GP2: 2000
=============== DEBUG MESSAGE: lir_cond_greater print reg_op1 opr1 and 
opr2 ================
GP1: cf
=============== DEBUG MESSAGE: lir_cond_greaterEqual opr1 ================
GP1: cf
=============== DEBUG MESSAGE: lir_cond_less opr1 ================
GP1: cf
   33909  275    b  3       java.nio.Buffer::position (43 bytes)
=============== DEBUG MESSAGE: reg2reg T_INT ================
GP1: 0
   33933  276    b  4       java.nio.Buffer::position (43 bytes)
   33946  275       3       java.nio.Buffer::position (43 bytes) made 
not entrant
=============== DEBUG MESSAGE: lir_cond_greater print reg_op2 opr1 and 
opr2 ================
GP2: cf
=============== DEBUG MESSAGE: lir_cond_greater print reg_op1 opr1 and 
opr2 ================
GP1: 0
=============== DEBUG MESSAGE: lir_cond_greater print reg_op2 opr1 and 
opr2 ================
GP2: cf
=============== DEBUG MESSAGE: lir_cond_greater print reg_op1 opr1 and 
opr2 ================
GP1: 0
=============== DEBUG MESSAGE: lir_cond_greaterEqual opr1 ================
GP1: 0
=============== DEBUG MESSAGE: lir_cond_less opr1 ================
GP1: 0
=============== DEBUG MESSAGE: lir_cond_less opr1 ================
GP1: ffffffffffffffff
=============== DEBUG MESSAGE: lir_cond_less opr1 ================
GP0: ffe70c8388 <-- it might be wrong
=============== DEBUG MESSAGE: lir_cond_greater print reg_op2 opr1 and 
opr2 ================
GP2: 0
=============== DEBUG MESSAGE: lir_cond_greater print reg_op1 opr1 and 
opr2 ================
GP0: ffe70c8388 <-- it might be wrong
=============== DEBUG MESSAGE: reg2reg T_INT ================
GP1: 12
=============== DEBUG MESSAGE: reg2reg T_INT ================
GP0: 12
=============== DEBUG MESSAGE: reg2reg T_INT ================
GP1: 22
=============== DEBUG MESSAGE: reg2reg T_INT ================
GP2: 22
=============== DEBUG MESSAGE: reg2reg T_INT ================
GP2: 22
=============== DEBUG MESSAGE: lir_cond_greater print reg_op2 opr1 and 
opr2 ================
GP1: 22
=============== DEBUG MESSAGE: lir_cond_greater print reg_op1 opr1 and 
opr2 ================
GP0: 10
...


But it can't 100% prove that emit_opBranch's left operator is wrong even 
that they are the same DEBUG MESSAGE:


   ;;  134 branch [LT] [GP0|I] [int:0|I] [B4]
   ;; DEBUG: lir_cond_less opr1 is_single_cpu
   0x0000000000a30798: ...


It is just able to find there might be a logical issue, but not able to 
confirm *WHERE* might lead the issue, please share your experience to 
debug C1 compiler's logical issue, thanks a lot!


[1] 
http://mail.openjdk.java.net/pipermail/hotspot-compiler-dev/2018-March/028566.html
[2] 
http://hg.openjdk.java.net/jdk/jdk/file/0611aa1568ef/src/hotspot/cpu/x86/macroAssembler_x86.cpp#l904

-- 
Regards,
Leslie Zhai





More information about the hotspot-compiler-dev mailing list