From 1aad2808cb01ec9a2a5f364d2a1b638736e35377 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Galder=20Zamarren=CC=83o?= Date: Tue, 14 Sep 2021 17:32:13 +0200 Subject: [PATCH 1/3] Draft support for AWT image resizing --- .../quarkus/deployment/Java2DProcessor.java | 68 +++++++++++++++++++ .../pkg/steps/NativeImageBuildStep.java | 2 + .../runtime/graal/Java2DSubstitutions.java | 20 ------ 3 files changed, 70 insertions(+), 20 deletions(-) create mode 100644 core/deployment/src/main/java/io/quarkus/deployment/Java2DProcessor.java delete mode 100644 core/runtime/src/main/java/io/quarkus/runtime/graal/Java2DSubstitutions.java diff --git a/core/deployment/src/main/java/io/quarkus/deployment/Java2DProcessor.java b/core/deployment/src/main/java/io/quarkus/deployment/Java2DProcessor.java new file mode 100644 index 0000000000000..983736f21a478 --- /dev/null +++ b/core/deployment/src/main/java/io/quarkus/deployment/Java2DProcessor.java @@ -0,0 +1,68 @@ +package io.quarkus.deployment; + +import io.quarkus.deployment.annotations.BuildStep; +import io.quarkus.deployment.builditem.nativeimage.JniRuntimeAccessBuildItem; +import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem; + +public class Java2DProcessor { + + @BuildStep + ReflectiveClassBuildItem setupReflectionClasses() { + return new ReflectiveClassBuildItem(false, false, + "sun.awt.X11GraphicsEnvironment", + "sun.awt.X11.XToolkit"); + } + + @BuildStep + JniRuntimeAccessBuildItem setupJava2DClasses() { + return new JniRuntimeAccessBuildItem(true, true, true, + "java.awt.AlphaComposite", + "java.awt.Color", + "java.awt.geom.AffineTransform", + "java.awt.geom.Path2D", + "java.awt.geom.Path2D$Float", + "java.awt.image.BufferedImage", + "java.awt.image.ColorModel", + "java.awt.image.IndexColorModel", + "java.awt.image.Raster", + "java.awt.image.SampleModel", + "java.awt.image.SinglePixelPackedSampleModel", + "sun.awt.SunHints", + "sun.awt.image.BufImgSurfaceData$ICMColorData", + "sun.awt.image.ByteComponentRaster", + "sun.awt.image.ImageRepresentation", + "sun.awt.image.IntegerComponentRaster", + "sun.java2d.Disposer", + "sun.java2d.InvalidPipeException", + "sun.java2d.NullSurfaceData", + "sun.java2d.SunGraphics2D", + "sun.java2d.SurfaceData", + "sun.java2d.loops.Blit", + "sun.java2d.loops.BlitBg", + "sun.java2d.loops.CompositeType", + "sun.java2d.loops.DrawGlyphList", + "sun.java2d.loops.DrawGlyphListAA", + "sun.java2d.loops.DrawGlyphListLCD", + "sun.java2d.loops.DrawLine", + "sun.java2d.loops.DrawParallelogram", + "sun.java2d.loops.DrawPath", + "sun.java2d.loops.DrawPolygons", + "sun.java2d.loops.DrawRect", + "sun.java2d.loops.FillParallelogram", + "sun.java2d.loops.FillPath", + "sun.java2d.loops.FillRect", + "sun.java2d.loops.FillSpans", + "sun.java2d.loops.GraphicsPrimitive", + "sun.java2d.loops.GraphicsPrimitiveMgr", + "sun.java2d.loops.GraphicsPrimitive[]", + "sun.java2d.loops.MaskBlit", + "sun.java2d.loops.MaskFill", + "sun.java2d.loops.ScaledBlit", + "sun.java2d.loops.SurfaceType", + "sun.java2d.loops.TransformHelper", + "sun.java2d.loops.XORComposite", + "sun.java2d.pipe.Region", + "sun.java2d.pipe.RegionIterator"); + } + +} diff --git a/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/NativeImageBuildStep.java b/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/NativeImageBuildStep.java index 75ba060b0e62c..4ec7c89c42a5f 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/NativeImageBuildStep.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/NativeImageBuildStep.java @@ -602,6 +602,8 @@ public NativeImageInvokerInfo build() { } handleAdditionalProperties(nativeConfig, nativeImageArgs, isContainerBuild, outputDir); + nativeImageArgs + .add("--initialize-at-run-time=java.awt,javax.imageio,sun.awt,sun.java2d,sun.font,com.sun.imageio"); nativeImageArgs.add( "-H:InitialCollectionPolicy=com.oracle.svm.core.genscavenge.CollectionPolicy$BySpaceAndTime"); //the default collection policy results in full GC's 50% of the time nativeImageArgs.add("-H:+JNI"); diff --git a/core/runtime/src/main/java/io/quarkus/runtime/graal/Java2DSubstitutions.java b/core/runtime/src/main/java/io/quarkus/runtime/graal/Java2DSubstitutions.java deleted file mode 100644 index 0ca2b30ab278e..0000000000000 --- a/core/runtime/src/main/java/io/quarkus/runtime/graal/Java2DSubstitutions.java +++ /dev/null @@ -1,20 +0,0 @@ -package io.quarkus.runtime.graal; - -import java.awt.Graphics; -import java.awt.GraphicsEnvironment; - -import com.oracle.svm.core.annotate.AlwaysInline; -import com.oracle.svm.core.annotate.Substitute; -import com.oracle.svm.core.annotate.TargetClass; - -@TargetClass(GraphicsEnvironment.class) -final class Target_java_awt_GraphicsEnvironment { - @AlwaysInline("DCE for things using Java2D") - @Substitute - public static Graphics getLocalGraphicsEnvironment() { - throw new UnsupportedOperationException("Not implemented yet for GraalVM native images"); - } -} - -class Java2DSubstitutions { -} From 28c9fc1d2b9c4033268e5aeef528bf585fec2e1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Galder=20Zamarren=CC=83o?= Date: Wed, 15 Sep 2021 13:01:45 +0200 Subject: [PATCH 2/3] Add missing JNI registration for it/main tests --- .../src/main/java/io/quarkus/deployment/Java2DProcessor.java | 1 + 1 file changed, 1 insertion(+) diff --git a/core/deployment/src/main/java/io/quarkus/deployment/Java2DProcessor.java b/core/deployment/src/main/java/io/quarkus/deployment/Java2DProcessor.java index 983736f21a478..7b0b7be54fdf6 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/Java2DProcessor.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/Java2DProcessor.java @@ -30,6 +30,7 @@ JniRuntimeAccessBuildItem setupJava2DClasses() { "sun.awt.SunHints", "sun.awt.image.BufImgSurfaceData$ICMColorData", "sun.awt.image.ByteComponentRaster", + "sun.awt.image.BytePackedRaster", "sun.awt.image.ImageRepresentation", "sun.awt.image.IntegerComponentRaster", "sun.java2d.Disposer", From 9d5d2ab208ca8f23f5eca1162c8a65ed492bcdb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Galder=20Zamarren=CC=83o?= Date: Wed, 15 Sep 2021 13:02:06 +0200 Subject: [PATCH 3/3] Temporarily add org.apache packages to runtime init for it/tika --- .../io/quarkus/deployment/pkg/steps/NativeImageBuildStep.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/NativeImageBuildStep.java b/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/NativeImageBuildStep.java index 4ec7c89c42a5f..99bda7864b5a1 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/NativeImageBuildStep.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/NativeImageBuildStep.java @@ -603,7 +603,7 @@ public NativeImageInvokerInfo build() { handleAdditionalProperties(nativeConfig, nativeImageArgs, isContainerBuild, outputDir); nativeImageArgs - .add("--initialize-at-run-time=java.awt,javax.imageio,sun.awt,sun.java2d,sun.font,com.sun.imageio"); + .add("--initialize-at-run-time=java.awt,javax.imageio,sun.awt,sun.java2d,sun.font,com.sun.imageio,org.apache.pdfbox,org.apache.poi.hssf.util,org.apache.poi.ss.format"); nativeImageArgs.add( "-H:InitialCollectionPolicy=com.oracle.svm.core.genscavenge.CollectionPolicy$BySpaceAndTime"); //the default collection policy results in full GC's 50% of the time nativeImageArgs.add("-H:+JNI");