bug 186886
diff --git a/bundles/org.eclipse.equinox.executable/bin/carbon/macosx/ppc/Eclipse.app/Contents/MacOS/eclipse.ini b/bundles/org.eclipse.equinox.executable/bin/carbon/macosx/ppc/Eclipse.app/Contents/MacOS/eclipse.ini
index 00f12af..cedbe2d 100644
--- a/bundles/org.eclipse.equinox.executable/bin/carbon/macosx/ppc/Eclipse.app/Contents/MacOS/eclipse.ini
+++ b/bundles/org.eclipse.equinox.executable/bin/carbon/macosx/ppc/Eclipse.app/Contents/MacOS/eclipse.ini
@@ -1,5 +1,7 @@
 -showsplash
 org.eclipse.platform
+--launcher.XXMaxPermSize
+256m
 -vmargs
 -Xdock:icon=../Resources/Eclipse.icns
 -XstartOnFirstThread
diff --git a/bundles/org.eclipse.equinox.executable/bin/carbon/macosx/x86/Eclipse.app/Contents/MacOS/eclipse.ini b/bundles/org.eclipse.equinox.executable/bin/carbon/macosx/x86/Eclipse.app/Contents/MacOS/eclipse.ini
index 00f12af..cedbe2d 100644
--- a/bundles/org.eclipse.equinox.executable/bin/carbon/macosx/x86/Eclipse.app/Contents/MacOS/eclipse.ini
+++ b/bundles/org.eclipse.equinox.executable/bin/carbon/macosx/x86/Eclipse.app/Contents/MacOS/eclipse.ini
@@ -1,5 +1,7 @@
 -showsplash
 org.eclipse.platform
+--launcher.XXMaxPermSize
+256m
 -vmargs
 -Xdock:icon=../Resources/Eclipse.icns
 -XstartOnFirstThread
diff --git a/bundles/org.eclipse.equinox.executable/library/carbon/eclipseCarbon.c b/bundles/org.eclipse.equinox.executable/library/carbon/eclipseCarbon.c
index 7dcb89d..27fcf4b 100644
--- a/bundles/org.eclipse.equinox.executable/library/carbon/eclipseCarbon.c
+++ b/bundles/org.eclipse.equinox.executable/library/carbon/eclipseCarbon.c
@@ -434,4 +434,8 @@
 		_stprintf( c, APP_ICON_PATTERN, pid );
 		setenv(c, icon, 1);
 	}
-}
\ No newline at end of file
+}
+
+int isSunVM( _TCHAR * vm ) {
+	return (strncmp(vm, JAVA_FRAMEWORK, strlen(JAVA_FRAMEWORK)) == 0);
+}
diff --git a/bundles/org.eclipse.equinox.executable/library/eclipse.c b/bundles/org.eclipse.equinox.executable/library/eclipse.c
index 1e1591e..bdd9879 100644
--- a/bundles/org.eclipse.equinox.executable/library/eclipse.c
+++ b/bundles/org.eclipse.equinox.executable/library/eclipse.c
@@ -228,6 +228,9 @@
 #define SUPRESSERRORS _T_ECLIPSE("--launcher.suppressErrors")
 #define INI			  _T_ECLIPSE("--launcher.ini")
 #define SECOND_THREAD _T_ECLIPSE("--launcher.secondThread")
+#define PERM_GEN	  _T_ECLIPSE("--launcher.XXMaxPermSize")
+
+#define XXPERMGEN	  _T_ECLIPSE("-XX:MaxPermSize=")
 
 /* constants for ee options file */
 #define EE_EXECUTABLE 			_T_ECLIPSE("-Dee.executable=")
@@ -250,6 +253,7 @@
 static _TCHAR*  vmName        = NULL;     		/* Java VM that the user wants to run */
 static _TCHAR*  name          = NULL;			/* program name */	
 static _TCHAR*  library       = NULL;			/* the shared library */
+static _TCHAR*  permGen  	  = NULL;			/* perm gen size for sun */
 
 /* variables for ee options */
 static _TCHAR* eeExecutable = NULL;
@@ -291,6 +295,7 @@
     { STARTUP,		&startupArg,	0,			2 },
     { VM,           &vmName,		0,			2 },
     { NAME,         &name,			0,			2 },
+    { PERM_GEN,		&permGen,		0,			2 },
     { WS,			&wsArg,			0,			2 } };
 static int optionsSize = (sizeof(options) / sizeof(options[0]));
 
@@ -656,6 +661,31 @@
     return execArg;
 }
 
+static void adjustVMArgs( _TCHAR *vm, _TCHAR **vmArgv[] ) {
+	/* Sun VMs need some extra perm gen space */
+	if (isSunVM(vm) && permGen != NULL) {
+		int specified = 0, i = -1;
+		
+		/* first check to see if it is already specified */
+		while ( (*vmArgv)[++i] != NULL) {
+			/* we are also counting the number of args here */
+			if (!specified && _tcsncmp((*vmArgv)[i], XXPERMGEN, _tcslen(XXPERMGEN)) == 0) {
+				specified = 1;
+			}
+		}
+		
+		if (!specified) {
+			_TCHAR ** oldArgs = *vmArgv;
+			_TCHAR *newArg = malloc((_tcslen(XXPERMGEN) + _tcslen(permGen) + 1) * sizeof(_TCHAR));
+			_stprintf(newArg, _T_ECLIPSE("%s%s"), XXPERMGEN, permGen);
+			
+			*vmArgv = malloc((i + 1) * sizeof(_TCHAR *));
+			memcpy(*vmArgv, oldArgs, i * sizeof(_TCHAR *));
+			(*vmArgv)[i] = newArg;
+			(*vmArgv)[i + 1] = 0;
+		}
+	}
+}
 /*
  * Get the command and arguments to start the Java VM.
  *
@@ -681,6 +711,8 @@
 	/* If the user specified "-vmargs", add them instead of the default VM args. */
 	vmArg = (userVMarg != NULL) ? userVMarg : getArgVM( javaVM != NULL ? javaVM : jniLib ); 
  	
+	adjustVMArgs(javaVM != NULL ? javaVM : jniLib, &vmArg);
+	
  	/* Calculate the number of VM arguments. */
  	while (vmArg[ nVMarg ] != NULL)
  		nVMarg++;
diff --git a/bundles/org.eclipse.equinox.executable/library/eclipseNix.c b/bundles/org.eclipse.equinox.executable/library/eclipseNix.c
index 475fac8..c48f21a 100644
--- a/bundles/org.eclipse.equinox.executable/library/eclipseNix.c
+++ b/bundles/org.eclipse.equinox.executable/library/eclipseNix.c
@@ -216,3 +216,8 @@
 {
 	return startJavaJNI(libPath, vmArgs, progArgs);
 }
+
+int isSunVM( _TCHAR * vm ) {
+	/* don't know how to decide on this platform */
+	return 0;
+}
diff --git a/bundles/org.eclipse.equinox.executable/library/eclipseOS.h b/bundles/org.eclipse.equinox.executable/library/eclipseOS.h
index 1e33cf6..2bb9d2c 100644
--- a/bundles/org.eclipse.equinox.executable/library/eclipseOS.h
+++ b/bundles/org.eclipse.equinox.executable/library/eclipseOS.h
@@ -35,6 +35,7 @@
 #define processVMArgs processVMArgsW
 #define initialArgv initialArgvW
 #define secondThread secondThreadW
+#define isSunVM isSunVMW
 #endif
 
 #ifdef MACOSX
@@ -127,5 +128,8 @@
 /* do any platform specific processing of the user vmargs */
 extern void processVMArgs(_TCHAR **vmargs[] );
 
+/* is this a Sun VM, returns 0 if we don't know */
+extern int isSunVM( _TCHAR * vm );
+
 #endif /* ECLIPSE_OS_H */
 
diff --git a/bundles/org.eclipse.equinox.executable/library/make_version.mak b/bundles/org.eclipse.equinox.executable/library/make_version.mak
index deb3af0..29da523 100644
--- a/bundles/org.eclipse.equinox.executable/library/make_version.mak
+++ b/bundles/org.eclipse.equinox.executable/library/make_version.mak
@@ -10,5 +10,5 @@
 #*******************************************************************************
 
 maj_ver=1
-min_ver=016
+min_ver=017
 LIB_VERSION = $(maj_ver)$(min_ver)
diff --git a/bundles/org.eclipse.equinox.executable/library/win32/eclipseWin.c b/bundles/org.eclipse.equinox.executable/library/win32/eclipseWin.c
index 6fa03db..f7772c9 100644
--- a/bundles/org.eclipse.equinox.executable/library/win32/eclipseWin.c
+++ b/bundles/org.eclipse.equinox.executable/library/win32/eclipseWin.c
@@ -58,6 +58,16 @@
 										 _T("classic"), _T("..\\jre\\bin\\classic"),
 										 _T("jrockit"), _T("..\\jre\\bin\\jrockit"),
 								 		 NULL };
+
+/* for detecting sun vms */
+typedef struct {
+	WORD language;
+	WORD codepage;
+} TRANSLATIONS;
+
+#define COMPANY_NAME_KEY _T_ECLIPSE("\\StringFileInfo\\%04x%04x\\CompanyName")
+#define SUN_MICROSYSTEMS _T_ECLIPSE("Sun Microsystems")
+
 /* Show the Splash Window
  *
  * Open the bitmap, insert into the splash window and display it.
@@ -442,3 +452,41 @@
 {
 	return startJavaJNI(libPath, vmArgs, progArgs);
 }
+
+int isSunVM( _TCHAR * vm ) {
+	int result = 0;
+	DWORD infoSize;
+	DWORD handle;
+	void * info;
+	
+	_TCHAR * key, *value;
+	int i, valueSize;
+	
+	if (vm == NULL)
+		return 0;
+	
+	infoSize = GetFileVersionInfoSize(vm, &handle);
+	if (infoSize > 0) {
+		info = malloc(infoSize);
+		if (GetFileVersionInfo(vm, 0,  infoSize, info)) {
+			TRANSLATIONS * translations;
+			int translationsSize;
+			VerQueryValue(info,  _T_ECLIPSE("\\VarFileInfo\\Translation"), (void *) &translations, &translationsSize);
+			
+			/* this size is only right because %04x is 4 characters */
+			key = malloc( (_tcslen(COMPANY_NAME_KEY) + 1) * sizeof(_TCHAR));
+			for (i = 0; i < (translationsSize / sizeof(TRANSLATIONS)); i++) {
+				_stprintf(key, COMPANY_NAME_KEY, translations[i].language, translations[i].codepage);
+				
+				VerQueryValue(info, key, (void *)&value, &valueSize);
+				if (_tcsncmp(value, SUN_MICROSYSTEMS, _tcslen(SUN_MICROSYSTEMS)) == 0) {
+					result = 1;
+					break;
+				}
+			}
+			free(key);
+		}
+		free(info);
+	}
+	return result;
+}
diff --git a/bundles/org.eclipse.equinox.executable/library/win32/make_mingw.mak b/bundles/org.eclipse.equinox.executable/library/win32/make_mingw.mak
index ff8e9fb..cd81036 100644
--- a/bundles/org.eclipse.equinox.executable/library/win32/make_mingw.mak
+++ b/bundles/org.eclipse.equinox.executable/library/win32/make_mingw.mak
@@ -54,7 +54,7 @@
 DLL_OBJS	= eclipse.o  eclipseWin.o  eclipseUtil.o  eclipseJNI.o eclipseShm.o\
 	  		  aeclipse.o aeclipseWin.o aeclipseUtil.o aeclipseJNI.o aeclipseShm.o
 	  		  
-LIBS	= -lkernel32 -luser32 -lgdi32 -lcomctl32 -lmsvcrt
+LIBS	= -lkernel32 -luser32 -lgdi32 -lcomctl32 -lmsvcrt -lversion
 LDFLAGS = -mwindows -mno-cygwin
 CONSOLEFLAGS = -mconsole -mno-cygwin
 DLL_LDFLAGS = -mno-cygwin -shared -Wl,--export-all-symbols -Wl,--kill-at
diff --git a/bundles/org.eclipse.equinox.executable/library/win32/make_win32.mak b/bundles/org.eclipse.equinox.executable/library/win32/make_win32.mak
index cf30192..b12bfe1 100644
--- a/bundles/org.eclipse.equinox.executable/library/win32/make_win32.mak
+++ b/bundles/org.eclipse.equinox.executable/library/win32/make_win32.mak
@@ -34,7 +34,7 @@
 	  		  aeclipse.obj aeclipseWin.obj aeclipseUtil.obj aeclipseJNI.obj aeclipseShm.obj
 
 LIBS   = kernel32.lib user32.lib comctl32.lib msvcrt.lib
-DLL_LIBS = kernel32.lib user32.lib comctl32.lib gdi32.lib Advapi32.lib msvcrt.lib
+DLL_LIBS = kernel32.lib user32.lib comctl32.lib gdi32.lib Advapi32.lib msvcrt.lib version.lib
 LFLAGS = /NODEFAULTLIB /INCREMENTAL:NO /RELEASE /NOLOGO -subsystem:windows,4.0 -entry:wmainCRTStartup
 CONSOLEFLAGS = /NODEFAULTLIB /INCREMENTAL:NO /RELEASE /NOLOGO -subsystem:console,4.0 -entry:wmainCRTStartup
 DLL_LFLAGS = /NODEFAULTLIB /INCREMENTAL:NO /PDB:NONE /RELEASE /NOLOGO -entry:_DllMainCRTStartup@12 -dll /BASE:0x10000000 /DLL
diff --git a/bundles/org.eclipse.equinox.executable/library/wpf/eclipseWpf.cpp b/bundles/org.eclipse.equinox.executable/library/wpf/eclipseWpf.cpp
index 94328c7..390cb14 100644
--- a/bundles/org.eclipse.equinox.executable/library/wpf/eclipseWpf.cpp
+++ b/bundles/org.eclipse.equinox.executable/library/wpf/eclipseWpf.cpp
@@ -64,6 +64,14 @@
 										 _T("classic"), _T("..\\jre\\bin\\classic"),
 										 _T("jrockit"), _T("..\\jre\\bin\\jrockit"),
 								 		 NULL };
+/* for detecting sun vms */
+typedef struct {
+	WORD language;
+	WORD codepage;
+} TRANSLATIONS;
+
+#define COMPANY_NAME_KEY _T_ECLIPSE("\\StringFileInfo\\%04x%04x\\CompanyName")
+#define SUN_MICROSYSTEMS _T_ECLIPSE("Sun Microsystems")
 
 delegate void NoArgsHandler ();
 
@@ -513,4 +521,42 @@
 	return startJavaJNI(libPath, vmArgs, progArgs);
 }
 
+int isSunVM( _TCHAR * vm ) {
+	int result = 0;
+	DWORD infoSize;
+	DWORD handle;
+	void * info;
+	
+	_TCHAR * key, *value;
+	int i, valueSize;
+	
+	if (vm == NULL)
+		return 0;
+	
+	infoSize = GetFileVersionInfoSize(vm, &handle);
+	if (infoSize > 0) {
+		info = malloc(infoSize);
+		if (GetFileVersionInfo(vm, 0,  infoSize, info)) {
+			TRANSLATIONS * translations;
+			int translationsSize;
+			VerQueryValue(info,  _T_ECLIPSE("\\VarFileInfo\\Translation"), (LPVOID *) &translations, (PUINT)&translationsSize);
+			
+			/* this size is only right because %04x is 4 characters */
+			key = (_TCHAR *) malloc( (_tcslen(COMPANY_NAME_KEY) + 1) * sizeof(_TCHAR));
+			for (i = 0; i < (translationsSize / sizeof(TRANSLATIONS)); i++) {
+				_stprintf(key, COMPANY_NAME_KEY, translations[i].language, translations[i].codepage);
+				
+				VerQueryValue(info, key, (LPVOID *)&value, (PUINT)&valueSize);
+				if (_tcsncmp(value, SUN_MICROSYSTEMS, _tcslen(SUN_MICROSYSTEMS)) == 0) {
+					result = 1;
+					break;
+				}
+			}
+			free(key);
+		}
+		free(info);
+	}
+	return result;
+}
+
 } // extern "C"
diff --git a/bundles/org.eclipse.equinox.executable/library/wpf/make_wpf.mak b/bundles/org.eclipse.equinox.executable/library/wpf/make_wpf.mak
index aa548cb..2afca3c 100644
--- a/bundles/org.eclipse.equinox.executable/library/wpf/make_wpf.mak
+++ b/bundles/org.eclipse.equinox.executable/library/wpf/make_wpf.mak
@@ -31,7 +31,7 @@
 DLL_OBJS	= eclipse.obj  eclipseWpf.obj  eclipseUtil.obj  eclipseJNI.obj eclipseShm.obj
 
 LIBS   = kernel32.lib msvcrt.lib mscoree.lib
-DLL_LIBS = kernel32.lib Advapi32.lib msvcrt.lib
+DLL_LIBS = kernel32.lib Advapi32.lib msvcrt.lib version.lib
 LFLAGS =  -CLRTHREADATTRIBUTE:STA /NODEFAULTLIB:LIBCMT /INCREMENTAL:NO /RELEASE /NOLOGO -subsystem:windows,4.0 -entry:wmainCRTStartup
 CONSOLEFLAGS =  -CLRTHREADATTRIBUTE:STA /NODEFAULTLIB:LIBCMT /INCREMENTAL:NO /RELEASE /NOLOGO -subsystem:console,4.0 -entry:wmainCRTStartup
 DLL_LFLAGS = -CLRTHREADATTRIBUTE:STA /NODEFAULTLIB:LIBCMT /INCREMENTAL:NO /PDB:NONE -dll /BASE:0x10000000 /DLL