@@ -3778,6 +3778,20 @@ bool LibraryCallKit::inline_native_Continuation_pinning(bool unpin) {
37783778 Node* test_pin_count_over_underflow = _gvn.transform (new BoolNode (pin_count_cmp, BoolTest::eq));
37793779 IfNode* iff_pin_count_over_underflow = create_and_map_if (control (), test_pin_count_over_underflow, PROB_MIN, COUNT_UNKNOWN);
37803780
3781+ // True branch, pin count over/underflow.
3782+ Node* pin_count_over_underflow = _gvn.transform (new IfTrueNode (iff_pin_count_over_underflow));
3783+ {
3784+ // Trap (but not deoptimize (Action_none)) and continue in the interpreter
3785+ // which will throw IllegalStateException for pin count over/underflow.
3786+ // No memory changed so far - we can use memory create by reset_memory()
3787+ // at the beginning of this intrinsic. No need to call reset_memory() again.
3788+ PreserveJVMState pjvms (this );
3789+ set_control (pin_count_over_underflow);
3790+ uncommon_trap (Deoptimization::Reason_intrinsic,
3791+ Deoptimization::Action_none);
3792+ assert (stopped (), " invariant" );
3793+ }
3794+
37813795 // False branch, no pin count over/underflow. Increment or decrement pin count and store back.
37823796 Node* valid_pin_count = _gvn.transform (new IfFalseNode (iff_pin_count_over_underflow));
37833797 set_control (valid_pin_count);
@@ -3789,20 +3803,7 @@ bool LibraryCallKit::inline_native_Continuation_pinning(bool unpin) {
37893803 next_pin_count = _gvn.transform (new AddINode (pin_count, _gvn.intcon (1 )));
37903804 }
37913805
3792- Node* updated_pin_count_memory = store_to_memory (control (), pin_count_offset, next_pin_count, T_INT, MemNode::unordered);
3793-
3794- // True branch, pin count over/underflow.
3795- Node* pin_count_over_underflow = _gvn.transform (new IfTrueNode (iff_pin_count_over_underflow));
3796- {
3797- // Trap (but not deoptimize (Action_none)) and continue in the interpreter
3798- // which will throw IllegalStateException for pin count over/underflow.
3799- PreserveJVMState pjvms (this );
3800- set_control (pin_count_over_underflow);
3801- set_all_memory (input_memory_state);
3802- uncommon_trap_exact (Deoptimization::Reason_intrinsic,
3803- Deoptimization::Action_none);
3804- assert (stopped (), " invariant" );
3805- }
3806+ store_to_memory (control (), pin_count_offset, next_pin_count, T_INT, MemNode::unordered);
38063807
38073808 // Result of top level CFG and Memory.
38083809 RegionNode* result_rgn = new RegionNode (PATH_LIMIT);
@@ -3812,7 +3813,7 @@ bool LibraryCallKit::inline_native_Continuation_pinning(bool unpin) {
38123813
38133814 result_rgn->init_req (_true_path, _gvn.transform (valid_pin_count));
38143815 result_rgn->init_req (_false_path, _gvn.transform (continuation_is_null));
3815- result_mem->init_req (_true_path, _gvn.transform (updated_pin_count_memory ));
3816+ result_mem->init_req (_true_path, _gvn.transform (reset_memory () ));
38163817 result_mem->init_req (_false_path, _gvn.transform (input_memory_state));
38173818
38183819 // Set output state.
0 commit comments