Skip to content

Commit 47a73a1

Browse files
authored
feat(xlang/java): refactor java native serialization type system and streaming type info for xlang (#3153)
## Why? Fory needs streaming-friendly shared type meta so readers can deserialize without seeking. The current work also unifies native/xlang type IDs and removes legacy paths that were causing inconsistent type resolution and CI failures across languages. ## What does this PR do? - Switch shared type meta to the streaming wire format (inline TypeDef bytes with index marker) and remove legacy meta-offset handling. - Unify native and xlang type ID handling in Java resolvers, simplify dispatch paths, and remove outdated compatibility branches. - Add `registerSerializerAndType` API for explicit type+serializer registration flow. - Fix Go skip path to consume streaming shared type meta in compatible struct skipping and add a regression test. - Keep resolver fast paths by inlining class-info reads and avoiding redundant serializer creation. ## Related issues Closes #3157 Closes #3119 #2609 #2818 ## Does this PR introduce any user-facing change? <!-- If any user-facing interface changes, please [open an issue](https://github.com/apache/fory/issues/new/choose) describing the need to do so and update the document if necessary. Delete section if not applicable. --> - [x] Does this PR introduce any public API change? - [x] Does this PR introduce any binary protocol compatibility change? ## Benchmark Not run.
1 parent 3f40a69 commit 47a73a1

File tree

114 files changed

+6609
-4659
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

114 files changed

+6609
-4659
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ jobs:
324324
- name: Run Rust Xlang Test
325325
env:
326326
FORY_RUST_JAVA_CI: "1"
327+
ENABLE_FORY_DEBUG_OUTPUT: "1"
327328
run: |
328329
cd java
329330
mvn -T16 --no-transfer-progress clean install -DskipTests
@@ -410,6 +411,7 @@ jobs:
410411
- name: Run CPP Xlang Test
411412
env:
412413
FORY_CPP_JAVA_CI: "1"
414+
ENABLE_FORY_DEBUG_OUTPUT: "1"
413415
run: |
414416
cd java
415417
mvn -T16 --no-transfer-progress clean install -DskipTests
@@ -531,6 +533,7 @@ jobs:
531533
- name: Run Python Xlang Test
532534
env:
533535
FORY_PYTHON_JAVA_CI: "1"
536+
ENABLE_FORY_DEBUG_OUTPUT: "1"
534537
run: |
535538
cd java
536539
mvn -T16 --no-transfer-progress clean install -DskipTests
@@ -599,6 +602,7 @@ jobs:
599602
- name: Run Go Xlang Test
600603
env:
601604
FORY_GO_JAVA_CI: "1"
605+
ENABLE_FORY_DEBUG_OUTPUT: "1"
602606
run: |
603607
cd java
604608
mvn -T16 --no-transfer-progress clean install -DskipTests

AGENTS.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ While working on Fory, please remember:
1414
- **Cross-Language Consistency**: Maintain consistency across language implementations while respecting language-specific idioms.
1515
- **Graalvm Support using fory codegen**: For graalvm, please use `fory codegen` to generate the serializer when building graalvm native image, do not use graallvm reflect-related configuration unless for JDK `proxy`.
1616
- **Xlang Type System**: Java `native mode(xlang=false)` shares same type systems between type id from `Types.BOOL~Types.STRING` with `xlang mode(xlang=true)`, but for other types, java `native mode` has different type ids.
17+
- **Remote git repository**: `git@github.com:apache/fory.git` is remote repository, do not use other remote repository when you want to check code under `main` branch.
18+
- **Contributor git repository**: A contributor should fork the `git@github.com:apache/fory.git` repo, and git push the code changes into their forked repo, then create a pull request from the branch in their forked repo into `git@github.com:apache/fory.git`.
1719

1820
## Build and Development Commands
1921

@@ -295,9 +297,6 @@ it_dir=$(pwd)
295297
# Run graalvm tests
296298
cd $it_dir/graalvm_tests && mvn -T16 -DskipTests=true -Pnative package && target/main
297299

298-
# Run latest_jdk_tests
299-
cd $it_dir/latest_jdk_tests && mvn -T16 test
300-
301300
# Run JDK compatibility tests
302301
cd $it_dir/jdk_compatibility_tests && mvn -T16 test
303302

@@ -498,7 +497,6 @@ Fory rust provides macro-based serialization and deserialization. Fory rust cons
498497
- Note that fory use codegen to support graalvm instead of reflection, fory don't use `reflect-config.json` for
499498
serialization, this is the core advantage of compared to graalvm JDK serialization.
500499
- **jdk_compatibility_tests**: test suite for fory serialization compatibility between multiple JDK versions
501-
- **latest_jdk_tests**: test suite for `jdk17+` versions
502500

503501
## Key Development Guidelines
504502

benchmarks/java_benchmark/src/main/java/org/apache/fory/benchmark/UserTypeDeserializeSuite.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public Object flatbuffers_deserialize(FlatBuffersState.FlatBuffersUserTypeState
147147
public static void main(String[] args) throws IOException {
148148
if (args.length == 0) {
149149
String commandLine =
150-
"org.apache.fory.*UserTypeDeserializeSuite.fory* -f 1 -wi 5 -i 10 -t 1 -w 2s -r 2s -rf csv "
150+
"org.apache.fory.*UserTypeDeserializeSuite.* -f 1 -wi 3 -i 3 -t 1 -w 2s -r 2s -rf csv "
151151
+ "-p objectType=MEDIA_CONTENT -p bufferType=array -p references=false";
152152
System.out.println(commandLine);
153153
args = commandLine.split(" ");

benchmarks/java_benchmark/src/main/java/org/apache/fory/benchmark/UserTypeSerializeSuite.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public Object flatbuffers_serialize(FlatBuffersState.FlatBuffersUserTypeState st
157157
public static void main(String[] args) throws IOException {
158158
if (args.length == 0) {
159159
String commandLine =
160-
"org.apache.fory.*UserTypeSerializeSuite.fory_serialize_compatible -f 1 -wi 5 -i 10 -t 1 -w 200s -r 2s -rf csv "
160+
"org.apache.fory.*UserTypeSerializeSuite.* -f 1 -wi 3 -i 3 -t 1 -w 2s -r 2s -rf csv "
161161
+ "-p objectType=MEDIA_CONTENT -p bufferType=array -p references=false";
162162
System.out.println(commandLine);
163163
args = commandLine.split(" ");

ci/format.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ format_java() {
143143
cd "$ROOT/benchmarks/java_benchmark"
144144
mvn -T10 --no-transfer-progress spotless:apply
145145
cd "$ROOT/integration_tests"
146-
dirs=("graalvm_tests" "jdk_compatibility_tests" "latest_jdk_tests")
146+
dirs=("graalvm_tests" "jdk_compatibility_tests")
147147
for d in "${dirs[@]}" ; do
148148
pushd "$d"
149149
mvn -T10 --no-transfer-progress spotless:apply

ci/release.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,15 +186,14 @@ def bump_java_version(new_version):
186186
"integration_tests/graalvm_tests",
187187
"integration_tests/jdk_compatibility_tests",
188188
"integration_tests/jpms_tests",
189-
"integration_tests/latest_jdk_tests",
190-
"integration_tests/latest_jdk_tests",
191189
"benchmarks/java_benchmark",
192190
"java/fory-core",
193191
"java/fory-format",
194192
"java/fory-simd",
195193
"java/fory-extensions",
196194
"java/fory-test-core",
197195
"java/fory-testsuite",
196+
"java/fory-latest-jdk-tests",
198197
]:
199198
_bump_version(p, "pom.xml", new_version, _update_pom_parent_version)
200199
# mvn versions:set too slow

ci/run_ci.sh

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -182,12 +182,6 @@ integration_tests() {
182182
echo "benchmark tests"
183183
cd "$ROOT"/benchmarks/java_benchmark
184184
mvn -T10 -B --no-transfer-progress clean test install -Pjmh
185-
echo "Start latest jdk tests"
186-
cd "$ROOT"/integration_tests/latest_jdk_tests
187-
echo "latest_jdk_tests: JDK 21"
188-
export JAVA_HOME="$ROOT/zulu21.28.85-ca-jdk21.0.0-linux_x64"
189-
export PATH=$JAVA_HOME/bin:$PATH
190-
mvn -T10 -B --no-transfer-progress clean test
191185
echo "Start JPMS tests"
192186
cd "$ROOT"/integration_tests/jpms_tests
193187
mvn -T10 -B --no-transfer-progress clean compile
@@ -220,10 +214,6 @@ jdk17_plus_tests() {
220214
exit $testcode
221215
fi
222216
echo "Executing fory java tests succeeds"
223-
echo "Executing latest_jdk_tests"
224-
cd "$ROOT"/integration_tests/latest_jdk_tests
225-
mvn -T10 -B --no-transfer-progress clean test
226-
echo "Executing latest_jdk_tests succeeds"
227217
}
228218

229219
kotlin_tests() {

ci/tasks/java.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -175,12 +175,6 @@ def run_jdk17_plus(java_version="17"):
175175
common.exec_cmd("mvn -T10 --batch-mode --no-transfer-progress install")
176176

177177
logging.info("Executing fory java tests succeeds")
178-
logging.info("Executing latest_jdk_tests")
179-
180-
common.cd_project_subdir("integration_tests/latest_jdk_tests")
181-
common.exec_cmd("mvn -T10 -B --no-transfer-progress clean test")
182-
183-
logging.info("Executing latest_jdk_tests succeeds")
184178

185179

186180
def run_windows_java21():
@@ -218,17 +212,6 @@ def run_integration_tests():
218212
common.cd_project_subdir("benchmarks/java_benchmark")
219213
common.exec_cmd("mvn -T10 -B --no-transfer-progress clean test install -Pjmh")
220214

221-
logging.info("Start latest jdk tests")
222-
common.cd_project_subdir("integration_tests/latest_jdk_tests")
223-
logging.info("latest_jdk_tests: JDK 21")
224-
225-
# Set Java 21 as the current JDK
226-
java_home = os.path.join(common.PROJECT_ROOT_DIR, JDKS["21"])
227-
os.environ["JAVA_HOME"] = java_home
228-
os.environ["PATH"] = f"{java_home}/bin:{os.environ.get('PATH', '')}"
229-
230-
common.exec_cmd("mvn -T10 -B --no-transfer-progress clean test")
231-
232215
logging.info("Start JPMS tests")
233216
common.cd_project_subdir("integration_tests/jpms_tests")
234217
common.exec_cmd("mvn -T10 -B --no-transfer-progress clean compile")

0 commit comments

Comments
 (0)