src/share/vm/utilities/exceptions.cpp

Thu, 02 Aug 2018 03:54:51 -0700

author
kevinw
date
Thu, 02 Aug 2018 03:54:51 -0700
changeset 9478
f3108e56b502
parent 9301
d47844b56aaf
child 9572
624a0741915c
permissions
-rw-r--r--

8196882: VS2017 Hotspot Defined vsnprintf Function Causes C2084 Already Defined Compilation Error
Summary: Add os::vsnprintf and os::snprintf.
Reviewed-by: kbarrett, lfoltan, stuefe, mlarsson

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

mercurial