Runtime.getRuntime().gc() never returns in included example

Øyvind Harboe oyvind.harboe@zylin.com
Fri Aug 15 21:55:00 GMT 2003


I'm was trying to track down a different bug, when I ran across
this behaviour. Don't know what to make of it.

The program below hangs in Runtime.getRuntime.gc(). This happens
across Linux and GCC versions...

Dump from GDB under Windows:

$ gdb ./test2
GNU gdb 2003-03-03-cvs (cygwin-special)
Copyright 2003 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you
are
welcome to change it and/or distribute copies of it under certain
conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for
details.
This GDB was configured as "i686-pc-cygwin"...
(gdb) run
Starting program: /cygdrive/y/test/test2.exe
first thread 0

Program received signal SIGINT, Interrupt.
[Switching to thread 2900.0xfe4]
0x77ea31c7 in KERNEL32!GetAtomNameA () from
/ecos-C/WINDOWS/system32/kernel32.dl
l
(gdb) thread apply all bt

Thread 3 (thread 2900.0xfe4):
#0  0x77ea31c7 in KERNEL32!GetAtomNameA () from
/ecos-C/WINDOWS/system32/kernel3
2.dll
#1  0x77f57d70 in ntdll!RtlAppendStringToString () from ntdll.dll
#2  0x77e7d33b in RegisterWaitForInputIdle () from
/ecos-C/WINDOWS/system32/kern
el32.dll

Thread 2 (thread 2900.0xf5c):
#0  0x7ffe0304 in ?? ()
#1  0x77e75faa in WaitForMultipleObjects () from
/ecos-C/WINDOWS/system32/kernel
32.dll
#2  0x00408ef3 in _ZN4java4lang6Object4waitExi () at
/datal/gcc/gcc/gcc/config/i
386/cygwin.asm:29
#3  0x00406cc9 in _ZN4java4lang6Object4waitEv () at
/datal/gcc/gcc/gcc/config/i3
86/cygwin.asm:29
#4  0x0041494f in _ZN3gnu3gcj7runtime15FinalizerThread3runEv () at
/datal/gcc/gc
c/gcc/config/i386/cygwin.asm:29
#5  0x0041e457 in _Z13_Jv_ThreadRunPN4java4lang6ThreadE () at
/datal/gcc/gcc/gcc
/config/i386/cygwin.asm:29
#6  0x0041d9f0 in _Z12really_startPv@4 () at
/datal/gcc/gcc/gcc/config/i386/cygw
in.asm:29
#7  0x004698fe in thread_start@4 () at
/datal/gcc/gcc/gcc/config/i386/cygwin.asm
:29
#8  0x77e7d33b in RegisterWaitForInputIdle () from
/ecos-C/WINDOWS/system32/kern
el32.dll

Thread 1 (thread 2900.0x950):
#0  0x7ffe0304 in ?? ()
#1  0x00467903 in GC_mark_some_inner () at
/datal/gcc/gcc/gcc/config/i386/cygwin
.asm:29
#2  0x00467c11 in GC_mark_some () at
/datal/gcc/gcc/gcc/config/i386/cygwin.asm:2
9
#3  0x00465c93 in GC_stopped_mark () at
/datal/gcc/gcc/gcc/config/i386/cygwin.as
m:29
#4  0x00465828 in GC_try_to_collect_inner () at
/datal/gcc/gcc/gcc/config/i386/c
ygwin.asm:29
#5  0x00466230 in GC_try_to_collect () at
/datal/gcc/gcc/gcc/config/i386/cygwin.
asm:29
#6  0x00466292 in GC_gcollect () at
/datal/gcc/gcc/gcc/config/i386/cygwin.asm:29

#7  0x004013da in Test2.replaceAll(java.lang.String, java.lang.String,
java.lang
.String) (in=0xc6eed0, a=0xc6ee70, b=0xc2efd8) at Test2.java:15
#8  0x00401a34 in Test2.stressGB(java.lang.String) (thread=0xc2b9c0) at
Test2.ja
va:60
#9  0x0040168e in Test2.main(java.lang.String[]) (args=0xc26fe0) at
Test2.java:3
6
#10 0x00414dc2 in _ZN3gnu3gcj7runtime11FirstThread3runEv () at
/datal/gcc/gcc/gc
c/config/i386/cygwin.asm:29
#11 0x0041e457 in _Z13_Jv_ThreadRunPN4java4lang6ThreadE () at
/datal/gcc/gcc/gcc
/config/i386/cygwin.asm:29
#12 0x0040376f in _Z11_Jv_RunMainPN4java4lang5ClassEPKciPS4_b () at
/datal/gcc/g
cc/gcc/config/i386/cygwin.asm:29
#13 0x0040383f in JvRunMain () at
/datal/gcc/gcc/gcc/config/i386/cygwin.asm:29
#14 0x004012e2 in main (argc=1, argv=0x3d2430)
#0  0x77ea31c7 in KERNEL32!GetAtomNameA () from
/ecos-C/WINDOWS/system32/kernel3
2.dll
(gdb)


This happens with GCC 3.2 under Linux:

Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/3.2.2/specs
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/3.2.2/libgcj.spec
rename spec lib to liborig
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --enable-shared --enable-threads=posix
--disable-checking --with-system-zlib --enable-__cxa_atexit
--host=i386-redhat-linux
Thread model: posix
gcc version 3.2.2 20030222 (Red Hat Linux 3.2.2-5)

And GCC 3.4 under Windows:

Reading specs from
/home/oyvind/fresh/gcc/build/crossgcc/bin/../lib/gcc/i686-pc-mingw32/3.4
/specs
Reading specs from
/home/oyvind/fresh/gcc/build/crossgcc/bin/../lib/gcc/i686-pc-mingw32/3.4
/../../../../i686-pc-mingw32/lib/libgcj.spec
rename spec lib to liborig
Configured with: /datal/gcc/gcc/configure
--prefix=/datal/gcc/build/crossgcc --target=i686-pc-mingw32
--host=i686-pc-linux-gnu --build=i686-pc-linux-gnu
--enable-languages=c,c++,java --disable-nls --disable-debug
--enable-threads=win32 --with-gcc --with-gnu-as --with-gnu-ld
--without-newlib --disable-win32-registry --disable-shared
--enable-libgcj --disable-java-awt --without-x --enable-java-gc=boehm
--disable-libgcj-debug --enable-interpreter
--enable-hash-synchronization --enable-sjlj-exceptions
Thread model: win32
gcc version 3.4 20030814 (experimental)




import java.lang.Runtime;

public class Test2
{
    static public String replaceAll(String in, String a, String b)
    {
	String t = "";
	int i;
	i = 0; 
	while (i < in.length() - a.length())
	    {
		String c = in.substring(i, i + a.length());
		// comment out the call below, and the program
		// no longer hangs.
		Runtime.getRuntime().gc();
		if (c.equals(a))
		    {
			t += b;
			i = i + a.length();
		    } else
			{
			    t += in.substring(i, i + 1);
			    i++;
			}
	    }
	if (i < in.length())
	    {
		t += in.substring(i, in.length());
	    }
	return t;
    }

    public static void main(String[] args)
    {
	Runtime.getRuntime().gc();
	stressGB("first thread");

    }

    static final char[] abs = { 'a', 'b', 'c', 'd', 'e', 'f', 'g' };
    static char rndChar()
    {
	double r = Math.random();
	return abs[Math.min(abs.length - 1, (int) (r * abs.length ))];
    }

    static void stressGB(String thread)
    {

	String foo = "";
	for (int i = 0; i < 100000000; i++)
	    {
		if ((i % 1000) == 0)
		    {
			System.out.println(thread + " " + i + " " + 
					   foo);
		    }

		foo = foo + rndChar();
		foo = replaceAll(foo, "" + rndChar(), "");
	    }
    }
}



More information about the Java mailing list