Skip to content

Port oracle/graal#14787: @Value.Optimized allocation-free interface proxies (GR-79503) - #171

Closed
Sam Gammon (sgammon) wants to merge 1 commit into
upstream/wave-15from
feat/optimized-value-proxies
Closed

Sam Gammon (sgammon) wants to merge 1 commit into
upstream/wave-15from
feat/optimized-value-proxies

Conversation

@sgammon

Copy link
Copy Markdown
Member

Ports oracle#14787 "[WIP] [GR-79503] Add allocation-free functional interface proxies" (Christian Humer), stacked on #170 (wave 15).

Upstream head at port time: c5471a1a85e (commits 4cc4d1f727a Add optimized Value interface proxies, c5471a1a85e Target optimized Value proxies for 25.6), based on upstream 49add4294bb. The upstream PR is WIP and may be force-pushed; compare against these SHAs.

What it adds

@Value.Optimized: annotating an interface makes Value.as(Interface.class) return a generated proxy class (PolyglotGeneratedProxy subclasses, generated with the Truffle ASM copy, PolyglotProxyGenerator/PolyglotProxyClass) instead of a java.lang.reflect.Proxy. Each method gets its own call target with typed arguments, so in Native Image with runtime compilation the Java-to-guest call carries no Object[]/boxing: TypedEntrySupport gets exact-entry graph builder plugins for generated proxy entries (with an AOT fallback address when no compiled code exists), the typed return kinds are extended to all primitives (byte, short, char, float added), and PolyglotProxyFeature registers annotated interfaces at image build time. Also: host stack traces through generated proxies, HostAccessFromModuleTest coverage, a JMH FunctionProxyBenchmark, docs in embed-languages.md.

Port

  • 4cc4d1f727a cherry-picked with -x. One conflict: TruffleFeature imports (the fork's SubstrateOptions/SubstrateTarget imports next to the new ParsingReason).
  • c5471a1a85e not picked: it only retargets the API to 25.6 (@since 25.6, a new "Version 25.6" CHANGELOG section). The fork is 25.5.5, and 4cc4d1f727a already says @since 25.5 with the CHANGELOG entry in the top "Version 25.5" section of sdk/CHANGELOG.md, which is where the fork wants it. No other adaptation.

EE

The typed-entry and proxy code is all CE code (com.oracle.svm.truffle, org.graalvm.truffle) that the EE hybrid gets from the fork's jars; TruffleFeature (which registers the exact-entry plugin) is required by Oracle's EnterpriseTruffleFeature. The removed TypedEntrySupport.lookupInterpreterEntryAddress/unspecializedInterpreterEntryAddress are not referenced by ea.05's enterprise jars. Checked on the top of the stack (with oracle#14788): LinkCheck clean, and a native image on the EE home with an @Value.Optimized interface over an SL function uses the generated proxy and runs compiled (numbers below).

Results (LabsJDK labsjdk-ce-latest-jvmci-25.5-b24, linux-amd64)

  • mx build --warning-as-error --force-javac in substratevm, truffle and compiler: OK. mx checkstyle --primary in truffle, sdk, substratevm, compiler: clean. mx sigtest --check all in truffle and sdk: OK.
  • New JVM tests: mx -p truffle unittest GuestFunctionToHostInterfaceProxyTest HostAccessFromModuleTest HostStackTraceTest GeneratedProxyNativeImageTest: OK (60 tests). mx -p compiler unittest GenericFunctionProxyCompilationTest: OK (1 test).
  • Native: mx native-truffle-unittest com.oracle.truffle.api.test.polyglot.GeneratedProxyNativeImageTest with the Truffle native-unittest gate's build args (incl. the new --add-exports=org.graalvm.truffle/com.oracle.truffle.polyglot=ALL-UNNAMED): 13 passed, 1 skipped by its own assumeFalse(TruffleOptions.AOT).
  • On the top of the stack ([WIP] [GR-79669] Support configurable context preinitialization for explicit engines oracle/graal#14788): Ristretto gate set OK (50 tests) + OK (2 tests); mx -p truffle unittest com.oracle.truffle.api.test.polyglot com.oracle.truffle.api.modularized.test: OK (2376 tests).
  • EE hybrid (ea.05 + fork jars from the top of the stack), SL native image, add(a, b) called 2M times per round through an @Value.Optimized interface vs the same interface without the annotation: generated proxy $GeneratedProxy$… (superclass PolyglotGeneratedProxy), engine implementation "Oracle GraalVM", ~9.3 ns/call optimized vs ~18.3 ns/call generic java.lang.reflect.Proxy, identical sums; no compilation failures with TraceCompilation. CE home: ~9.7 vs ~18.3 ns/call.

@sgammon

Copy link
Copy Markdown
Member Author

Landed on elide-25.5.x by fast-forward to b2eb4ee (with #170), for 25.5.5-elide.21. The commits are unchanged; GitHub can't mark a stacked PR merged once its base already contains it.

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