Skip to content

Conversation

@chaokunyang
Copy link
Collaborator

Summary

Closes #3112

This PR adds support for xlang serialization mode with GraalVM native image builds.

Changes:

  • Add XtypeResolver.ensureSerializersCompiled() to ensure serializers for xlang-registered classes are compiled at GraalVM build time
  • Update Fory.ensureSerializersCompiled() to also call XtypeResolver.ensureSerializersCompiled() when xlang mode is enabled
  • Add XlangExample for graalvm_tests to verify xlang mode works with native-image builds
  • Register XlangExample for build-time initialization in native-image properties

Root cause:

When xlang mode is enabled, classes registered via Fory.register() go through XtypeResolver, but Fory.ensureSerializersCompiled() only processed classes in ClassResolver.classInfoMap. This meant xlang-registered classes were not properly compiled at GraalVM build time, causing NullPointerException during initialization.

Test plan

  • Existing xlang tests pass
  • XlangExample added for native-image testing
  • CI should verify the graalvm_tests build succeeds

Closes apache#3112

- Add XtypeResolver.ensureSerializersCompiled() to ensure serializers
  for xlang-registered classes are compiled at GraalVM build time
- Update Fory.ensureSerializersCompiled() to also call XtypeResolver
  when xlang mode is enabled
- Add XlangExample for graalvm_tests to verify xlang mode works with
  native-image builds
- Register XlangExample for build-time initialization in native-image
  properties
GraalvmSupport.registerClass should be called for all classes, not just
during GraalVM build time. Only the enum-specific handling should be
guarded by isGraalBuildtime().
- Add abstract ensureSerializersCompiled() to TypeResolver
- Add @OverRide to ClassResolver.ensureSerializersCompiled()
- Have XtypeResolver.ensureSerializersCompiled() call classResolver first
- Simplify Fory.ensureSerializersCompiled() to use _getTypeResolver()
This commit adds support for xlang (cross-language) serialization
mode when running with GraalVM native image.

Key changes:
- Add "Xlang" suffix to generated codec class names to differentiate
  xlang and non-xlang codecs (BaseObjectCodecBuilder)
- Use configHash in graalvmSerializers cache key to prevent codec
  reuse between xlang and non-xlang modes (CodecUtils)
- Use TypeResolver interface instead of concrete class to support
  both xlang and non-xlang modes in generated code
- Add xwrite/xread methods to GraalvmSerializerHolder for xlang
  support (GraalvmSupport)
- Direct serializer creation in XtypeResolver.register for GraalVM
  build time to avoid DeferedLazySerializer persistence issues
- Add resolveSerializer() method to DeferedLazySerializer for
  explicit resolution during ensureSerializersCompiled
- Skip Lambda/Proxy serializers in xlang mode since java.lang.Class
  is not supported (ClassResolver)

Closes apache#3112
@chaokunyang chaokunyang merged commit 655cdd7 into apache:main Jan 12, 2026
99 of 103 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.

[Java] LambdaSerializer cannot be initialized when Language is XLANG.

2 participants