-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Micronaut support for SubstrateVM and native image #470
Comments
@graemerocher loading resources is currently available through the We are also currently working on a solution to provide a custom class loader at runtime that can be used to load any class that has been observed during image building. This class loader will be available through |
Regarding the |
@cstancu Thanks for the reply. Is there a way to use wildcards to include resources, such as Specifying every resource by name is not really practical as many are generated at compile time. |
Yes, wildcards should work, the option takes a regexp as an argument. It also works for resources in both directories and jars on the classpath. We don't have documentation for this yet, but the implementation is straightforward. |
@cstancu I have progressed past the resources issue. Our next problem is with regards to ServiceLoader<BeanDefinitionReference> services = ServiceLoader.load(BeanDefinitionReference.class);
System.out.println("services.iterator().hasNext() = " + services.iterator().hasNext());
for (BeanDefinitionReference beanDefinitionReference : services) {
System.out.println("beanDefinitionReference = " + beanDefinitionReference);
} The above results in:
I assume this related to limitations with regards to dynamic class loading, although in this case the classes are on the classpath when the image is created. Is this a limitation that can be overcome? |
Yes, this is related to the dynamic class loading limitation. Currently |
Gotcha. Thanks |
@cstancu do you have a timeline for when the feature you describe will be available? |
We will try to make it available in the next release, which as of now is planned for June 29th. |
Thanks for the update |
As of ef56566 we have support for dynamic class loading thanks to @vjovanov. That is |
By the way, now that you have access to a |
I also created a simple demo project for loading services with |
@cstancu Great thanks! Will try it out shortly |
Are there instructions somewhere to build from source on Mac OS X? |
@graemerocher AFAIK building from sources on Mac OS X shouldn't be any different than building on Linux. Please see the quick start guide for quick building for development purposes. You can also build a distribution of GraalVM by following the info in the VM suite. If you just care about
This will take a while as it builds several components. After that you will find a VM distribution in |
@cstancu Currently when I try this with the latest source it fails with:
I am using |
You need to use a labsjdk. You can get one from http://www.oracle.com/technetwork/oracle-labs/program-languages/downloads/index.html the JVMCI JDK Downloads section. We currently don't support self bootstrapping GraalVM |
That was it. Got it compiling. Thanks for the help |
I have gotten a little further with getting Micronaut running for the project https://github.com/micronaut-projects/micronaut-examples/tree/master/hello-world-kotlin After doing
I am hitting this error when running the application:
The class I assume it is because I need to configure the class for reflective access as per https://github.com/oracle/graal/blob/master/substratevm/REFLECTION.md We don't actually need to do any reflection on the class however, just instantiate it. What would a appropriate |
ok so doing:
Seems to get me further. I will have to figure out a way to make all It seems like it would be nice if there was an option in Graal to do this automatically? Since the classes are already declared in |
Yes, currently all classes used to allocate objects via |
Understood, I think I can probably write a build to that generates the |
Ok so I wrote a Gradle build task that generates the The steps I am taking with to build the image are here: It is now failing with
Is there a way we can get a better error to find out the class causing that exception? |
When you build from source for development (i.e., running Edit: You can deploy it locally running |
After deploying
It looks like the micronaut code makes some part of netty reachable that we haven't tried before. We don't have a general solution for this type of errors yet and the workaround in the error message, to " Write your own initialization methods and call them explicitly from your main entry point", cannot be easily applied to third party libraries. We are investigating the possibility to push some static initializers to runtime to avoid issues like this, but that feature is only at the drawing board stage. |
Is there a way to identify what part of Netty is starting threads in the static initialiser? We can then potentially report an issue to the Netty project to make it configurable somehow |
Hey @graemerocher, it has already been fixed in Netty snapshots, see https://twitter.com/normanmaurer/status/1014461371168247808. |
@sdeleuze Thanks for the pointer, will try out the snapshots |
I have made some more progress on getting Micronaut operational on Graal
Which leads to:
It seems there is no way in |
FWIW I tried to add |
You should use the |
The changes in 3c85875 might also interest you. It improves |
Ok, I will take a look, in the meantime what would really help is a fix for the |
@cstancu I tried to make some changes to get passed the array issue. However now the native imagine I built is exiting with:
How do I debug this issue? The application is at https://github.com/graemerocher/micronaut-graal-experiments |
Any thoughts on how to debug the Segmentation fault issue? |
I tried building your app but I hit the |
If you use GraalVM EE then you can pass the |
@cstancu I pushed the latest changes, btw something broke in rc5 because I get
When using rc5. With rc4 I get the segmentation fault still. |
The reason for the
|
@cstancu I have made significant progress with Micronaut on Graal First the good news is that Micronaut now starts up and takes 40ms to do so consuming 30mb of total memory. The application at https://github.com/graemerocher/micronaut-graal-experiments/tree/master/hello-world-java demonstrates this. To make it work I wrote a class loading reporter that generates the So effectively you run The bad news is that things are still not working 100% and request processing fails with the following exception:
Which refers to this line of code https://github.com/micronaut-projects/micronaut-core/blob/30826975035f0dcfbc4fd3fb615b3cb25adc374d/http-server-netty/src/main/java/io/micronaut/http/server/netty/RoutingInBoundHandler.java#L354 I don't really understand why that line is causing the issue since it is simply calling the You can reproduce the error by building the native image, running |
One other thing is that I still get intermittent segmentation faults which I don't know how to resolve. They seem to be related to logback. If you change the log level in Then I consistently get a |
Adding a recompute for Caffeine seems to have alleviated the Now I am just stuck on the If there are any thoughts on how I can alter the code to get past the error, or whether I should file a separate issue report please let me know. |
@graemerocher good to hear that you got past the segmentation fault. I will take a look at the |
@cstancu Thanks for looking into it. I tried changing the code from |
Micronaut now works on Graal native image with RC6. See https://github.com/graemerocher/micronaut-graal-experiments/tree/master/hello-world-java for a working example Thanks for all the great feedback |
That's great news. It looks like |
I have been investigating support for SubstrateVM and the nativeimage tool for Micronaut http://micronaut.io/
Micronaut produces largely reflection free DI and AOP, however does allow soft loading of classes.
Currently only one error occurs when preparing the image, which is probably a matter of supplying a correct reflection.json:
More fundamentally however, we rely on
ServiceLoader.load(..)
andclassLoader.getResources()
in a few places and these seem to be unimplemented? Calls to getClass().getClassLoader() return nullIs there an alternative way to load resources other than through the classloader? Can we provide an alternative to
ServiceLoader.load(..)
?We could certainly abstract the strategies for loading resources and service descriptors if there was an alternative way to get at these and a way to detect you are running on SubstrateVM (is there a way?)
The text was updated successfully, but these errors were encountered: