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

Initial work on native user API #5610

Closed

Conversation

stuartwdouglas
Copy link
Member

First part of #5601

@stuartwdouglas stuartwdouglas requested a review from gsmet November 20, 2019 02:55
@mkouba
Copy link
Contributor

mkouba commented Nov 20, 2019

Do you plan on adding a test for @RegisterResourceBundle? Otherwise looks very good!

Copy link
Member

@gsmet gsmet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely a very nice user experience improvement.

I added a few comments. Only the typo is a must fix, the rest is really to be discussed.

*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface RuntimeInitialized {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be a silly question and I'm not totally convinced myself but should we stick to the Register prefix?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know, I did think about it but I think it reads better this way. 'RegisterAsRuntimeInitialized' could be ok as well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I wonder if all of these should go in a 'native' package, although it would cause problems with the existing RegisterForReflection.

This guide covers some of the annotations that Quarkus supports to help generate native images. In some cases these
annotations are applied directly to a relevant class, but in others the class that they are placed on does not actually
matter (e.g. if you are referencing a class in a 3rd party jar). In this case we recommend creating an empty `NativeConfig`
class somewhere in your application and placing all annotation that control native image generation on it, so they are all
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
class somewhere in your application and placing all annotation that control native image generation on it, so they are all
class somewhere in your application and placing all annotations that control native image generation on it, so they are all

annotations are applied directly to a relevant class, but in others the class that they are placed on does not actually
matter (e.g. if you are referencing a class in a 3rd party jar). In this case we recommend creating an empty `NativeConfig`
class somewhere in your application and placing all annotation that control native image generation on it, so they are all
in the same place.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should have a table here summarizing the annotations so that the user has a global overview of what's possible.

}
----

In this example only the `ThirdPartyClass` and `ThirdPartyClass` other class are registered, `EmptyClass` is ignored.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find that a bit counter intuitive. To be fair the whole annotation approach feels counter intuitive. I wonder if we could allow the class enlistment via an API and annotated toe block of code to be called.

@QuarkusBuild
public void buildOperations(QuarkusBuildOperations ops) {
    ops.enlistClassForReflecton(ThirdPartyClass.clas);
    ops.otherOperations(...);
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Grouping those operations into a single interface looks like a nice idea.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually pretty common in Jakarta EE (annotations that are not directly applicable to the class they are placed on). Some examples:

CDI response producer fields:

@Produces
@EntityManager
EntityManager entityManger;

This enables EntityManager injection in you application, but it can be literally anywhere and the class it is on makes no difference. Same with things like @DataSourceDefinition.

I do agree that it is a bit weird but your solution does not solve the problem of code affecting the whole app that could be anywhere.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also we would need both, as for the cases where the class is in your application then an annotation is the easiest to understand.

@@ -20,6 +20,14 @@ Please refer to the appropriate section depending on your context.

GraalVM imposes a number of constraints and making your application a native executable might require a few tweaks.

=== Quarkus Annotations
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's mark new features as Preview in both docs and APIs/Annotations until we are happy we will support them for the while 1.x series.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once we have decided on the API I don't think there is any issue supporting these, they are just a new facade on functionality we already have.

@@ -278,9 +302,14 @@ method com.amazonaws.services.s3.model.CryptoConfiguration.<init>(CryptoMode)
Call path from entry point to com.amazonaws.services.s3.model.CryptoConfiguration.<init>(CryptoMode):
----

If you need to delay the initialization of a class, you can use the `--initialize-at-run-time=<package or class>` configuration knob.
If you need to delay the initialization of a class, you can use the `@io.quarkus.runtime.annotations.RuntimeInitialized` annotation
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here for API vs annotation.
Also we should explain why a user would want to do that.


It should be added to the `native-image` configuration using an `<additionalBuildArg>` as shown in the examples above.
Native mode also supports the notion of 'runtime reinitialization' where static init is run at image generation time, and
then re-run at startup. This can be done via the `@io.quarkus.runtime.annotations.RuntimeReinitialized` annotation in a
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explain why you would want to do that. It's dry otherwise.

[source,java]
----
@RegisterForReflection(targets={ThirdPartyClass.class, OtherClass.class})
public class EmptyClass {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it be NativeConfig then?

@emmanuelbernard
Copy link
Member

When I looked at the list of subjects, I think while there is value in this extension. It might actually be moot or less important if we really manage to improve #2277

@stuartwdouglas
Copy link
Member Author

@emmanuelbernard do we still want this? If not we should close the PR.

@emmanuelbernard
Copy link
Member

We want it in some form at some point. Whether I would spend our energy on in in the next 2/3 releases, I don't think so.

@gsmet gsmet added the triage/invalid This doesn't seem right label Jan 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants