This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

FYI: reduced memory usage in xlib


I just checked this change in.

I had an annoying slow memory usage increase in my application using xlib
peers, which this hack, er I mean patch, corrects.

The application's RSS increased at something like 1k per second until nearly
all of my system's 256M was in use.  The GC stats showed a total heap size
of about 15 megs.  Using ccmalloc I traced it to ...xlib.GC's creation of a
Clip instance, which was never disposed.  I tried calling clip.dispose, but
it didn't solve the problem. I don't really know why that approach didn't
work.  In the end I copied code from Clip into GC, eliminating the need to
create a Clip.  It seems a little bogus (in that the same code snippet now
appears in two places) but it cures the memory problem.
2003-12-05  Scott Gilbertson  <scottg@mantatest.com>

	* gnu/gcj/xlib/GC.java (updateClip): Added rectangles argument.
	(clip): Removed field
	(clipRectangles): New field.
	(clone): Use new updateClip.
	(setClipRectangles): Use new updateClip.
	* gnu/gcj/xlib/natGC.cc (updateClip): Prepare passed rectangles.
Index:
libjava/gnu/gcj/xlib/GC.java================================================
===================RCS file:
/cvs/gcc/gcc/libjava/gnu/gcj/xlib/GC.java,vretrieving revision
1.6diff -u -r1.6 GC.java--- libjava/gnu/gcj/xlib/GC.java 25 Aug 2003
19:02:29 -0000 1.6+++ libjava/gnu/gcj/xlib/GC.java 5 Dec 2003
21:55:02 -0000@@ -45,7 +45,7 @@      gcClone.structure = null;    }
gcClone.initStructure(this);- gcClone.updateClip();+
gcClone.updateClip(clipRectangles);  return gcClone;       }      catch
(CloneNotSupportedException ex)@@ -107,8 +107,8 @@    */   public void
setClipRectangles(Rectangle[] rectangles)   {-    clip = new
Clip(rectangles);-    updateClip();+    clipRectangles = rectangles;+
updateClip(clipRectangles);   }    public native void drawString(String
text, int x, int y);@@ -148,10 +148,10 @@     return target;   } -  private
native void updateClip();+  private native void updateClip(Rectangle[]
rectangles);    private Drawable target;   private RawData structure;-
private Clip clip;+  private Rectangle[] clipRectangles; } Index:
libjava/gnu/gcj/xlib/natGC.cc===============================================
====================RCS file:
/cvs/gcc/gcc/libjava/gnu/gcj/xlib/natGC.cc,vretrieving revision
1.7diff -u -r1.7 natGC.cc--- libjava/gnu/gcj/xlib/natGC.cc 25 Aug 2003
19:02:29 -0000 1.7+++ libjava/gnu/gcj/xlib/natGC.cc 5 Dec 2003
21:55:02 -0000@@ -217,25 +217,33 @@   // no fast fail } -void
gnu::gcj::xlib::GC::updateClip()+void
gnu::gcj::xlib::GC::updateClip(AWTRectArray* rectangles) {-  if (clip == 0)-
return;+  int numRect = JvGetArrayLength(rectangles);+  XRectVector*
xrectvector = new XRectVector(numRect);   +  for (int i=0; i<numRect; i++)+
{+    AWTRect* awtrect = elements(rectangles)[i];+    XRectangle& xrect =
(*xrectvector)[i];+      +    xrect.x      = awtrect->x;+    xrect.y      =
awtrect->y;+    xrect.width  = awtrect->width;+    xrect.height =
awtrect->height;+  }+   Display* display = target->getDisplay();
::Display* dpy = (::Display*) (display->display);   ::GC gc = (::GC)
structure;-  -  XRectVector* xrectvector = (XRectVector*) (clip->xrects);-
int numRect = xrectvector->size();-  +   int originX = 0;   int originY = 0;
int ordering = Unsorted;   XSetClipRectangles(dpy, gc, originX, originY,
&(xrectvector->front()), numRect,        ordering);-  // no fast fail+
delete xrectvector; }  void gnu::gcj::xlib::GC::copyArea
(gnu::gcj::xlib::Drawable * source,


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]