This is the mail archive of the java@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]

Re: gcj: mem leaks & speed.


[Comments added below.]

On Sat, 31 Jan 2004, Rutger Ovidius wrote:

> Hi,
>
> I have an app that runs well under java, but when compiled with gcj it
> seems to leak memory (a gig in a few hours) -- this has been reported
> by users of the app on linux and windows.
>
> Are there any tools or methods I can use that would help me track down
> the cause?  I'm finding it difficult since the mem leak isn't in my java
> code as far as I can tell and java profiling isn't helping me.
Try defining the environment
variable GC_PRINT_STATS.  This should generate a log on stdout (linux)
or in gc.log (Windows).  The high order bit you're looking for is whether
the growth is due to the Java heap or memory allocated with the system
malloc.
>
> (The app is an SWT gui app)
>
> --
>
> Also, while trying to track down memory use, I wrote the following
> class:
>
> public class Leak {
>   public static void main(String[] argv) {
>     long start = System.currentTimeMillis();
>     for (int i = 0;; i++) {
>       Leak l = new Leak();
>       if (i % 100000000 == 0) {
>         long curr = System.currentTimeMillis();
>         System.out.println(i / 100000000 + ": " + (curr - start));
>       }
>     }
>   }
> }
>
> This runs 10x as slow in gcj as it does in java on windows (~6x on
> linux) If you remove the "Leak l = new Leak();" line, the speed
> becomes rather similar to java. Why is class creation so slow? (or is
> it GC cleanup that is slow?)
The garbage collector used by gcj does not handle very short-lived
objects as efficiently as most JVMs, though it sometimes performs
better for applications that alternately allocate and drop very large
linked structures.  This example exercises short-lived allocation to
the extreme.

A factor of 10 is a larger difference than I would have expected.
It may well be that some JVMs recognize that the allocation is dead
and remove it (probably not very useful in practice) or recognize
that l doesn't escape the loop body, and hence the Leak object can
be stack allocated (may be useful in practice).  AFAIK, gcj
currently does neither.
>
> I then extended it to spawn threads to see if it gobbled up memory
> (which it seems to..)
>
> public class Leak implements Runnable {
>
>   public static void main(String[] argv) {
>    long start = System.currentTimeMillis();
>    for (int i = 0;; i++) {
>     Leak l = new Leak();
>     new Thread(l).start();
>       if (i % 10000 == 0) { // decrease
>         long curr = System.currentTimeMillis();
>         System.out.println(i / 10000 + ": " + (curr - start));
>       }
>     }
>   }
>   public void run() {
>     int i = 9;
>   }
> }
>
> This runs ~2x faster in gcj than in java for some reason (~5x faster
> on linux). But, at the 16th line of output on windows:
>
> libgcj failure: CreateEvent() failed
> This application has requested the Runtime to terminate it in an unusual way.
> Please contact the application's support team for more information.
>
> I use: gcc version 3.4.0 20040130 (prerelease)
>
> Regards,
> Rutger Ovidius
>


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