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 AWT image resize via new AWT extension #20239

Merged
merged 1 commit into from
Sep 23, 2021

Conversation

galderz
Copy link
Member

@galderz galderz commented Sep 17, 2021

This PR replaces #20148.

It enables AWT use cases, such as image resizing, using a dedicated AWT extension.

Note: the extension was generated with the create-extension command of the quarkus maven plugin.

@quarkus-bot quarkus-bot bot added area/core area/dependencies Pull requests that update a dependency file labels Sep 17, 2021
@gastaldi
Copy link
Contributor

@galderz can you rebase with the latest main? There are some conflicts

@gastaldi
Copy link
Contributor

Also it would be great if you could also squash your commits

@gastaldi gastaldi linked an issue Sep 17, 2021 that may be closed by this pull request
@galderz
Copy link
Member Author

galderz commented Sep 17, 2021

Yeah yeah, on it already...

@galderz galderz force-pushed the t_awt_image_resize_v4 branch from 2b5d57d to 55fb9f8 Compare September 17, 2021 15:10
@galderz
Copy link
Member Author

galderz commented Sep 17, 2021

@gastaldi Done. Let's see what CI says

@quarkus-bot
Copy link

quarkus-bot bot commented Sep 17, 2021

This workflow status is outdated as a new workflow run has been triggered.

Failing Jobs - Building 55fb9f8

Status Name Step Failures Logs Raw logs
Initial JDK 11 Build Build Failures Logs Raw logs

Failures

⚙️ Initial JDK 11 Build #

- Failing: integration-tests/awt 

📦 integration-tests/awt

Failed to execute goal net.revelc.code.formatter:formatter-maven-plugin:2.16.0:validate (default) on project quarkus-awt-integration-tests: File '/home/runner/work/quarkus/quarkus/integration-tests/awt/src/test/java/io/quarkus/awt/it/AwtImageResizeTest.java' has not been previously formatted. Please format file and commit before running validation!

import com.oracle.svm.core.annotate.AutomaticFeature;

@AutomaticFeature
public class AwtFeature implements Feature {
Copy link
Member

Choose a reason for hiding this comment

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

👍

@galderz galderz force-pushed the t_awt_image_resize_v4 branch from 55fb9f8 to 5189327 Compare September 17, 2021 16:27
@galderz
Copy link
Member Author

galderz commented Sep 17, 2021

@gastaldi @geoand All comments addressed.

@Sanne
Copy link
Member

Sanne commented Sep 17, 2021

I have a general question.. how do you expect users to know they need to add this extension?

Should we consider it a "technical extension" and have other extensions such as those doing image manipulations depend on it?

Or perhaps it belongs in all applications, and we should pull it in automatically for all users?

I'm inclined to think it shoud be pulled in for every user automatically, provided there is no overhead. I'd normally expect this to not have any overhead, but you seem to have registered some classes for reflective access so that might force some code inclusion which would otherwise be identified as dead code. Why the reflective registrations?

@geoand
Copy link
Contributor

geoand commented Sep 17, 2021

The test also needs to be added to the native test configuration. I don't remember exactly where it is (and I'm on a phone right now), but @gastaldi can give you the exact location

@gastaldi
Copy link
Contributor

The test also needs to be added to the native test configuration. I don't remember exactly where it is (and I'm on a phone right now), but @gastaldi can give you the exact location

It's in https://github.com/quarkusio/quarkus/blob/main/.github/native-tests.json

@quarkus-bot
Copy link

quarkus-bot bot commented Sep 17, 2021

This workflow status is outdated as a new workflow run has been triggered.

Failing Jobs - Building 5189327

Status Name Step Failures Logs Raw logs
Initial JDK 11 Build Verify extension dependencies ⚠️ Check → Logs Raw logs

@galderz galderz force-pushed the t_awt_image_resize_v4 branch from 5189327 to 5f2db3b Compare September 20, 2021 05:33
@quarkus-bot quarkus-bot bot added area/devtools Issues/PR related to maven, gradle, platform and cli tooling/plugins area/documentation area/infra-automation anything related to CI, bots, etc. that are used to automated our infrastructure labels Sep 20, 2021
@galderz
Copy link
Member Author

galderz commented Sep 20, 2021

I have a general question.. how do you expect users to know they need to add this extension?

Should we consider it a "technical extension" and have other extensions such as those doing image manipulations depend on it?

Or perhaps it belongs in all applications, and we should pull it in automatically for all users?

Is there such big proportion of Quarkus apps doing image manipulations? Unless there is, I'd keep this as something that people bring in when they need it.

Or are you seeing this as something that should work out of the box?

I'm inclined to think it shoud be pulled in for every user automatically, provided there is no overhead. I'd normally expect this to not have any overhead, but you seem to have registered some classes for reflective access so that might force some code inclusion which would otherwise be identified as dead code. Why the reflective registrations?

The reflection registration for sun.awt.X11.XToolkit are for the Toolkit.getDefaultToolkit() code. IIRC sun.awt.X11GraphicsEnvironment is for the GraphicsEnvironment initialization.

I would expect the JNI registrations to have some cost too, and there are more of them compared to reflection registrations. My gut feeling is that you'll need even more JNI registrations for other AWT use cases.

@galderz
Copy link
Member Author

galderz commented Sep 20, 2021

Actually @Sanne, I think might have a point:

The hibernate-orm-panache native image build didn't complete, see extract maven logs:

"ForkJoinPool-2-worker-3" Id=20 in RUNNABLE
    at [email protected]/sun.java2d.loops.FillRect.<clinit>(FillRect.java:79)

What's happening is that as a result of removing Java2DSubstitutions, a load of JAXB graphics related code makes it to the universe, e.g.

│   │       │   │       │       │           │   │   │   │       │           │   │   │   │   │   │   │   │   │   │           │   ├── directly calls com.sun.xml.bind.v2.model.impl.RuntimeBuiltinLeafInfoImpl$10$1.<init>(com.sun.xml.bind.v2.model.impl.RuntimeBuiltinLeafInfoImpl$10):void id=103127 @bci=21 
│   │       │   │       │       │           │   │   │   │       │           │   │   │   │   │   │   │   │   │   │           │   │   └── directly calls java.awt.Component.<init>():void id=104120 @bci=6 

To solve the problem above, we'd need an extension that is applied to all that takes care of the runtime initialization of all those packages. This could also be done directly in core, by moving io.quarkus.awt.runtime.graal.AwtFeature to core.

You could still have an optional extension for those who really want to use awt with reflection+jni registrations (or any optimised versions of those).

Thoughts?

@galderz galderz force-pushed the t_awt_image_resize_v4 branch from 4eb55df to a638a0f Compare September 22, 2021 08:36
@galderz
Copy link
Member Author

galderz commented Sep 22, 2021

Pushed a couple of commits to fix the tests that also failed in previous PR. They've fixed in different way this time:

  • ImageIOTestCase has been moved to integration tests for awt.
  • Tika extension now depends on awt extension. It also adds a feature to mark which packages need to be runtime initialized.

The only thing remaining then would be documentation. Where would it go?

@quarkus-bot
Copy link

quarkus-bot bot commented Sep 22, 2021

This workflow status is outdated as a new workflow run has been triggered.

Failing Jobs - Building 1848da0

Status Name Step Failures Logs Raw logs
Initial JDK 11 Build Build Failures Logs Raw logs

Failures

⚙️ Initial JDK 11 Build #

- Failing: extensions/tika/runtime integration-tests/awt 
! Skipped: devtools/bom-descriptor-json docs extensions/tika/deployment and 3 more

📦 extensions/tika/runtime

Failed to execute goal net.revelc.code:impsort-maven-plugin:1.6.2:check (check-imports) on project quarkus-tika: Imports are not sorted in /home/runner/work/quarkus/quarkus/extensions/tika/runtime/src/main/java/io/quarkus/tika/runtime/graal/TikaFeature.java

📦 integration-tests/awt

Failed to execute goal net.revelc.code:impsort-maven-plugin:1.6.2:check (check-imports) on project quarkus-awt-integration-tests: Imports are not sorted in /home/runner/work/quarkus/quarkus/integration-tests/awt/src/test/java/io/quarkus/awt/it/ImageIOTestCase.java

@geoand
Copy link
Contributor

geoand commented Sep 22, 2021

When everything is done, please squash the formatting commits

@Sanne
Copy link
Member

Sanne commented Sep 22, 2021

I like the shape this is taking - no idea where to put docs though, I suppose that can be deferred as a separate issue as really there isn't much to document, we just need figure out how to make sure people know about this extension when hitting problems with awt.

@geoand
Copy link
Contributor

geoand commented Sep 22, 2021

we just need figure out how to make sure people know about this extension when hitting problems with awt

Hopefully discoverability via the tooling would be enough

@galderz
Copy link
Member Author

galderz commented Sep 22, 2021

When everything is done, please squash the formatting commits

Yeah sure. Just waiting for a final CI run to make sure I've not forgotten anything.

@quarkus-bot
Copy link

quarkus-bot bot commented Sep 22, 2021

This workflow status is outdated as a new workflow run has been triggered.

Failing Jobs - Building 012d2a8

Status Name Step Failures Logs Raw logs
MicroProfile TCKs Tests Verify Failures Logs Raw logs

Full information is available in the Build summary check run.

Failures

⚙️ MicroProfile TCKs Tests #

- Failing: tcks/resteasy-reactive 

📦 tcks/resteasy-reactive

Failed to execute goal org.codehaus.mojo:exec-maven-plugin:3.0.0:exec (test) on project quarkus-tck-resteasy-reactive: Command execution failed.

📦 tcks/resteasy-reactive/target/testsuite/tests

com.sun.ts.tests.jaxrs.platform.container.completioncallback.JAXRSClient0164.argumentIsNullWhenRegistredClassTest line 209 - More details - Source on GitHub

com.sun.ts.tests.jaxrs.common.JAXRSCommonClient$Fault: Unexpected response content No name has been set yet expecting NULL
	at com.sun.ts.tests.jaxrs.platform.container.completioncallback.JAXRSClient0164.assertString(JAXRSClient0164.java:458)
	at com.sun.ts.tests.jaxrs.platform.container.completioncallback.JAXRSClient0164.argumentIsNullWhenRegistredClassTest(JAXRSClient0164.java:209)

* Even though reflection and JNI registrations
happen in the AWT extenssion,
runtime initialization packages are defined in core.
* This is done to avoid sun.java2d,
and related classes,
to be build time initialized,
which causes issues with other modules.
* Move ImageIO test from main to awt.
* Make Apache Tika depend on AWT extension
* Mark Tika packages that need runtime initialization for AWT.
This definition can happen directly at the Tika extension level.

Fix formatting
@galderz
Copy link
Member Author

galderz commented Sep 23, 2021

Squashed and pushed. This is ready to go in now.

@galderz galderz force-pushed the t_awt_image_resize_v4 branch from 012d2a8 to b6038fc Compare September 23, 2021 11:05
Copy link
Contributor

@geoand geoand left a comment

Choose a reason for hiding this comment

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

Thanks!

@quarkus-bot
Copy link

quarkus-bot bot commented Sep 23, 2021

Failing Jobs - Building b6038fc

Status Name Step Failures Logs Raw logs
Gradle Tests - JDK 11 Windows Build Failures Logs Raw logs
✔️ JVM Tests - JDK 11
JVM Tests - JDK 16 Build ⚠️ Check → Logs Raw logs

Full information is available in the Build summary check run.

Failures

⚙️ Gradle Tests - JDK 11 Windows #

- Failing: integration-tests/gradle 

📦 integration-tests/gradle

io.quarkus.gradle.devmode.MultiModuleIncludedBuildTest.main line 24 - More details - Source on GitHub

java.lang.AssertionError: 

Expecting actual:

@geoand
Copy link
Contributor

geoand commented Sep 23, 2021

@Sanne I'll leave the final decision up to you since you've been following this closely

@Sanne Sanne merged commit 103590b into quarkusio:main Sep 23, 2021
@quarkus-bot quarkus-bot bot added this to the 2.4 - main milestone Sep 23, 2021
@Sanne
Copy link
Member

Sanne commented Sep 23, 2021

@Sanne I'll leave the final decision up to you since you've been following this closely

damn :)

thanks all! merged it

@geoand
Copy link
Contributor

geoand commented Sep 23, 2021

One more question: Should we backport this into 2.3? It seems harmless, no?

@galderz
Copy link
Member Author

galderz commented Sep 23, 2021

@geoand Yeah, the impact on existing code is minimal (just add awt/imageio/java2d packages for runtime init). For the rest of the code to kick in, an extension has to depend on awt specifically.

@geoand
Copy link
Contributor

geoand commented Sep 24, 2021

I am removing the backport label as a concequence of #11563

@galderz
Copy link
Member Author

galderz commented Sep 30, 2021

@geoand Can someone create an issue for #11563 and assign it to me? I've been digging into graalvm/mandrel#292

@geoand
Copy link
Contributor

geoand commented Oct 1, 2021

Done: #20491

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/core area/dependencies Pull requests that update a dependency file area/devtools Issues/PR related to maven, gradle, platform and cli tooling/plugins area/documentation area/infra-automation anything related to CI, bots, etc. that are used to automated our infrastructure area/tika release/noteworthy-feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AWT Graphics does not seem to work in native image
4 participants