Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Graal Native image in micronaut-kafka #29

Closed
kortatu opened this issue Apr 2, 2019 · 8 comments
Closed

Support for Graal Native image in micronaut-kafka #29

kortatu opened this issue Apr 2, 2019 · 8 comments
Assignees

Comments

@kortatu
Copy link

kortatu commented Apr 2, 2019

Hi everyone,
I'm trying to create a native image with Graal in a micronaut project that uses micronaut-kafka.
I have found several problems and I think I hit a wall here trying to solve it. I also thought it was interesting to writing down my progress in case there is someone there with more knowledge than me who can solve it or at least advance a bit more.

First thing was the known Snappy compressor in org.apache.kafka.common.record.CompressionType enum. SNAPPY wrapForInput and wrapForOutput uses a MethodHandle.invoke that is Unsupported by Graal. As I'm not using this compression, and it is just an option, I overwrote the class with a NonSupportedException return instead of using the invoke.
Maybe this can be done with @substitute in MicronautSubstitutions, but I have no clue how to substitute Enum values.

But anyway, copying the class in my project with the same package and name and changing the SNAPPY field implementation worked and the building of the native image continued.

After that the creation of the image finished, but when I tried to start up the application I got two errors of classes intantiated by reflection but not registered, so I added them manually to reflect.json:
{ "name" : "[Lio.micronaut.configuration.kafka.bind.ConsumerRecordBinder;", "allDeclaredConstructors" : true }, { "name" : "[Lio.micronaut.configuration.kafka.serde.SerdeRegistry;", "allDeclaredConstructors" : true }

But the next error I got, I have no idea how to fix it (or even if it is possible):

ERROR io.micronaut.runtime.Micronaut - Error starting Micronaut server: Proxy class defined by interfaces [interface io.micronaut.configuration.kafka.annotation.Topic] not found. Generating proxy classes at runtime is not supported. Proxy classes need to be defined at image build time by specifying the list of interfaces that they implement. To define proxy classes use -H:DynamicProxyConfigurationFiles= and -H:DynamicProxyConfigurationResources= options.

I guess the solution is to implement those proxies at compile time.

So this is where I can get to. Maybe I can implement my producer using directly KafkaClient so no proxy is involved.

I have also found this thread in Graal project: failed to compile simple kafka consumer app to native image, reflection issue #532

@graemerocher
Copy link
Contributor

we are waiting for Micronaut 1.1 to be released then will upgrade the module to support Graal

@kortatu
Copy link
Author

kortatu commented Apr 2, 2019

That's great news! Thanks.

@florianrusch
Copy link

@graemerocher @kortatu what is the status of this issue? 1.1 is out for a while.

@graemerocher
Copy link
Contributor

Will look at this soon, shouldn't be too much work

@graemerocher
Copy link
Contributor

@ilopmar if you get to it before me let me now!

@florianrusch
Copy link

I'm getting some other error messages if I implement a simple Producer. Are this errors related to this issue?

Errors with -H:+ReportExceptionStackTraces:

Error: Unsupported features in 5 methods
Detailed message:
Error: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: Invoke with MethodHandle argument could not be reduced to at most a single call: java.lang.invoke.MethodHandle.bindTo(Object)
Trace: 
        at parsing java.lang.invoke.MethodHandleImpl.makePairwiseConvertByEditor(MethodHandleImpl.java:221)
Call path from entry point to java.lang.invoke.MethodHandleImpl.makePairwiseConvertByEditor(MethodHandle, MethodType, boolean, boolean): 
        at java.lang.invoke.MethodHandleImpl.makePairwiseConvertByEditor(MethodHandleImpl.java:207)
        at java.lang.invoke.MethodHandleImpl.makePairwiseConvert(MethodHandleImpl.java:194)
        at java.lang.invoke.MethodHandleImpl.makePairwiseConvert(MethodHandleImpl.java:380)
        at java.lang.invoke.MethodHandle.asTypeUncached(MethodHandle.java:776)
        at com.oracle.svm.reflect.MethodHandle_asTypeUncached_1e3763c86532486482d2521c9cebb3ff80653c74_603.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at io.micronaut.core.reflect.ReflectionUtils.invokeMethod(ReflectionUtils.java:204)
        at io.micronaut.core.beans.ReflectionBeanMap.get(ReflectionBeanMap.java:89)
        at io.micronaut.core.beans.ReflectionBeanMap$1.getValue(ReflectionBeanMap.java:148)
        at sun.security.ssl.SSLSocketImpl$NotifyHandshakeThread.run(SSLSocketImpl.java:2687)
        at com.oracle.svm.core.thread.JavaThreads.threadStartRoutine(JavaThreads.java:473)
        at com.oracle.svm.core.posix.thread.PosixJavaThreads.pthreadStartRoutine(PosixJavaThreads.java:193)
        at com.oracle.svm.core.code.IsolateEnterStub.PosixJavaThreads_pthreadStartRoutine_e1f4a8c0039f8337338252cd8734f63a79b5e3df(generated:0)
Error: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: Invoke with MethodHandle argument could not be reduced to at most a single call: java.lang.invoke.MethodHandleImpl$BindCaller.prepareForInvoker(MethodHandle)
Trace: 
        at parsing java.lang.invoke.MethodHandleImpl$BindCaller.makeInjectedInvoker(MethodHandleImpl.java:1166)
Call path from entry point to java.lang.invoke.MethodHandleImpl$BindCaller.makeInjectedInvoker(Class): 
        at java.lang.invoke.MethodHandleImpl$BindCaller.makeInjectedInvoker(MethodHandleImpl.java:1141)
        at java.lang.invoke.MethodHandleImpl$BindCaller.access$300(MethodHandleImpl.java:1122)
        at java.lang.invoke.MethodHandleImpl$BindCaller$1.computeValue(MethodHandleImpl.java:1175)
        at java.lang.invoke.MethodHandleImpl$BindCaller$1.computeValue(MethodHandleImpl.java:1173)
        at com.oracle.svm.core.jdk.Target_java_lang_ClassValue.get(JavaLangSubstitutions.java:512)
        at java.lang.invoke.MethodHandleImpl.makeArrayElementAccessor(MethodHandleImpl.java:76)
        at java.lang.invoke.MethodHandles.arrayElementGetter(MethodHandles.java:1825)
        at java.lang.invoke.LambdaFormEditor.spreadArgumentsForm(LambdaFormEditor.java:550)
        at java.lang.invoke.MethodHandle.asSpreader(MethodHandle.java:874)
        at com.oracle.svm.reflect.MethodHandle_asSpreader_d00ebec259ac90368129e731a032167345ea43f4_578.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at io.micronaut.core.reflect.ReflectionUtils.invokeMethod(ReflectionUtils.java:204)
        at io.micronaut.core.beans.ReflectionBeanMap.get(ReflectionBeanMap.java:89)
        at io.micronaut.core.beans.ReflectionBeanMap$1.getValue(ReflectionBeanMap.java:148)
        at sun.security.ssl.SSLSocketImpl$NotifyHandshakeThread.run(SSLSocketImpl.java:2687)
        at com.oracle.svm.core.thread.JavaThreads.threadStartRoutine(JavaThreads.java:473)
        at com.oracle.svm.core.posix.thread.PosixJavaThreads.pthreadStartRoutine(PosixJavaThreads.java:193)
        at com.oracle.svm.core.code.IsolateEnterStub.PosixJavaThreads_pthreadStartRoutine_e1f4a8c0039f8337338252cd8734f63a79b5e3df(generated:0)
Error: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: Invoke with MethodHandle argument could not be reduced to at most a single call: java.lang.invoke.MethodHandleImpl.buildVarargsArray(MethodHandle, MethodHandle, int)
Trace: 
        at parsing java.lang.invoke.MethodHandleImpl.varargsArray(MethodHandleImpl.java:1634)
Call path from entry point to java.lang.invoke.MethodHandleImpl.varargsArray(Class, int): 
        at java.lang.invoke.MethodHandleImpl.varargsArray(MethodHandleImpl.java:1611)
        at java.lang.invoke.MethodHandleImpl$IntrinsicMethodHandle.asCollector(MethodHandleImpl.java:1363)
        at com.oracle.svm.reflect.MethodHandle_asCollector_677f8860e9fa1556286f21d506365f7c078ddb56_577.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at io.micronaut.core.reflect.ReflectionUtils.invokeMethod(ReflectionUtils.java:204)
        at io.micronaut.core.beans.ReflectionBeanMap.get(ReflectionBeanMap.java:89)
        at io.micronaut.core.beans.ReflectionBeanMap$1.getValue(ReflectionBeanMap.java:148)
        at sun.security.ssl.SSLSocketImpl$NotifyHandshakeThread.run(SSLSocketImpl.java:2687)
        at com.oracle.svm.core.thread.JavaThreads.threadStartRoutine(JavaThreads.java:473)
        at com.oracle.svm.core.posix.thread.PosixJavaThreads.pthreadStartRoutine(PosixJavaThreads.java:193)
        at com.oracle.svm.core.code.IsolateEnterStub.PosixJavaThreads_pthreadStartRoutine_e1f4a8c0039f8337338252cd8734f63a79b5e3df(generated:0)
Error: type is not available in this platform: org.graalvm.nativeimage.hosted.Feature$BeforeAnalysisAccess
Trace:  object java.lang.Class[]
        object java.lang.invoke.MethodType
        object java.lang.invoke.MethodType$ConcurrentWeakInternSet$WeakEntry
        object java.util.concurrent.ConcurrentHashMap$Node
        object java.util.concurrent.ConcurrentHashMap$Node[]
        object java.util.concurrent.ConcurrentHashMap
        object java.lang.invoke.MethodType$ConcurrentWeakInternSet
        method java.lang.invoke.MethodType.makeImpl(Class, Class[], boolean)
Call path from entry point to java.lang.invoke.MethodType.makeImpl(Class, Class[], boolean): 
        at java.lang.invoke.MethodType.makeImpl(MethodType.java:301)
        at java.lang.invoke.MethodType.changeParameterType(MethodType.java:374)
        at java.lang.invoke.MethodHandleImpl.makeVarargsCollector(MethodHandleImpl.java:443)
        at java.lang.invoke.MethodHandle.asVarargsCollector(MethodHandle.java:1178)
        at com.oracle.svm.reflect.MethodHandle_asVarargsCollector_7e614d7bc3b70762d30c45c616fbe4a3e288ca1e_576.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at io.micronaut.core.reflect.ReflectionUtils.invokeMethod(ReflectionUtils.java:204)
        at io.micronaut.core.beans.ReflectionBeanMap.get(ReflectionBeanMap.java:89)
        at io.micronaut.core.beans.ReflectionBeanMap$1.getValue(ReflectionBeanMap.java:148)
        at sun.security.ssl.SSLSocketImpl$NotifyHandshakeThread.run(SSLSocketImpl.java:2687)
        at com.oracle.svm.core.thread.JavaThreads.threadStartRoutine(JavaThreads.java:473)
        at com.oracle.svm.core.posix.thread.PosixJavaThreads.pthreadStartRoutine(PosixJavaThreads.java:193)
        at com.oracle.svm.core.code.IsolateEnterStub.PosixJavaThreads_pthreadStartRoutine_e1f4a8c0039f8337338252cd8734f63a79b5e3df(generated:0)
Error: type is not available in this platform: org.graalvm.nativeimage.impl.ImageSingletonsSupport

com.oracle.svm.core.util.UserError$UserException: Unsupported features in 5 methods
Detailed message:
Error: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: Invoke with MethodHandle argument could not be reduced to at most a single call: java.lang.invoke.MethodHandle.bindTo(Object)
Trace: 
        at parsing java.lang.invoke.MethodHandleImpl.makePairwiseConvertByEditor(MethodHandleImpl.java:221)
Call path from entry point to java.lang.invoke.MethodHandleImpl.makePairwiseConvertByEditor(MethodHandle, MethodType, boolean, boolean): 
        at java.lang.invoke.MethodHandleImpl.makePairwiseConvertByEditor(MethodHandleImpl.java:207)
        at java.lang.invoke.MethodHandleImpl.makePairwiseConvert(MethodHandleImpl.java:194)
        at java.lang.invoke.MethodHandleImpl.makePairwiseConvert(MethodHandleImpl.java:380)
        at java.lang.invoke.MethodHandle.asTypeUncached(MethodHandle.java:776)
        at com.oracle.svm.reflect.MethodHandle_asTypeUncached_1e3763c86532486482d2521c9cebb3ff80653c74_603.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at io.micronaut.core.reflect.ReflectionUtils.invokeMethod(ReflectionUtils.java:204)
        at io.micronaut.core.beans.ReflectionBeanMap.get(ReflectionBeanMap.java:89)
        at io.micronaut.core.beans.ReflectionBeanMap$1.getValue(ReflectionBeanMap.java:148)
        at sun.security.ssl.SSLSocketImpl$NotifyHandshakeThread.run(SSLSocketImpl.java:2687)
        at com.oracle.svm.core.thread.JavaThreads.threadStartRoutine(JavaThreads.java:473)
        at com.oracle.svm.core.posix.thread.PosixJavaThreads.pthreadStartRoutine(PosixJavaThreads.java:193)
        at com.oracle.svm.core.code.IsolateEnterStub.PosixJavaThreads_pthreadStartRoutine_e1f4a8c0039f8337338252cd8734f63a79b5e3df(generated:0)
Error: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: Invoke with MethodHandle argument could not be reduced to at most a single call: java.lang.invoke.MethodHandleImpl$BindCaller.prepareForInvoker(MethodHandle)
Trace: 
        at parsing java.lang.invoke.MethodHandleImpl$BindCaller.makeInjectedInvoker(MethodHandleImpl.java:1166)
Call path from entry point to java.lang.invoke.MethodHandleImpl$BindCaller.makeInjectedInvoker(Class): 
        at java.lang.invoke.MethodHandleImpl$BindCaller.makeInjectedInvoker(MethodHandleImpl.java:1141)
        at java.lang.invoke.MethodHandleImpl$BindCaller.access$300(MethodHandleImpl.java:1122)
        at java.lang.invoke.MethodHandleImpl$BindCaller$1.computeValue(MethodHandleImpl.java:1175)
        at java.lang.invoke.MethodHandleImpl$BindCaller$1.computeValue(MethodHandleImpl.java:1173)
        at com.oracle.svm.core.jdk.Target_java_lang_ClassValue.get(JavaLangSubstitutions.java:512)
        at java.lang.invoke.MethodHandleImpl.makeArrayElementAccessor(MethodHandleImpl.java:76)
        at java.lang.invoke.MethodHandles.arrayElementGetter(MethodHandles.java:1825)
        at java.lang.invoke.LambdaFormEditor.spreadArgumentsForm(LambdaFormEditor.java:550)
        at java.lang.invoke.MethodHandle.asSpreader(MethodHandle.java:874)
        at com.oracle.svm.reflect.MethodHandle_asSpreader_d00ebec259ac90368129e731a032167345ea43f4_578.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at io.micronaut.core.reflect.ReflectionUtils.invokeMethod(ReflectionUtils.java:204)
        at io.micronaut.core.beans.ReflectionBeanMap.get(ReflectionBeanMap.java:89)
        at io.micronaut.core.beans.ReflectionBeanMap$1.getValue(ReflectionBeanMap.java:148)
        at sun.security.ssl.SSLSocketImpl$NotifyHandshakeThread.run(SSLSocketImpl.java:2687)
        at com.oracle.svm.core.thread.JavaThreads.threadStartRoutine(JavaThreads.java:473)
        at com.oracle.svm.core.posix.thread.PosixJavaThreads.pthreadStartRoutine(PosixJavaThreads.java:193)
        at com.oracle.svm.core.code.IsolateEnterStub.PosixJavaThreads_pthreadStartRoutine_e1f4a8c0039f8337338252cd8734f63a79b5e3df(generated:0)
Error: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: Invoke with MethodHandle argument could not be reduced to at most a single call: java.lang.invoke.MethodHandleImpl.buildVarargsArray(MethodHandle, MethodHandle, int)
Trace: 
        at parsing java.lang.invoke.MethodHandleImpl.varargsArray(MethodHandleImpl.java:1634)
Call path from entry point to java.lang.invoke.MethodHandleImpl.varargsArray(Class, int): 
        at java.lang.invoke.MethodHandleImpl.varargsArray(MethodHandleImpl.java:1611)
        at java.lang.invoke.MethodHandleImpl$IntrinsicMethodHandle.asCollector(MethodHandleImpl.java:1363)
        at com.oracle.svm.reflect.MethodHandle_asCollector_677f8860e9fa1556286f21d506365f7c078ddb56_577.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at io.micronaut.core.reflect.ReflectionUtils.invokeMethod(ReflectionUtils.java:204)
        at io.micronaut.core.beans.ReflectionBeanMap.get(ReflectionBeanMap.java:89)
        at io.micronaut.core.beans.ReflectionBeanMap$1.getValue(ReflectionBeanMap.java:148)
        at sun.security.ssl.SSLSocketImpl$NotifyHandshakeThread.run(SSLSocketImpl.java:2687)
        at com.oracle.svm.core.thread.JavaThreads.threadStartRoutine(JavaThreads.java:473)
        at com.oracle.svm.core.posix.thread.PosixJavaThreads.pthreadStartRoutine(PosixJavaThreads.java:193)
        at com.oracle.svm.core.code.IsolateEnterStub.PosixJavaThreads_pthreadStartRoutine_e1f4a8c0039f8337338252cd8734f63a79b5e3df(generated:0)
Error: type is not available in this platform: org.graalvm.nativeimage.hosted.Feature$BeforeAnalysisAccess
Trace:  object java.lang.Class[]
        object java.lang.invoke.MethodType
        object java.lang.invoke.MethodType$ConcurrentWeakInternSet$WeakEntry
        object java.util.concurrent.ConcurrentHashMap$Node
        object java.util.concurrent.ConcurrentHashMap$Node[]
        object java.util.concurrent.ConcurrentHashMap
        object java.lang.invoke.MethodType$ConcurrentWeakInternSet
        method java.lang.invoke.MethodType.makeImpl(Class, Class[], boolean)
Call path from entry point to java.lang.invoke.MethodType.makeImpl(Class, Class[], boolean): 
        at java.lang.invoke.MethodType.makeImpl(MethodType.java:301)
        at java.lang.invoke.MethodType.changeParameterType(MethodType.java:374)
        at java.lang.invoke.MethodHandleImpl.makeVarargsCollector(MethodHandleImpl.java:443)
        at java.lang.invoke.MethodHandle.asVarargsCollector(MethodHandle.java:1178)
        at com.oracle.svm.reflect.MethodHandle_asVarargsCollector_7e614d7bc3b70762d30c45c616fbe4a3e288ca1e_576.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at io.micronaut.core.reflect.ReflectionUtils.invokeMethod(ReflectionUtils.java:204)
        at io.micronaut.core.beans.ReflectionBeanMap.get(ReflectionBeanMap.java:89)
        at io.micronaut.core.beans.ReflectionBeanMap$1.getValue(ReflectionBeanMap.java:148)
        at sun.security.ssl.SSLSocketImpl$NotifyHandshakeThread.run(SSLSocketImpl.java:2687)
        at com.oracle.svm.core.thread.JavaThreads.threadStartRoutine(JavaThreads.java:473)
        at com.oracle.svm.core.posix.thread.PosixJavaThreads.pthreadStartRoutine(PosixJavaThreads.java:193)
        at com.oracle.svm.core.code.IsolateEnterStub.PosixJavaThreads_pthreadStartRoutine_e1f4a8c0039f8337338252cd8734f63a79b5e3df(generated:0)
Error: type is not available in this platform: org.graalvm.nativeimage.impl.ImageSingletonsSupport

        at com.oracle.svm.core.util.UserError.abort(UserError.java:75)
        at com.oracle.svm.hosted.FallbackFeature.reportAsFallback(FallbackFeature.java:218)
        at com.oracle.svm.hosted.NativeImageGenerator.runPointsToAnalysis(NativeImageGenerator.java:733)
        at com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:523)
        at com.oracle.svm.hosted.NativeImageGenerator.lambda$run$0(NativeImageGenerator.java:441)
        at java.util.concurrent.ForkJoinTask$AdaptedRunnableAction.exec(ForkJoinTask.java:1386)
        at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
        at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
        at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
        at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
Caused by: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: Unsupported features in 5 methods
Detailed message:
Error: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: Invoke with MethodHandle argument could not be reduced to at most a single call: java.lang.invoke.MethodHandle.bindTo(Object)
Trace: 
        at parsing java.lang.invoke.MethodHandleImpl.makePairwiseConvertByEditor(MethodHandleImpl.java:221)
Call path from entry point to java.lang.invoke.MethodHandleImpl.makePairwiseConvertByEditor(MethodHandle, MethodType, boolean, boolean): 
        at java.lang.invoke.MethodHandleImpl.makePairwiseConvertByEditor(MethodHandleImpl.java:207)
        at java.lang.invoke.MethodHandleImpl.makePairwiseConvert(MethodHandleImpl.java:194)
        at java.lang.invoke.MethodHandleImpl.makePairwiseConvert(MethodHandleImpl.java:380)
        at java.lang.invoke.MethodHandle.asTypeUncached(MethodHandle.java:776)
        at com.oracle.svm.reflect.MethodHandle_asTypeUncached_1e3763c86532486482d2521c9cebb3ff80653c74_603.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at io.micronaut.core.reflect.ReflectionUtils.invokeMethod(ReflectionUtils.java:204)
        at io.micronaut.core.beans.ReflectionBeanMap.get(ReflectionBeanMap.java:89)
        at io.micronaut.core.beans.ReflectionBeanMap$1.getValue(ReflectionBeanMap.java:148)
        at sun.security.ssl.SSLSocketImpl$NotifyHandshakeThread.run(SSLSocketImpl.java:2687)
        at com.oracle.svm.core.thread.JavaThreads.threadStartRoutine(JavaThreads.java:473)
        at com.oracle.svm.core.posix.thread.PosixJavaThreads.pthreadStartRoutine(PosixJavaThreads.java:193)
        at com.oracle.svm.core.code.IsolateEnterStub.PosixJavaThreads_pthreadStartRoutine_e1f4a8c0039f8337338252cd8734f63a79b5e3df(generated:0)
Error: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: Invoke with MethodHandle argument could not be reduced to at most a single call: java.lang.invoke.MethodHandleImpl$BindCaller.prepareForInvoker(MethodHandle)
Trace: 
        at parsing java.lang.invoke.MethodHandleImpl$BindCaller.makeInjectedInvoker(MethodHandleImpl.java:1166)
Call path from entry point to java.lang.invoke.MethodHandleImpl$BindCaller.makeInjectedInvoker(Class): 
        at java.lang.invoke.MethodHandleImpl$BindCaller.makeInjectedInvoker(MethodHandleImpl.java:1141)
        at java.lang.invoke.MethodHandleImpl$BindCaller.access$300(MethodHandleImpl.java:1122)
        at java.lang.invoke.MethodHandleImpl$BindCaller$1.computeValue(MethodHandleImpl.java:1175)
        at java.lang.invoke.MethodHandleImpl$BindCaller$1.computeValue(MethodHandleImpl.java:1173)
        at com.oracle.svm.core.jdk.Target_java_lang_ClassValue.get(JavaLangSubstitutions.java:512)
        at java.lang.invoke.MethodHandleImpl.makeArrayElementAccessor(MethodHandleImpl.java:76)
        at java.lang.invoke.MethodHandles.arrayElementGetter(MethodHandles.java:1825)
        at java.lang.invoke.LambdaFormEditor.spreadArgumentsForm(LambdaFormEditor.java:550)
        at java.lang.invoke.MethodHandle.asSpreader(MethodHandle.java:874)
        at com.oracle.svm.reflect.MethodHandle_asSpreader_d00ebec259ac90368129e731a032167345ea43f4_578.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at io.micronaut.core.reflect.ReflectionUtils.invokeMethod(ReflectionUtils.java:204)
        at io.micronaut.core.beans.ReflectionBeanMap.get(ReflectionBeanMap.java:89)
        at io.micronaut.core.beans.ReflectionBeanMap$1.getValue(ReflectionBeanMap.java:148)
        at sun.security.ssl.SSLSocketImpl$NotifyHandshakeThread.run(SSLSocketImpl.java:2687)
        at com.oracle.svm.core.thread.JavaThreads.threadStartRoutine(JavaThreads.java:473)
        at com.oracle.svm.core.posix.thread.PosixJavaThreads.pthreadStartRoutine(PosixJavaThreads.java:193)
        at com.oracle.svm.core.code.IsolateEnterStub.PosixJavaThreads_pthreadStartRoutine_e1f4a8c0039f8337338252cd8734f63a79b5e3df(generated:0)
Error: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: Invoke with MethodHandle argument could not be reduced to at most a single call: java.lang.invoke.MethodHandleImpl.buildVarargsArray(MethodHandle, MethodHandle, int)
Trace: 
        at parsing java.lang.invoke.MethodHandleImpl.varargsArray(MethodHandleImpl.java:1634)
Call path from entry point to java.lang.invoke.MethodHandleImpl.varargsArray(Class, int): 
        at java.lang.invoke.MethodHandleImpl.varargsArray(MethodHandleImpl.java:1611)
        at java.lang.invoke.MethodHandleImpl$IntrinsicMethodHandle.asCollector(MethodHandleImpl.java:1363)
        at com.oracle.svm.reflect.MethodHandle_asCollector_677f8860e9fa1556286f21d506365f7c078ddb56_577.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at io.micronaut.core.reflect.ReflectionUtils.invokeMethod(ReflectionUtils.java:204)
        at io.micronaut.core.beans.ReflectionBeanMap.get(ReflectionBeanMap.java:89)
        at io.micronaut.core.beans.ReflectionBeanMap$1.getValue(ReflectionBeanMap.java:148)
        at sun.security.ssl.SSLSocketImpl$NotifyHandshakeThread.run(SSLSocketImpl.java:2687)
        at com.oracle.svm.core.thread.JavaThreads.threadStartRoutine(JavaThreads.java:473)
        at com.oracle.svm.core.posix.thread.PosixJavaThreads.pthreadStartRoutine(PosixJavaThreads.java:193)
        at com.oracle.svm.core.code.IsolateEnterStub.PosixJavaThreads_pthreadStartRoutine_e1f4a8c0039f8337338252cd8734f63a79b5e3df(generated:0)
Error: type is not available in this platform: org.graalvm.nativeimage.hosted.Feature$BeforeAnalysisAccess
Trace:  object java.lang.Class[]
        object java.lang.invoke.MethodType
        object java.lang.invoke.MethodType$ConcurrentWeakInternSet$WeakEntry
        object java.util.concurrent.ConcurrentHashMap$Node
        object java.util.concurrent.ConcurrentHashMap$Node[]
        object java.util.concurrent.ConcurrentHashMap
        object java.lang.invoke.MethodType$ConcurrentWeakInternSet
        method java.lang.invoke.MethodType.makeImpl(Class, Class[], boolean)
Call path from entry point to java.lang.invoke.MethodType.makeImpl(Class, Class[], boolean): 
        at java.lang.invoke.MethodType.makeImpl(MethodType.java:301)
        at java.lang.invoke.MethodType.changeParameterType(MethodType.java:374)
        at java.lang.invoke.MethodHandleImpl.makeVarargsCollector(MethodHandleImpl.java:443)
        at java.lang.invoke.MethodHandle.asVarargsCollector(MethodHandle.java:1178)
        at com.oracle.svm.reflect.MethodHandle_asVarargsCollector_7e614d7bc3b70762d30c45c616fbe4a3e288ca1e_576.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at io.micronaut.core.reflect.ReflectionUtils.invokeMethod(ReflectionUtils.java:204)
        at io.micronaut.core.beans.ReflectionBeanMap.get(ReflectionBeanMap.java:89)
        at io.micronaut.core.beans.ReflectionBeanMap$1.getValue(ReflectionBeanMap.java:148)
        at sun.security.ssl.SSLSocketImpl$NotifyHandshakeThread.run(SSLSocketImpl.java:2687)
        at com.oracle.svm.core.thread.JavaThreads.threadStartRoutine(JavaThreads.java:473)
        at com.oracle.svm.core.posix.thread.PosixJavaThreads.pthreadStartRoutine(PosixJavaThreads.java:193)
        at com.oracle.svm.core.code.IsolateEnterStub.PosixJavaThreads_pthreadStartRoutine_e1f4a8c0039f8337338252cd8734f63a79b5e3df(generated:0)
Error: type is not available in this platform: org.graalvm.nativeimage.impl.ImageSingletonsSupport

        at com.oracle.graal.pointsto.constraints.UnsupportedFeatures.report(UnsupportedFeatures.java:133)
        at com.oracle.graal.pointsto.BigBang.finish(BigBang.java:564)
        at com.oracle.svm.hosted.NativeImageGenerator.runPointsToAnalysis(NativeImageGenerator.java:684)
        ... 7 more
Error: Image build request failed with exit status 1

My Producer:

import io.micronaut.configuration.kafka.annotation.KafkaClient;
import io.micronaut.configuration.kafka.annotation.Topic;

import java.util.concurrent.Future;

@KafkaClient
public interface PriceProducer {
    @Topic("plain-prices")
    Future<Integer> sendPrice(Integer price);
}

My Controller:

import io.micronaut.configuration.kafka.annotation.KafkaClient;
import io.micronaut.http.annotation.Controller;
import io.micronaut.http.annotation.Post;
import java.util.concurrent.Future;

@Controller("/price")
public class PriceController {
    private final PriceProducer priceProducerClient;

    public PriceController(
            @KafkaClient PriceProducer priceProducerClient) {
        this.priceProducerClient = priceProducerClient;
    }

    @Post
    public Future<Integer> add(Integer price) {
        return priceProducerClient.sendPrice(price);
    }
}

I've also tried to set a reflection configuration, but without any result:

[
  {
    "name" : "java.lang.invoke.MethodHandle",
    "allDeclaredConstructors" : true,
    "allPublicConstructors" : true,
    "allDeclaredMethods" : true,
    "allPublicMethods" : true,
    "allDeclaredClasses" : true,
    "allPublicClasses" : true
  },
  {
    "name" : "java.lang.Class",
    "allDeclaredConstructors" : true,
    "allPublicConstructors" : true,
    "allDeclaredMethods" : true,
    "allPublicMethods" : true,
    "allDeclaredClasses" : true,
    "allPublicClasses" : true
  }
]

@graemerocher
Copy link
Contributor

I have pushed the changes to include the Graal substrate metadata. However with Graal 19 it currently fails with:

Error: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: Invoke with MethodHandle argument could not be reduced to at most a single call: java.lang.invoke.LambdaForm$MH.87134021.invoke_MT(Object, Object, Object)
Trace: 
	at parsing org.apache.kafka.common.record.CompressionType$5.wrapForOutput(CompressionType.java:122)
Call path from entry point to org.apache.kafka.common.record.CompressionType$5.wrapForOutput(ByteBufferOutputStream, byte): 
	at org.apache.kafka.common.record.CompressionType$5.wrapForOutput(CompressionType.java:122)
	at org.apache.kafka.common.record.MemoryRecordsBuilder.<init>(MemoryRecordsBuilder.java:130)
	at org.apache.kafka.common.record.MemoryRecordsBuilder.<init>(MemoryRecordsBuilder.java:166)
	at org.apache.kafka.common.record.MemoryRecords.builder(MemoryRecords.java:534)
	at org.apache.kafka.common.record.MemoryRecords.builder(MemoryRecords.java:516)
	at org.apache.kafka.common.record.MemoryRecords.builder(MemoryRecords.java:451)
	at org.apache.kafka.common.record.RecordsUtil.convertRecordBatch(RecordsUtil.java:110)
	at org.apache.kafka.common.record.RecordsUtil.downConvert(RecordsUtil.java:88)

I have raised oracle/graal#1342 to track this issue

@graemerocher
Copy link
Contributor

So with the master branch of micronaut core and this above commit Kafka + Micronaut now works with GraalVM native-image in 19.1

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

No branches or pull requests

4 participants