8189794: Assert in InstanceKlass::cast called from Exceptions::new_exceptions

Fix call to InstanceKlass::cast to only be after verifying class is non-null.

Reviewed-by: dholmes, sspitsyn
This commit is contained in:
Coleen Phillimore 2017-10-24 08:29:00 -04:00
parent a5d5806cb4
commit 3ba67ae4df

View file

@ -218,10 +218,10 @@ void Exceptions::_throw_cause(Thread* thread, const char* file, int line, Symbol
void Exceptions::throw_stack_overflow_exception(Thread* THREAD, const char* file, int line, const methodHandle& method) { void Exceptions::throw_stack_overflow_exception(Thread* THREAD, const char* file, int line, const methodHandle& method) {
Handle exception; Handle exception;
if (!THREAD->has_pending_exception()) { if (!THREAD->has_pending_exception()) {
Klass* k = SystemDictionary::StackOverflowError_klass(); InstanceKlass* k = SystemDictionary::StackOverflowError_klass();
oop e = InstanceKlass::cast(k)->allocate_instance(CHECK); oop e = k->allocate_instance(CHECK);
exception = Handle(THREAD, e); // fill_in_stack trace does gc exception = Handle(THREAD, e); // fill_in_stack trace does gc
assert(InstanceKlass::cast(k)->is_initialized(), "need to increase java_thread_min_stack_allowed calculation"); assert(k->is_initialized(), "need to increase java_thread_min_stack_allowed calculation");
if (StackTraceInThrowable) { if (StackTraceInThrowable) {
java_lang_Throwable::fill_in_stack_trace(exception, method()); java_lang_Throwable::fill_in_stack_trace(exception, method());
} }
@ -258,25 +258,26 @@ Handle Exceptions::new_exception(Thread *thread, Symbol* name,
Handle h_exception; Handle h_exception;
// Resolve exception klass // Resolve exception klass, and check for pending exception below.
InstanceKlass* klass = InstanceKlass::cast(SystemDictionary::resolve_or_fail(name, h_loader, h_protection_domain, true, thread)); Klass* klass = SystemDictionary::resolve_or_fail(name, h_loader, h_protection_domain, true, thread);
if (!thread->has_pending_exception()) { if (!thread->has_pending_exception()) {
assert(klass != NULL, "klass must exist"); assert(klass != NULL, "klass must exist");
// We are about to create an instance - so make sure that klass is initialized // We are about to create an instance - so make sure that klass is initialized
klass->initialize(thread); InstanceKlass* ik = InstanceKlass::cast(klass);
ik->initialize(thread);
if (!thread->has_pending_exception()) { if (!thread->has_pending_exception()) {
// Allocate new exception // Allocate new exception
h_exception = klass->allocate_instance_handle(thread); h_exception = ik->allocate_instance_handle(thread);
if (!thread->has_pending_exception()) { if (!thread->has_pending_exception()) {
JavaValue result(T_VOID); JavaValue result(T_VOID);
args->set_receiver(h_exception); args->set_receiver(h_exception);
// Call constructor // Call constructor
JavaCalls::call_special(&result, klass, JavaCalls::call_special(&result, ik,
vmSymbols::object_initializer_name(), vmSymbols::object_initializer_name(),
signature, signature,
args, args,
thread); thread);
} }
} }
} }