Skip to content

Add SimulatorThread support for Thread subclasses under simulation#29

Merged
ylecaillez merged 1 commit intopingidentity:mainfrom
ylecaillez:feature/simulator-thread
Apr 11, 2026
Merged

Add SimulatorThread support for Thread subclasses under simulation#29
ylecaillez merged 1 commit intopingidentity:mainfrom
ylecaillez:feature/simulator-thread

Conversation

@ylecaillez
Copy link
Copy Markdown
Collaborator

Solve the 'extends Thread' problem: classes that subclass Thread now run as virtual threads under deterministic simulation.

Build-time:

  • PatchModuleGenerator creates opendst-patch.jar with a non-final VirtualThread and SimulatorThread that mirrors all Thread constructors using a trampoline pattern (Thread.currentThread().run())
  • CallSiteTransform rewrites direct Thread subclasses to extend SimulatorThread and redirects super() calls accordingly
  • BuildMojo packages opendst-patch.jar into the self-contained JAR
  • Build JDK version recorded in MANIFEST for runtime validation

Runtime:

  • TestExecutor adds --patch-module java.base=opendst-patch.jar
  • BuildRunner verifies the build JDK version matches the runtime JDK
  • SimulatorAgent installs EXECUTOR_SUPPLIER (provides per-node scheduler during construction) and ON_CONSTRUCT callback (attaches threads to the current node after construction)

Also removes CDS support: --patch-module on java.base makes CDS impossible (JVM refuses it), so the --cds/--no-cds flag was dead code.

@ylecaillez ylecaillez force-pushed the feature/simulator-thread branch 2 times, most recently from 4b7bbfc to 60ded94 Compare April 11, 2026 16:30
… simulation

Rewrite Thread subclasses to extend SimulatorThread (a VirtualThread injected
into java.base via --patch-module) so they run under the deterministic scheduler.

This is experimental and may be reverted if it causes more issues than it solves.
The approach of patching java.base and rewriting superclass hierarchies is
inherently fragile and may break with JDK updates or unusual Thread subclass
patterns.

Build time:
- PatchModuleGenerator strips ACC_FINAL from VirtualThread and compiles
  SimulatorThread from source, packaging both into opendst-patch.jar
- Instrumentation rewrites 'extends Thread' to 'extends SimulatorThread'
  and redirects super() calls in constructors

Runtime:
- --patch-module java.base=opendst-patch.jar injects SimulatorThread
- installSimulatorThreadCallback() wires the per-node executor and
  thread attachment callbacks into SimulatorThread's static fields

Also removes CDS support as it is incompatible with --patch-module.
@ylecaillez ylecaillez force-pushed the feature/simulator-thread branch from 60ded94 to b738cb0 Compare April 11, 2026 19:53
@ylecaillez ylecaillez merged commit ded8a06 into pingidentity:main Apr 11, 2026
1 check passed
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