Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@headius
Copy link
Member

@headius headius commented Jul 28, 2025

Specs and tests run only once, but much of JRuby's logic for optimizing code only runs after call sites have been executed more than once. This patch adds a CI job that runs ruby/spec examples at least twice to ensure such logic is tested.

headius added 9 commits August 6, 2025 19:32
Specs and tests run only once, but much of JRuby's logic for
optimizing code only runs after call sites have been executed more
than once. This patch adds a CI job that runs language examples
at least twice to ensure such logic is tested.

Currently this runs the specs four times, to try to ensure that
all optimizations are tested. This is based on an expectation that
most code will pass through the following stages (with JIT
threshold set to 0):

* Methods will be forced to JIT and execute their compiled form
  immediately, but blocks may delay compilation if their
  surrounding method has not yet been compiled. This first stage
  may run in the interpreter.
* Once compiled, call sites and other caches (like global vars)
  will initially be unoptimized, executing similar to the way
  the interpreter handles these constructs. This second stage
  is compiled, but unoptimized.
* After the initial encounter of a call site, the optimized code
  will be installed for future invocations. This third stage is
  now compiled and using optimized call sites.
* Some sites, such as those that redispatch for new/initialize
  or !=, may have additional caches that will not be encountered
  until the optimized code has been installed. This fourth stage
  helps ensure such multi-layer caches have optimized.

There are other cases where more than 4 runs may be necessary,
such as for polymorphic sites that must be built up across many
calls, but such cases usually will only have slight differences in
behavior from monomorphic sites (primarily around the cascading
PIC logic that searches for a matching type). Rather than attempt
to add additional runs with diminishing returns, we may explore
more repetitive runs on a narrower set of specs.

I have also included a small patch for mspec to allow using the
repeat flag in CI mode (previously it was only available for the
run command.
NthRef has the side effect requirement of a backref frame, so it
should not be represented as a side-effect free operand. This
patch introduces BuildNthRefInstr due to requirements that high
group numbers warn, which conflicts with the lettered backrefs
used in BuildBackrefInstr.

The lack of a frame caused optimized NthRef logic in the JIT to
fail to push a frame, which caused those references to break once
JIT had settled.

This patch also fixes defined?(any backref form) to also trigger a
backref frame, also broken once JIT settled.
Undefined globals should continue to retrieve and trigger the
undefined warning every time. By caching the result, we stop
attempting to retrieve it, which causes the warning to stop
displaying.
The JIT does not push backtrace frames, so we cannot rely on such
frames being in context for eval location reporting. This patch
modifies such calls to use full backtrace construction, done lazily
now to avoid full JVM stack reification, so that eval parent frames
can JIT without losing the backtrace information eval expects to be
able to report.

This only became visible while running specs repeatedly and
allowing eval parent frames to JIT at runtime, which would suddenly
cause their parent backtrace frame to disappear and the eval to
use an ancestor's backtrace location instead.
The modified spec requires a file but does not clean up afterwards.
This prevents it from being run repeatedly, since n+1 runs will
fail to actually execute the required script. The CodeLoading
fixture is used in the require specs for this sort of cleanup.
Private to_s should still be invoked, so switch this to doing a
functional-style call. This only affects optimized dstr on their
second and higher invocations.
@headius headius modified the milestones: Non-Release, JRuby 10.0.2.0 Aug 6, 2025
@headius headius merged commit 0e417ef into jruby:master Aug 6, 2025
73 checks passed
@headius headius deleted the repeat_specs branch August 6, 2025 18:06
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.

1 participant