Skip to content

Fix the iOS String.format crash and the toString it relied on (issue #5482) - #5510

Open
shai-almog wants to merge 3 commits into
masterfrom
fix-5482-string-format-ios-crash
Open

Fix the iOS String.format crash and the toString it relied on (issue #5482)#5510
shai-almog wants to merge 3 commits into
masterfrom
fix-5482-string-format-ios-crash

Conversation

@shai-almog

Copy link
Copy Markdown
Collaborator

Fixes #5482.

The crash

String.format was a native method. Its Objective-C branch formatted a string, threw it away, and returned fromNSString([NSString init]) -- sending init to the NSString class object:

NSString* result = [[[NSString alloc] initWithFormat:toNSString(...) arguments:argList] autorelease];
free(argList);
JAVA_OBJECT out = fromNSString(CN1_THREAD_STATE_PASS_ARG [NSString init]);

That aborts the process with +[NSString<0x...> init]: cannot init a class object, which is exactly the termination the reporter pasted. Every String.format call on iOS killed the app.

The C fallback used everywhere else did not crash, but ignored width and precision entirely, so "%.3f" printed every digit of the double and "%.2e" printed %. followed by the whole number and a literal 2e.

Neither was caught because the Apple branch is behind #if defined(__APPLE__) && defined(__OBJC__) and parparvm-tests runs on ubuntu-latest, so CI only ever compiled the #else branch.

The fix

Formatting is string manipulation, so the native is gone and the work happens once in java.lang.StringFormatter. A single implementation now serves iOS, the JavaScript target and the C fallback -- which also means the Linux CI test is finally meaningful for iOS.

Supported: s S b B h H c C d o x X e E f g G n %, the - + ' ' 0 , ( # flags, width, precision, and the %n$ / %< argument selectors. Rendering is locale independent.

%a (hexadecimal float) and %t (date and time) are not implemented; they raise UnknownFormatConversionException rather than producing something wrong. Both are documented in the class javadoc and pinned by the test.

A malformed format string now raises the java.util exception the JVM raises -- the ten missing exception classes are added here -- instead of taking the process down. That was the reporter's closing request: "it should have been a trapped error, presented as some kind of a runtime fault, rather than a hard crash."

Two further defects the new test exposed

Once the output could be diffed against a JVM, two unrelated ParparVM bugs failed the test:

  • Double.toString / Float.toString were badly non-conforming. They asked snprintf for a fixed "%f" (six decimals) in the plain range and "%1.20E" (twenty-one significant digits) in the scientific range. 1.0/3.0 rendered as "0.333333" instead of "0.3333333333333333"; 1e30 rendered as "1.00000000000000001988E30" instead of "1.0E30". This hit every concatenation of a double on iOS, not just formatting. Replaced with a binary search for the shortest rendering that round trips, which is what the specification asks for.
  • Math.abs(-0.0) returned -0.0, because a < 0 is false for negative zero. Now fabs/fabsf.

The reporter's other suspicion

He also suspected getClass() was returning null. It is not: getClassImpl cannot return null for a non-null receiver -- it hands back &ClazzClazz when the class reference is absent. GetClassIntegrationTest reproduces his exact shape (interface-typed reference, getClass() used as a HashMap key, the "class is " + cl concatenation that printed null) and re-checks every invariant across 200k allocations of churn. Class identity, hashing, string conversion and map lookup all match the JVM. That symptom was downstream of the process already being wrecked.

Coverage

StringFormatIntegrationTest and GetClassIntegrationTest run the same program on a real JVM and under ParparVM and diff it case by case, so the expectations are the JDK's rather than hand written. On macOS the harness compiles nativeMethods.m as Objective-C, so these exercise the branch that was crashing.

Off-line, the implementation was diffed against the JDK over:

sweep cases divergences
curated + generated conversions, flags, widths, precisions 384,089 0
randomly assembled format strings and argument lists 300,000 0 (excluding the documented %a / %t gap)
random double and float bit patterns through toString 399,110 0 vs JDK 21/25

JDK 11 and 17 differ from the last row on ~5.6% of random doubles because they predate JDK-4511638; the values used in the committed test are byte-identical across JDK 11, 17 and 25.

Full ParparVM suite: 411 tests, 0 failures.

cd vm && mvn -B test -pl tests -am -DexcludedGroups=benchmark

🤖 Generated with Claude Code

…5482)

String.format was a native method whose Objective-C branch formatted a string,
threw it away, and returned fromNSString([NSString init]) -- sending init to the
NSString class object, which aborts the process with
"+[NSString<0x...> init]: cannot init a class object". Every String.format call
on iOS killed the app. The C fallback that ran everywhere else did not crash but
ignored width and precision, so "%.3f" printed every digit of the double.

The Apple branch sits behind #if defined(__APPLE__) && defined(__OBJC__) and
parparvm-tests runs on ubuntu-latest, so CI only ever compiled the #else branch
and nothing flagged either problem.

Formatting is string manipulation, so drop the native entirely and implement it
once in java.lang.StringFormatter. One implementation now serves iOS, the
JavaScript target and the C fallback, which also makes the Linux CI test
meaningful for iOS. Supported conversions are s S b B h H c C d o x X e E f g G
n %, with the - + ' ' 0 , ( # flags, width, precision and the %n$ / %< argument
selectors. %a (hexadecimal float) and %t (date and time) are not implemented and
raise UnknownFormatConversionException rather than producing something wrong.

A malformed format string now raises the java.util exception the JVM raises
(the ten missing classes are added here) instead of taking the process down,
which is what the reporter asked for.

Two further defects surfaced once the output could be compared with a JVM:

- Double.toString and Float.toString were badly non-conforming. They asked
  snprintf for a fixed "%f" (six decimals) in the plain range and "%1.20E"
  (twenty-one significant digits) in the scientific range, so 1.0/3.0 rendered
  as "0.333333" instead of "0.3333333333333333" and 1e30 rendered as
  "1.00000000000000001988E30" instead of "1.0E30". That affected every
  concatenation of a double, not just formatting. Replaced with a search for the
  shortest rendering that round trips, which is what the specification asks for.

- Math.abs(-0.0) returned -0.0, because "a < 0" is false for negative zero.
  Now fabs/fabsf.

Coverage: StringFormatIntegrationTest and GetClassIntegrationTest run the same
program on a real JVM and under ParparVM and diff it case by case, so the
expectations are the JDK's rather than hand written. On macOS the harness
compiles nativeMethods.m as Objective-C, so these exercise the branch that was
crashing. Off-line, the implementation was diffed against the JDK over 384k
value cases, 300k randomly assembled format strings and 399k random double and
float bit patterns with no divergence.

GetClassIntegrationTest also covers the reporter's other suspicion, that
getClass() was returning null. It does not: getClassImpl cannot return null for
a non-null receiver, and Class identity, hashing, string conversion and use as a
HashMap key all match the JVM under allocation churn. The test pins that.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings August 2, 2026 08:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Not ready to approve

The new formatter has a confirmed edge-case bug for explicit argument index 0$ handling and there is a public JavaAPI compatibility issue in IllegalFormatException constructor visibility.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.

Pull request overview

This PR fixes the iOS hard-crash in String.format() (issue #5482) by removing the native implementation and replacing it with a shared Java formatter (java.lang.StringFormatter) that is exercised by new differential integration tests. It also corrects ParparVM’s Double.toString/Float.toString conformance and fixes Math.abs(-0.0) to match JVM behavior.

Changes:

  • Replace native String.format() with a Java implementation (StringFormatter) used across targets (iOS/JS/C fallback).
  • Fix ParparVM floating-to-string rendering to produce the shortest round-tripping decimal and correct Math.abs() for negative zero.
  • Add differential integration tests (JVM vs ParparVM) for String.format() output and getClass()/Class behavior under allocation churn.
File summaries
File Description
vm/tests/src/test/resources/com/codename1/tools/translator/StringFormatApp.java Test program emitting per-case String.format() results for line-by-line diffing.
vm/tests/src/test/resources/com/codename1/tools/translator/GetClassApp.java Test program pinning getClass() and Class identity/hash/toString under churn.
vm/tests/src/test/java/com/codename1/tools/translator/StringFormatIntegrationTest.java Differential JVM vs ParparVM integration test for formatting output and unsupported conversions.
vm/tests/src/test/java/com/codename1/tools/translator/GetClassIntegrationTest.java Differential JVM vs ParparVM integration test for getClass() and Class map-key behavior.
vm/JavaAPI/src/java/util/UnknownFormatConversionException.java Adds missing java.util exception used by formatter error paths.
vm/JavaAPI/src/java/util/MissingFormatWidthException.java Adds missing java.util exception used by formatter width validation.
vm/JavaAPI/src/java/util/MissingFormatArgumentException.java Adds missing java.util exception used for missing args/indexes.
vm/JavaAPI/src/java/util/IllegalFormatWidthException.java Adds missing java.util exception used for illegal width handling.
vm/JavaAPI/src/java/util/IllegalFormatPrecisionException.java Adds missing java.util exception used for illegal precision handling.
vm/JavaAPI/src/java/util/IllegalFormatFlagsException.java Adds missing java.util exception used for illegal flag combinations.
vm/JavaAPI/src/java/util/IllegalFormatException.java Adds missing java.util base exception type for formatter-related unchecked errors.
vm/JavaAPI/src/java/util/IllegalFormatConversionException.java Adds missing java.util exception used for wrong argument type per conversion.
vm/JavaAPI/src/java/util/IllegalFormatCodePointException.java Adds missing java.util exception for invalid code points in %c/%C.
vm/JavaAPI/src/java/util/FormatFlagsConversionMismatchException.java Adds missing java.util exception for flag/conversion mismatches.
vm/JavaAPI/src/java/util/DuplicateFormatFlagsException.java Adds missing java.util exception for duplicated flags.
vm/JavaAPI/src/java/lang/StringFormatter.java New shared Java implementation of String.format() logic (parsing, conversions, rounding).
vm/JavaAPI/src/java/lang/String.java Switches String.format() from native to StringFormatter.format().
vm/ByteCodeTranslator/src/nativeMethods.m Fixes Double.toString/Float.toString conformance and Math.abs() negative-zero behavior; removes native String.format.
vm/ByteCodeTranslator/src/javascript/parparvm_runtime.js Removes JavaScript native String.format() binding (now handled in Java).
vm/ByteCodeTranslator/src/com/codename1/tools/translator/JavascriptNativeRegistry.java Removes String.format from JS native registry list.
Review details
  • Files reviewed: 20/20 changed files
  • Comments generated: 2
  • Review effort level: Lite

We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.

Comment thread vm/JavaAPI/src/java/lang/StringFormatter.java Outdated
Comment thread vm/JavaAPI/src/java/util/IllegalFormatException.java

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d24938b462

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread vm/JavaAPI/src/java/lang/StringFormatter.java
Comment thread vm/JavaAPI/src/java/lang/StringFormatter.java Outdated
@github-actions

github-actions Bot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

✅ ByteCodeTranslator Quality Report

Test & Coverage

  • Tests: 416 total, 0 failed, 14 skipped

Benchmark Results

  • Execution Time: 23141 ms

  • Hotspots (Top 20 sampled methods):

    • 20.85% com.codename1.tools.translator.Parser.addToConstantPool (406 samples)
    • 7.29% java.util.ArrayList.indexOf (142 samples)
    • 3.95% com.codename1.tools.translator.ByteCodeClass.hasDeclaredMethod (77 samples)
    • 3.08% java.lang.StringBuilder.append (60 samples)
    • 2.72% com.codename1.tools.translator.ByteCodeClass.fillVirtualMethodTable (53 samples)
    • 2.67% org.objectweb.asm.tree.analysis.Analyzer.analyze (52 samples)
    • 2.57% com.codename1.tools.translator.Parser.cn1EnsureSubclassIndex (50 samples)
    • 2.26% com.codename1.tools.translator.BytecodeMethod.optimize (44 samples)
    • 2.16% com.codename1.tools.translator.Parser.classIndex (42 samples)
    • 1.90% java.lang.Object.hashCode (37 samples)
    • 1.34% com.codename1.tools.translator.bytecodes.Invoke.resolveDirectTarget (26 samples)
    • 1.23% com.codename1.tools.translator.bytecodes.Invoke.findMethodUp (24 samples)
    • 1.13% java.util.IdentityHashMap$KeySet.toArray (22 samples)
    • 1.13% com.codename1.tools.translator.BytecodeMethod.appendCMethodPrefix (22 samples)
    • 1.08% org.objectweb.asm.tree.analysis.Analyzer.findSubroutine (21 samples)
    • 1.08% java.util.HashMap.hash (21 samples)
    • 1.03% com.codename1.tools.translator.bytecodes.Invoke.addDependencies (20 samples)
    • 0.98% java.lang.String.equals (19 samples)
    • 0.92% java.lang.System.identityHashCode (18 samples)
    • 0.92% sun.nio.ch.FileDispatcherImpl.write0 (18 samples)
  • ⚠️ Coverage report not generated.

Static Analysis

  • ✅ SpotBugs: no findings (report was not generated by the build).
  • ⚠️ PMD report not generated.
  • ⚠️ Checkstyle report not generated.

Generated automatically by the PR CI workflow.

@github-actions

github-actions Bot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

✅ 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

github-actions Bot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Cloudflare Preview

@shai-almog

shai-almog commented Aug 2, 2026

Copy link
Copy Markdown
Collaborator Author

Compared 146 screenshots: 146 matched.
Native Windows port, REAL shipping pipeline: the hellocodenameone screenshot suite rendered by a binary CROSS-COMPILED on Linux (clang-cl + xwin, WebView2 linked) and RUN on a Windows x64 runner. Compared against the in-repo baseline in scripts/windows/screenshots.

Benchmark Results

Detailed Performance Metrics

Metric Duration
SIMD kernel backend SSE2 (x64) / NEON (arm64) native kernels
SIMD int-add (64K x300) java 63ms / native 5ms = 12.6x speedup
SIMD float-mul (64K x300) java 63ms / native 4ms = 15.7x speedup
SIMD kernel correctness PASS (native result == scalar reference)
Base64 native bridge unavailable (CN1 + SIMD + image benchmarks only)
Base64 payload size 8192 bytes
Base64 benchmark iterations 6000
Base64 SIMD byte path gated to scalar (CPU autovectorizes scalar; explicit SIMD not beneficial here)
Base64 CN1 encode 188.000 ms
Base64 CN1 decode 134.000 ms
Base64 SIMD encode 108.000 ms
Base64 encode ratio (SIMD/CN1) 0.574x (42.6% faster)
Base64 SIMD decode 98.000 ms
Base64 decode ratio (SIMD/CN1) 0.731x (26.9% faster)
Image encode benchmark iterations 100
Image createMask (SIMD off) 26.000 ms
Image createMask (SIMD on) 20.000 ms
Image createMask ratio (SIMD on/off) 0.769x (23.1% faster)
Image applyMask (SIMD off) 60.000 ms
Image applyMask (SIMD on) 52.000 ms
Image applyMask ratio (SIMD on/off) 0.867x (13.3% faster)
Image modifyAlpha (SIMD off) 59.000 ms
Image modifyAlpha (SIMD on) 54.000 ms
Image modifyAlpha ratio (SIMD on/off) 0.915x (8.5% faster)
Image modifyAlpha removeColor (SIMD off) 43.000 ms
Image modifyAlpha removeColor (SIMD on) 30.000 ms
Image modifyAlpha removeColor ratio (SIMD on/off) 0.698x (30.2% faster)

@shai-almog

shai-almog commented Aug 2, 2026

Copy link
Copy Markdown
Collaborator Author

Compared 146 screenshots: 146 matched.
Native Windows port (x64 / Intel-AMD): full hellocodenameone screenshot suite rendered offscreen with Direct2D/DirectWrite, plus the real benchmarks (base64 native/CN1/SIMD, image createMask/applyMask/modifyAlpha/PNG/JPEG, SSE2 SIMD kernels). Compared against the in-repo baseline in scripts/windows/screenshots.

Benchmark Results

Detailed Performance Metrics

Metric Duration
SIMD kernel backend SSE2 (x64) / NEON (arm64) native kernels
SIMD int-add (64K x300) java 63ms / native 4ms = 15.7x speedup
SIMD float-mul (64K x300) java 64ms / native 4ms = 16.0x speedup
SIMD kernel correctness PASS (native result == scalar reference)
Base64 native bridge unavailable (CN1 + SIMD + image benchmarks only)
Base64 payload size 8192 bytes
Base64 benchmark iterations 6000
Base64 SIMD byte path gated to scalar (CPU autovectorizes scalar; explicit SIMD not beneficial here)
Base64 CN1 encode 199.000 ms
Base64 CN1 decode 137.000 ms
Base64 SIMD encode 102.000 ms
Base64 encode ratio (SIMD/CN1) 0.513x (48.7% faster)
Base64 SIMD decode 98.000 ms
Base64 decode ratio (SIMD/CN1) 0.715x (28.5% faster)
Image encode benchmark iterations 100
Image createMask (SIMD off) 27.000 ms
Image createMask (SIMD on) 20.000 ms
Image createMask ratio (SIMD on/off) 0.741x (25.9% faster)
Image applyMask (SIMD off) 56.000 ms
Image applyMask (SIMD on) 140.000 ms
Image applyMask ratio (SIMD on/off) 2.500x (150.0% slower)
Image modifyAlpha (SIMD off) 64.000 ms
Image modifyAlpha (SIMD on) 52.000 ms
Image modifyAlpha ratio (SIMD on/off) 0.813x (18.8% faster)
Image modifyAlpha removeColor (SIMD off) 74.000 ms
Image modifyAlpha removeColor (SIMD on) 60.000 ms
Image modifyAlpha removeColor ratio (SIMD on/off) 0.811x (18.9% faster)

@shai-almog

shai-almog commented Aug 2, 2026

Copy link
Copy Markdown
Collaborator Author

Compared 147 screenshots: 147 matched.
Native Linux port (x64), GTK3/Cairo/Pango, ParparVM bytecode-to-C (no JVM): the hellocodenameone screenshot suite rendered by a native ELF built + run on the GitHub x64 runner. Baseline: scripts/linux/screenshots.

@shai-almog

shai-almog commented Aug 2, 2026

Copy link
Copy Markdown
Collaborator Author

Compared 147 screenshots: 147 matched.
Native Linux port (arm64), GTK3/Cairo/Pango, ParparVM bytecode-to-C (no JVM): the hellocodenameone screenshot suite rendered by a native ELF built + run on the GitHub arm64 runner. Baseline: scripts/linux/screenshots-arm.

@shai-almog

shai-almog commented Aug 2, 2026

Copy link
Copy Markdown
Collaborator Author

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

@shai-almog

shai-almog commented Aug 2, 2026

Copy link
Copy Markdown
Collaborator Author

Compared 146 screenshots: 146 matched.
Native Windows port (arm64 / Apple Silicon - Arm): full hellocodenameone screenshot suite rendered offscreen with Direct2D/DirectWrite, plus the real benchmarks (base64 native/CN1/SIMD, image createMask/applyMask/modifyAlpha/PNG/JPEG, NEON SIMD kernels). Compared against the in-repo baseline in scripts/windows/screenshots.

Benchmark Results

Detailed Performance Metrics

Metric Duration
SIMD kernel backend SSE2 (x64) / NEON (arm64) native kernels
SIMD int-add (64K x300) java 56ms / native 3ms = 18.6x speedup
SIMD float-mul (64K x300) java 55ms / native 3ms = 18.3x speedup
SIMD kernel correctness PASS (native result == scalar reference)
Base64 native bridge unavailable (CN1 + SIMD + image benchmarks only)
Base64 payload size 8192 bytes
Base64 benchmark iterations 6000
Base64 SIMD byte path gated to scalar (CPU autovectorizes scalar; explicit SIMD not beneficial here)
Base64 CN1 encode 246.000 ms
Base64 CN1 decode 128.000 ms
Base64 SIMD encode 65.000 ms
Base64 encode ratio (SIMD/CN1) 0.264x (73.6% faster)
Base64 SIMD decode 63.000 ms
Base64 decode ratio (SIMD/CN1) 0.492x (50.8% faster)
Image encode benchmark iterations 100
Image createMask (SIMD off) 13.000 ms
Image createMask (SIMD on) 8.000 ms
Image createMask ratio (SIMD on/off) 0.615x (38.5% faster)
Image applyMask (SIMD off) 138.000 ms
Image applyMask (SIMD on) 19.000 ms
Image applyMask ratio (SIMD on/off) 0.138x (86.2% faster)
Image modifyAlpha (SIMD off) 18.000 ms
Image modifyAlpha (SIMD on) 12.000 ms
Image modifyAlpha ratio (SIMD on/off) 0.667x (33.3% faster)
Image modifyAlpha removeColor (SIMD off) 21.000 ms
Image modifyAlpha removeColor (SIMD on) 13.000 ms
Image modifyAlpha removeColor ratio (SIMD on/off) 0.619x (38.1% faster)

@shai-almog

shai-almog commented Aug 2, 2026

Copy link
Copy Markdown
Collaborator Author

Compared 144 screenshots: 144 matched.
✅ Native Apple TV (tvOS, Metal) screenshot tests passed.

@shai-almog

shai-almog commented Aug 2, 2026

Copy link
Copy Markdown
Collaborator Author

Compared 217 screenshots: 217 matched.
✅ Native Apple Watch (watchOS, Core Graphics) screenshot tests passed.

@shai-almog

shai-almog commented Aug 2, 2026

Copy link
Copy Markdown
Collaborator Author

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

Benchmark Results

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

Build and Run Timing

Metric Duration
Simulator Boot 92000 ms
Simulator Boot (Run) 1000 ms
App Install 14000 ms
App Launch 5000 ms
Test Execution 637000 ms

Detailed Performance Metrics

Metric Duration
SIMD kernel backend SSE2 (x64) / NEON (arm64) native kernels
SIMD int-add (64K x300) java 95ms / native 6ms = 15.8x speedup
SIMD float-mul (64K x300) java 72ms / native 6ms = 12.0x speedup
SIMD kernel correctness PASS (native result == scalar reference)
Base64 payload size 8192 bytes
Base64 benchmark iterations 6000
Base64 SIMD byte path active (NEON-accelerated)
Base64 CN1 encode 323.000 ms
Base64 CN1 decode 138.000 ms
Base64 native encode 560.000 ms
Base64 encode ratio (CN1/native) 0.577x (42.3% faster)
Base64 native decode 398.000 ms
Base64 decode ratio (CN1/native) 0.347x (65.3% faster)
Base64 SIMD encode 85.000 ms
Base64 encode ratio (SIMD/CN1) 0.263x (73.7% faster)
Base64 SIMD decode 65.000 ms
Base64 decode ratio (SIMD/CN1) 0.471x (52.9% faster)
Base64 encode ratio (SIMD/native) 0.152x (84.8% faster)
Base64 decode ratio (SIMD/native) 0.163x (83.7% faster)
Image encode benchmark iterations 100
Image createMask (SIMD off) 10.000 ms
Image createMask (SIMD on) 3.000 ms
Image createMask ratio (SIMD on/off) 0.300x (70.0% faster)
Image applyMask (SIMD off) 93.000 ms
Image applyMask (SIMD on) 67.000 ms
Image applyMask ratio (SIMD on/off) 0.720x (28.0% faster)
Image modifyAlpha (SIMD off) 51.000 ms
Image modifyAlpha (SIMD on) 289.000 ms
Image modifyAlpha ratio (SIMD on/off) 5.667x (466.7% slower)
Image modifyAlpha removeColor (SIMD off) 386.000 ms
Image modifyAlpha removeColor (SIMD on) 239.000 ms
Image modifyAlpha removeColor ratio (SIMD on/off) 0.619x (38.1% faster)

…headers

Three review findings:

- "%0$s" recorded argIndex == 0, which the parser then treated as "no explicit
  index given" and satisfied from the next sequential argument. Argument indexes
  are 1-based, so this now raises IllegalFormatArgumentIndexException the way
  JDK 16 and later do. JDK 11 still accepts index zero, so the case is asserted
  against ParparVM alone rather than through the shared diff.

- A '.' with no digits after it defaulted the precision to zero, so "%.s"
  quietly produced an empty string. Every supported JDK rejects it with
  UnknownFormatConversionException naming '.' as the conversion; so do we now.

- The four new test files were missing the Codename One GPLv2 + Classpath
  Exception header, which failed check-copyright-headers.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings August 2, 2026 10:11
@shai-almog

shai-almog commented Aug 2, 2026

Copy link
Copy Markdown
Collaborator Author

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

Benchmark Results

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

Build and Run Timing

Metric Duration
Simulator Boot 79000 ms
Simulator Boot (Run) 1000 ms
App Install 14000 ms
App Launch 5000 ms
Test Execution 392000 ms

Detailed Performance Metrics

Metric Duration
SIMD kernel backend SSE2 (x64) / NEON (arm64) native kernels
SIMD int-add (64K x300) java 58ms / native 3ms = 19.3x speedup
SIMD float-mul (64K x300) java 62ms / native 3ms = 20.6x speedup
SIMD kernel correctness PASS (native result == scalar reference)
Base64 payload size 8192 bytes
Base64 benchmark iterations 6000
Base64 SIMD byte path active (NEON-accelerated)
Base64 CN1 encode 181.000 ms
Base64 CN1 decode 309.000 ms
Base64 native encode 742.000 ms
Base64 encode ratio (CN1/native) 0.244x (75.6% faster)
Base64 native decode 323.000 ms
Base64 decode ratio (CN1/native) 0.957x (4.3% faster)
Base64 SIMD encode 201.000 ms
Base64 encode ratio (SIMD/CN1) 1.110x (11.0% slower)
Base64 SIMD decode 193.000 ms
Base64 decode ratio (SIMD/CN1) 0.625x (37.5% faster)
Base64 encode ratio (SIMD/native) 0.271x (72.9% faster)
Base64 decode ratio (SIMD/native) 0.598x (40.2% faster)
Image encode benchmark iterations 100
Image createMask (SIMD off) 16.000 ms
Image createMask (SIMD on) 1.000 ms
Image createMask ratio (SIMD on/off) 0.063x (93.8% faster)
Image applyMask (SIMD off) 190.000 ms
Image applyMask (SIMD on) 137.000 ms
Image applyMask ratio (SIMD on/off) 0.721x (27.9% faster)
Image modifyAlpha (SIMD off) 63.000 ms
Image modifyAlpha (SIMD on) 79.000 ms
Image modifyAlpha ratio (SIMD on/off) 1.254x (25.4% slower)
Image modifyAlpha removeColor (SIMD off) 180.000 ms
Image modifyAlpha removeColor (SIMD on) 201.000 ms
Image modifyAlpha removeColor ratio (SIMD on/off) 1.117x (11.7% slower)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Not ready to approve

There are correctness/test-stability issues in the new formatter parsing and integration test setup that should be addressed to avoid divergent behavior and flaky results.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.

Review details

Suppressed comments (2)

vm/JavaAPI/src/java/lang/StringFormatter.java:154

  • The parser currently allows combining an explicit argument index (e.g. "%2$") with the previous-argument flag ('<'). That combination is not meaningful and the current logic will silently prioritize previous and ignore the explicit index (or throw MissingFormatArgumentException if it’s the first specifier), diverging from java.util.Formatter’s behavior for invalid format strings. Consider rejecting '<' when an explicit argument index was already parsed for this specifier.
                } else if (f == '<') {
                    previous = true;
                    pos++;
                    continue;

vm/tests/src/test/resources/com/codename1/tools/translator/StringFormatApp.java:244

  • This integration test derives its expected output from a JVM run of String.format(), but several cases depend on the JVM default locale (e.g. %,d, %,.2f, and %S uppercasing). Without pinning the default locale, the diff can become environment-dependent and fail on machines with non-"en_US" defaults even if ParparVM is correct. Consider setting the default locale explicitly at the start of main().
    public static void main(String[] args) {
        strings();
        integers();
        floats();
        failures();
  • Files reviewed: 21/21 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.

@shai-almog

shai-almog commented Aug 2, 2026

Copy link
Copy Markdown
Collaborator Author

Compared 148 screenshots: 148 matched.
✅ Native Mac screenshot tests passed.

Benchmark Results

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

Detailed Performance Metrics

Metric Duration
SIMD kernel backend SSE2 (x64) / NEON (arm64) native kernels
SIMD int-add (64K x300) java 63ms / native 4ms = 15.7x speedup
SIMD float-mul (64K x300) java 56ms / native 3ms = 18.6x speedup
SIMD kernel correctness PASS (native result == scalar reference)
Base64 payload size 8192 bytes
Base64 benchmark iterations 6000
Base64 SIMD byte path active (NEON-accelerated)
Base64 CN1 encode 171.000 ms
Base64 CN1 decode 132.000 ms
Base64 native encode 761.000 ms
Base64 encode ratio (CN1/native) 0.225x (77.5% faster)
Base64 native decode 501.000 ms
Base64 decode ratio (CN1/native) 0.263x (73.7% faster)
Base64 SIMD encode 66.000 ms
Base64 encode ratio (SIMD/CN1) 0.386x (61.4% faster)
Base64 SIMD decode 64.000 ms
Base64 decode ratio (SIMD/CN1) 0.485x (51.5% faster)
Base64 encode ratio (SIMD/native) 0.087x (91.3% faster)
Base64 decode ratio (SIMD/native) 0.128x (87.2% faster)
Image encode benchmark iterations 100
Image createMask (SIMD off) 14.000 ms
Image createMask (SIMD on) 11.000 ms
Image createMask ratio (SIMD on/off) 0.786x (21.4% faster)
Image applyMask (SIMD off) 137.000 ms
Image applyMask (SIMD on) 74.000 ms
Image applyMask ratio (SIMD on/off) 0.540x (46.0% faster)
Image modifyAlpha (SIMD off) 114.000 ms
Image modifyAlpha (SIMD on) 105.000 ms
Image modifyAlpha ratio (SIMD on/off) 0.921x (7.9% faster)
Image modifyAlpha removeColor (SIMD off) 99.000 ms
Image modifyAlpha removeColor (SIMD on) 89.000 ms
Image modifyAlpha removeColor ratio (SIMD on/off) 0.899x (10.1% faster)

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2e37e4b8ef

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread vm/JavaAPI/src/java/lang/StringFormatter.java Outdated
Comment thread vm/JavaAPI/src/java/lang/StringFormatter.java Outdated
Two more review findings, both confirmed against the JDK first:

- format(fmt, (Object[]) null) is not an empty argument list. The JVM skips the
  bounds checks and hands every specifier a null, so "%s %s" renders "null null"
  where this threw MissingFormatArgumentException. "%<" is the one exception: it
  reuses the previous argument, so it still requires that one existed, which is
  what the parser fuzz caught after the first attempt made null unconditional.

- '<' was consumed outside the duplicate-flag check, so "%s %<<s" quietly
  rendered "a a" instead of raising DuplicateFormatFlagsException. It is now a
  flag bit like every other, which also makes it participate in the %% and %n
  flag validation without the special case that was there before.

Both behaviours are identical on JDK 11, 17 and 25, so the new cases go through
the shared JVM-vs-ParparVM diff rather than being asserted one-sided.

The parser sweep now also generates null argument arrays and doubled flags;
divergence is still zero apart from the documented %a and %t gap.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings August 2, 2026 15:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Not ready to approve

The new differential test currently depends on the host default Locale and the public String.format() javadoc doesn’t document the locale-independent behavior, both of which can cause avoidable instability/confusion.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.

Review details

Suppressed comments (2)

vm/tests/src/test/java/com/codename1/tools/translator/StringFormatIntegrationTest.java:202

  • The JVM side of this differential test depends on the host default Locale for grouping/decimal separators. Since the ParparVM implementation is documented as locale-independent (always ',' grouping and '.' decimal), this test can become flaky or fail on machines with a non-English default locale. Consider forcing a known locale for the JVM run via system properties so the expected output matches the intended locale-independent behavior consistently.
        ProcessBuilder pb = new ProcessBuilder(
                javaExe,
                "-cp",
                classesDir + System.getProperty("path.separator") + javaApiDir,
                "StringFormatApp"

vm/JavaAPI/src/java/lang/String.java:1085

  • The public String.format() javadoc here doesn’t mention that this implementation is locale-independent (fixed '.' decimal separator and ',' grouping, and %n emits '\n'), which is a behavioral difference from the JDK that callers may rely on. Since this is a public API entry point, consider documenting the locale behavior (and that unsupported conversions like %a/%t throw UnknownFormatConversionException) here rather than only in the internal StringFormatter class.
    /**
     * Returns a formatted string using the specified format string and arguments.
     * Supports the {@code s b h c d o x e f g n %} conversions (and their uppercase
     * variants) with the {@code - + ' ' 0 , ( #} flags, width, precision, and the
     * {@code %n$} / {@code %<} argument selectors.
  • Files reviewed: 21/21 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.

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.

[Bug] IOS crash with "runtime exception"

2 participants