Skip to content

Conversation

@google-labs-jules
Copy link
Contributor

This PR implements an optimization in BytecodeTranslator to generate "barebone" C functions for methods that do not require full VM overhead.

Key changes:

  • Detection: New checkBarebone() method identifies candidates (methods without synchronization, native calls, exception handlers, method invocations, object allocations, or complex instructions).
  • Code Generation:
    • Skips DEFINE_METHOD_STACK, monitorEnter (unless synchronized), and __STATIC_INITIALIZER.
    • Declares C variables (olocals_, ilocals_, etc.) for arguments instead of using the VM's locals[] array.
    • Initializes a simplified Stack Pointer (SP).
    • Uses direct C return statements instead of the heavy releaseForReturn macros.
  • Safety: Includes a check (maxLocals > argSlots) to disable optimization if the method uses internal local variables but lacks debug information (which would otherwise lead to undeclared C variables).

These changes effectively eliminate the VM cost for simple arithmetic or field access methods, compiling them into efficient, standalone C functions.


PR created automatically by Jules for task 12500047631959537358 started by @shai-almog

- Implemented `checkBarebone` to identify simple methods (no sync, native, exceptions, allocations).
- Modified `BytecodeMethod` to skip `DEFINE_METHOD_STACK` and other VM overhead for barebone methods.
- Updated variable generation to use `olocals_`/`ilocals_` directly.
- Updated `BasicInstruction` to use direct C `return` instead of `releaseForReturn` macros.
- Added safety check to prevent optimization if internal locals exist but debug info is missing.
@google-labs-jules
Copy link
Contributor Author

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!


For security, I will only act on instructions from the user who triggered this task.

New to Jules? Learn more at jules.google/docs.

@github-actions
Copy link

github-actions bot commented Dec 25, 2025

✅ Continuous Quality Report

Test & Coverage

Static Analysis

Generated automatically by the PR CI workflow.

- Replaced usages of `locals[X]` with `olocals_X_` (and primitive equivalents) in code generated by `optimize()` for barebone methods via `fixUpBarebone`.
- Updated `VarOp.java` to support primitive types (`ILOAD`, `ISTORE`, etc.) using direct C variables in barebone mode.
- Exposed necessary fields in `CustomJump`, `CustomInstruction`, and `CustomInvoke` to facilitate post-optimization fixups.
… and 'this' access

- Updated `VarOp.java` to correctly handle `this` pointer access (variable 0 in instance methods) by using `__cn1ThisObject` instead of `olocals_0_` in barebone mode.
- Fixed `VarOp.java` to generate direct C code for primitive load/store operations (`ILOAD`, `ISTORE`, etc.) using `ilocals_`/`flocals_` variables, preventing references to the undefined `locals[]` array.
- Updated `BytecodeMethod.java` to run a `fixUpBarebone` pass that rewrites `locals[...]` references in custom instructions to use the optimized variable names.
- Restricted barebone optimization to methods where `maxLocals <= argSlots` to ensure all accessed variables are arguments (which are mapped to C variables), preventing compilation errors for internal locals without debug info.
@github-actions
Copy link

✅ ByteCodeTranslator Quality Report

Test & Coverage

  • Tests: 169 total, 0 failed, 2 skipped

Benchmark Results

  • Execution Time: 9641 ms

  • Hotspots (Top 20 sampled methods):

    • 23.30% java.lang.String.indexOf (390 samples)
    • 17.74% com.codename1.tools.translator.Parser.isMethodUsed (297 samples)
    • 15.47% com.codename1.tools.translator.Parser.addToConstantPool (259 samples)
    • 9.98% java.util.ArrayList.indexOf (167 samples)
    • 5.56% java.lang.Object.hashCode (93 samples)
    • 3.35% com.codename1.tools.translator.ByteCodeClass.calcUsedByNative (56 samples)
    • 3.11% com.codename1.tools.translator.ByteCodeClass.fillVirtualMethodTable (52 samples)
    • 2.69% java.lang.System.identityHashCode (45 samples)
    • 1.49% com.codename1.tools.translator.Parser.cullMethods (25 samples)
    • 1.14% com.codename1.tools.translator.BytecodeMethod.optimize (19 samples)
    • 1.02% com.codename1.tools.translator.ByteCodeClass.markDependent (17 samples)
    • 0.78% com.codename1.tools.translator.Parser.generateClassAndMethodIndexHeader (13 samples)
    • 0.72% java.io.FileInputStream.open0 (12 samples)
    • 0.66% java.lang.StringBuilder.append (11 samples)
    • 0.66% com.codename1.tools.translator.BytecodeMethod.isMethodUsedByNative (11 samples)
    • 0.60% java.io.FileOutputStream.open0 (10 samples)
    • 0.60% com.codename1.tools.translator.Parser.getClassByName (10 samples)
    • 0.54% java.lang.StringCoding$StringEncoder.encode (9 samples)
    • 0.48% java.io.FileOutputStream.writeBytes (8 samples)
    • 0.48% java.io.UnixFileSystem.getBooleanAttributes0 (8 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.

@shai-almog
Copy link
Collaborator

shai-almog commented Dec 25, 2025

iOS screenshot updates

Compared 30 screenshots: 23 matched, 6 updated, 1 missing reference.

  • BrowserComponent — updated screenshot. Screenshot differs (1206x2622 px, bit depth 8).

    BrowserComponent
    Preview info: Preview provided by instrumentation.
    Full-resolution PNG saved as BrowserComponent.png in workflow artifacts.

  • graphics-draw-arc — updated screenshot. Screenshot differs (1206x2622 px, bit depth 8).

    graphics-draw-arc
    Preview info: JPEG preview quality 20; JPEG preview quality 20; downscaled to 603x1311.
    Full-resolution PNG saved as graphics-draw-arc.png in workflow artifacts.

  • graphics-draw-gradient — updated screenshot. Screenshot differs (1206x2622 px, bit depth 8).

    graphics-draw-gradient
    Preview info: JPEG preview quality 10; JPEG preview quality 10; downscaled to 844x1835.
    Full-resolution PNG saved as graphics-draw-gradient.png in workflow artifacts.

  • graphics-draw-round-rect — missing reference. Reference screenshot missing at /Users/runner/work/CodenameOne/CodenameOne/scripts/ios/screenshots/graphics-draw-round-rect.png.

    graphics-draw-round-rect
    Preview info: JPEG preview quality 10; JPEG preview quality 10; downscaled to 844x1835.
    Full-resolution PNG saved as graphics-draw-round-rect.png in workflow artifacts.

  • graphics-draw-string — updated screenshot. Screenshot differs (1206x2622 px, bit depth 8).

    graphics-draw-string
    Preview info: JPEG preview quality 10; JPEG preview quality 10; downscaled to 422x918.
    Full-resolution PNG saved as graphics-draw-string.png in workflow artifacts.

  • graphics-draw-string-decorated — updated screenshot. Screenshot differs (1206x2622 px, bit depth 8).

    graphics-draw-string-decorated
    Preview info: JPEG preview quality 10; JPEG preview quality 10; downscaled to 603x1311.
    Full-resolution PNG saved as graphics-draw-string-decorated.png in workflow artifacts.

  • kotlin — updated screenshot. Screenshot differs (1206x2622 px, bit depth 8).

    kotlin
    Preview info: Preview provided by instrumentation.
    Full-resolution PNG saved as kotlin.png in workflow artifacts.

Benchmark Results

  • VM Translation Time: 268 seconds
  • Compilation Time: 47 seconds

Detailed Performance Metrics

Metric Duration
Build Time Statistics
Setup & Unzip 23783 ms
Extract Extensions 16 ms
Google Services Setup 2 ms
Scan Classes 446 ms
Extract Libs 782 ms
Inject Build Hints 28 ms
Generate Unit Tests 1 ms
Generate Stubs 723 ms
Compile Stubs 1808 ms
Generate Icons 825 ms
Prepare ParparVM 129 ms
ParparVM Execution 155258 ms
Post-VM Setup 122 ms
CocoaPods 4046 ms
Finalize 26 ms
Total Time 187996 msMaven Overhead : 81000 ms
CocoaPods Install (Script) 1000 ms
Simulator Boot (Run) 41000 ms
App Install 26000 ms
App Launch 10000 ms
Test Execution 168000 ms

@shai-almog shai-almog marked this pull request as ready for review December 25, 2025 18:58
@shai-almog shai-almog merged commit a3628a5 into master Dec 25, 2025
11 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.

2 participants