Mon, 02 Jul 2012 13:11:28 -0400
Merge
duke@435 | 1 | /* |
never@3499 | 2 | * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved. |
duke@435 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@435 | 4 | * |
duke@435 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@435 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@435 | 7 | * published by the Free Software Foundation. |
duke@435 | 8 | * |
duke@435 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@435 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@435 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@435 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@435 | 13 | * accompanied this code). |
duke@435 | 14 | * |
duke@435 | 15 | * You should have received a copy of the GNU General Public License version |
duke@435 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@435 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@435 | 18 | * |
trims@1907 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
trims@1907 | 20 | * or visit www.oracle.com if you need additional information or have any |
trims@1907 | 21 | * questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
stefank@2314 | 25 | #include "precompiled.hpp" |
stefank@2314 | 26 | #include "classfile/systemDictionary.hpp" |
stefank@2314 | 27 | #include "classfile/vmSymbols.hpp" |
stefank@2314 | 28 | #include "compiler/compileBroker.hpp" |
stefank@2314 | 29 | #include "oops/oop.inline.hpp" |
stefank@2314 | 30 | #include "runtime/init.hpp" |
stefank@2314 | 31 | #include "runtime/java.hpp" |
stefank@2314 | 32 | #include "runtime/javaCalls.hpp" |
stefank@2314 | 33 | #include "runtime/threadCritical.hpp" |
stefank@2314 | 34 | #include "utilities/events.hpp" |
stefank@2314 | 35 | #include "utilities/exceptions.hpp" |
stefank@2314 | 36 | #ifdef TARGET_OS_FAMILY_linux |
stefank@2314 | 37 | # include "thread_linux.inline.hpp" |
stefank@2314 | 38 | #endif |
stefank@2314 | 39 | #ifdef TARGET_OS_FAMILY_solaris |
stefank@2314 | 40 | # include "thread_solaris.inline.hpp" |
stefank@2314 | 41 | #endif |
stefank@2314 | 42 | #ifdef TARGET_OS_FAMILY_windows |
stefank@2314 | 43 | # include "thread_windows.inline.hpp" |
stefank@2314 | 44 | #endif |
never@3156 | 45 | #ifdef TARGET_OS_FAMILY_bsd |
never@3156 | 46 | # include "thread_bsd.inline.hpp" |
never@3156 | 47 | #endif |
duke@435 | 48 | |
duke@435 | 49 | |
duke@435 | 50 | // Implementation of ThreadShadow |
duke@435 | 51 | void check_ThreadShadow() { |
duke@435 | 52 | const ByteSize offset1 = byte_offset_of(ThreadShadow, _pending_exception); |
duke@435 | 53 | const ByteSize offset2 = Thread::pending_exception_offset(); |
duke@435 | 54 | if (offset1 != offset2) fatal("ThreadShadow::_pending_exception is not positioned correctly"); |
duke@435 | 55 | } |
duke@435 | 56 | |
duke@435 | 57 | |
duke@435 | 58 | void ThreadShadow::set_pending_exception(oop exception, const char* file, int line) { |
duke@435 | 59 | assert(exception != NULL && exception->is_oop(), "invalid exception oop"); |
duke@435 | 60 | _pending_exception = exception; |
duke@435 | 61 | _exception_file = file; |
duke@435 | 62 | _exception_line = line; |
duke@435 | 63 | } |
duke@435 | 64 | |
duke@435 | 65 | void ThreadShadow::clear_pending_exception() { |
duke@435 | 66 | if (TraceClearedExceptions) { |
duke@435 | 67 | if (_pending_exception != NULL) { |
duke@435 | 68 | tty->print_cr("Thread::clear_pending_exception: cleared exception:"); |
duke@435 | 69 | _pending_exception->print(); |
duke@435 | 70 | } |
duke@435 | 71 | } |
duke@435 | 72 | _pending_exception = NULL; |
duke@435 | 73 | _exception_file = NULL; |
duke@435 | 74 | _exception_line = 0; |
duke@435 | 75 | } |
duke@435 | 76 | // Implementation of Exceptions |
duke@435 | 77 | |
duke@435 | 78 | bool Exceptions::special_exception(Thread* thread, const char* file, int line, Handle h_exception) { |
duke@435 | 79 | // bootstrapping check |
duke@435 | 80 | if (!Universe::is_fully_initialized()) { |
duke@435 | 81 | vm_exit_during_initialization(h_exception); |
duke@435 | 82 | ShouldNotReachHere(); |
duke@435 | 83 | } |
duke@435 | 84 | |
coleenp@2222 | 85 | #ifdef ASSERT |
coleenp@2222 | 86 | // Check for trying to throw stack overflow before initialization is complete |
coleenp@2222 | 87 | // to prevent infinite recursion trying to initialize stack overflow without |
coleenp@2222 | 88 | // adequate stack space. |
coleenp@2222 | 89 | // This can happen with stress testing a large value of StackShadowPages |
coleenp@2222 | 90 | if (h_exception()->klass() == SystemDictionary::StackOverflowError_klass()) { |
coleenp@2222 | 91 | instanceKlass* ik = instanceKlass::cast(h_exception->klass()); |
coleenp@2222 | 92 | assert(ik->is_initialized(), |
coleenp@2222 | 93 | "need to increase min_stack_allowed calculation"); |
coleenp@2222 | 94 | } |
coleenp@2222 | 95 | #endif // ASSERT |
coleenp@2222 | 96 | |
duke@435 | 97 | if (thread->is_VM_thread() |
duke@435 | 98 | || thread->is_Compiler_thread() ) { |
duke@435 | 99 | // We do not care what kind of exception we get for the vm-thread or a thread which |
duke@435 | 100 | // is compiling. We just install a dummy exception object |
duke@435 | 101 | thread->set_pending_exception(Universe::vm_exception(), file, line); |
duke@435 | 102 | return true; |
duke@435 | 103 | } |
duke@435 | 104 | |
duke@435 | 105 | return false; |
duke@435 | 106 | } |
duke@435 | 107 | |
coleenp@2497 | 108 | bool Exceptions::special_exception(Thread* thread, const char* file, int line, Symbol* h_name, const char* message) { |
duke@435 | 109 | // bootstrapping check |
duke@435 | 110 | if (!Universe::is_fully_initialized()) { |
coleenp@2497 | 111 | if (h_name == NULL) { |
duke@435 | 112 | // atleast an informative message. |
duke@435 | 113 | vm_exit_during_initialization("Exception", message); |
duke@435 | 114 | } else { |
duke@435 | 115 | vm_exit_during_initialization(h_name, message); |
duke@435 | 116 | } |
duke@435 | 117 | ShouldNotReachHere(); |
duke@435 | 118 | } |
duke@435 | 119 | |
duke@435 | 120 | if (thread->is_VM_thread() |
duke@435 | 121 | || thread->is_Compiler_thread() ) { |
duke@435 | 122 | // We do not care what kind of exception we get for the vm-thread or a thread which |
duke@435 | 123 | // is compiling. We just install a dummy exception object |
duke@435 | 124 | thread->set_pending_exception(Universe::vm_exception(), file, line); |
duke@435 | 125 | return true; |
duke@435 | 126 | } |
duke@435 | 127 | return false; |
duke@435 | 128 | } |
duke@435 | 129 | |
duke@435 | 130 | // This method should only be called from generated code, |
duke@435 | 131 | // therefore the exception oop should be in the oopmap. |
duke@435 | 132 | void Exceptions::_throw_oop(Thread* thread, const char* file, int line, oop exception) { |
duke@435 | 133 | assert(exception != NULL, "exception should not be NULL"); |
duke@435 | 134 | Handle h_exception = Handle(thread, exception); |
duke@435 | 135 | _throw(thread, file, line, h_exception); |
duke@435 | 136 | } |
duke@435 | 137 | |
never@1446 | 138 | void Exceptions::_throw(Thread* thread, const char* file, int line, Handle h_exception, const char* message) { |
duke@435 | 139 | assert(h_exception() != NULL, "exception should not be NULL"); |
duke@435 | 140 | |
duke@435 | 141 | // tracing (do this up front - so it works during boot strapping) |
duke@435 | 142 | if (TraceExceptions) { |
duke@435 | 143 | ttyLocker ttyl; |
duke@435 | 144 | ResourceMark rm; |
never@1446 | 145 | tty->print_cr("Exception <%s>%s%s (" INTPTR_FORMAT " ) \n" |
never@1446 | 146 | "thrown [%s, line %d]\nfor thread " INTPTR_FORMAT, |
never@1446 | 147 | h_exception->print_value_string(), |
never@1446 | 148 | message ? ": " : "", message ? message : "", |
never@1446 | 149 | (address)h_exception(), file, line, thread); |
duke@435 | 150 | } |
duke@435 | 151 | // for AbortVMOnException flag |
kvn@2039 | 152 | NOT_PRODUCT(Exceptions::debug_check_abort(h_exception, message)); |
duke@435 | 153 | |
duke@435 | 154 | // Check for special boot-strapping/vm-thread handling |
duke@435 | 155 | if (special_exception(thread, file, line, h_exception)) return; |
duke@435 | 156 | |
never@1577 | 157 | assert(h_exception->is_a(SystemDictionary::Throwable_klass()), "exception is not a subclass of java/lang/Throwable"); |
duke@435 | 158 | |
duke@435 | 159 | // set the pending exception |
duke@435 | 160 | thread->set_pending_exception(h_exception(), file, line); |
duke@435 | 161 | |
duke@435 | 162 | // vm log |
never@3499 | 163 | Events::log_exception(thread, "Threw " INTPTR_FORMAT " at %s:%d", (address)h_exception(), file, line); |
duke@435 | 164 | } |
duke@435 | 165 | |
duke@435 | 166 | |
coleenp@2497 | 167 | void Exceptions::_throw_msg(Thread* thread, const char* file, int line, Symbol* h_name, const char* message, Handle h_loader, Handle h_protection_domain) { |
duke@435 | 168 | // Check for special boot-strapping/vm-thread handling |
duke@435 | 169 | if (special_exception(thread, file, line, h_name, message)) return; |
duke@435 | 170 | // Create and throw exception |
duke@435 | 171 | Handle h_cause(thread, NULL); |
duke@435 | 172 | Handle h_exception = new_exception(thread, h_name, message, h_cause, h_loader, h_protection_domain); |
never@1446 | 173 | _throw(thread, file, line, h_exception, message); |
duke@435 | 174 | } |
duke@435 | 175 | |
duke@435 | 176 | // Throw an exception with a message and a cause |
coleenp@2497 | 177 | void Exceptions::_throw_msg_cause(Thread* thread, const char* file, int line, Symbol* h_name, const char* message, Handle h_cause, Handle h_loader, Handle h_protection_domain) { |
duke@435 | 178 | // Check for special boot-strapping/vm-thread handling |
duke@435 | 179 | if (special_exception(thread, file, line, h_name, message)) return; |
duke@435 | 180 | // Create and throw exception and init cause |
duke@435 | 181 | Handle h_exception = new_exception(thread, h_name, message, h_cause, h_loader, h_protection_domain); |
never@1446 | 182 | _throw(thread, file, line, h_exception, message); |
duke@435 | 183 | } |
duke@435 | 184 | |
duke@435 | 185 | // This version already has a handle for name |
duke@435 | 186 | void Exceptions::_throw_msg(Thread* thread, const char* file, int line, |
coleenp@2497 | 187 | Symbol* name, const char* message) { |
duke@435 | 188 | Handle h_loader(thread, NULL); |
duke@435 | 189 | Handle h_protection_domain(thread, NULL); |
duke@435 | 190 | Exceptions::_throw_msg(thread, file, line, name, message, h_loader, h_protection_domain); |
duke@435 | 191 | } |
duke@435 | 192 | |
duke@435 | 193 | // This version already has a handle for name |
duke@435 | 194 | void Exceptions::_throw_msg_cause(Thread* thread, const char* file, int line, |
coleenp@2497 | 195 | Symbol* name, const char* message, Handle cause) { |
duke@435 | 196 | Handle h_loader(thread, NULL); |
duke@435 | 197 | Handle h_protection_domain(thread, NULL); |
duke@435 | 198 | Exceptions::_throw_msg_cause(thread, file, line, name, message, cause, h_loader, h_protection_domain); |
duke@435 | 199 | } |
duke@435 | 200 | |
coleenp@2497 | 201 | void Exceptions::_throw_args(Thread* thread, const char* file, int line, Symbol* h_name, Symbol* h_signature, JavaCallArguments *args) { |
duke@435 | 202 | // Check for special boot-strapping/vm-thread handling |
duke@435 | 203 | if (special_exception(thread, file, line, h_name, NULL)) return; |
duke@435 | 204 | // Create and throw exception |
duke@435 | 205 | Handle h_loader(thread, NULL); |
duke@435 | 206 | Handle h_prot(thread, NULL); |
duke@435 | 207 | Handle h_cause(thread, NULL); |
duke@435 | 208 | Handle exception = new_exception(thread, h_name, h_signature, args, h_cause, h_loader, h_prot); |
duke@435 | 209 | _throw(thread, file, line, exception); |
duke@435 | 210 | } |
duke@435 | 211 | |
duke@435 | 212 | |
coleenp@2804 | 213 | void Exceptions::throw_stack_overflow_exception(Thread* THREAD, const char* file, int line, methodHandle method) { |
duke@435 | 214 | Handle exception; |
duke@435 | 215 | if (!THREAD->has_pending_exception()) { |
duke@435 | 216 | klassOop k = SystemDictionary::StackOverflowError_klass(); |
duke@435 | 217 | oop e = instanceKlass::cast(k)->allocate_instance(CHECK); |
duke@435 | 218 | exception = Handle(THREAD, e); // fill_in_stack trace does gc |
coleenp@2222 | 219 | assert(instanceKlass::cast(k)->is_initialized(), "need to increase min_stack_allowed calculation"); |
duke@435 | 220 | if (StackTraceInThrowable) { |
coleenp@2804 | 221 | java_lang_Throwable::fill_in_stack_trace(exception, method()); |
duke@435 | 222 | } |
duke@435 | 223 | } else { |
duke@435 | 224 | // if prior exception, throw that one instead |
duke@435 | 225 | exception = Handle(THREAD, THREAD->pending_exception()); |
duke@435 | 226 | } |
coleenp@2804 | 227 | _throw(THREAD, file, line, exception); |
duke@435 | 228 | } |
duke@435 | 229 | |
coleenp@2497 | 230 | void Exceptions::fthrow(Thread* thread, const char* file, int line, Symbol* h_name, const char* format, ...) { |
duke@435 | 231 | const int max_msg_size = 1024; |
duke@435 | 232 | va_list ap; |
duke@435 | 233 | va_start(ap, format); |
duke@435 | 234 | char msg[max_msg_size]; |
duke@435 | 235 | vsnprintf(msg, max_msg_size, format, ap); |
duke@435 | 236 | msg[max_msg_size-1] = '\0'; |
duke@435 | 237 | va_end(ap); |
duke@435 | 238 | _throw_msg(thread, file, line, h_name, msg); |
duke@435 | 239 | } |
duke@435 | 240 | |
duke@435 | 241 | // Creates an exception oop, calls the <init> method with the given signature. |
duke@435 | 242 | // and returns a Handle |
duke@435 | 243 | // Initializes the cause if cause non-null |
coleenp@2497 | 244 | Handle Exceptions::new_exception(Thread *thread, Symbol* h_name, |
coleenp@2497 | 245 | Symbol* signature, |
duke@435 | 246 | JavaCallArguments *args, |
duke@435 | 247 | Handle h_cause, Handle h_loader, |
duke@435 | 248 | Handle h_protection_domain) { |
duke@435 | 249 | assert(Universe::is_fully_initialized(), |
duke@435 | 250 | "cannot be called during initialization"); |
duke@435 | 251 | assert(thread->is_Java_thread(), "can only be called by a Java thread"); |
duke@435 | 252 | assert(!thread->has_pending_exception(), "already has exception"); |
duke@435 | 253 | |
duke@435 | 254 | Handle h_exception; |
duke@435 | 255 | |
duke@435 | 256 | // Resolve exception klass |
duke@435 | 257 | klassOop ik = SystemDictionary::resolve_or_fail(h_name, h_loader, h_protection_domain, true, thread); |
duke@435 | 258 | instanceKlassHandle klass (thread, ik); |
duke@435 | 259 | |
duke@435 | 260 | if (!thread->has_pending_exception()) { |
duke@435 | 261 | assert(klass.not_null(), "klass must exist"); |
duke@435 | 262 | // We are about to create an instance - so make sure that klass is initialized |
duke@435 | 263 | klass->initialize(thread); |
duke@435 | 264 | if (!thread->has_pending_exception()) { |
duke@435 | 265 | // Allocate new exception |
duke@435 | 266 | h_exception = klass->allocate_instance_handle(thread); |
duke@435 | 267 | if (!thread->has_pending_exception()) { |
duke@435 | 268 | JavaValue result(T_VOID); |
duke@435 | 269 | args->set_receiver(h_exception); |
duke@435 | 270 | // Call constructor |
duke@435 | 271 | JavaCalls::call_special(&result, klass, |
coleenp@2497 | 272 | vmSymbols::object_initializer_name(), |
duke@435 | 273 | signature, |
duke@435 | 274 | args, |
duke@435 | 275 | thread); |
duke@435 | 276 | |
duke@435 | 277 | } |
duke@435 | 278 | } |
duke@435 | 279 | |
duke@435 | 280 | // Future: object initializer should take a cause argument |
duke@435 | 281 | if (h_cause() != NULL) { |
never@1577 | 282 | assert(h_cause->is_a(SystemDictionary::Throwable_klass()), |
duke@435 | 283 | "exception cause is not a subclass of java/lang/Throwable"); |
duke@435 | 284 | JavaValue result1(T_OBJECT); |
duke@435 | 285 | JavaCallArguments args1; |
duke@435 | 286 | args1.set_receiver(h_exception); |
duke@435 | 287 | args1.push_oop(h_cause); |
duke@435 | 288 | JavaCalls::call_virtual(&result1, klass, |
coleenp@2497 | 289 | vmSymbols::initCause_name(), |
coleenp@2497 | 290 | vmSymbols::throwable_throwable_signature(), |
duke@435 | 291 | &args1, |
duke@435 | 292 | thread); |
duke@435 | 293 | } |
duke@435 | 294 | } |
duke@435 | 295 | |
duke@435 | 296 | // Check if another exception was thrown in the process, if so rethrow that one |
duke@435 | 297 | if (thread->has_pending_exception()) { |
duke@435 | 298 | h_exception = Handle(thread, thread->pending_exception()); |
duke@435 | 299 | thread->clear_pending_exception(); |
duke@435 | 300 | } |
duke@435 | 301 | return h_exception; |
duke@435 | 302 | } |
duke@435 | 303 | |
duke@435 | 304 | // Convenience method. Calls either the <init>() or <init>(String) method when |
duke@435 | 305 | // creating a new exception |
coleenp@2497 | 306 | Handle Exceptions::new_exception(Thread* thread, Symbol* h_name, |
duke@435 | 307 | const char* message, Handle h_cause, |
duke@435 | 308 | Handle h_loader, |
duke@435 | 309 | Handle h_protection_domain, |
duke@435 | 310 | ExceptionMsgToUtf8Mode to_utf8_safe) { |
duke@435 | 311 | JavaCallArguments args; |
coleenp@2497 | 312 | Symbol* signature = NULL; |
duke@435 | 313 | if (message == NULL) { |
coleenp@2497 | 314 | signature = vmSymbols::void_method_signature(); |
duke@435 | 315 | } else { |
duke@435 | 316 | // We want to allocate storage, but we can't do that if there's |
duke@435 | 317 | // a pending exception, so we preserve any pending exception |
duke@435 | 318 | // around the allocation. |
duke@435 | 319 | // If we get an exception from the allocation, prefer that to |
duke@435 | 320 | // the exception we are trying to build, or the pending exception. |
duke@435 | 321 | // This is sort of like what PRESERVE_EXCEPTION_MARK does, except |
duke@435 | 322 | // for the preferencing and the early returns. |
duke@435 | 323 | Handle incoming_exception (thread, NULL); |
duke@435 | 324 | if (thread->has_pending_exception()) { |
duke@435 | 325 | incoming_exception = Handle(thread, thread->pending_exception()); |
duke@435 | 326 | thread->clear_pending_exception(); |
duke@435 | 327 | } |
duke@435 | 328 | Handle msg; |
duke@435 | 329 | if (to_utf8_safe == safe_to_utf8) { |
duke@435 | 330 | // Make a java UTF8 string. |
duke@435 | 331 | msg = java_lang_String::create_from_str(message, thread); |
duke@435 | 332 | } else { |
duke@435 | 333 | // Make a java string keeping the encoding scheme of the original string. |
duke@435 | 334 | msg = java_lang_String::create_from_platform_dependent_str(message, thread); |
duke@435 | 335 | } |
duke@435 | 336 | if (thread->has_pending_exception()) { |
duke@435 | 337 | Handle exception(thread, thread->pending_exception()); |
duke@435 | 338 | thread->clear_pending_exception(); |
duke@435 | 339 | return exception; |
duke@435 | 340 | } |
duke@435 | 341 | if (incoming_exception.not_null()) { |
duke@435 | 342 | return incoming_exception; |
duke@435 | 343 | } |
duke@435 | 344 | args.push_oop(msg); |
coleenp@2497 | 345 | signature = vmSymbols::string_void_signature(); |
duke@435 | 346 | } |
duke@435 | 347 | return new_exception(thread, h_name, signature, &args, h_cause, h_loader, h_protection_domain); |
duke@435 | 348 | } |
duke@435 | 349 | |
duke@435 | 350 | // Another convenience method that creates handles for null class loaders and |
duke@435 | 351 | // protection domains and null causes. |
duke@435 | 352 | // If the last parameter 'to_utf8_mode' is safe_to_utf8, |
duke@435 | 353 | // it means we can safely ignore the encoding scheme of the message string and |
duke@435 | 354 | // convert it directly to a java UTF8 string. Otherwise, we need to take the |
duke@435 | 355 | // encoding scheme of the string into account. One thing we should do at some |
duke@435 | 356 | // point is to push this flag down to class java_lang_String since other |
duke@435 | 357 | // classes may need similar functionalities. |
duke@435 | 358 | Handle Exceptions::new_exception(Thread* thread, |
coleenp@2497 | 359 | Symbol* name, |
duke@435 | 360 | const char* message, |
duke@435 | 361 | ExceptionMsgToUtf8Mode to_utf8_safe) { |
duke@435 | 362 | |
duke@435 | 363 | Handle h_loader(thread, NULL); |
duke@435 | 364 | Handle h_prot(thread, NULL); |
duke@435 | 365 | Handle h_cause(thread, NULL); |
coleenp@2497 | 366 | return Exceptions::new_exception(thread, name, message, h_cause, h_loader, |
duke@435 | 367 | h_prot, to_utf8_safe); |
duke@435 | 368 | } |
duke@435 | 369 | |
duke@435 | 370 | // Implementation of ExceptionMark |
duke@435 | 371 | |
duke@435 | 372 | ExceptionMark::ExceptionMark(Thread*& thread) { |
duke@435 | 373 | thread = Thread::current(); |
duke@435 | 374 | _thread = thread; |
duke@435 | 375 | if (_thread->has_pending_exception()) { |
duke@435 | 376 | oop exception = _thread->pending_exception(); |
duke@435 | 377 | _thread->clear_pending_exception(); // Needed to avoid infinite recursion |
duke@435 | 378 | exception->print(); |
duke@435 | 379 | fatal("ExceptionMark constructor expects no pending exceptions"); |
duke@435 | 380 | } |
duke@435 | 381 | } |
duke@435 | 382 | |
duke@435 | 383 | |
duke@435 | 384 | ExceptionMark::~ExceptionMark() { |
duke@435 | 385 | if (_thread->has_pending_exception()) { |
duke@435 | 386 | Handle exception(_thread, _thread->pending_exception()); |
duke@435 | 387 | _thread->clear_pending_exception(); // Needed to avoid infinite recursion |
duke@435 | 388 | if (is_init_completed()) { |
duke@435 | 389 | exception->print(); |
duke@435 | 390 | fatal("ExceptionMark destructor expects no pending exceptions"); |
duke@435 | 391 | } else { |
duke@435 | 392 | vm_exit_during_initialization(exception); |
duke@435 | 393 | } |
duke@435 | 394 | } |
duke@435 | 395 | } |
duke@435 | 396 | |
duke@435 | 397 | // ---------------------------------------------------------------------------------------- |
duke@435 | 398 | |
duke@435 | 399 | #ifndef PRODUCT |
duke@435 | 400 | // caller frees value_string if necessary |
kvn@2039 | 401 | void Exceptions::debug_check_abort(const char *value_string, const char* message) { |
duke@435 | 402 | if (AbortVMOnException != NULL && value_string != NULL && |
duke@435 | 403 | strstr(value_string, AbortVMOnException)) { |
kvn@2039 | 404 | if (AbortVMOnExceptionMessage == NULL || message == NULL || |
kvn@2039 | 405 | strcmp(message, AbortVMOnExceptionMessage) == 0) { |
kvn@2039 | 406 | fatal(err_msg("Saw %s, aborting", value_string)); |
kvn@2039 | 407 | } |
duke@435 | 408 | } |
duke@435 | 409 | } |
duke@435 | 410 | |
kvn@2039 | 411 | void Exceptions::debug_check_abort(Handle exception, const char* message) { |
duke@435 | 412 | if (AbortVMOnException != NULL) { |
duke@435 | 413 | ResourceMark rm; |
kvn@2039 | 414 | if (message == NULL && exception->is_a(SystemDictionary::Throwable_klass())) { |
kvn@2039 | 415 | oop msg = java_lang_Throwable::message(exception); |
kvn@2039 | 416 | if (msg != NULL) { |
kvn@2039 | 417 | message = java_lang_String::as_utf8_string(msg); |
kvn@2039 | 418 | } |
kvn@2039 | 419 | } |
kvn@2039 | 420 | debug_check_abort(instanceKlass::cast(exception()->klass())->external_name(), message); |
duke@435 | 421 | } |
duke@435 | 422 | } |
duke@435 | 423 | #endif |