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