# HG changeset patch # User Doug Simon # Date 1472226558 -7200 # Node ID a074ae16281debaae6c47ab7905f17ddf267fcde # Parent 76ab52763a5d642f27183e3e123c57788c0fb46f backport of JDK-8164480 diff -r 76ab52763a5d -r a074ae16281d src/share/vm/c1/c1_Runtime1.cpp --- a/src/share/vm/c1/c1_Runtime1.cpp Wed Aug 24 22:31:34 2016 +0200 +++ b/src/share/vm/c1/c1_Runtime1.cpp Fri Aug 26 17:49:18 2016 +0200 @@ -544,9 +544,8 @@ // normal bytecode execution. thread->clear_exception_oop_and_pc(); - Handle original_exception(thread, exception()); - - continuation = SharedRuntime::compute_compiled_exc_handler(nm, pc, exception, false, false); + bool recursive_exception = false; + continuation = SharedRuntime::compute_compiled_exc_handler(nm, pc, exception, false, false, recursive_exception); // If an exception was thrown during exception dispatch, the exception oop may have changed thread->set_exception_oop(exception()); thread->set_exception_pc(pc); @@ -554,8 +553,9 @@ // the exception cache is used only by non-implicit exceptions // Update the exception cache only when there didn't happen // another exception during the computation of the compiled - // exception handler. - if (continuation != NULL && original_exception() == exception()) { + // exception handler. Checking for exception oop equality is not + // sufficient because some exceptions are pre-allocated and reused. + if (continuation != NULL && !recursive_exception) { nm->add_handler_for_exception_and_pc(exception, pc, continuation); } } diff -r 76ab52763a5d -r a074ae16281d src/share/vm/jvmci/jvmciRuntime.cpp --- a/src/share/vm/jvmci/jvmciRuntime.cpp Wed Aug 24 22:31:34 2016 +0200 +++ b/src/share/vm/jvmci/jvmciRuntime.cpp Fri Aug 26 17:49:18 2016 +0200 @@ -305,13 +305,19 @@ // normal bytecode execution. thread->clear_exception_oop_and_pc(); - continuation = SharedRuntime::compute_compiled_exc_handler(nm, pc, exception, false, false); + bool recursive_exception = false; + continuation = SharedRuntime::compute_compiled_exc_handler(nm, pc, exception, false, false, recursive_exception); // If an exception was thrown during exception dispatch, the exception oop may have changed thread->set_exception_oop(exception()); thread->set_exception_pc(pc); - // the exception cache is used only by non-implicit exceptions - if (continuation != NULL && !SharedRuntime::deopt_blob()->contains(continuation)) { + // The exception cache is used only for non-implicit exceptions + // Update the exception cache only when another exception did + // occur during the computation of the compiled exception handler + // (e.g., when loading the class of the catch type). + // Checking for exception oop equality is not + // sufficient because some exceptions are pre-allocated and reused. + if (continuation != NULL && !recursive_exception && !SharedRuntime::deopt_blob()->contains(continuation)) { nm->add_handler_for_exception_and_pc(exception, pc, continuation); } } diff -r 76ab52763a5d -r a074ae16281d src/share/vm/opto/runtime.cpp --- a/src/share/vm/opto/runtime.cpp Wed Aug 24 22:31:34 2016 +0200 +++ b/src/share/vm/opto/runtime.cpp Fri Aug 26 17:49:18 2016 +0200 @@ -1129,17 +1129,22 @@ force_unwind ? NULL : nm->handler_for_exception_and_pc(exception, pc); if (handler_address == NULL) { - Handle original_exception(thread, exception()); - handler_address = SharedRuntime::compute_compiled_exc_handler(nm, pc, exception, force_unwind, true); + bool recursive_exception = false; + handler_address = SharedRuntime::compute_compiled_exc_handler(nm, pc, exception, force_unwind, true, recursive_exception); assert (handler_address != NULL, "must have compiled handler"); // Update the exception cache only when the unwind was not forced // and there didn't happen another exception during the computation of the - // compiled exception handler. - if (!force_unwind && original_exception() == exception()) { + // compiled exception handler. Checking for exception oop equality is not + // sufficient because some exceptions are pre-allocated and reused. + if (!force_unwind && recursive_exception) { nm->add_handler_for_exception_and_pc(exception,pc,handler_address); } } else { - assert(handler_address == SharedRuntime::compute_compiled_exc_handler(nm, pc, exception, force_unwind, true), "Must be the same"); +#ifdef ASSERT + bool recursive_exception = false; + address computed_address = SharedRuntime::compute_compiled_exc_handler(nm, pc, exception, force_unwind, true, recursive_exception); + assert(recursive_exception || (handler_address == computed_address), "Handler address inconsistency"); +#endif } } diff -r 76ab52763a5d -r a074ae16281d src/share/vm/runtime/sharedRuntime.cpp --- a/src/share/vm/runtime/sharedRuntime.cpp Wed Aug 24 22:31:34 2016 +0200 +++ b/src/share/vm/runtime/sharedRuntime.cpp Fri Aug 26 17:49:18 2016 +0200 @@ -646,7 +646,7 @@ // ret_pc points into caller; we are returning caller's exception handler // for given exception address SharedRuntime::compute_compiled_exc_handler(nmethod* nm, address ret_pc, Handle& exception, - bool force_unwind, bool top_frame_only) { + bool force_unwind, bool top_frame_only, bool& recursive_exception_occurred) { assert(nm != NULL, "must exist"); ResourceMark rm; @@ -701,6 +701,7 @@ // BCI of the exception handler which caused the exception to be // thrown (bugs 4307310 and 4546590). Set "exception" reference // argument to ensure that the correct exception is thrown (4870175). + recursive_exception_occurred = true; exception = Handle(THREAD, PENDING_EXCEPTION); CLEAR_PENDING_EXCEPTION; if (handler_bci >= 0) { diff -r 76ab52763a5d -r a074ae16281d src/share/vm/runtime/sharedRuntime.hpp --- a/src/share/vm/runtime/sharedRuntime.hpp Wed Aug 24 22:31:34 2016 +0200 +++ b/src/share/vm/runtime/sharedRuntime.hpp Fri Aug 26 17:49:18 2016 +0200 @@ -178,7 +178,7 @@ // exception handling and implicit exceptions static address compute_compiled_exc_handler(nmethod* nm, address ret_pc, Handle& exception, - bool force_unwind, bool top_frame_only); + bool force_unwind, bool top_frame_only, bool& recursive_exception_occurred); enum ImplicitExceptionKind { IMPLICIT_NULL, IMPLICIT_DIVIDE_BY_ZERO,