Skip to content

Commit fbfb5ba

Browse files
committed
docs(runners): document the JVM build lock and the per-run class copy
1 parent b3712e9 commit fbfb5ba

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

‎docs/architecture.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Dependencies point inward. Ports are Python `Protocol` classes in `cli/src/codin
5252
| `ItemRepository` | `FsItemRepository` | Reads the non-autograded items in `tracks/<track>/<slug>/` and validates `item.yaml` with JSON Schema, through the same `.cs/index.json` |
5353
| `StudyGuides` | `FsStudyGuides` | Locates the user's own study guides under config `study_guides.root` for item statements ([study guides](specs/content.md#study-guides)) |
5454
| `ProgressStore` | `SqliteProgressStore` | Schema in [progress-and-scheduling](specs/progress-and-scheduling.md) |
55-
| `LanguageRunner` | one per language (`adapters/languages/<python,typescript,jvm>/`) | `prepare(scope, notify)` returns `Prepared` (launch command) or `BuildFailed`, building when needed; scope `BenchCode` prepares the user's code and the references for one bench process |
55+
| `LanguageRunner` | one per language (`adapters/languages/<python,typescript,jvm>/`) | `prepare(scope, notify)` returns `Prepared` (launch command) or `BuildFailed`, building when needed; scope `BenchCode` prepares the user's code and the references for one bench process. Several `cstudy` processes may share a workspace: the JVM adapter builds under a file lock and launches from a private copy of the build output ([JVM build details](specs/runners.md#jvm-build-details)), which `RunnerProcess` removes when the run ends (`RunnerLaunch.scratch`) |
5656
| `RunnerProcess` | `SubprocessRunner` (one for every language) | `run(launch, request) -> RunReport` and `bench(launch, request) -> BenchReport`: request file, event file, hang guard, restarts; protocol in [runners](specs/runners.md) |
5757
| `MachineProbe` | `SystemMachine` | CPU model, power source, load average and core count for a bench run's environment record |
5858
| `StubGenerator` | one per language | `generate(meta) -> text`; mapping table in [problem-format](specs/problem-format.md#type-dsl) |

‎docs/specs/runners.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ Paths are relative to the workspace root. The runners themselves run from the wo
3434
| JVM flags | `-XX:+UseSerialGC -Xshare:auto`; no tiering flags (they distort performance cases) |
3535
| Compile errors | Gradle exit code non-zero: the CLI prints compiler lines mentioning the user's file (max 40 lines) and exits 2 |
3636
| Cold start | If no daemon is running, the CLI prints `warming Gradle daemon (first run)` before building |
37+
| Locking | `-Pcs.only` narrows each build to one problem, so every build rewrites the shared output directories and deletes the classes of the problem built before. Per Gradle project and language, one `cstudy` process at a time writes the reference sources (and removes the other approaches' files), runs Gradle and copies the built class directories: an exclusive `flock` on `.cs/build/jvm-locks/<references or practice>-<lang>.lock`. A process that finds the lock taken prints `waiting for another cstudy build in this workspace` and waits; the kernel drops the lock when its holder ends, however it ends. Java and Kotlin use different locks and still build side by side. |
38+
| Per-run class copy | Under the lock, the build's class directories (the classpath entries below the subproject's `build/`) are copied into `.cs/build/jvm-runs/<pid>-<random>/`, and the JVM's `-cp` names the copy; jars, including the runner and support jars, keep their paths. A later build for another problem cannot take classes away from a JVM that loads them lazily. The runner process removes the copy when the run ends (completed, failed or interrupted); the next preparation removes copies whose process no longer exists (killed). |
39+
40+
The lock and the copy protect against other `cstudy` processes. A Gradle build started by anything else on the same project (a script, an IDE build of `.cs/build/jvm`) does not take the lock and can still delete classes between the build and the copy.
3741

3842
## Request file
3943

0 commit comments

Comments
 (0)