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: SWT to libswt.a and binary size shrinking


Hi,

Alexandr Karimov wrote:

Exception in thread "main" org.eclipse.swt.SWTException: Unsupported or
unrecognized format
  at 0x004f732e (Unknown Source)
   ....

I think that this error is connected with gif image loading...

Yes, it is.


According to described above I have two questions: 1) What can be wrong with my libswt.a and how can I patch it to eliminate the above Exception?

Try the FileFormat.patch attached to this post. It is the same patch presented by John Murga (http://gcc.gnu.org/ml/java/2002-12/msg00147.html),
but adjusted to the new version of FileFormat.java (from SWT 3.0M8 -- 3044).
It should work fine with version 3050. Or, if not, it should be easy to implement 'by hand'.


2) Why is there so huge size difference between two compiled exe files
(with http://www.thisiscool.com/gcc_mingw.htm and alone MinGW instance) and
how I can shrink the generated exe to the minimum possible size?

Because the thisiscool.com build is using several optimizations. Some of those are only possible if you are building the compiler/libgcj from source.
Nevertheless, you should be able to reduce the size of your binaries by using some compiler flags when building libswt and your own programs:


-g0 (to remove debug information)
-Os (to optimize for size)

Also attached to the current post is a build-script for libswt (based on John Murga's script) that uses the patch and those compiler flags.
To build libswt.a, please place the build script, the patch file, swt.jar and swtsrc.zip into the same directory and run the build script from the MSYS environment. The script was tested with swt 3.0M8. You should get a libswt.a about 6 MB.



I guess that you know the next tip, but someone might not... You should also strip your generated .exe files:
strip your_program.exe
This can also be done by using the -s linker flag.



Regards, Joao


--- FileFormat.java.orig	Tue May  6 13:49:20 2003
+++ FileFormat.java	Thu May  6 17:27:22 2004
@@ -17,10 +17,19 @@
 
 public abstract class FileFormat {
 	static final String FORMAT_PACKAGE = "org.eclipse.swt.internal.image"; //$NON-NLS-1$
 	static final String FORMAT_SUFFIX = "FileFormat"; //$NON-NLS-1$
 	static final String[] FORMATS = {"WinBMP", "WinBMP", "GIF", "WinICO", "JPEG", "PNG", "TIFF"}; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$//$NON-NLS-5$ //$NON-NLS-6$//$NON-NLS-7$
+ 	static final FileFormat[] FORMATS_CLASSES = {
+ 		new WinBMPFileFormat(),
+ 		new WinBMPFileFormat(),
+ 		new GIFFileFormat(),
+ 		new WinICOFileFormat(),
+ 		new JPEGFileFormat(),
+ 		new PNGFileFormat(),
+ 		new TIFFFileFormat()
+ 	};
 	
 	LEDataInputStream inputStream;
 	LEDataOutputStream outputStream;
 	ImageLoader loader;
 	int compression;
@@ -56,19 +65,17 @@
 	LEDataInputStream stream = new LEDataInputStream(is);
 	boolean isSupported = false;	
 	for (int i = 1; i < FORMATS.length; i++) {
 		if (FORMATS[i] != null) {
 			try {
-				Class clazz = Class.forName(FORMAT_PACKAGE + '.' + FORMATS[i] + FORMAT_SUFFIX);
-				fileFormat = (FileFormat) clazz.newInstance();
-				if (fileFormat.isFileFormat(stream)) {
+				if (FORMATS_CLASSES[i].isFileFormat(stream)) {
+					fileFormat = FORMATS_CLASSES[i];
 					isSupported = true;
 					break;
 				}
-			} catch (ClassNotFoundException e) {
-				FORMATS[i] = null;
 			} catch (Exception e) {
+				System.out.println(e.toString());
 			}
 		}
 	}
 	if (!isSupported) SWT.error(SWT.ERROR_UNSUPPORTED_FORMAT);
 	fileFormat.loader = loader;

Attachment: build-swt30M8.sh
Description: Bourne shell script


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