Skip to content

goto-symex: record shared writes only once a thread is spawned - #9635

Draft
tautschnig wants to merge 1 commit into
diffblue:developfrom
tautschnig:kiro/symex-defer-shared-writes
Draft

tautschnig wants to merge 1 commit into
diffblue:developfrom
tautschnig:kiro/symex-defer-shared-writes

Conversation

@tautschnig

Copy link
Copy Markdown
Collaborator

Symbolic execution records a shared-write event for every write to an object that is not thread-local, heap objects and globals included, also in programs that never spawn a thread. The events are only used by the memory model, which runs only if the equation has threads (postprocess_equation, has_threads), and by traces only then; in a single-threaded program they are steps that cost time and memory and are never read. A Lua program writes the fields of every new table, so that 28 % of its steps were such events (luacheck's stages/detect_empty_blocks.lua: 147,846 of 524,168).

symex_target_equationt::shared_write now keeps the events recorded before the first spawn aside (their guard, object, atomic section, source and the number of steps before them), and spawn() inserts them where they would have been before it adds the spawn step, so that the equation of a program that spawns a thread is unchanged: the sorted --program-only output of each of the 68 tests of
regression/cbmc-concurrency is the same as before (apart from the run times that one of them prints). Without a spawn they are dropped. (Simply not recording them before the first spawn would be unsound for the spawned threads, which read the values written before it: the new regression test cbmc-concurrency/shared-writes-before-spawn fails then.)

The effect is mostly on steps and memory. A Lua front end built on CBMC (luacheck's stages/parse.lua, runs alternated on a quiet host): 1,228,346 to 915,985 steps, symbolic execution 85.4 to 84.1 s (mean of two runs), peak memory 3.17 to 3.06 GB. scripts/profile_cbmc.py --auto-large --runs 3: steps unchanged or fewer (array_ops 16,448 to 13,993, matrix 4,148 to 3,435, string_ops 1,950 to 1,737, unions 382 to 311, structs 312 to 207); pre-solver time -14.7 % to +4.8 % with develop run first and +0.3 % to +4.7 % with it second, on a host shared with other jobs, i.e. within the noise of the run order.

Tests: unit test in unit/goto-symex/ssa_equation.cpp (the deferred events and their positions); regression/cbmc-concurrency/ shared-writes-before-spawn (values written before the spawn, on both branches and twice, read by the thread; a write after the spawn; and a single-threaded program whose --program-only output has no shared writes). single-thread.desc fails on develop. regression/cbmc (also with --paths lifo), cbmc-concurrency, cbmc-cpp, cbmc-cover, cbmc-shadow-memory and cbmc-primitives pass with --validate-goto-model --validate-ssa-equation; cbmc-library's mmap/test, mmap/test_02 and munmap/test fail with these options, as on develop.

  • Each commit message has a non-empty body, explaining why the change was made.
  • n/a Methods or procedures I have added are documented, following the guidelines provided in CODING_STANDARD.md.
  • n/a The feature or user visible behaviour I have added or modified has been documented in the User Guide in doc/cprover-manual/
  • Regression or unit tests are included, or existing tests cover the modified code (in this case I have detailed which ones those are in the commit message).
  • My commit message includes data points confirming performance improvements (if claimed).
  • My PR is restricted to a single feature or bugfix.
  • n/a White-space or formatting changes outside the feature-related changed lines are in commits of their own.

Symbolic execution records a shared-write event for every write to an
object that is not thread-local, heap objects and globals included,
also in programs that never spawn a thread. The events are only used by
the memory model, which runs only if the equation has threads
(postprocess_equation, has_threads), and by traces only then; in a
single-threaded program they are steps that cost time and memory and
are never read. A Lua program writes the fields of every new table, so
that 28 % of its steps were such events (luacheck's
stages/detect_empty_blocks.lua: 147,846 of 524,168).

symex_target_equationt::shared_write now keeps the events recorded
before the first spawn aside (their guard, object, atomic section,
source and the number of steps before them), and spawn() inserts them
where they would have been before it adds the spawn step, so that the
equation of a program that spawns a thread is unchanged: the sorted
--program-only output of each of the 68 tests of
regression/cbmc-concurrency is the same as before (apart from the run
times that one of them prints). Without a spawn they
are dropped. (Simply not recording them before the first spawn would be
unsound for the spawned threads, which read the values written before
it: the new regression test cbmc-concurrency/shared-writes-before-spawn
fails then.)

The effect is mostly on steps and memory. A Lua front end built on CBMC
(luacheck's stages/parse.lua, runs alternated on a quiet host):
1,228,346 to 915,985 steps, symbolic execution 85.4 to 84.1 s (mean of
two runs), peak memory 3.17 to 3.06 GB. scripts/profile_cbmc.py
--auto-large --runs 3: steps unchanged or fewer (array_ops 16,448 to
13,993, matrix 4,148 to 3,435, string_ops 1,950 to 1,737, unions 382 to
311, structs 312 to 207); pre-solver time -14.7 % to +4.8 % with develop
run first and +0.3 % to +4.7 % with it second, on a host shared with
other jobs, i.e. within the noise of the run order.

Tests: unit test in unit/goto-symex/ssa_equation.cpp (the deferred
events and their positions); regression/cbmc-concurrency/
shared-writes-before-spawn (values written before the spawn, on both
branches and twice, read by the thread; a write after the spawn; and a
single-threaded program whose --program-only output has no shared
writes). single-thread.desc fails on develop. regression/cbmc (also with
--paths lifo), cbmc-concurrency, cbmc-cpp, cbmc-cover,
cbmc-shadow-memory and cbmc-primitives pass with --validate-goto-model
--validate-ssa-equation; cbmc-library's mmap/test, mmap/test_02 and
munmap/test fail with these options, as on develop.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
@codecov

codecov Bot commented Dec 4, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.87500% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.34%. Comparing base (cce28f5) to head (1985378).

Files with missing lines Patch % Lines
unit/goto-symex/ssa_equation.cpp 95.12% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #9635   +/-   ##
========================================
  Coverage    81.34%   81.34%           
========================================
  Files         1727     1727           
  Lines       191715   191779   +64     
  Branches        73       73           
========================================
+ Hits        155950   156009   +59     
- Misses       35765    35770    +5     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

This branch has not been deployed

No deployments
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