@@ -525,17 +525,13 @@ void GraphKit::uncommon_trap_if_should_post_on_exceptions(Deoptimization::DeoptR
525
525
526
526
}
527
527
528
- // ------------------------------builtin_throw----------------------------------
529
- void GraphKit::builtin_throw (Deoptimization::DeoptReason reason) {
530
- bool must_throw = true ;
531
-
528
+ Pair<bool , bool > GraphKit::builtin_throw_applies (Deoptimization::DeoptReason reason) {
532
529
// If this particular condition has not yet happened at this
533
530
// bytecode, then use the uncommon trap mechanism, and allow for
534
531
// a future recompilation if several traps occur here.
535
532
// If the throw is hot, try to use a more complicated inline mechanism
536
533
// which keeps execution inside the compiled code.
537
534
bool treat_throw_as_hot = false ;
538
- ciMethodData* md = method ()->method_data ();
539
535
540
536
if (ProfileTraps) {
541
537
if (too_many_traps (reason)) {
@@ -547,45 +543,55 @@ void GraphKit::builtin_throw(Deoptimization::DeoptReason reason) {
547
543
548
544
// Also, if there is a local exception handler, treat all throws
549
545
// as hot if there has been at least one in this method.
550
- if (C->trap_count (reason) != 0
551
- && method ()->method_data ()->trap_count (reason) != 0
552
- && has_exception_handler ()) {
553
- treat_throw_as_hot = true ;
546
+ if (C->trap_count (reason) != 0 && method ()->method_data ()->trap_count (reason) != 0 && has_exception_handler ()) {
547
+ treat_throw_as_hot = true ;
554
548
}
555
549
}
550
+ return {treat_throw_as_hot && method ()->can_omit_stack_trace (), treat_throw_as_hot};
551
+ }
552
+
553
+ // ------------------------------builtin_throw----------------------------------
554
+ void GraphKit::builtin_throw (Deoptimization::DeoptReason reason, ciInstance* exception_object) {
555
+ bool must_throw = true ;
556
+ Pair<bool , bool > applies_and_treat_throw_as_hot = builtin_throw_applies (reason);
557
+ bool treat_throw_as_hot = applies_and_treat_throw_as_hot.second ;
556
558
557
559
// If this throw happens frequently, an uncommon trap might cause
558
560
// a performance pothole. If there is a local exception handler,
559
561
// and if this particular bytecode appears to be deoptimizing often,
560
562
// let us handle the throw inline, with a preconstructed instance.
561
563
// Note: If the deopt count has blown up, the uncommon trap
562
564
// runtime is going to flush this nmethod, not matter what.
563
- if (treat_throw_as_hot && method ()-> can_omit_stack_trace () ) {
565
+ if (applies_and_treat_throw_as_hot. first ) {
564
566
// If the throw is local, we use a pre-existing instance and
565
567
// punt on the backtrace. This would lead to a missing backtrace
566
568
// (a repeat of 4292742) if the backtrace object is ever asked
567
569
// for its backtrace.
568
570
// Fixing this remaining case of 4292742 requires some flavor of
569
571
// escape analysis. Leave that for the future.
570
572
ciInstance* ex_obj = nullptr ;
571
- switch (reason) {
572
- case Deoptimization::Reason_null_check:
573
- ex_obj = env ()->NullPointerException_instance ();
574
- break ;
575
- case Deoptimization::Reason_div0_check:
576
- ex_obj = env ()->ArithmeticException_instance ();
577
- break ;
578
- case Deoptimization::Reason_range_check:
579
- ex_obj = env ()->ArrayIndexOutOfBoundsException_instance ();
580
- break ;
581
- case Deoptimization::Reason_class_check:
582
- ex_obj = env ()->ClassCastException_instance ();
583
- break ;
584
- case Deoptimization::Reason_array_check:
585
- ex_obj = env ()->ArrayStoreException_instance ();
586
- break ;
587
- default :
588
- break ;
573
+ if (exception_object != nullptr ) {
574
+ ex_obj = exception_object;
575
+ } else {
576
+ switch (reason) {
577
+ case Deoptimization::Reason_null_check:
578
+ ex_obj = env ()->NullPointerException_instance ();
579
+ break ;
580
+ case Deoptimization::Reason_div0_check:
581
+ ex_obj = env ()->ArithmeticException_instance ();
582
+ break ;
583
+ case Deoptimization::Reason_range_check:
584
+ ex_obj = env ()->ArrayIndexOutOfBoundsException_instance ();
585
+ break ;
586
+ case Deoptimization::Reason_class_check:
587
+ ex_obj = env ()->ClassCastException_instance ();
588
+ break ;
589
+ case Deoptimization::Reason_array_check:
590
+ ex_obj = env ()->ArrayStoreException_instance ();
591
+ break ;
592
+ default :
593
+ break ;
594
+ }
589
595
}
590
596
if (failing ()) { stop (); return ; } // exception allocation might fail
591
597
if (ex_obj != nullptr ) {
0 commit comments