From da7a2005a2c181737b163f60dd705acc00002463 Mon Sep 17 00:00:00 2001
From: hedongbo <hedongbo@huawei.com>
Date: Thu, 5 Jan 2023 10:22:15 +0000
Subject: 8185736: missing default exception handler in calls to
 rethrow_Stub

---
 hotspot/src/share/vm/opto/doCall.cpp | 9 +++++++++
 hotspot/src/share/vm/opto/output.cpp | 1 +
 2 files changed, 10 insertions(+)

diff --git a/hotspot/src/share/vm/opto/doCall.cpp b/hotspot/src/share/vm/opto/doCall.cpp
index 366769356..1b2b77c71 100644
--- a/hotspot/src/share/vm/opto/doCall.cpp
+++ b/hotspot/src/share/vm/opto/doCall.cpp
@@ -702,6 +702,7 @@ void Parse::catch_call_exceptions(ciExceptionHandlerStream& handlers) {
   GrowableArray<const Type*>* extypes = new (C->node_arena()) GrowableArray<const Type*>(C->node_arena(), 8, 0, NULL);
   GrowableArray<int>* saw_unloaded = new (C->node_arena()) GrowableArray<int>(C->node_arena(), 8, 0, 0);
 
+  bool default_handler = false;
   for (; !handlers.is_done(); handlers.next()) {
     ciExceptionHandler* h        = handlers.handler();
     int                 h_bci    = h->handler_bci();
@@ -724,6 +725,14 @@ void Parse::catch_call_exceptions(ciExceptionHandlerStream& handlers) {
     // Note:  It's OK if the BCIs repeat themselves.
     bcis->append(h_bci);
     extypes->append(h_extype);
+    if (h_bci == -1) {
+      default_handler = true;
+    }
+  }
+
+  if (!default_handler) {
+    bcis->append(-1);
+    extypes->append(TypeOopPtr::make_from_klass(env()->Throwable_klass())->is_instptr());
   }
 
   int len = bcis->length();
diff --git a/hotspot/src/share/vm/opto/output.cpp b/hotspot/src/share/vm/opto/output.cpp
index 5c9566e1e..6032b72a9 100644
--- a/hotspot/src/share/vm/opto/output.cpp
+++ b/hotspot/src/share/vm/opto/output.cpp
@@ -1761,6 +1761,7 @@ void Compile::FillExceptionTables(uint cnt, uint *call_returns, uint *inct_start
       }
 
       // Set the offset of the return from the call
+      assert(handler_bcis.find(-1) != -1, "must have default handler");
       _handler_table.add_subtable(call_return, &handler_bcis, NULL, &handler_pcos);
       continue;
     }
-- 
2.12.3

