Skip to content

Throw StackOverflowError from initMethodStack; add StackOverflowError class and native test#4461

Open
shai-almog wants to merge 25 commits intomasterfrom
codex/add-stackoverflowerror-and-virtualmachineerror
Open

Throw StackOverflowError from initMethodStack; add StackOverflowError class and native test#4461
shai-almog wants to merge 25 commits intomasterfrom
codex/add-stackoverflowerror-and-virtualmachineerror

Conversation

@shai-almog
Copy link
Collaborator

Motivation

  • Prevent an assertion crash when the VM call stack is exhausted by throwing a proper StackOverflowError so Java code can catch and recover.
  • Provide the missing java.lang.StackOverflowError class so the VM can instantiate and throw the error.
  • Add an integration test to validate that a stack overflow is thrown and that the VM can continue execution after it is caught.

Description

  • Added vm/JavaAPI/src/java/lang/StackOverflowError.java implementing java.lang.VirtualMachineError.
  • Updated vm/ByteCodeTranslator/src/nativeMethods.m to include the StackOverflowError header and change initMethodStack to check callStackOffset and call throwException(threadStateData, __NEW_INSTANCE_java_lang_StackOverflowError(threadStateData)) and return instead of asserting.
  • Added vm/tests/src/test/java/com/codename1/tools/translator/StackOverflowIntegrationTest.java, a native integration test that compiles a small app which triggers a stack overflow, verifies the StackOverflowError was thrown/caught (STACK_OVERFLOW_OK) and that normal execution (a recursive sum) still works after recovery (RECOVERY_OK:7).

Testing

  • No automated tests were executed as part of this change.
  • A new automated integration test StackOverflowIntegrationTest was added under vm/tests and will run as part of the VM test suite when the test goals are invoked.
  • The change is limited to VM native code, the JavaAPI, and an integration test; CI or a local Maven test run should be used to validate the new test in the full environment.

Codex Task

@github-actions
Copy link

github-actions bot commented Jan 25, 2026

@shai-almog
Copy link
Collaborator Author

shai-almog commented Jan 25, 2026

Compared 30 screenshots: 30 matched.
✅ Native Android screenshot tests passed.

Benchmark Results

  • VM Translation Time: 417 seconds
  • Compilation Time: 357 seconds

Detailed Performance Metrics

Metric Duration
Build Time Statistics
Setup & Unzip 45843 ms
Extract Extensions 27 ms
Google Services Setup 2 ms
Scan Classes 771 ms
Extract Libs 1098 ms
Inject Build Hints 46 ms
Generate Unit Tests 3 ms
Generate Stubs 1318 ms
Compile Stubs 3127 ms
Generate Icons 1788 ms
Prepare ParparVM 472 ms
ParparVM Execution 234588 ms
Post-VM Setup 232 ms
CocoaPods 5035 ms
Finalize 29 ms
Total Time 294380 msMaven Overhead : 123000 ms
CocoaPods Install (Script) 2000 ms
Simulator Boot 129000 ms
Simulator Boot (Run) 8000 ms
App Install 22000 ms
App Launch 6000 ms
Test Execution 192000 ms

@shai-almog shai-almog force-pushed the codex/add-stackoverflowerror-and-virtualmachineerror branch 3 times, most recently from 5a88bd8 to 5590a10 Compare February 4, 2026 17:00
@shai-almog shai-almog force-pushed the codex/add-stackoverflowerror-and-virtualmachineerror branch from 5590a10 to e8df884 Compare February 4, 2026 18:35
@shai-almog shai-almog force-pushed the codex/add-stackoverflowerror-and-virtualmachineerror branch from e8df884 to fb3ec1a Compare February 4, 2026 18:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant