Skip to content
46 changes: 21 additions & 25 deletions src/hotspot/share/opto/graphKit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ Pair<bool, bool> GraphKit::builtin_throw_applies(Deoptimization::DeoptReason rea
}

//------------------------------builtin_throw----------------------------------
void GraphKit::builtin_throw(Deoptimization::DeoptReason reason, ciInstance* exception_object) {
void GraphKit::builtin_throw(Deoptimization::DeoptReason reason, ciInstance* ex_obj) {
bool must_throw = true;
Pair<bool, bool> applies_and_treat_throw_as_hot = builtin_throw_applies(reason);
bool treat_throw_as_hot = applies_and_treat_throw_as_hot.second;
Expand All @@ -569,30 +569,6 @@ void GraphKit::builtin_throw(Deoptimization::DeoptReason reason, ciInstance* exc
// for its backtrace.
// Fixing this remaining case of 4292742 requires some flavor of
// escape analysis. Leave that for the future.
ciInstance* ex_obj = nullptr;
if (exception_object != nullptr) {
ex_obj = exception_object;
} else {
switch (reason) {
case Deoptimization::Reason_null_check:
ex_obj = env()->NullPointerException_instance();
break;
case Deoptimization::Reason_div0_check:
ex_obj = env()->ArithmeticException_instance();
break;
case Deoptimization::Reason_range_check:
ex_obj = env()->ArrayIndexOutOfBoundsException_instance();
break;
case Deoptimization::Reason_class_check:
ex_obj = env()->ClassCastException_instance();
break;
case Deoptimization::Reason_array_check:
ex_obj = env()->ArrayStoreException_instance();
break;
default:
break;
}
}
if (failing()) { stop(); return; } // exception allocation might fail
if (ex_obj != nullptr) {
if (env()->jvmti_can_post_on_exceptions()) {
Expand Down Expand Up @@ -660,6 +636,26 @@ void GraphKit::builtin_throw(Deoptimization::DeoptReason reason, ciInstance* exc
uncommon_trap(reason, action, (ciKlass*)nullptr, (char*)nullptr, must_throw);
}

ciInstance* GraphKit::guess_exception_from_deopt_reason(Deoptimization::DeoptReason reason) const {
switch (reason) {
case Deoptimization::Reason_null_check:
return env()->NullPointerException_instance();
case Deoptimization::Reason_div0_check:
return env()->ArithmeticException_instance();
case Deoptimization::Reason_range_check:
return env()->ArrayIndexOutOfBoundsException_instance();
case Deoptimization::Reason_class_check:
return env()->ClassCastException_instance();
case Deoptimization::Reason_array_check:
return env()->ArrayStoreException_instance();
default:
return nullptr;
}
}

void GraphKit::builtin_throw(Deoptimization::DeoptReason reason) {
builtin_throw(reason, guess_exception_from_deopt_reason(reason));
}

//----------------------------PreserveJVMState---------------------------------
PreserveJVMState::PreserveJVMState(GraphKit* kit, bool clone_map) {
Expand Down
6 changes: 3 additions & 3 deletions src/hotspot/share/opto/graphKit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,10 @@ class GraphKit : public Phase {

// Helper to throw a built-in exception.
// The JVMS must allow the bytecode to be re-executed via an uncommon trap.
// If `exception_object` is nullptr, the exception to throw will be guessed based on `reason`
void builtin_throw(Deoptimization::DeoptReason reason, ciInstance* exception_object = nullptr);
// Returns the pair (builtin_throw_applies, throw_is_hot) for builtin_throw usage.
void builtin_throw(Deoptimization::DeoptReason reason);
void builtin_throw(Deoptimization::DeoptReason reason, ciInstance* exception_object);
Pair<bool, bool> builtin_throw_applies(Deoptimization::DeoptReason reason);
ciInstance* guess_exception_from_deopt_reason(Deoptimization::DeoptReason reason) const;

// Helper to check the JavaThread::_should_post_on_exceptions flag
// and branch to an uncommon_trap if it is true (with the specified reason and must_throw)
Expand Down
Loading