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

✅ Continuous Quality Report

Test & Coverage

Static Analysis

Generated automatically by the PR CI workflow.

@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: 336 seconds
  • Compilation Time: 350 seconds

Detailed Performance Metrics

Metric Duration
Build Time Statistics
Setup & Unzip 31760 ms
Extract Extensions 29 ms
Google Services Setup 4 ms
Scan Classes 940 ms
Extract Libs 1281 ms
Inject Build Hints 80 ms
Generate Unit Tests 6 ms
Generate Stubs 2232 ms
Compile Stubs 2362 ms
Generate Icons 992 ms
Prepare ParparVM 240 ms
ParparVM Execution 185476 ms
Post-VM Setup 254 ms
CocoaPods 6244 ms
Finalize 29 ms
Total Time 231930 msMaven Overhead : 105000 ms
CocoaPods Install (Script) 2000 ms
Simulator Boot 270000 ms
Simulator Boot (Run) 6000 ms
App Install 19000 ms
App Launch 17000 ms
Test Execution 264000 ms

@shai-almog shai-almog force-pushed the codex/add-stackoverflowerror-and-virtualmachineerror branch 5 times, most recently from e8df884 to fb3ec1a Compare February 4, 2026 18:58
@shai-almog shai-almog force-pushed the codex/add-stackoverflowerror-and-virtualmachineerror branch from fb3ec1a to 56c72a4 Compare February 5, 2026 17:51
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