Skip to content

Detect unbalanced Graphics state in the simulator (#5058)#5060

Merged
shai-almog merged 2 commits into
masterfrom
fix/5058-paint-scope-checks
May 28, 2026
Merged

Detect unbalanced Graphics state in the simulator (#5058)#5060
shai-almog merged 2 commits into
masterfrom
fix/5058-paint-scope-checks

Conversation

@shai-almog
Copy link
Copy Markdown
Collaborator

Summary

  • Adds beginPaintScope / endPaintScope hooks on CodenameOneImplementation (no-op default; one virtual call per scope on device, inlinable on iOS / JIT'd on Android).
  • Component.paint, Component.paintBackground, Painter.paint, and the Form glass pane are now wrapped in begin/end scopes.
  • JavaSEPort overrides those hooks to snapshot Graphics state (clip-stack depth, clip rect, transform, color, font, composite/alpha) and on scope exit:
    • logs a warning naming the offending component when state leaked,
    • auto-restores so one bad component does not poison the next.
  • JavaSEPort.popClip now throws IllegalStateException when there is no matching pushClip, catching the bug at its source instead of silently no-oping and surfacing as a crash on iOS many frames later — which is what happened in crash in IOS graphics - probably a regression #5058.

Disable with -Dcn1.disable.paint.scope.checks=true if a third-party component triggers false positives.

The device ports are untouched: the base impl's beginPaintScope / endPaintScope are empty methods, and popClip keeps its existing behaviour on every non-JavaSE port.

Test plan

  • mvn test -Plocal-dev-javase -pl core,javase (70 tests, all green)
  • New PaintScopeTest covers: excess pop throws, scope auto-restores stack depth / transform / color, nested scopes pop LIFO, clean scope is silent
  • Manual: run the simulator on the crash in IOS graphics - probably a regression #5058 repro and confirm we get a warning naming the component on the first frame, instead of a delayed iOS crash

🤖 Generated with Claude Code

The simulator now wraps each user-overrideable paint dispatch
(Component.paint, paintBackground, Painter.paint, Form glass pane)
in a begin/end scope. On exit it verifies the Graphics is in the
same state it entered (clip stack depth, clip rect, transform,
color, font, composite/alpha) and auto-restores any drift while
logging a warning that names the offending component. JavaSEPort.popClip
also throws IllegalStateException when there is no matching pushClip,
catching the leak at its source.

The hook is a no-op default on CodenameOneImplementation, so device
ports pay nothing (one virtual call to an empty method per scope,
inlinable by the iOS C compiler / Android JIT).

Disable with -Dcn1.disable.paint.scope.checks=true if needed.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@shai-almog
Copy link
Copy Markdown
Collaborator Author

shai-almog commented May 28, 2026

Compared 11 screenshots: 11 matched.
✅ JavaSE simulator integration screenshots matched stored baselines.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 28, 2026

✅ Continuous Quality Report

Test & Coverage

Static Analysis

  • SpotBugs [Report archive]
    • ByteCodeTranslator: 0 findings (no issues)
    • android: 0 findings (no issues)
    • codenameone-maven-plugin: 0 findings (no issues)
    • core-unittests: 0 findings (no issues)
    • ios: 0 findings (no issues)
  • PMD: 0 findings (no issues) [Report archive]
  • Checkstyle: 0 findings (no issues) [Report archive]

Generated automatically by the PR CI workflow.

@github-actions
Copy link
Copy Markdown
Contributor

Cloudflare Preview

@shai-almog
Copy link
Copy Markdown
Collaborator Author

shai-almog commented May 28, 2026

Compared 45 screenshots: 45 matched.
✅ JavaScript-port screenshot tests passed.

@shai-almog
Copy link
Copy Markdown
Collaborator Author

shai-almog commented May 28, 2026

Compared 116 screenshots: 116 matched.

Native Android coverage

  • 📊 Line coverage: 12.41% (7192/57972 lines covered) [HTML preview] (artifact android-coverage-report, jacocoAndroidReport/html/index.html)
    • Other counters: instruction 10.13% (36205/357360), branch 4.25% (1437/33836), complexity 5.27% (1713/32486), method 9.20% (1400/15210), class 15.12% (320/2117)
    • Lowest covered classes
      • kotlin.collections.kotlin.collections.ArraysKt___ArraysKt – 0.00% (0/6327 lines covered)
      • kotlin.collections.unsigned.kotlin.collections.unsigned.UArraysKt___UArraysKt – 0.00% (0/2384 lines covered)
      • org.jacoco.agent.rt.internal_b6258fc.asm.org.jacoco.agent.rt.internal_b6258fc.asm.ClassReader – 0.00% (0/1519 lines covered)
      • kotlin.collections.kotlin.collections.CollectionsKt___CollectionsKt – 0.00% (0/1148 lines covered)
      • org.jacoco.agent.rt.internal_b6258fc.asm.org.jacoco.agent.rt.internal_b6258fc.asm.MethodWriter – 0.00% (0/923 lines covered)
      • kotlin.sequences.kotlin.sequences.SequencesKt___SequencesKt – 0.00% (0/730 lines covered)
      • kotlin.text.kotlin.text.StringsKt___StringsKt – 0.00% (0/623 lines covered)
      • org.jacoco.agent.rt.internal_b6258fc.asm.org.jacoco.agent.rt.internal_b6258fc.asm.Frame – 0.00% (0/564 lines covered)
      • kotlin.collections.kotlin.collections.ArraysKt___ArraysJvmKt – 0.00% (0/495 lines covered)
      • kotlinx.coroutines.kotlinx.coroutines.JobSupport – 0.00% (0/423 lines covered)

✅ Native Android screenshot tests passed.

Native Android coverage

  • 📊 Line coverage: 12.41% (7192/57972 lines covered) [HTML preview] (artifact android-coverage-report, jacocoAndroidReport/html/index.html)
    • Other counters: instruction 10.13% (36205/357360), branch 4.25% (1437/33836), complexity 5.27% (1713/32486), method 9.20% (1400/15210), class 15.12% (320/2117)
    • Lowest covered classes
      • kotlin.collections.kotlin.collections.ArraysKt___ArraysKt – 0.00% (0/6327 lines covered)
      • kotlin.collections.unsigned.kotlin.collections.unsigned.UArraysKt___UArraysKt – 0.00% (0/2384 lines covered)
      • org.jacoco.agent.rt.internal_b6258fc.asm.org.jacoco.agent.rt.internal_b6258fc.asm.ClassReader – 0.00% (0/1519 lines covered)
      • kotlin.collections.kotlin.collections.CollectionsKt___CollectionsKt – 0.00% (0/1148 lines covered)
      • org.jacoco.agent.rt.internal_b6258fc.asm.org.jacoco.agent.rt.internal_b6258fc.asm.MethodWriter – 0.00% (0/923 lines covered)
      • kotlin.sequences.kotlin.sequences.SequencesKt___SequencesKt – 0.00% (0/730 lines covered)
      • kotlin.text.kotlin.text.StringsKt___StringsKt – 0.00% (0/623 lines covered)
      • org.jacoco.agent.rt.internal_b6258fc.asm.org.jacoco.agent.rt.internal_b6258fc.asm.Frame – 0.00% (0/564 lines covered)
      • kotlin.collections.kotlin.collections.ArraysKt___ArraysJvmKt – 0.00% (0/495 lines covered)
      • kotlinx.coroutines.kotlinx.coroutines.JobSupport – 0.00% (0/423 lines covered)

Benchmark Results

Detailed Performance Metrics

Metric Duration
Base64 payload size 8192 bytes
Base64 benchmark iterations 6000
Base64 native encode 798.000 ms
Base64 CN1 encode 120.000 ms
Base64 encode ratio (CN1/native) 0.150x (85.0% faster)
Base64 native decode 1606.000 ms
Base64 CN1 decode 353.000 ms
Base64 decode ratio (CN1/native) 0.220x (78.0% faster)
Image encode benchmark status skipped (SIMD unsupported)

@shai-almog
Copy link
Copy Markdown
Collaborator Author

shai-almog commented May 28, 2026

Compared 115 screenshots: 115 matched.
✅ Native iOS screenshot tests passed.

Benchmark Results

  • VM Translation Time: 0 seconds
  • Compilation Time: 189 seconds

Build and Run Timing

Metric Duration
Simulator Boot 68000 ms
Simulator Boot (Run) 1000 ms
App Install 11000 ms
App Launch 9000 ms
Test Execution 336000 ms

Detailed Performance Metrics

Metric Duration
Base64 payload size 8192 bytes
Base64 benchmark iterations 6000
Base64 native encode 893.000 ms
Base64 CN1 encode 1823.000 ms
Base64 encode ratio (CN1/native) 2.041x (104.1% slower)
Base64 native decode 487.000 ms
Base64 CN1 decode 1729.000 ms
Base64 decode ratio (CN1/native) 3.550x (255.0% slower)
Base64 SIMD encode 514.000 ms
Base64 encode ratio (SIMD/native) 0.576x (42.4% faster)
Base64 encode ratio (SIMD/CN1) 0.282x (71.8% faster)
Base64 SIMD decode 710.000 ms
Base64 decode ratio (SIMD/native) 1.458x (45.8% slower)
Base64 decode ratio (SIMD/CN1) 0.411x (58.9% faster)
Image encode benchmark iterations 100
Image createMask (SIMD off) 59.000 ms
Image createMask (SIMD on) 9.000 ms
Image createMask ratio (SIMD on/off) 0.153x (84.7% faster)
Image applyMask (SIMD off) 263.000 ms
Image applyMask (SIMD on) 58.000 ms
Image applyMask ratio (SIMD on/off) 0.221x (77.9% faster)
Image modifyAlpha (SIMD off) 152.000 ms
Image modifyAlpha (SIMD on) 113.000 ms
Image modifyAlpha ratio (SIMD on/off) 0.743x (25.7% faster)
Image modifyAlpha removeColor (SIMD off) 245.000 ms
Image modifyAlpha removeColor (SIMD on) 64.000 ms
Image modifyAlpha removeColor ratio (SIMD on/off) 0.261x (73.9% faster)
Image PNG encode (SIMD off) 1023.000 ms
Image PNG encode (SIMD on) 823.000 ms
Image PNG encode ratio (SIMD on/off) 0.804x (19.6% faster)
Image JPEG encode 695.000 ms

input-validation.yml computed its own cn1-built cache key with a
different file set than _build-ios-port.yml saves under (e.g. no
svg-transcoder/src/main), so the restore always missed with
fail-on-cache-miss whenever a PR touched a file in the workflow's
paths filter (Component.java, Form.java, ...). Reuse the
cn1_built_cache_key output from build-port the way scripts-ios.yml
already does.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@shai-almog shai-almog linked an issue May 28, 2026 that may be closed by this pull request
@shai-almog
Copy link
Copy Markdown
Collaborator Author

shai-almog commented May 28, 2026

Compared 116 screenshots: 116 matched.
✅ Native iOS Metal screenshot tests passed.

Benchmark Results

  • VM Translation Time: 0 seconds
  • Compilation Time: 288 seconds

Build and Run Timing

Metric Duration
Simulator Boot 95000 ms
Simulator Boot (Run) 2000 ms
App Install 18000 ms
App Launch 4000 ms
Test Execution 315000 ms

Detailed Performance Metrics

Metric Duration
Base64 payload size 8192 bytes
Base64 benchmark iterations 6000
Base64 native encode 551.000 ms
Base64 CN1 encode 1217.000 ms
Base64 encode ratio (CN1/native) 2.209x (120.9% slower)
Base64 native decode 266.000 ms
Base64 CN1 decode 912.000 ms
Base64 decode ratio (CN1/native) 3.429x (242.9% slower)
Base64 SIMD encode 433.000 ms
Base64 encode ratio (SIMD/native) 0.786x (21.4% faster)
Base64 encode ratio (SIMD/CN1) 0.356x (64.4% faster)
Base64 SIMD decode 487.000 ms
Base64 decode ratio (SIMD/native) 1.831x (83.1% slower)
Base64 decode ratio (SIMD/CN1) 0.534x (46.6% faster)
Image encode benchmark iterations 100
Image createMask (SIMD off) 77.000 ms
Image createMask (SIMD on) 11.000 ms
Image createMask ratio (SIMD on/off) 0.143x (85.7% faster)
Image applyMask (SIMD off) 132.000 ms
Image applyMask (SIMD on) 76.000 ms
Image applyMask ratio (SIMD on/off) 0.576x (42.4% faster)
Image modifyAlpha (SIMD off) 184.000 ms
Image modifyAlpha (SIMD on) 79.000 ms
Image modifyAlpha ratio (SIMD on/off) 0.429x (57.1% faster)
Image modifyAlpha removeColor (SIMD off) 179.000 ms
Image modifyAlpha removeColor (SIMD on) 78.000 ms
Image modifyAlpha removeColor ratio (SIMD on/off) 0.436x (56.4% faster)
Image PNG encode (SIMD off) 1093.000 ms
Image PNG encode (SIMD on) 894.000 ms
Image PNG encode ratio (SIMD on/off) 0.818x (18.2% faster)
Image JPEG encode 564.000 ms

@shai-almog shai-almog merged commit 624b580 into master May 28, 2026
27 checks 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.

crash in IOS graphics - probably a regression

1 participant