-
Notifications
You must be signed in to change notification settings - Fork 51
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
Cannot use FontManager on windows #945
Comments
With the following feature: public class FontmanagerFeature implements Feature {
@Override
public void beforeAnalysis(BeforeAnalysisAccess access) {
FeatureImpl.BeforeAnalysisAccessImpl a = ((FeatureImpl.BeforeAnalysisAccessImpl) access);
PlatformNativeLibrarySupport.singleton().addBuiltinPkgNativePrefix("sun_font");
PlatformNativeLibrarySupport.singleton().addBuiltinPkgNativePrefix("sun_java2d_loops_DrawGlyphList");
PlatformNativeLibrarySupport.singleton().addBuiltinPkgNativePrefix("sun_awt_Win32FontManager_getFontPath");
PlatformNativeLibrarySupport.singleton().addBuiltinPkgNativePrefix("sun_awt_Win32FontManager_populateFontFileNameMap0");
NativeLibraries nativeLibraries = a.getNativeLibraries();
NativeLibrarySupport.singleton().preregisterUninitializedBuiltinLibrary("fontmanager");
NativeLibrarySupport.singleton().preregisterUninitializedBuiltinLibrary("freetype");
nativeLibraries.addStaticJniLibrary("fontmanager", "awt");
nativeLibraries.addStaticNonJniLibrary("freetype");
nativeLibraries.addDynamicNonJniLibrary("gdi32");
}
} And this plugin config: <nativeImageArgs>
<arg>--add-exports=org.graalvm.nativeimage.builder/com.oracle.svm.hosted=ALL-UNNAMED
</arg>
<arg>--add-exports=org.graalvm.nativeimage.builder/com.oracle.svm.hosted.c=ALL-UNNAMED
</arg>
<arg>--add-exports=org.graalvm.nativeimage.builder/com.oracle.svm.core.jdk=ALL-UNNAMED
</arg>
</nativeImageArgs>
<linkerArgs>
<arg>fontmanager.lib</arg>
<arg>freetype.lib</arg>
<arg>gdi32.lib</arg>
<!-- required for the shim dlls -->
<!-- https://github.com/oracle/graal/issues/4072#issuecomment-1025211534 -->
<!-- https://github.com/oracle/graal/blob/vm-ce-22.3.0/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationAWTSupport.java#L45-L66 -->
<arg>/export:JDK_LoadSystemLibrary</arg>
<arg>/export:JNU_CallMethodByName</arg>
<arg>/export:JNU_CallMethodByNameV</arg>
<arg>/export:JNU_CallStaticMethodByName</arg>
<arg>/export:JNU_ClassString</arg>
<arg>/export:JNU_GetEnv</arg>
<arg>/export:JNU_GetFieldByName</arg>
<arg>/export:JNU_GetStaticFieldByName</arg>
<arg>/export:JNU_IsInstanceOfByName</arg>
<arg>/export:JNU_NewObjectByName</arg>
<arg>/export:JNU_NewStringPlatform</arg>
<arg>/export:JNU_SetFieldByName</arg>
<arg>/export:JNU_ThrowArrayIndexOutOfBoundsException</arg>
<arg>/export:JNU_ThrowByName</arg>
<arg>/export:JNU_ThrowIOException</arg>
<arg>/export:JNU_ThrowIllegalArgumentException</arg>
<arg>/export:JNU_ThrowInternalError</arg>
<arg>/export:JNU_ThrowNullPointerException</arg>
<arg>/export:JNU_ThrowOutOfMemoryError</arg>
<arg>/export:getEncodingFromLangID</arg>
<arg>/export:getJavaIDFromLangID</arg>
<arg>shell32.lib</arg>
</linkerArgs> I almost have this working (I think). If there is nothing of javafx on the classpath, it works with the addition of If there is something from javafx on the classpath, I'm stuck on these linker issues:
And in this case, I cannot add
Please note that:
|
any news for inject in javafx project awt.lib? |
GraalVM 21.1.0 introduces shim dll's to support a broader range of libraries, which are not yet statically linked into the image itself.
Without these shim dll's, the FontManager stuff does not work.
The attached project has a small reproducer which forces the FontManager to be initialized, set up to be built with the native-image-maven-plugin, and the gluon client-maven-plugin.
Expected Behavior
The fontmanager calls succeed, and
Ran without issues.
is printed to the console.Current Behavior
Steps to Reproduce
fontmanager-project.zip
Unpack the attached project, and build it:
From GraalVM 21.1.0 onwards, this works out of the box, compiling with the native-image maven plugin. To verify, run:
Substitute
<project root>
with the actual location.To run the Gluon counterpart, run:
Again substitute
<project root>
.This however results in the stacktrace under
Current Behavior
.The essence of the issue here is that some dlls need to be copy pasted next to the executable, which for now needs to be done manually. The project keeps these dlls in the
gluon-extra-resources
folder.One of these dlls is java.dll, which is already statically linked in the native-image, and because of this, is not correctly initialized in its dll form.
While for using awt.dll this doesn't seem to be an issue, for using fontmanager.dll, is clearly is.
The
platform encoding not initialized
exception is thrown here deep in java.dll code.Because the
InitializeEncoding
function is never called,which normally gets called here in the
System.initProperties
native call, which will run the statically included call, not the one from java.dll.Long story short, to fix this, there needs to be an equivalent of the shim dlls in substrate.
Your Environment
The text was updated successfully, but these errors were encountered: