This is an automated email from the ASF dual-hosted git repository.
pandalee pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/fory.git
The following commit(s) were added to refs/heads/main by this push:
new 5c813fd68 fix(java): fix graalvm not use generated serializer (#2682)
5c813fd68 is described below
commit 5c813fd689a782f30a83fe28138fe47fc5da5a26
Author: Shawn Yang <[email protected]>
AuthorDate: Mon Sep 29 12:21:37 2025 +0800
fix(java): fix graalvm not use generated serializer (#2682)
<!--
**Thanks for contributing to Apache Fory™.**
**If this is your first time opening a PR on fory, you can refer to
[CONTRIBUTING.md](https://github.com/apache/fory/blob/main/CONTRIBUTING.md).**
Contribution Checklist
- The **Apache Fory™** community has requirements on the naming of pr
titles. You can also find instructions in
[CONTRIBUTING.md](https://github.com/apache/fory/blob/main/CONTRIBUTING.md).
- Apache Fory™ has a strong focus on performance. If the PR you submit
will have an impact on performance, please benchmark it first and
provide the benchmark result here.
-->
## Why?
<!-- Describe the purpose of this PR. -->
## What does this PR do?
<!-- Describe the details of this PR. -->
## Related issues
#2680
#2669
## 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.
-->
- [ ] Does this PR introduce any public API change?
- [ ] Does this PR introduce any binary protocol compatibility change?
## Benchmark
<!--
When the PR has an impact on performance (if you don't know whether the
PR will have an impact on performance, you can submit the PR first, and
if it will have impact on performance, the code reviewer will explain
it), be sure to attach a benchmark data here.
Delete section if not applicable.
-->
---
.../org/apache/fory/resolver/ClassResolver.java | 21 ++++++++++++++++++++-
.../java/org/apache/fory/resolver/TypeResolver.java | 1 +
2 files changed, 21 insertions(+), 1 deletion(-)
diff --git
a/java/fory-core/src/main/java/org/apache/fory/resolver/ClassResolver.java
b/java/fory-core/src/main/java/org/apache/fory/resolver/ClassResolver.java
index 4f7e5bcc3..8b9eca8dc 100644
--- a/java/fory-core/src/main/java/org/apache/fory/resolver/ClassResolver.java
+++ b/java/fory-core/src/main/java/org/apache/fory/resolver/ClassResolver.java
@@ -271,6 +271,14 @@ public class ClassResolver extends TypeResolver {
addDefaultSerializers();
shimDispatcher.initialize();
innerEndClassId = extRegistry.classIdGenerator;
+ if (GraalvmSupport.isGraalBuildtime()) {
+ classInfoMap.forEach(
+ (cls, classInfo) -> {
+ if (classInfo.serializer != null) {
+ extRegistry.registeredClassInfos.add(classInfo);
+ }
+ });
+ }
}
private void addDefaultSerializers() {
@@ -679,9 +687,11 @@ public class ClassResolver extends TypeResolver {
addSerializer(type, serializer);
ClassInfo classInfo = classInfoMap.get(type);
classInfoMap.put(type, classInfo);
+ extRegistry.registeredClassInfos.add(classInfo);
// in order to support customized serializer for abstract or interface.
if (!type.isPrimitive() && (ReflectionUtils.isAbstract(type) ||
type.isInterface())) {
extRegistry.absClassInfo.put(type, classInfo);
+ extRegistry.registeredClassInfos.add(classInfo);
}
}
@@ -1794,7 +1804,16 @@ public class ClassResolver extends TypeResolver {
}
}
});
- classInfoCache = NIL_CLASS_INFO;
+ if (GraalvmSupport.isGraalBuildtime()) {
+ classInfoCache = NIL_CLASS_INFO;
+ classInfoMap.forEach(
+ (cls, classInfo) -> {
+ if (classInfo.serializer != null
+ && !extRegistry.registeredClassInfos.contains(classInfo)) {
+ classInfo.serializer = null;
+ }
+ });
+ }
} finally {
fory.getJITContext().unlock();
}
diff --git
a/java/fory-core/src/main/java/org/apache/fory/resolver/TypeResolver.java
b/java/fory-core/src/main/java/org/apache/fory/resolver/TypeResolver.java
index 4bfb54431..4db04ecf9 100644
--- a/java/fory-core/src/main/java/org/apache/fory/resolver/TypeResolver.java
+++ b/java/fory-core/src/main/java/org/apache/fory/resolver/TypeResolver.java
@@ -697,6 +697,7 @@ public abstract class TypeResolver {
final IdentityMap<Type, GenericType> genericTypes = new IdentityMap<>();
final Map<Class, Map<String, GenericType>> classGenericTypes = new
HashMap<>();
final Map<List<ClassLoader>, CodeGenerator> codeGeneratorMap = new
HashMap<>();
+ final Set<ClassInfo> registeredClassInfos = new HashSet<>();
boolean ensureSerializersCompiled;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]