[OpenJDK 2D-Dev] Fw: [PATCH] Allow linking in (shared) libfontconfig directy

Phil Race Phil.Race at Sun.COM
Mon May 21 20:18:15 UTC 2007


Hi,

In many apps, fontconfig isn't loaded at all, so explicit
linking is actually a loss in startup and footprint.

Also since we dlclose, we reclaim the virtual memory, rather than keeping
it around when it will never be used again. That is there
is a very small bounded set of times when we might load this lib,
so its not something we keep coming back to.
I also think a couple of the cases could be collapsed into one.
One of them was something added last in JDK 6 so it
was playing safe rather than disturbing existing code.

Perhaps the most common case is going to be when running a GTK
Look and Feel app, and we look up the desktop fonts,
but in that case Swing pulls in GTK anyway and
keeps it around so although the memory footprint is there,
its swamped by GTK and there's really no cost to the dlopen
as the linker reference counts for you ..

Also I'll be making some fontconfig related changes
fairly soon .. once I can clear my desk so to speak, so
its probably not a good time to do this, even if its
really going to make a difference, which I doubt.

-Phil.

Diego 'Flameeyes' Pettenò wrote:
> Forwarding to 2d-dev as asked by Oleg Sukhodolsky (originally from
> awt-dev).
> 
> Begin forwarded message:
> 
> Date: Mon, 21 May 2007 17:45:29 +0200
> From: Diego 'Flameeyes' Pettenò <flameeyes at gmail.com>
> To: awt-dev at openjdk.java.net
> Subject: [PATCH] Allow linking in (shared) libfontconfig directy
> 
> 
> As it is, OpenJDK tries to dlopen fontconfig (multiple times too), to
> avoid a direct link dependency over it. This could be quite slow as the
> dynamic linker has to do its job multiple times, but is understandable
> for redistributable packages.
> 
> Distributions, though, might want to just depend on fontconfig itself
> and link it directly. The attached patch allows that through the
> DIRECT_LINK_FONTCONFIG=true option at make.
> 
> 
> 
> ------------------------------------------------------------------------
> 
> Index: openjdk/j2se/src/solaris/native/sun/awt/fontpath.c
> ===================================================================
> --- openjdk.orig/j2se/src/solaris/native/sun/awt/fontpath.c
> +++ openjdk/j2se/src/solaris/native/sun/awt/fontpath.c
> @@ -612,6 +612,9 @@ Java_sun_font_FontManager_populateFontFi
>  #include <link.h>
>  #endif
>  
> +#ifdef DIRECT_LINK_FONTCONFIG
> +# include <fontconfig/fontconfig.h>
> +#else /* DIRECT_LINK_FONTCONFIG */
>  #include "fontconfig.h"
>  
>  
> @@ -734,21 +737,12 @@ typedef FcPattern* (*FcFontMatchFuncType
>                                            FcResult *result);
>  typedef FcFontSet* (*FcFontSetCreateFuncType)();
>  typedef FcBool (*FcFontSetAddFuncType)(FcFontSet *s, FcPattern *font);
> -
> +#endif /* DIRECT_LINK_FONTCONFIG */
>  
>  static char **getFontConfigLocations() {
>  
>      char **fontdirs;
>      int numdirs = 0;
> -    FcInitLoadConfigFuncType FcInitLoadConfig;
> -    FcPatternBuildFuncType FcPatternBuild;
> -    FcObjectSetFuncType FcObjectSetBuild;
> -    FcFontListFuncType FcFontList;
> -    FcPatternGetStringFuncType FcPatternGetString;
> -    FcStrDirnameFuncType FcStrDirname;
> -    FcPatternDestroyFuncType FcPatternDestroy;
> -    FcFontSetDestroyFuncType FcFontSetDestroy;
> -    
>      FcConfig *fontconfig;
>      FcPattern *pattern;
>      FcObjectSet *objset;
> @@ -758,6 +752,16 @@ static char **getFontConfigLocations() {
>      int i, f, found, len=0;
>      char **fontPath;
>   
> +#ifndef DIRECT_LINK_FONTCONFIG
> +    FcInitLoadConfigFuncType FcInitLoadConfig;
> +    FcPatternBuildFuncType FcPatternBuild;
> +    FcObjectSetFuncType FcObjectSetBuild;
> +    FcFontListFuncType FcFontList;
> +    FcPatternGetStringFuncType FcPatternGetString;
> +    FcStrDirnameFuncType FcStrDirname;
> +    FcPatternDestroyFuncType FcPatternDestroy;
> +    FcFontSetDestroyFuncType FcFontSetDestroy;
> +    
>      void* libfontconfig = openFontConfig();
>  
>      if (libfontconfig == NULL) {
> @@ -789,6 +793,7 @@ static char **getFontConfigLocations() {
>          closeFontConfig(libfontconfig, JNI_FALSE);
>  	return NULL;
>      }
> +#endif
>  
>      /* Make calls into the fontconfig library to build a search for
>       * outline fonts, and to get the set of full file paths from the matches.
> @@ -831,7 +836,9 @@ static char **getFontConfigLocations() {
>      /* Free memory and close the ".so" */
>      (*FcFontSetDestroy)(fontSet);
>      (*FcPatternDestroy)(pattern);   
> +#ifndef DIRECT_LINK_FONTCONFIG
>      closeFontConfig(libfontconfig, JNI_TRUE);
> +#endif
>      return fontdirs; 
>  }
>  
> @@ -849,6 +856,7 @@ JNIEXPORT jint JNICALL
>  Java_sun_font_FontManager_getFontConfigAASettings
>  (JNIEnv *env, jclass obj, jstring localeStr, jstring fcNameStr) {
>  
> +#ifndef DIRECT_LINK_FONTCONFIG
>      FcNameParseFuncType FcNameParse;
>      FcPatternAddStringFuncType FcPatternAddString;
>      FcConfigSubstituteFuncType FcConfigSubstitute;
> @@ -857,6 +865,7 @@ Java_sun_font_FontManager_getFontConfigA
>      FcPatternGetBoolFuncType FcPatternGetBool;
>      FcPatternGetIntegerFuncType FcPatternGetInteger;
>      FcPatternDestroyFuncType FcPatternDestroy;
> +#endif
>  
>      FcPattern *pattern, *matchPattern;
>      FcResult result;
> @@ -875,6 +884,7 @@ Java_sun_font_FontManager_getFontConfigA
>      }
>      locale = (*env)->GetStringUTFChars(env, localeStr, 0);
>  
> +#ifndef DIRECT_LINK_FONTCONFIG
>      if ((libfontconfig = openFontConfig()) == NULL) {
>          (*env)->ReleaseStringUTFChars (env, fcNameStr, (const char*)fcName);
>          if (locale) {
> @@ -914,7 +924,7 @@ Java_sun_font_FontManager_getFontConfigA
>          closeFontConfig(libfontconfig, JNI_FALSE);
>          return -1;
>      }
> -
> +#endif
>  
>      pattern = (*FcNameParse)((FcChar8 *)fcName);
>      if (locale != NULL) {
> @@ -938,7 +948,9 @@ Java_sun_font_FontManager_getFontConfigA
>      if (locale) {
>          (*env)->ReleaseStringUTFChars (env, localeStr, (const char*)locale);
>      }
> +#ifndef DIRECT_LINK_FONTCONFIG
>      closeFontConfig(libfontconfig, JNI_TRUE);
> +#endif
>  
>      if (antialias == FcFalse) {
>          return TEXT_AA_OFF;
> @@ -960,6 +972,7 @@ JNIEXPORT void JNICALL
>  Java_sun_font_FontManager_getFontConfig
>  (JNIEnv *env, jclass obj, jstring localeStr, jobjectArray fontInfoArray) {
>  
> +#ifndef DIRECT_LINK_FONTCONFIG
>      FcNameParseFuncType FcNameParse;
>      FcPatternAddStringFuncType FcPatternAddString;
>      FcConfigSubstituteFuncType FcConfigSubstitute;
> @@ -967,6 +980,7 @@ Java_sun_font_FontManager_getFontConfig
>      FcFontMatchFuncType FcFontMatch;
>      FcPatternGetStringFuncType FcPatternGetString;
>      FcPatternDestroyFuncType FcPatternDestroy;
> +#endif
>  
>      int i, arrlen;
>      jobject fontInfoObj;
> @@ -997,6 +1011,7 @@ Java_sun_font_FontManager_getFontConfig
>          return;
>      }
>  
> +#ifndef DIRECT_LINK_FONTCONFIG
>      if ((libfontconfig = openFontConfig()) == NULL) {
>          return;
>      }
> @@ -1024,6 +1039,7 @@ Java_sun_font_FontManager_getFontConfig
>          closeFontConfig(libfontconfig, JNI_FALSE);
>          return;
>      }
> +#endif
>  
>      locale = (*env)->GetStringUTFChars(env, localeStr, 0);
>  
> @@ -1073,6 +1089,8 @@ Java_sun_font_FontManager_getFontConfig
>      if (locale) {
>          (*env)->ReleaseStringUTFChars (env, localeStr, (const char*)locale);
>      }
> +#ifndef DIRECT_LINK_FONTCONFIG
>      closeFontConfig(libfontconfig, JNI_TRUE);
> +#endif
>  }
>  
> Index: openjdk/j2se/make/sun/awt/Makefile
> ===================================================================
> --- openjdk.orig/j2se/make/sun/awt/Makefile
> +++ openjdk/j2se/make/sun/awt/Makefile
> @@ -580,6 +580,11 @@ ifeq ($(PLATFORM), linux)
>  LDFLAGS += -L$(MOTIF_LIB) -L$(OPENWIN_LIB)
>  endif
>  
> +ifeq ($(DIRECT_LINK_FONTCONFIG), true)
> +CPPFLAGS += -DDIRECT_LINK_FONTCONFIG
> +LDFLAGS += -lfontconfig
> +endif
> +
>  LDFLAGS += -L$(LIBDIR)/$(LIBARCH)/$(TSOBJDIR) \
>  	   $(AWT_RUNPATH)
>  
> Index: openjdk/j2se/make/sun/xawt/Makefile
> ===================================================================
> --- openjdk.orig/j2se/make/sun/xawt/Makefile
> +++ openjdk/j2se/make/sun/xawt/Makefile
> @@ -62,6 +62,11 @@ LDFLAGS += -lpthread
>  dummy := $(shell $(MKDIR) -p $(LIB_LOCATION))
>  endif
>  
> +ifeq ($(DIRECT_LINK_FONTCONFIG), true)
> +CPPFLAGS += -DDIRECT_LINK_FONTCONFIG
> +LDFLAGS += -lfontconfig
> +endif
> +
>  # Since this library will be living in a subdirectory below the other libraries
>  #   we need to add an extra runpath so that libraries in the upper directory
>  #   are found at runtime.



More information about the 2d-dev mailing list