Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ The headline artifact is a states-explored reduction table: naive DFS → +hashi
Concurrency bugs — race conditions, deadlocks, missed signals — are notoriously hard to find because they depend on exact thread ordering. Rather than running a program once and hoping for the right schedule, this checker systematically explores every distinct interleaving and reports the exact `(thread, step)` schedule that reaches a bad state.

The selected [#12 bounded Java bytecode workstream](docs/plans/bytecode-contract.md)
has an **internal 94A loader and single-actor interpreter** ([evidence](docs/measurements/94A-bytecode-foundation.md)).
Concurrent search and public evidence/CLI/library selection follow in 94B/94C; no public bytecode
has an **internal loader, interpreter and concurrent exact DFS** (94A/94B; [foundation](docs/measurements/94A-bytecode-foundation.md), [concurrency evidence](docs/measurements/94B-bytecode-concurrency.md)).
94B includes pure checks and measured instruction-reference/batched execution. Public evidence/CLI/library selection follows in 94C; no public bytecode
selection is available yet. Weak-memory work remains unselected.

The project is built as a clean, spec-driven proof-of-concept. It is not a production Java bytecode checker; programs are modeled as explicit atomic steps or bounded `.ilv` source over cloneable shared state so the core algorithms can be taught, verified, and measured.
Expand Down
18 changes: 18 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,24 @@ tasks.register<JavaExec>("profileSearch") {
args(layout.buildDirectory.dir("reports/search-profile/fork-${fork.get()}").get().asFile.absolutePath, fork.get())
}

// Internal 94B measurement runner; target programs remain interpreted, with no production selector.
tasks.register<JavaExec>("profileBytecode") {
group = "verification"
description = "Measure instruction/reference bytecode execution (Spec 94B)"
dependsOn(tasks.testClasses)
classpath = sourceSets.test.get().runtimeClasspath
mainClass.set("dev.samhb.interleave.bytecode.BytecodeMeasurementTest")
javaLauncher.set(javaToolchains.launcherFor { languageVersion.set(JavaLanguageVersion.of(26)) })
minHeapSize = "512m"
maxHeapSize = "512m"
// Eliminate SerialGC dead-space retention, which otherwise contaminates live-heap deltas.
jvmArgs("-XX:+UseSerialGC", "-XX:MarkSweepDeadRatio=0")
val fork = providers.gradleProperty("profileFork").orElse("1")
val output = providers.gradleProperty("bytecodeProfileOutput")
.orElse(layout.buildDirectory.dir("reports/bytecode-profile/fork-${fork.get()}").get().asFile.absolutePath)
args(output.get(), fork.get())
}

tasks.withType<JavaCompile> {
options.encoding = Charsets.UTF_8.name()
options.release.set(26)
Expand Down
355 changes: 355 additions & 0 deletions docs/measurements/94B-bytecode-concurrency.md

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions docs/plans/bytecode-contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

## Objective and status

**Selected; 94A internal foundation implemented, public release pending.** Approved scope: controlled interpretation of compiled Java for fixed
**Selected; internal94A/94B implemented, public release pending.** Approved scope: controlled interpretation of compiled Java for fixed
actors under bounded sequential consistency (SC). The first public release must find a real lost update
and a two-lock deadlock through loading, search, evidence, strict replay, library/CLI, reports and viewer.
No target-code host-JVM fallback is permitted. This is not unrestricted Java or full Java Memory Model coverage.
Expand All @@ -12,7 +12,9 @@ Planning baseline: remote main `2a242c4`, freshly fetched during authoring. B10
PRs #136/#137 and its closure commit. Sam explicitly selected #12 after that stopping point; #11
and parked conditional/deferred tasks remain unselected. The specification PR established no runtime
evidence. The [94A implementation ledger](../measurements/94A-bytecode-foundation.md) records subsequent
loader/single-actor evidence; concurrency, batching, sharedness-cost, DPOR and JPF gates remain pending. [Vocabulary](../../CONTEXT.md) owns domain terms; this document
loader/single-actor evidence; [the94B ledger](../measurements/94B-bytecode-concurrency.md) records
internal concurrent execution, batching preservation and measured setup-only sharedness costs. Public
consumer support, broader heap costs, restricted DPOR and JPF gates remain pending. [Vocabulary](../../CONTEXT.md) owns domain terms; this document
owns common behavior, interface seams, verification and phase boundaries.

## Sequential delivery and ownership
Expand Down
11 changes: 6 additions & 5 deletions docs/plans/future-work.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ milestones (94A–94C, 95–101). #11 and deferred/conditional work remain unsel
|---|---|---|---|---|---|
| 10 | Symmetry reduction — complete | High | Spec-set | [Spec 75](../specs/active/75-thread-symmetry-canonicalization.md), [Spec 76](../specs/active/76-source-symmetry-exact-search.md) and [Spec 77](../specs/active/77-source-symmetry-strategy-composition.md) shipped in PRs #117–119. Final composition merged at `d8ad49e`: checked source symmetry for exact DFS, static POR, DPOR and CBS, including iterative CBS and original-identity evidence. | Completed in three coherent stages: canonicalization/mappings; checked exact DFS and evidence; exact POR/DPOR/CBS composition with proof, callers and regressions. K1 / [Spec 89](../specs/active/89-approximate-symmetry-dfs-por.md) adds approximate bitstate composition for explicit DFS/static POR; [Spec 90](../specs/active/90-approximate-symmetry-cbs.md) adds CBS in K2; [Spec 91](../specs/active/91-approximate-symmetry-dpor.md) adds DPOR and all-strategy consumers in K3, completing B9 with PR #134 merged at `3d5c09e`. Arbitrary custom-store composition remains unsupported. [Spec 84](../specs/active/84-certified-symmetry-backends.md) adds a separately selected HASHED/ORDERED library storage choice under post-task-#10 B6. B10 [declarative JSON spec set](declarative-symmetry-contract.md) is selected: Specs 92/93 merged in PR #135; L1 exact support merged in PR #136 at `013c963`; L2 approximate support merged in PR #137 at `aebb919`, completing B10. All selected post-task-#10 follow-ups are complete. #12 is subsequently selected separately; #11 and deferred/conditional work remain parked. |
| 11 | Relaxed memory models | Very High | Spec-set | Fundamental semantics change — needs formal spec | Stage one selected memory model: state/transition foundations; complete execution and witness support; supported search/reduction integration. Keep each additional memory model separate. Exact PR count follows the semantics/proof scope. |
| 12 | Bounded Java bytecode checking — selected, internal foundation | Very High | Spec-set | Controlled JDK 26 Class-File API interpretation of fixed actors under bounded SC; no target host execution. | [Shared contract and Specs 94A–101](bytecode-contract.md): internal foundation (94A), concurrent feasibility gate (94B), complete public release (94C), then heap, exceptions, core library, CBS, restricted DPOR, narrow atomics and bitstate. 94A adds internal loading/single-actor execution; [foundation evidence](../measurements/94A-bytecode-foundation.md). Target ten sequential implementation PRs; concurrency/batching, DPOR and JPF measurements remain pending. |
| 12 | Bounded Java bytecode checking — selected, internal concurrency | Very High | Spec-set | Controlled JDK 26 Class-File API interpretation of fixed actors under bounded SC; no target host execution. | [Shared contract and Specs 94A–101](bytecode-contract.md): internal foundation (94A), concurrent feasibility gate (94B), complete public release (94C), then heap, exceptions, core library, CBS, restricted DPOR, narrow atomics and bitstate. 94A adds internal loading/single-actor execution; [foundation evidence](../measurements/94A-bytecode-foundation.md). 94B adds internal concurrent exact DFS, checks and measured batching; [concurrency evidence](../measurements/94B-bytecode-concurrency.md). Target ten sequential implementation PRs; public release, DPOR measurements and JPF acceptance remain pending. |

## Deferred

Expand Down Expand Up @@ -205,9 +205,10 @@ planned. **PR grouping:** none while deferred; do not bundle with active visuali

11. **Relaxed memory models** — support weak consistency models (e.g., ARM/POWER) instead of assuming sequential consistency. Fundamental change to `Configuration` snapshot semantics and step execution.

12. **Bounded Java bytecode checking — selected, internal foundation** — [contract/specification index](bytecode-contract.md).
12. **Bounded Java bytecode checking — selected, internal concurrency** — [contract/specification index](bytecode-contract.md).
Interpret compiled Java17–26 inputs with metadata-only JDK26 Class-File API and fixed annotation-declared
actors under bounded SC. 94A provides internal loading/single-actor interpretation; the
[foundation ledger](../measurements/94A-bytecode-foundation.md) records its evidence. Initial public
release follows 94B/94C; batching/sharedness measurements, optimized reduction and JPF acceptance
remain pending.
[foundation ledger](../measurements/94A-bytecode-foundation.md) records its evidence. 94B adds internal
concurrent exact DFS, pure checks and measured reference/batched execution; the
[concurrency ledger](../measurements/94B-bytecode-concurrency.md) records its evidence. Initial public
release remains 94C; optimized reduction and JPF acceptance remain pending.
32 changes: 21 additions & 11 deletions docs/specs/active/94B-bytecode-concurrency.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<!-- Roadmap #12 / 94B: implementation milestone specification; no production implementation in this PR. -->
<!-- Roadmap #12 / 94B: internal concurrent execution and its feasibility acceptance contract. -->
# Spec 94B: Concurrent execution and feasibility

## Objective

Deliver concurrent execution and feasibility as one coherent stage of bounded Java bytecode checking.
**Type: delta. Status: specified, not implemented or measured.** The
**Type: delta. Status: implemented; local acceptance complete, PR review pending.** The
[shared #12 contract](../../plans/bytecode-contract.md) is normative for common semantics, limits,
interface signatures, profile exclusions, phase ownership and verification. This spec owns 94B only.

Expand Down Expand Up @@ -117,18 +117,28 @@ choose existing equivalent modules at implementation after connected-source insp
- [verified] Planning main is `2a242c4`; the existing engine has immutable Program, forward SourceStep
continuations and source-specific evidence. The shared contract records inspected integration constraints.
- [approved decision] This milestone and the shared contract define the selected behavior/release boundary.
- [unverified] This milestone's bytecode implementation, measurements, compiler/runtime acceptance and
mutation results. No authoring review establishes those results.
- [implementation] Internal `BytecodeScheduler`, `BytecodeExplorer`, `BytecodeChecks` and
`BytecodeSharing` now implement this milestone. REFERENCE and BATCHED share `OpcodeExecutor`.
No public bytecode selection/serialization is introduced. Current implementation baseline is merged
main `3c2c799`, distinct from the historical planning revision above.
- [measured] Independent instruction enumeration and real two-fork interpreter measurements are in
[the94B ledger](../../measurements/94B-bytecode-concurrency.md), including the restricted preservation
argument and raw repetitions. Final validation/review disposition is recorded there; authoring review
alone does not establish implementation evidence. JPF remains later-phase acceptance.

## Tests

`lostUpdateAndDeadlockMatchInstructionEnumeration` (R1/R2/R4),
`reentrantCleanupAndBlockedAttemptsKeepExactAccounting` (R2), `checksUseSeparatePureObservers` (R3),
`batchYieldsBeforeCompetingTerminalEvents` (R4/R5), `historyAndBudgetsAffectKeys` (R1/R4),
`referenceBatchOutcomeGate` (R5/R6). Kill read/write merging, missing shared-history bits,
premature terminal delivery, cleanup depth errors and cutoff-as-deadlock mutations.
These are intended behavioral contracts/test names, not tests already implemented or executed.
Use independent expected values/oracles, preserve distinct regression cases and save generated seeds.
`BytecodeConcurrencyTest` covers split read/write choices, concrete deadlock relationships,
synchronized methods, frame roots, rewiring/publication and pending fault competition.
`BytecodeEventTest` / `BytecodeResourceTest` cover disabled/exhausted monitor attempts, exact limits,
null/nonowner releases and cleanup. `BytecodeCheckTest` covers both modes' observer timing, false,
fault/fuel/depth classifications and abnormal-prefix FINAL exclusions.
`BytecodeBatchingOracleTest` / `BytecodeInstructionOracle` independently enumerate targeted and
fixed-seed/shrunk tiny-program outcomes. `BytecodeSearchContractTest` covers complete payload hash
collisions, external stops, internal schedules and isolated concurrent/repeated runs.
`BytecodeMeasurementTest.referenceBatchOutcomeGate` verifies both real fixtures before the opt-in
`profileBytecode` runner measures them. [The ledger](../../measurements/94B-bytecode-concurrency.md)
records actual results and any remaining gate, without equating tests to a preservation proof.

## Constraints

Expand Down
70 changes: 70 additions & 0 deletions src/main/java/dev/samhb/interleave/bytecode/BytecodeChecks.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/** Pure interpreted observers with private frames and per-invocation fuel, never scheduler actors. */
package dev.samhb.interleave.bytecode;

import java.util.List;
import static dev.samhb.interleave.bytecode.BytecodeState.*;

/** Runs only loader-certified checks, returning diagnostics without modifying committed target state. */
final class BytecodeChecks {
/** Prevents construction of the stateless observer runner. */
private BytecodeChecks() {}

/** Observer-specific failure reasons, separate from actor violations. */
enum Kind {
/** A pure check returned false. */ FALSE,
/** A pure operation raised a modeled fault. */ ERROR,
/** Observer instruction or call-depth allowance was exhausted. */ LIMIT,
/** Host cancellation interrupted the checker, not the modeled program. */ INTERRUPTED
}

/** One failed check with genuine method/BCI identity.
* @param kind observer disposition
* @param check declared check identity
* @param location actual return, fault or omitted instruction; null for host cancellation
* @param fault interpreted observer fault, if any
* @param cutoff observer resource diagnostic, if any
*/
record Failure(Kind kind,BytecodeMethod.Id check,BytecodeLocation location,Fault fault,Cutoff cutoff) {}

/** Actual observer work for one ordered timing group.
* @param failure first failing check, otherwise null
* @param invocations attempted check invocations
* @param instructions executed observer instruction/intrinsic work
*/
record Evaluation(Failure failure,long invocations,long instructions) {}

/** Executes ordered ALWAYS or FINAL declarations synchronously on private scratch state.
* @param program immutable validated artifact
* @param parent committed model state, never modified
* @param always true for ALWAYS, false for FINAL
* @return first failure and actual separate observer work
*/
static Evaluation evaluate(BytecodeProgram program,BytecodeState parent,boolean always) {
long invocations=0,instructions=0;
for(var check:program.checks) {
if(check.always()!=always)continue;
invocations++;
var scratch=new BytecodeState();
for(var entry:parent.heap.entrySet())scratch.heap.put(entry.getKey(),entry.getValue().copy());
scratch.statics.putAll(parent.statics);
scratch.start(OBSERVER,program.methods.get(check.method()),List.of(FIXTURE));
while(true) {
var execution=scratch.executions.get(OBSERVER);
if(Thread.currentThread().isInterrupted())
return new Evaluation(new Failure(Kind.INTERRUPTED,check.method(),null,null,null),invocations,instructions+execution.instructions);
if(execution.phase==Phase.EXCEPTION)
return new Evaluation(new Failure(Kind.ERROR,check.method(),execution.fault.location(),execution.fault,null),invocations,instructions+execution.instructions);
if(execution.phase==Phase.CUTOFF_PENDING)
return new Evaluation(new Failure(Kind.LIMIT,check.method(),execution.cutoff.location(),null,execution.cutoff),invocations,instructions+execution.instructions);
if(execution.phase==Phase.RETURNING && execution.frames.size()==1) {
instructions+=execution.instructions;
if(((Int)execution.returned).value()==0)
return new Evaluation(new Failure(Kind.FALSE,check.method(),execution.eventLocation,null,null),invocations,instructions);
break;
}
scratch=OpcodeExecutor.step(program,scratch,OBSERVER).state();
}
}
return new Evaluation(null,invocations,instructions);
}
}
Loading
Loading