diff --git a/extensions/avro/deployment/src/main/java/io/quarkus/avro/deployment/AvroProcessor.java b/extensions/avro/deployment/src/main/java/io/quarkus/avro/deployment/AvroProcessor.java index 1cf6a40f8ed895..d1f96c6f6b2804 100644 --- a/extensions/avro/deployment/src/main/java/io/quarkus/avro/deployment/AvroProcessor.java +++ b/extensions/avro/deployment/src/main/java/io/quarkus/avro/deployment/AvroProcessor.java @@ -2,7 +2,6 @@ import java.util.Collection; -import org.apache.avro.generic.GenericDatumReader; import org.apache.avro.specific.AvroGenerated; import org.jboss.jandex.AnnotationInstance; import org.jboss.jandex.AnnotationTarget; @@ -24,14 +23,12 @@ public void build(CombinedIndexBuildItem indexBuildItem, BuildProducer conf) { NativeImageConfigBuildItem.Builder builder = NativeImageConfigBuildItem.builder(); - builder.addRuntimeInitializedClass(GenericDatumReader.class.getName()); Collection annotations = indexBuildItem.getIndex() .getAnnotations(DotName.createSimple(AvroGenerated.class.getName())); for (AnnotationInstance annotation : annotations) { if (annotation.target().kind() == AnnotationTarget.Kind.CLASS) { String className = annotation.target().asClass().name().toString(); - builder.addRuntimeInitializedClass(className); reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, true, className)); } } diff --git a/extensions/avro/runtime/src/main/java/io/quarkus/avro/graal/AvroSubstitutions.java b/extensions/avro/runtime/src/main/java/io/quarkus/avro/graal/AvroSubstitutions.java index 6d480fef3d507f..009db1593e49e1 100644 --- a/extensions/avro/runtime/src/main/java/io/quarkus/avro/graal/AvroSubstitutions.java +++ b/extensions/avro/runtime/src/main/java/io/quarkus/avro/graal/AvroSubstitutions.java @@ -2,10 +2,16 @@ import java.lang.reflect.Constructor; import java.util.HashMap; +import java.util.IdentityHashMap; import java.util.Map; import java.util.function.Function; +import org.apache.avro.Schema; +import org.apache.avro.generic.GenericData; import org.apache.avro.generic.IndexedRecord; +import org.apache.avro.io.DatumReader; +import org.apache.avro.io.ResolvingDecoder; +import org.apache.avro.util.WeakIdentityHashMap; import com.oracle.svm.core.annotate.Alias; import com.oracle.svm.core.annotate.Inject; @@ -79,5 +85,45 @@ public Target_org_apache_avro_reflect_ReflectData_ClassAccessorData(Class c) } +@TargetClass(className = "org.apache.avro.generic.GenericDatumReader") +final class Target_org_apache_avro_generic_GenericDatumReader { + + @Alias + private GenericData data; + @Alias + private Schema actual; + @Alias + private Schema expected; + @Alias + private DatumReader fastDatumReader; + @Alias + private ResolvingDecoder creatorResolver; + @Alias + @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.Reset) + private Thread creator; + + @Alias + @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.FromAlias) + private static ThreadLocal>> RESOLVER_CACHE = ThreadLocal.withInitial( + WeakIdentityHashMap::new); + @Alias + @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.Reset) + private Map stringClassCache; + @Alias + @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.Reset) + private Map stringCtorCache; + + @Substitute + protected Target_org_apache_avro_generic_GenericDatumReader(GenericData data) { + this.fastDatumReader = null; + this.creatorResolver = null; + this.stringClassCache = new IdentityHashMap(); + this.stringCtorCache = new HashMap(); + this.data = data; + this.creator = Thread.currentThread(); + } + +} + class AvroSubstitutions { }