<div class="__aliyun_email_body_block"><div  style="line-height:1.7;font-family:Microsoft Yahei;font-size:14.0px;color:#000000;"><div  style="clear:both;"><span >Hi team,</span></div><div  style="clear:both;"><br ><div  style="clear:both;">We encountered a crash due to a bad oop map.</div><div  style="clear:both;">The following steps can quickly reproduce the problem on JDK master on Linux x64:</div><div  style="clear:both;">1. Modify z_x86_64.ad and add 3 temporary registers of type rRegN to zLoadP(If this change is illegal, please let me know)</div><div  style="clear:both;">```</div><div  style="clear:both;">diff --git a/src/hotspot/cpu/x86/gc/z/z_x86_64.ad b/src/hotspot/cpu/x86/gc/z/z_x86_64.ad</div><div  style="clear:both;">index f3e19b41733..129c93d3da8 100644</div><div  style="clear:both;">--- a/src/hotspot/cpu/x86/gc/z/z_x86_64.ad</div><div  style="clear:both;">+++ b/src/hotspot/cpu/x86/gc/z/z_x86_64.ad</div><div  style="clear:both;">@@ -63,11 +63,11 @@ static void z_load_barrier_cmpxchg(MacroAssembler& _masm, const MachNode* node,</div><div  style="clear:both;">%}</div><div  style="clear:both;">// Load Pointer</div><div  style="clear:both;">-instruct zLoadP(rRegP dst, memory mem, rFlagsReg cr)</div><div  style="clear:both;">+instruct zLoadP(rRegP dst, memory mem, rRegN tmp1, rRegN tmp2, rRegN tmp3, rFlagsReg cr)</div><div  style="clear:both;">%{</div><div  style="clear:both;">  predicate(UseZGC && n->as_Load()->barrier_data() != 0);</div><div  style="clear:both;">  match(Set dst (LoadP mem));</div><div  style="clear:both;">-  effect(KILL cr, TEMP dst);</div><div  style="clear:both;">+  effect(KILL cr, TEMP dst, TEMP tmp1, TEMP tmp2, TEMP tmp3);</div><div  style="clear:both;">  ins_cost(125);</div><div  style="clear:both;">```</div><div  style="clear:both;">2. Run the following code (./build/linux-x86_64-server-fastdebug/images/jdk/bin/java -XX:-Inline -XX:CompileCommand=compileonly,Test::call -XX:+PrintAssembly -XX:PrintIdealGraphLevel=2 -XX:PrintIdealGraphFile=call.xml -XX:+UseZGC -XX:+UseNewCode -XX:+PrintGC -Xmx500m -Xms500m -XX:-Inline Test)</div><div  style="clear:both;">```</div><div  style="clear:both;">import java.util.concurrent.locks.Lock;</div><div  style="clear:both;">import java.util.concurrent.locks.ReentrantLock;</div><div  style="clear:both;">class Test {</div><div  style="clear:both;">  private Lock lock = new ReentrantLock();</div><div  style="clear:both;">  public static void main(String... args) throws Exception {</div><div  style="clear:both;">    new Thread(() -> {</div><div  style="clear:both;">      while (true) {</div><div  style="clear:both;">        byte[] b = new byte[10 * 1024 * 1024];</div><div  style="clear:both;">      }</div><div  style="clear:both;">    }).start();</div><div  style="clear:both;">    while (true) {</div><div  style="clear:both;">      new Test().call(() -> { new Object(); });</div><div  style="clear:both;">    }</div><div  style="clear:both;">  }</div><div  style="clear:both;">  public void call(Runnable cb) {</div><div  style="clear:both;">    lock.lock();</div><div  style="clear:both;">    try {</div><div  style="clear:both;">      cb.run();</div><div  style="clear:both;">    } finally {</div><div  style="clear:both;">      lock.unlock();</div><div  style="clear:both;">    }</div><div  style="clear:both;">  }</div><div  style="clear:both;">}</div><div  style="clear:both;">```</div><div  style="clear:both;"><br ></div><div  style="clear:both;">It can be observed through the IGV Final Code that zLoadP(202, 204) and a MachTemp(81) it uses are placed in different blocks. When processing CallStaticJavaDirect(74) in the c2 buildOopMap step, MachTemp(81) is considered to be alive. Because the register type specified by the above modification is rRegN (if it is specified as rRegI or rRegP, no crash will occur), so the type of MachTemp(81) is narrowOop, which will eventually be added to the oopMap of CallStaticJavaDirect(74). But logically, zLoadP doesn't depend on the original value of MachTemp(81), so I don't think it should be added to oopMap.</div><div  style="clear:both;"><br ></div><div  style="clear:both;">I put the ideal graph file to <a  href="http://cr.openjdk.java.net/~ddong/call.xml" target="_blank">http://cr.openjdk.java.net/~ddong/call.xml</a></div><div  style="clear:both;"><br ></div><div  style="clear:both;">I think the problem may lie in two places:</div><div  style="clear:both;">1. gcm and regAlloc do not put MachTemp(81) in the correct location</div><div  style="clear:both;">2. buildOopMap should not treat MachTemp as Oop because its original value is meaningless</div><div  style="clear:both;"><br ></div><div  style="clear:both;">I'm not a JIT expert and sorry if there is anything unnatural or non-standard in the above description.</div><div  style="clear:both;"><br ></div><div  style="clear:both;">Any input is appreciated.</div><div  style="clear:both;"><br ></div><span >Denghui Dong</span></div></div></div>