8206075: On x86, assert on unbound assembler Labels used as branch targets
authorkvn
Fri, 20 Jul 2018 11:55:05 -0700
changeset 51178 416a76fe8067
parent 51177 ae39ec0b0502
child 51179 516acf6956a2
8206075: On x86, assert on unbound assembler Labels used as branch targets Reviewed-by: kvn, mdoerr, phh Contributed-by: xxinliu@amazon.com
src/hotspot/cpu/x86/interp_masm_x86.cpp
src/hotspot/cpu/x86/templateTable_x86.cpp
src/hotspot/share/asm/assembler.hpp
src/hotspot/share/c1/c1_LIRAssembler.hpp
--- a/src/hotspot/cpu/x86/interp_masm_x86.cpp	Wed Jul 18 00:23:06 2018 -0700
+++ b/src/hotspot/cpu/x86/interp_masm_x86.cpp	Fri Jul 20 11:55:05 2018 -0700
@@ -1963,7 +1963,9 @@
   incrementl(scratch, increment);
   movl(counter_addr, scratch);
   andl(scratch, mask);
-  jcc(cond, *where);
+  if (where != NULL) {
+    jcc(cond, *where);
+  }
 }
 
 void InterpreterMacroAssembler::notify_method_entry() {
--- a/src/hotspot/cpu/x86/templateTable_x86.cpp	Wed Jul 18 00:23:06 2018 -0700
+++ b/src/hotspot/cpu/x86/templateTable_x86.cpp	Fri Jul 20 11:55:05 2018 -0700
@@ -2227,8 +2227,8 @@
         const Address mdo_backedge_counter(rbx, in_bytes(MethodData::backedge_counter_offset()) +
                                            in_bytes(InvocationCounter::counter_offset()));
         const Address mask(rbx, in_bytes(MethodData::backedge_mask_offset()));
-        __ increment_mask_and_jump(mdo_backedge_counter, increment, mask,
-                                   rax, false, Assembler::zero, &backedge_counter_overflow);
+        __ increment_mask_and_jump(mdo_backedge_counter, increment, mask, rax, false, Assembler::zero,
+                                   UseOnStackReplacement ? &backedge_counter_overflow : NULL);
         __ jmp(dispatch);
       }
       __ bind(no_mdo);
@@ -2236,7 +2236,8 @@
       __ movptr(rcx, Address(rcx, Method::method_counters_offset()));
       const Address mask(rcx, in_bytes(MethodCounters::backedge_mask_offset()));
       __ increment_mask_and_jump(Address(rcx, be_offset), increment, mask,
-                                 rax, false, Assembler::zero, &backedge_counter_overflow);
+                                 rax, false, Assembler::zero,
+                                 UseOnStackReplacement ? &backedge_counter_overflow : NULL);
     } else { // not TieredCompilation
       // increment counter
       __ movptr(rcx, Address(rcx, Method::method_counters_offset()));
--- a/src/hotspot/share/asm/assembler.hpp	Wed Jul 18 00:23:06 2018 -0700
+++ b/src/hotspot/share/asm/assembler.hpp	Fri Jul 20 11:55:05 2018 -0700
@@ -159,6 +159,14 @@
   Label() {
     init();
   }
+
+  ~Label() {
+    assert(is_bound() || is_unused(), "Label was never bound to a location, but it was used as a jmp target");
+  }
+
+  void reset() {
+    init(); //leave _patch_overflow because it points to CodeBuffer.
+  }
 };
 
 // A NearLabel must be bound to a location near its users. Users can
--- a/src/hotspot/share/c1/c1_LIRAssembler.hpp	Wed Jul 18 00:23:06 2018 -0700
+++ b/src/hotspot/share/c1/c1_LIRAssembler.hpp	Fri Jul 20 11:55:05 2018 -0700
@@ -71,7 +71,11 @@
   void record_non_safepoint_debug_info();
 
   // unified bailout support
-  void bailout(const char* msg) const            { compilation()->bailout(msg); }
+  void bailout(const char* msg) {
+    // reset the label in case it hits assertion in destructor.
+    _unwind_handler_entry.reset();
+    compilation()->bailout(msg);
+  }
   bool bailed_out() const                        { return compilation()->bailed_out(); }
 
   // code emission patterns and accessors