Skip to content

[native-image] java.lang.UnsatisfiedLinkError in native-images utilizing Fonts or Graphics2D #1813

@karstenw-ro

Description

@karstenw-ro

I tried to generate native-images from simple examples utilizing java.awt.Graphics2D and java.awt.Font using GraalVM EE 19.2.1. However, I could not get them to work.

As AWT is not officially supported at the moment, does this apply to awt in general or are there only specific parts which do not work?
Supporting java.awt in headless environments would already be a big improvement. Is there a rough time frame on when this could be expected?

In general, everything seems to work fine until native JNI methods are being called.
At that point, UnsatisfiedLinkErrors are thrown:

Font sample:

Exception in thread "main" java.lang.UnsatisfiedLinkError: sun.font.FontConfigManager.getFontConfigVersion()I [symbol: Java_sun_font_FontConfigManager_getFontConfigVersion or Java_sun_font_FontConfigManager_getFontConfigVersion__]
	at com.oracle.svm.jni.access.JNINativeLinkage.getOrFindEntryPoint(JNINativeLinkage.java:145)
	at com.oracle.svm.jni.JNIGeneratedMethodSupport.nativeCallAddress(JNIGeneratedMethodSupport.java:57)
	at sun.font.FontConfigManager.getFontConfigVersion(FontConfigManager.java)
	at sun.font.FcFontConfiguration.readFcInfo(FcFontConfiguration.java:455)
	at sun.font.FcFontConfiguration.init(FcFontConfiguration.java:94)
	at sun.font.FcFontConfiguration.<init>(FcFontConfiguration.java:76)
	at sun.awt.X11FontManager.createFontConfiguration(X11FontManager.java:768)
	at sun.font.SunFontManager$2.run(SunFontManager.java:431)
	at java.security.AccessController.doPrivileged(AccessController.java:69)
	at sun.font.SunFontManager.<init>(SunFontManager.java:376)
	at sun.awt.FcFontManager.<init>(FcFontManager.java:35)
	at sun.awt.X11FontManager.<init>(X11FontManager.java:57)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	at java.lang.Class.newInstance(DynamicHub.java:778)
	at sun.font.FontManagerFactory$1.run(FontManagerFactory.java:83)
	at java.security.AccessController.doPrivileged(AccessController.java:69)
	at sun.font.FontManagerFactory.getInstance(FontManagerFactory.java:74)
	at java.awt.Font.getFont2D(Font.java:491)
	at java.awt.Font.getFamily(Font.java:1220)
	at java.awt.Font.getFamily_NoClientCode(Font.java:1194)
	at java.awt.Font.getFamily(Font.java:1186)
	at java.awt.Font.toString(Font.java:1683)
	at java.lang.String.valueOf(String.java:2994)
	at java.io.PrintStream.println(PrintStream.java:821)
	at GraalTest.main(GraalTest.java:10)

Graphics2D sample:

Exception in thread "main" java.lang.UnsatisfiedLinkError: sun.awt.image.BufImgSurfaceData.initRaster(Ljava/lang/Object;IIIIIILjava/awt/image/IndexColorModel;)V [symbol: Java_sun_awt_image_BufImgSurfaceData_initRaster or Java_sun_awt_image_BufImgSurfaceData_initRaster__Ljava_lang_Object_2IIIIIILjava_awt_image_IndexColorModel_2]
	at com.oracle.svm.jni.access.JNINativeLinkage.getOrFindEntryPoint(JNINativeLinkage.java:145)
	at com.oracle.svm.jni.JNIGeneratedMethodSupport.nativeCallAddress(JNIGeneratedMethodSupport.java:57)
	at sun.awt.image.BufImgSurfaceData.initRaster(BufImgSurfaceData.java)
	at sun.awt.image.BufImgSurfaceData.createDataIC(BufImgSurfaceData.java:254)
	at sun.awt.image.BufImgSurfaceData.createData(BufImgSurfaceData.java:87)
	at sun.awt.image.BufImgSurfaceManager.<init>(BufImgSurfaceManager.java:55)
	at sun.awt.image.SurfaceManager.getManager(SurfaceManager.java:79)
	at sun.java2d.SurfaceData.getPrimarySurfaceData(SurfaceData.java:273)
	at sun.java2d.SunGraphicsEnvironment.createGraphics(SunGraphicsEnvironment.java:185)
	at sun.java2d.HeadlessGraphicsEnvironment.createGraphics(HeadlessGraphicsEnvironment.java:89)
	at java.awt.image.BufferedImage.createGraphics(BufferedImage.java:1182)
	at GraalTest.main(GraalTest.java:17)

To resolve this, I tried to load the used libraries manually during runtime using NativeLibrarySupport.singleton().loadLibrary(), which did not seem to work.

As this commit(942be17) indicates, built-in native libraries are being prepared during build-time (Is this commit already included in version 19.2.1?). Does this mean that loading and registering native libraries which were included in the JDK manually should not be required in any case?

Is this a known issue regarding libawt in general or should the provided samples work in principle? Also, are there any other major known obstacles that could keep a native image using headless awt features from working?

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions