< prev index next >

src/hotspot/share/utilities/exceptions.cpp

Print this page
*** 60,10 ***
--- 60,12 ---
    _exception_file    = file;
    _exception_line    = line;
  }
  
  void ThreadShadow::clear_pending_exception() {
+   assert(_pending_exception == nullptr || !_pending_exception->is_a(vmClasses::PreemptedException_klass()),
+          "unexpected PreemptedException, missing NoPreemptMark?");
    LogTarget(Debug, exceptions) lt;
    if (_pending_exception != nullptr && lt.is_enabled()) {
      ResourceMark rm;
      LogStream ls(lt);
      ls.print("Thread::clear_pending_exception: cleared exception:");

*** 80,10 ***
--- 82,34 ---
         java_lang_InternalError::during_unsafe_access(_pending_exception) != JNI_TRUE)) {
      clear_pending_exception();
    }
  }
  
+ void ThreadShadow::set_pending_preempted_exception() {
+   assert(!has_pending_exception(), "");
+   // We always install the same pre-allocated exception since we only
+   // want to use the TRAPS mechanism to bail out from all methods until
+   // reaching the one using the CHECK_AND_CLEAR_PREEMPTED macro.
+   set_pending_exception(Universe::preempted_exception_instance(), __FILE__, __LINE__);
+ }
+ 
+ void ThreadShadow::clear_pending_preempted_exception() {
+   assert(has_pending_exception(), "");
+   if (pending_exception()->is_a(vmClasses::PreemptedException_klass())) {
+     _pending_exception = nullptr;
+     _exception_file    = nullptr;
+     _exception_line    = 0;
+   }
+ }
+ 
+ #ifdef ASSERT
+ void ThreadShadow::check_preempted_exception() {
+   assert(has_pending_exception(), "");
+   assert(pending_exception()->is_a(vmClasses::PreemptedException_klass()), "should only be PreemptedException");
+ }
+ #endif
+ 
  // Implementation of Exceptions
  
  bool Exceptions::special_exception(JavaThread* thread, const char* file, int line, Handle h_exception, Symbol* h_name, const char* message) {
    assert(h_exception.is_null() != (h_name == nullptr), "either exception (" PTR_FORMAT ") or "
           "symbol (" PTR_FORMAT ") must be non-null but not both", p2i(h_exception()), p2i(h_name));

*** 315,10 ***
--- 341,15 ---
    // Resolve exception klass, and check for pending exception below.
    Klass* klass = SystemDictionary::resolve_or_fail(name, h_loader, true, thread);
  
    if (!thread->has_pending_exception()) {
      assert(klass != nullptr, "klass must exist");
+     // We could get here while linking or initializing a klass
+     // from a preemptable call. Don't preempt here since before
+     // the exception is propagated we might make an upcall to
+     // Java to initialize the object with the cause of exception.
+     NoPreemptMark npm(thread);
      h_exception = JavaCalls::construct_new_instance(InstanceKlass::cast(klass),
                                  signature,
                                  args,
                                  thread);
    }
< prev index next >