< prev index next >

src/hotspot/share/utilities/exceptions.cpp

Print this page

 45 
 46 // Limit exception message components to 64K (the same max as Symbols)
 47 #define MAX_LEN 65535
 48 
 49 // Implementation of ThreadShadow
 50 void check_ThreadShadow() {
 51   const ByteSize offset1 = byte_offset_of(ThreadShadow, _pending_exception);
 52   const ByteSize offset2 = Thread::pending_exception_offset();
 53   if (offset1 != offset2) fatal("ThreadShadow::_pending_exception is not positioned correctly");
 54 }
 55 
 56 
 57 void ThreadShadow::set_pending_exception(oop exception, const char* file, int line) {
 58   assert(exception != nullptr && oopDesc::is_oop(exception), "invalid exception oop");
 59   _pending_exception = exception;
 60   _exception_file    = file;
 61   _exception_line    = line;
 62 }
 63 
 64 void ThreadShadow::clear_pending_exception() {


 65   LogTarget(Debug, exceptions) lt;
 66   if (_pending_exception != nullptr && lt.is_enabled()) {
 67     ResourceMark rm;
 68     LogStream ls(lt);
 69     ls.print("Thread::clear_pending_exception: cleared exception:");
 70     _pending_exception->print_on(&ls);
 71   }
 72   _pending_exception = nullptr;
 73   _exception_file    = nullptr;
 74   _exception_line    = 0;
 75 }
 76 
 77 void ThreadShadow::clear_pending_nonasync_exception() {
 78   // Do not clear probable async exceptions.
 79   if ((_pending_exception->klass() != vmClasses::InternalError_klass() ||
 80        java_lang_InternalError::during_unsafe_access(_pending_exception) != JNI_TRUE)) {
 81     clear_pending_exception();
 82   }
 83 }
 84 
























 85 // Implementation of Exceptions
 86 
 87 bool Exceptions::special_exception(JavaThread* thread, const char* file, int line, Handle h_exception, Symbol* h_name, const char* message) {
 88   assert(h_exception.is_null() != (h_name == nullptr), "either exception (" PTR_FORMAT ") or "
 89          "symbol (" PTR_FORMAT ") must be non-null but not both", p2i(h_exception()), p2i(h_name));
 90 
 91   // bootstrapping check
 92   if (!Universe::is_fully_initialized()) {
 93     if (h_exception.not_null()) {
 94       vm_exit_during_initialization(h_exception);
 95     } else if (h_name == nullptr) {
 96       // at least an informative message.
 97       vm_exit_during_initialization("Exception", message);
 98     } else {
 99       vm_exit_during_initialization(h_name, message);
100     }
101    ShouldNotReachHere();
102   }
103 
104 #ifdef ASSERT

300   _throw_msg(thread, file, line, h_name, msg);
301 }
302 
303 
304 // Creates an exception oop, calls the <init> method with the given signature.
305 // and returns a Handle
306 Handle Exceptions::new_exception(JavaThread* thread, Symbol* name,
307                                  Symbol* signature, JavaCallArguments *args,
308                                  Handle h_loader) {
309   assert(Universe::is_fully_initialized(),
310     "cannot be called during initialization");
311   assert(!thread->has_pending_exception(), "already has exception");
312 
313   Handle h_exception;
314 
315   // Resolve exception klass, and check for pending exception below.
316   Klass* klass = SystemDictionary::resolve_or_fail(name, h_loader, true, thread);
317 
318   if (!thread->has_pending_exception()) {
319     assert(klass != nullptr, "klass must exist");





320     h_exception = JavaCalls::construct_new_instance(InstanceKlass::cast(klass),
321                                 signature,
322                                 args,
323                                 thread);
324   }
325 
326   // Check if another exception was thrown in the process, if so rethrow that one
327   if (thread->has_pending_exception()) {
328     h_exception = Handle(thread, thread->pending_exception());
329     thread->clear_pending_exception();
330   }
331   return h_exception;
332 }
333 
334 // Creates an exception oop, calls the <init> method with the given signature.
335 // and returns a Handle
336 // Initializes the cause if cause non-null
337 Handle Exceptions::new_exception(JavaThread* thread, Symbol* name,
338                                  Symbol* signature, JavaCallArguments *args,
339                                  Handle h_cause,

 45 
 46 // Limit exception message components to 64K (the same max as Symbols)
 47 #define MAX_LEN 65535
 48 
 49 // Implementation of ThreadShadow
 50 void check_ThreadShadow() {
 51   const ByteSize offset1 = byte_offset_of(ThreadShadow, _pending_exception);
 52   const ByteSize offset2 = Thread::pending_exception_offset();
 53   if (offset1 != offset2) fatal("ThreadShadow::_pending_exception is not positioned correctly");
 54 }
 55 
 56 
 57 void ThreadShadow::set_pending_exception(oop exception, const char* file, int line) {
 58   assert(exception != nullptr && oopDesc::is_oop(exception), "invalid exception oop");
 59   _pending_exception = exception;
 60   _exception_file    = file;
 61   _exception_line    = line;
 62 }
 63 
 64 void ThreadShadow::clear_pending_exception() {
 65   assert(_pending_exception == nullptr || !_pending_exception->is_a(vmClasses::PreemptedException_klass()),
 66          "unexpected PreemptedException, missing NoPreemptMark?");
 67   LogTarget(Debug, exceptions) lt;
 68   if (_pending_exception != nullptr && lt.is_enabled()) {
 69     ResourceMark rm;
 70     LogStream ls(lt);
 71     ls.print("Thread::clear_pending_exception: cleared exception:");
 72     _pending_exception->print_on(&ls);
 73   }
 74   _pending_exception = nullptr;
 75   _exception_file    = nullptr;
 76   _exception_line    = 0;
 77 }
 78 
 79 void ThreadShadow::clear_pending_nonasync_exception() {
 80   // Do not clear probable async exceptions.
 81   if ((_pending_exception->klass() != vmClasses::InternalError_klass() ||
 82        java_lang_InternalError::during_unsafe_access(_pending_exception) != JNI_TRUE)) {
 83     clear_pending_exception();
 84   }
 85 }
 86 
 87 void ThreadShadow::set_pending_preempted_exception() {
 88   assert(!has_pending_exception(), "");
 89   // We always install the same pre-allocated exception since we only
 90   // want to use the TRAPS mechanism to bail out from all methods until
 91   // reaching the one using the CHECK_AND_CLEAR_PREEMPTED macro.
 92   set_pending_exception(Universe::preempted_exception_instance(), __FILE__, __LINE__);
 93 }
 94 
 95 void ThreadShadow::clear_pending_preempted_exception() {
 96   assert(has_pending_exception(), "");
 97   if (pending_exception()->is_a(vmClasses::PreemptedException_klass())) {
 98     _pending_exception = nullptr;
 99     _exception_file    = nullptr;
100     _exception_line    = 0;
101   }
102 }
103 
104 #ifdef ASSERT
105 void ThreadShadow::check_preempted_exception() {
106   assert(has_pending_exception(), "");
107   assert(pending_exception()->is_a(vmClasses::PreemptedException_klass()), "should only be PreemptedException");
108 }
109 #endif
110 
111 // Implementation of Exceptions
112 
113 bool Exceptions::special_exception(JavaThread* thread, const char* file, int line, Handle h_exception, Symbol* h_name, const char* message) {
114   assert(h_exception.is_null() != (h_name == nullptr), "either exception (" PTR_FORMAT ") or "
115          "symbol (" PTR_FORMAT ") must be non-null but not both", p2i(h_exception()), p2i(h_name));
116 
117   // bootstrapping check
118   if (!Universe::is_fully_initialized()) {
119     if (h_exception.not_null()) {
120       vm_exit_during_initialization(h_exception);
121     } else if (h_name == nullptr) {
122       // at least an informative message.
123       vm_exit_during_initialization("Exception", message);
124     } else {
125       vm_exit_during_initialization(h_name, message);
126     }
127    ShouldNotReachHere();
128   }
129 
130 #ifdef ASSERT

326   _throw_msg(thread, file, line, h_name, msg);
327 }
328 
329 
330 // Creates an exception oop, calls the <init> method with the given signature.
331 // and returns a Handle
332 Handle Exceptions::new_exception(JavaThread* thread, Symbol* name,
333                                  Symbol* signature, JavaCallArguments *args,
334                                  Handle h_loader) {
335   assert(Universe::is_fully_initialized(),
336     "cannot be called during initialization");
337   assert(!thread->has_pending_exception(), "already has exception");
338 
339   Handle h_exception;
340 
341   // Resolve exception klass, and check for pending exception below.
342   Klass* klass = SystemDictionary::resolve_or_fail(name, h_loader, true, thread);
343 
344   if (!thread->has_pending_exception()) {
345     assert(klass != nullptr, "klass must exist");
346     // We could get here while linking or initializing a klass
347     // from a preemptable call. Don't preempt here since before
348     // the exception is propagated we might make an upcall to
349     // Java to initialize the object with the cause of exception.
350     NoPreemptMark npm(thread);
351     h_exception = JavaCalls::construct_new_instance(InstanceKlass::cast(klass),
352                                 signature,
353                                 args,
354                                 thread);
355   }
356 
357   // Check if another exception was thrown in the process, if so rethrow that one
358   if (thread->has_pending_exception()) {
359     h_exception = Handle(thread, thread->pending_exception());
360     thread->clear_pending_exception();
361   }
362   return h_exception;
363 }
364 
365 // Creates an exception oop, calls the <init> method with the given signature.
366 // and returns a Handle
367 // Initializes the cause if cause non-null
368 Handle Exceptions::new_exception(JavaThread* thread, Symbol* name,
369                                  Symbol* signature, JavaCallArguments *args,
370                                  Handle h_cause,
< prev index next >