Bug 458558 - [1.9] --launcher.XXMaxPermSize should not pass
-XX:MaxPermSize= for Oracle VMs >= 8

Change-Id: If930c83b63af879e0edd31713f9bcc75a62efa87
Signed-off-by: Arun Thondapu <arunkumar.thondapu@in.ibm.com>
diff --git a/features/org.eclipse.equinox.executable.feature/library/carbon/eclipseCarbon.c b/features/org.eclipse.equinox.executable.feature/library/carbon/eclipseCarbon.c
index 500311a..a158f64 100644
--- a/features/org.eclipse.equinox.executable.feature/library/carbon/eclipseCarbon.c
+++ b/features/org.eclipse.equinox.executable.feature/library/carbon/eclipseCarbon.c
@@ -533,8 +533,12 @@
 		}
 		if (strstr(buffer, "Java HotSpot(TM)") || strstr(buffer, "OpenJDK")) {
 			if (version != NULL) {
-				if (version[0] == '1' && ((int)(version[2] - '0') < 8)) {
-					isSunMaxPermSizeVM = 1;
+				_TCHAR *value = strtok(version, ".");
+				if (value != NULL && (strtol(value, NULL, 10) == 1)) {
+					value = strtok(NULL, ".");
+					if (strtol(value, NULL, 10) < 8) {
+						result = 1;
+					}
 				}
 			}
 			break;
diff --git a/features/org.eclipse.equinox.executable.feature/library/eclipseNix.c b/features/org.eclipse.equinox.executable.feature/library/eclipseNix.c
index a4439c7..c6062b2 100644
--- a/features/org.eclipse.equinox.executable.feature/library/eclipseNix.c
+++ b/features/org.eclipse.equinox.executable.feature/library/eclipseNix.c
@@ -175,6 +175,9 @@
 }
 
 int isMaxPermSizeVM( _TCHAR * javaVM, _TCHAR * jniLib ) {
+	if (javaVM == NULL) {
+		return 0;
+	}
 	FILE *fp = NULL;
 	_TCHAR buffer[4096];
 	_TCHAR *version = NULL, *firstChar;
@@ -199,8 +202,12 @@
 		}
 		if (_tcsstr(buffer, "Java HotSpot(TM)") || _tcsstr(buffer, "OpenJDK")) {
 			if (version != NULL) {
-				if (version[0] == '1' && ((int)(version[2] - '0') < 8)) {
-					result = 1;
+				_TCHAR *value = _tcstok(version, ".");
+				if (value != NULL && (_tcstol(value, NULL, 10) == 1)) {
+					value = _tcstok(NULL, ".");
+					if (_tcstol(value, NULL, 10) < 8) {
+						result = 1;
+					}
 				}
 			}
 			break;
diff --git a/features/org.eclipse.equinox.executable.feature/library/eclipseUnicode.h b/features/org.eclipse.equinox.executable.feature/library/eclipseUnicode.h
index f98b77d..6d758b9 100644
--- a/features/org.eclipse.equinox.executable.feature/library/eclipseUnicode.h
+++ b/features/org.eclipse.equinox.executable.feature/library/eclipseUnicode.h
@@ -96,6 +96,7 @@
 #define _tgetcwd getcwd
 #define _tgetenv getenv
 #define _tcstol strtol
+#define _tcstok strtok
 #ifndef LINUX
 #define _totupper toupper
 #endif /* LINUX */
diff --git a/features/org.eclipse.equinox.executable.feature/library/win32/eclipseWin.c b/features/org.eclipse.equinox.executable.feature/library/win32/eclipseWin.c
index e933882..cd88067 100644
--- a/features/org.eclipse.equinox.executable.feature/library/win32/eclipseWin.c
+++ b/features/org.eclipse.equinox.executable.feature/library/win32/eclipseWin.c
@@ -78,6 +78,7 @@
 } TRANSLATIONS;
 
 #define COMPANY_NAME_KEY _T_ECLIPSE("\\StringFileInfo\\%04x%04x\\CompanyName")
+#define PRODUCT_VERSION_KEY _T_ECLIPSE("\\StringFileInfo\\%04x%04x\\ProductVersion")
 #define SUN_MICROSYSTEMS _T_ECLIPSE("Sun Microsystems")
 #define ORACLE 			 _T_ECLIPSE("Oracle")
 
@@ -584,9 +585,9 @@
 	DWORD handle;
 	void * info;
 	
-	_TCHAR * key, *value;
+	_TCHAR *key, *value, *versionKey, *version;
 	size_t i;
-	int valueSize;
+	int valueSize, versionSize;
 	
 	if (vm == NULL)
 		return 0;
@@ -598,22 +599,25 @@
 			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));
+			key = malloc((_tcslen(COMPANY_NAME_KEY) + 1) * sizeof(_TCHAR));
+			versionKey = malloc((_tcslen(PRODUCT_VERSION_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;
-				} else if (_tcsncmp(value, ORACLE, _tcslen(ORACLE)) == 0) {
-					result = 1;
+
+				if ((_tcsncmp(value, SUN_MICROSYSTEMS, _tcslen(SUN_MICROSYSTEMS)) == 0) || (_tcsncmp(value, ORACLE, _tcslen(ORACLE)) == 0)) {
+					_stprintf(versionKey, PRODUCT_VERSION_KEY, translations[i].language, translations[i].codepage);
+					VerQueryValue(info, versionKey, (void *)&version, &versionSize);
+					if ((version[0] - '0') < 8) {
+						result = 1;
+					}
 					break;
 				}
 			}
 			free(key);
+			free(versionKey);
 		}
 		free(info);
 	}