[aarch64-port-dev ] [EXT] Re: RFR(XS): Provide information when hitting a HaltNode for architectures other than x86

Andrew Haley aph at redhat.com
Thu May 7 17:48:29 UTC 2020


On 5/7/20 9:11 AM, Andrew Haley wrote:
> On 5/6/20 9:45 PM, Doerr, Martin wrote:
>> I had also thought about using a trap based implementation.
>> Maybe it makes sense to add a feature to shared code for that.
>> E.g. we could emit an illegal instruction (which raises SIGILL) followed by some kind of index into a descriptor array.
>> PPC64 would also benefit from a more compact solution.
>
> Most of the stuff to handle this would be in the back end, I would
> have thought. I'll have a look.

This attached patch does the job for Linux/AArch64. It has two
disadvantages:

1. It corrupts R8, rscratch1. This doesn't really matter for AArch64.

2. If we execute stop() in the context of a signal handler triggered
   by another trap, we'll have a double fault and the OS will kill our
   process.

1 is fixable by pushing rscratch1 before executing the trap. I'm not
sure it's worth doing; I'd rather have a tiny implementation of stop()
that we can use guilt-free in release code.

I don't think 2 is an issue because we never call out to generated
code from a signal handler.

-- 
Andrew Haley  (he/him)
Java Platform Lead Engineer
Red Hat UK Ltd. <https://www.redhat.com>
https://keybase.io/andrewhaley
EAC8 43EB D3EF DB98 CC77 2FAD A5CD 6035 332F A671

-------------- next part --------------
diff -r ed406ec0c5cd src/hotspot/cpu/aarch64/aarch64.ad
--- a/src/hotspot/cpu/aarch64/aarch64.ad	Thu May 07 14:44:09 2020 +0100
+++ b/src/hotspot/cpu/aarch64/aarch64.ad	Thu May 07 13:47:05 2020 -0400
@@ -15333,9 +15333,7 @@
   format %{ "ShouldNotReachHere" %}
 
   ins_encode %{
-    // +1 so NativeInstruction::is_sigill_zombie_not_entrant() doesn't
-    // return true
-    __ dpcs1(0xdead + 1);
+    __ stop(_halt_reason);
   %}
 
   ins_pipe(pipe_class_default);
diff -r ed406ec0c5cd src/hotspot/cpu/aarch64/macroAssembler_aarch64.cpp
--- a/src/hotspot/cpu/aarch64/macroAssembler_aarch64.cpp	Thu May 07 14:44:09 2020 +0100
+++ b/src/hotspot/cpu/aarch64/macroAssembler_aarch64.cpp	Thu May 07 13:47:05 2020 -0400
@@ -2223,14 +2223,8 @@
 }
 
 void MacroAssembler::stop(const char* msg) {
-  address ip = pc();
-  pusha();
-  mov(c_rarg0, (address)msg);
-  mov(c_rarg1, (address)ip);
-  mov(c_rarg2, sp);
-  mov(c_rarg3, CAST_FROM_FN_PTR(address, MacroAssembler::debug64));
-  blr(c_rarg3);
-  hlt(0);
+  mov(rscratch1, (address)msg);
+  dpcs1(0xdeaf);
 }
 
 void MacroAssembler::warn(const char* msg) {
@@ -2610,7 +2604,7 @@
       BREAKPOINT;
     }
   }
-  fatal("DEBUG MESSAGE: %s", msg);
+  report_fatal(__FILE__, __LINE__, "DEBUG MESSAGE: %s", msg);
 }
 
 void MacroAssembler::push_call_clobbered_registers() {
diff -r ed406ec0c5cd src/hotspot/cpu/aarch64/nativeInst_aarch64.cpp
--- a/src/hotspot/cpu/aarch64/nativeInst_aarch64.cpp	Thu May 07 14:44:09 2020 +0100
+++ b/src/hotspot/cpu/aarch64/nativeInst_aarch64.cpp	Thu May 07 13:47:05 2020 -0400
@@ -458,6 +458,10 @@
   return uint_at(0) == 0xd4bbd5a1; // dcps1 #0xdead
 }
 
+bool NativeInstruction::is_stop() {
+  return uint_at(0) == 0xd4bbd5e1; // dcps1 #0xdeaf
+}
+
 void NativeIllegalInstruction::insert(address code_pos) {
   *(juint*)code_pos = 0xd4bbd5a1; // dcps1 #0xdead
 }
diff -r ed406ec0c5cd src/hotspot/cpu/aarch64/nativeInst_aarch64.hpp
--- a/src/hotspot/cpu/aarch64/nativeInst_aarch64.hpp	Thu May 07 14:44:09 2020 +0100
+++ b/src/hotspot/cpu/aarch64/nativeInst_aarch64.hpp	Thu May 07 13:47:05 2020 -0400
@@ -76,6 +76,7 @@
   bool is_movz();
   bool is_movk();
   bool is_sigill_zombie_not_entrant();
+  bool is_stop();
 
  protected:
   address addr_at(int offset) const    { return address(this) + offset; }
diff -r ed406ec0c5cd src/hotspot/os_cpu/linux_aarch64/os_linux_aarch64.cpp
--- a/src/hotspot/os_cpu/linux_aarch64/os_linux_aarch64.cpp	Thu May 07 14:44:09 2020 +0100
+++ b/src/hotspot/os_cpu/linux_aarch64/os_linux_aarch64.cpp	Thu May 07 13:47:05 2020 -0400
@@ -381,6 +381,10 @@
           }
           stub = SharedRuntime::handle_unsafe_access(thread, next_pc);
         }
+      } else if (sig == SIGILL && nativeInstruction_at(pc)->is_stop()) {
+        int64_t *regs = (int64_t *)(uc->uc_mcontext.regs);
+        MacroAssembler::debug64((char*)regs[rscratch1->encoding()],
+                                (int64_t)pc, regs);
       }
       else
 


More information about the hotspot-compiler-dev mailing list