Skip to content

Commit

Permalink
[Java] use raw type serializer for getSerialzier in jit (#943)
Browse files Browse the repository at this point in the history
use raw type serializer for getSerialzier in jit
  • Loading branch information
chaokunyang authored Oct 5, 2023
1 parent 96ee19f commit e01370f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ protected Expression getOrCreateSerializer(Class<?> cls) {
// Don't invoke `Serializer.newSerializer` here, since it(ex. ObjectSerializer) may set itself
// as global serializer, which overwrite serializer updates in jit callback.
Expression newSerializerExpr =
inlineInvoke(classResolverRef, "getSerializer", SERIALIZER_TYPE, fieldTypeExpr);
inlineInvoke(classResolverRef, "getRawSerializer", SERIALIZER_TYPE, fieldTypeExpr);
String name = ctx.newName(StringUtils.uncapitalize(serializerClass.getSimpleName()));
// It's ok it jit already finished and this method return false, in such cases
// `serializerClass` is already jit generated class.
Expand Down
12 changes: 12 additions & 0 deletions java/fury-core/src/main/java/io/fury/resolver/ClassResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.google.common.primitives.Primitives;
import com.google.common.reflect.TypeToken;
import io.fury.Fury;
import io.fury.annotation.CodegenInvoke;
import io.fury.annotation.Internal;
import io.fury.builder.CodecUtils;
import io.fury.builder.Generated;
Expand Down Expand Up @@ -738,6 +739,17 @@ public <T> Serializer<T> getSerializer(Class<T> cls) {
return (Serializer<T>) getOrUpdateClassInfo(cls).serializer;
}

/**
* Return serializer without generics for specified class. The cast of Serializer to subclass
* serializer with generic is easy to raise compiler error for javac, so just use raw type.
*/
@Internal
@CodegenInvoke
public Serializer<?> getRawSerializer(Class<?> cls) {
Preconditions.checkNotNull(cls);
return getOrUpdateClassInfo(cls).serializer;
}

public boolean isSerializable(Class<?> cls) {
if (ReflectionUtils.isAbstract(cls) || cls.isInterface()) {
return false;
Expand Down

0 comments on commit e01370f

Please sign in to comment.