diff -r edf37d840190 -r 1b2b5f740ee0 hotspot/src/share/vm/utilities/exceptions.cpp --- a/hotspot/src/share/vm/utilities/exceptions.cpp Wed Aug 01 14:44:26 2012 -0700 +++ b/hotspot/src/share/vm/utilities/exceptions.cpp Tue Aug 07 14:32:08 2012 -0700 @@ -164,52 +164,58 @@ } -void Exceptions::_throw_msg(Thread* thread, const char* file, int line, Symbol* h_name, const char* message, Handle h_loader, Handle h_protection_domain) { +void Exceptions::_throw_msg(Thread* thread, const char* file, int line, Symbol* name, const char* message, + Handle h_loader, Handle h_protection_domain) { // Check for special boot-strapping/vm-thread handling - if (special_exception(thread, file, line, h_name, message)) return; + if (special_exception(thread, file, line, name, message)) return; // Create and throw exception Handle h_cause(thread, NULL); - Handle h_exception = new_exception(thread, h_name, message, h_cause, h_loader, h_protection_domain); + Handle h_exception = new_exception(thread, name, message, h_cause, h_loader, h_protection_domain); _throw(thread, file, line, h_exception, message); } -// Throw an exception with a message and a cause -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) { +void Exceptions::_throw_msg_cause(Thread* thread, const char* file, int line, Symbol* name, const char* message, Handle h_cause, + Handle h_loader, Handle h_protection_domain) { // Check for special boot-strapping/vm-thread handling - if (special_exception(thread, file, line, h_name, message)) return; + if (special_exception(thread, file, line, name, message)) return; // Create and throw exception and init cause - Handle h_exception = new_exception(thread, h_name, message, h_cause, h_loader, h_protection_domain); + Handle h_exception = new_exception(thread, name, message, h_cause, h_loader, h_protection_domain); _throw(thread, file, line, h_exception, message); } -// This version already has a handle for name -void Exceptions::_throw_msg(Thread* thread, const char* file, int line, - Symbol* name, const char* message) { - Handle h_loader(thread, NULL); - Handle h_protection_domain(thread, NULL); - Exceptions::_throw_msg(thread, file, line, name, message, h_loader, h_protection_domain); +void Exceptions::_throw_cause(Thread* thread, const char* file, int line, Symbol* name, Handle h_cause, + Handle h_loader, Handle h_protection_domain) { + // Check for special boot-strapping/vm-thread handling + if (special_exception(thread, file, line, h_cause)) return; + // Create and throw exception + Handle h_exception = new_exception(thread, name, h_cause, h_loader, h_protection_domain); + _throw(thread, file, line, h_exception, NULL); } -// This version already has a handle for name -void Exceptions::_throw_msg_cause(Thread* thread, const char* file, int line, - Symbol* name, const char* message, Handle cause) { - Handle h_loader(thread, NULL); - Handle h_protection_domain(thread, NULL); - Exceptions::_throw_msg_cause(thread, file, line, name, message, cause, h_loader, h_protection_domain); -} - -void Exceptions::_throw_args(Thread* thread, const char* file, int line, Symbol* h_name, Symbol* h_signature, JavaCallArguments *args) { +void Exceptions::_throw_args(Thread* thread, const char* file, int line, Symbol* name, Symbol* signature, JavaCallArguments *args) { // Check for special boot-strapping/vm-thread handling - if (special_exception(thread, file, line, h_name, NULL)) return; + if (special_exception(thread, file, line, name, NULL)) return; // Create and throw exception Handle h_loader(thread, NULL); Handle h_prot(thread, NULL); - Handle h_cause(thread, NULL); - Handle exception = new_exception(thread, h_name, h_signature, args, h_cause, h_loader, h_prot); + Handle exception = new_exception(thread, name, signature, args, h_loader, h_prot); _throw(thread, file, line, exception); } +// Methods for default parameters. +// NOTE: These must be here (and not in the header file) because of include circularities. +void Exceptions::_throw_msg_cause(Thread* thread, const char* file, int line, Symbol* name, const char* message, Handle h_cause) { + _throw_msg_cause(thread, file, line, name, message, h_cause, Handle(thread, NULL), Handle(thread, NULL)); +} +void Exceptions::_throw_msg(Thread* thread, const char* file, int line, Symbol* name, const char* message) { + _throw_msg(thread, file, line, name, message, Handle(thread, NULL), Handle(thread, NULL)); +} +void Exceptions::_throw_cause(Thread* thread, const char* file, int line, Symbol* name, Handle h_cause) { + _throw_cause(thread, file, line, name, h_cause, Handle(thread, NULL), Handle(thread, NULL)); +} + + void Exceptions::throw_stack_overflow_exception(Thread* THREAD, const char* file, int line, methodHandle method) { Handle exception; if (!THREAD->has_pending_exception()) { @@ -240,12 +246,9 @@ // Creates an exception oop, calls the method with the given signature. // and returns a Handle -// Initializes the cause if cause non-null -Handle Exceptions::new_exception(Thread *thread, Symbol* h_name, - Symbol* signature, - JavaCallArguments *args, - Handle h_cause, Handle h_loader, - Handle h_protection_domain) { +Handle Exceptions::new_exception(Thread *thread, Symbol* name, + Symbol* signature, JavaCallArguments *args, + Handle h_loader, Handle h_protection_domain) { assert(Universe::is_fully_initialized(), "cannot be called during initialization"); assert(thread->is_Java_thread(), "can only be called by a Java thread"); @@ -254,8 +257,8 @@ Handle h_exception; // Resolve exception klass - klassOop ik = SystemDictionary::resolve_or_fail(h_name, h_loader, h_protection_domain, true, thread); - instanceKlassHandle klass (thread, ik); + klassOop ik = SystemDictionary::resolve_or_fail(name, h_loader, h_protection_domain, true, thread); + instanceKlassHandle klass(thread, ik); if (!thread->has_pending_exception()) { assert(klass.not_null(), "klass must exist"); @@ -273,24 +276,8 @@ signature, args, thread); - } } - - // Future: object initializer should take a cause argument - if (h_cause() != NULL) { - assert(h_cause->is_a(SystemDictionary::Throwable_klass()), - "exception cause is not a subclass of java/lang/Throwable"); - JavaValue result1(T_OBJECT); - JavaCallArguments args1; - args1.set_receiver(h_exception); - args1.push_oop(h_cause); - JavaCalls::call_virtual(&result1, klass, - vmSymbols::initCause_name(), - vmSymbols::throwable_throwable_signature(), - &args1, - thread); - } } // Check if another exception was thrown in the process, if so rethrow that one @@ -301,12 +288,60 @@ return h_exception; } +// Creates an exception oop, calls the method with the given signature. +// and returns a Handle +// Initializes the cause if cause non-null +Handle Exceptions::new_exception(Thread *thread, Symbol* name, + Symbol* signature, JavaCallArguments *args, + Handle h_cause, + Handle h_loader, Handle h_protection_domain) { + Handle h_exception = new_exception(thread, name, signature, args, h_loader, h_protection_domain); + + // Future: object initializer should take a cause argument + if (h_cause.not_null()) { + assert(h_cause->is_a(SystemDictionary::Throwable_klass()), + "exception cause is not a subclass of java/lang/Throwable"); + JavaValue result1(T_OBJECT); + JavaCallArguments args1; + args1.set_receiver(h_exception); + args1.push_oop(h_cause); + JavaCalls::call_virtual(&result1, h_exception->klass(), + vmSymbols::initCause_name(), + vmSymbols::throwable_throwable_signature(), + &args1, + thread); + } + + // Check if another exception was thrown in the process, if so rethrow that one + if (thread->has_pending_exception()) { + h_exception = Handle(thread, thread->pending_exception()); + thread->clear_pending_exception(); + } + return h_exception; +} + +// Convenience method. Calls either the () or (Throwable) method when +// creating a new exception +Handle Exceptions::new_exception(Thread* thread, Symbol* name, + Handle h_cause, + Handle h_loader, Handle h_protection_domain, + ExceptionMsgToUtf8Mode to_utf8_safe) { + JavaCallArguments args; + Symbol* signature = NULL; + if (h_cause.is_null()) { + signature = vmSymbols::void_method_signature(); + } else { + signature = vmSymbols::throwable_void_signature(); + args.push_oop(h_cause); + } + return new_exception(thread, name, signature, &args, h_loader, h_protection_domain); +} + // Convenience method. Calls either the () or (String) method when // creating a new exception -Handle Exceptions::new_exception(Thread* thread, Symbol* h_name, +Handle Exceptions::new_exception(Thread* thread, Symbol* name, const char* message, Handle h_cause, - Handle h_loader, - Handle h_protection_domain, + Handle h_loader, Handle h_protection_domain, ExceptionMsgToUtf8Mode to_utf8_safe) { JavaCallArguments args; Symbol* signature = NULL; @@ -320,7 +355,7 @@ // the exception we are trying to build, or the pending exception. // This is sort of like what PRESERVE_EXCEPTION_MARK does, except // for the preferencing and the early returns. - Handle incoming_exception (thread, NULL); + Handle incoming_exception(thread, NULL); if (thread->has_pending_exception()) { incoming_exception = Handle(thread, thread->pending_exception()); thread->clear_pending_exception(); @@ -344,7 +379,7 @@ args.push_oop(msg); signature = vmSymbols::string_void_signature(); } - return new_exception(thread, h_name, signature, &args, h_cause, h_loader, h_protection_domain); + return new_exception(thread, name, signature, &args, h_cause, h_loader, h_protection_domain); } // Another convenience method that creates handles for null class loaders and @@ -355,8 +390,7 @@ // encoding scheme of the string into account. One thing we should do at some // point is to push this flag down to class java_lang_String since other // classes may need similar functionalities. -Handle Exceptions::new_exception(Thread* thread, - Symbol* name, +Handle Exceptions::new_exception(Thread* thread, Symbol* name, const char* message, ExceptionMsgToUtf8Mode to_utf8_safe) {