Garbage collector question - "too many roots set"

Øyvind Harboe oyvind.harboe@zylin.com
Wed May 21 09:49:00 GMT 2003


In trying to track down a heap corruption problem (GDB has a warning
about heap corruption), I've stumbled across a weird failure.

"Too many root sets"

I think my test isn't eating memory, so why does the garbage 
collector go gaga?



gcj --main=TestSerial ..\scripts\native\modified_swt.jar
..\scripts\native\comm.jar -fjni -o ..\scripts\native\test2.exe
TestSerial.java


The various files required for this test are too big to post, 
but they can be downloaded here:

http://www.harboe.org/oyvind/rootsets.zip


import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.RowLayout;
import javax.comm.CommPortIdentifier;
import javax.comm.NoSuchPortException;
import javax.comm.PortInUseException;
import javax.comm.SerialPort;
import javax.comm.UnsupportedCommOperationException;

public class TestSerial
{
	public void run() 
	{
		Display display = new Display();
		final Shell shell = new Shell(display);
		RowLayout layout = new RowLayout();
		layout.justify = true;
		layout.pack = true;
		shell.setLayout(layout);
		shell.setText("Hello GCJ World!");
		Label label = new Label(shell, SWT.CENTER);
		label.setText("Hello, GCJ World!");
		Button button=new Button(shell, SWT.NONE);
   button.setText("wweee!");
		shell.pack();
		shell.open ();

		
		try
		{
			CommPortIdentifier portId =
CommPortIdentifier.getPortIdentifier("COM2");

			SerialPort sPort = (SerialPort)
portId.open("transfer", 0);
			
			try
			{
				sPort.setSerialPortParams(19200,
SerialPort.DATABITS_8, 
				SerialPort.STOPBITS_1,
				 SerialPort.PARITY_NONE);
				
	
sPort.setFlowControlMode(SerialPort.FLOWCONTROL_NONE);
				
				InputStream sIn=sPort.getInputStream();
				OutputStream
sOut=sPort.getOutputStream();
			
			}
			finally
			{			
				sPort.close();
			}
		} catch (IOException e)
		{
			e.printStackTrace();
		} catch (NoSuchPortException e)
		{
			e.printStackTrace();
		} catch (PortInUseException e)
		{
			e.printStackTrace();
		} catch (UnsupportedCommOperationException e)
		{
			e.printStackTrace();
		}
		shell.dispose();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) display.sleep
();
		}
	   display.dispose ();
	}
	
	public static void main(String[] args)
	{
		// avoid dependency on the silly javax.comm.properties
file
		// works for Java Web Start *and* GCJ.
		String driverName = "com.sun.comm.Win32Driver";
		try
		{
			javax.comm.CommDriver commDriver =
				(javax.comm.CommDriver) Class
					.forName(driverName)
					.newInstance();
			commDriver.initialize();
		} catch (ClassNotFoundException e)
		{
			e.printStackTrace();
		} catch (InstantiationException e)
		{
			e.printStackTrace();
		} catch (IllegalAccessException e)
		{
			e.printStackTrace();
		}
		for (int i=0; i<1000; i++)
		{
			System.out.println("Test " + i);
			new TestSerial().run();
		}
	}
}



More information about the Java mailing list