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