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]

memory leak in 3.3?


While trying to reproduce a problem I've been seeing in 3.1, I decided
to run my test program under 3.3 to see if this is something already
fixed and have noticed that the memory size has grow to be 825 megs over
the past 17 hours and appears to be continually growing. I searched the
bug database and there does not appear to be anything under memory leaks
for 3.3. Does anyone know of any cases where I might encounter this. The
code I'm running is attached. 


NOTE: The problem I've seen in 3.1 is that the program eventually throws
an IllegalMonitorStateException from _Jv_MonitorExit, with the message
"current thread not owner", and then deadlocks. I'm using hash
synchronization.


thanks
jake





import java.io.IOException;
import java.util.Date;
import java.util.Random;

public class DeadLockTest implements Runnable {
    private Object _mutex;
    private int _count;

    private static final Random _rand = new Random();
    private static final int LOOP_COUNT = 6;

    public DeadLockTest( Object mutex ) {
	_mutex = mutex;
    }

    public void log( String msg ) {
	if (_count == LOOP_COUNT) {
	    System.err.println( new Date() + ": " + Thread.currentThread() + ": " + msg );
	}
    }

    public void foo() throws IOException {
	throw new IOException( "hello" );
    }

    public void run() {
	int sleepTime = 0;

	while (true) {
	    _count++;
	    sleepTime = _rand.nextInt( 2000 );

	    log( "Aqcuring mutex after sleep: " + sleepTime );

	    try {
		Thread.sleep( sleepTime );
	    } catch (Exception e) {
		e.printStackTrace();
	    }

	    synchronized (_mutex) {
		log( "Have mutex" );

		try {
		    foo();
		} catch (Exception e) {
		}
	    }

	    log( "releasing mutex" );

	    if (_count == LOOP_COUNT) {
		_count = 0;
	    }
	}
    }

    public static void main( String[] args ) {
	Object mutex = new Object();

	for (int i = 0; i < 40; ++i) {
	    Thread t = new Thread( new DeadLockTest(mutex) );
	    t.start();
	}
    }
}


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