PATCH: xlib GC cache
Scott Gilbertson
scottg@mantatest.com
Wed Mar 19 23:35:00 GMT 2003
This patch caches xlib graphics contexts, to reduce the number of
XCreateGC/XFreeGC calls, especially in applications with lots of lightweight
components, and reduce the number of GCs simultaneously open in the X
server. I ran a small, strange application (attached) to test it.
Performance is noticably better with the change. I initially tackled this
because my system has a bug wherein XFree86 crashes (segv in CopyGC) if you
do a lot of XCreateGC/XCopyGC/XFreeGC operations with real time extensions
(RTAI) loaded. The cache reduces the frequency of the crash, but doesn't
eliminate it (the real problem is either in XFree86 or RTAI). I also used
xmon to verify that the right X protocol operations were happening.
With the patch, when you dispose a GC, it doesn't free any X server
resources. Instead, the GC is cached in a list associated with the GC's
target. When you subsequently create or clone another GC on the same
drawable (which happens every paint), the operation gets the GC from the
cache instead of creating a new one. The cached GCs aren't freed until you
finalize the target Drawable. The number of GCs created for each
heavyweight is equal to the depth of the lightweight component hierarchy
under that heavyweight (typically only 2 or 3), instead of being equal to
the number of components contained in the heavyweight (can be a hundred or
so). The number of XCopyGC operations is not reduced by this patch, because
they are necessary to allow components to inherit their parents' properties.
Patch is attached.
Index: libjava/ChangeLog
from Scott Gilbertson <scottg@mantatest.com>
* libjava/gnu/awt/xlib/XGraphics.java
gcc/libjava/gnu/awt/xlib/XGraphics.java (constructor): use new GC.create
(dispose): null metrics
* libjava/gnu/awt/xlib/XToolkit.java gcc/libjava/gnu/awt/xlib/XToolkit.java
(sync): implement, with a FIXME
* libjava/gnu/gcj/xlib/Clip.java gcc/libjava/gnu/gcj/xlib/Clip.java
(dispose): change name of native from finalize
(finalize): call dispose
* libjava/gnu/gcj/xlib/Drawable.java gcc/libjava/gnu/gcj/xlib/Drawable.java
(gcCache): new field
(gcCachedCount): new field
(finalize): new method
(putGCInCache): new method
(getGCFromCache): new method
* libjava/gnu/gcj/xlib/GC.java gcc/libjava/gnu/gcj/xlib/GC.java
(constructor): make protected
(clone): get new GC from cache if possible
(create): new static method
(dispose): save old GC in cache
* libjava/gnu/gcj/xlib/natClip.cc gcc/libjava/gnu/gcj/xlib/natClip.cc
(dispose): check for null before deleting
* libjava/gnu/gcj/xlib/natGC.cc gcc/libjava/gnu/gcj/xlib/natGC.cc
(initStructure): call XCreateGC only if gc is null
* libjava/gnu/gcj/xlib/Pixmap.java gcc/libjava/gnu/gcj/xlib/Pixmap.java
(constructor): use new GC.create
* libjava/java/awt/Container.java gcc/libjava/java/awt/Container.java
(visitChild): dispose gfx2 when finished
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 20030319_XlibGcCache.patch
Type: application/octet-stream
Size: 8438 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/java-patches/attachments/20030319/fbefda7f/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: AwtLoad.java
Type: application/octet-stream
Size: 9130 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/java-patches/attachments/20030319/fbefda7f/attachment-0001.obj>
More information about the Java-patches
mailing list