Skip to content

Implement :fiber_switch trace event - #9603

Merged
headius merged 1 commit into
jruby:masterfrom
headius:fiber_switch_event
Sep 10, 2026
Merged

headius merged 1 commit into
jruby:masterfrom
headius:fiber_switch_event

Conversation

@headius

@headius headius commented Aug 21, 2026

Copy link
Copy Markdown
Member

This is mostly working, but does not yet pass CRuby's test_fiber_switch in test_setttracefunc.rb for a few reasons:

  • The current thread check there is incompatible with JRuby's Thread.current being different for each Fiber.
  • Raise events are not being triggered from Fiber.raise or Fiber errors.

As usual, for accurate file and line numbers, it should be run with --debug.

Might be enough for #9600.

@headius headius added this to the JRuby 10.1.x milestone Aug 21, 2026
@headius headius modified the milestones: JRuby 10.1.x, JRuby 10.1.2.0 Aug 23, 2026
@headius
headius force-pushed the fiber_switch_event branch from 8c31668 to 9fd4e71 Compare August 31, 2026 20:53
headius added a commit to headius/jruby that referenced this pull request Aug 31, 2026
A few step toward getting Thread.current in general to behave like
CRuby, returning the same Thread for all Fiber instances that it
owns.

Behind the scenes, each Fiber is still backed by a VirtualThread
with an associated ThreadContext and RubyThread, but user code
should generally not see those.

Additional fixes will follow for internal code that has
expectations about the current thread of a fiber.

See other attempts to do this and issues related:

* My attempt: jruby#5827
* Community attempt: jruby#1225
* An early issue: jruby#1806

Relates to test failures mentioned in jruby#9603 and
workarounds from users in jruby#9600.
This is mostly working, but does not yet pass CRuby's
test_fiber_switch in test_setttracefunc.rb for a few reasons:

* The current thread check there is incompatible with JRuby's
  Thread.current being different for each Fiber.
* Raise events are not being triggered from Fiber.raise or Fiber
  errors.

As usual, for accurate file and line numbers, it should be run
with --debug.

Might be enough for jruby#9600.
@headius

headius commented Sep 10, 2026

Copy link
Copy Markdown
Member Author

Rebased and still does not pass the relevant test due to Thread.current behavior, but I think this would be fine to merge any time.

@headius
headius merged commit f4c0379 into jruby:master Sep 10, 2026
135 checks passed
@headius
headius deleted the fiber_switch_event branch September 10, 2026 22:28
@headius headius linked an issue Sep 10, 2026 that may be closed by this pull request
sampokuokkanen pushed a commit to sampokuokkanen/jruby that referenced this pull request Oct 30, 2026
A few step toward getting Thread.current in general to behave like
CRuby, returning the same Thread for all Fiber instances that it
owns.

Behind the scenes, each Fiber is still backed by a VirtualThread
with an associated ThreadContext and RubyThread, but user code
should generally not see those.

Additional fixes will follow for internal code that has
expectations about the current thread of a fiber.

See other attempts to do this and issues related:

* My attempt: jruby#5827
* Community attempt: jruby#1225
* An early issue: jruby#1806

Relates to test failures mentioned in jruby#9603 and
workarounds from users in jruby#9600.
sampokuokkanen pushed a commit to sampokuokkanen/jruby that referenced this pull request Nov 6, 2026
A few step toward getting Thread.current in general to behave like
CRuby, returning the same Thread for all Fiber instances that it
owns.

Behind the scenes, each Fiber is still backed by a VirtualThread
with an associated ThreadContext and RubyThread, but user code
should generally not see those.

Additional fixes will follow for internal code that has
expectations about the current thread of a fiber.

See other attempts to do this and issues related:

* My attempt: jruby#5827
* Community attempt: jruby#1225
* An early issue: jruby#1806

Relates to test failures mentioned in jruby#9603 and
workarounds from users in jruby#9600.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TracePoint does not support fiber_switch (Ruby 2.3+ compatibility)

1 participant