8189794: Assert in InstanceKlass::cast called from Exceptions::new_exceptions
authorcoleenp
Tue, 24 Oct 2017 08:29:00 -0400
changeset 47689 54b78d6243c5
parent 47688 3d1e3786d66e
child 47691 4a095d9ea838
8189794: Assert in InstanceKlass::cast called from Exceptions::new_exceptions Summary: Fix call to InstanceKlass::cast to only be after verifying class is non-null. Reviewed-by: dholmes, sspitsyn
src/hotspot/share/utilities/exceptions.cpp
--- a/src/hotspot/share/utilities/exceptions.cpp	Mon Sep 04 19:50:01 2017 +0200
+++ b/src/hotspot/share/utilities/exceptions.cpp	Tue Oct 24 08:29:00 2017 -0400
@@ -218,10 +218,10 @@
 void Exceptions::throw_stack_overflow_exception(Thread* THREAD, const char* file, int line, const methodHandle& method) {
   Handle exception;
   if (!THREAD->has_pending_exception()) {
-    Klass* k = SystemDictionary::StackOverflowError_klass();
-    oop e = InstanceKlass::cast(k)->allocate_instance(CHECK);
+    InstanceKlass* k = SystemDictionary::StackOverflowError_klass();
+    oop e = k->allocate_instance(CHECK);
     exception = Handle(THREAD, e);  // fill_in_stack trace does gc
-    assert(InstanceKlass::cast(k)->is_initialized(), "need to increase java_thread_min_stack_allowed calculation");
+    assert(k->is_initialized(), "need to increase java_thread_min_stack_allowed calculation");
     if (StackTraceInThrowable) {
       java_lang_Throwable::fill_in_stack_trace(exception, method());
     }
@@ -258,25 +258,26 @@
 
   Handle h_exception;
 
-  // Resolve exception klass
-  InstanceKlass* klass = InstanceKlass::cast(SystemDictionary::resolve_or_fail(name, h_loader, h_protection_domain, true, thread));
+  // Resolve exception klass, and check for pending exception below.
+  Klass* klass = SystemDictionary::resolve_or_fail(name, h_loader, h_protection_domain, true, thread);
 
   if (!thread->has_pending_exception()) {
     assert(klass != NULL, "klass must exist");
     // We are about to create an instance - so make sure that klass is initialized
-    klass->initialize(thread);
+    InstanceKlass* ik = InstanceKlass::cast(klass);
+    ik->initialize(thread);
     if (!thread->has_pending_exception()) {
       // Allocate new exception
-      h_exception = klass->allocate_instance_handle(thread);
+      h_exception = ik->allocate_instance_handle(thread);
       if (!thread->has_pending_exception()) {
         JavaValue result(T_VOID);
         args->set_receiver(h_exception);
         // Call constructor
-        JavaCalls::call_special(&result, klass,
-                                         vmSymbols::object_initializer_name(),
-                                         signature,
-                                         args,
-                                         thread);
+        JavaCalls::call_special(&result, ik,
+                                vmSymbols::object_initializer_name(),
+                                signature,
+                                args,
+                                thread);
       }
     }
   }